FaceAccess/Linguist/setupUi/SetupUi.cpp

365 lines
16 KiB
C++
Raw Normal View History

2024-07-11 11:27:12 +08:00
#include "SetupUi.h"
#include "UiConfig.h"
#include <QDebug>
#include <QTextEdit>
#include <QScrollBar>
#include <QScroller>
static const int FONT_SIZE[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = {24, 38, 38, 14, 14};
SetupUiProtoDoc::SetupUiProtoDoc(QWidget *parent) : MyWidgetWithMainStyleColor(parent)
{
QLabel* doc = new QLabel(this);
doc->setWordWrap(true);
doc->setText(tr("这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档"
"这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档"
"这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档"
"这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档"
"这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档"
"这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档"
"这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档这是协议文档"));
QVBoxLayout* vlay = new QVBoxLayout();
vlay->addWidget(doc);
setLayout(vlay);
}
SetupUiPrivacyDoc::SetupUiPrivacyDoc(QWidget *parent) : MyWidgetWithMainStyleColor(parent)
{
#if 0
QTextEdit* doc = new QTextEdit(this);
doc->setReadOnly(true);
doc->verticalScrollBar()->hide();
// QScroller::grabGesture(doc, QScroller::LeftMouseButtonGesture);
//doc->setVerticalScrollMode(QListWidget::ScrollPerPixel);
//doc->setWordWrap(true);
#else
QLabel* doc = new QLabel(this);
doc->setWordWrap(true);
#endif
doc->setText(tr("这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档"
"这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档"
"这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档"
"这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档"
"这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档这是隐私文档"));
QVBoxLayout* vlay = new QVBoxLayout();
vlay->addWidget(doc);
setLayout(vlay);
}
const int SetupUiConfig::JUMP_BTN_FONT_SIZE[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = {17, 27, 27, 10, 10};
SetupUiConfig::SetupUiConfig(QWidget *parent) : MyWidgetWithMainStyleColor(parent)
{
QFont ft;
ft.setPointSize(FONT_SIZE[UiConfig::GetInstance()->getScreenConfigIndex()]);
QPalette palette;
palette.setColor(QPalette::ButtonText,QColor(15, 116, 248, 0xFF));
QLabel* label0 = new QLabel(tr("配置方式"), this);
label0->setFont(ft);
const QString btnStyle{"QPushButton {"
"border: 0px;"
"border-radius:10px;"
"background-color:rgb(24, 144, 255);"
"focus{outline: none;}"
"}"
"QPushButton:hover { "
"background-color:rgb(24, 144, 255);"
"}"
"QPushButton:pressed {"
"background-color:rgb(222, 222, 222);"
"}"};
m_btnQrcode = new QPushButton(tr("二维码配置"), this);
//m_btnQrcode->setIcon(QIcon(":/res/image/setup_qrcode_large.png"));
//m_btnQrcode->setToolButtonStyle(Qt::Qt::ToolButtonTextBesideIcon);
m_btnQrcode->setFixedSize(static_cast<int>(UiConfig::GetInstance()->getUiWidth() * 0.75),
static_cast<int>(UiConfig::GetInstance()->getUiWidth() * 0.37));
m_btnQrcode->setFocusPolicy(Qt::NoFocus);
m_btnQrcode->setFont(ft);
m_btnQrcode->setStyleSheet(btnStyle);
connect(m_btnQrcode, SIGNAL(clicked()), this, SLOT(slotBtnClicked()));
m_btnManual = new QPushButton(tr("手动配置"), this);
//m_btnManual->setIcon(QIcon(":/res/image/setup_manual_large.png"));
m_btnManual->setFixedSize(static_cast<int>(UiConfig::GetInstance()->getUiWidth() * 0.75),
static_cast<int>(UiConfig::GetInstance()->getUiWidth() * 0.37));
m_btnManual->setFocusPolicy(Qt::NoFocus);
m_btnManual->setFont(ft);
m_btnManual->setStyleSheet(btnStyle);
connect(m_btnManual, SIGNAL(clicked()), this, SLOT(slotBtnClicked()));
m_btnSkip = new QPushButton(tr("跳过"), this);
m_btnSkip->setFocusPolicy(Qt::NoFocus);
ft.setPointSize(JUMP_BTN_FONT_SIZE[UiConfig::GetInstance()->getScreenConfigIndex()]);
m_btnSkip->setFont(ft);
m_btnSkip->setFlat(true);
m_btnSkip->setStyleSheet("border: 0px");
//m_btnSkip->setFocusPolicy(Qt::NoFocus);
connect(m_btnSkip, SIGNAL(clicked()), this, SLOT(slotBtnClicked()));
QVBoxLayout* bLay = new QVBoxLayout();
bLay->addWidget(label0, 1, Qt::AlignCenter | Qt::AlignTop);
bLay->addWidget(m_btnQrcode, 1, Qt::AlignCenter | Qt::AlignTop);
bLay->addWidget(m_btnManual, 80, Qt::AlignCenter | Qt::AlignTop);
bLay->addWidget(m_btnSkip, 1, Qt::AlignRight | Qt::AlignBottom);
bLay->setSpacing(UiConfig::GetInstance()->getUiHeight() / 30);
bLay->setContentsMargins(UiConfig::GetInstance()->getUiWidth() / 20,
UiConfig::GetInstance()->getUiHeight() / 20,
UiConfig::GetInstance()->getUiWidth() / 20,
UiConfig::GetInstance()->getUiHeight() / 10);
setLayout(bLay);
}
void SetupUiConfig::slotBtnClicked()
{
const QObject* btn = sender();
if(btn == m_btnQrcode){
emit signalJumpPage(0); //need page enum
}
else if(btn == m_btnManual){
emit signalJumpPage(1);
}
else if(btn == m_btnSkip){
emit signalSetupDone();
}
}
SetupUiStart::SetupUiStart(QWidget *parent) : MyWidgetWithMainStyleColor(parent)
{
QFont ft;
ft.setPointSize(FONT_SIZE[UiConfig::GetInstance()->getScreenConfigIndex()]);
QPalette palette;
palette.setColor(QPalette::ButtonText,QColor(15, 116, 248, 0xFF));
QLabel* label0 = new QLabel(tr("请仔细阅读以下内容"), this);
label0->setFont(ft);
m_btnProtocol = new QPushButton(tr("《XXXX协议》"), this);
m_btnProtocol->setPalette(palette);
m_btnProtocol->setFlat(true);
m_btnProtocol->setFont(ft);
m_btnProtocol->setFocusPolicy(Qt::NoFocus);
m_btnProtocol->setStyleSheet("border: 0px");
connect(m_btnProtocol, SIGNAL(clicked()), this, SLOT(slotBtnClicked()));
m_btnPrivacy = new QPushButton(tr("《XX隐私声明》"), this);
m_btnPrivacy->setPalette(palette);
m_btnPrivacy->setFlat(true);
m_btnPrivacy->setFont(ft);
m_btnPrivacy->setFocusPolicy(Qt::NoFocus);
m_btnPrivacy->setStyleSheet("border: 0px");
connect(m_btnPrivacy, SIGNAL(clicked()), this, SLOT(slotBtnClicked()));
m_rbAgree = new QRadioButton(tr("我已阅读并同意以上协议"), this);
m_rbAgree->setFocusPolicy(Qt::NoFocus);
m_rbAgree->setStyleSheet("QRadioButton::indicator:unchecked{image: url(:/res/image/select_1.png);}"
"QRadioButton::indicator:checked{image: url(:/res/image/select_2.png);}");
connect(m_rbAgree, SIGNAL(pressed()), this, SLOT(slotRadioButtonPressed()));
m_btnStart = new QPushButton(tr("开始使用"), this);
m_btnStart->setFixedSize(UiConfig::GetInstance()->getUiWidth() / 3,
UiConfig::GetInstance()->getUiWidth() / 6);
m_btnStart->setFont(ft);
m_btnStart->setFocusPolicy(Qt::NoFocus);
m_btnStart->setEnabled(false);
m_btnStart->setStyleSheet("QPushButton {"
"border: 0px;"
"border-radius:10px;"
"background-color:rgb(24, 144, 255);"
"focus{outline: none;}"
"}"
"QPushButton:hover { "
"background-color:rgb(24, 144, 255);"
"}"
"QPushButton:pressed {"
"background-color:rgb(222, 222, 222);"
"}");
connect(m_btnStart, SIGNAL(clicked()), this, SLOT(slotBtnClicked()));
QVBoxLayout* bLay = new QVBoxLayout();
bLay->addWidget(label0, 1, Qt::AlignCenter | Qt::AlignTop);
bLay->addWidget(m_btnProtocol, 1, Qt::AlignCenter | Qt::AlignTop);
bLay->addWidget(m_btnPrivacy, 80, Qt::AlignCenter | Qt::AlignTop);
bLay->addWidget(m_rbAgree, 1, Qt::AlignCenter | Qt::AlignBottom);
bLay->addWidget(m_btnStart, 1, Qt::AlignCenter | Qt::AlignBottom);
bLay->setSpacing(UiConfig::GetInstance()->getUiHeight() / 30);
bLay->setContentsMargins(UiConfig::GetInstance()->getUiWidth() / 20,
UiConfig::GetInstance()->getUiHeight() / 20,
UiConfig::GetInstance()->getUiWidth() / 20,
UiConfig::GetInstance()->getUiHeight() / 10);
setLayout(bLay);
}
void SetupUiStart::slotRadioButtonPressed()
{
m_btnStart->setEnabled(!m_rbAgree->isChecked());
}
void SetupUiStart::slotBtnClicked()
{
const QObject* btn = sender();
if(btn == m_btnProtocol){
emit signalJumpPage(0); //need page enum
}
else if(btn == m_btnPrivacy){
emit signalJumpPage(1);
}
else if(btn == m_btnStart){
emit signalJumpPage(2);
m_rbAgree->setChecked(false);
m_btnStart->setEnabled(false);
}
}
SetupUiTop::SetupUiTop(QWidget *parent) : MyWidgetWithMainStyleColor(parent)
{
m_btnBack = new QPushButton(this);
setButtonBackImage(m_btnBack, ":res/image/ProjectSet_return.png", 37, 61);
//m_btnBack->setFixedWidth(UiConfig::GetInstance()->getUiWidth() / 10);
m_btnBack->setFocusPolicy(Qt::NoFocus);
m_btnBack->hide();
connect(m_btnBack, SIGNAL(clicked()), this, SIGNAL(signalReturnBtnClicked()));
QHBoxLayout* hLay = new QHBoxLayout();
hLay->addWidget(m_btnBack, 1, Qt::AlignLeft);
hLay->setContentsMargins(UiConfig::GetInstance()->getUiWidth() / 15,
UiConfig::GetInstance()->getUiHeight() / 40, 0,
UiConfig::GetInstance()->getUiHeight() / 80);
setLayout(hLay);
}
void SetupUiTop::hideBackBtn(bool hide)
{
if(hide){
m_btnBack->hide();
}
else{
m_btnBack->show();
}
}
SetupUi::SetupUi(QWidget *parent) : WidgetWithBackstageInterface(parent)
{
QPalette pal = palette();
pal.setColor(QPalette::Background, Qt::transparent);
setPalette(pal);
m_topbar = new SetupUiTop(this);
m_topbar->setAttribute(Qt::WA_TranslucentBackground);
m_topbar->setFixedHeight(UiConfig::GetInstance()->getUiHeight() / 12);
connect(m_topbar, SIGNAL(signalReturnBtnClicked()), this, SLOT(slotBtnClicked()));
QFont ft;
ft.setPointSize(FONT_SIZE[UiConfig::GetInstance()->getScreenConfigIndex()]);
m_stackPages = new QStackedWidget(this);
m_pageStart = new SetupUiStart(this);
connect(m_pageStart, SIGNAL(signalJumpPage(int)), this, SLOT(slotJumpPage(int)));
m_stackPages->addWidget(m_pageStart);
m_pageProt = new SetupUiProtoDoc(this);
m_stackPages->addWidget(m_pageProt);
m_pagePriv= new SetupUiPrivacyDoc(this);
m_stackPages->addWidget(m_pagePriv);
m_pageConfig = new SetupUiConfig(this);
connect(m_pageConfig, SIGNAL(signalJumpPage(int)), this, SLOT(slotJumpPage(int)));
connect(m_pageConfig, SIGNAL(signalSetupDone()), this, SLOT(slotSetupDone()));
m_stackPages->addWidget(m_pageConfig);
m_pageQrcode = new SettingUiQrcode(0, this);
m_stackPages->addWidget(m_pageQrcode);
connect(parent, SIGNAL(signalCenterMsg(const int, const QString&)), m_pageQrcode, SLOT(slotCenterMsg(const int, const QString&)));
connect(parent, SIGNAL(signalQrcodeFastCfgResult(bool)), m_pageQrcode, SLOT(slotQrcodeFastCfgResult(bool)));
connect(m_pageQrcode, SIGNAL(signalExitSettingUi()), this, SLOT(slotSetupDone()));
m_pageManualNet = new settingUiFastCfgWireNet(0, this);
connect(m_pageManualNet, SIGNAL(signalJumpPage(int)), this, SLOT(slotJumpPage(int)));
m_stackPages->addWidget(m_pageManualNet);
m_pageManualPark = new settingUiFastCfgPark(0, this);
#if 0
connect(m_pageManualPark, SIGNAL(signalSetupDone()), this, SLOT(slotSetupDone()));
#else
connect(m_pageManualPark, SIGNAL(signalJumpPage(int)), this, SLOT(slotJumpPage(int)));
#endif
m_stackPages->addWidget(m_pageManualPark);
QVBoxLayout* bLay = new QVBoxLayout();
bLay->addWidget(m_topbar);
bLay->addWidget(m_stackPages);
bLay->setSpacing(0);
bLay->setMargin(0);
setLayout(bLay);
//hide protocol page until doc done
m_stackPages->setCurrentIndex(3);
//hide protocol page until doc done end
}
void SetupUi::setBackstageUiinterface(BackstageInterfaceForUi* interface)
{
m_backstageIf = interface;
m_pageStart->setBackstageUiinterface(interface);
m_pageQrcode->setBackstageUiinterface(interface);
m_pageManualNet->setBackstageUiinterface(interface);
m_pageManualPark->setBackstageUiinterface(interface);
}
void SetupUi::slotSetupDone()
{
m_backstageIf->setSetupAlreadyFlag();
emit signalSetupDone();
UiConfig::GetInstance()->setFastCfgStatus(false);
}
void SetupUi::slotBtnClicked()
{
const QObject* btn = sender();
if(m_pagePath.size()){
m_stackPages->setCurrentIndex(m_pagePath.pop());
}
//hide protocol page until doc done
if(3 == m_stackPages->currentIndex()){
m_topbar->hideBackBtn(true);
}
//hide protocol page until doc done end
}
void SetupUi::slotJumpPage(int pageIndex)
{
m_pagePath.push(m_stackPages->currentIndex());
const QObject* page = sender();
if(page == m_pageStart){
m_stackPages->setCurrentIndex(pageIndex + 1);//1:pageIndexOffset for this page
}
else if(page == m_pageConfig){
m_stackPages->setCurrentIndex(pageIndex + 4);//4:pageIndexOffset for this page
qDebug() << "page index:" << pageIndex;
if(pageIndex == 0){ //qrcode config
UiConfig::GetInstance()->setFastCfgStatus(true);
}
else if(pageIndex == 1){//manual cfg, need enum
m_pageManualNet->reset();
}
}
else if(page == m_pageManualNet){
m_stackPages->setCurrentIndex(pageIndex + 6);//6:pageIndexOffset for this page
m_pageManualPark->reset();
}
else if(page == m_pageManualPark){
m_stackPages->setCurrentIndex(4);//to qrcode page, need enum
UiConfig::GetInstance()->setFastCfgStatus(true);
}
m_topbar->hideBackBtn(false);
}