
#ifndef DIAGRAMSCENE_H
#define DIAGRAMSCENE_H

#include <QGraphicsScene>
#include "diagramitem.h"
#include "diagramtextitem.h"

QT_BEGIN_NAMESPACE
class QGraphicsSceneMouseEvent;
class QMenu;
class QPointF;
class QGraphicsLineItem;
class QFont;
class QGraphicsTextItem;
class QColor;
class QGraphicsSceneContextMenuEvent;
QT_END_NAMESPACE

//! [0]
class DiagramScene : public QGraphicsScene
{
    Q_OBJECT

public:
    enum Mode { InsertItem, InsertLine, InsertText, MoveItem };

    DiagramScene(QMenu *itemMenu, QObject *parent = 0, QMenu *sceneMenu=0);
    QFont font() const
        { return myFont; }
    QColor textColor() const
        { return myTextColor; }
    QColor itemColor() const
        { return myItemColor; }
    QColor lineColor() const
        { return myLineColor; }

    int getNumberB() {return numberB;};
    void setNewNumberB(int num) {numberB = num;};
    void setLineColor(const QColor &color);
    void setTextColor(const QColor &color);
    void setItemColor(const QColor &color);
    void setFont(const QFont &font);
	void setID(int ID);
    int getID() {return id;};
    void setNumberB(int num);
	bool fl;
	bool fl1;
    int isAnythingSelected;
	
public slots:
    void setMode(Mode mode);
    void setItemType(DiagramItem::DiagramType type);
    void editorLostFocus(DiagramTextItem *item);
    void arrowDown2(QGraphicsItem * par);
    void arrowUp2(QGraphicsItem * par);
    void arrowBack2(QGraphicsItem * par);
    void arrowFront2(QGraphicsItem * par);

	void setItem(DiagramItem *item);

signals:
    void itemInserted(DiagramItem *item);
    void arrInserted(Arrow2 *arrow, int startId, int endId, int arrId, QPointF Pend, int type);
    void textInserted(DiagramTextItem *item, QPointF point);
	void commentInserted(QGraphicsTextItem* item, QPointF point, int id1, int id2);
	void itemCommInserted(QString text, int Id);
    void itemSelected(QGraphicsItem *item);
    void itemMoved();
	void itemChangeKoords(DiagramItem *item, QPointF point);

	void retItem(int ID);

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
    void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
	void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);	//если нажали правой кнопкой на сцену - вызвалась контекстная менюшка

private:
    bool isItemChange(int type);
	int id;
        int numberB;

    DiagramItem::DiagramType myItemType;
    QMenu *myItemMenu;
	QMenu *mySceneMenu;
    Mode myMode;
    bool leftButtonDown;
    QPointF startPoint;
    QGraphicsLineItem *line;
    QFont myFont;
    DiagramTextItem *textItem;
    QColor myTextColor;
    QColor myItemColor;
    QColor myLineColor;

	QPointF  dragStartPosition;
	QPointF  textPos;
	DiagramItem *dragItem;
	DiagramItem *newItem;
	DiagramItem *movingItem;
	//bool fl;
	//bool fl1;
	bool altFlag; bool comFlag;
};
//! [0]

#endif
