Salome HOME
3ba1689a3b5168c44bb828a7f22de419154429ee
[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) :
6     QWidgetAction(parent), myId(theId)
7 {
8 }
9
10 XGUI_Command::XGUI_Command(const QString& theId, const QIcon& icon, const QString& text, QObject* parent):
11     QWidgetAction(parent), myId(theId)
12 {
13     setIcon(icon);
14     setText(text);
15 }
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* aBtn = new QPushButton(theParent);
26         aBtn->setIcon(icon());
27         aBtn->setText(text());
28         QKeySequence aKeys = shortcut();
29         QString aToolTip = toolTip();
30         if (!aKeys.isEmpty())
31             aToolTip = aToolTip + " (" + aKeys.toString() + ")";
32         if (!aToolTip.isEmpty())
33             aBtn->setToolTip(aToolTip);
34
35         aBtn->addAction(this);
36         connect(aBtn, SIGNAL(clicked()), this, SLOT(trigger()));
37         aBtn->setFlat(true);
38         aBtn->setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT);
39         return aBtn;
40     }
41     return QWidgetAction::createWidget(theParent);
42 }
43
44 bool XGUI_Command::enabled() const
45 {
46     return isEnabled();
47 }
48
49 void XGUI_Command::enable()
50 {
51     setEnabled(true);
52 }
53
54 void XGUI_Command::disable()
55 {
56     setEnabled(false);
57 }
58
59 void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot)
60 {
61     connect(this, SIGNAL(triggered()), theResiver, theSlot);
62 }