phoneuis/bubblemanager2/bubblecore/src/bubbleimagewidget.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 06 Jul 2010 14:15:47 +0300
changeset 46 bc5a64e5bc3c
parent 45 6b911d05207e
child 50 377c906a8701
child 51 f39ed5e045e0
permissions -rw-r--r--
Revision: 201025 Kit: 2010127
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     1
/*!
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     3
* All rights reserved.
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     8
*
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     9
* Initial Contributors:
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    11
*
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    12
* Contributors:
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    13
*
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    14
* Description:  Widget to display contact image.
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    15
*               Displays default avatar, when image is not set.
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    16
*
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    17
*/
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    18
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    19
#include <QPainter>
45
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
    20
#include <QGraphicsSceneResizeEvent>
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
    21
#include <QDebug>
37
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    22
#include <hbstyle.h>
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    23
#include <hbiconitem.h>
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    24
#include <hbstyleloader.h>
46
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
    25
#include <hbdeviceprofile.h>
37
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    26
#include "bubbleimagemanager.h"
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    27
#include "bubbleimagewidget.h"
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    28
46
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
    29
static const qreal BubbbleImageRounding = 1.5; // units
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
    30
37
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    31
BubbleImageWidget::BubbleImageWidget(
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    32
    BubbleImageManager& imageManager,
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    33
    QGraphicsItem* parent)
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    34
    : HbWidget(parent),
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    35
      mImageManager(imageManager),
45
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
    36
      mDefaultAvatar(0),
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
    37
      mKeepSquareShape(0)
37
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    38
{
46
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
    39
    setFlag(QGraphicsItem::ItemHasNoContents, false);
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
    40
37
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    41
    // create avatar
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    42
    mDefaultAvatar = new HbIconItem(this);
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    43
    style()->setItemName( mDefaultAvatar, "default_avatar" );
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    44
    mDefaultAvatar->setAspectRatioMode(Qt::KeepAspectRatioByExpanding);
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    45
    mDefaultAvatar->setAlignment(Qt::AlignCenter);
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    46
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    47
    connect(&mImageManager, SIGNAL(pixmapReady(QString)),
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    48
            this, SLOT(imageLoaded(QString)));
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    49
46
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
    50
    HbStyleLoader::registerFilePath(
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
    51
        QLatin1String(":/bubbleimagewidget.css"));
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
    52
    HbStyleLoader::registerFilePath(
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
    53
        QLatin1String(":/bubbleimagewidget.widgetml"));
37
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    54
}
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    55
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    56
BubbleImageWidget::~BubbleImageWidget()
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    57
{
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    58
}
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    59
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    60
void BubbleImageWidget::setImage(const QString& name)
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    61
{
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    62
    mImageName = name;
45
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
    63
    mUpdateCount = 0;
37
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    64
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    65
    if (!mImageName.isEmpty()) {
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    66
        mDefaultAvatar->setVisible(false);
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    67
        mDefaultAvatar->setIcon(HbIcon());
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    68
        mImageManager.loadImage(mImageName);
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    69
    } else {
46
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
    70
        mDefaultAvatar->setIconName(QLatin1String("qtg_large_avatar"));
37
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    71
        mDefaultAvatar->setVisible(true);
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    72
    }
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    73
}
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    74
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    75
void BubbleImageWidget::imageLoaded(QString imageFileName)
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    76
{
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    77
    if (imageFileName==mImageName) {
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    78
        update(); // does nothing if invisible
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    79
    }
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    80
}
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    81
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    82
void BubbleImageWidget::paint(
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    83
    QPainter* painter,
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    84
    const QStyleOptionGraphicsItem* option,
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    85
    QWidget* widget)
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    86
{
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    87
    Q_UNUSED(option);
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    88
    Q_UNUSED(widget);
45
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
    89
37
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    90
    if (mImageName.isEmpty())
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    91
        return;
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    92
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    93
    const QPixmap* pixmap =
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    94
        mImageManager.pixmap(mImageName);
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    95
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    96
    if (pixmap) {
46
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
    97
        painter->save();
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
    98
37
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    99
        // up or downscales images to fill image area
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   100
        QSize imageSize(pixmap->size());
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   101
        QSize sourceSize(rect().size().toSize());
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   102
        sourceSize.scale(imageSize,Qt::KeepAspectRatio);
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   103
        QRect sourceRect(QPoint(0,0),sourceSize);
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   104
        int xOff = (imageSize.width() - sourceSize.width())/2;
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   105
        int yOff = (imageSize.height() - sourceSize.height())/2;
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   106
        sourceRect.moveLeft(xOff);
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   107
        sourceRect.moveTop(yOff);
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   108
        // qDebug() << "imageSize:" << imageSize;
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   109
        // qDebug() << "sourceRect:" << sourceRect;
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   110
        painter->setRenderHint(QPainter::SmoothPixmapTransform);
46
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
   111
        painter->setRenderHint(QPainter::Antialiasing);
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
   112
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
   113
        QPainterPath clip;
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
   114
        qreal rounding = BubbbleImageRounding *
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
   115
                         HbDeviceProfile::profile(this).unitValue();
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
   116
        clip.addRoundedRect(rect(), rounding, rounding);
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
   117
        painter->setClipPath(clip);
37
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   118
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   119
#ifdef __WINS__
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   120
        // sourceRect crashes emulator, RC ou1cimx1#320113
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   121
        painter->drawPixmap(rect().toRect(),*pixmap);
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   122
#else        
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   123
        painter->drawPixmap(rect().toRect(),*pixmap,sourceRect);
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   124
#endif        
46
bc5a64e5bc3c Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 45
diff changeset
   125
        painter->restore();
37
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   126
    }
ba76fc04e6c2 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   127
}
45
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   128
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   129
QSizeF BubbleImageWidget::sizeHint(
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   130
    Qt::SizeHint which,
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   131
    const QSizeF & constraint) const
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   132
{
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   133
    Q_UNUSED(which);
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   134
    Q_UNUSED(constraint);
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   135
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   136
    if (mKeepSquareShape && which==Qt::PreferredSize ) {
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   137
        QSizeF hint(size().height(), size().height());
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   138
        if (hint.isNull()) {
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   139
            hint = QSizeF(100,100);
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   140
        }
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   141
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   142
        // workaround, sometimes last resize event is missing
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   143
        if ((size().width()!=size().height()) && (mUpdateCount<10)) {
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   144
            BubbleImageWidget* mutableThis = const_cast<BubbleImageWidget*>(this);
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   145
            mutableThis->updateGeometry();
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   146
            mutableThis->mUpdateCount++; // prevent looping
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   147
        }
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   148
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   149
        // qDebug() << "size hint: " << hint;
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   150
        return hint;
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   151
    } else {
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   152
        return HbWidget::sizeHint(which,constraint);
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   153
    }
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   154
}
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   155
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   156
void BubbleImageWidget::resizeEvent(QGraphicsSceneResizeEvent * event)
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   157
{
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   158
    // qDebug() << "size:" << event->newSize();
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   159
    if ( event->newSize().height()!= event->oldSize().height() &&
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   160
         event->newSize().height() > 1 ) {
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   161
        updateGeometry();
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   162
    }
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   163
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   164
    HbWidget::resizeEvent(event);
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   165
}
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   166
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   167
bool BubbleImageWidget::keepSquareShape() const
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   168
{
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   169
    return mKeepSquareShape;
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   170
}
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   171
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   172
void BubbleImageWidget::setKeepSquareShape(bool keepSquare)
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   173
{
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   174
    mKeepSquareShape = keepSquare;
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   175
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   176
    if (mKeepSquareShape) {
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   177
        setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   178
    } else {
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   179
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   180
    }
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   181
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   182
    updateGeometry();
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   183
}
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   184
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   185
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   186
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   187
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   188
6b911d05207e Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 37
diff changeset
   189