编辑界面
| 
						 | 
				
			
			@ -3,5 +3,14 @@
 | 
			
		|||
        <file>images/emscfg-main.ico</file>
 | 
			
		||||
        <file>images/hj-net.png</file>
 | 
			
		||||
        <file>images/icon.png</file>
 | 
			
		||||
        <file>images/PageAir.png</file>
 | 
			
		||||
        <file>images/PageBattery.png</file>
 | 
			
		||||
        <file>images/PageFan.png</file>
 | 
			
		||||
        <file>images/PagePower.png</file>
 | 
			
		||||
        <file>images/PagePV.png</file>
 | 
			
		||||
        <file>images/PageSensor.png</file>
 | 
			
		||||
        <file>images/PageSetting.png</file>
 | 
			
		||||
        <file>images/PageSwitch.png</file>
 | 
			
		||||
        <file>images/PageUps.png</file>
 | 
			
		||||
    </qresource>
 | 
			
		||||
</RCC>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
		 After Width: | Height: | Size: 9.8 KiB  | 
| 
		 After Width: | Height: | Size: 8.5 KiB  | 
| 
		 After Width: | Height: | Size: 10 KiB  | 
| 
		 After Width: | Height: | Size: 9.9 KiB  | 
| 
		 After Width: | Height: | Size: 9.3 KiB  | 
| 
		 After Width: | Height: | Size: 10 KiB  | 
| 
		 After Width: | Height: | Size: 15 KiB  | 
| 
		 After Width: | Height: | Size: 8.5 KiB  | 
| 
		 After Width: | Height: | Size: 9.2 KiB  | 
| 
						 | 
				
			
			@ -1,14 +1,216 @@
 | 
			
		|||
#include "maindialog.h"
 | 
			
		||||
#include "maindialog.h"
 | 
			
		||||
#include "ui_maindialog.h"
 | 
			
		||||
#include <QToolBar>
 | 
			
		||||
#include <QListWidget>
 | 
			
		||||
#include <QStackedWidget>
 | 
			
		||||
#include <QVBoxLayout>
 | 
			
		||||
#include <QIcon>
 | 
			
		||||
#include <QSize>
 | 
			
		||||
#include <QPushButton>
 | 
			
		||||
#include <QSplitter>
 | 
			
		||||
#include <QSettings>
 | 
			
		||||
#include <QCloseEvent>
 | 
			
		||||
#include <QMessageBox>
 | 
			
		||||
#include <QTableView>
 | 
			
		||||
#include <QStandardItemModel>
 | 
			
		||||
 | 
			
		||||
MainDialog::MainDialog(QWidget *parent) :
 | 
			
		||||
    QDialog(parent),
 | 
			
		||||
    QMainWindow (parent),
 | 
			
		||||
    ui(new Ui::MainDialog)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
    //ui->setupUi(this);
 | 
			
		||||
 | 
			
		||||
    this->setWindowIcon(QIcon(":/images/icon.png"));
 | 
			
		||||
 | 
			
		||||
    InitializeUI();
 | 
			
		||||
 | 
			
		||||
    connect(m_pDeviceListWidget, &QListWidget::currentItemChanged, this, &MainDialog::changePage);
 | 
			
		||||
 | 
			
		||||
    // Load the window state
 | 
			
		||||
    loadWindowState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
MainDialog::~MainDialog()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainDialog::InitializeUI()
 | 
			
		||||
{
 | 
			
		||||
    // Create central widget and layout
 | 
			
		||||
    QWidget *centralWidget = new QWidget(this);
 | 
			
		||||
    QVBoxLayout *mainLayout = new QVBoxLayout(centralWidget);
 | 
			
		||||
 | 
			
		||||
    //Create toolbar
 | 
			
		||||
    CreateToolbar();
 | 
			
		||||
 | 
			
		||||
    // Set up the QListWidget
 | 
			
		||||
    m_pDeviceListWidget = new QListWidget(this);
 | 
			
		||||
 | 
			
		||||
    m_pDeviceListWidget->setStyleSheet("background-color:transparent");
 | 
			
		||||
    m_pDeviceListWidget->setViewMode(QListView::IconMode);
 | 
			
		||||
    m_pDeviceListWidget->setIconSize(QSize(70, 70));
 | 
			
		||||
    m_pDeviceListWidget->setGridSize(QSize(145, 100)); // item 的大小
 | 
			
		||||
    m_pDeviceListWidget->setMovement(QListView::Static);
 | 
			
		||||
 | 
			
		||||
    m_pDeviceListWidget->setMaximumWidth(170);
 | 
			
		||||
    m_pDeviceListWidget->setMinimumWidth(170); // Set minimum width
 | 
			
		||||
 | 
			
		||||
    m_pDeviceListWidget->setResizeMode(QListView::Fixed);
 | 
			
		||||
 | 
			
		||||
    m_pDeviceListWidget->setSpacing(25);
 | 
			
		||||
    //m_pDeviceListWidget->setUniformItemSizes(true); // 所有的 item 一样大
 | 
			
		||||
    m_pDeviceListWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    CreateIcon(QIcon(":/images/PagePower.png"),tr("Power"));
 | 
			
		||||
    CreateIcon(QIcon(":/images/PageBattery.png"),tr("Battery"));
 | 
			
		||||
    CreateIcon(QIcon(":/images/PageSwitch.png"),tr("Switch"));
 | 
			
		||||
    CreateIcon(QIcon(":/images/PageAir.png"),tr("Air"));
 | 
			
		||||
    CreateIcon(QIcon(":/images/PageFan.png"),tr("Fan"));
 | 
			
		||||
    CreateIcon(QIcon(":/images/PageSensor.png"),tr("Sensor"));
 | 
			
		||||
 | 
			
		||||
    // Set up the QStackedWidget
 | 
			
		||||
    CreateTablePage();
 | 
			
		||||
 | 
			
		||||
    // Set up the QSplitter to manage the resizing of QListWidget and QStackedWidget
 | 
			
		||||
    QSplitter *splitter = new QSplitter(Qt::Horizontal, this);
 | 
			
		||||
    splitter->addWidget(m_pDeviceListWidget);
 | 
			
		||||
    splitter->addWidget(m_pDevicestackedWidget);
 | 
			
		||||
    splitter->setSizes(QList<int>({200, 600}));  // Set initial sizes (200 for QListWidget, 600 for QStackedWidget)
 | 
			
		||||
 | 
			
		||||
    // Disable splitter dragging
 | 
			
		||||
    splitter->setChildrenCollapsible(false);
 | 
			
		||||
 | 
			
		||||
    // Set up layout
 | 
			
		||||
    mainLayout->addWidget(m_pMainToolBar);
 | 
			
		||||
    mainLayout->addWidget(splitter);
 | 
			
		||||
    centralWidget->setLayout(mainLayout);
 | 
			
		||||
 | 
			
		||||
    // Set central widget
 | 
			
		||||
    setCentralWidget(centralWidget);
 | 
			
		||||
 | 
			
		||||
    // Set initial size of the dialog
 | 
			
		||||
    setWindowTitle(tr("EMS Configurer "));
 | 
			
		||||
 | 
			
		||||
    //resize(800, 600);
 | 
			
		||||
 | 
			
		||||
    setMinimumSize(1024, 768);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void MainDialog::CreateToolbar()
 | 
			
		||||
{
 | 
			
		||||
    m_pMainToolBar = new QToolBar(this);
 | 
			
		||||
    m_pMainToolBar->setIconSize(QSize(48, 48));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // Create actions for the toolbar
 | 
			
		||||
    QAction *action1 = new QAction(QIcon(":/images/icon.png"), "Button 1", this);
 | 
			
		||||
    QAction *action2 = new QAction(QIcon(":/images/icon.png"), "Button 2", this);
 | 
			
		||||
    QAction *action3 = new QAction(QIcon(":/images/icon.png"), "About...", this);
 | 
			
		||||
 | 
			
		||||
    // Add actions to the toolbar
 | 
			
		||||
    m_pMainToolBar->addAction(action1);
 | 
			
		||||
    m_pMainToolBar->addAction(action2);
 | 
			
		||||
    m_pMainToolBar->addAction(action3);
 | 
			
		||||
 | 
			
		||||
    // Connect actions to slots
 | 
			
		||||
    connect(action1, &QAction::triggered, this, &MainDialog::onToolButton1Clicked);
 | 
			
		||||
    connect(action2, &QAction::triggered, this, &MainDialog::onToolButton1Clicked);
 | 
			
		||||
    connect(action3, &QAction::triggered, this, &MainDialog::onAboutButtonClicked);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainDialog::CreateTablePage()
 | 
			
		||||
{
 | 
			
		||||
    m_pDevicestackedWidget = new QStackedWidget(this);
 | 
			
		||||
 | 
			
		||||
    QVBoxLayout *stackedWidgetLayout = new QVBoxLayout;
 | 
			
		||||
    m_pDevicestackedWidget->setLayout(stackedWidgetLayout);
 | 
			
		||||
 | 
			
		||||
    // Create and set up QTableView
 | 
			
		||||
    QTableView *tableView = new QTableView(this);
 | 
			
		||||
 | 
			
		||||
    // Create and set up a model for the table view
 | 
			
		||||
    QStandardItemModel *model = new QStandardItemModel(4, 3, this); // 4 rows, 3 columns
 | 
			
		||||
    model->setHorizontalHeaderLabels(QStringList() << "Column 1" << "Column 2" << "Column 3");
 | 
			
		||||
 | 
			
		||||
    // Fill the model with data
 | 
			
		||||
    for (int row = 0; row < 4; ++row)
 | 
			
		||||
    {
 | 
			
		||||
        for (int col = 0; col < 3; ++col)
 | 
			
		||||
        {
 | 
			
		||||
            QStandardItem *item = new QStandardItem(QString("Item %1-%2").arg(row).arg(col));
 | 
			
		||||
            model->setItem(row, col, item);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    tableView->setModel(model);
 | 
			
		||||
 | 
			
		||||
    m_pDevicestackedWidget->addWidget(tableView); // Add QTableView as a page
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    m_pDevicestackedWidget->addWidget(new QPushButton("Page 2"));
 | 
			
		||||
    m_pDevicestackedWidget->addWidget(new QPushButton("Page 3"));
 | 
			
		||||
    m_pDevicestackedWidget->addWidget(new QPushButton("Page 4"));
 | 
			
		||||
    m_pDevicestackedWidget->addWidget(new QPushButton("Page 5"));
 | 
			
		||||
    m_pDevicestackedWidget->addWidget(new QPushButton("Page 6"));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
void MainDialog::CreateIcon(const QIcon& icon,QString text)
 | 
			
		||||
{
 | 
			
		||||
    QListWidgetItem *itemButton = new QListWidgetItem(m_pDeviceListWidget);
 | 
			
		||||
    itemButton->setIcon(icon);
 | 
			
		||||
    itemButton->setText(text);
 | 
			
		||||
    itemButton->setTextAlignment(Qt::AlignHCenter);
 | 
			
		||||
    itemButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
 | 
			
		||||
{
 | 
			
		||||
    if (!current)
 | 
			
		||||
        current = previous;
 | 
			
		||||
 | 
			
		||||
    m_pDevicestackedWidget->setCurrentIndex(m_pDeviceListWidget->row(current));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainDialog::closeEvent(QCloseEvent *event)
 | 
			
		||||
{
 | 
			
		||||
    // Save the window state
 | 
			
		||||
    saveWindowState();
 | 
			
		||||
    QMainWindow::closeEvent(event);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainDialog::saveWindowState()
 | 
			
		||||
{
 | 
			
		||||
    QSettings settings("HJ-NET", "EMSCFG");
 | 
			
		||||
    settings.setValue("geometry", saveGeometry());
 | 
			
		||||
    settings.setValue("windowState", saveState());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainDialog::loadWindowState()
 | 
			
		||||
{
 | 
			
		||||
    QSettings settings("HJ-NET", "EMSCFG");
 | 
			
		||||
    restoreGeometry(settings.value("geometry").toByteArray());
 | 
			
		||||
    restoreState(settings.value("windowState").toByteArray());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainDialog::onToolButton1Clicked()
 | 
			
		||||
{
 | 
			
		||||
    QMessageBox::information(this, "Button Clicked", "Button 1 was clicked!");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainDialog::onToolButton2Clicked()
 | 
			
		||||
{
 | 
			
		||||
    QMessageBox::information(this, "Button Clicked", "Button 2 was clicked!");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainDialog::onAboutButtonClicked()
 | 
			
		||||
{
 | 
			
		||||
    QMessageBox::information(this, "Button Clicked", "About");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,13 +1,19 @@
 | 
			
		|||
#ifndef MAINDIALOG_H
 | 
			
		||||
#ifndef MAINDIALOG_H
 | 
			
		||||
#define MAINDIALOG_H
 | 
			
		||||
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
#include <QMainWindow>
 | 
			
		||||
#include <QListWidget>
 | 
			
		||||
#include <QListWidgetItem>
 | 
			
		||||
#include <QIcon>
 | 
			
		||||
#include <QStackedWidget>
 | 
			
		||||
#include <QToolBar>
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class MainDialog;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class MainDialog : public QDialog
 | 
			
		||||
 | 
			
		||||
class MainDialog : public QMainWindow
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -15,8 +21,31 @@ public:
 | 
			
		|||
    explicit MainDialog(QWidget *parent = nullptr);
 | 
			
		||||
    ~MainDialog();
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    void changePage(QListWidgetItem *current, QListWidgetItem *previous);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void onToolButton1Clicked();
 | 
			
		||||
    void onToolButton2Clicked();
 | 
			
		||||
    void onAboutButtonClicked();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::MainDialog *ui;
 | 
			
		||||
    QListWidget *m_pDeviceListWidget;
 | 
			
		||||
    QStackedWidget *m_pDevicestackedWidget;
 | 
			
		||||
    QToolBar *m_pMainToolBar;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    void InitializeUI();
 | 
			
		||||
    void CreateToolbar();
 | 
			
		||||
    void CreateIcon(const QIcon& icon,QString text);
 | 
			
		||||
    void CreateTablePage();
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    void closeEvent(QCloseEvent *event) override;
 | 
			
		||||
    void saveWindowState();
 | 
			
		||||
    void loadWindowState();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // MAINDIALOG_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,9 @@
 | 
			
		|||
<ui version="4.0">
 | 
			
		||||
 <class>MainDialog</class>
 | 
			
		||||
 <widget class="QDialog" name="MainDialog">
 | 
			
		||||
  <property name="windowModality">
 | 
			
		||||
   <enum>Qt::NonModal</enum>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="geometry">
 | 
			
		||||
   <rect>
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
| 
						 | 
				
			
			@ -10,6 +13,9 @@
 | 
			
		|||
    <height>665</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="contextMenuPolicy">
 | 
			
		||||
   <enum>Qt::NoContextMenu</enum>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowTitle">
 | 
			
		||||
   <string>Dialog</string>
 | 
			
		||||
  </property>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||