#include "mainwindow.h" #include "ui_mainwindow.h" #include #include #include #include #include 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(); }