~ubuntu-branches/ubuntu/saucy/libkdegames/saucy

« back to all changes in this revision

Viewing changes to libkdegamesprivate/kgame/dialogs/kgamedialog.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell, Rohan Garg, Philip Muškovac, Jonathan Riddell
  • Date: 2013-06-21 01:42:38 UTC
  • mfrom: (1.2.3)
  • Revision ID: package-import@ubuntu.com-20130621014238-mk0kx5llg3m15ua6
Tags: 4:4.10.80-0ubuntu1
[ Rohan Garg ]
* New upstream release

[ Philip Muškovac ]
* Add Qml imports to libkdegames6.install 
* Add new symbols to libkdegames6.symbols

[ Jonathan Riddell ]
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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)
5
 
 
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.
9
 
 
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.
14
 
 
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.
19
 
*/
20
 
 
21
 
// NAMING
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.
27
 
 
28
 
#ifndef __KGAMEDIALOG_H__
29
 
#define __KGAMEDIALOG_H__
30
 
 
31
 
#include <kpagedialog.h>
32
 
#include "../../libkdegamesprivate_export.h"
33
 
#include <QtGui/QVBoxLayout>
34
 
#include <QtGui/QGridLayout>
35
 
class QGridLayout;
36
 
class QVBoxLayout;
37
 
class KVBox;
38
 
 
39
 
class KGame;
40
 
class KPlayer;
41
 
 
42
 
class KGameDialogConfig;
43
 
class KGameDialogGeneralConfig;
44
 
class KGameDialogNetworkConfig;
45
 
class KGameDialogMsgServerConfig;
46
 
class KGameDialogChatConfig;
47
 
class KGameDialogConnectionConfig;
48
 
 
49
 
class KGameDialogPrivate;
50
 
/**
51
 
 * \class KGameDialog kgamedialog.h <KGameDialog>
52
 
 * 
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.
59
 
 *
60
 
 *
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):
65
 
 * \code
66
 
 *      KGameDialog dlg(kgame, i18n("New Game"), localPlayer, this, true,
67
 
 *      ID_CHAT);
68
 
 *      dlg.setDefaultNetworkInfo(port, host); // AB: obsolete!
69
 
 *      dlg.exec();
70
 
 * \endcode
71
 
 * This will create a default modal dialog with the title "New Game". You don't
72
 
 * have to do more than this. 
73
 
 *
74
 
 * @short Main configuration dialog for KGame
75
 
 * @author Andreas Beckermann <b_mann@gmx.de>
76
 
 **/
77
 
class KDEGAMESPRIVATE_EXPORT KGameDialog : public KPageDialog
78
 
{
79
 
        Q_OBJECT
80
 
public:
81
 
 
82
 
        enum ConfigOptions
83
 
        {
84
 
                NoConfig = 0,
85
 
                ChatConfig = 1,
86
 
                GameConfig = 2,
87
 
                NetworkConfig = 4,
88
 
                MsgServerConfig = 8,
89
 
                BanPlayerConfig = 16,
90
 
                AllConfig = 0xffff
91
 
        };
92
 
 
93
 
        /**
94
 
         * Create an empty KGameDialog. You can add widgets using
95
 
         * addConfigPage.
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
102
 
         **/
103
 
        KGameDialog(KGame* g, KPlayer* owner, const QString& title, 
104
 
                        QWidget* parent, bool modal = false);
105
 
        
106
 
        /**
107
 
         * Create a KGameDialog with the standard configuration widgets. This
108
 
         * creates the following widgets:
109
 
         * <ul>
110
 
         * <li> KGameDialogGeneralConfig
111
 
         * <li> KGameDialogNetworkConfig
112
 
         * <li> KGameDialogMsgServerConfig
113
 
         * <li> KGameDialogChatConfig
114
 
         * <li> KGameDialogConnectionConfig
115
 
         * </ul>
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.
120
 
         *
121
 
         * If you want to add further configuration widget you can simply use
122
 
         * addConfigPage
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
134
 
         **/
135
 
        KGameDialog(KGame* g, KPlayer* owner, const QString& title, 
136
 
                        QWidget* parent, long initConfigs = AllConfig, 
137
 
                        int chatMsgId = 15432, bool modal = false);
138
 
 
139
 
        virtual ~KGameDialog();
140
 
 
141
 
 
142
 
        /**
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
146
 
         * KGame object!
147
 
         *
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)
153
 
         **/
154
 
        void setOwner(KPlayer* owner);
155
 
 
156
 
        /**
157
 
         * Change the KGame object this dialog is used for.
158
 
         *
159
 
         * Calls the KGameDialogConfig::setKGame implementation of all
160
 
         * widgets that have been added by addConfigWidget
161
 
         * @param g The new KGame object
162
 
         **/
163
 
        void setKGame(KGame* g);
164
 
 
165
 
        /**
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
170
 
         **/
171
 
        virtual void submitToKGame();
172
 
 
173
 
        /**
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
179
 
         * if parent is 0.
180
 
         **/
181
 
        void addChatWidget(KGameDialogChatConfig* chat, KVBox* parent = 0);
182
 
 
183
 
        /**
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
187
 
         * the game.
188
 
         *
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
193
 
         * page is used.
194
 
         **/
195
 
        void addConnectionList(KGameDialogConnectionConfig* c, KVBox* parent = 0);
196
 
 
197
 
        /**
198
 
         * Add a new page to the dialog. The page will contain you new config
199
 
         * widget and will have your provided title.
200
 
         *
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.
206
 
         **/
207
 
        KVBox* addConfigPage(KGameDialogConfig* widget, const QString& title);
208
 
 
209
 
        /**
210
 
         * @return The QVBox of the given key, The key is from ConfigOptions
211
 
         * Note that not all are supported yet
212
 
         **/
213
 
        KVBox *configPage(ConfigOptions which);
214
 
 
215
 
        /**
216
 
         * @return The default netowrk config. Note that this always returns 0 if
217
 
         * you did not specify NetworkConfig in the constructor!
218
 
         **/
219
 
        KGameDialogNetworkConfig* networkConfig() const;
220
 
 
221
 
        /**
222
 
         * @return The default game config. Note that this always returns 0 if
223
 
         * you did not specify GameConfig in the constructor!
224
 
         **/
225
 
        KGameDialogGeneralConfig* gameConfig() const;
226
 
 
227
 
        /**
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
231
 
         * addConfigPage.
232
 
         **/
233
 
        void addConfigWidget(KGameDialogConfig* widget, QWidget* parent);
234
 
 
235
 
        /**
236
 
         * Used to add the main network config widget in a new page. Use this to
237
 
         * make networkConfig return something useful.
238
 
         **/
239
 
        void addNetworkConfig(KGameDialogNetworkConfig* netConf);
240
 
 
241
 
        /**
242
 
         * Add the main game config widget in a new page. Use this to make 
243
 
         * gameConfig return something useful.
244
 
         **/
245
 
        void addGameConfig(KGameDialogGeneralConfig* conf);
246
 
 
247
 
        /**
248
 
         * Used to add the message server config widget in a new page.
249
 
         **/
250
 
        void addMsgServerConfig(KGameDialogMsgServerConfig* conf);
251
 
 
252
 
protected:
253
 
 
254
 
        /**
255
 
         * This is used to create a dialog containing all the default widgets. 
256
 
         *
257
 
         * You may want to use this if you just want to use your own
258
 
         * configuration widgets which inherit the standard ones.
259
 
         *
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
266
 
         **/
267
 
        void initDefaultDialog(ConfigOptions initConfigs, int chatMsgId = 15432);
268
 
 
269
 
        /**
270
 
         * Go through all config widgets and call their 
271
 
         * KGameDialogConfig::setKGame and KGameDialogConfig::setOwner implementation
272
 
         * 
273
 
         * This function could be private and probably will be very soon.
274
 
         * Don't use it yourself
275
 
         **/
276
 
        void configureConfigWidgets();
277
 
 
278
 
protected Q_SLOTS:
279
 
        /**
280
 
         * Called when the user clicks on Ok. Calls slotApply and
281
 
         * QDialog::accept()
282
 
         **/
283
 
        virtual void slotOk();
284
 
 
285
 
        /**
286
 
         * Just calls submitToKGame()
287
 
         **/
288
 
        virtual void slotApply();
289
 
 
290
 
        /**
291
 
         * Sets the default values for the configuration widgets. Set these
292
 
         * values by (e.g.) setDefaultMaxPlayers()
293
 
         * @deprecated
294
 
         **/
295
 
        virtual void slotDefault();
296
 
 
297
 
        /**
298
 
         * Called when the KGame object is destroyed. Calls setKGame(0) so
299
 
         * that all widgets can disconnect their slots and so on.
300
 
         **/
301
 
        void slotUnsetKGame();
302
 
 
303
 
        /**
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
307
 
         **/
308
 
        void setAdmin(bool isAdmin);
309
 
 
310
 
        /**
311
 
         * Remove a config widget from the widget list. 
312
 
         * @see QObject::destroyed
313
 
         **/
314
 
        void slotRemoveConfigWidget(QObject* configWidget);
315
 
 
316
 
private:
317
 
        void init(KGame*, KPlayer*);
318
 
 
319
 
private:
320
 
        KGameDialogPrivate* const d;
321
 
};
322
 
 
323
 
#endif