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