emailuis/nmailui/src/nmeditorheader.cpp
changeset 54 997a02608b3a
parent 53 bf7eb7911fc5
child 59 16ed8d08d0b1
equal deleted inserted replaced
53:bf7eb7911fc5 54:997a02608b3a
    17 
    17 
    18 #include "nmuiheaders.h"
    18 #include "nmuiheaders.h"
    19 
    19 
    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 = "containerContents";
    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_CC_FIELD = "editorCcField";
    25 static const char *NMUI_EDITOR_CC_FIELD = "editorCcField";
    26 static const char *NMUI_EDITOR_BCC_FIELD = "editorBccField";
    26 static const char *NMUI_EDITOR_BCC_FIELD = "editorBccField";
    27 static const char *NMUI_EDITOR_PRIORITY_ICON = "editPriorityIcon";
    27 static const char *NMUI_EDITOR_PRIORITY_ICON = "editPriorityIcon";
    29 static const char *NMUI_EDITOR_ATTACHMENT_LIST = "attachmentListWidget";
    29 static const char *NMUI_EDITOR_ATTACHMENT_LIST = "attachmentListWidget";
    30 static const char *NMUI_EDITOR_PREFIX_TO = "editorTo";
    30 static const char *NMUI_EDITOR_PREFIX_TO = "editorTo";
    31 static const char *NMUI_EDITOR_PREFIX_CC = "editorCc";
    31 static const char *NMUI_EDITOR_PREFIX_CC = "editorCc";
    32 static const char *NMUI_EDITOR_PREFIX_BCC = "editorBcc";
    32 static const char *NMUI_EDITOR_PREFIX_BCC = "editorBcc";
    33 
    33 
    34 static const int MaxRows = 10000;
    34 static const int NmMaxRows = 10000;
    35 
    35 
    36 // this timeout seems to be long enough for all cases. see sendDelayedHeaderHeightChanged
    36 // this timeout seems to be long enough for all cases. see sendDelayedHeaderHeightChanged
    37 static const int LayoutSystemWaitTimer = 500; // 0.5 sec
    37 static const int NmLayoutSystemWaitTimer = 500; // 0.5 sec
    38 
    38 
    39 /*!
    39 /*!
    40     Constructor
    40     Constructor
    41 */
    41 */
    42 NmEditorHeader::NmEditorHeader(HbDocumentLoader *documentLoader) :
    42 NmEditorHeader::NmEditorHeader(QObject *parent, HbDocumentLoader *documentLoader) :
       
    43     QObject(parent),
    43     mDocumentLoader(documentLoader),
    44     mDocumentLoader(documentLoader),
    44     mHeaderHeight(0),
    45     mHeaderHeight(0),
    45     mIconVisible(false),
    46     mIconVisible(false),
    46     mSubjectEdit(NULL),
    47     mSubjectEdit(NULL),
    47     mRecipientFieldsEmpty(true),
    48     mRecipientFieldsEmpty(true),
    74 	
    75 	
    75     // Load widgets from docml and construct handlers. Those widgets that are not shown by default
    76     // Load widgets from docml and construct handlers. Those widgets that are not shown by default
    76     // are hidden and removed from the layout at this phase.    
    77     // are hidden and removed from the layout at this phase.    
    77     HbWidget *contentWidget =
    78     HbWidget *contentWidget =
    78         qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_CONTAINER));
    79         qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_CONTAINER));
    79     mLayout = static_cast<QGraphicsLinearLayout *>(contentWidget->layout());
    80     if (contentWidget) {
    80 
    81         mLayout = static_cast<QGraphicsLinearLayout *>(contentWidget->layout());
    81     // base class QObject takes the deleting responsibility
    82     
    82     mToField = new NmRecipientField(this, *mDocumentLoader, NMUI_EDITOR_PREFIX_TO);
    83         // base class QObject takes the deleting responsibility
    83     mCcField = new NmRecipientField(this, *mDocumentLoader, NMUI_EDITOR_PREFIX_CC);
    84         mToField = new NmRecipientField(this, *mDocumentLoader, NMUI_EDITOR_PREFIX_TO);
    84     mBccField = new NmRecipientField(this, *mDocumentLoader, NMUI_EDITOR_PREFIX_BCC);
    85         mCcField = new NmRecipientField(this, *mDocumentLoader, NMUI_EDITOR_PREFIX_CC);
    85 
    86         mBccField = new NmRecipientField(this, *mDocumentLoader, NMUI_EDITOR_PREFIX_BCC);
    86     // Cc field is not shown by default. It needs to be both hidden and removed from the layout.
    87     
    87 	mCcWidget = qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_CC_FIELD));
    88         // Sets up editor properties like no prediction, lower case preferred etc.
    88     mCcWidget->hide();
    89         HbEditorInterface toEditorInterface(mToField->editor());
    89     mLayout->removeItem(mCcWidget);
    90         HbEditorInterface ccEditorInterface(mCcField->editor());
    90     
    91         HbEditorInterface bccEditorInterface(mBccField->editor());
    91     // Bcc field is not shown by default. It needs to be both hidden and removed from the layout.
    92         toEditorInterface.setUpAsLatinAlphabetOnlyEditor();
    92     mBccWidget = qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_BCC_FIELD));
    93         ccEditorInterface.setUpAsLatinAlphabetOnlyEditor();
    93     mBccWidget->hide();
    94         bccEditorInterface.setUpAsLatinAlphabetOnlyEditor();
    94     mLayout->removeItem(mBccWidget);
    95 
    95 
    96         // Cc field is not shown by default. It needs to be both hidden and removed from the layout.
    96     mSubjectWidget =
    97         mCcWidget = qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_CC_FIELD));
    97         qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_FIELD));
    98         mCcWidget->hide();
    98     mSubjectLayout = static_cast<QGraphicsLinearLayout *>(mSubjectWidget->layout());
    99         mLayout->removeItem(mCcWidget);
    99     
   100           
   100     // Add Subject: field
   101         // Bcc field is not shown by default. It needs to be both hidden and removed from the layout.
   101     mSubjectEdit = qobject_cast<NmHtmlLineEdit *>
   102         mBccWidget = qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_BCC_FIELD));
   102         (mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_EDIT));
   103         mBccWidget->hide();
   103     mSubjectEdit->setMaxRows(MaxRows);
   104         mLayout->removeItem(mBccWidget);
   104 
   105     
   105     // Add attachment list
   106         mSubjectWidget =
   106     NmAttachmentListWidget *attachmentList = qobject_cast<NmAttachmentListWidget *>
   107             qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_FIELD));
   107         (mDocumentLoader->findWidget(NMUI_EDITOR_ATTACHMENT_LIST));
   108         mSubjectLayout = static_cast<QGraphicsLinearLayout *>(mSubjectWidget->layout());
   108     // Create attachment list handling object
   109           
   109     mAttachmentList = new NmAttachmentList(*attachmentList);
   110         // Add Subject: field
   110     mAttachmentList->setParent(this); // ownership changes
   111         mSubjectEdit = qobject_cast<NmHtmlLineEdit *>
   111     attachmentList->hide();
   112             (mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_EDIT));
   112     mLayout->removeItem(attachmentList);
   113         mSubjectEdit->setMaxRows(NmMaxRows);
   113 
   114     
   114     // Add priority icon
   115         // Add attachment list
   115     mPriorityIcon = qobject_cast<HbLabel *>
   116         NmAttachmentListWidget *attachmentList = qobject_cast<NmAttachmentListWidget *>
   116         (mDocumentLoader->findWidget(NMUI_EDITOR_PRIORITY_ICON));
   117             (mDocumentLoader->findWidget(NMUI_EDITOR_ATTACHMENT_LIST));
   117     mPriorityIcon->hide();
   118         // Create attachment list handling object
   118     mSubjectLayout->removeItem(mPriorityIcon);
   119         mAttachmentList = new NmAttachmentList(*attachmentList);
   119 
   120         mAttachmentList->setParent(this); // ownership changes
   120     // follow-up icon is not yet supported
   121         attachmentList->hide();
   121     HbLabel *followUpIcon = qobject_cast<HbLabel *>
   122         mLayout->removeItem(attachmentList);
   122         (mDocumentLoader->findWidget(NMUI_EDITOR_FOLLOWUP_ICON));
   123     
   123     followUpIcon->hide();
   124         // Add priority icon
   124     mSubjectLayout->removeItem(followUpIcon);
   125         mPriorityIcon = qobject_cast<HbLabel *>
       
   126             (mDocumentLoader->findWidget(NMUI_EDITOR_PRIORITY_ICON));
       
   127         mPriorityIcon->hide();
       
   128         mSubjectLayout->removeItem(mPriorityIcon);
       
   129     
       
   130         // follow-up icon is not yet supported
       
   131         HbLabel *followUpIcon = qobject_cast<HbLabel *>
       
   132             (mDocumentLoader->findWidget(NMUI_EDITOR_FOLLOWUP_ICON));
       
   133         followUpIcon->hide();
       
   134         mSubjectLayout->removeItem(followUpIcon);    
       
   135     }
   125 }
   136 }
   126 
   137 
   127 /*!
   138 /*!
   128     Create signal - slot connections.
   139     Create signal - slot connections.
   129 */
   140 */
   177         sendDelayedHeaderHeightChanged();
   188         sendDelayedHeaderHeightChanged();
   178 	}
   189 	}
   179 }
   190 }
   180 
   191 
   181 /*!
   192 /*!
   182     Return the height of the whole header widget.
   193     Return the sum of the header widget heights. This contains all the spacings a well. 
   183  */
   194  */
   184 qreal NmEditorHeader::headerHeight() const
   195 qreal NmEditorHeader::headerHeight() const
   185 {
   196 {
   186     NM_FUNCTION;
   197     NM_FUNCTION;
   187 
   198 
   223     information.
   234     information.
   224  */
   235  */
   225 void NmEditorHeader::sendDelayedHeaderHeightChanged()
   236 void NmEditorHeader::sendDelayedHeaderHeightChanged()
   226 {
   237 {
   227     NM_FUNCTION;
   238     NM_FUNCTION;
   228 	QTimer::singleShot(LayoutSystemWaitTimer, this, SLOT(sendHeaderHeightChanged()));
   239 	QTimer::singleShot(NmLayoutSystemWaitTimer, this, SLOT(sendHeaderHeightChanged()));
   229 }
   240 }
   230 
   241 
   231 /*!
   242 /*!
   232     Send a signal that the header area height has been changed if necessary. This is needed for the
   243     Send a signal that the header area height has been changed if necessary. This is needed for the
   233     body and scroll area widgets. See NmEditorTextEdit::setHeaderHeight for more info.
   244     body and scroll area widgets. See NmEditorTextEdit::setHeaderHeight for more info.
   287 */
   298 */
   288 void NmEditorHeader::editorContentChanged()
   299 void NmEditorHeader::editorContentChanged()
   289 {
   300 {
   290     NM_FUNCTION;
   301     NM_FUNCTION;
   291     
   302     
   292     bool recipientsFieldsEmpty = true;
   303     bool recipientsFieldsEmpty(true);
   293     if (mToField->text().length()) {
   304     if (mToField->text().length()) {
   294         recipientsFieldsEmpty = false;
   305         recipientsFieldsEmpty = false;
   295     }
   306     }
   296     else if (mCcField->text().length()) {
   307     else if (mCcField->text().length()) {
   297         recipientsFieldsEmpty = false;
   308         recipientsFieldsEmpty = false;
   378     if (!mAttachmentList->listWidget().isVisible()) {
   389     if (!mAttachmentList->listWidget().isVisible()) {
   379         // attachment list is inserted just before the body widget (see docml).
   390         // attachment list is inserted just before the body widget (see docml).
   380         mLayout->insertItem(mLayout->count() - 1, &mAttachmentList->listWidget());
   391         mLayout->insertItem(mLayout->count() - 1, &mAttachmentList->listWidget());
   381         mAttachmentList->listWidget().show();
   392         mAttachmentList->listWidget().show();
   382     }
   393     }
   383     sendDelayedHeaderHeightChanged();
   394     sendHeaderHeightChanged();
   384 }
   395 }
   385 
   396 
   386 /*!
   397 /*!
   387    Remove attachment from the list. This function is used when
   398    Remove attachment from the list. This function is used when
   388    attachment adding has failed and attachment id is not known.
   399    attachment adding has failed and attachment id is not known.
   437    Slot attachment activated from attachment list by short tap.
   448    Slot attachment activated from attachment list by short tap.
   438  */
   449  */
   439 void NmEditorHeader::attachmentActivated(int arrayIndex)
   450 void NmEditorHeader::attachmentActivated(int arrayIndex)
   440 {
   451 {
   441     NM_FUNCTION;
   452     NM_FUNCTION;
   442     
   453 
   443     //
       
   444     emit attachmentShortPressed(mAttachmentList->nmIdByIndex(arrayIndex));    
   454     emit attachmentShortPressed(mAttachmentList->nmIdByIndex(arrayIndex));    
   445 }
   455 }
   446 
   456 
   447 /*!
   457 /*!
   448    Slot attachment selected from attachment list by longtap.
   458    Slot attachment selected from attachment list by longtap.