124 */ |
93 */ |
125 void HbCheckBoxPrivate::createPrimitives( ) |
94 void HbCheckBoxPrivate::createPrimitives( ) |
126 { |
95 { |
127 Q_Q( HbCheckBox ); |
96 Q_Q( HbCheckBox ); |
128 if( !mTouchArea ) { |
97 if( !mTouchArea ) { |
129 mTouchArea = q->style( )->createPrimitive( HbStyle::P_CheckBox_toucharea, q ); |
98 mTouchArea = HbStylePrivate::createPrimitive( HbStylePrivate::P_CheckBox_toucharea, q ); |
130 if( QGraphicsObject *ta = qgraphicsitem_cast<QGraphicsObject*>( mTouchArea ) ) { |
99 if( QGraphicsObject *ta = qgraphicsitem_cast<QGraphicsObject*>( mTouchArea ) ) { |
131 ta->grabGesture( Qt::TapGesture ); |
100 ta->grabGesture( Qt::TapGesture ); |
132 } |
101 } |
133 } |
102 } |
134 if ( !mTextItem ) { |
103 if ( !mTextItem ) { |
135 mTextItem = q->style( )->createPrimitive( HbStyle::P_CheckBox_text, q ); |
104 mTextItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_CheckBox_text, q ); |
136 } |
105 } |
137 if ( !mIconItem ) { |
106 if ( !mIconItem ) { |
138 mIconItem = q->style( )->createPrimitive( HbStyle::P_CheckBox_icon, q ); |
107 mIconItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_CheckBox_icon, q ); |
139 } |
108 } |
140 } |
109 } |
141 |
110 |
142 /*! |
111 /*! |
143 @beta |
|
144 @hbwidgets |
112 @hbwidgets |
145 \class HbCheckBox |
113 \class HbCheckBox |
146 \brief The HbCheckBox widget provides a checkbox with a text label. |
114 \brief The HbCheckBox class provides a check box widget with a text label. |
147 |
115 |
148 \image html checkbox_unchecked.png A checkbox with unchecked state. |
116 A check box is an option button that can be in checked, unchecked, and |
149 |
117 partially checked states as shown in the pictures below. Check boxes are |
150 \image html checkbox_checked.png A checkbox with checked state. |
118 typically used to represent application features that can be enabled or |
151 |
119 disabled without affecting other features, but you can also subclass it to |
152 \image html checkbox_partiallychecked.png A checkbox with partiallychecked state. |
120 implement different behavior. |
153 |
121 |
154 A HbCheckBox is an option button that can be switched on (checked) |
122 \image html checkbox_unchecked.png A check box in unchecked state. |
155 or off (unchecked). Checkboxes are typically used to represent |
123 |
156 features in an application that can be enabled or disabled without |
124 \image html checkbox_checked.png A check box in checked state. |
157 affecting others, but different types of behavior can be |
125 |
158 implemented. |
126 \image html checkbox_partiallychecked.png A check box in partially checked state. |
159 |
127 |
160 Whenever a checkbox is checked or cleared it emits the signal |
128 When a user checks or unchecks a check box, it emits the stateChanged() |
161 stateChanged(). Connect to this signal if you want to trigger an |
129 signal. Connect a slot to this signal if you want to trigger an action every |
162 action each time the checkbox changes state. You can use |
130 time the check box state changes. You can use isChecked() to query whether a |
163 isChecked() to query whether or not a checkbox is checked. |
131 check box is checked or not. |
164 |
132 |
165 In addition to checked and unchecked states, HbCheckBox |
133 In addition to checked and unchecked states, %HbCheckBox provides |
166 optionally provides a third state which is PartiallyChecked. This |
134 an optional partially checked state. This state is useful when you handle |
167 is useful for Hierarchical list item. If you need this third state, |
135 hierarchical list items, for example. If you need the partially checked |
168 enable it with setTristate(), and use checkState() to query the current |
136 state, enable it with setTristate() and query the state of the check box |
169 toggle state. |
137 with checkState(). |
170 |
138 |
171 Checkbox has default icon for checked,unchecked and partiallyChecked states. |
139 A check box has default icons for checked, unchecked, and partially checked |
172 The text can be set in the constructor or with setText(). |
140 states. The text can be set in the constructor or with setText(). If the |
173 |
141 check box text is long, it is shown in multiple lines. By default a check box |
174 Example usage: |
142 can have up to three lines of text. |
|
143 |
|
144 \section _usecases_hbcheckbox Using the HbCheckBox class |
|
145 |
|
146 \subsection _uc_hbcheckbox_001 Creating a check box. |
|
147 |
|
148 The following code snippet creates a check box in the layout. |
|
149 |
175 \code |
150 \code |
176 HbCheckBox *checkbox = new HbCheckBox(QString("checkbox_text")); |
151 HbCheckBox *checkbox = new HbCheckBox(QString("checkbox_text")); |
177 layout->addItem(checkbox); |
152 layout->addItem(checkbox); |
178 \endcode |
153 \endcode |
179 |
154 |
180 */ |
155 */ |
181 |
156 |
182 |
157 |
183 /*! |
158 /*! |
|
159 |
184 \fn void HbCheckBox::stateChanged(int state) |
160 \fn void HbCheckBox::stateChanged(int state) |
185 This signal is emitted whenever the check box's state changes, |
161 |
186 i.e. whenever the user checks or unchecks it. |
162 This signal is emitted when the user checks or unchecks a check box causing a |
187 \a state contains the check box's new Qt::CheckState. |
163 state change of the check box. |
188 */ |
164 |
189 |
165 \param state The new state (Qt::CheckState) of the check box. |
190 |
166 |
191 |
167 \sa Qt |
192 /*! |
168 |
193 @beta |
169 */ |
194 Constructor an object of HbCheckBox with default parameters. |
170 |
195 By default the state of check box will be Unchecked, text will |
171 |
196 be empty and tristate will be false. |
172 /*! |
|
173 |
|
174 Constructs a check box with the following default values: |
|
175 - \a state is \c Qt::CheckState::Unchecked. |
|
176 - \a text is empty. |
|
177 - \a tristate is \c false. |
|
178 |
|
179 \sa Qt |
|
180 |
197 */ |
181 */ |
198 HbCheckBox::HbCheckBox( QGraphicsItem *parent ) |
182 HbCheckBox::HbCheckBox( QGraphicsItem *parent ) |
199 : HbAbstractButton( *new HbCheckBoxPrivate, parent ) |
183 : HbAbstractButton( *new HbCheckBoxPrivate, parent ) |
200 { |
184 { |
201 Q_D( HbCheckBox ); |
185 Q_D( HbCheckBox ); |
202 d->q_ptr = this; |
186 d->q_ptr = this; |
203 setCheckable( true ); |
187 setCheckable( true ); |
204 d->createPrimitives( ); |
188 d->createPrimitives( ); |
205 // creattion of top and bottom spacer. |
|
206 HbStyle::setItemName( new HbCheckBoxSpacer( this ), "topSpacer" ); |
|
207 HbStyle::setItemName( new HbCheckBoxSpacer( this ), "bottomSpacer" ); |
|
208 #ifdef HB_GESTURE_FW |
189 #ifdef HB_GESTURE_FW |
209 grabGesture( Qt::TapGesture ); |
190 grabGesture( Qt::TapGesture ); |
210 #endif |
191 #endif |
211 |
192 |
212 } |
193 } |
213 |
194 |
214 /*! |
195 /*! |
215 @beta |
196 |
216 Constructor an object of HbCheckBox with \a text passed. |
197 Constructs a check box with \a text and the following default values: |
217 By default the state of check box will be Unchecked. |
198 - \a state is \c Qt::CheckState::Unchecked. |
218 Tristate will be false by default. |
199 - \a tristate is \c false. |
|
200 |
|
201 \sa Qt |
|
202 |
219 */ |
203 */ |
220 HbCheckBox::HbCheckBox( const QString &text, QGraphicsItem *parent ) |
204 HbCheckBox::HbCheckBox( const QString &text, QGraphicsItem *parent ) |
221 : HbAbstractButton( *new HbCheckBoxPrivate, parent ) |
205 : HbAbstractButton( *new HbCheckBoxPrivate, parent ) |
222 { |
206 { |
223 Q_D( HbCheckBox ); |
207 Q_D( HbCheckBox ); |
224 d->q_ptr = this; |
208 d->q_ptr = this; |
225 d->mText = text; |
209 d->mText = text; |
226 setCheckable( true ); |
210 setCheckable( true ); |
227 d->createPrimitives( ); |
211 d->createPrimitives( ); |
228 // creattion of top and bottom spacer. |
|
229 HbStyle::setItemName( new HbCheckBoxSpacer(this), "topSpacer"); |
|
230 HbStyle::setItemName( new HbCheckBoxSpacer(this), "bottomSpacer"); |
|
231 |
|
232 } |
212 } |
233 |
213 |
234 /*! |
214 /*! |
235 Destructor. |
215 Destructor. |
236 */ |
216 */ |
237 HbCheckBox::~HbCheckBox( ) |
217 HbCheckBox::~HbCheckBox( ) |
238 { |
218 { |
239 } |
219 } |
240 |
220 |
241 /*! |
221 /*! |
242 @beta |
222 |
243 Sets the text of checkbox. |
223 Sets the \a text shown on a check box. |
244 UpdatePrimitive is called by this functions once the text is changed. |
224 |
245 \sa text() |
225 \sa text() |
246 */ |
226 */ |
247 void HbCheckBox::setText( const QString &text ) |
227 void HbCheckBox::setText( const QString &text ) |
248 { |
228 { |
249 Q_D( HbCheckBox ); |
229 Q_D( HbCheckBox ); |
251 d->mText = text; |
231 d->mText = text; |
252 //updatePrimitives(); |
232 //updatePrimitives(); |
253 if( d->mTextItem ){ |
233 if( d->mTextItem ){ |
254 HbStyleOptionCheckBox checkBoxOption; |
234 HbStyleOptionCheckBox checkBoxOption; |
255 initStyleOption( &checkBoxOption ); |
235 initStyleOption( &checkBoxOption ); |
256 style( )->updatePrimitive( d->mTextItem, HbStyle::P_CheckBox_text, &checkBoxOption ); |
236 HbStylePrivate::updatePrimitive( d->mTextItem, HbStylePrivate::P_CheckBox_text, &checkBoxOption ); |
257 } |
237 } |
258 } |
238 } |
259 } |
239 } |
260 |
240 |
261 /*! |
241 /*! |
262 @beta |
242 |
263 Returns the text of checkbox. |
243 Returns the text of a check box. |
|
244 |
264 \sa setText() |
245 \sa setText() |
265 */ |
246 */ |
266 QString HbCheckBox::text( ) const |
247 QString HbCheckBox::text( ) const |
267 { |
248 { |
268 Q_D( const HbCheckBox ); |
249 Q_D( const HbCheckBox ); |
269 return d->mText; |
250 return d->mText; |
270 } |
251 } |
271 |
252 |
272 /*! |
253 /*! |
273 @beta |
254 |
274 Sets tristate support for checkbox based upon \a flag. |
255 Sets a check box to: |
275 By default tristate is false and checkbox has got only two states. |
256 - tristate-enabled mode if \a isTristate is \c true. |
|
257 - twostate-enabled mode if \a isTristate is \c false (default). |
|
258 |
276 \sa isTristate( ) |
259 \sa isTristate( ) |
277 */ |
260 */ |
278 void HbCheckBox::setTristate( bool isTristate ) |
261 void HbCheckBox::setTristate( bool isTristate ) |
279 { |
262 { |
280 Q_D( HbCheckBox ); |
263 Q_D( HbCheckBox ); |
281 d->mTristate = isTristate; |
264 d->mTristate = isTristate; |
282 } |
265 } |
283 |
266 |
284 /*! |
267 /*! |
285 @beta |
268 |
286 Returns whether tristate is enabled for checkbox or not. |
269 Checks whether a check box can have two or three states. |
|
270 |
|
271 \return \c true if a check box is tristate-enabled. |
|
272 \return \c false if a check box is twostate-enabled. |
|
273 |
287 \sa setTristate( ) |
274 \sa setTristate( ) |
288 */ |
275 */ |
289 bool HbCheckBox::isTristate( ) const |
276 bool HbCheckBox::isTristate( ) const |
290 { |
277 { |
291 Q_D( const HbCheckBox ); |
278 Q_D( const HbCheckBox ); |
292 return d->mTristate; |
279 return d->mTristate; |
293 } |
280 } |
294 |
281 |
295 /*! |
282 /*! |
296 @beta |
283 |
297 Returns the current state of HbCheckBox. |
284 Returns the current state (checked, unchecked, or partially checked) of a |
|
285 check box. |
|
286 |
298 */ |
287 */ |
299 Qt::CheckState HbCheckBox::checkState() const |
288 Qt::CheckState HbCheckBox::checkState() const |
300 { |
289 { |
301 Q_D( const HbCheckBox ); |
290 Q_D( const HbCheckBox ); |
302 if ( d->mTristate && d->mNoChange ) { |
291 if ( d->mTristate && d->mNoChange ) { |
356 emit stateChanged( state ); |
345 emit stateChanged( state ); |
357 } |
346 } |
358 } |
347 } |
359 |
348 |
360 /*! |
349 /*! |
361 Updates the icon and text primitives. |
350 Updates the icon and the text primitives of a check box. |
362 */ |
351 */ |
363 void HbCheckBox::updatePrimitives( ) |
352 void HbCheckBox::updatePrimitives( ) |
364 { |
353 { |
365 HbWidget::updatePrimitives( ); |
354 HbWidget::updatePrimitives( ); |
366 Q_D( HbCheckBox ); |
355 Q_D( HbCheckBox ); |
367 |
356 |
368 HbStyleOptionCheckBox checkBoxOption; |
357 HbStyleOptionCheckBox checkBoxOption; |
369 initStyleOption( &checkBoxOption ); |
358 initStyleOption( &checkBoxOption ); |
370 |
359 |
371 if ( d->mTextItem ) { |
360 if ( d->mTextItem ) { |
372 style( )->updatePrimitive( d->mTextItem, HbStyle::P_CheckBox_text, &checkBoxOption ); |
361 HbStylePrivate::updatePrimitive( d->mTextItem, HbStylePrivate::P_CheckBox_text, &checkBoxOption ); |
373 } |
362 } |
374 if ( d->mIconItem ) { |
363 if ( d->mIconItem ) { |
375 style( )->updatePrimitive( d->mIconItem, HbStyle::P_CheckBox_icon, &checkBoxOption ); |
364 HbStylePrivate::updatePrimitive( d->mIconItem, HbStylePrivate::P_CheckBox_icon, &checkBoxOption ); |
376 } |
365 } |
377 if (d->mTouchArea) { |
366 if (d->mTouchArea) { |
378 style( )->updatePrimitive( d->mTouchArea, HbStyle::P_CheckBox_toucharea, &checkBoxOption ); |
367 HbStylePrivate::updatePrimitive( d->mTouchArea, HbStylePrivate::P_CheckBox_toucharea, &checkBoxOption ); |
379 } |
368 } |
380 } |
369 } |
381 |
370 |
382 /*! |
371 /*! |
383 Initializes the style for check box with the \a option passed. |
372 Initializes the style of a check box with the \a option style. |
384 */ |
373 */ |
385 void HbCheckBox::initStyleOption(HbStyleOptionCheckBox *option) const |
374 void HbCheckBox::initStyleOption(HbStyleOptionCheckBox *option) const |
386 { |
375 { |
387 Q_D( const HbCheckBox ); |
376 Q_D( const HbCheckBox ); |
388 |
377 |