1 // Copyright (C) 2014-2024 CEA, EDF
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 * SHAPERGUI_NestedButton.cpp
23 * Created on: Apr 13, 2015
27 #include <SHAPERGUI_NestedButton.h>
31 #include <QHBoxLayout>
32 #include <QToolButton>
36 SHAPERGUI_NestedButton::SHAPERGUI_NestedButton(
39 const QList<QAction*>& theNestedActions
41 : QtxAction(theParent, false /*isCheckable*/, theID),
42 myNestedActions(theNestedActions),
43 myAdditionalButtonsWidget(0),
48 void SHAPERGUI_NestedButton::setEnabled(bool theOn)
50 QtxAction::setEnabled(theOn);
52 myThisButton->setEnabled(theOn);
55 void SHAPERGUI_NestedButton::showAdditionalButtons(bool isShow)
57 myAdditionalButtonsWidget->setVisible(isShow);
59 myButtonFrame->setFrameStyle(QFrame::WinPanel);
60 myButtonFrame->setFrameShadow(QFrame::Sunken);
61 myThisButton->setAutoRaise(false);
63 myButtonFrame->setFrameStyle(QFrame::NoFrame);
64 myButtonFrame->setFrameShadow(QFrame::Plain);
65 myThisButton->setAutoRaise(true);
69 QWidget * SHAPERGUI_NestedButton::createWidget(QWidget * theParent)
71 // the action has widget only in tool bar, in menu bar, the default
72 // action presentation is shown
73 QToolBar* aToolBar = dynamic_cast<QToolBar*>(theParent);
77 myButtonFrame = new QFrame(theParent);
78 QHBoxLayout* aBoxLay = new QHBoxLayout(myButtonFrame);
79 aBoxLay->setContentsMargins(2, 0, 0, 0);
80 aBoxLay->setSpacing(1);
81 QSizePolicy aSizePolicy;
82 aSizePolicy.setControlType(QSizePolicy::ToolButton);
83 myButtonFrame->setSizePolicy(aSizePolicy);
85 myThisButton = new QToolButton(myButtonFrame);
86 myThisButton->setDefaultAction(this);
87 myThisButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
88 aBoxLay->addWidget(myThisButton, 1);
90 myAdditionalButtonsWidget = new QWidget(myButtonFrame);
91 QHBoxLayout* aAdditionalBoxLay = new QHBoxLayout(myAdditionalButtonsWidget);
92 aAdditionalBoxLay->setContentsMargins(0, 0, 0, 0);
93 aAdditionalBoxLay->setSpacing(1);
94 foreach (QAction* eachAct, myNestedActions) {
95 QToolButton* aButton = new QToolButton(myButtonFrame);
96 aButton->setDefaultAction(eachAct);
97 aButton->setAutoRaise(true);
98 aAdditionalBoxLay->addWidget(aButton);
100 myAdditionalButtonsWidget->setLayout(aAdditionalBoxLay);
101 aBoxLay->addWidget(myAdditionalButtonsWidget);
103 myButtonFrame->setLayout(aBoxLay);
105 showAdditionalButtons(false);
106 connect(this, SIGNAL(toggled(bool)), this, SLOT(showAdditionalButtons(bool)));
107 return myButtonFrame;
110 bool SHAPERGUI_NestedButton::event(QEvent* theEvent)
112 if (theEvent->type() == QEvent::ActionChanged) {
114 myThisButton->setEnabled(isEnabled());
118 return QtxAction::event(theEvent);