Merge remote-tracking branch 'origin/5.15' into dev

Change-Id: Ic1fd51143f903b7e9086fc19ca960dfd9654ee00
This commit is contained in:
Friedemann Kleint 2019-09-17 08:32:43 +02:00
commit d49d076431
291 changed files with 6538 additions and 4869 deletions

View File

@ -222,6 +222,21 @@
{ "type": "pkgConfig", "args": "libudev" },
"-ludev"
]
},
"libdl": {
"label": "dlopen()",
"test": {
"main": [
"dlclose(dlopen(0, 0));",
"dlsym(RTLD_DEFAULT, 0);",
"dlerror();"
]
},
"headers": "dlfcn.h",
"sources": [
"",
"-ldl"
]
}
},
@ -1340,6 +1355,17 @@
"autoDetect": false,
"condition": "!features.shared",
"output": [ "publicConfig", "publicQtConfig" ]
},
"dlopen": {
"label": "dlopen()",
"condition": "config.unix && libs.libdl",
"output": [ "privateFeature" ]
},
"relocatable": {
"label": "Relocatable",
"autoDetect": "features.shared",
"condition": "features.dlopen || config.win32 || !features.shared",
"output": [ "privateFeature" ]
}
},
@ -1466,6 +1492,7 @@ Configure with '-qreal float' to create a build that is binary-compatible with 5
"args": "enable_gdb_index",
"condition": "config.gcc && !config.clang && (features.debug || features.force_debug_info || features.debug_and_release)"
},
"relocatable",
"precompile_header",
"ltcg",
{

View File

@ -763,6 +763,11 @@ defineTest(qtConfOutput_preparePaths) {
have_hostprefix = true
}
equals(config.input.prefix, $$config.input.extprefix): \
qmake_crossbuild = false
else: \
qmake_crossbuild = true
PREFIX_COMPLAINTS =
PREFIX_REMINDER = false
win32: \
@ -802,6 +807,18 @@ defineTest(qtConfOutput_preparePaths) {
processQtPath(host, hostdatadir, $$config.rel_input.archdatadir)
}
win32:$$qtConfEvaluate("features.shared") {
# Windows DLLs are in the bin dir.
libloc_absolute_path = $$absolute_path($$config.rel_input.bindir, $$config.input.prefix)
} else {
libloc_absolute_path = $$absolute_path($$config.rel_input.libdir, $$config.input.prefix)
}
config.input.liblocation_to_prefix = $$relative_path($$config.input.prefix, $$libloc_absolute_path)
hostbindir_absolute_path = $$absolute_path($$config.rel_input.hostbindir, $$config.input.hostprefix)
config.input.hostbindir_to_hostprefix = $$relative_path($$config.input.hostprefix, $$hostbindir_absolute_path)
config.input.hostbindir_to_extprefix = $$relative_path($$config.input.extprefix, $$hostbindir_absolute_path)
!isEmpty(PREFIX_COMPLAINTS) {
PREFIX_COMPLAINTS = "$$join(PREFIX_COMPLAINTS, "$$escape_expand(\\n)Note: ")"
$$PREFIX_REMINDER: \
@ -864,9 +881,13 @@ defineTest(qtConfOutput_preparePaths) {
";" \
"" \
"$${LITERAL_HASH}define QT_CONFIGURE_SETTINGS_PATH \"$$config.rel_input.sysconfdir\"" \
"$${LITERAL_HASH}define QT_CONFIGURE_LIBLOCATION_TO_PREFIX_PATH \"$$config.input.liblocation_to_prefix\"" \
"$${LITERAL_HASH}define QT_CONFIGURE_HOSTBINDIR_TO_EXTPREFIX_PATH \"$$config.input.hostbindir_to_extprefix\"" \
"$${LITERAL_HASH}define QT_CONFIGURE_HOSTBINDIR_TO_HOSTPREFIX_PATH \"$$config.input.hostbindir_to_hostprefix\"" \
"" \
"$${LITERAL_HASH}ifdef QT_BUILD_QMAKE" \
"$${LITERAL_HASH} define QT_CONFIGURE_SYSROOTIFY_PREFIX $$qmake_sysrootify" \
"$${LITERAL_HASH} define QT_CONFIGURE_CROSSBUILD $$qmake_crossbuild" \
"$${LITERAL_HASH}endif" \
"" \
"$${LITERAL_HASH}define QT_CONFIGURE_PREFIX_PATH qt_configure_prefix_path_str + 12" \

109
dist/changes-5.12.5 vendored Normal file
View File

@ -0,0 +1,109 @@
Qt 5.12.5 is a bug-fix release. It maintains both forward and backward
compatibility (source and binary) with Qt 5.12.0 through 5.12.4.
For more details, refer to the online documentation included in this
distribution. The documentation is also available online:
https://doc.qt.io/qt-5/index.html
The Qt version 5.12 series is binary compatible with the 5.11.x series.
Applications compiled for 5.11 will continue to run with 5.12.
Some of the changes listed in this file include issue tracking numbers
corresponding to tasks in the Qt Bug Tracker:
https://bugreports.qt.io/
Each of these identifiers can be entered in the bug tracker to obtain more
information about a particular change.
****************************************************************************
* QtCore *
****************************************************************************
- QBitArray:
* Fixed two bugs that caused QBitArrays created using fromBits() not to
compare equal to the equivalent QBitArray created using other methods
if the size was zero or not a multiple of 4. If the size modulus 8 was
5, 6, or 7, the data was actually incorrect.
- QCborStreamReader:
* Fixed a bug that caused the QIODevice that the data was being read
from not to show the entire CBOR message as consumed. This allows the
user to consume data that may follow the CBOR payload.
- QCryptographicHash:
* Fixed a bug that caused the SHA-3 and Keccak algorithms to crash if
passed 256 MB of data or more.
- QObject:
* Fixed a resource leak caused by a race condition if multiple QObjects
were created at the same time, for the first time in an application,
from multiple threads (implies threads not started with QThread).
- QStorageInfo:
* Fixed a bug that caused QStorageInfo to be unable to report all
filesystems if the options to mounted filesystems were too long (over
900 characters, roughly), such as those found in Docker overlay
mounts.
- QTimeZone:
* The IANA timezone database backend now properly follows symlinks even
when they point to variable locations like /run or /var (useful when
/etc is mounted read-only).
****************************************************************************
* QtGui *
****************************************************************************
- QImage:
* Improve loading time when loading png files that have the same size as
the target.
- QPixmapCache:
* [QTBUG-76694][QTBUG-72523] Ignore unsafe access from non-main threads
- Text:
* [QTBUG-76219] Fixed a bug which could cause the font cache to grow
larger than it was supposed to.
* [QTBUG-55096][QTBUG-74761] Fixed bug where regular text rendered with
a color font would always display in black.
* [QTBUG-69546] Fixed a crash bug in
QTextDocument::clearUndoRedoStacks(QTextDocument::UndoStack).
****************************************************************************
* QtNetwork *
****************************************************************************
- QHostInfo:
* Functors used in the lookupHost overloads are now called correctly in
the thread of the context object. When used without context object,
the thread that initiates the lookup will run the functor, and is
required to run an event loop.
- Windows:
* Correctly emit errors when trying to reach unreachable hosts or
services
****************************************************************************
* QtWidgets *
****************************************************************************
- QGraphicsView:
* Ignore disabled items when setting the mouse cursor.
- QSplashScreen:
* On macOS, lower the splash screen when a modal dialog is shown to make
sure the user sees the dialog.
- QSystemTrayIcon:
* On macOS, show the icon passed into showMessage in the notification
popup
****************************************************************************
* Android *
****************************************************************************
- [QTBUG-76293] Fix NDK r20 linking.
- [QTBUG-76036] Fixed an issue where menus would not work on 64 bit
builds.

141
dist/changes-5.13.1 vendored Normal file
View File

@ -0,0 +1,141 @@
Qt 5.13.1 is a bug-fix release. It maintains both forward and backward
compatibility (source and binary) with Qt 5.13.0.
For more details, refer to the online documentation included in this
distribution. The documentation is also available online:
https://doc.qt.io/qt-5/index.html
The Qt version 5.13 series is binary compatible with the 5.12.x series.
Applications compiled for 5.12 will continue to run with 5.13.
Some of the changes listed in this file include issue tracking numbers
corresponding to tasks in the Qt Bug Tracker:
https://bugreports.qt.io/
Each of these identifiers can be entered in the bug tracker to obtain more
information about a particular change.
****************************************************************************
* Important Behavior Changes *
****************************************************************************
- [QTBUG-76521] RCC's default compression algorithm was changed back to
Zlib, as it was in all previous releases until 5.13.0. The default will
remain Zlib for all Qt 5.x releases but will change in Qt 6.0. To
activate Zstd compression for your resources, either pass the
--compress-algo=zstd option to the rcc tool or add the XML attribute
compression-algorithm="zstd" to the <file> tags in the .qrc file.
****************************************************************************
* Android *
****************************************************************************
- [QTBUG-76293] Fix NDK r20 linking.
****************************************************************************
* QtCore *
****************************************************************************
- Global:
* [QTBUG-72073] Added the QT_NO_FLOAT16_OPERATORS macro in order to work
around a Microsoft <= VS2017 compiler bug that is exposed when using
std::bitset along with any Qt header that includes <qfloat16.h>.
- QCborStreamReader:
* Fixed a bug that caused the QIODevice that the data was being read
from not to show the entire CBOR message as consumed. This allows the
user to consume data that may follow the CBOR payload.
- QDeadlineTimer:
* [QTBUG-69750] Fixed integer overflows leading to immediate timeouts.
- QStorageInfo:
* Fixed a bug that caused QStorageInfo to be unable to report all
filesystems if the options to mounted filesystems were too long (over
900 characters, roughly), such as those found in Docker overlay
mounts.
- QTextBoundaryFinder:
* Sentence breaking now no longer breaks between uppercase letters and
comma. This is a deviation from the Unicode specification, but
produces less surprising behavior.
- QTimeZone:
* The IANA timezone database backend now properly follows symlinks even
when they point to variable locations like /run or /var (useful when
/etc is mounted read-only).
- QVector:
* Fixed a regression that caused fill() not to detach, corrupting shared
copies.
****************************************************************************
* QtNetwork *
****************************************************************************
- Windows:
* Correctly emit errors when trying to reach unreachable hosts or
services
- QNetworkAccessManager:
* Fixed QNetworkAccessManager::sendCustomRequest for Qt For WebAssembly.
****************************************************************************
* QtGui *
****************************************************************************
- [QTBUG-73231] QWindow::mapToGlobal()/mapFromGlobal() now handle windows
spanning screens correctly.
- QImage:
* Improve loading time when loading png files that have the same size as
the target.
- QPixmapCache:
* [QTBUG-76694][QTBUG-72523] Ignore unsafe access from non-main threads
- Text:
* [QTBUG-76219] Fixed a bug which could cause the font cache to grow
larger than it was supposed to.
* [QTBUG-55096][QTBUG-74761] Fixed bug where regular text rendered with
a color font would always display in black.
****************************************************************************
* QtWidgets *
****************************************************************************
- QSystemTrayIcon:
* On macOS, show the icon passed into showMessage in the notification
popup
- QDateTimeEdit:
* Use the information provided by the locale to determine the AM/PM
strings, unless they are already translated.
- QGraphicsView:
* Ignore disabled items when setting the mouse cursor.
- QMenu:
* Shortcuts are again shown by default in context menus, except on
macOS. They can be forced off by setting
AA_DontShowShortcutsInContextMenus to true.
- QSplashScreen:
* On macOS, lower the splash screen when a modal dialog is shown to make
sure the user sees the dialog.
****************************************************************************
* Third-Party Code *
****************************************************************************
- Updated bundled SQLite to version 3.28.0
- Updated QLocale's data to CLDR v35.1
****************************************************************************
* qmake *
****************************************************************************
- [QTBUG-75653] The CONFIG value c++latest was added to select the latest
C++ standard the currently used toolchain supports.

View File

@ -1,6 +1,8 @@
TEMPLATE = aux
global_docs.files = $$PWD/global
global_docs.files = \
$$PWD/global \
$$PWD/config
global_docs.path = $$[QT_INSTALL_DOCS]
INSTALLS += global_docs
!prefix_build:!equals(OUT_PWD, $$PWD): \

View File

@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
@ -61,6 +61,18 @@
\externalpage http://doc.qt.io/qtcreator/creator-quick-tour.html
\title Qt Creator: User Interface
*/
/*!
\externalpage http://doc.qt.io/qtcreator/creator-modes.html
\title Qt Creator: Selecting Modes
*/
/*!
\externalpage http://doc.qt.io/qtcreator/creator-sidebar-views.html
\title Qt Creator: Browsing Project Contents
*/
/*!
\externalpage http://doc.qt.io/qtcreator/creator-output-panes.html
\title Qt Creator: Viewing Output
*/
/*!
\externalpage http://doc.qt.io/qtcreator/creator-cli.html
\title Qt Creator: Using Command Line Options
@ -125,7 +137,7 @@
\externalpage http://doc.qt.io/qtcreator/quick-signals.html
\title Qt Creator: Connecting Objects to Signals
*/
* /*!
/*!
\externalpage http://doc.qt.io/qtcreator/quick-dynamic-properties.html
\title Qt Creator: Specifying Dynamic Properties
*/
@ -153,6 +165,10 @@
\externalpage http://doc.qt.io/qtcreator/creator-qml-modules-with-plugins.html
\title Qt Creator: Using QML Modules with Plugins
*/
/*!
\externalpage http://doc.qt.io/qtcreator/quick-converting-ui-projects.html
\title Qt Creator: Converting UI Projects to Applications
*/
/*!
\externalpage http://doc.qt.io/qtcreator/creator-visual-editor.html
\title Qt Creator: Developing Qt Quick Applications
@ -553,6 +569,10 @@
\externalpage http://doc.qt.io/qtcreator/creator-cpu-usage-analyzer.html
\title Qt Creator: Analyzing CPU Usage
*/
/*!
\externalpage http://doc.qt.io/qtcreator/creator-cppcheck.html
\title Qt Creator: Analyzing Code with Cppcheck
*/
/*!
\externalpage http://doc.qt.io/qtcreator/creator-autotest.html
\title Qt Creator: Running Autotests
@ -581,3 +601,27 @@
\externalpage http://doc.qt.io/qtcreator/creator-scxml.html
\title Qt Creator: Editing State Charts
*/
/*!
\externalpage http://doc.qt.io/qtcreator/studio-timeline.html
\title Qt Creator: Creating Animations
*/
/*!
\externalpage http://doc.qt.io/qtcreator/creator-language-servers.html
\title Qt Creator: Using Language Servers
*/
/*!
\externalpage http://doc.qt.io/qtcreator/qtcreator-toc.html
\title Qt Creator: All Topics
*/
/*!
\externalpage http://doc.qt.io/qtcreator/creator-live-preview.html
\title Qt Creator: Previewing
*/
/*!
\externalpage http://doc.qt.io/qtcreator/creator-live-preview-desktop.html
\title Qt Creator: Previewing on Desktop
*/
/*!
\externalpage http://doc.qt.io/qtcreator/creator-live-preview-devices.html
\title Qt Creator: Previewing on Devices
*/

View File

@ -75,7 +75,8 @@
\section1 Mouse Class Definition
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

View File

@ -643,7 +643,9 @@
This function is called when the item is removed from the scene
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
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:

View File

@ -88,7 +88,7 @@ int main(int argc, char **argv)
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
l->setSpacing(0);
QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window);
QGraphicsWidget *w = new QGraphicsWidget(nullptr, Qt::Window);
w->setPos(20, 20);
w->setLayout(l);

View File

@ -51,33 +51,26 @@
#include "layoutitem.h"
#include <QGradient>
#include <QGraphicsLinearLayout>
#include <QPainter>
//! [0]
LayoutItem::LayoutItem(QGraphicsItem *parent/* = 0*/)
: QGraphicsLayoutItem(), QGraphicsItem(parent)
LayoutItem::LayoutItem(QGraphicsItem *parent)
: QGraphicsLayoutItem(), QGraphicsItem(parent),
m_pix(QPixmap(QLatin1String(":/images/block.png")))
{
m_pix = new QPixmap(QLatin1String(":/images/block.png"));
setGraphicsItem(this);
}
//! [0]
LayoutItem::~LayoutItem()
{
delete m_pix;
}
//! [1]
void LayoutItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget /*= 0*/)
void LayoutItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(widget);
Q_UNUSED(option);
QRectF frame(QPointF(0,0), geometry().size());
qreal w = m_pix->width();
qreal h = m_pix->height();
QRectF frame(QPointF(0, 0), geometry().size());
const QSize pmSize = m_pix.size();
QGradientStops stops;
//! [1]
@ -94,8 +87,8 @@ void LayoutItem::paint(QPainter *painter,
painter->drawRoundedRect(frame, 10.0, 10.0);
// paint a rect around the pixmap (with gradient)
QPointF pixpos = frame.center() - (QPointF(w, h) / 2);
QRectF innerFrame(pixpos, QSizeF(w, h));
QPointF pixpos = frame.center() - (QPointF(pmSize.width(), pmSize.height()) / 2);
QRectF innerFrame(pixpos, pmSize);
innerFrame.adjust(-4, -4, 4, 4);
gradient.setStart(innerFrame.topLeft());
gradient.setFinalStop(innerFrame.bottomRight());
@ -106,14 +99,14 @@ void LayoutItem::paint(QPainter *painter,
gradient.setStops(stops);
painter->setBrush(QBrush(gradient));
painter->drawRoundedRect(innerFrame, 10.0, 10.0);
painter->drawPixmap(pixpos, *m_pix);
painter->drawPixmap(pixpos, m_pix);
}
//! [2]
//! [3]
QRectF LayoutItem::boundingRect() const
{
return QRectF(QPointF(0,0), geometry().size());
return QRectF(QPointF(0, 0), geometry().size());
}
//! [3]
@ -133,7 +126,7 @@ QSizeF LayoutItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
case Qt::MinimumSize:
case Qt::PreferredSize:
// 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:
return QSizeF(1000,1000);
default:

View File

@ -53,23 +53,24 @@
#include <QGraphicsLayoutItem>
#include <QGraphicsItem>
#include <QPixmap>
//! [0]
class LayoutItem : public QGraphicsLayoutItem, public QGraphicsItem
{
public:
LayoutItem(QGraphicsItem *parent = 0);
~LayoutItem();
LayoutItem(QGraphicsItem *parent = nullptr);
// Inherited from QGraphicsLayoutItem
void setGeometry(const QRectF &geom) override;
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override;
// Inherited from QGraphicsItem
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:
QPixmap *m_pix;
QPixmap m_pix;
};
//! [0]

View File

@ -54,11 +54,11 @@
#include <QGraphicsWidget>
//! [0]
class Window : public QGraphicsWidget {
class Window : public QGraphicsWidget
{
Q_OBJECT
public:
Window(QGraphicsWidget *parent = 0);
Window(QGraphicsWidget *parent = nullptr);
};
//! [0]

View File

@ -49,8 +49,6 @@
****************************************************************************/
#include "glbuffers.h"
#include <QtGui/qmatrix4x4.h>
#include <QtCore/qmath.h>
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() : m_texture(0), m_failed(false)
GLTexture::GLTexture()
{
glGenTextures(1, &m_texture);
}
@ -83,7 +81,7 @@ GLTexture2D::GLTexture2D(int width, int height)
{
glBindTexture(GL_TEXTURE_2D, m_texture);
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_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.
QImage image(fileName);
@ -162,7 +160,7 @@ GLTexture3D::GLTexture3D(int width, int height, int depth)
glBindTexture(GL_TEXTURE_3D, m_texture);
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_T, GL_REPEAT);
@ -206,7 +204,7 @@ GLTextureCube::GLTextureCube(int size)
for (int i = 0; i < 6; ++i)
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_T, GL_CLAMP_TO_EDGE);
@ -252,7 +250,7 @@ GLTextureCube::GLTextureCube(const QStringList &fileNames, int size)
// Clear remaining faces.
while (index < 6) {
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;
}
@ -291,11 +289,8 @@ void GLTextureCube::unbind()
//============================================================================//
GLFrameBufferObject::GLFrameBufferObject(int width, int height)
: m_fbo(0)
, m_depthBuffer(0)
, m_width(width)
: m_width(width)
, m_height(height)
, m_failed(false)
{
GLBUFFERS_ASSERT_OPENGL("GLFrameBufferObject::GLFrameBufferObject",
glGenFramebuffersEXT && glGenRenderbuffersEXT && glBindRenderbufferEXT && glRenderbufferStorageEXT, return)
@ -373,7 +368,7 @@ void GLRenderTargetCube::getViewMatrix(QMatrix4x4& mat, int face)
return;
}
static int perm[6][3] = {
static constexpr int perm[6][3] = {
{2, 1, 0},
{2, 1, 0},
{0, 2, 1},
@ -382,7 +377,7 @@ void GLRenderTargetCube::getViewMatrix(QMatrix4x4& mat, int face)
{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},

View File

@ -58,7 +58,7 @@
#include <QtOpenGL>
#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) \
if (m_failed || !(assertion)) { \
@ -82,8 +82,8 @@ public:
virtual void unbind() = 0;
virtual bool failed() const {return m_failed;}
protected:
GLuint m_texture;
bool m_failed;
GLuint m_texture = 0;
bool m_failed = false;
};
class GLFrameBufferObject
@ -98,17 +98,17 @@ public:
virtual bool failed() const {return m_failed;}
protected:
void setAsRenderTarget(bool state = true);
GLuint m_fbo;
GLuint m_depthBuffer;
GLuint m_fbo = 0;
GLuint m_depthBuffer = 0;
int m_width, m_height;
bool m_failed;
bool m_failed = false;
};
class GLTexture2D : public GLTexture
{
public:
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 bind() override;
void unbind() override;
@ -197,11 +197,7 @@ template<class T>
class GLVertexBuffer
{
public:
GLVertexBuffer(int length, const T *data = 0, int mode = GL_STATIC_DRAW)
: m_length(0)
, m_mode(mode)
, m_buffer(0)
, m_failed(false)
GLVertexBuffer(int length, const T *data = nullptr, int mode = GL_STATIC_DRAW)
{
GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::GLVertexBuffer", glGenBuffers && glBindBuffer && glBufferData, return)
@ -275,12 +271,12 @@ public:
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);
//glBufferData(GL_ARRAY_BUFFER, m_length, NULL, m_mode);
GLvoid* buffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
m_failed = (buffer == 0);
m_failed = (buffer == nullptr);
return reinterpret_cast<T *>(buffer);
}
@ -298,16 +294,17 @@ public:
}
private:
int m_length, m_mode;
GLuint m_buffer;
bool m_failed;
int m_length = 0;
int m_mode = 0;
GLuint m_buffer = 0;
bool m_failed = false;
};
template<class T>
class GLIndexBuffer
{
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_mode(mode)
, m_buffer(0)
@ -345,11 +342,11 @@ public:
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);
GLvoid* buffer = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_READ_WRITE);
m_failed = (buffer == 0);
m_failed = (buffer == nullptr);
return reinterpret_cast<T *>(buffer);
}

View File

@ -51,13 +51,12 @@
#ifndef GLTRIANGLEMESH_H
#define GLTRIANGLEMESH_H
//#include <GL/glew.h>
#include "glbuffers.h"
#include "glextensions.h"
#include <QtWidgets>
#include <QtOpenGL>
#include "glbuffers.h"
template<class TVertex, class TIndex>
class GLTriangleMesh

View File

@ -48,13 +48,11 @@
**
****************************************************************************/
//#include <GL/glew.h>
#include "glextensions.h"
#include "scene.h"
#include <QtWidgets>
#include <QGLWidget>
#include <QtWidgets>
class GraphicsView : public QGraphicsView
{
@ -114,7 +112,7 @@ int main(int argc, char **argv)
QApplication app(argc, argv);
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"
"The program will now exit.");
return -1;
@ -125,7 +123,7 @@ int main(int argc, char **argv)
widget->makeCurrent();
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 program will now exit.");
delete widget;
@ -134,7 +132,7 @@ int main(int argc, char **argv)
// Check if all the necessary functions are resolved.
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"
"The program will now exit.");
delete widget;
@ -142,7 +140,7 @@ int main(int argc, char **argv)
}
// 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"
"work poorly or not at all on your system.");

View File

@ -50,28 +50,23 @@
#include "qtbox.h"
const qreal ROTATE_SPEED_X = 30.0 / 1000.0;
const qreal ROTATE_SPEED_Y = 20.0 / 1000.0;
const qreal ROTATE_SPEED_Z = 40.0 / 1000.0;
const int MAX_ITEM_SIZE = 512;
const int MIN_ITEM_SIZE = 16;
constexpr qreal ROTATE_SPEED_X = 30.0 / 1000.0;
constexpr qreal ROTATE_SPEED_Y = 20.0 / 1000.0;
constexpr qreal ROTATE_SPEED_Z = 40.0 / 1000.0;
constexpr int MAX_ITEM_SIZE = 512;
constexpr int MIN_ITEM_SIZE = 16;
//============================================================================//
// 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::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemIsFocusable, true);
setAcceptHoverEvents(true);
setPos(x, y);
m_startTime = QTime::currentTime();
}
ItemBase::~ItemBase()
{
}
QRectF ItemBase::boundingRect() const
@ -252,10 +247,7 @@ void ItemBase::wheelEvent(QGraphicsSceneWheelEvent *event)
{
prepareGeometryChange();
m_size = int(m_size * qExp(-event->delta() / 600.0));
if (m_size > MAX_ITEM_SIZE)
m_size = MAX_ITEM_SIZE;
else if (m_size < MIN_ITEM_SIZE)
m_size = MIN_ITEM_SIZE;
m_size = qBound(MIN_ITEM_SIZE, m_size, MAX_ITEM_SIZE);
}
int ItemBase::type() const
@ -273,7 +265,7 @@ bool ItemBase::isInResizeArea(const QPointF &pos)
// 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) {
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()
{
if (m_texture)
delete m_texture;
delete m_texture;
}
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_NORMALIZE);
if(m_texture == 0)
if (m_texture == nullptr)
m_texture = new GLTexture2D(":/res/boxes/qt-logo.jpg", 64, 64);
m_texture->bind();
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)
{
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)
{
@ -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)
{
m_image = QPixmap(":/res/boxes/square.jpg");
}
, m_image(QPixmap(":/res/boxes/square.jpg"))
{}
void SquareItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{

View File

@ -51,18 +51,17 @@
#ifndef QTBOX_H
#define QTBOX_H
#include <QtWidgets>
#include <QtGui/qvector3d.h>
#include "glbuffers.h"
#include <QtWidgets>
#include <QVector3D>
class ItemBase : public QGraphicsItem
{
public:
enum { Type = UserType + 1 };
ItemBase(int size, int x, int y);
virtual ~ItemBase();
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
protected:
@ -84,7 +83,7 @@ protected:
int m_size;
QTime m_startTime;
bool m_isResizing;
bool m_isResizing = false;
};
class QtBox : public ItemBase
@ -99,7 +98,7 @@ private:
QVector3D m_vertices[8];
QVector3D m_texCoords[4];
QVector3D m_normals[6];
GLTexture *m_texture;
GLTexture *m_texture = nullptr;
};
class CircleItem : public ItemBase

View File

@ -51,16 +51,12 @@
#ifndef 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 "glextensions.h"
#include "gltrianglemesh.h"
#include <QVector2D>
#include <QVector3D>
struct P3T2N3Vertex
{

View File

@ -48,45 +48,15 @@
**
****************************************************************************/
#include <QDebug>
#include "scene.h"
#include <QtCore/QRandomGenerator>
#include <QtGui/qmatrix4x4.h>
#include <QtGui/qvector3d.h>
#include <QMatrix4x4>
#include <QRandomGenerator>
#include <QVector3D>
#include <qmath.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 //
//============================================================================//
@ -126,7 +96,7 @@ void ColorEdit::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
QColor color(m_color);
QColorDialog dialog(color, 0);
QColorDialog dialog(color, nullptr);
dialog.setOption(QColorDialog::ShowAlphaChannel, true);
dialog.move(280, 120);
if (dialog.exec() == QDialog::Rejected)
@ -179,17 +149,6 @@ void FloatEdit::editDone()
//============================================================================//
// 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)
{
if (index < 0 || index >= 2)
@ -201,8 +160,7 @@ void TwoSidedGraphicsWidget::setWidget(int index, QWidget *widget)
GraphicsWidget *proxy = new GraphicsWidget;
proxy->setWidget(widget);
if (m_proxyWidgets[index])
delete m_proxyWidgets[index];
delete m_proxyWidgets[index];
m_proxyWidgets[index] = proxy;
proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache);
@ -219,7 +177,7 @@ QWidget *TwoSidedGraphicsWidget::widget(int index)
if (index < 0 || index >= 2)
{
qWarning("TwoSidedGraphicsWidget::widget: Index out of bounds, index == %d", index);
return 0;
return nullptr;
}
return m_proxyWidgets[index]->widget();
}
@ -289,7 +247,7 @@ void GraphicsWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
//============================================================================//
RenderOptionsDialog::RenderOptionsDialog()
: QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
: QDialog(nullptr, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
{
setWindowOpacity(0.75);
setWindowTitle(tr("Options (double click to flip)"));
@ -423,7 +381,7 @@ void RenderOptionsDialog::mouseDoubleClickEvent(QMouseEvent *event)
//============================================================================//
ItemDialog::ItemDialog()
: QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
: QDialog(nullptr, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
{
setWindowTitle(tr("Items (double click to flip)"));
setWindowOpacity(0.75);
@ -487,10 +445,10 @@ Scene::Scene(int width, int height, int maxTextureSize)
, m_currentTexture(0)
, m_dynamicCubemap(false)
, m_updateAllCubemaps(true)
, m_box(0)
, m_vertexShader(0)
, m_environmentShader(0)
, m_environmentProgram(0)
, m_box(nullptr)
, m_vertexShader(nullptr)
, m_environmentShader(nullptr)
, m_environmentProgram(nullptr)
{
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
m_noise = new GLTexture3D(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE);
QRgb *data = new QRgb[NOISE_SIZE * NOISE_SIZE * NOISE_SIZE];
memset(data, 0, NOISE_SIZE * NOISE_SIZE * NOISE_SIZE * sizeof(QRgb));
QRgb *p = data;
QVector<QRgb> data(NOISE_SIZE * NOISE_SIZE * NOISE_SIZE, QRgb(0));
QRgb *p = data.data();
float pos[3];
for (int k = 0; k < NOISE_SIZE; ++k) {
pos[2] = k * (0x20 / (float)NOISE_SIZE);
@ -581,8 +538,7 @@ void Scene::initGL()
}
}
}
m_noise->load(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE, data);
delete[] data;
m_noise->load(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE, data.data());
m_mainCubemap = new GLRenderTargetCube(512);
@ -634,7 +590,7 @@ void Scene::initGL()
m_renderOptions->addShader(file.baseName());
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();
}

View File

@ -51,17 +51,12 @@
#ifndef 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 "glextensions.h"
#include "gltrianglemesh.h"
#include "qtbox.h"
#include "roundedbox.h"
#include "trackball.h"
QT_BEGIN_NAMESPACE
class QMatrix4x4;
@ -116,7 +111,7 @@ private:
class GraphicsWidget : public QGraphicsProxyWidget
{
public:
GraphicsWidget() : QGraphicsProxyWidget(0, Qt::Window) {}
GraphicsWidget() : QGraphicsProxyWidget(nullptr, Qt::Window) {}
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
void resizeEvent(QGraphicsSceneResizeEvent *event) override;
@ -127,7 +122,7 @@ class TwoSidedGraphicsWidget : public QObject
{
Q_OBJECT
public:
TwoSidedGraphicsWidget(QGraphicsScene *scene);
using QObject::QObject;
void setWidget(int index, QWidget *widget);
QWidget *widget(int index);
public slots:
@ -135,10 +130,10 @@ public slots:
protected slots:
void animateFlip();
private:
GraphicsWidget *m_proxyWidgets[2];
int m_current;
int m_angle; // angle in degrees
int m_delta;
GraphicsWidget *m_proxyWidgets[2] = {nullptr, nullptr};
int m_current = 0;
int m_angle = 0; // angle in degrees
int m_delta = 0;
};
class RenderOptionsDialog : public QDialog

View File

@ -50,34 +50,21 @@
#include "trackball.h"
#include "scene.h"
#include <qmath.h>
#include <cmath>
//============================================================================//
// TrackBall //
//============================================================================//
TrackBall::TrackBall(TrackMode mode)
: m_angularVelocity(0)
, m_paused(false)
, m_pressed(false)
, m_mode(mode)
: TrackBall(0, QVector3D(0, 1, 0), mode)
{
m_axis = QVector3D(0, 1, 0);
m_rotation = QQuaternion();
m_lastTime = QTime::currentTime();
}
TrackBall::TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode)
: m_axis(axis)
, m_angularVelocity(angularVelocity)
, m_paused(false)
, m_pressed(false)
, m_mode(mode)
{
m_rotation = QQuaternion();
m_lastTime = QTime::currentTime();
}
{}
void TrackBall::push(const QPointF& p, const QQuaternion &)
{

View File

@ -51,10 +51,9 @@
#ifndef TRACKBALL_H
#define TRACKBALL_H
#include <QtWidgets>
#include <QtGui/qvector3d.h>
#include <QtGui/qquaternion.h>
#include <QQuaternion>
#include <QTime>
#include <QVector3D>
class TrackBall
{
@ -65,24 +64,24 @@ public:
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]
void push(const QPointF& p, const QQuaternion &transformation);
void move(const QPointF& p, const QQuaternion &transformation);
void release(const QPointF& p, const QQuaternion &transformation);
void push(const QPointF &p, const QQuaternion &transformation);
void move(const QPointF &p, const QQuaternion &transformation);
void release(const QPointF &p, const QQuaternion &transformation);
void start(); // starts clock
void stop(); // stops clock
QQuaternion rotation() const;
private:
QQuaternion m_rotation;
QVector3D m_axis;
float m_angularVelocity;
QVector3D m_axis = QVector3D(0, 1, 0);
float m_angularVelocity = 0;
QPointF m_lastPos;
QTime m_lastTime;
bool m_paused;
bool m_pressed;
QTime m_lastTime = QTime::currentTime();
TrackMode m_mode;
bool m_paused = false;
bool m_pressed = false;
};
#endif

View File

@ -50,7 +50,9 @@
#include "chip.h"
#include <QtWidgets>
#include <QGraphicsSceneMouseEvent>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
Chip::Chip(const QColor &color, int x, int y)
{

View File

@ -56,13 +56,11 @@
#include <QSplitter>
MainWindow::MainWindow(QWidget *parent)
: QWidget(parent)
: QWidget(parent), scene(new QGraphicsScene(this))
, h1Splitter(new QSplitter(this)), h2Splitter(new QSplitter(this))
{
populateScene();
h1Splitter = new QSplitter;
h2Splitter = new QSplitter;
QSplitter *vSplitter = new QSplitter;
vSplitter->setOrientation(Qt::Vertical);
vSplitter->addWidget(h1Splitter);
@ -93,8 +91,6 @@ MainWindow::MainWindow(QWidget *parent)
void MainWindow::populateScene()
{
scene = new QGraphicsScene(this);
QImage image(":/qt4logo.png");
// Populate scene

View File

@ -62,7 +62,7 @@ class MainWindow : public QWidget
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
MainWindow(QWidget *parent = nullptr);
private:
void setupMatrix();

View File

@ -62,7 +62,7 @@
#else
#include <QtWidgets>
#endif
#include <qmath.h>
#include <QtMath>
#if QT_CONFIG(wheelevent)
void GraphicsView::wheelEvent(QWheelEvent *e)

View File

@ -81,7 +81,7 @@ class View : public QFrame
{
Q_OBJECT
public:
explicit View(const QString &name, QWidget *parent = 0);
explicit View(const QString &name, QWidget *parent = nullptr);
QGraphicsView *view() const;

View File

@ -48,13 +48,12 @@
**
****************************************************************************/
#include <QtMath>
#include <QtWidgets>
#include <math.h>
#include "mouse.h"
static const int MouseCount = 7;
static constexpr int MouseCount = 7;
//! [0]
int main(int argc, char **argv)

View File

@ -54,10 +54,10 @@
#include <QPainter>
#include <QRandomGenerator>
#include <QStyleOption>
#include <qmath.h>
#include <QtMath>
const qreal Pi = M_PI;
const qreal TwoPi = 2 * M_PI;
constexpr qreal Pi = M_PI;
constexpr qreal TwoPi = 2 * M_PI;
static qreal normalizeAngle(qreal angle)
{
@ -70,8 +70,7 @@ static qreal normalizeAngle(qreal angle)
//! [0]
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));
}

View File

@ -68,9 +68,9 @@ protected:
void advance(int step) override;
private:
qreal angle;
qreal speed;
qreal mouseEyeDirection;
qreal angle = 0;
qreal speed = 0;
qreal mouseEyeDirection = 0;
QColor color;
};
//! [0]

View File

@ -50,19 +50,17 @@
#include "arrow.h"
#include "diagramitem.h"
#include <qmath.h>
#include <QPen>
#include <QPainter>
#include <QPen>
#include <QtMath>
//! [0]
Arrow::Arrow(DiagramItem *startItem, DiagramItem *endItem, QGraphicsItem *parent)
: QGraphicsLineItem(parent)
: QGraphicsLineItem(parent), myStartItem(startItem), myEndItem(endItem)
{
myStartItem = startItem;
myEndItem = endItem;
setFlag(QGraphicsItem::ItemIsSelectable, true);
myColor = Qt::black;
setPen(QPen(myColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
}
//! [0]
@ -98,7 +96,7 @@ void Arrow::updatePosition()
//! [4]
void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
QWidget *)
QWidget *)
{
if (myStartItem->collidesWithItem(myEndItem))
return;

View File

@ -53,16 +53,7 @@
#include <QGraphicsLineItem>
#include "diagramitem.h"
QT_BEGIN_NAMESPACE
class QGraphicsPolygonItem;
class QGraphicsLineItem;
class QGraphicsScene;
class QRectF;
class QGraphicsSceneMouseEvent;
class QPainterPath;
QT_END_NAMESPACE
class DiagramItem;
//! [0]
class Arrow : public QGraphicsLineItem
@ -71,7 +62,7 @@ public:
enum { Type = UserType + 4 };
Arrow(DiagramItem *startItem, DiagramItem *endItem,
QGraphicsItem *parent = 0);
QGraphicsItem *parent = nullptr);
int type() const override { return Type; }
QRectF boundingRect() const override;
@ -83,13 +74,14 @@ public:
void updatePosition();
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget = nullptr) override;
private:
DiagramItem *myStartItem;
DiagramItem *myEndItem;
QColor myColor;
QPolygonF arrowHead;
QColor myColor = Qt::black;
};
//! [0]

View File

@ -58,12 +58,10 @@
//! [0]
DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
QGraphicsItem *parent)
: QGraphicsPolygonItem(parent)
QGraphicsItem *parent)
: QGraphicsPolygonItem(parent), myDiagramType(diagramType)
, myContextMenu(contextMenu)
{
myDiagramType = diagramType;
myContextMenu = contextMenu;
QPainterPath path;
switch (myDiagramType) {
case StartEnd:
@ -101,17 +99,17 @@ DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
//! [1]
void DiagramItem::removeArrow(Arrow *arrow)
{
int index = arrows.indexOf(arrow);
if (index != -1)
arrows.removeAt(index);
arrows.removeAll(arrow);
}
//! [1]
//! [2]
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->endItem()->removeArrow(arrow);
scene()->removeItem(arrow);

View File

@ -52,19 +52,12 @@
#define DIAGRAMITEM_H
#include <QGraphicsPixmapItem>
#include <QList>
#include <QVector>
QT_BEGIN_NAMESPACE
class QPixmap;
class QGraphicsItem;
class QGraphicsScene;
class QTextEdit;
class QGraphicsSceneMouseEvent;
class QMenu;
class QGraphicsSceneContextMenuEvent;
class QPainter;
class QStyleOptionGraphicsItem;
class QWidget;
class QMenu;
class QPolygonF;
QT_END_NAMESPACE
@ -77,7 +70,7 @@ public:
enum { Type = UserType + 15 };
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 removeArrows();
@ -85,7 +78,7 @@ public:
QPolygonF polygon() const { return myPolygon; }
void addArrow(Arrow *arrow);
QPixmap image() const;
int type() const override { return Type;}
int type() const override { return Type; }
protected:
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
@ -95,7 +88,7 @@ private:
DiagramType myDiagramType;
QPolygonF myPolygon;
QMenu *myContextMenu;
QList<Arrow *> arrows;
QVector<Arrow *> arrows;
};
//! [0]

View File

@ -51,8 +51,8 @@
#include "diagramscene.h"
#include "arrow.h"
#include <QTextCursor>
#include <QGraphicsSceneMouseEvent>
#include <QTextCursor>
//! [0]
DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
@ -61,8 +61,8 @@ DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
myItemMenu = itemMenu;
myMode = MoveItem;
myItemType = DiagramItem::Step;
line = 0;
textItem = 0;
line = nullptr;
textItem = nullptr;
myItemColor = Qt::white;
myTextColor = Qt::black;
myLineColor = Qt::black;
@ -188,7 +188,7 @@ void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
//! [10]
void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
if (myMode == InsertLine && line != 0) {
if (myMode == InsertLine && line != nullptr) {
QLineF newLine(line->line().p1(), mouseEvent->scenePos());
line->setLine(newLine);
} else if (myMode == MoveItem) {
@ -200,7 +200,7 @@ void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
//! [11]
void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
if (line != 0 && myMode == InsertLine) {
if (line != nullptr && myMode == InsertLine) {
QList<QGraphicsItem *> startItems = items(line->line().p1());
if (startItems.count() && startItems.first() == line)
startItems.removeFirst();
@ -228,7 +228,7 @@ void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
}
}
//! [12] //! [13]
line = 0;
line = nullptr;
QGraphicsScene::mouseReleaseEvent(mouseEvent);
}
//! [13]

View File

@ -74,7 +74,7 @@ class DiagramScene : public QGraphicsScene
public:
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; }
QColor textColor() const { return myTextColor; }
QColor itemColor() const { return myItemColor; }

View File

@ -52,12 +52,8 @@
#define DIAGRAMTEXTITEM_H
#include <QGraphicsTextItem>
#include <QPen>
QT_BEGIN_NAMESPACE
class QFocusEvent;
class QGraphicsItem;
class QGraphicsScene;
class QGraphicsSceneMouseEvent;
QT_END_NAMESPACE
@ -69,7 +65,7 @@ class DiagramTextItem : public QGraphicsTextItem
public:
enum { Type = UserType + 3 };
DiagramTextItem(QGraphicsItem *parent = 0);
DiagramTextItem(QGraphicsItem *parent = nullptr);
int type() const override { return Type; }

View File

@ -48,10 +48,18 @@
**
****************************************************************************/
#include <QtWidgets>
#include "coloritem.h"
#include <QApplication>
#include <QBitmap>
#include <QCursor>
#include <QDrag>
#include <QGraphicsSceneMouseEvent>
#include <QMimeData>
#include <QPainter>
#include <QRandomGenerator>
#include <QWidget>
//! [0]
ColorItem::ColorItem()
: 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);
painter.translate(15, 15);
painter.setRenderHint(QPainter::Antialiasing);
paint(&painter, 0, 0);
paint(&painter, nullptr, nullptr);
painter.end();
pixmap.setMask(pixmap.createHeuristicMask());

View File

@ -48,19 +48,20 @@
**
****************************************************************************/
#include <QtWidgets>
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include "coloritem.h"
#include "robot.h"
#include <math.h>
#include <cmath>
class GraphicsView : public QGraphicsView
{
public:
GraphicsView(QGraphicsScene *scene) : QGraphicsView(scene)
{
}
using QGraphicsView::QGraphicsView;
protected:
void resizeEvent(QResizeEvent *) override
@ -96,7 +97,7 @@ int main(int argc, char **argv)
view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view.setBackgroundBrush(QColor(230, 200, 167));
view.setWindowTitle("Drag and Drop Robot");
view.show();
view.show();
return app.exec();
}

View File

@ -48,13 +48,17 @@
**
****************************************************************************/
#include <QtWidgets>
#include "robot.h"
#include <QGraphicsSceneDragDropEvent>
#include <QMimeData>
#include <QPainter>
#include <QParallelAnimationGroup>
#include <QPropertyAnimation>
//! [0]
RobotPart::RobotPart(QGraphicsItem *parent)
: QGraphicsObject(parent), color(Qt::lightGray), dragOver(false)
: QGraphicsObject(parent), color(Qt::lightGray)
{
setAcceptDrops(true);
}
@ -157,11 +161,6 @@ void RobotHead::dropEvent(QGraphicsSceneDragDropEvent *event)
}
//! [8]
RobotTorso::RobotTorso(QGraphicsItem *parent)
: RobotPart(parent)
{
}
QRectF RobotTorso::boundingRect() const
{
return QRectF(-30, -20, 60, 60);

View File

@ -62,15 +62,15 @@ QT_END_NAMESPACE
class RobotPart : public QGraphicsObject
{
public:
RobotPart(QGraphicsItem *parent = 0);
RobotPart(QGraphicsItem *parent = nullptr);
protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override;
void dropEvent(QGraphicsSceneDragDropEvent *event) override;
QColor color;
bool dragOver;
QColor color = Qt::lightGray;
bool dragOver = false;
};
//! [0]
@ -78,10 +78,10 @@ protected:
class RobotHead : public RobotPart
{
public:
RobotHead(QGraphicsItem *parent = 0);
RobotHead(QGraphicsItem *parent = nullptr);
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:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
@ -96,10 +96,10 @@ private:
class RobotTorso : public RobotPart
{
public:
RobotTorso(QGraphicsItem *parent = 0);
using RobotPart::RobotPart;
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]
@ -107,10 +107,10 @@ public:
class RobotLimb : public RobotPart
{
public:
RobotLimb(QGraphicsItem *parent = 0);
RobotLimb(QGraphicsItem *parent = nullptr);
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]
@ -118,10 +118,10 @@ public:
class Robot : public RobotPart
{
public:
Robot(QGraphicsItem *parent = 0);
Robot(QGraphicsItem *parent = nullptr);
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]

View File

@ -51,16 +51,14 @@
#include "edge.h"
#include "node.h"
#include <qmath.h>
#include <QPainter>
#include <QtMath>
//! [0]
Edge::Edge(Node *sourceNode, Node *destNode)
: arrowSize(10)
: source(sourceNode), dest(destNode)
{
setAcceptedMouseButtons(0);
source = sourceNode;
dest = destNode;
setAcceptedMouseButtons(Qt::NoButton);
source->addEdge(this);
dest->addEdge(this);
adjust();

View File

@ -78,7 +78,7 @@ private:
QPointF sourcePoint;
QPointF destPoint;
qreal arrowSize;
qreal arrowSize = 10;
};
//! [0]

View File

@ -59,7 +59,7 @@
//! [0]
GraphWidget::GraphWidget(QWidget *parent)
: QGraphicsView(parent), timerId(0)
: QGraphicsView(parent)
{
QGraphicsScene *scene = new QGraphicsScene(this);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
@ -163,7 +163,7 @@ void GraphWidget::timerEvent(QTimerEvent *event)
{
Q_UNUSED(event);
QList<Node *> nodes;
QVector<Node *> nodes;
const QList<QGraphicsItem *> items = scene()->items();
for (QGraphicsItem *item : items) {
if (Node *node = qgraphicsitem_cast<Node *>(item))
@ -190,7 +190,7 @@ void GraphWidget::timerEvent(QTimerEvent *event)
//! [5]
void GraphWidget::wheelEvent(QWheelEvent *event)
{
scaleView(pow((double)2, -event->angleDelta().y() / 240.0));
scaleView(pow(2., -event->angleDelta().y() / 240.0));
}
//! [5]
#endif

View File

@ -61,7 +61,7 @@ class GraphWidget : public QGraphicsView
Q_OBJECT
public:
GraphWidget(QWidget *parent = 0);
GraphWidget(QWidget *parent = nullptr);
void itemMoved();
@ -81,7 +81,7 @@ protected:
void scaleView(qreal scaleFactor);
private:
int timerId;
int timerId = 0;
Node *centerNode;
};
//! [0]

View File

@ -75,7 +75,7 @@ void Node::addEdge(Edge *edge)
edge->adjust();
}
QList<Edge *> Node::edges() const
QVector<Edge *> Node::edges() const
{
return edgeList;
}

View File

@ -52,13 +52,10 @@
#define NODE_H
#include <QGraphicsItem>
#include <QList>
#include <QVector>
class Edge;
class GraphWidget;
QT_BEGIN_NAMESPACE
class QGraphicsSceneMouseEvent;
QT_END_NAMESPACE
//! [0]
class Node : public QGraphicsItem
@ -67,7 +64,7 @@ public:
Node(GraphWidget *graphWidget);
void addEdge(Edge *edge);
QList<Edge *> edges() const;
QVector<Edge *> edges() const;
enum { Type = UserType + 1 };
int type() const override { return Type; }
@ -86,7 +83,7 @@ protected:
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
private:
QList<Edge *> edgeList;
QVector<Edge *> edgeList;
QPointF newPos;
GraphWidget *graph;
};

View File

@ -50,14 +50,13 @@
#include "customproxy.h"
#include <QStyleOptionGraphicsItem>
#include <QPainter>
#include <QGraphicsScene>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
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,
this, &CustomProxy::updateStep);
connect(timeLine, &QTimeLine::stateChanged,
@ -99,7 +98,7 @@ void CustomProxy::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
QGraphicsProxyWidget::hoverEnterEvent(event);
scene()->setActiveWindow(this);
if (timeLine->currentValue() != 1)
if (qFuzzyCompare(timeLine->currentValue(), 1))
zoomIn();
}
@ -107,7 +106,7 @@ void CustomProxy::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
QGraphicsProxyWidget::hoverLeaveEvent(event);
if (!popupShown
&& (timeLine->direction() != QTimeLine::Backward || timeLine->currentValue() != 0)) {
&& (timeLine->direction() != QTimeLine::Backward || qFuzzyIsNull(timeLine->currentValue()))) {
zoomOut();
}
}

View File

@ -59,7 +59,7 @@ class CustomProxy : public QGraphicsProxyWidget
Q_OBJECT
public:
explicit CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
explicit CustomProxy(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = nullptr);
QRectF boundingRect() const override;
void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
@ -79,8 +79,8 @@ private slots:
private:
QTimeLine *timeLine;
bool popupShown;
QGraphicsItem *currentPopup;
QGraphicsItem *currentPopup = nullptr;
bool popupShown = false;
};
#endif // CUSTOMPROXY_H

View File

@ -64,7 +64,7 @@ class EmbeddedDialog : public QDialog
Q_OBJECT
public:
EmbeddedDialog(QWidget *parent = 0);
EmbeddedDialog(QWidget *parent = nullptr);
~EmbeddedDialog();
private slots:

View File

@ -50,14 +50,10 @@
#include "flowlayout.h"
#include <qmath.h>
#include <QtMath>
#include <QWidget>
FlowLayout::FlowLayout()
FlowLayout::FlowLayout(QGraphicsLayoutItem *parent) : QGraphicsLayout(parent)
{
m_spacing[0] = 6;
m_spacing[1] = 6;
QSizePolicy sp = sizePolicy();
sp.setHeightForWidth(true);
setSizePolicy(sp);
@ -66,7 +62,7 @@ FlowLayout::FlowLayout()
void FlowLayout::insertItem(int index, QGraphicsLayoutItem *item)
{
item->setParentLayoutItem(this);
if (uint(index) > uint(m_items.count()))
if (index > m_items.count())
index = m_items.count();
m_items.insert(index, item);
invalidate();
@ -117,15 +113,14 @@ qreal FlowLayout::doLayout(const QRectF &geom, bool applyNewGeometry) const
qreal y = 0;
qreal maxRowHeight = 0;
QSizeF pref;
for (int i = 0; i < m_items.count(); ++i) {
QGraphicsLayoutItem *item = m_items.at(i);
for (QGraphicsLayoutItem *item : m_items) {
pref = item->effectiveSizeHint(Qt::PreferredSize);
maxRowHeight = qMax(maxRowHeight, pref.height());
qreal next_x;
next_x = x + pref.width();
if (next_x > maxw) {
if (x == 0) {
if (qFuzzyIsNull(x)) {
pref.setWidth(maxw);
} else {
x = 0;
@ -156,7 +151,7 @@ QSizeF FlowLayout::minSize(const QSizeF &constraint) const
} else {
for (const QGraphicsLayoutItem *item : qAsConst(m_items))
size = size.expandedTo(item->effectiveSizeHint(Qt::MinimumSize));
size += QSize(left + right, top + bottom);
size += QSizeF(left + right, top + bottom);
}
return size;
}
@ -164,7 +159,7 @@ QSizeF FlowLayout::minSize(const QSizeF &constraint) const
QSizeF FlowLayout::prefSize() const
{
qreal left, right;
getContentsMargins(&left, 0, &right, 0);
getContentsMargins(&left, nullptr, &right, nullptr);
qreal maxh = 0;
qreal totalWidth = 0;

View File

@ -53,7 +53,7 @@
class FlowLayout : public QGraphicsLayout
{
public:
FlowLayout();
FlowLayout(QGraphicsLayoutItem *parent = nullptr);
inline void addItem(QGraphicsLayoutItem *item);
void insertItem(int index, QGraphicsLayoutItem *item);
void setSpacing(Qt::Orientations o, qreal spacing);
@ -75,8 +75,8 @@ private:
QSizeF prefSize() const;
QSizeF maxSize() const;
QList<QGraphicsLayoutItem*> m_items;
qreal m_spacing[2];
QVector<QGraphicsLayoutItem*> m_items;
qreal m_spacing[2] = {6, 6};
};

View File

@ -59,12 +59,12 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
QGraphicsScene scene;
QGraphicsView *view = new QGraphicsView(&scene);
QGraphicsView view(&scene);
Window *w = new Window;
scene.addItem(w);
view->resize(400, 300);
view->show();
view.resize(400, 300);
view.show();
return app.exec();
}

View File

@ -48,23 +48,21 @@
**
****************************************************************************/
#include "flowlayout.h"
#include "window.h"
#include "flowlayout.h"
#include <QGraphicsProxyWidget>
#include <QLabel>
Window::Window()
: QGraphicsWidget(0, Qt::Window)
Window::Window(QGraphicsItem *parent) : QGraphicsWidget(parent, Qt::Window)
{
FlowLayout *lay = new FlowLayout;
QLatin1String wiseWords("I am not bothered by the fact that I am unknown."
" I am bothered when I do not know others. (Confucius)");
QString sentence(wiseWords);
QStringList words = sentence.split(QLatin1Char(' '), QString::SkipEmptyParts);
for (int i = 0; i < words.count(); ++i) {
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)"));
const QVector<QStringRef> words = sentence.splitRef(QLatin1Char(' '), QString::SkipEmptyParts);
for (const QStringRef &word : words) {
QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
QLabel *label = new QLabel(words.at(i));
QLabel *label = new QLabel(word.toString());
label->setFrameStyle(QFrame::Box | QFrame::Plain);
proxy->setWidget(label);
lay->addItem(proxy);

View File

@ -53,7 +53,6 @@
class Window : public QGraphicsWidget
{
Q_OBJECT
public:
Window();
Window(QGraphicsItem *parent = nullptr);
};

View File

@ -75,8 +75,8 @@ FlippablePad::FlippablePad(const QSize &size, QGraphicsItem *parent)
//! [2]
//! [3]
int numIcons = size.width() * size.height();
QList<QPixmap> pixmaps;
QDirIterator it(":/images", QStringList() << "*.png");
QVector<QPixmap> pixmaps;
QDirIterator it(":/images", {"*.png"});
while (it.hasNext() && pixmaps.size() < numIcons)
pixmaps << it.next();
//! [3]

View File

@ -53,15 +53,13 @@
#include "roundrectitem.h"
#include <QGraphicsObject>
#include <QLinearGradient>
#include <QVector>
//! [0]
class FlippablePad : public RoundRectItem
{
public:
explicit FlippablePad(const QSize &size, QGraphicsItem *parent = 0);
explicit FlippablePad(const QSize &size, QGraphicsItem *parent = nullptr);
RoundRectItem *iconAt(int column, int row) const;

View File

@ -52,10 +52,18 @@
#include "padnavigator.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
#include <QtOpenGL>
#else
#include <QtWidgets>
#include <QOpenGLWidget>
#endif
//! [0]

View File

@ -54,17 +54,12 @@
#include <QGraphicsView>
#include "ui_form.h"
QT_BEGIN_NAMESPACE
class QState;
class QStateMachine;
QT_END_NAMESPACE
//! [0]
class PadNavigator : public QGraphicsView
{
Q_OBJECT
public:
explicit PadNavigator(const QSize &size, QWidget *parent = 0);
explicit PadNavigator(const QSize &size, QWidget *parent = nullptr);
protected:
void resizeEvent(QResizeEvent *event) override;

View File

@ -50,7 +50,7 @@
#include "roundrectitem.h"
#include <QApplication>
#include <QGuiApplication>
#include <QPainter>
#include <QPalette>
@ -98,7 +98,7 @@ void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
//! [3]
//! [4]
if (fillRect)
painter->setBrush(QApplication::palette().brush(QPalette::Window));
painter->setBrush(QGuiApplication::palette().brush(QPalette::Window));
else
painter->setBrush(gradient);
painter->setPen(QPen(Qt::black, 1));

View File

@ -61,13 +61,13 @@ class RoundRectItem : public QGraphicsObject
Q_PROPERTY(bool fill READ fill WRITE setFill)
public:
RoundRectItem(const QRectF &bounds, const QColor &color,
QGraphicsItem *parent = 0);
QGraphicsItem *parent = nullptr);
QPixmap pixmap() const;
void setPixmap(const QPixmap &pixmap);
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;
void setFill(bool fill);

View File

@ -58,10 +58,10 @@ class SplashItem : public QGraphicsObject
{
Q_OBJECT
public:
explicit SplashItem(QGraphicsItem *parent = 0);
explicit SplashItem(QGraphicsItem *parent = nullptr);
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:
QString text;

View File

@ -54,7 +54,7 @@ class Widget : public QGraphicsWidget
{
public:
Widget(const QColor &color, const QColor &textColor, const QString &caption,
QGraphicsItem *parent = 0)
QGraphicsItem *parent = nullptr)
: QGraphicsWidget(parent)
, caption(caption)
, 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;
font.setPixelSize(0.75 * qMin(boundingRect().width(), boundingRect().height()));
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QGraphicsScene *scene = new QGraphicsScene();
QGraphicsScene scene;
Widget *a = new Widget(Qt::blue, Qt::white, "a");
a->setPreferredSize(100, 100);
@ -94,7 +94,7 @@ int main(int argc, char *argv[])
Widget *c = new Widget(Qt::red, Qt::black, "c");
c->setPreferredSize(100, 100);
QGraphicsAnchorLayout *layout = new QGraphicsAnchorLayout();
QGraphicsAnchorLayout *layout = new QGraphicsAnchorLayout;
/*
//! [adding a corner anchor in two steps]
layout->addAnchor(a, Qt::AnchorTop, layout, Qt::AnchorTop);
@ -128,20 +128,20 @@ int main(int argc, char *argv[])
// corner of the layout.
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->setMinimumSize(100, 100);
w->setPreferredSize(320, 240);
w->setLayout(layout);
w->setWindowTitle(QApplication::translate("simpleanchorlayout", "QGraphicsAnchorLayout in use"));
scene->addItem(w);
scene.addItem(w);
QGraphicsView *view = new QGraphicsView();
view->setScene(scene);
view->setWindowTitle(QApplication::translate("simpleanchorlayout", "Simple Anchor Layout"));
QGraphicsView view;
view.setScene(&scene);
view.setWindowTitle(QApplication::translate("simpleanchorlayout", "Simple Anchor Layout"));
view->resize(360, 320);
view->show();
view.resize(360, 320);
view.show();
return app.exec();
}

View File

@ -50,15 +50,14 @@
#include <QApplication>
#include <QLabel>
#include <QPainter>
#include <QPushButton>
#include <QGraphicsAnchorLayout>
#include <QGraphicsProxyWidget>
#include <QGraphicsScene>
#include <QGraphicsSceneResizeEvent>
#include <QGraphicsView>
#include <QGraphicsWidget>
#include <QPainter>
#include <QPushButton>
class GraphicsView : public QGraphicsView
@ -79,20 +78,18 @@ public:
class PixmapWidget : public QGraphicsLayoutItem
{
public:
PixmapWidget(const QPixmap &pix)
: QGraphicsLayoutItem()
: QGraphicsLayoutItem(), original(new QGraphicsPixmapItem(pix))
, r(QRectF(QPointF(0, 0), pix.size()))
{
original = new QGraphicsPixmapItem(pix);
setGraphicsItem(original);
original->show();
r = QRectF(QPointF(0, 0), pix.size());
}
~PixmapWidget()
{
setGraphicsItem(0);
setGraphicsItem(nullptr);
delete original;
}
@ -101,7 +98,7 @@ public:
original->setZValue(z);
}
void setGeometry (const QRectF &rect) override
void setGeometry(const QRectF &rect) override
{
original->setTransform(QTransform::fromScale(rect.width() / r.width(),
rect.height() / r.height()), true);
@ -150,8 +147,7 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
{
QPointF reflection = QPointF();
reflection.setY(scaled.height() + 2);
const QPointF reflection(0, scaled.height() + 2);
painter->drawPixmap(QPointF(), scaled);
@ -239,7 +235,7 @@ int main(int argc, char *argv[])
layout->setSpacing(0);
// setup the main widget
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
QGraphicsWidget *widget = new QGraphicsWidget(nullptr, Qt::Window);
QPalette p;
p.setColor(QPalette::Window, Qt::black);
widget->setPalette(p);

View File

@ -48,12 +48,21 @@
**
****************************************************************************/
#include <QtWidgets>
#include "mainwindow.h"
#include "encodingdialog.h"
#include "previewform.h"
#include <QAction>
#include <QApplication>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QMenuBar>
#include <QMessageBox>
#include <QPlainTextEdit>
#include <QRegularExpression>
#include <QTextCodec>
#include <QTextStream>
MainWindow::MainWindow()
{
textEdit = new QPlainTextEdit;
@ -146,14 +155,14 @@ void MainWindow::findCodecs()
QTextCodec *codec = QTextCodec::codecForMib(mib);
QString sortKey = codec->name().toUpper();
int rank;
char rank;
if (sortKey.startsWith(QLatin1String("UTF-8"))) {
rank = 1;
} else if (sortKey.startsWith(QLatin1String("UTF-16"))) {
rank = 2;
} else if ((match = iso8859RegExp.match(sortKey)).hasMatch()) {
if (match.captured(1).size() == 1)
if (match.capturedRef(1).size() == 1)
rank = 3;
else
rank = 4;
@ -164,7 +173,8 @@ void MainWindow::findCodecs()
codecMap.insert(sortKey, codec);
}
codecs = codecMap.values();
for (const auto &codec : qAsConst(codecMap))
codecs += codec;
}
void MainWindow::createMenus()

View File

@ -51,7 +51,7 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QList>
#include <QVector>
#include <QMainWindow>
QT_BEGIN_NAMESPACE
@ -81,10 +81,10 @@ private:
void findCodecs();
void createMenus();
QList<QAction *> saveAsActs;
QVector<QAction *> saveAsActs;
QPlainTextEdit *textEdit;
PreviewForm *previewForm;
QList<QTextCodec *> codecs;
QVector<QTextCodec *> codecs;
EncodingDialog *m_encodingDialog = nullptr;
};

View File

@ -48,10 +48,19 @@
**
****************************************************************************/
#include <QtWidgets>
#include "previewform.h"
#include <QApplication>
#include <QComboBox>
#include <QDesktopWidget>
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QLabel>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QTextCodec>
#include <QTextStream>
// Helpers for creating hex dumps
static void indent(QTextStream &str, int indent)
{
@ -83,8 +92,7 @@ static void formatHex(QTextStream &str, const QByteArray &data)
static void formatPrintableCharacters(QTextStream &str, const QByteArray &data)
{
for (int i = 0, size = data.size(); i < size; ++i) {
const char c = data.at(i);
for (const char c : data) {
switch (c) {
case '\0':
str << "\\0";
@ -179,7 +187,7 @@ PreviewForm::PreviewForm(QWidget *parent)
resize(screenGeometry.width() * 2 / 5, screenGeometry.height() / 2);
}
void PreviewForm::setCodecList(const QList<QTextCodec *> &list)
void PreviewForm::setCodecList(const QVector<QTextCodec *> &list)
{
encodingComboBox->clear();
for (const QTextCodec *codec : list) {
@ -226,10 +234,10 @@ void PreviewForm::updateTextEdit()
statusLabel->setText(message);
statusLabel->setStyleSheet(QStringLiteral("background-color: \"red\";"));
} else if (state.invalidChars) {
statusLabel->setText(tr("%1: %n invalid characters", 0, state.invalidChars).arg(name));
statusLabel->setText(tr("%1: %n invalid characters", nullptr, state.invalidChars).arg(name));
statusLabel->setStyleSheet(QStringLiteral("background-color: \"yellow\";"));
} else {
statusLabel->setText(tr("%1: %n bytes converted", 0, encodedData.size()).arg(name));
statusLabel->setText(tr("%1: %n bytes converted", nullptr, encodedData.size()).arg(name));
statusLabel->setStyleSheet(QString());
}
if (success)

View File

@ -52,7 +52,7 @@
#define PREVIEWFORM_H
#include <QDialog>
#include <QList>
#include <QVector>
QT_BEGIN_NAMESPACE
class QComboBox;
@ -71,7 +71,7 @@ class PreviewForm : public QDialog
public:
explicit PreviewForm(QWidget *parent = nullptr);
void setCodecList(const QList<QTextCodec *> &list);
void setCodecList(const QVector<QTextCodec *> &list);
void setEncodedData(const QByteArray &data);
QString decodedString() const { return decodedStr; }

View File

@ -62,7 +62,7 @@
class FileSystemModel : public QFileSystemModel
{
public:
FileSystemModel(QObject *parent = 0);
FileSystemModel(QObject *parent = nullptr);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
};
//! [0]

View File

@ -48,13 +48,28 @@
**
****************************************************************************/
#include <QtWidgets>
#include "fsmodel.h"
#include "mainwindow.h"
#include "fsmodel.h"
#include <QAction>
#include <QApplication>
#include <QCheckBox>
#include <QComboBox>
#include <QCompleter>
#include <QGridLayout>
#include <QHeaderView>
#include <QLabel>
#include <QLineEdit>
#include <QMenuBar>
#include <QMessageBox>
#include <QSpinBox>
#include <QStandardItemModel>
#include <QStringListModel>
#include <QTreeView>
//! [0]
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), completer(0), lineEdit(0)
: QMainWindow(parent)
{
createMenu();
@ -64,8 +79,8 @@ MainWindow::MainWindow(QWidget *parent)
modelLabel->setText(tr("Model"));
modelCombo = new QComboBox;
modelCombo->addItem(tr("QFileSytemModel"));
modelCombo->addItem(tr("QFileSytemModel that shows full path"));
modelCombo->addItem(tr("QFileSystemModel"));
modelCombo->addItem(tr("QFileSystemModel that shows full path"));
modelCombo->addItem(tr("Country list"));
modelCombo->addItem(tr("Word list"));
modelCombo->setCurrentIndex(0);
@ -144,17 +159,17 @@ void MainWindow::createMenu()
connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
QMenu* fileMenu = menuBar()->addMenu(tr("File"));
QMenu *fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(exitAction);
QMenu* helpMenu = menuBar()->addMenu(tr("About"));
QMenu *helpMenu = menuBar()->addMenu(tr("About"));
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
}
//! [4]
//! [5]
QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
QAbstractItemModel *MainWindow::modelFromFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QFile::ReadOnly))
@ -170,7 +185,7 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
while (!file.atEnd()) {
QByteArray line = file.readLine();
if (!line.isEmpty())
words << line.trimmed();
words << QString::fromUtf8(line.trimmed());
}
#ifndef QT_NO_CURSOR
@ -191,8 +206,8 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
for (int i = 0; i < words.count(); ++i) {
QModelIndex countryIdx = m->index(i, 0);
QModelIndex symbolIdx = m->index(i, 1);
QString country = words[i].mid(0, words[i].length() - 2).trimmed();
QString symbol = words[i].right(2);
QString country = words.at(i).mid(0, words[i].length() - 2).trimmed();
QString symbol = words.at(i).right(2);
m->setData(countryIdx, country);
m->setData(symbolIdx, symbol);
}
@ -233,7 +248,7 @@ void MainWindow::changeModel()
case 0:
{ // Unsorted QFileSystemModel
QFileSystemModel *fsModel = new QFileSystemModel(completer);
fsModel->setRootPath("");
fsModel->setRootPath(QString());
completer->setModel(fsModel);
contentsLabel->setText(tr("Enter file path"));
}
@ -243,7 +258,7 @@ void MainWindow::changeModel()
{ // FileSystemModel that shows full paths
FileSystemModel *fsModel = new FileSystemModel(completer);
completer->setModel(fsModel);
fsModel->setRootPath("");
fsModel->setRootPath(QString());
contentsLabel->setText(tr("Enter file path"));
}
break;

View File

@ -59,7 +59,6 @@ class QComboBox;
class QCompleter;
class QLabel;
class QLineEdit;
class QProgressBar;
class QCheckBox;
class QSpinBox;
QT_END_NAMESPACE
@ -70,7 +69,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
MainWindow(QWidget *parent = nullptr);
private slots:
void about();
@ -83,16 +82,16 @@ private slots:
//! [1]
private:
void createMenu();
QAbstractItemModel *modelFromFile(const QString& fileName);
QAbstractItemModel *modelFromFile(const QString &fileName);
QComboBox *caseCombo;
QComboBox *modeCombo;
QComboBox *modelCombo;
QSpinBox *maxVisibleSpinBox;
QCheckBox *wrapCheckBox;
QCompleter *completer;
QLabel *contentsLabel;
QLineEdit *lineEdit;
QComboBox *caseCombo = nullptr;
QComboBox *modeCombo = nullptr;
QComboBox *modelCombo = nullptr;
QSpinBox *maxVisibleSpinBox = nullptr;
QCheckBox *wrapCheckBox = nullptr;
QCompleter *completer = nullptr;
QLabel *contentsLabel = nullptr;
QLineEdit *lineEdit = nullptr;
};
//! [1]

View File

@ -48,13 +48,20 @@
**
****************************************************************************/
#include <QtWidgets>
#include "mainwindow.h"
#include "textedit.h"
#include <QAction>
#include <QApplication>
#include <QCompleter>
#include <QFile>
#include <QMenuBar>
#include <QMessageBox>
#include <QStringListModel>
//! [0]
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), completer(0)
: QMainWindow(parent)
{
createMenu();
@ -83,10 +90,10 @@ void MainWindow::createMenu()
connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
QMenu* fileMenu = menuBar()->addMenu(tr("File"));
QMenu *fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(exitAction);
QMenu* helpMenu = menuBar()->addMenu(tr("About"));
QMenu *helpMenu = menuBar()->addMenu(tr("About"));
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
}
@ -107,7 +114,7 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
while (!file.atEnd()) {
QByteArray line = file.readLine();
if (!line.isEmpty())
words << line.trimmed();
words << QString::fromUtf8(line.trimmed());
}
#ifndef QT_NO_CURSOR

View File

@ -55,11 +55,7 @@
QT_BEGIN_NAMESPACE
class QAbstractItemModel;
class QComboBox;
class QCompleter;
class QLabel;
class QLineEdit;
class QProgressBar;
QT_END_NAMESPACE
class TextEdit;
@ -69,7 +65,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
MainWindow(QWidget *parent = nullptr);
private slots:
void about();
@ -78,7 +74,7 @@ private:
void createMenu();
QAbstractItemModel *modelFromFile(const QString& fileName);
QCompleter *completer;
QCompleter *completer = nullptr;
TextEdit *completingTextEdit;
};
//! [0]

View File

@ -60,7 +60,7 @@
//! [0]
TextEdit::TextEdit(QWidget *parent)
: QTextEdit(parent), c(0)
: QTextEdit(parent)
{
setPlainText(tr("This TextEdit provides autocompletions for words that have more than"
" 3 characters. You can trigger autocompletion using ") +
@ -78,7 +78,7 @@ TextEdit::~TextEdit()
void TextEdit::setCompleter(QCompleter *completer)
{
if (c)
QObject::disconnect(c, 0, this, 0);
c->disconnect(this);
c = completer;
@ -101,7 +101,7 @@ QCompleter *TextEdit::completer() const
//! [3]
//! [4]
void TextEdit::insertCompletion(const QString& completion)
void TextEdit::insertCompletion(const QString &completion)
{
if (c->widget() != this)
return;
@ -150,18 +150,19 @@ void TextEdit::keyPressEvent(QKeyEvent *e)
}
}
bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E
const bool isShortcut = (e->modifiers().testFlag(Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E
if (!c || !isShortcut) // do not process the shortcut when we have a completer
QTextEdit::keyPressEvent(e);
//! [7]
//! [8]
const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
const bool ctrlOrShift = e->modifiers().testFlag(Qt::ControlModifier) ||
e->modifiers().testFlag(Qt::ShiftModifier);
if (!c || (ctrlOrShift && e->text().isEmpty()))
return;
static QString eow("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-="); // end of word
bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
const bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
QString completionPrefix = textUnderCursor();
if (!isShortcut && (hasModifier || e->text().isEmpty()|| completionPrefix.length() < 3

View File

@ -63,7 +63,7 @@ class TextEdit : public QTextEdit
Q_OBJECT
public:
TextEdit(QWidget *parent = 0);
TextEdit(QWidget *parent = nullptr);
~TextEdit();
void setCompleter(QCompleter *c);
@ -80,7 +80,7 @@ private:
QString textUnderCursor() const;
private:
QCompleter *c;
QCompleter *c = nullptr;
};
//! [0]

View File

@ -51,13 +51,14 @@
#ifndef ECHOINTERFACE_H
#define ECHOINTERFACE_H
#include <QObject>
#include <QString>
//! [0]
class EchoInterface
{
public:
virtual ~EchoInterface() {}
virtual ~EchoInterface() = default;
virtual QString echo(const QString &message) = 0;
};

View File

@ -48,10 +48,17 @@
**
****************************************************************************/
#include <QtWidgets>
#include "echowindow.h"
#include <QCoreApplication>
#include <QDir>
#include <QLabel>
#include <QLayout>
#include <QLineEdit>
#include <QMessageBox>
#include <QPluginLoader>
#include <QPushButton>
//! [0]
EchoWindow::EchoWindow()
{
@ -101,7 +108,7 @@ void EchoWindow::createGUI()
//! [3]
bool EchoWindow::loadPlugin()
{
QDir pluginsDir(qApp->applicationDirPath());
QDir pluginsDir(QCoreApplication::applicationDirPath());
#if defined(Q_OS_WIN)
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
pluginsDir.cdUp();
@ -121,6 +128,7 @@ bool EchoWindow::loadPlugin()
echoInterface = qobject_cast<EchoInterface *>(plugin);
if (echoInterface)
return true;
pluginLoader.unload();
}
}

View File

@ -48,7 +48,7 @@
**
****************************************************************************/
#include <QtWidgets>
#include <QApplication>
#include "echowindow.h"
#include "echointerface.h"

View File

@ -48,8 +48,6 @@
**
****************************************************************************/
#include <QtWidgets>
#include "echoplugin.h"
//! [0]

View File

@ -48,34 +48,39 @@
**
****************************************************************************/
#include <QtWidgets>
#include "languagechooser.h"
#include "mainwindow.h"
LanguageChooser::LanguageChooser(const QString& defaultLang, QWidget *parent)
#include <QCoreApplication>
#include <QCheckBox>
#include <QDialogButtonBox>
#include <QDir>
#include <QGridLayout>
#include <QGroupBox>
#include <QPushButton>
#include <QTranslator>
LanguageChooser::LanguageChooser(const QString &defaultLang, QWidget *parent)
: QDialog(parent, Qt::WindowStaysOnTopHint)
{
groupBox = new QGroupBox("Languages");
QGridLayout *groupBoxLayout = new QGridLayout;
QStringList qmFiles = findQmFiles();
const QStringList qmFiles = findQmFiles();
for (int i = 0; i < qmFiles.size(); ++i) {
QCheckBox *checkBox = new QCheckBox(languageName(qmFiles[i]));
qmFileForCheckBoxMap.insert(checkBox, qmFiles[i]);
connect(checkBox,
QOverload<bool>::of(&QCheckBox::toggled),
this,
&LanguageChooser::checkBoxToggled);
if (languageMatch(defaultLang, qmFiles[i]))
checkBox->setCheckState(Qt::Checked);
const QString &qmlFile = qmFiles.at(i);
QCheckBox *checkBox = new QCheckBox(languageName(qmlFile));
qmFileForCheckBoxMap.insert(checkBox, qmlFile);
connect(checkBox, &QCheckBox::toggled,
this, &LanguageChooser::checkBoxToggled);
if (languageMatch(defaultLang, qmlFile))
checkBox->setCheckState(Qt::Checked);
groupBoxLayout->addWidget(checkBox, i / 2, i % 2);
}
groupBox->setLayout(groupBoxLayout);
buttonBox = new QDialogButtonBox;
showAllButton = buttonBox->addButton("Show All",
QDialogButtonBox::ActionRole);
hideAllButton = buttonBox->addButton("Hide All",
@ -92,7 +97,7 @@ LanguageChooser::LanguageChooser(const QString& defaultLang, QWidget *parent)
setWindowTitle("I18N");
}
bool LanguageChooser::languageMatch(const QString& lang, const QString& qmFile)
bool LanguageChooser::languageMatch(const QString &lang, const QString &qmFile)
{
//qmFile: i18n_xx.qm
const QString prefix = "i18n_";
@ -110,21 +115,21 @@ bool LanguageChooser::eventFilter(QObject *object, QEvent *event)
checkBox->setChecked(false);
}
}
return QWidget::eventFilter(object, event);
return QDialog::eventFilter(object, event);
}
void LanguageChooser::closeEvent(QCloseEvent * /* event */)
{
qApp->quit();
QCoreApplication::quit();
}
void LanguageChooser::checkBoxToggled()
{
QCheckBox *checkBox = qobject_cast<QCheckBox *>(sender());
MainWindow *window = mainWindowForCheckBoxMap[checkBox];
MainWindow *window = mainWindowForCheckBoxMap.value(checkBox);
if (!window) {
QTranslator translator;
translator.load(qmFileForCheckBoxMap[checkBox]);
translator.load(qmFileForCheckBoxMap.value(checkBox));
qApp->installTranslator(&translator);
window = new MainWindow;

View File

@ -52,7 +52,7 @@
#define LANGUAGECHOOSER_H
#include <QDialog>
#include <QMap>
#include <QHash>
#include <QStringList>
QT_BEGIN_NAMESPACE
@ -68,7 +68,7 @@ class LanguageChooser : public QDialog
Q_OBJECT
public:
explicit LanguageChooser(const QString& defaultLang = QString(), QWidget *parent = 0);
explicit LanguageChooser(const QString &defaultLang = QString(), QWidget *parent = nullptr);
protected:
bool eventFilter(QObject *object, QEvent *event) override;
@ -80,17 +80,17 @@ private slots:
void hideAll();
private:
QStringList findQmFiles();
QString languageName(const QString &qmFile);
QColor colorForLanguage(const QString &language);
static bool languageMatch(const QString& lang, const QString& qmFile);
static QStringList findQmFiles();
static QString languageName(const QString &qmFile);
static QColor colorForLanguage(const QString &language);
static bool languageMatch(const QString &lang, const QString &qmFile);
QGroupBox *groupBox;
QDialogButtonBox *buttonBox;
QAbstractButton *showAllButton;
QAbstractButton *hideAllButton;
QMap<QCheckBox *, QString> qmFileForCheckBoxMap;
QMap<QCheckBox *, MainWindow *> mainWindowForCheckBoxMap;
QHash<QCheckBox *, QString> qmFileForCheckBoxMap;
QHash<QCheckBox *, MainWindow *> mainWindowForCheckBoxMap;
};
#endif

View File

@ -48,18 +48,26 @@
**
****************************************************************************/
#include <QtWidgets>
#include "mainwindow.h"
#include <QAction>
#include <QCoreApplication>
#include <QGroupBox>
#include <QListWidget>
#include <QMenuBar>
#include <QRadioButton>
#include <QStatusBar>
#include <QVBoxLayout>
static const char * const listEntries[] = {
QT_TRANSLATE_NOOP("MainWindow", "First"),
QT_TRANSLATE_NOOP("MainWindow", "Second"),
QT_TRANSLATE_NOOP("MainWindow", "Third"),
0
nullptr
};
MainWindow::MainWindow()
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
centralWidget = new QWidget;
setCentralWidget(centralWidget);
@ -67,8 +75,8 @@ MainWindow::MainWindow()
createGroupBox();
listWidget = new QListWidget;
for (int i = 0; listEntries[i]; ++i)
listWidget->addItem(tr(listEntries[i]));
for (const char *entry : listEntries)
listWidget->addItem(tr(entry));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(groupBox);
@ -76,7 +84,7 @@ MainWindow::MainWindow()
centralWidget->setLayout(mainLayout);
exitAction = new QAction(tr("E&xit"), this);
connect(exitAction, &QAction::triggered, qApp, QApplication::quit);
connect(exitAction, &QAction::triggered, qApp, QCoreApplication::quit);
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->setPalette(QPalette(Qt::red));

View File

@ -67,7 +67,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
MainWindow();
MainWindow(QWidget *parent = nullptr);
private:
void createGroupBox();

View File

@ -49,8 +49,8 @@
****************************************************************************/
#include "interfaces.h"
#include "mainwindow.h"
#include "interfaces.h"
#include "paintarea.h"
#include "plugindialog.h"
@ -67,9 +67,8 @@
#include <QScrollArea>
#include <QTimer>
MainWindow::MainWindow() :
paintArea(new PaintArea),
scrollArea(new QScrollArea)
MainWindow::MainWindow() : paintArea(new PaintArea)
, scrollArea(new QScrollArea)
{
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(paintArea);
@ -136,7 +135,11 @@ void MainWindow::brushWidth()
void MainWindow::changeBrush()
{
auto action = qobject_cast<QAction *>(sender());
if (!action)
return;
auto iBrush = qobject_cast<BrushInterface *>(action->parent());
if (!iBrush)
return;
const QString brush = action->text();
paintArea->setBrush(iBrush, brush);
@ -147,7 +150,11 @@ void MainWindow::changeBrush()
void MainWindow::insertShape()
{
auto action = qobject_cast<QAction *>(sender());
if (!action)
return;
auto iShape = qobject_cast<ShapeInterface *>(action->parent());
if (!iShape)
return;
const QPainterPath path = iShape->generateShape(action->text(), this);
if (!path.isEmpty())
@ -159,7 +166,11 @@ void MainWindow::insertShape()
void MainWindow::applyFilter()
{
auto action = qobject_cast<QAction *>(sender());
if (!action)
return;
auto iFilter = qobject_cast<FilterInterface *>(action->parent());
if (!iFilter)
return;
const QImage image = iFilter->filterImage(action->text(), paintArea->image(),
this);
@ -247,7 +258,7 @@ void MainWindow::loadPlugins()
populateMenus(plugin);
//! [4] //! [5]
pluginsDir = QDir(qApp->applicationDirPath());
pluginsDir = QDir(QCoreApplication::applicationDirPath());
#if defined(Q_OS_WIN)
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")

View File

@ -49,14 +49,13 @@
****************************************************************************/
#include "interfaces.h"
#include "paintarea.h"
#include "interfaces.h"
#include <QMouseEvent>
#include <QPainter>
PaintArea::PaintArea(QWidget *parent) :
QWidget(parent)
PaintArea::PaintArea(QWidget *parent) : QWidget(parent)
{
setAttribute(Qt::WA_StaticContents);
setAttribute(Qt::WA_OpaquePaintEvent);

View File

@ -49,8 +49,8 @@
****************************************************************************/
#include "interfaces.h"
#include "plugindialog.h"
#include "interfaces.h"
#include <QDir>
#include <QGridLayout>

View File

@ -50,10 +50,10 @@
#include "basictoolsplugin.h"
#include <QInputDialog>
#include <QPainter>
#include <QRandomGenerator>
#include <QtMath>
#include <QtWidgets>
#include <stdlib.h>
//! [0]
QStringList BasicToolsPlugin::brushes() const

View File

@ -54,12 +54,12 @@
//! [0]
#include <interfaces.h>
#include <QRect>
#include <QObject>
#include <QtPlugin>
#include <QStringList>
#include <QPainterPath>
#include <QImage>
#include <QObject>
#include <QPainterPath>
#include <QRect>
#include <QStringList>
#include <QtPlugin>
//! [1]
class BasicToolsPlugin : public QObject,

View File

@ -50,10 +50,7 @@
#include "extrafiltersplugin.h"
#include <QtWidgets>
#include <math.h>
#include <stdlib.h>
#include <QInputDialog>
QStringList ExtraFiltersPlugin::filters() const
{

View File

@ -65,7 +65,7 @@ class RegExpDialog : public QDialog
Q_OBJECT
public:
RegExpDialog(QWidget *parent = 0);
RegExpDialog(QWidget *parent = nullptr);
private slots:
void refresh();

View File

@ -70,7 +70,7 @@ class RegularExpressionDialog : public QDialog
Q_OBJECT
public:
RegularExpressionDialog(QWidget *parent = 0);
RegularExpressionDialog(QWidget *parent = nullptr);
private:
void refresh();

View File

@ -48,10 +48,20 @@
**
****************************************************************************/
#include <QtWidgets>
#include "locationdialog.h"
#include <QBoxLayout>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QDir>
#include <QPushButton>
#include <QGroupBox>
#include <QHeaderView>
#include <QLabel>
#include <QLineEdit>
#include <QTableWidget>
#include <QTableWidgetItem>
LocationDialog::LocationDialog(QWidget *parent)
: QDialog(parent)
{
@ -91,8 +101,7 @@ LocationDialog::LocationDialog(QWidget *parent)
locationsGroupBox = new QGroupBox(tr("Setting Locations"));
QStringList labels;
labels << tr("Location") << tr("Access");
const QStringList labels{tr("Location"), tr("Access")};
locationsTable = new QTableWidget;
locationsTable->setSelectionMode(QAbstractItemView::SingleSelection);

View File

@ -68,7 +68,7 @@ class LocationDialog : public QDialog
Q_OBJECT
public:
LocationDialog(QWidget *parent = 0);
LocationDialog(QWidget *parent = nullptr);
QSettings::Format format() const;
QSettings::Scope scope() const;

View File

@ -48,15 +48,23 @@
**
****************************************************************************/
#include <QtWidgets>
#include "locationdialog.h"
#include "mainwindow.h"
#include "settingstree.h"
MainWindow::MainWindow()
: settingsTree(new SettingsTree)
, locationDialog(nullptr)
#include <QAction>
#include <QApplication>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QInputDialog>
#include <QLineEdit>
#include <QMenuBar>
#include <QMessageBox>
#include <QStandardPaths>
#include <QStatusBar>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
, settingsTree(new SettingsTree)
{
setCentralWidget(settingsTree);

View File

@ -68,7 +68,7 @@ class MainWindow : public QMainWindow
public:
typedef QSharedPointer<QSettings> SettingsPtr;
MainWindow();
MainWindow(QWidget *parent = nullptr);
private slots:
void openSettings();
@ -81,11 +81,11 @@ private:
void createActions();
void setSettingsObject(const SettingsPtr &settings);
SettingsTree *settingsTree;
LocationDialog *locationDialog;
QAction *refreshAct;
QAction *autoRefreshAct;
QAction *fallbacksAct;
SettingsTree *settingsTree = nullptr;
LocationDialog *locationDialog = nullptr;
QAction *refreshAct = nullptr;
QAction *autoRefreshAct = nullptr;
QAction *fallbacksAct = nullptr;
};
#endif

View File

@ -48,20 +48,20 @@
**
****************************************************************************/
#include <QtWidgets>
#include "settingstree.h"
#include "variantdelegate.h"
#include <QApplication>
#include <QDesktopWidget>
#include <QHeaderView>
#include <QSettings>
SettingsTree::SettingsTree(QWidget *parent)
: QTreeWidget(parent)
, autoRefresh(false)
{
setItemDelegate(new VariantDelegate(this));
QStringList labels;
labels << tr("Setting") << tr("Type") << tr("Value");
setHeaderLabels(labels);
setHeaderLabels({tr("Setting"), tr("Type"), tr("Value")});
header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(2, QHeaderView::Stretch);
@ -77,10 +77,6 @@ SettingsTree::SettingsTree(QWidget *parent)
connect(&refreshTimer, &QTimer::timeout, this, &SettingsTree::maybeRefresh);
}
SettingsTree::~SettingsTree()
{
}
void SettingsTree::setSettingsObject(const SettingsPtr &newSettings)
{
settings = newSettings;
@ -137,7 +133,7 @@ void SettingsTree::refresh()
this, &SettingsTree::updateSetting);
settings->sync();
updateChildItems(0);
updateChildItems(nullptr);
connect(this, &QTreeWidget::itemChanged,
this, &SettingsTree::updateSetting);
@ -228,7 +224,7 @@ void SettingsTree::updateChildItems(QTreeWidgetItem *parent)
QTreeWidgetItem *SettingsTree::createItem(const QString &text,
QTreeWidgetItem *parent, int index)
{
QTreeWidgetItem *after = 0;
QTreeWidgetItem *after = nullptr;
if (index != 0)
after = childAt(parent, index - 1);
@ -243,24 +239,18 @@ QTreeWidgetItem *SettingsTree::createItem(const QString &text,
return item;
}
QTreeWidgetItem *SettingsTree::childAt(QTreeWidgetItem *parent, int index)
QTreeWidgetItem *SettingsTree::childAt(QTreeWidgetItem *parent, int index) const
{
if (parent)
return parent->child(index);
else
return topLevelItem(index);
return (parent ? parent->child(index) : topLevelItem(index));
}
int SettingsTree::childCount(QTreeWidgetItem *parent)
int SettingsTree::childCount(QTreeWidgetItem *parent) const
{
if (parent)
return parent->childCount();
else
return topLevelItemCount();
return (parent ? parent->childCount() : topLevelItemCount());
}
int SettingsTree::findChild(QTreeWidgetItem *parent, const QString &text,
int startIndex)
int startIndex) const
{
for (int i = startIndex; i < childCount(parent); ++i) {
if (childAt(parent, i)->text(0) == text)

View File

@ -65,10 +65,9 @@ class SettingsTree : public QTreeWidget
Q_OBJECT
public:
typedef QSharedPointer<QSettings> SettingsPtr;
using SettingsPtr = QSharedPointer<QSettings>;
SettingsTree(QWidget *parent = 0);
~SettingsTree();
SettingsTree(QWidget *parent = nullptr);
void setSettingsObject(const SettingsPtr &settings);
QSize sizeHint() const override;
@ -89,16 +88,16 @@ private:
void updateChildItems(QTreeWidgetItem *parent);
QTreeWidgetItem *createItem(const QString &text, QTreeWidgetItem *parent,
int index);
QTreeWidgetItem *childAt(QTreeWidgetItem *parent, int index);
int childCount(QTreeWidgetItem *parent);
int findChild(QTreeWidgetItem *parent, const QString &text, int startIndex);
QTreeWidgetItem *childAt(QTreeWidgetItem *parent, int index) const;
int childCount(QTreeWidgetItem *parent) const;
int findChild(QTreeWidgetItem *parent, const QString &text, int startIndex) const;
void moveItemForward(QTreeWidgetItem *parent, int oldIndex, int newIndex);
SettingsPtr settings;
QTimer refreshTimer;
bool autoRefresh;
QIcon groupIcon;
QIcon keyIcon;
bool autoRefresh = false;
};
#endif

View File

@ -48,12 +48,14 @@
**
****************************************************************************/
#include <QtWidgets>
#include "variantdelegate.h"
#include <QDateTime>
#include <QLineEdit>
#include <QRegularExpressionValidator>
VariantDelegate::VariantDelegate(QObject *parent)
: QItemDelegate(parent)
: QStyledItemDelegate(parent)
{
boolExp.setPattern("true|false");
boolExp.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
@ -82,12 +84,12 @@ void VariantDelegate::paint(QPainter *painter,
if (!isSupportedType(value.type())) {
QStyleOptionViewItem myOption = option;
myOption.state &= ~QStyle::State_Enabled;
QItemDelegate::paint(painter, myOption, index);
QStyledItemDelegate::paint(painter, myOption, index);
return;
}
}
QItemDelegate::paint(painter, option, index);
QStyledItemDelegate::paint(painter, option, index);
}
QWidget *VariantDelegate::createEditor(QWidget *parent,
@ -95,11 +97,11 @@ QWidget *VariantDelegate::createEditor(QWidget *parent,
const QModelIndex &index) const
{
if (index.column() != 2)
return 0;
return nullptr;
QVariant originalValue = index.model()->data(index, Qt::UserRole);
if (!isSupportedType(originalValue.type()))
return 0;
return nullptr;
QLineEdit *lineEdit = new QLineEdit(parent);
lineEdit->setFrame(false);
@ -149,7 +151,7 @@ QWidget *VariantDelegate::createEditor(QWidget *parent,
regExp = unsignedIntegerExp;
break;
default:
;
break;
}
if (regExp.isValid()) {

View File

@ -51,15 +51,15 @@
#ifndef VARIANTDELEGATE_H
#define VARIANTDELEGATE_H
#include <QItemDelegate>
#include <QStyledItemDelegate>
#include <QRegularExpression>
class VariantDelegate : public QItemDelegate
class VariantDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
VariantDelegate(QObject *parent = 0);
VariantDelegate(QObject *parent = nullptr);
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;

Some files were not shown because too many files have changed in this diff Show More