#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(app, this); ui->content_layout->addWidget(status_frame); rusification_frame = new RusificationWidget(app, this); ui->content_layout->addWidget(rusification_frame); settings_frame = new SettingsWidget(app, this); ui->content_layout->addWidget(settings_frame); news_frame = new NewsWidget(app, this); ui->content_layout->addWidget(news_frame); help_frame = new HelpWidget(app, this); ui->content_layout->addWidget(help_frame); hideAllContentWidgets(); status_frame->show(); setupWindowBackgroundAndMask(1); setupMenuHoverWidget(); changeFontSizeRecursive(100, this); updateGeometry(); 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_common_clicked() { hideAllContentWidgets(); status_frame->show(); } void MainWindow::on_menuentry_2_common_clicked() { hideAllContentWidgets(); settings_frame->show(); } void MainWindow::on_menuentry_3_common_clicked() { hideAllContentWidgets(); rusification_frame->show(); } void MainWindow::on_menuentry_4_common_clicked() { hideAllContentWidgets(); news_frame->show(); } void MainWindow::on_menuentry_5_common_clicked() { hideAllContentWidgets(); help_frame->show(); } 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::FastTransformation); setMask(maskPix.mask()); QPalette palette; palette.setBrush(QPalette::Window, maskPix); setPalette(palette); } 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_common, &MenuEntry::hover_label_changed, this, &MainWindow::onHoverMenuentry); connect(ui->menuentry_2_common, &MenuEntry::hover_label_changed, this, &MainWindow::onHoverMenuentry); connect(ui->menuentry_3_common, &MenuEntry::hover_label_changed, this, &MainWindow::onHoverMenuentry); connect(ui->menuentry_4_common, &MenuEntry::hover_label_changed, this, &MainWindow::onHoverMenuentry); connect(ui->menuentry_5_common, &MenuEntry::hover_label_changed, this, &MainWindow::onHoverMenuentry); MenuEntry::setActiveLabel(ui->menuentry_1_common); 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_common->raise(); ui->menuentry_2_common->raise(); ui->menuentry_3_common->raise(); ui->menuentry_4_common->raise(); ui->menuentry_5_common->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(); settings_frame->hide(); news_frame->hide(); help_frame->hide(); } void MainWindow::changeFontSizeRecursive(size_t percent, QWidget *widget) { if (!widget) return; QFont widget_font = widget->font(); QString widget_name = widget->objectName(); if (widget_name.contains("_common")) widget_font.setPixelSize(common_font_size * percent / 100); if (widget_name.contains("_title")) widget_font.setPixelSize(title_font_size * percent / 100); if (widget_name.contains("_supertitle")) widget_font.setPixelSize(supertitle_font_size * percent / 100); if (widget_name.contains("_bigbutton")) widget_font.setPixelSize(bigbutton_font_size * percent / 100); widget->setFont(widget_font); for (QObject* child : widget->children()) if (child->isWidgetType()) { QWidget* w = qobject_cast(child); changeFontSizeRecursive(percent, w); w->resize(w->sizeHint()); } } void MainWindow::on_closeButton_clicked() { qApp->quit(); } void MainWindow::on_minimizeButton_clicked() { setWindowState(Qt::WindowMinimized); }