From 74cee662731d0004adbfdaa657eed3bdc8c45986 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 7 Oct 2013 11:14:11 +0200 Subject: [PATCH] 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 36ace68f0e..e3618c5493 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 d7d37c98f6..2140cd1e02 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 d5c9dd5d2f..2e83b0c6d7 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 7c716b5fce..2972c53913 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 00631c360c..f713ca3dff 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 b4277bcbe7..2435a8e357 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 feee78376b..a8fe2b5a6c 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);