50 #include "hbeffectinternal_p.h" |
50 #include "hbeffectinternal_p.h" |
51 #define HB_TOOLBAR_ITEM_TYPE "HB_TOOLBAR" |
51 #define HB_TOOLBAR_ITEM_TYPE "HB_TOOLBAR" |
52 bool HbToolBarPrivate::effectsLoaded = false; |
52 bool HbToolBarPrivate::effectsLoaded = false; |
53 #endif |
53 #endif |
54 |
54 |
|
55 //If minimum button size cannot be calculated |
|
56 //more button will appear after default button count is exceeded |
|
57 static const int DEFAULT_TOOLBUTTON_COUNT = 5; |
|
58 |
55 HbToolBarPrivate::HbToolBarPrivate() : |
59 HbToolBarPrivate::HbToolBarPrivate() : |
56 mLayout(0), |
60 mLayout(0), |
57 mPressedDownButton(0), |
61 mPressedDownButton(0), |
58 mPreviouslyPressedDownButton(0), |
62 mPreviouslyPressedDownButton(0), |
59 mOrientation(Qt::Horizontal), |
63 mOrientation(Qt::Horizontal), |
170 |
175 |
171 } |
176 } |
172 |
177 |
173 void HbToolBarPrivate::calculateMaximumButtons() { |
178 void HbToolBarPrivate::calculateMaximumButtons() { |
174 Q_Q(HbToolBar); |
179 Q_Q(HbToolBar); |
175 maxToolBarButtons = 2; |
180 maxToolBarButtons = DEFAULT_TOOLBUTTON_COUNT; |
176 if (!minimumToolButtonSize.isEmpty()) { |
181 if (!minimumToolButtonSize.isEmpty()) { |
177 if (mOrientation == Qt::Horizontal) { |
182 if (mOrientation == Qt::Horizontal) { |
178 if ((q->size().width() > 0) && (q->size().width() > minimumToolButtonSize.width())) |
183 if ((q->size().width() > 0) && (q->size().width() > minimumToolButtonSize.width())) |
179 maxToolBarButtons = int(q->size().width() / minimumToolButtonSize.width()); |
184 maxToolBarButtons = int(q->size().width() / minimumToolButtonSize.width()); |
180 } else { |
185 } else { |
359 //creates a new toolbutton and calls actionAdded if update is true. |
364 //creates a new toolbutton and calls actionAdded if update is true. |
360 //update can be true in cases where toolbar is polished and actionAdded |
365 //update can be true in cases where toolbar is polished and actionAdded |
361 //event is recieved by toolbar. |
366 //event is recieved by toolbar. |
362 //we emit visibilitychanged signal here if this is the firstAction added in cases |
367 //we emit visibilitychanged signal here if this is the firstAction added in cases |
363 //after toolbar is polished and visible. |
368 //after toolbar is polished and visible. |
364 void HbToolBarPrivate::createToolButton(QAction *Action, bool update) |
369 void HbToolBarPrivate::createToolButton(QAction *newAction, bool update) |
365 { |
370 { |
366 Q_Q(HbToolBar); |
371 Q_Q(HbToolBar); |
367 if(!Action) |
372 if(!newAction) |
368 return; |
373 return; |
369 HbAction* action = qobject_cast<HbAction*>(Action); |
374 |
|
375 HbAction* action = qobject_cast<HbAction*>(newAction); |
370 |
376 |
371 if (action) { |
377 if (action) { |
372 // Find out index where to insert button |
378 // Find out index where to insert button |
373 int index = q->actions().indexOf(Action); |
379 int index = q->actions().indexOf(newAction); |
374 |
380 |
375 // Lets give the action manager possibility to calculate position for the action |
381 // Lets give the action manager possibility to calculate position for the action |
376 if (action->commandRole() != HbAction::NoRole) { |
382 if (action->commandRole() != HbAction::NoRole) { |
377 // Create action manager when needed |
383 // Create action manager when needed |
378 if (!actionManager) { |
384 if (!actionManager) { |
618 return; |
624 return; |
619 Q_Q(HbToolBar); |
625 Q_Q(HbToolBar); |
620 HbToolButton *button = 0; |
626 HbToolButton *button = 0; |
621 for (int i = 0; i < mToolButtons.count(); i++) { |
627 for (int i = 0; i < mToolButtons.count(); i++) { |
622 button = mToolButtons.at(i); |
628 button = mToolButtons.at(i); |
623 if (button->action() == event->action()) { |
629 if (button && button->action() == event->action()) { |
624 mToolButtons.removeAt(i); |
630 mToolButtons.removeAt(i); |
625 // Emit signal when the only action is removed |
631 // Emit signal when the only action is removed |
626 if (mToolButtons.count() == 0) { |
632 if (mToolButtons.count() == 0) { |
627 if (moreExtensionButton) |
633 if (moreExtensionButton) |
628 moreExtensionButton->setVisible(false); |
634 moreExtensionButton->setVisible(false); |
634 q->resize(0, 0); |
640 q->resize(0, 0); |
635 if (q->isVisible()) |
641 if (q->isVisible()) |
636 QMetaObject::invokeMethod(&core, "visibilityChanged", Qt::QueuedConnection); |
642 QMetaObject::invokeMethod(&core, "visibilityChanged", Qt::QueuedConnection); |
637 return; |
643 return; |
638 } |
644 } |
|
645 int index = mVisibleToolButtons.indexOf(button); |
|
646 if (index != -1){ |
|
647 mVisibleToolButtons.removeAt(index); |
|
648 if (mVisibleToolButtons.isEmpty()){ |
|
649 q->setLayout(0); |
|
650 mLayout = 0; |
|
651 } |
|
652 else |
|
653 actionRemoved(index,button); |
|
654 } |
|
655 delete button; |
|
656 |
639 break; |
657 break; |
640 } |
658 } |
641 } |
659 } |
642 int index = mVisibleToolButtons.indexOf(button); |
|
643 if (index != -1){ |
|
644 mVisibleToolButtons.removeAt(index); |
|
645 if (mVisibleToolButtons.isEmpty()){ |
|
646 q->setLayout(0); |
|
647 mLayout = 0; |
|
648 } |
|
649 else |
|
650 actionRemoved(index,button); |
|
651 } |
|
652 delete button; |
|
653 } |
660 } |
654 |
661 |
655 void HbToolBarPrivate::updateButtonStyle(HbToolButton *button,bool notInExtension) |
662 void HbToolBarPrivate::updateButtonStyle(HbToolButton *button,bool notInExtension) |
656 { |
663 { |
657 Q_Q(HbToolBar); |
664 Q_Q(HbToolBar); |