--- a/emailuis/nmailuiwidgets/src/nmattachmentlistitem.cpp Mon May 24 21:02:02 2010 +0300
+++ b/emailuis/nmailuiwidgets/src/nmattachmentlistitem.cpp Fri May 28 13:56:43 2010 +0300
@@ -23,7 +23,6 @@
static const int PROGRESSBAR_MIN = 0;
static const int PROGRESSBAR_MAX = 100;
static const int PROGRESSBAR_HIDE_COUNTDOWN = 500;
-static const int LONGPRESS_TIMER = 2000;
// Hardcoded file size length. Maximum (999.9 Mb) fits into size field.
static const int FILE_SIZE_FIELD_LENGTH = 120;
@@ -47,12 +46,15 @@
: HbWidget( parent ),
mFileNameText(NULL),
mFileSizeText(NULL),
- mProgressBar(NULL),
- mTimer(NULL),
- mButtonPressed(false),
- mLongPressedPoint(0,0)
+ mProgressBar(NULL)
{
+ NM_FUNCTION;
+
init( );
+
+ // Informs GestureFramework that NmAttachmentListItem widget is interested
+ // Tap gesture and TapAndHold gesture.
+ grabGesture(Qt::TapGesture);
}
/*!
@@ -61,6 +63,8 @@
*/
void NmAttachmentListItem::setTextColor(const QColor color)
{
+ NM_FUNCTION;
+
mTextColor=color;
}
@@ -69,11 +73,10 @@
*/
NmAttachmentListItem::~NmAttachmentListItem( )
{
+ NM_FUNCTION;
+
HbStyleLoader::unregisterFilePath(FILE_PATH_WIDGETML);
HbStyleLoader::unregisterFilePath(FILE_PATH_CSS);
-
- delete mTimer;
- mTimer = NULL;
}
/*!
@@ -81,6 +84,8 @@
*/
void NmAttachmentListItem::setFileNameText(const QString &fileName)
{
+ NM_FUNCTION;
+
if (mFileNameText){
if (mTextColor.isValid()){
mFileNameText->setTextColor(mTextColor);
@@ -95,6 +100,8 @@
*/
void NmAttachmentListItem::setFileSizeText(const QString &fileSize)
{
+ NM_FUNCTION;
+
if (mFileSizeText){
if (mTextColor.isValid()){
mFileSizeText->setTextColor(mTextColor);
@@ -109,6 +116,8 @@
*/
void NmAttachmentListItem::resetFileNameLength(Qt::Orientation orientation)
{
+ NM_FUNCTION;
+
QSizeF reso = screenSize(orientation);
if (orientation == Qt::Horizontal) {
@@ -124,6 +133,8 @@
*/
void NmAttachmentListItem::setProgressBarValue(const int value)
{
+ NM_FUNCTION;
+
//first check if value is 0 or below -> hide progressbar
if ( 0 >= value ){
removeProgressBar();
@@ -150,6 +161,8 @@
*/
int NmAttachmentListItem::progressBarValue() const
{
+ NM_FUNCTION;
+
int ret = 0;
if ( mProgressBar ){
ret = mProgressBar->progressValue();
@@ -163,6 +176,8 @@
*/
void NmAttachmentListItem::hideProgressBar()
{
+ NM_FUNCTION;
+
QTimer::singleShot(PROGRESSBAR_HIDE_COUNTDOWN,this, SLOT(removeProgressBar()));
}
@@ -171,16 +186,13 @@
*/
void NmAttachmentListItem::init( )
{
+ NM_FUNCTION;
+
constructUi();
//set default values
setFlag(QGraphicsItem::ItemIsFocusable);
setFlag(QGraphicsItem::ItemIsSelectable);
-
- //set temporary longpress timer
- mTimer = new QTimer(this);
- mTimer->setSingleShot(true);
- connect(mTimer, SIGNAL(timeout()), this, SLOT(longPressedActivated()));
}
/*!
@@ -188,6 +200,8 @@
*/
void NmAttachmentListItem::constructUi()
{
+ NM_FUNCTION;
+
//construct default ui.
HbStyleLoader::registerFilePath(FILE_PATH_WIDGETML);
HbStyleLoader::registerFilePath(FILE_PATH_CSS);
@@ -205,38 +219,12 @@
/*!
- \reimp
- */
-void NmAttachmentListItem::mousePressEvent( QGraphicsSceneMouseEvent *event )
-{
- NMLOG("NmAttachmentListItem::mousePressEvent");
-
- mButtonPressed = true;
- mLongPressedPoint = event->scenePos();
- if(mTimer){
- mTimer->start(LONGPRESS_TIMER);
- }
-}
-
-/*!
- \reimp
- */
-void NmAttachmentListItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
-{
- Q_UNUSED(event);
- NMLOG("NmAttachmentListItem::mouseReleasedEvent");
- if ( mTimer && mButtonPressed ){
- emit itemActivated();
- mButtonPressed = false;
- mTimer->stop();
- }
-}
-
-/*!
Hides the download progress bar
*/
void NmAttachmentListItem::removeProgressBar()
{
+ NM_FUNCTION;
+
if ( mProgressBar ){
HbStyle::setItemName( mProgressBar, "" );
mProgressBar->deleteLater();
@@ -245,18 +233,6 @@
}
}
-/*!
-
- */
-void NmAttachmentListItem::longPressedActivated()
-{
- //check first if button is not released already
- if ( mButtonPressed ){
- NMLOG("NmAttachmentListItem::longPressedActivated");
- emit itemLongPressed(mLongPressedPoint);
- mButtonPressed = false;
- }
-}
/*!
This function returns screen size depending on the orientation.
@@ -264,6 +240,8 @@
*/
QSize NmAttachmentListItem::screenSize(Qt::Orientation orientation)
{
+ NM_FUNCTION;
+
QSize ret(0,0);
HbDeviceProfile currentP = HbDeviceProfile::current();
HbDeviceProfile altP(currentP.alternateProfileName());
@@ -290,3 +268,35 @@
return ret;
}
+/*!
+ This function handles gestures
+ */
+void NmAttachmentListItem::gestureEvent(QGestureEvent *event)
+{
+ NM_FUNCTION;
+
+ if (HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
+ switch(tap->tapStyleHint()) {
+ case HbTapGesture::Tap:
+ {
+ if (tap->state() == Qt::GestureFinished) {
+ emit itemActivated();
+ }
+ }
+ break;
+
+ case HbTapGesture::TapAndHold:
+ {
+ if (tap->state() == Qt::GestureFinished) {
+ emit itemLongPressed(event->mapToGraphicsScene(tap->position()));
+ }
+ }
+ break;
+ }
+ }
+ else {
+ HbWidget::gestureEvent(event);
+ }
+}
+
+