e73354431347126a4b24b1d3a1c04b40a8fb0701
[medard] / src / forecastwidget.cpp
1 /*
2  *  Medard for Maemo.
3  *  Copyright (C) 2011 Roman Moravcik
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include <QtGui>
21
22 #include "forecastwidget.h"
23
24 #ifdef Q_WS_MAEMO_6
25 ForecastWidget::ForecastWidget(QGraphicsWidget *parent) : QGraphicsWidget(parent)
26 #else
27 ForecastWidget::ForecastWidget(QWidget *parent) : QWidget(parent)
28 #endif
29 {
30     m_filename.clear();
31     m_error = false;
32 }
33
34 void ForecastWidget::setImage(const QString &filename)
35 {
36     m_filename = filename;
37     m_error = false;
38     update();
39 }
40
41 void ForecastWidget::clearImage(bool error)
42 {
43     m_filename.clear();
44     m_error = error;
45     update();
46 }
47
48 #ifdef Q_WS_MAEMO_6
49 void ForecastWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
50 {
51     Q_UNUSED(widget);
52     Q_UNUSED(option);
53
54     painter->setRenderHint(QPainter::Antialiasing);
55
56     QRect widgetArea(rect().x(), rect().y(), rect().width(), 369);
57
58     painter->setPen(QColor(0, 0, 0));
59     painter->setBrush(QColor(255, 255, 255));
60     painter->drawRect(widgetArea);
61
62     if (m_error) {
63         painter->drawText(widgetArea, Qt::AlignCenter, tr("Download failed!"));
64     } else {
65         if (!m_filename.isEmpty()) {
66             QImage image(m_filename);
67             painter->drawImage(widgetArea, image);
68         } else {
69             painter->drawText(widgetArea, Qt::AlignCenter, tr("Downloading image..."));
70         }
71     }
72 }
73 #else
74 void ForecastWidget::paintEvent(QPaintEvent * /* event */)
75 {
76     QPainter painter(this);
77     painter.setRenderHint(QPainter::Antialiasing);
78
79     QRect widgetArea(rect().x(), rect().y(), rect().width(), 408);
80
81     painter.setPen(QColor(0, 0, 0));
82     painter.setBrush(QColor(255, 255, 255));
83     painter.drawRect(widgetArea);
84
85     if (m_error) {
86         painter.drawText(widgetArea, Qt::AlignCenter, tr("Download failed!"));
87     } else {
88         if (!m_filename.isEmpty()) {
89             QImage image(m_filename);
90             painter.drawImage(widgetArea, image);
91         } else {
92             painter.drawText(widgetArea, Qt::AlignCenter, tr("Downloading image..."));
93         }
94     }
95 }
96 #endif