Selaa lähdekoodia

update: tweak UI

Yao 4 viikkoa sitten
vanhempi
commit
2fb8c4aefb
3 muutettua tiedostoa jossa 32 lisäystä ja 4 poistoa
  1. 21 2
      mainwindow.cpp
  2. 6 0
      mainwindow.h
  3. 5 2
      mainwindow.ui

+ 21 - 2
mainwindow.cpp

@@ -2,6 +2,9 @@
 #include "ui_mainwindow.h"
 #include "jobs.h"
 #include <QDebug>
+#include <QWidget>
+#include <QPushButton>
+
 // 定义 ANzI 转义序列来设置颜色
 #define ANSI_COLOR_GREEN "\x1B[32m"
 #define ANSI_COLOR_RESET "\x1B[0m"
@@ -13,8 +16,9 @@ MainWindow::MainWindow(QWidget *parent)
     // 去除窗口边界,设置为无边框窗口
     this->setWindowFlags(Qt::FramelessWindowHint);
     ui->setupUi(this);
-    this->setWindowFlags(Qt::FramelessWindowHint); //Makes the frame invisible
     this->setWindowState(Qt::WindowMaximized); //Maximizes the window
+
+    ui->setupUi(this);
     initializeAnimate();
     // initialMqttService();
 
@@ -40,6 +44,20 @@ MainWindow::MainWindow(QWidget *parent)
     ui->labLat->setText("经度: "+lat);
     ui->labLon->setText("维度: "+lon);
     connect(ui->btnClose, &QPushButton::clicked, this, &MainWindow::close);
+    connect(this, &MainWindow::projectTitleChanged, this, &MainWindow::updateProjectTitleLabel);
+}
+
+void MainWindow::updateProjectTitleLabel(const QString &newTitle) {
+    ui->projectTitleLable->setText(newTitle);
+}
+
+void MainWindow::setProjectTitle(const QString &newTitle) {
+    if (m_currentProjectTitle != newTitle) {
+        m_currentProjectTitle = newTitle;
+        qDebug() << "Project title changed to:" << m_currentProjectTitle;
+        // Emit the signal to notify listeners (like our QLabel slot)
+        emit projectTitleChanged(m_currentProjectTitle);
+    }
 }
 
 void MainWindow::initializeAnimate() {
@@ -83,6 +101,7 @@ void MainWindow::switchPage(QWidget *button) {
             buttonToPage.remove(button);
         }
 
+
         QWidget* newPage = factory->createPage(this);
         ui->stackedWidget->addWidget(newPage);
         ui->stackedWidget->setCurrentWidget(newPage);
@@ -90,6 +109,7 @@ void MainWindow::switchPage(QWidget *button) {
         buttonToPage.insert(button, newPage);
         int pageCount = ui->stackedWidget->count();
 
+        setProjectTitle(qobject_cast<QPushButton*>(button)->text());
     }
 }
 
@@ -208,4 +228,3 @@ void MainWindow::mouseMoveEvent(QMouseEvent *event)
         event->accept();
     }
 }
-

+ 6 - 0
mainwindow.h

@@ -32,12 +32,17 @@ public:
     MainWindow(QWidget *parent = nullptr);
     ~MainWindow();
 
+    void setProjectTitle(const QString &newTitle);
+
+signals:
+    void projectTitleChanged(const QString &newTitle);
 
 private slots:
     void onToggleButtonClicked();
     void onButtonClicked(QPushButton  *button);
     void handleStoredGNRMCData(const RMCData &data);
     void onTimeUpdated(const QString &timeString);
+    void updateProjectTitleLabel(const QString &newTitle);
 
     void messageAndTopicReceived(const QByteArray &message, const QMqttTopicName &topic);
 private:
@@ -65,6 +70,7 @@ private:
     QString lat = "未知";
     QString lon = "未知";
     QPoint m_dragPosition;
+    QString m_currentProjectTitle;    // Stores the current project title
 
 
     void mousePressEvent(QMouseEvent *event);

+ 5 - 2
mainwindow.ui

@@ -275,9 +275,12 @@ left_buttonsBox里的QPushButton
               <number>0</number>
              </property>
              <item>
-              <widget class="QLabel" name="projectTitle">
+              <widget class="QLabel" name="projectTitleLable">
                <property name="text">
-                <string>projectTitle</string>
+                <string>首页</string>
+               </property>
+               <property name="margin">
+                <number>5</number>
                </property>
               </widget>
              </item>