Viergewinnt (four-in-a-row) implementation in c++ and QT
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

selectmaster.cpp 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* VierGewinnt - A simple 4-in-a-row network game
  2. *
  3. * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de
  4. * http://www.seba-geek.de
  5. *
  6. * This file is part of VierGewinnt.
  7. *
  8. * VierGewinnt is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * VierGewinnt is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with VierGewinnt. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include "selectmaster.h"
  22. SelectMasterDialog::SelectMasterDialog(QWidget *parent) : QDialog(parent) {
  23. labelhead = new QLabel(tr("Bitte gib einen anderen Masterserver an"));
  24. labelmasteraddr = new QLabel(tr("Master-Server:"));
  25. labelmasterport = new QLabel(tr("Master-Port:"));
  26. editmasteraddr = new QLineEdit;
  27. editmasterport = new QLineEdit;
  28. okcancel = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
  29. connect(okcancel, SIGNAL(accepted()), this, SLOT(checkAndAccept()));
  30. connect(okcancel, SIGNAL(rejected()), this, SLOT(reject()));
  31. layout = new QGridLayout;
  32. layout->addWidget(labelhead, 0, 0, 1, 2);
  33. layout->addWidget(labelmasteraddr, 1, 0);
  34. layout->addWidget(editmasteraddr, 1, 1);
  35. layout->addWidget(labelmasterport, 2, 0);
  36. layout->addWidget(editmasterport, 2, 1);
  37. layout->addWidget(okcancel, 3, 0, 1, 2);
  38. setLayout(layout);
  39. setWindowTitle(tr("Master-Server ändern"));
  40. setModal(Qt::WindowModal);
  41. }
  42. void SelectMasterDialog::checkAndAccept() {
  43. if(editmasteraddr->text()=="") {
  44. QMessageBox msgbox(this);
  45. msgbox.setText(tr("Der Master-Server ist ungültig"));
  46. msgbox.exec();
  47. return;
  48. }
  49. int tmpport = editmasterport->text().toInt();
  50. if(tmpport<1||tmpport>65535) {
  51. QMessageBox msgbox(this);
  52. msgbox.setText(tr("Der Master-Port ist ungültig"));
  53. msgbox.exec();
  54. return;
  55. }
  56. masterserver = editmasteraddr->text();
  57. masterport = tmpport;
  58. accept();
  59. }
  60. void SelectMasterDialog::setData(QString srv, int port) {
  61. masterserver = srv;
  62. masterport = port;
  63. editmasteraddr->setText(masterserver);
  64. std::stringstream str;
  65. str << masterport;
  66. editmasterport->setText(QString(str.str().c_str()));
  67. }
  68. QString SelectMasterDialog::getMasterServer() {
  69. return masterserver;
  70. }
  71. int SelectMasterDialog::getMasterPort() {
  72. return masterport;
  73. }