Salome HOME
Call show method of the error dialog in it's thread. Fixes #79
[modules/shaper.git] / src / XGUI / XGUI_Command.cpp
1 #include "XGUI_Command.h"
2
3 #include <QToolButton>
4
5 XGUI_Command::XGUI_Command(const QString& theId, QObject * parent, bool isCheckable)
6     : QWidgetAction(parent), myCheckable(isCheckable)
7 {
8   setData(theId);
9 }
10
11 XGUI_Command::XGUI_Command(const QString& theId, const QIcon& icon, const QString& text,
12                            QObject* parent, bool isCheckable)
13     : QWidgetAction(parent), myCheckable(isCheckable)
14 {
15   setIcon(icon);
16   setText(text);
17   setData(theId);
18 }
19
20 XGUI_Command::~XGUI_Command()
21 {
22 }
23
24 QWidget* XGUI_Command::createWidget(QWidget* theParent)
25 {
26   if (theParent->inherits("XGUI_MenuGroupPanel")) {
27     QToolButton* aButton = new QToolButton(theParent);
28     aButton->setIcon(icon());
29     aButton->setText(text());
30     aButton->setStyleSheet("QToolButton::menu-indicator { image: none; }");
31     aButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
32     aButton->setAutoRaise(true);
33     aButton->setArrowType(Qt::NoArrow);
34     aButton->setCheckable(myCheckable);
35     aButton->setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT);
36     aButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
37     QKeySequence aKeys = shortcut();
38     QString aToolTip = toolTip();
39     if (!aKeys.isEmpty())
40       aToolTip = aToolTip + " (" + aKeys.toString() + ")";
41     if (!aToolTip.isEmpty())
42       aButton->setToolTip(aToolTip);
43
44     aButton->addAction(this);
45     connect(aButton, SIGNAL(clicked()), this, SLOT(trigger()));
46     connect(this, SIGNAL(toggled(bool)), aButton, SLOT(setChecked(bool)));
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 }