From 542570896e1e0ce73ebfc442b48e741c2ea32377 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Wed, 25 Jul 2012 22:27:32 +0200 Subject: Removed all the hardcoded sizes of the various setup tabs Instead, support for dynamically adjusting layout was added to the Container class. Various other places were also adapted to use the new layout support in Container. Reviewed-by: Erik Schilling --- src/gui/widgets/container.cpp | 25 ++++++++++++++++++++++++- src/gui/widgets/container.h | 24 ++++++++++++++++++++++++ src/gui/widgets/layouthelper.cpp | 5 ----- src/gui/widgets/layouthelper.h | 4 ++-- src/gui/widgets/setuptab.cpp | 1 - src/gui/widgets/vertcontainer.h | 2 +- 6 files changed, 51 insertions(+), 10 deletions(-) (limited to 'src/gui/widgets') diff --git a/src/gui/widgets/container.cpp b/src/gui/widgets/container.cpp index af4f0155..e1b99af7 100644 --- a/src/gui/widgets/container.cpp +++ b/src/gui/widgets/container.cpp @@ -21,7 +21,10 @@ #include "gui/widgets/container.h" -Container::Container() +#include "gui/widgets/layouthelper.h" + +Container::Container(): + mLayoutHelper(0) { setOpaque(false); } @@ -30,4 +33,24 @@ Container::~Container() { while (!mWidgets.empty()) delete mWidgets.front(); + + delete mLayoutHelper; +} + +Layout &Container::getLayout() +{ + if (!mLayoutHelper) + mLayoutHelper = new LayoutHelper(this); + return mLayoutHelper->getLayout(); +} + +LayoutCell &Container::place(int x, int y, gcn::Widget *wg, int w, int h) +{ + add(wg); + return getLayout().place(wg, x, y, w, h); +} + +ContainerPlacer Container::getPlacer(int x, int y) +{ + return ContainerPlacer(this, &getLayout().at(x, y)); } diff --git a/src/gui/widgets/container.h b/src/gui/widgets/container.h index e582f2a8..46b719a1 100644 --- a/src/gui/widgets/container.h +++ b/src/gui/widgets/container.h @@ -24,6 +24,11 @@ #include +class ContainerPlacer; +class Layout; +class LayoutCell; +class LayoutHelper; + /** * A widget container. * @@ -38,6 +43,25 @@ class Container : public gcn::Container public: Container(); ~Container(); + + protected: + /** + * Gets the layout handler for this container. + */ + Layout &getLayout(); + + /** + * Adds a widget to the container and sets it at given cell. + */ + LayoutCell &place(int x, int y, gcn::Widget *wg, int w = 1, int h = 1); + + /** + * Returns a proxy for adding widgets in an inner table of the layout. + */ + ContainerPlacer getPlacer(int x, int y); + + private: + LayoutHelper *mLayoutHelper; }; #endif diff --git a/src/gui/widgets/layouthelper.cpp b/src/gui/widgets/layouthelper.cpp index 1a634fcd..e1006bd9 100644 --- a/src/gui/widgets/layouthelper.cpp +++ b/src/gui/widgets/layouthelper.cpp @@ -32,11 +32,6 @@ LayoutHelper::~LayoutHelper() mContainer->removeWidgetListener(this); } -Layout &LayoutHelper::getLayout() -{ - return mLayout; -} - LayoutCell &LayoutHelper::place(int x, int y, gcn::Widget *wg, int w, int h) { mContainer->add(wg); diff --git a/src/gui/widgets/layouthelper.h b/src/gui/widgets/layouthelper.h index 055e6fa6..b8512212 100644 --- a/src/gui/widgets/layouthelper.h +++ b/src/gui/widgets/layouthelper.h @@ -34,14 +34,14 @@ class LayoutHelper : public gcn::WidgetListener { public: - LayoutHelper(gcn::Container *container); + explicit LayoutHelper(gcn::Container *container); ~LayoutHelper(); /** * Gets the layout handler. */ - Layout &getLayout(); + Layout &getLayout() { return mLayout; } /** * Computes the position of the widgets according to the current diff --git a/src/gui/widgets/setuptab.cpp b/src/gui/widgets/setuptab.cpp index a1a493ad..dc183a50 100644 --- a/src/gui/widgets/setuptab.cpp +++ b/src/gui/widgets/setuptab.cpp @@ -23,5 +23,4 @@ SetupTab::SetupTab() { - setOpaque(false); } diff --git a/src/gui/widgets/vertcontainer.h b/src/gui/widgets/vertcontainer.h index 10bc68c3..c2403afb 100644 --- a/src/gui/widgets/vertcontainer.h +++ b/src/gui/widgets/vertcontainer.h @@ -28,7 +28,7 @@ /** * A widget container. * - * This container places it's contents veritcally. + * This container places its contents vertically. */ class VertContainer : public Container, public gcn::WidgetListener { -- cgit v1.2.3-60-g2f50