0bd29e81f234351d833907d4077f405ceedee7e1
[buliscores] / src / 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(MatchDayModel* model, QWidget *parent) :
9     QTableView(parent)
10 {
11     QPalette palette;
12
13     this->hide();
14     // data
15     this->setModel(model);
16
17     // behaviour
18     this->setSelectionMode(QAbstractItemView::NoSelection);
19
20     // style
21     palette.setColor(QPalette::Background, QColor(0, 0, 0, 200));
22
23     this->verticalHeader()->hide();
24     this->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
25     this->verticalHeader()->setMinimumSectionSize(1);
26     this->horizontalHeader()->hide();
27     this->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
28     this->horizontalHeader()->setMinimumSectionSize(1);
29
30     this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
31     this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
32
33     this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
34     this->setAttribute(Qt::WA_TranslucentBackground);
35     this->viewport()->setAttribute(Qt::WA_TranslucentBackground);
36
37     this->setShowGrid(false);
38 }
39
40 QSize ScoreTable::sizeHint() const
41 {
42     QSize s;
43     int maxrows = 9;
44
45     for (int i = 0; i < horizontalHeader()->count(); i++) {
46         s.setWidth(s.width() + horizontalHeader()->sectionSize(i));
47     }
48
49     for (int i = 0; i < verticalHeader()->count(), i < maxrows; i++) {
50         s.setHeight(s.height() + verticalHeader()->sectionSize(i));
51     }
52     // add missing few pixels (from borders mabye?)
53     // TODO: find better solution!
54     s.setHeight(s.height() + 2);
55
56     return s;
57 }
58
59 void ScoreTable::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
60 {
61     // this will recalculate section sizes
62     QTableView::dataChanged(topLeft, bottomRight);
63 }
64
65