Dialog.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "Dialog.h"
  2. #include "options.h"
  3. #include <QBoxLayout>
  4. #include <QLineEdit>
  5. #include <QTimeEdit>
  6. #include <QTime>
  7. #include <QDialogButtonBox>
  8. #include <QLabel>
  9. #include <QFormLayout>
  10. #include <QCheckBox>
  11. Dialog::Dialog(Options *option, QWidget *parent) :
  12. QDialog(parent),
  13. _option(option)
  14. {
  15. QHBoxLayout *layoutLineEdit = new QHBoxLayout;
  16. QVBoxLayout *layoutDialog = new QVBoxLayout;
  17. QFormLayout *layoutForm = new QFormLayout;
  18. QDialogButtonBox *boutonJouer = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
  19. checkBoxSon = new QCheckBox();
  20. checkBoxSon->setChecked(_option->son());
  21. spinTempsDepart = new QTimeEdit;
  22. spinTempsDepart->setTimeRange(QTime(0,0,5,0), QTime(3,0,0,0));
  23. spinTempsDepart->setTime(_option->tempsDepart());
  24. spinTempsDepart->setDisplayFormat("HH:mm:ss");
  25. joueur1LineEdit = new QLineEdit(_option->nomJoueur1() , this);
  26. joueur2LineEdit = new QLineEdit(_option->nomJoueur2() , this);
  27. joueur1LineEdit->selectAll();
  28. layoutLineEdit->addWidget(joueur1LineEdit);
  29. layoutLineEdit->addWidget(joueur2LineEdit);
  30. layoutForm->addRow("Son", checkBoxSon);
  31. layoutForm->addRow("Temps de départ", spinTempsDepart);
  32. layoutDialog->addLayout(layoutLineEdit);
  33. layoutDialog->addLayout(layoutForm);
  34. layoutDialog->addWidget(boutonJouer);
  35. setLayout(layoutDialog);
  36. QObject::connect(boutonJouer , SIGNAL(accepted()) , this, SLOT(accept()));
  37. QObject::connect(boutonJouer , SIGNAL(rejected()) , this, SLOT(close()));
  38. }
  39. Dialog::~Dialog() {
  40. }
  41. void Dialog::accept() {
  42. _option->setNomJoueur1(joueur1LineEdit->text());
  43. _option->setNomJoueur2(joueur2LineEdit->text());
  44. _option->setTempsDepart(spinTempsDepart->time());
  45. _option->setSon(checkBoxSon->isChecked());
  46. QDialog::accept();
  47. }