2 * NewGeom_NestedButton.cpp
4 * Created on: Apr 13, 2015
8 #include <NewGeom_NestedButton.h>
12 #include <QHBoxLayout>
13 #include <QToolButton>
16 NewGeom_NestedButton::NewGeom_NestedButton(QObject* theParent,
17 const QList<QAction*>& theNestedActions)
18 : QWidgetAction(theParent),
19 myNestedActions(theNestedActions),
20 myAdditionalButtonsWidget(0),
26 NewGeom_NestedButton::~NewGeom_NestedButton()
30 void NewGeom_NestedButton::showAdditionalButtons(bool isShow)
32 myAdditionalButtonsWidget->setVisible(isShow);
34 myButtonFrame->setFrameStyle(QFrame::WinPanel);
35 myButtonFrame->setFrameShadow(QFrame::Sunken);
36 myThisButton->setAutoRaise(false);
38 myButtonFrame->setFrameStyle(QFrame::NoFrame);
39 myButtonFrame->setFrameShadow(QFrame::Plain);
40 myThisButton->setAutoRaise(true);
44 QWidget * NewGeom_NestedButton::createWidget(QWidget * theParent)
46 myButtonFrame = new QFrame(theParent);
47 QHBoxLayout* aBoxLay = new QHBoxLayout(myButtonFrame);
48 aBoxLay->setContentsMargins(2, 0, 0, 0);
49 aBoxLay->setSpacing(1);
50 QSizePolicy aSizePolicy;
51 aSizePolicy.setControlType(QSizePolicy::ToolButton);
52 myButtonFrame->setSizePolicy(aSizePolicy);
54 myThisButton = new QToolButton(myButtonFrame);
55 myThisButton->setDefaultAction(this);
56 myThisButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
57 aBoxLay->addWidget(myThisButton, 1);
59 myAdditionalButtonsWidget = new QWidget(myButtonFrame);
60 QHBoxLayout* aAdditionalBoxLay = new QHBoxLayout(myAdditionalButtonsWidget);
61 aAdditionalBoxLay->setContentsMargins(0, 0, 0, 0);
62 aAdditionalBoxLay->setSpacing(1);
63 foreach (QAction* eachAct, myNestedActions) {
64 QToolButton* aButton = new QToolButton(myButtonFrame);
65 aButton->setDefaultAction(eachAct);
66 aButton->setAutoRaise(true);
67 aAdditionalBoxLay->addWidget(aButton);
69 myAdditionalButtonsWidget->setLayout(aAdditionalBoxLay);
70 aBoxLay->addWidget(myAdditionalButtonsWidget);
72 myButtonFrame->setLayout(aBoxLay);
74 showAdditionalButtons(false);
75 connect(this, SIGNAL(toggled(bool)), this, SLOT(showAdditionalButtons(bool)));
76 connect(this, SIGNAL(changed()), this, SLOT(actionStateChanged()));
80 bool NewGeom_NestedButton::event(QEvent* theEvent)
82 if (theEvent->type() == QEvent::ActionChanged) {
84 myThisButton->setEnabled(isEnabled());
88 return QWidgetAction::event(theEvent);
92 void NewGeom_NestedButton::actionStateChanged()