Refactor forms/settings/ package.
This commit is contained in:
116
src/forms/settings/GeneralForm.cpp
Normal file
116
src/forms/settings/GeneralForm.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
#include "generalform.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QDebug>
|
||||
#include <QLabel>
|
||||
#include <QEvent>
|
||||
|
||||
#include "event/EventCenter.h"
|
||||
#include "json/jsonobject.h"
|
||||
#include "dialogs/SelectDialog.h"
|
||||
#include "utilities/Locker.h"
|
||||
#include "utilities/Languageswitcher.h"
|
||||
#include "components/ULineEdit.h"
|
||||
|
||||
GeneralForm::GeneralForm(QWidget* aParent)
|
||||
: QWidget(aParent)
|
||||
, mLayout(new QVBoxLayout(this))
|
||||
, mSelectDialog(new SelectDialog(this))
|
||||
{
|
||||
QWidget* lanHeader = new QWidget(this);
|
||||
mLayout->addWidget(lanHeader);
|
||||
mSelectDialog->setWindowModality(Qt::WindowModal);
|
||||
|
||||
QHBoxLayout* lanHeaderLayout = new QHBoxLayout(lanHeader);
|
||||
QLabel* languageLabel = new QLabel(tr("Language"));
|
||||
lanHeaderLayout->addWidget(languageLabel);
|
||||
|
||||
QPushButton* btnLan = new QPushButton(lanHeader);
|
||||
lanHeaderLayout->addWidget(btnLan);
|
||||
lanHeaderLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding));
|
||||
|
||||
QWidget* instHeader = new QWidget(this);
|
||||
mLayout->addWidget(instHeader);
|
||||
QHBoxLayout* instHeaderLayout = new QHBoxLayout(instHeader);
|
||||
QLabel* institutionNameLabel = new QLabel(tr("Institution Name"));
|
||||
instHeaderLayout->addWidget(institutionNameLabel);
|
||||
QLineEdit* instName = new ULineEdit(instHeader);
|
||||
instName->setMaximumSize(QSize(300, 32768));
|
||||
instHeaderLayout->addWidget(instName);
|
||||
instHeaderLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Fixed));
|
||||
|
||||
QLabel* institutionAddressLabel = new QLabel(tr("Institution Addr"));
|
||||
instHeaderLayout->addWidget(institutionAddressLabel);
|
||||
QLineEdit* instAddr = new ULineEdit(instHeader);
|
||||
instHeaderLayout->addWidget(instAddr);
|
||||
instAddr->setMaximumSize(QSize(300, 32768));
|
||||
instHeaderLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding));
|
||||
|
||||
QWidget* lockHeader = new QWidget(this);
|
||||
mLayout->addWidget(lockHeader);
|
||||
QHBoxLayout* lockHeaderLayout = new QHBoxLayout(lockHeader);
|
||||
|
||||
QLabel* lockScreenLabel = new QLabel(tr("Lock Screen"));
|
||||
lockHeaderLayout->addWidget(lockScreenLabel);
|
||||
|
||||
QLineEdit* lockTime = new ULineEdit(lockHeader);
|
||||
lockTime->setMaximumSize(QSize(300, 32768));
|
||||
lockHeaderLayout->addWidget(lockTime);
|
||||
|
||||
QLabel* ss = new QLabel(tr("s"));
|
||||
lockHeaderLayout->addWidget(ss);
|
||||
lockHeaderLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding));
|
||||
|
||||
//...
|
||||
mLayout->addSpacerItem(new QSpacerItem(20, 300, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
||||
|
||||
//init
|
||||
btnLan->setText(JsonObject::Instance()->defaultLanguage());
|
||||
instName->setText(JsonObject::Instance()->institutionName());
|
||||
instAddr->setText(JsonObject::Instance()->institutionAddr());
|
||||
lockTime->setText(JsonObject::Instance()->lockScreenTimeout());
|
||||
|
||||
//connection
|
||||
connect(instName, &QLineEdit::textChanged, [=](const QString& str)
|
||||
{
|
||||
JsonObject::Instance()->setInstitutionName(str);
|
||||
});
|
||||
|
||||
connect(instAddr, &QLineEdit::textChanged, [=](const QString& str)
|
||||
{
|
||||
JsonObject::Instance()->setInstitutionAddr(str);
|
||||
});
|
||||
connect(lockTime, &QLineEdit::textChanged, [=](const QString& str)
|
||||
{
|
||||
//take effect
|
||||
JsonObject::Instance()->setLockScreenTimeout(str);
|
||||
Locker::getInstance()->setTimer(JsonObject::Instance()->lockerCount());
|
||||
|
||||
});
|
||||
|
||||
connect(btnLan, &QPushButton::clicked, [=]()
|
||||
{
|
||||
mSelectDialog->setValues(JsonObject::Instance()->language());
|
||||
mSelectDialog->setSelectedValue(JsonObject::Instance()->defaultLanguage());
|
||||
if (mSelectDialog->exec() == QDialog::Accepted)
|
||||
{
|
||||
QString language = mSelectDialog->getSelectedValue();
|
||||
|
||||
//take effect
|
||||
JsonObject::Instance()->setDefaultLanguage(language);
|
||||
LanguageSwitcher::getInstance()->setDefaultLanguage(language);
|
||||
btnLan->setText(JsonObject::Instance()->defaultLanguage());
|
||||
}
|
||||
});
|
||||
|
||||
connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]()
|
||||
{
|
||||
languageLabel->setText(tr("Language"));
|
||||
institutionNameLabel->setText(tr("Institution Addr"));
|
||||
institutionAddressLabel->setText(tr("Institution Addr"));
|
||||
lockScreenLabel->setText(tr("Lock Screen"));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user