|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QDir> |
|
19 #include <QPainter> |
|
20 #include "hswallpaper.h" |
|
21 #include "hswallpaper_p.h" |
|
22 #include "hsscene.h" |
|
23 |
|
24 HsWallpaperPrivate::HsWallpaperPrivate() |
|
25 : mOrientation(Qt::Vertical) |
|
26 { |
|
27 } |
|
28 |
|
29 HsWallpaperPrivate::~HsWallpaperPrivate() |
|
30 { |
|
31 } |
|
32 |
|
33 HsWallpaper::HsWallpaper(QGraphicsItem *parent) |
|
34 : HbWidget(parent) |
|
35 { |
|
36 mD.reset(new HsWallpaperPrivate); |
|
37 } |
|
38 |
|
39 HsWallpaper::~HsWallpaper() |
|
40 { |
|
41 } |
|
42 |
|
43 void HsWallpaper::paint(QPainter *painter, |
|
44 const QStyleOptionGraphicsItem *option, |
|
45 QWidget *widget) |
|
46 { |
|
47 Q_UNUSED(option); |
|
48 Q_UNUSED(widget); |
|
49 |
|
50 Qt::Orientation orientation = HsScene::orientation(); |
|
51 if (orientation != mD->mOrientation) { |
|
52 mD->mOrientation = orientation; |
|
53 mD->mImage = QPixmap(); |
|
54 if (orientation == Qt::Horizontal) { |
|
55 mD->mImage.load(mD->mLImagePath); |
|
56 } else { |
|
57 mD->mImage.load(mD->mPImagePath); |
|
58 } |
|
59 } |
|
60 |
|
61 if (!mD->mImage.isNull()) { |
|
62 painter->drawPixmap(rect().toRect(), mD->mImage); |
|
63 } |
|
64 } |
|
65 |
|
66 bool HsWallpaper::setImagesById(const QString &id, |
|
67 const QString &ext) |
|
68 { |
|
69 return setImagesByPaths( |
|
70 wallpaperPath(Qt::Horizontal, id, ext), |
|
71 wallpaperPath(Qt::Vertical, id, ext)); |
|
72 } |
|
73 |
|
74 bool HsWallpaper::setImagesByPaths(const QString &landscapeImagePath, |
|
75 const QString &portraitImagePath) |
|
76 { |
|
77 mD->mLImagePath = landscapeImagePath; |
|
78 mD->mPImagePath = portraitImagePath; |
|
79 mD->mOrientation = HsScene::orientation(); |
|
80 |
|
81 if (mD->mOrientation == Qt::Horizontal) { |
|
82 return mD->mImage.load(mD->mLImagePath); |
|
83 } else { |
|
84 return mD->mImage.load(mD->mPImagePath); |
|
85 } |
|
86 } |
|
87 |
|
88 bool HsWallpaper::removeImages() |
|
89 { |
|
90 if (mD->mLImagePath != wallpaperPath(Qt::Horizontal)) { |
|
91 QFile::remove(mD->mLImagePath); |
|
92 mD->mLImagePath.clear(); |
|
93 } |
|
94 if (mD->mPImagePath != wallpaperPath(Qt::Vertical)) { |
|
95 QFile::remove(mD->mPImagePath); |
|
96 mD->mPImagePath.clear(); |
|
97 } |
|
98 return true; |
|
99 } |
|
100 |
|
101 QString HsWallpaper::wallpaperDirectory() |
|
102 { |
|
103 #ifdef Q_OS_SYMBIAN |
|
104 static QString directory = |
|
105 QDir::toNativeSeparators("c:/private/20022f35/wallpapers/"); |
|
106 #else |
|
107 static QString directory = |
|
108 QDir::toNativeSeparators(QDir::currentPath() + "/wallpapers/"); |
|
109 #endif |
|
110 |
|
111 return directory; |
|
112 } |
|
113 |
|
114 QString HsWallpaper::wallpaperPath(Qt::Orientation orientation, |
|
115 const QString &id, |
|
116 const QString &ext) |
|
117 { |
|
118 QString orientationString = orientation == Qt::Horizontal ? |
|
119 "_landscape." : "_portrait."; |
|
120 return wallpaperDirectory() + id + |
|
121 orientationString + ext; |
|
122 } |