X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Command.cpp;h=1194dc4543785c84b0339555b385dab588506de9;hb=81e0a6c31838fd3f276d6b44ae24a2acc831a8f4;hp=3ba1689a3b5168c44bb828a7f22de419154429ee;hpb=cea3f78cfb7c796ba5be6bc9ee21e930abe14021;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Command.cpp b/src/XGUI/XGUI_Command.cpp index 3ba1689a3..1194dc454 100644 --- a/src/XGUI/XGUI_Command.cpp +++ b/src/XGUI/XGUI_Command.cpp @@ -1,62 +1,85 @@ #include "XGUI_Command.h" +#include +#include +#include +#include -#include - -XGUI_Command::XGUI_Command(const QString& theId, QObject * parent) : - QWidgetAction(parent), myId(theId) +XGUI_Command::XGUI_Command(const QString& theId, + const QString& theDocumentKind, + QObject * parent, + bool isCheckable) + : QWidgetAction(parent), + myCheckable(isCheckable), + myDocumentKind(theDocumentKind) { + setData(theId); } -XGUI_Command::XGUI_Command(const QString& theId, const QIcon& icon, const QString& text, QObject* parent): - QWidgetAction(parent), myId(theId) +XGUI_Command::XGUI_Command(const QString& theId, + const QString& theDocumentKind, + const QIcon& icon, + const QString& text, + QObject* parent, + bool isCheckable) + : QWidgetAction(parent), + myCheckable(isCheckable), + myDocumentKind(theDocumentKind) { - setIcon(icon); - setText(text); + setIcon(icon); + setText(text); + setData(theId); } - XGUI_Command::~XGUI_Command() { } -QWidget* XGUI_Command::createWidget(QWidget* theParent) +const QString& XGUI_Command::documentKind() const { - if (theParent->inherits("XGUI_MenuGroupPanel")) { - QPushButton* aBtn = new QPushButton(theParent); - aBtn->setIcon(icon()); - aBtn->setText(text()); - QKeySequence aKeys = shortcut(); - QString aToolTip = toolTip(); - if (!aKeys.isEmpty()) - aToolTip = aToolTip + " (" + aKeys.toString() + ")"; - if (!aToolTip.isEmpty()) - aBtn->setToolTip(aToolTip); - - aBtn->addAction(this); - connect(aBtn, SIGNAL(clicked()), this, SLOT(trigger())); - aBtn->setFlat(true); - aBtn->setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT); - return aBtn; - } - return QWidgetAction::createWidget(theParent); + return myDocumentKind; } -bool XGUI_Command::enabled() const +QWidget* XGUI_Command::createWidget(QWidget* theParent) { - return isEnabled(); + if (theParent->inherits("XGUI_MenuGroupPanel")) { + QToolButton* aButton = new QToolButton(theParent); + aButton->setIcon(icon()); + aButton->setText(text()); + QKeySequence aKeys = shortcut(); + QString aToolTip = toolTip(); + if (!aKeys.isEmpty()) { + aToolTip = QString("%1 (%2)").arg(aToolTip).arg(aKeys.toString()); + aButton->setShortcut(aKeys); + } + if (!aToolTip.isEmpty()) { + aButton->setToolTip(aToolTip); + } + aButton->setCheckable(myCheckable); + aButton->setAutoRaise(true); + aButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + aButton->setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT); + aButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); + + connect(aButton, SIGNAL(clicked()), this, SLOT(trigger())); + connect(this, SIGNAL(toggled(bool)), aButton, SLOT(setChecked(bool))); + this->setCheckable(myCheckable); + + return aButton; + } + return QWidgetAction::createWidget(theParent); } -void XGUI_Command::enable() +void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot) { - setEnabled(true); + connect(this, SIGNAL(triggered(bool)), theResiver, theSlot); } -void XGUI_Command::disable() +const QStringList& XGUI_Command::nestedCommands() const { - setEnabled(false); + return myNestedCommands; } -void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot) +void XGUI_Command::setNestedCommands(const QStringList& myUnblockableCommands) { - connect(this, SIGNAL(triggered()), theResiver, theSlot); -} \ No newline at end of file + this->myNestedCommands = myUnblockableCommands; +}