IPBS_Station/widget.h
2024-08-13 17:07:34 +08:00

132 lines
4.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include "CCSocket.h"
#include "CCThread.h"
#include "nlohmann/json.hpp"
#include "QMessageBox"
#include "ctime"
#include <QCloseEvent>
#include <QPaintEvent>
#include <QPainter>
#include <QMetaMethod>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QProcess>
#include "QDateTime"
#include "QCoreApplication"
#include "CCString.h"
#include "QFile"
#include "CCFile.h"
#include "vector"
#include "Tools/CText.h"
#include <QAbstractSocket>
#include <QHostAddress>
#include <QNetworkInterface>
#include <QFileDialog>
#ifdef _WIN32
#include <tchar.h>
#include <windows.h>
#include <tlhelp32.h>
#elif __linux__
#endif
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
private:
//E:/project/UDate/Project/QtProject/WebDeploy/
const CCString WebSubPaths = "./";
const CCString ServerSttingsPath = "./src/main/resources/ServerSettings/ServerSettings.CText";
const CCString NginxSttingsPath = "./conf/nginx.conf";
CCThread WebThread, ServerThread;
#ifdef _WIN32
const CCString NginxExe = "./WebSub/nginx.exe";
const CCString JavaExe = "WebSub/jreWin/bin/java.exe";
#elif __linux__
const CCString NginxExe = "./WebSub/nginx";
const CCString JavaExe = "WebSub/jreLinux/bin/java";
#endif
QProcess process,nginxprocess;
QRect m_areaMovable;//可移动窗口的区域,鼠标只有在该区域按下才能移动窗口
bool m_bPressed;//鼠标按下标志(不分左右键)
QPoint m_ptPress;//鼠标按下的初始位置
QSystemTrayIcon *trayIcon = new QSystemTrayIcon(this);
QMenu *trayIconMenu = new QMenu(this);
QAction *quitAction = new QAction(tr("&退出"), this);
QAction *showAction = new QAction(tr("&显示"), this);
std::map<CCString,CCString> ServerSettings;
int t = 0,h = 0,f = 0,s = 0;
public:
Widget(QWidget *parent = nullptr);
~Widget();
void on_pushButton_clicked();
void on_pushButton_clicked2();
void WebThreadRun();
bool WebRunFun();
void ServerListening();
void OpenServerClick();
bool isJarRunning(const char* jarName);
bool terminateProcessByName(const char* processName);
void ServerReRun();
void onCurrentIndexChanged(int index);
void SetSuBState(bool F);
void SetWebState(bool F);
void SetSaveBtn();
void Initlogo();
void SelectFile();
private:
Ui::Widget *ui;
bool ServerFlag = false;
std::vector<QPushButton*> Btns;
void OpenFlagBtn(bool F);
void SetPage(int i);
void SetBtn(int i);
void ServerConfigInit();
void onTextChanged(const QString &text);
bool isTime235959();
protected:
void closeEvent(QCloseEvent *event) override;
void paintEvent(QPaintEvent * event) override{
QPainter painter(this);// 创建一个QPainter对象并指定绘制设备为this即当前窗口
painter.setRenderHint(QPainter::Antialiasing); // 设置绘制选项为反锯齿,使绘制的图形边缘更加平滑
painter.setBrush(QBrush(QColor(255, 255, 255))); //设置画刷颜色,这里为白色
painter.setPen(Qt::transparent); //设置画笔颜色为透明,即不绘制边框线
QRect rect = this->rect(); //获取当前窗口的矩形区域
painter.drawRoundedRect(rect, 15, 15);
}
void mousePressEvent(QMouseEvent *e) override {
// 鼠标左键
if (e->button() == Qt::LeftButton) {
m_ptPress = e->pos();
m_bPressed = true; // 修改这里总是设置为true因为我们希望点击控件时移动窗口
}
}
void mouseMoveEvent(QMouseEvent *e) override {
if (m_bPressed) {
move(pos() + e->pos() - m_ptPress);
}
}
void mouseReleaseEvent(QMouseEvent *) override {
m_bPressed = false;
}
void setAreaMovable(const QRect rt) {
// 这里不需要再判断是否改变,因为我们将直接在控件上响应鼠标事件
m_areaMovable = rt;
}
};
#endif // WIDGET_H