diff --git a/CMakeLists.txt b/CMakeLists.txt index 928c393..cfe7990 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,30 +5,40 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_INCLUDE_CURRENT_DIR ON) #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -pthread") -file(GLOB_RECURSE project_headers ./src/*.h) +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) + file(GLOB_RECURSE project_c ./src/json/*.c) else() -file(GLOB_RECURSE project_c ./src/*.c) + 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}) + + + +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) -target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Widgets Qt5::Gui Qt5::OpenGL Qt5::Sql Qt5::VirtualKeyboard pthread usct_shim dmapi log4c cunit ctomat hdf5 matio m) + link_directories(/usr/local/lib64) + target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Widgets Qt5::Gui Qt5::OpenGL Qt5::Sql Qt5::VirtualKeyboard pthread usct_shim dmapi log4c cunit ctomat hdf5 matio m) else() -target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Widgets Qt5::Gui Qt5::OpenGL Qt5::Sql Qt5::VirtualKeyboard) + target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Widgets Qt5::Gui Qt5::OpenGL Qt5::Sql Qt5::VirtualKeyboard) endif() if(MSVC) diff --git a/src/InputObject.cpp b/src/InputObject.cpp index 10038bb..0709cd1 100644 --- a/src/InputObject.cpp +++ b/src/InputObject.cpp @@ -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); diff --git a/src/generalform.cpp b/src/generalform.cpp new file mode 100644 index 0000000..49521cd --- /dev/null +++ b/src/generalform.cpp @@ -0,0 +1,106 @@ +#include "generalform.h" + +#include +#include +#include +#include +#include +#include +#include +#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); +} \ No newline at end of file diff --git a/src/generalform.h b/src/generalform.h new file mode 100644 index 0000000..cd62d82 --- /dev/null +++ b/src/generalform.h @@ -0,0 +1,26 @@ +#ifndef GENERALFORM_H +#define GENERALFORM_H + +#include +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 \ No newline at end of file diff --git a/src/locker.cpp b/src/locker.cpp new file mode 100644 index 0000000..2abb693 --- /dev/null +++ b/src/locker.cpp @@ -0,0 +1,52 @@ +#include "locker.h" + +#include +#include "appvals/AppGlobalValues.h" +#include +#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); +} diff --git a/src/locker.h b/src/locker.h new file mode 100644 index 0000000..3b7b3e3 --- /dev/null +++ b/src/locker.h @@ -0,0 +1,28 @@ +#ifndef LOCKER_H +#define LOCKER_H + +#include + +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 diff --git a/src/main.cpp b/src/main.cpp index 197862d..562f521 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,7 +10,10 @@ #include #include #include "log/UserOperationLog.h" - +#include +#include "json/jsonobject.h" +#include "locker.h" +#include "languageswitcher.h" QString loadFontFromFile(QString path) { static QString font; @@ -57,32 +60,42 @@ 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(); if (app_args.contains("-d")) - { - w.debugConsoleOn(); - qInstallMessageHandler(MainWindow::QMessageOutput); - QThread thread; - StdOutRedirector redir; - redir.setOutputTF(w.getEdit()); - QTimer Timer; - redir.moveToThread(&thread); - QObject::connect(&Timer, SIGNAL(timeout()), &redir, SLOT(readOutsToTF())); - fflush(stdout); - Timer.start(1000); - thread.start(); - w.showFullScreen(); - w.requestLogin(); - int ret = a.exec(); - thread.terminate(); - return ret; - } else{ - w.showFullScreen(); - w.requestLogin(); - return a.exec(); + { + w.debugConsoleOn(); + qInstallMessageHandler(MainWindow::QMessageOutput); + QThread thread; + StdOutRedirector redir; + redir.setOutputTF(w.getEdit()); + QTimer Timer; + redir.moveToThread(&thread); + QObject::connect(&Timer, SIGNAL(timeout()), &redir, SLOT(readOutsToTF())); + fflush(stdout); + Timer.start(1000); + thread.start(); + w.showFullScreen(); + w.requestLogin(); + int ret = a.exec(); + thread.terminate(); + return ret; + } + else { + w.showFullScreen(); + w.requestLogin(); + return a.exec(); } } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a0847d1..78729a0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,4 +1,4 @@ -#include "mainwindow.h" +#include "mainwindow.h" #include "ui_mainwindow.h" #include #include @@ -15,6 +15,10 @@ #include "models/User.h" #include "AdminSettingForm.h" #include "appvals/AppGlobalValues.h" +#include +#include +#include + void MainWindow::QMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg) @@ -206,9 +210,12 @@ 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); if (msg) @@ -227,15 +234,9 @@ MainWindow::MainWindow(QWidget* parent) : if (!msgDialog->isHidden())msgDialog->accept(); delete msgDialog; msgDialog = nullptr; - }); - connect(EventCenter::Default(), &EventCenter::RequestLogin, [=](QObject*, QObject* msg) { - this->requestLogin(); + AppGlobalValues::setInProcessing(false); }); - 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); } + + QWidget::changeEvent(event); } -void MainWindow::refreshTimer() -{ - screenTimer->stop(); - screenTimer->start(counter); -} void MainWindow::centerWidgetHide() { ui->centralWidget->setVisible(false); } diff --git a/src/mainwindow.h b/src/mainwindow.h index bed6364..b9c427a 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -5,11 +5,15 @@ #include #include #include "StdOutRedirector.h" +#include "json/cJSON.h" + namespace Ui { class MainWindow; } class GUIMessageDialog; class QTabWidget; + + class MainWindow : public QMainWindow { Q_OBJECT @@ -23,19 +27,21 @@ 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; - QTabWidget* tab= nullptr; - int admin_tab_index = -1; + bool m_bLoaded = false; + QTabWidget* tab = nullptr; + int admin_tab_index = -1; }; #endif // MAINWINDOW_H