added intermedia code that selects the corrent icons for the Kicker
[buliscores] / src / matchdaymodel.cpp
1 #include "matchdaymodel.h"
2 #include <QColor>
3 #include <QFontMetrics>
4 #include <QFont>
5 #include <QIcon>
6
7 MatchDayModel::MatchDayModel(QObject *parent) :
8     QAbstractTableModel(parent)
9 {
10     backendkicker = new BackendKicker(this);
11
12     connect(backendkicker, SIGNAL(matchListChanged()),
13             this, SLOT(onMatchListChanged()));
14
15 }
16
17 int MatchDayModel::rowCount(const QModelIndex& index) const
18 {
19     int count = backendkicker->matchList().count();
20
21     return count;
22 }
23
24 int MatchDayModel::columnCount(const QModelIndex& index) const
25 {
26     return 7;
27 }
28
29 QVariant MatchDayModel::data(const QModelIndex& index, int role) const
30 {
31     Match*       match;
32     QFont        f;
33     QSize        s;
34     QIcon        i;
35
36     f.setPixelSize(14);
37
38     if ((match = backendkicker->matchList().at(index.row())) == NULL) {
39         return QVariant(QVariant::Invalid);
40     }
41
42     // DisplayRole
43     switch (role) {
44     case Qt::DecorationRole:
45         switch (index.column()) {
46         case AwayIcon:
47             i = match->awayEmblem().pixmap(25,25);
48             break;
49         case HomeIcon:
50             i = match->homeEmblem().pixmap(25,25);
51             break;
52         }
53         return i;
54         break;
55
56     case Qt::DisplayRole:
57         switch (index.column()) {
58         case AwayIcon:
59             return match->awayEmblem();
60             break;
61         case AwayTeam:
62             return match->awayteam();
63             break;
64         case AwayScore:
65             return match->awayscore();
66             break;
67         case HomeIcon:
68             return match->homeEmblem();
69             break;
70         case HomeTeam:
71             return match->hometeam();
72             break;
73         case HomeScore:
74             return match->homescore();
75             break;
76         default:
77             return QVariant(QVariant::Invalid);
78             break;
79         }
80         break;
81
82     case Qt::SizeHintRole:
83         s.setHeight(25);
84         switch (index.column()) {
85         case AwayIcon:
86             s.setWidth(29);
87             break;
88         case AwayTeam:
89             s.setWidth(120);
90             break;
91         case AwayScore:
92             s.setWidth(4);
93             break;
94         case HomeIcon:
95             s.setWidth(29);
96             break;
97         case HomeTeam:
98             s.setWidth(120);
99             break;
100         case HomeScore:
101             s.setWidth(4);
102             break;
103         case Seperator:
104             s.setWidth(3);
105             break;
106         default:
107             return QVariant(QVariant::Invalid);
108             break;
109         }
110         return s;
111         break;
112
113     case Qt::BackgroundRole:
114         return QColor(0, 0, 0, 120);
115         break;
116
117     case Qt::TextAlignmentRole:
118         if (index.column() < 3) {
119             return 0x0002 | 0x0080;
120         } else if (index.column() > 3) {
121             return 0x0001 | 0x0080;
122         } else {
123             return Qt::AlignCenter;
124         }
125         break;
126     case Qt::FontRole:
127
128
129         return f;
130
131     default:
132         return QVariant(QVariant::Invalid);
133     }
134 }
135
136
137 // only adds for now
138 void MatchDayModel::onMatchListChanged(void)
139 {
140     beginInsertRows(QModelIndex(),
141                     rowCount(QModelIndex()),
142                     rowCount(QModelIndex()));
143     endInsertRows();
144
145     // invalidate complete data
146     emit dataChanged(index(0, 0),
147                      index(rowCount(QModelIndex()) - 1, columnCount(QModelIndex()) - 1));
148
149 }