emailuis/nmailui/src/nmeditorheader.cpp
changeset 51 d845db10c0d4
parent 48 10eaf342f539
child 56 15bc1d5d6267
equal deleted inserted replaced
49:00c7ae862740 51:d845db10c0d4
    20 // Layout
    20 // Layout
    21 // These match to the defintions in nmeditorview.docml
    21 // These match to the defintions in nmeditorview.docml
    22 static const char *NMUI_EDITOR_CONTAINER = "scrollAreaContents";
    22 static const char *NMUI_EDITOR_CONTAINER = "scrollAreaContents";
    23 static const char *NMUI_EDITOR_SUBJECT_FIELD = "editorSubjectField";
    23 static const char *NMUI_EDITOR_SUBJECT_FIELD = "editorSubjectField";
    24 static const char *NMUI_EDITOR_SUBJECT_EDIT = "editorSubjectEdit";
    24 static const char *NMUI_EDITOR_SUBJECT_EDIT = "editorSubjectEdit";
       
    25 static const char *NMUI_EDITOR_TO_FIELD = "editorToField";
    25 static const char *NMUI_EDITOR_CC_FIELD = "editorCcField";
    26 static const char *NMUI_EDITOR_CC_FIELD = "editorCcField";
    26 static const char *NMUI_EDITOR_BCC_FIELD = "editorBccField";
    27 static const char *NMUI_EDITOR_BCC_FIELD = "editorBccField";
    27 static const char *NMUI_EDITOR_PRIORITY_ICON = "editPriorityIcon";
    28 static const char *NMUI_EDITOR_PRIORITY_ICON = "editPriorityIcon";
    28 static const char *NMUI_EDITOR_FOLLOWUP_ICON = "editFollowUpIcon";
    29 static const char *NMUI_EDITOR_FOLLOWUP_ICON = "editFollowUpIcon";
    29 static const char *NMUI_EDITOR_ATTACHMENT_LIST = "attachmentListWidget";
    30 static const char *NMUI_EDITOR_ATTACHMENT_LIST = "attachmentListWidget";
    37 static const int NmLayoutSystemWaitTimer = 500; // 0.5 sec
    38 static const int NmLayoutSystemWaitTimer = 500; // 0.5 sec
    38 
    39 
    39 /*!
    40 /*!
    40     Constructor
    41     Constructor
    41 */
    42 */
    42 NmEditorHeader::NmEditorHeader(QObject *parent, HbDocumentLoader *documentLoader) :
    43 NmEditorHeader::NmEditorHeader(
       
    44     QObject *parent, NmApplication &application, HbDocumentLoader *documentLoader) :
    43     QObject(parent),
    45     QObject(parent),
       
    46     mApplication(application),
    44     mDocumentLoader(documentLoader),
    47     mDocumentLoader(documentLoader),
    45     mHeaderHeight(0),
    48     mHeaderHeight(0),
    46     mIconVisible(false),
    49     mIconVisible(false),
    47     mSubjectEdit(NULL),
    50     mSubjectEdit(NULL),
    48     mRecipientFieldsEmpty(true),
    51     mRecipientFieldsEmpty(true),
    91         HbEditorInterface bccEditorInterface(mBccField->editor());
    94         HbEditorInterface bccEditorInterface(mBccField->editor());
    92         toEditorInterface.setUpAsLatinAlphabetOnlyEditor();
    95         toEditorInterface.setUpAsLatinAlphabetOnlyEditor();
    93         ccEditorInterface.setUpAsLatinAlphabetOnlyEditor();
    96         ccEditorInterface.setUpAsLatinAlphabetOnlyEditor();
    94         bccEditorInterface.setUpAsLatinAlphabetOnlyEditor();
    97         bccEditorInterface.setUpAsLatinAlphabetOnlyEditor();
    95 
    98 
       
    99         mToWidget = qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_TO_FIELD));
       
   100         
    96         // Cc field is not shown by default. It needs to be both hidden and removed from the layout.
   101         // Cc field is not shown by default. It needs to be both hidden and removed from the layout.
    97         mCcWidget = qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_CC_FIELD));
   102         mCcWidget = qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_CC_FIELD));
    98         mCcWidget->hide();
   103         mCcWidget->hide();
    99         mLayout->removeItem(mCcWidget);
   104         mLayout->removeItem(mCcWidget);
   100           
   105           
   111         mSubjectEdit = qobject_cast<NmHtmlLineEdit *>
   116         mSubjectEdit = qobject_cast<NmHtmlLineEdit *>
   112             (mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_EDIT));
   117             (mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_EDIT));
   113         mSubjectEdit->setMaxRows(NmMaxRows);
   118         mSubjectEdit->setMaxRows(NmMaxRows);
   114     
   119     
   115         // Add attachment list
   120         // Add attachment list
   116         NmAttachmentListWidget *attachmentList = qobject_cast<NmAttachmentListWidget *>
   121         mAttachmentListWidget = qobject_cast<NmAttachmentListWidget *>
   117             (mDocumentLoader->findWidget(NMUI_EDITOR_ATTACHMENT_LIST));
   122             (mDocumentLoader->findWidget(NMUI_EDITOR_ATTACHMENT_LIST));
   118         // Create attachment list handling object
   123         // Create attachment list handling object
   119         mAttachmentList = new NmAttachmentList(*attachmentList);
   124         mAttachmentList = new NmAttachmentList(*mAttachmentListWidget);
   120         mAttachmentList->setParent(this); // ownership changes
   125         mAttachmentList->setParent(this); // ownership changes
   121         attachmentList->hide();
   126         mAttachmentListWidget->hide();
   122         mLayout->removeItem(attachmentList);
       
   123     
   127     
   124         // Add priority icon
   128         // Add priority icon
   125         mPriorityIcon = qobject_cast<HbLabel *>
   129         mPriorityIcon = qobject_cast<HbLabel *>
   126             (mDocumentLoader->findWidget(NMUI_EDITOR_PRIORITY_ICON));
   130             (mDocumentLoader->findWidget(NMUI_EDITOR_PRIORITY_ICON));
   127         mPriorityIcon->hide();
   131         mPriorityIcon->hide();
   248     qreal hHeight = headerHeight();
   252     qreal hHeight = headerHeight();
   249     if (mHeaderHeight != hHeight) {
   253     if (mHeaderHeight != hHeight) {
   250         mHeaderHeight = hHeight;
   254         mHeaderHeight = hHeight;
   251         emit headerHeightChanged(mHeaderHeight);
   255         emit headerHeightChanged(mHeaderHeight);
   252     }
   256     }
       
   257 }
       
   258 
       
   259 /*!
       
   260     Because header filds have fixed size policy. This function must be called to set
       
   261     new width for every header field when orintation has been changed.
       
   262  */
       
   263 void NmEditorHeader::adjustHeaderWidth()
       
   264 {
       
   265     NM_FUNCTION;
       
   266     
       
   267     int newWidth = mApplication.screenSize().width();
       
   268     mToWidget->setPreferredWidth(newWidth);
       
   269     mCcWidget->setPreferredWidth(newWidth);
       
   270     mBccWidget->setPreferredWidth(newWidth);
       
   271     mSubjectWidget->setPreferredWidth(newWidth);
       
   272     mAttachmentListWidget->setPreferredWidth(newWidth);
       
   273     mSubjectWidget->setPreferredWidth(newWidth);
   253 }
   274 }
   254 
   275 
   255 /*!
   276 /*!
   256     Return pointer to to edit
   277     Return pointer to to edit
   257  */
   278  */
   383 void NmEditorHeader::addAttachment(
   404 void NmEditorHeader::addAttachment(
   384     const QString &fileName, const QString &fileSize, const NmId &nmid)
   405     const QString &fileName, const QString &fileSize, const NmId &nmid)
   385 {
   406 {
   386     NM_FUNCTION;
   407     NM_FUNCTION;
   387     
   408     
       
   409     if (!mAttachmentList->listWidget().isVisible()) {
       
   410         mAttachmentList->listWidget().show();
       
   411     }
       
   412 
   388     mAttachmentList->insertAttachment(fileName, fileSize, nmid);
   413     mAttachmentList->insertAttachment(fileName, fileSize, nmid);
   389     if (!mAttachmentList->listWidget().isVisible()) {
       
   390         // attachment list is inserted just before the body widget (see docml).
       
   391         mLayout->insertItem(mLayout->count() - 1, &mAttachmentList->listWidget());
       
   392         mAttachmentList->listWidget().show();
       
   393     }
       
   394     sendHeaderHeightChanged();
   414     sendHeaderHeightChanged();
   395 }
   415 }
   396 
   416 
   397 /*!
   417 /*!
   398    Remove attachment from the list. This function is used when
   418    Remove attachment from the list. This function is used when
   462     NM_FUNCTION;
   482     NM_FUNCTION;
   463     
   483     
   464     // Remove selected attachment
   484     // Remove selected attachment
   465     emit attachmentLongPressed(mAttachmentList->nmIdByIndex(arrayIndex), point);
   485     emit attachmentLongPressed(mAttachmentList->nmIdByIndex(arrayIndex), point);
   466 }
   486 }
   467     
   487 
       
   488 /*!
       
   489     This slot is called when scroll position has been changed.
       
   490     Function set new positions for header fields so that header stays visible
       
   491     when body is scrolled horizontally.
       
   492  */
       
   493 void NmEditorHeader::repositHeader(const QPointF &scrollPosition)
       
   494 {
       
   495     NM_FUNCTION;
       
   496     
       
   497     QTransform tr;
       
   498     tr.translate(scrollPosition.x(),0);
       
   499     mToWidget->setTransform(tr);
       
   500     mCcWidget->setTransform(tr);
       
   501     mBccWidget->setTransform(tr);
       
   502     mSubjectWidget->setTransform(tr);
       
   503     mAttachmentListWidget->setTransform(tr);
       
   504 }
       
   505