emailuis/nmailui/src/nmeditorcontent.cpp
changeset 20 ecc8def7944a
parent 18 578830873419
child 23 2dc6caa42ec3
equal deleted inserted replaced
18:578830873419 20:ecc8def7944a
    26 /*!
    26 /*!
    27     Constructor
    27     Constructor
    28 */
    28 */
    29 NmEditorContent::NmEditorContent(QGraphicsItem *parent,
    29 NmEditorContent::NmEditorContent(QGraphicsItem *parent,
    30                                  NmEditorView *parentView,
    30                                  NmEditorView *parentView,
    31                                  HbDocumentLoader *documentLoader) :
    31                                  HbDocumentLoader *documentLoader,
       
    32                                  QNetworkAccessManager &manager) :
    32     HbWidget(parent),
    33     HbWidget(parent),
    33     mHeaderWidget(NULL),
    34     mHeaderWidget(NULL),
    34     mParentView(parentView),
    35     mParentView(parentView),
    35     mEditorLayout(NULL),
    36     mEditorLayout(NULL),
    36     mMessage(NULL),
       
    37     mMessageBodyType(PlainText),
    37     mMessageBodyType(PlainText),
    38     mEditorWidget(NULL),
    38     mEditorWidget(NULL),
    39     mBackgroundScrollArea((NmBaseViewScrollArea*)parent)
    39     mBackgroundScrollArea((NmBaseViewScrollArea*)parent)
    40 {
    40 {
    41     mBackgroundScrollArea->setLongPressEnabled(true);
    41     mBackgroundScrollArea->setLongPressEnabled(true);
    43     // Add header area handling widget into layout
    43     // Add header area handling widget into layout
    44     mHeaderWidget = new NmEditorHeader(documentLoader, this);
    44     mHeaderWidget = new NmEditorHeader(documentLoader, this);
    45 
    45 
    46     // Get pointer to body text area handling widget
    46     // Get pointer to body text area handling widget
    47     mEditorWidget = qobject_cast<NmEditorTextEdit *>(documentLoader->findWidget(NMUI_EDITOR_BODY));
    47     mEditorWidget = qobject_cast<NmEditorTextEdit *>(documentLoader->findWidget(NMUI_EDITOR_BODY));
       
    48 
       
    49     // Set body editor to use NmEditorTextDocument
       
    50     NmEditorTextDocument *textDocument = new NmEditorTextDocument(manager);
       
    51     mEditorWidget->setDocument(textDocument); 
       
    52     textDocument->setParent(mEditorWidget); // ownership changes
       
    53 
    48     mEditorWidget->init(this, mBackgroundScrollArea);
    54     mEditorWidget->init(this, mBackgroundScrollArea);
    49     
    55     
    50     // Remove the comment to enable style picker menu item.
    56     // Remove the comment to enable style picker menu item.
    51     mEditorWidget->setFormatDialog(new HbFormatDialog());
    57     mEditorWidget->setFormatDialog(new HbFormatDialog());
    52 
    58 
    61 {
    67 {
    62    delete mHeaderWidget;
    68    delete mHeaderWidget;
    63 }
    69 }
    64 
    70 
    65 /*!
    71 /*!
    66     Fill message data into header and body fileds
    72     Fill message data into header and body fileds. If reply envelopw is
       
    73     present, reply header is generated and set to editor. Reply
       
    74     envelope ownership is not transferred here.
    67  */
    75  */
    68 void NmEditorContent::setMessageData(NmMessage *message)
    76 void NmEditorContent::setMessageData(const NmMessage &message,
       
    77                                      NmMessageEnvelope *replyMsgEnvelope)
    69 {
    78 {
    70     if(message)	{
    79     // Check which part is present. Html or plain text part
    71         mMessage = message;
    80     const NmMessagePart *htmlPart = message.htmlBodyPart();
    72         // Check which part is present. Html or plain text part
    81     const NmMessagePart *plainPart = message.plainTextBodyPart();
    73         NmMessagePart *htmlPart = mMessage->htmlBodyPart();
       
    74         NmMessagePart *plainPart = mMessage->plainTextBodyPart();
       
    75 
    82 
    76         QList<NmMessagePart*> parts;
    83     QList<NmMessagePart*> parts;
    77         mMessage->attachmentList(parts);
    84     message.attachmentList(parts);
    78         NmMessagePart* attachmentHtml = NULL;
    85     NmMessagePart* attachmentHtml = NULL;
    79 
    86 
    80         foreach(NmMessagePart* part, parts) {
    87     foreach(NmMessagePart* part, parts) {
    81             if (part->contentDescription().startsWith( NmContentDescrAttachmentHtml )) {
    88         if (part->contentDescription().startsWith( NmContentDescrAttachmentHtml )) {
    82                     attachmentHtml = part;
    89                 attachmentHtml = part;
    83                 }
       
    84             }
    90             }
    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         }
    91         }
   100         else if (plainPart) {
    92     
   101             // Plain text part was present, set it to HbTextEdit
    93     if (htmlPart) {	    
   102             emit setPlainText(plainPart->textContent());
    94         // Html part was present, set it to HbTextEdit
   103             mMessageBodyType = PlainText;
    95         // This will generate contentsChanged() event which is used to
       
    96         // set new height for the editor widget and content.
       
    97         if(attachmentHtml){
       
    98             QString htmlText = htmlPart->textContent() + attachmentHtml->textContent();
       
    99             emit setHtml(htmlText);
       
   100         } 
       
   101         else{
       
   102             emit setHtml(htmlPart->textContent());    
   104         }
   103         }
       
   104         mMessageBodyType = HTMLText;
   105     }
   105     }
   106 }
   106     else if (plainPart) {
       
   107         // Plain text part was present, set it to HbTextEdit
       
   108         emit setPlainText(plainPart->textContent());
       
   109         mMessageBodyType = PlainText;
       
   110     }
       
   111     
       
   112     // Original message text to editor content fiel
       
   113     if (replyMsgEnvelope && mEditorWidget) {          
       
   114         QTextCursor cursor = mEditorWidget->textCursor();
       
   115         cursor.setPosition(1);
       
   116         cursor.insertHtml(NmUtilities::createReplyHeader(*replyMsgEnvelope));
       
   117     }
       
   118 }  
   107 
   119 
   108 /*!
   120 /*!
   109    This method set new height for the editor content when header or body field
   121    This method set new height for the editor content when header or body field
   110    height has been changed.
   122    height has been changed.
   111  */
   123  */