From 7be1f1afc2a9e5ce7f6e0d95d22483fc544d90ac Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 28 Sep 2013 13:10:42 +0200 Subject: [PATCH] implemented SceneToolMode as a horizontal panel with radiobutton-type buttons --- apps/opencs/view/world/scenesubview.cpp | 7 +++- apps/opencs/view/world/scenetool.cpp | 14 ++++++- apps/opencs/view/world/scenetool.hpp | 9 +++++ apps/opencs/view/world/scenetoolmode.cpp | 47 +++++++++++++++++++++++- apps/opencs/view/world/scenetoolmode.hpp | 20 ++++++++++ 5 files changed, 94 insertions(+), 3 deletions(-) diff --git a/apps/opencs/view/world/scenesubview.cpp b/apps/opencs/view/world/scenesubview.cpp index 8f3ecab21..36ace68f0 100644 --- a/apps/opencs/view/world/scenesubview.cpp +++ b/apps/opencs/view/world/scenesubview.cpp @@ -30,7 +30,12 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D layout2->setContentsMargins (QMargins (0, 0, 0, 0)); SceneToolbar *toolbar = new SceneToolbar (this); -toolbar->addTool (new SceneToolMode (this)); // test +// test +SceneToolMode *tool = new SceneToolMode (this); +tool->addButton (":door.png", "a"); +tool->addButton (":GMST.png", "b"); +tool->addButton (":Info.png", "c"); +toolbar->addTool (tool); toolbar->addTool (new SceneToolMode (this)); toolbar->addTool (new SceneToolMode (this)); toolbar->addTool (new SceneToolMode (this)); diff --git a/apps/opencs/view/world/scenetool.cpp b/apps/opencs/view/world/scenetool.cpp index f67e4fa45..d7d37c98f 100644 --- a/apps/opencs/view/world/scenetool.cpp +++ b/apps/opencs/view/world/scenetool.cpp @@ -5,4 +5,16 @@ CSVWorld::SceneTool::SceneTool (QWidget *parent) : QPushButton (parent) { setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed)); setFixedSize (48, 48); -} \ No newline at end of file + + connect (this, SIGNAL (clicked()), this, SLOT (openRequest())); +} + +void CSVWorld::SceneTool::updateIcon (const QIcon& icon) +{ + setIcon (icon); +} + +void CSVWorld::SceneTool::openRequest() +{ + showPanel (parentWidget()->mapToGlobal (pos())); +} diff --git a/apps/opencs/view/world/scenetool.hpp b/apps/opencs/view/world/scenetool.hpp index c3e9e3b4b..d5c9dd5d2 100644 --- a/apps/opencs/view/world/scenetool.hpp +++ b/apps/opencs/view/world/scenetool.hpp @@ -14,6 +14,15 @@ namespace CSVWorld SceneTool (QWidget *parent = 0); + virtual void showPanel (const QPoint& position) = 0; + + protected slots: + + void updateIcon (const QIcon& icon); + + private slots: + + void openRequest(); }; } diff --git a/apps/opencs/view/world/scenetoolmode.cpp b/apps/opencs/view/world/scenetoolmode.cpp index a6b9b5a28..b4277bcbe 100644 --- a/apps/opencs/view/world/scenetoolmode.cpp +++ b/apps/opencs/view/world/scenetoolmode.cpp @@ -1,6 +1,51 @@ #include "scenetoolmode.hpp" +#include +#include +#include + CSVWorld::SceneToolMode::SceneToolMode (QWidget *parent) : SceneTool (parent) -{} \ No newline at end of file +{ + mPanel = new QFrame (this, Qt::Popup); + + mLayout = new QHBoxLayout (mPanel); + + mLayout->setContentsMargins (QMargins (0, 0, 0, 0)); + + mPanel->setLayout (mLayout); +} + +void CSVWorld::SceneToolMode::showPanel (const QPoint& position) +{ + mPanel->move (position); + mPanel->show(); +} + +void CSVWorld::SceneToolMode::addButton (const std::string& icon, const std::string& id) +{ + QPushButton *button = new QPushButton (QIcon (QPixmap (icon.c_str())), "", mPanel); + button->setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed)); + button->setFixedSize (48, 48); + + mLayout->addWidget (button); + + mButtons.insert (std::make_pair (button, id)); + + connect (button, SIGNAL (clicked()), this, SLOT (selected())); +} + +void CSVWorld::SceneToolMode::selected() +{ + std::map::const_iterator iter = + mButtons.find (dynamic_cast (sender())); + + if (iter!=mButtons.end()) + { + mPanel->hide(); + + emit updateIcon (iter->first->icon()); + emit modeChanged (iter->second); + } +} \ No newline at end of file diff --git a/apps/opencs/view/world/scenetoolmode.hpp b/apps/opencs/view/world/scenetoolmode.hpp index d54ec76b2..feee78376 100644 --- a/apps/opencs/view/world/scenetoolmode.hpp +++ b/apps/opencs/view/world/scenetoolmode.hpp @@ -3,6 +3,10 @@ #include "scenetool.hpp" +#include + +class QHBoxLayout; + namespace CSVWorld { ///< \brief Mode selector tool @@ -10,9 +14,25 @@ namespace CSVWorld { Q_OBJECT + QWidget *mPanel; + QHBoxLayout *mLayout; + std::map mButtons; // widget, id + public: SceneToolMode (QWidget *parent = 0); + + virtual void showPanel (const QPoint& position); + + void addButton (const std::string& icon, const std::string& id); + + signals: + + void modeChanged (const std::string& id); + + private slots: + + void selected(); }; }