#include "DialogUiOption.h"
#include "../Common/Utility.h"
#include "Common.h"
DialogUiOption::DialogUiOption(int nWidth, int nHeight, QWidget *parent)
: QDialog(parent)
, m_nWidth(nWidth)
, m_nHeight(nHeight)
{
ui.setupUi(this);
// 对话框初始化
this->initUI();
}
DialogUiOption::~DialogUiOption()
{
}
///
/// 对话框初始化
///
void DialogUiOption::initUI()
{
this->setWindowTitle(("UI Option"));
// 对话框风格
this->setAttribute(Qt::WA_QuitOnClose);
this->setWindowModality(Qt::ApplicationModal);
// 槽函数
connect(ui.buttonOK, SIGNAL(clicked()), this, SLOT(onButtonOKClicked()));
connect(ui.buttonResolution, SIGNAL(clicked()), this, SLOT(onButtonResolutionClicked()));
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
// 固定窗体大小
this->setFixedSize(495, 340);
// 初始化数值显示
ui.editWidth->setText(QString::number(m_nWidth));
ui.editHeight->setText(QString::number(m_nHeight));
}
///
/// OK按钮
///
void DialogUiOption::onButtonOKClicked()
{
m_nWidth = ui.editWidth->text().toInt();
m_nHeight = ui.editHeight->text().toInt();
// 检查数据有效性
if (m_nWidth <= 0 || m_nHeight <=0 )
{
CRITICAL_MESSAGE("The width and height must > 0.");
return;
}
this->accept();
}
///
/// 分辨率按钮
///
void DialogUiOption::onButtonResolutionClicked()
{
QRect rect = QApplication::desktop()->screenGeometry();
int with = rect.width();
int heigh = rect.height();
ui.editWidth->setText(QString::number(with));
ui.editHeight->setText(QString::number(heigh));
}