Lock and setting json about
This commit is contained in:
@@ -9,7 +9,8 @@ file(GLOB_RECURSE project_headers ./src/*.h)
|
||||
file(GLOB_RECURSE project_cpps ./src/*.cpp)
|
||||
file(GLOB_RECURSE project_cxx ./src/*.cxx)
|
||||
file(GLOB_RECURSE project_cc ./src/*.cc)
|
||||
set(USE_SHIMLIB ON)
|
||||
|
||||
set(USE_SHIMLIB OFF)
|
||||
if(UNIX AND USE_SHIMLIB)
|
||||
file(GLOB_RECURSE project_c ./src/json/*.c)
|
||||
else()
|
||||
@@ -17,12 +18,21 @@ file(GLOB_RECURSE project_c ./src/*.c)
|
||||
endif()
|
||||
include_directories(./src/)
|
||||
|
||||
source_group(TREE ${CMAKE_SOURCE_DIR} FILES ${project_headers})
|
||||
source_group(TREE ${CMAKE_SOURCE_DIR} FILES ${project_cpps})
|
||||
source_group(TREE ${CMAKE_SOURCE_DIR} FILES ${project_cxx})
|
||||
source_group(TREE ${CMAKE_SOURCE_DIR} FILES ${project_cc})
|
||||
source_group(TREE ${CMAKE_SOURCE_DIR} FILES ${project_c})
|
||||
|
||||
find_package(Qt5 COMPONENTS Core Widgets Gui OpenGL Sql VirtualKeyboard REQUIRED)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
file(GLOB project_uis ./src/*.ui)
|
||||
qt5_wrap_ui(ui_FILES ${project_uis})
|
||||
file(GLOB project_res ./src/*.qrc)
|
||||
|
||||
|
||||
|
||||
add_executable(${PROJECT_NAME} ${project_headers} ${project_cpps} ${project_cxx} ${project_res} ${project_cc} ${project_c} ${ui_FILES} )
|
||||
if(UNIX AND USE_SHIMLIB)
|
||||
link_directories(/usr/local/lib64)
|
||||
|
||||
@@ -88,6 +88,7 @@ bool InputObject::eventFilter(QObject* obj, QEvent* event)
|
||||
if (event->type() == QEvent::MouseButtonPress)
|
||||
{
|
||||
emit touchScreen();
|
||||
|
||||
qDebug() << "touchScreen()";
|
||||
}
|
||||
//mouse button release means setfocus is useless
|
||||
@@ -165,17 +166,26 @@ void InputObject::ShowPanel() {
|
||||
|
||||
this->showFullScreen();
|
||||
this->setVisible(true);
|
||||
const DWORD currentThread = GetCurrentThreadId();
|
||||
qDebug() << "currentThread" << currentThread;
|
||||
|
||||
this->activateWindow(); //it is quite important!!!
|
||||
while (QApplication::activeWindow() != this)
|
||||
{
|
||||
qApp->processEvents();
|
||||
}
|
||||
|
||||
if (curLine) {
|
||||
ui->lineEdit->setText(curLine->text());
|
||||
ui->lineEdit->setEchoMode(curLine->echoMode());
|
||||
ui->lineEdit->setInputMethodHints(Qt::InputMethodHint::ImhNoAutoUppercase);
|
||||
//ui->lineEdit->setFocus(Qt::MouseFocusReason);
|
||||
ui->lineEdit->setFocus();
|
||||
while (QGuiApplication::focusObject() != ui->lineEdit)
|
||||
{
|
||||
qApp->processEvents();
|
||||
}
|
||||
|
||||
//while (QGuiApplication::focusObject() != ui->lineEdit)
|
||||
//{
|
||||
// qApp->processEvents();
|
||||
//}
|
||||
|
||||
QEvent event(QEvent::RequestSoftwareInputPanel);
|
||||
QApplication::sendEvent(ui->lineEdit, &event);
|
||||
|
||||
106
src/generalform.cpp
Normal file
106
src/generalform.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "generalform.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QDebug>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QEvent>
|
||||
#include "json/jsonobject.h"
|
||||
#include "SelectDialog.h"
|
||||
|
||||
#include "locker.h"
|
||||
#include "languageswitcher.h"
|
||||
|
||||
GeneralForm::GeneralForm(QWidget* parent) : QWidget(parent)
|
||||
{
|
||||
layout = new QVBoxLayout(this);
|
||||
QWidget* lanHeader = new QWidget(this);
|
||||
layout->addWidget(lanHeader);
|
||||
|
||||
QHBoxLayout* lanHeaderLayout = new QHBoxLayout(lanHeader);
|
||||
lanHeaderLayout->addWidget(new QLabel(tr("Language")));
|
||||
QPushButton* btnLan = new QPushButton(lanHeader);
|
||||
lanHeaderLayout->addWidget(btnLan);
|
||||
lanHeaderLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding));
|
||||
|
||||
QWidget* instHeader = new QWidget(this);
|
||||
layout->addWidget(instHeader);
|
||||
QHBoxLayout* instHeaderLayout = new QHBoxLayout(instHeader);
|
||||
instHeaderLayout->addWidget(new QLabel(tr("Institution Name")));
|
||||
QLineEdit* instName = new QLineEdit(instHeader);
|
||||
instName->setMaximumSize(QSize(300, 32768));
|
||||
instHeaderLayout->addWidget(instName);
|
||||
instHeaderLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Fixed));
|
||||
instHeaderLayout->addWidget(new QLabel(tr("Institution Addr")));
|
||||
QLineEdit* instAddr = new QLineEdit(instHeader);
|
||||
instHeaderLayout->addWidget(instAddr);
|
||||
instAddr->setMaximumSize(QSize(300, 32768));
|
||||
instHeaderLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding));
|
||||
|
||||
QWidget* lockHeader = new QWidget(this);
|
||||
layout->addWidget(lockHeader);
|
||||
QHBoxLayout* lockHeaderLayout = new QHBoxLayout(lockHeader);
|
||||
lockHeaderLayout->addWidget(new QLabel(tr("Lock Screen Timeout")));
|
||||
QLineEdit* lockTime = new QLineEdit(lockHeader);
|
||||
lockTime->setMaximumSize(QSize(300, 32768));
|
||||
lockHeaderLayout->addWidget(lockTime);
|
||||
lockHeaderLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding));
|
||||
|
||||
//...
|
||||
layout->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, [=](QString str)
|
||||
{
|
||||
JsonObject::Instance()->setInstitutionName(str);
|
||||
});
|
||||
|
||||
connect(instAddr, &QLineEdit::textChanged, [=](QString str)
|
||||
{
|
||||
JsonObject::Instance()->setInstitutionAddr(str);
|
||||
});
|
||||
connect(lockTime, &QLineEdit::textChanged, [=](QString str)
|
||||
{
|
||||
//take effect
|
||||
JsonObject::Instance()->setLockScreenTimeout(str);
|
||||
Locker::Instance()->setTimer(JsonObject::Instance()->lockerCount());
|
||||
|
||||
});
|
||||
|
||||
connect(btnLan, &QPushButton::clicked, [=]() {
|
||||
if (!dialog) {
|
||||
dialog = new SelectDialog(this);
|
||||
dialog->setWindowModality(Qt::WindowModal);
|
||||
}
|
||||
dialog->setAvailableDates(JsonObject::Instance()->language());
|
||||
dialog->setSelectedValue(JsonObject::Instance()->defaultLanguage());
|
||||
if (dialog->exec() == QDialog::Accepted)
|
||||
{
|
||||
QString lan = dialog->getSelectedValue();
|
||||
|
||||
//take effect
|
||||
JsonObject::Instance()->setDefaultLanguage(lan);
|
||||
LanguageSwitcher::Instance()->setDefaultLanguage(lan);
|
||||
|
||||
btnLan->setText(JsonObject::Instance()->defaultLanguage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void GeneralForm::changeEvent(QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::LanguageChange)
|
||||
{
|
||||
qDebug() << "change language";
|
||||
|
||||
}
|
||||
QWidget::changeEvent(event);
|
||||
}
|
||||
26
src/generalform.h
Normal file
26
src/generalform.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef GENERALFORM_H
|
||||
#define GENERALFORM_H
|
||||
|
||||
#include <QWidget>
|
||||
class QPushButton;
|
||||
class QVBoxLayout;
|
||||
class SelectDialog;
|
||||
|
||||
class GeneralForm : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GeneralForm(QWidget* parent = nullptr);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
protected:
|
||||
void changeEvent(QEvent* event);
|
||||
|
||||
private:
|
||||
QVBoxLayout* layout = nullptr;
|
||||
SelectDialog* dialog = nullptr;
|
||||
};
|
||||
|
||||
#endif // GENERALFORM_H
|
||||
52
src/locker.cpp
Normal file
52
src/locker.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "locker.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include "appvals/AppGlobalValues.h"
|
||||
#include <src/event/EventCenter.h>
|
||||
#include "json/jsonobject.h"
|
||||
Locker* Locker::locker = Q_NULLPTR;
|
||||
|
||||
Locker* Locker::Instance()
|
||||
{
|
||||
if (locker == Q_NULLPTR)
|
||||
{
|
||||
locker = new Locker();
|
||||
}
|
||||
return locker;
|
||||
}
|
||||
Locker::Locker()
|
||||
{
|
||||
counter = JsonObject::Instance()->lockerCount();
|
||||
screenTimer = new QTimer(this);
|
||||
connect(screenTimer, SIGNAL(timeout()), this, SLOT(coverScreen()));
|
||||
}
|
||||
Locker::~Locker() {}
|
||||
|
||||
void Locker::start()
|
||||
{
|
||||
screenTimer->start(counter);
|
||||
}
|
||||
void Locker::coverScreen()
|
||||
{
|
||||
|
||||
if (AppGlobalValues::InProcessing().toBool()) {
|
||||
refreshTimer();
|
||||
}
|
||||
else
|
||||
{
|
||||
screenTimer->stop();
|
||||
EventCenter::Default()->triggerEvent(GUIEvents::RequestLogin, nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
void Locker::setTimer(int interval)
|
||||
{
|
||||
this->counter = interval;
|
||||
screenTimer->stop();
|
||||
screenTimer->start(this->counter);
|
||||
|
||||
}
|
||||
void Locker::refreshTimer()
|
||||
{
|
||||
screenTimer->stop();
|
||||
screenTimer->start(counter);
|
||||
}
|
||||
28
src/locker.h
Normal file
28
src/locker.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef LOCKER_H
|
||||
#define LOCKER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QTimer;
|
||||
class Locker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static Locker* Instance();
|
||||
void start();
|
||||
void setTimer(int interval);
|
||||
|
||||
public slots:
|
||||
void refreshTimer();
|
||||
void coverScreen();
|
||||
private:
|
||||
Locker();
|
||||
~Locker();
|
||||
|
||||
QTimer* screenTimer = nullptr;
|
||||
int counter = 30000;
|
||||
|
||||
static Locker* locker;
|
||||
};
|
||||
|
||||
#endif // LOCKER_H
|
||||
19
src/main.cpp
19
src/main.cpp
@@ -10,7 +10,10 @@
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
#include "log/UserOperationLog.h"
|
||||
|
||||
#include <QTranslator>
|
||||
#include "json/jsonobject.h"
|
||||
#include "locker.h"
|
||||
#include "languageswitcher.h"
|
||||
QString loadFontFromFile(QString path)
|
||||
{
|
||||
static QString font;
|
||||
@@ -57,7 +60,16 @@ int main(int argc, char* argv[])
|
||||
SQLHelper::Open();
|
||||
MainWindow w;
|
||||
UserOperationLog::Default()->init();
|
||||
QObject::connect(obj, SIGNAL(touchScreen()), &w, SLOT(refreshTimer()));
|
||||
|
||||
Locker::Instance()->start();
|
||||
QObject::connect(obj, SIGNAL(touchScreen()), Locker::Instance(), SLOT(refreshTimer()));
|
||||
|
||||
|
||||
//multi-language suppport
|
||||
QTranslator translator;
|
||||
LanguageSwitcher::Instance()->setTranslator(&translator);
|
||||
LanguageSwitcher::Instance()->setDefaultLanguage(JsonObject::Instance()->defaultLanguage());
|
||||
a.installTranslator(&translator);
|
||||
|
||||
|
||||
QStringList app_args = a.arguments();
|
||||
@@ -79,7 +91,8 @@ int main(int argc, char* argv[])
|
||||
int ret = a.exec();
|
||||
thread.terminate();
|
||||
return ret;
|
||||
} else{
|
||||
}
|
||||
else {
|
||||
w.showFullScreen();
|
||||
w.requestLogin();
|
||||
return a.exec();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "mainwindow.h"
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <qtabwidget.h>
|
||||
#include <QSizePolicy>
|
||||
@@ -15,6 +15,10 @@
|
||||
#include "models/User.h"
|
||||
#include "AdminSettingForm.h"
|
||||
#include "appvals/AppGlobalValues.h"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <QDateTime>
|
||||
|
||||
|
||||
|
||||
void MainWindow::QMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg)
|
||||
@@ -206,8 +210,11 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||
}
|
||||
msgDialog->hideExitButton();
|
||||
msgDialog->startLoading();
|
||||
AppGlobalValues::setInProcessing(true);
|
||||
// msgDialog->showFullScreen();
|
||||
if (msgDialog->isHidden())msgDialog->show();
|
||||
if (msgDialog->isHidden()){
|
||||
msgDialog->show();
|
||||
}
|
||||
});
|
||||
connect(EventCenter::Default(), &EventCenter::InvokeOperationProgress, [=](QObject*, QObject* msg) {
|
||||
if (!msgDialog) msgDialog = new GUIMessageDialog(this);
|
||||
@@ -227,15 +234,9 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||
if (!msgDialog->isHidden())msgDialog->accept();
|
||||
delete msgDialog;
|
||||
msgDialog = nullptr;
|
||||
AppGlobalValues::setInProcessing(false);
|
||||
});
|
||||
connect(EventCenter::Default(), &EventCenter::RequestLogin, [=](QObject*, QObject* msg) {
|
||||
this->requestLogin();
|
||||
});
|
||||
DeviceManager::Default()->initDevice();
|
||||
centerWidgetHide();
|
||||
screenTimer = new QTimer(this);
|
||||
connect(screenTimer, SIGNAL(timeout()), this, SLOT(coverScreen()));
|
||||
screenTimer->start(counter);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@@ -243,26 +244,16 @@ MainWindow::~MainWindow()
|
||||
delete ui;
|
||||
delete redir;
|
||||
}
|
||||
|
||||
void MainWindow::coverScreen()
|
||||
void MainWindow::changeEvent(QEvent* event)
|
||||
{
|
||||
|
||||
if (AppGlobalValues::InProcessing().toBool()) {
|
||||
refreshTimer();
|
||||
}
|
||||
else
|
||||
if (event->type() == QEvent::LanguageChange)
|
||||
{
|
||||
screenTimer->stop();
|
||||
requestLogin();
|
||||
qDebug() << "coverScreen()";
|
||||
}
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
|
||||
void MainWindow::refreshTimer()
|
||||
{
|
||||
screenTimer->stop();
|
||||
screenTimer->start(counter);
|
||||
QWidget::changeEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::centerWidgetHide() {
|
||||
ui->centralWidget->setVisible(false);
|
||||
}
|
||||
|
||||
@@ -5,11 +5,15 @@
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
#include "StdOutRedirector.h"
|
||||
#include "json/cJSON.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
class GUIMessageDialog;
|
||||
class QTabWidget;
|
||||
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -23,17 +27,19 @@ public:
|
||||
void requestLogin();
|
||||
QTextEdit* getEdit();
|
||||
void debugConsoleOn();
|
||||
public slots:
|
||||
void coverScreen();
|
||||
void refreshTimer();
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent* event);
|
||||
|
||||
private:
|
||||
QTimer* screenTimer = nullptr;
|
||||
int counter = 30000;
|
||||
|
||||
cJSON* json_root = nullptr;
|
||||
|
||||
Ui::MainWindow* ui;
|
||||
GUIMessageDialog* msgDialog = nullptr;
|
||||
StdOutRedirector* redir = nullptr;
|
||||
QTextEdit* console = nullptr;
|
||||
bool m_bLoaded = false;
|
||||
QTabWidget* tab = nullptr;
|
||||
int admin_tab_index = -1;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user