mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
添加Openssl,Gmssl加密库
This commit is contained in:
178
src/qt/MainApp.cpp
Normal file
178
src/qt/MainApp.cpp
Normal file
@@ -0,0 +1,178 @@
|
||||
#include "MainApp.h"
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QComboBox>
|
||||
#include <QtWidgets/QGridLayout>
|
||||
#include <QtWidgets/QLabel>
|
||||
#include <QtWidgets/QLineEdit>
|
||||
#include <QtWidgets/QPushButton>
|
||||
#include <QtWidgets/QWidget>
|
||||
#include <QPalette>
|
||||
#include <QGroupBox>
|
||||
|
||||
static const std::string QSS_BTN_MENU =
|
||||
"QPushButton{background:rgba(50,128,218,200);color:white;border-radius:5px;border:2px solid rgb(10,120,215);font:bold 18px;}"
|
||||
"QPushButton:hover{background-color:rgb(32,164,128);}"
|
||||
"QPushButton:pressed{border-width:3px 0 0 3px;background-color:rgb(1,32,54);border-style:inset;}"
|
||||
"QPushButton:disabled{color:rgb(150,150,150);}";
|
||||
|
||||
static const std::string QSS_LINE =
|
||||
"QLineEdit { background-color: rgb(14, 49, 66); color: #ffffff; border: 1px solid rgb(18, 251, 255); border-radius: 5px; font: normal 13px; }";
|
||||
|
||||
static const std::string QSS_GROUP =
|
||||
"QGroupBox { border: 1px solid gray; margin-top: 8px; border-radius: 5px;}"
|
||||
"QGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; left:10px; margin-left: 0px; padding:0 1px; }";
|
||||
|
||||
MainApp::MainApp()
|
||||
{
|
||||
QPalette palette(this->palette());
|
||||
|
||||
// 设置背景为黑色
|
||||
palette.setColor(QPalette::Window, QColor(1, 32, 54));
|
||||
this->setAutoFillBackground(true);
|
||||
this->setPalette(palette);
|
||||
this->setStyleSheet("color: white;");
|
||||
|
||||
this->resize(1440, 900);
|
||||
this->show();
|
||||
|
||||
//ui.bkg.setGeometry(0, 0, 1440, 900);
|
||||
//ui.bkg.setStyleSheet("background-color: rgb(17, 36, 102);");
|
||||
|
||||
//ui.weburl = std::make_shared<LabelPair>(this, 10, 10, 240, 30);
|
||||
//ui.weburl->setTitle("页面地址:");
|
||||
//ui.weburl->setValue("http://www.baidu.com");
|
||||
|
||||
this->setMyLayout();
|
||||
}
|
||||
|
||||
class MyMenu : public QWidget
|
||||
{
|
||||
public:
|
||||
MyMenu(QWidget* parent) : QWidget(parent), layout(this)
|
||||
{
|
||||
this->setObjectName("menu");
|
||||
this->setStyleSheet("#menu { background-color:rgba(120,120,120,80); }");
|
||||
this->show();
|
||||
vecMenuItems.reserve(20);
|
||||
|
||||
layout.setSpacing(2);
|
||||
layout.setContentsMargins(2, 2, 2, 2);
|
||||
|
||||
this->addMenuItem("系统总览");
|
||||
this->addMenuItem("运行监控");
|
||||
}
|
||||
|
||||
void addMenuItem(std::string name)
|
||||
{
|
||||
int row = vecMenuItems.size();
|
||||
auto item = std::make_shared<QPushButton>(this);
|
||||
vecMenuItems.push_back(item);
|
||||
item->setText(name.c_str());
|
||||
item->setStyleSheet(QSS_BTN_MENU.c_str());
|
||||
|
||||
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
item->setSizePolicy(sizePolicy);
|
||||
layout.addWidget(item.get(), row, 0, 1, 1);
|
||||
|
||||
// 设置列宽和行高
|
||||
layout.setRowMinimumHeight(row, 50); // 设置第0列的最小宽度为100像素
|
||||
// 设置列和行的伸缩因子
|
||||
layout.setRowStretch(row, 0); // 设置第0列的伸缩因子为0,不伸缩
|
||||
layout.setRowStretch(row+1, 2); // 设置第1列的伸缩因子为2,使其更宽
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<QPushButton>> vecMenuItems;
|
||||
|
||||
QGridLayout layout;
|
||||
};
|
||||
|
||||
void PairLine(QWidget* parent, int x, int y, string k, string v)
|
||||
{
|
||||
auto key = new QLabel(parent);
|
||||
key->setText(k.c_str());
|
||||
key->setGeometry(x, y, 80, 26);
|
||||
auto value = new QLineEdit(parent);
|
||||
value->setText(v.c_str());
|
||||
value->setGeometry(x+80, y, 180, 26);
|
||||
value->setStyleSheet(QSS_LINE.c_str());
|
||||
}
|
||||
|
||||
|
||||
class MyWorkspace : public QWidget
|
||||
{
|
||||
public:
|
||||
MyWorkspace(QWidget* parent) : QWidget(parent)
|
||||
{
|
||||
this->setObjectName("workspace");
|
||||
this->setStyleSheet("#workspace { background-color:rgba(100,100,100,50); }");
|
||||
|
||||
int x=10, y=10;
|
||||
{
|
||||
QGroupBox* groupBox = new QGroupBox("HTTP", this);
|
||||
groupBox->setGeometry(x, y, 300, 120);
|
||||
groupBox->setStyleSheet(QSS_GROUP.c_str());
|
||||
|
||||
PairLine(groupBox, 20, 20, "服务类型: ", "服务端");
|
||||
PairLine(groupBox, 20, 50, "服务地址: ", "92.168.0.13:17900");
|
||||
PairLine(groupBox, 20, 80, "服务状态: ", "---");
|
||||
}
|
||||
{
|
||||
x += 320;
|
||||
QGroupBox* groupBox = new QGroupBox("MQTT", this);
|
||||
groupBox->setGeometry(x, y, 300, 120);
|
||||
groupBox->setStyleSheet(QSS_GROUP.c_str());
|
||||
|
||||
PairLine(groupBox, 20, 20, "服务类型: ", "客户端");
|
||||
PairLine(groupBox, 20, 50, "服务地址: ", "92.168.0.13:17800");
|
||||
PairLine(groupBox, 20, 80, "服务状态: ", "---");
|
||||
}
|
||||
{
|
||||
x += 320;
|
||||
QGroupBox* groupBox = new QGroupBox("数据库", this);
|
||||
groupBox->setGeometry(x, y, 300, 120);
|
||||
groupBox->setStyleSheet(QSS_GROUP.c_str());
|
||||
|
||||
PairLine(groupBox, 20, 20, "数据库名: ", "ees");
|
||||
PairLine(groupBox, 20, 50, "主机地址: ", "92.168.0.13:17800");
|
||||
PairLine(groupBox, 20, 80, "用 户 名: ", "root");
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void MainApp::setMyLayout()
|
||||
{
|
||||
layout.main = std::make_shared<QGridLayout>(this);
|
||||
|
||||
auto Widget = this;
|
||||
|
||||
layout.main->setObjectName(QString::fromUtf8("layout.main"));
|
||||
layout.main->setSpacing(6);
|
||||
layout.main->setContentsMargins(11, 11, 11, 11);
|
||||
//// 设置间距和边距
|
||||
//layout->setHorizontalSpacing(10); // 设置列间距为10像素
|
||||
//layout->setVerticalSpacing(10); // 设置行间距为10像素
|
||||
//layout->setContentsMargins(10, 10, 10, 10); // 设置内容边距为10像素
|
||||
|
||||
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
|
||||
MyMenu* menu = new MyMenu(this);
|
||||
menu->setSizePolicy(sizePolicy);
|
||||
layout.main->addWidget(menu, 0, 0, 1, 1);
|
||||
|
||||
MyWorkspace* workspace = new MyWorkspace(this);
|
||||
workspace->setSizePolicy(sizePolicy);
|
||||
layout.main->addWidget(workspace, 0, 1, 1, 1);
|
||||
|
||||
// 设置列宽和行高
|
||||
layout.main->setColumnMinimumWidth(0, 200); // 设置第0列的最小宽度为100像素
|
||||
//gridLayout->setRowMinimumHeight(0, 200); // 设置第0行的最小高度为50像素
|
||||
|
||||
// 设置列和行的伸缩因子
|
||||
layout.main->setColumnStretch(0, 0); // 设置第0列的伸缩因子为0,不伸缩
|
||||
layout.main->setColumnStretch(1, 2); // 设置第1列的伸缩因子为2,使其更宽
|
||||
//gridLayout->setRowStretch(0, 1); // 设置第0行的伸缩因子为1
|
||||
|
||||
}
|
||||
53
src/qt/MainApp.h
Normal file
53
src/qt/MainApp.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <QMainWindow>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QHBoxLayout>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
class LabelPair
|
||||
{
|
||||
public:
|
||||
LabelPair(QWidget* parent, int x, int y, int w, int h)
|
||||
{
|
||||
title.setParent(parent);
|
||||
value.setParent(&title);
|
||||
|
||||
title.setGeometry(x, y, w, h);
|
||||
value.setGeometry(80, 0, w-80, h);
|
||||
|
||||
title.show();
|
||||
value.show();
|
||||
}
|
||||
|
||||
void setTitle(std::string text)
|
||||
{
|
||||
title.setText(text.c_str());
|
||||
}
|
||||
|
||||
void setValue(std::string text)
|
||||
{
|
||||
value.setText(text.c_str());
|
||||
}
|
||||
|
||||
QLabel title;
|
||||
QLabel value;
|
||||
};
|
||||
|
||||
class MainApp : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainApp();
|
||||
|
||||
void setMyLayout();
|
||||
|
||||
struct {
|
||||
std::shared_ptr<LabelPair> weburl {};
|
||||
} ui;
|
||||
|
||||
struct {
|
||||
std::shared_ptr<QGridLayout> main;
|
||||
} layout;
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user