Icons for 2. Bundesliga (Germany) still have to be sorted.
[buliscores] / src / scoretable.cpp
1 #include <QHeaderView>
2 #include <QDebug>
3 #include <QRect>
4
5 #include "scoretable.h"
6 #include "matchdaymodel.h"
7
8 ScoreTable::ScoreTable(QWidget *parent) :
9     QTableView(parent)
10 {
11     this->setAttribute(Qt::WA_TranslucentBackground);
12     this->setModel(new MatchDayModel(this));
13     this->setSelectionMode(QAbstractItemView::NoSelection);
14
15     this->verticalHeader()->hide();
16     this->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
17     this->verticalHeader()->setMinimumSectionSize(1);
18
19     this->horizontalHeader()->hide();
20     this->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
21     this->horizontalHeader()->setMinimumSectionSize(1);
22
23     qDebug() << "Min VertHeaderSize: " << this->verticalHeader()->minimumSectionSize();
24
25
26     this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
27     this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
28
29     this->viewport()->setAutoFillBackground(true);
30     this->setShowGrid(false);
31 }
32
33 QSize ScoreTable::sizeHint() const
34 {
35     QSize s;
36
37     for (int i = 0; i < horizontalHeader()->count(); i++) {
38         s.setWidth(s.width() + horizontalHeader()->sectionSize(i));
39     }
40     // add missing few pixels (from borders mabye?)
41     // TODO: find better solution!
42     s.setWidth(s.width());
43     for (int i = 0; i < verticalHeader()->count(); i++) {
44         s.setHeight(s.height() + verticalHeader()->sectionSize(i));
45     }
46     // add missing few pixels (from borders mabye?)
47     // TODO: find better solution!
48     s.setHeight(s.height() + 3);
49
50     return s;
51 }
52
53 void ScoreTable::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
54 {
55     QSize s;
56
57     // this will recalculate section sizes
58     QTableView::dataChanged(topLeft, bottomRight);
59
60     for (int i = 0; i < horizontalHeader()->count(); i++) {
61         s.setWidth(s.width() + horizontalHeader()->sectionSize(i));
62     }
63     // add missing few pixels (from borders mabye?)
64     // TODO: find better solution!
65     s.setWidth(s.width());
66     for (int i = 0; i < verticalHeader()->count(); i++) {
67         s.setHeight(s.height() + verticalHeader()->sectionSize(i));
68     }
69     // add missing few pixels (from borders mabye?)
70     // TODO: find better solution!
71     s.setHeight(s.height() + 3);
72
73     this->resize(s);
74     this->parentWidget()->resize(s);
75
76     qDebug() << s;
77
78     updateGeometry();
79 }