-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainview.cpp
76 lines (58 loc) · 1.64 KB
/
mainview.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
#include "mainview.h"
#include "menuscene.h"
#include "gamescene.h"
#include <QtCore>
MainView::MainView()
: width(900), height(600),
username("Global/Username"),
menuScene(nullptr), gameScene(nullptr)
{
setMouseTracking(true);
setRenderHint(QPainter::Antialiasing, true);
setRenderHint(QPainter::TextAntialiasing, true);
setRenderHint(QPainter::SmoothPixmapTransform, true);
setFrameStyle(0);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setMinimumSize(width, height);
// set username of the all scenes
if(getUsername().isEmpty()){
QString username = qgetenv("USER"); // Linux or Mac
if (username.isEmpty())
username = qgetenv("USERNAME"); // Windows
if (username.isEmpty())
username = tr("Guest");
setUsername(username);
}
}
MainView::~MainView()
{
if(menuScene)
menuScene->deleteLater();
if(gameScene)
gameScene->deleteLater();
}
QString MainView::getUsername() const
{
return QSettings().value(username, "").toString();
}
void MainView::setUsername(const QString &usernameSetInMenuScene)
{
return QSettings().setValue(username, usernameSetInMenuScene);
}
void MainView::switchToMenuScene()
{
MenuScene *newMenuScene = new MenuScene();
setScene(newMenuScene);
if (menuScene)
menuScene->deleteLater();
menuScene = newMenuScene;
}
void MainView::switchToGameScene()
{
GameScene *newGameScene = new GameScene();
setScene(newGameScene);
if(gameScene)
gameScene->deleteLater();
gameScene = newGameScene;
}