File indexing completed on 2024-09-08 06:49:27
0001 /* 0002 SPDX-FileCopyrightText: 1999-2006 Éric Bischoff <ebischoff@nerim.net> 0003 SPDX-FileCopyrightText: 2007 Albert Astals Cid <aacid@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include <QApplication> 0009 #include "ktuberling_debug.h" 0010 #include <QHBoxLayout> 0011 #include <QLabel> 0012 #include <QPushButton> 0013 #include <QScreen> 0014 0015 #include "filefactory.h" 0016 #include "soundfactory.h" 0017 #include "playground.h" 0018 0019 class KTuberlingMobile : public PlayGroundCallbacks, public SoundFactoryCallbacks 0020 { 0021 public: 0022 KTuberlingMobile() 0023 : m_soundEnabled(true) 0024 { 0025 m_soundFactory = new SoundFactory(this); 0026 m_soundFactory->registerLanguages(); 0027 m_soundFactory->loadLanguage(FileFactory::locate(QStringLiteral("sounds/en.soundtheme"))); 0028 0029 QWidget *mainWidget = new QWidget(); 0030 QHBoxLayout *lay = new QHBoxLayout(mainWidget); 0031 m_themesWidget = new QWidget(); 0032 m_gameboardLayout = new QGridLayout(m_themesWidget); 0033 0034 m_playground = new PlayGround(this, mainWidget); 0035 m_playground->registerPlayGrounds(); 0036 m_playground->lockAspectRatio(true); 0037 m_playground->setAllowOnlyDrag(true); 0038 m_playground->loadPlayGround(FileFactory::locate(QStringLiteral("pics/default_theme.theme"))); 0039 0040 QVBoxLayout *sideLayout = new QVBoxLayout(); 0041 0042 // Not sure this is the best way but it works for now 0043 const int screenWidth = QApplication::primaryScreen()->geometry().width(); 0044 const int iconWidth = screenWidth / 15; 0045 0046 QPushButton *themesButton = new QPushButton(mainWidget); 0047 themesButton->setIcon(QPixmap(QStringLiteral(":/games-config-theme.png"))); 0048 themesButton->setIconSize(QSize(iconWidth, iconWidth)); 0049 themesButton->setFocusPolicy(Qt::NoFocus); 0050 QObject::connect(themesButton, &QPushButton::clicked, [this] { 0051 m_themesWidget->showFullScreen(); 0052 }); 0053 0054 QPushButton *soundsButton = new QPushButton(mainWidget); 0055 soundsButton->setIcon(QPixmap(QStringLiteral(":/audio-volume-high.png"))); 0056 soundsButton->setIconSize(QSize(iconWidth, iconWidth)); 0057 soundsButton->setFocusPolicy(Qt::NoFocus); 0058 QObject::connect(soundsButton, &QPushButton::clicked, [this, soundsButton] { 0059 m_soundEnabled = !m_soundEnabled; 0060 soundsButton->setIcon(QPixmap(m_soundEnabled ? QStringLiteral(":/audio-volume-high.png") : QStringLiteral(":/audio-volume-muted.png"))); 0061 }); 0062 0063 sideLayout->addWidget(themesButton); 0064 sideLayout->addWidget(soundsButton); 0065 sideLayout->addStretch(1); 0066 0067 lay->setContentsMargins(0, 0, 0, 0); 0068 lay->setSpacing(0); 0069 lay->addWidget(m_playground); 0070 lay->addLayout(sideLayout); 0071 0072 mainWidget->showFullScreen(); 0073 } 0074 0075 ~KTuberlingMobile() 0076 { 0077 delete m_soundFactory; 0078 } 0079 0080 void playSound(const QString &ref) override 0081 { 0082 m_soundFactory->playSound(ref); 0083 } 0084 0085 void changeGameboard(const QString &/*gameboard*/) override 0086 { 0087 // Only needed when loading a file so not needed for now 0088 } 0089 0090 void registerGameboard(const QString& menuText, const QString& boardFile, const QPixmap &/*pixmap*/) override 0091 { 0092 // TODO this should be scrollable 0093 // TODO use the pixmap 0094 QPushButton *pb = new QPushButton(menuText); 0095 QObject::connect(pb, &QPushButton::clicked, [this, boardFile] { 0096 m_playground->loadPlayGround(boardFile); 0097 m_themesWidget->hide(); 0098 }); 0099 0100 m_gameboardLayout->addWidget(pb, m_gameboardLayout->count() / 2, m_gameboardLayout->count() % 2); 0101 } 0102 0103 bool isSoundEnabled() const override 0104 { 0105 return m_soundEnabled; 0106 } 0107 0108 void registerLanguage(const QString &/*code*/, const QString &/*soundFile*/, bool /*enabled*/) override 0109 { 0110 // TODO 0111 } 0112 0113 private: 0114 SoundFactory *m_soundFactory; 0115 PlayGround *m_playground; 0116 QWidget *m_themesWidget; 0117 QGridLayout *m_gameboardLayout; 0118 bool m_soundEnabled; 0119 }; 0120 0121 // Main function 0122 Q_DECL_EXPORT int main(int argc, char *argv[]) 0123 { 0124 QApplication app(argc, argv); 0125 QLocale::system().name(); // needed to workaround QTBUG-41385 0126 app.setApplicationName(QStringLiteral("ktuberling")); 0127 0128 KTuberlingMobile tuberling; 0129 0130 return app.exec(); 0131 }