-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathranklistpage.cpp
220 lines (181 loc) · 6.78 KB
/
ranklistpage.cpp
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include "ranklistpage.h"
#include "ui_ranklistpage.h"
//#include "startpage.h"
//#include "ui_startpage.h"
#include<windows.h>
#include<stdio.h>
#include <QDesktopServices>
#include "CGammaRamp.h"
#include "iostream"
//class StartPage;
rankListPage::rankListPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::rankListPage)
{
QSqlDatabase db=mysql->connect();
if(db.isOpen()){
qDebug()<<"ranklist connect success";
}else{
qDebug()<<"ranklist connect fail";
}
this->hide();
ui->setupUi(this);
returnButton = new HoverButton();
returnButton->setSound(":/music/button/button_mouseover.wav", ":/music/button/button_mouseleave.wav", ":/music/button/button_press.wav", ":/music/button/button_release.wav"); //默认音效
//禁用最大化按钮、设置窗口大小固定
this->setWindowFlags(windowFlags()& ~Qt::WindowMaximizeButtonHint);
this->setFixedSize(this->width(),this->height());
labelRanklist = new QLabel(this);
labelUserRanklist = new QLabel(this);
labelRanklist->setText("Total Rank List");
labelUserRanklist->setText("User Rank List");
QFont ftr;
ftr.setPointSize(30);
labelRanklist->setFont(ftr);
labelUserRanklist->setFont(ftr);
labelRanklist->setGeometry(this->width()/2+100,this->height()/2-30,1000,450);
labelUserRanklist->setGeometry(this->width()/2+2000,this->height()/2-30,1000,450);
ranklist = new QTextBrowser(this);
// ranklist->setText("");
ranklist->setText("ID\t\t\t\tSCORE\t\t\t\tRANK\n");
QFont ft;
ft.setPointSize(20);
ranklist->setFont(ft);
ranklist->setGeometry(this->width()/2+100,this->height()/2+250,1000,450);
QPalette pl = ranklist->palette();
pl.setBrush(QPalette::Base,QBrush(QColor(255,0,0,0)));
ranklist->setPalette(pl);
ranklist->setStyleSheet("QTextBrowser{border-width:0;border-style:outset}");
userRanklist = new QTextBrowser(this);
// ranklist->setText("");
userRanklist->setText("ID\t\tSCORE\t\t\n");
QFont ft1;
ft1.setPointSize(20);
userRanklist->setFont(ft1);
userRanklist->setGeometry(this->width()/2+1000,this->height()/2+250,1000,450);
QPalette pl1 = ranklist->palette();
pl1.setBrush(QPalette::Base,QBrush(QColor(255,0,0,0)));
userRanklist->setPalette(pl);
userRanklist->setStyleSheet("QTextBrowser{border-width:0;border-style:outset}");
//全屏
QWidget::showFullScreen();
//设置窗口背景黑色
QPalette palette(this->palette());
palette.setColor(QPalette::Background, Qt::black);
this->setPalette(palette);
//设置鼠标-普通
setCursor(QCursor(QPixmap("://picture/mouse1.png")));
// QTimer::singleShot(1500, this, [=](){
QParallelAnimationGroup *group = new QParallelAnimationGroup;
group->addAnimation(ShowBackground());
SetButton();
returnButton->showContent("Return",30);
group->addAnimation(returnButton->textAnim);
group->addAnimation(ShowTitle());
Sleep(200);
group->start(QAbstractAnimation::DeleteWhenStopped);
QSqlQuery query("SELECT * FROM game_rank ORDER BY score DESC", db);
if(!query.exec("SELECT * FROM game_rank ORDER BY score DESC")){
QMessageBox::critical(this, "Query Error", query.lastError().text());
return;
}
// 创建一个数据模型,并将查询结果加载到模型中
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery(query);
QTableView *tableView = new QTableView(this);
// 设置表格的字体
QFont font("Arial", 20); // 使用 Arial 字体,字号为 20
tableView->setFont(font);
tableView->setGeometry(500,300,2000,800);
tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
//tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
tableView->setModel(model);
// 将表格视图添加到主窗口
tableView->show();
this->hide();
}
rankListPage::~rankListPage()
{
delete ui;
}
void rankListPage::setUserRankList(QString s) {
userRanklist->setText(s);
}
void rankListPage::setRankList(QString s) {
ranklist->setText(s);
}
QPropertyAnimation * rankListPage::ShowTitle(){
QPixmap pix;
QLabel *title = new QLabel(this);
title->setGeometry(this->width()/2-903/2,-title->height(),903,200);
setAdaptedImg(":/picture/StartPage/title.png",title);
title->show();
QPropertyAnimation *animation = new QPropertyAnimation(title, "geometry",this);
animation->setDuration(2000);
animation->setStartValue(QRect(title->x(), title->y(), title->width(), title->height()));
animation->setEndValue(QRect(title->x(), 100, title->width(), title->height()));
animation->setEasingCurve(QEasingCurve::OutExpo);
return animation;
}
QPropertyAnimation * rankListPage::ShowBackground(){
QPixmap pix;
QLabel *background = new QLabel(this);
bkAnim = new QPropertyAnimation(background, "geometry",this);
setBkImg("://picture/StartPage/background.png",background);
background->show();
bkAnim->setDuration(2000);
bkAnim->setStartValue(QRect(background->x(), background->y(), background->width(), background->height()));
bkAnim->setEndValue(QRect(background->x(), this->height() - background->height(), background->width(), background->height()));
bkAnim->setEasingCurve(QEasingCurve::InOutCubic);
return bkAnim;
}
void rankListPage::SetButton(){
returnButton->setCircle(this->width()/10, this->width()/2, this->height()/2+400, this->width(), this->height(),\
":/picture/button/ball.png", "", this);
connect(returnButton, &HoverButton::clicked, [=](){
this->hide();
showStartPage();
}) ;
}
//将path的图片放置到label上,自适应label大小
void rankListPage::setAdaptedImg(QString path,QLabel *label)
{
QImage image(path);
QSize size=label->size();
QImage image2=image.scaled(size,Qt::IgnoreAspectRatio);//重新调整图像大小以适应label
label->setPixmap(QPixmap::fromImage(image2));//显示
}
//将path的图片放置到label上,自适应label大小
void rankListPage::setBkImg(QString path,QLabel *label)
{
QImage image = QImage(path);
if(image.isNull()){
qDebug()<<"background:empty";
}
double ratio=(double)image.height()/(double)image.width();
QImage image2=image.scaled(this->width(),ratio*this->width(),Qt::IgnoreAspectRatio);//重新调整图像大小以适应label
label->setPixmap(QPixmap::fromImage(image2));//显示
label->setGeometry(0,0,this->width(),ratio*this->width());
}
void rankListPage::keyPressEvent(QKeyEvent *ev)
{
//Esc退出全屏
if(ev->key() == Qt::Key_Escape)
{
QWidget::showNormal();
return;
}
//F11全屏
if(ev->key() == Qt::Key_F11)
{
QWidget::showFullScreen();
return;
}
QWidget::keyPressEvent(ev);
}
void rankListPage::Sleep(int msec)
{
QTime dieTime = QTime::currentTime().addMSecs(msec);
while( QTime::currentTime() < dieTime )
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}