#ifndef UGLWIDGET_H
#define UGLWIDGET_H

#include <QDebug>
#include <QWidget>
#if QT_VERSION >= 0x050400
#  include <QOpenGLWidget>
typedef QOpenGLWidget __GLWidget__;
#else
#  include <QGLWidget>
typedef QGLWidget __GLWidget__;
#  ifndef GL_MULTISAMPLE
#	define GL_MULTISAMPLE 0x809D
#  endif
#endif
#include "qad_graphic_export.h"


class QAD_GRAPHIC_EXPORT UGLWidget: public __GLWidget__ {
	Q_OBJECT

public:
#if QT_VERSION >= 0x050400
	UGLWidget(QWidget * parent = 0): __GLWidget__(parent) {
		QSurfaceFormat sf = format();
		sf.setSamples(8);
		setFormat(sf);
	}
#else
	UGLWidget(QWidget * parent = 0)
		: __GLWidget__(QGLFormat(QGL::DoubleBuffer | QGL::AlphaChannel | QGL::DirectRendering | QGL::SampleBuffers), parent) {}
#endif
	// UGLWidget(QGLContext * context, QWidget * parent = 0): __GLWidget__(context, parent) {}

#if QT_VERSION >= 0x050400
	QImage grabFrameBuffer() { return grabFramebuffer(); }
#endif

protected:
#if QT_VERSION >= 0x050400
	virtual void paintGL() { emit paintSignal(); }
#else
	virtual void paintEvent(QPaintEvent *) { emit paintSignal(); }
#endif
	virtual void resizeEvent(QResizeEvent * e) {
		__GLWidget__::resizeEvent(e);
		emit resizeSignal();
	}


signals:
	void closeEvent(QCloseEvent * e);
	void dragEnterEvent(QDragEnterEvent * e);
	void dragLeaveEvent(QDragLeaveEvent * e);
	void dragMoveEvent(QDragMoveEvent * e);
	void dropEvent(QDropEvent * e);
	void enterEvent(QEvent * e);
	void hideEvent(QHideEvent * e);
	void keyPressEvent(QKeyEvent * e);
	void keyReleaseEvent(QKeyEvent * e);
	void leaveEvent(QEvent * e);
	void mouseDoubleClickEvent(QMouseEvent * e);
	void mouseMoveEvent(QMouseEvent * e);
	void mousePressEvent(QMouseEvent * e);
	void mouseReleaseEvent(QMouseEvent * e);
	void moveEvent(QMoveEvent * e);
	void showEvent(QShowEvent * e);
	void wheelEvent(QWheelEvent * e);
	void resizeSignal();
	void paintSignal();
};

#endif
