Merge change ,debug window, logout
This commit is contained in:
@@ -3,6 +3,7 @@ set(PROJECT_NAME GUI)
|
|||||||
project(${PROJECT_NAME})
|
project(${PROJECT_NAME})
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
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_cpps ./src/*.cpp)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
//
|
//
|
||||||
// Created by Krad on 2021/11/10.
|
// Created by Krad on 2021/11/10.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "AccountFormDialog.h"
|
#include "AccountFormDialog.h"
|
||||||
#include "ChangePasswordFormDialog.h"
|
#include "ChangePasswordFormDialog.h"
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
@@ -9,6 +8,7 @@
|
|||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
#include <src/event/EventCenter.h>
|
||||||
#include "db/SQLHelper.h"
|
#include "db/SQLHelper.h"
|
||||||
#include "models/User.h"
|
#include "models/User.h"
|
||||||
AccountFormDialog::AccountFormDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
|
AccountFormDialog::AccountFormDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
|
||||||
@@ -84,7 +84,7 @@ AccountFormDialog::AccountFormDialog(QWidget *parent, Qt::WindowFlags f) : GUIFo
|
|||||||
|
|
||||||
connect(btn_Logout, &QAbstractButton::clicked, [=](){
|
connect(btn_Logout, &QAbstractButton::clicked, [=](){
|
||||||
this->accept();
|
this->accept();
|
||||||
this->parentWidget()->parentWidget()->parentWidget()->hide();
|
EventCenter::Default()->triggerEvent(GUIEvents::RequestLogin, nullptr, nullptr);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
62
src/StdOutRedirector.cpp
Normal file
62
src/StdOutRedirector.cpp
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
|
StdOutRedirector::~StdOutRedirector()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void StdOutRedirector::readOutsToTF()
|
||||||
|
{
|
||||||
|
|
||||||
|
int n_out;
|
||||||
|
char* buffer = new char[4096];
|
||||||
|
QString str;
|
||||||
|
//char buffer[512];
|
||||||
|
//qDebug() << "from qdebug...";
|
||||||
|
//printf("from printf...\n");
|
||||||
|
//std::cout << "from std::cout..." << std::endl;
|
||||||
|
fflush(stdout);
|
||||||
|
//Perhaps there is a non-blocking version of _read() that you can call ?
|
||||||
|
n_out = read(fdguistd[0], buffer, 4096);
|
||||||
|
|
||||||
|
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) {
|
||||||
|
str = str.remove(con - remv, str.length());
|
||||||
|
output->append(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
45
src/StdOutRedirector.h
Normal file
45
src/StdOutRedirector.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#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];
|
||||||
|
};
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#define ADD_EVENT()\
|
#define ADD_EVENT()\
|
||||||
|
ADD_EVENT_VALUE(RequestLogin)\
|
||||||
ADD_EVENT_VALUE(PatientSelected)\
|
ADD_EVENT_VALUE(PatientSelected)\
|
||||||
ADD_EVENT_VALUE(RequestPreviewScan)\
|
ADD_EVENT_VALUE(RequestPreviewScan)\
|
||||||
ADD_EVENT_VALUE(RequestEmptyScan)\
|
ADD_EVENT_VALUE(RequestEmptyScan)\
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ void LoginWindow::doLogin()
|
|||||||
QString strPassWord = m_pPassWordEdit->text();
|
QString strPassWord = m_pPassWordEdit->text();
|
||||||
|
|
||||||
QString encryptedPassword = strPassWord;
|
QString encryptedPassword = strPassWord;
|
||||||
strPassWord = "123456";
|
strPassWord = "12345678";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
41
src/main.cpp
41
src/main.cpp
@@ -6,6 +6,10 @@
|
|||||||
#include <src/db/SQLHelper.h>
|
#include <src/db/SQLHelper.h>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QThread>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
QString loadFontFromFile(QString path)
|
QString loadFontFromFile(QString path)
|
||||||
{
|
{
|
||||||
static QString font;
|
static QString font;
|
||||||
@@ -51,20 +55,29 @@ int main(int argc, char* argv[])
|
|||||||
a.installEventFilter(obj);
|
a.installEventFilter(obj);
|
||||||
SQLHelper::Open();
|
SQLHelper::Open();
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.showFullScreen();
|
|
||||||
|
|
||||||
|
QStringList app_args = a.arguments();
|
||||||
|
if (app_args.contains("-d"))
|
||||||
{
|
{
|
||||||
|
w.debugConsoleOn();
|
||||||
LoginWindow l;
|
qInstallMessageHandler(MainWindow::QMessageOutput);
|
||||||
needLogin:
|
QThread thread;
|
||||||
l.showFullScreen();
|
StdOutRedirector redir;
|
||||||
int rec = l.exec();
|
redir.setOutputTF(w.getEdit());
|
||||||
if (rec != QDialog::Accepted) {
|
QTimer Timer;
|
||||||
return 0;
|
redir.moveToThread(&thread);
|
||||||
}
|
QObject::connect(&Timer, SIGNAL(timeout()), &redir, SLOT(readOutsToTF()));
|
||||||
}
|
fflush(stdout);
|
||||||
// l.deleteLater();
|
Timer.start(1000);
|
||||||
w.centerWidgetShow();
|
thread.start();
|
||||||
|
w.showFullScreen();
|
||||||
|
w.requestLogin();
|
||||||
|
return a.exec();
|
||||||
|
} else{
|
||||||
|
w.showFullScreen();
|
||||||
|
w.requestLogin();
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,6 +9,35 @@
|
|||||||
#include "ScanFormWidget.h"
|
#include "ScanFormWidget.h"
|
||||||
#include "guimessagedialog.h"
|
#include "guimessagedialog.h"
|
||||||
#include "device/DeviceManager.h"
|
#include "device/DeviceManager.h"
|
||||||
|
#include "loginwindow.h"
|
||||||
|
#include <QTextEdit>
|
||||||
|
#include <QScrollBar>
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::QMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg)
|
||||||
|
{
|
||||||
|
|
||||||
|
std::cout << msg.toStdString().c_str() << std::endl;
|
||||||
|
|
||||||
|
//QByteArray localMsg = msg.toLocal8Bit();
|
||||||
|
//switch (type) {
|
||||||
|
//case QtDebugMsg:
|
||||||
|
// fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
||||||
|
// break;
|
||||||
|
//case QtInfoMsg:
|
||||||
|
// fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
||||||
|
// break;
|
||||||
|
//case QtWarningMsg:
|
||||||
|
// fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
||||||
|
// break;
|
||||||
|
//case QtCriticalMsg:
|
||||||
|
// fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
||||||
|
// break;
|
||||||
|
//case QtFatalMsg:
|
||||||
|
// fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
||||||
|
// abort();
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget* parent) :
|
MainWindow::MainWindow(QWidget* parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
@@ -35,14 +64,14 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||||||
"QLineEdit:enabled{background-color: #515151}"
|
"QLineEdit:enabled{background-color: #515151}"
|
||||||
"QDateEdit{min-height:36px;max-height:36px; border:1px solid silver}"
|
"QDateEdit{min-height:36px;max-height:36px; border:1px solid silver}"
|
||||||
"QDateEdit:enabled{background-color: #515151}"
|
"QDateEdit:enabled{background-color: #515151}"
|
||||||
"QTextEdit{border:1px solid silver}"
|
//"QTextEdit{background-attachment: scroll; }"
|
||||||
"QTextEdit:enabled{background-color: #515151}"
|
"QTextEdit:enabled{background-color: #515151}"
|
||||||
"QComboBox{text-align:center;min-height:36px;max-height:36px; border:1px solid silver}"
|
"QComboBox{text-align:center;min-height:36px;max-height:36px; border:1px solid silver}"
|
||||||
"QComboBox:enabled{background-color: #515151}"
|
"QComboBox:enabled{background-color: #515151}"
|
||||||
"QComboBox::drop-down{width:20px}"
|
"QComboBox::drop-down{width:20px}"
|
||||||
"QComboBox QAbstractItemView{min-width:120px;}"
|
"QComboBox QAbstractItemView{min-width:120px;}"
|
||||||
"QComboBox QAbstractItemView::item {min-height:60px;max-height:60px; border:1px solid white;}"
|
"QComboBox QAbstractItemView::item {min-height:60px;max-height:60px; border:1px solid white;}"
|
||||||
"QScrollBar:vertical {min-width: 50px;}"
|
//"QScrollBar:vertical {min-width: 50px;}"
|
||||||
"QLabel{color:white; font-weight:bold; font-size:16px;}\n"
|
"QLabel{color:white; font-weight:bold; font-size:16px;}\n"
|
||||||
"QWidget#topbarWidget{min-height:36px;max-height:36px;}\n"
|
"QWidget#topbarWidget{min-height:36px;max-height:36px;}\n"
|
||||||
"QWidget#contentWidget{border-top:1px solid #515151;}\n"
|
"QWidget#contentWidget{border-top:1px solid #515151;}\n"
|
||||||
@@ -91,6 +120,7 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||||||
QHBoxLayout* layout = new QHBoxLayout();
|
QHBoxLayout* layout = new QHBoxLayout();
|
||||||
layout->setMargin(0);
|
layout->setMargin(0);
|
||||||
layout->addWidget(tab);
|
layout->addWidget(tab);
|
||||||
|
|
||||||
ui->centralWidget->setLayout(layout);
|
ui->centralWidget->setLayout(layout);
|
||||||
this->setWindowFlags(Qt::Window);
|
this->setWindowFlags(Qt::Window);
|
||||||
connect(EventCenter::Default(), &EventCenter::GUIErrorRaise, [=](QObject*, QObject* msg) {
|
connect(EventCenter::Default(), &EventCenter::GUIErrorRaise, [=](QObject*, QObject* msg) {
|
||||||
@@ -150,6 +180,9 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||||||
delete msgDialog;
|
delete msgDialog;
|
||||||
msgDialog = nullptr;
|
msgDialog = nullptr;
|
||||||
});
|
});
|
||||||
|
connect(EventCenter::Default(), &EventCenter::RequestLogin, [=](QObject*, QObject* msg) {
|
||||||
|
this->requestLogin();
|
||||||
|
});
|
||||||
DeviceManager::Default()->initDevice();
|
DeviceManager::Default()->initDevice();
|
||||||
centerWidgetHide();
|
centerWidgetHide();
|
||||||
}
|
}
|
||||||
@@ -157,12 +190,43 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
|
delete redir;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::centerWidgetHide() {
|
void MainWindow::centerWidgetHide() {
|
||||||
ui->centralWidget->hide();
|
ui->centralWidget->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::centerWidgetShow() {
|
void MainWindow::centerWidgetShow() {
|
||||||
ui->centralWidget->show();
|
qApp->processEvents();
|
||||||
|
ui->centralWidget->setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QTextEdit* MainWindow::getEdit()
|
||||||
|
{
|
||||||
|
return this->console;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::requestLogin() {
|
||||||
|
LoginWindow l(this);
|
||||||
|
l.showFullScreen();
|
||||||
|
this->centerWidgetHide();
|
||||||
|
while(l.result() != QDialog::Accepted)
|
||||||
|
{
|
||||||
|
l.exec();
|
||||||
|
}
|
||||||
|
this->centerWidgetShow();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::debugConsoleOn() {
|
||||||
|
QTextEdit* text_edit = new QTextEdit(this);
|
||||||
|
ui->centralWidget->layout()->addWidget(text_edit);
|
||||||
|
const QString edit_style =
|
||||||
|
"QScrollBar:vertical{border: 0px solid grey; background:#2d2d2d; width: 15px; margin: 0px 0 0px 0; }"
|
||||||
|
"QScrollBar::handle:vertical{background:#5a5a5a;min-height: 25px;}"
|
||||||
|
"QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical{background:#2d2d2d;}";
|
||||||
|
text_edit->verticalScrollBar()->setStyleSheet(edit_style);
|
||||||
|
//clear buffer before redirect;
|
||||||
|
this->console = text_edit;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include "StdOutRedirector.h"
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
}
|
}
|
||||||
@@ -14,11 +14,17 @@ class MainWindow : public QMainWindow
|
|||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget* parent = nullptr);
|
explicit MainWindow(QWidget* parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
static void QMessageOutput(QtMsgType, const QMessageLogContext&, const QString& msg);
|
||||||
void centerWidgetHide();
|
void centerWidgetHide();
|
||||||
void centerWidgetShow();
|
void centerWidgetShow();
|
||||||
|
void requestLogin();
|
||||||
|
QTextEdit* getEdit();
|
||||||
|
void debugConsoleOn();
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow* ui;
|
Ui::MainWindow* ui;
|
||||||
GUIMessageDialog* msgDialog = nullptr;
|
GUIMessageDialog* msgDialog = nullptr;
|
||||||
|
StdOutRedirector* redir = nullptr;
|
||||||
|
QTextEdit* console = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user