Salome HOME
Document's kind dependent features implemented
[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     }
53     if (!aToolTip.isEmpty()) {
54       aButton->setToolTip(aToolTip);
55     }
56     aButton->setCheckable(myCheckable);
57     aButton->setAutoRaise(true);
58     aButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
59     aButton->setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT);
60     aButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
61
62     connect(aButton, SIGNAL(clicked()), this, SLOT(trigger()));
63     connect(this, SIGNAL(toggled(bool)), aButton, SLOT(setChecked(bool)));
64     this->setCheckable(myCheckable);
65
66     return aButton;
67   }
68   return QWidgetAction::createWidget(theParent);
69 }
70
71 void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot)
72 {
73   connect(this, SIGNAL(triggered(bool)), theResiver, theSlot);
74 }
75
76 const QStringList& XGUI_Command::nestedCommands() const
77 {
78   return myNestedCommands;
79 }
80
81 void XGUI_Command::setNestedCommands(const QStringList& myUnblockableCommands)
82 {
83   this->myNestedCommands = myUnblockableCommands;
84 }