123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QBitmap>
- #include <QMouseEvent>
- #include <QMessageBox>
- #include <QDesktopWidget>
- 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();
- 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();
- settings_frame->show();
- }
- void MainWindow::on_menuentry_3_clicked()
- {
- hideAllContentWidgets();
- rusification_frame->show();
- }
- void MainWindow::on_menuentry_4_clicked()
- {
- hideAllContentWidgets();
- news_frame->show();
- }
- void MainWindow::on_menuentry_5_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::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();
- settings_frame->hide();
- news_frame->hide();
- help_frame->hide();
- }
- void MainWindow::on_closeButton_clicked()
- {
- qApp->quit();
- }
- void MainWindow::on_minimizeButton_clicked()
- {
- setWindowState(Qt::WindowMinimized);
- }
|