361 lines
11 KiB
C++
361 lines
11 KiB
C++
|
#include "wordsinputdialog.h"
|
|||
|
#include "ui_wordsinputdialog.h"
|
|||
|
|
|||
|
WordsInputDialog::WordsInputDialog(QWidget *parent) :
|
|||
|
QDialog(parent),
|
|||
|
ui(new Ui::WordsInputDialog)
|
|||
|
{
|
|||
|
ui->setupUi(this);
|
|||
|
setWindowFlags (Qt::Window | Qt::FramelessWindowHint);
|
|||
|
setWindowModality(Qt::ApplicationModal);
|
|||
|
setAttribute(Qt::WA_TranslucentBackground, true);//设置窗体背景透明
|
|||
|
|
|||
|
m_buttonWordList.clear();
|
|||
|
m_buttonWordList.append(ui->buttonLatterQ);
|
|||
|
m_buttonWordList.append(ui->buttonLatterW);
|
|||
|
m_buttonWordList.append(ui->buttonLatterE);
|
|||
|
m_buttonWordList.append(ui->buttonLatterR);
|
|||
|
m_buttonWordList.append(ui->buttonLatterT);
|
|||
|
m_buttonWordList.append(ui->buttonLatterY);
|
|||
|
m_buttonWordList.append(ui->buttonLatterU);
|
|||
|
m_buttonWordList.append(ui->buttonLatterI);
|
|||
|
m_buttonWordList.append(ui->buttonLatterO);
|
|||
|
m_buttonWordList.append(ui->buttonLatterP);
|
|||
|
m_buttonWordList.append(ui->buttonLatterA);
|
|||
|
m_buttonWordList.append(ui->buttonLatterS);
|
|||
|
m_buttonWordList.append(ui->buttonLatterD);
|
|||
|
m_buttonWordList.append(ui->buttonLatterF);
|
|||
|
m_buttonWordList.append(ui->buttonLatterG);
|
|||
|
m_buttonWordList.append(ui->buttonLatterH);
|
|||
|
m_buttonWordList.append(ui->buttonLatterJ);
|
|||
|
m_buttonWordList.append(ui->buttonLatterK);
|
|||
|
m_buttonWordList.append(ui->buttonLatterL);
|
|||
|
m_buttonWordList.append(ui->buttonLatterZ);
|
|||
|
m_buttonWordList.append(ui->buttonLatterX);
|
|||
|
m_buttonWordList.append(ui->buttonLatterC);
|
|||
|
m_buttonWordList.append(ui->buttonLatterV);
|
|||
|
m_buttonWordList.append(ui->buttonLatterB);
|
|||
|
m_buttonWordList.append(ui->buttonLatterN);
|
|||
|
m_buttonWordList.append(ui->buttonLatterM);
|
|||
|
|
|||
|
for(int var = 0; var < m_buttonWordList.size(); var++)
|
|||
|
{
|
|||
|
connect(m_buttonWordList.at(var),
|
|||
|
SIGNAL(clicked()),
|
|||
|
this,
|
|||
|
SLOT(inputBtnClick())
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
m_buttonNumberList.clear();
|
|||
|
m_buttonNumberList.append(ui->buttonNum1);
|
|||
|
m_buttonNumberList.append(ui->buttonNum2);
|
|||
|
m_buttonNumberList.append(ui->buttonNum3);
|
|||
|
m_buttonNumberList.append(ui->buttonNum4);
|
|||
|
m_buttonNumberList.append(ui->buttonNum5);
|
|||
|
m_buttonNumberList.append(ui->buttonNum6);
|
|||
|
m_buttonNumberList.append(ui->buttonNum7);
|
|||
|
m_buttonNumberList.append(ui->buttonNum8);
|
|||
|
m_buttonNumberList.append(ui->buttonNum9);
|
|||
|
m_buttonNumberList.append(ui->buttonNum0);
|
|||
|
for(int var = 0; var < m_buttonNumberList.size(); var++)
|
|||
|
{
|
|||
|
connect(m_buttonNumberList.at(var),
|
|||
|
SIGNAL(clicked()),
|
|||
|
this,
|
|||
|
SLOT(inputBtnClick())
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
m_shift = 1;
|
|||
|
m_inputStr.clear();
|
|||
|
ui->labelNameNewWords->clear();
|
|||
|
ui->labelNameOldWords->clear();
|
|||
|
ui->buttonOk->setEnabled(false);
|
|||
|
|
|||
|
initControl();
|
|||
|
}
|
|||
|
|
|||
|
WordsInputDialog::~WordsInputDialog()
|
|||
|
{
|
|||
|
delete ui;
|
|||
|
}
|
|||
|
|
|||
|
void WordsInputDialog::setInputStr(QString str)
|
|||
|
{
|
|||
|
m_inputStr = m_inputStr + str;
|
|||
|
ui->labelNameNewWords->setText(m_inputStr);
|
|||
|
if(m_inputStr.length() > 0)
|
|||
|
{
|
|||
|
ui->buttonOk->setEnabled(true);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//初始化窗体控件,包括位置、尺寸、样式
|
|||
|
void WordsInputDialog::initControl()
|
|||
|
{
|
|||
|
//根据不同分辨率设置控件的位置和尺寸
|
|||
|
switch (g_emResolut)
|
|||
|
{
|
|||
|
case resolution1910:
|
|||
|
initResolution1910();
|
|||
|
break;
|
|||
|
case resolution1006:
|
|||
|
initResolution1006();
|
|||
|
default:
|
|||
|
this->resize(1920,1080);
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
initControlStyle();//初始化窗体控件样式
|
|||
|
}
|
|||
|
|
|||
|
//初始化窗体控件为1920x1080分辨率
|
|||
|
void WordsInputDialog::initResolution1910()
|
|||
|
{
|
|||
|
double factoryX = 1.875;
|
|||
|
double factoryY = 1.8;
|
|||
|
|
|||
|
this->resize(1024*factoryX,600*factoryY);
|
|||
|
this->move((1920-this->width())/2,(1080-this->height())/2);
|
|||
|
ui->frameBack->setGeometry(0*factoryX,0,1024*factoryX,600*factoryY);
|
|||
|
ui->labelTitle->setGeometry(50*factoryX,55*factoryY,1024*factoryX,48*factoryY);
|
|||
|
|
|||
|
ui->labelName->setGeometry(65*factoryX,148*factoryY,95*factoryX,33*factoryY);
|
|||
|
ui->labelNameNewWords->setGeometry(194*factoryX,143*factoryY,554*factoryX,44*factoryY);
|
|||
|
ui->labelNameOldWords->setGeometry(575*factoryX,147*factoryY,200*factoryX,44*factoryY);
|
|||
|
|
|||
|
for(int i = 0; i < m_buttonNumberList.size(); i++)
|
|||
|
{
|
|||
|
m_buttonNumberList[i]->setGeometry((60+i*91)*factoryX,233*factoryY,67*factoryX,40*factoryY);
|
|||
|
}
|
|||
|
|
|||
|
int x = 0;
|
|||
|
int y = 0;
|
|||
|
int idx = 0;
|
|||
|
for(int i = 0; i < m_buttonWordList.size(); i++)
|
|||
|
{
|
|||
|
if(m_buttonWordList[i]->text().toUpper() == "Q")
|
|||
|
{
|
|||
|
x = 60;
|
|||
|
y = 295;
|
|||
|
idx = i;
|
|||
|
}
|
|||
|
if(m_buttonWordList[i]->text().toUpper() == "A")
|
|||
|
{
|
|||
|
x =97;
|
|||
|
y = 353;
|
|||
|
idx = 0;
|
|||
|
}
|
|||
|
if(m_buttonWordList[i]->text().toUpper() == "Z")
|
|||
|
{
|
|||
|
x = 189;
|
|||
|
y = 414;
|
|||
|
idx = 0;
|
|||
|
}
|
|||
|
m_buttonWordList[i]->setGeometry((x+idx*91)*factoryX,y*factoryY,67*factoryX,40*factoryY);
|
|||
|
idx++;
|
|||
|
}
|
|||
|
|
|||
|
ui->buttonShift->setGeometry(60*factoryX,414*factoryY,107*factoryX,40*factoryY);
|
|||
|
ui->buttonBack->setGeometry(827*factoryX,414*factoryY,107*factoryX,40*factoryY);
|
|||
|
ui->frameTwo->setGeometry(725*factoryX,472*factoryY,321*factoryX,51*factoryY);
|
|||
|
ui->buttonOk->setGeometry(0,0,107*factoryX,40*factoryY);
|
|||
|
ui->buttonCancel->setGeometry(135*factoryX,0,107*factoryX,40*factoryY);
|
|||
|
}
|
|||
|
//初始化窗体控件为1024x600分辨率
|
|||
|
void WordsInputDialog::initResolution1006()
|
|||
|
{
|
|||
|
this->resize(1024,600);
|
|||
|
this->move((1024-this->width())/2,(600-this->height())/2);
|
|||
|
ui->frameBack->setGeometry(0,0,1024,600);
|
|||
|
ui->labelTitle->setGeometry(50,55,1024,48);
|
|||
|
|
|||
|
ui->labelName->setGeometry(65,148,95,33);
|
|||
|
ui->labelNameNewWords->setGeometry(194,143,554,44);
|
|||
|
ui->labelNameOldWords->setGeometry(575,147,200,44);
|
|||
|
|
|||
|
for(int i = 0; i < m_buttonNumberList.size(); i++)
|
|||
|
{
|
|||
|
m_buttonNumberList[i]->setGeometry(60+i*91,233,67,40);
|
|||
|
}
|
|||
|
|
|||
|
int x = 0;
|
|||
|
int y = 0;
|
|||
|
int idx = 0;
|
|||
|
for(int i = 0; i < m_buttonWordList.size(); i++)
|
|||
|
{
|
|||
|
if(m_buttonWordList[i]->text().toUpper() == "Q")
|
|||
|
{
|
|||
|
x = 60;
|
|||
|
y = 295;
|
|||
|
idx = i;
|
|||
|
}
|
|||
|
if(m_buttonWordList[i]->text().toUpper() == "A")
|
|||
|
{
|
|||
|
x =97;
|
|||
|
y = 353;
|
|||
|
idx = 0;
|
|||
|
}
|
|||
|
if(m_buttonWordList[i]->text().toUpper() == "Z")
|
|||
|
{
|
|||
|
x = 189;
|
|||
|
y = 414;
|
|||
|
idx = 0;
|
|||
|
}
|
|||
|
m_buttonWordList[i]->setGeometry(x+idx*91,y,67,40);
|
|||
|
idx++;
|
|||
|
}
|
|||
|
ui->buttonShift->setGeometry(60,414,107,40);
|
|||
|
ui->buttonBack->setGeometry(827,414,107,40);
|
|||
|
ui->frameTwo->setGeometry(725,472,321,51);
|
|||
|
ui->buttonOk->setGeometry(0,0,107,40);
|
|||
|
ui->buttonCancel->setGeometry(135,0,107,40);
|
|||
|
}
|
|||
|
|
|||
|
//初始化窗体控件样式
|
|||
|
void WordsInputDialog::initControlStyle()
|
|||
|
{
|
|||
|
SetControlStyle setControlStyle;
|
|||
|
setControlStyle.setUiName(this->objectName());
|
|||
|
|
|||
|
//白蓝色渐变、灰蓝色渐变
|
|||
|
QString style = "QPushButton{background-color: qlineargradient(spread:pad, x1:0.5 y1:0, x2:0.5, y2:1, stop:0 rgb(255, 255, 255), stop:1 rgb(215, 243, 254));border-radius:5px;}";
|
|||
|
style += "QPushButton:pressed{background-color: qlineargradient(spread:pad, x1:0.5 y1:0, x2:0.5, y2:1, stop:0 rgb(217, 222, 224), stop:1 rgb(191,213,223));}";
|
|||
|
style += "QPushButton:disabled{background-color: qlineargradient(spread:pad, x1:0.5 y1:0, x2:0.5, y2:1, stop:0 rgb(230, 230, 230), stop:1 rgb(182,182,182));}";
|
|||
|
|
|||
|
for(int i = 0; i < m_buttonWordList.size(); i++)
|
|||
|
{
|
|||
|
m_buttonWordList[i]->setStyleSheet(style);
|
|||
|
m_buttonWordList[i]->setFont(fontNormal_1);
|
|||
|
}
|
|||
|
|
|||
|
for(int i = 0; i < m_buttonNumberList.size(); i++)
|
|||
|
{
|
|||
|
m_buttonNumberList[i]->setStyleSheet(style);
|
|||
|
m_buttonNumberList[i]->setFont(fontNormal_1);
|
|||
|
}
|
|||
|
|
|||
|
ui->frameBack->setStyleSheet(TRANSPARENTSTYLE);
|
|||
|
ui->frameBack->setStyleSheet(setControlStyle.getStyleSheet(this->objectName()));
|
|||
|
|
|||
|
ui->labelName->setStyleSheet(LABELWHITESTYLE);
|
|||
|
ui->labelName->setFont(fontNormal_1);
|
|||
|
// ui->labelName->setAlignment(Qt::AlignRight);
|
|||
|
// ui->labelName->setAlignment(Qt::AlignVCenter);
|
|||
|
|
|||
|
ui->labelTitle->setStyleSheet(LABELWHITESTYLE);
|
|||
|
ui->labelTitle->setFont(fontNormal_1);
|
|||
|
ui->labelTitle->setAlignment(Qt::AlignLeft);
|
|||
|
ui->labelTitle->setAlignment(Qt::AlignVCenter);
|
|||
|
|
|||
|
ui->labelNameNewWords->setStyleSheet(LABELWHITESTYLE);
|
|||
|
ui->labelNameNewWords->setFont(fontNormal_1);
|
|||
|
ui->labelNameNewWords->setAlignment(Qt::AlignLeft);
|
|||
|
ui->labelNameNewWords->setAlignment(Qt::AlignVCenter);
|
|||
|
|
|||
|
ui->labelNameOldWords->setStyleSheet(LABELWHITESTYLE);
|
|||
|
ui->labelNameOldWords->setFont(fontNormal_1);
|
|||
|
ui->labelNameOldWords->setAlignment(Qt::AlignLeft);
|
|||
|
ui->labelNameOldWords->setAlignment(Qt::AlignVCenter);
|
|||
|
|
|||
|
ui->buttonShift->setStyleSheet(style);
|
|||
|
ui->buttonShift->setFont(fontNormal_1);
|
|||
|
|
|||
|
ui->buttonBack->setStyleSheet(style);
|
|||
|
ui->buttonBack->setFont(fontNormal_1);
|
|||
|
|
|||
|
ui->frameTwo->setStyleSheet(TRANSPARENTSTYLE);
|
|||
|
ui->buttonOk->setWhiteBlueBottomStyle();
|
|||
|
ui->buttonOk->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonOk->objectName()+"_1"),12);
|
|||
|
ui->buttonCancel->setWhiteBlueBottomStyle();
|
|||
|
ui->buttonCancel->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonCancel->objectName()+"_1"),12);
|
|||
|
}
|
|||
|
|
|||
|
void WordsInputDialog::setTitleStr(QString str)
|
|||
|
{
|
|||
|
ui->labelTitle->setText(str);
|
|||
|
}
|
|||
|
|
|||
|
void WordsInputDialog::setOldWordsStr(QString str)
|
|||
|
{
|
|||
|
ui->labelNameOldWords->setText(str);
|
|||
|
}
|
|||
|
|
|||
|
void WordsInputDialog::clean()
|
|||
|
{
|
|||
|
m_inputStr.clear();
|
|||
|
ui->labelNameNewWords->clear();
|
|||
|
ui->buttonOk->setEnabled(false);
|
|||
|
}
|
|||
|
|
|||
|
void WordsInputDialog::wifiClean()
|
|||
|
{
|
|||
|
m_inputStr.clear();
|
|||
|
ui->labelNameNewWords->clear();
|
|||
|
ui->buttonOk->setEnabled(true);
|
|||
|
}
|
|||
|
|
|||
|
QString WordsInputDialog::getInputStr()
|
|||
|
{
|
|||
|
return m_inputStr;
|
|||
|
}
|
|||
|
|
|||
|
void WordsInputDialog::inputBtnClick()
|
|||
|
{
|
|||
|
QPushButton *button = (QPushButton*) this->sender() ;
|
|||
|
|
|||
|
if(button == NULL)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
QString str = button->text();
|
|||
|
setInputStr(str);
|
|||
|
}
|
|||
|
|
|||
|
void WordsInputDialog::on_buttonShift_clicked()
|
|||
|
{
|
|||
|
m_shift = -1 * m_shift;
|
|||
|
|
|||
|
for(int i = 0; i < m_buttonWordList.size(); i++)
|
|||
|
{
|
|||
|
if(m_shift == -1)
|
|||
|
{
|
|||
|
QString lostr=m_buttonWordList[i]->text().toLower();
|
|||
|
m_buttonWordList[i]->setText(lostr);
|
|||
|
}
|
|||
|
else if(m_shift == 1)
|
|||
|
{
|
|||
|
QString upstr=m_buttonWordList[i]->text().toUpper();
|
|||
|
m_buttonWordList[i]->setText(upstr);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void WordsInputDialog::on_buttonBack_clicked()
|
|||
|
{
|
|||
|
if(m_inputStr.length() <= 0)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
m_inputStr = m_inputStr.remove(m_inputStr.length()-1,m_inputStr.length()); // 删除最后一位字符
|
|||
|
ui->labelNameNewWords->setText(m_inputStr);
|
|||
|
|
|||
|
if(m_inputStr.length() <= 0)
|
|||
|
{
|
|||
|
ui->buttonOk->setEnabled(false);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void WordsInputDialog::on_buttonOk_clicked()
|
|||
|
{
|
|||
|
done(1);
|
|||
|
}
|
|||
|
|
|||
|
void WordsInputDialog::on_buttonCancel_clicked()
|
|||
|
{
|
|||
|
clean();
|
|||
|
done(0);
|
|||
|
}
|