Salome HOME
0ddb0ecfcd8dafc2aa6bd851b42d4094ade036cb
[modules/shaper.git] / src / XGUI / XGUI_Command.cpp
1 #include "XGUI_Command.h"
2
3 #include <QPushButton>
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     QPushButton* aButton = new QPushButton(theParent);
28     aButton->setIcon(icon());
29     aButton->setText(text());
30     aButton->setStyleSheet("text-align: left");
31     QKeySequence aKeys = shortcut();
32     QString aToolTip = toolTip();
33     if (!aKeys.isEmpty())
34       aToolTip = aToolTip + " (" + aKeys.toString() + ")";
35     if (!aToolTip.isEmpty())
36       aButton->setToolTip(aToolTip);
37
38     aButton->addAction(this);
39     connect(aButton, SIGNAL(clicked()), this, SLOT(trigger()));
40     connect(this, SIGNAL(toggled(bool)), aButton, SLOT(setChecked(bool)));
41     connect(this, SIGNAL(toggled(bool)), aButton, SLOT(setChecked(bool)));
42     aButton->setFlat(true);
43     aButton->setCheckable(myCheckable);
44     this->setCheckable(myCheckable);
45     aButton->setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT);
46
47     return aButton;
48   }
49   return QWidgetAction::createWidget(theParent);
50 }
51
52 void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot)
53 {
54     connect(this, SIGNAL(triggered(bool)), theResiver, theSlot);
55 }
56
57 const QStringList& XGUI_Command::nestedCommands() const
58 {
59   return myNestedCommands;
60 }
61
62 void XGUI_Command::setNestedCommands(const QStringList& myUnblockableCommands)
63 {
64   this->myNestedCommands = myUnblockableCommands;
65 }