]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #20 Menu buttons' behavior correct
authorsbh <sergey.belash@opencascade.com>
Fri, 8 Aug 2014 09:21:53 +0000 (13:21 +0400)
committersbh <sergey.belash@opencascade.com>
Fri, 8 Aug 2014 09:21:53 +0000 (13:21 +0400)
src/XGUI/XGUI_Command.cpp
src/XGUI/XGUI_Command.h

index f260a1691ab43575caa8d72e2686c62ed33af402..01b3bf83595f4d8a4dd6d420da4e021285dc1d80 100644 (file)
@@ -1,33 +1,6 @@
 #include "XGUI_Command.h"
 #include <QEvent>
-
-
-XGUI_MenuButton::XGUI_MenuButton(const QIcon& theIcon,
-                                 const QString& theText,
-                                 QWidget * theParent)
-    : QPushButton(theIcon, theText, theParent)
-
-{
-  setFlat(true);
-  setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT);
-  setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
-  QString aStyleSheet = "QPushButton { text-align: left; }";
-  //aStyleSheet += "QPushButton:hover { border: 1px solid gray; border-radius: 3px; }";
-  setStyleSheet(aStyleSheet);
-  installEventFilter(this);
-}
-
-//void XGUI_MenuButton::enterEvent(QEvent * event)
-//{
-//  if(isEnabled()) {
-//    setFlat(false);
-//  }
-//}
-
-//void XGUI_MenuButton::leaveEvent(QEvent * event)
-//{
-//  setFlat(true);
-//}
+#include <QToolButton>
 
 XGUI_Command::XGUI_Command(const QString& theId, QObject * parent, bool isCheckable)
     : QWidgetAction(parent), myCheckable(isCheckable)
@@ -51,19 +24,25 @@ XGUI_Command::~XGUI_Command()
 QWidget* XGUI_Command::createWidget(QWidget* theParent)
 {
   if (theParent->inherits("XGUI_MenuGroupPanel")) {
-    XGUI_MenuButton* aButton = new XGUI_MenuButton(icon(), text(), theParent);
-    aButton->setCheckable(myCheckable);
+    QToolButton* aButton = new QToolButton(theParent);
+    aButton->setIcon(icon());
+    aButton->setText(text());
     QKeySequence aKeys = shortcut();
     QString aToolTip = toolTip();
-    if (!aKeys.isEmpty())
-      aToolTip = aToolTip + " (" + aKeys.toString() + ")";
-    if (!aToolTip.isEmpty())
+    if (!aKeys.isEmpty()) {
+      aToolTip = QString("%1 (%2)").arg(aToolTip).arg(aKeys.toString());
+    }
+    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);
 
-    aButton->addAction(this);
     connect(aButton, SIGNAL(clicked()), this, SLOT(trigger()));
     connect(this, SIGNAL(toggled(bool)), aButton, SLOT(setChecked(bool)));
-    connect(this, SIGNAL(toggled(bool)), aButton, SLOT(setChecked(bool)));
     this->setCheckable(myCheckable);
 
     return aButton;
index fcd99b3c8c6bca97c200d50f3c7a19b835dea89e..9367e83756404b43ca11b836642be6166de01249 100644 (file)
@@ -3,23 +3,11 @@
 
 #include "XGUI.h"
 #include <QWidgetAction>
-#include <QPushButton>
+
 
 #define MIN_BUTTON_HEIGHT 25
 #define MIN_BUTTON_WIDTH 60
 
-class XGUI_EXPORT XGUI_MenuButton: public QPushButton
-{
-  Q_OBJECT
- public:
-  XGUI_MenuButton(const QIcon & icon, const QString & text, QWidget * parent = 0);
-
-// protected:
-//  virtual void enterEvent(QEvent * event);
-//  virtual void leaveEvent(QEvent * event);
-
-};
-
 /**\class XGUI_Command
  * \ingroup GUI
  * \brief Represents a command item in the application menu (Workbench)