
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include "diagramitem.h"
#include "itemmanager.h"
#include "States.h"
class DiagramScene;
class ItemManager;
QT_BEGIN_NAMESPACE
class QAction;
class QToolBox;
class QSpinBox;
class QComboBox;
class QFontComboBox;
class QButtonGroup;
class QLineEdit;
class QGraphicsTextItem;
class QFont;
class QToolButton;
class QAbstractButton;
class QGraphicsView;
class QImage;
class QPainter;
QT_END_NAMESPACE

//! [0]

struct Frame
{
    QString authorLine;
	QString projectLine;
	QString dateLine;
	QString timeLine;
	QString versionLine;
	QString commentsLine;
	QString usingLine;
	QString nodeLine;
	QString nameLine;
	QString numberLine;

	bool check;
};

class MainWindow : public QMainWindow
{
    Q_OBJECT

	friend class FrameDialog;

public:
   MainWindow();
   ~MainWindow();

   Frame returnFrame()
   {	return mainFrame;}

   void paintingFrame();


private slots:

    void buttonGroupClicked(int id);
    void deleteItem();
        void nameItem();
        void weightItem();
        void arrowDown();
        void arrowUp();
        void arrowBack();
        void arrowFront();
    void pointerGroupClicked(int id);

    void itemInserted(DiagramItem *item);
    void arrInserted(Arrow2 *arrow, int startId, int endId, int arrId, QPointF Pend, int type);
	void itemCommInserted(QString text, int Id);
	void itemMoved();
	void itemChangeKoords(DiagramItem *item, QPointF point);
    void textInserted(DiagramTextItem *item, QPointF point);
    void loadXY();
    void closeEvent(QCloseEvent *event);

    void sceneScaleChanged(const QString &scale);


 //  void itemSelected(QGraphicsItem *item);

	void retItem(int ID);
    //////////////////////////////
    // Cлоты для загрузки/выгрузки результатов.
	void newDm();
    void load();
    void save();
	void saveAs();
    void expPicture(); // code by Kuts

	void setFrame();
    //Слоты Undo/Redo
        void undoState();
        void redoState();
        void updateState();
        // Слоты для вставки/копирования итемов
           void pasteItem();
           void copyItem();
private:
    QTimer *timer;
    QString filename;
    int windowX, windowY, windowWidth, windowHeight, state;
    void createToolBox();
    void createActions();
    void createMenus();
    void createToolbars();

    QWidget *createBackgroundCellWidget(const QString &text,
                                        const QString &image);
    QWidget *createCellWidget(const QString &text,
                              DiagramItem::DiagramType type);
    QMenu *createColorMenu(const char *slot, QColor defaultColor);
    QIcon createColorToolButtonIcon(const QString &image, QColor color);
    QIcon createColorIcon(QColor color);
////////////
    ItemManager manager;
    States *statesManager;
    ////////////
    DiagramScene *scene;
    QGraphicsView *view;

    QAction *exitAction;
    QAction *addAction;
    QAction *deleteAction;
        QAction *undoAction;
        QAction *redoAction;
	QAction *frameAction;
	QAction *nameAction;
        QAction *weightAction;
        QAction *arrowDownAction;
        QAction *arrowUpAction;
        QAction *arrowRightAction;
        QAction *arrowFrontAction;
    /////////////
	QAction *newAction;
    QAction *loadAction;
    QAction *saveAction;
	QAction *saveAsAction;
    QAction *exportAction; // code by Kuts
    QAction *copyAction;
    QAction *pasteAction;
    QClipboard *clipBoard;

    /////////////


    QMenu *fileMenu;
    QMenu *itemMenu;
    QMenu *aboutMenu;
	QMenu *sceneMenu;

    QToolBar *textToolBar;
    QToolBar *editToolBar;
	QToolBar *frameToolBar;
	QToolBar *editToolBar2;
    QToolBar *colorToolBar;
    QToolBar *pointerToolbar;
	QToolBar *paintToolbar;

    QComboBox *sceneScaleCombo;
    QComboBox *itemColorCombo;
    QComboBox *textColorCombo;
    QComboBox *fontSizeCombo;
   // QFontComboBox *fontCombo;

    QToolBox *toolBox;
    QButtonGroup *buttonGroup;
    QButtonGroup *pointerTypeGroup;
    QButtonGroup *backgroundButtonGroup;



   	Frame mainFrame;
	QList <QGraphicsTextItem*> Texts;
	QList <QGraphicsTextItem*> NameOfItems;
};
//! [0]

#endif
