emailuis/nmailui/src/nmeditorcontent.cpp
changeset 18 578830873419
child 20 ecc8def7944a
equal deleted inserted replaced
4:e7aa27f58ae1 18:578830873419
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Message editor contents widget
       
    15 *
       
    16 */
       
    17 
       
    18 #include "nmuiheaders.h"
       
    19 
       
    20 // Layout
       
    21 static const char *NMUI_EDITOR_BODY = "BodyTextEdit";
       
    22 
       
    23 static const double Un = 6.66;
       
    24 static const double HeaderAreaMarginsTotal = 3 * Un;
       
    25 
       
    26 /*!
       
    27     Constructor
       
    28 */
       
    29 NmEditorContent::NmEditorContent(QGraphicsItem *parent,
       
    30                                  NmEditorView *parentView,
       
    31                                  HbDocumentLoader *documentLoader) :
       
    32     HbWidget(parent),
       
    33     mHeaderWidget(NULL),
       
    34     mParentView(parentView),
       
    35     mEditorLayout(NULL),
       
    36     mMessage(NULL),
       
    37     mMessageBodyType(PlainText),
       
    38     mEditorWidget(NULL),
       
    39     mBackgroundScrollArea((NmBaseViewScrollArea*)parent)
       
    40 {
       
    41     mBackgroundScrollArea->setLongPressEnabled(true);
       
    42 
       
    43     // Add header area handling widget into layout
       
    44     mHeaderWidget = new NmEditorHeader(documentLoader, this);
       
    45 
       
    46     // Get pointer to body text area handling widget
       
    47     mEditorWidget = qobject_cast<NmEditorTextEdit *>(documentLoader->findWidget(NMUI_EDITOR_BODY));
       
    48     mEditorWidget->init(this, mBackgroundScrollArea);
       
    49     
       
    50     // Remove the comment to enable style picker menu item.
       
    51     mEditorWidget->setFormatDialog(new HbFormatDialog());
       
    52 
       
    53     // Create signal slot connections
       
    54     createConnections();
       
    55 }
       
    56 
       
    57 /*!
       
    58     Destructor
       
    59 */
       
    60 NmEditorContent::~NmEditorContent()
       
    61 {
       
    62    delete mHeaderWidget;
       
    63 }
       
    64 
       
    65 /*!
       
    66     Fill message data into header and body fileds
       
    67  */
       
    68 void NmEditorContent::setMessageData(NmMessage *message)
       
    69 {
       
    70     if(message)	{
       
    71         mMessage = message;
       
    72         // Check which part is present. Html or plain text part
       
    73         NmMessagePart *htmlPart = mMessage->htmlBodyPart();
       
    74         NmMessagePart *plainPart = mMessage->plainTextBodyPart();
       
    75 
       
    76         QList<NmMessagePart*> parts;
       
    77         mMessage->attachmentList(parts);
       
    78         NmMessagePart* attachmentHtml = NULL;
       
    79 
       
    80         foreach(NmMessagePart* part, parts) {
       
    81             if (part->contentDescription().startsWith( NmContentDescrAttachmentHtml )) {
       
    82                     attachmentHtml = part;
       
    83                 }
       
    84             }
       
    85         
       
    86         if (htmlPart) {	    
       
    87             // Html part was present, set it to HbTextEdit
       
    88             // This will generate contentsChanged() event which is used to
       
    89             // set new height for the editor widget and content.
       
    90             if(attachmentHtml){
       
    91                 QString htmlText = htmlPart->textContent() + attachmentHtml->textContent();
       
    92                 emit setHtml(htmlText);
       
    93             }
       
    94             else{
       
    95                 emit setHtml(htmlPart->textContent());    
       
    96             }
       
    97 
       
    98             mMessageBodyType = HTMLText;
       
    99         }
       
   100         else if (plainPart) {
       
   101             // Plain text part was present, set it to HbTextEdit
       
   102             emit setPlainText(plainPart->textContent());
       
   103             mMessageBodyType = PlainText;
       
   104         }
       
   105     }
       
   106 }
       
   107 
       
   108 /*!
       
   109    This method set new height for the editor content when header or body field
       
   110    height has been changed.
       
   111  */
       
   112 void NmEditorContent::setEditorContentHeight()
       
   113 {
       
   114 	const QSizeF reso = HbDeviceProfile::current().logicalSize();
       
   115     qreal containerHeight =
       
   116         mEditorWidget->contentHeight() + mHeaderWidget->headerHeight() + HeaderAreaMarginsTotal;
       
   117     if (containerHeight < reso.height()) {
       
   118         //Currently content height is too long because Chrome hiding is not supported.
       
   119         //Fix this when Chrome works.
       
   120         containerHeight = reso.height();
       
   121         qreal bodyContentHeight =
       
   122             reso.height() - mHeaderWidget->headerHeight() - HeaderAreaMarginsTotal;
       
   123         mEditorWidget->setPreferredHeight(bodyContentHeight);
       
   124         mEditorWidget->setMaximumHeight(bodyContentHeight);
       
   125     }
       
   126     mParentView->scrollAreaContents()->setMinimumHeight(containerHeight);
       
   127     mParentView->scrollAreaContents()->setMaximumHeight(containerHeight);
       
   128     mBackgroundScrollArea->setMaximumHeight(containerHeight);
       
   129 }
       
   130 
       
   131 /*!
       
   132    This method creates all needed signal-slot connections
       
   133  */
       
   134 void NmEditorContent::createConnections()
       
   135 {
       
   136     // Body edit widget is also interested about bg scroll position change
       
   137     connect(mBackgroundScrollArea, SIGNAL(scrollPositionChanged(QPointF)),
       
   138             mEditorWidget, SLOT(updateScrollPosition(QPointF)));
       
   139     // Signal for setting HbTextEdit widgets html content
       
   140     connect(this, SIGNAL(setHtml(QString)),
       
   141             mEditorWidget, SLOT(setHtml(QString)));
       
   142     // Signal for setting HbTextEdit widgets plain text content
       
   143     connect(this, SIGNAL(setPlainText(QString)),
       
   144             mEditorWidget, SLOT(setPlainText(QString)));
       
   145     // Inform text edit widget that header height has been changed
       
   146     connect(mHeaderWidget, SIGNAL(headerHeightChanged(int)),
       
   147             mEditorWidget, SLOT(setHeaderHeight(int)));
       
   148 }
       
   149 
       
   150 /*!
       
   151     Return pointer to the email body text edit widget
       
   152  */
       
   153 NmEditorTextEdit* NmEditorContent::editor() const
       
   154 {
       
   155     return mEditorWidget;
       
   156 }
       
   157 
       
   158 /*!
       
   159     Return pointer to the header widget
       
   160  */
       
   161 NmEditorHeader* NmEditorContent::header() const
       
   162 {
       
   163     return mHeaderWidget;
       
   164 }
       
   165