14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <QDir> |
18 #include <QDir> |
19 #include <QPainter> |
19 #include <QGraphicsLinearLayout> |
|
20 #include <HbIconItem> |
|
21 #include <HbMainWindow> |
20 #include "hswallpaper.h" |
22 #include "hswallpaper.h" |
21 #include "hsscene.h" |
23 #include "hsscene.h" |
22 |
24 |
23 HsWallpaper::HsWallpaper(QGraphicsItem *parent) |
25 HsWallpaper::HsWallpaper(QGraphicsItem *parent) |
24 : HbWidget(parent), |
26 : HbWidget(parent), |
25 mOrientation(Qt::Vertical) |
27 mOrientation(Qt::Vertical), |
|
28 mIconItem(0) |
26 { |
29 { |
|
30 mIconItem = new HbIconItem(); |
|
31 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(); |
|
32 layout->setContentsMargins(0, 0, 0, 0); |
|
33 layout->addItem(mIconItem); |
|
34 setLayout(layout); |
|
35 |
|
36 connect(HsScene::mainWindow(), |
|
37 SIGNAL(orientationChanged(Qt::Orientation)), |
|
38 SLOT(onOrientationChanged(Qt::Orientation))); |
27 } |
39 } |
28 |
40 |
29 HsWallpaper::~HsWallpaper() |
41 HsWallpaper::~HsWallpaper() |
30 { |
42 { |
31 } |
|
32 |
|
33 void HsWallpaper::paint(QPainter *painter, |
|
34 const QStyleOptionGraphicsItem *option, |
|
35 QWidget *widget) |
|
36 { |
|
37 Q_UNUSED(option); |
|
38 Q_UNUSED(widget); |
|
39 |
|
40 Qt::Orientation orientation = HsScene::orientation(); |
|
41 if (orientation != mOrientation) { |
|
42 mOrientation = orientation; |
|
43 mImage = QPixmap(); |
|
44 if (orientation == Qt::Horizontal) { |
|
45 mImage.load(mLImagePath); |
|
46 } else { |
|
47 mImage.load(mPImagePath); |
|
48 } |
|
49 } |
|
50 |
|
51 if (!mImage.isNull()) { |
|
52 painter->drawPixmap(rect().toRect(), mImage); |
|
53 } |
|
54 } |
43 } |
55 |
44 |
56 bool HsWallpaper::setImagesById(const QString &id, |
45 bool HsWallpaper::setImagesById(const QString &id, |
57 const QString &ext) |
46 const QString &ext) |
58 { |
47 { |
67 mLImagePath = landscapeImagePath; |
56 mLImagePath = landscapeImagePath; |
68 mPImagePath = portraitImagePath; |
57 mPImagePath = portraitImagePath; |
69 mOrientation = HsScene::orientation(); |
58 mOrientation = HsScene::orientation(); |
70 |
59 |
71 if (mOrientation == Qt::Horizontal) { |
60 if (mOrientation == Qt::Horizontal) { |
72 return mImage.load(mLImagePath); |
61 setLandscapeImage(mLImagePath, true); |
73 } else { |
62 } else { |
74 return mImage.load(mPImagePath); |
63 setPortraitImage(mPImagePath, true); |
|
64 } |
|
65 return true; |
|
66 } |
|
67 |
|
68 void HsWallpaper::setPortraitImage(const QString &path, bool activate) |
|
69 { |
|
70 mPImagePath = path; |
|
71 if (activate) { |
|
72 mIconItem->setIcon(HbIcon(QIcon(path))); |
|
73 } |
|
74 } |
|
75 |
|
76 void HsWallpaper::setLandscapeImage(const QString &path, bool activate) |
|
77 { |
|
78 mLImagePath = path; |
|
79 if (activate) { |
|
80 mIconItem->setIcon(HbIcon(QIcon(path))); |
75 } |
81 } |
76 } |
82 } |
77 |
83 |
78 bool HsWallpaper::removeImages() |
84 bool HsWallpaper::removeImages() |
79 { |
85 { |
108 QString orientationString = orientation == Qt::Horizontal ? |
114 QString orientationString = orientation == Qt::Horizontal ? |
109 "_landscape." : "_portrait."; |
115 "_landscape." : "_portrait."; |
110 return wallpaperDirectory() + id + |
116 return wallpaperDirectory() + id + |
111 orientationString + ext; |
117 orientationString + ext; |
112 } |
118 } |
|
119 |
|
120 void HsWallpaper::onOrientationChanged(Qt::Orientation orientation) |
|
121 { |
|
122 if (orientation == Qt::Horizontal) { |
|
123 mIconItem->setIcon(HbIcon(QIcon(mLImagePath))); |
|
124 } else { |
|
125 mIconItem->setIcon(HbIcon(QIcon(mPImagePath))); |
|
126 } |
|
127 } |