emailuis/nmailui/src/nmeditorheader.cpp
changeset 27 9ba4404ef423
parent 23 2dc6caa42ec3
child 30 759dc5235cdb
equal deleted inserted replaced
23:2dc6caa42ec3 27:9ba4404ef423
    16 */
    16 */
    17 
    17 
    18 #include "nmuiheaders.h"
    18 #include "nmuiheaders.h"
    19 
    19 
    20 // Layout
    20 // Layout
    21 static const char *NMUI_EDITOR_TO_LABEL = "EditorHeaderToLabel";
    21 static const char *NMUI_EDITOR_RECIPIENT_FIELDS = "RecipientFields";
    22 static const char *NMUI_EDITOR_TO_EDIT = "EditorHeaderToEdit";
       
    23 static const char *NMUI_EDITOR_TO_BUTTON = "EditorHeaderToButton";
       
    24 static const char *NMUI_EDITOR_RECIPIENT_GB = "EditorHeaderRecipientGB";
       
    25 static const char *NMUI_EDITOR_SUBJECT_LABEL = "EditorHeaderSubjectLabel";
    22 static const char *NMUI_EDITOR_SUBJECT_LABEL = "EditorHeaderSubjectLabel";
    26 static const char *NMUI_EDITOR_SUBJECT_EDIT = "EditorHeaderSubjectEdit";
    23 static const char *NMUI_EDITOR_SUBJECT_EDIT = "EditorHeaderSubjectEdit";
    27 static const char *NMUI_EDITOR_PRIORITY_ICON = "labelPriorityIcon";
    24 static const char *NMUI_EDITOR_PRIORITY_ICON = "labelPriorityIcon";
    28 static const char *NMUI_EDITOR_ATTACHMENT_LIST = "attachmentListWidget";
    25 static const char *NMUI_EDITOR_ATTACHMENT_LIST = "attachmentListWidget";
    29 
    26 
    30 // Following constants are removed when header fields will offer these
    27 // Following constants are removed when header fields will offer these
    31 static const double Un = 6.66;
    28 static const double Un = 6.66;
    32 static const double FieldHeightWhenSecondaryFont = 5 * Un;
    29 static const double FieldHeightWhenSecondaryFont = 5 * Un;
    33 static const int GroupBoxTitleHeight = 42;
       
    34 static const double Margin = 2 * Un;
    30 static const double Margin = 2 * Un;
    35 static const double HeaderAreaMarginsTotal = 3 * Un;
       
    36 static const double IconFieldWidth = 5 * Un;
    31 static const double IconFieldWidth = 5 * Un;
    37 
    32 
    38 static const int nmLayoutSystemWaitTimer = 10;
    33 static const int nmLayoutSystemWaitTimer = 10;
    39 
    34 
    40 /*!
    35 /*!
    46     mHeaderHeight(0),
    41     mHeaderHeight(0),
    47     mSubjectLabel(NULL),
    42     mSubjectLabel(NULL),
    48     mIconVisible(false),
    43     mIconVisible(false),
    49     mSubjectEdit(NULL),
    44     mSubjectEdit(NULL),
    50     mRecipientFieldsEmpty(true),
    45     mRecipientFieldsEmpty(true),
    51     mGroupBoxRecipient(NULL),
    46     mAttachmentList(NULL),
    52     mAttachmentList(NULL)
    47     mToField(NULL),
       
    48     mCcField(NULL),
       
    49     mBccField(NULL),
       
    50     mCcBccFieldVisible(false)
    53 {
    51 {
    54     loadWidgets();
    52     loadWidgets();
    55     rescaleHeader();
    53     rescaleHeader();
    56     createConnections();
    54     createConnections();
    57 }
    55 }
    70 /*!
    68 /*!
    71     Load widgets from XML for the header.
    69     Load widgets from XML for the header.
    72 */
    70 */
    73 void NmEditorHeader::loadWidgets()
    71 void NmEditorHeader::loadWidgets()
    74 {
    72 {
    75     // To: field objects
    73 	// Add "To:", "CC:" and "BCC:" fields
    76     HbLabel *toLabel = qobject_cast<HbLabel *>
    74 	mHeader = qobject_cast<HbWidget *>
    77         (mDocumentLoader->findWidget(NMUI_EDITOR_TO_LABEL));
    75 	        (mDocumentLoader->findWidget(NMUI_EDITOR_RECIPIENT_FIELDS));
    78     NmRecipientLineEdit *toEdit = qobject_cast<NmRecipientLineEdit *>
    76 
    79         (mDocumentLoader->findWidget(NMUI_EDITOR_TO_EDIT));
    77 	mLayout = new QGraphicsLinearLayout(Qt::Vertical);
    80     HbPushButton *toButton = qobject_cast<HbPushButton *>
    78 	mLayout->setContentsMargins(0,Un,0,0);
    81         (mDocumentLoader->findWidget(NMUI_EDITOR_TO_BUTTON));
    79 
    82     mToField = new NmRecipientField(toLabel, toEdit, toButton);
    80 	mToField = new NmRecipientField(QString("To:"), mHeader);
    83 
    81 	mCcField = new NmRecipientField(QString("Cc:"), mHeader);
    84     // Create recipient group box which includes cc and bcc fields
    82 	mBccField = new NmRecipientField(QString("Bcc:"), mHeader);
    85     mGroupBoxRecipient = qobject_cast<HbGroupBox *>
    83 
    86         (mDocumentLoader->findWidget(NMUI_EDITOR_RECIPIENT_GB));
    84     // Only 'To:' field is visible at startup
    87     // Ownership is transfered
    85 	mLayout->addItem(mToField);
    88     mGroupBoxRecipient->setContentWidget(createRecipientGroupBoxContentWidget());
    86 	mCcField->hide();
    89     mGroupBoxRecipient->setHeading(hbTrId("txt_mail_subhead_ccbcc"));
    87 	mBccField->hide();
    90     mGroupBoxRecipient->setCollapsable(true);
    88 
    91     mGroupBoxRecipient->setCollapsed(true);
    89 	mHeader->setLayout(mLayout);
       
    90 	mHeader->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
    92 
    91 
    93     // Add Subject: field
    92     // Add Subject: field
    94     mSubjectLabel = qobject_cast<HbLabel *>
    93     mSubjectLabel = qobject_cast<HbLabel *>
    95         (mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_LABEL));
    94         (mDocumentLoader->findWidget(NMUI_EDITOR_SUBJECT_LABEL));
    96     mSubjectEdit = qobject_cast<NmHtmlLineEdit *>
    95     mSubjectEdit = qobject_cast<NmHtmlLineEdit *>
   119     connect(mBccField, SIGNAL(textChanged(const QString &)),
   118     connect(mBccField, SIGNAL(textChanged(const QString &)),
   120             this, SLOT(editorContentChanged()));
   119             this, SLOT(editorContentChanged()));
   121 
   120 
   122     // Signals for handling the recipient field expanding
   121     // Signals for handling the recipient field expanding
   123     connect(mToField, SIGNAL(textChanged(const QString &)),
   122     connect(mToField, SIGNAL(textChanged(const QString &)),
   124             this, SLOT(sendHeaderHeightChanged()));
   123             this, SLOT(fixHeaderFieldHeights()));
   125     connect(mCcField, SIGNAL(textChanged(const QString &)),
   124     connect(mCcField, SIGNAL(textChanged(const QString &)),
   126             this, SLOT(sendHeaderHeightChanged()));
   125             this, SLOT(fixHeaderFieldHeights()));
   127     connect(mBccField, SIGNAL(textChanged(const QString &)),
   126     connect(mBccField, SIGNAL(textChanged(const QString &)),
   128             this, SLOT(sendHeaderHeightChanged()));
   127             this, SLOT(fixHeaderFieldHeights()));
   129     connect(mSubjectEdit, SIGNAL(contentsChanged()), this, SLOT(sendHeaderHeightChanged()));
   128     connect(mSubjectEdit, SIGNAL(contentsChanged()), this, SLOT(fixHeaderFieldHeights()));
   130 
       
   131     // Signal for handling the recipient group box expanding/collapsing
       
   132     connect(mGroupBoxRecipient, SIGNAL(toggled(bool)),
       
   133             this, SLOT(groupBoxExpandCollapse()));
       
   134 
   129 
   135     // Signals for handling the attachment list
   130     // Signals for handling the attachment list
   136     connect(&mAttachmentList->listWidget(), SIGNAL(itemActivated(int)),
   131     connect(&mAttachmentList->listWidget(), SIGNAL(itemActivated(int)),
   137             this, SLOT(attachmentActivated(int)));
   132             this, SLOT(attachmentActivated(int)));
   138     connect(&mAttachmentList->listWidget(), SIGNAL(longPressed(int, QPointF)),
   133     connect(&mAttachmentList->listWidget(), SIGNAL(longPressed(int, QPointF)),
   140     connect(mAttachmentList ,SIGNAL(attachmentListLayoutChanged()),
   135     connect(mAttachmentList ,SIGNAL(attachmentListLayoutChanged()),
   141             this, SLOT(sendHeaderHeightChanged()));
   136             this, SLOT(sendHeaderHeightChanged()));
   142 }
   137 }
   143 
   138 
   144 /*!
   139 /*!
       
   140    Show or hide recipient field
       
   141 */
       
   142 void NmEditorHeader::setFieldVisibility(bool isVisible)
       
   143 {
       
   144 	if ( mCcBccFieldVisible != isVisible ) {
       
   145 		mCcBccFieldVisible = isVisible;
       
   146 		if (mCcBccFieldVisible) {
       
   147 			mCcField->show();
       
   148 			mBccField->show();
       
   149 			mLayout->addItem(mCcField);
       
   150 			mLayout->addItem(mBccField);
       
   151 		}
       
   152 		else {
       
   153 			mCcField->hide();
       
   154 			mBccField->hide();
       
   155 			mLayout->removeItem(mCcField);
       
   156 			mLayout->removeItem(mBccField);
       
   157 		}
       
   158 
       
   159 		QTimer::singleShot(nmLayoutSystemWaitTimer*2, this, SLOT(fixHeaderFieldHeights()));
       
   160 	}
       
   161 }
       
   162 
       
   163 /*!
   145     Function can be used to rescale the header area.
   164     Function can be used to rescale the header area.
   146 */
   165 */
   147 void NmEditorHeader::rescaleHeader()
   166 void NmEditorHeader::rescaleHeader()
   148 {
   167 {
   149 }
   168 }
   153     (Should find beter way to get the height of the header area.)
   172     (Should find beter way to get the height of the header area.)
   154  */
   173  */
   155 int NmEditorHeader::headerHeight() const
   174 int NmEditorHeader::headerHeight() const
   156 {
   175 {
   157     qreal toHeight = mToField->height();
   176     qreal toHeight = mToField->height();
       
   177     qreal ccHeight = 0;
       
   178     qreal bccHeight = 0;
       
   179     if (mCcBccFieldVisible) {
       
   180 		ccHeight = mCcField->height();
       
   181 		bccHeight = mBccField->height();
       
   182     }
   158     qreal subjectHeight = mSubjectEdit->geometry().height() + Margin;
   183     qreal subjectHeight = mSubjectEdit->geometry().height() + Margin;
   159 
   184 
   160     // When called first time, height is wrongly 'Margin'
   185     // When called first time, height is wrongly 'Margin'
   161     if (toHeight == Margin) {
   186     if (toHeight == Margin) {
   162         toHeight = FieldHeightWhenSecondaryFont;
   187         toHeight = FieldHeightWhenSecondaryFont;
       
   188     	ccHeight = FieldHeightWhenSecondaryFont;
       
   189     	bccHeight = FieldHeightWhenSecondaryFont;
   163         subjectHeight = FieldHeightWhenSecondaryFont;
   190         subjectHeight = FieldHeightWhenSecondaryFont;
   164     }
       
   165 
       
   166     // Recipient GroupBox
       
   167     qreal recipientGroupBoxHeight = GroupBoxTitleHeight;
       
   168     if (!mGroupBoxRecipient->isCollapsed()) {
       
   169         recipientGroupBoxHeight +=
       
   170             mGroupBoxRecipientContent->geometry().height() + HeaderAreaMarginsTotal;
       
   171     }
   191     }
   172 
   192 
   173     qreal attHeight = 0;
   193     qreal attHeight = 0;
   174     if (mAttachmentList && mAttachmentList->count() > 0) {
   194     if (mAttachmentList && mAttachmentList->count() > 0) {
   175         attHeight = mAttachmentList->listWidget().geometry().height();
   195         attHeight = mAttachmentList->listWidget().geometry().height();
   176     }
   196     }
   177 
   197 
   178     return (int)(toHeight + recipientGroupBoxHeight + subjectHeight + attHeight);
   198     return (int)(toHeight + ccHeight + bccHeight + subjectHeight + attHeight);
   179 }
   199 }
   180 
   200 
   181 /*!
   201 /*!
   182     Send signal to inform that one of the recipient fields height has been changed.
   202     Send signal to inform that one of the recipient fields height has been changed.
   183  */
   203  */
       
   204 void NmEditorHeader::fixHeaderFieldHeights()
       
   205 {
       
   206     // Adjust height of recipient fields 
       
   207 	adjustFieldSizeValues(mToField->editor(), mToField->editor()->document()->size().height());
       
   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 }
       
   238 
       
   239 /*!
       
   240     Send signal to inform that one of the recipient fields height has been changed.
       
   241  */
   184 void NmEditorHeader::sendHeaderHeightChanged()
   242 void NmEditorHeader::sendHeaderHeightChanged()
   185 {
   243 {
   186     // Adjust field heights
       
   187     mToField->editor()->setPreferredHeight(
       
   188         mToField->editor()->document()->size().height() + Margin);
       
   189     mCcField->editor()->setPreferredHeight(
       
   190         mCcField->editor()->document()->size().height() + Margin);
       
   191     mBccField->editor()->setPreferredHeight(
       
   192         mBccField->editor()->document()->size().height() + Margin);
       
   193     mSubjectEdit->setPreferredHeight(
       
   194         mSubjectEdit->document()->size().height() + Margin);
       
   195 
       
   196     int hHeight = headerHeight();
   244     int hHeight = headerHeight();
   197     if (mHeaderHeight != hHeight) {
   245     if (mHeaderHeight != hHeight) {
   198         mHeaderHeight = hHeight;
   246         mHeaderHeight = hHeight;
   199         emit headerHeightChanged(mHeaderHeight);
   247         emit headerHeightChanged(mHeaderHeight);
   200     }
   248     }
   201 }
   249 }
   202 
   250 
   203 /*!
   251 /*!
   204     This slot is called when group box state is changed. Timer is used to give some time
   252     Return pointer to to edit
   205     for layout system so that header hight can be recalculated correctly
   253  */
   206  */
   254 NmRecipientLineEdit* NmEditorHeader::toEdit() const
   207 void NmEditorHeader::groupBoxExpandCollapse()
       
   208 {
       
   209     QTimer::singleShot(nmLayoutSystemWaitTimer, this, SLOT(sendHeaderHeightChanged()));
       
   210 }
       
   211 
       
   212 /*!
       
   213     Return pointer to to field
       
   214  */
       
   215 NmRecipientLineEdit* NmEditorHeader::toField() const
       
   216 {
   255 {
   217     return mToField->editor();
   256     return mToField->editor();
   218 }
   257 }
   219 
   258 
   220 /*!
   259 /*!
   221     Return pointer to cc field
   260     Return pointer to cc edit
   222  */
   261  */
   223 NmRecipientLineEdit* NmEditorHeader::ccField() const
   262 NmRecipientLineEdit* NmEditorHeader::ccEdit() const
   224 {
   263 {
   225     return mCcField->editor();
   264     return mCcField->editor();
   226 }
   265 }
   227 
   266 
   228 /*!
   267 /*!
   229     Return pointer to bcc field
   268     Return pointer to bcc edit
   230  */
   269  */
   231 NmRecipientLineEdit* NmEditorHeader::bccField() const
   270 NmRecipientLineEdit* NmEditorHeader::bccEdit() const
   232 {
   271 {
   233     return mBccField->editor();
   272     return mBccField->editor();
   234 }
   273 }
   235 
   274 
   236 /*!
   275 /*!
   237     Return pointer to subject field
   276     Return pointer to subject field
   238  */
   277  */
   239 NmHtmlLineEdit* NmEditorHeader::subjectField() const
   278 NmHtmlLineEdit* NmEditorHeader::subjectEdit() const
   240 {
   279 {
   241     return mSubjectEdit;
   280     return mSubjectEdit;
   242 }
   281 }
   243 
   282 
   244 /*!
   283 /*!
   259     }
   298     }
   260     if (mRecipientFieldsEmpty != recipientsFieldsEmpty) {
   299     if (mRecipientFieldsEmpty != recipientsFieldsEmpty) {
   261         mRecipientFieldsEmpty = recipientsFieldsEmpty;
   300         mRecipientFieldsEmpty = recipientsFieldsEmpty;
   262         emit recipientFieldsHaveContent(!mRecipientFieldsEmpty);
   301         emit recipientFieldsHaveContent(!mRecipientFieldsEmpty);
   263     }
   302     }
   264 }
       
   265 
       
   266 /*!
       
   267     This function create content widget for recipient group box.
       
   268     When AD offers groupBox content widget handling. This function
       
   269     need to be changed to use AD/docml
       
   270  */
       
   271 HbWidget* NmEditorHeader::createRecipientGroupBoxContentWidget()
       
   272 {
       
   273     mGroupBoxRecipientContent = new HbWidget();
       
   274 
       
   275     // Create layout for the widget
       
   276     mGbVerticalLayout = new QGraphicsLinearLayout(Qt::Vertical,mGroupBoxRecipientContent);
       
   277     mCcFieldLayout = new QGraphicsLinearLayout(Qt::Horizontal, mGbVerticalLayout);
       
   278     mBccFieldLayout = new QGraphicsLinearLayout(Qt::Horizontal, mGbVerticalLayout);
       
   279 
       
   280     // Add Cc: field into widget
       
   281     mCcField = new NmRecipientField(hbTrId("txt_mail_editor_cc"));
       
   282     if (mCcField) {
       
   283         mCcField->setObjectName("lineEditCcField");
       
   284         mGbVerticalLayout->insertItem(EEditorCcLine, mCcField );
       
   285     }
       
   286 
       
   287     // Add Bcc: field into widget
       
   288     mBccField = new NmRecipientField(hbTrId("txt_mail_editor_bcc"));
       
   289     if (mBccField){
       
   290         mBccField->setObjectName("lineEditBccField");
       
   291         mGbVerticalLayout->insertItem(EEditorBccLine, mBccField);
       
   292     }
       
   293     mGbVerticalLayout->setContentsMargins(0,0,0,0);
       
   294 
       
   295     mGroupBoxRecipientContent->setLayout(mGbVerticalLayout);
       
   296     return mGroupBoxRecipientContent;
       
   297 }
   303 }
   298 
   304 
   299 /*!
   305 /*!
   300     Sets the icon for priority
   306     Sets the icon for priority
   301  */
   307  */
   347             mSubjectEdit->setMaximumWidth(mSubjectEdit->geometry().width() + IconFieldWidth);
   353             mSubjectEdit->setMaximumWidth(mSubjectEdit->geometry().width() + IconFieldWidth);
   348         }
   354         }
   349         break;
   355         break;
   350     }
   356     }
   351     // Update subject field height because row amount might have been changed.
   357     // Update subject field height because row amount might have been changed.
   352     // Done with delayed timer so that layout system has finished before.
   358     QTimer::singleShot(nmLayoutSystemWaitTimer * 3, this, SLOT(fixHeaderFieldHeights()));
   353     QTimer::singleShot(nmLayoutSystemWaitTimer, this, SLOT(sendHeaderHeightChanged()));
       
   354     // This second call will set new position for body if subject field height has been changed.
       
   355     QTimer::singleShot(nmLayoutSystemWaitTimer * 2, this, SLOT(sendHeaderHeightChanged()));
       
   356 }
       
   357 
       
   358 /*!
       
   359  * \brief Sets the groupbox to be expanded or collapsed. 
       
   360  */
       
   361 void NmEditorHeader::setGroupBoxCollapsed( bool collapsed )
       
   362 {
       
   363     mGroupBoxRecipient->setCollapsed( collapsed );
       
   364 }
   359 }
   365 
   360 
   366 /*!
   361 /*!
   367    Adds an attachment to attachment list for mail.
   362    Adds an attachment to attachment list for mail.
   368  */
   363  */