tried to propagate mouse events to the toplevel widget
[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, MatchDayModel* model) :
9     QTableView(parent)
10 {
11     this->setAttribute(Qt::WA_TranslucentBackground);
12     this->setAttribute(Qt::WA_TransparentForMouseEvents);
13
14     this->setModel(model);
15     this->setSelectionMode(QAbstractItemView::NoSelection);
16
17     this->verticalHeader()->hide();
18     this->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
19     this->verticalHeader()->setMinimumSectionSize(1);
20
21     this->horizontalHeader()->hide();
22     this->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
23     this->horizontalHeader()->setMinimumSectionSize(1);
24
25     qDebug() << "Min VertHeaderSize: " << this->verticalHeader()->minimumSectionSize();
26
27     this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
28     this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
29
30     this->viewport()->setAutoFillBackground(true);
31     this->setShowGrid(false);
32 }
33
34 QSize ScoreTable::sizeHint() const
35 {
36     QSize s;
37
38     for (int i = 0; i < horizontalHeader()->count(); i++) {
39         s.setWidth(s.width() + horizontalHeader()->sectionSize(i));
40     }
41     // add missing few pixels (from borders mabye?)
42     // TODO: find better solution!
43     s.setWidth(s.width());
44     for (int i = 0; i < verticalHeader()->count(); i++) {
45         s.setHeight(s.height() + verticalHeader()->sectionSize(i));
46     }
47     // add missing few pixels (from borders mabye?)
48     // TODO: find better solution!
49     s.setHeight(s.height() + 3);
50
51     return s;
52 }
53
54 void ScoreTable::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
55 {
56     QSize s;
57
58     // this will recalculate section sizes
59     QTableView::dataChanged(topLeft, bottomRight);
60
61     for (int i = 0; i < horizontalHeader()->count(); i++) {
62         s.setWidth(s.width() + horizontalHeader()->sectionSize(i));
63     }
64     // add missing few pixels (from borders mabye?)
65     // TODO: find better solution!
66     s.setWidth(s.width());
67     for (int i = 0; i < verticalHeader()->count(); i++) {
68         s.setHeight(s.height() + verticalHeader()->sectionSize(i));
69     }
70     // add missing few pixels (from borders mabye?)
71     // TODO: find better solution!
72     s.setHeight(s.height() + 3);
73
74     this->resize(s);
75     this->parentWidget()->resize(s);
76
77     qDebug() << s;
78
79     updateGeometry();
80 }
81
82 //void ScoreTable::mousePressEvent(QMouseEvent* event)
83 //{
84 //    event->ignore();
85 //}
86