emailuis/nmhswidget/src/nmhswidgettitlerow.cpp
author hgs
Thu, 14 Oct 2010 17:33:43 +0300
changeset 76 38bf5461e270
parent 74 6c59112cfd31
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
 * All rights reserved.
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
 *
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
 * Initial Contributors:
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
 *
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
 * Contributors:
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
 *
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
 * Description: 
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
 *
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
 */
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    18
#include <qgraphicslinearlayout.h>
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    19
#include <QtGui>
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
#include <hbdocumentloader.h>
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
#include <hblabel.h>
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    22
#include <hbpushbutton.h>
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    23
#include <hbcolorscheme.h>
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    24
#include <hbevent.h>
47
hgs
parents: 43
diff changeset
    25
#include <hbframedrawer.h>
hgs
parents: 43
diff changeset
    26
#include <hbframeitem.h>
62
hgs
parents: 49
diff changeset
    27
#include <hbtapgesture.h>
hgs
parents: 49
diff changeset
    28
#include <hbinstantfeedback.h>
74
hgs
parents: 68
diff changeset
    29
#include <hbstringutil.h>
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
#include "nmicons.h"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
#include "nmhswidgettitlerow.h"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    32
#include "nmhswidgetconsts.h"
43
hgs
parents: 23
diff changeset
    33
#include "emailtrace.h"
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    35
NmHsWidgetTitleRow::NmHsWidgetTitleRow(QGraphicsItem *parent, Qt::WindowFlags flags) :
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    36
    HbWidget(parent, flags), 
62
hgs
parents: 49
diff changeset
    37
    mContainer(0),
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    38
    mMailboxIcon(0), 
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    39
    mMailboxInfo(0), 
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    40
    mUnreadCountLabel(0),
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    41
    mCollapseExpIconLabel(0), 
43
hgs
parents: 23
diff changeset
    42
    mAccountName(),
47
hgs
parents: 43
diff changeset
    43
    mUnreadCount(0),
hgs
parents: 43
diff changeset
    44
    mBackgroundLayoutItem(0)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
{
43
hgs
parents: 23
diff changeset
    46
    NM_FUNCTION;
62
hgs
parents: 49
diff changeset
    47
    grabGesture(Qt::TapGesture);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    50
/*!
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    51
 Destructor
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    52
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    53
NmHsWidgetTitleRow::~NmHsWidgetTitleRow()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    54
{
47
hgs
parents: 43
diff changeset
    55
    NM_FUNCTION; 
hgs
parents: 43
diff changeset
    56
}
hgs
parents: 43
diff changeset
    57
hgs
parents: 43
diff changeset
    58
/*!
hgs
parents: 43
diff changeset
    59
 \fn QPainterPath NmHsWidgetTitleRow::shape()
hgs
parents: 43
diff changeset
    60
hgs
parents: 43
diff changeset
    61
 Called by home screen fw to check widget boundaries, needed to draw
hgs
parents: 43
diff changeset
    62
 outside widget boundingRect.
hgs
parents: 43
diff changeset
    63
 /return QPainterPath path describing actual boundaries of widget 
hgs
parents: 43
diff changeset
    64
  including child items
hgs
parents: 43
diff changeset
    65
 */
hgs
parents: 43
diff changeset
    66
QPainterPath NmHsWidgetTitleRow::shape() const
hgs
parents: 43
diff changeset
    67
{
43
hgs
parents: 23
diff changeset
    68
    NM_FUNCTION;
47
hgs
parents: 43
diff changeset
    69
    
hgs
parents: 43
diff changeset
    70
    QPainterPath path;
hgs
parents: 43
diff changeset
    71
    path.setFillRule(Qt::WindingFill);
62
hgs
parents: 49
diff changeset
    72
    if (mContainer){
hgs
parents: 49
diff changeset
    73
        path.addRect(mContainer->geometry());
hgs
parents: 49
diff changeset
    74
    }
47
hgs
parents: 43
diff changeset
    75
    if (mMailboxIcon){
hgs
parents: 43
diff changeset
    76
        path.addRect(mMailboxIcon->geometry());
hgs
parents: 43
diff changeset
    77
    }    
hgs
parents: 43
diff changeset
    78
    return path.simplified();
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
}
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    80
62
hgs
parents: 49
diff changeset
    81
/*!
hgs
parents: 49
diff changeset
    82
 \fn qreal NmHsWidgetTitleRow::containerHeight()
hgs
parents: 49
diff changeset
    83
hgs
parents: 49
diff changeset
    84
 /return qreal defining title row container height in pixels
hgs
parents: 49
diff changeset
    85
 */
hgs
parents: 49
diff changeset
    86
qreal NmHsWidgetTitleRow::containerHeight()
hgs
parents: 49
diff changeset
    87
{
hgs
parents: 49
diff changeset
    88
    if (mContainer){
hgs
parents: 49
diff changeset
    89
        return mContainer->preferredHeight();
hgs
parents: 49
diff changeset
    90
    }
hgs
parents: 49
diff changeset
    91
    return 0;
hgs
parents: 49
diff changeset
    92
}
hgs
parents: 49
diff changeset
    93
47
hgs
parents: 43
diff changeset
    94
/*
hgs
parents: 43
diff changeset
    95
 Setup email row ui
hgs
parents: 43
diff changeset
    96
  Must be called after constructor.
hgs
parents: 43
diff changeset
    97
   /return true if loading succeeded, otherwise false. False indicates that object is unusable.
hgs
parents: 43
diff changeset
    98
 */
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    99
bool NmHsWidgetTitleRow::setupUI(HbDocumentLoader &loader)
47
hgs
parents: 43
diff changeset
   100
    {
hgs
parents: 43
diff changeset
   101
    NM_FUNCTION;
hgs
parents: 43
diff changeset
   102
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   103
    if(!loadDocML(loader) || !setupGraphics()){
47
hgs
parents: 43
diff changeset
   104
        return false;
hgs
parents: 43
diff changeset
   105
    }
76
hgs
parents: 74
diff changeset
   106
    
hgs
parents: 74
diff changeset
   107
    HbEffect::add(mBackgroundLayoutItem, "listviewitem_press", "pressed");
hgs
parents: 74
diff changeset
   108
    HbEffect::add(mBackgroundLayoutItem, "listviewitem_release", "released");
hgs
parents: 74
diff changeset
   109
    
47
hgs
parents: 43
diff changeset
   110
    return true;
hgs
parents: 43
diff changeset
   111
    }
hgs
parents: 43
diff changeset
   112
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   113
/*!
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   114
 Loads layout data and child items from docml file. Must be called after constructor.
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   115
 /return true if loading succeeded, otherwise false. False indicates that object is unusable
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   116
 */
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   117
bool NmHsWidgetTitleRow::loadDocML(HbDocumentLoader &loader)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   118
{
43
hgs
parents: 23
diff changeset
   119
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   120
    QT_TRY{
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   121
        // find container widget
62
hgs
parents: 49
diff changeset
   122
        mContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetTitleRowContainer));
hgs
parents: 49
diff changeset
   123
        if (!mContainer) {
43
hgs
parents: 23
diff changeset
   124
            NM_ERROR(1,"NmHsWidgetTitleRow::loadDocML Fail @ container");
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   125
            return false;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   126
        }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   127
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   128
        //child items possible to update
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   129
        mMailboxIcon = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetTitleRowMailboxIcon));
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   130
        mMailboxInfo = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetTitleRowMailboxNameLabel));
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   131
        mUnreadCountLabel = static_cast<HbLabel*> (loader.findWidget(
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   132
            KNmHsWidgetTitleRowUnreadCountLabel));
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   133
        mCollapseExpIconLabel = static_cast<HbPushButton*> (loader.findWidget(
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   134
            KNmHsWidgetTitleRowCollapseExpandIconLabel));
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   135
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   136
        if (!mMailboxIcon || !mMailboxInfo || !mUnreadCountLabel || !mCollapseExpIconLabel) {
43
hgs
parents: 23
diff changeset
   137
            NM_ERROR(1,"NmHsWidgetTitleRow::loadDocML Fail @ icons & labels");
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   138
            return false;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   139
        }
47
hgs
parents: 43
diff changeset
   140
		
hgs
parents: 43
diff changeset
   141
		//Expand collapse button
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   142
        connect(mCollapseExpIconLabel, SIGNAL(clicked()), this, SIGNAL(expandCollapseButtonPressed()));
47
hgs
parents: 43
diff changeset
   143
		
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   144
        return true;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   145
    }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   146
    QT_CATCH(...){
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   147
        return false;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   148
    }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   149
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   150
47
hgs
parents: 43
diff changeset
   151
/*
hgs
parents: 43
diff changeset
   152
 Setup graphics that cannot be loaded from docml.
hgs
parents: 43
diff changeset
   153
  /return true if loading succeeded, otherwise false. False indicates that object is unusable.
hgs
parents: 43
diff changeset
   154
 */
hgs
parents: 43
diff changeset
   155
bool NmHsWidgetTitleRow::setupGraphics()
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   156
{
47
hgs
parents: 43
diff changeset
   157
    NM_FUNCTION;
hgs
parents: 43
diff changeset
   158
    
hgs
parents: 43
diff changeset
   159
    HbFrameDrawer* backgroundFrameDrawer = 0;
hgs
parents: 43
diff changeset
   160
    QT_TRY{
76
hgs
parents: 74
diff changeset
   161
        //default background
hgs
parents: 74
diff changeset
   162
        backgroundFrameDrawer = new HbFrameDrawer(KNmHsWidgetBackgroundImage, HbFrameDrawer::NinePieces);
47
hgs
parents: 43
diff changeset
   163
        mBackgroundLayoutItem = new HbFrameItem( backgroundFrameDrawer );
62
hgs
parents: 49
diff changeset
   164
        mContainer->setBackgroundItem( mBackgroundLayoutItem );
47
hgs
parents: 43
diff changeset
   165
        
hgs
parents: 43
diff changeset
   166
        //set fonts color
76
hgs
parents: 74
diff changeset
   167
		setFontsColor();
62
hgs
parents: 49
diff changeset
   168
		
hgs
parents: 49
diff changeset
   169
		//to get gestures
hgs
parents: 49
diff changeset
   170
		setGeometry(mContainer->childrenBoundingRect());
hgs
parents: 49
diff changeset
   171
		
47
hgs
parents: 43
diff changeset
   172
        return true;
hgs
parents: 43
diff changeset
   173
    }
hgs
parents: 43
diff changeset
   174
    QT_CATCH(...){
hgs
parents: 43
diff changeset
   175
        if(!mBackgroundLayoutItem && backgroundFrameDrawer){
hgs
parents: 43
diff changeset
   176
            delete backgroundFrameDrawer;
hgs
parents: 43
diff changeset
   177
            backgroundFrameDrawer = NULL;
hgs
parents: 43
diff changeset
   178
        }
hgs
parents: 43
diff changeset
   179
hgs
parents: 43
diff changeset
   180
        return false;
hgs
parents: 43
diff changeset
   181
    }
hgs
parents: 43
diff changeset
   182
    
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   183
}
47
hgs
parents: 43
diff changeset
   184
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   185
/*!
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   186
 Slot for updating account name, calls updateData to update ui.
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   187
 */
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   188
void NmHsWidgetTitleRow::updateAccountName(const QString& accountName)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   189
{
43
hgs
parents: 23
diff changeset
   190
    NM_FUNCTION;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   191
    mAccountName = accountName;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   192
    updateData();
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   193
}
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   194
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   195
/*!
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   196
 Set account icon name
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   197
 */
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   198
void NmHsWidgetTitleRow::setAccountIcon(const QString& accountIconName)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   199
{
43
hgs
parents: 23
diff changeset
   200
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   201
    mMailboxIcon->setIcon(accountIconName);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   202
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   203
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   204
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   205
 Slot for updating unread count, calls updateData to update ui.
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   206
 */
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   207
void NmHsWidgetTitleRow::updateUnreadCount(const int& unreadCount)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   208
{
43
hgs
parents: 23
diff changeset
   209
    NM_FUNCTION;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   210
    mUnreadCount = unreadCount;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   211
    updateData();
43
hgs
parents: 23
diff changeset
   212
}
hgs
parents: 23
diff changeset
   213
hgs
parents: 23
diff changeset
   214
hgs
parents: 23
diff changeset
   215
/*!
hgs
parents: 23
diff changeset
   216
 Slot for updating expand collapse icon
hgs
parents: 23
diff changeset
   217
 */
hgs
parents: 23
diff changeset
   218
void NmHsWidgetTitleRow::setExpandCollapseIcon(const bool& expand)
hgs
parents: 23
diff changeset
   219
{
hgs
parents: 23
diff changeset
   220
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   221
    if(expand){
hgs
parents: 23
diff changeset
   222
        HbIcon icon("qtg_mono_arrow_up");
hgs
parents: 23
diff changeset
   223
        mCollapseExpIconLabel->setIcon(icon);
hgs
parents: 23
diff changeset
   224
    }
hgs
parents: 23
diff changeset
   225
    else{
hgs
parents: 23
diff changeset
   226
        HbIcon icon("qtg_mono_arrow_down");
hgs
parents: 23
diff changeset
   227
        mCollapseExpIconLabel->setIcon(icon);
hgs
parents: 23
diff changeset
   228
    }
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   229
}
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   230
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   231
/*!
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   232
 Update the data displayed in the UI
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   233
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   234
void NmHsWidgetTitleRow::updateData()
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   235
{
43
hgs
parents: 23
diff changeset
   236
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   237
    mMailboxInfo->setPlainText(mAccountName);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   238
    //If unread count is -1, hide the unread count label completely.
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   239
    //This indicates that there are no mails at all (or the initial sync is not done)
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   240
    if (mUnreadCount >= 0) {
74
hgs
parents: 68
diff changeset
   241
        QString unreadCount(HbStringUtil::convertDigits(hbTrId("txt_mail_widget_list_l1").arg(mUnreadCount)));
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   242
        mUnreadCountLabel->setPlainText(unreadCount);
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   243
        QFontMetrics fm(mUnreadCountLabel->font());
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   244
        qreal textWidth = fm.width(unreadCount);
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   245
        mUnreadCountLabel->setMaximumWidth(textWidth);
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   246
    }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   247
    else {
76
hgs
parents: 74
diff changeset
   248
        //set empty string as nothing to show
hgs
parents: 74
diff changeset
   249
        mUnreadCountLabel->setPlainText(QString());
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   250
        mUnreadCountLabel->setMaximumWidth(0);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   251
    }
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   252
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   253
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   254
/*!
43
hgs
parents: 23
diff changeset
   255
    sets fonts color.
hgs
parents: 23
diff changeset
   256
*/
76
hgs
parents: 74
diff changeset
   257
void NmHsWidgetTitleRow::setFontsColor()
43
hgs
parents: 23
diff changeset
   258
    {
hgs
parents: 23
diff changeset
   259
    NM_FUNCTION;
76
hgs
parents: 74
diff changeset
   260
    QColor newFontColor = HbColorScheme::color("qtc_hs_list_item_title_normal");
43
hgs
parents: 23
diff changeset
   261
 
hgs
parents: 23
diff changeset
   262
    mMailboxInfo->setTextColor(newFontColor);
hgs
parents: 23
diff changeset
   263
    mUnreadCountLabel->setTextColor(newFontColor);
hgs
parents: 23
diff changeset
   264
    }
hgs
parents: 23
diff changeset
   265
47
hgs
parents: 43
diff changeset
   266
/*!
76
hgs
parents: 74
diff changeset
   267
    hide background
47
hgs
parents: 43
diff changeset
   268
*/
76
hgs
parents: 74
diff changeset
   269
void NmHsWidgetTitleRow::hideHighlight(const HbEffect::EffectStatus &status)
47
hgs
parents: 43
diff changeset
   270
    {
76
hgs
parents: 74
diff changeset
   271
    NM_FUNCTION;
hgs
parents: 74
diff changeset
   272
hgs
parents: 74
diff changeset
   273
    Q_UNUSED(status);
hgs
parents: 74
diff changeset
   274
    mBackgroundLayoutItem->frameDrawer().setFrameGraphicsName(KNmHsWidgetBackgroundImage);
47
hgs
parents: 43
diff changeset
   275
    }
43
hgs
parents: 23
diff changeset
   276
62
hgs
parents: 49
diff changeset
   277
/*
hgs
parents: 49
diff changeset
   278
 * NmHsWidgetTitleRow::gestureEvent(QGestureEvent *event)
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   279
 */
62
hgs
parents: 49
diff changeset
   280
void NmHsWidgetTitleRow::gestureEvent(QGestureEvent *event)
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   281
{
43
hgs
parents: 23
diff changeset
   282
    NM_FUNCTION;
62
hgs
parents: 49
diff changeset
   283
    
hgs
parents: 49
diff changeset
   284
    if(!event){
hgs
parents: 49
diff changeset
   285
        return;
hgs
parents: 49
diff changeset
   286
    }    
hgs
parents: 49
diff changeset
   287
    HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
hgs
parents: 49
diff changeset
   288
    if(!gesture){
hgs
parents: 49
diff changeset
   289
        return;
hgs
parents: 49
diff changeset
   290
    }
hgs
parents: 49
diff changeset
   291
    //to avoid opening email account mistakenly  when tabbing expand/collapse button
hgs
parents: 49
diff changeset
   292
    //we dont handle events that are on the top, down or right side of the button
hgs
parents: 49
diff changeset
   293
    QPointF posFromScene = mapFromScene(event->mapToGraphicsScene(gesture->position()));
68
hgs
parents: 62
diff changeset
   294
    bool inArea = false;
hgs
parents: 62
diff changeset
   295
    
hgs
parents: 62
diff changeset
   296
    if(this->layoutDirection() == Qt::LeftToRight &&  
hgs
parents: 62
diff changeset
   297
       posFromScene.x() < mUnreadCountLabel->geometry().right()) {
hgs
parents: 62
diff changeset
   298
        inArea = true;
hgs
parents: 62
diff changeset
   299
    }
hgs
parents: 62
diff changeset
   300
    else if(this->layoutDirection() == Qt::RightToLeft && 
hgs
parents: 62
diff changeset
   301
            posFromScene.x() > mUnreadCountLabel->geometry().right()) {
hgs
parents: 62
diff changeset
   302
        inArea = true;
hgs
parents: 62
diff changeset
   303
    }
hgs
parents: 62
diff changeset
   304
    
hgs
parents: 62
diff changeset
   305
    if (inArea) {    
62
hgs
parents: 49
diff changeset
   306
        switch (gesture->state()) {
hgs
parents: 49
diff changeset
   307
            case Qt::GestureStarted:
76
hgs
parents: 74
diff changeset
   308
                HbEffect::start( mBackgroundLayoutItem, "pressed");
hgs
parents: 74
diff changeset
   309
                mBackgroundLayoutItem->frameDrawer().setFrameGraphicsName("qtg_fr_hsitems_pressed");
62
hgs
parents: 49
diff changeset
   310
            break;
hgs
parents: 49
diff changeset
   311
            case Qt::GestureCanceled:
76
hgs
parents: 74
diff changeset
   312
                HbEffect::start( mBackgroundLayoutItem, "released", this, "hideHighlight");
62
hgs
parents: 49
diff changeset
   313
            break;
hgs
parents: 49
diff changeset
   314
            case Qt::GestureFinished:
76
hgs
parents: 74
diff changeset
   315
                HbEffect::start( mBackgroundLayoutItem, "released", this, "hideHighlight");
62
hgs
parents: 49
diff changeset
   316
                if (gesture->tapStyleHint() == HbTapGesture::Tap) {
hgs
parents: 49
diff changeset
   317
                    HbInstantFeedback::play(HbFeedback::BasicItem);
hgs
parents: 49
diff changeset
   318
                    emit mailboxLaunchTriggered();
hgs
parents: 49
diff changeset
   319
                }
hgs
parents: 49
diff changeset
   320
            break;
hgs
parents: 49
diff changeset
   321
        default: 
hgs
parents: 49
diff changeset
   322
            break;
47
hgs
parents: 43
diff changeset
   323
        }
62
hgs
parents: 49
diff changeset
   324
    }
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   325
}
43
hgs
parents: 23
diff changeset
   326
hgs
parents: 23
diff changeset
   327
/*
hgs
parents: 23
diff changeset
   328
 * NmHsWidgetTitleRow::event()
hgs
parents: 23
diff changeset
   329
 */
hgs
parents: 23
diff changeset
   330
bool NmHsWidgetTitleRow::event( QEvent *event )
hgs
parents: 23
diff changeset
   331
{
hgs
parents: 23
diff changeset
   332
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   333
    QEvent::Type eventType = event->type();
hgs
parents: 23
diff changeset
   334
    if( eventType == HbEvent::ThemeChanged ){
76
hgs
parents: 74
diff changeset
   335
        setFontsColor();
43
hgs
parents: 23
diff changeset
   336
        return true;
hgs
parents: 23
diff changeset
   337
    }
hgs
parents: 23
diff changeset
   338
    return HbWidget::event(event);
hgs
parents: 23
diff changeset
   339
}