125 lines
4.3 KiB
C++
125 lines
4.3 KiB
C++
#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/DialogManager.h"
|
|
#include "utilities/Locker.h"
|
|
#include "utilities/LanguageSwitcher.h"
|
|
#include "components/ULineEdit.h"
|
|
#include "components/ListBox.h"
|
|
|
|
namespace
|
|
{
|
|
const int MINIMUM_LOCKTIME = 30;
|
|
}
|
|
|
|
GeneralForm::GeneralForm(QWidget* aParent)
|
|
: QWidget(aParent)
|
|
, mLayout(new QVBoxLayout(this))
|
|
{
|
|
setFocusPolicy(Qt::ClickFocus);
|
|
QWidget* lanHeader = new QWidget(this);
|
|
mLayout->addWidget(lanHeader);
|
|
|
|
QHBoxLayout* lanHeaderLayout = new QHBoxLayout(lanHeader);
|
|
QLabel* languageLabel = new QLabel(tr("Language"));
|
|
lanHeaderLayout->addWidget(languageLabel);
|
|
|
|
QToolButton* btnLan = new ListBox(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
|
|
int time = str.toInt();
|
|
if (MINIMUM_LOCKTIME < time)
|
|
{
|
|
JsonObject::Instance()->setLockScreenTimeout(str);
|
|
Locker::getInstance()->setTimer(str.toInt() * 1000);
|
|
}
|
|
|
|
});
|
|
|
|
connect(btnLan, &QPushButton::clicked, [=]()
|
|
{
|
|
DialogResult result = DialogManager::Default()->requestSelectLanguage();
|
|
if (result.ResultCode == QDialog::Accepted)
|
|
{
|
|
QString language = result.ResultData.toString();
|
|
|
|
//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"));
|
|
});
|
|
}
|