/*
    QAD - Qt ADvanced

    Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef GRAPHIC_H
#define GRAPHIC_H

#include "evalspinbox.h"
#include "graphic_conf.h"
#include "qad_graphic_export.h"

#include <QComboBox>
#include <QDebug>
#include <QElapsedTimer>
#include <QFileDialog>
#include <QGestureEvent>
#include <QGridLayout>
#include <QMenu>
#include <QMouseEvent>
#include <QPainter>
#include <QPixmap>
#include <QTranslator>
#include <QWidget>
#include <float.h>
#include <qmath.h>


namespace Ui {
class Graphic;
}


class UGLWidget;
class GraphicPlugin;


Q_DECLARE_METATYPE(QVector<QPointF>)


class QAD_GRAPHIC_EXPORT Graphic: public QFrame {
	Q_OBJECT
	Q_FLAGS(Buttons)
	Q_ENUMS(Alignment Graduation AxisType FloatingAxisType)

	Q_PROPERTY(QString caption READ caption WRITE setCaption)
	Q_PROPERTY(QString labelX READ labelX WRITE setLabelX)
	Q_PROPERTY(QString labelY READ labelY WRITE setLabelY)
	Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
	Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)

	Q_PROPERTY(int currentGraphic READ currentGraphic WRITE setCurrentGraphic)
	Q_PROPERTY(int graphicsCount READ graphicsCount WRITE setGraphicsCount)
	Q_PROPERTY(QString graphicName READ graphicName WRITE setGraphicName)
	Q_PROPERTY(QPen graphicPen READ graphicPen WRITE setGraphicPen)
	Q_PROPERTY(QColor graphicColor READ graphicColor WRITE setGraphicColor)
	Q_PROPERTY(Qt::PenStyle graphicStyle READ graphicStyle WRITE setGraphicStyle)
	Q_PROPERTY(double graphicLineWidth READ graphicLineWidth WRITE setGraphicLineWidth)
	Q_PROPERTY(double graphicPointWidth READ graphicPointWidth WRITE setGraphicPointWidth)
	Q_PROPERTY(QColor graphicFillColor READ graphicFillColor WRITE setGraphicFillColor)
	Q_PROPERTY(bool graphicLinesEnabled READ graphicLinesEnabled WRITE setGraphicLinesEnabled)
	Q_PROPERTY(bool graphicPointsEnabled READ graphicPointsEnabled WRITE setGraphicPointsEnabled)
	Q_PROPERTY(bool graphicFillEnabled READ graphicFillEnabled WRITE setGraphicFillEnabled)

	Q_PROPERTY(bool gridEnabled READ gridEnabled WRITE setGridEnabled)
	Q_PROPERTY(QPen gridPen READ gridPen WRITE setGridPen)
	Q_PROPERTY(QColor gridColor READ gridColor WRITE setGridColor)
	Q_PROPERTY(Qt::PenStyle gridStyle READ gridStyle WRITE setGridStyle)

	Q_PROPERTY(QPen selectionPen READ selectionPen WRITE setSelectionPen)
	Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor)
	Q_PROPERTY(Qt::PenStyle selectionStyle READ selectionStyle WRITE setSelectionStyle)
	Q_PROPERTY(QBrush selectionBrush READ selectionBrush WRITE setSelectionBrush)

	Q_PROPERTY(Alignment buttonsPosition READ buttonsPosition WRITE setButtonsPosition)
	Q_PROPERTY(Buttons buttons READ buttons WRITE setButtons)
	Q_PROPERTY(bool navigationEnabled READ navigationEnabled WRITE setNavigationEnabled)
	Q_PROPERTY(bool openGL READ openGL WRITE setOpenGL)
	Q_PROPERTY(bool antialiasing READ antialiasing WRITE setAntialiasing)
	Q_PROPERTY(bool autoUpdate READ autoUpdate WRITE setAutoUpdate)
	Q_PROPERTY(bool borderInputsVisible READ borderInputsVisible WRITE setBorderInputsVisible)
	Q_PROPERTY(bool statusVisible READ statusVisible WRITE setStatusVisible)
	Q_PROPERTY(bool legendVisible READ legendVisible WRITE setLegendVisible)
	Q_PROPERTY(bool paused READ paused WRITE setPaused)
	Q_PROPERTY(bool onlyExpandY READ onlyExpandY WRITE setOnlyExpandY)
	Q_PROPERTY(bool onlyExpandX READ onlyExpandX WRITE setOnlyExpandX)
	Q_PROPERTY(bool gesturesNavigation READ gesturesNavigation WRITE setGesturesNavigation)
	Q_PROPERTY(bool LODOptimization READ LODOptimization WRITE setLODOptimization)
	Q_PROPERTY(double historySize READ historySize WRITE setHistorySize)
	Q_PROPERTY(double maxVisibleTime READ maxVisibleTime WRITE setMaxVisibleTime)
	Q_PROPERTY(double autoXIncrement READ autoXIncrement WRITE setAutoXIncrement)
	Q_PROPERTY(QRectF limit READ limit WRITE setLimit)
	Q_PROPERTY(QRect margins READ margins WRITE setMargins)
	Q_PROPERTY(QRectF visualRect READ visualRect WRITE setVisualRect)
	Q_PROPERTY(QRectF defaultRect READ defaultRect WRITE setDefaultRect)
	Q_PROPERTY(int minimumRepaintInterval READ minimumRepaintInterval WRITE setMinimumRepaintInterval)

	Q_PROPERTY(double gridNumbersMultiplierX READ gridNumbersMultiplierX WRITE setGridNumbersMultiplierX)
	Q_PROPERTY(double gridNumbersMultiplierY READ gridNumbersMultiplierY WRITE setGridNumbersMultiplierY)
	Q_PROPERTY(Graduation graduationX READ graduationX WRITE setGraduationX)
	Q_PROPERTY(Graduation graduationY READ graduationY WRITE setGraduationY)
	Q_PROPERTY(double graduationStepX READ graduationStepX WRITE setGraduationStepX)
	Q_PROPERTY(double graduationStepY READ graduationStepY WRITE setGraduationStepY)
	Q_PROPERTY(AxisType axisType READ axisType WRITE setAxisType)
	Q_PROPERTY(FloatingAxisType floatingAxisType READ floatingAxisType WRITE setFloatingAxisType)

	Q_PROPERTY(Graphic::GraphicsData graphicsData READ graphicsData WRITE setGraphicsData)
	Q_PROPERTY(QByteArray graphicsDataRaw READ graphicsDataRaw WRITE setGraphicsDataRaw)

	friend class GraphicPlugin;

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

	typedef QVector<QVector<QPointF>> GraphicsData;
	enum GraphicAction {
		gaNone,
		gaZoomInRect,
		gaZoomRangeX,
		gaZoomRangeY,
		gaMove
	};
	enum Button {
		NoButtons       = 0x0,
		AllButtons      = 0xFFFFFFFF,
		Autofit         = 0x01,
		Grid            = 0x02,
		CursorAxis      = 0x04,
		Fullscreen      = 0x20,
		BorderInputs    = 0x40,
		Legend          = 0x80,
		Configure       = 0x100,
		Save            = 0x200,
		Export          = 0x400,
		Clear           = 0x800,
		Close           = 0x1000,
		Pause           = 0x2000,
		Record          = 0x4000,
		StandartButtons = 0x2BFF
	};
	enum Alignment {
		Left,
		Right
	};
	enum Graduation {
		Auto,
		Fixed
	};
	enum AxisType {
		Numeric,
		DateTime
	};
	enum FloatingAxisType {
		Free,
		Trace
	};
	Q_DECLARE_FLAGS(Buttons, Button)

	QString caption() const;
	QString labelX() const { return label_x; }
	QString labelY() const { return label_y; }
	QString graphicName() const { return graphicName(curGraphic); }
	QString graphicName(int index) const;
	QColor backgroundColor() const { return back_color; }
	QColor textColor() const { return text_color; }
	QColor graphicColor() const { return graphicColor(curGraphic); }
	QColor graphicColor(int index) const;
	QColor gridColor() const { return grid_pen.color(); }
	QColor selectionColor() const { return selpen.color(); }
	Qt::PenStyle graphicStyle() const { return graphicStyle(curGraphic); }
	Qt::PenStyle graphicStyle(int index) const;
	Qt::PenStyle gridStyle() const { return grid_pen.style(); }
	Qt::PenStyle selectionStyle() const { return selpen.style(); }
	double graphicLineWidth() const { return graphicLineWidth(curGraphic); }
	double graphicLineWidth(int index) const;
	double graphicPointWidth() const { return graphicPointWidth(curGraphic); }
	double graphicPointWidth(int index) const;
	QColor graphicFillColor() const { return graphicFillColor(curGraphic); }
	QColor graphicFillColor(int index) const;
	bool graphicVisible() const { return graphicVisible(curGraphic); }
	bool graphicVisible(int index) const;
	bool graphicLinesEnabled() const { return graphicLinesEnabled(curGraphic); }
	bool graphicLinesEnabled(int index) const;
	bool graphicPointsEnabled() const { return graphicPointsEnabled(curGraphic); }
	bool graphicPointsEnabled(int index) const;
	bool graphicFillEnabled() const { return graphicFillEnabled(curGraphic); }
	bool graphicFillEnabled(int index) const;
	QPen graphicPen() const { return graphicPen(curGraphic); }
	QPen graphicPen(int index) const;
	QPen gridPen() const { return grid_pen; }
	QPen selectionPen() const { return selpen; }
	QBrush selectionBrush() const { return selbrush; }
	bool navigationEnabled() const { return navigation; }
	bool openGL() const { return isOGL; }
	bool antialiasing() const { return aalias; }
	bool autoUpdate() const { return aupdate; }
	bool gridEnabled() const { return grid; }
	bool borderInputsVisible() const;
	bool statusVisible() const;
	bool legendVisible() const;
	bool paused() const { return pause_; }
	bool onlyExpandY() const { return only_expand_y; }
	bool onlyExpandX() const { return only_expand_x; }
	bool gesturesNavigation() const { return gestures; }
	bool LODOptimization() const { return m_LODOptimization; }
	bool isAutofitted() const { return isFit; }
	int currentGraphic() const { return curGraphic; }
	int graphicsCount() const { return graphics.size(); }
	Graphic::Buttons buttons() const { return buttons_; }
	Graphic::Alignment buttonsPosition() const { return align; }
	double historySize() const { return history; }
	double maxVisibleTime() const { return visible_time; }
	double autoXIncrement() const { return inc_x; }
	QRectF visualRect() const { return selrect; }
	QRectF defaultRect() const { return def_rect; }
	QRectF limit() const { return limit_; }
	QRect margins() const { return margins_; }
	int minimumRepaintInterval() const { return min_repaint_int; }
	double gridNumbersMultiplierX() const { return grid_numbers_x; }
	double gridNumbersMultiplierY() const { return grid_numbers_y; }
	Graduation graduationX() const { return grad_x; }
	Graduation graduationY() const { return grad_y; }
	double graduationStepX() const { return gridx; }
	double graduationStepY() const { return gridy; }
	AxisType axisType() const { return axis_type_x; }
	FloatingAxisType floatingAxisType() const { return floating_axis_type; }
	QVector<QPointF> graphicData() const { return graphicData(curGraphic); }
	QVector<QPointF> graphicData(int index) const;
	GraphicsData graphicsData() const;
	QByteArray graphicsDataRaw() const;
	QWidget * viewport() const { return canvas; }

	QByteArray save();
	void load(QByteArray ba);

	GraphicType graphic(int arg);
	const QVector<GraphicType> & allGraphics() const { return graphics; }
	void setAllGraphics(const QVector<GraphicType> & g, bool update = true);

	double canvas2realX(double px) const;
	double canvas2realY(double py) const;
	double real2canvasX(double px) const;
	double real2canvasY(double py) const;
	QPointF canvas2real(QPointF canvas_point) const { return QPointF(canvas2realX(canvas_point.x()), canvas2realY(canvas_point.y())); }
	QPointF real2canvas(QPointF real_point) const { return QPointF(real2canvasX(real_point.x()), real2canvasY(real_point.y())); }
	QPolygonF real2canvas(const QPolygonF & real_polygon) const;
	QPolygonF canvas2real(const QPolygonF & canvas_polygon) const;
	double getScaleX() const;
	double getScaleY() const;
	QPointF getScale() const { return QPointF(getScaleX(), getScaleY()); }

public slots:
	void setCaption(const QString & str);
	void setLabelX(const QString & str);
	void setLabelY(const QString & str);
	void setGraphicName(const QString & str, int index);
	void setGraphicName(const QString & str);
	void setBackgroundColor(const QColor & color);
	void setTextColor(const QColor & color);
	void setGraphicColor(const QColor & color, int index);
	void setGraphicColor(const QColor & color);
	void setGridColor(const QColor & color);
	void setSelectionColor(const QColor & color);
	void setGraphicStyle(const Qt::PenStyle & style, int index);
	void setGraphicStyle(const Qt::PenStyle & style);
	void setGridStyle(const Qt::PenStyle & style);
	void setSelectionStyle(const Qt::PenStyle & style);
	void setGraphicVisible(bool visible, int index);
	void setGraphicVisible(bool visible);
	void setGraphicLineWidth(double w, int index);
	void setGraphicLineWidth(double w);
	void setGraphicPointWidth(double w, int index);
	void setGraphicPointWidth(double w);
	void setGraphicFillColor(const QColor & w, int index);
	void setGraphicFillColor(const QColor & w);
	void setGraphicLinesEnabled(bool w, int index);
	void setGraphicLinesEnabled(bool w);
	void setGraphicPointsEnabled(bool w, int index);
	void setGraphicPointsEnabled(bool w);
	void setGraphicFillEnabled(bool w, int index);
	void setGraphicFillEnabled(bool w);
	void setGraphicPen(const QPen & pen, int index);
	void setGraphicPen(const QPen & pen);
	void setGridPen(const QPen & pen);
	void setSelectionPen(const QPen & pen);
	void setSelectionBrush(const QBrush & brush);
	void setNavigationEnabled(bool on);
	void setLODOptimization(bool yes);
	void setOpenGL(bool on);
	void setAntialiasing(bool enabled);
	void setAutoUpdate(bool enabled);
	void setGridEnabled(bool enabled);
	void setBorderInputsVisible(bool visible);
	void setStatusVisible(bool visible);
	void setLegendVisible(bool visible);
	void setPaused(bool yes);
	void setButtons(Graphic::Buttons b);
	void setButtonsPosition(Graphic::Alignment a);
	void setHistorySize(double val);
	void setMaxVisibleTime(double val);
	void setAutoXIncrement(double val);
	void setLimit(const QRectF & val);
	void setMargins(const QRect & val);
	void setMargins(int left_, int right_, int top_, int bottom_);
	void setLeftMargin(int value);
	void setRightMargin(int value);
	void setTopMargin(int value);
	void setBottomMargin(int value);
	void setMinimumRepaintInterval(const int & val);
	void setOnlyExpandY(bool yes);
	void setOnlyExpandX(bool yes);
	void setGesturesNavigation(bool yes);
	void setGraphicsData(const GraphicsData & gd);
	void setGraphicsDataRaw(const QByteArray & ba);

	void setGridNumbersMultiplierX(double value);
	void setGridNumbersMultiplierY(double value);
	void setGraduationX(Graduation value);
	void setGraduationY(Graduation value);
	void setGraduationStepX(double sx);
	void setGraduationStepY(double sy);
	void setGraduationSteps(double sx, double sy);
	void setAxisType(AxisType t);
	void setFloatingAxisType(FloatingAxisType t);
	void setFloatingAxisEnabled(bool on);

	void addPoint(const QPointF & p, int graphic, bool update_ = true);
	void addPoint(const QPointF & p, bool update = true);
	void addPoint(double x, double y, int graphic, bool update = true);
	void addPoint(double x, double y, bool update = true);
	void addPoint(double y, int graphic, bool update = true);
	void addPoint(double y, bool update = true);
	void addPoints(const QPolygonF & pts, int graphic, bool update_ = true);
	void addPoints(const QPolygonF & pts, bool update = true);
	void addPoints(const QVector<double> & pts, int graphic, bool update_ = true);
	void addPoints(const QVector<double> & pts, bool update = true);
	void setGraphicData(const QVector<QPointF> & g, int graphic, bool update_ = true);
	void setGraphicData(const QVector<QPointF> & g);
	void setGraphicProperties(const QString & name,
	                          const QColor & color = Qt::darkRed,
	                          Qt::PenStyle style   = Qt::SolidLine,
	                          double width         = 0.,
	                          bool visible         = true);
	void setGraphicProperties(int graphic,
	                          const QString & name,
	                          const QColor & color = Qt::darkRed,
	                          Qt::PenStyle style   = Qt::SolidLine,
	                          double width         = 0.,
	                          bool visible         = true);
	void addGraphic(const QString & name,
	                const QColor & color = Qt::darkRed,
	                Qt::PenStyle style   = Qt::SolidLine,
	                double width         = 0.,
	                bool visible         = true);
	void addGraphic(const GraphicType & gd);
	void setVisualRect(const QRectF & rect);
	void setDefaultRect(const QRectF & rect);
	void autofit();
	void saveImage(QString filename);
	void exportGraphics(QString filename, QChar decimal_point, bool view_only = false);
	void clear();
	void update();
	void updateGraphics();
	void setCurrentGraphic(int arg);
	void setGraphicsCount(int arg, bool update = true);
	void removeGraphic(int arg, bool update = true);
	void setCustomGridMarkFuncs(std::function<QString(double val)> fx, std::function<QString(double val)> fy);
	void setCustomSaveImageTitleFunc(std::function<QString()> func);

	void zoom(float factor);
	void zoomIn() { zoom(1. / 1.2); }
	void zoomOut() { zoom(1.2); }
	void fullscreen();


protected:
	struct DateFormats {
		QString upper;
		QString center;
		QString lower;
	};

	void changeEvent(QEvent * e) override;
	void resizeEvent(QResizeEvent *) override;
	void showEvent(QShowEvent *) override;
	QSize sizeHint() const override { return QSize(400, 300); }
	void timerEvent(QTimerEvent * e) override;
	bool eventFilter(QObject * o, QEvent * e) override;

	void prepareCanvas(QWidget * w);
	void procGesture(QGesture * g);
	void procZoom(QPointF view_center, double dzoom, Qt::KeyboardModifiers km = Qt::NoModifier);
	void totalUpdate();
	void setCurrentAction(GraphicAction action);
	void findGraphicsRect(double start_x = 0., double end_x = 0., double start_y = 0., double end_y = 0.);
	void tick(int index, bool slide = true, bool update = true);
	void calcLOD(int index);
	void repaintCanvas(bool force = false);
	void drawGraphics();
	void drawGrid();
	void drawGuides();
	void drawPause();
	void drawAction();
	void updateLegend(bool es = true);
	void updateLegendChecks();
	void setCanvasCursor(QCursor cursor);
	void setGuidesCursor();
	void swapToBuffer();
	void swapToNormal() { bufferActive = false; }
	void setRectToLines();
	void checkLines();
	double splitRange(double range, int count = 1);
	double splitRangeDate(double range, int count, DateFormats & formats, int step[7]);
	double roundTo(double value, double round_to);
	void roundDateTime(QDateTime & dt, int * c);
	void addDateTime(QDateTime & dt, int * c, qint64 mul = 1);
	QPointF absPoint(QPointF point) { return QPointF(qAbs(point.x()), qAbs(point.y())); }
	QString pointCoords(QPointF point, bool x = true, bool y = true);
	QPair<QString, QString> gridMark(double v) const;
	void fillDateFormats();
	void askForExport(bool view_only);
	bool checkGraphicIndex(int index) const;
	void graphicVisibleChanged();

	Ui::Graphic * ui;
	UGLWidget * canvas_gl;
	QWidget * canvas;
	QPixmap buffer;
	QPainter * painter;
	QBrush selbrush;
	QPen grid_pen, selpen;
	QColor back_color, text_color;
	QVector<GraphicType> graphics, loaded_configs;
	int curGraphic;
	GraphicAction curaction, prevaction;
	QRectF grect, selrect, limit_, def_rect;
	QRect margins_;
	QSize font_sz;
	QPoint startpos, curpos, prevpos, gridborder;
	QPointF startpos_r, curpos_r;
	QString label_x, label_y, ppath, fp_size;
	Graphic::Buttons buttons_;
	Graphic::Alignment align;
	GraphicConf * conf;
	EvalSpinBox line_x_min, line_x_max, line_y_min, line_y_max;
	QElapsedTimer tm;
	QMenu * buttons_menu      = nullptr;
	QCheckBox * action_source = nullptr;
#ifdef Q_OS_ANDROID
	QElapsedTimer tm_fscr;
#endif
	QIcon icon_exp_x, icon_exp_y, icon_exp_sx, icon_exp_sy;
	QImage icon_pause_b, icon_pause_f;
	Graduation grad_x, grad_y;
	AxisType axis_type_x;
	FloatingAxisType floating_axis_type;
	double gridx, gridy, history, visible_time, inc_x, grid_numbers_x, grid_numbers_y, LN10;
	double eminx, eminy, emaxx, emaxy, pause_phase, gesture_angle;
	int lastw, lasth, min_repaint_int, thick;
	int timer_pause, timer_record;
	bool aalias, aupdate, grid, guides, isFit, isOGL, isHover, bufferActive, cancel, pause_, gestures, m_LODOptimization, m_fakeGL,
		need_createGL;
	bool hasLblX, hasLblY, navigation, only_expand_y, only_expand_x, is_lines_update, leg_update, visible_update, fullscr, need_mouse_pan,
		was_trace;
	std::function<QString(double val)> func_gridMarkX, func_gridMarkY;
	std::function<QString()> func_image_title;
	QVector<DateFormats> date_formats;
	QList<QImage> record_imgs;

protected slots:
	void canvasPaintEvent();
	void canvasMouseMoveEvent(QMouseEvent *);
	void canvasMousePressEvent(QMouseEvent *);
	void canvasMouseReleaseEvent(QMouseEvent *);
	void canvasMouseDoubleClickEvent(QMouseEvent *);
	void canvasWheelEvent(QWheelEvent *);
	void canvasLeaveEvent(QEvent *);
	void graphicVisibleChange(bool checked);
	void lineXMinChanged(double value);
	void lineXMaxChanged(double value);
	void lineYMinChanged(double value);
	void lineYMaxChanged(double value);
	void on_actionCheck_all_triggered();
	void on_actionUncheck_all_triggered();
	void on_actionInvert_selection_triggered();
	void on_actionSelect_only_this_triggered();
	void on_graphic_buttonClose_clicked();
	void on_graphic_buttonClear_clicked();
	void on_graphic_buttonAutofit_clicked();
	void on_graphic_buttonConfigure_clicked();
	void on_graphic_buttonFullscreen_clicked();
	void on_graphic_actionSaveImage_triggered();
	void on_graphic_actionExportCSV_triggered();
	void on_graphic_actionExportCSV_View_triggered();
	void on_graphic_buttonRecord_clicked(bool checked);
	void on_graphic_checkGuides_toggled(bool checked);
	void on_graphic_actionExpandX_triggered(bool checked);
	void on_graphic_actionExpandY_triggered(bool checked);
	void on_graphic_checkBorderInputs_toggled(bool checked);
	void on_graphic_checkLegend_toggled(bool checked);
	void on_graphic_checkPause_toggled(bool checked);
	void actionGuidesTriggered(QAction * a);
	void enterFullscreen();
	void leaveFullscreen();
	void showMenu();

signals:
	void beforeGraphicPaintEvent(QPainter *);
	void graphicPaintEvent(QPainter *);
	void graphicMouseMoveEvent(QPointF point, int buttons);
	void graphicMousePressEvent(QPointF point, int buttons);
	void graphicMouseReleaseEvent(QPointF point, int buttons);
	void graphicWheelEvent(QPointF point, int delta);
	void graphicTraceEvent(int graphic, QPointF point);
	void closeRequest(QWidget *);
	void cleared();
	void visualRectChanged();
	void graphicSettingsChanged();
};


Q_DECLARE_METATYPE(Graphic::GraphicsData)

Q_DECLARE_OPERATORS_FOR_FLAGS(Graphic::Buttons)


inline QDataStream & operator<<(QDataStream & s, const Graphic::Graduation & v) {
	s << (int)v;
	return s;
}
inline QDataStream & operator>>(QDataStream & s, Graphic::Graduation & v) {
	s >> *((int *)(&v));
	return s;
}


class QAD_GRAPHIC_EXPORT __GraphicRegistrator__ {
public:
	__GraphicRegistrator__() {
		qRegisterMetaType<QVector<QPointF>>("QVector<QPointF>");
		qRegisterMetaType<Graphic::GraphicsData>("Graphic::GraphicsData");
#if QT_VERSION_MAJOR <= 5
		qRegisterMetaTypeStreamOperators<Graphic::GraphicsData>("Graphic::GraphicsData");
#endif
	}
};

#endif // GRAPHIC_H
