DialogUiOption.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "DialogUiOption.h"
  2. #include "../Common/Utility.h"
  3. #include "Common.h"
  4. DialogUiOption::DialogUiOption(int nWidth, int nHeight, QWidget *parent)
  5. : QDialog(parent)
  6. , m_nWidth(nWidth)
  7. , m_nHeight(nHeight)
  8. {
  9. ui.setupUi(this);
  10. // 对话框初始化
  11. this->initUI();
  12. }
  13. DialogUiOption::~DialogUiOption()
  14. {
  15. }
  16. /// <summary>
  17. /// 对话框初始化
  18. /// </summary>
  19. void DialogUiOption::initUI()
  20. {
  21. this->setWindowTitle(("UI Option"));
  22. // 对话框风格
  23. this->setAttribute(Qt::WA_QuitOnClose);
  24. this->setWindowModality(Qt::ApplicationModal);
  25. // 槽函数
  26. connect(ui.buttonOK, SIGNAL(clicked()), this, SLOT(onButtonOKClicked()));
  27. connect(ui.buttonResolution, SIGNAL(clicked()), this, SLOT(onButtonResolutionClicked()));
  28. connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
  29. // 固定窗体大小
  30. this->setFixedSize(495, 340);
  31. // 初始化数值显示
  32. ui.editWidth->setText(QString::number(m_nWidth));
  33. ui.editHeight->setText(QString::number(m_nHeight));
  34. }
  35. /// <summary>
  36. /// OK按钮
  37. /// </summary>
  38. void DialogUiOption::onButtonOKClicked()
  39. {
  40. m_nWidth = ui.editWidth->text().toInt();
  41. m_nHeight = ui.editHeight->text().toInt();
  42. // 检查数据有效性
  43. if (m_nWidth <= 0 || m_nHeight <=0 )
  44. {
  45. CRITICAL_MESSAGE("The width and height must > 0.");
  46. return;
  47. }
  48. this->accept();
  49. }
  50. /// <summary>
  51. /// 分辨率按钮
  52. /// </summary>
  53. void DialogUiOption::onButtonResolutionClicked()
  54. {
  55. QRect rect = QApplication::desktop()->screenGeometry();
  56. int with = rect.width();
  57. int heigh = rect.height();
  58. ui.editWidth->setText(QString::number(with));
  59. ui.editHeight->setText(QString::number(heigh));
  60. }