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