16 * |
16 * |
17 */ |
17 */ |
18 |
18 |
19 #include <QPainter> |
19 #include <QPainter> |
20 #include <hbstyle.h> |
20 #include <hbstyle.h> |
|
21 #include <hbiconitem.h> |
|
22 #include <hbstyleloader.h> |
21 #include "bubbleimagemanager.h" |
23 #include "bubbleimagemanager.h" |
22 #include "bubbleimagewidget.h" |
24 #include "bubbleimagewidget.h" |
23 #include "bubbleprimitives.h" |
|
24 #include "bubblestyleoption.h" |
|
25 |
25 |
26 BubbleImageWidget::BubbleImageWidget(const QString& stylePluginName, |
26 BubbleImageWidget::BubbleImageWidget( |
27 BubbleImageManager& imageManager, QGraphicsItem* parent) |
27 BubbleImageManager& imageManager, |
28 : HbWidget(parent), mStylePluginName(stylePluginName), |
28 QGraphicsItem* parent) |
29 mImageManager(imageManager), mDefaultAvatar(0) |
29 : HbWidget(parent), |
|
30 mImageManager(imageManager), |
|
31 mDefaultAvatar(0) |
30 { |
32 { |
31 setPluginBaseId(style()->registerPlugin(mStylePluginName)); |
33 // create avatar |
32 Q_ASSERT(pluginBaseId()!=-1); |
34 mDefaultAvatar = new HbIconItem(this); |
|
35 style()->setItemName( mDefaultAvatar, "default_avatar" ); |
|
36 mDefaultAvatar->setAspectRatioMode(Qt::KeepAspectRatioByExpanding); |
|
37 mDefaultAvatar->setAlignment(Qt::AlignCenter); |
33 |
38 |
34 // create avatar |
39 connect(&mImageManager, SIGNAL(pixmapReady(QString)), |
35 delete mDefaultAvatar; |
40 this, SLOT(imageLoaded(QString))); |
36 mDefaultAvatar = style()->createPrimitive( |
|
37 (HbStyle::Primitive)(pluginBaseId()+BP_DefaultAvatar_icon), this); |
|
38 style()->setItemName( mDefaultAvatar, "default_avatar" ); |
|
39 |
41 |
40 connect(&mImageManager,SIGNAL(pixmapReady(QString)), |
42 HbStyleLoader::registerFilePath(":/bubbleimagewidget.css"); |
41 this,SLOT(imageLoaded(QString))); |
43 HbStyleLoader::registerFilePath(":/bubbleimagewidget.widgetml"); |
42 } |
44 } |
43 |
45 |
44 BubbleImageWidget::~BubbleImageWidget() |
46 BubbleImageWidget::~BubbleImageWidget() |
45 { |
47 { |
46 style()->unregisterPlugin(mStylePluginName); |
|
47 } |
48 } |
48 |
49 |
49 void BubbleImageWidget::setImage(const QString& name) |
50 void BubbleImageWidget::setImage(const QString& name) |
50 { |
51 { |
51 mImageName = name; |
52 mImageName = name; |
52 |
53 |
53 if (!mImageName.isEmpty()) { |
54 if (!mImageName.isEmpty()) { |
54 mDefaultAvatar->setVisible(false); |
55 mDefaultAvatar->setVisible(false); |
|
56 mDefaultAvatar->setIcon(HbIcon()); |
55 mImageManager.loadImage(mImageName); |
57 mImageManager.loadImage(mImageName); |
56 } else { |
58 } else { |
57 BubbleStyleOption option; |
59 mDefaultAvatar->setIconName("qtg_large_avatar"); |
58 style()->updatePrimitive( |
|
59 mDefaultAvatar, |
|
60 (HbStyle::Primitive)(pluginBaseId()+BP_DefaultAvatar_icon), |
|
61 &option); |
|
62 mDefaultAvatar->setVisible(true); |
60 mDefaultAvatar->setVisible(true); |
63 } |
61 } |
64 } |
62 } |
65 |
63 |
66 void BubbleImageWidget::imageLoaded(QString imageFileName) |
64 void BubbleImageWidget::imageLoaded(QString imageFileName) |