emailuis/nmhswidget/src/nmhswidgettitlerow.cpp
author hgs
Thu, 30 Sep 2010 11:43:07 +0300
changeset 74 6c59112cfd31
parent 68 83cc6bae1de8
child 76 38bf5461e270
permissions -rw-r--r--
201039
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
    }
hgs
parents: 43
diff changeset
   106
    return true;
hgs
parents: 43
diff changeset
   107
    }
hgs
parents: 43
diff changeset
   108
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   109
/*!
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   110
 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
   111
 /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
   112
 */
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   113
bool NmHsWidgetTitleRow::loadDocML(HbDocumentLoader &loader)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   114
{
43
hgs
parents: 23
diff changeset
   115
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   116
    QT_TRY{
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   117
        // find container widget
62
hgs
parents: 49
diff changeset
   118
        mContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetTitleRowContainer));
hgs
parents: 49
diff changeset
   119
        if (!mContainer) {
43
hgs
parents: 23
diff changeset
   120
            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
   121
            return false;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   122
        }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   123
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   124
        //child items possible to update
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   125
        mMailboxIcon = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetTitleRowMailboxIcon));
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   126
        mMailboxInfo = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetTitleRowMailboxNameLabel));
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   127
        mUnreadCountLabel = static_cast<HbLabel*> (loader.findWidget(
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   128
            KNmHsWidgetTitleRowUnreadCountLabel));
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   129
        mCollapseExpIconLabel = static_cast<HbPushButton*> (loader.findWidget(
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   130
            KNmHsWidgetTitleRowCollapseExpandIconLabel));
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   131
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   132
        if (!mMailboxIcon || !mMailboxInfo || !mUnreadCountLabel || !mCollapseExpIconLabel) {
43
hgs
parents: 23
diff changeset
   133
            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
   134
            return false;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   135
        }
47
hgs
parents: 43
diff changeset
   136
		
hgs
parents: 43
diff changeset
   137
		//Expand collapse button
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   138
        connect(mCollapseExpIconLabel, SIGNAL(clicked()), this, SIGNAL(expandCollapseButtonPressed()));
47
hgs
parents: 43
diff changeset
   139
		
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   140
        return true;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   141
    }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   142
    QT_CATCH(...){
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   143
        return false;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   144
    }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   145
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   146
47
hgs
parents: 43
diff changeset
   147
/*
hgs
parents: 43
diff changeset
   148
 Setup graphics that cannot be loaded from docml.
hgs
parents: 43
diff changeset
   149
  /return true if loading succeeded, otherwise false. False indicates that object is unusable.
hgs
parents: 43
diff changeset
   150
 */
hgs
parents: 43
diff changeset
   151
bool NmHsWidgetTitleRow::setupGraphics()
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   152
{
47
hgs
parents: 43
diff changeset
   153
    NM_FUNCTION;
hgs
parents: 43
diff changeset
   154
    
hgs
parents: 43
diff changeset
   155
    HbFrameDrawer* backgroundFrameDrawer = 0;
hgs
parents: 43
diff changeset
   156
    QT_TRY{
hgs
parents: 43
diff changeset
   157
        //pressed background
hgs
parents: 43
diff changeset
   158
        backgroundFrameDrawer = new HbFrameDrawer("qtg_fr_hsitems_pressed", HbFrameDrawer::NinePieces);
hgs
parents: 43
diff changeset
   159
        mBackgroundLayoutItem = new HbFrameItem( backgroundFrameDrawer );
62
hgs
parents: 49
diff changeset
   160
        mContainer->setBackgroundItem( mBackgroundLayoutItem );
47
hgs
parents: 43
diff changeset
   161
		mBackgroundLayoutItem->hide();
hgs
parents: 43
diff changeset
   162
        
hgs
parents: 43
diff changeset
   163
        //set fonts color
hgs
parents: 43
diff changeset
   164
		setHighlighedFontsColor(false);
62
hgs
parents: 49
diff changeset
   165
		
hgs
parents: 49
diff changeset
   166
		//to get gestures
hgs
parents: 49
diff changeset
   167
		setGeometry(mContainer->childrenBoundingRect());
hgs
parents: 49
diff changeset
   168
		
47
hgs
parents: 43
diff changeset
   169
        return true;
hgs
parents: 43
diff changeset
   170
    }
hgs
parents: 43
diff changeset
   171
    QT_CATCH(...){
hgs
parents: 43
diff changeset
   172
        if(!mBackgroundLayoutItem && backgroundFrameDrawer){
hgs
parents: 43
diff changeset
   173
            delete backgroundFrameDrawer;
hgs
parents: 43
diff changeset
   174
            backgroundFrameDrawer = NULL;
hgs
parents: 43
diff changeset
   175
        }
hgs
parents: 43
diff changeset
   176
hgs
parents: 43
diff changeset
   177
        return false;
hgs
parents: 43
diff changeset
   178
    }
hgs
parents: 43
diff changeset
   179
    
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   180
}
47
hgs
parents: 43
diff changeset
   181
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   182
/*!
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   183
 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
   184
 */
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   185
void NmHsWidgetTitleRow::updateAccountName(const QString& accountName)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   186
{
43
hgs
parents: 23
diff changeset
   187
    NM_FUNCTION;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   188
    mAccountName = accountName;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   189
    updateData();
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   190
}
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   191
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   192
/*!
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   193
 Set account icon name
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   194
 */
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   195
void NmHsWidgetTitleRow::setAccountIcon(const QString& accountIconName)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   196
{
43
hgs
parents: 23
diff changeset
   197
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   198
    mMailboxIcon->setIcon(accountIconName);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   199
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   200
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   201
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   202
 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
   203
 */
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   204
void NmHsWidgetTitleRow::updateUnreadCount(const int& unreadCount)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   205
{
43
hgs
parents: 23
diff changeset
   206
    NM_FUNCTION;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   207
    mUnreadCount = unreadCount;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   208
    updateData();
43
hgs
parents: 23
diff changeset
   209
}
hgs
parents: 23
diff changeset
   210
hgs
parents: 23
diff changeset
   211
hgs
parents: 23
diff changeset
   212
/*!
hgs
parents: 23
diff changeset
   213
 Slot for updating expand collapse icon
hgs
parents: 23
diff changeset
   214
 */
hgs
parents: 23
diff changeset
   215
void NmHsWidgetTitleRow::setExpandCollapseIcon(const bool& expand)
hgs
parents: 23
diff changeset
   216
{
hgs
parents: 23
diff changeset
   217
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   218
    if(expand){
hgs
parents: 23
diff changeset
   219
        HbIcon icon("qtg_mono_arrow_up");
hgs
parents: 23
diff changeset
   220
        mCollapseExpIconLabel->setIcon(icon);
hgs
parents: 23
diff changeset
   221
    }
hgs
parents: 23
diff changeset
   222
    else{
hgs
parents: 23
diff changeset
   223
        HbIcon icon("qtg_mono_arrow_down");
hgs
parents: 23
diff changeset
   224
        mCollapseExpIconLabel->setIcon(icon);
hgs
parents: 23
diff changeset
   225
    }
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   226
}
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   227
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   228
/*!
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   229
 Update the data displayed in the UI
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   230
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   231
void NmHsWidgetTitleRow::updateData()
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   232
{
43
hgs
parents: 23
diff changeset
   233
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   234
    mMailboxInfo->setPlainText(mAccountName);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   235
    //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
   236
    //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
   237
    if (mUnreadCount >= 0) {
74
hgs
parents: 68
diff changeset
   238
        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
   239
        mUnreadCountLabel->setPlainText(unreadCount);
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   240
        QFontMetrics fm(mUnreadCountLabel->font());
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   241
        qreal textWidth = fm.width(unreadCount);
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   242
        mUnreadCountLabel->setMaximumWidth(textWidth);
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   243
    }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   244
    else {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   245
        mUnreadCountLabel->setMaximumWidth(0);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   246
    }
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   247
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   248
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   249
/*!
43
hgs
parents: 23
diff changeset
   250
    sets fonts color.
47
hgs
parents: 43
diff changeset
   251
    /param bool pressed indicates if row is pressed down or not
43
hgs
parents: 23
diff changeset
   252
*/
47
hgs
parents: 43
diff changeset
   253
void NmHsWidgetTitleRow::setHighlighedFontsColor( bool pressed )
43
hgs
parents: 23
diff changeset
   254
    {
hgs
parents: 23
diff changeset
   255
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   256
    QColor newFontColor;
hgs
parents: 23
diff changeset
   257
    
hgs
parents: 23
diff changeset
   258
    if(pressed){
hgs
parents: 23
diff changeset
   259
        newFontColor = HbColorScheme::color("qtc_hs_list_item_pressed");
hgs
parents: 23
diff changeset
   260
    }
hgs
parents: 23
diff changeset
   261
    else{
hgs
parents: 23
diff changeset
   262
        newFontColor = HbColorScheme::color("qtc_hs_list_item_title_normal");
hgs
parents: 23
diff changeset
   263
    }
hgs
parents: 23
diff changeset
   264
 
hgs
parents: 23
diff changeset
   265
    mMailboxInfo->setTextColor(newFontColor);
hgs
parents: 23
diff changeset
   266
    mUnreadCountLabel->setTextColor(newFontColor);
hgs
parents: 23
diff changeset
   267
    }
hgs
parents: 23
diff changeset
   268
47
hgs
parents: 43
diff changeset
   269
/*!
hgs
parents: 43
diff changeset
   270
    change background pressed state
hgs
parents: 43
diff changeset
   271
    /param bool show if true then shown, false hide
hgs
parents: 43
diff changeset
   272
*/
hgs
parents: 43
diff changeset
   273
void NmHsWidgetTitleRow::showHighlight( bool show )
hgs
parents: 43
diff changeset
   274
    {
hgs
parents: 43
diff changeset
   275
    NM_FUNCTION;;
hgs
parents: 43
diff changeset
   276
    
hgs
parents: 43
diff changeset
   277
    if(show){
hgs
parents: 43
diff changeset
   278
        mBackgroundLayoutItem->show();
hgs
parents: 43
diff changeset
   279
    }
hgs
parents: 43
diff changeset
   280
    else{
hgs
parents: 43
diff changeset
   281
        mBackgroundLayoutItem->hide();
hgs
parents: 43
diff changeset
   282
    }
hgs
parents: 43
diff changeset
   283
    }
43
hgs
parents: 23
diff changeset
   284
62
hgs
parents: 49
diff changeset
   285
/*
hgs
parents: 49
diff changeset
   286
 * NmHsWidgetTitleRow::gestureEvent(QGestureEvent *event)
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   287
 */
62
hgs
parents: 49
diff changeset
   288
void NmHsWidgetTitleRow::gestureEvent(QGestureEvent *event)
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   289
{
43
hgs
parents: 23
diff changeset
   290
    NM_FUNCTION;
62
hgs
parents: 49
diff changeset
   291
    
hgs
parents: 49
diff changeset
   292
    if(!event){
hgs
parents: 49
diff changeset
   293
        return;
hgs
parents: 49
diff changeset
   294
    }    
hgs
parents: 49
diff changeset
   295
    HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
hgs
parents: 49
diff changeset
   296
    if(!gesture){
hgs
parents: 49
diff changeset
   297
        return;
hgs
parents: 49
diff changeset
   298
    }
hgs
parents: 49
diff changeset
   299
    //to avoid opening email account mistakenly  when tabbing expand/collapse button
hgs
parents: 49
diff changeset
   300
    //we dont handle events that are on the top, down or right side of the button
hgs
parents: 49
diff changeset
   301
    QPointF posFromScene = mapFromScene(event->mapToGraphicsScene(gesture->position()));
68
hgs
parents: 62
diff changeset
   302
    bool inArea = false;
hgs
parents: 62
diff changeset
   303
    
hgs
parents: 62
diff changeset
   304
    if(this->layoutDirection() == Qt::LeftToRight &&  
hgs
parents: 62
diff changeset
   305
       posFromScene.x() < mUnreadCountLabel->geometry().right()) {
hgs
parents: 62
diff changeset
   306
        inArea = true;
hgs
parents: 62
diff changeset
   307
    }
hgs
parents: 62
diff changeset
   308
    else if(this->layoutDirection() == Qt::RightToLeft && 
hgs
parents: 62
diff changeset
   309
            posFromScene.x() > mUnreadCountLabel->geometry().right()) {
hgs
parents: 62
diff changeset
   310
        inArea = true;
hgs
parents: 62
diff changeset
   311
    }
hgs
parents: 62
diff changeset
   312
    
hgs
parents: 62
diff changeset
   313
    if (inArea) {    
62
hgs
parents: 49
diff changeset
   314
        switch (gesture->state()) {
hgs
parents: 49
diff changeset
   315
            case Qt::GestureStarted:
hgs
parents: 49
diff changeset
   316
                setHighlighedFontsColor(true);
hgs
parents: 49
diff changeset
   317
                showHighlight(true);
hgs
parents: 49
diff changeset
   318
            break;
hgs
parents: 49
diff changeset
   319
            case Qt::GestureCanceled:
hgs
parents: 49
diff changeset
   320
                setHighlighedFontsColor(false);
hgs
parents: 49
diff changeset
   321
                showHighlight(false);
hgs
parents: 49
diff changeset
   322
            break;
hgs
parents: 49
diff changeset
   323
            case Qt::GestureFinished:
hgs
parents: 49
diff changeset
   324
                setHighlighedFontsColor(false);
hgs
parents: 49
diff changeset
   325
                showHighlight(false);
hgs
parents: 49
diff changeset
   326
                if (gesture->tapStyleHint() == HbTapGesture::Tap) {
hgs
parents: 49
diff changeset
   327
                    HbInstantFeedback::play(HbFeedback::BasicItem);
hgs
parents: 49
diff changeset
   328
                    emit mailboxLaunchTriggered();
hgs
parents: 49
diff changeset
   329
                }
hgs
parents: 49
diff changeset
   330
            break;
hgs
parents: 49
diff changeset
   331
        default: 
hgs
parents: 49
diff changeset
   332
            break;
47
hgs
parents: 43
diff changeset
   333
        }
62
hgs
parents: 49
diff changeset
   334
    }
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   335
}
43
hgs
parents: 23
diff changeset
   336
hgs
parents: 23
diff changeset
   337
/*
hgs
parents: 23
diff changeset
   338
 * NmHsWidgetTitleRow::event()
hgs
parents: 23
diff changeset
   339
 */
hgs
parents: 23
diff changeset
   340
bool NmHsWidgetTitleRow::event( QEvent *event )
hgs
parents: 23
diff changeset
   341
{
hgs
parents: 23
diff changeset
   342
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   343
    QEvent::Type eventType = event->type();
hgs
parents: 23
diff changeset
   344
    if( eventType == HbEvent::ThemeChanged ){
47
hgs
parents: 43
diff changeset
   345
        setHighlighedFontsColor(false);
43
hgs
parents: 23
diff changeset
   346
        return true;
hgs
parents: 23
diff changeset
   347
    }
hgs
parents: 23
diff changeset
   348
    return HbWidget::event(event);
hgs
parents: 23
diff changeset
   349
}