emailuis/nmailui/src/nmeditorheader.cpp
changeset 74 6c59112cfd31
parent 66 084b5b1f02a7
equal deleted inserted replaced
69:4e54af54a4a1 74:6c59112cfd31
    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_SUBJECT_LABEL = "editorSubjectLabel";
    25 static const char *NMUI_EDITOR_TO_FIELD = "editorToField";
    26 static const char *NMUI_EDITOR_TO_FIELD = "editorToField";
    26 static const char *NMUI_EDITOR_CC_FIELD = "editorCcField";
    27 static const char *NMUI_EDITOR_CC_FIELD = "editorCcField";
    27 static const char *NMUI_EDITOR_BCC_FIELD = "editorBccField";
    28 static const char *NMUI_EDITOR_BCC_FIELD = "editorBccField";
    28 static const char *NMUI_EDITOR_PRIORITY_ICON = "editPriorityIcon";
    29 static const char *NMUI_EDITOR_PRIORITY_ICON = "editPriorityIcon";
    29 static const char *NMUI_EDITOR_FOLLOWUP_ICON = "editFollowUpIcon";
    30 static const char *NMUI_EDITOR_FOLLOWUP_ICON = "editFollowUpIcon";
    85     
    86     
    86         // base class QObject takes the deleting responsibility
    87         // base class QObject takes the deleting responsibility
    87         mToField = new NmRecipientField(this, *mDocumentLoader, NMUI_EDITOR_PREFIX_TO);
    88         mToField = new NmRecipientField(this, *mDocumentLoader, NMUI_EDITOR_PREFIX_TO);
    88         mCcField = new NmRecipientField(this, *mDocumentLoader, NMUI_EDITOR_PREFIX_CC);
    89         mCcField = new NmRecipientField(this, *mDocumentLoader, NMUI_EDITOR_PREFIX_CC);
    89         mBccField = new NmRecipientField(this, *mDocumentLoader, NMUI_EDITOR_PREFIX_BCC);
    90         mBccField = new NmRecipientField(this, *mDocumentLoader, NMUI_EDITOR_PREFIX_BCC);
       
    91         // Connection for adjusting recipient field labels. Connection done earlier than other connections
       
    92         // so that we don't miss signal.
       
    93         connect(mToField->editor(), SIGNAL(layoutChanged ()), this, SLOT(toFieldLayoutReady()));
    90     
    94     
    91         // Sets up editor properties like no prediction, lower case preferred etc.
    95         // Sets up editor properties like no prediction, lower case preferred etc.
    92         HbEditorInterface toEditorInterface(mToField->editor());
    96         HbEditorInterface toEditorInterface(mToField->editor());
    93         HbEditorInterface ccEditorInterface(mCcField->editor());
    97         HbEditorInterface ccEditorInterface(mCcField->editor());
    94         HbEditorInterface bccEditorInterface(mBccField->editor());
    98         HbEditorInterface bccEditorInterface(mBccField->editor());
   109         mLayout->removeItem(mBccWidget);
   113         mLayout->removeItem(mBccWidget);
   110     
   114     
   111         mSubjectWidget =
   115         mSubjectWidget =
   112             qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_FIELD));
   116             qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_FIELD));
   113         mSubjectLayout = static_cast<QGraphicsLinearLayout *>(mSubjectWidget->layout());
   117         mSubjectLayout = static_cast<QGraphicsLinearLayout *>(mSubjectWidget->layout());
       
   118         mSubjectLabel =
       
   119             qobject_cast<HbLabel *>(mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_LABEL));
   114           
   120           
   115         // Add Subject: field
   121         // Add Subject: field
   116         mSubjectEdit = qobject_cast<NmHtmlLineEdit *>
   122         mSubjectEdit = qobject_cast<NmHtmlLineEdit *>
   117             (mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_EDIT));
   123             (mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_EDIT));
   118         mSubjectEdit->setMaxRows(NmMaxRows);
   124         mSubjectEdit->setMaxRows(NmMaxRows);
   503     mBccWidget->setTransform(transform);
   509     mBccWidget->setTransform(transform);
   504     mSubjectWidget->setTransform(transform);
   510     mSubjectWidget->setTransform(transform);
   505     mAttachmentListWidget->setTransform(transform);
   511     mAttachmentListWidget->setTransform(transform);
   506 }
   512 }
   507 
   513 
       
   514 /*!
       
   515    This slot will set the geometry, margin and font for the To,Cc,Bcc and Subject
       
   516    labels located inside the edit fields. These adjustments are done to fix label text
       
   517    position so that it is in same lavel than first line of the edit widget.
       
   518    Slot is called once when 'To' field layout is ready after editor startup.
       
   519    Because all fields are similar it is enough to use only 'To' field information
       
   520    to adjust all header fields.
       
   521 */
       
   522 void NmEditorHeader::toFieldLayoutReady()
       
   523 {
       
   524     NM_FUNCTION;
       
   525     
       
   526     // Set same font for label and edit.
       
   527     QFont editorFont = mToField->editor()->font();
       
   528     mToField->label()->setFont(editorFont);
       
   529     mCcField->label()->setFont(editorFont);
       
   530     mBccField->label()->setFont(editorFont);
       
   531     mSubjectLabel->setFont(editorFont);
       
   532 
       
   533     // Set same height for label and edit.
       
   534     qreal editorWidgetHeight = mToField->editor()->geometry().height();
       
   535     mToField->label()->setPreferredHeight(editorWidgetHeight);
       
   536     mCcField->label()->setPreferredHeight(editorWidgetHeight);
       
   537     mBccField->label()->setPreferredHeight(editorWidgetHeight);
       
   538     mSubjectLabel->setPreferredHeight(editorWidgetHeight);
       
   539     
       
   540     // Set left margin for labels.
       
   541     qreal leftMargin;
       
   542     mToField->editor()->layout()->getContentsMargins(&leftMargin, 0, 0, 0);
       
   543     mToField->label()->setContentsMargins(leftMargin, 0, 0, 0);
       
   544     mCcField->label()->setContentsMargins(leftMargin, 0, 0, 0);
       
   545     mBccField->label()->setContentsMargins(leftMargin, 0, 0, 0);
       
   546     mSubjectLabel->setContentsMargins(leftMargin, 0, 0, 0);
       
   547     
       
   548     adjustIndentForEditFields();
       
   549 }
       
   550 
       
   551 /*!
       
   552    Set the length of the label and the indention of the edit fields (To,Cc,Bcc,Subject) so
       
   553    that there is enough space for the label field.
       
   554 */
       
   555 void NmEditorHeader::adjustIndentForEditFields()
       
   556 {
       
   557     NM_FUNCTION;
       
   558 
       
   559     // Get spacing between label and edit.
       
   560     qreal spacingBetweenLabelAndEdit = 0;
       
   561     HbStyle().parameter("hb-param-margin-gene-middle-horizontal", spacingBetweenLabelAndEdit);
       
   562     // Add more space for label right margin. Without this, last letter ':' of the label is not
       
   563     // fit into field.
       
   564     spacingBetweenLabelAndEdit *= 2;
       
   565     
       
   566     // Get font metrics (We assume that every label has same font).
       
   567     QFontMetrics fm(mToField->label()->font());
       
   568     
       
   569     // Set length of the label widgets based on the string width.
       
   570     // Also set indent for the first line of the edit widget.
       
   571     qreal textWidth = 0;
       
   572     textWidth = fm.width(mToField->label()->plainText()) + spacingBetweenLabelAndEdit;
       
   573     mToField->label()->setPreferredWidth(textWidth);    
       
   574     mToField->editor()->setIndentForLabel(textWidth);    
       
   575     
       
   576     textWidth = fm.width(mCcField->label()->plainText()) + spacingBetweenLabelAndEdit;
       
   577     mCcField->label()->setPreferredWidth(textWidth);
       
   578     mCcField->editor()->setIndentForLabel(textWidth);
       
   579 
       
   580     textWidth = fm.width(mBccField->label()->plainText()) + spacingBetweenLabelAndEdit;
       
   581     mBccField->label()->setPreferredWidth(textWidth);
       
   582     mBccField->editor()->setIndentForLabel(textWidth);
       
   583     
       
   584     textWidth = fm.width(mSubjectLabel->plainText()) + spacingBetweenLabelAndEdit;
       
   585     mSubjectLabel->setPreferredWidth(textWidth);
       
   586     mSubjectEdit->setIndentForLabel(textWidth);
       
   587 }