20 #include <QGraphicsSceneResizeEvent> |
20 #include <QGraphicsSceneResizeEvent> |
21 #include <QDebug> |
21 #include <QDebug> |
22 #include <hbstyle.h> |
22 #include <hbstyle.h> |
23 #include <hbiconitem.h> |
23 #include <hbiconitem.h> |
24 #include <hbstyleloader.h> |
24 #include <hbstyleloader.h> |
|
25 #include <hbdeviceprofile.h> |
25 #include "bubbleimagemanager.h" |
26 #include "bubbleimagemanager.h" |
26 #include "bubbleimagewidget.h" |
27 #include "bubbleimagewidget.h" |
|
28 |
|
29 static const qreal BubbbleImageRounding = 1.5; // units |
27 |
30 |
28 BubbleImageWidget::BubbleImageWidget( |
31 BubbleImageWidget::BubbleImageWidget( |
29 BubbleImageManager& imageManager, |
32 BubbleImageManager& imageManager, |
30 QGraphicsItem* parent) |
33 QGraphicsItem* parent) |
31 : HbWidget(parent), |
34 : HbWidget(parent), |
32 mImageManager(imageManager), |
35 mImageManager(imageManager), |
33 mDefaultAvatar(0), |
36 mDefaultAvatar(0), |
34 mKeepSquareShape(0) |
37 mKeepSquareShape(0) |
35 { |
38 { |
|
39 setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
40 |
36 // create avatar |
41 // create avatar |
37 mDefaultAvatar = new HbIconItem(this); |
42 mDefaultAvatar = new HbIconItem(this); |
38 style()->setItemName( mDefaultAvatar, "default_avatar" ); |
43 style()->setItemName( mDefaultAvatar, "default_avatar" ); |
39 mDefaultAvatar->setAspectRatioMode(Qt::KeepAspectRatioByExpanding); |
44 mDefaultAvatar->setAspectRatioMode(Qt::KeepAspectRatioByExpanding); |
40 mDefaultAvatar->setAlignment(Qt::AlignCenter); |
45 mDefaultAvatar->setAlignment(Qt::AlignCenter); |
41 |
46 |
42 connect(&mImageManager, SIGNAL(pixmapReady(QString)), |
47 connect(&mImageManager, SIGNAL(pixmapReady(QString)), |
43 this, SLOT(imageLoaded(QString))); |
48 this, SLOT(imageLoaded(QString))); |
44 |
49 |
45 HbStyleLoader::registerFilePath(":/bubbleimagewidget.css"); |
50 HbStyleLoader::registerFilePath( |
46 HbStyleLoader::registerFilePath(":/bubbleimagewidget.widgetml"); |
51 QLatin1String(":/bubbleimagewidget.css")); |
|
52 HbStyleLoader::registerFilePath( |
|
53 QLatin1String(":/bubbleimagewidget.widgetml")); |
47 } |
54 } |
48 |
55 |
49 BubbleImageWidget::~BubbleImageWidget() |
56 BubbleImageWidget::~BubbleImageWidget() |
50 { |
57 { |
51 } |
58 } |
58 if (!mImageName.isEmpty()) { |
65 if (!mImageName.isEmpty()) { |
59 mDefaultAvatar->setVisible(false); |
66 mDefaultAvatar->setVisible(false); |
60 mDefaultAvatar->setIcon(HbIcon()); |
67 mDefaultAvatar->setIcon(HbIcon()); |
61 mImageManager.loadImage(mImageName); |
68 mImageManager.loadImage(mImageName); |
62 } else { |
69 } else { |
63 mDefaultAvatar->setIconName("qtg_large_avatar"); |
70 mDefaultAvatar->setIconName(QLatin1String("qtg_large_avatar")); |
64 mDefaultAvatar->setVisible(true); |
71 mDefaultAvatar->setVisible(true); |
65 } |
72 } |
66 } |
73 } |
67 |
74 |
68 void BubbleImageWidget::imageLoaded(QString imageFileName) |
75 void BubbleImageWidget::imageLoaded(QString imageFileName) |
85 |
92 |
86 const QPixmap* pixmap = |
93 const QPixmap* pixmap = |
87 mImageManager.pixmap(mImageName); |
94 mImageManager.pixmap(mImageName); |
88 |
95 |
89 if (pixmap) { |
96 if (pixmap) { |
|
97 painter->save(); |
|
98 |
90 // up or downscales images to fill image area |
99 // up or downscales images to fill image area |
91 QSize imageSize(pixmap->size()); |
100 QSize imageSize(pixmap->size()); |
92 QSize sourceSize(rect().size().toSize()); |
101 QSize sourceSize(rect().size().toSize()); |
93 sourceSize.scale(imageSize,Qt::KeepAspectRatio); |
102 sourceSize.scale(imageSize,Qt::KeepAspectRatio); |
94 QRect sourceRect(QPoint(0,0),sourceSize); |
103 QRect sourceRect(QPoint(0,0),sourceSize); |
97 sourceRect.moveLeft(xOff); |
106 sourceRect.moveLeft(xOff); |
98 sourceRect.moveTop(yOff); |
107 sourceRect.moveTop(yOff); |
99 // qDebug() << "imageSize:" << imageSize; |
108 // qDebug() << "imageSize:" << imageSize; |
100 // qDebug() << "sourceRect:" << sourceRect; |
109 // qDebug() << "sourceRect:" << sourceRect; |
101 painter->setRenderHint(QPainter::SmoothPixmapTransform); |
110 painter->setRenderHint(QPainter::SmoothPixmapTransform); |
|
111 painter->setRenderHint(QPainter::Antialiasing); |
|
112 |
|
113 QPainterPath clip; |
|
114 qreal rounding = BubbbleImageRounding * |
|
115 HbDeviceProfile::profile(this).unitValue(); |
|
116 clip.addRoundedRect(rect(), rounding, rounding); |
|
117 painter->setClipPath(clip); |
102 |
118 |
103 #ifdef __WINS__ |
119 #ifdef __WINS__ |
104 // sourceRect crashes emulator, RC ou1cimx1#320113 |
120 // sourceRect crashes emulator, RC ou1cimx1#320113 |
105 painter->drawPixmap(rect().toRect(),*pixmap); |
121 painter->drawPixmap(rect().toRect(),*pixmap); |
106 #else |
122 #else |
107 painter->drawPixmap(rect().toRect(),*pixmap,sourceRect); |
123 painter->drawPixmap(rect().toRect(),*pixmap,sourceRect); |
108 #endif |
124 #endif |
109 |
125 painter->restore(); |
110 } |
126 } |
111 } |
127 } |
112 |
128 |
113 QSizeF BubbleImageWidget::sizeHint( |
129 QSizeF BubbleImageWidget::sizeHint( |
114 Qt::SizeHint which, |
130 Qt::SizeHint which, |