|
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: Silent widget |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <HbPushButton> |
|
20 #include <QGraphicsLinearLayout> |
|
21 #include <HbStyle> |
|
22 #include <HbDocumentLoader> |
|
23 #include <HbFrameItem> |
|
24 #include <HbFrameDrawer> |
|
25 #include <xqsettingsmanager.h> |
|
26 #include <ProfileEngineInternalCRKeys.h> |
|
27 |
|
28 // User includes |
|
29 #include "silentwidget.h" |
|
30 #include "silentwidgetconsts.h" |
|
31 #include "silentmodel.h" |
|
32 #include "silentobserver.h" |
|
33 |
|
34 /*! |
|
35 \class SilentWidget |
|
36 \implementation for silent widget |
|
37 |
|
38 This class is used to create silent widget |
|
39 */ |
|
40 |
|
41 // ======== MEMBER FUNCTIONS ======== |
|
42 |
|
43 /*! |
|
44 Constructor |
|
45 */ |
|
46 SilentWidget::SilentWidget(QGraphicsItem* parent, Qt::WindowFlags flags) |
|
47 : HbWidget(parent, flags), |
|
48 mButton(0), |
|
49 mModel(new SilentModel), |
|
50 mObserver(new SilentObserver(this)) |
|
51 { |
|
52 QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout( |
|
53 Qt::Vertical, this); |
|
54 |
|
55 // load the widget from .docml |
|
56 HbDocumentLoader loader; |
|
57 bool ok = false; |
|
58 loader.load(":/docml/silentdocml", &ok); |
|
59 if (!ok) { |
|
60 // fail to load .docml file |
|
61 return; |
|
62 } |
|
63 mButton = (HbPushButton *) loader.findWidget("pushButton"); |
|
64 if (!mButton) { |
|
65 // fail to find push button |
|
66 return; |
|
67 } |
|
68 |
|
69 // set icon and background |
|
70 HbFrameDrawer *background = new HbFrameDrawer("qtg_fr_hsshortcut_normal", |
|
71 HbFrameDrawer::NinePieces); |
|
72 mButton->setFrameBackground(background); |
|
73 HbFrameDrawer *foreground; |
|
74 if (mModel->silenceMode()) { |
|
75 foreground = new HbFrameDrawer("qtg_large_tone_off", |
|
76 HbFrameDrawer::NinePieces); |
|
77 } else { |
|
78 foreground = new HbFrameDrawer("qtg_large_tone", |
|
79 HbFrameDrawer::NinePieces); |
|
80 } |
|
81 HbFrameItem* frameItem = new HbFrameItem(foreground); |
|
82 mButton->setBackgroundItem(frameItem); |
|
83 |
|
84 mButton->setCheckable(true); |
|
85 mainLayout->addItem(mButton); |
|
86 |
|
87 connect(mButton, SIGNAL(toggled(bool)), this, SLOT(handleClickEvent(bool))); |
|
88 setLayout(mainLayout); |
|
89 |
|
90 // create XQSettingsManager, monitor KProEngSilenceMode |
|
91 mSettingManager = new XQSettingsManager(); |
|
92 XQCentralRepositorySettingsKey silenceKey(KCRUidProfileEngine.iUid, |
|
93 KProEngSilenceMode); |
|
94 mSettingManager->startMonitoring(silenceKey, XQSettingsManager::TypeInt); |
|
95 connect(mSettingManager, SIGNAL(valueChanged(XQSettingsKey, QVariant)), |
|
96 this, SLOT(settingValueChanged(XQSettingsKey, QVariant))); |
|
97 } |
|
98 |
|
99 /*! |
|
100 Monitor KProEngSilenceMode |
|
101 */ |
|
102 void SilentWidget::settingValueChanged(const XQSettingsKey &key, |
|
103 const QVariant &value) |
|
104 { |
|
105 // change icon according to latest silence mode |
|
106 if (key.uid() == KCRUidProfileEngine.iUid && key.key() == KProEngSilenceMode) { |
|
107 HbFrameDrawer *foreground; |
|
108 if (value.toBool()) { |
|
109 foreground = new HbFrameDrawer("qtg_large_tone_off", |
|
110 HbFrameDrawer::NinePieces); |
|
111 } else { |
|
112 foreground = new HbFrameDrawer("qtg_large_tone", |
|
113 HbFrameDrawer::NinePieces); |
|
114 } |
|
115 HbFrameItem* frameItem = new HbFrameItem(foreground); |
|
116 mButton->setBackgroundItem(frameItem); |
|
117 } |
|
118 } |
|
119 |
|
120 /*! |
|
121 Handle click events |
|
122 */ |
|
123 void SilentWidget::handleClickEvent(bool /*state*/) |
|
124 { |
|
125 // switch icon and activate silece state |
|
126 HbFrameDrawer *foreground; |
|
127 if (!mModel->silenceMode()) { |
|
128 mModel->setSilenceMode(true); |
|
129 foreground = new HbFrameDrawer("qtg_large_tone_off", |
|
130 HbFrameDrawer::NinePieces); |
|
131 } else { |
|
132 mModel->setSilenceMode(false); |
|
133 foreground = new HbFrameDrawer("qtg_large_tone", |
|
134 HbFrameDrawer::NinePieces); |
|
135 } |
|
136 HbFrameItem* frameItem = new HbFrameItem(foreground); |
|
137 mButton->setBackgroundItem(frameItem); |
|
138 } |
|
139 |
|
140 /*! |
|
141 Change icon according to observer event |
|
142 */ |
|
143 void SilentWidget::changeIcon() |
|
144 { |
|
145 HbFrameDrawer *foreground; |
|
146 if (mModel->silenceMode()) { |
|
147 foreground = new HbFrameDrawer("qtg_large_tone_off", |
|
148 HbFrameDrawer::NinePieces); |
|
149 } else { |
|
150 foreground = new HbFrameDrawer("qtg_large_tone", |
|
151 HbFrameDrawer::NinePieces); |
|
152 } |
|
153 HbFrameItem* frameItem = new HbFrameItem(foreground); |
|
154 mButton->setBackgroundItem(frameItem); |
|
155 } |
|
156 |
|
157 /*! |
|
158 Destructor |
|
159 */ |
|
160 SilentWidget::~SilentWidget() |
|
161 { |
|
162 if (mModel) { |
|
163 delete mModel; |
|
164 mModel = NULL; |
|
165 } |
|
166 |
|
167 if (mSettingManager) { |
|
168 delete mSettingManager; |
|
169 mSettingManager = NULL; |
|
170 } |
|
171 } |
|
172 |
|
173 /*! |
|
174 Return bounding rect |
|
175 */ |
|
176 QRectF SilentWidget::boundingRect() const |
|
177 { |
|
178 return childrenBoundingRect(); |
|
179 } |
|
180 |
|
181 /*! |
|
182 Return shape |
|
183 */ |
|
184 QPainterPath SilentWidget::shape() const |
|
185 { |
|
186 QPainterPath path; |
|
187 path.addRect(boundingRect()); |
|
188 return path; |
|
189 } |
|
190 |
|
191 /*! |
|
192 Called when widget is shown in the home screen |
|
193 */ |
|
194 void SilentWidget::onShow() |
|
195 { |
|
196 } |
|
197 |
|
198 /*! |
|
199 Called when widget is hidden from the home screen |
|
200 */ |
|
201 void SilentWidget::onHide() |
|
202 { |
|
203 } |