]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Command.cpp
Salome HOME
Merge branch 'master' into BR_PYTHON_PLUGIN
[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,
8                            const QString& theDocumentKind,
9                            QObject * parent,
10                            bool isCheckable)
11     : QWidgetAction(parent),
12       myCheckable(isCheckable),
13       myDocumentKind(theDocumentKind)
14 {
15   setData(theId);
16 }
17
18 XGUI_Command::XGUI_Command(const QString& theId,
19                            const QString& theDocumentKind,
20                            const QIcon& icon,
21                            const QString& text,
22                            QObject* parent,
23                            bool isCheckable)
24     : QWidgetAction(parent),
25       myCheckable(isCheckable),
26       myDocumentKind(theDocumentKind)
27 {
28   setIcon(icon);
29   setText(text);
30   setData(theId);
31 }
32
33 XGUI_Command::~XGUI_Command()
34 {
35 }
36
37 const QString& XGUI_Command::documentKind() const
38 {
39   return myDocumentKind;
40 }
41
42 QWidget* XGUI_Command::createWidget(QWidget* theParent)
43 {
44   if (theParent->inherits("XGUI_MenuGroupPanel")) {
45     QToolButton* aButton = new QToolButton(theParent);
46     aButton->setIcon(icon());
47     aButton->setText(text());
48     QKeySequence aKeys = shortcut();
49     QString aToolTip = toolTip();
50     if (!aKeys.isEmpty()) {
51       aToolTip = QString("%1 (%2)").arg(aToolTip).arg(aKeys.toString());
52       aButton->setShortcut(aKeys);
53     }
54     if (!aToolTip.isEmpty()) {
55       aButton->setToolTip(aToolTip);
56     }
57     aButton->setCheckable(myCheckable);
58     aButton->setAutoRaise(true);
59     aButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
60     aButton->setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT);
61     aButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
62
63     connect(aButton, SIGNAL(clicked()), this, SLOT(trigger()));
64     connect(this, SIGNAL(toggled(bool)), aButton, SLOT(setChecked(bool)));
65     this->setCheckable(myCheckable);
66
67     return aButton;
68   }
69   return QWidgetAction::createWidget(theParent);
70 }
71
72 void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot)
73 {
74   connect(this, SIGNAL(triggered(bool)), theResiver, theSlot);
75 }
76
77 const QStringList& XGUI_Command::nestedCommands() const
78 {
79   return myNestedCommands;
80 }
81
82 void XGUI_Command::setNestedCommands(const QStringList& myUnblockableCommands)
83 {
84   this->myNestedCommands = myUnblockableCommands;
85 }