#ifndef MAINWINDOW_H
#define MAINWINDOW_H

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

#include "exportwidget.h"
#include "importwidget.h"
#include "managewidget.h"
#include "browsewidget.h"
#include "lotroprogresswidget.h"

namespace Ui {
class MainWindow;
}

class MenuEntry;
class LotroDatManager;

class MainWindow : public QMainWindow
{
    Q_OBJECT

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

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

public slots:
    void enableMenuItems();
    void disableMenuItems();

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 onHoverMenuentry();

    void on_closeButton_clicked();

    void on_minimizeButton_clicked();

    void setupWindowBackgroundAndMask(QPixmap background);

    void onLotroManagerStarted(QString, QVector<QVariant>);

    void onLotroManagerFinished(QString, QVector<QVariant>);

    void onLotroManagerErrorOccured(QString, QVector<QVariant>);

private:
    void makeConnections();

    void setupMenuHoverWidget();

    void moveMenuHoverWidget(MenuEntry* target);

    void checkMenuIsHovered();

    void hideAllContentWidgets();

private:
    Ui::MainWindow *ui;

    LotroDatManager* lotro_manager;
    QThread *lotro_mgr_thread;

    ExportWidget *export_widget;
    ImportWidget *import_widget;
    ManageWidget *manage_widget;
    BrowseWidget *browse_widget;
    LotroProgressWidget *lotro_progress_widget;

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

    QPoint dragPosition;

    int current_bg_id;
    QPixmap current_bg;
    QBitmap current_mask;
    QTimer background_update_timer;

    const int MAX_PIXMAP_ID = 14;

    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
