2024-10-31 22:02:32 +08:00
|
|
|
|
#include "mainwindow.h"
|
2024-10-31 17:47:16 +08:00
|
|
|
|
#include "ui_mainwindow.h"
|
2024-11-01 17:40:37 +08:00
|
|
|
|
#include "view/beltspeedlinewidget.h"
|
|
|
|
|
#include "view/coaldistributbarchartwidget.h"
|
|
|
|
|
#include "view/coalstatisticschartwidget.h"
|
2024-10-31 17:47:16 +08:00
|
|
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
MainWindow::MainWindow(QWidget* parent)
|
|
|
|
|
: QMainWindow(parent)
|
|
|
|
|
, ui(new Ui::MainWindow)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
this->setWindowFlag(Qt::FramelessWindowHint);
|
|
|
|
|
this->setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint);
|
2024-10-31 17:47:16 +08:00
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
ui->widget_head->installEventFilter(this);
|
2024-10-31 17:47:16 +08:00
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
m_systemSetting = new QSettings("system.ini", QSettings::IniFormat);
|
2024-11-01 17:40:37 +08:00
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
calendarLoopPlay();
|
2024-11-01 17:40:37 +08:00
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
setSystemTitle();
|
2024-11-01 17:40:37 +08:00
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
setBeltWarnInfoTextEditStyle();
|
2024-11-04 21:11:39 +08:00
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
addcoalDistributChart();
|
|
|
|
|
|
|
|
|
|
addbeltSpeedChat();
|
|
|
|
|
|
|
|
|
|
addCoalStatisticsChart();
|
|
|
|
|
|
|
|
|
|
addCoalBeltVideo();
|
2024-10-31 17:47:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-31 22:02:32 +08:00
|
|
|
|
MainWindow::~MainWindow() { delete ui; }
|
2024-10-31 17:47:16 +08:00
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
bool MainWindow::eventFilter(QObject* watched, QEvent* event)
|
|
|
|
|
{
|
|
|
|
|
// 处理鼠标按下、释放和移动事件
|
|
|
|
|
if (watched == ui->widget_head) {
|
|
|
|
|
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
|
|
|
|
|
if (mouseEvent->type() == QEvent::MouseButtonPress) {
|
|
|
|
|
if (mouseEvent->button() == Qt::LeftButton) {
|
|
|
|
|
m_mousePressed = true; // 启动拖拽
|
|
|
|
|
m_mousePoint = mouseEvent->globalPos() - this->pos();
|
|
|
|
|
|
|
|
|
|
this->setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint | Qt::Window | Qt::WindowStaysOnTopHint);
|
|
|
|
|
this->show(); // 确保窗口显示
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else if (mouseEvent->type() == QEvent::MouseButtonRelease) {
|
|
|
|
|
m_mousePressed = false;
|
|
|
|
|
return true;
|
|
|
|
|
} else if (mouseEvent->type() == QEvent::MouseMove) {
|
|
|
|
|
if (m_mousePressed && (mouseEvent->buttons() & Qt::LeftButton)) {
|
|
|
|
|
this->move(mouseEvent->globalPos() - m_mousePoint);
|
|
|
|
|
|
|
|
|
|
// 每次移动时设置为最上方
|
|
|
|
|
this->setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint | Qt::Window | Qt::WindowStaysOnTopHint);
|
|
|
|
|
this->show();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-01 17:40:37 +08:00
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
void MainWindow::addBeltWarnInfoToTextEdit(const QString& consoleInfo)
|
|
|
|
|
{
|
|
|
|
|
m_textEditConsoleInfo.append(consoleInfo);
|
|
|
|
|
QDateTime startDateTime = QDateTime::currentDateTime();
|
|
|
|
|
QString formattedTime = startDateTime.toString("yyyy-MM-dd hh:mm:ss");
|
2024-11-01 17:40:37 +08:00
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
if (m_textEditConsoleInfo.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
QString lastConsoleInfo = m_textEditConsoleInfo.last();
|
2024-11-01 17:40:37 +08:00
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
qint64 timeDifferenceInMilliseconds = m_previousConsleInfoDateTime.secsTo(startDateTime);
|
2024-11-01 17:40:37 +08:00
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
if ((lastConsoleInfo == consoleInfo) && timeDifferenceInMilliseconds < 2)
|
|
|
|
|
return;
|
2024-11-01 17:40:37 +08:00
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
QString consoleInfoResult = QStringLiteral("[%1]%2").arg(formattedTime).arg(consoleInfo);
|
|
|
|
|
ui->textEdit_beltWarnInfo->append(consoleInfoResult);
|
|
|
|
|
|
|
|
|
|
m_previousConsleInfoDateTime = QDateTime::currentDateTime();
|
2024-11-01 17:40:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-31 22:02:32 +08:00
|
|
|
|
void MainWindow::on_pushButton_close_clicked() { this->close(); }
|
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
void MainWindow::on_pushButton_max_clicked()
|
|
|
|
|
{
|
|
|
|
|
if (isFullScreen()) {
|
|
|
|
|
this->showMaximized();
|
|
|
|
|
} else {
|
|
|
|
|
this->showFullScreen();
|
|
|
|
|
}
|
2024-10-31 17:47:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-31 22:02:32 +08:00
|
|
|
|
void MainWindow::on_pushButton_min_clicked() { this->showMinimized(); }
|
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
void MainWindow::calendarLoopPlay()
|
|
|
|
|
{
|
|
|
|
|
ui->label_calendar->clear();
|
|
|
|
|
QTimer* timer_calendar = new QTimer(this);
|
|
|
|
|
connect(timer_calendar, &QTimer::timeout, this, [this]() {
|
|
|
|
|
QDateTime time = QDateTime::currentDateTime();
|
|
|
|
|
QString str = time.toString("yyyy-MM-dd hh:mm:ss dddd");
|
|
|
|
|
ui->label_calendar->setText(str);
|
|
|
|
|
});
|
|
|
|
|
timer_calendar->start(1000); //每一秒溢出一次进入槽函数
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::setSystemTitle()
|
|
|
|
|
{
|
|
|
|
|
QString titleName = m_systemSetting->value("system/name").toString();
|
|
|
|
|
if (!titleName.isEmpty()) {
|
|
|
|
|
ui->label_title->clear();
|
|
|
|
|
ui->label_title->setText(titleName);
|
|
|
|
|
}
|
2024-11-01 17:40:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
void MainWindow::setBeltWarnInfoTextEditStyle()
|
|
|
|
|
{
|
|
|
|
|
ui->textEdit_beltWarnInfo->document()->setMaximumBlockCount(100);
|
|
|
|
|
ui->textEdit_beltWarnInfo->setReadOnly(true);
|
|
|
|
|
ui->textEdit_beltWarnInfo->setTextInteractionFlags(Qt::NoTextInteraction);
|
2024-11-01 17:40:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
void MainWindow::addcoalDistributChart()
|
|
|
|
|
{
|
|
|
|
|
// addBeltWarnInfoToTextEdit("添加煤流分布窗口成功!");
|
|
|
|
|
ui->textEdit_beltWarnInfo->append("添加煤流分布窗口成功!");
|
2024-11-04 21:11:39 +08:00
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
CoalDistributBarChartWidget* coalDistributBarChartWidget = new CoalDistributBarChartWidget(this);
|
2024-11-01 17:40:37 +08:00
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
// 检查布局是否已设置
|
|
|
|
|
if (!ui->widget_coalDistributChart->layout()) {
|
|
|
|
|
ui->widget_coalDistributChart->setLayout(new QVBoxLayout);
|
|
|
|
|
}
|
|
|
|
|
coalDistributBarChartWidget->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
ui->widget_coalDistributChart->layout()->addWidget(
|
|
|
|
|
coalDistributBarChartWidget);
|
2024-11-04 21:11:39 +08:00
|
|
|
|
}
|
2024-11-01 17:40:37 +08:00
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
void MainWindow::addbeltSpeedChat()
|
|
|
|
|
{
|
|
|
|
|
ui->textEdit_beltWarnInfo->append("添加皮带机速度曲线窗口成功!");
|
|
|
|
|
BeltSpeedLineWidget* beltSpeedLineWidget = new BeltSpeedLineWidget(this);
|
|
|
|
|
// 检查布局是否已设置
|
|
|
|
|
if (!ui->widget_beltSpeedChart->layout()) {
|
|
|
|
|
ui->widget_beltSpeedChart->setLayout(new QVBoxLayout);
|
|
|
|
|
}
|
|
|
|
|
beltSpeedLineWidget->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
ui->widget_beltSpeedChart->layout()->addWidget(beltSpeedLineWidget);
|
2024-11-01 17:40:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
void MainWindow::addCoalStatisticsChart()
|
|
|
|
|
{
|
|
|
|
|
ui->textEdit_beltWarnInfo->append("添加煤量统计窗口成功!");
|
|
|
|
|
CoalStatisticsChartWidget* coalStatisticsChartWidget = new CoalStatisticsChartWidget(this);
|
|
|
|
|
// 检查布局是否已设置
|
|
|
|
|
if (!ui->widget_beltSpeedChart->layout()) {
|
|
|
|
|
ui->widget_beltSpeedChart->setLayout(new QVBoxLayout);
|
|
|
|
|
}
|
|
|
|
|
coalStatisticsChartWidget->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
ui->widget_coalStatisticsChart->layout()->addWidget(
|
|
|
|
|
coalStatisticsChartWidget);
|
2024-10-31 17:47:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-05 17:48:05 +08:00
|
|
|
|
void MainWindow::addCoalBeltVideo()
|
|
|
|
|
{
|
|
|
|
|
// QString url = "https://stream7.iqilu.com/10339/upload_transcode/202002/18/"
|
|
|
|
|
// "20200218114723HDu3hhxqIT.mp4";
|
|
|
|
|
// QString url = "rtsp://admin:1234qwer@192.168.80.82:554/Streaming/Channels/101";
|
|
|
|
|
QString url = m_systemSetting->value("camera/rtsp").toString();
|
|
|
|
|
ui->widget_beltVideo->setUrl(url);
|
|
|
|
|
ui->widget_beltVideo->open();
|
2024-10-31 17:47:16 +08:00
|
|
|
|
}
|