File indexing completed on 2024-11-03 03:46:41
0001 /* 0002 This file is part of the KDE games kwin4 program 0003 SPDX-FileCopyrightText: 2000 Martin Heni <kde@heni-online.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KWIN4_H 0009 #define KWIN4_H 0010 0011 // own 0012 #include "kwin4global.h" 0013 #include "thememanager.h" 0014 // KDEGames 0015 #define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API 0016 #include <libkdegamesprivate/kgame/kgameio.h> 0017 // KF 0018 #include <KXmlGuiWindow> 0019 // Qt 0020 #include <QLabel> 0021 0022 class KWin4Doc; 0023 class KWin4View; 0024 class QGroupBox; 0025 0026 class KPlayer; 0027 class KGame; 0028 class ChatDlg; 0029 class ReflectionGraphicsScene; 0030 0031 /** 0032 * The base class for Kwin4 application. 0033 */ 0034 class KWin4App : public KXmlGuiWindow 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 /** 0040 * Construct the application. 0041 * @param parent The parent 0042 */ 0043 explicit KWin4App(QWidget *parent = nullptr); 0044 0045 /** 0046 * Destruct the application. 0047 */ 0048 ~KWin4App() override; 0049 0050 protected: 0051 /** 0052 * The game is ended. Either because it is finished or because it is 0053 * aborted by the player. 0054 * @param mode Result of the game 0055 */ 0056 void EndGame(TABLE mode); 0057 0058 /** 0059 * Flags which menus should be checked and set by below functions. 0060 */ 0061 enum CheckFlags { All = 0, CheckFileMenu = 1, CheckEditMenu = 2 }; 0062 0063 /** 0064 * Enable or disable an action depending on the boolean parameter. 0065 * @param action The action to affect 0066 * @param enable True if the action should be enabled, false otherwise. 0067 */ 0068 void changeAction(const QString &action, bool enable); 0069 0070 /** 0071 * Enable oactions that is menu/toolbar items. 0072 * @param action The action to affect 0073 */ 0074 void enableAction(const QString &action) 0075 { 0076 changeAction(action, true); 0077 } 0078 0079 /** 0080 * Disable actions that is menu/toolbar items. 0081 * @param action The action to affect 0082 */ 0083 void disableAction(const QString &action) 0084 { 0085 changeAction(action, false); 0086 } 0087 0088 /** 0089 * Checks all menus and depending on the game status enables or disables them. 0090 * This is usually done on program init. 0091 * @param menu Which menu to check, default all menus 0092 */ 0093 void checkMenus(CheckFlags menu = All); 0094 0095 /** 0096 * Setup all actions (menus and toolbar items). 0097 */ 0098 void initGUI(); 0099 0100 /** 0101 * Setup the statusbar. 0102 */ 0103 void initStatusBar(); 0104 0105 /** 0106 * Prepare the game engine (document) and connect its signals. 0107 */ 0108 void connectDocument(); 0109 0110 /** 0111 * Save the properties of the application. 0112 */ 0113 void saveProperties(); 0114 0115 /** 0116 * Save instance-specific properties. The function is 0117 * invoked when the session manager requests your application 0118 * to save its state. 0119 * @param grp The config group 0120 */ 0121 void saveProperties(KConfigGroup &grp) override; 0122 0123 /** 0124 * Read the properties of the application. 0125 */ 0126 void readProperties(); 0127 0128 /** 0129 * Read instance-specific properties. 0130 * @param grp The config group 0131 */ 0132 void readProperties(const KConfigGroup &grp) override; 0133 0134 /** 0135 * Called by Qt when closing the window 0136 */ 0137 void closeEvent(QCloseEvent *event) override; 0138 0139 /** 0140 * Retrieve the theme file from the theme index number give. 0141 * @param idx The theme index number [0..] 0142 * @return The theme file name. 0143 */ 0144 QString themefileFromIdx(int idx); 0145 0146 /** 0147 * Retrieve the theme idx number from the theme name give. 0148 * @param name The theme file name. 0149 * @return The theme index number [0..] 0150 */ 0151 int themeIdxFromName(const QString &name); 0152 0153 public Q_SLOTS: 0154 /** 0155 * The server type was changed (KGame) 0156 * @param t The server type 0157 */ 0158 void serverTypeChanged(int t); 0159 0160 /** 0161 * The remote player changed (GUI signal) 0162 * @param who The remote player is 0:y ellow, 1: red 0163 */ 0164 void remoteChanged(int who); 0165 0166 /** 0167 * The game is over indication. 0168 * @param status -1: remis, 1: won/loss 2: abort 0169 * @param p The player who made the last move 0170 * @param me The game 0171 */ 0172 void slotGameOver(int status, KPlayer *p, KGame *me); 0173 0174 /** 0175 * A move has been performed. Update the status etc. 0176 * @param playerNumber Number of the next player to move 0177 */ 0178 void moveDone(int playerNumber); 0179 0180 /** 0181 * The network connection has been lost. 0182 * @param id Game id 0183 * @param oldstatus Previous game status 0184 * @param game Our game 0185 */ 0186 void networkBroken(int id, int oldstatus, KGame *game); 0187 0188 /** 0189 * Being noticed by KGAme that a new game started 0190 */ 0191 void gameRun(); 0192 0193 /** 0194 * Update the names in the status bar. 0195 */ 0196 void updateStatusNames(); 0197 0198 /** 0199 * Show the network configuration dialog. 0200 */ 0201 void configureNetwork(); 0202 0203 /** 0204 * Show the network chat dialog. 0205 */ 0206 void configureChat(); 0207 0208 /** 0209 * Show the debug a KGame dialog. 0210 */ 0211 void debugKGame(); 0212 0213 /** 0214 * The New game menu is selected. 0215 */ 0216 void menuNewGame(); 0217 0218 /** 0219 * The Load game menu is selected. 0220 */ 0221 void menuOpenGame(); 0222 0223 /** 0224 * The Save game menu is selected. 0225 */ 0226 void menuSaveGame(); 0227 0228 /** 0229 * Called when the game is to be ended, e.g. via the abort game menu. 0230 */ 0231 void endGame(); 0232 0233 /** 0234 * Shows the statistics dialog. 0235 */ 0236 void showStatistics(); 0237 0238 /** 0239 * A game hint is asked via the menu. The game will give a 0240 * movement tip. 0241 */ 0242 void askForHint(); 0243 0244 /** 0245 * A new theme is selected from the menu. 0246 * @param idx The theme index 0247 */ 0248 void changeTheme(int idx); 0249 0250 /** 0251 * A move undo request is given via the menu. 0252 */ 0253 void undoMove(); 0254 0255 /** 0256 * A move redo request is given via the menu. 0257 */ 0258 void redoMove(); 0259 0260 /** 0261 * Display the current player to move in the statusbar. 0262 * @param text The text to display 0263 */ 0264 void displayStatusbarMover(const QString &text); 0265 0266 /** 0267 * Display a message in the status bar. 0268 * @param text The message to display 0269 */ 0270 void displayStatusMessage(const QString &text); 0271 0272 /** 0273 * Show the settings dialog. 0274 */ 0275 void configureSettings(); 0276 0277 /** 0278 * SLot if a new game is started from the intro display. 0279 * @param startPlayer Color of the starting player 0280 * @param input0 Input device of player 1 0281 * @param input1 Input device of player 2 0282 * @param aiLevel Level for AI (-1: no change) 0283 */ 0284 void quickStart(COLOUR startPlayer, KGameIO::IOMode input0, KGameIO::IOMode input1, int level); 0285 0286 private: 0287 // The theme manager used 0288 ThemeManager *mTheme; 0289 0290 // The available themes 0291 QHash<QString, QString> mThemeFiles; 0292 0293 // Current theme index 0294 int mThemeIndexNo; 0295 0296 // Default theme 0297 QString mThemeDefault; 0298 0299 // The game view 0300 KWin4View *mView; 0301 0302 // The game document/engine 0303 KWin4Doc *mDoc; 0304 0305 // The graphics scene to use 0306 ReflectionGraphicsScene *mScene; 0307 0308 // Buttons of the network dialog 0309 QGroupBox *mColorGroup; 0310 0311 // The chat dialog 0312 ChatDlg *mMyChatDlg; 0313 0314 // Status bar texts. 0315 QLabel *mStatusMsg; 0316 QLabel *mStatusMover; 0317 }; 0318 0319 #endif // KWIN4_H