107 mIconItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_CheckBox_icon, q ); |
107 mIconItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_CheckBox_icon, q ); |
108 } |
108 } |
109 } |
109 } |
110 |
110 |
111 /*! |
111 /*! |
112 @beta |
|
113 @hbwidgets |
112 @hbwidgets |
114 \class HbCheckBox |
113 \class HbCheckBox |
115 \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. |
116 |
115 |
117 \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 |
118 |
117 partially checked states as shown in the pictures below. Check boxes are |
119 \image html checkbox_checked.png A checkbox with checked state. |
118 typically used to represent application features that can be enabled or |
120 |
119 disabled without affecting other features, but you can also subclass it to |
121 \image html checkbox_partiallychecked.png A checkbox with partiallychecked state. |
120 implement different behavior. |
122 |
121 |
123 A HbCheckBox is an option button that can be switched on (checked) |
122 \image html checkbox_unchecked.png A check box in unchecked state. |
124 or off (unchecked). Checkboxes are typically used to represent |
123 |
125 features in an application that can be enabled or disabled without |
124 \image html checkbox_checked.png A check box in checked state. |
126 affecting others, but different types of behavior can be |
125 |
127 implemented. |
126 \image html checkbox_partiallychecked.png A check box in partially checked state. |
128 |
127 |
129 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() |
130 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 |
131 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 |
132 isChecked() to query whether or not a checkbox is checked. |
131 check box is checked or not. |
133 |
132 |
134 In addition to checked and unchecked states, HbCheckBox |
133 In addition to checked and unchecked states, %HbCheckBox provides |
135 optionally provides a third state which is PartiallyChecked. This |
134 an optional partially checked state. This state is useful when you handle |
136 is useful for Hierarchical list item. If you need this third state, |
135 hierarchical list items, for example. If you need the partially checked |
137 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 |
138 toggle state. |
137 with checkState(). |
139 |
138 |
140 Checkbox has default icon for checked,unchecked and partiallyChecked states. |
139 A check box has default icons for checked, unchecked, and partially checked |
141 The text can be set in the constructor or with setText().For long text checkbox will show |
140 states. The text can be set in the constructor or with setText(). If the |
142 multiline text,default checkbox will have text up to three lines. |
141 check box text is long, it is shown in multiple lines. By default a check box |
143 |
142 can have up to three lines of text. |
144 Example usage: |
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 |
145 \code |
150 \code |
146 HbCheckBox *checkbox = new HbCheckBox(QString("checkbox_text")); |
151 HbCheckBox *checkbox = new HbCheckBox(QString("checkbox_text")); |
147 layout->addItem(checkbox); |
152 layout->addItem(checkbox); |
148 \endcode |
153 \endcode |
149 |
154 |
150 */ |
155 */ |
151 |
156 |
152 |
157 |
153 /*! |
158 /*! |
|
159 |
154 \fn void HbCheckBox::stateChanged(int state) |
160 \fn void HbCheckBox::stateChanged(int state) |
155 This signal is emitted whenever the check box's state changes, |
161 |
156 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 |
157 \a state contains the check box's new Qt::CheckState. |
163 state change of the check box. |
158 */ |
164 |
159 |
165 \param state The new state (Qt::CheckState) of the check box. |
160 |
166 |
161 |
167 \sa Qt |
162 /*! |
168 |
163 @beta |
169 */ |
164 Constructor an object of HbCheckBox with default parameters. |
170 |
165 By default the state of check box will be Unchecked, text will |
171 |
166 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 |
167 */ |
181 */ |
168 HbCheckBox::HbCheckBox( QGraphicsItem *parent ) |
182 HbCheckBox::HbCheckBox( QGraphicsItem *parent ) |
169 : HbAbstractButton( *new HbCheckBoxPrivate, parent ) |
183 : HbAbstractButton( *new HbCheckBoxPrivate, parent ) |
170 { |
184 { |
171 Q_D( HbCheckBox ); |
185 Q_D( HbCheckBox ); |
220 } |
237 } |
221 } |
238 } |
222 } |
239 } |
223 |
240 |
224 /*! |
241 /*! |
225 @beta |
242 |
226 Returns the text of checkbox. |
243 Returns the text of a check box. |
|
244 |
227 \sa setText() |
245 \sa setText() |
228 */ |
246 */ |
229 QString HbCheckBox::text( ) const |
247 QString HbCheckBox::text( ) const |
230 { |
248 { |
231 Q_D( const HbCheckBox ); |
249 Q_D( const HbCheckBox ); |
232 return d->mText; |
250 return d->mText; |
233 } |
251 } |
234 |
252 |
235 /*! |
253 /*! |
236 @beta |
254 |
237 Sets tristate support for checkbox based upon \a flag. |
255 Sets a check box to: |
238 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 |
239 \sa isTristate( ) |
259 \sa isTristate( ) |
240 */ |
260 */ |
241 void HbCheckBox::setTristate( bool isTristate ) |
261 void HbCheckBox::setTristate( bool isTristate ) |
242 { |
262 { |
243 Q_D( HbCheckBox ); |
263 Q_D( HbCheckBox ); |
244 d->mTristate = isTristate; |
264 d->mTristate = isTristate; |
245 } |
265 } |
246 |
266 |
247 /*! |
267 /*! |
248 @beta |
268 |
249 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 |
250 \sa setTristate( ) |
274 \sa setTristate( ) |
251 */ |
275 */ |
252 bool HbCheckBox::isTristate( ) const |
276 bool HbCheckBox::isTristate( ) const |
253 { |
277 { |
254 Q_D( const HbCheckBox ); |
278 Q_D( const HbCheckBox ); |
255 return d->mTristate; |
279 return d->mTristate; |
256 } |
280 } |
257 |
281 |
258 /*! |
282 /*! |
259 @beta |
283 |
260 Returns the current state of HbCheckBox. |
284 Returns the current state (checked, unchecked, or partially checked) of a |
|
285 check box. |
|
286 |
261 */ |
287 */ |
262 Qt::CheckState HbCheckBox::checkState() const |
288 Qt::CheckState HbCheckBox::checkState() const |
263 { |
289 { |
264 Q_D( const HbCheckBox ); |
290 Q_D( const HbCheckBox ); |
265 if ( d->mTristate && d->mNoChange ) { |
291 if ( d->mTristate && d->mNoChange ) { |
359 option->state.operator = ( d->checked ? QStyle::State_On : QStyle::State_Off ); |
385 option->state.operator = ( d->checked ? QStyle::State_On : QStyle::State_Off ); |
360 } |
386 } |
361 } |
387 } |
362 |
388 |
363 /*! |
389 /*! |
364 Updates the primitive as per new size. |
390 |
365 */ |
391 */ |
366 void HbCheckBox::resizeEvent( QGraphicsSceneResizeEvent *event ) |
392 void HbCheckBox::resizeEvent( QGraphicsSceneResizeEvent *event ) |
367 { |
393 { |
368 HbAbstractButton::resizeEvent( event ); |
394 HbAbstractButton::resizeEvent( event ); |
369 } |
395 } |
370 |
396 |
371 /*! |
397 /*! |
372 Overloaded hit detection to include touch area |
398 |
373 */ |
399 */ |
374 bool HbCheckBox::hitButton( const QPointF &pos ) const |
400 bool HbCheckBox::hitButton( const QPointF &pos ) const |
375 { |
401 { |
376 Q_D(const HbCheckBox); |
402 Q_D(const HbCheckBox); |
377 QRectF compRect = d->mTouchArea->boundingRect( ); |
403 QRectF compRect = d->mTouchArea->boundingRect( ); |
378 compRect.translate( d->mTouchArea->pos( ) ); |
404 compRect.translate( d->mTouchArea->pos( ) ); |
379 return compRect.contains( pos ); |
405 return compRect.contains( pos ); |
380 } |
406 } |
381 |
407 |
382 /*! |
408 /*! |
383 \reimp. |
409 |
384 */ |
410 */ |
385 void HbCheckBox::checkStateSet( ) |
411 void HbCheckBox::checkStateSet( ) |
386 { |
412 { |
387 Q_D(HbCheckBox); |
413 Q_D(HbCheckBox); |
388 d->mNoChange = false; |
414 d->mNoChange = false; |