resize_dialog.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "resize_dialog.h"
  2. #include <QFormLayout>
  3. #include <QLabel>
  4. #include <QPushButton>
  5. #include <QVBoxLayout>
  6. namespace MapEditor {
  7. ResizeDialog::ResizeDialog(int currentWidth, int currentHeight, QWidget *parent)
  8. : QDialog(parent) {
  9. setupUI(currentWidth, currentHeight);
  10. }
  11. void ResizeDialog::setupUI(int currentWidth, int currentHeight) {
  12. setWindowTitle("Resize Map");
  13. resize(300, 150);
  14. auto *layout = new QVBoxLayout(this);
  15. auto *formLayout = new QFormLayout();
  16. m_widthSpinBox = new QSpinBox(this);
  17. m_widthSpinBox->setRange(10, 1000);
  18. m_widthSpinBox->setValue(currentWidth);
  19. formLayout->addRow("Width:", m_widthSpinBox);
  20. m_heightSpinBox = new QSpinBox(this);
  21. m_heightSpinBox->setRange(10, 1000);
  22. m_heightSpinBox->setValue(currentHeight);
  23. formLayout->addRow("Height:", m_heightSpinBox);
  24. layout->addLayout(formLayout);
  25. auto *buttonLayout = new QHBoxLayout();
  26. auto *cancelButton = new QPushButton("Cancel", this);
  27. auto *okButton = new QPushButton("OK", this);
  28. okButton->setDefault(true);
  29. buttonLayout->addStretch();
  30. buttonLayout->addWidget(cancelButton);
  31. buttonLayout->addWidget(okButton);
  32. layout->addLayout(buttonLayout);
  33. connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);
  34. connect(okButton, &QPushButton::clicked, this, &QDialog::accept);
  35. }
  36. int ResizeDialog::newWidth() const { return m_widthSpinBox->value(); }
  37. int ResizeDialog::newHeight() const { return m_heightSpinBox->value(); }
  38. } // namespace MapEditor