]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Command.cpp
Salome HOME
f260a1691ab43575caa8d72e2686c62ed33af402
[modules/shaper.git] / src / XGUI / XGUI_Command.cpp
1 #include "XGUI_Command.h"
2 #include <QEvent>
3
4
5 XGUI_MenuButton::XGUI_MenuButton(const QIcon& theIcon,
6                                  const QString& theText,
7                                  QWidget * theParent)
8     : QPushButton(theIcon, theText, theParent)
9
10 {
11   setFlat(true);
12   setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT);
13   setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
14   QString aStyleSheet = "QPushButton { text-align: left; }";
15   //aStyleSheet += "QPushButton:hover { border: 1px solid gray; border-radius: 3px; }";
16   setStyleSheet(aStyleSheet);
17   installEventFilter(this);
18 }
19
20 //void XGUI_MenuButton::enterEvent(QEvent * event)
21 //{
22 //  if(isEnabled()) {
23 //    setFlat(false);
24 //  }
25 //}
26
27 //void XGUI_MenuButton::leaveEvent(QEvent * event)
28 //{
29 //  setFlat(true);
30 //}
31
32 XGUI_Command::XGUI_Command(const QString& theId, QObject * parent, bool isCheckable)
33     : QWidgetAction(parent), myCheckable(isCheckable)
34 {
35   setData(theId);
36 }
37
38 XGUI_Command::XGUI_Command(const QString& theId, const QIcon& icon, const QString& text,
39                            QObject* parent, bool isCheckable)
40     : QWidgetAction(parent), myCheckable(isCheckable)
41 {
42   setIcon(icon);
43   setText(text);
44   setData(theId);
45 }
46
47 XGUI_Command::~XGUI_Command()
48 {
49 }
50
51 QWidget* XGUI_Command::createWidget(QWidget* theParent)
52 {
53   if (theParent->inherits("XGUI_MenuGroupPanel")) {
54     XGUI_MenuButton* aButton = new XGUI_MenuButton(icon(), text(), theParent);
55     aButton->setCheckable(myCheckable);
56     QKeySequence aKeys = shortcut();
57     QString aToolTip = toolTip();
58     if (!aKeys.isEmpty())
59       aToolTip = aToolTip + " (" + aKeys.toString() + ")";
60     if (!aToolTip.isEmpty())
61       aButton->setToolTip(aToolTip);
62
63     aButton->addAction(this);
64     connect(aButton, SIGNAL(clicked()), this, SLOT(trigger()));
65     connect(this, SIGNAL(toggled(bool)), aButton, SLOT(setChecked(bool)));
66     connect(this, SIGNAL(toggled(bool)), aButton, SLOT(setChecked(bool)));
67     this->setCheckable(myCheckable);
68
69     return aButton;
70   }
71   return QWidgetAction::createWidget(theParent);
72 }
73
74 void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot)
75 {
76     connect(this, SIGNAL(triggered(bool)), theResiver, theSlot);
77 }
78
79 const QStringList& XGUI_Command::nestedCommands() const
80 {
81   return myNestedCommands;
82 }
83
84 void XGUI_Command::setNestedCommands(const QStringList& myUnblockableCommands)
85 {
86   this->myNestedCommands = myUnblockableCommands;
87 }