summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuiz Agostini <luiz.agostini@openbossa.org>2009-11-13 15:19:27 -0300
committerLuiz Agostini <luiz.agostini@openbossa.org>2009-11-13 15:42:02 -0300
commit8d70e9e9fdf8b9870df0f720d6094b3db04f7c40 (patch)
tree56bab7fdfda1148aa0babf213c28ee3b22a7b8bd
parent112cb2a1503cdef17b09706822e0ec57096897ef (diff)
Weather: "Add a city" text.
Signed-off-by: Luiz Agostini <luiz.agostini@openbossa.org>
-rw-r--r--weather/addcitytool.cpp42
-rw-r--r--weather/addcitytool.h19
2 files changed, 57 insertions, 4 deletions
diff --git a/weather/addcitytool.cpp b/weather/addcitytool.cpp
index 4d0e4ed..7d8870c 100644
--- a/weather/addcitytool.cpp
+++ b/weather/addcitytool.cpp
@@ -58,6 +58,44 @@ void AddCityScreen::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
Q_UNUSED(widget);
}
+//
+
+#define ADD_A_CITY_TEXT "Add a city"
+
+AddCityLineEdit::AddCityLineEdit(QWidget *parent)
+ : QLineEdit(parent)
+ , m_clean(true)
+{
+ editReset();
+ connect(this, SIGNAL(textEdited(QString)), this, SLOT(textEditedSlot(QString)));
+}
+
+void AddCityLineEdit::editReset()
+{
+ m_clean = true;
+ setText(ADD_A_CITY_TEXT);
+}
+
+void AddCityLineEdit::focusOutEvent(QFocusEvent *event)
+{
+ if (m_clean)
+ setText(ADD_A_CITY_TEXT);
+ QLineEdit::focusOutEvent(event);
+}
+
+void AddCityLineEdit::focusInEvent(QFocusEvent *event)
+{
+ if (m_clean)
+ setText("");
+ QLineEdit::focusInEvent(event);
+}
+
+void AddCityLineEdit::textEditedSlot(const QString & text)
+{
+ Q_UNUSED(text);
+ m_clean = false;
+}
+
// AddCityFirstScreen
AddCityFirstScreen::AddCityFirstScreen(const QRectF &boundingRect, QGraphicsItem *parent)
@@ -65,7 +103,7 @@ AddCityFirstScreen::AddCityFirstScreen(const QRectF &boundingRect, QGraphicsItem
, 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())
+ , m_lineEdit(new AddCityLineEdit())
{
setFlag(ItemHasNoContents, true);
@@ -99,7 +137,7 @@ AddCityFirstScreen::AddCityFirstScreen(const QRectF &boundingRect, QGraphicsItem
void AddCityFirstScreen::clean()
{
- m_lineEdit->setText("");
+ m_lineEdit->editReset();
}
void AddCityFirstScreen::buttonClick()
diff --git a/weather/addcitytool.h b/weather/addcitytool.h
index bc313b0..f0f6b1f 100644
--- a/weather/addcitytool.h
+++ b/weather/addcitytool.h
@@ -29,6 +29,22 @@ private:
const QRectF m_boundingRect;
};
+class AddCityLineEdit : public QLineEdit
+{
+ Q_OBJECT
+public:
+ AddCityLineEdit(QWidget *parent = 0);
+ void editReset();
+protected:
+ void focusInEvent(QFocusEvent *event);
+ void focusOutEvent(QFocusEvent *event);
+private:
+ bool m_clean;
+private slots:
+ void textEditedSlot(const QString & text);
+};
+
+
class AddCityFirstScreen : public QObject, public AddCityScreen
{
Q_OBJECT
@@ -44,7 +60,7 @@ private:
PixmapButton * const m_button;
QString m_text;
QGraphicsProxyWidget *m_proxy;
- QLineEdit *m_lineEdit;
+ AddCityLineEdit *m_lineEdit;
private slots:
void buttonClick();
@@ -98,7 +114,6 @@ private:
void paintNotFound(QPainter *painter);
void paintAlreadyInList(QPainter *painter);
};
-
class AddCityTool : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT