From 9ea092927fca60c1b92b8d4fbc7305eda672c8db Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 28 Sep 2013 09:25:54 +0200 Subject: [PATCH 1/6] added basic scene subview (no functionality yet) --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/model/world/universalid.cpp | 1 + apps/opencs/model/world/universalid.hpp | 5 +- apps/opencs/view/doc/view.cpp | 9 ++++ apps/opencs/view/doc/view.hpp | 2 + apps/opencs/view/world/scenesubview.cpp | 72 +++++++++++++++++++++++++ apps/opencs/view/world/scenesubview.hpp | 37 +++++++++++++ apps/opencs/view/world/scenetoolbar.cpp | 8 +++ apps/opencs/view/world/scenetoolbar.hpp | 20 +++++++ apps/opencs/view/world/subviews.cpp | 2 + 10 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 apps/opencs/view/world/scenesubview.cpp create mode 100644 apps/opencs/view/world/scenesubview.hpp create mode 100644 apps/opencs/view/world/scenetoolbar.cpp create mode 100644 apps/opencs/view/world/scenetoolbar.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 00547a2ba..2fbceac96 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -59,7 +59,7 @@ opencs_hdrs_noqt (view/doc opencs_units (view/world table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator - cellcreator referenceablecreator referencecreator + cellcreator referenceablecreator referencecreator scenesubview scenetoolbar ) opencs_units_noqt (view/world diff --git a/apps/opencs/model/world/universalid.cpp b/apps/opencs/model/world/universalid.cpp index 60a8485f8..c9edd0c16 100644 --- a/apps/opencs/model/world/universalid.cpp +++ b/apps/opencs/model/world/universalid.cpp @@ -87,6 +87,7 @@ namespace static const TypeData sIndexArg[] = { { CSMWorld::UniversalId::Class_Transient, CSMWorld::UniversalId::Type_VerificationResults, "Verification Results", 0 }, + { CSMWorld::UniversalId::Class_Collection, CSMWorld::UniversalId::Type_Scene, "Scene", 0 }, { CSMWorld::UniversalId::Class_None, CSMWorld::UniversalId::Type_None, 0, 0 } // end marker }; diff --git a/apps/opencs/model/world/universalid.hpp b/apps/opencs/model/world/universalid.hpp index aa0cdacc0..246640733 100644 --- a/apps/opencs/model/world/universalid.hpp +++ b/apps/opencs/model/world/universalid.hpp @@ -86,10 +86,11 @@ namespace CSMWorld Type_Reference, Type_RegionMap, Type_Filter, - Type_Filters + Type_Filters, + Type_Scene }; - enum { NumberOfTypes = Type_Filters+1 }; + enum { NumberOfTypes = Type_Scene+1 }; private: diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 7183753e1..b29250d20 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -115,6 +115,10 @@ void CSVDoc::View::setupWorldMenu() world->addSeparator(); // items that don't represent single record lists follow here + QAction *scene = new QAction (tr ("Scene"), this); + connect (scene, SIGNAL (triggered()), this, SLOT (addSceneSubView())); + world->addAction (scene); + QAction *regionMap = new QAction (tr ("Region Map"), this); connect (regionMap, SIGNAL (triggered()), this, SLOT (addRegionMapSubView())); world->addAction (regionMap); @@ -403,6 +407,11 @@ void CSVDoc::View::addFiltersSubView() addSubView (CSMWorld::UniversalId::Type_Filters); } +void CSVDoc::View::addSceneSubView() +{ + addSubView (CSMWorld::UniversalId::Type_Scene); +} + void CSVDoc::View::abortOperation (int type) { mDocument->abortOperation (type); diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index 29a1d52f7..6f3c38daa 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -164,6 +164,8 @@ namespace CSVDoc void addFiltersSubView(); + void addSceneSubView(); + void toggleShowStatusBar (bool show); }; } diff --git a/apps/opencs/view/world/scenesubview.cpp b/apps/opencs/view/world/scenesubview.cpp new file mode 100644 index 000000000..bb77fec2e --- /dev/null +++ b/apps/opencs/view/world/scenesubview.cpp @@ -0,0 +1,72 @@ + +#include "scenesubview.hpp" + +#include +#include +#include + +#include "../../model/doc/document.hpp" + +#include "../filter/filterbox.hpp" + +#include "tablebottombox.hpp" +#include "creator.hpp" +#include "scenetoolbar.hpp" + +CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document) +: SubView (id) +{ + QVBoxLayout *layout = new QVBoxLayout; + + layout->setContentsMargins (QMargins (0, 0, 0, 0)); + + layout->addWidget (mBottom = + new TableBottomBox (NullCreatorFactory(), document.getData(), document.getUndoStack(), id, + this), 0); + + QHBoxLayout *layout2 = new QHBoxLayout; + + layout2->setContentsMargins (QMargins (0, 0, 0, 0)); + + SceneToolbar *toolbar = new SceneToolbar (this); + layout2->addWidget (toolbar, 0); + + /// \todo replace with rendering widget + QPalette palette2 (palette()); + palette2.setColor (QPalette::Background, Qt::white); + QLabel *placeholder = new QLabel ("Here goes the 3D scene", this); + placeholder->setAutoFillBackground (true); + placeholder->setPalette (palette2); + placeholder->setAlignment (Qt::AlignHCenter); + + layout2->addWidget (placeholder, 1); + + layout->insertLayout (0, layout2, 1); + + CSVFilter::FilterBox *filterBox = new CSVFilter::FilterBox (document.getData(), this); + + layout->insertWidget (0, filterBox); + + QWidget *widget = new QWidget; + + widget->setLayout (layout); + + setWidget (widget); +} + +void CSVWorld::SceneSubView::setEditLock (bool locked) +{ + + +} + +void CSVWorld::SceneSubView::updateEditorSetting(const QString &settingName, const QString &settingValue) +{ + + +} + +void CSVWorld::SceneSubView::setStatusBar (bool show) +{ + mBottom->setStatusBar (show); +} \ No newline at end of file diff --git a/apps/opencs/view/world/scenesubview.hpp b/apps/opencs/view/world/scenesubview.hpp new file mode 100644 index 000000000..a0fed908d --- /dev/null +++ b/apps/opencs/view/world/scenesubview.hpp @@ -0,0 +1,37 @@ +#ifndef CSV_WORLD_SCENESUBVIEW_H +#define CSV_WORLD_SCENESUBVIEW_H + +#include "../doc/subview.hpp" + +class QModelIndex; + +namespace CSMDoc +{ + class Document; +} + +namespace CSVWorld +{ + class Table; + class TableBottomBox; + class CreatorFactoryBase; + + class SceneSubView : public CSVDoc::SubView + { + Q_OBJECT + + TableBottomBox *mBottom; + + public: + + SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document); + + virtual void setEditLock (bool locked); + + virtual void updateEditorSetting (const QString& key, const QString& value); + + virtual void setStatusBar (bool show); + }; +} + +#endif diff --git a/apps/opencs/view/world/scenetoolbar.cpp b/apps/opencs/view/world/scenetoolbar.cpp new file mode 100644 index 000000000..6ced03a9f --- /dev/null +++ b/apps/opencs/view/world/scenetoolbar.cpp @@ -0,0 +1,8 @@ + +#include "scenetoolbar.hpp" + +CSVWorld::SceneToolbar::SceneToolbar (QWidget *parent) : QWidget (parent) +{ + setFixedWidth (52); + +} diff --git a/apps/opencs/view/world/scenetoolbar.hpp b/apps/opencs/view/world/scenetoolbar.hpp new file mode 100644 index 000000000..2fb288100 --- /dev/null +++ b/apps/opencs/view/world/scenetoolbar.hpp @@ -0,0 +1,20 @@ +#ifndef CSV_WORLD_SCENETOOLBAR_H +#define CSV_WORLD_SCENETOOLBAR_H + +#include + +namespace CSVWorld +{ + class SceneToolbar : public QWidget + { + Q_OBJECT + + public: + + SceneToolbar (QWidget *parent); + + + }; +} + +#endif diff --git a/apps/opencs/view/world/subviews.cpp b/apps/opencs/view/world/subviews.cpp index d22e07d89..0e3465b38 100644 --- a/apps/opencs/view/world/subviews.cpp +++ b/apps/opencs/view/world/subviews.cpp @@ -13,6 +13,7 @@ #include "cellcreator.hpp" #include "referenceablecreator.hpp" #include "referencecreator.hpp" +#include "scenesubview.hpp" void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) { @@ -62,4 +63,5 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) new CSVDoc::SubViewFactoryWithCreator >); + manager.add (CSMWorld::UniversalId::Type_Scene, new CSVDoc::SubViewFactory); } \ No newline at end of file From 84cadc10f4a32a752426f106d75db9078f160c10 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 28 Sep 2013 11:06:56 +0200 Subject: [PATCH 2/6] added scene toolbar buttons (still not doing anything) --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/view/world/scenesubview.cpp | 5 +++++ apps/opencs/view/world/scenetool.cpp | 9 +++++++++ apps/opencs/view/world/scenetool.hpp | 19 +++++++++++++++++++ apps/opencs/view/world/scenetoolbar.cpp | 17 ++++++++++++++++- apps/opencs/view/world/scenetoolbar.hpp | 8 +++++++- 6 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 apps/opencs/view/world/scenetool.cpp create mode 100644 apps/opencs/view/world/scenetool.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 2fbceac96..2bb31be9f 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -59,7 +59,7 @@ opencs_hdrs_noqt (view/doc opencs_units (view/world table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator - cellcreator referenceablecreator referencecreator scenesubview scenetoolbar + cellcreator referenceablecreator referencecreator scenesubview scenetoolbar scenetool ) opencs_units_noqt (view/world diff --git a/apps/opencs/view/world/scenesubview.cpp b/apps/opencs/view/world/scenesubview.cpp index bb77fec2e..3b15326ab 100644 --- a/apps/opencs/view/world/scenesubview.cpp +++ b/apps/opencs/view/world/scenesubview.cpp @@ -12,6 +12,7 @@ #include "tablebottombox.hpp" #include "creator.hpp" #include "scenetoolbar.hpp" +#include "scenetool.hpp" CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document) : SubView (id) @@ -29,6 +30,10 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D layout2->setContentsMargins (QMargins (0, 0, 0, 0)); SceneToolbar *toolbar = new SceneToolbar (this); +toolbar->addTool (new SceneTool (this)); // test +toolbar->addTool (new SceneTool (this)); +toolbar->addTool (new SceneTool (this)); +toolbar->addTool (new SceneTool (this)); layout2->addWidget (toolbar, 0); /// \todo replace with rendering widget diff --git a/apps/opencs/view/world/scenetool.cpp b/apps/opencs/view/world/scenetool.cpp new file mode 100644 index 000000000..12743c52c --- /dev/null +++ b/apps/opencs/view/world/scenetool.cpp @@ -0,0 +1,9 @@ + +#include "scenetool.hpp" + +CSVWorld::SceneTool::SceneTool (QWidget *parent) : QPushButton (parent) +{ + setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed)); + setFixedSize (48, 48); + +} \ No newline at end of file diff --git a/apps/opencs/view/world/scenetool.hpp b/apps/opencs/view/world/scenetool.hpp new file mode 100644 index 000000000..ae440b579 --- /dev/null +++ b/apps/opencs/view/world/scenetool.hpp @@ -0,0 +1,19 @@ +#ifndef CSV_WORLD_SCENETOOL_H +#define CSV_WORLD_SCENETOOL_H + +#include + +namespace CSVWorld +{ + class SceneTool : public QPushButton + { + Q_OBJECT + + public: + + SceneTool (QWidget *parent = 0); + + }; +} + +#endif diff --git a/apps/opencs/view/world/scenetoolbar.cpp b/apps/opencs/view/world/scenetoolbar.cpp index 6ced03a9f..7c716b5fc 100644 --- a/apps/opencs/view/world/scenetoolbar.cpp +++ b/apps/opencs/view/world/scenetoolbar.cpp @@ -1,8 +1,23 @@ #include "scenetoolbar.hpp" +#include + +#include "scenetool.hpp" + CSVWorld::SceneToolbar::SceneToolbar (QWidget *parent) : QWidget (parent) { - setFixedWidth (52); + setFixedWidth (48); + mLayout = new QVBoxLayout (this); + mLayout->setAlignment (Qt::AlignTop); + + mLayout->setContentsMargins (QMargins (0, 0, 0, 0)); + + setLayout (mLayout); } + +void CSVWorld::SceneToolbar::addTool (SceneTool *tool) +{ + mLayout->addWidget (tool, 0, Qt::AlignTop); +} \ No newline at end of file diff --git a/apps/opencs/view/world/scenetoolbar.hpp b/apps/opencs/view/world/scenetoolbar.hpp index 2fb288100..00631c360 100644 --- a/apps/opencs/view/world/scenetoolbar.hpp +++ b/apps/opencs/view/world/scenetoolbar.hpp @@ -3,17 +3,23 @@ #include +class QVBoxLayout; + namespace CSVWorld { + class SceneTool; + class SceneToolbar : public QWidget { Q_OBJECT + QVBoxLayout *mLayout; + public: SceneToolbar (QWidget *parent); - + void addTool (SceneTool *tool); }; } From 0c5f07a65addf90c4fd033b2d4e4e03424f26e24 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 28 Sep 2013 11:27:24 +0200 Subject: [PATCH 3/6] added SceneToolMode class --- apps/opencs/CMakeLists.txt | 1 + apps/opencs/view/world/scenesubview.cpp | 10 +++++----- apps/opencs/view/world/scenetool.cpp | 1 - apps/opencs/view/world/scenetool.hpp | 1 + apps/opencs/view/world/scenetoolmode.cpp | 6 ++++++ apps/opencs/view/world/scenetoolmode.hpp | 19 +++++++++++++++++++ 6 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 apps/opencs/view/world/scenetoolmode.cpp create mode 100644 apps/opencs/view/world/scenetoolmode.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 2bb31be9f..f918cfebf 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -60,6 +60,7 @@ opencs_hdrs_noqt (view/doc opencs_units (view/world table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator cellcreator referenceablecreator referencecreator scenesubview scenetoolbar scenetool + scenetoolmode ) opencs_units_noqt (view/world diff --git a/apps/opencs/view/world/scenesubview.cpp b/apps/opencs/view/world/scenesubview.cpp index 3b15326ab..8f3ecab21 100644 --- a/apps/opencs/view/world/scenesubview.cpp +++ b/apps/opencs/view/world/scenesubview.cpp @@ -12,7 +12,7 @@ #include "tablebottombox.hpp" #include "creator.hpp" #include "scenetoolbar.hpp" -#include "scenetool.hpp" +#include "scenetoolmode.hpp" CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document) : SubView (id) @@ -30,10 +30,10 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D layout2->setContentsMargins (QMargins (0, 0, 0, 0)); SceneToolbar *toolbar = new SceneToolbar (this); -toolbar->addTool (new SceneTool (this)); // test -toolbar->addTool (new SceneTool (this)); -toolbar->addTool (new SceneTool (this)); -toolbar->addTool (new SceneTool (this)); +toolbar->addTool (new SceneToolMode (this)); // test +toolbar->addTool (new SceneToolMode (this)); +toolbar->addTool (new SceneToolMode (this)); +toolbar->addTool (new SceneToolMode (this)); layout2->addWidget (toolbar, 0); /// \todo replace with rendering widget diff --git a/apps/opencs/view/world/scenetool.cpp b/apps/opencs/view/world/scenetool.cpp index 12743c52c..f67e4fa45 100644 --- a/apps/opencs/view/world/scenetool.cpp +++ b/apps/opencs/view/world/scenetool.cpp @@ -5,5 +5,4 @@ CSVWorld::SceneTool::SceneTool (QWidget *parent) : QPushButton (parent) { setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed)); setFixedSize (48, 48); - } \ No newline at end of file diff --git a/apps/opencs/view/world/scenetool.hpp b/apps/opencs/view/world/scenetool.hpp index ae440b579..c3e9e3b4b 100644 --- a/apps/opencs/view/world/scenetool.hpp +++ b/apps/opencs/view/world/scenetool.hpp @@ -5,6 +5,7 @@ namespace CSVWorld { + ///< \brief Tool base class class SceneTool : public QPushButton { Q_OBJECT diff --git a/apps/opencs/view/world/scenetoolmode.cpp b/apps/opencs/view/world/scenetoolmode.cpp new file mode 100644 index 000000000..a6b9b5a28 --- /dev/null +++ b/apps/opencs/view/world/scenetoolmode.cpp @@ -0,0 +1,6 @@ + +#include "scenetoolmode.hpp" + +CSVWorld::SceneToolMode::SceneToolMode (QWidget *parent) +: SceneTool (parent) +{} \ No newline at end of file diff --git a/apps/opencs/view/world/scenetoolmode.hpp b/apps/opencs/view/world/scenetoolmode.hpp new file mode 100644 index 000000000..d54ec76b2 --- /dev/null +++ b/apps/opencs/view/world/scenetoolmode.hpp @@ -0,0 +1,19 @@ +#ifndef CSV_WORLD_SCENETOOL_MODE_H +#define CSV_WORLD_SCENETOOL_MODE_H + +#include "scenetool.hpp" + +namespace CSVWorld +{ + ///< \brief Mode selector tool + class SceneToolMode : public SceneTool + { + Q_OBJECT + + public: + + SceneToolMode (QWidget *parent = 0); + }; +} + +#endif From 7be1f1afc2a9e5ce7f6e0d95d22483fc544d90ac Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 28 Sep 2013 13:10:42 +0200 Subject: [PATCH 4/6] 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(); }; } From 74cee662731d0004adbfdaa657eed3bdc8c45986 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 7 Oct 2013 11:14:11 +0200 Subject: [PATCH 5/6] consolidated magic numbers for button size --- apps/opencs/view/world/scenesubview.cpp | 10 +++++----- apps/opencs/view/world/scenetool.cpp | 6 ++++-- apps/opencs/view/world/scenetool.hpp | 4 +++- apps/opencs/view/world/scenetoolbar.cpp | 10 ++++++++-- apps/opencs/view/world/scenetoolbar.hpp | 5 ++++- apps/opencs/view/world/scenetoolmode.cpp | 8 +++++--- apps/opencs/view/world/scenetoolmode.hpp | 5 ++++- 7 files changed, 33 insertions(+), 15 deletions(-) diff --git a/apps/opencs/view/world/scenesubview.cpp b/apps/opencs/view/world/scenesubview.cpp index 36ace68f0..e3618c549 100644 --- a/apps/opencs/view/world/scenesubview.cpp +++ b/apps/opencs/view/world/scenesubview.cpp @@ -29,16 +29,16 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D layout2->setContentsMargins (QMargins (0, 0, 0, 0)); - SceneToolbar *toolbar = new SceneToolbar (this); + SceneToolbar *toolbar = new SceneToolbar (48, this); // test -SceneToolMode *tool = new SceneToolMode (this); +SceneToolMode *tool = new SceneToolMode (toolbar); 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)); +toolbar->addTool (new SceneToolMode (toolbar)); +toolbar->addTool (new SceneToolMode (toolbar)); +toolbar->addTool (new SceneToolMode (toolbar)); layout2->addWidget (toolbar, 0); /// \todo replace with rendering widget diff --git a/apps/opencs/view/world/scenetool.cpp b/apps/opencs/view/world/scenetool.cpp index d7d37c98f..2140cd1e0 100644 --- a/apps/opencs/view/world/scenetool.cpp +++ b/apps/opencs/view/world/scenetool.cpp @@ -1,10 +1,12 @@ #include "scenetool.hpp" -CSVWorld::SceneTool::SceneTool (QWidget *parent) : QPushButton (parent) +#include "scenetoolbar.hpp" + +CSVWorld::SceneTool::SceneTool (SceneToolbar *parent) : QPushButton (parent) { setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed)); - setFixedSize (48, 48); + setFixedSize (parent->getButtonSize(), parent->getButtonSize()); connect (this, SIGNAL (clicked()), this, SLOT (openRequest())); } diff --git a/apps/opencs/view/world/scenetool.hpp b/apps/opencs/view/world/scenetool.hpp index d5c9dd5d2..2e83b0c6d 100644 --- a/apps/opencs/view/world/scenetool.hpp +++ b/apps/opencs/view/world/scenetool.hpp @@ -5,6 +5,8 @@ namespace CSVWorld { + class SceneToolbar; + ///< \brief Tool base class class SceneTool : public QPushButton { @@ -12,7 +14,7 @@ namespace CSVWorld public: - SceneTool (QWidget *parent = 0); + SceneTool (SceneToolbar *parent); virtual void showPanel (const QPoint& position) = 0; diff --git a/apps/opencs/view/world/scenetoolbar.cpp b/apps/opencs/view/world/scenetoolbar.cpp index 7c716b5fc..2972c5391 100644 --- a/apps/opencs/view/world/scenetoolbar.cpp +++ b/apps/opencs/view/world/scenetoolbar.cpp @@ -5,9 +5,10 @@ #include "scenetool.hpp" -CSVWorld::SceneToolbar::SceneToolbar (QWidget *parent) : QWidget (parent) +CSVWorld::SceneToolbar::SceneToolbar (int buttonSize, QWidget *parent) +: QWidget (parent), mButtonSize (buttonSize) { - setFixedWidth (48); + setFixedWidth (mButtonSize); mLayout = new QVBoxLayout (this); mLayout->setAlignment (Qt::AlignTop); @@ -20,4 +21,9 @@ CSVWorld::SceneToolbar::SceneToolbar (QWidget *parent) : QWidget (parent) void CSVWorld::SceneToolbar::addTool (SceneTool *tool) { mLayout->addWidget (tool, 0, Qt::AlignTop); +} + +int CSVWorld::SceneToolbar::getButtonSize() const +{ + return mButtonSize; } \ No newline at end of file diff --git a/apps/opencs/view/world/scenetoolbar.hpp b/apps/opencs/view/world/scenetoolbar.hpp index 00631c360..f713ca3df 100644 --- a/apps/opencs/view/world/scenetoolbar.hpp +++ b/apps/opencs/view/world/scenetoolbar.hpp @@ -14,12 +14,15 @@ namespace CSVWorld Q_OBJECT QVBoxLayout *mLayout; + int mButtonSize; public: - SceneToolbar (QWidget *parent); + SceneToolbar (int buttonSize, QWidget *parent = 0); void addTool (SceneTool *tool); + + int getButtonSize() const; }; } diff --git a/apps/opencs/view/world/scenetoolmode.cpp b/apps/opencs/view/world/scenetoolmode.cpp index b4277bcbe..2435a8e35 100644 --- a/apps/opencs/view/world/scenetoolmode.cpp +++ b/apps/opencs/view/world/scenetoolmode.cpp @@ -5,8 +5,10 @@ #include #include -CSVWorld::SceneToolMode::SceneToolMode (QWidget *parent) -: SceneTool (parent) +#include "scenetoolbar.hpp" + +CSVWorld::SceneToolMode::SceneToolMode (SceneToolbar *parent) +: SceneTool (parent), mButtonSize (parent->getButtonSize()) { mPanel = new QFrame (this, Qt::Popup); @@ -27,7 +29,7 @@ void CSVWorld::SceneToolMode::addButton (const std::string& icon, const std::str { QPushButton *button = new QPushButton (QIcon (QPixmap (icon.c_str())), "", mPanel); button->setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed)); - button->setFixedSize (48, 48); + button->setFixedSize (mButtonSize, mButtonSize); mLayout->addWidget (button); diff --git a/apps/opencs/view/world/scenetoolmode.hpp b/apps/opencs/view/world/scenetoolmode.hpp index feee78376..a8fe2b5a6 100644 --- a/apps/opencs/view/world/scenetoolmode.hpp +++ b/apps/opencs/view/world/scenetoolmode.hpp @@ -9,6 +9,8 @@ class QHBoxLayout; namespace CSVWorld { + class SceneToolbar; + ///< \brief Mode selector tool class SceneToolMode : public SceneTool { @@ -17,10 +19,11 @@ namespace CSVWorld QWidget *mPanel; QHBoxLayout *mLayout; std::map mButtons; // widget, id + int mButtonSize; public: - SceneToolMode (QWidget *parent = 0); + SceneToolMode (SceneToolbar *parent); virtual void showPanel (const QPoint& position); From 4624bed899568f8465399048502b1e0ef9aa073c Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 13 Oct 2013 15:41:48 +0200 Subject: [PATCH 6/6] changed handling of scene toolbar button icons --- apps/opencs/view/world/scenetool.cpp | 5 ----- apps/opencs/view/world/scenetool.hpp | 4 ---- apps/opencs/view/world/scenetoolmode.cpp | 5 ++++- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/apps/opencs/view/world/scenetool.cpp b/apps/opencs/view/world/scenetool.cpp index 2140cd1e0..320deb1ba 100644 --- a/apps/opencs/view/world/scenetool.cpp +++ b/apps/opencs/view/world/scenetool.cpp @@ -11,11 +11,6 @@ CSVWorld::SceneTool::SceneTool (SceneToolbar *parent) : QPushButton (parent) 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 2e83b0c6d..07e8b58d7 100644 --- a/apps/opencs/view/world/scenetool.hpp +++ b/apps/opencs/view/world/scenetool.hpp @@ -18,10 +18,6 @@ namespace CSVWorld 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 2435a8e35..281d703b6 100644 --- a/apps/opencs/view/world/scenetoolmode.cpp +++ b/apps/opencs/view/world/scenetoolmode.cpp @@ -36,6 +36,9 @@ void CSVWorld::SceneToolMode::addButton (const std::string& icon, const std::str mButtons.insert (std::make_pair (button, id)); connect (button, SIGNAL (clicked()), this, SLOT (selected())); + + if (mButtons.size()==1) + setIcon (button->icon()); } void CSVWorld::SceneToolMode::selected() @@ -47,7 +50,7 @@ void CSVWorld::SceneToolMode::selected() { mPanel->hide(); - emit updateIcon (iter->first->icon()); + setIcon (iter->first->icon()); emit modeChanged (iter->second); } } \ No newline at end of file