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