#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QImage>
#include <QPixmap>
#include <QTimer>
#include <QUrl>
#include <QString>
#include "GraphicsScene.h"
#include "GraphicsView.h"

class MainWindow : public QMainWindow
{
    Q_OBJECT

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

protected:
    virtual void dragEnterEvent(QDragEnterEvent *e);
    virtual void dropEvent(QDropEvent *e);
    virtual void mouseMoveEvent(QMouseEvent *e);
    virtual void mousePressEvent(QMouseEvent *e);
    virtual void wheelEvent(QWheelEvent *e);
    virtual void keyPressEvent(QKeyEvent *e);

private:
    void setupUi();
    void regenerate(bool smooth = false);
    void reset();
    void updateTitle(QString title);
    QImage download(QUrl url);

private slots:
    void regenerateSmooth();

private:
    GraphicsScene mScene;
    GraphicsView *mView;

    QImage mImage;
    QString mFileName;
    QImage mForeground;
    QImage mFinalImage;
    QImage mCached;
    bool mValidFinalImage;

    double mScale;
    bool mScaleChanged;
    long mOffsetX;
    long mOffsetY;

    QPixmap mIcon;
    QPoint mStartDrag;
    QTimer *mTimer;
};

#endif // MAINWINDOW_H
