emailuis/nmailui/src/nmeditorcontent.cpp
changeset 62 a8c646b56683
parent 51 d845db10c0d4
child 66 084b5b1f02a7
equal deleted inserted replaced
57:ae34e1715e21 62:a8c646b56683
    33                                  HbDocumentLoader *documentLoader,
    33                                  HbDocumentLoader *documentLoader,
    34                                  QNetworkAccessManager &manager,
    34                                  QNetworkAccessManager &manager,
    35                                  NmApplication &application) :
    35                                  NmApplication &application) :
    36     QObject(parent),
    36     QObject(parent),
    37     mHeader(NULL),
    37     mHeader(NULL),
    38     mMessageBodyType(NmPlainText),
       
    39     mEditorWidget(NULL),
    38     mEditorWidget(NULL),
    40     mScrollArea(NULL),
    39     mScrollArea(NULL),
    41     mScrollAreaContents(NULL),
    40     mScrollAreaContents(NULL),
    42     mApplication(application),
    41     mApplication(application),
    43     mNeedForWidthAdjustment(false)
    42     mNeedForWidthAdjustment(false)
    87 {
    86 {
    88     NM_FUNCTION;
    87     NM_FUNCTION;
    89 }
    88 }
    90 
    89 
    91 /*!
    90 /*!
    92     Fill message data into header and body fileds. If reply envelopw is
    91     Sets the body content. If reply envelopw is present, reply header is generated and set to 
    93     present, reply header is generated and set to editor. Reply
    92     editor. Reply envelope ownership is not transferred here.
    94     envelope ownership is not transferred here.
    93  */
    95  */
    94 void NmEditorContent::setBodyContent(NmUiEditorStartMode editorStartMode,
    96 void NmEditorContent::setMessageData(const NmMessage &originalMessage, 
    95                                      const NmMessage *originalMessage, 
    97                                      NmUiEditorStartMode &editorStartMode)
    96                                      const QString *signature)
    98 {
    97 {
    99     NM_FUNCTION;
    98     NM_FUNCTION;
   100     
    99     
   101     QString bodyContent;
   100     QString bodyContent;
       
   101     
       
   102     // first insert the signature
       
   103     if (signature) {
       
   104         bodyContent.append("<html><body><br><br>");
       
   105         bodyContent.append(*signature);
       
   106         bodyContent.append("<br></body></html>");
       
   107     }
       
   108     
   102 	QTextCursor cursor(mEditorWidget->document());
   109 	QTextCursor cursor(mEditorWidget->document());
   103     
   110     
   104     // Create the "reply" header (also for forward message)
   111     // Create the "reply" header (also for forward message)
   105     if (editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll || 
   112 	// sets the font color of the reply header and the original body text to black
   106         editorStartMode==NmUiEditorForward) {
   113     if ((editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll || 
       
   114         editorStartMode==NmUiEditorForward) && originalMessage) {
   107 		bodyContent.append(QString("<style type=\"text/css\">* { color: black; }</style>"));
   115 		bodyContent.append(QString("<style type=\"text/css\">* { color: black; }</style>"));
   108         bodyContent.append(NmUtilities::createReplyHeader(originalMessage.envelope()));
   116         bodyContent.append(NmUtilities::createReplyHeader(originalMessage->envelope()));
   109     }
   117     }
   110     
   118     
   111     // Check which part is present. Html or plain text part. We use the original message parts.
   119     // Check which part is present. Html or plain text part. We use the original message parts.
   112     const NmMessagePart *htmlPart = originalMessage.htmlBodyPart();
   120     const NmMessagePart *htmlPart = NULL;
   113     const NmMessagePart *plainPart = originalMessage.plainTextBodyPart();
   121     const NmMessagePart *plainPart = NULL;
       
   122     if (originalMessage) {
       
   123         htmlPart = originalMessage->htmlBodyPart();
       
   124         plainPart = originalMessage->plainTextBodyPart();
       
   125     }
   114  
   126  
   115     if (htmlPart) {
   127     if (htmlPart) {
   116         bodyContent.append(htmlPart->textContent());
   128         bodyContent.append(htmlPart->textContent());
   117         if(editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll ) {
   129         if(editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll ) {
   118             removeEmbeddedImages(bodyContent);
   130             removeEmbeddedImages(bodyContent);
   119         }
   131         }
   120         cursor.insertHtml(bodyContent);
       
   121         mMessageBodyType = NmHTMLText;
       
   122     }
   132     }
   123     else if (plainPart) {
   133     else if (plainPart) {
   124         // Plain text part was present, set it to HbTextEdit
   134         // Plain text part was present, set it to HbTextEdit as HTML
       
   135         bodyContent.append(QString("<html><body><p>"));
   125         bodyContent.append(plainPart->textContent());
   136         bodyContent.append(plainPart->textContent());
   126         cursor.insertText(bodyContent);
   137         bodyContent.append(QString("</p></body></html>"));
   127         mMessageBodyType = NmPlainText;
   138     }
   128         
   139     cursor.insertHtml(bodyContent);
   129 		// Next we set text color for black for all current content
   140 
   130         QTextCharFormat blackForeground;
       
   131     	blackForeground = cursor.charFormat();
       
   132     	blackForeground.setForeground(Qt::black);
       
   133     	cursor.select(QTextCursor::Document);
       
   134     	cursor.mergeCharFormat(blackForeground);
       
   135     }
       
   136     // Update of the body width is done when next contentChanged signal comes from the body.
   141     // Update of the body width is done when next contentChanged signal comes from the body.
   137     mNeedForWidthAdjustment = true;
   142     mNeedForWidthAdjustment = true;
   138 	cursor.clearSelection();
   143 	cursor.clearSelection();
   139 	cursor.setPosition(0);
   144 	cursor.setPosition(0);
   140 	cursor.insertHtml(QString("<html><body><br><br></body></html>"));
   145 	cursor.insertHtml(QString("<html><body></body></html>"));
   141 }  
   146 }  
   142 
   147 
   143 /*!
   148 /*!
   144    This method creates all needed signal-slot connections
   149    This method creates all needed signal-slot connections
   145  */
   150  */
   179     connect(parent(), SIGNAL(sizeChanged()), this, SLOT(ensureCursorVisibility()),
   184     connect(parent(), SIGNAL(sizeChanged()), this, SLOT(ensureCursorVisibility()),
   180         Qt::QueuedConnection);
   185         Qt::QueuedConnection);
   181 
   186 
   182     // Listen scroll posion change signals for header reposition.
   187     // Listen scroll posion change signals for header reposition.
   183     connect(mScrollArea, SIGNAL(scrollPositionChanged(QPointF)),
   188     connect(mScrollArea, SIGNAL(scrollPositionChanged(QPointF)),
   184     		mHeader, SLOT(repositHeader(QPointF)));
   189        		this, SLOT(repositHeader(QPointF)));
   185 
   190     
   186     // Listen content change signal for body widget width adjustment.
   191     // Listen content change signal for body widget width adjustment.
   187     connect(mEditorWidget->document(), SIGNAL(contentsChanged()), this, 
   192     connect(mEditorWidget->document(), SIGNAL(contentsChanged()), this, 
   188         SLOT(setEditorContentWidth()), Qt::QueuedConnection);
   193         SLOT(setEditorContentWidth()), Qt::QueuedConnection);
   189 }
   194 }
   190 
   195 
   311     NM_FUNCTION;
   316     NM_FUNCTION;
   312  
   317  
   313     QRegExp regExp(NMUI_EDITOR_REMOVE_EMBD_IMAGES_REG, Qt::CaseInsensitive);
   318     QRegExp regExp(NMUI_EDITOR_REMOVE_EMBD_IMAGES_REG, Qt::CaseInsensitive);
   314     bodyContent.remove(regExp);
   319     bodyContent.remove(regExp);
   315 }
   320 }
       
   321 
       
   322 /*!
       
   323     This slot is called when scroll position has been changed.
       
   324     Function create translation object which is used to set new position for
       
   325     header so that header stays visible when body is scrolled horizontally.
       
   326  */
       
   327 void NmEditorContent::repositHeader(const QPointF &scrollPosition)
       
   328 {
       
   329     NM_FUNCTION;
       
   330     
       
   331     // Get the layout's left margin
       
   332     qreal margin = 0;
       
   333     HbStyle().parameter("hb-param-margin-gene-left", margin);
       
   334     
       
   335     // Calculate header width. (Screen width minus left and right margins.
       
   336     qreal headerWidth = mApplication.screenSize().width() - margin - margin;
       
   337 
       
   338     // Create translation object for header position adjustment.
       
   339     QRectF editorBodyRect = mEditorWidget->geometry();
       
   340     QTransform tr;
       
   341     qreal leftMovementThreshold(editorBodyRect.width() - headerWidth);
       
   342     if (scrollPosition.x() < 0) {
       
   343         // Left side positioning. Allow left side baunch effect.
       
   344         tr.translate(editorBodyRect.topLeft().x() - margin ,0);
       
   345     }
       
   346     else if (scrollPosition.x() >= 0 && scrollPosition.x() < leftMovementThreshold) {
       
   347         // Middle area positioning
       
   348         tr.translate(scrollPosition.x() ,0);
       
   349     }
       
   350     else {
       
   351         // Right side positioning. Allow right side baunch effect.
       
   352         tr.translate(editorBodyRect.topLeft().x() + leftMovementThreshold - margin ,0);
       
   353     }
       
   354     // Call header to perform the translation which moves hader to new position.
       
   355     mHeader->repositHeader(tr);
       
   356 }
       
   357