|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbApps module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include <hbmainwindow.h> |
|
27 #include <hbaction.h> |
|
28 #include <hbtoolbar.h> |
|
29 #include <hbdataform.h> |
|
30 #include <hbdataformmodel.h> |
|
31 #include <hbdataformmodelitem.h> |
|
32 #include <QGraphicsLinearLayout> |
|
33 #include <hbthemeutils_p.h> |
|
34 #include <hbcombobox.h> |
|
35 #include <hbmessagebox.h> |
|
36 #include <hbiconitem.h> |
|
37 #include <hbthemeutils_p.h> |
|
38 #include <QDir> |
|
39 #include "resourceview.h" |
|
40 #include <hbsearchpanel.h> |
|
41 #include <hbtumbleview.h> |
|
42 #include <hblabel.h> |
|
43 #include <hbcolorscheme.h> |
|
44 #include <hbiconanimator.h> |
|
45 #include <hbiconanimationmanager.h> |
|
46 |
|
47 /** |
|
48 * Constructor |
|
49 */ |
|
50 ResourceView::ResourceView(HbMainWindow *mainWindow, HbView* parent): HbView(parent) |
|
51 { |
|
52 mMainWindow = mainWindow; |
|
53 mParentView = parent; |
|
54 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical); |
|
55 |
|
56 this->setTitle(tr("Resource lookup")); |
|
57 |
|
58 HbAction *act = new HbAction(Hb::BackNaviAction); |
|
59 connect(act, SIGNAL(triggered()), this, SLOT(close())); |
|
60 |
|
61 this->setNavigationAction(act); |
|
62 |
|
63 act = new HbAction(tr("Icons")); |
|
64 connect(act, SIGNAL(triggered()), this, SLOT(iconModeSelected())); |
|
65 this->toolBar()->addAction(act); |
|
66 |
|
67 act = new HbAction(tr("Colors")); |
|
68 connect(act, SIGNAL(triggered()), this, SLOT(colorModeSelected())); |
|
69 this->toolBar()->addAction(act); |
|
70 |
|
71 act = new HbAction(tr("Effects")); |
|
72 connect(act, SIGNAL(triggered()), this, SLOT(effectModeSelected())); |
|
73 this->toolBar()->addAction(act); |
|
74 |
|
75 act = new HbAction(tr("Animations")); |
|
76 connect(act, SIGNAL(triggered()), this, SLOT(animationModeSelected())); |
|
77 this->toolBar()->addAction(act); |
|
78 |
|
79 |
|
80 loadThemedIcons(); |
|
81 loadThemedColors(); |
|
82 loadThemedEffects(); |
|
83 loadThemedAnimations(); |
|
84 mAnimator = new HbIconAnimator(); |
|
85 mResourceItem = new HbLabel(this); |
|
86 mResourceItem->setIcon(HbIcon(mThemedIcons.size()?mThemedIcons[0]:"")); |
|
87 mResourceItem->setAlignment(Qt::AlignCenter); |
|
88 mResourceItem->setFontSpec(HbFontSpec(HbFontSpec::Secondary)); |
|
89 mResourcesList = new HbTumbleView(mThemedIcons, this); |
|
90 |
|
91 layout->addItem(mResourceItem); |
|
92 layout->addItem(mResourcesList); |
|
93 |
|
94 mSearchPanel = new HbSearchPanel(this); |
|
95 mSearchPanel->setCancelEnabled(false); |
|
96 mSearchPanel->setPlaceholderText(tr("Search")); |
|
97 layout->addItem(mSearchPanel); |
|
98 this->setLayout(layout); |
|
99 |
|
100 connect(mSearchPanel, SIGNAL(criteriaChanged(const QString &)), this, SLOT(criteriaChanged(const QString &))); |
|
101 connect(mResourcesList, SIGNAL(itemSelected(int)), this, SLOT(iconItemSelected(int))); |
|
102 mMode = iconMode; |
|
103 |
|
104 mMainWindow->addView(this); |
|
105 } |
|
106 |
|
107 /** |
|
108 * Destructor |
|
109 */ |
|
110 ResourceView::~ResourceView() |
|
111 { |
|
112 delete mAnimator; |
|
113 } |
|
114 |
|
115 void ResourceView::close() |
|
116 { |
|
117 mMainWindow->setCurrentView(mParentView); |
|
118 } |
|
119 |
|
120 void ResourceView::toggleMode(ListMode mode) |
|
121 { |
|
122 if (mode == mMode) { |
|
123 return; |
|
124 } |
|
125 |
|
126 switch (mMode) { |
|
127 case colorMode: |
|
128 disconnect(mResourcesList, SIGNAL(itemSelected(int)), this, SLOT(colorItemSelected(int))); |
|
129 break; |
|
130 case iconMode: |
|
131 disconnect(mResourcesList, SIGNAL(itemSelected(int)), this, SLOT(iconItemSelected(int))); |
|
132 break; |
|
133 case effectMode: |
|
134 mResourcesList->setSelected(0); |
|
135 disconnect(mResourcesList, SIGNAL(itemSelected(int)), this, SLOT(effectItemSelected(int))); |
|
136 break; |
|
137 case animationMode: |
|
138 mResourcesList->setSelected(0); |
|
139 disconnect(mResourcesList, SIGNAL(itemSelected(int)), this, SLOT(animationItemSelected(int))); |
|
140 break; |
|
141 default: |
|
142 break; |
|
143 } |
|
144 |
|
145 mMode = mode; |
|
146 switch (mode) { |
|
147 case colorMode: |
|
148 connect(mResourcesList, SIGNAL(itemSelected(int)), this, SLOT(colorItemSelected(int))); |
|
149 mSearchPanel->setCriteria(""); |
|
150 mResourcesList->setSelected(0); |
|
151 break; |
|
152 case iconMode: |
|
153 connect(mResourcesList, SIGNAL(itemSelected(int)), this, SLOT(iconItemSelected(int))); |
|
154 mSearchPanel->setCriteria(""); |
|
155 mResourcesList->setSelected(0); |
|
156 break; |
|
157 case effectMode: |
|
158 connect(mResourcesList, SIGNAL(itemSelected(int)), this, SLOT(effectItemSelected(int))); |
|
159 mSearchPanel->setCriteria(""); |
|
160 mResourcesList->setSelected(0); |
|
161 break; |
|
162 case animationMode: |
|
163 connect(mResourcesList, SIGNAL(itemSelected(int)), this, SLOT(animationItemSelected(int))); |
|
164 mSearchPanel->setCriteria(""); |
|
165 mResourcesList->setSelected(0); |
|
166 break; |
|
167 default: |
|
168 break; |
|
169 } |
|
170 } |
|
171 |
|
172 void ResourceView::loadThemedIcons() |
|
173 { |
|
174 mThemedIcons.clear(); |
|
175 QString basetheme = HbThemeUtils::getThemeSetting(HbThemeUtils::BaseThemeSetting); |
|
176 QDir scalableIconsDir(basetheme + "/scalable"); |
|
177 QDir pixmapIconsDir(basetheme + "/pixmap"); |
|
178 QFileInfoList files = scalableIconsDir.entryInfoList(QDir::Files); |
|
179 files += pixmapIconsDir.entryInfoList(QDir::Files); |
|
180 // Strip the file extensions |
|
181 for (int i=0;i<files.count();i++) { |
|
182 mThemedIcons += files[i].baseName(); |
|
183 } |
|
184 } |
|
185 |
|
186 void ResourceView::loadThemedEffects() |
|
187 { |
|
188 mThemedEffects.clear(); |
|
189 QString basetheme = HbThemeUtils::getThemeSetting(HbThemeUtils::BaseThemeSetting); |
|
190 basetheme = basetheme.replace("/icons/", "/effects/"); |
|
191 QDir effectsDir(basetheme); |
|
192 QFileInfoList files = effectsDir.entryInfoList(QDir::Files); |
|
193 // Strip the file extensions |
|
194 for (int i=0;i<files.count();i++) { |
|
195 mThemedEffects += files[i].baseName(); |
|
196 } |
|
197 } |
|
198 |
|
199 void ResourceView::loadThemedAnimations() |
|
200 { |
|
201 mThemedAnimations.clear(); |
|
202 QString basetheme = HbThemeUtils::getThemeSetting(HbThemeUtils::BaseThemeSetting); |
|
203 basetheme = basetheme.replace("/icons/", "/animations/"); |
|
204 QDir animationsDir(basetheme); |
|
205 QFileInfoList files = animationsDir.entryInfoList(QDir::Files); |
|
206 // Add animation definitions and strip the file extensions |
|
207 for (int i=0;i<files.count();i++) { |
|
208 HbIconAnimationManager::global()->addDefinitionFile(files[i].fileName()); |
|
209 mThemedAnimations += files[i].baseName(); |
|
210 } |
|
211 } |
|
212 |
|
213 void ResourceView::loadThemedColors() |
|
214 { |
|
215 mThemedColors.clear(); |
|
216 QString basetheme = HbThemeUtils::getThemeSetting(HbThemeUtils::BaseThemeSetting); |
|
217 basetheme = basetheme.replace("/icons/", "/style/"); |
|
218 QFile file(basetheme + "/variables/color/hbcolorgroup.css"); |
|
219 |
|
220 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
221 QTextStream in(&file); |
|
222 |
|
223 while(!in.atEnd()) { |
|
224 QString line = in.readLine().trimmed(); |
|
225 if (line.startsWith("qtc_")) { |
|
226 // Extract logical name |
|
227 mThemedColors += line.mid(0, line.indexOf(':')).trimmed(); |
|
228 } |
|
229 } |
|
230 file.close(); |
|
231 } |
|
232 } |
|
233 |
|
234 void ResourceView::iconModeSelected() |
|
235 { |
|
236 toggleMode(iconMode); |
|
237 } |
|
238 |
|
239 void ResourceView::colorModeSelected() |
|
240 { |
|
241 toggleMode(colorMode); |
|
242 } |
|
243 |
|
244 void ResourceView::effectModeSelected() |
|
245 { |
|
246 toggleMode(effectMode); |
|
247 } |
|
248 |
|
249 void ResourceView::animationModeSelected() |
|
250 { |
|
251 toggleMode(animationMode); |
|
252 } |
|
253 |
|
254 |
|
255 void ResourceView::iconItemSelected(int index) |
|
256 { |
|
257 mResourceItem->setIcon(HbIcon(mResourcesList->items()[index])); |
|
258 } |
|
259 |
|
260 void ResourceView::animationItemSelected(int index) |
|
261 { |
|
262 mResourceItem->setIcon(HbIcon(mResourcesList->items()[index])); |
|
263 mAnimator->setIcon(mResourceItem->icon()); |
|
264 mAnimator->startAnimation(); |
|
265 } |
|
266 |
|
267 |
|
268 void ResourceView::colorItemSelected(int index) |
|
269 { |
|
270 QString rgbValue("#"); |
|
271 rgbValue += QString::number(HbColorScheme::color(mResourcesList->items()[index]).red(), 16); |
|
272 rgbValue += QString::number(HbColorScheme::color(mResourcesList->items()[index]).green(), 16); |
|
273 rgbValue += QString::number(HbColorScheme::color(mResourcesList->items()[index]).blue(), 16); |
|
274 mResourceItem->setPlainText(rgbValue.toUpper()); |
|
275 } |
|
276 |
|
277 void ResourceView::effectItemSelected(int index) |
|
278 { |
|
279 HbEffect::add(mResourceItem,mResourcesList->items()[index],"selected"); |
|
280 HbEffect::start(mResourceItem,"selected"); |
|
281 } |
|
282 |
|
283 |
|
284 void ResourceView::criteriaChanged(const QString &criteria) |
|
285 { |
|
286 QStringList filteredItems; |
|
287 switch (mMode) { |
|
288 case iconMode: |
|
289 filteredItems = mThemedIcons.filter(criteria.toLower()); |
|
290 break; |
|
291 case colorMode: |
|
292 filteredItems = mThemedColors.filter(criteria.toLower()); |
|
293 break; |
|
294 case effectMode: |
|
295 filteredItems = mThemedEffects.filter(criteria.toLower()); |
|
296 break; |
|
297 case animationMode: |
|
298 filteredItems = mThemedAnimations.filter(criteria.toLower()); |
|
299 break; |
|
300 default: |
|
301 break; |
|
302 } |
|
303 mResourcesList->setItems(filteredItems); |
|
304 } |