]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Command.cpp
Salome HOME
Issue #20 Menu buttons' behavior correct
[modules/shaper.git] / src / XGUI / XGUI_Command.cpp
1 #include "XGUI_Command.h"
2 #include <QEvent>
3 #include <QToolButton>
4
5 XGUI_Command::XGUI_Command(const QString& theId, QObject * parent, bool isCheckable)
6     : QWidgetAction(parent), myCheckable(isCheckable)
7 {
8   setData(theId);
9 }
10
11 XGUI_Command::XGUI_Command(const QString& theId, const QIcon& icon, const QString& text,
12                            QObject* parent, bool isCheckable)
13     : QWidgetAction(parent), myCheckable(isCheckable)
14 {
15   setIcon(icon);
16   setText(text);
17   setData(theId);
18 }
19
20 XGUI_Command::~XGUI_Command()
21 {
22 }
23
24 QWidget* XGUI_Command::createWidget(QWidget* theParent)
25 {
26   if (theParent->inherits("XGUI_MenuGroupPanel")) {
27     QToolButton* aButton = new QToolButton(theParent);
28     aButton->setIcon(icon());
29     aButton->setText(text());
30     QKeySequence aKeys = shortcut();
31     QString aToolTip = toolTip();
32     if (!aKeys.isEmpty()) {
33       aToolTip = QString("%1 (%2)").arg(aToolTip).arg(aKeys.toString());
34     }
35     if (!aToolTip.isEmpty()) {
36       aButton->setToolTip(aToolTip);
37     }
38     aButton->setCheckable(myCheckable);
39     aButton->setAutoRaise(true);
40     aButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
41     aButton->setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT);
42     aButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
43
44     connect(aButton, SIGNAL(clicked()), this, SLOT(trigger()));
45     connect(this, SIGNAL(toggled(bool)), aButton, SLOT(setChecked(bool)));
46     this->setCheckable(myCheckable);
47
48     return aButton;
49   }
50   return QWidgetAction::createWidget(theParent);
51 }
52
53 void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot)
54 {
55     connect(this, SIGNAL(triggered(bool)), theResiver, theSlot);
56 }
57
58 const QStringList& XGUI_Command::nestedCommands() const
59 {
60   return myNestedCommands;
61 }
62
63 void XGUI_Command::setNestedCommands(const QStringList& myUnblockableCommands)
64 {
65   this->myNestedCommands = myUnblockableCommands;
66 }