|
@@ -1,8 +1,9 @@
|
|
|
#include "MainWnd.h"
|
|
|
#include "ui_MainWnd.h"
|
|
|
-#include "Demo001_1.h"
|
|
|
-#include "Demo001_2.h"
|
|
|
-#include "Demo001_3.h"
|
|
|
+#include "Login.h"
|
|
|
+#include <QMouseEvent>
|
|
|
+#include <qDebug>
|
|
|
+#include "OriginalWnd/OriginalWnd.h"
|
|
|
|
|
|
MainWnd::MainWnd(QWidget *parent)
|
|
|
: QMainWindow(parent)
|
|
@@ -31,47 +32,154 @@ void MainWnd::initForm()
|
|
|
QPixmap scaledPixmap = pixmap.scaled(90, 49, Qt::KeepAspectRatio);
|
|
|
ui->label_logo->setPixmap(scaledPixmap);
|
|
|
|
|
|
- ui->tabBondBtn->setIcon(QIcon(":/images/light/home.png"));
|
|
|
- ui->tabBondBtn_2->setIcon(QIcon(":/images/light/Productionn assistance.png"));
|
|
|
- ui->tabBondBtn_3->setIcon(QIcon(":/images/light/Program.png"));
|
|
|
- ui->tabBondBtn_4->setIcon(QIcon(":/images/light/Message.png"));
|
|
|
- ui->tabBondBtn_5->setIcon(QIcon(":/images/light/Module.png"));
|
|
|
- ui->tabBondBtn_6->setIcon(QIcon(":/images/light/Disposition.png"));
|
|
|
- ui->tabBondBtn_7->setIcon(QIcon(":/images/light/Diagnosis.png"));
|
|
|
- ui->tabBondBtn_8->setIcon(QIcon(":/images/light/System.png"));
|
|
|
- ui->tabBondBtn_9->setIcon(QIcon(":/images/light/Help.png"));
|
|
|
- ui->tabBondBtn_2->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
|
|
-
|
|
|
- ui->toolButton->setIcon(QIcon(":/images/light/stop.png"));
|
|
|
- ui->toolButton_2->setIcon(QIcon(":/images/light/start.png"));
|
|
|
- ui->toolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
|
|
- ui->toolButton_2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
|
|
+ Login *login = new Login;
|
|
|
+ ui->stackedWidget_3->addWidget(login);
|
|
|
+ ui->stackedWidget_3->setCurrentIndex(ui->stackedWidget_3->indexOf(login));
|
|
|
+
|
|
|
+ //登录监听
|
|
|
+ ui->label_logo->installEventFilter(this);
|
|
|
+
|
|
|
+ //安装监听事件,点击左侧按钮图标变化
|
|
|
+ ui->tabBondBtn->installEventFilter(this);
|
|
|
+ ui->tabBondBtn_2->installEventFilter(this);
|
|
|
+ ui->tabBondBtn_3->installEventFilter(this);
|
|
|
+ ui->tabBondBtn_4->installEventFilter(this);
|
|
|
+ ui->tabBondBtn_5->installEventFilter(this);
|
|
|
+ ui->tabBondBtn_6->installEventFilter(this);
|
|
|
+ ui->tabBondBtn_7->installEventFilter(this);
|
|
|
+ ui->tabBondBtn_8->installEventFilter(this);
|
|
|
+ ui->tabBondBtn_9->installEventFilter(this);
|
|
|
+}
|
|
|
|
|
|
+bool MainWnd::eventFilter(QObject *obj, QEvent *event)
|
|
|
+{
|
|
|
|
|
|
- ui->label_6->setPixmap(QPixmap(":/images/light/user.png").scaled(20, 20, Qt::KeepAspectRatio));
|
|
|
+ if (obj == this->ui->label_logo)
|
|
|
+ {
|
|
|
+ //判断事件类型是否为鼠标事件
|
|
|
+ if (event->type() == QEvent::MouseButtonPress)
|
|
|
+ {
|
|
|
+ //转换为鼠标事件
|
|
|
+ QMouseEvent* mouseenevt = static_cast<QMouseEvent*>(event);
|
|
|
+ //判断鼠标左键点击
|
|
|
+ if (mouseenevt->button() == Qt::LeftButton)
|
|
|
+ {
|
|
|
+ Login *login = new Login;
|
|
|
+ ui->stackedWidget_3->addWidget(login);
|
|
|
+ ui->stackedWidget_3->setCurrentIndex(ui->stackedWidget_3->indexOf(login));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static const QStringList buttonNames = {
|
|
|
+ "home",
|
|
|
+ "Productionn assistance",
|
|
|
+ "Program",
|
|
|
+ "Message",
|
|
|
+ "Module",
|
|
|
+ "Disposition",
|
|
|
+ "Diagnosis",
|
|
|
+ "System",
|
|
|
+ "Help"
|
|
|
+ };
|
|
|
+ static QToolButton* lastHoveredButton = nullptr; // 用于跟踪上一个悬停的按钮
|
|
|
+ static QMap<QToolButton*, QString> buttonLightIcons; // 存储每个按钮的亮色图标路径
|
|
|
+
|
|
|
+ // 处理鼠标按下事件或鼠标悬停进入事件
|
|
|
+ if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::HoverEnter) {
|
|
|
+ if (obj && obj->inherits("QToolButton")) {
|
|
|
+ QToolButton* button = static_cast<QToolButton*>(obj);
|
|
|
+
|
|
|
+ // 恢复所有按钮为亮色图标(如果没有选中)
|
|
|
+ for (int i = 0; i < buttonNames.size(); ++i) {
|
|
|
+ QToolButton* currentButton = nullptr;
|
|
|
+ switch (i) {
|
|
|
+ case 0: currentButton = ui->tabBondBtn; break;
|
|
|
+ case 1: currentButton = ui->tabBondBtn_2; break;
|
|
|
+ case 2: currentButton = ui->tabBondBtn_3; break;
|
|
|
+ case 3: currentButton = ui->tabBondBtn_4; break;
|
|
|
+ case 4: currentButton = ui->tabBondBtn_5; break;
|
|
|
+ case 5: currentButton = ui->tabBondBtn_6; break;
|
|
|
+ case 6: currentButton = ui->tabBondBtn_7; break;
|
|
|
+ case 7: currentButton = ui->tabBondBtn_8; break;
|
|
|
+ case 8: currentButton = ui->tabBondBtn_9; break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (currentButton) {
|
|
|
+ QString lightIconPath = QString(":/images/light/%1.png").arg(buttonNames[i]);
|
|
|
+ if (currentButton == button) {
|
|
|
+ // 当前悬停的按钮,设置为深色图标
|
|
|
+ QString deepIconPath = QString(":/images/deep/%1.png").arg(buttonNames[i]);
|
|
|
+ currentButton->setIcon(QIcon(deepIconPath));
|
|
|
+ currentButton->setChecked(true);
|
|
|
+ } else if (!currentButton->isChecked()) {
|
|
|
+ // 恢复为亮色图标
|
|
|
+ buttonLightIcons[currentButton] = lightIconPath; // 存储亮色图标路径
|
|
|
+ currentButton->setIcon(QIcon(lightIconPath));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果上一个悬停按钮存在且不是当前按钮,恢复其亮色图标
|
|
|
+ if (lastHoveredButton && lastHoveredButton != button && !lastHoveredButton->isChecked()) {
|
|
|
+ QString lightIconPath = buttonLightIcons.value(lastHoveredButton);
|
|
|
+ if (!lightIconPath.isEmpty()) {
|
|
|
+ lastHoveredButton->setIcon(QIcon(lightIconPath));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ lastHoveredButton = button; // 更新为当前悬停的按钮
|
|
|
+ }
|
|
|
+ return true; // 表示事件已处理
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理鼠标离开事件
|
|
|
+ if (event->type() == QEvent::HoverLeave) {
|
|
|
+ if (obj && obj->inherits("QToolButton")) {
|
|
|
+ QToolButton* button = static_cast<QToolButton*>(obj);
|
|
|
+ if (button == lastHoveredButton && !button->isChecked()) {
|
|
|
+ QString lightIconPath = buttonLightIcons.value(button);
|
|
|
+ if (!lightIconPath.isEmpty()) {
|
|
|
+ button->setIcon(QIcon(lightIconPath));
|
|
|
+ }
|
|
|
+ lastHoveredButton = nullptr; // 重置上一个悬停的按钮
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true; // 表示事件已处理
|
|
|
+ }
|
|
|
+
|
|
|
+ return QWidget::eventFilter(obj, event); // 如果没有处理返回默认事件处理
|
|
|
}
|
|
|
|
|
|
+// void MainWnd::on_pushButton_4_clicked()
|
|
|
+// {
|
|
|
+// Demo001_1 *demo001_1 = new Demo001_1;
|
|
|
+// ui->switchShowPageUI->addWidget(demo001_1);
|
|
|
+// ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_1));
|
|
|
+// }
|
|
|
|
|
|
-void MainWnd::on_pushButton_4_clicked()
|
|
|
-{
|
|
|
- Demo001_1 *demo001_1 = new Demo001_1;
|
|
|
- ui->switchShowPageUI->addWidget(demo001_1);
|
|
|
- ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_1));
|
|
|
-}
|
|
|
|
|
|
+// void MainWnd::on_pushButton_5_clicked()
|
|
|
+// {
|
|
|
+// Demo001_2 *demo001_2 = new Demo001_2;
|
|
|
+// ui->switchShowPageUI->addWidget(demo001_2);
|
|
|
+// ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_2));
|
|
|
+// }
|
|
|
|
|
|
-void MainWnd::on_pushButton_5_clicked()
|
|
|
-{
|
|
|
- Demo001_2 *demo001_2 = new Demo001_2;
|
|
|
- ui->switchShowPageUI->addWidget(demo001_2);
|
|
|
- ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_2));
|
|
|
-}
|
|
|
+
|
|
|
+// void MainWnd::on_pushButton_6_clicked()
|
|
|
+// {
|
|
|
+// Demo001_3 *demo001_3 = new Demo001_3;
|
|
|
+// ui->switchShowPageUI->addWidget(demo001_3);
|
|
|
+// ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_3));
|
|
|
+// }
|
|
|
|
|
|
|
|
|
-void MainWnd::on_pushButton_6_clicked()
|
|
|
+void MainWnd::on_tabBondBtn_clicked()
|
|
|
{
|
|
|
- Demo001_3 *demo001_3 = new Demo001_3;
|
|
|
- ui->switchShowPageUI->addWidget(demo001_3);
|
|
|
- ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_3));
|
|
|
+ OriginalWnd *originalWnd = new OriginalWnd;
|
|
|
+ ui->stackedWidget_3->addWidget(originalWnd);
|
|
|
+ ui->stackedWidget_3->setCurrentIndex(ui->stackedWidget_3->indexOf(originalWnd));
|
|
|
}
|
|
|
|