123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- #include "MainWnd.h"
- #include "ui_MainWnd.h"
- #include "Login.h"
- #include <QMouseEvent>
- #include <qDebug>
- #include "OriginalWnd/OriginalWnd.h"
- MainWnd::MainWnd(QWidget *parent)
- : QMainWindow(parent)
- , ui(new Ui::MainWnd)
- {
- ui->setupUi(this);
-
- initForm();
- }
- MainWnd::~MainWnd()
- {
- delete ui;
- }
- void MainWnd::initForm()
- {
-
- setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
-
- setAttribute(Qt::WA_TranslucentBackground, true);
- QPixmap pixmap(":/images/light/logo1.png");
- QPixmap scaledPixmap = pixmap.scaled(90, 49, Qt::KeepAspectRatio);
- ui->label_logo->setPixmap(scaledPixmap);
- Login *login = new Login;
- ui->stackedWidget_3->addWidget(login);
- ui->stackedWidget_3->setCurrentIndex(ui->stackedWidget_3->indexOf(login));
-
- ui->label_logo->installEventFilter(this);
- ui->stackedWidget_3->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)
- {
- if (obj == this->ui->stackedWidget_3)
- {
- onCurrentWidgetChanged();
- }
- 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::onCurrentWidgetChanged() {
- QWidget *currentWidget = ui->stackedWidget_3->currentWidget();
- if (currentWidget) {
- QString currentWidgetName = currentWidget->objectName();
- if (currentWidgetName == "OriginalWnd") {
- ui->tabBondBtn->setIcon(QIcon(":/images/deep/home.png"));
- ui->tabBondBtn->setChecked(true);
- ui->tabBondBtn->setStyleSheet("background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #949FE8,stop:1 #2D309B);color:#FFFFFF;");
- ui->tabBondBtn->update();
- } else {
- ui->tabBondBtn->setStyleSheet("");
- }
- }
- }
- void MainWnd::on_tabBondBtn_clicked()
- {
- OriginalWnd *originalWnd = new OriginalWnd(this);
- ui->stackedWidget_3->addWidget(originalWnd);
- ui->stackedWidget_3->setCurrentIndex(ui->stackedWidget_3->indexOf(originalWnd));
- }
- void MainWnd::on_pushButton_clicked()
- {
- qApp->quit();
- }
|