2
This file is part of the KDE games library
3
Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
4
Copyright (C) 2001 Martin Heni (kde at heni-online.de)
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public
8
License version 2 as published by the Free Software Foundation.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
Boston, MA 02110-1301, USA.
22
// please follow these naming rules if you add/change classes:
23
// the main dialog is named KGameDialog and the base config widget
24
// KGameDialogConfig. All config widgets are named KGameDialogXYZConfig (where
25
// XYZ = the name of the config widget, like "general" or "network") and are
26
// inherited from KGameDialogConfig.
28
#ifndef __KGAMEDIALOG_H__
29
#define __KGAMEDIALOG_H__
31
#include <kpagedialog.h>
32
#include "../../libkdegamesprivate_export.h"
33
#include <QtGui/QVBoxLayout>
34
#include <QtGui/QGridLayout>
42
class KGameDialogConfig;
43
class KGameDialogGeneralConfig;
44
class KGameDialogNetworkConfig;
45
class KGameDialogMsgServerConfig;
46
class KGameDialogChatConfig;
47
class KGameDialogConnectionConfig;
49
class KGameDialogPrivate;
51
* \class KGameDialog kgamedialog.h <KGameDialog>
53
* TODO: rewrite entire documentation. Nearly nothing is valid anymore.
54
* The main configuration dialog for KGame. Here all players meat each other,
55
* every player can see how many players connected (and their names) and the
56
* ADMIN can even "kick" players out. You can talk to each other (using
57
* KGameChat and the ADMIN can define the maxPlayers/minPlayers as well as the
58
* number of computer players.
61
* AB: setDefaultXYZ is obsolete!!
62
* You will usually create an instance of KGameDialog or any derived class and
63
* call setDefaultXYZ methods. Example (maybe
64
* obsoleted parameters - docu is currently changing very fast):
66
* KGameDialog dlg(kgame, i18n("New Game"), localPlayer, this, true,
68
* dlg.setDefaultNetworkInfo(port, host); // AB: obsolete!
71
* This will create a default modal dialog with the title "New Game". You don't
72
* have to do more than this.
74
* @short Main configuration dialog for KGame
75
* @author Andreas Beckermann <b_mann@gmx.de>
77
class KDEGAMESPRIVATE_EXPORT KGameDialog : public KPageDialog
94
* Create an empty KGameDialog. You can add widgets using
96
* @param g The KGame object of this game
97
* @param owner The KPlayer object who is responsible for this
98
* dialog, aka "the local player"
99
* @param title The title of the dialog - see KDialog::setCaption
100
* @param parent The parent of the dialog
101
* @param modal Whether the dialog is modal or not
103
KGameDialog(KGame* g, KPlayer* owner, const QString& title,
104
QWidget* parent, bool modal = false);
107
* Create a KGameDialog with the standard configuration widgets. This
108
* creates the following widgets:
110
* <li> KGameDialogGeneralConfig
111
* <li> KGameDialogNetworkConfig
112
* <li> KGameDialogMsgServerConfig
113
* <li> KGameDialogChatConfig
114
* <li> KGameDialogConnectionConfig
116
* If you want to use your own implementations (or none) of the widgets
117
* above you should subclass KGameDialog. Use addGameConfig,
118
* addNetworkConfig, addMsgConfig, addChatWidget and
119
* addConnectionList in this case.
121
* If you want to add further configuration widget you can simply use
123
* @param g The KGame object of this game
124
* @param owner The KPlayer object who is responsible for this
125
* dialog, aka "the local player"
126
* @param title The title of the dialog - see KDialog::setCaption
127
* @param parent The parent of the dialog
128
* @param modal Whether the dialog is modal or not
129
* @param initConfigs whether the default KGameDialogConfig widgets
130
* shall be created using initDefaultDialog. Use false if you want
131
* to use custom widgets.
132
* @param chatMsgId The ID of Chat messages. See KGameChat. Unused
133
* if initConfigs = false
135
KGameDialog(KGame* g, KPlayer* owner, const QString& title,
136
QWidget* parent, long initConfigs = AllConfig,
137
int chatMsgId = 15432, bool modal = false);
139
virtual ~KGameDialog();
143
* Change the owner of the dialog. This will be used as the fromPlayer in
144
* KGameChat and will receive the entered player name.
145
* @param owner The owner of the dialog. It must already be added to the
148
* Calls the KGameDialogConfig::setOwner implementation of all
149
* widgets that have been added by addConfigWidget
150
* @param owner The new owner player of this dialog must already be
151
* added to the KGame object. Can even be NULL (then no player
152
* configuration is made)
154
void setOwner(KPlayer* owner);
157
* Change the KGame object this dialog is used for.
159
* Calls the KGameDialogConfig::setKGame implementation of all
160
* widgets that have been added by addConfigWidget
161
* @param g The new KGame object
163
void setKGame(KGame* g);
166
* This will submit all configuration data to the KGame object.
167
* Automatically called by slotApply and slotOk
168
* There is no need to replace this unless you
169
* want to add widgets which are not derived from those classes
171
virtual void submitToKGame();
174
* Adds a KGameChat to the dialog. If no parent is specified the
175
* game page will be used.
176
* @param chat The chat widget
177
* @param parent The parent of the chat widget. This MUST be an
178
* already added config widget. Note that the game page will be used
181
void addChatWidget(KGameDialogChatConfig* chat, KVBox* parent = 0);
184
* Add a connection list to the dialog. The list consists of a
185
* KLisBox containing all players in the current game (see
186
* KGame::playerList). The admin can "ban" players, ie kick them out of
189
* This is another not-really-config-config-widget. It just displays the
190
* connections and lets you ban players.
191
* @param c The KGameDialogConnectionConfig object
192
* @param parent The parent of the widget. If 0 the networkConfig
195
void addConnectionList(KGameDialogConnectionConfig* c, KVBox* parent = 0);
198
* Add a new page to the dialog. The page will contain you new config
199
* widget and will have your provided title.
201
* The widget will be reparented to this dialog. This also calls
202
* KGameDialogConfig::setKGame and KGameDialogConfig::setOwner.
203
* @param widget The new config widget
204
* @param title The title of the newly added page.
205
* @return The newly added page which contains your config widget.
207
KVBox* addConfigPage(KGameDialogConfig* widget, const QString& title);
210
* @return The QVBox of the given key, The key is from ConfigOptions
211
* Note that not all are supported yet
213
KVBox *configPage(ConfigOptions which);
216
* @return The default netowrk config. Note that this always returns 0 if
217
* you did not specify NetworkConfig in the constructor!
219
KGameDialogNetworkConfig* networkConfig() const;
222
* @return The default game config. Note that this always returns 0 if
223
* you did not specify GameConfig in the constructor!
225
KGameDialogGeneralConfig* gameConfig() const;
228
* Add a config widget to the specified parent. Usually you call
229
* addConfigPage for one widget and addConfigWidget for another to add
230
* it to the same page. Just use the returned page of
233
void addConfigWidget(KGameDialogConfig* widget, QWidget* parent);
236
* Used to add the main network config widget in a new page. Use this to
237
* make networkConfig return something useful.
239
void addNetworkConfig(KGameDialogNetworkConfig* netConf);
242
* Add the main game config widget in a new page. Use this to make
243
* gameConfig return something useful.
245
void addGameConfig(KGameDialogGeneralConfig* conf);
248
* Used to add the message server config widget in a new page.
250
void addMsgServerConfig(KGameDialogMsgServerConfig* conf);
255
* This is used to create a dialog containing all the default widgets.
257
* You may want to use this if you just want to use your own
258
* configuration widgets which inherit the standard ones.
260
* Note that if one of the widgets is NULL the default implementation
261
* will be used! (except the chat widget - you need to create it
262
* yourself as you have to provide a message id)
263
* @param initConfigs The widgets to be created
264
* @param chatMsgId The msgid for the chat config (only if specified in
265
* initConfigs) - see KGameDialogChatConfig
267
void initDefaultDialog(ConfigOptions initConfigs, int chatMsgId = 15432);
270
* Go through all config widgets and call their
271
* KGameDialogConfig::setKGame and KGameDialogConfig::setOwner implementation
273
* This function could be private and probably will be very soon.
274
* Don't use it yourself
276
void configureConfigWidgets();
280
* Called when the user clicks on Ok. Calls slotApply and
283
virtual void slotOk();
286
* Just calls submitToKGame()
288
virtual void slotApply();
291
* Sets the default values for the configuration widgets. Set these
292
* values by (e.g.) setDefaultMaxPlayers()
295
virtual void slotDefault();
298
* Called when the KGame object is destroyed. Calls setKGame(0) so
299
* that all widgets can disconnect their slots and so on.
301
void slotUnsetKGame();
304
* Called when the ADMIN status of this KGame client changes. See
305
* KGameNetwork::signalAdminStatusChanged
306
* @param isAdmin TRUE if this client is now the ADMIN otherwise FALSE
308
void setAdmin(bool isAdmin);
311
* Remove a config widget from the widget list.
312
* @see QObject::destroyed
314
void slotRemoveConfigWidget(QObject* configWidget);
317
void init(KGame*, KPlayer*);
320
KGameDialogPrivate* const d;