Merge change ,debug window, logout
This commit is contained in:
@@ -3,6 +3,7 @@ set(PROJECT_NAME GUI)
|
||||
project(${PROJECT_NAME})
|
||||
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_cpps ./src/*.cpp)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
//
|
||||
// Created by Krad on 2021/11/10.
|
||||
//
|
||||
|
||||
#include "AccountFormDialog.h"
|
||||
#include "ChangePasswordFormDialog.h"
|
||||
#include <QVBoxLayout>
|
||||
@@ -9,6 +8,7 @@
|
||||
#include <QToolButton>
|
||||
#include <QPushButton>
|
||||
#include <QLineEdit>
|
||||
#include <src/event/EventCenter.h>
|
||||
#include "db/SQLHelper.h"
|
||||
#include "models/User.h"
|
||||
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, [=](){
|
||||
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>
|
||||
|
||||
#define ADD_EVENT()\
|
||||
ADD_EVENT_VALUE(RequestLogin)\
|
||||
ADD_EVENT_VALUE(PatientSelected)\
|
||||
ADD_EVENT_VALUE(RequestPreviewScan)\
|
||||
ADD_EVENT_VALUE(RequestEmptyScan)\
|
||||
|
||||
@@ -135,7 +135,7 @@ void LoginWindow::doLogin()
|
||||
QString strPassWord = m_pPassWordEdit->text();
|
||||
|
||||
QString encryptedPassword = strPassWord;
|
||||
strPassWord = "123456";
|
||||
strPassWord = "12345678";
|
||||
|
||||
|
||||
|
||||
|
||||
45
src/main.cpp
45
src/main.cpp
@@ -6,6 +6,10 @@
|
||||
#include <src/db/SQLHelper.h>
|
||||
#include <QTextCodec>
|
||||
#include <QFontDatabase>
|
||||
#include <QDebug>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
|
||||
QString loadFontFromFile(QString path)
|
||||
{
|
||||
static QString font;
|
||||
@@ -49,22 +53,31 @@ int main(int argc, char* argv[])
|
||||
//a.installEventFilter(obj);
|
||||
InputObject* obj = new InputObject();
|
||||
a.installEventFilter(obj);
|
||||
SQLHelper::Open();
|
||||
MainWindow w;
|
||||
w.showFullScreen();
|
||||
SQLHelper::Open();
|
||||
MainWindow w;
|
||||
|
||||
|
||||
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();
|
||||
return a.exec();
|
||||
} else{
|
||||
w.showFullScreen();
|
||||
w.requestLogin();
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
LoginWindow l;
|
||||
needLogin:
|
||||
l.showFullScreen();
|
||||
int rec = l.exec();
|
||||
if (rec != QDialog::Accepted) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// l.deleteLater();
|
||||
w.centerWidgetShow();
|
||||
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,35 @@
|
||||
#include "ScanFormWidget.h"
|
||||
#include "guimessagedialog.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) :
|
||||
QMainWindow(parent),
|
||||
@@ -35,14 +64,14 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||
"QLineEdit:enabled{background-color: #515151}"
|
||||
"QDateEdit{min-height:36px;max-height:36px; border:1px solid silver}"
|
||||
"QDateEdit:enabled{background-color: #515151}"
|
||||
"QTextEdit{border:1px solid silver}"
|
||||
//"QTextEdit{background-attachment: scroll; }"
|
||||
"QTextEdit:enabled{background-color: #515151}"
|
||||
"QComboBox{text-align:center;min-height:36px;max-height:36px; border:1px solid silver}"
|
||||
"QComboBox:enabled{background-color: #515151}"
|
||||
"QComboBox::drop-down{width:20px}"
|
||||
"QComboBox QAbstractItemView{min-width:120px;}"
|
||||
"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"
|
||||
"QWidget#topbarWidget{min-height:36px;max-height:36px;}\n"
|
||||
"QWidget#contentWidget{border-top:1px solid #515151;}\n"
|
||||
@@ -91,6 +120,7 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||
QHBoxLayout* layout = new QHBoxLayout();
|
||||
layout->setMargin(0);
|
||||
layout->addWidget(tab);
|
||||
|
||||
ui->centralWidget->setLayout(layout);
|
||||
this->setWindowFlags(Qt::Window);
|
||||
connect(EventCenter::Default(), &EventCenter::GUIErrorRaise, [=](QObject*, QObject* msg) {
|
||||
@@ -150,19 +180,53 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||
delete msgDialog;
|
||||
msgDialog = nullptr;
|
||||
});
|
||||
DeviceManager::Default()->initDevice();
|
||||
connect(EventCenter::Default(), &EventCenter::RequestLogin, [=](QObject*, QObject* msg) {
|
||||
this->requestLogin();
|
||||
});
|
||||
DeviceManager::Default()->initDevice();
|
||||
centerWidgetHide();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
delete redir;
|
||||
}
|
||||
|
||||
void MainWindow::centerWidgetHide() {
|
||||
ui->centralWidget->hide();
|
||||
ui->centralWidget->setVisible(false);
|
||||
}
|
||||
|
||||
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,23 +2,29 @@
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "StdOutRedirector.h"
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
class MainWindow;
|
||||
}
|
||||
class GUIMessageDialog;
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
void centerWidgetHide();
|
||||
void centerWidgetShow();
|
||||
explicit MainWindow(QWidget* parent = nullptr);
|
||||
~MainWindow();
|
||||
static void QMessageOutput(QtMsgType, const QMessageLogContext&, const QString& msg);
|
||||
void centerWidgetHide();
|
||||
void centerWidgetShow();
|
||||
void requestLogin();
|
||||
QTextEdit* getEdit();
|
||||
void debugConsoleOn();
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
GUIMessageDialog* msgDialog = nullptr;
|
||||
Ui::MainWindow* ui;
|
||||
GUIMessageDialog* msgDialog = nullptr;
|
||||
StdOutRedirector* redir = nullptr;
|
||||
QTextEdit* console = nullptr;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
Reference in New Issue
Block a user