]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Command.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom
[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), myId(theId), myCheckable(isCheckable)
7 {
8 }
9
10 XGUI_Command::XGUI_Command(const QString& theId, const QIcon& icon, const QString& text,
11                            QObject* parent, bool isCheckable)
12     : QWidgetAction(parent), myId(theId), myCheckable(isCheckable)
13 {
14   setIcon(icon);
15   setText(text);
16 }
17
18 XGUI_Command::~XGUI_Command()
19 {
20 }
21
22 QWidget* XGUI_Command::createWidget(QWidget* theParent)
23 {
24   if (theParent->inherits("XGUI_MenuGroupPanel")) {
25     QPushButton* aButton = new QPushButton(theParent);
26     aButton->setIcon(icon());
27     aButton->setText(text());
28     aButton->setStyleSheet("text-align: left");
29     QKeySequence aKeys = shortcut();
30     QString aToolTip = toolTip();
31     if (!aKeys.isEmpty())
32       aToolTip = aToolTip + " (" + aKeys.toString() + ")";
33     if (!aToolTip.isEmpty())
34       aButton->setToolTip(aToolTip);
35
36     aButton->addAction(this);
37     connect(aButton, SIGNAL(clicked()), this, SLOT(trigger()));
38     connect(this, SIGNAL(toggled(bool)), aButton, SLOT(setChecked(bool)));
39     aButton->setFlat(true);
40     aButton->setCheckable(myCheckable);
41     this->setCheckable(myCheckable);
42     aButton->setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT);
43
44     return aButton;
45   }
46   return QWidgetAction::createWidget(theParent);
47 }
48
49 bool XGUI_Command::enabled() const
50 {
51   return isEnabled();
52 }
53
54 void XGUI_Command::enable()
55 {
56   setEnabled(true);
57 }
58
59 void XGUI_Command::disable()
60 {
61   setEnabled(false);
62 }
63
64 void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot)
65 {
66     connect(this, SIGNAL(triggered(bool)), theResiver, theSlot);
67 }
68
69 const QStringList& XGUI_Command::unblockableCommands() const
70 {
71   return myUnblockableCommands;
72 }
73
74 void XGUI_Command::setUnblockableCommands(const QStringList& myUnblockableCommands)
75 {
76   this->myUnblockableCommands = myUnblockableCommands;
77 }