From 32e48edb83b63c3f3c8f2308256dfa43871de202 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 10 Jul 2014 12:53:57 +0200 Subject: [PATCH] toolbar tooltip system --- apps/opencs/view/widget/pushbutton.cpp | 25 +++++++++++++++++++---- apps/opencs/view/widget/pushbutton.hpp | 11 ++++++++-- apps/opencs/view/widget/scenetool.cpp | 2 +- apps/opencs/view/widget/scenetoolmode.cpp | 2 +- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/apps/opencs/view/widget/pushbutton.cpp b/apps/opencs/view/widget/pushbutton.cpp index 8fb90c4d00..52c78ff1cd 100644 --- a/apps/opencs/view/widget/pushbutton.cpp +++ b/apps/opencs/view/widget/pushbutton.cpp @@ -4,6 +4,20 @@ #include #include +void CSVWidget::PushButton::setExtendedToolTip (const std::string& text) +{ + std::string tooltip = text; + + if (tooltip.empty()) + tooltip = "(Tool tip not implemented yet)"; + + if (!mPush) + tooltip += + "

(left click to activate,
shift-left click to activate and keep panel open)"; + + setToolTip (QString::fromUtf8 (tooltip.c_str())); +} + void CSVWidget::PushButton::keyPressEvent (QKeyEvent *event) { if (event->key()!=Qt::Key_Shift) @@ -29,16 +43,19 @@ void CSVWidget::PushButton::mouseReleaseEvent (QMouseEvent *event) QPushButton::mouseReleaseEvent (event); } -CSVWidget::PushButton::PushButton (const QIcon& icon, bool push, QWidget *parent) -: QPushButton (icon, "", parent), mKeepOpen (false) +CSVWidget::PushButton::PushButton (const QIcon& icon, bool push, const std::string& tooltip, + QWidget *parent) +: QPushButton (icon, "", parent), mKeepOpen (false), mPush (push) { setCheckable (!push); + setExtendedToolTip (tooltip); } -CSVWidget::PushButton::PushButton (bool push, QWidget *parent) -: QPushButton (parent), mKeepOpen (false) +CSVWidget::PushButton::PushButton (bool push, const std::string& tooltip, QWidget *parent) +: QPushButton (parent), mKeepOpen (false), mPush (push) { setCheckable (!push); + setExtendedToolTip (tooltip); } bool CSVWidget::PushButton::hasKeepOpen() const diff --git a/apps/opencs/view/widget/pushbutton.hpp b/apps/opencs/view/widget/pushbutton.hpp index 7c2a2caca0..6cd4f65ab4 100644 --- a/apps/opencs/view/widget/pushbutton.hpp +++ b/apps/opencs/view/widget/pushbutton.hpp @@ -10,6 +10,11 @@ namespace CSVWidget Q_OBJECT bool mKeepOpen; + bool mPush; + + private: + + void setExtendedToolTip (const std::string& text); protected: @@ -22,10 +27,12 @@ namespace CSVWidget public: /// \param push Do not maintain a toggle state - PushButton (const QIcon& icon, bool push = false, QWidget *parent = 0); + PushButton (const QIcon& icon, bool push = false, const std::string& tooltip = "", + QWidget *parent = 0); /// \param push Do not maintain a toggle state - PushButton (bool push = false, QWidget *parent = 0); + PushButton (bool push = false, const std::string& tooltip = "", + QWidget *parent = 0); bool hasKeepOpen() const; }; diff --git a/apps/opencs/view/widget/scenetool.cpp b/apps/opencs/view/widget/scenetool.cpp index 36d1f66101..d247096b03 100644 --- a/apps/opencs/view/widget/scenetool.cpp +++ b/apps/opencs/view/widget/scenetool.cpp @@ -3,7 +3,7 @@ #include "scenetoolbar.hpp" -CSVWidget::SceneTool::SceneTool (SceneToolbar *parent) : PushButton (true, parent) +CSVWidget::SceneTool::SceneTool (SceneToolbar *parent) : PushButton (true, "", parent) { setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed)); setIconSize (QSize (parent->getIconSize(), parent->getIconSize())); diff --git a/apps/opencs/view/widget/scenetoolmode.cpp b/apps/opencs/view/widget/scenetoolmode.cpp index 0d8526a30c..152a7c0ced 100644 --- a/apps/opencs/view/widget/scenetoolmode.cpp +++ b/apps/opencs/view/widget/scenetoolmode.cpp @@ -31,7 +31,7 @@ void CSVWidget::SceneToolMode::showPanel (const QPoint& position) void CSVWidget::SceneToolMode::addButton (const std::string& icon, const std::string& id) { - PushButton *button = new PushButton (QIcon (QPixmap (icon.c_str())), false, mPanel); + PushButton *button = new PushButton (QIcon (QPixmap (icon.c_str())), false, "", mPanel); button->setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed)); button->setIconSize (QSize (mIconSize, mIconSize)); button->setFixedSize (mButtonSize, mButtonSize);