2011-08-22 08:49:28 +00:00
|
|
|
#include "paintedwindow.h"
|
|
|
|
|
|
|
|
#include <QOpenGLContext>
|
2011-09-07 08:31:03 +00:00
|
|
|
#include <QOpenGLPaintDevice>
|
2011-08-22 08:49:28 +00:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
#include <qmath.h>
|
|
|
|
|
|
|
|
PaintedWindow::PaintedWindow()
|
|
|
|
{
|
|
|
|
QSurfaceFormat format;
|
|
|
|
format.setStencilBufferSize(8);
|
2011-09-07 08:31:03 +00:00
|
|
|
format.setSamples(4);
|
2011-08-22 08:49:28 +00:00
|
|
|
|
|
|
|
setSurfaceType(QWindow::OpenGLSurface);
|
|
|
|
setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
|
|
|
|
setFormat(format);
|
|
|
|
|
|
|
|
create();
|
|
|
|
|
|
|
|
m_context = new QOpenGLContext(this);
|
|
|
|
m_context->setFormat(format);
|
|
|
|
m_context->create();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PaintedWindow::resizeEvent(QResizeEvent *)
|
|
|
|
{
|
2011-09-07 08:31:03 +00:00
|
|
|
paint();
|
|
|
|
}
|
2011-08-22 08:49:28 +00:00
|
|
|
|
2011-09-07 08:31:03 +00:00
|
|
|
void PaintedWindow::exposeEvent(QExposeEvent *)
|
|
|
|
{
|
|
|
|
paint();
|
2011-08-22 08:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PaintedWindow::paint()
|
|
|
|
{
|
|
|
|
m_context->makeCurrent(this);
|
|
|
|
|
|
|
|
QPainterPath path;
|
2011-09-07 08:31:03 +00:00
|
|
|
path.addEllipse(0, 0, width(), height());
|
|
|
|
|
|
|
|
QOpenGLPaintDevice device(size());
|
2011-08-22 08:49:28 +00:00
|
|
|
|
2011-09-07 08:31:03 +00:00
|
|
|
QPainter painter(&device);
|
|
|
|
painter.fillRect(0, 0, width(), height(), Qt::white);
|
2011-08-22 08:49:28 +00:00
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
painter.fillPath(path, Qt::blue);
|
|
|
|
painter.end();
|
|
|
|
|
|
|
|
m_context->swapBuffers(this);
|
|
|
|
}
|