- played around with transparency
authorDavid Solbach <d@vidsolbach.de>
Thu, 14 Oct 2010 22:54:52 +0000 (00:54 +0200)
committerDavid Solbach <d@vidsolbach.de>
Thu, 14 Oct 2010 22:54:52 +0000 (00:54 +0200)
- hide table during update
- created an abstract class as backend interface

13 files changed:
BundesligaWidget.pro
src/backendkicker.cpp
src/backendkicker.h
src/main.cpp
src/mainwidget.cpp
src/mainwidget.h
src/matchdaybackend.cpp [new file with mode: 0644]
src/matchdaybackend.h [new file with mode: 0644]
src/matchdaymodel.cpp
src/matchdaymodel.h
src/scoretable.cpp
src/scoretable.h
src/settingsdialog.cpp

index 0d5dfcf..b367705 100644 (file)
@@ -11,7 +11,8 @@ HEADERS += \
     src/mainwidget.h \
     src/matchdaymodel.h \
     src/scoretable.h \
-    src/settingsdialog.h
+    src/settingsdialog.h \
+    src/matchdaybackend.h
 
 SOURCES += \
     src/main.cpp \
@@ -20,7 +21,8 @@ SOURCES += \
     src/mainwidget.cpp \
     src/matchdaymodel.cpp \
     src/scoretable.cpp \
-    src/settingsdialog.cpp
+    src/settingsdialog.cpp \
+    src/matchdaybackend.cpp
 
 RESOURCES += \
     resources.qrc
index e4f0dd0..d2914aa 100644 (file)
@@ -6,14 +6,15 @@
 #include <QStringList>
 #include <QDateTime>
 #include <QSettings>
+#include <QApplication>
 
 #include "backendkicker.h"
 
 BackendKicker::BackendKicker(QObject *parent) :
-    QObject(parent)
+    MatchDayBackend(parent)
 {
-    QSettings settings("David Solbach", "BuliScores");
-    this->setLeague(settings.value("League", "1. Bundesliga").toString());
+    QSettings settings(qApp->organizationName(), qApp->applicationName());
+    this->selectLeague(settings.value("League", "1. Bundesliga").toString());
 
     this->update();
 }
@@ -84,9 +85,8 @@ static QString parseTeam(QString teamhtml)
     return team;
 }
 
-static int parseScore(Match* match, QString scorehtml)
+static void parseScore(Match* match, QString scorehtml)
 {
-    int         score = -1;
     QStringList tokens;
 
     qDebug() << "parseScore in: " << scorehtml;
@@ -105,7 +105,7 @@ static int parseScore(Match* match, QString scorehtml)
             match->setState(Match::HalfTime);
         } else {
             // no color tag and no "-" -> game is finished
-            match->setScore(tokens.at(1).toInt(), tokens.at(3).toInt());
+            match->setScore(tokens.at(1).toInt(), tokens.at(2).toInt());
             match->setState(Match::Finished);
         }
     } else {
@@ -122,9 +122,9 @@ static int parseScore(Match* match, QString scorehtml)
         }
 
     }
-    qDebug() << "match out: " << match;
-
-    return score;
+    qDebug() << "match state: " << match->state();
+    qDebug() << "match home: " << match->homeScore();
+    qDebug() << "match away: " << match->awayScore();
 }
 
 void BackendKicker::parsePage (QString htmlstr)
@@ -180,25 +180,29 @@ void BackendKicker::parsePage (QString htmlstr)
     }
 }
 
-void BackendKicker::setLeague(QString league)
+bool BackendKicker::selectLeague(QString league)
 {
+    bool leagueIsSupported = true;
+
     if (league == "1. Bundesliga") {
         m_URL = "http://www.kicker.de/news/fussball/bundesliga/spieltag/1-bundesliga/2010-11/spieltag.html";
     } else if (league == "2. Bundesliga") {
         m_URL = "http://www.kicker.de/news/fussball/bundesliga/spieltag/2-bundesliga/2010-11/spieltag.html";
     } else if (league == "tipp3 Bundesliga") {
         m_URL = "http://www.kicker.de/news/fussball/intligen/oesterreich/tipp3-bundesliga/2010-11/spieltag.html";
+    } else {
+        leagueIsSupported = false;
     }
 
     // delete last data
-    this->m_matchlist.clear();
-    emit matchListChanged();
+    return leagueIsSupported;
 }
 
 void BackendKicker::update()
 {
-    //QString URL = "file:///home/david/Projects/git-buliscores/testdata/spieltag.html";
+    emit updateStarted();
 
+    //QString URL = "file:///home/david/Projects/git-buliscores/testdata/spieltag.html";
     QNetworkAccessManager *manager = new QNetworkAccessManager(this);
     connect(manager, SIGNAL(finished(QNetworkReply*)),
             this, SLOT(dlndFinished(QNetworkReply*)));
@@ -216,7 +220,10 @@ void BackendKicker::dlndFinished(QNetworkReply *reply)
         qDebug() << "dlnd failed: error: " << reply->error();
     }
 
+    this->m_matchlist.clear();
+
     rawdata = reply->readAll();
     parsePage(rawdata);
+
     emit matchListChanged();
 }
index 34598dd..679fef8 100644 (file)
@@ -4,9 +4,9 @@
 #include <QObject>
 #include <QNetworkReply>
 
-#include "match.h"
+#include "matchdaybackend.h"
 
-class BackendKicker : public QObject
+class BackendKicker : public MatchDayBackend
 {
     Q_OBJECT
 private:
@@ -21,10 +21,11 @@ public:
     Match*        getMatch(QString hometeam, QString awayteam, QDateTime date);
     QList<Match*> matchList();
 
-    void          setLeague(QString league);
+    bool          selectLeague(QString league);
 
 signals:
     void matchListChanged(void);
+    void updateStarted(void);
 
 private slots:
     void dlndFinished(QNetworkReply *reply);
index 9adfbef..655cb33 100644 (file)
@@ -53,6 +53,9 @@ int main(int argc, char *argv[])
     QApplication app(argc, argv);
     MainWidget mw;
 
+    app.setApplicationName("Buli Scores");
+    app.setApplicationVersion("0.1");
+    app.setOrganizationName("David Solbach");
     mw.resize(400,250);
 
     QMaemo5HomescreenAdaptor *adaptor = new QMaemo5HomescreenAdaptor(&mw);
index 3c2b110..f25f7e1 100644 (file)
@@ -1,47 +1,78 @@
 #include <QSettings>
 #include <QMouseEvent>
-
+#include <QApplication>
 
 #include "mainwidget.h"
+#include "backendkicker.h"
 #include "matchdaymodel.h"
 #include "settingsdialog.h"
 
 MainWidget::MainWidget(QWidget *parent) :
     QWidget(parent),
-    m_datamodel(new MatchDayModel(this)),
+    m_backend(new BackendKicker(this)),
+    m_datamodel(new MatchDayModel(this, m_backend)),
     m_scoretbl(new ScoreTable(m_datamodel)),
-    m_settingsdlg(new SettingsDialog(this))
+    m_settingsdlg(new SettingsDialog(this)),
+    m_settings(qApp->organizationName(), qApp->applicationName())
 {
     QFont f;
     QPalette palette;
 
-    f.setPixelSize(14);
-    palette.setColor(QPalette::Window, QColor(100, 100, 100, 127));
-
-    m_statuslbl.setAttribute(Qt::WA_TransparentForMouseEvents);
+    f.setPixelSize(40);
+    palette.setColor(QPalette::Background, QColor(0, 0, 0, 127));
+    palette.setColor(QPalette::Foreground, QColor(255, 255, 255, 127));
+    m_statuslbl.hide();
     m_statuslbl.setPalette(palette);
+    m_statuslbl.setAttribute(Qt::WA_TransparentForMouseEvents);
+    m_statuslbl.setAutoFillBackground(true);
+    m_statuslbl.setBackgroundRole(QPalette::Background);
+    m_statuslbl.setAlignment(Qt::AlignCenter);
+
     m_statuslbl.setFont(f);
-    m_statuslbl.setText(tr("Last Update: Never"));
 
     this->setAttribute(Qt::WA_TranslucentBackground);
 
-
     this->setLayout(&m_layout);
 
     m_layout.addWidget(&m_statuslbl);
     m_layout.addWidget(m_scoretbl);
 
-    this->setAutoFillBackground(true);
-
     connect(m_settingsdlg, SIGNAL(accepted()),
-            m_datamodel, SLOT(update()));
+            this, SLOT(update()));
+
+    connect(m_backend, SIGNAL(matchListChanged()),
+            this, SLOT(onBackendUpdateFinished()));
+
+    connect(m_backend, SIGNAL(updateStarted()),
+            this, SLOT(onBackendUpdateStarted()));
 }
 
+// only needed for testing on desktop
 void MainWidget::mousePressEvent(QMouseEvent* event)
 {
-    this->showSettingsDialog();
+    if (event->button() == Qt::RightButton) {
+        this->showSettingsDialog();
+    }
 }
 
+void MainWidget::update(void)
+{
+    m_backend->selectLeague(m_settings.value("League", "1. Bundesliga").toString());
+    m_backend->update();
+}
+
+void MainWidget::onBackendUpdateStarted()
+{
+    m_statuslbl.setText(tr("Updating..."));
+    m_statuslbl.show();
+    m_scoretbl->hide();
+}
+
+void MainWidget::onBackendUpdateFinished()
+{
+    m_scoretbl->show();
+    m_statuslbl.hide();
+}
 
 void MainWidget::showSettingsDialog()
 {
index 5049189..1b68c1e 100644 (file)
@@ -5,6 +5,7 @@
 #include <QVBoxLayout>
 #include <QLabel>
 
+#include "matchdaybackend.h"
 #include "scoretable.h"
 #include "settingsdialog.h"
 
 class MainWidget : public QWidget
 {
     Q_OBJECT
-private:
-    MatchDayModel*  m_datamodel;
-    ScoreTable*     m_scoretbl;
-    SettingsDialog* m_settingsdlg;
-
-    QVBoxLayout m_layout;
-    QLabel      m_statuslbl;
-
 public:
     explicit MainWidget(QWidget *parent = 0);
 
     void mousePressEvent(QMouseEvent* event);
 
-signals:
-
 public slots:
     void showSettingsDialog();
 
+protected slots:
+    void onBackendUpdateStarted();
+    void onBackendUpdateFinished(void);
+
+private:
+    MatchDayBackend* m_backend;
+    MatchDayModel*   m_datamodel;
+    ScoreTable*      m_scoretbl;
+    SettingsDialog*  m_settingsdlg;
+    QSettings        m_settings;
+
+    QVBoxLayout m_layout;
+    QLabel      m_statuslbl;
+
+private slots:
+    void update(void);
+
 };
 
 #endif // MAINWIDGET_H
diff --git a/src/matchdaybackend.cpp b/src/matchdaybackend.cpp
new file mode 100644 (file)
index 0000000..9d70119
--- /dev/null
@@ -0,0 +1,11 @@
+#include <QObject>
+
+#include "match.h"
+#include "matchdaybackend.h"
+
+
+MatchDayBackend::MatchDayBackend(QObject *parent) : QObject(parent)
+{
+
+}
+
diff --git a/src/matchdaybackend.h b/src/matchdaybackend.h
new file mode 100644 (file)
index 0000000..51a4a11
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef MATCHDAYBACKEND_H
+#define MATCHDAYBACKEND_H
+
+#include <QObject>
+
+#include "match.h"
+
+/*
+ * Pure virtual class serving as a common interface for backends
+ * providing MatchDay Data
+ */
+class MatchDayBackend : public QObject
+{
+    Q_OBJECT
+public:
+    explicit MatchDayBackend(QObject *parent = 0);
+
+public:
+
+    virtual Match* getMatch(QString hometeam, QString awayteam, QDateTime date) = 0;
+    virtual QList<Match*> matchList() = 0;
+
+    virtual bool selectLeague(QString league) = 0;
+    virtual bool setAutomaticUpdate(bool) = 0;
+
+signals:
+    void matchListChanged(void);
+    void updateStarted(void);
+
+public slots:
+    virtual void update() = 0;
+};
+
+#endif // MATCHDAYBACKEND_H
index c280271..901a5d2 100644 (file)
@@ -1,24 +1,24 @@
 #include <QDebug>
+#include <QBrush>
 #include <QColor>
 #include <QFontMetrics>
 #include <QFont>
 #include <QIcon>
 #include <QSettings>
+#include <QApplication>
 
 #include "matchdaymodel.h"
 #include "match.h"
 
-MatchDayModel::MatchDayModel(QObject *parent) :
+MatchDayModel::MatchDayModel(QObject *parent, MatchDayBackend *backend) :
     QAbstractTableModel(parent),
     m_lastRowCount(0),
-    m_settings("David Solbach", "BuliScores")
+    m_settings(qApp->organizationName(), qApp->applicationName())
 {
-
-    m_backend = new BackendKicker(this);
+    m_backend = backend;
 
     connect(m_backend, SIGNAL(matchListChanged()),
             this, SLOT(onMatchListChanged()));
-
 }
 
 int MatchDayModel::rowCount(const QModelIndex&) const
@@ -48,6 +48,9 @@ QVariant MatchDayModel::data(const QModelIndex& index, int role) const
 
     // DisplayRole
     switch (role) {
+    case Qt::BackgroundRole:
+        return QBrush(QColor(0, 0, 0, 100));
+        break;
     case Qt::DecorationRole:
         switch (index.column()) {
         case AwayIcon:
@@ -134,10 +137,6 @@ QVariant MatchDayModel::data(const QModelIndex& index, int role) const
         return s;
         break;
 
-    case Qt::BackgroundRole:
-        return QColor(0, 0, 0, 120);
-        break;
-
     case Qt::TextAlignmentRole:
         if (index.column() < 3) {
             return 0x0002 | 0x0080;
@@ -180,15 +179,8 @@ void MatchDayModel::onMatchListChanged(void)
     m_lastRowCount = m_backend->matchList().count() - 1;
 
     // invalidate complete data
-
     qDebug() << "rowCount @ emit dataChanged: " << rowCount(QModelIndex());
     emit dataChanged(index(0, 0),
                      index(rowCount(QModelIndex()) - 1, columnCount(QModelIndex()) - 1));
 
 }
-
-void MatchDayModel::update(void)
-{
-    this->m_backend->setLeague(m_settings.value("League", "1. Bundesliga").toString());
-    this->m_backend->update();
-}
index 21fc9fc..228ba2d 100644 (file)
@@ -5,7 +5,7 @@
 #include <QFontMetrics>
 #include <QSettings>
 
-#include "backendkicker.h"
+#include "matchdaybackend.h"
 
 class MatchDayModel : public QAbstractTableModel
 {
@@ -23,14 +23,14 @@ class MatchDayModel : public QAbstractTableModel
     };
 
 private:
-    QString         m_url;
-    BackendKicker*  m_backend;
-    int             m_lastRowCount;
-    QSettings       m_settings;
+    QString          m_url;
+    MatchDayBackend* m_backend;
+    int              m_lastRowCount;
+    QSettings        m_settings;
 
 
 public:
-    explicit MatchDayModel(QObject *parent = 0);
+    explicit MatchDayModel(QObject *parent, MatchDayBackend* backend);
 
     int rowCount(const QModelIndex& index) const;
     int columnCount(const QModelIndex& index) const;
@@ -39,9 +39,6 @@ public:
 protected slots:
     void onMatchListChanged(void);
 
-public slots:
-    void update(void);
-
 };
 
 #endif // MATCHDAYMODEL_H
index 7b9cbf1..3de9573 100644 (file)
@@ -8,28 +8,33 @@
 ScoreTable::ScoreTable(MatchDayModel* model, QWidget *parent) :
     QTableView(parent)
 {
-    this->setAttribute(Qt::WA_TransparentForMouseEvents);
-    this->setAttribute(Qt::WA_TranslucentBackground);
+    QPalette palette;
 
+    this->hide();
+    // data
     this->setModel(model);
+
+    // behaviour
+    this->setAttribute(Qt::WA_TransparentForMouseEvents);
     this->setSelectionMode(QAbstractItemView::NoSelection);
 
-    this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+    // style
+    palette.setColor(QPalette::Background, QColor(0, 0, 0, 200));
 
     this->verticalHeader()->hide();
     this->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
     this->verticalHeader()->setMinimumSectionSize(1);
-
     this->horizontalHeader()->hide();
     this->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
     this->horizontalHeader()->setMinimumSectionSize(1);
 
-    qDebug() << "Min VertHeaderSize: " << this->verticalHeader()->minimumSectionSize();
-
     this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
-    this->viewport()->setAutoFillBackground(true);
+    this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+    this->setAttribute(Qt::WA_TranslucentBackground);
+    this->viewport()->setAttribute(Qt::WA_TranslucentBackground);
+
     this->setShowGrid(false);
 }
 
@@ -61,10 +66,4 @@ void ScoreTable::dataChanged(const QModelIndex &topLeft, const QModelIndex &bott
     this->updateGeometry();
 }
 
-void ScoreTable::mousePressEvent(QMouseEvent* event)
-{
-    MatchDayModel* m = (MatchDayModel*)this->model();
-    m->update();
-}
-
 
index 100b8cc..908439d 100644 (file)
@@ -9,9 +9,6 @@
 class ScoreTable : public QTableView
 {
     Q_OBJECT
-protected:
-    void mousePressEvent(QMouseEvent*);
-
 public:
     explicit ScoreTable(MatchDayModel* model, QWidget *parent = 0);
     QSize sizeHint() const;
index b251b9f..fdf56d6 100644 (file)
@@ -6,7 +6,7 @@
 SettingsDialog::SettingsDialog(QWidget *parent) :
     QDialog(parent),
     ui(new Ui::SettingsDialog),
-    settings("David Solbach", "BuliScores")
+    settings(qApp->organizationName(), qApp->applicationName())
 {
     QString league;