2 * NewGeom_NestedButton.cpp
4 * Created on: Apr 13, 2015
8 #include <NewGeom_NestedButton.h>
12 #include <QHBoxLayout>
13 #include <QToolButton>
15 NewGeom_NestedButton::NewGeom_NestedButton(QObject* theParent,
16 const QList<QAction*>& theNestedActions)
17 : QWidgetAction(theParent),
18 myNestedActions(theNestedActions),
19 myAdditionalButtonsWidget(0),
25 NewGeom_NestedButton::~NewGeom_NestedButton()
29 void NewGeom_NestedButton::showAdditionalButtons(bool isShow)
31 myAdditionalButtonsWidget->setVisible(isShow);
33 myButtonFrame->setFrameStyle(QFrame::WinPanel);
34 myButtonFrame->setFrameShadow(QFrame::Sunken);
35 myThisButton->setAutoRaise(false);
37 myButtonFrame->setFrameStyle(QFrame::NoFrame);
38 myButtonFrame->setFrameShadow(QFrame::Plain);
39 myThisButton->setAutoRaise(true);
43 QWidget * NewGeom_NestedButton::createWidget(QWidget * theParent)
45 myButtonFrame = new QFrame(theParent);
46 QHBoxLayout* aBoxLay = new QHBoxLayout(myButtonFrame);
47 aBoxLay->setContentsMargins(2, 0, 0, 0);
48 aBoxLay->setSpacing(1);
50 myThisButton = new QToolButton(myButtonFrame);
51 myThisButton->setDefaultAction(this);
52 myThisButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
53 aBoxLay->addWidget(myThisButton, 1);
55 myAdditionalButtonsWidget = new QWidget(myButtonFrame);
56 QHBoxLayout* aAdditionalBoxLay = new QHBoxLayout(myAdditionalButtonsWidget);
57 aAdditionalBoxLay->setContentsMargins(0, 0, 0, 0);
58 aAdditionalBoxLay->setSpacing(1);
59 foreach (QAction* eachAct, myNestedActions) {
60 QToolButton* aButton = new QToolButton(myButtonFrame);
61 aButton->setDefaultAction(eachAct);
62 aButton->setAutoRaise(true);
63 aAdditionalBoxLay->addWidget(aButton);
65 myAdditionalButtonsWidget->setLayout(aAdditionalBoxLay);
66 aBoxLay->addWidget(myAdditionalButtonsWidget);
68 myButtonFrame->setLayout(aBoxLay);
70 showAdditionalButtons(false);
71 connect(this, SIGNAL(toggled(bool)), this, SLOT(showAdditionalButtons(bool)));
72 connect(this, SIGNAL(changed()), this, SLOT(actionStateChanged()));
76 void NewGeom_NestedButton::actionStateChanged()