#ifndef MAINWINDOW_H
#define MAINWINDOW_H

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

#include "statuswidget.h"
#include "settingswidget.h"
#include "aboutwidget.h"
#include "helpwidget.h"
#include "chooseversiondialog.h"

namespace Ui {
class MainWindow;
}

class MenuEntry;
class DialogWindow;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

public slots:
    void showChooseVersionDialog();
    void hideChooseVersionDialog();
    void updateFontSizes();

protected:
    void mouseMoveEvent(QMouseEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void resizeEvent(QResizeEvent *event) override;
    bool eventFilter(QObject *watched, QEvent *event) override;

private slots:
    void randomChangeBackground();

    void on_menuentry_1_clicked();

    void on_menuentry_2_clicked();

    void on_menuentry_3_clicked();

    void on_menuentry_4_clicked();

    void onHoverMenuentry(MenuEntry* hovered_entry);

    void on_closeButton_clicked();

    void on_minimizeButton_clicked();

    void setupWindowBackgroundAndMask(QPixmap background);

    void onPatchDownloaderStarted();
    void onPatchDownloaderFinished();

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

    bool buttonsMouseMoveEventFilter(QObject *obj, QEvent *event);

    void setEventFilterRecursive(QObject* widget);
private:    
    MenuEntry* currently_active_entry;
    MenuEntry* currently_hover_entry;

    Ui::MainWindow *ui;

    StatusWidget *status_widget;
    SettingsWidget *settings_widget;
    HelpWidget *help_widget;
    AboutWidget *about_widget;

    ChooseVersionDialog *choose_locale_dialog;
    DialogWindow *dialog_window;

    QWidget* menuHoverWidget;
    QPropertyAnimation* menuHoverWidgetAnimation;
    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 = 21;
};


#endif // MAINWINDOW_H
