summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2010-02-26 11:32:16 +0100
committerChristian Kamm <christian.d.kamm@nokia.com>2010-02-26 11:32:16 +0100
commitcef2b1fee913b50167ba26598dcfc7124cc98185 (patch)
tree6f2e525e776c86c12741ff586b63e111176e2739
parent3a11db5d90e1c79d6e8fe47afda3b96cd7d8406b (diff)
Improve separation of ToolBoxPages and the RCW.
Instead of adding themselves to the RCW in the constructor, just initialize the page there and count on the user to add the page when needed.
-rw-r--r--example/main.cpp4
-rw-r--r--library/components/locationui.cpp9
-rw-r--r--library/components/locationui.h8
-rw-r--r--library/remotecontrolwidget.cpp4
-rw-r--r--library/remotecontrolwidget.h3
-rw-r--r--library/toolbox.cpp37
-rw-r--r--library/toolbox.h18
7 files changed, 50 insertions, 33 deletions
diff --git a/example/main.cpp b/example/main.cpp
index b36749e..e8716bc 100644
--- a/example/main.cpp
+++ b/example/main.cpp
@@ -8,7 +8,9 @@ int main(int argc, char *argv[])
{
QApplication a(argc, argv);
RemoteControlWidget w;
- LocationUi l(&w);
+
+ LocationUi l;
+ w.addToolBoxPage(&l);
BatteryButton batteryButton;
w.addMenuButton(&batteryButton);
diff --git a/library/components/locationui.cpp b/library/components/locationui.cpp
index 4d1f6ff..b0a08e7 100644
--- a/library/components/locationui.cpp
+++ b/library/components/locationui.cpp
@@ -1,7 +1,7 @@
#include "locationui.h"
#include "optionsitem.h"
-#include "remotecontrolwidget.h"
+#include "toolbox.h"
#include <QtGui/QLineEdit>
#include <QtGui/QDoubleValidator>
@@ -9,8 +9,8 @@
#include <QtGui/QBoxLayout>
#include <QtGui/QDateTimeEdit>
-LocationUi::LocationUi(RemoteControlWidget *w)
- : QObject(w)
+LocationUi::LocationUi(QWidget *parent)
+ : ToolBoxPage(parent)
, mLatitudeEdit(0)
, mLongitudeEdit(0)
, mAltitudeEdit(0)
@@ -56,7 +56,8 @@ LocationUi::LocationUi(RemoteControlWidget *w)
item->setTags(tags);
optionsList << item;
- w->addToolBoxPage(tr("Location"), optionsList);
+ setOptions(optionsList);
+ setTitle(tr("Location"));
}
void LocationUi::updateLocationTime()
diff --git a/library/components/locationui.h b/library/components/locationui.h
index 53d0d14..e40581f 100644
--- a/library/components/locationui.h
+++ b/library/components/locationui.h
@@ -2,18 +2,16 @@
#define LOCATIONUI_H
#include "remotecontrolwidget_global.h"
+#include "toolbox.h"
-#include <QtCore/QObject>
-
-class RemoteControlWidget;
class QLineEdit;
class QDateTimeEdit;
-class REMOTECONTROLWIDGETSHARED_EXPORT LocationUi : public QObject
+class REMOTECONTROLWIDGETSHARED_EXPORT LocationUi : public ToolBoxPage
{
Q_OBJECT
public:
- LocationUi(RemoteControlWidget* w);
+ explicit LocationUi(QWidget *parent = 0);
public slots:
void setLocation(/* LocationData */);
diff --git a/library/remotecontrolwidget.cpp b/library/remotecontrolwidget.cpp
index f731d46..a26195e 100644
--- a/library/remotecontrolwidget.cpp
+++ b/library/remotecontrolwidget.cpp
@@ -107,9 +107,9 @@ void RemoteControlWidget::filtersChanged()
mToolBox->filtersChanged(mFilterLineEdit->typedText());
}
-void RemoteControlWidget::addToolBoxPage(const QString &title, const QList<OptionsItem *> &options)
+void RemoteControlWidget::addToolBoxPage(ToolBoxPage *page)
{
- mToolBox->addPage(title, options);
+ mToolBox->addPage(page);
}
void RemoteControlWidget::addMenuButton(QToolButton *button)
diff --git a/library/remotecontrolwidget.h b/library/remotecontrolwidget.h
index 891dcd2..f405194 100644
--- a/library/remotecontrolwidget.h
+++ b/library/remotecontrolwidget.h
@@ -8,6 +8,7 @@
class OptionsItem;
class FilterLineEdit;
class ToolBox;
+class ToolBoxPage;
class StyledBar;
class ManhattanStyle;
class QToolButton;
@@ -24,7 +25,7 @@ public:
virtual void writeSettings(const QString &vendor, const QString &name) const;
virtual void readSettings(const QString &vendor, const QString &name);
- void addToolBoxPage(const QString &title, const QList<OptionsItem *> &options);
+ void addToolBoxPage(ToolBoxPage *page);
void addMenuButton(QToolButton *button);
protected:
diff --git a/library/toolbox.cpp b/library/toolbox.cpp
index eb88a45..e919745 100644
--- a/library/toolbox.cpp
+++ b/library/toolbox.cpp
@@ -27,18 +27,19 @@ ToolBox::~ToolBox()
{
}
-bool ToolBox::addPage(const QString &title, const QList<OptionsItem *> &options)
+bool ToolBox::addPage(ToolBoxPage *page)
{
- return insertPage(-1, title, options);
+ return insertPage(-1, page);
}
-bool ToolBox::insertPage(int index, const QString &title, const QList<OptionsItem *> &options)
+bool ToolBox::insertPage(int index, ToolBoxPage *page)
{
if (index == -1)
index = layout()->count() - 1; //As the spacer is the layout's last item
if (index < 0 || index > layout()->count() - 1)
return false;
- ToolBoxPage *page = new ToolBoxPage(title, options, this);
page->setStyle(style());
+ page->mHeaderBar->setStyle(style());
+ page->mButton->setStyle(style());
mLayout->insertWidget(index, page);
mPages.insert(index, page);
connect(page, SIGNAL(minimalInputWidthChanged(int)), SLOT(processPageMinimalInputWidth(int)));
@@ -104,13 +105,12 @@ void ToolBox::processPageMinimalInputWidth(int newWidth)
}
}
-ToolBoxPage::ToolBoxPage(const QString &title, const QList<OptionsItem *> &options, ToolBox *box)
- : QFrame(box)
+ToolBoxPage::ToolBoxPage(QWidget *parent)
+ : QFrame(parent)
, mButton(0)
, mPage(0)
, mInnerLayout(0)
, mHeaderLayout(0)
- , mOptions(options)
, mAdvancedMode(false)
, mExplicitOpen(false)
, mMinimalInputWidth(0)
@@ -123,21 +123,18 @@ ToolBoxPage::ToolBoxPage(const QString &title, const QList<OptionsItem *> &optio
mButton = new QToolButton(this);
mButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
- mButton->setText(title);
mButton->setArrowType(Qt::RightArrow);
mButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
- mButton->setStyle(box->style());
connect(mButton, SIGNAL(clicked()), SLOT(toggleOpenExplicitly()));
mHeaderLayout = new QHBoxLayout();
mHeaderLayout->setSpacing(0);
mHeaderLayout->setContentsMargins(0,0,0,0);
mHeaderLayout->addWidget(mButton);
- StyledBar *top = new StyledBar;
- top->setStyle(box->style());
- top->setLightColored(true);
- top->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
- top->setLayout(mHeaderLayout);
- vLayout->addWidget(top);
+ mHeaderBar = new StyledBar;
+ mHeaderBar->setLightColored(true);
+ mHeaderBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
+ mHeaderBar->setLayout(mHeaderLayout);
+ vLayout->addWidget(mHeaderBar);
mPage = new QWidget(this);
mInnerLayout = new QFormLayout();
@@ -153,6 +150,16 @@ ToolBoxPage::~ToolBoxPage()
{
}
+void ToolBoxPage::setOptions(const QList<OptionsItem *> &options)
+{
+ mOptions = options;
+}
+
+void ToolBoxPage::setTitle(const QString &title)
+{
+ mButton->setText(title);
+}
+
void ToolBoxPage::init()
{
//Initially add all the "basic" items to the page, even if nothing is visible
diff --git a/library/toolbox.h b/library/toolbox.h
index 6ce7425..340ea60 100644
--- a/library/toolbox.h
+++ b/library/toolbox.h
@@ -1,6 +1,7 @@
#ifndef TOOLBOX_H
#define TOOLBOX_H
+#include "remotecontrolwidget_global.h"
#include "optionsitem.h"
#include <QtGui/QFrame>
@@ -8,9 +9,10 @@
#include <QtCore/QList>
class ToolBoxPage;
+class StyledBar;
+class OptionsItem;
class QToolButton;
class QFormLayout;
-class OptionsItem;
class QStringList;
class QVBoxLayout;
class QHBoxLayout;
@@ -24,8 +26,8 @@ public:
virtual ~ToolBox();
public:
- bool addPage(const QString &title, const QList<OptionsItem *> &options);
- bool insertPage(int index, const QString &title, const QList<OptionsItem *> &options);
+ bool addPage(ToolBoxPage *page);
+ bool insertPage(int index, ToolBoxPage *page);
void filtersChanged(const QString &filters);
@@ -42,23 +44,29 @@ private slots:
void processPageMinimalInputWidth(int newWidth);
};
-class ToolBoxPage : public QFrame
+class REMOTECONTROLWIDGETSHARED_EXPORT ToolBoxPage : public QFrame
{
Q_OBJECT
friend class ToolBox;
public:
- ToolBoxPage(const QString &title, const QList<OptionsItem *> &options, ToolBox *box);
+ explicit ToolBoxPage(QWidget *parent = 0);
virtual ~ToolBoxPage();
public slots:
unsigned int filtersChanged(const QStringList &filters);
void advancedToggled(OptionsItem *item);
+protected:
+ // must be set before page is added to tool box
+ void setOptions(const QList<OptionsItem *> &options);
+ void setTitle(const QString &title);
+
private:
QToolButton *mButton;
QWidget *mPage;
QFormLayout *mInnerLayout;
QHBoxLayout *mHeaderLayout;
+ StyledBar *mHeaderBar;
QList<OptionsItem *> mOptions;
bool mAdvancedMode;
QStringList mLastFilters;