emailuis/nmailuiwidgets/src/nmattachmentlistitem.cpp
author hgs
Fri, 03 Sep 2010 14:07:42 +0300
changeset 66 084b5b1f02a7
parent 62 a8c646b56683
permissions -rw-r--r--
201035
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: Attachment list item widget
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
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
#include "nmailuiwidgetsheaders.h"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
static const QString FILE_PATH_WIDGETML = ":nmattachmentlistitem.widgetml";
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
static const QString FILE_PATH_CSS = ":nmattachmentlistitem.css";
62
hgs
parents: 56
diff changeset
    22
static const QString LIST_ITEM_BG_FRAME_NORMAL ("qtg_fr_list_normal");
hgs
parents: 56
diff changeset
    23
static const QString LIST_ITEM_BG_FRAME_PRESSED("qtg_fr_list_pressed");
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    25
static const int PROGRESSBAR_MIN = 0; 
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
static const int PROGRESSBAR_MAX = 100;
66
hgs
parents: 62
diff changeset
    27
static const int PROGRESSBAR_HIDE_COUNTDOWN = 500; // Milliseconds
hgs
parents: 62
diff changeset
    28
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
/*!
66
hgs
parents: 62
diff changeset
    31
    @nmailuiwidgets
hgs
parents: 62
diff changeset
    32
hgs
parents: 62
diff changeset
    33
    \class NmAttachmentListItem
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
66
hgs
parents: 62
diff changeset
    35
    \brief  NmAttachmentListItem is a widget used for displaying a single
hgs
parents: 62
diff changeset
    36
            attachment with the attachment file size and download progress in
hgs
parents: 62
diff changeset
    37
            the attachment list.
hgs
parents: 62
diff changeset
    38
*/
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
/*!
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
    Constructs a new NmAttachmentListItem with \a parent.
66
hgs
parents: 62
diff changeset
    43
*/
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    44
NmAttachmentListItem::NmAttachmentListItem(QGraphicsItem *parent)
66
hgs
parents: 62
diff changeset
    45
: HbWidget( parent ),
hgs
parents: 62
diff changeset
    46
  mFileNameText(NULL),
hgs
parents: 62
diff changeset
    47
  mFileSizeText(NULL),
hgs
parents: 62
diff changeset
    48
  mProgressBar(NULL),
hgs
parents: 62
diff changeset
    49
  mBackground(NULL)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    50
{
43
hgs
parents: 23
diff changeset
    51
    NM_FUNCTION;
66
hgs
parents: 62
diff changeset
    52
hgs
parents: 62
diff changeset
    53
    init();
43
hgs
parents: 23
diff changeset
    54
	
hgs
parents: 23
diff changeset
    55
    // Informs GestureFramework that NmAttachmentListItem widget is interested 
66
hgs
parents: 62
diff changeset
    56
    // in Tap and TapAndHold gestures.
43
hgs
parents: 23
diff changeset
    57
    grabGesture(Qt::TapGesture);
62
hgs
parents: 56
diff changeset
    58
    HbEffect::add("mailAttachmentWidget", "listviewitem_press", "pressed");
hgs
parents: 56
diff changeset
    59
    HbEffect::add("mailAttachmentWidget", "listviewitem_release", "released");
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    61
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    62
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    63
/*!
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    64
    Destructor.
66
hgs
parents: 62
diff changeset
    65
*/
hgs
parents: 62
diff changeset
    66
NmAttachmentListItem::~NmAttachmentListItem()
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
{
43
hgs
parents: 23
diff changeset
    68
    NM_FUNCTION;
hgs
parents: 23
diff changeset
    69
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    70
    HbStyleLoader::unregisterFilePath(FILE_PATH_WIDGETML);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
    HbStyleLoader::unregisterFilePath(FILE_PATH_CSS);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
66
hgs
parents: 62
diff changeset
    74
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    75
/*!
66
hgs
parents: 62
diff changeset
    76
    Setter for items text color override. This method can be used if the theme
hgs
parents: 62
diff changeset
    77
    background is not used and text needs to be shown with a different color.
hgs
parents: 62
diff changeset
    78
hgs
parents: 62
diff changeset
    79
    \param color The new test color.
hgs
parents: 62
diff changeset
    80
*/
hgs
parents: 62
diff changeset
    81
void NmAttachmentListItem::setTextColor(const QColor color)
hgs
parents: 62
diff changeset
    82
{
hgs
parents: 62
diff changeset
    83
    NM_FUNCTION;
hgs
parents: 62
diff changeset
    84
    
hgs
parents: 62
diff changeset
    85
    mTextColor = color;
hgs
parents: 62
diff changeset
    86
hgs
parents: 62
diff changeset
    87
    if (mTextColor.isValid() && mFileNameText) {
hgs
parents: 62
diff changeset
    88
        mFileNameText->setTextColor(mTextColor);
hgs
parents: 62
diff changeset
    89
    }
hgs
parents: 62
diff changeset
    90
}
hgs
parents: 62
diff changeset
    91
hgs
parents: 62
diff changeset
    92
hgs
parents: 62
diff changeset
    93
/*!
hgs
parents: 62
diff changeset
    94
    Sets the background color. This method can be used to override the
hgs
parents: 62
diff changeset
    95
    default background color set by the current theme. Because of the effect,
hgs
parents: 62
diff changeset
    96
    the implementation "smoke and mirrors" but it works.
hgs
parents: 62
diff changeset
    97
hgs
parents: 62
diff changeset
    98
    \param color The new background color.
hgs
parents: 62
diff changeset
    99
*/
hgs
parents: 62
diff changeset
   100
void NmAttachmentListItem::setBackgroundColor(const QColor color)
hgs
parents: 62
diff changeset
   101
{
hgs
parents: 62
diff changeset
   102
    NM_FUNCTION;
hgs
parents: 62
diff changeset
   103
hgs
parents: 62
diff changeset
   104
    if (!color.isValid()) {
hgs
parents: 62
diff changeset
   105
        // Invalid color!
hgs
parents: 62
diff changeset
   106
        return;
hgs
parents: 62
diff changeset
   107
    }
hgs
parents: 62
diff changeset
   108
hgs
parents: 62
diff changeset
   109
    mBackgroundColor = color;
hgs
parents: 62
diff changeset
   110
hgs
parents: 62
diff changeset
   111
    // The effect color is the opposite color of the background color.
hgs
parents: 62
diff changeset
   112
    QColor effectColor(qAbs(color.red() - 255),
hgs
parents: 62
diff changeset
   113
                       qAbs(color.green() - 255),
hgs
parents: 62
diff changeset
   114
                       qAbs(color.blue() - 255));
hgs
parents: 62
diff changeset
   115
    
hgs
parents: 62
diff changeset
   116
    QPalette palette = QApplication::palette();
hgs
parents: 62
diff changeset
   117
    QBrush brush(effectColor);
hgs
parents: 62
diff changeset
   118
    palette.setBrush(QPalette::Window, effectColor);
hgs
parents: 62
diff changeset
   119
    setPalette(palette);
hgs
parents: 62
diff changeset
   120
    setAutoFillBackground(true);
hgs
parents: 62
diff changeset
   121
hgs
parents: 62
diff changeset
   122
    if (mBackground) {
hgs
parents: 62
diff changeset
   123
        // Set the background color for the background item.
hgs
parents: 62
diff changeset
   124
        brush.setColor(mBackgroundColor);
hgs
parents: 62
diff changeset
   125
        palette.setBrush(QPalette::Window, brush);
hgs
parents: 62
diff changeset
   126
        mBackground->setPalette(palette);
hgs
parents: 62
diff changeset
   127
        mBackground->setAutoFillBackground(true);
hgs
parents: 62
diff changeset
   128
        mBackground->frameDrawer().setFrameType(HbFrameDrawer::OnePiece);
hgs
parents: 62
diff changeset
   129
    }
hgs
parents: 62
diff changeset
   130
hgs
parents: 62
diff changeset
   131
    repolish();
hgs
parents: 62
diff changeset
   132
}
hgs
parents: 62
diff changeset
   133
hgs
parents: 62
diff changeset
   134
hgs
parents: 62
diff changeset
   135
/*!
hgs
parents: 62
diff changeset
   136
    Sets the text to be displayed in the file name item.
hgs
parents: 62
diff changeset
   137
hgs
parents: 62
diff changeset
   138
    \param filename The filename.
hgs
parents: 62
diff changeset
   139
*/
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   140
void NmAttachmentListItem::setFileNameText(const QString &fileName)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   141
{
43
hgs
parents: 23
diff changeset
   142
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   143
    
66
hgs
parents: 62
diff changeset
   144
    if (mFileNameText) {
hgs
parents: 62
diff changeset
   145
        if (mTextColor.isValid()) {
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   146
            mFileNameText->setTextColor(mTextColor);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   147
        }
66
hgs
parents: 62
diff changeset
   148
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   149
        mFileNameText->setTextWrapping(Hb::TextNoWrap);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   150
        mFileNameText->setText(fileName);    
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   151
    }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   152
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   153
66
hgs
parents: 62
diff changeset
   154
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   155
/*!
66
hgs
parents: 62
diff changeset
   156
    Sets the value of the text for displaying the attachment file size.
hgs
parents: 62
diff changeset
   157
    
hgs
parents: 62
diff changeset
   158
    \param fileSize The file size as a string.
hgs
parents: 62
diff changeset
   159
*/
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   160
void NmAttachmentListItem::setFileSizeText(const QString &fileSize)
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   161
{
43
hgs
parents: 23
diff changeset
   162
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   163
    
66
hgs
parents: 62
diff changeset
   164
    if (mFileSizeText) {
hgs
parents: 62
diff changeset
   165
        if (mTextColor.isValid()) {
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   166
            mFileSizeText->setTextColor(mTextColor);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   167
        }
66
hgs
parents: 62
diff changeset
   168
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   169
        mFileSizeText->setTextWrapping(Hb::TextNoWrap);
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   170
        mFileSizeText->setText(fileSize);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   171
    }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   172
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   173
66
hgs
parents: 62
diff changeset
   174
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   175
/*!
66
hgs
parents: 62
diff changeset
   176
    Set the download progress bar value (0 - 100 %). If the given value is 0,
hgs
parents: 62
diff changeset
   177
    the progress bar is hidden.
hgs
parents: 62
diff changeset
   178
hgs
parents: 62
diff changeset
   179
    \param value The progress bar value.
hgs
parents: 62
diff changeset
   180
*/
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   181
void NmAttachmentListItem::setProgressBarValue(const int value)
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   182
{
43
hgs
parents: 23
diff changeset
   183
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   184
    
66
hgs
parents: 62
diff changeset
   185
    // First check if the value is 0 or below -> hide progressbar.
hgs
parents: 62
diff changeset
   186
    if (0 >= value) {
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   187
        removeProgressBar();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   188
        return;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   189
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   190
66
hgs
parents: 62
diff changeset
   191
    if (!mProgressBar) {
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   192
        mProgressBar = new HbProgressBar(this); 
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   193
        mProgressBar->setObjectName("attachmentlistitem_progress");
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   194
        mProgressBar->setRange(PROGRESSBAR_MIN,PROGRESSBAR_MAX);
66
hgs
parents: 62
diff changeset
   195
        HbStyle::setItemName(mProgressBar, "progressbar");
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   196
        repolish();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   197
    }
66
hgs
parents: 62
diff changeset
   198
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   199
    mProgressBar->setProgressValue(value);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   200
    
66
hgs
parents: 62
diff changeset
   201
    // Start hiding the count down.
hgs
parents: 62
diff changeset
   202
    if (PROGRESSBAR_MAX <= value){
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   203
        hideProgressBar();
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   204
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   205
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   206
66
hgs
parents: 62
diff changeset
   207
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   208
/*!
66
hgs
parents: 62
diff changeset
   209
    \return The value of the download progress bar.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   210
*/
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   211
int NmAttachmentListItem::progressBarValue() const
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   212
{
43
hgs
parents: 23
diff changeset
   213
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   214
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   215
    int ret = 0;
66
hgs
parents: 62
diff changeset
   216
hgs
parents: 62
diff changeset
   217
    if (mProgressBar) {
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   218
        ret = mProgressBar->progressValue();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   219
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   220
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   221
    return ret;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   222
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   223
66
hgs
parents: 62
diff changeset
   224
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   225
/*!
66
hgs
parents: 62
diff changeset
   226
    Hides the progress bar. Used if the download is cancelled before 100
hgs
parents: 62
diff changeset
   227
    percent is reached.
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   228
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   229
void NmAttachmentListItem::hideProgressBar()
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   230
{
43
hgs
parents: 23
diff changeset
   231
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   232
    
66
hgs
parents: 62
diff changeset
   233
    QTimer::singleShot(PROGRESSBAR_HIDE_COUNTDOWN, this, SLOT(removeProgressBar()));
hgs
parents: 62
diff changeset
   234
}
hgs
parents: 62
diff changeset
   235
hgs
parents: 62
diff changeset
   236
hgs
parents: 62
diff changeset
   237
/*!
hgs
parents: 62
diff changeset
   238
    Displays a visual effect according to the current pressed state.
hgs
parents: 62
diff changeset
   239
hgs
parents: 62
diff changeset
   240
    \param pressed True, if the item was pressed.
hgs
parents: 62
diff changeset
   241
*/
hgs
parents: 62
diff changeset
   242
void NmAttachmentListItem::setPressed(bool pressed)
hgs
parents: 62
diff changeset
   243
{
hgs
parents: 62
diff changeset
   244
    if (pressed) {
hgs
parents: 62
diff changeset
   245
        setProperty("state", "pressed");
hgs
parents: 62
diff changeset
   246
        mBackground->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_PRESSED);
hgs
parents: 62
diff changeset
   247
        HbEffect::cancel(mBackground, "released");
hgs
parents: 62
diff changeset
   248
        HbEffect::start(mBackground, "mailAttachmentWidget", "pressed");
hgs
parents: 62
diff changeset
   249
    }
hgs
parents: 62
diff changeset
   250
    else {
hgs
parents: 62
diff changeset
   251
        setProperty("state", "normal");
hgs
parents: 62
diff changeset
   252
        mBackground->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
hgs
parents: 62
diff changeset
   253
        HbEffect::cancel(mBackground, "pressed");
hgs
parents: 62
diff changeset
   254
        HbEffect::start(mBackground, "mailAttachmentWidget", "released");
hgs
parents: 62
diff changeset
   255
    }    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   256
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   257
66
hgs
parents: 62
diff changeset
   258
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   259
/*!
66
hgs
parents: 62
diff changeset
   260
    Handles the given gesture event.
hgs
parents: 62
diff changeset
   261
hgs
parents: 62
diff changeset
   262
    \param event The event to handle.
hgs
parents: 62
diff changeset
   263
*/
hgs
parents: 62
diff changeset
   264
void NmAttachmentListItem::gestureEvent(QGestureEvent *event)
hgs
parents: 62
diff changeset
   265
{
hgs
parents: 62
diff changeset
   266
    NM_FUNCTION;
hgs
parents: 62
diff changeset
   267
    
hgs
parents: 62
diff changeset
   268
    if (HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
hgs
parents: 62
diff changeset
   269
        switch (tap->tapStyleHint()) {
hgs
parents: 62
diff changeset
   270
            case HbTapGesture::Tap: {
hgs
parents: 62
diff changeset
   271
                Qt::GestureState state = tap->state();
hgs
parents: 62
diff changeset
   272
                HbInstantFeedback::play(HbFeedback::Basic);
hgs
parents: 62
diff changeset
   273
                setPressed(true);
hgs
parents: 62
diff changeset
   274
hgs
parents: 62
diff changeset
   275
                if (state == Qt::GestureFinished) {
hgs
parents: 62
diff changeset
   276
                    emit itemActivated();
hgs
parents: 62
diff changeset
   277
                    setPressed(false);
hgs
parents: 62
diff changeset
   278
                }
hgs
parents: 62
diff changeset
   279
                else if (state == Qt::GestureCanceled) {
hgs
parents: 62
diff changeset
   280
                    setPressed(false);
hgs
parents: 62
diff changeset
   281
                }
hgs
parents: 62
diff changeset
   282
hgs
parents: 62
diff changeset
   283
                break;
hgs
parents: 62
diff changeset
   284
            }
hgs
parents: 62
diff changeset
   285
            case HbTapGesture::TapAndHold: {
hgs
parents: 62
diff changeset
   286
                emit itemLongPressed(event->mapToGraphicsScene(tap->position()));
hgs
parents: 62
diff changeset
   287
                setPressed(false);    
hgs
parents: 62
diff changeset
   288
                break;
hgs
parents: 62
diff changeset
   289
            }
hgs
parents: 62
diff changeset
   290
        } // switch
hgs
parents: 62
diff changeset
   291
    }
hgs
parents: 62
diff changeset
   292
    else {
hgs
parents: 62
diff changeset
   293
        // Let the HbWidget handle the event.
hgs
parents: 62
diff changeset
   294
        HbWidget::gestureEvent(event);
hgs
parents: 62
diff changeset
   295
    }
hgs
parents: 62
diff changeset
   296
}
hgs
parents: 62
diff changeset
   297
hgs
parents: 62
diff changeset
   298
hgs
parents: 62
diff changeset
   299
/*!
hgs
parents: 62
diff changeset
   300
    Hides and deletes the download progress bar.
hgs
parents: 62
diff changeset
   301
*/
hgs
parents: 62
diff changeset
   302
void NmAttachmentListItem::removeProgressBar()
hgs
parents: 62
diff changeset
   303
{
hgs
parents: 62
diff changeset
   304
    NM_FUNCTION;
hgs
parents: 62
diff changeset
   305
    
hgs
parents: 62
diff changeset
   306
    if (mProgressBar) {
hgs
parents: 62
diff changeset
   307
        HbStyle::setItemName(mProgressBar, "");
hgs
parents: 62
diff changeset
   308
        mProgressBar->deleteLater();
hgs
parents: 62
diff changeset
   309
        mProgressBar = 0;
hgs
parents: 62
diff changeset
   310
        repolish();
hgs
parents: 62
diff changeset
   311
    }
hgs
parents: 62
diff changeset
   312
}
hgs
parents: 62
diff changeset
   313
hgs
parents: 62
diff changeset
   314
hgs
parents: 62
diff changeset
   315
/*!
hgs
parents: 62
diff changeset
   316
    Initializes the widget.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   317
*/
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   318
void NmAttachmentListItem::init( )
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   319
{
43
hgs
parents: 23
diff changeset
   320
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   321
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   322
    constructUi();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   323
66
hgs
parents: 62
diff changeset
   324
    // Set the default flag values.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   325
    setFlag(QGraphicsItem::ItemIsFocusable);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   326
    setFlag(QGraphicsItem::ItemIsSelectable);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   327
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   328
66
hgs
parents: 62
diff changeset
   329
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   330
/*!
66
hgs
parents: 62
diff changeset
   331
    Constructs the UI, sets style item names etc.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   332
*/
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   333
void NmAttachmentListItem::constructUi()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   334
{
43
hgs
parents: 23
diff changeset
   335
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   336
    
66
hgs
parents: 62
diff changeset
   337
    // Background
hgs
parents: 62
diff changeset
   338
    QScopedPointer<HbFrameItem> background(new HbFrameItem(this));
hgs
parents: 62
diff changeset
   339
    background->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
hgs
parents: 62
diff changeset
   340
    background->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
hgs
parents: 62
diff changeset
   341
    setBackgroundItem(background.data());
hgs
parents: 62
diff changeset
   342
hgs
parents: 62
diff changeset
   343
    // The ownership was transferred to the base class.
hgs
parents: 62
diff changeset
   344
    mBackground = background.take();
62
hgs
parents: 56
diff changeset
   345
    
66
hgs
parents: 62
diff changeset
   346
    // Construct the default UI.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   347
    HbStyleLoader::registerFilePath(FILE_PATH_WIDGETML);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   348
    HbStyleLoader::registerFilePath(FILE_PATH_CSS);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   349
    
62
hgs
parents: 56
diff changeset
   350
    QScopedPointer<HbTextItem> fileNameText(new HbTextItem(this));
hgs
parents: 56
diff changeset
   351
    fileNameText->setObjectName("nmattachmentlistitem_filenametext");
66
hgs
parents: 62
diff changeset
   352
    HbStyle::setItemName(fileNameText.data(), "filename");
62
hgs
parents: 56
diff changeset
   353
    fileNameText->setElideMode(Qt::ElideRight);
hgs
parents: 56
diff changeset
   354
    
hgs
parents: 56
diff changeset
   355
    QScopedPointer<HbTextItem> fileSizeText(new HbTextItem(this));
hgs
parents: 56
diff changeset
   356
    fileSizeText->setObjectName("nmattachmentlistitem_filenamesize");
66
hgs
parents: 62
diff changeset
   357
    HbStyle::setItemName(fileSizeText.data(), "filesize");
62
hgs
parents: 56
diff changeset
   358
    fileSizeText->setElideMode(Qt::ElideNone);
hgs
parents: 56
diff changeset
   359
    
66
hgs
parents: 62
diff changeset
   360
    // The ownership was transferred to this instance.
62
hgs
parents: 56
diff changeset
   361
    mFileSizeText = fileSizeText.take(); 
hgs
parents: 56
diff changeset
   362
    mFileNameText = fileNameText.take();
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   363
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   364
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   365
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   366
66
hgs
parents: 62
diff changeset
   367
// End of file.