Widgets/GraphicsView examples: cleanup
Cleanup GraphicsView examples with the help of clang-tidy - modernize-use-nullptr - modernize-use-default-member-init - modernize-use-override.IgnoreDestructors - Some QList -> QVector changes - use nullptr - use normalized includes, remove unused includes - fix style Change-Id: I79347e55bfde52f6ae7749cc7093fbd442044020 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
42011c0361
commit
6f4bc3942d
@ -75,7 +75,8 @@
|
|||||||
\section1 Mouse Class Definition
|
\section1 Mouse Class Definition
|
||||||
|
|
||||||
When constructing a mouse item, we first ensure that all the item's
|
When constructing a mouse item, we first ensure that all the item's
|
||||||
private variables are properly initialized:
|
private variables which were no yet initialized directly in the class
|
||||||
|
are properly initialized:
|
||||||
|
|
||||||
\snippet graphicsview/collidingmice/mouse.cpp 0
|
\snippet graphicsview/collidingmice/mouse.cpp 0
|
||||||
|
|
||||||
|
@ -643,7 +643,9 @@
|
|||||||
This function is called when the item is removed from the scene
|
This function is called when the item is removed from the scene
|
||||||
and removes all arrows that are connected to this item. The arrow
|
and removes all arrows that are connected to this item. The arrow
|
||||||
must be removed from the \c arrows list of both its start and end
|
must be removed from the \c arrows list of both its start and end
|
||||||
item.
|
item. Since either the start or the end item is the object where
|
||||||
|
this function is currently called, we have to make sure to work on
|
||||||
|
a copy of arrows since removeArrow() is modifying this container.
|
||||||
|
|
||||||
Here is the \c addArrow() function:
|
Here is the \c addArrow() function:
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ int main(int argc, char **argv)
|
|||||||
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
||||||
l->setSpacing(0);
|
l->setSpacing(0);
|
||||||
|
|
||||||
QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window);
|
QGraphicsWidget *w = new QGraphicsWidget(nullptr, Qt::Window);
|
||||||
w->setPos(20, 20);
|
w->setPos(20, 20);
|
||||||
w->setLayout(l);
|
w->setLayout(l);
|
||||||
|
|
||||||
|
@ -51,33 +51,26 @@
|
|||||||
#include "layoutitem.h"
|
#include "layoutitem.h"
|
||||||
|
|
||||||
#include <QGradient>
|
#include <QGradient>
|
||||||
#include <QGraphicsLinearLayout>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
LayoutItem::LayoutItem(QGraphicsItem *parent/* = 0*/)
|
LayoutItem::LayoutItem(QGraphicsItem *parent)
|
||||||
: QGraphicsLayoutItem(), QGraphicsItem(parent)
|
: QGraphicsLayoutItem(), QGraphicsItem(parent),
|
||||||
|
m_pix(QPixmap(QLatin1String(":/images/block.png")))
|
||||||
{
|
{
|
||||||
m_pix = new QPixmap(QLatin1String(":/images/block.png"));
|
|
||||||
setGraphicsItem(this);
|
setGraphicsItem(this);
|
||||||
}
|
}
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
LayoutItem::~LayoutItem()
|
|
||||||
{
|
|
||||||
delete m_pix;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! [1]
|
//! [1]
|
||||||
void LayoutItem::paint(QPainter *painter,
|
void LayoutItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
const QStyleOptionGraphicsItem *option, QWidget *widget /*= 0*/)
|
QWidget *widget)
|
||||||
{
|
{
|
||||||
Q_UNUSED(widget);
|
Q_UNUSED(widget);
|
||||||
Q_UNUSED(option);
|
Q_UNUSED(option);
|
||||||
|
|
||||||
QRectF frame(QPointF(0,0), geometry().size());
|
QRectF frame(QPointF(0, 0), geometry().size());
|
||||||
qreal w = m_pix->width();
|
const QSize pmSize = m_pix.size();
|
||||||
qreal h = m_pix->height();
|
|
||||||
QGradientStops stops;
|
QGradientStops stops;
|
||||||
//! [1]
|
//! [1]
|
||||||
|
|
||||||
@ -94,8 +87,8 @@ void LayoutItem::paint(QPainter *painter,
|
|||||||
painter->drawRoundedRect(frame, 10.0, 10.0);
|
painter->drawRoundedRect(frame, 10.0, 10.0);
|
||||||
|
|
||||||
// paint a rect around the pixmap (with gradient)
|
// paint a rect around the pixmap (with gradient)
|
||||||
QPointF pixpos = frame.center() - (QPointF(w, h) / 2);
|
QPointF pixpos = frame.center() - (QPointF(pmSize.width(), pmSize.height()) / 2);
|
||||||
QRectF innerFrame(pixpos, QSizeF(w, h));
|
QRectF innerFrame(pixpos, pmSize);
|
||||||
innerFrame.adjust(-4, -4, 4, 4);
|
innerFrame.adjust(-4, -4, 4, 4);
|
||||||
gradient.setStart(innerFrame.topLeft());
|
gradient.setStart(innerFrame.topLeft());
|
||||||
gradient.setFinalStop(innerFrame.bottomRight());
|
gradient.setFinalStop(innerFrame.bottomRight());
|
||||||
@ -106,14 +99,14 @@ void LayoutItem::paint(QPainter *painter,
|
|||||||
gradient.setStops(stops);
|
gradient.setStops(stops);
|
||||||
painter->setBrush(QBrush(gradient));
|
painter->setBrush(QBrush(gradient));
|
||||||
painter->drawRoundedRect(innerFrame, 10.0, 10.0);
|
painter->drawRoundedRect(innerFrame, 10.0, 10.0);
|
||||||
painter->drawPixmap(pixpos, *m_pix);
|
painter->drawPixmap(pixpos, m_pix);
|
||||||
}
|
}
|
||||||
//! [2]
|
//! [2]
|
||||||
|
|
||||||
//! [3]
|
//! [3]
|
||||||
QRectF LayoutItem::boundingRect() const
|
QRectF LayoutItem::boundingRect() const
|
||||||
{
|
{
|
||||||
return QRectF(QPointF(0,0), geometry().size());
|
return QRectF(QPointF(0, 0), geometry().size());
|
||||||
}
|
}
|
||||||
//! [3]
|
//! [3]
|
||||||
|
|
||||||
@ -133,7 +126,7 @@ QSizeF LayoutItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
|
|||||||
case Qt::MinimumSize:
|
case Qt::MinimumSize:
|
||||||
case Qt::PreferredSize:
|
case Qt::PreferredSize:
|
||||||
// Do not allow a size smaller than the pixmap with two frames around it.
|
// Do not allow a size smaller than the pixmap with two frames around it.
|
||||||
return m_pix->size() + QSize(12, 12);
|
return m_pix.size() + QSize(12, 12);
|
||||||
case Qt::MaximumSize:
|
case Qt::MaximumSize:
|
||||||
return QSizeF(1000,1000);
|
return QSizeF(1000,1000);
|
||||||
default:
|
default:
|
||||||
|
@ -53,23 +53,24 @@
|
|||||||
|
|
||||||
#include <QGraphicsLayoutItem>
|
#include <QGraphicsLayoutItem>
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
class LayoutItem : public QGraphicsLayoutItem, public QGraphicsItem
|
class LayoutItem : public QGraphicsLayoutItem, public QGraphicsItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LayoutItem(QGraphicsItem *parent = 0);
|
LayoutItem(QGraphicsItem *parent = nullptr);
|
||||||
~LayoutItem();
|
|
||||||
// Inherited from QGraphicsLayoutItem
|
// Inherited from QGraphicsLayoutItem
|
||||||
void setGeometry(const QRectF &geom) override;
|
void setGeometry(const QRectF &geom) override;
|
||||||
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override;
|
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override;
|
||||||
|
|
||||||
// Inherited from QGraphicsItem
|
// Inherited from QGraphicsItem
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPixmap *m_pix;
|
QPixmap m_pix;
|
||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
|
@ -54,11 +54,11 @@
|
|||||||
#include <QGraphicsWidget>
|
#include <QGraphicsWidget>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
class Window : public QGraphicsWidget {
|
class Window : public QGraphicsWidget
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Window(QGraphicsWidget *parent = 0);
|
Window(QGraphicsWidget *parent = nullptr);
|
||||||
|
|
||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
@ -49,8 +49,6 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "glbuffers.h"
|
#include "glbuffers.h"
|
||||||
#include <QtGui/qmatrix4x4.h>
|
|
||||||
#include <QtCore/qmath.h>
|
|
||||||
|
|
||||||
void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
|
void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
|
||||||
{
|
{
|
||||||
@ -65,7 +63,7 @@ void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zF
|
|||||||
// GLTexture //
|
// GLTexture //
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
|
|
||||||
GLTexture::GLTexture() : m_texture(0), m_failed(false)
|
GLTexture::GLTexture()
|
||||||
{
|
{
|
||||||
glGenTextures(1, &m_texture);
|
glGenTextures(1, &m_texture);
|
||||||
}
|
}
|
||||||
@ -83,7 +81,7 @@ GLTexture2D::GLTexture2D(int width, int height)
|
|||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, m_texture);
|
glBindTexture(GL_TEXTURE_2D, m_texture);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0,
|
glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0,
|
||||||
GL_BGRA, GL_UNSIGNED_BYTE, 0);
|
GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
@ -95,7 +93,7 @@ GLTexture2D::GLTexture2D(int width, int height)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GLTexture2D::GLTexture2D(const QString& fileName, int width, int height)
|
GLTexture2D::GLTexture2D(const QString &fileName, int width, int height)
|
||||||
{
|
{
|
||||||
// TODO: Add error handling.
|
// TODO: Add error handling.
|
||||||
QImage image(fileName);
|
QImage image(fileName);
|
||||||
@ -162,7 +160,7 @@ GLTexture3D::GLTexture3D(int width, int height, int depth)
|
|||||||
|
|
||||||
glBindTexture(GL_TEXTURE_3D, m_texture);
|
glBindTexture(GL_TEXTURE_3D, m_texture);
|
||||||
glTexImage3D(GL_TEXTURE_3D, 0, 4, width, height, depth, 0,
|
glTexImage3D(GL_TEXTURE_3D, 0, 4, width, height, depth, 0,
|
||||||
GL_BGRA, GL_UNSIGNED_BYTE, 0);
|
GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
@ -206,7 +204,7 @@ GLTextureCube::GLTextureCube(int size)
|
|||||||
|
|
||||||
for (int i = 0; i < 6; ++i)
|
for (int i = 0; i < 6; ++i)
|
||||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 4, size, size, 0,
|
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 4, size, size, 0,
|
||||||
GL_BGRA, GL_UNSIGNED_BYTE, 0);
|
GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
@ -252,7 +250,7 @@ GLTextureCube::GLTextureCube(const QStringList &fileNames, int size)
|
|||||||
// Clear remaining faces.
|
// Clear remaining faces.
|
||||||
while (index < 6) {
|
while (index < 6) {
|
||||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, 0, 4, size, size, 0,
|
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, 0, 4, size, size, 0,
|
||||||
GL_BGRA, GL_UNSIGNED_BYTE, 0);
|
GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,11 +289,8 @@ void GLTextureCube::unbind()
|
|||||||
//============================================================================//
|
//============================================================================//
|
||||||
|
|
||||||
GLFrameBufferObject::GLFrameBufferObject(int width, int height)
|
GLFrameBufferObject::GLFrameBufferObject(int width, int height)
|
||||||
: m_fbo(0)
|
: m_width(width)
|
||||||
, m_depthBuffer(0)
|
|
||||||
, m_width(width)
|
|
||||||
, m_height(height)
|
, m_height(height)
|
||||||
, m_failed(false)
|
|
||||||
{
|
{
|
||||||
GLBUFFERS_ASSERT_OPENGL("GLFrameBufferObject::GLFrameBufferObject",
|
GLBUFFERS_ASSERT_OPENGL("GLFrameBufferObject::GLFrameBufferObject",
|
||||||
glGenFramebuffersEXT && glGenRenderbuffersEXT && glBindRenderbufferEXT && glRenderbufferStorageEXT, return)
|
glGenFramebuffersEXT && glGenRenderbuffersEXT && glBindRenderbufferEXT && glRenderbufferStorageEXT, return)
|
||||||
@ -373,7 +368,7 @@ void GLRenderTargetCube::getViewMatrix(QMatrix4x4& mat, int face)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int perm[6][3] = {
|
static constexpr int perm[6][3] = {
|
||||||
{2, 1, 0},
|
{2, 1, 0},
|
||||||
{2, 1, 0},
|
{2, 1, 0},
|
||||||
{0, 2, 1},
|
{0, 2, 1},
|
||||||
@ -382,7 +377,7 @@ void GLRenderTargetCube::getViewMatrix(QMatrix4x4& mat, int face)
|
|||||||
{0, 1, 2},
|
{0, 1, 2},
|
||||||
};
|
};
|
||||||
|
|
||||||
static float signs[6][3] = {
|
static constexpr float signs[6][3] = {
|
||||||
{-1.0f, -1.0f, -1.0f},
|
{-1.0f, -1.0f, -1.0f},
|
||||||
{+1.0f, -1.0f, +1.0f},
|
{+1.0f, -1.0f, +1.0f},
|
||||||
{+1.0f, +1.0f, -1.0f},
|
{+1.0f, +1.0f, -1.0f},
|
||||||
|
@ -58,7 +58,7 @@
|
|||||||
#include <QtOpenGL>
|
#include <QtOpenGL>
|
||||||
|
|
||||||
#define BUFFER_OFFSET(i) ((char*)0 + (i))
|
#define BUFFER_OFFSET(i) ((char*)0 + (i))
|
||||||
#define SIZE_OF_MEMBER(cls, member) sizeof(static_cast<cls *>(0)->member)
|
#define SIZE_OF_MEMBER(cls, member) sizeof(static_cast<cls *>(nullptr)->member)
|
||||||
|
|
||||||
#define GLBUFFERS_ASSERT_OPENGL(prefix, assertion, returnStatement) \
|
#define GLBUFFERS_ASSERT_OPENGL(prefix, assertion, returnStatement) \
|
||||||
if (m_failed || !(assertion)) { \
|
if (m_failed || !(assertion)) { \
|
||||||
@ -82,8 +82,8 @@ public:
|
|||||||
virtual void unbind() = 0;
|
virtual void unbind() = 0;
|
||||||
virtual bool failed() const {return m_failed;}
|
virtual bool failed() const {return m_failed;}
|
||||||
protected:
|
protected:
|
||||||
GLuint m_texture;
|
GLuint m_texture = 0;
|
||||||
bool m_failed;
|
bool m_failed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GLFrameBufferObject
|
class GLFrameBufferObject
|
||||||
@ -98,17 +98,17 @@ public:
|
|||||||
virtual bool failed() const {return m_failed;}
|
virtual bool failed() const {return m_failed;}
|
||||||
protected:
|
protected:
|
||||||
void setAsRenderTarget(bool state = true);
|
void setAsRenderTarget(bool state = true);
|
||||||
GLuint m_fbo;
|
GLuint m_fbo = 0;
|
||||||
GLuint m_depthBuffer;
|
GLuint m_depthBuffer = 0;
|
||||||
int m_width, m_height;
|
int m_width, m_height;
|
||||||
bool m_failed;
|
bool m_failed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GLTexture2D : public GLTexture
|
class GLTexture2D : public GLTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GLTexture2D(int width, int height);
|
GLTexture2D(int width, int height);
|
||||||
explicit GLTexture2D(const QString& fileName, int width = 0, int height = 0);
|
explicit GLTexture2D(const QString &fileName, int width = 0, int height = 0);
|
||||||
void load(int width, int height, QRgb *data);
|
void load(int width, int height, QRgb *data);
|
||||||
void bind() override;
|
void bind() override;
|
||||||
void unbind() override;
|
void unbind() override;
|
||||||
@ -197,11 +197,7 @@ template<class T>
|
|||||||
class GLVertexBuffer
|
class GLVertexBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GLVertexBuffer(int length, const T *data = 0, int mode = GL_STATIC_DRAW)
|
GLVertexBuffer(int length, const T *data = nullptr, int mode = GL_STATIC_DRAW)
|
||||||
: m_length(0)
|
|
||||||
, m_mode(mode)
|
|
||||||
, m_buffer(0)
|
|
||||||
, m_failed(false)
|
|
||||||
{
|
{
|
||||||
GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::GLVertexBuffer", glGenBuffers && glBindBuffer && glBufferData, return)
|
GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::GLVertexBuffer", glGenBuffers && glBindBuffer && glBufferData, return)
|
||||||
|
|
||||||
@ -275,12 +271,12 @@ public:
|
|||||||
|
|
||||||
T *lock()
|
T *lock()
|
||||||
{
|
{
|
||||||
GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::lock", glBindBuffer && glMapBuffer, return 0)
|
GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::lock", glBindBuffer && glMapBuffer, return nullptr)
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, m_buffer);
|
||||||
//glBufferData(GL_ARRAY_BUFFER, m_length, NULL, m_mode);
|
//glBufferData(GL_ARRAY_BUFFER, m_length, NULL, m_mode);
|
||||||
GLvoid* buffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
|
GLvoid* buffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
|
||||||
m_failed = (buffer == 0);
|
m_failed = (buffer == nullptr);
|
||||||
return reinterpret_cast<T *>(buffer);
|
return reinterpret_cast<T *>(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,16 +294,17 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_length, m_mode;
|
int m_length = 0;
|
||||||
GLuint m_buffer;
|
int m_mode = 0;
|
||||||
bool m_failed;
|
GLuint m_buffer = 0;
|
||||||
|
bool m_failed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
class GLIndexBuffer
|
class GLIndexBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GLIndexBuffer(int length, const T *data = 0, int mode = GL_STATIC_DRAW)
|
GLIndexBuffer(int length, const T *data = nullptr, int mode = GL_STATIC_DRAW)
|
||||||
: m_length(0)
|
: m_length(0)
|
||||||
, m_mode(mode)
|
, m_mode(mode)
|
||||||
, m_buffer(0)
|
, m_buffer(0)
|
||||||
@ -345,11 +342,11 @@ public:
|
|||||||
|
|
||||||
T *lock()
|
T *lock()
|
||||||
{
|
{
|
||||||
GLBUFFERS_ASSERT_OPENGL("GLIndexBuffer::lock", glBindBuffer && glMapBuffer, return 0)
|
GLBUFFERS_ASSERT_OPENGL("GLIndexBuffer::lock", glBindBuffer && glMapBuffer, return nullptr)
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_buffer);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_buffer);
|
||||||
GLvoid* buffer = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_READ_WRITE);
|
GLvoid* buffer = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_READ_WRITE);
|
||||||
m_failed = (buffer == 0);
|
m_failed = (buffer == nullptr);
|
||||||
return reinterpret_cast<T *>(buffer);
|
return reinterpret_cast<T *>(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,13 +51,12 @@
|
|||||||
#ifndef GLTRIANGLEMESH_H
|
#ifndef GLTRIANGLEMESH_H
|
||||||
#define GLTRIANGLEMESH_H
|
#define GLTRIANGLEMESH_H
|
||||||
|
|
||||||
//#include <GL/glew.h>
|
#include "glbuffers.h"
|
||||||
#include "glextensions.h"
|
#include "glextensions.h"
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
#include <QtOpenGL>
|
#include <QtOpenGL>
|
||||||
|
|
||||||
#include "glbuffers.h"
|
|
||||||
|
|
||||||
template<class TVertex, class TIndex>
|
template<class TVertex, class TIndex>
|
||||||
class GLTriangleMesh
|
class GLTriangleMesh
|
||||||
|
@ -48,13 +48,11 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
//#include <GL/glew.h>
|
|
||||||
#include "glextensions.h"
|
#include "glextensions.h"
|
||||||
|
|
||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
#include <QGLWidget>
|
#include <QGLWidget>
|
||||||
|
#include <QtWidgets>
|
||||||
|
|
||||||
class GraphicsView : public QGraphicsView
|
class GraphicsView : public QGraphicsView
|
||||||
{
|
{
|
||||||
@ -114,7 +112,7 @@ int main(int argc, char **argv)
|
|||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_5) == 0) {
|
if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_5) == 0) {
|
||||||
QMessageBox::critical(0, "OpenGL features missing",
|
QMessageBox::critical(nullptr, "OpenGL features missing",
|
||||||
"OpenGL version 1.5 or higher is required to run this demo.\n"
|
"OpenGL version 1.5 or higher is required to run this demo.\n"
|
||||||
"The program will now exit.");
|
"The program will now exit.");
|
||||||
return -1;
|
return -1;
|
||||||
@ -125,7 +123,7 @@ int main(int argc, char **argv)
|
|||||||
widget->makeCurrent();
|
widget->makeCurrent();
|
||||||
|
|
||||||
if (!necessaryExtensionsSupported()) {
|
if (!necessaryExtensionsSupported()) {
|
||||||
QMessageBox::critical(0, "OpenGL features missing",
|
QMessageBox::critical(nullptr, "OpenGL features missing",
|
||||||
"The OpenGL extensions required to run this demo are missing.\n"
|
"The OpenGL extensions required to run this demo are missing.\n"
|
||||||
"The program will now exit.");
|
"The program will now exit.");
|
||||||
delete widget;
|
delete widget;
|
||||||
@ -134,7 +132,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
// Check if all the necessary functions are resolved.
|
// Check if all the necessary functions are resolved.
|
||||||
if (!getGLExtensionFunctions().resolve(widget->context())) {
|
if (!getGLExtensionFunctions().resolve(widget->context())) {
|
||||||
QMessageBox::critical(0, "OpenGL features missing",
|
QMessageBox::critical(nullptr, "OpenGL features missing",
|
||||||
"Failed to resolve OpenGL functions required to run this demo.\n"
|
"Failed to resolve OpenGL functions required to run this demo.\n"
|
||||||
"The program will now exit.");
|
"The program will now exit.");
|
||||||
delete widget;
|
delete widget;
|
||||||
@ -142,7 +140,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make conditional for final release
|
// TODO: Make conditional for final release
|
||||||
QMessageBox::information(0, "For your information",
|
QMessageBox::information(nullptr, "For your information",
|
||||||
"This demo can be GPU and CPU intensive and may\n"
|
"This demo can be GPU and CPU intensive and may\n"
|
||||||
"work poorly or not at all on your system.");
|
"work poorly or not at all on your system.");
|
||||||
|
|
||||||
|
@ -50,28 +50,23 @@
|
|||||||
|
|
||||||
#include "qtbox.h"
|
#include "qtbox.h"
|
||||||
|
|
||||||
const qreal ROTATE_SPEED_X = 30.0 / 1000.0;
|
constexpr qreal ROTATE_SPEED_X = 30.0 / 1000.0;
|
||||||
const qreal ROTATE_SPEED_Y = 20.0 / 1000.0;
|
constexpr qreal ROTATE_SPEED_Y = 20.0 / 1000.0;
|
||||||
const qreal ROTATE_SPEED_Z = 40.0 / 1000.0;
|
constexpr qreal ROTATE_SPEED_Z = 40.0 / 1000.0;
|
||||||
const int MAX_ITEM_SIZE = 512;
|
constexpr int MAX_ITEM_SIZE = 512;
|
||||||
const int MIN_ITEM_SIZE = 16;
|
constexpr int MIN_ITEM_SIZE = 16;
|
||||||
|
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
// ItemBase //
|
// ItemBase //
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
|
|
||||||
ItemBase::ItemBase(int size, int x, int y) : m_size(size), m_isResizing(false)
|
ItemBase::ItemBase(int size, int x, int y) : m_size(size), m_startTime(QTime::currentTime())
|
||||||
{
|
{
|
||||||
setFlag(QGraphicsItem::ItemIsMovable, true);
|
setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||||
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
setFlag(QGraphicsItem::ItemIsFocusable, true);
|
setFlag(QGraphicsItem::ItemIsFocusable, true);
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
setPos(x, y);
|
setPos(x, y);
|
||||||
m_startTime = QTime::currentTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemBase::~ItemBase()
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF ItemBase::boundingRect() const
|
QRectF ItemBase::boundingRect() const
|
||||||
@ -252,10 +247,7 @@ void ItemBase::wheelEvent(QGraphicsSceneWheelEvent *event)
|
|||||||
{
|
{
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
m_size = int(m_size * qExp(-event->delta() / 600.0));
|
m_size = int(m_size * qExp(-event->delta() / 600.0));
|
||||||
if (m_size > MAX_ITEM_SIZE)
|
m_size = qBound(MIN_ITEM_SIZE, m_size, MAX_ITEM_SIZE);
|
||||||
m_size = MAX_ITEM_SIZE;
|
|
||||||
else if (m_size < MIN_ITEM_SIZE)
|
|
||||||
m_size = MIN_ITEM_SIZE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ItemBase::type() const
|
int ItemBase::type() const
|
||||||
@ -273,7 +265,7 @@ bool ItemBase::isInResizeArea(const QPointF &pos)
|
|||||||
// QtBox //
|
// QtBox //
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
|
|
||||||
QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y), m_texture(0)
|
QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i) {
|
||||||
m_vertices[i].setX(i & 1 ? 0.5f : -0.5f);
|
m_vertices[i].setX(i & 1 ? 0.5f : -0.5f);
|
||||||
@ -294,8 +286,7 @@ QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y), m_texture(0)
|
|||||||
|
|
||||||
QtBox::~QtBox()
|
QtBox::~QtBox()
|
||||||
{
|
{
|
||||||
if (m_texture)
|
delete m_texture;
|
||||||
delete m_texture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemBase *QtBox::createNew(int size, int x, int y)
|
ItemBase *QtBox::createNew(int size, int x, int y)
|
||||||
@ -337,7 +328,7 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
|
|||||||
glEnable(GL_COLOR_MATERIAL);
|
glEnable(GL_COLOR_MATERIAL);
|
||||||
glEnable(GL_NORMALIZE);
|
glEnable(GL_NORMALIZE);
|
||||||
|
|
||||||
if(m_texture == 0)
|
if (m_texture == nullptr)
|
||||||
m_texture = new GLTexture2D(":/res/boxes/qt-logo.jpg", 64, 64);
|
m_texture = new GLTexture2D(":/res/boxes/qt-logo.jpg", 64, 64);
|
||||||
m_texture->bind();
|
m_texture->bind();
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
@ -405,9 +396,8 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
|
|||||||
//============================================================================//
|
//============================================================================//
|
||||||
|
|
||||||
CircleItem::CircleItem(int size, int x, int y) : ItemBase(size, x, y)
|
CircleItem::CircleItem(int size, int x, int y) : ItemBase(size, x, y)
|
||||||
{
|
, m_color(QColor::fromHsv(QRandomGenerator::global()->bounded(360), 255, 255))
|
||||||
m_color = QColor::fromHsv(QRandomGenerator::global()->bounded(360), 255, 255);
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
@ -455,9 +445,8 @@ ItemBase *CircleItem::createNew(int size, int x, int y)
|
|||||||
//============================================================================//
|
//============================================================================//
|
||||||
|
|
||||||
SquareItem::SquareItem(int size, int x, int y) : ItemBase(size, x, y)
|
SquareItem::SquareItem(int size, int x, int y) : ItemBase(size, x, y)
|
||||||
{
|
, m_image(QPixmap(":/res/boxes/square.jpg"))
|
||||||
m_image = QPixmap(":/res/boxes/square.jpg");
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
void SquareItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
void SquareItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
|
@ -51,18 +51,17 @@
|
|||||||
#ifndef QTBOX_H
|
#ifndef QTBOX_H
|
||||||
#define QTBOX_H
|
#define QTBOX_H
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
#include <QtGui/qvector3d.h>
|
|
||||||
#include "glbuffers.h"
|
#include "glbuffers.h"
|
||||||
|
|
||||||
|
#include <QtWidgets>
|
||||||
|
#include <QVector3D>
|
||||||
|
|
||||||
class ItemBase : public QGraphicsItem
|
class ItemBase : public QGraphicsItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum { Type = UserType + 1 };
|
enum { Type = UserType + 1 };
|
||||||
|
|
||||||
ItemBase(int size, int x, int y);
|
ItemBase(int size, int x, int y);
|
||||||
virtual ~ItemBase();
|
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||||
protected:
|
protected:
|
||||||
@ -84,7 +83,7 @@ protected:
|
|||||||
|
|
||||||
int m_size;
|
int m_size;
|
||||||
QTime m_startTime;
|
QTime m_startTime;
|
||||||
bool m_isResizing;
|
bool m_isResizing = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QtBox : public ItemBase
|
class QtBox : public ItemBase
|
||||||
@ -99,7 +98,7 @@ private:
|
|||||||
QVector3D m_vertices[8];
|
QVector3D m_vertices[8];
|
||||||
QVector3D m_texCoords[4];
|
QVector3D m_texCoords[4];
|
||||||
QVector3D m_normals[6];
|
QVector3D m_normals[6];
|
||||||
GLTexture *m_texture;
|
GLTexture *m_texture = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CircleItem : public ItemBase
|
class CircleItem : public ItemBase
|
||||||
|
@ -51,16 +51,12 @@
|
|||||||
#ifndef ROUNDEDBOX_H
|
#ifndef ROUNDEDBOX_H
|
||||||
#define ROUNDEDBOX_H
|
#define ROUNDEDBOX_H
|
||||||
|
|
||||||
//#include <GL/glew.h>
|
|
||||||
#include "glextensions.h"
|
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
#include <QtOpenGL>
|
|
||||||
|
|
||||||
#include "gltrianglemesh.h"
|
|
||||||
#include <QtGui/qvector3d.h>
|
|
||||||
#include <QtGui/qvector2d.h>
|
|
||||||
#include "glbuffers.h"
|
#include "glbuffers.h"
|
||||||
|
#include "glextensions.h"
|
||||||
|
#include "gltrianglemesh.h"
|
||||||
|
|
||||||
|
#include <QVector2D>
|
||||||
|
#include <QVector3D>
|
||||||
|
|
||||||
struct P3T2N3Vertex
|
struct P3T2N3Vertex
|
||||||
{
|
{
|
||||||
|
@ -48,45 +48,15 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
#include <QtCore/QRandomGenerator>
|
|
||||||
#include <QtGui/qmatrix4x4.h>
|
#include <QMatrix4x4>
|
||||||
#include <QtGui/qvector3d.h>
|
#include <QRandomGenerator>
|
||||||
|
#include <QVector3D>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
|
||||||
#include "3rdparty/fbm.h"
|
#include "3rdparty/fbm.h"
|
||||||
|
|
||||||
void checkGLErrors(const QString& prefix)
|
|
||||||
{
|
|
||||||
switch (glGetError()) {
|
|
||||||
case GL_NO_ERROR:
|
|
||||||
//qDebug() << prefix << tr("No error.");
|
|
||||||
break;
|
|
||||||
case GL_INVALID_ENUM:
|
|
||||||
qDebug() << prefix << QObject::tr("Invalid enum.");
|
|
||||||
break;
|
|
||||||
case GL_INVALID_VALUE:
|
|
||||||
qDebug() << prefix << QObject::tr("Invalid value.");
|
|
||||||
break;
|
|
||||||
case GL_INVALID_OPERATION:
|
|
||||||
qDebug() << prefix << QObject::tr("Invalid operation.");
|
|
||||||
break;
|
|
||||||
case GL_STACK_OVERFLOW:
|
|
||||||
qDebug() << prefix << QObject::tr("Stack overflow.");
|
|
||||||
break;
|
|
||||||
case GL_STACK_UNDERFLOW:
|
|
||||||
qDebug() << prefix << QObject::tr("Stack underflow.");
|
|
||||||
break;
|
|
||||||
case GL_OUT_OF_MEMORY:
|
|
||||||
qDebug() << prefix << QObject::tr("Out of memory.");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
qDebug() << prefix << QObject::tr("Unknown error.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
// ColorEdit //
|
// ColorEdit //
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
@ -126,7 +96,7 @@ void ColorEdit::mousePressEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
QColor color(m_color);
|
QColor color(m_color);
|
||||||
QColorDialog dialog(color, 0);
|
QColorDialog dialog(color, nullptr);
|
||||||
dialog.setOption(QColorDialog::ShowAlphaChannel, true);
|
dialog.setOption(QColorDialog::ShowAlphaChannel, true);
|
||||||
dialog.move(280, 120);
|
dialog.move(280, 120);
|
||||||
if (dialog.exec() == QDialog::Rejected)
|
if (dialog.exec() == QDialog::Rejected)
|
||||||
@ -179,17 +149,6 @@ void FloatEdit::editDone()
|
|||||||
//============================================================================//
|
//============================================================================//
|
||||||
// TwoSidedGraphicsWidget //
|
// TwoSidedGraphicsWidget //
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
|
|
||||||
TwoSidedGraphicsWidget::TwoSidedGraphicsWidget(QGraphicsScene *scene)
|
|
||||||
: QObject(scene)
|
|
||||||
, m_current(0)
|
|
||||||
, m_angle(0)
|
|
||||||
, m_delta(0)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 2; ++i)
|
|
||||||
m_proxyWidgets[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TwoSidedGraphicsWidget::setWidget(int index, QWidget *widget)
|
void TwoSidedGraphicsWidget::setWidget(int index, QWidget *widget)
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= 2)
|
if (index < 0 || index >= 2)
|
||||||
@ -201,8 +160,7 @@ void TwoSidedGraphicsWidget::setWidget(int index, QWidget *widget)
|
|||||||
GraphicsWidget *proxy = new GraphicsWidget;
|
GraphicsWidget *proxy = new GraphicsWidget;
|
||||||
proxy->setWidget(widget);
|
proxy->setWidget(widget);
|
||||||
|
|
||||||
if (m_proxyWidgets[index])
|
delete m_proxyWidgets[index];
|
||||||
delete m_proxyWidgets[index];
|
|
||||||
m_proxyWidgets[index] = proxy;
|
m_proxyWidgets[index] = proxy;
|
||||||
|
|
||||||
proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache);
|
proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache);
|
||||||
@ -219,7 +177,7 @@ QWidget *TwoSidedGraphicsWidget::widget(int index)
|
|||||||
if (index < 0 || index >= 2)
|
if (index < 0 || index >= 2)
|
||||||
{
|
{
|
||||||
qWarning("TwoSidedGraphicsWidget::widget: Index out of bounds, index == %d", index);
|
qWarning("TwoSidedGraphicsWidget::widget: Index out of bounds, index == %d", index);
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return m_proxyWidgets[index]->widget();
|
return m_proxyWidgets[index]->widget();
|
||||||
}
|
}
|
||||||
@ -289,7 +247,7 @@ void GraphicsWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
|
|||||||
//============================================================================//
|
//============================================================================//
|
||||||
|
|
||||||
RenderOptionsDialog::RenderOptionsDialog()
|
RenderOptionsDialog::RenderOptionsDialog()
|
||||||
: QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
|
: QDialog(nullptr, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
|
||||||
{
|
{
|
||||||
setWindowOpacity(0.75);
|
setWindowOpacity(0.75);
|
||||||
setWindowTitle(tr("Options (double click to flip)"));
|
setWindowTitle(tr("Options (double click to flip)"));
|
||||||
@ -423,7 +381,7 @@ void RenderOptionsDialog::mouseDoubleClickEvent(QMouseEvent *event)
|
|||||||
//============================================================================//
|
//============================================================================//
|
||||||
|
|
||||||
ItemDialog::ItemDialog()
|
ItemDialog::ItemDialog()
|
||||||
: QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
|
: QDialog(nullptr, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
|
||||||
{
|
{
|
||||||
setWindowTitle(tr("Items (double click to flip)"));
|
setWindowTitle(tr("Items (double click to flip)"));
|
||||||
setWindowOpacity(0.75);
|
setWindowOpacity(0.75);
|
||||||
@ -487,10 +445,10 @@ Scene::Scene(int width, int height, int maxTextureSize)
|
|||||||
, m_currentTexture(0)
|
, m_currentTexture(0)
|
||||||
, m_dynamicCubemap(false)
|
, m_dynamicCubemap(false)
|
||||||
, m_updateAllCubemaps(true)
|
, m_updateAllCubemaps(true)
|
||||||
, m_box(0)
|
, m_box(nullptr)
|
||||||
, m_vertexShader(0)
|
, m_vertexShader(nullptr)
|
||||||
, m_environmentShader(0)
|
, m_environmentShader(nullptr)
|
||||||
, m_environmentProgram(0)
|
, m_environmentProgram(nullptr)
|
||||||
{
|
{
|
||||||
setSceneRect(0, 0, width, height);
|
setSceneRect(0, 0, width, height);
|
||||||
|
|
||||||
@ -564,9 +522,8 @@ void Scene::initGL()
|
|||||||
|
|
||||||
const int NOISE_SIZE = 128; // for a different size, B and BM in fbm.c must also be changed
|
const int NOISE_SIZE = 128; // for a different size, B and BM in fbm.c must also be changed
|
||||||
m_noise = new GLTexture3D(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE);
|
m_noise = new GLTexture3D(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE);
|
||||||
QRgb *data = new QRgb[NOISE_SIZE * NOISE_SIZE * NOISE_SIZE];
|
QVector<QRgb> data(NOISE_SIZE * NOISE_SIZE * NOISE_SIZE, QRgb(0));
|
||||||
memset(data, 0, NOISE_SIZE * NOISE_SIZE * NOISE_SIZE * sizeof(QRgb));
|
QRgb *p = data.data();
|
||||||
QRgb *p = data;
|
|
||||||
float pos[3];
|
float pos[3];
|
||||||
for (int k = 0; k < NOISE_SIZE; ++k) {
|
for (int k = 0; k < NOISE_SIZE; ++k) {
|
||||||
pos[2] = k * (0x20 / (float)NOISE_SIZE);
|
pos[2] = k * (0x20 / (float)NOISE_SIZE);
|
||||||
@ -581,8 +538,7 @@ void Scene::initGL()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_noise->load(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE, data);
|
m_noise->load(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE, data.data());
|
||||||
delete[] data;
|
|
||||||
|
|
||||||
m_mainCubemap = new GLRenderTargetCube(512);
|
m_mainCubemap = new GLRenderTargetCube(512);
|
||||||
|
|
||||||
@ -634,7 +590,7 @@ void Scene::initGL()
|
|||||||
m_renderOptions->addShader(file.baseName());
|
m_renderOptions->addShader(file.baseName());
|
||||||
|
|
||||||
program->bind();
|
program->bind();
|
||||||
m_cubemaps << ((program->uniformLocation("env") != -1) ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : 0);
|
m_cubemaps << ((program->uniformLocation("env") != -1) ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : nullptr);
|
||||||
program->release();
|
program->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,17 +51,12 @@
|
|||||||
#ifndef SCENE_H
|
#ifndef SCENE_H
|
||||||
#define SCENE_H
|
#define SCENE_H
|
||||||
|
|
||||||
//#include <GL/glew.h>
|
|
||||||
#include "glextensions.h"
|
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
#include <QtOpenGL>
|
|
||||||
|
|
||||||
#include "roundedbox.h"
|
|
||||||
#include "gltrianglemesh.h"
|
|
||||||
#include "trackball.h"
|
|
||||||
#include "glbuffers.h"
|
#include "glbuffers.h"
|
||||||
|
#include "glextensions.h"
|
||||||
|
#include "gltrianglemesh.h"
|
||||||
#include "qtbox.h"
|
#include "qtbox.h"
|
||||||
|
#include "roundedbox.h"
|
||||||
|
#include "trackball.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QMatrix4x4;
|
class QMatrix4x4;
|
||||||
@ -116,7 +111,7 @@ private:
|
|||||||
class GraphicsWidget : public QGraphicsProxyWidget
|
class GraphicsWidget : public QGraphicsProxyWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GraphicsWidget() : QGraphicsProxyWidget(0, Qt::Window) {}
|
GraphicsWidget() : QGraphicsProxyWidget(nullptr, Qt::Window) {}
|
||||||
protected:
|
protected:
|
||||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||||
void resizeEvent(QGraphicsSceneResizeEvent *event) override;
|
void resizeEvent(QGraphicsSceneResizeEvent *event) override;
|
||||||
@ -127,7 +122,7 @@ class TwoSidedGraphicsWidget : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
TwoSidedGraphicsWidget(QGraphicsScene *scene);
|
using QObject::QObject;
|
||||||
void setWidget(int index, QWidget *widget);
|
void setWidget(int index, QWidget *widget);
|
||||||
QWidget *widget(int index);
|
QWidget *widget(int index);
|
||||||
public slots:
|
public slots:
|
||||||
@ -135,10 +130,10 @@ public slots:
|
|||||||
protected slots:
|
protected slots:
|
||||||
void animateFlip();
|
void animateFlip();
|
||||||
private:
|
private:
|
||||||
GraphicsWidget *m_proxyWidgets[2];
|
GraphicsWidget *m_proxyWidgets[2] = {nullptr, nullptr};
|
||||||
int m_current;
|
int m_current = 0;
|
||||||
int m_angle; // angle in degrees
|
int m_angle = 0; // angle in degrees
|
||||||
int m_delta;
|
int m_delta = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RenderOptionsDialog : public QDialog
|
class RenderOptionsDialog : public QDialog
|
||||||
|
@ -50,34 +50,21 @@
|
|||||||
|
|
||||||
#include "trackball.h"
|
#include "trackball.h"
|
||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
#include <qmath.h>
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
// TrackBall //
|
// TrackBall //
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
|
|
||||||
TrackBall::TrackBall(TrackMode mode)
|
TrackBall::TrackBall(TrackMode mode)
|
||||||
: m_angularVelocity(0)
|
: TrackBall(0, QVector3D(0, 1, 0), mode)
|
||||||
, m_paused(false)
|
|
||||||
, m_pressed(false)
|
|
||||||
, m_mode(mode)
|
|
||||||
{
|
{
|
||||||
m_axis = QVector3D(0, 1, 0);
|
|
||||||
m_rotation = QQuaternion();
|
|
||||||
m_lastTime = QTime::currentTime();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackBall::TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode)
|
TrackBall::TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode)
|
||||||
: m_axis(axis)
|
: m_axis(axis)
|
||||||
, m_angularVelocity(angularVelocity)
|
, m_angularVelocity(angularVelocity)
|
||||||
, m_paused(false)
|
|
||||||
, m_pressed(false)
|
|
||||||
, m_mode(mode)
|
, m_mode(mode)
|
||||||
{
|
{}
|
||||||
m_rotation = QQuaternion();
|
|
||||||
m_lastTime = QTime::currentTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackBall::push(const QPointF& p, const QQuaternion &)
|
void TrackBall::push(const QPointF& p, const QQuaternion &)
|
||||||
{
|
{
|
||||||
|
@ -51,10 +51,9 @@
|
|||||||
#ifndef TRACKBALL_H
|
#ifndef TRACKBALL_H
|
||||||
#define TRACKBALL_H
|
#define TRACKBALL_H
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QQuaternion>
|
||||||
|
#include <QTime>
|
||||||
#include <QtGui/qvector3d.h>
|
#include <QVector3D>
|
||||||
#include <QtGui/qquaternion.h>
|
|
||||||
|
|
||||||
class TrackBall
|
class TrackBall
|
||||||
{
|
{
|
||||||
@ -65,24 +64,24 @@ public:
|
|||||||
Sphere,
|
Sphere,
|
||||||
};
|
};
|
||||||
TrackBall(TrackMode mode = Sphere);
|
TrackBall(TrackMode mode = Sphere);
|
||||||
TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode = Sphere);
|
TrackBall(float angularVelocity, const QVector3D &axis, TrackMode mode = Sphere);
|
||||||
// coordinates in [-1,1]x[-1,1]
|
// coordinates in [-1,1]x[-1,1]
|
||||||
void push(const QPointF& p, const QQuaternion &transformation);
|
void push(const QPointF &p, const QQuaternion &transformation);
|
||||||
void move(const QPointF& p, const QQuaternion &transformation);
|
void move(const QPointF &p, const QQuaternion &transformation);
|
||||||
void release(const QPointF& p, const QQuaternion &transformation);
|
void release(const QPointF &p, const QQuaternion &transformation);
|
||||||
void start(); // starts clock
|
void start(); // starts clock
|
||||||
void stop(); // stops clock
|
void stop(); // stops clock
|
||||||
QQuaternion rotation() const;
|
QQuaternion rotation() const;
|
||||||
private:
|
private:
|
||||||
QQuaternion m_rotation;
|
QQuaternion m_rotation;
|
||||||
QVector3D m_axis;
|
QVector3D m_axis = QVector3D(0, 1, 0);
|
||||||
float m_angularVelocity;
|
float m_angularVelocity = 0;
|
||||||
|
|
||||||
QPointF m_lastPos;
|
QPointF m_lastPos;
|
||||||
QTime m_lastTime;
|
QTime m_lastTime = QTime::currentTime();
|
||||||
bool m_paused;
|
|
||||||
bool m_pressed;
|
|
||||||
TrackMode m_mode;
|
TrackMode m_mode;
|
||||||
|
bool m_paused = false;
|
||||||
|
bool m_pressed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -50,7 +50,9 @@
|
|||||||
|
|
||||||
#include "chip.h"
|
#include "chip.h"
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QStyleOptionGraphicsItem>
|
||||||
|
|
||||||
Chip::Chip(const QColor &color, int x, int y)
|
Chip::Chip(const QColor &color, int x, int y)
|
||||||
{
|
{
|
||||||
|
@ -56,13 +56,11 @@
|
|||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent), scene(new QGraphicsScene(this))
|
||||||
|
, h1Splitter(new QSplitter(this)), h2Splitter(new QSplitter(this))
|
||||||
{
|
{
|
||||||
populateScene();
|
populateScene();
|
||||||
|
|
||||||
h1Splitter = new QSplitter;
|
|
||||||
h2Splitter = new QSplitter;
|
|
||||||
|
|
||||||
QSplitter *vSplitter = new QSplitter;
|
QSplitter *vSplitter = new QSplitter;
|
||||||
vSplitter->setOrientation(Qt::Vertical);
|
vSplitter->setOrientation(Qt::Vertical);
|
||||||
vSplitter->addWidget(h1Splitter);
|
vSplitter->addWidget(h1Splitter);
|
||||||
@ -93,8 +91,6 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
|
|
||||||
void MainWindow::populateScene()
|
void MainWindow::populateScene()
|
||||||
{
|
{
|
||||||
scene = new QGraphicsScene(this);
|
|
||||||
|
|
||||||
QImage image(":/qt4logo.png");
|
QImage image(":/qt4logo.png");
|
||||||
|
|
||||||
// Populate scene
|
// Populate scene
|
||||||
|
@ -62,7 +62,7 @@ class MainWindow : public QWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
MainWindow(QWidget *parent = 0);
|
MainWindow(QWidget *parent = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupMatrix();
|
void setupMatrix();
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
#else
|
#else
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
#endif
|
#endif
|
||||||
#include <qmath.h>
|
#include <QtMath>
|
||||||
|
|
||||||
#if QT_CONFIG(wheelevent)
|
#if QT_CONFIG(wheelevent)
|
||||||
void GraphicsView::wheelEvent(QWheelEvent *e)
|
void GraphicsView::wheelEvent(QWheelEvent *e)
|
||||||
|
@ -81,7 +81,7 @@ class View : public QFrame
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit View(const QString &name, QWidget *parent = 0);
|
explicit View(const QString &name, QWidget *parent = nullptr);
|
||||||
|
|
||||||
QGraphicsView *view() const;
|
QGraphicsView *view() const;
|
||||||
|
|
||||||
|
@ -48,13 +48,12 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QtMath>
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#include "mouse.h"
|
#include "mouse.h"
|
||||||
|
|
||||||
static const int MouseCount = 7;
|
static constexpr int MouseCount = 7;
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
@ -54,10 +54,10 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QRandomGenerator>
|
#include <QRandomGenerator>
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
#include <qmath.h>
|
#include <QtMath>
|
||||||
|
|
||||||
const qreal Pi = M_PI;
|
constexpr qreal Pi = M_PI;
|
||||||
const qreal TwoPi = 2 * M_PI;
|
constexpr qreal TwoPi = 2 * M_PI;
|
||||||
|
|
||||||
static qreal normalizeAngle(qreal angle)
|
static qreal normalizeAngle(qreal angle)
|
||||||
{
|
{
|
||||||
@ -70,8 +70,7 @@ static qreal normalizeAngle(qreal angle)
|
|||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
Mouse::Mouse()
|
Mouse::Mouse()
|
||||||
: angle(0), speed(0), mouseEyeDirection(0),
|
: color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
|
||||||
color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
|
|
||||||
{
|
{
|
||||||
setRotation(QRandomGenerator::global()->bounded(360 * 16));
|
setRotation(QRandomGenerator::global()->bounded(360 * 16));
|
||||||
}
|
}
|
||||||
|
@ -68,9 +68,9 @@ protected:
|
|||||||
void advance(int step) override;
|
void advance(int step) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
qreal angle;
|
qreal angle = 0;
|
||||||
qreal speed;
|
qreal speed = 0;
|
||||||
qreal mouseEyeDirection;
|
qreal mouseEyeDirection = 0;
|
||||||
QColor color;
|
QColor color;
|
||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
@ -50,19 +50,17 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "arrow.h"
|
#include "arrow.h"
|
||||||
|
#include "diagramitem.h"
|
||||||
|
|
||||||
#include <qmath.h>
|
|
||||||
#include <QPen>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QPen>
|
||||||
|
#include <QtMath>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
Arrow::Arrow(DiagramItem *startItem, DiagramItem *endItem, QGraphicsItem *parent)
|
Arrow::Arrow(DiagramItem *startItem, DiagramItem *endItem, QGraphicsItem *parent)
|
||||||
: QGraphicsLineItem(parent)
|
: QGraphicsLineItem(parent), myStartItem(startItem), myEndItem(endItem)
|
||||||
{
|
{
|
||||||
myStartItem = startItem;
|
|
||||||
myEndItem = endItem;
|
|
||||||
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
myColor = Qt::black;
|
|
||||||
setPen(QPen(myColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
setPen(QPen(myColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||||
}
|
}
|
||||||
//! [0]
|
//! [0]
|
||||||
@ -98,7 +96,7 @@ void Arrow::updatePosition()
|
|||||||
|
|
||||||
//! [4]
|
//! [4]
|
||||||
void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
|
void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
|
||||||
QWidget *)
|
QWidget *)
|
||||||
{
|
{
|
||||||
if (myStartItem->collidesWithItem(myEndItem))
|
if (myStartItem->collidesWithItem(myEndItem))
|
||||||
return;
|
return;
|
||||||
|
@ -53,16 +53,7 @@
|
|||||||
|
|
||||||
#include <QGraphicsLineItem>
|
#include <QGraphicsLineItem>
|
||||||
|
|
||||||
#include "diagramitem.h"
|
class DiagramItem;
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QGraphicsPolygonItem;
|
|
||||||
class QGraphicsLineItem;
|
|
||||||
class QGraphicsScene;
|
|
||||||
class QRectF;
|
|
||||||
class QGraphicsSceneMouseEvent;
|
|
||||||
class QPainterPath;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
class Arrow : public QGraphicsLineItem
|
class Arrow : public QGraphicsLineItem
|
||||||
@ -71,7 +62,7 @@ public:
|
|||||||
enum { Type = UserType + 4 };
|
enum { Type = UserType + 4 };
|
||||||
|
|
||||||
Arrow(DiagramItem *startItem, DiagramItem *endItem,
|
Arrow(DiagramItem *startItem, DiagramItem *endItem,
|
||||||
QGraphicsItem *parent = 0);
|
QGraphicsItem *parent = nullptr);
|
||||||
|
|
||||||
int type() const override { return Type; }
|
int type() const override { return Type; }
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
@ -83,13 +74,14 @@ public:
|
|||||||
void updatePosition();
|
void updatePosition();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
|
QWidget *widget = nullptr) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DiagramItem *myStartItem;
|
DiagramItem *myStartItem;
|
||||||
DiagramItem *myEndItem;
|
DiagramItem *myEndItem;
|
||||||
QColor myColor;
|
|
||||||
QPolygonF arrowHead;
|
QPolygonF arrowHead;
|
||||||
|
QColor myColor = Qt::black;
|
||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
|
@ -58,12 +58,10 @@
|
|||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
|
DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
|
||||||
QGraphicsItem *parent)
|
QGraphicsItem *parent)
|
||||||
: QGraphicsPolygonItem(parent)
|
: QGraphicsPolygonItem(parent), myDiagramType(diagramType)
|
||||||
|
, myContextMenu(contextMenu)
|
||||||
{
|
{
|
||||||
myDiagramType = diagramType;
|
|
||||||
myContextMenu = contextMenu;
|
|
||||||
|
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
switch (myDiagramType) {
|
switch (myDiagramType) {
|
||||||
case StartEnd:
|
case StartEnd:
|
||||||
@ -101,17 +99,17 @@ DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
|
|||||||
//! [1]
|
//! [1]
|
||||||
void DiagramItem::removeArrow(Arrow *arrow)
|
void DiagramItem::removeArrow(Arrow *arrow)
|
||||||
{
|
{
|
||||||
int index = arrows.indexOf(arrow);
|
arrows.removeAll(arrow);
|
||||||
|
|
||||||
if (index != -1)
|
|
||||||
arrows.removeAt(index);
|
|
||||||
}
|
}
|
||||||
//! [1]
|
//! [1]
|
||||||
|
|
||||||
//! [2]
|
//! [2]
|
||||||
void DiagramItem::removeArrows()
|
void DiagramItem::removeArrows()
|
||||||
{
|
{
|
||||||
for (Arrow *arrow : qAsConst(arrows)) {
|
// need a copy here since removeArrow() will
|
||||||
|
// modify the arrows container
|
||||||
|
const auto arrowsCopy = arrows;
|
||||||
|
for (Arrow *arrow : arrowsCopy) {
|
||||||
arrow->startItem()->removeArrow(arrow);
|
arrow->startItem()->removeArrow(arrow);
|
||||||
arrow->endItem()->removeArrow(arrow);
|
arrow->endItem()->removeArrow(arrow);
|
||||||
scene()->removeItem(arrow);
|
scene()->removeItem(arrow);
|
||||||
|
@ -52,19 +52,12 @@
|
|||||||
#define DIAGRAMITEM_H
|
#define DIAGRAMITEM_H
|
||||||
|
|
||||||
#include <QGraphicsPixmapItem>
|
#include <QGraphicsPixmapItem>
|
||||||
#include <QList>
|
#include <QVector>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QPixmap;
|
class QPixmap;
|
||||||
class QGraphicsItem;
|
|
||||||
class QGraphicsScene;
|
|
||||||
class QTextEdit;
|
|
||||||
class QGraphicsSceneMouseEvent;
|
|
||||||
class QMenu;
|
|
||||||
class QGraphicsSceneContextMenuEvent;
|
class QGraphicsSceneContextMenuEvent;
|
||||||
class QPainter;
|
class QMenu;
|
||||||
class QStyleOptionGraphicsItem;
|
|
||||||
class QWidget;
|
|
||||||
class QPolygonF;
|
class QPolygonF;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
@ -77,7 +70,7 @@ public:
|
|||||||
enum { Type = UserType + 15 };
|
enum { Type = UserType + 15 };
|
||||||
enum DiagramType { Step, Conditional, StartEnd, Io };
|
enum DiagramType { Step, Conditional, StartEnd, Io };
|
||||||
|
|
||||||
DiagramItem(DiagramType diagramType, QMenu *contextMenu, QGraphicsItem *parent = 0);
|
DiagramItem(DiagramType diagramType, QMenu *contextMenu, QGraphicsItem *parent = nullptr);
|
||||||
|
|
||||||
void removeArrow(Arrow *arrow);
|
void removeArrow(Arrow *arrow);
|
||||||
void removeArrows();
|
void removeArrows();
|
||||||
@ -85,7 +78,7 @@ public:
|
|||||||
QPolygonF polygon() const { return myPolygon; }
|
QPolygonF polygon() const { return myPolygon; }
|
||||||
void addArrow(Arrow *arrow);
|
void addArrow(Arrow *arrow);
|
||||||
QPixmap image() const;
|
QPixmap image() const;
|
||||||
int type() const override { return Type;}
|
int type() const override { return Type; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||||
@ -95,7 +88,7 @@ private:
|
|||||||
DiagramType myDiagramType;
|
DiagramType myDiagramType;
|
||||||
QPolygonF myPolygon;
|
QPolygonF myPolygon;
|
||||||
QMenu *myContextMenu;
|
QMenu *myContextMenu;
|
||||||
QList<Arrow *> arrows;
|
QVector<Arrow *> arrows;
|
||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@
|
|||||||
#include "diagramscene.h"
|
#include "diagramscene.h"
|
||||||
#include "arrow.h"
|
#include "arrow.h"
|
||||||
|
|
||||||
#include <QTextCursor>
|
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QTextCursor>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
|
DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
|
||||||
@ -61,8 +61,8 @@ DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
|
|||||||
myItemMenu = itemMenu;
|
myItemMenu = itemMenu;
|
||||||
myMode = MoveItem;
|
myMode = MoveItem;
|
||||||
myItemType = DiagramItem::Step;
|
myItemType = DiagramItem::Step;
|
||||||
line = 0;
|
line = nullptr;
|
||||||
textItem = 0;
|
textItem = nullptr;
|
||||||
myItemColor = Qt::white;
|
myItemColor = Qt::white;
|
||||||
myTextColor = Qt::black;
|
myTextColor = Qt::black;
|
||||||
myLineColor = Qt::black;
|
myLineColor = Qt::black;
|
||||||
@ -188,7 +188,7 @@ void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
|||||||
//! [10]
|
//! [10]
|
||||||
void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
{
|
{
|
||||||
if (myMode == InsertLine && line != 0) {
|
if (myMode == InsertLine && line != nullptr) {
|
||||||
QLineF newLine(line->line().p1(), mouseEvent->scenePos());
|
QLineF newLine(line->line().p1(), mouseEvent->scenePos());
|
||||||
line->setLine(newLine);
|
line->setLine(newLine);
|
||||||
} else if (myMode == MoveItem) {
|
} else if (myMode == MoveItem) {
|
||||||
@ -200,7 +200,7 @@ void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
|||||||
//! [11]
|
//! [11]
|
||||||
void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
{
|
{
|
||||||
if (line != 0 && myMode == InsertLine) {
|
if (line != nullptr && myMode == InsertLine) {
|
||||||
QList<QGraphicsItem *> startItems = items(line->line().p1());
|
QList<QGraphicsItem *> startItems = items(line->line().p1());
|
||||||
if (startItems.count() && startItems.first() == line)
|
if (startItems.count() && startItems.first() == line)
|
||||||
startItems.removeFirst();
|
startItems.removeFirst();
|
||||||
@ -228,7 +228,7 @@ void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//! [12] //! [13]
|
//! [12] //! [13]
|
||||||
line = 0;
|
line = nullptr;
|
||||||
QGraphicsScene::mouseReleaseEvent(mouseEvent);
|
QGraphicsScene::mouseReleaseEvent(mouseEvent);
|
||||||
}
|
}
|
||||||
//! [13]
|
//! [13]
|
||||||
|
@ -74,7 +74,7 @@ class DiagramScene : public QGraphicsScene
|
|||||||
public:
|
public:
|
||||||
enum Mode { InsertItem, InsertLine, InsertText, MoveItem };
|
enum Mode { InsertItem, InsertLine, InsertText, MoveItem };
|
||||||
|
|
||||||
explicit DiagramScene(QMenu *itemMenu, QObject *parent = 0);
|
explicit DiagramScene(QMenu *itemMenu, QObject *parent = nullptr);
|
||||||
QFont font() const { return myFont; }
|
QFont font() const { return myFont; }
|
||||||
QColor textColor() const { return myTextColor; }
|
QColor textColor() const { return myTextColor; }
|
||||||
QColor itemColor() const { return myItemColor; }
|
QColor itemColor() const { return myItemColor; }
|
||||||
|
@ -52,12 +52,8 @@
|
|||||||
#define DIAGRAMTEXTITEM_H
|
#define DIAGRAMTEXTITEM_H
|
||||||
|
|
||||||
#include <QGraphicsTextItem>
|
#include <QGraphicsTextItem>
|
||||||
#include <QPen>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QFocusEvent;
|
|
||||||
class QGraphicsItem;
|
|
||||||
class QGraphicsScene;
|
|
||||||
class QGraphicsSceneMouseEvent;
|
class QGraphicsSceneMouseEvent;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
@ -69,7 +65,7 @@ class DiagramTextItem : public QGraphicsTextItem
|
|||||||
public:
|
public:
|
||||||
enum { Type = UserType + 3 };
|
enum { Type = UserType + 3 };
|
||||||
|
|
||||||
DiagramTextItem(QGraphicsItem *parent = 0);
|
DiagramTextItem(QGraphicsItem *parent = nullptr);
|
||||||
|
|
||||||
int type() const override { return Type; }
|
int type() const override { return Type; }
|
||||||
|
|
||||||
|
@ -48,10 +48,18 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
#include "coloritem.h"
|
#include "coloritem.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QBitmap>
|
||||||
|
#include <QCursor>
|
||||||
|
#include <QDrag>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QMimeData>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
ColorItem::ColorItem()
|
ColorItem::ColorItem()
|
||||||
: color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
|
: color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
|
||||||
@ -128,7 +136,7 @@ void ColorItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
QPainter painter(&pixmap);
|
QPainter painter(&pixmap);
|
||||||
painter.translate(15, 15);
|
painter.translate(15, 15);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
paint(&painter, 0, 0);
|
paint(&painter, nullptr, nullptr);
|
||||||
painter.end();
|
painter.end();
|
||||||
|
|
||||||
pixmap.setMask(pixmap.createHeuristicMask());
|
pixmap.setMask(pixmap.createHeuristicMask());
|
||||||
|
@ -48,19 +48,20 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QApplication>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
|
||||||
#include "coloritem.h"
|
#include "coloritem.h"
|
||||||
#include "robot.h"
|
#include "robot.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
|
|
||||||
|
|
||||||
class GraphicsView : public QGraphicsView
|
class GraphicsView : public QGraphicsView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GraphicsView(QGraphicsScene *scene) : QGraphicsView(scene)
|
using QGraphicsView::QGraphicsView;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *) override
|
void resizeEvent(QResizeEvent *) override
|
||||||
@ -96,7 +97,7 @@ int main(int argc, char **argv)
|
|||||||
view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
|
view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
|
||||||
view.setBackgroundBrush(QColor(230, 200, 167));
|
view.setBackgroundBrush(QColor(230, 200, 167));
|
||||||
view.setWindowTitle("Drag and Drop Robot");
|
view.setWindowTitle("Drag and Drop Robot");
|
||||||
view.show();
|
view.show();
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
@ -48,13 +48,17 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
#include "robot.h"
|
#include "robot.h"
|
||||||
|
|
||||||
|
#include <QGraphicsSceneDragDropEvent>
|
||||||
|
#include <QMimeData>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QParallelAnimationGroup>
|
||||||
|
#include <QPropertyAnimation>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
RobotPart::RobotPart(QGraphicsItem *parent)
|
RobotPart::RobotPart(QGraphicsItem *parent)
|
||||||
: QGraphicsObject(parent), color(Qt::lightGray), dragOver(false)
|
: QGraphicsObject(parent), color(Qt::lightGray)
|
||||||
{
|
{
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
}
|
}
|
||||||
@ -157,11 +161,6 @@ void RobotHead::dropEvent(QGraphicsSceneDragDropEvent *event)
|
|||||||
}
|
}
|
||||||
//! [8]
|
//! [8]
|
||||||
|
|
||||||
RobotTorso::RobotTorso(QGraphicsItem *parent)
|
|
||||||
: RobotPart(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QRectF RobotTorso::boundingRect() const
|
QRectF RobotTorso::boundingRect() const
|
||||||
{
|
{
|
||||||
return QRectF(-30, -20, 60, 60);
|
return QRectF(-30, -20, 60, 60);
|
||||||
|
@ -62,15 +62,15 @@ QT_END_NAMESPACE
|
|||||||
class RobotPart : public QGraphicsObject
|
class RobotPart : public QGraphicsObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RobotPart(QGraphicsItem *parent = 0);
|
RobotPart(QGraphicsItem *parent = nullptr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
|
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
|
||||||
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override;
|
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override;
|
||||||
void dropEvent(QGraphicsSceneDragDropEvent *event) override;
|
void dropEvent(QGraphicsSceneDragDropEvent *event) override;
|
||||||
|
|
||||||
QColor color;
|
QColor color = Qt::lightGray;
|
||||||
bool dragOver;
|
bool dragOver = false;
|
||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
@ -78,10 +78,10 @@ protected:
|
|||||||
class RobotHead : public RobotPart
|
class RobotHead : public RobotPart
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RobotHead(QGraphicsItem *parent = 0);
|
RobotHead(QGraphicsItem *parent = nullptr);
|
||||||
|
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
|
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
|
||||||
@ -96,10 +96,10 @@ private:
|
|||||||
class RobotTorso : public RobotPart
|
class RobotTorso : public RobotPart
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RobotTorso(QGraphicsItem *parent = 0);
|
using RobotPart::RobotPart;
|
||||||
|
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
|
||||||
};
|
};
|
||||||
//! [2]
|
//! [2]
|
||||||
|
|
||||||
@ -107,10 +107,10 @@ public:
|
|||||||
class RobotLimb : public RobotPart
|
class RobotLimb : public RobotPart
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RobotLimb(QGraphicsItem *parent = 0);
|
RobotLimb(QGraphicsItem *parent = nullptr);
|
||||||
|
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
|
||||||
};
|
};
|
||||||
//! [3]
|
//! [3]
|
||||||
|
|
||||||
@ -118,10 +118,10 @@ public:
|
|||||||
class Robot : public RobotPart
|
class Robot : public RobotPart
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Robot(QGraphicsItem *parent = 0);
|
Robot(QGraphicsItem *parent = nullptr);
|
||||||
|
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
|
||||||
};
|
};
|
||||||
//! [4]
|
//! [4]
|
||||||
|
|
||||||
|
@ -51,16 +51,14 @@
|
|||||||
#include "edge.h"
|
#include "edge.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
||||||
#include <qmath.h>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QtMath>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
Edge::Edge(Node *sourceNode, Node *destNode)
|
Edge::Edge(Node *sourceNode, Node *destNode)
|
||||||
: arrowSize(10)
|
: source(sourceNode), dest(destNode)
|
||||||
{
|
{
|
||||||
setAcceptedMouseButtons(0);
|
setAcceptedMouseButtons(Qt::NoButton);
|
||||||
source = sourceNode;
|
|
||||||
dest = destNode;
|
|
||||||
source->addEdge(this);
|
source->addEdge(this);
|
||||||
dest->addEdge(this);
|
dest->addEdge(this);
|
||||||
adjust();
|
adjust();
|
||||||
|
@ -78,7 +78,7 @@ private:
|
|||||||
|
|
||||||
QPointF sourcePoint;
|
QPointF sourcePoint;
|
||||||
QPointF destPoint;
|
QPointF destPoint;
|
||||||
qreal arrowSize;
|
qreal arrowSize = 10;
|
||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@
|
|||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
GraphWidget::GraphWidget(QWidget *parent)
|
GraphWidget::GraphWidget(QWidget *parent)
|
||||||
: QGraphicsView(parent), timerId(0)
|
: QGraphicsView(parent)
|
||||||
{
|
{
|
||||||
QGraphicsScene *scene = new QGraphicsScene(this);
|
QGraphicsScene *scene = new QGraphicsScene(this);
|
||||||
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||||
@ -163,7 +163,7 @@ void GraphWidget::timerEvent(QTimerEvent *event)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
|
|
||||||
QList<Node *> nodes;
|
QVector<Node *> nodes;
|
||||||
const QList<QGraphicsItem *> items = scene()->items();
|
const QList<QGraphicsItem *> items = scene()->items();
|
||||||
for (QGraphicsItem *item : items) {
|
for (QGraphicsItem *item : items) {
|
||||||
if (Node *node = qgraphicsitem_cast<Node *>(item))
|
if (Node *node = qgraphicsitem_cast<Node *>(item))
|
||||||
@ -190,7 +190,7 @@ void GraphWidget::timerEvent(QTimerEvent *event)
|
|||||||
//! [5]
|
//! [5]
|
||||||
void GraphWidget::wheelEvent(QWheelEvent *event)
|
void GraphWidget::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
scaleView(pow((double)2, -event->angleDelta().y() / 240.0));
|
scaleView(pow(2., -event->angleDelta().y() / 240.0));
|
||||||
}
|
}
|
||||||
//! [5]
|
//! [5]
|
||||||
#endif
|
#endif
|
||||||
|
@ -61,7 +61,7 @@ class GraphWidget : public QGraphicsView
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GraphWidget(QWidget *parent = 0);
|
GraphWidget(QWidget *parent = nullptr);
|
||||||
|
|
||||||
void itemMoved();
|
void itemMoved();
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ protected:
|
|||||||
void scaleView(qreal scaleFactor);
|
void scaleView(qreal scaleFactor);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int timerId;
|
int timerId = 0;
|
||||||
Node *centerNode;
|
Node *centerNode;
|
||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
@ -75,7 +75,7 @@ void Node::addEdge(Edge *edge)
|
|||||||
edge->adjust();
|
edge->adjust();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Edge *> Node::edges() const
|
QVector<Edge *> Node::edges() const
|
||||||
{
|
{
|
||||||
return edgeList;
|
return edgeList;
|
||||||
}
|
}
|
||||||
|
@ -52,13 +52,10 @@
|
|||||||
#define NODE_H
|
#define NODE_H
|
||||||
|
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
#include <QList>
|
#include <QVector>
|
||||||
|
|
||||||
class Edge;
|
class Edge;
|
||||||
class GraphWidget;
|
class GraphWidget;
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QGraphicsSceneMouseEvent;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
class Node : public QGraphicsItem
|
class Node : public QGraphicsItem
|
||||||
@ -67,7 +64,7 @@ public:
|
|||||||
Node(GraphWidget *graphWidget);
|
Node(GraphWidget *graphWidget);
|
||||||
|
|
||||||
void addEdge(Edge *edge);
|
void addEdge(Edge *edge);
|
||||||
QList<Edge *> edges() const;
|
QVector<Edge *> edges() const;
|
||||||
|
|
||||||
enum { Type = UserType + 1 };
|
enum { Type = UserType + 1 };
|
||||||
int type() const override { return Type; }
|
int type() const override { return Type; }
|
||||||
@ -86,7 +83,7 @@ protected:
|
|||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<Edge *> edgeList;
|
QVector<Edge *> edgeList;
|
||||||
QPointF newPos;
|
QPointF newPos;
|
||||||
GraphWidget *graph;
|
GraphWidget *graph;
|
||||||
};
|
};
|
||||||
|
@ -50,14 +50,13 @@
|
|||||||
|
|
||||||
#include "customproxy.h"
|
#include "customproxy.h"
|
||||||
|
|
||||||
#include <QStyleOptionGraphicsItem>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QStyleOptionGraphicsItem>
|
||||||
|
|
||||||
CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags)
|
CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags)
|
||||||
: QGraphicsProxyWidget(parent, wFlags), popupShown(false), currentPopup(nullptr)
|
: QGraphicsProxyWidget(parent, wFlags), timeLine(new QTimeLine(250, this))
|
||||||
{
|
{
|
||||||
timeLine = new QTimeLine(250, this);
|
|
||||||
connect(timeLine, &QTimeLine::valueChanged,
|
connect(timeLine, &QTimeLine::valueChanged,
|
||||||
this, &CustomProxy::updateStep);
|
this, &CustomProxy::updateStep);
|
||||||
connect(timeLine, &QTimeLine::stateChanged,
|
connect(timeLine, &QTimeLine::stateChanged,
|
||||||
@ -99,7 +98,7 @@ void CustomProxy::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|||||||
{
|
{
|
||||||
QGraphicsProxyWidget::hoverEnterEvent(event);
|
QGraphicsProxyWidget::hoverEnterEvent(event);
|
||||||
scene()->setActiveWindow(this);
|
scene()->setActiveWindow(this);
|
||||||
if (timeLine->currentValue() != 1)
|
if (qFuzzyCompare(timeLine->currentValue(), 1))
|
||||||
zoomIn();
|
zoomIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +106,7 @@ void CustomProxy::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|||||||
{
|
{
|
||||||
QGraphicsProxyWidget::hoverLeaveEvent(event);
|
QGraphicsProxyWidget::hoverLeaveEvent(event);
|
||||||
if (!popupShown
|
if (!popupShown
|
||||||
&& (timeLine->direction() != QTimeLine::Backward || timeLine->currentValue() != 0)) {
|
&& (timeLine->direction() != QTimeLine::Backward || qFuzzyIsNull(timeLine->currentValue()))) {
|
||||||
zoomOut();
|
zoomOut();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ class CustomProxy : public QGraphicsProxyWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
|
explicit CustomProxy(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = nullptr);
|
||||||
|
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
@ -79,8 +79,8 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QTimeLine *timeLine;
|
QTimeLine *timeLine;
|
||||||
bool popupShown;
|
QGraphicsItem *currentPopup = nullptr;
|
||||||
QGraphicsItem *currentPopup;
|
bool popupShown = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CUSTOMPROXY_H
|
#endif // CUSTOMPROXY_H
|
||||||
|
@ -64,7 +64,7 @@ class EmbeddedDialog : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EmbeddedDialog(QWidget *parent = 0);
|
EmbeddedDialog(QWidget *parent = nullptr);
|
||||||
~EmbeddedDialog();
|
~EmbeddedDialog();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -50,14 +50,10 @@
|
|||||||
|
|
||||||
#include "flowlayout.h"
|
#include "flowlayout.h"
|
||||||
|
|
||||||
#include <qmath.h>
|
#include <QtMath>
|
||||||
|
|
||||||
#include <QWidget>
|
FlowLayout::FlowLayout(QGraphicsLayoutItem *parent) : QGraphicsLayout(parent)
|
||||||
|
|
||||||
FlowLayout::FlowLayout()
|
|
||||||
{
|
{
|
||||||
m_spacing[0] = 6;
|
|
||||||
m_spacing[1] = 6;
|
|
||||||
QSizePolicy sp = sizePolicy();
|
QSizePolicy sp = sizePolicy();
|
||||||
sp.setHeightForWidth(true);
|
sp.setHeightForWidth(true);
|
||||||
setSizePolicy(sp);
|
setSizePolicy(sp);
|
||||||
@ -66,7 +62,7 @@ FlowLayout::FlowLayout()
|
|||||||
void FlowLayout::insertItem(int index, QGraphicsLayoutItem *item)
|
void FlowLayout::insertItem(int index, QGraphicsLayoutItem *item)
|
||||||
{
|
{
|
||||||
item->setParentLayoutItem(this);
|
item->setParentLayoutItem(this);
|
||||||
if (uint(index) > uint(m_items.count()))
|
if (index > m_items.count())
|
||||||
index = m_items.count();
|
index = m_items.count();
|
||||||
m_items.insert(index, item);
|
m_items.insert(index, item);
|
||||||
invalidate();
|
invalidate();
|
||||||
@ -117,15 +113,14 @@ qreal FlowLayout::doLayout(const QRectF &geom, bool applyNewGeometry) const
|
|||||||
qreal y = 0;
|
qreal y = 0;
|
||||||
qreal maxRowHeight = 0;
|
qreal maxRowHeight = 0;
|
||||||
QSizeF pref;
|
QSizeF pref;
|
||||||
for (int i = 0; i < m_items.count(); ++i) {
|
for (QGraphicsLayoutItem *item : m_items) {
|
||||||
QGraphicsLayoutItem *item = m_items.at(i);
|
|
||||||
pref = item->effectiveSizeHint(Qt::PreferredSize);
|
pref = item->effectiveSizeHint(Qt::PreferredSize);
|
||||||
maxRowHeight = qMax(maxRowHeight, pref.height());
|
maxRowHeight = qMax(maxRowHeight, pref.height());
|
||||||
|
|
||||||
qreal next_x;
|
qreal next_x;
|
||||||
next_x = x + pref.width();
|
next_x = x + pref.width();
|
||||||
if (next_x > maxw) {
|
if (next_x > maxw) {
|
||||||
if (x == 0) {
|
if (qFuzzyIsNull(x)) {
|
||||||
pref.setWidth(maxw);
|
pref.setWidth(maxw);
|
||||||
} else {
|
} else {
|
||||||
x = 0;
|
x = 0;
|
||||||
@ -156,7 +151,7 @@ QSizeF FlowLayout::minSize(const QSizeF &constraint) const
|
|||||||
} else {
|
} else {
|
||||||
for (const QGraphicsLayoutItem *item : qAsConst(m_items))
|
for (const QGraphicsLayoutItem *item : qAsConst(m_items))
|
||||||
size = size.expandedTo(item->effectiveSizeHint(Qt::MinimumSize));
|
size = size.expandedTo(item->effectiveSizeHint(Qt::MinimumSize));
|
||||||
size += QSize(left + right, top + bottom);
|
size += QSizeF(left + right, top + bottom);
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@ -164,7 +159,7 @@ QSizeF FlowLayout::minSize(const QSizeF &constraint) const
|
|||||||
QSizeF FlowLayout::prefSize() const
|
QSizeF FlowLayout::prefSize() const
|
||||||
{
|
{
|
||||||
qreal left, right;
|
qreal left, right;
|
||||||
getContentsMargins(&left, 0, &right, 0);
|
getContentsMargins(&left, nullptr, &right, nullptr);
|
||||||
|
|
||||||
qreal maxh = 0;
|
qreal maxh = 0;
|
||||||
qreal totalWidth = 0;
|
qreal totalWidth = 0;
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
class FlowLayout : public QGraphicsLayout
|
class FlowLayout : public QGraphicsLayout
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FlowLayout();
|
FlowLayout(QGraphicsLayoutItem *parent = nullptr);
|
||||||
inline void addItem(QGraphicsLayoutItem *item);
|
inline void addItem(QGraphicsLayoutItem *item);
|
||||||
void insertItem(int index, QGraphicsLayoutItem *item);
|
void insertItem(int index, QGraphicsLayoutItem *item);
|
||||||
void setSpacing(Qt::Orientations o, qreal spacing);
|
void setSpacing(Qt::Orientations o, qreal spacing);
|
||||||
@ -75,8 +75,8 @@ private:
|
|||||||
QSizeF prefSize() const;
|
QSizeF prefSize() const;
|
||||||
QSizeF maxSize() const;
|
QSizeF maxSize() const;
|
||||||
|
|
||||||
QList<QGraphicsLayoutItem*> m_items;
|
QVector<QGraphicsLayoutItem*> m_items;
|
||||||
qreal m_spacing[2];
|
qreal m_spacing[2] = {6, 6};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,12 +59,12 @@ int main(int argc, char *argv[])
|
|||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
QGraphicsScene scene;
|
QGraphicsScene scene;
|
||||||
QGraphicsView *view = new QGraphicsView(&scene);
|
QGraphicsView view(&scene);
|
||||||
Window *w = new Window;
|
Window *w = new Window;
|
||||||
scene.addItem(w);
|
scene.addItem(w);
|
||||||
|
|
||||||
view->resize(400, 300);
|
view.resize(400, 300);
|
||||||
view->show();
|
view.show();
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
@ -48,23 +48,21 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "flowlayout.h"
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
#include "flowlayout.h"
|
||||||
|
|
||||||
#include <QGraphicsProxyWidget>
|
#include <QGraphicsProxyWidget>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
||||||
Window::Window()
|
Window::Window(QGraphicsItem *parent) : QGraphicsWidget(parent, Qt::Window)
|
||||||
: QGraphicsWidget(0, Qt::Window)
|
|
||||||
{
|
{
|
||||||
FlowLayout *lay = new FlowLayout;
|
FlowLayout *lay = new FlowLayout;
|
||||||
QLatin1String wiseWords("I am not bothered by the fact that I am unknown."
|
const QString sentence(QLatin1String("I am not bothered by the fact that I am unknown."
|
||||||
" I am bothered when I do not know others. (Confucius)");
|
" I am bothered when I do not know others. (Confucius)"));
|
||||||
QString sentence(wiseWords);
|
const QVector<QStringRef> words = sentence.splitRef(QLatin1Char(' '), QString::SkipEmptyParts);
|
||||||
QStringList words = sentence.split(QLatin1Char(' '), QString::SkipEmptyParts);
|
for (const QStringRef &word : words) {
|
||||||
for (int i = 0; i < words.count(); ++i) {
|
|
||||||
QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
|
QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
|
||||||
QLabel *label = new QLabel(words.at(i));
|
QLabel *label = new QLabel(word.toString());
|
||||||
label->setFrameStyle(QFrame::Box | QFrame::Plain);
|
label->setFrameStyle(QFrame::Box | QFrame::Plain);
|
||||||
proxy->setWidget(label);
|
proxy->setWidget(label);
|
||||||
lay->addItem(proxy);
|
lay->addItem(proxy);
|
||||||
|
@ -53,7 +53,6 @@
|
|||||||
class Window : public QGraphicsWidget
|
class Window : public QGraphicsWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Window();
|
Window(QGraphicsItem *parent = nullptr);
|
||||||
};
|
};
|
||||||
|
@ -75,8 +75,8 @@ FlippablePad::FlippablePad(const QSize &size, QGraphicsItem *parent)
|
|||||||
//! [2]
|
//! [2]
|
||||||
//! [3]
|
//! [3]
|
||||||
int numIcons = size.width() * size.height();
|
int numIcons = size.width() * size.height();
|
||||||
QList<QPixmap> pixmaps;
|
QVector<QPixmap> pixmaps;
|
||||||
QDirIterator it(":/images", QStringList() << "*.png");
|
QDirIterator it(":/images", {"*.png"});
|
||||||
while (it.hasNext() && pixmaps.size() < numIcons)
|
while (it.hasNext() && pixmaps.size() < numIcons)
|
||||||
pixmaps << it.next();
|
pixmaps << it.next();
|
||||||
//! [3]
|
//! [3]
|
||||||
|
@ -53,15 +53,13 @@
|
|||||||
|
|
||||||
#include "roundrectitem.h"
|
#include "roundrectitem.h"
|
||||||
|
|
||||||
#include <QGraphicsObject>
|
|
||||||
#include <QLinearGradient>
|
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
class FlippablePad : public RoundRectItem
|
class FlippablePad : public RoundRectItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit FlippablePad(const QSize &size, QGraphicsItem *parent = 0);
|
explicit FlippablePad(const QSize &size, QGraphicsItem *parent = nullptr);
|
||||||
|
|
||||||
RoundRectItem *iconAt(int column, int row) const;
|
RoundRectItem *iconAt(int column, int row) const;
|
||||||
|
|
||||||
|
@ -52,10 +52,18 @@
|
|||||||
#include "padnavigator.h"
|
#include "padnavigator.h"
|
||||||
#include "splashitem.h"
|
#include "splashitem.h"
|
||||||
|
|
||||||
|
#include <QEventTransition>
|
||||||
|
#include <QGraphicsProxyWidget>
|
||||||
|
#include <QGraphicsRotation>
|
||||||
|
#include <QHistoryState>
|
||||||
|
#include <QKeyEventTransition>
|
||||||
|
#include <QParallelAnimationGroup>
|
||||||
|
#include <QPropertyAnimation>
|
||||||
|
#include <QSequentialAnimationGroup>
|
||||||
|
#include <QStateMachine>
|
||||||
|
|
||||||
#ifndef QT_NO_OPENGL
|
#ifndef QT_NO_OPENGL
|
||||||
#include <QtOpenGL>
|
#include <QOpenGLWidget>
|
||||||
#else
|
|
||||||
#include <QtWidgets>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
|
@ -54,17 +54,12 @@
|
|||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include "ui_form.h"
|
#include "ui_form.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QState;
|
|
||||||
class QStateMachine;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
class PadNavigator : public QGraphicsView
|
class PadNavigator : public QGraphicsView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit PadNavigator(const QSize &size, QWidget *parent = 0);
|
explicit PadNavigator(const QSize &size, QWidget *parent = nullptr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
|
|
||||||
#include "roundrectitem.h"
|
#include "roundrectitem.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QGuiApplication>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
|
|||||||
//! [3]
|
//! [3]
|
||||||
//! [4]
|
//! [4]
|
||||||
if (fillRect)
|
if (fillRect)
|
||||||
painter->setBrush(QApplication::palette().brush(QPalette::Window));
|
painter->setBrush(QGuiApplication::palette().brush(QPalette::Window));
|
||||||
else
|
else
|
||||||
painter->setBrush(gradient);
|
painter->setBrush(gradient);
|
||||||
painter->setPen(QPen(Qt::black, 1));
|
painter->setPen(QPen(Qt::black, 1));
|
||||||
|
@ -61,13 +61,13 @@ class RoundRectItem : public QGraphicsObject
|
|||||||
Q_PROPERTY(bool fill READ fill WRITE setFill)
|
Q_PROPERTY(bool fill READ fill WRITE setFill)
|
||||||
public:
|
public:
|
||||||
RoundRectItem(const QRectF &bounds, const QColor &color,
|
RoundRectItem(const QRectF &bounds, const QColor &color,
|
||||||
QGraphicsItem *parent = 0);
|
QGraphicsItem *parent = nullptr);
|
||||||
|
|
||||||
QPixmap pixmap() const;
|
QPixmap pixmap() const;
|
||||||
void setPixmap(const QPixmap &pixmap);
|
void setPixmap(const QPixmap &pixmap);
|
||||||
|
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
|
||||||
|
|
||||||
bool fill() const;
|
bool fill() const;
|
||||||
void setFill(bool fill);
|
void setFill(bool fill);
|
||||||
|
@ -58,10 +58,10 @@ class SplashItem : public QGraphicsObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SplashItem(QGraphicsItem *parent = 0);
|
explicit SplashItem(QGraphicsItem *parent = nullptr);
|
||||||
|
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString text;
|
QString text;
|
||||||
|
@ -54,7 +54,7 @@ class Widget : public QGraphicsWidget
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Widget(const QColor &color, const QColor &textColor, const QString &caption,
|
Widget(const QColor &color, const QColor &textColor, const QString &caption,
|
||||||
QGraphicsItem *parent = 0)
|
QGraphicsItem *parent = nullptr)
|
||||||
: QGraphicsWidget(parent)
|
: QGraphicsWidget(parent)
|
||||||
, caption(caption)
|
, caption(caption)
|
||||||
, color(color)
|
, color(color)
|
||||||
@ -62,7 +62,7 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * = 0) override
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override
|
||||||
{
|
{
|
||||||
QFont font;
|
QFont font;
|
||||||
font.setPixelSize(0.75 * qMin(boundingRect().width(), boundingRect().height()));
|
font.setPixelSize(0.75 * qMin(boundingRect().width(), boundingRect().height()));
|
||||||
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
QGraphicsScene *scene = new QGraphicsScene();
|
QGraphicsScene scene;
|
||||||
|
|
||||||
Widget *a = new Widget(Qt::blue, Qt::white, "a");
|
Widget *a = new Widget(Qt::blue, Qt::white, "a");
|
||||||
a->setPreferredSize(100, 100);
|
a->setPreferredSize(100, 100);
|
||||||
@ -94,7 +94,7 @@ int main(int argc, char *argv[])
|
|||||||
Widget *c = new Widget(Qt::red, Qt::black, "c");
|
Widget *c = new Widget(Qt::red, Qt::black, "c");
|
||||||
c->setPreferredSize(100, 100);
|
c->setPreferredSize(100, 100);
|
||||||
|
|
||||||
QGraphicsAnchorLayout *layout = new QGraphicsAnchorLayout();
|
QGraphicsAnchorLayout *layout = new QGraphicsAnchorLayout;
|
||||||
/*
|
/*
|
||||||
//! [adding a corner anchor in two steps]
|
//! [adding a corner anchor in two steps]
|
||||||
layout->addAnchor(a, Qt::AnchorTop, layout, Qt::AnchorTop);
|
layout->addAnchor(a, Qt::AnchorTop, layout, Qt::AnchorTop);
|
||||||
@ -128,20 +128,20 @@ int main(int argc, char *argv[])
|
|||||||
// corner of the layout.
|
// corner of the layout.
|
||||||
layout->addCornerAnchors(c, Qt::BottomRightCorner, layout, Qt::BottomRightCorner);
|
layout->addCornerAnchors(c, Qt::BottomRightCorner, layout, Qt::BottomRightCorner);
|
||||||
|
|
||||||
QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
|
auto w = new QGraphicsWidget(nullptr, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
|
||||||
w->setPos(20, 20);
|
w->setPos(20, 20);
|
||||||
w->setMinimumSize(100, 100);
|
w->setMinimumSize(100, 100);
|
||||||
w->setPreferredSize(320, 240);
|
w->setPreferredSize(320, 240);
|
||||||
w->setLayout(layout);
|
w->setLayout(layout);
|
||||||
w->setWindowTitle(QApplication::translate("simpleanchorlayout", "QGraphicsAnchorLayout in use"));
|
w->setWindowTitle(QApplication::translate("simpleanchorlayout", "QGraphicsAnchorLayout in use"));
|
||||||
scene->addItem(w);
|
scene.addItem(w);
|
||||||
|
|
||||||
QGraphicsView *view = new QGraphicsView();
|
QGraphicsView view;
|
||||||
view->setScene(scene);
|
view.setScene(&scene);
|
||||||
view->setWindowTitle(QApplication::translate("simpleanchorlayout", "Simple Anchor Layout"));
|
view.setWindowTitle(QApplication::translate("simpleanchorlayout", "Simple Anchor Layout"));
|
||||||
|
|
||||||
view->resize(360, 320);
|
view.resize(360, 320);
|
||||||
view->show();
|
view.show();
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
@ -50,15 +50,14 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPainter>
|
|
||||||
#include <QPushButton>
|
|
||||||
|
|
||||||
#include <QGraphicsAnchorLayout>
|
#include <QGraphicsAnchorLayout>
|
||||||
#include <QGraphicsProxyWidget>
|
#include <QGraphicsProxyWidget>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsSceneResizeEvent>
|
#include <QGraphicsSceneResizeEvent>
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QGraphicsWidget>
|
#include <QGraphicsWidget>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
|
||||||
class GraphicsView : public QGraphicsView
|
class GraphicsView : public QGraphicsView
|
||||||
@ -79,20 +78,18 @@ public:
|
|||||||
|
|
||||||
class PixmapWidget : public QGraphicsLayoutItem
|
class PixmapWidget : public QGraphicsLayoutItem
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PixmapWidget(const QPixmap &pix)
|
PixmapWidget(const QPixmap &pix)
|
||||||
: QGraphicsLayoutItem()
|
: QGraphicsLayoutItem(), original(new QGraphicsPixmapItem(pix))
|
||||||
|
, r(QRectF(QPointF(0, 0), pix.size()))
|
||||||
{
|
{
|
||||||
original = new QGraphicsPixmapItem(pix);
|
|
||||||
setGraphicsItem(original);
|
setGraphicsItem(original);
|
||||||
original->show();
|
original->show();
|
||||||
r = QRectF(QPointF(0, 0), pix.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~PixmapWidget()
|
~PixmapWidget()
|
||||||
{
|
{
|
||||||
setGraphicsItem(0);
|
setGraphicsItem(nullptr);
|
||||||
delete original;
|
delete original;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +98,7 @@ public:
|
|||||||
original->setZValue(z);
|
original->setZValue(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setGeometry (const QRectF &rect) override
|
void setGeometry(const QRectF &rect) override
|
||||||
{
|
{
|
||||||
original->setTransform(QTransform::fromScale(rect.width() / r.width(),
|
original->setTransform(QTransform::fromScale(rect.width() / r.width(),
|
||||||
rect.height() / r.height()), true);
|
rect.height() / r.height()), true);
|
||||||
@ -150,8 +147,7 @@ public:
|
|||||||
|
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
|
||||||
{
|
{
|
||||||
QPointF reflection = QPointF();
|
const QPointF reflection(0, scaled.height() + 2);
|
||||||
reflection.setY(scaled.height() + 2);
|
|
||||||
|
|
||||||
painter->drawPixmap(QPointF(), scaled);
|
painter->drawPixmap(QPointF(), scaled);
|
||||||
|
|
||||||
@ -239,7 +235,7 @@ int main(int argc, char *argv[])
|
|||||||
layout->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
|
|
||||||
// setup the main widget
|
// setup the main widget
|
||||||
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
|
QGraphicsWidget *widget = new QGraphicsWidget(nullptr, Qt::Window);
|
||||||
QPalette p;
|
QPalette p;
|
||||||
p.setColor(QPalette::Window, Qt::black);
|
p.setColor(QPalette::Window, Qt::black);
|
||||||
widget->setPalette(p);
|
widget->setPalette(p);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user