-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.cpp
More file actions
112 lines (99 loc) · 3.55 KB
/
Copy pathgame.cpp
File metadata and controls
112 lines (99 loc) · 3.55 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "game.hpp"
#include "font.hpp"
#include "wids/icobtn.hpp"
#include "wids/flow.hpp"
#include <QBoxLayout>
#include <QPushButton>
#include <QKeyEvent>
#include <QFile>
MainGame::MainGame() {
stack = new QStackedWidget(this);
setCentralWidget(stack);
// Create the main screen
main = new QWidget();
stack->addWidget(main);
auto mlay = new QVBoxLayout(main);
house = new House(main);
house->setStyleSheet("background-color: transparent;");
mlay->addWidget(house, 2);
auto* curtxt = new QLabel(main);
curtxt->setWordWrap(true);
curtxt->setAlignment(Qt::AlignCenter);
curtxt->setStyleSheet("background-color: #CC88CC;");
curtxt->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
curtxt->setObjectName("curtxt");
resizeFont(curtxt, 1.2);
QFontMetrics fm(curtxt->font());
curtxt->setMinimumHeight(fm.lineSpacing() * 1.2 * 2); // 2 lines plus extra space
#ifdef APP_DEBUG
{
auto* btn = new QPushButton("REDO", this);
btn->setProperty("fancy", true);
btn->setProperty("optbtn", true);
resizeFont(btn, 0.7);
connect(btn, &QPushButton::clicked, this, [=](){ conv->onclick({}); });
auto* lay = new QHBoxLayout();
lay->addWidget(curtxt);
lay->addWidget(btn);
mlay->addLayout(lay);
}
#else
mlay->addWidget(curtxt);
#endif
auto botsect = new QHBoxLayout();
auto optcontnr = new QWidget(main);
optcontnr->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
auto* olay = new FlowLayout(optcontnr, 8, 8, 16);
botsect->addWidget(optcontnr);
conv = new Conversation(olay, curtxt);
auto quickbtns = new QVBoxLayout();
auto addBtn = [&](const QString& labl, const QString& asset, auto slot) {
auto btn = new IcoButton(labl, asset);
btn->setIconSize(QSize(0,0));
resizeFont(btn, 0.9);
connect(btn, &QPushButton::clicked, this, slot);
return btn;
};
auto nt = addBtn("New topic", ":/assets/UI/new.svg", [=](){ conv->newTopic(); });
auto at = addBtn("All Tasks", ":/assets/UI/tasks.svg", [=](){ toTasks(); });
auto st = addBtn("Settings", ":/assets/UI/settings.svg", [=](){ toSetts(); });
int w = std::max({
nt->sizeHint().width(), at->sizeHint().width(), st->sizeHint().width()
});
QSize sze(w*0.6, w*0.6);
auto fixBtn = [&](IcoButton* btn) {
quickbtns->addWidget(btn);
btn->setMinimumWidth(w+6);
btn->setIconSize(sze);
};
fixBtn(nt); fixBtn(at); fixBtn(st);
botsect->addLayout(quickbtns);
mlay->addLayout(botsect, 1);
// Create the settings screen
setts = new QWidget();
stack->addWidget(setts);
generateSettings();
// Create the tasks screen
tasks = new TaskView();
stack->addWidget(tasks);
// Last initialisation!
QFile file(":/style.qss");
bool ok = file.open(QIODevice::ReadOnly);
// Should always be ok because we're loading from a preset internal file
setStyleSheet(QString::fromUtf8(file.readAll()));
stack->setCurrentWidget(main);
}
void MainGame::keyPressEvent(QKeyEvent* event) {
if (event->key() == Qt::Key_Back) {
stack->setCurrentWidget(main);
event->accept();
return;
}
QWidget::keyPressEvent(event);
}
void MainGame::toTasks() {
#ifdef APP_DEBUG
tasks->redoTasks();
#endif
stack->setCurrentWidget(tasks);
}