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)
6     : QWidgetAction(parent), myId(theId)
7 {
8 }
9
10 XGUI_Command::XGUI_Command(const QString& theId, const QIcon& icon, const QString& text,
11                            QObject* parent)
12     : QWidgetAction(parent), myId(theId)
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* aBtn = new QPushButton(theParent);
26     aBtn->setIcon(icon());
27     aBtn->setText(text());
28     aBtn->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       aBtn->setToolTip(aToolTip);
35
36     aBtn->addAction(this);
37     connect(aBtn, SIGNAL(clicked()), this, SLOT(trigger()));
38     aBtn->setFlat(true);
39     aBtn->setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT);
40     return aBtn;
41   }
42   return QWidgetAction::createWidget(theParent);
43 }
44
45 bool XGUI_Command::enabled() const
46 {
47   return isEnabled();
48 }
49
50 void XGUI_Command::enable()
51 {
52   setEnabled(true);
53 }
54
55 void XGUI_Command::disable()
56 {
57   setEnabled(false);
58 }
59
60 void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot)
61 {
62   connect(this, SIGNAL(triggered()), theResiver, theSlot);
63 }