File indexing completed on 2024-04-28 04:02:07

0001 /*
0002     This file is part of the KDE games library
0003     SPDX-FileCopyrightText: 2001 Andreas Beckermann (b_mann@gmx.de)
0004     SPDX-FileCopyrightText: 2001 Martin Heni (kde at heni-online.de)
0005 
0006     SPDX-License-Identifier: LGPL-2.0-only
0007 */
0008 
0009 // NAMING
0010 // please follow these naming rules if you add/change classes:
0011 // the main dialog is named KGameDialog and the base config widget
0012 // KGameDialogConfig. All config widgets are named KGameDialogXYZConfig (where
0013 // XYZ = the name of the config widget, like "general" or "network") and are
0014 // inherited from KGameDialogConfig.
0015 
0016 #ifndef __KGAMEDIALOG_H__
0017 #define __KGAMEDIALOG_H__
0018 
0019 // KF
0020 #include <KPageDialog>
0021 // Qt
0022 
0023 class KGame;
0024 class KPlayer;
0025 
0026 class KGameDialogConfig;
0027 class KGameDialogNetworkConfig;
0028 
0029 class KGameDialogPrivate;
0030 /**
0031  * \class KGameDialog kgamedialog.h <KGameDialog>
0032  *
0033  * TODO: rewrite entire documentation. Nearly nothing is valid anymore.
0034  * The main configuration dialog for KGame. Here all players meat each other,
0035  * every player can see how many players connected (and their names) and the
0036  * ADMIN can even "kick" players out. You can talk to each other (using
0037  * KGameChat and the ADMIN can define the maxPlayers/minPlayers as well as the
0038  * number of computer players.
0039  *
0040  *
0041  * AB: setDefaultXYZ is obsolete!!
0042  * You will usually create an instance of KGameDialog or any derived class and
0043  * call setDefaultXYZ methods. Example (maybe
0044  * obsoleted parameters - docu is currently changing very fast):
0045  * \code
0046  *  KGameDialog dlg(kgame, i18n("New Game"), localPlayer, this, true,
0047  *  ID_CHAT);
0048  *  dlg.setDefaultNetworkInfo(port, host); // AB: obsolete!
0049  *  dlg.exec();
0050  * \endcode
0051  * This will create a default modal dialog with the title "New Game". You don't
0052  * have to do more than this.
0053  *
0054  * @short Main configuration dialog for KGame
0055  * @author Andreas Beckermann <b_mann@gmx.de>
0056  */
0057 class KGameDialog : public KPageDialog
0058 {
0059     Q_OBJECT
0060 public:
0061     /**
0062      * Create a KGameDialog with the standard configuration widgets. This
0063      * creates the following widgets:
0064      * <ul>
0065      * <li> KGameDialogNetworkConfig
0066      * </ul>
0067      * If you want to use your own implementations (or none) of the widgets
0068      * above you should subclass KGameDialog.
0069      *
0070      * If you want to add further configuration widget you can simply use
0071      * addConfigPage
0072      * @param g The KGame object of this game
0073      * @param owner The KPlayer object who is responsible for this
0074      * dialog, aka "the local player"
0075      * @param title The title of the dialog - see QDialog::setWindowTitle
0076      * @param parent The parent of the dialog
0077      * @param modal Whether the dialog is modal or not
0078      * @param initConfigs whether the default KGameDialogConfig widgets
0079      * shall be created using initDefaultDialog. Use false if you want
0080      * to use custom widgets.
0081      * @param chatMsgId The ID of Chat messages. See KGameChat. Unused
0082      * if initConfigs = false
0083      */
0084     KGameDialog(KGame *g, KPlayer *owner, const QString &title, QWidget *parent);
0085 
0086     ~KGameDialog() override;
0087 
0088     /**
0089      * Change the owner of the dialog. This will be used as the fromPlayer in
0090      * KGameChat and will receive the entered player name.
0091      * @param owner The owner of the dialog. It must already be added to the
0092      * KGame object!
0093      *
0094      * Calls the KGameDialogConfig::setOwner implementation of all
0095      * widgets that have been added by addConfigWidget
0096      * @param owner The new owner player of this dialog must already be
0097      * added to the KGame object. Can even be NULL (then no player
0098      * configuration is made)
0099      */
0100     void setOwner(KPlayer *owner);
0101 
0102     /**
0103      * Change the KGame object this dialog is used for.
0104      *
0105      * Calls the KGameDialogConfig::setKGame implementation of all
0106      * widgets that have been added by addConfigWidget
0107      * @param g The new KGame object
0108      */
0109     void setKGame(KGame *g);
0110 
0111     /**
0112      * This will submit all configuration data to the KGame object.
0113      * Automatically called by slotApply and slotOk
0114      * There is no need to replace this unless you
0115      * want to add widgets which are not derived from those classes
0116      */
0117     virtual void submitToKGame();
0118 
0119     /**
0120      * Add a new page to the dialog. The page will contain you new config
0121      * widget and will have your provided title.
0122      *
0123      * The widget will be reparented to this dialog. This also calls
0124      * KGameDialogConfig::setKGame and KGameDialogConfig::setOwner.
0125      * @param widget The new config widget
0126      * @param title The title of the newly added page.
0127      * @return The newly added page which contains your config widget.
0128      */
0129     QWidget *addConfigPage(KGameDialogConfig *widget, const QString &title);
0130 
0131     /**
0132      * @return The QVBox of the given key, The key is from ConfigOptions
0133      * Note that not all are supported yet
0134      */
0135     QWidget *configPage();
0136 
0137     /**
0138      * @return The default network config. Note that this always returns 0 if
0139      * you did not specify NetworkConfig in the constructor!
0140      */
0141     KGameDialogNetworkConfig *networkConfig() const;
0142 
0143     /**
0144      * Add a config widget to the specified parent. Usually you call
0145      * addConfigPage for one widget and addConfigWidget for another to add
0146      * it to the same page. Just use the returned page of
0147      * addConfigPage.
0148      */
0149     void addConfigWidget(KGameDialogConfig *widget, QWidget *parent);
0150 
0151     /**
0152      * Used to add the main network config widget in a new page. Use this to
0153      * make networkConfig return something useful.
0154      */
0155     void addNetworkConfig(KGameDialogNetworkConfig *netConf);
0156 
0157 protected Q_SLOTS:
0158     /**
0159      * Called when the user clicks on Ok. Calls slotApply and
0160      * QDialog::accept()
0161      */
0162     virtual void slotOk();
0163 
0164     /**
0165      * Just calls submitToKGame()
0166      */
0167     virtual void slotApply();
0168 
0169     /**
0170      * Sets the default values for the configuration widgets. Set these
0171      * values by (e.g.) setDefaultMaxPlayers()
0172      * @deprecated
0173      */
0174     virtual void slotDefault();
0175 
0176     /**
0177      * Called when the KGame object is destroyed. Calls setKGame(0) so
0178      * that all widgets can disconnect their slots and so on.
0179      */
0180     void slotUnsetKGame();
0181 
0182     /**
0183      * Called when the ADMIN status of this KGame client changes. See
0184      * KGameNetwork::signalAdminStatusChanged
0185      * @param isAdmin TRUE if this client is now the ADMIN otherwise FALSE
0186      */
0187     void setAdmin(bool isAdmin);
0188 
0189     /**
0190      * Remove a config widget from the widget list.
0191      * @see QObject::destroyed
0192      */
0193     void slotRemoveConfigWidget(QObject *configWidget);
0194 
0195 private:
0196     void init(KGame *, KPlayer *);
0197 
0198 private:
0199     KGameDialogPrivate *const d;
0200 };
0201 
0202 #endif