123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QBitmap>
- #include <QMouseEvent>
- #include <QMessageBox>
- #include <QDesktopWidget>
- #include <QDebug>
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent, Qt::Window | Qt::FramelessWindowHint),
- ui(new Ui::MainWindow), menuHoverWidget(nullptr), menuHoverWidgetAnimation(nullptr)
- {
- ui->setupUi(this);
- QPixmap maskPix;
- maskPix.fill(":/assets/bg1.png");
- maskPix = maskPix.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- setMask(maskPix.mask());
- menuHoverWidget = new QWidget(ui->menu_widget);
- menuHoverWidget->setStyleSheet("background-color: rgba(55, 37, 31, 250);");
- menuHoverWidget->resize(0, 0);
- connect(ui->menuentry_1, &ClickableLabel::active_label_changed, this, &MainWindow::on_active_menuentry_changed);
- connect(ui->menuentry_2, &ClickableLabel::active_label_changed, this, &MainWindow::on_active_menuentry_changed);
- connect(ui->menuentry_3, &ClickableLabel::active_label_changed, this, &MainWindow::on_active_menuentry_changed);
- connect(ui->menuentry_4, &ClickableLabel::active_label_changed, this, &MainWindow::on_active_menuentry_changed);
- connect(ui->menuentry_5, &ClickableLabel::active_label_changed, this, &MainWindow::on_active_menuentry_changed);
- connect(ui->menuentry_6, &ClickableLabel::active_label_changed, this, &MainWindow::on_active_menuentry_changed);
- }
- void MainWindow::mousePressEvent(QMouseEvent *event)
- {
- if (event->button() == Qt::LeftButton) {
- dragPosition = event->globalPos() - frameGeometry().topLeft();
- event->accept();
- }
- }
- void MainWindow::mouseMoveEvent(QMouseEvent *event)
- {
- if (event->buttons() & Qt::LeftButton) {
- move(event->globalPos() - dragPosition);
- event->accept();
- }
- }
- void MainWindow::resizeEvent(QResizeEvent * /* event */)
- {
- QPixmap maskPix(":/assets/bg1.png");
- maskPix = maskPix.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- setMask(maskPix.mask());
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::on_menuentry_1_clicked()
- {
- QMessageBox msgBox;
- msgBox.setIcon(QMessageBox::Information);
- msgBox.setText("Нажали на \"Статус\"!");
- msgBox.exec();
- }
- void MainWindow::on_menuentry_2_clicked()
- {
- QMessageBox msgBox;
- msgBox.setIcon(QMessageBox::Information);
- msgBox.setText("Нажали на \"Настройки\"!");
- msgBox.exec();
- }
- void MainWindow::on_menuentry_3_clicked()
- {
- QMessageBox msgBox;
- msgBox.setIcon(QMessageBox::Information);
- msgBox.setText("Нажали на \"Русификация\"!");
- msgBox.exec();
- }
- void MainWindow::on_menuentry_4_clicked()
- {
- QMessageBox msgBox;
- msgBox.setIcon(QMessageBox::Information);
- msgBox.setText("Нажали на \"Новости\"!");
- msgBox.exec();
- }
- void MainWindow::on_menuentry_5_clicked()
- {
- QMessageBox msgBox;
- msgBox.setIcon(QMessageBox::Information);
- msgBox.setText("Нажали на \"Помощь\"!");
- msgBox.exec();
- }
- void MainWindow::on_menuentry_6_clicked()
- {
- QMessageBox msgBox;
- msgBox.setIcon(QMessageBox::Information);
- msgBox.setText("Нажали на \"О нас\"!");
- msgBox.exec();
- }
- void MainWindow::on_active_menuentry_changed()
- {
- ClickableLabel* active_label = ClickableLabel::getActiveLabel();
- if (menuHoverWidget->size() == QSize(0, 0)) {
- menuHoverWidget->resize(active_label->size() + QSize(10, 0));
- menuHoverWidget->move(active_label->pos() + QPoint(-5, 0));
- }
- if (menuHoverWidgetAnimation == nullptr)
- menuHoverWidgetAnimation = new QPropertyAnimation(menuHoverWidget, "geometry");
- else
- menuHoverWidgetAnimation->stop();
- menuHoverWidgetAnimation->setDuration(200);
- menuHoverWidgetAnimation->setStartValue(QRect(menuHoverWidget->pos(), menuHoverWidget->size()));
- menuHoverWidgetAnimation->setEndValue(QRect(active_label->pos() + QPoint(-5, 0), active_label->size() + QSize(10, 0)));
- menuHoverWidgetAnimation->start();
- ui->menuentry_1->raise();
- ui->menuentry_2->raise();
- ui->menuentry_3->raise();
- ui->menuentry_4->raise();
- ui->menuentry_5->raise();
- ui->menuentry_6->raise();
- }
|