emailuis/nmailui/src/nmeditorheader.cpp
changeset 44 c2d07d913565
parent 43 99bcbff212ad
child 47 f83bd4ae1fe3
child 54 997a02608b3a
equal deleted inserted replaced
43:99bcbff212ad 44:c2d07d913565
    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 MaxRows = 10000;
    35 
    35 
    36 static const int nmLayoutSystemWaitTimer = 10;
    36 // this timeout seems to be long enough for all cases. see sendDelayedHeaderHeightChanged
       
    37 static const int LayoutSystemWaitTimer = 500; // 0.5 sec
    37 
    38 
    38 /*!
    39 /*!
    39     Constructor
    40     Constructor
    40 */
    41 */
    41 NmEditorHeader::NmEditorHeader(HbDocumentLoader *documentLoader) :
    42 NmEditorHeader::NmEditorHeader(HbDocumentLoader *documentLoader) :
   150     // Signals for handling the attachment list
   151     // Signals for handling the attachment list
   151     connect(&mAttachmentList->listWidget(), SIGNAL(itemActivated(int)),
   152     connect(&mAttachmentList->listWidget(), SIGNAL(itemActivated(int)),
   152             this, SLOT(attachmentActivated(int)));
   153             this, SLOT(attachmentActivated(int)));
   153     connect(&mAttachmentList->listWidget(), SIGNAL(longPressed(int, QPointF)),
   154     connect(&mAttachmentList->listWidget(), SIGNAL(longPressed(int, QPointF)),
   154             this, SLOT(attachmentLongPressed(int, QPointF)));
   155             this, SLOT(attachmentLongPressed(int, QPointF)));
   155     connect(mAttachmentList ,SIGNAL(attachmentListLayoutChanged()),
       
   156             this, SLOT(sendHeaderHeightChanged()));
       
   157 }
   156 }
   158 
   157 
   159 /*!
   158 /*!
   160    Show or hide recipient field
   159    Show or hide recipient field
   161 */
   160 */
   173             mCcWidget->hide();
   172             mCcWidget->hide();
   174             mBccWidget->hide();
   173             mBccWidget->hide();
   175 			mLayout->removeItem(mCcWidget);
   174 			mLayout->removeItem(mCcWidget);
   176 			mLayout->removeItem(mBccWidget);
   175 			mLayout->removeItem(mBccWidget);
   177 		}
   176 		}
   178 
   177         sendDelayedHeaderHeightChanged();
   179 		QTimer::singleShot(
       
   180 		    nmLayoutSystemWaitTimer * 2, this, SLOT(sendDelayedHeaderHeightChanged()));
       
   181 	}
   178 	}
   182 }
   179 }
   183 
   180 
   184 /*!
   181 /*!
   185     Return the height of the whole header widget.
   182     Return the height of the whole header widget.
   216 
   213 
   217     return height;
   214     return height;
   218 }
   215 }
   219 
   216 
   220 /*!
   217 /*!
   221     Send signal to inform that one of the recipient fields height has been changed.
   218     This is called when the contents of some of the header widgets have been changed. When the
       
   219     contents change the widget's actual size may also change. The header area height is needed to
       
   220     calculate the size hints of the body and the scroll area widgets. We need to use a timer to let 
       
   221     the Orbit FW adjust the heights eg. if the subject and recipient fields are expanded by the FW.
       
   222     It would be best to find a solution which doesn't depend on the header area's actual height size
       
   223     information.
   222  */
   224  */
   223 void NmEditorHeader::sendDelayedHeaderHeightChanged()
   225 void NmEditorHeader::sendDelayedHeaderHeightChanged()
   224 {
   226 {
   225     NM_FUNCTION;
   227     NM_FUNCTION;
   226 	QTimer::singleShot(nmLayoutSystemWaitTimer * 5, this, SLOT(sendHeaderHeightChanged()));
   228 	QTimer::singleShot(LayoutSystemWaitTimer, this, SLOT(sendHeaderHeightChanged()));
   227 }
   229 }
   228 
   230 
   229 /*!
   231 /*!
   230     Send signal to inform that one of the recipient fields height has been changed.
   232     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.
   231  */
   234  */
   232 void NmEditorHeader::sendHeaderHeightChanged()
   235 void NmEditorHeader::sendHeaderHeightChanged()
   233 {
   236 {
   234     qreal hHeight = headerHeight();
   237     qreal hHeight = headerHeight();
   235     if (mHeaderHeight != hHeight) {
   238     if (mHeaderHeight != hHeight) {
   358             mSubjectLayout->removeItem(mPriorityIcon);
   361             mSubjectLayout->removeItem(mPriorityIcon);
   359             mPriorityIcon->hide();
   362             mPriorityIcon->hide();
   360         }
   363         }
   361         break;
   364         break;
   362     }
   365     }
   363     // Update subject field height because row amount might have been changed.
   366     sendDelayedHeaderHeightChanged();
   364     QTimer::singleShot(nmLayoutSystemWaitTimer * 3, this, SLOT(sendDelayedHeaderHeightChanged()));
       
   365 }
   367 }
   366 
   368 
   367 /*!
   369 /*!
   368    Adds an attachment to attachment list for mail.
   370    Adds an attachment to attachment list for mail.
   369  */
   371  */
   376     if (!mAttachmentList->listWidget().isVisible()) {
   378     if (!mAttachmentList->listWidget().isVisible()) {
   377         // attachment list is inserted just before the body widget (see docml).
   379         // attachment list is inserted just before the body widget (see docml).
   378         mLayout->insertItem(mLayout->count() - 1, &mAttachmentList->listWidget());
   380         mLayout->insertItem(mLayout->count() - 1, &mAttachmentList->listWidget());
   379         mAttachmentList->listWidget().show();
   381         mAttachmentList->listWidget().show();
   380     }
   382     }
   381     sendHeaderHeightChanged();
   383     sendDelayedHeaderHeightChanged();
   382 }
   384 }
   383 
   385 
   384 /*!
   386 /*!
   385    Remove attachment from the list. This function is used when
   387    Remove attachment from the list. This function is used when
   386    attachment adding has failed and attachment id is not known.
   388    attachment adding has failed and attachment id is not known.
   392     mAttachmentList->removeAttachment(fileName);
   394     mAttachmentList->removeAttachment(fileName);
   393     if (mAttachmentList->count() == 0) {
   395     if (mAttachmentList->count() == 0) {
   394         mAttachmentList->listWidget().hide();
   396         mAttachmentList->listWidget().hide();
   395         mLayout->removeItem(&mAttachmentList->listWidget());
   397         mLayout->removeItem(&mAttachmentList->listWidget());
   396     }
   398     }
   397     sendHeaderHeightChanged();
   399     sendDelayedHeaderHeightChanged();
   398 }
   400 }
   399 
   401 
   400 /*!
   402 /*!
   401    Remove attachment from the list. This function is used when
   403    Remove attachment from the list. This function is used when
   402    attachment has been selected for remove.
   404    attachment has been selected for remove.
   404 void NmEditorHeader::removeAttachment(const NmId &nmid)
   406 void NmEditorHeader::removeAttachment(const NmId &nmid)
   405 {
   407 {
   406     NM_FUNCTION;
   408     NM_FUNCTION;
   407     
   409     
   408     mAttachmentList->removeAttachment(nmid);
   410     mAttachmentList->removeAttachment(nmid);
   409     sendHeaderHeightChanged();
   411     if (mAttachmentList->count() == 0) {
       
   412         mAttachmentList->listWidget().hide();
       
   413         mLayout->removeItem(&mAttachmentList->listWidget());
       
   414     }
       
   415     sendDelayedHeaderHeightChanged();
   410 }
   416 }
   411 
   417 
   412 /*!
   418 /*!
   413     This function set messagePartId and fileSize for attachment.
   419     This function set messagePartId and fileSize for attachment.
   414  */
   420  */
   426         mAttachmentList->setAttachmentSize(msgPartId, fileSize);
   432         mAttachmentList->setAttachmentSize(msgPartId, fileSize);
   427     }
   433     }
   428 }
   434 }
   429 
   435 
   430 /*!
   436 /*!
   431    Attachment launched from attachment list by "open" menu item.
       
   432  */
       
   433 void NmEditorHeader::launchAttachment(const NmId &itemId)
       
   434 {
       
   435     NM_FUNCTION;
       
   436     
       
   437     attachmentActivated(mAttachmentList->indexByNmId(itemId));
       
   438 }
       
   439 
       
   440 /*!
       
   441    Slot attachment activated from attachment list by short tap.
   437    Slot attachment activated from attachment list by short tap.
   442  */
   438  */
   443 void NmEditorHeader::attachmentActivated(int arrayIndex)
   439 void NmEditorHeader::attachmentActivated(int arrayIndex)
   444 {
   440 {
   445     NM_FUNCTION;
   441     NM_FUNCTION;
   446     
   442     
   447     QFile launchFile(mAttachmentList->getFullFileNameByIndex(arrayIndex));
   443     //
   448     if (NmUtilities::openFile( launchFile ) == NmNotFoundError) {
   444     emit attachmentShortPressed(mAttachmentList->nmIdByIndex(arrayIndex));    
   449         NmUtilities::displayErrorNote(hbTrId("txt_mail_dialog_unable_to_open_attachment_file_ty")); 
       
   450     }
       
   451 }
   445 }
   452 
   446 
   453 /*!
   447 /*!
   454    Slot attachment selected from attachment list by longtap.
   448    Slot attachment selected from attachment list by longtap.
   455  */
   449  */