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 "hbstyle_p.h" |
|
35 #include <hbglobal.h> |
|
36 #include "hbcolorscheme.h" |
33 #include "hbcolorscheme.h" |
37 #include "hbtextitem.h" |
34 #include "hbtextitem.h" |
38 #include "hbiconitem.h" |
35 #include "hbiconitem.h" |
39 #include "hbview.h" |
36 #include "hbview.h" |
40 #include "hbmainwindow.h" |
37 #include "hbmainwindow.h" |
41 |
38 |
42 #include "hbglobal_p.h" // remove when removing HB_DEPRECATED |
39 #include "hbglobal_p.h" // remove when removing HB_DEPRECATED |
|
40 |
|
41 #include "hbstyle_p.h" // for iconmodes... |
|
42 |
|
43 #include <hbstyleframeprimitivedata.h> |
|
44 #include <hbstyleiconprimitivedata.h> |
|
45 #include <hbstyletextprimitivedata.h> |
43 |
46 |
44 #include <QGraphicsSceneHelpEvent> |
47 #include <QGraphicsSceneHelpEvent> |
45 #include <QGraphicsSceneMouseEvent> |
48 #include <QGraphicsSceneMouseEvent> |
46 #include <QCoreApplication> |
49 #include <QCoreApplication> |
47 |
50 |
118 void HbToolButtonPrivate::createPrimitives() |
121 void HbToolButtonPrivate::createPrimitives() |
119 { |
122 { |
120 Q_Q(HbToolButton); |
123 Q_Q(HbToolButton); |
121 if (backgroundVisible) { |
124 if (backgroundVisible) { |
122 if (!frameItem){ |
125 if (!frameItem){ |
123 frameItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_ToolButton_frame, q); |
126 frameItem = q->style()->createPrimitive(HbStyle::PT_FrameItem, "background", q); |
124 } |
127 } |
125 } else if (frameItem) { |
128 } else if (frameItem) { |
126 delete frameItem; |
129 delete frameItem; |
127 frameItem = 0; |
130 frameItem = 0; |
128 } |
131 } |
129 if (!textItem) { |
132 if (!textItem) { |
130 textItem = static_cast<HbTextItem *>(HbStylePrivate::createPrimitive(HbStylePrivate::P_ToolButton_text, q)); |
133 textItem = q->style()->createPrimitive(HbStyle::PT_TextItem, "text", q); |
131 textItem->setTextWrapping(Hb::TextWordWrap); |
134 } |
132 } // I dare you to optimize this |
135 HbStyleTextPrimitiveData textData; |
|
136 textData.textWrapping = Hb::TextWordWrap; |
|
137 q->style()->updatePrimitive(textItem, &textData, q); |
|
138 |
133 if (!iconItem) { |
139 if (!iconItem) { |
134 iconItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_ToolButton_icon, q); |
140 iconItem = q->style()->createPrimitive(HbStyle::PT_IconItem, "icon", q); |
135 } |
141 } |
|
142 |
136 } |
143 } |
137 |
144 |
138 void HbToolButtonPrivate::setOrientation(Qt::Orientation orientation) |
145 void HbToolButtonPrivate::setOrientation(Qt::Orientation orientation) |
139 { |
146 { |
140 if (this->orientation != orientation) { |
147 if (this->orientation != orientation) { |
183 |
190 |
184 void HbToolButtonPrivate::setLayoutProperty(const char *name, bool value) |
191 void HbToolButtonPrivate::setLayoutProperty(const char *name, bool value) |
185 { |
192 { |
186 Q_Q(HbToolButton); |
193 Q_Q(HbToolButton); |
187 q->setProperty(name, value); |
194 q->setProperty(name, value); |
188 q->repolish(); |
195 q->repolish(); |
|
196 } |
|
197 |
|
198 |
|
199 bool HbToolButtonPrivate::useTransparentGraphics() const |
|
200 { |
|
201 Q_Q(const HbToolButton); |
|
202 if (q->mainWindow() && q->mainWindow()->currentView()) { |
|
203 if (q->mainWindow()->currentView()->viewFlags() & HbView::ViewTitleBarTransparent) { |
|
204 return true; |
|
205 } |
|
206 } |
|
207 return false; |
|
208 } |
|
209 |
|
210 bool HbToolButtonPrivate::isToolBarExtension() const |
|
211 { |
|
212 return (action != 0 && toolbarExtensionFrame); |
|
213 } |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 void HbToolButtonPrivate::framePrimitiveData(HbStyleFramePrimitiveData *data) |
|
219 { |
|
220 |
|
221 Q_Q(HbToolButton); |
|
222 |
|
223 data->fillWholeRect = true; |
|
224 |
|
225 if (orientation == Qt::Vertical) { |
|
226 data->frameType = HbFrameDrawer::ThreePiecesHorizontal; |
|
227 } else { |
|
228 data->frameType = HbFrameDrawer::ThreePiecesVertical; |
|
229 } |
|
230 |
|
231 QStringList list; |
|
232 QString frameGraphicsFooter; |
|
233 // data->state already set by abstractbutton's data init |
|
234 QIcon::Mode mode = HbStylePrivate::iconMode(data->state); |
|
235 QIcon::State state = HbStylePrivate::iconState(data->state); |
|
236 |
|
237 // custom background |
|
238 if (!q->background().isNull()) { |
|
239 data->frameGraphicsName = customBackground.iconName(mode, state); |
|
240 return; |
|
241 } |
|
242 |
|
243 // in toolbar extension |
|
244 if(isToolBarExtension()) { |
|
245 if (mode == QIcon::Normal && state == QIcon::On) { |
|
246 if(!q->isCheckable()){ |
|
247 data->frameGraphicsName = QLatin1String("qtg_fr_popup_grid_pressed"); |
|
248 } else { |
|
249 data->frameGraphicsName = QLatin1String("qtg_fr_tb_ext"); |
|
250 } |
|
251 } |
|
252 data->frameType = HbFrameDrawer::NinePieces; |
|
253 return; |
|
254 } |
|
255 |
|
256 if (!toolBarPosition) { |
|
257 if (mode == QIcon::Disabled && state == QIcon::Off) { |
|
258 data->frameGraphicsName = QLatin1String("qtg_fr_btn_disabled"); |
|
259 } else if (mode == QIcon::Normal && state == QIcon::On) { |
|
260 if(!q->isCheckable()){ |
|
261 data->frameGraphicsName = QLatin1String("qtg_fr_btn_pressed"); |
|
262 } else { |
|
263 data->frameGraphicsName = QLatin1String("qtg_fr_btn_latched"); |
|
264 } |
|
265 } else if (mode == QIcon::Selected && state == QIcon::Off) { |
|
266 data->frameGraphicsName = QLatin1String("qtg_fr_btn_highlight"); |
|
267 } else { |
|
268 data->frameGraphicsName = QLatin1String("qtg_fr_btn_normal"); |
|
269 } |
|
270 data->frameType = HbFrameDrawer::NinePieces; |
|
271 return; |
|
272 } |
|
273 // For toolbar: |
|
274 |
|
275 QString frameGraphicsHeader; |
|
276 if (!mDialogToolBar){ |
|
277 if (useTransparentGraphics()) { |
|
278 frameGraphicsHeader = orientation == Qt::Vertical ? |
|
279 QLatin1String("qtg_fr_tb_trans_h_"): |
|
280 QLatin1String("qtg_fr_tb_trans_v_"); |
|
281 } else { |
|
282 frameGraphicsHeader = orientation == Qt::Vertical ? |
|
283 QLatin1String("qtg_fr_tb_h_"): |
|
284 QLatin1String("qtg_fr_tb_v_"); |
|
285 } |
|
286 }else { |
|
287 frameGraphicsHeader = QLatin1String("qtg_fr_popup_sk_"); |
|
288 data->mirroringMode = HbIcon::LayoutDirection; |
|
289 } |
|
290 |
|
291 switch (toolBarPosition) { |
|
292 case TB_OnlyOne: |
|
293 if (orientation == Qt::Vertical) { |
|
294 list << QLatin1String("_l") << QLatin1String("_c") << QLatin1String("_r"); |
|
295 } else { |
|
296 list << QLatin1String("_t") << QLatin1String("_c") << QLatin1String("_b"); |
|
297 } |
|
298 break; |
|
299 case TB_Beginning: |
|
300 if (orientation== Qt::Vertical) { |
|
301 list << QLatin1String("_l") << QLatin1String("_c") << QLatin1String("_cr"); |
|
302 } else { |
|
303 list << QLatin1String("_t") << QLatin1String("_c") << QLatin1String("_cb"); |
|
304 } |
|
305 break; |
|
306 case TB_Middle: |
|
307 if (orientation == Qt::Vertical) { |
|
308 list << QLatin1String("_cl") << QLatin1String("_c") << QLatin1String("_cr"); |
|
309 } else { |
|
310 list << QLatin1String("_ct") << QLatin1String("_c") << QLatin1String("_cb"); |
|
311 } |
|
312 break; |
|
313 case TB_End: |
|
314 if (orientation== Qt::Vertical) { |
|
315 list << QLatin1String("_cl") << QLatin1String("_c") << QLatin1String("_r"); |
|
316 } else { |
|
317 list << QLatin1String("_ct") << QLatin1String("_c") << QLatin1String("_b"); |
|
318 } |
|
319 break; |
|
320 |
|
321 default: |
|
322 case TB_None: |
|
323 break; |
|
324 }; // switch case end |
|
325 |
|
326 |
|
327 |
|
328 data->fileNameSuffixList = list; |
|
329 if (mode == QIcon::Disabled && state == QIcon::Off) { |
|
330 frameGraphicsFooter = QLatin1String("disabled"); |
|
331 } else if (mode == QIcon::Normal && state == QIcon::On) { |
|
332 if(!q->isCheckable()) { |
|
333 frameGraphicsFooter = QLatin1String("pressed"); |
|
334 } else { |
|
335 frameGraphicsFooter = QLatin1String("latched"); |
|
336 } |
|
337 } else if (mode == QIcon::Selected && state == QIcon::Off) { |
|
338 frameGraphicsFooter = QLatin1String("highlight"); |
|
339 } else { |
|
340 frameGraphicsFooter = QLatin1String("normal"); |
|
341 } |
|
342 data->frameGraphicsName = QString ("%0%1").arg(frameGraphicsHeader).arg(frameGraphicsFooter); |
|
343 data->mirroringMode = HbIcon::LayoutDirection; |
|
344 return; |
|
345 |
|
346 } |
|
347 void HbToolButtonPrivate::iconPrimitiveData(HbStyleIconPrimitiveData *data) |
|
348 { |
|
349 Q_Q(HbToolButton); |
|
350 if (q->action()) |
|
351 data->icon = q->action()->icon(); |
|
352 |
|
353 data->iconMode = HbStylePrivate::iconMode(data->state); |
|
354 data->iconState = HbStylePrivate::iconState(data->state); |
|
355 return; |
|
356 } |
|
357 void HbToolButtonPrivate::textPrimitiveData(HbStyleTextPrimitiveData *data) |
|
358 { |
|
359 Q_Q(HbToolButton); |
|
360 if (q->action()) |
|
361 data->text = q->action()->text(); |
|
362 return; |
189 } |
363 } |
190 |
364 |
191 QSizeF HbToolButtonPrivate::getMinimumSize() |
365 QSizeF HbToolButtonPrivate::getMinimumSize() |
192 { |
366 { |
193 Q_Q(HbToolButton); |
367 Q_Q(HbToolButton); |
339 if (isVisible() || d->polished) |
513 if (isVisible() || d->polished) |
340 updatePrimitives(); |
514 updatePrimitives(); |
341 } |
515 } |
342 } |
516 } |
343 |
517 |
344 |
518 /*! |
345 /*! |
|
346 |
|
347 \deprecated HbToolButton::primitive(HbStyle::Primitive) |
|
348 is deprecated. |
|
349 |
|
350 \reimp |
519 \reimp |
351 */ |
520 */ |
352 QGraphicsItem *HbToolButton::primitive(HbStyle::Primitive primitive) const |
|
353 { |
|
354 Q_D(const HbToolButton); |
|
355 switch (primitive) { |
|
356 case HbStylePrivate::P_ToolButton_frame: |
|
357 return d->frameItem; |
|
358 case HbStylePrivate::P_ToolButton_icon: |
|
359 return d->iconItem; |
|
360 case HbStylePrivate::P_ToolButton_text: |
|
361 return d->textItem; |
|
362 default: |
|
363 return 0; |
|
364 } |
|
365 } |
|
366 |
|
367 /*! |
|
368 \reimp |
|
369 */ |
|
370 void HbToolButton::updatePrimitives() |
521 void HbToolButton::updatePrimitives() |
371 { |
522 { |
372 Q_D(HbToolButton); |
523 Q_D(HbToolButton); |
373 |
524 |
374 HbStyleOptionToolButton option; |
525 |
375 if (d->action) { |
526 if (d->action) { |
376 setCheckable(d->action->isCheckable()); |
527 setCheckable(d->action->isCheckable()); |
377 setChecked(d->action->isChecked()); |
528 setChecked(d->action->isChecked()); |
378 setEnabled(d->action->isEnabled()); |
529 setEnabled(d->action->isEnabled()); |
379 HbAction *hbAction = qobject_cast<HbAction *>(d->action); |
530 HbAction *hbAction = qobject_cast<HbAction *>(d->action); |
391 setChecked(false); |
542 setChecked(false); |
392 setEnabled(false); |
543 setEnabled(false); |
393 setToolTip(QString()); |
544 setToolTip(QString()); |
394 } |
545 } |
395 |
546 |
396 initStyleOption(&option); |
|
397 setProperty("dialogtoolbar", d->mDialogToolBar); |
547 setProperty("dialogtoolbar", d->mDialogToolBar); |
398 if (d->frameItem) { |
548 if (d->frameItem) { |
399 HbStylePrivate::updatePrimitive(d->frameItem, HbStylePrivate::P_ToolButton_frame, &option); |
549 HbStyleFramePrimitiveData data; |
|
550 initPrimitiveData(&data, d->frameItem); |
|
551 style()->updatePrimitive(d->frameItem, &data, this); |
|
552 d->frameItem->update(); |
400 } |
553 } |
401 if (d->textItem) { |
554 if (d->textItem) { |
|
555 HbStyleTextPrimitiveData data; |
|
556 initPrimitiveData(&data, d->textItem); |
402 bool itemHasNoContents = false; |
557 bool itemHasNoContents = false; |
403 if (option.text.isEmpty() || option.text.isNull() || |
558 if (data.text.isSet()) { |
404 (property(BUTTONSTYLE).toInt() == HbToolButtonPrivate::ToolButtonIcon)) { |
559 if ( data.text.value().isEmpty() || data.text.value().isNull() || |
405 itemHasNoContents = true; |
560 (property(BUTTONSTYLE).toInt() == HbToolButtonPrivate::ToolButtonIcon)) { |
|
561 itemHasNoContents = true; |
|
562 } |
406 } |
563 } |
407 d->textItem->setFlag(QGraphicsItem::ItemHasNoContents, itemHasNoContents); |
564 d->textItem->setFlag(QGraphicsItem::ItemHasNoContents, itemHasNoContents); |
408 if(!itemHasNoContents) |
565 if(!itemHasNoContents) { |
409 HbStylePrivate::updatePrimitive(d->textItem, HbStylePrivate::P_ToolButton_text, &option); |
566 |
|
567 style()->updatePrimitive(d->textItem, &data, this); |
|
568 d->textItem->update(); |
|
569 } |
410 } |
570 } |
411 if (d->iconItem) { |
571 if (d->iconItem) { |
|
572 HbStyleIconPrimitiveData data; |
|
573 initPrimitiveData(&data, d->iconItem); |
|
574 |
412 bool itemHasNoContents = false; |
575 bool itemHasNoContents = false; |
413 if (option.icon.isNull() || (property(BUTTONSTYLE).toInt() == HbToolButtonPrivate::ToolButtonText)) { |
576 if (data.icon.isSet()) { |
414 itemHasNoContents = true; |
577 if (data.icon.value().isNull() || (property(BUTTONSTYLE).toInt() == HbToolButtonPrivate::ToolButtonText)) { |
415 } else { |
578 itemHasNoContents = true; |
416 HbStylePrivate::updatePrimitive(d->iconItem, HbStylePrivate::P_ToolButton_icon, &option); |
579 } else { |
417 if (option.icon.flags() & HbIcon::Colorized) { |
580 style()->updatePrimitive(d->iconItem, &data, this); |
418 static_cast<HbIconItem *>(d->iconItem)->setFlags(HbIcon::Colorized); |
581 d->iconItem->update(); |
419 } |
582 } |
420 if (option.icon.mirroringMode() != HbIcon::Default) { |
|
421 HbIconItem *iconItem = static_cast<HbIconItem *>(d->iconItem); |
|
422 iconItem->setMirroringMode( option.icon.mirroringMode() ); |
|
423 } |
|
424 } |
583 } |
425 d->iconItem->setFlag(QGraphicsItem::ItemHasNoContents, itemHasNoContents); |
584 d->iconItem->setFlag(QGraphicsItem::ItemHasNoContents, itemHasNoContents); |
426 } |
585 } |
427 } |
586 |
428 |
587 } |
429 /*! |
588 |
430 Initializes \a option with the values from this HbToolButton. This method is useful for |
|
431 subclasses when they need a HbStyleOptionToolButton, but don't want to fill in all the |
|
432 information themselves. |
|
433 */ |
|
434 void HbToolButton::initStyleOption(HbStyleOptionToolButton *option) |
|
435 { |
|
436 Q_D(HbToolButton); |
|
437 HbAbstractButton::initStyleOption(option); |
|
438 |
|
439 Q_ASSERT(option); |
|
440 option->customBackground = d->customBackground; |
|
441 option->backgroundVisible = d->backgroundVisible; |
|
442 option->toolBarPosition = d->toolBarPosition; |
|
443 option->orientation = d->orientation; |
|
444 option->isCheckable = d->checkable; |
|
445 option->useSecondaryGraphics = d->mDialogToolBar; |
|
446 option->useTransparentGraphics = false; |
|
447 if (mainWindow() && mainWindow()->currentView()) { |
|
448 if (mainWindow()->currentView()->viewFlags() & HbView::ViewTitleBarTransparent) { |
|
449 option->useTransparentGraphics = true; |
|
450 } |
|
451 } |
|
452 |
|
453 if (d->action) { |
|
454 option->text = d->action->text(); |
|
455 HbAction *hbAction = qobject_cast<HbAction*>(d->action); |
|
456 if (hbAction) |
|
457 option->icon = hbAction->icon(); |
|
458 else |
|
459 option->icon = d->action->icon(); |
|
460 |
|
461 option->isToolBarExtension = d->toolbarExtensionFrame; |
|
462 } |
|
463 } |
|
464 |
589 |
465 /*! |
590 /*! |
466 \internal |
591 \internal |
467 */ |
592 */ |
468 HbToolButton::HbToolButton(HbToolButtonPrivate &dd, QGraphicsItem *parent) : |
593 HbToolButton::HbToolButton(HbToolButtonPrivate &dd, QGraphicsItem *parent) : |
511 bool HbToolButton::sceneEvent(QEvent *event) |
636 bool HbToolButton::sceneEvent(QEvent *event) |
512 { |
637 { |
513 if (event->type() == QEvent::GraphicsSceneHelp) { |
638 if (event->type() == QEvent::GraphicsSceneHelp) { |
514 Q_D(HbToolButton); |
639 Q_D(HbToolButton); |
515 // Check whether toolbutton is inside a toolbar. |
640 // Check whether toolbutton is inside a toolbar. |
516 if (d->toolBarPosition != HbStyleOptionToolButton::TB_None) { |
641 if (d->toolBarPosition != HbToolButtonPrivate::TB_None) { |
517 d->showToolTip(); |
642 d->showToolTip(); |
518 event->accept(); |
643 event->accept(); |
519 return true; |
644 return true; |
520 } |
645 } |
521 } |
646 } |
522 return HbAbstractButton::sceneEvent(event); |
647 return HbAbstractButton::sceneEvent(event); |
|
648 } |
|
649 |
|
650 void HbToolButton::initPrimitiveData(HbStylePrimitiveData *primitiveData, const QGraphicsObject *primitive) |
|
651 { |
|
652 Q_D(HbToolButton); |
|
653 HbAbstractButton::initPrimitiveData(primitiveData, primitive); |
|
654 QString itemName = HbStyle::itemName(primitive); |
|
655 if (itemName == QLatin1String("background")) { |
|
656 d->framePrimitiveData(hbstyleprimitivedata_cast<HbStyleFramePrimitiveData*>(primitiveData)); |
|
657 } else if (itemName == QLatin1String("text")) { |
|
658 d->textPrimitiveData(hbstyleprimitivedata_cast<HbStyleTextPrimitiveData*>(primitiveData)); |
|
659 } else if (itemName == QLatin1String("icon")) { |
|
660 d->iconPrimitiveData(hbstyleprimitivedata_cast<HbStyleIconPrimitiveData*>(primitiveData)); |
|
661 } |
523 } |
662 } |
524 |
663 |
525 /*! |
664 /*! |
526 \reimp |
665 \reimp |
527 */ |
666 */ |