-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
main_mobile.cpp
131 lines (107 loc) · 3.91 KB
/
main_mobile.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
/*
SPDX-FileCopyrightText: 1999-2006 Éric Bischoff <[email protected]>
SPDX-FileCopyrightText: 2007 Albert Astals Cid <[email protected]>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <QApplication>
#include "ktuberling_debug.h"
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QScreen>
#include "filefactory.h"
#include "soundfactory.h"
#include "playground.h"
class KTuberlingMobile : public PlayGroundCallbacks, public SoundFactoryCallbacks
{
public:
KTuberlingMobile()
: m_soundEnabled(true)
{
m_soundFactory = new SoundFactory(this);
m_soundFactory->registerLanguages();
m_soundFactory->loadLanguage(FileFactory::locate(QStringLiteral("sounds/en.soundtheme")));
QWidget *mainWidget = new QWidget();
QHBoxLayout *lay = new QHBoxLayout(mainWidget);
m_themesWidget = new QWidget();
m_gameboardLayout = new QGridLayout(m_themesWidget);
m_playground = new PlayGround(this, mainWidget);
m_playground->registerPlayGrounds();
m_playground->lockAspectRatio(true);
m_playground->setAllowOnlyDrag(true);
m_playground->loadPlayGround(FileFactory::locate(QStringLiteral("pics/default_theme.theme")));
QVBoxLayout *sideLayout = new QVBoxLayout();
// Not sure this is the best way but it works for now
const int screenWidth = QApplication::primaryScreen()->geometry().width();
const int iconWidth = screenWidth / 15;
QPushButton *themesButton = new QPushButton(mainWidget);
themesButton->setIcon(QPixmap(QStringLiteral(":/games-config-theme.png")));
themesButton->setIconSize(QSize(iconWidth, iconWidth));
themesButton->setFocusPolicy(Qt::NoFocus);
QObject::connect(themesButton, &QPushButton::clicked, [this] {
m_themesWidget->showFullScreen();
});
QPushButton *soundsButton = new QPushButton(mainWidget);
soundsButton->setIcon(QPixmap(QStringLiteral(":/audio-volume-high.png")));
soundsButton->setIconSize(QSize(iconWidth, iconWidth));
soundsButton->setFocusPolicy(Qt::NoFocus);
QObject::connect(soundsButton, &QPushButton::clicked, [this, soundsButton] {
m_soundEnabled = !m_soundEnabled;
soundsButton->setIcon(QPixmap(m_soundEnabled ? QStringLiteral(":/audio-volume-high.png") : QStringLiteral(":/audio-volume-muted.png")));
});
sideLayout->addWidget(themesButton);
sideLayout->addWidget(soundsButton);
sideLayout->addStretch(1);
lay->setContentsMargins(0, 0, 0, 0);
lay->setSpacing(0);
lay->addWidget(m_playground);
lay->addLayout(sideLayout);
mainWidget->showFullScreen();
}
~KTuberlingMobile()
{
delete m_soundFactory;
}
void playSound(const QString &ref) override
{
m_soundFactory->playSound(ref);
}
void changeGameboard(const QString &/*gameboard*/) override
{
// Only needed when loading a file so not needed for now
}
void registerGameboard(const QString& menuText, const QString& boardFile, const QPixmap &/*pixmap*/) override
{
// TODO this should be scrollable
// TODO use the pixmap
QPushButton *pb = new QPushButton(menuText);
QObject::connect(pb, &QPushButton::clicked, [this, boardFile] {
m_playground->loadPlayGround(boardFile);
m_themesWidget->hide();
});
m_gameboardLayout->addWidget(pb, m_gameboardLayout->count() / 2, m_gameboardLayout->count() % 2);
}
bool isSoundEnabled() const override
{
return m_soundEnabled;
}
void registerLanguage(const QString &/*code*/, const QString &/*soundFile*/, bool /*enabled*/) override
{
// TODO
}
private:
SoundFactory *m_soundFactory;
PlayGround *m_playground;
QWidget *m_themesWidget;
QGridLayout *m_gameboardLayout;
bool m_soundEnabled;
};
// Main function
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLocale::system().name(); // needed to workaround QTBUG-41385
app.setApplicationName(QStringLiteral("ktuberling"));
KTuberlingMobile tuberling;
return app.exec();
}