dialogform.cpp 957 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "dialogform.h"
  2. #include "ui_dialogform.h"
  3. DialogForm::DialogForm(QWidget *parent) :
  4. Scene(parent),
  5. ui(new Ui::DialogForm)
  6. {
  7. ok = false;
  8. setWindowModality(Qt::ApplicationModal);
  9. ui->setupUi(this);
  10. raise();
  11. }
  12. void DialogForm::exec()
  13. {
  14. raise();
  15. QEventLoop loop;
  16. connect(ui->ok_button, &QPushButton::clicked, &loop, &QEventLoop::quit);
  17. connect(ui->cancel_button, &QPushButton::clicked, &loop, &QEventLoop::quit);
  18. loop.exec();
  19. }
  20. bool DialogForm::isOk()
  21. {
  22. return ok;
  23. }
  24. void DialogForm::setTitle(QString title)
  25. {
  26. ui->title->setText(title);
  27. }
  28. void DialogForm::setText(QString text)
  29. {
  30. ui->text->setText(text);
  31. }
  32. void DialogForm::setShowCancel(bool show)
  33. {
  34. show ? ui->cancel_button->show() : ui->cancel_button->hide();
  35. }
  36. DialogForm::~DialogForm()
  37. {
  38. delete ui;
  39. }
  40. void DialogForm::on_cancel_button_clicked()
  41. {
  42. ok = false;
  43. }
  44. void DialogForm::on_ok_button_clicked()
  45. {
  46. ok = true;
  47. }