emailuis/nmailui/src/nmeditorheader.cpp
changeset 43 99bcbff212ad
parent 40 2c62ef3caffd
child 44 c2d07d913565
equal deleted inserted replaced
42:139d4b7b2938 43:99bcbff212ad
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description: Message editor header widget
    14 * Description: Message editor header container class. Collects the header widgets.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "nmuiheaders.h"
    18 #include "nmuiheaders.h"
    19 
    19 
    20 // Layout
    20 // Layout
    21 static const char *NMUI_EDITOR_RECIPIENT_FIELDS = "RecipientFields";
    21 // These match to the defintions in nmeditorview.docml
    22 static const char *NMUI_EDITOR_SUBJECT_LABEL = "EditorHeaderSubjectLabel";
    22 static const char *NMUI_EDITOR_CONTAINER = "containerContents";
    23 static const char *NMUI_EDITOR_SUBJECT_EDIT = "EditorHeaderSubjectEdit";
    23 static const char *NMUI_EDITOR_SUBJECT_FIELD = "editorSubjectField";
    24 static const char *NMUI_EDITOR_PRIORITY_ICON = "labelPriorityIcon";
    24 static const char *NMUI_EDITOR_SUBJECT_EDIT = "editorSubjectEdit";
       
    25 static const char *NMUI_EDITOR_CC_FIELD = "editorCcField";
       
    26 static const char *NMUI_EDITOR_BCC_FIELD = "editorBccField";
       
    27 static const char *NMUI_EDITOR_PRIORITY_ICON = "editPriorityIcon";
       
    28 static const char *NMUI_EDITOR_FOLLOWUP_ICON = "editFollowUpIcon";
    25 static const char *NMUI_EDITOR_ATTACHMENT_LIST = "attachmentListWidget";
    29 static const char *NMUI_EDITOR_ATTACHMENT_LIST = "attachmentListWidget";
    26 
    30 static const char *NMUI_EDITOR_PREFIX_TO = "editorTo";
    27 // Following constants are removed when header fields will offer these
    31 static const char *NMUI_EDITOR_PREFIX_CC = "editorCc";
    28 static const double Un = 6.66;
    32 static const char *NMUI_EDITOR_PREFIX_BCC = "editorBcc";
    29 static const double FieldHeightWhenSecondaryFont = 5 * Un;
    33 
    30 static const double Margin = 2 * Un;
    34 static const int MaxRows = 10000;
    31 static const double IconFieldWidth = 5 * Un;
       
    32 
    35 
    33 static const int nmLayoutSystemWaitTimer = 10;
    36 static const int nmLayoutSystemWaitTimer = 10;
    34 
    37 
    35 /*!
    38 /*!
    36     Constructor
    39     Constructor
    37 */
    40 */
    38 NmEditorHeader::NmEditorHeader(HbDocumentLoader *documentLoader, QGraphicsItem *parent) :
    41 NmEditorHeader::NmEditorHeader(HbDocumentLoader *documentLoader) :
    39     HbWidget(parent),
       
    40     mDocumentLoader(documentLoader),
    42     mDocumentLoader(documentLoader),
    41     mHeaderHeight(0),
    43     mHeaderHeight(0),
    42     mSubjectLabel(NULL),
       
    43     mIconVisible(false),
    44     mIconVisible(false),
    44     mSubjectEdit(NULL),
    45     mSubjectEdit(NULL),
    45     mRecipientFieldsEmpty(true),
    46     mRecipientFieldsEmpty(true),
    46     mAttachmentList(NULL),
    47     mAttachmentList(NULL),
    47     mToField(NULL),
    48     mToField(NULL),
    48     mCcField(NULL),
    49     mCcField(NULL),
    49     mBccField(NULL),
    50     mBccField(NULL),
    50     mCcBccFieldVisible(false)
    51     mCcBccFieldVisible(false)
    51 {
    52 {
       
    53     NM_FUNCTION;
       
    54     
    52     loadWidgets();
    55     loadWidgets();
    53     rescaleHeader();
       
    54     createConnections();
    56     createConnections();
    55 }
    57 }
    56 
    58 
    57 /*!
    59 /*!
    58     Destructor
    60     Destructor
    59 */
    61 */
    60 NmEditorHeader::~NmEditorHeader()
    62 NmEditorHeader::~NmEditorHeader()
    61 {
    63 {
    62     if (mAttachmentList) {
    64     NM_FUNCTION;
    63         mAttachmentList->clearList();
       
    64         delete mAttachmentList;
       
    65     }
       
    66 }
    65 }
    67 
    66 
    68 /*!
    67 /*!
    69     Load widgets from XML for the header.
    68     Load widgets from XML for the header.
    70 */
    69 */
    71 void NmEditorHeader::loadWidgets()
    70 void NmEditorHeader::loadWidgets()
    72 {
    71 {
    73 	// Add "To:", "CC:" and "BCC:" fields
    72     NM_FUNCTION;
    74 	mHeader = qobject_cast<HbWidget *>
    73 	
    75 	        (mDocumentLoader->findWidget(NMUI_EDITOR_RECIPIENT_FIELDS));
    74     // Load widgets from docml and construct handlers. Those widgets that are not shown by default
    76 
    75     // are hidden and removed from the layout at this phase.    
    77 	mLayout = new QGraphicsLinearLayout(Qt::Vertical);
    76     HbWidget *contentWidget =
    78 	mLayout->setContentsMargins(0,Un,0,0);
    77         qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_CONTAINER));
    79 
    78     mLayout = static_cast<QGraphicsLinearLayout *>(contentWidget->layout());
    80 	mToField = new NmRecipientField(QString("To:"), mHeader);
    79 
    81 	mCcField = new NmRecipientField(QString("Cc:"), mHeader);
    80     // base class QObject takes the deleting responsibility
    82 	mBccField = new NmRecipientField(QString("Bcc:"), mHeader);
    81     mToField = new NmRecipientField(this, *mDocumentLoader, NMUI_EDITOR_PREFIX_TO);
    83 
    82     mCcField = new NmRecipientField(this, *mDocumentLoader, NMUI_EDITOR_PREFIX_CC);
    84     // Only 'To:' field is visible at startup
    83     mBccField = new NmRecipientField(this, *mDocumentLoader, NMUI_EDITOR_PREFIX_BCC);
    85 	mLayout->addItem(mToField);
    84 
    86 	mCcField->hide();
    85     // Cc field is not shown by default. It needs to be both hidden and removed from the layout.
    87 	mBccField->hide();
    86 	mCcWidget = qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_CC_FIELD));
    88 
    87     mCcWidget->hide();
    89 	mHeader->setLayout(mLayout);
    88     mLayout->removeItem(mCcWidget);
    90 	mHeader->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
    89     
    91 
    90     // Bcc field is not shown by default. It needs to be both hidden and removed from the layout.
       
    91     mBccWidget = qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_BCC_FIELD));
       
    92     mBccWidget->hide();
       
    93     mLayout->removeItem(mBccWidget);
       
    94 
       
    95     mSubjectWidget =
       
    96         qobject_cast<HbWidget *>(mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_FIELD));
       
    97     mSubjectLayout = static_cast<QGraphicsLinearLayout *>(mSubjectWidget->layout());
       
    98     
    92     // Add Subject: field
    99     // Add Subject: field
    93     mSubjectLabel = qobject_cast<HbLabel *>
       
    94         (mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_LABEL));
       
    95     mSubjectEdit = qobject_cast<NmHtmlLineEdit *>
   100     mSubjectEdit = qobject_cast<NmHtmlLineEdit *>
    96         (mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_EDIT));
   101         (mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_EDIT));
       
   102     mSubjectEdit->setMaxRows(MaxRows);
    97 
   103 
    98     // Add attachment list
   104     // Add attachment list
    99     NmAttachmentListWidget *attachmentList = qobject_cast<NmAttachmentListWidget *>
   105     NmAttachmentListWidget *attachmentList = qobject_cast<NmAttachmentListWidget *>
   100         (mDocumentLoader->findWidget(NMUI_EDITOR_ATTACHMENT_LIST));
   106         (mDocumentLoader->findWidget(NMUI_EDITOR_ATTACHMENT_LIST));
   101     // Create attachment list handling object
   107     // Create attachment list handling object
   102     mAttachmentList = new NmAttachmentList(*attachmentList);
   108     mAttachmentList = new NmAttachmentList(*attachmentList);
   103 
   109     mAttachmentList->setParent(this); // ownership changes
   104     mPriorityIconLabel = qobject_cast<HbLabel *>
   110     attachmentList->hide();
       
   111     mLayout->removeItem(attachmentList);
       
   112 
       
   113     // Add priority icon
       
   114     mPriorityIcon = qobject_cast<HbLabel *>
   105         (mDocumentLoader->findWidget(NMUI_EDITOR_PRIORITY_ICON));
   115         (mDocumentLoader->findWidget(NMUI_EDITOR_PRIORITY_ICON));
       
   116     mPriorityIcon->hide();
       
   117     mSubjectLayout->removeItem(mPriorityIcon);
       
   118 
       
   119     // follow-up icon is not yet supported
       
   120     HbLabel *followUpIcon = qobject_cast<HbLabel *>
       
   121         (mDocumentLoader->findWidget(NMUI_EDITOR_FOLLOWUP_ICON));
       
   122     followUpIcon->hide();
       
   123     mSubjectLayout->removeItem(followUpIcon);
   106 }
   124 }
   107 
   125 
   108 /*!
   126 /*!
   109     Create signal - slot connections.
   127     Create signal - slot connections.
   110 */
   128 */
   111 void NmEditorHeader::createConnections()
   129 void NmEditorHeader::createConnections()
   112 {
   130 {
       
   131     NM_FUNCTION;
       
   132     
   113     // Signals for checking if the recipient fields have text.
   133     // Signals for checking if the recipient fields have text.
   114     connect(mToField, SIGNAL(textChanged(const QString &)),
   134     connect(mToField, SIGNAL(textChanged(const QString &)),
   115             this, SLOT(editorContentChanged()));
   135             this, SLOT(editorContentChanged()));
   116     connect(mCcField, SIGNAL(textChanged(const QString &)),
   136     connect(mCcField, SIGNAL(textChanged(const QString &)),
   117             this, SLOT(editorContentChanged()));
   137             this, SLOT(editorContentChanged()));
   118     connect(mBccField, SIGNAL(textChanged(const QString &)),
   138     connect(mBccField, SIGNAL(textChanged(const QString &)),
   119             this, SLOT(editorContentChanged()));
   139             this, SLOT(editorContentChanged()));
   120 
   140 
   121     // Signals for handling the recipient field expanding
   141     // Signals for handling the recipient field expanding
   122     connect(mToField, SIGNAL(textChanged(const QString &)),
   142     connect(mToField, SIGNAL(textChanged(const QString &)),
   123             this, SLOT(fixHeaderFieldHeights()));
   143             this, SLOT(sendDelayedHeaderHeightChanged()));
   124     connect(mCcField, SIGNAL(textChanged(const QString &)),
   144     connect(mCcField, SIGNAL(textChanged(const QString &)),
   125             this, SLOT(fixHeaderFieldHeights()));
   145             this, SLOT(sendDelayedHeaderHeightChanged()));
   126     connect(mBccField, SIGNAL(textChanged(const QString &)),
   146     connect(mBccField, SIGNAL(textChanged(const QString &)),
   127             this, SLOT(fixHeaderFieldHeights()));
   147             this, SLOT(sendDelayedHeaderHeightChanged()));
   128     connect(mSubjectEdit, SIGNAL(contentsChanged()), this, SLOT(fixHeaderFieldHeights()));
   148     connect(mSubjectEdit, SIGNAL(contentsChanged()), this, SLOT(sendDelayedHeaderHeightChanged()));
   129 
   149 
   130     // Signals for handling the attachment list
   150     // Signals for handling the attachment list
   131     connect(&mAttachmentList->listWidget(), SIGNAL(itemActivated(int)),
   151     connect(&mAttachmentList->listWidget(), SIGNAL(itemActivated(int)),
   132             this, SLOT(attachmentActivated(int)));
   152             this, SLOT(attachmentActivated(int)));
   133     connect(&mAttachmentList->listWidget(), SIGNAL(longPressed(int, QPointF)),
   153     connect(&mAttachmentList->listWidget(), SIGNAL(longPressed(int, QPointF)),
   142 void NmEditorHeader::setFieldVisibility(bool isVisible)
   162 void NmEditorHeader::setFieldVisibility(bool isVisible)
   143 {
   163 {
   144 	if ( mCcBccFieldVisible != isVisible ) {
   164 	if ( mCcBccFieldVisible != isVisible ) {
   145 		mCcBccFieldVisible = isVisible;
   165 		mCcBccFieldVisible = isVisible;
   146 		if (mCcBccFieldVisible) {
   166 		if (mCcBccFieldVisible) {
   147 			mCcField->show();
   167             mLayout->insertItem(1, mBccWidget);
   148 			mBccField->show();
   168 			mLayout->insertItem(1, mCcWidget);
   149 			mLayout->addItem(mCcField);
   169 			mCcWidget->show();
   150 			mLayout->addItem(mBccField);
   170             mBccWidget->show();
   151 		}
   171 		}
   152 		else {
   172 		else {
   153 			mCcField->hide();
   173             mCcWidget->hide();
   154 			mBccField->hide();
   174             mBccWidget->hide();
   155 			mLayout->removeItem(mCcField);
   175 			mLayout->removeItem(mCcWidget);
   156 			mLayout->removeItem(mBccField);
   176 			mLayout->removeItem(mBccWidget);
   157 		}
   177 		}
   158 
   178 
   159 		QTimer::singleShot(nmLayoutSystemWaitTimer*2, this, SLOT(fixHeaderFieldHeights()));
   179 		QTimer::singleShot(
       
   180 		    nmLayoutSystemWaitTimer * 2, this, SLOT(sendDelayedHeaderHeightChanged()));
   160 	}
   181 	}
   161 }
   182 }
   162 
   183 
   163 /*!
   184 /*!
   164     Function can be used to rescale the header area.
       
   165 */
       
   166 void NmEditorHeader::rescaleHeader()
       
   167 {
       
   168 }
       
   169 
       
   170 /*!
       
   171     Return the height of the whole header widget.
   185     Return the height of the whole header widget.
   172     (Should find beter way to get the height of the header area.)
   186  */
   173  */
   187 qreal NmEditorHeader::headerHeight() const
   174 int NmEditorHeader::headerHeight() const
   188 {
   175 {
   189     NM_FUNCTION;
   176     qreal toHeight = mToField->height();
   190 
   177     qreal ccHeight = 0;
   191     // get the layout's vertical spacing
   178     qreal bccHeight = 0;
   192     qreal spacing = 0;
       
   193     HbStyle().parameter("hb-param-margin-gene-middle-vertical", spacing);
       
   194 
       
   195     // calculate the height
       
   196     qreal height = 0;
       
   197     
       
   198     height += mToField->height(); // returns widget's geometry height
       
   199     height += spacing;
       
   200     
   179     if (mCcBccFieldVisible) {
   201     if (mCcBccFieldVisible) {
   180 		ccHeight = mCcField->height();
   202         height += mCcField->height(); // returns widget's geometry height
   181 		bccHeight = mBccField->height();
   203         height += spacing;
   182     }
   204         
   183     qreal subjectHeight = mSubjectEdit->geometry().height() + Margin;
   205         height += mBccField->height(); // returns widget's geometry height
   184 
   206         height += spacing;
   185     // When called first time, height is wrongly 'Margin'
   207     }
   186     if (toHeight == Margin) {
   208 
   187         toHeight = FieldHeightWhenSecondaryFont;
   209     height += mSubjectWidget->geometry().height();
   188     	ccHeight = FieldHeightWhenSecondaryFont;
   210     height += spacing;
   189     	bccHeight = FieldHeightWhenSecondaryFont;
   211 
   190         subjectHeight = FieldHeightWhenSecondaryFont;
   212     if (mAttachmentList->listWidget().isVisible()) {
   191     }
   213         height += mAttachmentList->listWidget().geometry().height();
   192 
   214         height += spacing;
   193     qreal attHeight = 0;
   215     }
   194     if (mAttachmentList && mAttachmentList->count() > 0) {
   216 
   195         attHeight = mAttachmentList->listWidget().geometry().height();
   217     return height;
   196     }
       
   197 
       
   198     return (int)(toHeight + ccHeight + bccHeight + subjectHeight + attHeight);
       
   199 }
   218 }
   200 
   219 
   201 /*!
   220 /*!
   202     Send signal to inform that one of the recipient fields height has been changed.
   221     Send signal to inform that one of the recipient fields height has been changed.
   203  */
   222  */
   204 void NmEditorHeader::fixHeaderFieldHeights()
   223 void NmEditorHeader::sendDelayedHeaderHeightChanged()
   205 {
   224 {
   206     // Adjust height of recipient fields 
   225     NM_FUNCTION;
   207 	adjustFieldSizeValues(mToField->editor(), mToField->editor()->document()->size().height());
   226 	QTimer::singleShot(nmLayoutSystemWaitTimer * 5, this, SLOT(sendHeaderHeightChanged()));
   208 	adjustFieldSizeValues(mCcField->editor(), mCcField->editor()->document()->size().height());
       
   209 	adjustFieldSizeValues(mBccField->editor(), mBccField->editor()->document()->size().height());
       
   210 
       
   211     // Adjust height of the subject field 
       
   212 	if (mSubjectEdit->document()->size().height() > FieldHeightWhenSecondaryFont) {
       
   213 	mSubjectEdit->setPreferredHeight(
       
   214 			mSubjectEdit->document()->size().height() + Margin );
       
   215 	}
       
   216 	else {
       
   217 		mSubjectEdit->setPreferredHeight( FieldHeightWhenSecondaryFont );
       
   218 	}
       
   219 
       
   220 	QTimer::singleShot(nmLayoutSystemWaitTimer*5, this, SLOT(sendHeaderHeightChanged()));	
       
   221 }
       
   222 
       
   223 
       
   224 /*!
       
   225     Private routine to adjust heights of the recipient fields
       
   226  */
       
   227 void NmEditorHeader::adjustFieldSizeValues( NmRecipientLineEdit *widget, qreal height )
       
   228 {
       
   229 	if (height > FieldHeightWhenSecondaryFont) {
       
   230 		widget->setMaximumHeight( height + Margin );
       
   231 		widget->setMinimumHeight( height + Margin );
       
   232 	}
       
   233 	else {
       
   234 		widget->setMaximumHeight( FieldHeightWhenSecondaryFont );	
       
   235 		widget->setMinimumHeight( FieldHeightWhenSecondaryFont );	
       
   236 	}	
       
   237 }
   227 }
   238 
   228 
   239 /*!
   229 /*!
   240     Send signal to inform that one of the recipient fields height has been changed.
   230     Send signal to inform that one of the recipient fields height has been changed.
   241  */
   231  */
   242 void NmEditorHeader::sendHeaderHeightChanged()
   232 void NmEditorHeader::sendHeaderHeightChanged()
   243 {
   233 {
   244     int hHeight = headerHeight();
   234     qreal hHeight = headerHeight();
   245     if (mHeaderHeight != hHeight) {
   235     if (mHeaderHeight != hHeight) {
   246         mHeaderHeight = hHeight;
   236         mHeaderHeight = hHeight;
   247         emit headerHeightChanged(mHeaderHeight);
   237         emit headerHeightChanged(mHeaderHeight);
   248     }
   238     }
   249 }
   239 }
   251 /*!
   241 /*!
   252     Return pointer to to edit
   242     Return pointer to to edit
   253  */
   243  */
   254 NmRecipientLineEdit* NmEditorHeader::toEdit() const
   244 NmRecipientLineEdit* NmEditorHeader::toEdit() const
   255 {
   245 {
       
   246     NM_FUNCTION;
       
   247     
   256     return mToField->editor();
   248     return mToField->editor();
   257 }
   249 }
   258 
   250 
   259 /*!
   251 /*!
   260     Return pointer to cc edit
   252     Return pointer to cc edit
   261  */
   253  */
   262 NmRecipientLineEdit* NmEditorHeader::ccEdit() const
   254 NmRecipientLineEdit* NmEditorHeader::ccEdit() const
   263 {
   255 {
       
   256     NM_FUNCTION;
       
   257     
   264     return mCcField->editor();
   258     return mCcField->editor();
   265 }
   259 }
   266 
   260 
   267 /*!
   261 /*!
   268     Return pointer to bcc edit
   262     Return pointer to bcc edit
   269  */
   263  */
   270 NmRecipientLineEdit* NmEditorHeader::bccEdit() const
   264 NmRecipientLineEdit* NmEditorHeader::bccEdit() const
   271 {
   265 {
       
   266     NM_FUNCTION;
       
   267     
   272     return mBccField->editor();
   268     return mBccField->editor();
   273 }
   269 }
   274 
   270 
   275 /*!
   271 /*!
   276     Return pointer to subject field
   272     Return pointer to subject field
   277  */
   273  */
   278 NmHtmlLineEdit* NmEditorHeader::subjectEdit() const
   274 NmHtmlLineEdit* NmEditorHeader::subjectEdit() const
   279 {
   275 {
       
   276     NM_FUNCTION;
       
   277     
   280     return mSubjectEdit;
   278     return mSubjectEdit;
   281 }
   279 }
   282 
   280 
   283 /*!
   281 /*!
   284     Checks if recipient editors are empty and emits a signal if
   282     Checks if recipient editors are empty and emits a signal if
   285     the state is changed.
   283     the state is changed.
   286 */
   284 */
   287 void NmEditorHeader::editorContentChanged()
   285 void NmEditorHeader::editorContentChanged()
   288 {
   286 {
       
   287     NM_FUNCTION;
       
   288     
   289     bool recipientsFieldsEmpty = true;
   289     bool recipientsFieldsEmpty = true;
   290     if (mToField->text().length()) {
   290     if (mToField->text().length()) {
   291         recipientsFieldsEmpty = false;
   291         recipientsFieldsEmpty = false;
   292     }
   292     }
   293     else if (mCcField->text().length()) {
   293     else if (mCcField->text().length()) {
   305 /*!
   305 /*!
   306     Sets the icon for priority
   306     Sets the icon for priority
   307  */
   307  */
   308 void NmEditorHeader::setPriority(NmMessagePriority priority)
   308 void NmEditorHeader::setPriority(NmMessagePriority priority)
   309 {
   309 {
       
   310     NM_FUNCTION;
       
   311     
   310     switch (priority) {
   312     switch (priority) {
   311     case NmMessagePriorityHigh:
   313     case NmMessagePriorityHigh:
   312         setPriority(NmActionResponseCommandPriorityHigh);
   314         setPriority(NmActionResponseCommandPriorityHigh);
   313         break;
   315         break;
   314     case NmMessagePriorityLow:
   316     case NmMessagePriorityLow:
   323 /*!
   325 /*!
   324     Sets the icon for priority
   326     Sets the icon for priority
   325  */
   327  */
   326 void NmEditorHeader::setPriority(NmActionResponseCommand prio)
   328 void NmEditorHeader::setPriority(NmActionResponseCommand prio)
   327 {
   329 {
       
   330     NM_FUNCTION;
       
   331     
   328     switch(prio) {
   332     switch(prio) {
   329     case NmActionResponseCommandPriorityHigh:
   333     case NmActionResponseCommandPriorityHigh:
   330         if (!mIconVisible) {
   334         if (!mIconVisible) {
   331             mIconVisible = true;
   335             mIconVisible = true;
   332             mPriorityIconLabel->setMaximumWidth(IconFieldWidth);
   336             // icon widget is just after the subject line edit (see docml)
   333             mSubjectEdit->setMaximumWidth(mSubjectEdit->geometry().width() - IconFieldWidth);
   337             mSubjectLayout->insertItem(2, mPriorityIcon);
       
   338             mPriorityIcon->show();
   334         }
   339         }
   335         mPriorityIconLabel->setIcon(
   340         mPriorityIcon->setIcon(
   336             NmIcons::getIcon(NmIcons::NmIconPriorityHigh));
   341             NmIcons::getIcon(NmIcons::NmIconPriorityHigh));
   337         break;
   342         break;
   338     case NmActionResponseCommandPriorityLow:
   343     case NmActionResponseCommandPriorityLow:
   339         if (!mIconVisible) {
   344         if (!mIconVisible) {
   340             mIconVisible = true;
   345             mIconVisible = true;
   341             mPriorityIconLabel->setMaximumWidth(IconFieldWidth);
   346             // icon widget is just after the subject line edit (see docml)
   342             mSubjectEdit->setMaximumWidth(mSubjectEdit->geometry().width() - IconFieldWidth);
   347             mSubjectLayout->insertItem(2, mPriorityIcon);
       
   348             mPriorityIcon->show();
   343         }
   349         }
   344         mPriorityIconLabel->setIcon(
   350         mPriorityIcon->setIcon(
   345             NmIcons::getIcon(NmIcons::NmIconPriorityLow));
   351             NmIcons::getIcon(NmIcons::NmIconPriorityLow));
   346         break;
   352         break;
   347     default:
   353     default:
   348         if (mIconVisible) {
   354         if (mIconVisible) {
   349             mIconVisible = false;
   355             mIconVisible = false;
   350             HbIcon emptyIcon;
   356             HbIcon emptyIcon;
   351             mPriorityIconLabel->setIcon(emptyIcon);
   357             mPriorityIcon->setIcon(emptyIcon);
   352             mPriorityIconLabel->setMaximumWidth(0);
   358             mSubjectLayout->removeItem(mPriorityIcon);
   353             mSubjectEdit->setMaximumWidth(mSubjectEdit->geometry().width() + IconFieldWidth);
   359             mPriorityIcon->hide();
   354         }
   360         }
   355         break;
   361         break;
   356     }
   362     }
   357     // Update subject field height because row amount might have been changed.
   363     // Update subject field height because row amount might have been changed.
   358     QTimer::singleShot(nmLayoutSystemWaitTimer * 3, this, SLOT(fixHeaderFieldHeights()));
   364     QTimer::singleShot(nmLayoutSystemWaitTimer * 3, this, SLOT(sendDelayedHeaderHeightChanged()));
   359 }
   365 }
   360 
   366 
   361 /*!
   367 /*!
   362    Adds an attachment to attachment list for mail.
   368    Adds an attachment to attachment list for mail.
   363  */
   369  */
   364 void NmEditorHeader::addAttachment(
   370 void NmEditorHeader::addAttachment(
   365     const QString &fileName, const QString &fileSize, const NmId &nmid)
   371     const QString &fileName, const QString &fileSize, const NmId &nmid)
   366 {
   372 {
       
   373     NM_FUNCTION;
       
   374     
   367     mAttachmentList->insertAttachment(fileName, fileSize, nmid);
   375     mAttachmentList->insertAttachment(fileName, fileSize, nmid);
       
   376     if (!mAttachmentList->listWidget().isVisible()) {
       
   377         // attachment list is inserted just before the body widget (see docml).
       
   378         mLayout->insertItem(mLayout->count() - 1, &mAttachmentList->listWidget());
       
   379         mAttachmentList->listWidget().show();
       
   380     }
   368     sendHeaderHeightChanged();
   381     sendHeaderHeightChanged();
   369 }
   382 }
   370 
   383 
   371 /*!
   384 /*!
   372    Remove attachment from the list. This function is used when
   385    Remove attachment from the list. This function is used when
   373    attachment adding has failed and attachment id is not known.
   386    attachment adding has failed and attachment id is not known.
   374  */
   387  */
   375 void NmEditorHeader::removeAttachment(const QString &fileName)
   388 void NmEditorHeader::removeAttachment(const QString &fileName)
   376 {
   389 {
       
   390     NM_FUNCTION;
       
   391     
   377     mAttachmentList->removeAttachment(fileName);
   392     mAttachmentList->removeAttachment(fileName);
       
   393     if (mAttachmentList->count() == 0) {
       
   394         mAttachmentList->listWidget().hide();
       
   395         mLayout->removeItem(&mAttachmentList->listWidget());
       
   396     }
   378     sendHeaderHeightChanged();
   397     sendHeaderHeightChanged();
   379 }
   398 }
   380 
   399 
   381 /*!
   400 /*!
   382    Remove attachment from the list. This function is used when
   401    Remove attachment from the list. This function is used when
   383    attachment has been selected for remove.
   402    attachment has been selected for remove.
   384  */
   403  */
   385 void NmEditorHeader::removeAttachment(const NmId &nmid)
   404 void NmEditorHeader::removeAttachment(const NmId &nmid)
   386 {
   405 {
       
   406     NM_FUNCTION;
       
   407     
   387     mAttachmentList->removeAttachment(nmid);
   408     mAttachmentList->removeAttachment(nmid);
   388     sendHeaderHeightChanged();
   409     sendHeaderHeightChanged();
   389 }
   410 }
   390 
   411 
   391 /*!
   412 /*!
   395     const QString &fileName,
   416     const QString &fileName,
   396     const NmId &msgPartId,
   417     const NmId &msgPartId,
   397     const QString &fileSize,
   418     const QString &fileSize,
   398     int result)
   419     int result)
   399 {
   420 {
       
   421     NM_FUNCTION;
       
   422     
   400     if (result == NmNoError) {
   423     if (result == NmNoError) {
   401         // Attachment adding succesful, set message part id and size for attachment
   424         // Attachment adding succesful, set message part id and size for attachment
   402         mAttachmentList->setAttachmentPartId(fileName, msgPartId);
   425         mAttachmentList->setAttachmentPartId(fileName, msgPartId);
   403         mAttachmentList->setAttachmentSize(msgPartId, fileSize);
   426         mAttachmentList->setAttachmentSize(msgPartId, fileSize);
   404     }
   427     }
   407 /*!
   430 /*!
   408    Attachment launched from attachment list by "open" menu item.
   431    Attachment launched from attachment list by "open" menu item.
   409  */
   432  */
   410 void NmEditorHeader::launchAttachment(const NmId &itemId)
   433 void NmEditorHeader::launchAttachment(const NmId &itemId)
   411 {
   434 {
       
   435     NM_FUNCTION;
       
   436     
   412     attachmentActivated(mAttachmentList->indexByNmId(itemId));
   437     attachmentActivated(mAttachmentList->indexByNmId(itemId));
   413 }
   438 }
   414 
   439 
   415 /*!
   440 /*!
   416    Slot attachment activated from attachment list by short tap.
   441    Slot attachment activated from attachment list by short tap.
   417  */
   442  */
   418 void NmEditorHeader::attachmentActivated(int arrayIndex)
   443 void NmEditorHeader::attachmentActivated(int arrayIndex)
   419 {
   444 {
       
   445     NM_FUNCTION;
       
   446     
   420     QFile launchFile(mAttachmentList->getFullFileNameByIndex(arrayIndex));
   447     QFile launchFile(mAttachmentList->getFullFileNameByIndex(arrayIndex));
   421     if (NmUtilities::openFile( launchFile ) == NmNotFoundError) {
   448     if (NmUtilities::openFile( launchFile ) == NmNotFoundError) {
   422         NmUtilities::displayErrorNote(hbTrId("txt_mail_dialog_unable_to_open_attachment_file_ty")); 
   449         NmUtilities::displayErrorNote(hbTrId("txt_mail_dialog_unable_to_open_attachment_file_ty")); 
   423     }
   450     }
   424 }
   451 }
   426 /*!
   453 /*!
   427    Slot attachment selected from attachment list by longtap.
   454    Slot attachment selected from attachment list by longtap.
   428  */
   455  */
   429 void NmEditorHeader::attachmentLongPressed(int arrayIndex, QPointF point)
   456 void NmEditorHeader::attachmentLongPressed(int arrayIndex, QPointF point)
   430 {
   457 {
       
   458     NM_FUNCTION;
       
   459     
   431     // Remove selected attachment
   460     // Remove selected attachment
   432     emit attachmentLongPressed(mAttachmentList->nmIdByIndex(arrayIndex), point);
   461     emit attachmentLongPressed(mAttachmentList->nmIdByIndex(arrayIndex), point);
   433 }
   462 }
   434     
   463