#ifndef MDI_WINDOW_H
#define MDI_WINDOW_H


#include <QMainWindow>
#include <QTextEdit>


class MdiChild;
class QAction;
class QMenu;
class QMdiArea;
class QMdiSubWindow;
class QSignalMapper;
class Ui_MainWindow;


class MdiChild : public QTextEdit
{
    Q_OBJECT
public:
    MdiChild();
    ~MdiChild();

    void newFile();
    bool loadFile(const QString &fileName);
    bool save();
    bool saveAs();
    bool saveFile(const QString &fileName);
    QString userFriendlyCurrentFile();
    QString currentFile() { return curFile; }

    void markdownSelection(const char* preText, const char* postText);

    void bold();
    void italic();
    void quote();
    void code();
    void heading1();
    void heading2();
    void heading3();
    void heading4();
    void hyperlink();
    void image();
    void unorderedList();
    void orderedList();
    void horizontalRule();
    void timestamp();
    void pageNumber();
    void pageCount();
    void del();
    void undo();
    void redo();
    void find();
    void findNext();
    void findPrevious();
    void goToLine();

signals:
    void closing();
    void documentContentsChanged();

private slots:
    void documentWasModified();

protected:
    void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;

private:
    bool maybeSave();
    void setCurrentFile(const QString &fileName);
    QString strippedName(const QString &fullFileName);

    QString curFile;
    bool isUntitled;
};


/*
class MdiOptions
{
public:
    void serialize();
    void deserialize();
};
*/


class MdiWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MdiWindow(QWidget *parent = 0);
    void init(Ui_MainWindow* ui);

    bool openFile(const QString &fileName);
signals:

protected:
    void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;

public slots:

private slots:

    // File menu actions
    void newFile();
    void open();
    void save();
    void saveAs();

    void updatePreview();

    // Edit menu actions
#ifndef QT_NO_CLIPBOARD
    void cut();
    void copy();
    void paste();
#endif

    void bold();
    void italic();
    void quote();
    void code();
    void heading1();
    void heading2();
    void heading3();
    void heading4();
    void hyperlink();
    void image();
    void unorderedList();
    void orderedList();
    void horizontalRule();
    void timestamp();
    void pageNumber();
    void pageCount();
    void options();
    void saveAll();
    void selectAll();
    void del();
    void undo();
    void redo();
    void find();
    void findNext();
    void findPrevious();
    void goToLine();

    // Help
    void support();
    void website();

    // Window menu actions
    void cascadeSubWindows();
    void tileSubWindows();
    void tabSubWindows();

    void updateActions();
    MdiChild *createMdiChild();
    void switchLayoutDirection();
    void setActiveSubWindow(QWidget *window);

private:
    void readSettings();
    void writeSettings();
    MdiChild *activeMdiChild();
    QMdiSubWindow *findMdiChild(const QString &fileName);

    QMdiArea *mdiArea;
    QSignalMapper *windowMapper;
    Ui_MainWindow *appWindow;
};


#endif // MDI_WINDOW_H
