-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWinScreen.cpp
86 lines (71 loc) · 2.56 KB
/
WinScreen.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
// Author: Annie Berend (5033782) - Jonathan Verbeek (5058288)
#include "WinScreen.h"
#include "ui_WinScreen.h"
#include "Main.h"
#include <QLabel>
#include <QDesktopWidget>
CWinScreen::CWinScreen(int score, int moves, QString time, QWidget *parent) :
QWidget(parent),
ui(new Ui::WinScreen)
{
ui->setupUi(this);
// Place the window at the center of the screen
QDesktopWidget* desktop = QApplication::desktop();
int screenW = desktop->width();
int screenH = desktop->height();
int windowW = this->size().width();
int windowH = this->size().height();
this->move((screenW / 2) - (windowW / 2), (screenH / 2) - (windowH / 2));
// Pixmap of the win screen)
QPixmap winPixmap(":/assets/winscreen.png");
// Add the win image
QLabel* winImage = new QLabel(this);
winImage->setPixmap(winPixmap.scaled(500, 500, Qt::KeepAspectRatio, Qt::SmoothTransformation));
winImage->resize(500, 500);
ui->gridLayout_2->addWidget(winImage, 0, 0, 1, 3);
// Create the score label
QLabel* scoreLabel = new QLabel("Score: " + QString::number(score), this);
// Set up a font to use
QFont font = scoreLabel->font();
font.setBold(true);
font.setPointSize(12);
// Apply the score label
scoreLabel->setFont(font);
scoreLabel->setStyleSheet("color: white;");
ui->gridLayout_2->addWidget(scoreLabel, 1, 0, Qt::AlignCenter);
// Create the moves label
QLabel* movesLabel = new QLabel("Moves: " + QString::number(moves), this);
movesLabel->setFont(font);
movesLabel->setStyleSheet("color: white;");
ui->gridLayout_2->addWidget(movesLabel, 1, 1, Qt::AlignCenter);
// Create the time label
QLabel* timeLabel = new QLabel("Time: " + time, this);
timeLabel->setFont(font);
timeLabel->setStyleSheet("color: white;");
ui->gridLayout_2->addWidget(timeLabel, 1, 2, Qt::AlignCenter);
// Assign the background to the window's palette
QPixmap bg(":/assets/table_background.png");
bg.scaled(this->size(), Qt::IgnoreAspectRatio);
QPalette palette;
palette.setBrush(QPalette::Background, bg);
this->setPalette(palette);
}
void CWinScreen::mousePressEvent(QMouseEvent* ev)
{
Q_UNUSED(ev);
// Restart the game
CMain::get()->getGameInstance()->restartGame();
CMain::get()->getGameWindow()->resetGameWindow();
}
void CWinScreen::closeEvent(QCloseEvent* ev)
{
Q_UNUSED(ev);
// Restart the game
CMain::get()->getGameInstance()->restartGame();
CMain::get()->getGameWindow()->resetGameWindow();
}
CWinScreen::~CWinScreen()
{
// Delete the UI
delete ui;
}