#pragma execution_character_set("utf-8") #include "AuthorityDialog.h" #include "ui_AuthorityDialog.h" #include #include #include #include #include #include #include "Common.h" #include "auth/Auth.h" extern double gZoomValue; AuthorityDialog::AuthorityDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AuthorityDialog) { ui->setupUi(this); this->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint); this->setWindowTitle(tr("授权验证(Verify)")); this->setStyleSheet(gstrStyleSheetStatic.arg(gnFontSizeStatic)); ui->lineEditPassword->setStyleSheet(gstrStyleSheet.arg(gnFontSize)); ui->lineEditPassword->setEchoMode(QLineEdit::Password); //m_regExp.setPattern("^[0-9|a-z|A-Z|^\\s]{1,16}$"); //限制接受1至16个字符,减号、数字和英文字母 m_regExp.setPattern("^[0-9|a-z|A-Z|!@#$%&*()|^\\s]{1,16}$"); //限制接受1至16个字符,减号、数字和英文字母 m_validator = new QRegExpValidator(m_regExp, this); ui->lineEditPassword->setValidator(m_validator); show(); } AuthorityDialog::~AuthorityDialog() { ui->lineEditPassword->setValidator(nullptr); delete m_validator; delete ui; } bool AuthorityDialog::isAuthorized() { #ifdef USE_AUTH if(ui->lineEditPassword->text().compare(QString::fromStdString(Auth::GetInstance()->getAdvancePwd())) == 0) #else if(ui->lineEditPassword->text() == "tmskey") #endif { return true; } return false; } void AuthorityDialog::showEvent(QShowEvent *event) { show(); ui->lineEditPassword->setFocus(); QDialog::showEvent(event); } //void AuthorityDialog::resizeEvent(QResizeEvent *event) //{ // show(); //} void AuthorityDialog::show() { //double zoomValue = (double)width() / 180.0; double zoomValue = gZoomValue; if(zoomValue < 1.0) { zoomValue = 1.0; } int nFontSize = gnFontSizeStatic * zoomValue; this->setStyleSheet(gstrStyleSheetStatic.arg(nFontSize)); this->layout()->setSpacing(12 * zoomValue); int nWidget1Height = 36 * zoomValue + 12 * zoomValue; ui->widget->setFixedHeight(nWidget1Height); ui->widget->layout()->setAlignment(Qt::AlignBottom | Qt::AlignCenter); //ui->widget->setStyleSheet("background:blue;"); int nWidget2Height = 36 * zoomValue +24 * zoomValue; ui->widget_2->setFixedHeight(nWidget2Height); ui->widget_2->layout()->setAlignment(Qt::AlignTop | Qt::AlignCenter); //ui->widget_2->setStyleSheet("background:blue;"); int nlineEditPasswordWidth = 180 * zoomValue - 40 * zoomValue; int nlineEditPasswordHeight = 36 * zoomValue; ui->lineEditPassword->setFixedSize(nlineEditPasswordWidth, nlineEditPasswordHeight); ui->lineEditPassword->setStyleSheet(gstrStyleSheet.arg(gnFontSize * zoomValue)); int nButtonHeight = 36 * zoomValue; int nButtonWidth = 80 * zoomValue; int nButtonBoxHeight = nButtonHeight;//ui->buttonBox->height(); int nButtonBoxWidth = nButtonWidth;//ui->buttonBox->width(); ui->buttonBox->button(QDialogButtonBox::Ok)->setText("确定\nOK"); //ui->buttonBox->button(QDialogButtonBox::Ok)->setStyleSheet("background:red;"); ui->buttonBox->button(QDialogButtonBox::Ok)->setFixedSize(nButtonWidth, nButtonHeight); ui->buttonBox->setFixedSize(nButtonBoxWidth, nButtonBoxHeight); //ui->buttonBox->setStyleSheet("background:green;"); int nWidth = 180 * zoomValue; int nHeight = nWidget1Height + nWidget2Height; this->setFixedSize(nWidth, nHeight); // QMessageBox::warning(this, "Warning!", // tr("w:%1, h:%2\nWidget1: h:%3\npassword: w:%4, h:%5") // .arg(nWidth).arg(nHeight) // .arg(nWidget1Height) // .arg(nlineEditPasswordWidth).arg(nlineEditPasswordHeight)); }