|
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 HbWidgets 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 "hbvolumeslider_p.h" |
|
27 #include <hbvolumesliderpopup.h> |
|
28 #include <hbinstance.h> |
|
29 #include "hbsliderpopup_p.h" |
|
30 #include "hblayoutdirectionnotifier_p.h" |
|
31 #include <hbmessagebox.h> |
|
32 #include "hbdeviceprofile.h" |
|
33 |
|
34 /*! |
|
35 @beta |
|
36 @hbwidgets |
|
37 \class HbVolumeSliderPopup |
|
38 \brief HbVolumeSliderPopup widget provides a vertical volume slider embedded in a popup. |
|
39 |
|
40 HbVolumeSliderPopup is provided for convenience. HbVolumeSlider sets appropriate |
|
41 icons and provides volume slider specific functionality like a |
|
42 checkable mute button and appropriate elements out of the box. HbVolumeSliderPopup |
|
43 consists of following slider elements by default: |
|
44 \li HbSlider::IncreaseElement |
|
45 \li HbSlider::TrackElement |
|
46 \li HbSlider::DecreaseElement |
|
47 \li HbSlider::IconElement |
|
48 |
|
49 \image html hbvolumeslider.png A volume slider. |
|
50 |
|
51 The elements can be changed by calling HbSlider::setElements() later at any time. |
|
52 |
|
53 \note order of element can not be changed |
|
54 |
|
55 Orientation of HbVolumeSliderPopup can not be changed. If orientation change is need, |
|
56 then first create HbSliderPopup and set needed elements. |
|
57 |
|
58 It is positioned at Right side of the screen in non mirrored layout. |
|
59 |
|
60 Example usage: |
|
61 \code |
|
62 HbVolumeSliderPopup *slider = new HbVolumeSliderPopup(); |
|
63 connect(slider, SIGNAL(valueChanged(int)), receiver, SLOT(volumeSliderChanged(int))); |
|
64 connect(slider, SIGNAL(iconToggled(bool)), receiver, SLOT(volumeMuted(bool))); |
|
65 \endcode |
|
66 |
|
67 Note:: position and size of these elements cant be change. |
|
68 use HbVolumeSlider instead if you want to change position or size |
|
69 |
|
70 Note:: if setElement is called on this slider , application is reponsible for |
|
71 inconsitent UI. |
|
72 */ |
|
73 |
|
74 |
|
75 /* |
|
76 internal |
|
77 */ |
|
78 class HbVolumeSliderPopupPrivate : public HbSliderPopupPrivate |
|
79 { |
|
80 Q_DECLARE_PUBLIC(HbVolumeSliderPopup) |
|
81 protected: |
|
82 virtual void createSlider(); |
|
83 public: |
|
84 HbVolumeSliderPopupPrivate(); |
|
85 virtual ~HbVolumeSliderPopupPrivate(); |
|
86 void init(); |
|
87 }; |
|
88 |
|
89 /* |
|
90 internal |
|
91 */ |
|
92 void HbVolumeSliderPopupPrivate::init() |
|
93 { |
|
94 Q_Q( HbVolumeSliderPopup); |
|
95 q->setTimeout(2000); |
|
96 HbVolumeSlider* volumeSlider = static_cast<HbVolumeSlider *>(slider); |
|
97 q->connect(volumeSlider,SIGNAL(iconToggled(bool)),q,SIGNAL(iconToggled(bool))); |
|
98 |
|
99 } |
|
100 |
|
101 /* |
|
102 internal |
|
103 */ |
|
104 HbVolumeSliderPopupPrivate::HbVolumeSliderPopupPrivate() |
|
105 { |
|
106 } |
|
107 |
|
108 /* |
|
109 reimp |
|
110 */ |
|
111 void HbVolumeSliderPopupPrivate::createSlider() |
|
112 { |
|
113 slider = new HbVolumeSlider(true); |
|
114 } |
|
115 |
|
116 /* |
|
117 \internal |
|
118 */ |
|
119 HbVolumeSliderPopupPrivate::~HbVolumeSliderPopupPrivate() |
|
120 { |
|
121 } |
|
122 |
|
123 /*! |
|
124 @beta |
|
125 Constructs a HbVolumeSliderPopup with \a parent. |
|
126 |
|
127 orientation will be vertical |
|
128 |
|
129 */ |
|
130 HbVolumeSliderPopup::HbVolumeSliderPopup( ) : |
|
131 HbSliderPopup(*new HbVolumeSliderPopupPrivate, 0) |
|
132 { |
|
133 Q_D(HbVolumeSliderPopup); |
|
134 d->q_ptr = this; |
|
135 d->init(); |
|
136 } |
|
137 |
|
138 /*! |
|
139 @beta |
|
140 \internal |
|
141 */ |
|
142 HbVolumeSliderPopup::HbVolumeSliderPopup(HbVolumeSliderPopupPrivate &dd, QGraphicsItem *parent) : |
|
143 HbSliderPopup(dd, parent) |
|
144 { |
|
145 dd.init(); |
|
146 } |
|
147 |
|
148 /*! |
|
149 Destructs the slider. |
|
150 */ |
|
151 HbVolumeSliderPopup::~HbVolumeSliderPopup() |
|
152 { |
|
153 } |
|
154 |
|
155 |
|
156 /*! |
|
157 @beta |
|
158 Sets whether the text element is visible. |
|
159 |
|
160 \default is true |
|
161 |
|
162 \sa isCurrentValueVisible() |
|
163 */ |
|
164 void HbVolumeSliderPopup::setCurrentValueVisible(bool visible) |
|
165 { |
|
166 Q_D(HbVolumeSliderPopup); |
|
167 if( d->slider ) { |
|
168 HbVolumeSlider* volumeSlider = static_cast<HbVolumeSlider *>(d->slider); |
|
169 volumeSlider->setCurrentValueVisible(visible); |
|
170 } |
|
171 } |
|
172 |
|
173 /*! |
|
174 @beta |
|
175 Returns \c true whether the text element is visible. |
|
176 |
|
177 The default value is \c false. |
|
178 |
|
179 \sa setCurrentValueVisible() |
|
180 */ |
|
181 bool HbVolumeSliderPopup::isCurrentValueVisible() const |
|
182 { |
|
183 Q_D(const HbVolumeSliderPopup); |
|
184 if( d->slider ) { |
|
185 HbVolumeSlider* volumeslider = static_cast<HbVolumeSlider *>(d->slider); |
|
186 return volumeslider->isCurrentValueVisible() ; |
|
187 } |
|
188 return false; |
|
189 } |
|
190 |
|
191 /*! |
|
192 \reimp |
|
193 re position the slider popup |
|
194 */ |
|
195 |
|
196 |
|
197 /*! |
|
198 Reimplemented from QGraphicsItem::keyReleaseEvent(). |
|
199 */ |
|
200 void HbVolumeSliderPopup::keyReleaseEvent(QKeyEvent *keyevent) |
|
201 { |
|
202 switch (keyevent->key()) { |
|
203 //hide popup for following key press event |
|
204 case Qt::Key_Enter: |
|
205 case Qt::Key_Return: |
|
206 case Qt::Key_Select: |
|
207 { |
|
208 HbMessageBox *note = new HbMessageBox( |
|
209 tr("Volume Adjusted"), HbMessageBox::MessageTypeInformation); |
|
210 note->show(); |
|
211 } |
|
212 hide(); |
|
213 break; |
|
214 case Qt::Key_Left: |
|
215 case Qt::Key_Backspace: |
|
216 case Qt::Key_Back: |
|
217 hide(); |
|
218 keyevent->accept(); |
|
219 break; |
|
220 default: |
|
221 HbSliderPopup::keyReleaseEvent(keyevent); |
|
222 break; |
|
223 } |
|
224 |
|
225 } |
|
226 |
|
227 /*! |
|
228 Reimplemented from QGraphicsItem::keyPressEvent(). |
|
229 */ |
|
230 void HbVolumeSliderPopup::keyPressEvent(QKeyEvent *keyevent) |
|
231 { |
|
232 switch (keyevent->key()) { |
|
233 case Qt::Key_Left: |
|
234 case Qt::Key_Right: |
|
235 case Qt::Key_Back: |
|
236 case Qt::Key_Backspace: |
|
237 hide(); |
|
238 keyevent->accept(); |
|
239 break; |
|
240 default: |
|
241 HbSliderPopup::keyPressEvent(keyevent); |
|
242 break; |
|
243 } |
|
244 |
|
245 } |
|
246 |
|
247 |
|
248 #include "moc_hbvolumesliderpopup.cpp" |