#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QPropertyAnimation>
#include <QTimer>
#include <QPixmap>
#include <QBitmap>

#include "statuswidget.h"
#include "rusificationwidget.h"
#include "settingswidget.h"
#include "newswidget.h"
#include "helpwidget.h"

namespace Ui {
class MainWindow;
}

class MenuEntry;
class LegacyApp;

class MainWindow : public QMainWindow
{
    Q_OBJECT
    struct PixmapObertka{
        QPixmap* pixmap;
    };

public:
    explicit MainWindow(LegacyApp *app = 0, QWidget *parent = 0);
    void Init();
    void changeFontSizeRecursive(size_t percent, QWidget* widget);
    ~MainWindow();

protected:
    void mouseMoveEvent(QMouseEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void resizeEvent(QResizeEvent *event) override;

private slots:
    void randomChangeBackground();

    void on_menuentry_1_common_clicked();

    void on_menuentry_2_common_clicked();

    void on_menuentry_3_common_clicked();

    void on_menuentry_4_common_clicked();

    void on_menuentry_5_common_clicked();

    void onHoverMenuentry();

    void on_closeButton_clicked();

    void on_minimizeButton_clicked();

private:
    void setupWindowBackgroundAndMask();

    void setupMenuHoverWidget();

    void moveMenuHoverWidget(MenuEntry* target);

    void checkMenuIsHovered();

    void hideAllContentWidgets();

private:
    LegacyApp *app;

    Ui::MainWindow *ui;

    QWidget* menuHoverWidget;
    QPropertyAnimation* menuHoverWidgetAnimation;
    QPropertyAnimation* menuHoverWidgetScaleAnimation;
    QTimer menu_hover_checker_timer;

    QPoint dragPosition;

    StatusWidget *status_frame;
    RusificationWidget *rusification_frame;
    SettingsWidget *settings_frame;
    NewsWidget *news_frame;
    HelpWidget *help_frame;

    QPixmap *background;
    QPixmap *next_pixmap {nullptr};

    QPixmap current_bg;
    QBitmap current_mask;

    QTimer background_update_timer;
    QTimer fade_animation_timer;
    double next_pixmap_opacity;

    const int MAX_PIXMAP_ID = 9;

    const size_t common_font_size = 15;
    const size_t title_font_size = 17;
    const size_t supertitle_font_size = 32;
    const size_t bigbutton_font_size = 22;
};

#endif // MAINWINDOW_H
