|
1 /* |
|
2 * Copyright (c) 2010 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 <HbInstance> |
|
19 #include <HbMainWindow> |
|
20 #include <HbView> |
|
21 #include <HbMenu> |
|
22 #include <HbAction> |
|
23 |
|
24 #include "hsgui.h" |
|
25 #include "hsidlewidget.h" |
|
26 #include "hsscene.h" |
|
27 #include "hspropertyanimationwrapper.h" |
|
28 |
|
29 namespace { |
|
30 const char gApplicationLibraryIconName[] = "qtg_mono_applications_all"; |
|
31 } |
|
32 |
|
33 /*! |
|
34 \class HsGui |
|
35 \ingroup group_hsdomainmodel |
|
36 \brief Represents a view in the framework. |
|
37 HsGui includes common UI components for Home screen. |
|
38 */ |
|
39 |
|
40 HsGui *HsGui::mInstance(0); |
|
41 |
|
42 struct HsGuiImpl |
|
43 { |
|
44 HsIdleWidget *mIdleWidget; |
|
45 HbView *mIdleView; |
|
46 HbMainWindow *mWindow; |
|
47 HbAction *mNavigationAction; |
|
48 HsPropertyAnimationWrapper *mPageChangeAnimation; |
|
49 HsPropertyAnimationWrapper *mPageCrawlingAnimation; |
|
50 }; |
|
51 |
|
52 |
|
53 |
|
54 HsGui::~HsGui() |
|
55 { |
|
56 if (mImpl->mNavigationAction) { |
|
57 delete mImpl->mNavigationAction; |
|
58 } |
|
59 |
|
60 if (mImpl->mPageChangeAnimation) { |
|
61 mImpl->mPageChangeAnimation->stop(); |
|
62 delete mImpl->mPageChangeAnimation; |
|
63 } |
|
64 if (mImpl->mPageCrawlingAnimation) { |
|
65 mImpl->mPageCrawlingAnimation->stop(); |
|
66 delete mImpl->mPageCrawlingAnimation; |
|
67 } |
|
68 delete mImpl; |
|
69 } |
|
70 |
|
71 HsGui *HsGui::setInstance(HsGui *instance) |
|
72 { |
|
73 HsGui *old = mInstance; |
|
74 if (mInstance != instance) { |
|
75 mInstance = instance; |
|
76 } |
|
77 return old; |
|
78 } |
|
79 |
|
80 HsGui *HsGui::instance() |
|
81 { |
|
82 if (!mInstance) { |
|
83 mInstance = new HsGui(QCoreApplication::instance()); |
|
84 } |
|
85 return mInstance; |
|
86 } |
|
87 |
|
88 HsGui *HsGui::takeInstance() |
|
89 { |
|
90 HsGui *instance = mInstance; |
|
91 mInstance = 0; |
|
92 return instance; |
|
93 } |
|
94 |
|
95 void HsGui::setupIdleUi() |
|
96 { |
|
97 if (!mImpl->mIdleWidget) { |
|
98 mImpl->mIdleWidget = new HsIdleWidget; |
|
99 mImpl->mIdleView = mImpl->mWindow->addView(mImpl->mIdleWidget); |
|
100 mImpl->mIdleView->setContentFullScreen(); |
|
101 |
|
102 delete mImpl->mNavigationAction; |
|
103 mImpl->mNavigationAction = 0; |
|
104 mImpl->mNavigationAction = new HbAction; |
|
105 mImpl->mNavigationAction->setIcon(HbIcon(gApplicationLibraryIconName)); |
|
106 mImpl->mNavigationAction->setObjectName("applib_navigation_action"); |
|
107 connect(mImpl->mNavigationAction, SIGNAL(triggered()), SIGNAL(navigateToApplibrary())); |
|
108 mImpl->mIdleView->setNavigationAction(mImpl->mNavigationAction); |
|
109 } |
|
110 mImpl->mWindow->setCurrentView(mImpl->mIdleView); |
|
111 } |
|
112 |
|
113 void HsGui::cleanupIdleUi() |
|
114 { |
|
115 if (mImpl->mIdleView) { |
|
116 mImpl->mIdleView->setNavigationAction(0); |
|
117 delete mImpl->mNavigationAction; |
|
118 mImpl->mNavigationAction = 0; |
|
119 |
|
120 mImpl->mWindow->removeView(mImpl->mIdleView); |
|
121 delete mImpl->mIdleView; |
|
122 mImpl->mIdleView = 0; |
|
123 |
|
124 delete mImpl->mPageChangeAnimation; |
|
125 mImpl->mPageChangeAnimation = 0; |
|
126 |
|
127 delete mImpl->mPageCrawlingAnimation; |
|
128 mImpl->mPageCrawlingAnimation = 0; |
|
129 } |
|
130 |
|
131 } |
|
132 |
|
133 void HsGui::setOrientation(Qt::Orientation orientation) |
|
134 { |
|
135 mImpl->mWindow->setOrientation(orientation); |
|
136 } |
|
137 |
|
138 Qt::Orientation HsGui::orientation() |
|
139 { |
|
140 return mImpl->mWindow->orientation(); |
|
141 } |
|
142 |
|
143 HbView *HsGui::idleView() const |
|
144 { |
|
145 return mImpl->mIdleView; |
|
146 } |
|
147 |
|
148 HsIdleWidget *HsGui::idleWidget() const |
|
149 { |
|
150 return mImpl->mIdleWidget; |
|
151 } |
|
152 |
|
153 QRectF HsGui::layoutRect() const |
|
154 { |
|
155 return mImpl->mWindow->layoutRect(); |
|
156 } |
|
157 |
|
158 void HsGui::show() |
|
159 { |
|
160 mImpl->mWindow->raise(); |
|
161 mImpl->mWindow->show(); |
|
162 } |
|
163 |
|
164 HsPropertyAnimationWrapper *HsGui::pageChangeAnimation() |
|
165 { |
|
166 if (!mImpl->mPageChangeAnimation) { |
|
167 mImpl->mPageChangeAnimation = new HsPropertyAnimationWrapper; |
|
168 mImpl->mPageChangeAnimation->setTargetObject(mImpl->mIdleWidget); |
|
169 mImpl->mPageChangeAnimation->setPropertyName("sceneX"); |
|
170 } |
|
171 return mImpl->mPageChangeAnimation; |
|
172 } |
|
173 HsPropertyAnimationWrapper *HsGui::pageCrawlingAnimation() |
|
174 { |
|
175 if (!mImpl->mPageCrawlingAnimation) { |
|
176 mImpl->mPageCrawlingAnimation = new HsPropertyAnimationWrapper; |
|
177 mImpl->mPageCrawlingAnimation->setTargetObject(mImpl->mIdleWidget); |
|
178 mImpl->mPageCrawlingAnimation->setPropertyName("sceneX"); |
|
179 } |
|
180 return mImpl->mPageCrawlingAnimation; |
|
181 } |
|
182 |
|
183 HsGui::HsGui(QObject *parent): |
|
184 QObject(parent),mImpl(new HsGuiImpl) |
|
185 { |
|
186 mImpl->mIdleView = 0; |
|
187 mImpl->mIdleWidget = 0; |
|
188 mImpl->mNavigationAction = 0; |
|
189 mImpl->mPageChangeAnimation = 0; |
|
190 mImpl->mPageCrawlingAnimation = 0; |
|
191 |
|
192 mImpl->mWindow = hbInstance->allMainWindows().first(); |
|
193 connect(mImpl->mWindow, SIGNAL(orientationChanged(Qt::Orientation)), |
|
194 SIGNAL(orientationChanged(Qt::Orientation))); |
|
195 } |