libkdegames Library API Documentation

kgameconnectdialog.cpp

00001 /* 00002 This file is part of the KDE games library 00003 Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de) 00004 Copyright (C) 2001 Martin Heni (martin@heni-online.de) 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License version 2 as published by the Free Software Foundation. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, USA. 00019 */ 00020 00021 00022 #include "kgameconnectdialog.h" 00023 00024 #include <knuminput.h> 00025 #include <klocale.h> 00026 00027 #include <qlineedit.h> 00028 #include <qvbuttongroup.h> 00029 #include <qlayout.h> 00030 #include <qradiobutton.h> 00031 #include <qlabel.h> 00032 #include <qpushbutton.h> 00033 #include <qgrid.h> 00034 00035 class KGameConnectWidgetPrivate 00036 { 00037 public: 00038 KGameConnectWidgetPrivate() 00039 { 00040 mPort = 0; 00041 mHost = 0; 00042 mButtonGroup = 0; 00043 } 00044 00045 KIntNumInput* mPort; 00046 QLineEdit* mHost; //KLineEdit? 00047 QVButtonGroup* mButtonGroup; 00048 }; 00049 00050 KGameConnectWidget::KGameConnectWidget(QWidget* parent) : QWidget(parent) 00051 { 00052 d = new KGameConnectWidgetPrivate; 00053 00054 QVBoxLayout* vb = new QVBoxLayout(this, KDialog::spacingHint()); 00055 d->mButtonGroup = new QVButtonGroup(this); 00056 vb->addWidget(d->mButtonGroup); 00057 connect(d->mButtonGroup, SIGNAL(clicked(int)), this, SLOT(slotTypeChanged(int))); 00058 (void)new QRadioButton(i18n("Create a network game"), d->mButtonGroup); 00059 (void)new QRadioButton(i18n("Join a network game"), d->mButtonGroup); 00060 00061 QGrid* g = new QGrid(2, this); 00062 vb->addWidget(g); 00063 g->setSpacing(KDialog::spacingHint()); 00064 (void)new QLabel(i18n("Port to connect to:"), g); 00065 d->mPort = new KIntNumInput(g); 00066 (void)new QLabel(i18n("Host to connect to:"), g); 00067 d->mHost = new QLineEdit(g); 00068 00069 QPushButton *button=new QPushButton(i18n("&Start Network"), this); 00070 connect(button, SIGNAL(clicked()), this, SIGNAL(signalNetworkSetup())); 00071 vb->addWidget(button); 00072 } 00073 00074 KGameConnectWidget::~KGameConnectWidget() 00075 { 00076 delete d; 00077 } 00078 00079 QString KGameConnectWidget::host() const 00080 { 00081 if (d->mHost->isEnabled()) { 00082 return d->mHost->text(); 00083 } else { 00084 return QString::null; 00085 } 00086 } 00087 00088 unsigned short int KGameConnectWidget::port() const 00089 { 00090 return d->mPort->value(); 00091 } 00092 00093 void KGameConnectWidget::setHost(const QString& host) 00094 { 00095 d->mHost->setText(host); 00096 } 00097 00098 void KGameConnectWidget::setPort(unsigned short int port) 00099 { 00100 d->mPort->setValue(port); 00101 } 00102 00103 void KGameConnectWidget::setDefault(int state) 00104 { 00105 d->mButtonGroup->setButton(state); 00106 slotTypeChanged(state); 00107 } 00108 00109 void KGameConnectWidget::slotTypeChanged(int t) 00110 { 00111 if (t == 0) { 00112 d->mHost->setEnabled(false); 00113 } else if (t == 1) { 00114 d->mHost->setEnabled(true); 00115 } 00116 emit signalServerTypeChanged(t); 00117 } 00118 00119 class KGameConnectDialogPrivate 00120 { 00121 public: 00122 KGameConnectDialogPrivate() 00123 { 00124 mConnect = 0; 00125 } 00126 00127 KGameConnectWidget* mConnect; 00128 }; 00129 00130 // buttonmask =Ok|Cancel 00131 KGameConnectDialog::KGameConnectDialog(QWidget* parent,int buttonmask) : KDialogBase(Plain, 00132 i18n("Network Game"),buttonmask , Ok, parent, 0, true, buttonmask!=0) 00133 { 00134 d = new KGameConnectDialogPrivate; 00135 QVBoxLayout* vb = new QVBoxLayout(plainPage(), spacingHint()); 00136 d->mConnect = new KGameConnectWidget(plainPage()); 00137 vb->addWidget(d->mConnect); 00138 } 00139 00140 KGameConnectDialog::~KGameConnectDialog() 00141 { 00142 delete d; 00143 } 00144 00145 int KGameConnectDialog::initConnection( unsigned short int& port, 00146 QString& host, QWidget* parent, bool server) 00147 { 00148 KGameConnectDialog d(parent); 00149 d.setHost(host); 00150 d.setPort(port); 00151 if (server) { 00152 d.setDefault(0); 00153 } else { 00154 d.setDefault(1); 00155 } 00156 00157 int result = d.exec(); 00158 if (result == QDialog::Accepted) { 00159 host = d.host(); 00160 port = d.port(); 00161 } 00162 return result; 00163 } 00164 00165 QString KGameConnectDialog::host() const 00166 { 00167 return d->mConnect->host(); 00168 } 00169 00170 unsigned short int KGameConnectDialog::port() const 00171 { 00172 return d->mConnect->port(); 00173 } 00174 00175 void KGameConnectDialog::setHost(const QString& host) 00176 { 00177 d->mConnect->setHost(host); 00178 } 00179 00180 void KGameConnectDialog::setPort(unsigned short int port) 00181 { 00182 d->mConnect->setPort(port); 00183 } 00184 00185 void KGameConnectDialog::setDefault(int state) 00186 { 00187 d->mConnect->setDefault(state); 00188 } 00189 00190 00191 00192 #include "kgameconnectdialog.moc" 00193
KDE Logo
This file is part of the documentation for libkdegames Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 13 12:48:52 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003