emailuis/nmailui/src/nmeditorcontent.cpp
changeset 43 99bcbff212ad
parent 23 2dc6caa42ec3
child 44 c2d07d913565
equal deleted inserted replaced
42:139d4b7b2938 43:99bcbff212ad
    18 #include "nmuiheaders.h"
    18 #include "nmuiheaders.h"
    19 
    19 
    20 // Layout
    20 // Layout
    21 static const char *NMUI_EDITOR_BODY = "BodyTextEdit";
    21 static const char *NMUI_EDITOR_BODY = "BodyTextEdit";
    22 
    22 
    23 static const double Un = 6.66;
       
    24 static const double HeaderAreaMarginsTotal = 3 * Un;
       
    25 
       
    26 /*!
    23 /*!
    27     Constructor
    24     Constructor
    28 */
    25 */
    29 NmEditorContent::NmEditorContent(QGraphicsItem *parent,
    26 NmEditorContent::NmEditorContent(QGraphicsItem *parent,
    30                                  NmEditorView *parentView,
    27                                  NmEditorView *parentView,
    36     mEditorLayout(NULL),
    33     mEditorLayout(NULL),
    37     mMessageBodyType(PlainText),
    34     mMessageBodyType(PlainText),
    38     mEditorWidget(NULL),
    35     mEditorWidget(NULL),
    39     mBackgroundScrollArea((NmBaseViewScrollArea*)parent)
    36     mBackgroundScrollArea((NmBaseViewScrollArea*)parent)
    40 {
    37 {
    41     mBackgroundScrollArea->setLongPressEnabled(true);
    38     NM_FUNCTION;
    42 
    39 
    43     // Add header area handling widget into layout
    40     // Add header area handling widget into layout
    44     mHeaderWidget = new NmEditorHeader(documentLoader, this);
    41     mHeaderWidget = new NmEditorHeader(documentLoader);
    45 
    42 
    46     // Get pointer to body text area handling widget
    43     // Get pointer to body text area handling widget
    47     mEditorWidget = qobject_cast<NmEditorTextEdit *>(documentLoader->findWidget(NMUI_EDITOR_BODY));
    44     mEditorWidget = qobject_cast<NmEditorTextEdit *>(documentLoader->findWidget(NMUI_EDITOR_BODY));
    48 
    45     
    49     // Set body editor to use NmEditorTextDocument
    46     // Set body editor to use NmEditorTextDocument
    50     NmEditorTextDocument *textDocument = new NmEditorTextDocument(manager);
    47     NmEditorTextDocument *textDocument = new NmEditorTextDocument(manager);
    51     mEditorWidget->setDocument(textDocument); 
    48     mEditorWidget->setDocument(textDocument); 
    52     textDocument->setParent(mEditorWidget); // ownership changes
    49     textDocument->setParent(mEditorWidget); // ownership changes
    53 
    50 
    66 /*!
    63 /*!
    67     Destructor
    64     Destructor
    68 */
    65 */
    69 NmEditorContent::~NmEditorContent()
    66 NmEditorContent::~NmEditorContent()
    70 {
    67 {
       
    68     NM_FUNCTION;
       
    69     
    71    delete mHeaderWidget;
    70    delete mHeaderWidget;
    72 }
    71 }
    73 
    72 
    74 /*!
    73 /*!
    75     Fill message data into header and body fileds. If reply envelopw is
    74     Fill message data into header and body fileds. If reply envelopw is
    76     present, reply header is generated and set to editor. Reply
    75     present, reply header is generated and set to editor. Reply
    77     envelope ownership is not transferred here.
    76     envelope ownership is not transferred here.
    78  */
    77  */
    79 void NmEditorContent::setMessageData(const NmMessage &message,
    78 void NmEditorContent::setMessageData(const NmMessage &originalMessage)
    80                                      NmMessageEnvelope *replyMsgEnvelope)
       
    81 {
    79 {
    82     // Check which part is present. Html or plain text part
    80     NM_FUNCTION;
    83     const NmMessagePart *htmlPart = message.htmlBodyPart();
    81     // Check which part is present. Html or plain text part. We use the original message parts.
    84     const NmMessagePart *plainPart = message.plainTextBodyPart();
    82     const NmMessagePart *htmlPart = originalMessage.htmlBodyPart();
    85 
    83 
    86     QList<NmMessagePart*> parts;
    84     const NmMessagePart *plainPart = originalMessage.plainTextBodyPart();
    87     message.attachmentList(parts);
       
    88     NmMessagePart* attachmentHtml = NULL;
       
    89 
    85 
    90     foreach(NmMessagePart* part, parts) {
    86     if (htmlPart) {
    91         if (part->contentDescription().startsWith( NmContentDescrAttachmentHtml )) {
    87         emit setHtml(htmlPart->textContent());    
    92                 attachmentHtml = part;
       
    93             }
       
    94         }
       
    95     
       
    96     if (htmlPart) {	    
       
    97         // Html part was present, set it to HbTextEdit
       
    98         // This will generate contentsChanged() event which is used to
       
    99         // set new height for the editor widget and content.
       
   100         if(attachmentHtml){
       
   101             QString htmlText = htmlPart->textContent() + attachmentHtml->textContent();
       
   102             emit setHtml(htmlText);
       
   103         } 
       
   104         else{
       
   105             emit setHtml(htmlPart->textContent());    
       
   106         }
       
   107         mMessageBodyType = HTMLText;
    88         mMessageBodyType = HTMLText;
   108     }
    89     }
   109     else if (plainPart) {
    90     else if (plainPart) {
   110         // Plain text part was present, set it to HbTextEdit
    91         // Plain text part was present, set it to HbTextEdit
   111         emit setPlainText(plainPart->textContent());
    92         emit setPlainText(plainPart->textContent());
   112         mMessageBodyType = PlainText;
    93         mMessageBodyType = PlainText;
   113     }
    94     }
   114     
    95     
   115     // Original message text to editor content fiel
    96     // We create the "reply" header (also for forward message)
   116     if (replyMsgEnvelope && mEditorWidget) {          
    97     if (mEditorWidget) {          
   117         QTextCursor cursor = mEditorWidget->textCursor();
    98         QTextCursor cursor = mEditorWidget->textCursor();
   118         cursor.setPosition(0);
    99         cursor.setPosition(0);
   119         cursor.insertHtml(NmUtilities::createReplyHeader(*replyMsgEnvelope));
   100         cursor.insertHtml(NmUtilities::createReplyHeader(originalMessage.envelope()));
   120     }
   101     }
   121 }  
   102 }  
   122 
   103 
   123 /*!
   104 /*!
   124    This method set new height for the editor content when header or body field
   105    This method set new height for the editor content when header or body field
   125    height has been changed.
   106    height has been changed.
   126  */
   107  */
   127 void NmEditorContent::setEditorContentHeight()
   108 void NmEditorContent::setEditorContentHeight()
   128 {
   109 {
       
   110     NM_FUNCTION;
       
   111     
   129 	const QSizeF reso = HbDeviceProfile::current().logicalSize();
   112 	const QSizeF reso = HbDeviceProfile::current().logicalSize();
   130     qreal containerHeight =
   113     qreal containerHeight = mEditorWidget->contentHeight() + mHeaderWidget->headerHeight();
   131         mEditorWidget->contentHeight() + mHeaderWidget->headerHeight() + HeaderAreaMarginsTotal;
       
   132     if (containerHeight < reso.height()) {
   114     if (containerHeight < reso.height()) {
   133         //Currently content height is too long because Chrome hiding is not supported.
   115         //Currently content height is too long because Chrome hiding is not supported.
   134         //Fix this when Chrome works.
   116         //Fix this when Chrome works.
   135         containerHeight = reso.height();
   117         containerHeight = reso.height();
   136         qreal bodyContentHeight =
   118         qreal bodyContentHeight =
   137             reso.height() - mHeaderWidget->headerHeight() - HeaderAreaMarginsTotal;
   119             reso.height() - mHeaderWidget->headerHeight();
   138         mEditorWidget->setPreferredHeight(bodyContentHeight);
   120         mEditorWidget->setPreferredHeight(bodyContentHeight);
   139         mEditorWidget->setMaximumHeight(bodyContentHeight);
   121         mEditorWidget->setMaximumHeight(bodyContentHeight);
   140     }
   122     }
   141     mParentView->scrollAreaContents()->setMinimumHeight(containerHeight);
   123     mParentView->scrollAreaContents()->setMinimumHeight(containerHeight);
   142     mParentView->scrollAreaContents()->setMaximumHeight(containerHeight);
   124     mParentView->scrollAreaContents()->setMaximumHeight(containerHeight);
   146 /*!
   128 /*!
   147    This method creates all needed signal-slot connections
   129    This method creates all needed signal-slot connections
   148  */
   130  */
   149 void NmEditorContent::createConnections()
   131 void NmEditorContent::createConnections()
   150 {
   132 {
       
   133     NM_FUNCTION;
       
   134     
   151     // Body edit widget is also interested about bg scroll position change
   135     // Body edit widget is also interested about bg scroll position change
   152     connect(mBackgroundScrollArea, SIGNAL(scrollPositionChanged(QPointF)),
   136     connect(mBackgroundScrollArea, SIGNAL(scrollPositionChanged(QPointF)),
   153             mEditorWidget, SLOT(updateScrollPosition(QPointF)));
   137             mEditorWidget, SLOT(updateScrollPosition(QPointF)));
   154     // Signal for setting HbTextEdit widgets html content
   138     // Signal for setting HbTextEdit widgets html content
   155     connect(this, SIGNAL(setHtml(QString)),
   139     connect(this, SIGNAL(setHtml(QString)),
   165 /*!
   149 /*!
   166     Return pointer to the email body text edit widget
   150     Return pointer to the email body text edit widget
   167  */
   151  */
   168 NmEditorTextEdit* NmEditorContent::editor() const
   152 NmEditorTextEdit* NmEditorContent::editor() const
   169 {
   153 {
       
   154     NM_FUNCTION;
       
   155     
   170     return mEditorWidget;
   156     return mEditorWidget;
   171 }
   157 }
   172 
   158 
   173 /*!
   159 /*!
   174     Return pointer to the header widget
   160     Return pointer to the header widget
   175  */
   161  */
   176 NmEditorHeader* NmEditorContent::header() const
   162 NmEditorHeader* NmEditorContent::header() const
   177 {
   163 {
       
   164     NM_FUNCTION;
       
   165     
   178     return mHeaderWidget;
   166     return mHeaderWidget;
   179 }
   167 }
   180 
   168