diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 5d8d99f27..c03cc3138 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -69,7 +69,7 @@ opencs_units_noqt (view/world ) opencs_units (view/widget - scenetoolbar scenetool scenetoolmode + scenetoolbar scenetool scenetoolmode pushbutton ) opencs_units (view/render diff --git a/apps/opencs/view/widget/pushbutton.cpp b/apps/opencs/view/widget/pushbutton.cpp new file mode 100644 index 000000000..8b4cf65e3 --- /dev/null +++ b/apps/opencs/view/widget/pushbutton.cpp @@ -0,0 +1,29 @@ + +#include "pushbutton.hpp" + +#include +#include + +void CSVWidget::PushButton::keyPressEvent (QKeyEvent *event) +{ + if (event->key()!=Qt::Key_Shift) + mKeepOpen = false; + + QPushButton::keyPressEvent (event); +} + +void CSVWidget::PushButton::mouseReleaseEvent (QMouseEvent *event) +{ + mKeepOpen = event->button()==Qt::LeftButton && (event->modifiers() & Qt::ShiftModifier); + QPushButton::mouseReleaseEvent (event); +} + +CSVWidget::PushButton::PushButton (const QIcon& icon, const QString& text, QWidget *parent) +: QPushButton (icon, text, parent), mKeepOpen (false) +{ +} + +bool CSVWidget::PushButton::hasKeepOpen() const +{ + return mKeepOpen; +} \ No newline at end of file diff --git a/apps/opencs/view/widget/pushbutton.hpp b/apps/opencs/view/widget/pushbutton.hpp new file mode 100644 index 000000000..aa9da4885 --- /dev/null +++ b/apps/opencs/view/widget/pushbutton.hpp @@ -0,0 +1,28 @@ +#ifndef CSV_WIDGET_PUSHBUTTON_H +#define CSV_WIDGET_PUSHBUTTON_H + +#include + +namespace CSVWidget +{ + class PushButton : public QPushButton + { + Q_OBJECT + + bool mKeepOpen; + + protected: + + virtual void keyPressEvent (QKeyEvent *event); + + virtual void mouseReleaseEvent (QMouseEvent *event); + + public: + + PushButton (const QIcon& icon, const QString& text, QWidget *parent = 0); + + bool hasKeepOpen() const; + }; +} + +#endif diff --git a/apps/opencs/view/widget/scenetoolmode.cpp b/apps/opencs/view/widget/scenetoolmode.cpp index 72efae0df..87abd8140 100644 --- a/apps/opencs/view/widget/scenetoolmode.cpp +++ b/apps/opencs/view/widget/scenetoolmode.cpp @@ -6,6 +6,7 @@ #include #include "scenetoolbar.hpp" +#include "pushbutton.hpp" CSVWidget::SceneToolMode::SceneToolMode (SceneToolbar *parent) : SceneTool (parent), mButtonSize (parent->getButtonSize()), mIconSize (parent->getIconSize()) @@ -27,7 +28,7 @@ void CSVWidget::SceneToolMode::showPanel (const QPoint& position) void CSVWidget::SceneToolMode::addButton (const std::string& icon, const std::string& id) { - QPushButton *button = new QPushButton (QIcon (QPixmap (icon.c_str())), "", mPanel); + PushButton *button = new PushButton (QIcon (QPixmap (icon.c_str())), "", mPanel); button->setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed)); button->setIconSize (QSize (mIconSize, mIconSize)); button->setFixedSize (mButtonSize, mButtonSize); @@ -44,12 +45,13 @@ void CSVWidget::SceneToolMode::addButton (const std::string& icon, const std::st void CSVWidget::SceneToolMode::selected() { - std::map::const_iterator iter = - mButtons.find (dynamic_cast (sender())); + std::map::const_iterator iter = + mButtons.find (dynamic_cast (sender())); if (iter!=mButtons.end()) { - mPanel->hide(); + if (!iter->first->hasKeepOpen()) + mPanel->hide(); setIcon (iter->first->icon()); emit modeChanged (iter->second); diff --git a/apps/opencs/view/widget/scenetoolmode.hpp b/apps/opencs/view/widget/scenetoolmode.hpp index 175c53f96..0ad5243b3 100644 --- a/apps/opencs/view/widget/scenetoolmode.hpp +++ b/apps/opencs/view/widget/scenetoolmode.hpp @@ -10,6 +10,7 @@ class QHBoxLayout; namespace CSVWidget { class SceneToolbar; + class PushButton; ///< \brief Mode selector tool class SceneToolMode : public SceneTool @@ -18,7 +19,7 @@ namespace CSVWidget QWidget *mPanel; QHBoxLayout *mLayout; - std::map mButtons; // widget, id + std::map mButtons; // widget, id int mButtonSize; int mIconSize;