24 ****************************************************************************/ |
24 ****************************************************************************/ |
25 |
25 |
26 #include "hbtoolbutton.h" |
26 #include "hbtoolbutton.h" |
27 #include "hbtoolbutton_p.h" |
27 #include "hbtoolbutton_p.h" |
28 #include "hbtooltip.h" |
28 #include "hbtooltip.h" |
29 #include "hbstyleoptiontoolbutton_p.h" |
|
30 #include "hbtoolbarextension.h" |
29 #include "hbtoolbarextension.h" |
31 #include "hbtoolbarextension_p.h" |
30 #include "hbtoolbarextension_p.h" |
32 #include "hbaction.h" |
31 #include "hbaction.h" |
33 #include "hbaction_p.h" |
32 #include "hbaction_p.h" |
34 #include <hbglobal.h> |
|
35 #include "hbcolorscheme.h" |
33 #include "hbcolorscheme.h" |
36 #include "hbtextitem.h" |
34 #include "hbtextitem.h" |
37 #include "hbiconitem.h" |
35 #include "hbiconitem.h" |
38 #include "hbview.h" |
36 #include "hbview.h" |
39 #include "hbmainwindow.h" |
37 #include "hbmainwindow.h" |
|
38 #include "hbframeitem.h" |
|
39 #include "hbevent.h" |
40 |
40 |
41 #include "hbglobal_p.h" // remove when removing HB_DEPRECATED |
41 #include "hbglobal_p.h" // remove when removing HB_DEPRECATED |
|
42 |
|
43 #include "hbstyle_p.h" // for iconmodes... |
|
44 |
|
45 #include <hbstyleframeprimitivedata.h> |
|
46 #include <hbstyleiconprimitivedata.h> |
|
47 #include <hbstyletextprimitivedata.h> |
42 |
48 |
43 #include <QGraphicsSceneHelpEvent> |
49 #include <QGraphicsSceneHelpEvent> |
44 #include <QGraphicsSceneMouseEvent> |
50 #include <QGraphicsSceneMouseEvent> |
45 #include <QCoreApplication> |
51 #include <QCoreApplication> |
46 |
52 |
77 layout->addItem(toolButton); |
80 layout->addItem(toolButton); |
78 \endcode |
81 \endcode |
79 |
82 |
80 \sa HbAction, HbPushButton |
83 \sa HbAction, HbPushButton |
81 */ |
84 */ |
82 |
|
83 /*! |
|
84 \enum HbToolButton::ToolButtonStyle |
|
85 \deprecated HbToolButton::ToolButtonStyle |
|
86 |
|
87 This enum defines available tool button styles. |
|
88 |
|
89 The tool button style describes how the button's text and icon should be displayed. |
|
90 */ |
|
91 |
|
92 /*! |
|
93 \var HbToolButton::ToolButtonIcon |
|
94 \deprecated HbToolButton::ToolButtonIcon |
|
95 |
|
96 Only display the icon. |
|
97 */ |
|
98 |
|
99 /*! |
|
100 \var HbToolButton::ToolButtonText |
|
101 \deprecated HbToolButton::ToolButtonText |
|
102 |
|
103 Only display the text. |
|
104 */ |
|
105 |
|
106 /*! |
|
107 \var HbToolButton::ToolButtonTextAndIcon |
|
108 \deprecated HbToolButton::ToolButtonTextAndIcon |
|
109 |
|
110 Display both text and icon. |
|
111 */ |
|
112 |
85 |
113 /*! |
86 /*! |
114 \fn void HbToolButton::triggered(HbAction *action) |
87 \fn void HbToolButton::triggered(HbAction *action) |
115 |
88 |
116 This signal is emitted when the \a action is triggered. |
89 This signal is emitted when the \a action is triggered. |
151 void HbToolButtonPrivate::createPrimitives() |
123 void HbToolButtonPrivate::createPrimitives() |
152 { |
124 { |
153 Q_Q(HbToolButton); |
125 Q_Q(HbToolButton); |
154 if (backgroundVisible) { |
126 if (backgroundVisible) { |
155 if (!frameItem){ |
127 if (!frameItem){ |
156 frameItem = q->style()->createPrimitive(HbStyle::P_ToolButton_frame, q); |
128 frameItem = q->style()->createPrimitive(HbStyle::PT_FrameItem, "background", q); |
157 } |
129 } |
158 } else if (frameItem) { |
130 } else if (frameItem) { |
159 delete frameItem; |
131 delete frameItem; |
160 frameItem = 0; |
132 frameItem = 0; |
161 } |
133 } |
162 |
134 if (!textItem) { |
163 if (action && !action->text().isEmpty()) { |
135 textItem = q->style()->createPrimitive(HbStyle::PT_TextItem, "text", q); |
164 if (!textItem) { |
136 } |
165 textItem = static_cast<HbTextItem *>(q->style()->createPrimitive(HbStyle::P_ToolButton_text, q)); |
137 HbStyleTextPrimitiveData textData; |
166 textItem->setTextWrapping(Hb::TextWordWrap); |
138 textData.textWrapping = Hb::TextWordWrap; |
167 } |
139 q->style()->updatePrimitive(textItem, &textData, q); |
168 textItem->setVisible(buttonStyle & HbToolButton::ToolButtonText); |
140 |
169 } else if (textItem) { |
141 if (!iconItem) { |
170 delete textItem; |
142 iconItem = q->style()->createPrimitive(HbStyle::PT_IconItem, "icon", q); |
171 textItem = 0; |
143 } |
172 } |
144 |
173 |
|
174 if (action && (buttonStyle & HbToolButton::ToolButtonIcon)) { |
|
175 if (!iconItem) { |
|
176 iconItem = q->style()->createPrimitive(HbStyle::P_ToolButton_icon, q); |
|
177 } |
|
178 } else if (iconItem){ |
|
179 delete iconItem; |
|
180 iconItem = 0; |
|
181 } |
|
182 } |
145 } |
183 |
146 |
184 void HbToolButtonPrivate::setOrientation(Qt::Orientation orientation) |
147 void HbToolButtonPrivate::setOrientation(Qt::Orientation orientation) |
185 { |
148 { |
186 if (this->orientation != orientation) { |
149 if (this->orientation != orientation) { |
187 this->orientation = orientation; |
150 this->orientation = orientation; |
188 Q_Q(HbToolButton); |
151 Q_Q(HbToolButton); |
189 if (q->isVisible() && polished) { |
152 q->setMinimumSize(QSizeF()); |
190 q->repolish(); |
153 q->repolish(); |
191 } |
|
192 } |
154 } |
193 } |
155 } |
194 |
156 |
195 void HbToolButtonPrivate::setToolBarPosition(HbStyleOptionToolButton::ToolBarPosition position) |
157 void HbToolButtonPrivate::setToolBarPosition(ToolButtonPosition position) |
196 { |
158 { |
197 Q_Q(HbToolButton); |
159 Q_Q(HbToolButton); |
198 if (toolBarPosition != position) { |
160 if (toolBarPosition != position) { |
199 toolBarPosition = position; |
161 toolBarPosition = position; |
200 // required for toolbar()->action()[i]->setVisible(visible) |
162 // required for toolbar()->action()[i]->setVisible(visible) |
231 |
193 |
232 void HbToolButtonPrivate::setLayoutProperty(const char *name, bool value) |
194 void HbToolButtonPrivate::setLayoutProperty(const char *name, bool value) |
233 { |
195 { |
234 Q_Q(HbToolButton); |
196 Q_Q(HbToolButton); |
235 q->setProperty(name, value); |
197 q->setProperty(name, value); |
236 if (q->isVisible() && polished) { |
|
237 q->repolish(); |
198 q->repolish(); |
|
199 } |
|
200 |
|
201 |
|
202 bool HbToolButtonPrivate::useTransparentGraphics() const |
|
203 { |
|
204 Q_Q(const HbToolButton); |
|
205 if (q->mainWindow() && q->mainWindow()->currentView()) { |
|
206 if (q->mainWindow()->currentView()->viewFlags() & HbView::ViewTitleBarTransparent) { |
|
207 return true; |
|
208 } |
|
209 } |
|
210 return false; |
|
211 } |
|
212 |
|
213 bool HbToolButtonPrivate::isToolBarExtension() const |
|
214 { |
|
215 return (action != 0 && toolbarExtensionFrame); |
|
216 } |
|
217 |
|
218 void HbToolButtonPrivate::framePrimitiveData(HbStyleFramePrimitiveData *data) |
|
219 { |
|
220 Q_Q(HbToolButton); |
|
221 |
|
222 data->fillWholeRect = true; |
|
223 |
|
224 if (orientation == Qt::Vertical) { |
|
225 data->frameType = HbFrameDrawer::ThreePiecesHorizontal; |
|
226 } else { |
|
227 data->frameType = HbFrameDrawer::ThreePiecesVertical; |
|
228 } |
|
229 |
|
230 QStringList list; |
|
231 QString frameGraphicsFooter; |
|
232 // data->state already set by abstractbutton's data init |
|
233 QIcon::Mode mode = HbStylePrivate::iconMode(data->state); |
|
234 QIcon::State state = HbStylePrivate::iconState(data->state); |
|
235 |
|
236 // custom background |
|
237 if (!q->background().isNull()) { |
|
238 data->frameGraphicsName = customBackground.iconName(mode, state); |
|
239 return; |
|
240 } |
|
241 |
|
242 // in toolbar extension |
|
243 if(isToolBarExtension()) { |
|
244 if (mode == QIcon::Normal && state == QIcon::On) { |
|
245 if(!q->isCheckable()){ |
|
246 data->frameGraphicsName = QLatin1String("qtg_fr_popup_grid_pressed"); |
|
247 } else { |
|
248 data->frameGraphicsName = QLatin1String("qtg_fr_tb_ext"); |
|
249 } |
|
250 } else { |
|
251 data->frameGraphicsName = QLatin1String(""); |
|
252 } |
|
253 data->frameType = HbFrameDrawer::NinePieces; |
|
254 return; |
|
255 } |
|
256 |
|
257 if (!toolBarPosition) { |
|
258 if (mode == QIcon::Disabled && state == QIcon::Off) { |
|
259 data->frameGraphicsName = QLatin1String("qtg_fr_btn_disabled"); |
|
260 } else if (mode == QIcon::Normal && state == QIcon::On) { |
|
261 if(!q->isCheckable()){ |
|
262 data->frameGraphicsName = QLatin1String("qtg_fr_btn_pressed"); |
|
263 } else { |
|
264 data->frameGraphicsName = QLatin1String("qtg_fr_btn_latched"); |
|
265 } |
|
266 } else if (mode == QIcon::Selected && state == QIcon::Off) { |
|
267 data->frameGraphicsName = QLatin1String("qtg_fr_btn_highlight"); |
|
268 } else { |
|
269 data->frameGraphicsName = QLatin1String("qtg_fr_btn_normal"); |
|
270 } |
|
271 data->frameType = HbFrameDrawer::NinePieces; |
|
272 return; |
|
273 } |
|
274 // For toolbar: |
|
275 |
|
276 QString frameGraphicsHeader; |
|
277 if (!mDialogToolBar){ |
|
278 if (useTransparentGraphics()) { |
|
279 frameGraphicsHeader = orientation == Qt::Vertical ? |
|
280 QLatin1String("qtg_fr_tb_trans_h_"): |
|
281 QLatin1String("qtg_fr_tb_trans_v_"); |
|
282 } else { |
|
283 frameGraphicsHeader = orientation == Qt::Vertical ? |
|
284 QLatin1String("qtg_fr_tb_h_"): |
|
285 QLatin1String("qtg_fr_tb_v_"); |
|
286 } |
|
287 } else { |
|
288 frameGraphicsHeader = QLatin1String("qtg_fr_popup_sk_"); |
|
289 data->mirroringMode = HbIcon::LayoutDirection; |
|
290 } |
|
291 |
|
292 switch (toolBarPosition) { |
|
293 case TB_OnlyOne: |
|
294 if (orientation == Qt::Vertical) { |
|
295 list << QLatin1String("_l") << QLatin1String("_c") << QLatin1String("_r"); |
|
296 } else { |
|
297 list << QLatin1String("_t") << QLatin1String("_c") << QLatin1String("_b"); |
|
298 } |
|
299 break; |
|
300 case TB_Beginning: |
|
301 if (orientation== Qt::Vertical) { |
|
302 list << QLatin1String("_l") << QLatin1String("_c") << QLatin1String("_cr"); |
|
303 } else { |
|
304 list << QLatin1String("_t") << QLatin1String("_c") << QLatin1String("_cb"); |
|
305 } |
|
306 break; |
|
307 case TB_Middle: |
|
308 if (orientation == Qt::Vertical) { |
|
309 list << QLatin1String("_cl") << QLatin1String("_c") << QLatin1String("_cr"); |
|
310 } else { |
|
311 list << QLatin1String("_ct") << QLatin1String("_c") << QLatin1String("_cb"); |
|
312 } |
|
313 break; |
|
314 case TB_End: |
|
315 if (orientation== Qt::Vertical) { |
|
316 list << QLatin1String("_cl") << QLatin1String("_c") << QLatin1String("_r"); |
|
317 } else { |
|
318 list << QLatin1String("_ct") << QLatin1String("_c") << QLatin1String("_b"); |
|
319 } |
|
320 break; |
|
321 |
|
322 default: |
|
323 case TB_None: |
|
324 break; |
|
325 } // switch case end |
|
326 |
|
327 data->fileNameSuffixList = list; |
|
328 if (mode == QIcon::Disabled && state == QIcon::Off) { |
|
329 frameGraphicsFooter = QLatin1String("disabled"); |
|
330 } else if (mode == QIcon::Normal && state == QIcon::On) { |
|
331 if(!q->isCheckable()) { |
|
332 frameGraphicsFooter = QLatin1String("pressed"); |
|
333 } else { |
|
334 frameGraphicsFooter = QLatin1String("latched"); |
|
335 } |
|
336 } else if (mode == QIcon::Selected && state == QIcon::Off) { |
|
337 frameGraphicsFooter = QLatin1String("highlight"); |
|
338 } else { |
|
339 frameGraphicsFooter = QLatin1String("normal"); |
|
340 } |
|
341 data->frameGraphicsName = QString ("%0%1").arg(frameGraphicsHeader).arg(frameGraphicsFooter); |
|
342 data->mirroringMode = HbIcon::LayoutDirection; |
|
343 } |
|
344 |
|
345 void HbToolButtonPrivate::iconPrimitiveData(HbStyleIconPrimitiveData *data) |
|
346 { |
|
347 Q_Q(HbToolButton); |
|
348 if (q->action()) { |
|
349 data->icon = q->action()->icon(); |
|
350 } else if(action){ |
|
351 data->icon = action->icon(); |
|
352 } else { |
|
353 data->icon = HbIcon(); |
|
354 } |
|
355 data->iconMode = HbStylePrivate::iconMode(data->state); |
|
356 data->iconState = HbStylePrivate::iconState(data->state); |
|
357 return; |
|
358 } |
|
359 void HbToolButtonPrivate::textPrimitiveData(HbStyleTextPrimitiveData *data) |
|
360 { |
|
361 if(action) { |
|
362 data->text = action->text(); |
|
363 } else { |
|
364 data->text = QString(); |
238 } |
365 } |
239 } |
366 } |
240 |
367 |
241 QSizeF HbToolButtonPrivate::getMinimumSize() |
368 QSizeF HbToolButtonPrivate::getMinimumSize() |
242 { |
369 { |
264 |
390 |
265 void HbToolButtonPrivate::_q_actionChanged() |
391 void HbToolButtonPrivate::_q_actionChanged() |
266 { |
392 { |
267 Q_Q(HbToolButton); |
393 Q_Q(HbToolButton); |
268 HbAction *hbAction = qobject_cast<HbAction *>(action); |
394 HbAction *hbAction = qobject_cast<HbAction *>(action); |
269 if ((hbAction && !hbAction->icon().isNull()) || !action->icon().isNull()) { |
395 bool oldIconProperty = q->property("icon").toBool(); |
270 if (orientation == Qt::Horizontal) { |
396 bool oldTextProperty = q->property("text").toBool(); |
271 buttonStyle = HbToolButton::ToolButtonIcon; |
397 if ((hbAction && !hbAction->icon().isNull()) || (action && !action->icon().isNull())) { |
272 } else if (!action->text().isEmpty()) { |
398 q->setProperty("icon", true); |
273 buttonStyle = HbToolButton::ToolButtonTextAndIcon; |
399 } else { |
274 } else { |
400 q->setProperty("icon", false); |
275 buttonStyle = HbToolButton::ToolButtonIcon; |
401 } |
276 } |
402 if ((!action->text().isEmpty() && (orientation == Qt::Vertical || isToolBarExtension())) || |
277 } else { |
403 (orientation == Qt::Horizontal && !q->property("icon").toBool())) { |
278 buttonStyle = HbToolButton::ToolButtonText; |
404 q->setProperty("text", true); |
279 } |
405 } else { |
280 // action text/icon may have changed, |
406 q->setProperty("text", false); |
281 if (polished) { |
407 } |
282 q->repolish(); |
408 if (oldTextProperty != q->property("text").toBool() || |
283 QCoreApplication::sendPostedEvents(q, QEvent::Polish); |
409 oldIconProperty != q->property("icon").toBool()) { |
|
410 q->repolish(); |
|
411 } else if (polished) { |
|
412 q->updatePrimitives(); |
284 } |
413 } |
285 } |
414 } |
286 |
415 |
287 void HbToolButtonPrivate::showToolTip() |
416 void HbToolButtonPrivate::showToolTip() |
288 { |
417 { |
355 d->action = action; |
484 d->action = action; |
356 if (d->action) { |
485 if (d->action) { |
357 connect(action, SIGNAL(triggered()), this, SLOT(_q_actionTriggered())); |
486 connect(action, SIGNAL(triggered()), this, SLOT(_q_actionTriggered())); |
358 connect(action, SIGNAL(changed()), this, SLOT(_q_actionChanged())); |
487 connect(action, SIGNAL(changed()), this, SLOT(_q_actionChanged())); |
359 } |
488 } |
360 |
489 // If action was null then there is a chance that the iconitem is not yet created. |
|
490 // If the new action is null then we may need to get rid of the icon completely. |
|
491 if ((!oldAction && action) || (oldAction && !action)) { |
|
492 repolish(); // will call createPrimitives() |
|
493 } |
361 if (isVisible() && d->polished) { |
494 if (isVisible() && d->polished) { |
362 // If action was null then there is a chance that the iconitem is not yet created. |
|
363 // If the new action is null then we may need to get rid of the icon completely. |
|
364 if ((!oldAction && action) || (oldAction && !action)) { |
|
365 repolish(); // will call createPrimitives() |
|
366 } |
|
367 updatePrimitives(); |
495 updatePrimitives(); |
368 } |
496 } |
369 } |
497 } |
370 |
498 |
371 /*! |
499 /*! |
389 updatePrimitives(); |
517 updatePrimitives(); |
390 } |
518 } |
391 } |
519 } |
392 |
520 |
393 /*! |
521 /*! |
394 \deprecated HbToolButton::toolButtonStyle() const |
|
395 is deprecated. |
|
396 |
|
397 @beta |
|
398 Returns the tool button style. |
|
399 |
|
400 The default value is \b HbToolButton::ToolButtonIcon. |
|
401 |
|
402 \sa setToolButtonStyle() |
|
403 */ |
|
404 HbToolButton::ToolButtonStyle HbToolButton::toolButtonStyle() const |
|
405 { |
|
406 HB_DEPRECATED("HbToolButton::toolButtonStyle() is deprecated."); |
|
407 |
|
408 Q_D(const HbToolButton); |
|
409 return d->buttonStyle; |
|
410 } |
|
411 |
|
412 /*! |
|
413 \deprecated HbToolButton::setToolButtonStyle(HbToolButton::ToolButtonStyle) |
|
414 is deprecated. |
|
415 |
|
416 @beta |
|
417 Sets the tool button style. |
|
418 |
|
419 \sa toolButtonStyle() |
|
420 */ |
|
421 void HbToolButton::setToolButtonStyle(HbToolButton::ToolButtonStyle style) |
|
422 { |
|
423 HB_DEPRECATED("HbToolButton::setToolButtonStyle(HbToolButton::ToolButtonStyle style) is deprecated."); |
|
424 |
|
425 Q_D(HbToolButton); |
|
426 if (d->buttonStyle != style) { |
|
427 d->buttonStyle = style; |
|
428 |
|
429 // action text/icon may have changed, |
|
430 // primitives might need to be created/cleaned up |
|
431 if (size() != QSize(0, 0)) { |
|
432 repolish(); |
|
433 } |
|
434 } |
|
435 } |
|
436 |
|
437 /*! |
|
438 |
|
439 \deprecated HbToolButton::primitive(HbStyle::Primitive) |
|
440 is deprecated. |
|
441 |
|
442 \reimp |
522 \reimp |
443 */ |
523 */ |
444 QGraphicsItem *HbToolButton::primitive(HbStyle::Primitive primitive) const |
|
445 { |
|
446 Q_D(const HbToolButton); |
|
447 switch (primitive) { |
|
448 case HbStyle::P_ToolButton_frame: |
|
449 return d->frameItem; |
|
450 case HbStyle::P_ToolButton_icon: |
|
451 return d->iconItem; |
|
452 case HbStyle::P_ToolButton_text: |
|
453 return d->textItem; |
|
454 default: |
|
455 return 0; |
|
456 } |
|
457 } |
|
458 |
|
459 /*! |
|
460 \reimp |
|
461 */ |
|
462 void HbToolButton::updatePrimitives() |
524 void HbToolButton::updatePrimitives() |
463 { |
525 { |
464 Q_D(HbToolButton); |
526 Q_D(HbToolButton); |
465 |
527 |
466 HbStyleOptionToolButton option; |
|
467 if (d->action) { |
528 if (d->action) { |
468 setCheckable(d->action->isCheckable()); |
529 setCheckable(d->action->isCheckable()); |
469 setChecked(d->action->isChecked()); |
530 setChecked(d->action->isChecked()); |
470 setEnabled(d->action->isEnabled()); |
531 setEnabled(d->action->isEnabled()); |
471 HbAction *hbAction = qobject_cast<HbAction *>(d->action); |
532 HbAction *hbAction = qobject_cast<HbAction *>(d->action); |
483 setChecked(false); |
544 setChecked(false); |
484 setEnabled(false); |
545 setEnabled(false); |
485 setToolTip(QString()); |
546 setToolTip(QString()); |
486 } |
547 } |
487 |
548 |
488 initStyleOption(&option); |
|
489 setProperty("dialogtoolbar", d->mDialogToolBar); |
549 setProperty("dialogtoolbar", d->mDialogToolBar); |
490 if (d->frameItem) { |
550 if (d->frameItem) { |
491 style()->updatePrimitive(d->frameItem, HbStyle::P_ToolButton_frame, &option); |
551 HbStyleFramePrimitiveData data; |
|
552 initPrimitiveData(&data, d->frameItem); |
|
553 style()->updatePrimitive(d->frameItem, &data, this); |
|
554 d->frameItem->update(); |
|
555 } |
|
556 if (d->iconItem) { |
|
557 HbStyleIconPrimitiveData data; |
|
558 initPrimitiveData(&data, d->iconItem); |
|
559 |
|
560 bool itemHasNoContents = false; |
|
561 if (data.icon.isSet()) { |
|
562 if (data.icon.value().isNull()) { |
|
563 itemHasNoContents = true; |
|
564 } else { |
|
565 style()->updatePrimitive(d->iconItem, &data, this); |
|
566 d->iconItem->update(); |
|
567 } |
|
568 } |
|
569 if (itemHasNoContents) { |
|
570 setProperty("icon", false); |
|
571 } else { |
|
572 setProperty("icon", true); |
|
573 } |
|
574 d->iconItem->setFlag(QGraphicsItem::ItemHasNoContents, itemHasNoContents); |
492 } |
575 } |
493 if (d->textItem) { |
576 if (d->textItem) { |
494 style()->updatePrimitive(d->textItem, HbStyle::P_ToolButton_text, &option); |
577 HbStyleTextPrimitiveData data; |
495 } |
578 initPrimitiveData(&data, d->textItem); |
496 if (d->iconItem) { |
579 bool itemHasNoContents = false; |
497 style()->updatePrimitive(d->iconItem, HbStyle::P_ToolButton_icon, &option); |
580 if (data.text.isSet()) { |
498 HbAction *hbAction = qobject_cast<HbAction *>(d->action); |
581 if ( data.text.value().isEmpty() || data.text.value().isNull()) { |
499 if (hbAction) { |
582 itemHasNoContents = true; |
500 if (hbAction->icon().flags() & HbIcon::Colorized) { |
583 } |
501 static_cast<HbIconItem *>(d->iconItem)->setFlags(HbIcon::Colorized); |
584 } |
502 } |
585 if ((!property("icon").toBool() && d->orientation == Qt::Horizontal) || |
503 if (hbAction->icon().mirroringMode() != HbIcon::Default) { |
586 (!itemHasNoContents && (d->orientation == Qt::Vertical || d->isToolBarExtension()))) { |
504 HbIconItem *iconItem = static_cast<HbIconItem *>(d->iconItem); |
587 setProperty("text", true); |
505 iconItem->setMirroringMode( hbAction->icon().mirroringMode() ); |
588 itemHasNoContents = false; |
506 } |
589 } else { |
507 } |
590 setProperty("text", false); |
508 |
591 itemHasNoContents = true; |
509 } |
592 } |
510 } |
593 d->textItem->setFlag(QGraphicsItem::ItemHasNoContents, itemHasNoContents); |
511 |
594 if(!itemHasNoContents) { |
512 /*! |
595 style()->updatePrimitive(d->textItem, &data, this); |
513 Initializes \a option with the values from this HbToolButton. This method is useful for |
596 /* HbDialog::setPrimaryAction deprecation action coloring - begin */ |
514 subclasses when they need a HbStyleOptionToolButton, but don't want to fill in all the |
597 if (d->action && d->action->property("invalid_addition").isValid() ) { |
515 information themselves. |
598 HbTextItem *textItem = qgraphicsitem_cast<HbTextItem*>(d->textItem); |
516 */ |
599 textItem->setTextColor(QColor("magenta")); |
517 void HbToolButton::initStyleOption(HbStyleOptionToolButton *option) |
600 } |
518 { |
601 /* HbDialog::setPrimaryAction deprecation action coloring - end */ |
519 Q_D(HbToolButton); |
602 d->textItem->update(); |
520 HbAbstractButton::initStyleOption(option); |
603 } |
521 |
604 |
522 Q_ASSERT(option); |
605 /* HbDialog::setPrimaryAction deprecation action coloring - begin */ |
523 option->customBackground = d->customBackground; |
606 if (d->action && d->action->property("invalid_addition").isValid() ) { |
524 option->backgroundVisible = d->backgroundVisible; |
607 HbIconItem *iconItem = qgraphicsitem_cast<HbIconItem*>(d->iconItem); |
525 option->toolBarPosition = d->toolBarPosition; |
608 iconItem->setColor(QColor("magenta")); |
526 option->orientation = d->orientation; |
609 } |
527 option->isCheckable = d->checkable; |
610 /* HbDialog::setPrimaryAction deprecation action coloring - end */ |
528 option->useSecondaryGraphics = d->mDialogToolBar; |
611 } |
529 option->useTransparentGraphics = false; |
612 } |
530 if (mainWindow() && mainWindow()->currentView()) { |
613 |
531 if (mainWindow()->currentView()->viewFlags() & HbView::ViewTitleBarTransparent) { |
|
532 option->useTransparentGraphics = true; |
|
533 } |
|
534 } |
|
535 |
|
536 if (d->action) { |
|
537 option->text = d->action->text(); |
|
538 HbAction *hbAction = qobject_cast<HbAction*>(d->action); |
|
539 if (hbAction) |
|
540 option->icon = hbAction->icon(); |
|
541 else |
|
542 option->icon = d->action->icon(); |
|
543 |
|
544 option->isToolBarExtension = d->toolbarExtensionFrame; |
|
545 } |
|
546 } |
|
547 |
614 |
548 /*! |
615 /*! |
549 \internal |
616 \internal |
550 */ |
617 */ |
551 HbToolButton::HbToolButton(HbToolButtonPrivate &dd, QGraphicsItem *parent) : |
618 HbToolButton::HbToolButton(HbToolButtonPrivate &dd, QGraphicsItem *parent) : |
589 } |
656 } |
590 |
657 |
591 /*! |
658 /*! |
592 \reimp |
659 \reimp |
593 */ |
660 */ |
|
661 void HbToolButton::checkStateSet() |
|
662 { |
|
663 Q_D(HbToolButton); |
|
664 if (d->checked || (d->checkable && d->down)) { |
|
665 setProperty( "state", "latched" ); |
|
666 } else if (d->down) { |
|
667 setProperty( "state", "pressed" ); |
|
668 } else { |
|
669 setProperty( "state", "normal" ); |
|
670 } |
|
671 } |
|
672 |
|
673 /*! |
|
674 \reimp |
|
675 */ |
594 bool HbToolButton::sceneEvent(QEvent *event) |
676 bool HbToolButton::sceneEvent(QEvent *event) |
595 { |
677 { |
596 if (event->type() == QEvent::GraphicsSceneHelp) { |
678 if (event->type() == QEvent::GraphicsSceneHelp) { |
597 Q_D(HbToolButton); |
679 Q_D(HbToolButton); |
598 // Check whether toolbutton is inside a toolbar. |
680 // Check whether toolbutton is inside a toolbar. |
599 if (d->toolBarPosition != HbStyleOptionToolButton::TB_None) { |
681 if (d->toolBarPosition != HbToolButtonPrivate::TB_None) { |
600 d->showToolTip(); |
682 d->showToolTip(); |
601 event->accept(); |
683 event->accept(); |
602 return true; |
684 return true; |
603 } |
685 } |
604 } |
686 } |
605 return HbAbstractButton::sceneEvent(event); |
687 return HbAbstractButton::sceneEvent(event); |
606 } |
688 } |
607 |
689 |
|
690 void HbToolButton::initPrimitiveData(HbStylePrimitiveData *primitiveData, const QGraphicsObject *primitive) |
|
691 { |
|
692 Q_D(HbToolButton); |
|
693 HbAbstractButton::initPrimitiveData(primitiveData, primitive); |
|
694 QString itemName = HbStyle::itemName(primitive); |
|
695 if (itemName == QLatin1String("background")) { |
|
696 d->framePrimitiveData(hbstyleprimitivedata_cast<HbStyleFramePrimitiveData*>(primitiveData)); |
|
697 } else if (itemName == QLatin1String("text")) { |
|
698 d->textPrimitiveData(hbstyleprimitivedata_cast<HbStyleTextPrimitiveData*>(primitiveData)); |
|
699 } else if (itemName == QLatin1String("icon")) { |
|
700 d->iconPrimitiveData(hbstyleprimitivedata_cast<HbStyleIconPrimitiveData*>(primitiveData)); |
|
701 } |
|
702 } |
|
703 |
608 /*! |
704 /*! |
609 \reimp |
705 \reimp |
610 */ |
706 */ |
611 bool HbToolButton::event(QEvent *event) |
707 bool HbToolButton::event(QEvent *event) |
612 { |
708 { |
613 if (event->type() == QEvent::GraphicsSceneMouseRelease) { |
709 if (event->type() == QEvent::GraphicsSceneMouseRelease) { |
614 mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent*>(event)); |
710 mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent*>(event)); |
615 return true; |
711 return true; |
|
712 } else if(event->type() == HbEvent::ThemeChanged) { |
|
713 Q_D(HbToolButton); |
|
714 changeEvent(event); |
|
715 if (d->frameItem) { |
|
716 HbFrameItem *item = static_cast<HbFrameItem*>(d->frameItem); |
|
717 item->frameDrawer().themeChanged(); |
|
718 } |
616 } |
719 } |
617 |
720 |
618 return HbAbstractButton::event(event); |
721 return HbAbstractButton::event(event); |
619 } |
722 } |
620 |
723 |