File arrangement
This commit is contained in:
260
src/utilities/InputObject.cpp
Normal file
260
src/utilities/InputObject.cpp
Normal file
@@ -0,0 +1,260 @@
|
||||
#include "InputObject.h"
|
||||
#include "ui_inputobject.h"
|
||||
//#include "qdesktopwidget.h"
|
||||
#include <QDebug>
|
||||
#include <QEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QComboBox>
|
||||
#include <QDateEdit>
|
||||
#include <QtVirtualKeyboard>
|
||||
#include <QKeyEvent>
|
||||
#include <QLineEdit>
|
||||
#include <QAbstractSpinBox>
|
||||
|
||||
InputObject::InputObject(QWidget* parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::InputObject)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
initUi();
|
||||
|
||||
this->setVisible(false);
|
||||
this->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
|
||||
|
||||
|
||||
}
|
||||
|
||||
InputObject::~InputObject()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void InputObject::initUi()
|
||||
{
|
||||
//#3c3c3c
|
||||
#ifdef CUTE_STYLE
|
||||
QString style =
|
||||
"QWidget#WiBack{background-image: url(:/icons/bg.jpeg);}"
|
||||
"QWidget#WiBo{background-color: black;}"
|
||||
"QLineEdit,QDateEdit{background-color: rgba(0,0,0,0.5);\
|
||||
min-height:100px;max-height:100px; min-width:500px;max-width:500px;\
|
||||
border: 2px solid #ef9cba; border-radius:20px;\
|
||||
color:white;margin:0;font-size:36px;}"
|
||||
"QTextEdit{background-color: rgba(0,0,0,0.5);\
|
||||
min-height:300px;max-height:300px; min-width:700px;max-width:700px;\
|
||||
border: 2px solid #ef9cba; border-radius:20px;\
|
||||
font-family:Arial; color:white;margin:0;font-size:36px;}"
|
||||
"QDateEdit::up-button{image: url(:/up.png);height:15px;}"
|
||||
"QDateEdit::down-button{image:url(:/down.png);height:15px;}"
|
||||
;
|
||||
#else
|
||||
QString style =
|
||||
"QWidget#WiBack{background-color: #383533;}"
|
||||
"QWidget#WiBo{background-color: black;}"
|
||||
"QLineEdit,QDateEdit,QTextEdit{\
|
||||
background:qlineargradient(x1:0,y1:0,x2:1,y2:1,stop: 0.0 silver, stop: 1.0 grey);\
|
||||
border: 1px solid #1e1b18; border-radius:20px;\
|
||||
color:black;margin:0;font-size:36px;}"
|
||||
|
||||
"QLineEdit,QDateEdit{min-height:100px; max-height:100px; min-width:500px; max-width:500px;}"
|
||||
"QTextEdit{min-height:300px;max-height:300px; min-width:700px;max-width:700px;}"
|
||||
|
||||
"QDateEdit::up-button{image: url(:/up.png);height:15px;}"
|
||||
"QDateEdit::down-button{image:url(:/down.png);height:15px;}"
|
||||
;
|
||||
#endif
|
||||
setStyleSheet(style);
|
||||
|
||||
ui->dateEdit->setVisible(false);
|
||||
ui->dateEdit->setMaximumDate(QDate::currentDate());
|
||||
ui->dateEdit->setDisplayFormat("yyyy/MM/dd");
|
||||
ui->dateEdit->setStyleSheet(style);
|
||||
//this->setWindowOpacity(0.8);
|
||||
|
||||
connect(QGuiApplication::inputMethod(), &QInputMethod::visibleChanged, [=]() {
|
||||
if (QGuiApplication::inputMethod()->isVisible()) return;
|
||||
//qDebug() << "HidePanel";
|
||||
//qDebug() << "focusWidget" << qApp->focusWidget();
|
||||
this->HidePanel();
|
||||
this->hide();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
bool InputObject::eventFilter(QObject* obj, QEvent* event)
|
||||
{
|
||||
|
||||
if (event->type() == QEvent::MouseButtonPress)
|
||||
{
|
||||
emit touchScreen();
|
||||
|
||||
//qDebug() << "touchScreen()";
|
||||
}
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
|
||||
if (keyEvent->key() == Qt::Key_Return && curDateEdit)
|
||||
{
|
||||
this->HidePanel();
|
||||
this->hide();
|
||||
}
|
||||
}
|
||||
//mouse button release means setfocus is useless
|
||||
if (event->type() == QEvent::MouseButtonRelease)
|
||||
{
|
||||
//qDebug() << obj << event->type();
|
||||
|
||||
if (obj->objectName() == QString("qt_spinbox_lineedit"))
|
||||
{
|
||||
QDateEdit* _date = qobject_cast<QDateEdit*>(obj->parent());
|
||||
if (_date == ui->dateEdit)return true;
|
||||
if (_date->isEnabled())
|
||||
{
|
||||
this->ShowPanel();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (obj->objectName() == QString("qt_scrollarea_viewport"))
|
||||
{
|
||||
QTextEdit* _text = qobject_cast<QTextEdit*>(obj->parent());
|
||||
if (!_text) return false;
|
||||
if (_text == ui->textEdit) return true; //
|
||||
if (_text->isEnabled())
|
||||
{
|
||||
this->ShowPanel();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (obj->inherits("QLineEdit")) {
|
||||
QLineEdit* tbx = qobject_cast<QLineEdit*>(obj);
|
||||
//you have to tell whether it is coming from qdateedit!!!
|
||||
if (ui->lineEdit != tbx && tbx->isEnabled())
|
||||
{
|
||||
//qDebug() << "ShowPanel";
|
||||
//qDebug() << "focusWidget" << qApp->focusWidget();
|
||||
//qDebug() << "lineEdit" << ui->lineEdit;
|
||||
//qDebug() << "obj" << obj;
|
||||
this->ShowPanel();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void InputObject::ShowPanel() {
|
||||
if (!qApp->focusWidget()) return;
|
||||
if (qApp->focusWidget()->inherits("QLineEdit"))
|
||||
{
|
||||
curLine = qobject_cast<QLineEdit*>(qApp->focusWidget());
|
||||
ui->dateEdit->setVisible(false);
|
||||
ui->lineEdit->setVisible(true);
|
||||
ui->textEdit->setVisible(false);
|
||||
}
|
||||
if (qApp->focusWidget()->inherits("QDateEdit"))
|
||||
{
|
||||
curDateEdit = qobject_cast<QDateEdit*>(qApp->focusWidget());
|
||||
ui->dateEdit->setVisible(true);
|
||||
ui->lineEdit->setVisible(false);
|
||||
ui->textEdit->setVisible(false);
|
||||
}
|
||||
|
||||
if (qApp->focusWidget()->inherits("QTextEdit"))
|
||||
{
|
||||
curText = qobject_cast<QTextEdit*>(qApp->focusWidget());
|
||||
ui->dateEdit->setVisible(false);
|
||||
ui->lineEdit->setVisible(false);
|
||||
ui->textEdit->setVisible(true);
|
||||
}
|
||||
|
||||
this->showFullScreen();
|
||||
this->setVisible(true);
|
||||
|
||||
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();
|
||||
//}
|
||||
|
||||
QEvent event(QEvent::RequestSoftwareInputPanel);
|
||||
QApplication::sendEvent(ui->lineEdit, &event);
|
||||
|
||||
}
|
||||
if (curDateEdit)
|
||||
{
|
||||
|
||||
ui->dateEdit->setDateTime(curDateEdit->dateTime());
|
||||
ui->dateEdit->setFocus();
|
||||
while (QGuiApplication::focusObject() != ui->dateEdit)
|
||||
{
|
||||
qApp->processEvents();
|
||||
}
|
||||
qDebug() << QGuiApplication::focusObject();
|
||||
QEvent event(QEvent::RequestSoftwareInputPanel);
|
||||
QApplication::sendEvent(ui->dateEdit, &event);
|
||||
}
|
||||
|
||||
if (curText)
|
||||
{
|
||||
ui->textEdit->setPlainText(curText->toPlainText());
|
||||
ui->textEdit->setFocus();
|
||||
while (QGuiApplication::focusObject() != ui->textEdit)
|
||||
{
|
||||
qApp->processEvents();
|
||||
}
|
||||
//qDebug() << QGuiApplication::focusObject();
|
||||
QEvent event(QEvent::RequestSoftwareInputPanel);
|
||||
QApplication::sendEvent(ui->textEdit, &event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void InputObject::HidePanel()
|
||||
{
|
||||
if (curLine) {
|
||||
curLine->setText(ui->lineEdit->text());
|
||||
ui->lineEdit->clearFocus();
|
||||
ui->lineEdit->clear();
|
||||
//this->setVisible(false);
|
||||
curLine = nullptr;
|
||||
}
|
||||
else if (curDateEdit)
|
||||
{
|
||||
//curDateEdit->setDateTime(QDateTime::currentDateTime());
|
||||
curDateEdit->setDateTime(ui->dateEdit->dateTime());
|
||||
ui->dateEdit->clearFocus();
|
||||
ui->dateEdit->clear();
|
||||
//this->setVisible(false);
|
||||
curDateEdit = nullptr;
|
||||
}
|
||||
else if (curText)
|
||||
{
|
||||
curText->setText(ui->textEdit->toPlainText());
|
||||
ui->textEdit->clearFocus();
|
||||
ui->textEdit->clear();
|
||||
//this->setVisible(false);
|
||||
curText = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
36
src/utilities/InputObject.h
Normal file
36
src/utilities/InputObject.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef INPUTOBJECT_H
|
||||
#define INPUTOBJECT_H
|
||||
|
||||
#include <QWidget>
|
||||
class QLineEdit;
|
||||
class QDateEdit;
|
||||
class QTextEdit;
|
||||
|
||||
//#define CUTE_STYLE
|
||||
|
||||
namespace Ui {
|
||||
class InputObject;
|
||||
}
|
||||
|
||||
class InputObject : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InputObject(QWidget* parent = nullptr);
|
||||
~InputObject();
|
||||
bool eventFilter(QObject* obj, QEvent* event);
|
||||
void ShowPanel();
|
||||
signals:
|
||||
void touchScreen();
|
||||
private:
|
||||
Ui::InputObject* ui;
|
||||
void initUi();
|
||||
// void ShowPanel();
|
||||
void HidePanel();
|
||||
QDateEdit* curDateEdit = nullptr;
|
||||
QLineEdit* curLine = nullptr;
|
||||
QTextEdit* curText = nullptr;
|
||||
};
|
||||
|
||||
#endif // INPUTOBJECT_H
|
||||
67
src/utilities/StdOutRedirector.cpp
Normal file
67
src/utilities/StdOutRedirector.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "StdOutRedirector.h"
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
StdOutRedirector::StdOutRedirector()
|
||||
: QObject()
|
||||
{
|
||||
#ifdef __linux__
|
||||
if (pipe(fdguistd) == -1)
|
||||
printf("failed!");
|
||||
#else
|
||||
// Redirect
|
||||
if (_pipe(fdguistd, 4096, _O_BINARY) == -1)
|
||||
printf("failed!");
|
||||
#endif
|
||||
//int tr = fcntl(fdguistd, O_NONBLOCK);
|
||||
// Duplicate stdout file descriptor (next line will close original)
|
||||
fdStdOut = dup(fileno(stdout));
|
||||
// Duplicate write end of pipe to stdout file descriptor
|
||||
if (dup2(fdguistd[1], fileno(stdout)) != 0)
|
||||
printf("failed!");
|
||||
// Close original
|
||||
close(1);
|
||||
// Duplicate write end of original
|
||||
dup2(fdguistd[1], 1);
|
||||
|
||||
buffer = new char[bufferSize];
|
||||
}
|
||||
|
||||
StdOutRedirector::~StdOutRedirector()
|
||||
{
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
void StdOutRedirector::readOutsToTF()
|
||||
{
|
||||
|
||||
size_t len;
|
||||
char* copy;
|
||||
|
||||
int n_out;
|
||||
QString str;
|
||||
//char buffer[512];
|
||||
//qDebug() << "begin read...";
|
||||
//qDebug() << "from qdebug...";
|
||||
//printf("from printf...");
|
||||
//std::cout << "from std::cout..." << std::endl;
|
||||
fflush(stdout);
|
||||
//Perhaps there is a non-blocking version of _read() that you can call ?
|
||||
memset(buffer, 0, bufferSize);
|
||||
n_out = read(fdguistd[0], buffer, bufferSize);
|
||||
if (n_out <= 0) {
|
||||
return;
|
||||
}
|
||||
if (n_out >= 1) {
|
||||
str.append(QString(buffer));
|
||||
int con = str.lastIndexOf('\n');
|
||||
int remv = str.at(con - 1) == '\n' ? 1 : 0;
|
||||
if (con > 0) {
|
||||
str = str.remove(con - remv, str.length());
|
||||
output->append(str);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
47
src/utilities/StdOutRedirector.h
Normal file
47
src/utilities/StdOutRedirector.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
//class StdOutRedirector : public QObject
|
||||
//{
|
||||
// Q_OBJECT
|
||||
//
|
||||
//public:
|
||||
// StdOutRedirector(QObject *parent);
|
||||
// ~StdOutRedirector();
|
||||
//};
|
||||
|
||||
|
||||
#include <QString>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <QTextEdit>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
class StdOutRedirector : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
StdOutRedirector();
|
||||
~StdOutRedirector();
|
||||
void setOutputTF(QTextEdit* _output)
|
||||
{
|
||||
output = _output;
|
||||
}
|
||||
|
||||
public slots:
|
||||
void readOutsToTF();
|
||||
|
||||
private:
|
||||
QTextEdit* output;
|
||||
int fdStdOut;
|
||||
int fdguistd[2];
|
||||
char* buffer = nullptr;
|
||||
const int bufferSize = 4096;
|
||||
};
|
||||
149
src/utilities/inputobject.ui
Normal file
149
src/utilities/inputobject.ui
Normal file
@@ -0,0 +1,149 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>InputObject</class>
|
||||
<widget class="QWidget" name="InputObject">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>952</width>
|
||||
<height>660</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QWidget" name="WiBack" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>235</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_3" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>214</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDateEdit" name="dateEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="textEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>800</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>235</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="WiBo" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
37
src/utilities/languageswitcher.cpp
Normal file
37
src/utilities/languageswitcher.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "languageswitcher.h"
|
||||
#include <QTranslator>
|
||||
#include "event/EventCenter.h"
|
||||
|
||||
LanguageSwitcher* LanguageSwitcher::lsw = Q_NULLPTR;
|
||||
|
||||
LanguageSwitcher* LanguageSwitcher::Instance()
|
||||
{
|
||||
if (lsw == Q_NULLPTR)
|
||||
{
|
||||
lsw = new LanguageSwitcher();
|
||||
|
||||
}
|
||||
return lsw;
|
||||
}
|
||||
LanguageSwitcher::LanguageSwitcher()
|
||||
{}
|
||||
|
||||
LanguageSwitcher::~LanguageSwitcher()
|
||||
{}
|
||||
|
||||
void LanguageSwitcher::setTranslator(QTranslator* tra)
|
||||
{
|
||||
this->translator = tra;
|
||||
}
|
||||
|
||||
void LanguageSwitcher::setDefaultLanguage(QString str)
|
||||
{
|
||||
QString lan = QString(":/translations/" + str + ".qm");
|
||||
if (translator->load(lan))
|
||||
{
|
||||
//qDebug() << "installTranslator";
|
||||
//QApplication::installTranslator(translator);
|
||||
}
|
||||
EventCenter::Default()->triggerEvent(ReloadLanguage, nullptr, nullptr);
|
||||
}
|
||||
|
||||
25
src/utilities/languageswitcher.h
Normal file
25
src/utilities/languageswitcher.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef LANGUAGESWITCHER_H
|
||||
#define LANGUAGESWITCHER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QTranslator;
|
||||
class LanguageSwitcher : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static LanguageSwitcher* Instance();
|
||||
void setDefaultLanguage(QString str);
|
||||
void setTranslator(QTranslator* tra);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
explicit LanguageSwitcher();
|
||||
~LanguageSwitcher();
|
||||
static LanguageSwitcher* lsw;
|
||||
QTranslator* translator = nullptr;
|
||||
};
|
||||
|
||||
#endif // LANGUAGESWITCHER_H
|
||||
52
src/utilities/locker.cpp
Normal file
52
src/utilities/locker.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "locker.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include "appvals/AppGlobalValues.h"
|
||||
#include "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/utilities/locker.h
Normal file
28
src/utilities/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
|
||||
Reference in New Issue
Block a user