sss
|
@ -9,6 +9,7 @@ CONFIG += c++17
|
|||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
SOURCES += \
|
||||
appinit.cpp \
|
||||
libmodbus/modbus-data.c \
|
||||
libmodbus/modbus-rtu.c \
|
||||
libmodbus/modbus-tcp.c \
|
||||
|
@ -17,6 +18,7 @@ SOURCES += \
|
|||
mainwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
appinit.h \
|
||||
libmodbus/config.h \
|
||||
libmodbus/modbus-private.h \
|
||||
libmodbus/modbus-rtu-private.h \
|
||||
|
@ -52,3 +54,6 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
|
|||
|
||||
DISTFILES += \
|
||||
emsshower.ini
|
||||
|
||||
RESOURCES += \
|
||||
qss.qrc
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
#include "appinit.h"
|
||||
//#include "qmutex.h"
|
||||
#include "qapplication.h"
|
||||
#include "qevent.h"
|
||||
#include "qwidget.h"
|
||||
|
||||
AppInit AppInit::self;
|
||||
AppInit *AppInit::Instance()
|
||||
{
|
||||
// if (!self)
|
||||
// {
|
||||
// QMutex mutex;
|
||||
// QMutexLocker locker(&mutex);
|
||||
// if (!self)
|
||||
// {
|
||||
// self = new AppInit;
|
||||
// }
|
||||
// }
|
||||
|
||||
return &self;
|
||||
}
|
||||
|
||||
AppInit::AppInit(QObject *parent) : QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool AppInit::eventFilter(QObject *obj, QEvent *evt)
|
||||
{
|
||||
QWidget *w = (QWidget *)obj;
|
||||
if (!w->property("canMove").toBool())
|
||||
{
|
||||
return QObject::eventFilter(obj, evt);
|
||||
}
|
||||
|
||||
static QPoint mousePoint;
|
||||
static bool mousePressed = false;
|
||||
|
||||
QMouseEvent *event = static_cast<QMouseEvent *>(evt);
|
||||
if (event->type() == QEvent::MouseButtonPress)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
mousePressed = true;
|
||||
mousePoint = event->globalPos() - w->pos();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (event->type() == QEvent::MouseButtonRelease)
|
||||
{
|
||||
mousePressed = false;
|
||||
return true;
|
||||
}
|
||||
else if (event->type() == QEvent::MouseMove)
|
||||
{
|
||||
if (mousePressed && (event->buttons() && Qt::LeftButton))
|
||||
{
|
||||
w->move(event->globalPos() - mousePoint);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return QObject::eventFilter(obj, evt);
|
||||
}
|
||||
|
||||
void AppInit::start()
|
||||
{
|
||||
qApp->installEventFilter(this);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef APPINIT_H
|
||||
#define APPINIT_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class AppInit : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static AppInit *Instance();
|
||||
explicit AppInit(QObject *parent = 0);
|
||||
|
||||
void start();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *evt);
|
||||
|
||||
private:
|
||||
static AppInit self;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
};
|
||||
|
||||
#endif // APPINIT_H
|
|
@ -0,0 +1,44 @@
|
|||
* { color: #3d4150; }
|
||||
QPushButton { border-style: none;border: 1px solid #DCDFE6;border-radius: 6px;padding: 5px 10px;font-size: 13px; }
|
||||
QPushButton:hover { color: #ffffff; font-weight: bold; background-color: #fd839a; }
|
||||
QScrollBar:vertical { background:#f5f6f8; padding:0px; border-radius: 3px; width:6px; }
|
||||
QScrollBar::handle:vertical { background:#C0C4CC; border-radius: 3px; }
|
||||
QScrollBar::handle:vertical:hover { background:#909399; }
|
||||
QScrollBar::handle:vertical:pressed { background:#909399; }
|
||||
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical, QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical { background:none; }
|
||||
QCheckBox, QRadioButton { font-size: 13px; }
|
||||
QComboBox, QLineEdit, QTextEdit, QTextBrowser, QTimeEdit, QDateEdit, QDateTimeEdit, QSpinBox,
|
||||
QDoubleSpinBox { background-color: #ffffff; border: 1px solid #DCDFE6; border-radius: 6px; padding: 5px 10px; font-size: 13px; }
|
||||
QTextEdit, QTextBrowser { padding-right: 3px; }
|
||||
QLineEdit:hover, QComboBox:hover, QTimeEdit:hover, QDateEdit:hover, QDateTimeEdit:hover, QSpinBox:hover, QDoubleSpinBox:hover { border: 1px solid #409EFF; }
|
||||
QComboBox::down-arrow { width:10px; height:10px; right:2px; image:url(:/icons/down.png); }
|
||||
QComboBox::drop-down { subcontrol-origin:padding; subcontrol-position:top right; width:15px; border-left-width:0px; border-left-style:solid; border-top-right-radius:3px; border-bottom-right-radius:3px; border-left-color:#242424; }
|
||||
QComboBox QAbstractItemView::item{ min-height:20px; min-width:10px; }
|
||||
QComboBox::drop-down:on{ top: 1px; }
|
||||
QTimeEdit::up-button, QDateEdit::up-button, QDateTimeEdit::up-button, QSpinBox::up-button, QDoubleSpinBox::up-button { width:10px; height:10px; image:url(:/icons/up.png); padding: 3px 8px 0px 0px; }
|
||||
QTimeEdit::down-button, QDateEdit::down-button, QDateTimeEdit::down-button, QSpinBox::down-button, QDoubleSpinBox::down-button { width:10px; height:10px; image:url(:/icons/down.png); padding: 0px 8px 3px 0px; }
|
||||
QTimeEdit::up-button:pressed, QDateEdit::up-button:pressed, QDateTimeEdit::up-button:pressed, QSpinBox::up-button:pressed, QDoubleSpinBox::up-button:pressed { top: -2px; }
|
||||
QTimeEdit::down-button:pressed, QDateEdit::down-button:pressed, QDateTimeEdit::down-button:pressed, QSpinBox::down-button:pressed, QDoubleSpinBox::down-button:pressed { bottom: -2px; }
|
||||
QTabWidget::pane{ border:1px solid #DCDFE6; border-radius: 6px; border-top-left-radius: 0px; background-color: #ffffff; selection-background-color:#ffffff; selection-color:#DCDFE6; alternate-background-color:#f2f1f5; gridline-color:#3d4150; }
|
||||
QTabBar::tab { border:1px solid #DCDFE6; border-top-left-radius: 6px; border-top-right-radius: 6px; font-size: 13px; background-color: #f2f1f5; padding: 2px 6px; }
|
||||
QTabWidget::pane:top { top:-1px; }
|
||||
QTabWidget::pane:bottom { bottom:-1px; }
|
||||
QTabWidget::pane:left { right:-1px; }
|
||||
QTabWidget::pane:right { left:-1px; }
|
||||
QTabBar::tab:selected { background-color: #ffffff; border-bottom: none; }
|
||||
QGroupBox { border: 1px solid #DCDFE6; border-radius: 6px; font-size: 13px; margin-top: 7px; }
|
||||
QGroupBox::title { subcontrol-origin: margin; subcontrol-position: top center; padding: 0px 5px 3px; }
|
||||
#w_bg { background-color: #f2f1f5; border-radius: 22px; }
|
||||
#w_menu { background-color: #f8f8f8; border-radius: 16px; }
|
||||
#btn_menu_item_1, #btn_menu_item_2, #btn_menu_item_3, #btn_menu_item_4, #btn_menu_item_5, #btn_menu_item_6 { background-color: #ffffff; border-radius: 5px; padding: 12px 0 0; }
|
||||
#btn_menu_item_1:hover, #btn_menu_item_2:hover, #btn_menu_item_3:hover, #btn_menu_item_4:hover, #btn_menu_item_5:hover, #btn_menu_item_6:hover { background-color: #f8f8f8; border: 1px solid #f0f0f0; }
|
||||
#lab_title { padding: 0 10px; }
|
||||
#btn_main_item_1, #btn_main_item_2, #btn_main_item_3, #btn_main_item_4 { padding: 8px 12px; color: #909399; border: none; }
|
||||
#btn_main_item_1:hover, #btn_main_item_2:hover, #btn_main_item_3:hover, #btn_main_item_4:hover { background-color: #ffffff; border-radius: 15px; color: #3d4150; }
|
||||
#btn_mine, #btn_setting, #btn_home, #btn_littleshow, #btn_logout { border: none; }
|
||||
#btn_mine:hover, #btn_setting:hover, #btn_home:hover, #btn_littleshow:hover, #btn_logout:hover { background-color: #eeeff4; border-radius: 10px; }
|
||||
#sw_main { background-color: #f8f8f8; border-radius: 16px; }
|
||||
#lab_mess_1, #lab_mess_2, #lab_mess_3, #lab_mess_4 { color: #C0C4CC; }
|
||||
#MyMessageBox QLabel { color: #3d4150; }
|
||||
#btn_mbox_btn01, #btn_mbox_btn02 { height: 16px; color: #fd839a; font-size: 14px; background-color: #f2f2f2; border: 1px solid #DCDFE6; border-radius: 13px; padding: 6px 20px; }
|
||||
#btn_mbox_btn01:hover, #btn_mbox_btn02:hover { color: #ffffff; font-weight: bold; background-color: #fd839a; }
|
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 418 B |
After Width: | Height: | Size: 259 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1023 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 428 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 899 B |
After Width: | Height: | Size: 711 B |
After Width: | Height: | Size: 455 B |
After Width: | Height: | Size: 502 B |
After Width: | Height: | Size: 308 B |
After Width: | Height: | Size: 280 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 991 B |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 813 B |
After Width: | Height: | Size: 357 B |
After Width: | Height: | Size: 806 B |
|
@ -3,15 +3,33 @@
|
|||
#endif
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include "appinit.h"
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
#include <QFont>
|
||||
#include <QLocale>
|
||||
#include <QTranslator>
|
||||
#include <QStyleFactory>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
//QApplication::setStyle(QStyleFactory::create("Fusion"));
|
||||
|
||||
//加载样式表
|
||||
QFile file(":/css/index.css");
|
||||
if (file.open(QFile::ReadOnly))
|
||||
{
|
||||
QString qss = QLatin1String(file.readAll());
|
||||
qApp->setStyleSheet(qss);
|
||||
file.close();
|
||||
}
|
||||
|
||||
//全局字体
|
||||
QFont font("Arial", 10);
|
||||
a.setFont(font);
|
||||
|
||||
QTranslator translator;
|
||||
const QStringList uiLanguages = QLocale::system().uiLanguages();
|
||||
for (const QString &locale : uiLanguages)
|
||||
|
@ -23,7 +41,14 @@ int main(int argc, char *argv[])
|
|||
break;
|
||||
}
|
||||
}
|
||||
//屏幕拖动
|
||||
AppInit::Instance()->start();
|
||||
|
||||
MainWindow w;
|
||||
w.show();
|
||||
w.setStyleSheet("background-color: white;");
|
||||
//w.setWindowFlags(Qt::FramelessWindowHint);
|
||||
//w.setAttribute(Qt::WA_TranslucentBackground);
|
||||
w.showMaximized();
|
||||
//w.show();
|
||||
return a.exec();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
#include <QVector>
|
||||
#include <QThread>
|
||||
#include <QDebug>
|
||||
#include <QGridLayout>
|
||||
#include <QToolBar>
|
||||
#include <QLabel>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
|
||||
#include "libmodbus/modbus.h"
|
||||
|
||||
|
@ -193,6 +197,63 @@ void MainWindow::getConfiguration(QString iniFilePath)
|
|||
|
||||
bool MainWindow::InitializeUI()
|
||||
{
|
||||
//初始化窗口边框
|
||||
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
|
||||
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
|
||||
shadow->setOffset(0, 0);
|
||||
shadow->setColor(QColor("#444444"));
|
||||
shadow->setBlurRadius(16);
|
||||
// ui->w_bg->setGraphicsEffect(shadow);
|
||||
//ui->lay_bg->setMargin(12);
|
||||
QWidget *centralWidget = new QWidget(this);
|
||||
QGridLayout *mainLayout = new QGridLayout(centralWidget);
|
||||
|
||||
// 创建2行4列布局(共8个控件示例)
|
||||
for(int row=0; row<2; ++row)
|
||||
{
|
||||
for(int col=0; col<4; ++col)
|
||||
{
|
||||
QLabel *label = new QLabel(QString("Cell %1-%2").arg(row).arg(col),this);
|
||||
label->setStyleSheet("background-color: rgb(192, 192, 192);"
|
||||
"color: #333333;"
|
||||
"border-radius: 8px;"
|
||||
"font: bold 14px;");
|
||||
label->setAutoFillBackground(true);
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
mainLayout->addWidget(label, row, col);
|
||||
m_panel_labels.push_back(label);
|
||||
}
|
||||
}
|
||||
|
||||
// 设置布局的间距和边距
|
||||
mainLayout->setSpacing(5);
|
||||
//mainLayout->setContentsMargins(10, 40, 10, 10); // 顶部留出工具栏空间
|
||||
setCentralWidget(centralWidget);
|
||||
|
||||
QToolBar *toolBar = new QToolBar(this);
|
||||
toolBar->setMovable(false);
|
||||
toolBar->setIconSize(QSize(64,64));
|
||||
|
||||
// 添加工具栏按钮
|
||||
QAction *actionRead = new QAction(QIcon(":/icons/modular.png"), tr("Read"), this);
|
||||
actionRead->setToolTip(tr("Read Data"));
|
||||
|
||||
QAction *actionClose = new QAction(QIcon(":/icons/close.png"), tr("Close"), this);
|
||||
actionClose->setToolTip(tr("Close Application"));
|
||||
|
||||
toolBar->addAction(actionRead);
|
||||
toolBar->addSeparator();
|
||||
toolBar->addAction(actionClose);
|
||||
toolBar->addSeparator();
|
||||
|
||||
// 将工具栏定位到窗口顶部
|
||||
addToolBar(Qt::TopToolBarArea, toolBar);
|
||||
|
||||
connect(actionClose, &QAction::triggered, this, &QMainWindow::close);
|
||||
connect(actionRead, &QAction::triggered, this, &MainWindow::ReadSerialPortData);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -308,11 +369,13 @@ bool MainWindow::readRegister(int addr,int nb,uint16_t* dest)
|
|||
assert(pData);
|
||||
if (pData->bDecodeTemp)
|
||||
{
|
||||
ui->txt_content_1->append(QString(tr("温度:%1\n湿度: %2\n露点: %3\n")).arg(pData->TempValue).arg(pData->HumidityValue).arg(pData->DewPointValue));
|
||||
//ui->txt_content_1->append(QString(tr("温度:%1\n湿度: %2\n露点: %3\n")).arg(pData->TempValue).arg(pData->HumidityValue).arg(pData->DewPointValue));
|
||||
m_panel_labels[0]->setText(QString(tr("温度: %1\n湿度: %2\n露点: %3\n")).arg(pData->TempValue).arg(pData->HumidityValue).arg(pData->DewPointValue));
|
||||
}
|
||||
if (pData->bDecodeAlarm)
|
||||
{
|
||||
ui->txt_content_1->append(QString(tr("高温告警:%1\n低温告警: %2\n湿度告警: %3\n")).arg(pData->TempHighAlarm).arg(pData->TempLowAlarm).arg(pData->HumidityHighAlarm));
|
||||
//ui->txt_content_1->append(QString(tr("高温告警: %1\n低温告警: %2\n湿度告警: %3\n")).arg(pData->TempHighAlarm).arg(pData->TempLowAlarm).arg(pData->HumidityHighAlarm));
|
||||
//m_panel_labels[0]->setText(QString(tr("高温告警: %1\n低温告警: %2\n湿度告警: %3\n")).arg(pData->TempHighAlarm).arg(pData->TempLowAlarm).arg(pData->HumidityHighAlarm));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,7 +422,7 @@ void MainWindow::startAsyncProcess(const QVector<uint16_t>& array,int slave_id,i
|
|||
}
|
||||
|
||||
|
||||
void MainWindow::on_btn_read_register_clicked()
|
||||
void MainWindow::ReadSerialPortData()
|
||||
{
|
||||
readRegister(0,0,0);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <QMainWindow>
|
||||
#include <QSettings>
|
||||
#include <QVector>
|
||||
#include <QLabel>
|
||||
|
||||
#include "libmodbus/modbus.h"
|
||||
#include "slave_define.h"
|
||||
|
@ -26,20 +28,20 @@ class DecodeWorker : public QObject
|
|||
Q_OBJECT
|
||||
public:
|
||||
DecodeWorker(QObject* parent = nullptr) : QObject(parent) {}
|
||||
void setParameters(const QVector<uint16_t>& array, int slave_id, int start_addr, int quantity, DeviceData* pDevice)
|
||||
{
|
||||
this->array = array;
|
||||
this->slave_id = slave_id;
|
||||
this->start_addr = start_addr;
|
||||
this->quantity = quantity;
|
||||
this->pDevice = pDevice;
|
||||
}
|
||||
void setParameters(const QVector<uint16_t>& array, int slave_id, int start_addr, int quantity, DeviceData* pDevice)
|
||||
{
|
||||
this->array = array;
|
||||
this->slave_id = slave_id;
|
||||
this->start_addr = start_addr;
|
||||
this->quantity = quantity;
|
||||
this->pDevice = pDevice;
|
||||
}
|
||||
|
||||
private:
|
||||
QVector<uint16_t> array;
|
||||
int slave_id;
|
||||
int start_addr;
|
||||
int quantity;
|
||||
QVector<uint16_t> array;
|
||||
int slave_id;
|
||||
int start_addr;
|
||||
int quantity;
|
||||
DeviceData* pDevice;
|
||||
|
||||
signals:
|
||||
|
@ -93,12 +95,14 @@ protected:
|
|||
QSettings* m_pSettings;
|
||||
|
||||
|
||||
protected:
|
||||
QVector<QLabel*> m_panel_labels;
|
||||
protected:
|
||||
//异步处理数据
|
||||
void startAsyncProcess(const QVector<uint16_t>& array,int slave_id,int start_addr,int quantity,DeviceData* pData);
|
||||
|
||||
private slots:
|
||||
void on_btn_read_register_clicked();
|
||||
void ReadSerialPortData();
|
||||
|
||||
signals:
|
||||
// 处理进度信号
|
||||
|
@ -107,6 +111,6 @@ signals:
|
|||
void finished();
|
||||
|
||||
signals:
|
||||
void startProcessing(const QVector<uint16_t>& array, int slave_id, int start_addr, int quantity, DeviceData* pData);
|
||||
void startProcessing(const QVector<uint16_t>& array, int slave_id, int start_addr, int quantity, DeviceData* pData);
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
@ -13,41 +13,7 @@
|
|||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<widget class="QPushButton" name="btn_read_register">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>20</y>
|
||||
<width>93</width>
|
||||
<height>29</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>read</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTextEdit" name="txt_content_1">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>60</x>
|
||||
<y>100</y>
|
||||
<width>331</width>
|
||||
<height>331</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTextEdit" name="txt_content_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>410</x>
|
||||
<y>100</y>
|
||||
<width>341</width>
|
||||
<height>331</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="centralwidget"/>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>css/index.css</file>
|
||||
<file>icons/analysic.png</file>
|
||||
<file>icons/check.png</file>
|
||||
<file>icons/close.png</file>
|
||||
<file>icons/down.png</file>
|
||||
<file>icons/error.png</file>
|
||||
<file>icons/home.png</file>
|
||||
<file>icons/item_01.png</file>
|
||||
<file>icons/item_02.png</file>
|
||||
<file>icons/logo.png</file>
|
||||
<file>icons/logout.png</file>
|
||||
<file>icons/member.png</file>
|
||||
<file>icons/mine.png</file>
|
||||
<file>icons/mini.png</file>
|
||||
<file>icons/modular.png</file>
|
||||
<file>icons/money.png</file>
|
||||
<file>icons/out.png</file>
|
||||
<file>icons/phone.png</file>
|
||||
<file>icons/question.png</file>
|
||||
<file>icons/setting.png</file>
|
||||
<file>icons/show.png</file>
|
||||
<file>icons/umbrella.png</file>
|
||||
<file>icons/up.png</file>
|
||||
<file>icons/warn.png</file>
|
||||
</qresource>
|
||||
</RCC>
|