diff options
author | Luiz Agostini <luiz.agostini@openbossa.org> | 2009-11-03 21:21:17 -0300 |
---|---|---|
committer | Luiz Agostini <luiz.agostini@openbossa.org> | 2009-11-05 00:42:09 -0300 |
commit | c3dcea71ee47e0166b6245437a906046dcf2f5b7 (patch) | |
tree | 1368c548b9d46298bace02d1843b72e0f61e3857 /weather | |
parent | 122ea22c9cb15da3aed92cd720610d69af80ac7c (diff) |
Weather: city manager.
Signed-off-by: Luiz Agostini <luiz.agostini@openbossa.org>
Diffstat (limited to 'weather')
-rw-r--r-- | weather/addcitytool.cpp | 361 | ||||
-rw-r--r-- | weather/addcitytool.h | 121 | ||||
-rw-r--r-- | weather/citymanager.cpp | 183 | ||||
-rw-r--r-- | weather/citymanager.h | 91 | ||||
-rw-r--r-- | weather/mainview.cpp | 28 | ||||
-rw-r--r-- | weather/mainview.h | 5 | ||||
-rw-r--r-- | weather/weather.pro | 8 |
7 files changed, 789 insertions, 8 deletions
diff --git a/weather/addcitytool.cpp b/weather/addcitytool.cpp new file mode 100644 index 0000000..dd2539f --- /dev/null +++ b/weather/addcitytool.cpp @@ -0,0 +1,361 @@ +#include "addcitytool.h" +#include "settings.h" +#include "forecastprovider.h" + +#include <QPainter> +#include <QInputDialog> +#include <QEvent> +#include <QGraphicsScene> +#include <QGraphicsSceneMouseEvent> +#include <QApplication> +#include <QDebug> + +#define ADD_BACKGROUND (Settings::getScaledPic("background_add_city")) +#define ADD_ERROR_BACKGROUND (Settings::getScaledPic("background_error_adding")) + +#define CLOSE_BUTTON_PIXMAP (Settings::getScaledPic("button_list_delete")) +#define ADD_BUTTON_PIXMAP (Settings::getScaledPic("button_city_send")) +#define BUTTON_LEFT (Settings::scaleWidth(408.0)) + +#define ADD_TEXT_BACKGROUND (Settings::getScaledPic("textfield_add_city")) +#define ADD_TEXT_LEFT (Settings::scaleWidth(38.0)) + +#define ADD_SCREEN_FONT_SIZE (Settings::scaleHeight(40.0)) + +#define CITY_NAME_FONT_SIZE (Settings::scaleHeight(40.0)) + + +static inline qreal getCenterVerticalPos(QGraphicsItem *parent, QGraphicsItem *item) +{ + const qreal top = (parent->boundingRect().height() - item->boundingRect().height()) / 2; + return top - parent->boundingRect().top() - item->boundingRect().top(); +} + +static inline qreal getCenterVerticalPos(QGraphicsItem *item) +{ + return getCenterVerticalPos(item->parentItem(), item); +} + +// AddCityScreen + +AddCityScreen::AddCityScreen(const QRectF &boundingRect, QGraphicsItem *parent) + : QGraphicsItem(parent) + , m_boundingRect(boundingRect) +{ +} + +QRectF AddCityScreen::boundingRect () const +{ + return m_boundingRect; +} + +void AddCityScreen::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *widget) +{ + Q_UNUSED(painter); + Q_UNUSED(opt); + Q_UNUSED(widget); +} + +// AddCityFirstScreen + +AddCityFirstScreen::AddCityFirstScreen(const QRectF &boundingRect, QGraphicsItem *parent) + : AddCityScreen(boundingRect, parent) + , m_textBackground(new QGraphicsPixmapItem(ADD_TEXT_BACKGROUND, this)) + , m_button(new PixmapButton(80.0, ADD_BUTTON_PIXMAP, this)) + , m_proxy(new QGraphicsProxyWidget(this)) + , m_lineEdit(new QLineEdit()) +{ + setFlag(ItemHasNoContents, true); + + m_button->setPos(BUTTON_LEFT, getCenterVerticalPos(m_button)); + m_textBackground->setPos(ADD_TEXT_LEFT, getCenterVerticalPos(m_textBackground)); + + + QFont font; + font.setFamily("Nokia Sans"); + font.setPixelSize(CITY_NAME_FONT_SIZE); + font.setStyleStrategy(QFont::PreferAntialias); + m_lineEdit->setFont(font); + + m_lineEdit->setFrame(false); + m_lineEdit->setTextMargins(0, 0, 0, 0); + m_lineEdit->setAttribute(Qt::WA_NoSystemBackground); + m_lineEdit->setStyleSheet("background: transparent; color:white"); + + QRect rect(0, 0, m_textBackground->pixmap().width(), m_textBackground->pixmap().height()); + rect.adjust(5, 5, -5, -5); + m_lineEdit->setGeometry(rect); + + qDebug() << m_lineEdit->geometry(); + + m_proxy->setWidget(m_lineEdit); + m_proxy->setParentItem(m_textBackground); + m_proxy->setPos(5.0, 5.0); + + m_lineEdit->setFocus(); + + connect(m_button, SIGNAL(clicked()), this, SLOT(buttonClick())); +} + +QVariant AddCityFirstScreen::itemChange(GraphicsItemChange change, const QVariant &value) +{ +// if (change == ItemSceneHasChanged) +// createInputElement(); + return AddCityScreen::itemChange(change, value); +} + +void AddCityFirstScreen::createInputElement() +{ + if (m_proxy) { + delete m_proxy; + m_proxy = 0; + m_lineEdit = 0; + } + + if (!scene()) + return; + + /* + m_lineEdit = new QLineEdit(); + m_proxy = scene()->addWidget(m_lineEdit); + m_proxy->setParentItem(this); + m_proxy->setPos(5.0, 5.0); + m_lineEdit->setText("sao paulo"); + m_lineEdit->setFocus(); + */ + +} + +void AddCityFirstScreen::buttonClick() +{ + if (!m_lineEdit->text().isEmpty()) + emit citySelected(m_lineEdit->text()); +} + +// AddCitySearchScreen + +AddCitySearchScreen::AddCitySearchScreen(const QRectF &boundingRect, + const QString &city, QGraphicsItem *parent) + : AddCityScreen(boundingRect, parent) + , m_city(city) + , m_loading(new Loading(this)) +{ + m_loading->setPos(BUTTON_LEFT, getCenterVerticalPos(m_loading)); + m_loading->start(); + + ForecastProvider::connectToResponseSignal(this, SLOT(forecastResponse(ForecastData))); + ForecastProvider::getForecast(city, this); +} + +void AddCitySearchScreen::forecastResponse(const ForecastData &forecast) +{ + if (forecast.key() == m_city) { + if (forecast.error()) + emit forecastIsNotOk(forecast); + else + emit forecastIsOk(forecast); + } +} + +void AddCitySearchScreen::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *widget) +{ + Q_UNUSED(opt); + Q_UNUSED(widget); + + QBrush brush(Qt::white); + QFont font; + font.setFamily("Nokia Sans"); + font.setPixelSize(ADD_SCREEN_FONT_SIZE); + font.setStyleStrategy(QFont::PreferAntialias); + + QColor color(255, 255, 255, 102); + + QPen pen; + pen.setJoinStyle(Qt::RoundJoin); + + pen.setColor(color); + pen.setBrush(color); + brush.setColor(color); + + QFontMetrics m(font); + + int height = m.height(); + qreal pos = 10.0 + height; + + painter->setBrush(brush); + painter->setPen(pen); + painter->setFont(font); + + QFont fontB(font); + fontB.setBold(true); + QFontMetrics mB(fontB); + + static const QString header("Searching for"); + QString text = mB.elidedText(m_city, Qt::ElideRight, BUTTON_LEFT - 20); + text = "\"" + text + "\""; + + int headerWidth = m.width(header); + int bWidth = mB.width(text); + + + qreal topLeft = (BUTTON_LEFT - qreal(headerWidth)) / 2; + qreal bottomLeft = (BUTTON_LEFT - qreal(bWidth)) / 2; + + painter->drawText(QPointF(topLeft, pos), header); + + pen.setColor(Qt::white); + pen.setBrush(Qt::white); + brush.setColor(Qt::white); + + painter->setBrush(brush); + painter->setPen(pen); + painter->setFont(fontB); + painter->drawText(QPointF(bottomLeft, pos + height), text); +} + +// AddCityErrorScreen + +AddCityErrorScreen::AddCityErrorScreen(const QString &city, QGraphicsItem *parent) + : QGraphicsPixmapItem(ADD_ERROR_BACKGROUND, parent) + , m_button(new PixmapButton(80.0, CLOSE_BUTTON_PIXMAP, this)) + , m_city(city) +{ + m_button->setPos(BUTTON_LEFT, getCenterVerticalPos(m_button)); + connect(m_button, SIGNAL(clicked()), this, SIGNAL(closed())); +} + +void AddCityErrorScreen::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *widget) +{ + Q_UNUSED(opt); + Q_UNUSED(widget); + + QGraphicsPixmapItem::paint(painter, opt, widget); + + QBrush brush(Qt::white); + QFont font; + font.setFamily("Nokia Sans"); + font.setPixelSize(ADD_SCREEN_FONT_SIZE); + font.setStyleStrategy(QFont::PreferAntialias); + + QColor color(255, 255, 255, 102); + + QPen pen; + + pen.setColor(color); + pen.setBrush(color); + pen.setJoinStyle(Qt::RoundJoin); + + brush.setColor(color); + + QFontMetrics m(font); + + int height = m.height(); // + m.descent(); + qreal pos = 10.0 + height; + + painter->setBrush(brush); + painter->setPen(pen); + painter->setFont(font); + + QFont fontB(font); + fontB.setBold(true); + QFontMetrics mB(fontB); + + static const QString header("The city"); + static const QString footer("wasn't found"); + QString text = mB.elidedText(m_city, Qt::ElideRight, Settings::scaleWidth(200.0)); + text = "\"" + text + "\""; + + int margin = 5; + int headerWidth = m.width(header); + int bWidth = mB.width(text) + margin; + int footerWidth = m.width(footer); + + + qreal topLeft = (BUTTON_LEFT - qreal(headerWidth + bWidth)) / 2; + int bottomLeft = ((headerWidth + bWidth - footerWidth) >> 1) + topLeft; + + qDebug() << bWidth; + + painter->drawText(QPointF(topLeft, pos), header); + painter->drawText(QPointF(bottomLeft, pos + height), footer); + + pen.setColor(Qt::white); + pen.setBrush(Qt::white); + brush.setColor(Qt::white); + + painter->setBrush(brush); + painter->setPen(pen); + painter->setFont(fontB); + painter->drawText(QPointF(topLeft + headerWidth + margin, pos), text); +} + +// AddCityTool + +AddCityTool::AddCityTool(QGraphicsItem *parent) + : QGraphicsPixmapItem(ADD_BACKGROUND, parent) + , m_screen(createFirstScreen()) +{ +} + +AddCityTool::~AddCityTool() +{ + m_screen->deleteLater(); +} + +void AddCityTool::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_UNUSED(event); +} + +AddCityFirstScreen *AddCityTool::createFirstScreen() +{ + AddCityFirstScreen *result = new AddCityFirstScreen(boundingRect(), this); + connect(result, SIGNAL(citySelected(QString)), this, SLOT(citySelected(QString))); + result->setPos(0.0, 0.0); + return result; +} + +AddCitySearchScreen *AddCityTool::createSearchScreen(const QString &city) +{ + AddCitySearchScreen *result = new AddCitySearchScreen(boundingRect(), city, this); + connect(result, SIGNAL(forecastIsNotOk(ForecastData)), + this, SLOT(forecastIsNotOk(ForecastData))); + connect(result, SIGNAL(forecastIsOk(ForecastData)), this, SLOT(forecastIsOk(ForecastData))); + result->setPos(0.0, 0.0); + return result; +} + +AddCityErrorScreen *AddCityTool::createErrorScreen(const QString &city) +{ + AddCityErrorScreen *result = new AddCityErrorScreen(city, this); + connect(result, SIGNAL(closed()), this, SLOT(errorScreenClosed())); + result->setPos(0.0, 0.0); + return result; +} + +void AddCityTool::replaceScreen(QObject *screen) +{ + m_screen->deleteLater(); + m_screen = screen; +} + +void AddCityTool::errorScreenClosed() +{ + replaceScreen(createFirstScreen()); +} + +void AddCityTool::forecastIsOk(const ForecastData &forecast) +{ + emit newForecast(forecast); + replaceScreen(createFirstScreen()); +} + +void AddCityTool::forecastIsNotOk(const ForecastData &forecast) +{ + replaceScreen(createErrorScreen(forecast.key())); +} + +void AddCityTool::citySelected(const QString &city) +{ + replaceScreen(createSearchScreen(city)); +} diff --git a/weather/addcitytool.h b/weather/addcitytool.h new file mode 100644 index 0000000..788bec7 --- /dev/null +++ b/weather/addcitytool.h @@ -0,0 +1,121 @@ +#ifndef ADDCITYTOOL_H +#define ADDCITYTOOL_H + +#include <QGraphicsItem> +#include <QGraphicsPixmapItem> +#include <QBasicTimer> +#include <QGraphicsSimpleTextItem> +#include <QPen> +#include <QBrush> +#include <QFont> + #include <QGraphicsProxyWidget> +#include <QLineEdit> + +#include "pixmapbutton.h" +#include "forecastprovider.h" +#include "loading.h" +#include "forecastdata.h" + +class AddCityScreen : public QGraphicsItem +{ +public: + AddCityScreen(const QRectF &boundingRect, QGraphicsItem *parent = 0); + + QRectF boundingRect () const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + +private: + const QRectF m_boundingRect; +}; + +class AddCityFirstScreen : public QObject, public AddCityScreen +{ + Q_OBJECT +public: + AddCityFirstScreen(const QRectF &boundingRect, QGraphicsItem *parent = 0); + +signals: + void citySelected(const QString &city); + +protected: + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + +private: + QGraphicsPixmapItem * const m_textBackground; + PixmapButton * const m_button; +// QGraphicsSimpleTextItem * const m_textItem; + QString m_text; + QGraphicsProxyWidget *m_proxy; + QLineEdit *m_lineEdit; + + void createInputElement(); + + +private slots: + void buttonClick(); +}; + +class AddCitySearchScreen : public QObject , public AddCityScreen +{ + Q_OBJECT +public: + AddCitySearchScreen(const QRectF &boundingRect, const QString &city, QGraphicsItem *parent = 0); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + +signals: + void forecastIsOk(const ForecastData &forecast); + void forecastIsNotOk(const ForecastData &forecast); + +private: + const QString m_city; + Loading *m_loading; + +private slots: + void forecastResponse(const ForecastData &forecast); +}; + +class AddCityErrorScreen : public QObject, public QGraphicsPixmapItem +{ + Q_OBJECT +public: + AddCityErrorScreen(const QString &city, QGraphicsItem *parent = 0); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + +signals: + void closed(); + +private: + PixmapButton * const m_button; + const QString m_city; +}; + +class AddCityTool : public QObject, public QGraphicsPixmapItem +{ + Q_OBJECT +public: + AddCityTool(QGraphicsItem *parent = 0); + ~AddCityTool(); + +private: + QObject *m_screen; + + AddCityFirstScreen *createFirstScreen(); + AddCitySearchScreen *createSearchScreen(const QString &city); + AddCityErrorScreen *createErrorScreen(const QString &city); + void replaceScreen(QObject *screen); + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event); + +signals: + void newForecast(const ForecastData &forecast); + +private slots: + void errorScreenClosed(); + void forecastIsOk(const ForecastData &forecast); + void forecastIsNotOk(const ForecastData &forecast); + void citySelected(const QString &city); + +}; + +#endif // ADDCITYTOOL_H diff --git a/weather/citymanager.cpp b/weather/citymanager.cpp new file mode 100644 index 0000000..6e5e67a --- /dev/null +++ b/weather/citymanager.cpp @@ -0,0 +1,183 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: openBossa - INdT (renato.chencarek@openbossa.org) +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** the openBossa stream from INdT (renato.chencarek@openbossa.org). +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "citymanager.h" +#include "settings.h" + +#include <QGraphicsSceneMouseEvent> +#include <QDebug> + +#define ITEM_BACKGROUND (Settings::getScaledPic("list_item_bg")) +#define SELECTED_ITEM_BACKGROUND (Settings::getScaledPic("list_item_selected_bg")) + +#define ITEM_BUTTON_PIXMAP (Settings::getScaledPic("button_list_delete")) +#define ITEM_BUTTON_LEFT (Settings::scaleWidth(406.0)) + +#define ITEM_CHECK_PIXMAP (Settings::getScaledPic("list_check")) +#define ITEM_CHECK_LEFT (Settings::scaleWidth(20.0)) + +static inline qreal getCenterVerticalPos(QGraphicsItem *parent, QGraphicsItem *item) +{ + const qreal top = (parent->boundingRect().height() - item->boundingRect().height()) / 2; + return top - parent->boundingRect().top() - item->boundingRect().top(); +} + +static inline qreal getCenterVerticalPos(QGraphicsItem *item) +{ + return getCenterVerticalPos(item->parentItem(), item); +} + +static inline qreal getBottomVerticalPos(qreal &bottom, QGraphicsItem *item) +{ + const qreal result = bottom - item->boundingRect().bottom(); + bottom -= item->boundingRect().height(); + return result; +} + +// CityListElement + +CityListElement::CityListElement(bool checked, QGraphicsItem *parent) + : QGraphicsPixmapItem(ITEM_BACKGROUND, parent) + , m_check(checked ? new QGraphicsPixmapItem(ITEM_CHECK_PIXMAP, this) : 0) + , m_button(new QGraphicsPixmapItem(ITEM_BUTTON_PIXMAP, this)) +{ + m_button->setPos(ITEM_BUTTON_LEFT, getCenterVerticalPos(m_button)); + if (m_check) + m_check->setPos(ITEM_CHECK_LEFT, getCenterVerticalPos(m_check)); +} + +// CityManagerContent + +struct CityInfo +{ + const char * name; + const int lower; + const int temp; + const int upper; + const bool night; +}; + +static const CityInfo cityNames[Forecast::UnknownForecast] = { + {"Araxa", -7, -4, -1, true}, // MostlyCloudy + {"Belo Horizonte", 18, 22, 27, false}, // Cloudy + {"Recife", 25, 31, 34, true}, // MostlySunny + {"Ipojuca", 22, 29, 36, false}, // PartlyCloudy + {"Fortaleza", 31, 34, 36, true}, // Sunny + {"Sao Paulo", -1, 10, 12, false}, // Flurries + {"Uberlandia", -26, -23, -20, false}, // Fog + {"Governador Valadares", 3, 17, 18, true}, // Haze + {"Brasilia", 22, 25, 30, false}, // Sand + {"Florianopolis", 0, 8, 10, true}, // Dust + {"Gravata", -10, -2, 3, false}, // Icy + {"Maceio", 22, 35, 38, true}, // Sleet + {"Porto Alegre", -8, -6, -4, true}, // ChanceOfSleet + {"Batatais", -20, -12, -10, false}, // Snow + {"Ribeirao Preto", -20, -17, 0, true}, // ChanceOfSnow + {"Campinas", 1, 4, 10, false}, // Mist + {"Campo belo", 12, 19, 21, true}, // Rain + {"Sertaozinho", 10, 15, 17, true}, // ChanceOfRain + {"Pirassununga", -15, -12, 2, false}, // Storm + {"Goiania", 7, 13, 18, true}, // ChanceOfStorm + {"Manaus", 35, 41, 44, false}, // Thunderstorm + {"Belem", -14, -13, -5, true} // ChanceOfThunderstorm +}; + +CityManagerContent::CityManagerContent(QGraphicsItem *parent) + : QGraphicsItem(parent) + , m_boundingRect(QPointF(0.0, 0.0), Settings::windowSize()) +{ + setFlag(ItemHasNoContents); + + qreal bottom = m_boundingRect.bottom(); + m_addTool = new AddCityTool(this); + m_addTool->setPos(0.0, getBottomVerticalPos(bottom, m_addTool)); + m_addTool->setZValue(10.0); + + m_list = new CityList(this); + m_list->setPos(0.0, getBottomVerticalPos(bottom, m_list) + m_list->initialTop()); + m_list->setZValue(0.0); + + connect(m_addTool, SIGNAL(newForecast(ForecastData)), m_list, SLOT(addForecast(ForecastData))); + + + for (int i = 0; i < Forecast::UnknownForecast; ++i) + m_list->addForecast(ForecastData(false, Forecast::ForecastType(i), + i % 2, cityNames[i].name,cityNames[i].name, + cityNames[i].lower, cityNames[i].temp, cityNames[i].upper)); + +} + +QRectF CityManagerContent::boundingRect () const +{ + return m_boundingRect; +} + +void CityManagerContent::paint(QPainter *painter, + const QStyleOptionGraphicsItem *opt, QWidget *widget) +{ + Q_UNUSED(painter); + Q_UNUSED(opt); + Q_UNUSED(widget); +} + +// CityManager + +CityManager::CityManager(QGraphicsItem *parent) + : QGraphicsItem(parent) + , m_boundingRect(QPointF(0.0, 0.0), Settings::windowSize()) +{ + m_content = new CityManagerContent(this); + m_content->setPos(0.0, 0.0); +} + +void CityManager::newCitySelected(const QString &city) +{ + qDebug() << "new city:" << city; +} + +QRectF CityManager::boundingRect () const +{ + return m_boundingRect; +} + +void CityManager::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *widget) +{ + Q_UNUSED(painter); + Q_UNUSED(opt); + Q_UNUSED(widget); +} + +void CityManager::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + qDebug() << "manager clicked"; + event->accept(); + emit terminated(); +} diff --git a/weather/citymanager.h b/weather/citymanager.h new file mode 100644 index 0000000..1e926b4 --- /dev/null +++ b/weather/citymanager.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: openBossa - INdT (renato.chencarek@openbossa.org) +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** the openBossa stream from INdT (renato.chencarek@openbossa.org). +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CITYMANAGER_H +#define CITYMANAGER_H + +#include <QGraphicsItem> +#include <QGraphicsPixmapItem> + +#include "addcitytool.h" +#include "citylist.h" + +class CityListElement : public QGraphicsPixmapItem +{ +public: + CityListElement(bool checked, QGraphicsItem *parent = 0); + +private: + QGraphicsPixmapItem *m_check; + QGraphicsPixmapItem *m_button; +}; + +class CityManagerContent : public QObject, public QGraphicsItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsItem) +public: + CityManagerContent(QGraphicsItem *parent = 0); + + QRectF boundingRect () const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + +private: + const QRectF m_boundingRect; + AddCityTool *m_addTool; + CityList *m_list; +}; + +class CityManager : public QObject, public QGraphicsItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsItem) +public: + CityManager(QGraphicsItem *parent = 0); + + QRectF boundingRect () const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event); + +signals: + void terminated(); + +private: + const QRectF m_boundingRect; + CityManagerContent *m_content; + +private slots: + void newCitySelected(const QString &city); +}; + +#endif // CITYMANAGER_H diff --git a/weather/mainview.cpp b/weather/mainview.cpp index 48780b0..8191663 100644 --- a/weather/mainview.cpp +++ b/weather/mainview.cpp @@ -55,6 +55,7 @@ MainView::MainView(QWidget *parent) , m_carroussel(0) , m_loading(0) , m_bootManager(0) + , m_manager(0) { setScene(&m_scene); setFrameShape(QFrame::NoFrame); @@ -101,16 +102,33 @@ void MainView::showCarroussel() { QList<ForecastData> data = m_bootManager->data(); m_carroussel = new CityCarroussel(); + connect(m_carroussel, SIGNAL(cityNameClicked()), this, SLOT(cityNameClicked())); foreach (const ForecastData &forecast, data) m_carroussel->add(new MyCityForecastData(forecast)); m_carroussel->setPos(0.0, 0.0); + m_carroussel->setZValue(0.0); m_scene.addItem(m_carroussel); } -void MainView::keyPressEvent(QKeyEvent* event) +void MainView::cityNameClicked() { - if (event->key() == Qt::Key_Left) - emit moveLeft(); - if (event->key() == Qt::Key_Right) - emit moveRight(); + if (m_manager) + return; + qDebug() << "city name clicked"; + m_carroussel->setActive(false); + m_manager = new CityManager(); + m_manager->setPos(0.0, 0.0); + m_manager->setZValue(1.0); + m_scene.addItem(m_manager); + connect(m_manager, SIGNAL(terminated()), this, SLOT(closeCityManager())); +} + +void MainView::closeCityManager() +{ + if (m_manager) { + qDebug() << "close manager"; + m_manager->deleteLater(); + m_manager = 0; + m_carroussel->setActive(true); + } } diff --git a/weather/mainview.h b/weather/mainview.h index f60aa6e..67459a3 100644 --- a/weather/mainview.h +++ b/weather/mainview.h @@ -41,6 +41,7 @@ #include "forecastdata.h" #include "bootmanager.h" #include "loading.h" +#include "citymanager.h" class MainView: public QGraphicsView { @@ -49,13 +50,14 @@ class MainView: public QGraphicsView public: MainView(QWidget *parent = 0); ~MainView(); - void keyPressEvent(QKeyEvent* event); signals: void moveLeft(); void moveRight(); private slots: + void cityNameClicked(); + void closeCityManager(); void pixmapLoaderIsIdle(); void bootEnd(); @@ -65,6 +67,7 @@ private: CityCarroussel *m_carroussel; Loading *m_loading; BootManager *m_bootManager; + CityManager *m_manager; void showCarroussel(); }; diff --git a/weather/weather.pro b/weather/weather.pro index deb28bd..1af84b2 100644 --- a/weather/weather.pro +++ b/weather/weather.pro @@ -47,7 +47,9 @@ HEADERS += mainview.h \ pixmapbutton.h \ scrollbar.h \ contentlist.h \ - citylist.h + citylist.h \ + citymanager.h \ + addcitytool.h SOURCES += mainview.cpp \ main.cpp \ settings.cpp \ @@ -67,4 +69,6 @@ SOURCES += mainview.cpp \ pixmapbutton.cpp \ scrollbar.cpp \ contentlist.cpp \ - citylist.cpp + citylist.cpp \ + citymanager.cpp \ + addcitytool.cpp |