#include "mainwindow.h" #include "ui_mainwindow.h" #include #include #include #include MainWindow::MainWindow(LegacyApp *app, QWidget *parent) : QMainWindow(parent, Qt::Window | Qt::FramelessWindowHint), app(app), ui(new Ui::MainWindow), menuHoverWidget(nullptr), menuHoverWidgetAnimation(nullptr) {} void MainWindow::Init() { ui->setupUi(this); status_frame = new StatusWidget(this); ui->content_layout->addWidget(status_frame); rusification_frame = new RusificationWidget(this); ui->content_layout->addWidget(rusification_frame); hideAllContentWidgets(); status_frame->show(); setupWindowBackgroundAndMask(1); setupMenuHoverWidget(); show(); } 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::FastTransformation); setMask(maskPix.mask()); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_menuentry_1_clicked() { hideAllContentWidgets(); status_frame->show(); } void MainWindow::on_menuentry_2_clicked() { hideAllContentWidgets(); } void MainWindow::on_menuentry_3_clicked() { hideAllContentWidgets(); rusification_frame->show(); } void MainWindow::on_menuentry_4_clicked() { hideAllContentWidgets(); } void MainWindow::on_menuentry_5_clicked() { hideAllContentWidgets(); } void MainWindow::onHoverMenuentry() { moveMenuHoverWidget(MenuEntry::getHoverLabel()); } void MainWindow::setupWindowBackgroundAndMask(int bg_id) { QPixmap maskPix(":/assets/bg" + QString::number(bg_id) + ".png"); maskPix = maskPix.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); setMask(maskPix.mask()); ui->centralWidget->setStyleSheet("border-image: url(:/assets/bg" + QString::number(bg_id) + ".png)"); } void MainWindow::setupMenuHoverWidget() { menuHoverWidget = new QWidget(ui->menu_widget); menuHoverWidget->setStyleSheet("background-color: rgba(55, 37, 31, 250);"); menuHoverWidget->resize(0, 0); connect(ui->menuentry_1, &MenuEntry::hover_label_changed, this, &MainWindow::onHoverMenuentry); connect(ui->menuentry_2, &MenuEntry::hover_label_changed, this, &MainWindow::onHoverMenuentry); connect(ui->menuentry_3, &MenuEntry::hover_label_changed, this, &MainWindow::onHoverMenuentry); connect(ui->menuentry_4, &MenuEntry::hover_label_changed, this, &MainWindow::onHoverMenuentry); connect(ui->menuentry_5, &MenuEntry::hover_label_changed, this, &MainWindow::onHoverMenuentry); MenuEntry::setActiveLabel(ui->menuentry_1); menu_hover_checker_timer.setInterval(500); connect(&menu_hover_checker_timer, &QTimer::timeout, this, &MainWindow::checkMenuIsHovered); menu_hover_checker_timer.start(); } void MainWindow::moveMenuHoverWidget(MenuEntry *target) { if (menuHoverWidget->size() == QSize(0, 0)) { menuHoverWidget->resize(target->size() + QSize(10, 0)); menuHoverWidget->move(target->pos() + QPoint(-5, 0)); } else { if (menuHoverWidgetAnimation == nullptr) menuHoverWidgetAnimation = new QPropertyAnimation(menuHoverWidget, "geometry"); else menuHoverWidgetAnimation->stop(); menuHoverWidgetAnimation->setDuration(200); menuHoverWidgetAnimation->setStartValue(QRect(menuHoverWidget->pos(), menuHoverWidget->size())); menuHoverWidgetAnimation->setEndValue(QRect(target->pos() + QPoint(-5, 0), target->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(); } void MainWindow::checkMenuIsHovered() { QPoint pos = QCursor::pos(); QWidget *hovered = qApp->widgetAt(pos); if (!hovered || hovered->objectName().size() < 4 || (hovered->objectName().left(9) != "menuentry" && hovered->objectName() != "menu_widget")) { moveMenuHoverWidget(MenuEntry::getActiveLabel()); MenuEntry::setHoverLabel(nullptr); } } void MainWindow::hideAllContentWidgets() { status_frame->hide(); rusification_frame->hide(); } void MainWindow::on_closeButton_clicked() { qApp->quit(); } void MainWindow::on_minimizeButton_clicked() { setWindowState(Qt::WindowMinimized); }