home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kgame / kgamedialog.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  10.3 KB  |  321 lines

  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 (martin@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 <kdialogbase.h>
  32. #include <kdemacros.h>
  33. class QGridLayout;
  34. class QVBoxLayout;
  35. class QListBoxItem;
  36.  
  37. class KGame;
  38. class KPlayer;
  39. class KGamePropertyBase;
  40.  
  41. class KGameDialogConfig;
  42. class KGameDialogGeneralConfig;
  43. class KGameDialogNetworkConfig;
  44. class KGameDialogMsgServerConfig;
  45. class KGameDialogChatConfig;
  46. class KGameDialogConnectionConfig;
  47.  
  48. class KGameDialogPrivate;
  49. /**
  50.  * TODO: rewrite entire documentation. Nearly nothing is valid anymore.
  51.  * The main configuration dialog for KGame. Here all players meat each other,
  52.  * every player can see how many players connected (and their names) and the
  53.  * ADMIN can even "kick" players out. You can talk to each other (using 
  54.  * KGameChat and the ADMIN can define the maxPlayers/minPlayers as well as the
  55.  * number of computer players.
  56.  *
  57.  *
  58.  * AB: setDefaultXYZ is obsolete!!
  59.  * You will usually create an instance of KGameDialog or any derived class and
  60.  * call setDefaultXYZ methods. Example (maybe
  61.  * obsoleted parameters - docu is currently changing very fast):
  62.  * \code
  63.  *     KGameDialog dlg(kgame, i18n("New Game"), localPlayer, this, true,
  64.  *     ID_CHAT);
  65.  *     dlg.setDefaultNetworkInfo(port, host); // AB: obsolete!
  66.  *     dlg.exec();
  67.  * \endcode
  68.  * This will create a default modal dialog with the title "New Game". You don't
  69.  * have to do more than this. 
  70.  *
  71.  * @short Main configuration dialog for KGame
  72.  * @author Andreas Beckermann <b_mann@gmx.de>
  73.  **/
  74. class KDE_EXPORT KGameDialog : public KDialogBase
  75. {
  76.     Q_OBJECT
  77. public:
  78.  
  79.     enum ConfigOptions
  80.     {
  81.         NoConfig = 0,
  82.         ChatConfig = 1,
  83.         GameConfig = 2,
  84.         NetworkConfig = 4,
  85.         MsgServerConfig = 8,
  86.         BanPlayerConfig = 16,
  87.         AllConfig = 0xffff
  88.     };
  89.  
  90.     /**
  91.      * Create an empty KGameDialog. You can add widgets using
  92.      * addConfigPage.
  93.      * @param g The KGame object of this game
  94.      * @param owner The KPlayer object who is responsible for this
  95.      * dialog, aka "the local player"
  96.      * @param title The title of the dialog - see KDialog::setCaption
  97.      * @param parent The parent of the dialog
  98.      * @param modal Whether the dialog is modal or not
  99.      **/
  100.     KGameDialog(KGame* g, KPlayer* owner, const QString& title, 
  101.             QWidget* parent, bool modal = false);
  102.     
  103.     /**
  104.      * Create a KGameDialog with the standard configuration widgets. This
  105.      * creates the following widgets:
  106.      * <ul>
  107.      * <li> KGameDialogGeneralConfig
  108.      * <li> KGameDialogNetworkConfig
  109.      * <li> KGameDialogMsgServerConfig
  110.      * <li> KGameDialogChatConfig
  111.      * <li> KGameDialogConnectionConfig
  112.      * </ul>
  113.      * If you want to use your own implementations (or none) of the widgets
  114.      * above you should subclass KGameDialog. Use addGameConfig, 
  115.      * addNetworkConfig, addMsgConfig, addChatWidget and 
  116.      * addConnectionList in this case.
  117.      *
  118.      * If you want to add further configuration widget you can simply use
  119.      * addConfigPage
  120.      * @param g The KGame object of this game
  121.      * @param owner The KPlayer object who is responsible for this
  122.      * dialog, aka "the local player"
  123.      * @param title The title of the dialog - see KDialog::setCaption
  124.      * @param parent The parent of the dialog
  125.      * @param modal Whether the dialog is modal or not
  126.      * @param initConfigs whether the default KGameDialogConfig widgets
  127.      * shall be created using initDefaultDialog. Use false if you want
  128.      * to use custom widgets.
  129.      * @param chatMsgId The ID of Chat messages. See KGameChat. Unused
  130.      * if initConfigs = false
  131.      **/
  132.     KGameDialog(KGame* g, KPlayer* owner, const QString& title, 
  133.             QWidget* parent, long initConfigs = AllConfig, 
  134.             int chatMsgId = 15432, bool modal = false);
  135.  
  136.     virtual ~KGameDialog();
  137.  
  138.  
  139.     /**
  140.      * Change the owner of the dialog. This will be used as the fromPlayer in
  141.      * KGameChat and will receive the entered player name.
  142.      * @param owner The owner of the dialog. It must already be added to the
  143.      * KGame object!
  144.      *
  145.      * Calls the KGameDialogConfig::setOwner implementation of all
  146.      * widgets that have been added by addConfigWidget
  147.      * @param owner The new owner player of this dialog must already be
  148.      * added to the KGame object. Can even be NULL (then no player
  149.      * configuration is made)
  150.      **/
  151.     void setOwner(KPlayer* owner);
  152.  
  153.     /**
  154.      * Change the KGame object this dialog is used for.
  155.      *
  156.      * Calls the KGameDialogConfig::setKGame implementation of all
  157.      * widgets that have been added by addConfigWidget
  158.      * @param g The new KGame object
  159.      **/
  160.     void setKGame(KGame* g);
  161.  
  162.     /**
  163.      * This will submit all configuration data to the KGame object.
  164.      * Automatically called by slotApply and slotOk
  165.      * There is no need to replace this unless you
  166.      * want to add widgets which are not derived from those classes
  167.      **/
  168.     virtual void submitToKGame();
  169.  
  170.     /**
  171.      * Adds a KGameChat to the dialog. If no parent is specified the
  172.      * game page will be used.
  173.      * @param chat The chat widget
  174.      * @param parent The parent of the chat widget. This MUST be an
  175.      * already added config widget. Note that the game page will be used
  176.      * if parent is 0.
  177.      **/
  178.     void addChatWidget(KGameDialogChatConfig* chat, QVBox* parent = 0);
  179.  
  180.     /**
  181.      * Add a connection list to the dialog. The list consists of a
  182.      * KLisBox containing all players in the current game (see
  183.      * KGame::playerList). The admin can "ban" players, ie kick them out of
  184.      * the game.
  185.      *
  186.      * This is another not-really-config-config-widget. It just displays the
  187.      * connections and lets you ban players.
  188.      * @param c The KGameDialogConnectionConfig object
  189.      * @param parent The parent of the widget. If 0 the networkConfig
  190.      * page is used.
  191.      **/
  192.     void addConnectionList(KGameDialogConnectionConfig* c, QVBox* parent = 0);
  193.  
  194.     /**
  195.      * Add a new page to the dialog. The page will contain you new config
  196.      * widget and will have your provided title.
  197.      *
  198.      * The widget will be reparented to this dialog. This also calls
  199.      * KGameDialogConfig::setKGame and KGameDialogConfig::setOwner.
  200.      * @param widget The new config widget
  201.      * @param title The title of the newly added page.
  202.      * @return The newly added page which contains your config widget.
  203.      **/
  204.     QVBox* addConfigPage(KGameDialogConfig* widget, const QString& title);
  205.  
  206.     /**
  207.      * @return The QVBox of the given key, The key is from ConfigOptions
  208.      * Note that not all are supported yet
  209.      **/
  210.     QVBox *configPage(ConfigOptions which);
  211.  
  212.     /**
  213.      * @return The default netowrk config. Note that this always returns 0 if
  214.      * you did not specify NetworkConfig in the constructor!
  215.      **/
  216.     KGameDialogNetworkConfig* networkConfig() const;
  217.  
  218.     /**
  219.      * @return The default game config. Note that this always returns 0 if
  220.      * you did not specify GameConfig in the constructor!
  221.      **/
  222.     KGameDialogGeneralConfig* gameConfig() const;
  223.  
  224.     /**
  225.      * Add a config widget to the specified parent. Usually you call
  226.      * addConfigPage for one widget and addConfigWidget for another to add
  227.      * it to the same page. Just use the returned page of
  228.      * addConfigPage.
  229.      **/
  230.     void addConfigWidget(KGameDialogConfig* widget, QWidget* parent);
  231.  
  232.     /**
  233.      * Used to add the main network config widget in a new page. Use this to
  234.      * make networkConfig return something useful.
  235.      **/
  236.     void addNetworkConfig(KGameDialogNetworkConfig* netConf);
  237.  
  238.     /**
  239.      * Add the main game config widget in a new page. Use this to make 
  240.      * gameConfig return something useful.
  241.      **/
  242.     void addGameConfig(KGameDialogGeneralConfig* conf);
  243.  
  244.     /**
  245.      * Used to add the message server config widget in a new page.
  246.      **/
  247.     void addMsgServerConfig(KGameDialogMsgServerConfig* conf);
  248.  
  249. protected:
  250.  
  251.     /**
  252.      * This is used to create a dialog containing all the default widgets. 
  253.      *
  254.      * You may want to use this if you just want to use your own
  255.      * configuration widgets which inherit the standard ones.
  256.      *
  257.      * Note that if one of the widgets is NULL the default implementation
  258.      * will be used! (except the chat widget - you need to create it
  259.      * yourself as you have to provide a message id)
  260.      * @param initConfigs The widgets to be created
  261.      * @param chatMsgId The msgid for the chat config (only if specified in
  262.      * initConfigs) - see KGameDialogChatConfig
  263.      **/
  264.     void initDefaultDialog(ConfigOptions initConfigs, int chatMsgId = 15432);
  265.  
  266.     /**
  267.      * Go through all config widgets and call their 
  268.      * KGameDialogConfig::setKGame and KGameDialogConfig::setOwner implementation
  269.      * 
  270.      * This function could be private and probably will be very soon.
  271.      * Don't use it yourself
  272.      **/
  273.     void configureConfigWidgets();
  274.  
  275. protected slots:
  276.     /**
  277.      * Called when the user clicks on Ok. Calls slotApply and
  278.      * QDialog::accept()
  279.      **/
  280.     virtual void slotOk();
  281.  
  282.     /**
  283.      * Just calls submitToKGame()
  284.      **/
  285.     virtual void slotApply();
  286.  
  287.     /**
  288.      * Sets the default values for the configuration widgets. Set these
  289.      * values by (e.g.) setDefaultMaxPlayers()
  290.      * @deprecated
  291.      **/
  292.     virtual void slotDefault();
  293.  
  294.     /**
  295.      * Called when the KGame object is destroyed. Calls setKGame(0) so
  296.      * that all widgets can disconnect their slots and so on.
  297.      **/
  298.     void slotUnsetKGame();
  299.  
  300.     /**
  301.      * Called when the ADMIN status of this KGame client changes. See 
  302.      * KGameNetwork::signalAdminStatusChanged
  303.      * @param isAdmin TRUE if this client is now the ADMIN otherwise FALSE
  304.      **/
  305.     void setAdmin(bool isAdmin);
  306.  
  307.     /**
  308.      * Remove a config widget from the widget list. 
  309.      * @see QObject::destroyed
  310.      **/
  311.     void slotRemoveConfigWidget(QObject* configWidget);
  312.  
  313. private:
  314.     void init(KGame*, KPlayer*);
  315.  
  316. private:
  317.     KGameDialogPrivate* d;
  318. };
  319.  
  320. #endif
  321.