2 * SHAPERGUI_NestedButton.cpp
4 * Created on: Apr 13, 2015
8 #include <SHAPERGUI_NestedButton.h>
12 #include <QHBoxLayout>
13 #include <QToolButton>
17 SHAPERGUI_NestedButton::SHAPERGUI_NestedButton(QObject* theParent,
18 const QList<QAction*>& theNestedActions)
19 : QWidgetAction(theParent),
20 myNestedActions(theNestedActions),
21 myAdditionalButtonsWidget(0),
27 SHAPERGUI_NestedButton::~SHAPERGUI_NestedButton()
31 void SHAPERGUI_NestedButton::showAdditionalButtons(bool isShow)
33 myAdditionalButtonsWidget->setVisible(isShow);
35 myButtonFrame->setFrameStyle(QFrame::WinPanel);
36 myButtonFrame->setFrameShadow(QFrame::Sunken);
37 myThisButton->setAutoRaise(false);
39 myButtonFrame->setFrameStyle(QFrame::NoFrame);
40 myButtonFrame->setFrameShadow(QFrame::Plain);
41 myThisButton->setAutoRaise(true);
45 QWidget * SHAPERGUI_NestedButton::createWidget(QWidget * theParent)
47 // the action has widget only in tool bar, in menu bar, the default
48 // action presentation is shown
49 QToolBar* aToolBar = dynamic_cast<QToolBar*>(theParent);
53 myButtonFrame = new QFrame(theParent);
54 QHBoxLayout* aBoxLay = new QHBoxLayout(myButtonFrame);
55 aBoxLay->setContentsMargins(2, 0, 0, 0);
56 aBoxLay->setSpacing(1);
57 QSizePolicy aSizePolicy;
58 aSizePolicy.setControlType(QSizePolicy::ToolButton);
59 myButtonFrame->setSizePolicy(aSizePolicy);
61 myThisButton = new QToolButton(myButtonFrame);
62 myThisButton->setDefaultAction(this);
63 myThisButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
64 aBoxLay->addWidget(myThisButton, 1);
66 myAdditionalButtonsWidget = new QWidget(myButtonFrame);
67 QHBoxLayout* aAdditionalBoxLay = new QHBoxLayout(myAdditionalButtonsWidget);
68 aAdditionalBoxLay->setContentsMargins(0, 0, 0, 0);
69 aAdditionalBoxLay->setSpacing(1);
70 foreach (QAction* eachAct, myNestedActions) {
71 QToolButton* aButton = new QToolButton(myButtonFrame);
72 aButton->setDefaultAction(eachAct);
73 aButton->setAutoRaise(true);
74 aAdditionalBoxLay->addWidget(aButton);
76 myAdditionalButtonsWidget->setLayout(aAdditionalBoxLay);
77 aBoxLay->addWidget(myAdditionalButtonsWidget);
79 myButtonFrame->setLayout(aBoxLay);
81 showAdditionalButtons(false);
82 connect(this, SIGNAL(toggled(bool)), this, SLOT(showAdditionalButtons(bool)));
83 connect(this, SIGNAL(changed()), this, SLOT(actionStateChanged()));
87 bool SHAPERGUI_NestedButton::event(QEvent* theEvent)
89 if (theEvent->type() == QEvent::ActionChanged) {
91 myThisButton->setEnabled(isEnabled());
95 return QWidgetAction::event(theEvent);
99 void SHAPERGUI_NestedButton::actionStateChanged()