- fix sound playback
[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     this->setAttribute(Qt::WA_TransparentForMouseEvents);
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     int maxrows = 9;
45
46     if (verticalHeader()->count() > 0) {
47         for (int i = 0; i < horizontalHeader()->count(); i++) {
48             s.setWidth(s.width() + horizontalHeader()->sectionSize(i));
49         }
50
51         for (int i = 0; i < verticalHeader()->count() && i < maxrows; 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     } else {
58         s.setHeight(200);
59         s.setWidth(400);
60     }
61
62     return s;
63 }
64
65 void ScoreTable::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
66 {
67     // this will recalculate section sizes
68     QTableView::dataChanged(topLeft, bottomRight);
69 }
70
71