-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTopList.cpp
More file actions
98 lines (91 loc) · 3.18 KB
/
TopList.cpp
File metadata and controls
98 lines (91 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "TopList.h"
#include "ui_TopList.h"
#include <QString>
#include <QTableWidgetItem>
#include <QSqlQuery>
#include <QDebug>
#include "DbHandler.h"
TopList::TopList(QWidget *parent) :
QWidget(parent),
ui(new Ui::TopList)
{
qRegisterMetaType<PlayerResult>("PlayerResult");
ui->setupUi(this);
animation = new QPropertyAnimation(this, "size");
model = new QSqlQueryModel(this);
proxy= new QSortFilterProxyModel(this);
connect(this, &TopList::destroyed, animation, &QPropertyAnimation::deleteLater);
connect(this, &TopList::destroyed, proxy, &QSortFilterProxyModel::deleteLater);
connect(this, &TopList::destroyed, model, &QSqlQueryModel::deleteLater);
connect(ui->tableView->horizontalHeader(), &QHeaderView::sortIndicatorChanged, this, &TopList::sortByColumn);
proxy->setSortLocaleAware(true);
proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
}
TopList::~TopList()
{
delete ui;
}
void TopList::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
if (e && e->type() == QEvent::LanguageChange)
{
ui->retranslateUi(this);
setHeaders();
}
}
void TopList::setHeaders()
{
if (model)
{
model->setHeaderData(0, Qt::Horizontal, tr("Játékos"));
model->setHeaderData(1, Qt::Horizontal, tr("Max. pont"));
model->setHeaderData(2, Qt::Horizontal, tr("Akt. pont"));
model->setHeaderData(3, Qt::Horizontal, tr("Legjobb idő"));
model->setHeaderData(4, Qt::Horizontal, tr("Akt. idő"));
}
}
void TopList::onSetPlayerResult(PlayerResult &res)
{
DbHandler::getDbHandler()->update(res);
}
void TopList::show()
{
DbHandler::getDbHandler()->open();
model->setQuery("SELECT * FROM SCORES");
proxy->setSourceModel(model);
proxy->setDynamicSortFilter(true);
ui->tableView->setModel(proxy);
ui->tableView->setSortingEnabled(true);
ui->tableView->sortByColumn(2, Qt::DescendingOrder);
ui->tableView->horizontalHeader()->setStyleSheet(
"QHeaderView::section {font: bold; color: white; background-color:darkCyan;}"
"QHeaderView::up-arrow {image: url(:/images/up_arrow.png);}"
"QHeaderView::down-arrow {image: url(:/images/down_arrow.png);}");
ui->tableView->setStyleSheet(
"QTableView {"
"border-radius: 5px; color: darkBlue;"
"background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 #ffffff, stop:1 #0ad487);"
"alternate-background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 #0ad487, stop:1 #ffffff)};");
setHeaders();
adjustSize();
animation->setDuration(1500);
animation->setStartValue(QSize(this->size().width(), 0));
animation->setEndValue(this->size());
animation->start();
QWidget::show();
}
void TopList::sortByColumn(int col, Qt::SortOrder order)
{
Q_UNUSED(order)
switch (col)
{
case 0:
ui->tableView->setLocale(parentWidget()->locale());
ui->tableView->sortByColumn(col, order);
break;
default:
setLocale(QLocale::system());
break;
}
}