2,新增“Apps”; 3,新增“Common”; 4,新增“FileList”; 5,新增“MediaX”; 6,新增“OpenSource”; 7,新增“Samples”; 8,新增“SoftwareBusinessLines”.
272 lines
6.6 KiB
C++
272 lines
6.6 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include "../Common/include/jsoncpp/json.h"
|
|
|
|
#include "commonhelper.h"
|
|
#include "frameless_helper.h"
|
|
|
|
#include <fstream>
|
|
#include <QMessageBox>
|
|
#include <QDebug>
|
|
|
|
#include <mmsystem.h>
|
|
#pragma comment(lib, "winmm")
|
|
|
|
#define MaxSize_IRSensorTool (4096*2048)
|
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
QMainWindow(parent),
|
|
ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
this->setWindowTitle(tr(" ") );
|
|
|
|
// OpenGLView
|
|
//this->setAttribute(Qt::WA_Mapped);
|
|
|
|
//
|
|
m_bMousePressed = false;
|
|
|
|
//
|
|
m_bThreadRunning = false;
|
|
m_ptrThread = nullptr;
|
|
|
|
// 初始化界面
|
|
InitStyle();
|
|
|
|
// 加载信号槽函数连接
|
|
Connect();
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
//
|
|
Disconnect();
|
|
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::Connect()
|
|
{
|
|
// 通用
|
|
connect(ui->m_pushButton_MinMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
|
connect(ui->m_pushButton_CloseMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
|
|
|
// 数据库测试
|
|
connect(ui->m_pushButton_LoadFile, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
|
connect(ui->m_pushButton_GenerateFile, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
|
|
|
//
|
|
connect(&m_varTimer, &QTimer::timeout, this, &MainWindow::OnTimer);
|
|
m_varTimer.setTimerType(Qt::PreciseTimer);
|
|
m_varTimer.start(40);
|
|
}
|
|
|
|
void MainWindow::Disconnect()
|
|
{
|
|
// 通用
|
|
disconnect(ui->m_pushButton_MinMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
|
disconnect(ui->m_pushButton_CloseMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
|
|
|
// 数据库测试
|
|
disconnect(ui->m_pushButton_LoadFile, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
|
disconnect(ui->m_pushButton_GenerateFile, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
|
|
|
//
|
|
m_varTimer.stop();
|
|
disconnect(&m_varTimer, &QTimer::timeout, this, &MainWindow::OnTimer);
|
|
}
|
|
|
|
void MainWindow::OnButtonClicked()
|
|
{
|
|
// 最小化
|
|
if(sender() == ui->m_pushButton_MinMenu)
|
|
{
|
|
this->showMinimized();
|
|
}
|
|
|
|
// 退出程序
|
|
if(sender() == ui->m_pushButton_CloseMenu)
|
|
{
|
|
qApp->exit();
|
|
}
|
|
|
|
if(sender() == ui->m_pushButton_LoadFile)
|
|
{
|
|
LoadJsonFile();
|
|
}
|
|
|
|
if(sender() == ui->m_pushButton_GenerateFile)
|
|
{
|
|
GenerateJsonFile();
|
|
}
|
|
}
|
|
|
|
void MainWindow::InitStyle()
|
|
{
|
|
m_bMousePressed = false;
|
|
|
|
//安装事件监听器,让标题栏识别鼠标双击
|
|
ui->lblTitle->installEventFilter(this);
|
|
/*
|
|
this->setWindowFlags(/*Qt::FramelessWindowHint |*
|
|
Qt::WindowTitleHint |
|
|
Qt::WindowSystemMenuHint);
|
|
*/
|
|
FramelessHelper *pHelper = new FramelessHelper(this);
|
|
pHelper->activateOn(this); //激活当前窗体
|
|
pHelper->setTitleHeight(ui->wgtTitleBar->height()); //设置窗体的标题栏高度
|
|
|
|
CommonHelper::SetStyle("blue");//"blue"//"dark"
|
|
}
|
|
|
|
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
|
|
{
|
|
//if (ui->lblTitle == obj)
|
|
{
|
|
if (event->type() == QEvent::MouseButtonPress)
|
|
{
|
|
|
|
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
|
|
|
|
if (mouseEvent->button() == Qt::LeftButton)
|
|
{
|
|
m_bMousePressed = true;
|
|
m_ptMouse = mouseEvent->globalPos() - pos();
|
|
mouseEvent->accept();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
else if (event->type() == QEvent::MouseMove)
|
|
{
|
|
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
|
|
|
|
if (m_bMousePressed && this->windowState() != Qt::WindowMaximized)
|
|
{
|
|
if (mouseEvent->globalY() <= qApp->desktop()->availableGeometry().bottom())
|
|
{
|
|
move(mouseEvent->globalPos() - m_ptMouse);
|
|
mouseEvent->accept();
|
|
}
|
|
else
|
|
{
|
|
qApp->desktop()->cursor().setPos(
|
|
qApp->desktop()->cursor().pos().x(),
|
|
qApp->desktop()->availableGeometry().bottom()
|
|
);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
else if (event->type() == QEvent::MouseButtonRelease)
|
|
{
|
|
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
|
|
|
|
if (mouseEvent->button() == Qt::LeftButton)
|
|
{
|
|
m_bMousePressed = false;
|
|
mouseEvent->accept();
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
return QMainWindow::eventFilter(obj, event);
|
|
}
|
|
|
|
void MainWindow::OnTimer()
|
|
{
|
|
}
|
|
|
|
bool MainWindow::LoadJsonFile()
|
|
{
|
|
Json::Value config;
|
|
Json::Reader jsonReader;
|
|
std::ifstream reader;
|
|
|
|
reader.open("json.txt");
|
|
bool bRs = jsonReader.parse(reader, config);
|
|
reader.close();
|
|
|
|
QString str = config["name"].as<std::string>().c_str();
|
|
str = config["skills"]["c++"]["cpp11"].as<std::string>().c_str();
|
|
str = config["age"].as<std::string>().c_str();
|
|
|
|
ui->m_textEdit_Result->setText(config.toStyledString().c_str() );
|
|
|
|
return true;
|
|
}
|
|
|
|
bool MainWindow::GenerateJsonFile()
|
|
{
|
|
Json::Value config;
|
|
config["name"] = "guide coder";
|
|
config["skills"]["c++"]["cpp11"] = "c++11";
|
|
config["skills"]["c++"]["cpp14"] = "c++14";
|
|
config["skills"]["c++"]["cpp17"] = "c++17";
|
|
config["skills"]["c++"]["cpp19"] = "c++19";
|
|
config["skills"]["c++"]["cpp22"] = "c++22";
|
|
config["skills"]["java"]["javase"] = "javase 8";
|
|
config["skills"]["java"]["javame"] = "javame 8";
|
|
config["skills"]["java"]["javaee"] = "javaee 8";
|
|
config["age"] = "22";
|
|
|
|
Json::String str = config.toStyledString();
|
|
std::ofstream varGenYamlFile("json.txt");
|
|
varGenYamlFile << config;
|
|
varGenYamlFile.close();
|
|
|
|
return true;
|
|
}
|
|
|
|
void MainWindow::ThreadEntry(ThreadRunFunPtr pRunFun, void* pOwner)
|
|
{
|
|
MainWindow* pThis = reinterpret_cast<MainWindow*>(pOwner);
|
|
|
|
if (NULL == pThis)
|
|
{
|
|
return;
|
|
}
|
|
|
|
(pThis->*pRunFun)();
|
|
}
|
|
|
|
void MainWindow::ThreadFun()
|
|
{
|
|
timeBeginPeriod(1);
|
|
|
|
|
|
timeEndPeriod(1);
|
|
}
|
|
|
|
bool MainWindow::StartThread()
|
|
{
|
|
StopThread();
|
|
|
|
//
|
|
m_bThreadRunning = true;
|
|
m_ptrThread = new std::thread(std::bind(&MainWindow::ThreadEntry, &MainWindow::ThreadFun, (void*)this));
|
|
|
|
return true;
|
|
}
|
|
|
|
void MainWindow::StopThread()
|
|
{
|
|
//
|
|
if(m_bThreadRunning)
|
|
{
|
|
m_bThreadRunning = false;
|
|
|
|
if(nullptr != m_ptrThread)
|
|
{
|
|
m_ptrThread->join();
|
|
|
|
delete m_ptrThread;
|
|
m_ptrThread = nullptr;
|
|
}
|
|
}
|
|
}
|