diff options
author | Christian Kamm <christian.d.kamm@nokia.com> | 2010-02-26 11:03:56 +0100 |
---|---|---|
committer | Christian Kamm <christian.d.kamm@nokia.com> | 2010-02-26 11:03:56 +0100 |
commit | 1b158abe4f9c696f77cc8530691297536ec48fb7 (patch) | |
tree | 99b0a65dfff074706ef812bb07c7e82b42c1b4ad | |
parent | 40c3f2af63cd3c584f355e49d1b2b19be579ce60 (diff) |
Move power and battery button to remote control widget repo.
19 files changed, 214 insertions, 6 deletions
diff --git a/example/main.cpp b/example/main.cpp index 1274a5b..b36749e 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -1,6 +1,8 @@ #include <QtGui/QApplication> #include "remotecontrolwidget.h" -#include "locationui.h" +#include "components/locationui.h" +#include "components/batterybutton.h" +#include "components/powerbutton.h" int main(int argc, char *argv[]) { @@ -8,6 +10,12 @@ int main(int argc, char *argv[]) RemoteControlWidget w; LocationUi l(&w); + BatteryButton batteryButton; + w.addMenuButton(&batteryButton); + + PowerButton powerButton; + w.addMenuButton(&powerButton); + w.show(); return a.exec(); } diff --git a/library/components/batterybutton.cpp b/library/components/batterybutton.cpp new file mode 100644 index 0000000..1c7ebb3 --- /dev/null +++ b/library/components/batterybutton.cpp @@ -0,0 +1,63 @@ +#include "batterybutton.h" + +#include <QtCore/QSignalMapper> +#include <QtGui/QMenu> +#include <QtGui/QIcon> + +BatteryButton::BatteryButton(QWidget *parent) + : QToolButton(parent) +{ + setPopupMode(QToolButton::InstantPopup); + setDisplayedBatteryLevel(BatteryNormal); + setProperty("noArrow", true); + + QMenu *menu = new QMenu(this); + QAction *action = 0; + + action = menu->addAction(QIcon(":/components/images/battery_100.png"), tr("Normal")); + action->setProperty("batteryLevel", BatteryNormal); + connect(action, SIGNAL(triggered()), SLOT(emitBatteryLevelChanged())); + + action = menu->addAction(QIcon(":/components/images/battery_40.png"), tr("Low")); + action->setProperty("batteryLevel", BatteryLow); + connect(action, SIGNAL(triggered()), SLOT(emitBatteryLevelChanged())); + + action = menu->addAction(QIcon(":/components/images/battery_20.png"), tr("Very low")); + action->setProperty("batteryLevel", BatteryVeryLow); + connect(action, SIGNAL(triggered()), SLOT(emitBatteryLevelChanged())); + + action = menu->addAction(QIcon(":/components/images/battery_0.png"), tr("Critical")); + action->setProperty("batteryLevel", BatteryCritical); + connect(action, SIGNAL(triggered()), SLOT(emitBatteryLevelChanged())); + + setMenu(menu); +} + +BatteryButton::~BatteryButton() +{ +} + +void BatteryButton::emitBatteryLevelChanged() +{ + QAction *action = qobject_cast<QAction *>(sender()); + if (!action) + return; + BatteryLevel newLevel = static_cast<BatteryLevel>(action->property("batteryLevel").toInt()); + + setDisplayedBatteryLevel(newLevel); + emit batteryLevelChanged(newLevel); +} + +void BatteryButton::setDisplayedBatteryLevel(BatteryLevel level) +{ + QIcon newIcon; + if (level == BatteryNormal) + newIcon = QIcon(":/components/images/battery_100.png"); + else if (level == BatteryLow) + newIcon = QIcon(":/components/images/battery_40.png"); + else if (level == BatteryVeryLow) + newIcon = QIcon(":/components/images/battery_20.png"); + else if (level == BatteryCritical) + newIcon = QIcon(":/components/images/battery_0.png"); + setIcon(newIcon); +} diff --git a/library/components/batterybutton.h b/library/components/batterybutton.h new file mode 100644 index 0000000..61a39ab --- /dev/null +++ b/library/components/batterybutton.h @@ -0,0 +1,35 @@ +#ifndef BATTERYBUTTON_H +#define BATTERYBUTTON_H + +#include "remotecontrolwidget_global.h" + +#include <QtGui/QToolButton> + +class REMOTECONTROLWIDGETSHARED_EXPORT BatteryButton : public QToolButton +{ + Q_OBJECT +public: + enum BatteryLevel { + NoBatteryLevel, + BatteryCritical, + BatteryVeryLow, + BatteryLow, + BatteryNormal + }; + Q_ENUMS(BatteryLevel) + +public: + explicit BatteryButton(QWidget *parent = 0); + virtual ~BatteryButton(); + +public slots: + void setDisplayedBatteryLevel(BatteryLevel level); + +signals: + void batteryLevelChanged(BatteryLevel level) const; + +private slots: + void emitBatteryLevelChanged(); +}; + +#endif //BATTERYBUTTON_H diff --git a/library/components/images/battery_0.png b/library/components/images/battery_0.png Binary files differnew file mode 100644 index 0000000..eb4d1e8 --- /dev/null +++ b/library/components/images/battery_0.png diff --git a/library/components/images/battery_100.png b/library/components/images/battery_100.png Binary files differnew file mode 100644 index 0000000..de8c2e9 --- /dev/null +++ b/library/components/images/battery_100.png diff --git a/library/components/images/battery_20.png b/library/components/images/battery_20.png Binary files differnew file mode 100644 index 0000000..4048b36 --- /dev/null +++ b/library/components/images/battery_20.png diff --git a/library/components/images/battery_40.png b/library/components/images/battery_40.png Binary files differnew file mode 100644 index 0000000..71e4e09 --- /dev/null +++ b/library/components/images/battery_40.png diff --git a/library/components/images/battery_60.png b/library/components/images/battery_60.png Binary files differnew file mode 100644 index 0000000..2562a3e --- /dev/null +++ b/library/components/images/battery_60.png diff --git a/library/components/images/battery_80.png b/library/components/images/battery_80.png Binary files differnew file mode 100644 index 0000000..6947b1f --- /dev/null +++ b/library/components/images/battery_80.png diff --git a/library/components/images/batterypower.png b/library/components/images/batterypower.png Binary files differnew file mode 100644 index 0000000..67d15e4 --- /dev/null +++ b/library/components/images/batterypower.png diff --git a/library/components/images/unknownpower.png b/library/components/images/unknownpower.png Binary files differnew file mode 100644 index 0000000..e09005c --- /dev/null +++ b/library/components/images/unknownpower.png diff --git a/library/components/images/wall.png b/library/components/images/wall.png Binary files differnew file mode 100644 index 0000000..3845fc3 --- /dev/null +++ b/library/components/images/wall.png diff --git a/library/components/images/wall_charge.png b/library/components/images/wall_charge.png Binary files differnew file mode 100644 index 0000000..85caf66 --- /dev/null +++ b/library/components/images/wall_charge.png diff --git a/library/locationui.cpp b/library/components/locationui.cpp index 4d1f6ff..4d1f6ff 100644 --- a/library/locationui.cpp +++ b/library/components/locationui.cpp diff --git a/library/locationui.h b/library/components/locationui.h index 53d0d14..53d0d14 100644 --- a/library/locationui.h +++ b/library/components/locationui.h diff --git a/library/components/powerbutton.cpp b/library/components/powerbutton.cpp new file mode 100644 index 0000000..6c2b716 --- /dev/null +++ b/library/components/powerbutton.cpp @@ -0,0 +1,62 @@ +#include "powerbutton.h" + +#include <QtGui/QMenu> +#include <QtGui/QIcon> + +PowerButton::PowerButton(QWidget *parent) + : QToolButton(parent) +{ + setPopupMode(QToolButton::InstantPopup); + setDisplayedState(BatteryPower); + setProperty("noArrow", true); + + QMenu *menu = new QMenu(this); + QAction *action = 0; + + action = menu->addAction(QIcon(":/components/images/unknownpower.png"), tr("Unknown or error")); + action->setProperty("powerState", UnknownPower); + connect(action, SIGNAL(triggered()), SLOT(emitPowerStateChanged())); + + action = menu->addAction(QIcon(":/components/images/batterypower.png"), tr("Battery")); + action->setProperty("powerState", BatteryPower); + connect(action, SIGNAL(triggered()), SLOT(emitPowerStateChanged())); + + action = menu->addAction(QIcon(":/components/images/wall.png"), tr("Wall")); + action->setProperty("powerState", WallPower); + connect(action, SIGNAL(triggered()), SLOT(emitPowerStateChanged())); + + action = menu->addAction(QIcon(":/components/images/wall_charge.png"), tr("Wall and charging")); + action->setProperty("powerState", WallPowerChargingBattery); + connect(action, SIGNAL(triggered()), SLOT(emitPowerStateChanged())); + + setMenu(menu); +} + +PowerButton::~PowerButton() +{ +} + +void PowerButton::setDisplayedState(PowerState state) +{ + QIcon newIcon; + if (state == UnknownPower) + newIcon = QIcon(":/components/images/unknownpower.png"); + else if (state == BatteryPower) + newIcon = QIcon(":/components/images/batterypower.png"); + else if (state == WallPower) + newIcon = QIcon(":/components/images/wall.png"); + else if (state == WallPowerChargingBattery) + newIcon = QIcon(":/components/images/wall_charge.png"); + setIcon(newIcon); +} + +void PowerButton::emitPowerStateChanged() +{ + QAction *action = qobject_cast<QAction *>(sender()); + if (!action) + return; + PowerState newState = static_cast<PowerState>(action->property("powerState").toInt()); + + setDisplayedState(newState); + emit powerStateChanged(newState); +} diff --git a/library/components/powerbutton.h b/library/components/powerbutton.h new file mode 100644 index 0000000..4e861de --- /dev/null +++ b/library/components/powerbutton.h @@ -0,0 +1,34 @@ +#ifndef POWERBUTTON_H +#define POWERBUTTON_H + +#include "remotecontrolwidget_global.h" + +#include <QtGui/QToolButton> + +class REMOTECONTROLWIDGETSHARED_EXPORT PowerButton : public QToolButton +{ + Q_OBJECT +public: + enum PowerState { + UnknownPower, + BatteryPower, + WallPower, + WallPowerChargingBattery + }; + Q_ENUMS(PowerState) + +public: + explicit PowerButton(QWidget *parent = 0); + virtual ~PowerButton(); + +public slots: + void setDisplayedState(PowerState state); + +signals: + void powerStateChanged(PowerState state) const; + +private slots: + void emitPowerStateChanged(); +}; + +#endif //POWERBUTTON_H diff --git a/library/remotecontrolwidget.cpp b/library/remotecontrolwidget.cpp index 33adc40..3f6a308 100644 --- a/library/remotecontrolwidget.cpp +++ b/library/remotecontrolwidget.cpp @@ -114,6 +114,7 @@ void RemoteControlWidget::addToolBoxPage(const QString &title, const QList<Optio void RemoteControlWidget::addMenuButton(QToolButton *button) { + button->setStyle(mManhattanStyle); mMenuLayout->addWidget(button); } diff --git a/library/remotecontrolwidget.pro b/library/remotecontrolwidget.pro index f3cc3eb..3244dfe 100644 --- a/library/remotecontrolwidget.pro +++ b/library/remotecontrolwidget.pro @@ -15,27 +15,32 @@ SOURCES += \ remotecontrolwidget.cpp \ toolbox.cpp \ optionsitem.cpp \ - locationui.cpp \ style/stylehelper.cpp \ style/styledbar.cpp \ style/styleanimator.cpp \ style/manhattanstyle.cpp \ style/filterlineedit.cpp \ - style/fancylineedit.cpp + style/fancylineedit.cpp \ + components/locationui.cpp \ + components/powerbutton.cpp \ + components/batterybutton.cpp HEADERS += \ remotecontrolwidget.h \ remotecontrolwidget_global.h \ toolbox.h \ optionsitem.h \ - locationui.h \ style/styledbar.h \ style/styleanimator.h \ style/qtcassert.h \ style/manhattanstyle.h \ style/filterlineedit.h \ style/fancylineedit.h \ - style/stylehelper.h + style/stylehelper.h \ + components/locationui.h \ + components/powerbutton.h \ + components/batterybutton.h RESOURCES += \ - style/style.qrc + style/style.qrc \ + components/component.qrc |