1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * SHAPERGUI_NestedButton.cpp
6 * Created on: Apr 13, 2015
10 #include <SHAPERGUI_NestedButton.h>
14 #include <QHBoxLayout>
15 #include <QToolButton>
19 SHAPERGUI_NestedButton::SHAPERGUI_NestedButton(QObject* theParent,
20 const QList<QAction*>& theNestedActions)
21 : QWidgetAction(theParent),
22 myNestedActions(theNestedActions),
23 myAdditionalButtonsWidget(0),
29 SHAPERGUI_NestedButton::~SHAPERGUI_NestedButton()
33 void SHAPERGUI_NestedButton::showAdditionalButtons(bool isShow)
35 myAdditionalButtonsWidget->setVisible(isShow);
37 myButtonFrame->setFrameStyle(QFrame::WinPanel);
38 myButtonFrame->setFrameShadow(QFrame::Sunken);
39 myThisButton->setAutoRaise(false);
41 myButtonFrame->setFrameStyle(QFrame::NoFrame);
42 myButtonFrame->setFrameShadow(QFrame::Plain);
43 myThisButton->setAutoRaise(true);
47 QWidget * SHAPERGUI_NestedButton::createWidget(QWidget * theParent)
49 // the action has widget only in tool bar, in menu bar, the default
50 // action presentation is shown
51 QToolBar* aToolBar = dynamic_cast<QToolBar*>(theParent);
55 myButtonFrame = new QFrame(theParent);
56 QHBoxLayout* aBoxLay = new QHBoxLayout(myButtonFrame);
57 aBoxLay->setContentsMargins(2, 0, 0, 0);
58 aBoxLay->setSpacing(1);
59 QSizePolicy aSizePolicy;
60 aSizePolicy.setControlType(QSizePolicy::ToolButton);
61 myButtonFrame->setSizePolicy(aSizePolicy);
63 myThisButton = new QToolButton(myButtonFrame);
64 myThisButton->setDefaultAction(this);
65 myThisButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
66 aBoxLay->addWidget(myThisButton, 1);
68 myAdditionalButtonsWidget = new QWidget(myButtonFrame);
69 QHBoxLayout* aAdditionalBoxLay = new QHBoxLayout(myAdditionalButtonsWidget);
70 aAdditionalBoxLay->setContentsMargins(0, 0, 0, 0);
71 aAdditionalBoxLay->setSpacing(1);
72 foreach (QAction* eachAct, myNestedActions) {
73 QToolButton* aButton = new QToolButton(myButtonFrame);
74 aButton->setDefaultAction(eachAct);
75 aButton->setAutoRaise(true);
76 aAdditionalBoxLay->addWidget(aButton);
78 myAdditionalButtonsWidget->setLayout(aAdditionalBoxLay);
79 aBoxLay->addWidget(myAdditionalButtonsWidget);
81 myButtonFrame->setLayout(aBoxLay);
83 showAdditionalButtons(false);
84 connect(this, SIGNAL(toggled(bool)), this, SLOT(showAdditionalButtons(bool)));
85 connect(this, SIGNAL(changed()), this, SLOT(actionStateChanged()));
89 bool SHAPERGUI_NestedButton::event(QEvent* theEvent)
91 if (theEvent->type() == QEvent::ActionChanged) {
93 myThisButton->setEnabled(isEnabled());
97 return QWidgetAction::event(theEvent);
101 void SHAPERGUI_NestedButton::actionStateChanged()