emailuis/nmhswidget/src/nmhswidgetemailrow.cpp
changeset 30 759dc5235cdb
parent 23 2dc6caa42ec3
child 47 f83bd4ae1fe3
equal deleted inserted replaced
27:9ba4404ef423 30:759dc5235cdb
    13  *
    13  *
    14  * Description: 
    14  * Description: 
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include <QDebug>
       
    19 #include <QGraphicsLinearLayout>
    18 #include <QGraphicsLinearLayout>
    20 #include <hbdocumentloader.h>
    19 #include <hbdocumentloader.h>
    21 #include <hblabel.h>
    20 #include <hblabel.h>
    22 #include <hbextendedlocale.h>
    21 #include <hbextendedlocale.h>
    23 #include <HbFrameDrawer>
    22 #include <HbFrameDrawer>
    24 #include <HbFrameItem>
    23 #include <HbFrameItem>
       
    24 #include <HbColorScheme>
       
    25 #include <HbEvent>
    25 #include "nmicons.h"
    26 #include "nmicons.h"
    26 #include "nmcommon.h"
    27 #include "nmcommon.h"
    27 #include "nmhswidgetemailrow.h"
    28 #include "nmhswidgetemailrow.h"
    28 #include "nmhswidgetconsts.h"
    29 #include "nmhswidgetconsts.h"
    29 #include "nmmessageenvelope.h"
    30 #include "emailtrace.h"
    30 
    31 
    31 NmHsWidgetEmailRow::NmHsWidgetEmailRow(QGraphicsItem *parent, Qt::WindowFlags flags) :
    32 NmHsWidgetEmailRow::NmHsWidgetEmailRow(QGraphicsItem *parent, Qt::WindowFlags flags) :
    32     HbWidget(parent, flags), 
    33     HbWidget(parent, flags), 
    33     mSenderLabel(0), 
    34     mSenderLabel(0), 
    34     mSubjectLabel(0), 
    35     mSubjectLabel(0), 
    35     mTimeLabel(0), 
    36     mTimeLabel(0), 
    36     mNewMailIcon(0),
    37     mNewMailIcon(0),
    37     mSeparatorIcon(0), 
    38     mSeparatorIcon(0), 
    38     mMessageId(0)
    39     mMessageId(0)
    39 {
    40 {
    40     qDebug() << "NmHsWidgetEmailRow::NmHsWidgetEmailRow IN -->>";
    41     NM_FUNCTION;
    41 
       
    42     qDebug() << "NmHsWidgetEmailRow::NmHsWidgetEmailRow OUT <<--";
       
    43 }
    42 }
    44 
    43 
    45 /*!
    44 /*!
    46  Destructor
    45  Destructor
    47  */
    46  */
    48 NmHsWidgetEmailRow::~NmHsWidgetEmailRow()
    47 NmHsWidgetEmailRow::~NmHsWidgetEmailRow()
    49 {
    48 {
    50     qDebug() << "NmHsWidgetEmailRow::~NmHsWidgetEmailRow IN -->>";
    49     NM_FUNCTION;
    51 
       
    52     qDebug() << "NmHsWidgetEmailRow::~NmHsWidgetEmailRow OUT <<--";
       
    53 }
    50 }
    54 
    51 
    55 /*!
    52 /*!
    56  Returns id of message shown
    53  Returns id of message shown
    57  */
    54  */
    58 NmId NmHsWidgetEmailRow::messageId()
    55 NmId NmHsWidgetEmailRow::messageId()
    59 {
    56 {
    60     qDebug() << "NmHsWidgetEmailRow::messageId()";
    57     NM_FUNCTION;
    61     return mMessageId;
    58     return mMessageId;
    62 
    59 
    63 }
    60 }
    64 
    61 
    65 /*!
    62 /*!
    67  Must be called after constructor.
    64  Must be called after constructor.
    68   /return true if loading succeeded, otherwise false. False indicates that object is unusable.
    65   /return true if loading succeeded, otherwise false. False indicates that object is unusable.
    69  */
    66  */
    70 bool NmHsWidgetEmailRow::loadDocML()
    67 bool NmHsWidgetEmailRow::loadDocML()
    71 {
    68 {
       
    69     NM_FUNCTION;
       
    70     
    72     HbFrameDrawer* backgroundFrameDrawer = 0;
    71     HbFrameDrawer* backgroundFrameDrawer = 0;
    73     HbFrameItem* backgroundLayoutItem = 0;
    72     HbFrameItem* backgroundLayoutItem = 0;
    74     QT_TRY{
    73     QT_TRY{   
    75         qDebug() << "NmHsWidgetEmailRow::loadDocML IN -->>";
       
    76     
       
    77         // Use document loader to load the contents
    74         // Use document loader to load the contents
    78         HbDocumentLoader loader;
    75         HbDocumentLoader loader;
    79         bool ok(false);
    76         bool ok(false);
    80         loader.load(KNmHsWidgetMailRowDocML, &ok);
    77         loader.load(KNmHsWidgetMailRowDocML, &ok);
    81         if (!ok) {
    78         if (!ok) {
    82             qDebug() << "NmHsWidgetEmailRow::loadDocML fail @ loader <<--";
    79             NM_ERROR(1,"NmHsWidgetEmailRow::loadDocML fail @ loader");
    83             return false;
    80             return false;
    84         }
    81         }
    85     
    82     
    86         QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
    83         QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
    87     
    84     
    92         setLayout(layout);
    89         setLayout(layout);
    93     
    90     
    94         //find container widget
    91         //find container widget
    95         QGraphicsWidget *container = loader.findWidget(KNmHsWidgetMailRowContainer);
    92         QGraphicsWidget *container = loader.findWidget(KNmHsWidgetMailRowContainer);
    96         if (!container) {
    93         if (!container) {
    97             qDebug() << "NmHsWidgetEmailRow::loadDocML fail @ container <<--";
    94             NM_ERROR(1,"NmHsWidgetEmailRow::loadDocML fail @ container");
    98             return false;
    95             return false;
    99         }
    96         }
   100         layout->addItem(container);
    97         layout->addItem(container);
   101     
    98     
   102         //child items possible to update
    99         //child items possible to update
   116         mStatusIcons.append(static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetMailRowMiddleIcon)));
   113         mStatusIcons.append(static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetMailRowMiddleIcon)));
   117         mStatusIcons.append(static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetMailRowLeftIcon)));
   114         mStatusIcons.append(static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetMailRowLeftIcon)));
   118     
   115     
   119         //Verify that items are valid
   116         //Verify that items are valid
   120         if (!mSenderLabel || !mSubjectLabel || !mTimeLabel || !mNewMailIcon || !mSeparatorIcon) {
   117         if (!mSenderLabel || !mSubjectLabel || !mTimeLabel || !mNewMailIcon || !mSeparatorIcon) {
   121             qDebug() << "NmHsWidgetEmailRow::loadDocML fail @ labels & icons <<--";
   118             NM_ERROR(1,"NmHsWidgetEmailRow::loadDocML fail @ labels & icons");
   122             return false;
   119             return false;
   123         }
   120         }
   124         //Verify all mStatusIcons
   121         //Verify all mStatusIcons
   125         for (int i = 0; i < mStatusIcons.length(); i++) {
   122         for (int i = 0; i < mStatusIcons.length(); i++) {
   126             if (!mStatusIcons[i]) {
   123             if (!mStatusIcons[i]) {
   127                 qDebug() << "NmHsWidgetEmailRow::loadDocML status icons <<--";
       
   128                 return false;
   124                 return false;
   129             }
   125             }
   130         }
   126         }
   131     
   127     
   132         //separator icon
   128         //separator icon
   140         mNewMailIcon->setBackgroundItem(backgroundLayoutItem);
   136         mNewMailIcon->setBackgroundItem(backgroundLayoutItem);
   141     
   137     
   142         //hide all the icons first to avoid blinking
   138         //hide all the icons first to avoid blinking
   143         hideIcons();
   139         hideIcons();
   144     
   140     
   145         qDebug() << "NmHsWidgetEmailRow::loadDocML OK OUT <<--";
       
   146         return true;
   141         return true;
   147     }
   142     }
   148     QT_CATCH(...){
   143     QT_CATCH(...){
   149         if(!backgroundLayoutItem && backgroundFrameDrawer){
   144         if(!backgroundLayoutItem && backgroundFrameDrawer){
   150             delete backgroundFrameDrawer;
   145             delete backgroundFrameDrawer;
   158  Sets the data provided as a parameter to the UI components
   153  Sets the data provided as a parameter to the UI components
   159  \param envelope message envelope representing an email
   154  \param envelope message envelope representing an email
   160  */
   155  */
   161 void NmHsWidgetEmailRow::updateMailData(const NmMessageEnvelope& envelope)
   156 void NmHsWidgetEmailRow::updateMailData(const NmMessageEnvelope& envelope)
   162 {
   157 {
   163     qDebug() << "NmHsWidgetEmailRow::updateMailData IN -->>";
   158     NM_FUNCTION;
   164 
   159 
       
   160     mEnvelope = NmMessageEnvelope(envelope);
       
   161     
   165     //hide all icons, so no previous data is messing with the new
   162     //hide all icons, so no previous data is messing with the new
   166     hideIcons();
   163     hideIcons();
   167 
   164 
   168     mMessageId = envelope.messageId();
   165     mMessageId = envelope.messageId();
   169     //Show sender name if it is available, otherwise show email address
   166     //Show sender name if it is available, otherwise show email address
   181     mMessageSentTime = envelope.sentTime();
   178     mMessageSentTime = envelope.sentTime();
   182     updateDateTime();
   179     updateDateTime();
   183     
   180     
   184     //set new icons to widget based on the data
   181     //set new icons to widget based on the data
   185     setIconsToWidget( envelope );
   182     setIconsToWidget( envelope );
   186     qDebug() << "NmHsWidgetEmailRow::updateMailData OUT <<--";
   183     
       
   184     //set fonts color and size
       
   185     setFontsSize(mEnvelope.isRead());
       
   186     setFontsColor(false);
   187     }
   187     }
   188 
   188 
   189 /*!
   189 /*!
   190     updateDateTime to label using correct locale
   190     updateDateTime to label using correct locale
   191 */
   191 */
   192 void NmHsWidgetEmailRow::updateDateTime()
   192 void NmHsWidgetEmailRow::updateDateTime()
   193     {
   193     {
   194     qDebug() << "NmHsWidgetEmailRow::updateDateTime IN -->>";
   194     NM_FUNCTION;
   195     //Set Date with locale support
   195     //Set Date with locale support
   196     //Time shown if message is sent today, otherwise show date
   196     //Time shown if message is sent today, otherwise show date
   197     HbExtendedLocale locale = HbExtendedLocale::system();
   197     HbExtendedLocale locale = HbExtendedLocale::system();
   198     QDateTime now = QDateTime::currentDateTime();
   198     QDateTime now = QDateTime::currentDateTime();
   199     if ( mMessageSentTime.date() == now.date() )
   199     if ( mMessageSentTime.date() == now.date() )
   205     else
   205     else
   206         {
   206         {
   207         QString dateSpec = r_qtn_date_without_year;
   207         QString dateSpec = r_qtn_date_without_year;
   208         mTimeLabel->setPlainText( locale.format(mMessageSentTime.date(), dateSpec) );
   208         mTimeLabel->setPlainText( locale.format(mMessageSentTime.date(), dateSpec) );
   209         }
   209         }
   210     qDebug() << "NmHsWidgetEmailRow::updateDateTime OUT <<--";
       
   211     }
   210     }
   212 
   211 
   213 /*!
   212 /*!
   214  hide icons from widget
   213  hide icons from widget
   215  */
   214  */
   216 void NmHsWidgetEmailRow::hideIcons()
   215 void NmHsWidgetEmailRow::hideIcons()
   217 {
   216 {
   218     qDebug() << "NmHsWidgetEmailRow::hideIcons IN -->>";
   217     NM_FUNCTION;
   219     for (int i = 0; i < mStatusIcons.count(); i++) {
   218     for (int i = 0; i < mStatusIcons.count(); i++) {
   220         mStatusIcons[i]->hide();
   219         mStatusIcons[i]->hide();
   221     }
   220     }
   222     mNewMailIcon->hide();
   221     mNewMailIcon->hide();
   223     qDebug() << "NmHsWidgetEmailRow::hideIcons OUT <<--";
       
   224 }
   222 }
   225 
   223 
   226 /*!
   224 /*!
   227  Set icons to widget
   225  Set icons to widget
   228  */
   226  */
   229 void NmHsWidgetEmailRow::setIconsToWidget(const NmMessageEnvelope& envelope)
   227 void NmHsWidgetEmailRow::setIconsToWidget(const NmMessageEnvelope& envelope)
   230 {
   228 {
   231     qDebug() << "NmHsWidgetEmailRow::setIconsToWidget IN -->>";
   229     NM_FUNCTION;
   232 
   230 
   233     bool unreadMail = !envelope.isRead();
   231     bool unreadMail = !envelope.isRead();
   234     bool attachment = envelope.hasAttachments();
   232     bool attachment = envelope.hasAttachments();
   235     int priority = envelope.priority();
   233     int priority = envelope.priority();
   236 
   234 
   265     // Here we show icons added to the iconList in the order they have been added.
   263     // Here we show icons added to the iconList in the order they have been added.
   266     for (int count = 0; count < iconList.count(); count++) {
   264     for (int count = 0; count < iconList.count(); count++) {
   267         mStatusIcons[count]->setIcon(iconList[count]);
   265         mStatusIcons[count]->setIcon(iconList[count]);
   268         mStatusIcons[count]->show();
   266         mStatusIcons[count]->show();
   269     }
   267     }
   270 
   268 }
   271     qDebug() << "NmHsWidgetEmailRow::setIconsToWidget OUT <<--";
   269 
   272 }
   270 
       
   271 /*!
       
   272     sets fonts size. Unread and read mails are shown differently
       
   273 */
       
   274 void NmHsWidgetEmailRow::setFontsSize( bool read )
       
   275     {
       
   276     NM_FUNCTION;
       
   277     HbFontSpec fontSpec;
       
   278     
       
   279     if(!read){
       
   280         fontSpec.setRole(HbFontSpec::Primary);
       
   281         mTimeLabel->fontSpec().setRole(HbFontSpec::Primary);
       
   282     }
       
   283     else{
       
   284         fontSpec.setRole(HbFontSpec::Secondary);
       
   285         mTimeLabel->fontSpec().setRole(HbFontSpec::Secondary);
       
   286     }  
       
   287     
       
   288     HbStyle style;
       
   289     qreal size;
       
   290     bool found = style.parameter(QString("hb-param-text-height-secondary"), size );
       
   291     if (found) {
       
   292         fontSpec.setTextHeight(size);
       
   293     }
       
   294     
       
   295     mSenderLabel->setFontSpec(fontSpec);
       
   296     mSubjectLabel->setFontSpec(fontSpec);
       
   297     }
       
   298 
       
   299 /*!
       
   300     sets fonts color.
       
   301 */
       
   302 void NmHsWidgetEmailRow::setFontsColor( bool pressed )
       
   303     {
       
   304     NM_FUNCTION;;
       
   305     QColor newFontColor;
       
   306     
       
   307     if(pressed){
       
   308         newFontColor = HbColorScheme::color("qtc_hs_list_item_pressed");
       
   309     }
       
   310     else if(mEnvelope.isRead()){
       
   311         newFontColor = HbColorScheme::color("qtc_hs_list_item_content_normal");
       
   312     }
       
   313     else{
       
   314         newFontColor = HbColorScheme::color("qtc_hs_list_item_title_normal");
       
   315     }
       
   316  
       
   317     mSenderLabel->setTextColor(newFontColor);
       
   318     mSubjectLabel->setTextColor(newFontColor);
       
   319     mTimeLabel->setTextColor(newFontColor);
       
   320     }
       
   321 
   273 
   322 
   274 /*!
   323 /*!
   275  mousePressEvent(QGraphicsSceneMouseEvent *event)
   324  mousePressEvent(QGraphicsSceneMouseEvent *event)
   276  */
   325  */
   277 void NmHsWidgetEmailRow::mousePressEvent(QGraphicsSceneMouseEvent *event)
   326 void NmHsWidgetEmailRow::mousePressEvent(QGraphicsSceneMouseEvent *event)
   278 {
   327 {
   279     qDebug() << "NmHsWidgetTitleRow::mousePressEvent() IN -->>";
   328     NM_FUNCTION;
   280     Q_UNUSED(event); 
   329     Q_UNUSED(event); 
   281     qDebug() << "NmHsWidgetTitleRow::mousePressEvent() OUT <<--";
   330     setFontsColor(true);
   282 }
   331 }
   283 
   332 
   284 /*!
   333 /*!
   285     mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   334     mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   286 */
   335 */
   287 void NmHsWidgetEmailRow::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   336 void NmHsWidgetEmailRow::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   288 {
   337 {
   289     qDebug() << "NmHsWidgetTitleRow::mouseReleaseEvent() IN -->>";
   338     NM_FUNCTION;
   290     Q_UNUSED(event);
   339     Q_UNUSED(event);
       
   340     setFontsColor(false);
   291     emit mailViewerLaunchTriggered(mMessageId);
   341     emit mailViewerLaunchTriggered(mMessageId);
   292     qDebug() << "NmHsWidgetTitleRow::mouseReleaseEvent() OUT <<--";
   342 }
   293 }
   343 
       
   344 /*
       
   345  * NmHsWidgetEmailRow::event()
       
   346  */
       
   347 bool NmHsWidgetEmailRow::event( QEvent *event )
       
   348 {
       
   349     NM_FUNCTION;
       
   350     QEvent::Type eventType = event->type();
       
   351     if( eventType == HbEvent::ThemeChanged ){
       
   352         setFontsColor(false);
       
   353         return true;
       
   354     }
       
   355     return HbWidget::event(event);
       
   356 }