Merge remote-tracking branch 'origin/dev' into wip/cmake

Change-Id: I4a78428a8ea273b6960792e3b8043f816fa37fcf
This commit is contained in:
Alexandru Croitor 2019-10-14 17:46:16 +02:00
commit 440286655e
893 changed files with 28164 additions and 21419 deletions

View File

@ -132,6 +132,23 @@ attribute_target("rdrnd") int test_rdrnd()
} }
#endif #endif
#if T(RDSEED)
attribute_target("rdseed") int test_rdseed()
{
unsigned short us;
unsigned int ui;
if (_rdseed16_step(&us))
return 1;
if (_rdseed32_step(&ui))
return 1;
# if defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64)
unsigned long long ull;
if (_rdseed64_step(&ull))
return 1;
# endif
}
#endif
#if T(SHANI) #if T(SHANI)
attribute_target("sha") void test_shani() attribute_target("sha") void test_shani()
{ {

View File

@ -38,8 +38,7 @@ except -sysconfdir should be located under -prefix/-hostprefix:
-plugindir <dir> ...... Plugins [ARCHDATADIR/plugins] -plugindir <dir> ...... Plugins [ARCHDATADIR/plugins]
-libexecdir <dir> ..... Helper programs [ARCHDATADIR/bin on Windows, -libexecdir <dir> ..... Helper programs [ARCHDATADIR/bin on Windows,
ARCHDATADIR/libexec otherwise] ARCHDATADIR/libexec otherwise]
-importdir <dir> ...... QML1 imports [ARCHDATADIR/imports] -qmldir <dir> ......... QML imports [ARCHDATADIR/qml]
-qmldir <dir> ......... QML2 imports [ARCHDATADIR/qml]
-datadir <dir> ........ Arch-independent data [PREFIX] -datadir <dir> ........ Arch-independent data [PREFIX]
-docdir <dir> ......... Documentation [DATADIR/doc] -docdir <dir> ......... Documentation [DATADIR/doc]
-translationdir <dir> . Translations [DATADIR/translations] -translationdir <dir> . Translations [DATADIR/translations]
@ -281,6 +280,7 @@ Gui, printing, widget options:
es2 (default on Windows), desktop (default on Unix), es2 (default on Windows), desktop (default on Unix),
dynamic (Windows only) dynamic (Windows only)
-opengles3 ........... Enable OpenGL ES 3.x support instead of ES 2.x [auto] -opengles3 ........... Enable OpenGL ES 3.x support instead of ES 2.x [auto]
-egl ................. Enable EGL support [auto]
-angle ............... Use bundled ANGLE to support OpenGL ES 2.0 [auto] -angle ............... Use bundled ANGLE to support OpenGL ES 2.0 [auto]
(Windows only) (Windows only)
-combined-angle-lib .. Merge LibEGL and LibGLESv2 into LibANGLE (Windows only) -combined-angle-lib .. Merge LibEGL and LibGLESv2 into LibANGLE (Windows only)

1
configure vendored
View File

@ -497,7 +497,6 @@ while [ "$#" -gt 0 ]; do
-docdir| \ -docdir| \
-headerdir| \ -headerdir| \
-plugindir| \ -plugindir| \
-importdir| \
-qmldir| \ -qmldir| \
-archdatadir| \ -archdatadir| \
-datadir| \ -datadir| \

View File

@ -40,7 +40,6 @@
"hostbindir": "string", "hostbindir": "string",
"hostdatadir": "string", "hostdatadir": "string",
"hostlibdir": "string", "hostlibdir": "string",
"importdir": "string",
"libdir": "string", "libdir": "string",
"libexecdir": "string", "libexecdir": "string",
"plugindir": "string", "plugindir": "string",
@ -222,6 +221,21 @@
{ "type": "pkgConfig", "args": "libudev" }, { "type": "pkgConfig", "args": "libudev" },
"-ludev" "-ludev"
] ]
},
"libdl": {
"label": "dlopen()",
"test": {
"main": [
"dlclose(dlopen(0, 0));",
"dlsym(RTLD_DEFAULT, 0);",
"dlerror();"
]
},
"headers": "dlfcn.h",
"sources": [
"",
"-ldl"
]
} }
}, },
@ -321,13 +335,13 @@
"qmake": "CONFIG += c++11 c++14" "qmake": "CONFIG += c++11 c++14"
} }
}, },
"c++1z": { "c++17": {
"label": "C++17 support", "label": "C++17 support",
"type": "compile", "type": "compile",
"test": { "test": {
"head": [ "head": [
"#if __cplusplus > 201402L", "#if __cplusplus > 201402L",
"// Compiler claims to support experimental C++1z, trust it", "// Compiler claims to support C++17, trust it",
"#else", "#else",
"# error __cplusplus must be > 201402L (the value for C++14)", "# error __cplusplus must be > 201402L (the value for C++14)",
"#endif", "#endif",
@ -339,7 +353,7 @@
"int i = std::get<int>(v);", "int i = std::get<int>(v);",
"std::visit([](const auto &) { return 1; }, v);" "std::visit([](const auto &) { return 1; }, v);"
], ],
"qmake": "CONFIG += c++11 c++14 c++1z" "qmake": "CONFIG += c++11 c++14 c++17"
} }
}, },
"c++2a": { "c++2a": {
@ -353,7 +367,7 @@
"# error __cplusplus must be > 201703L (the value for C++17)", "# error __cplusplus must be > 201703L (the value for C++17)",
"#endif" "#endif"
], ],
"qmake": "CONFIG += c++11 c++14 c++1z c++2a" "qmake": "CONFIG += c++11 c++14 c++17 c++2a"
} }
}, },
"precompile_header": { "precompile_header": {
@ -469,6 +483,17 @@
] ]
} }
}, },
"signaling_nan": {
"label": "Signaling NaN for doubles",
"type": "compile",
"test": {
"head": [ "#include <limits>" ],
"main": [
"using B = std::numeric_limits<double>;",
"static_assert(B::has_signaling_NaN, \"System lacks signaling NaN\");"
]
}
},
"sse2": { "sse2": {
"label": "SSE2 instructions", "label": "SSE2 instructions",
"type": "x86Simd" "type": "x86Simd"
@ -501,6 +526,10 @@
"label": "RDRAND instruction", "label": "RDRAND instruction",
"type": "x86Simd" "type": "x86Simd"
}, },
"rdseed": {
"label": "RDSEED instruction",
"type": "x86Simd"
},
"shani": { "shani": {
"label": "SHA new instructions", "label": "SHA new instructions",
"type": "x86Simd" "type": "x86Simd"
@ -751,7 +780,7 @@
"debug_and_release": { "debug_and_release": {
"label": "Compile libs in debug and release mode", "label": "Compile libs in debug and release mode",
"autoDetect": "input.debug == ''", "autoDetect": "input.debug == ''",
"condition": "config.darwin || config.win32", "condition": "config.darwin || (config.win32 && !config.gcc)",
"output": [ "publicFeature", "publicQtConfig", "debugAndRelease" ] "output": [ "publicFeature", "publicQtConfig", "debugAndRelease" ]
}, },
"force_debug_info": { "force_debug_info": {
@ -792,6 +821,7 @@
"rpath": { "rpath": {
"label": "Build with RPATH", "label": "Build with RPATH",
"autoDetect": "var.QMAKE_LFLAGS_RPATH != '' && features.shared", "autoDetect": "var.QMAKE_LFLAGS_RPATH != '' && features.shared",
"condition": "!config.android",
"output": [ "publicFeature", "publicQtConfig" ] "output": [ "publicFeature", "publicQtConfig" ]
}, },
"rpath_dir": { "rpath_dir": {
@ -924,15 +954,20 @@
"condition": "features.c++11 && tests.c++14", "condition": "features.c++11 && tests.c++14",
"output": [ "publicFeature", "publicQtConfig" ] "output": [ "publicFeature", "publicQtConfig" ]
}, },
"c++17": {
"label": "C++17",
"condition": "features.c++14 && tests.c++17",
"output": [ "publicFeature", "publicQtConfig" ]
},
"c++1z": { "c++1z": {
"label": "C++17", "label": "C++17",
"condition": "features.c++14 && tests.c++1z", "condition": "features.c++17",
"output": [ "publicFeature", "publicQtConfig" ] "output": [ "publicFeature", "publicQtConfig" ]
}, },
"c++2a": { "c++2a": {
"label": "C++2a", "label": "C++2a",
"autoDetect": false, "autoDetect": false,
"condition": "features.c++1z && tests.c++2a", "condition": "features.c++17 && tests.c++2a",
"output": [ "publicFeature", "publicQtConfig" ] "output": [ "publicFeature", "publicQtConfig" ]
}, },
"c89": { "c89": {
@ -990,6 +1025,11 @@
{ "type": "define", "name": "QT_REDUCE_RELOCATIONS" } { "type": "define", "name": "QT_REDUCE_RELOCATIONS" }
] ]
}, },
"signaling_nan": {
"label": "Signaling NaN",
"condition": "tests.signaling_nan",
"output": [ "publicFeature" ]
},
"sse2": { "sse2": {
"label": "SSE2", "label": "SSE2",
"condition": "(arch.i386 || arch.x86_64) && tests.sse2", "condition": "(arch.i386 || arch.x86_64) && tests.sse2",
@ -1144,6 +1184,14 @@
{ "type": "define", "name": "QT_COMPILER_SUPPORTS_RDRND", "value": 1 } { "type": "define", "name": "QT_COMPILER_SUPPORTS_RDRND", "value": 1 }
] ]
}, },
"rdseed": {
"label": "RDSEED",
"condition": "tests.rdseed",
"output": [
"privateConfig",
{ "type": "define", "name": "QT_COMPILER_SUPPORTS_RDSEED", "value": 1 }
]
},
"shani": { "shani": {
"label": "SHA", "label": "SHA",
"condition": "features.sse2 && tests.shani", "condition": "features.sse2 && tests.shani",
@ -1340,6 +1388,17 @@
"autoDetect": false, "autoDetect": false,
"condition": "!features.shared", "condition": "!features.shared",
"output": [ "publicConfig", "publicQtConfig" ] "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" ]
} }
}, },
@ -1438,7 +1497,7 @@
{ {
"message": "Using C++ standard", "message": "Using C++ standard",
"type": "firstAvailableFeature", "type": "firstAvailableFeature",
"args": "c++2a c++1z c++14 c++11" "args": "c++2a c++17 c++14 c++11"
}, },
{ {
"type": "feature", "type": "feature",
@ -1461,6 +1520,7 @@
"args": "enable_gdb_index", "args": "enable_gdb_index",
"condition": "config.gcc && !config.clang && (features.debug || features.force_debug_info || features.debug_and_release)" "condition": "config.gcc && !config.clang && (features.debug || features.force_debug_info || features.debug_and_release)"
}, },
"relocatable",
"precompile_header", "precompile_header",
"ltcg", "ltcg",
{ {

View File

@ -699,7 +699,6 @@ defineReplace(printInstallPaths) {
$$printInstallPath(LibraryExecutables, libexecdir, $$DEFAULT_LIBEXEC) \ $$printInstallPath(LibraryExecutables, libexecdir, $$DEFAULT_LIBEXEC) \
$$printInstallPath(Binaries, bindir, bin) \ $$printInstallPath(Binaries, bindir, bin) \
$$printInstallPath(Plugins, plugindir, plugins) \ $$printInstallPath(Plugins, plugindir, plugins) \
$$printInstallPath(Imports, importdir, imports) \
$$printInstallPath(Qml2Imports, qmldir, qml) \ $$printInstallPath(Qml2Imports, qmldir, qml) \
$$printInstallPath(ArchData, archdatadir, .) \ $$printInstallPath(ArchData, archdatadir, .) \
$$printInstallPath(Data, datadir, .) \ $$printInstallPath(Data, datadir, .) \
@ -763,6 +762,11 @@ defineTest(qtConfOutput_preparePaths) {
have_hostprefix = true have_hostprefix = true
} }
equals(config.input.prefix, $$config.input.extprefix): \
qmake_crossbuild = false
else: \
qmake_crossbuild = true
PREFIX_COMPLAINTS = PREFIX_COMPLAINTS =
PREFIX_REMINDER = false PREFIX_REMINDER = false
win32: \ win32: \
@ -789,7 +793,6 @@ defineTest(qtConfOutput_preparePaths) {
archdata_pfx = $$config.rel_input.archdatadir/ archdata_pfx = $$config.rel_input.archdatadir/
processQtPath("", libexecdir, $${archdata_pfx}$$DEFAULT_LIBEXEC) processQtPath("", libexecdir, $${archdata_pfx}$$DEFAULT_LIBEXEC)
processQtPath("", plugindir, $${archdata_pfx}plugins) processQtPath("", plugindir, $${archdata_pfx}plugins)
processQtPath("", importdir, $${archdata_pfx}imports)
processQtPath("", qmldir, $${archdata_pfx}qml) processQtPath("", qmldir, $${archdata_pfx}qml)
processQtPath("", sysconfdir, $$DEFAULT_SYSCONFDIR) processQtPath("", sysconfdir, $$DEFAULT_SYSCONFDIR)
$$have_hostprefix { $$have_hostprefix {
@ -802,6 +805,18 @@ defineTest(qtConfOutput_preparePaths) {
processQtPath(host, hostdatadir, $$config.rel_input.archdatadir) 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) { !isEmpty(PREFIX_COMPLAINTS) {
PREFIX_COMPLAINTS = "$$join(PREFIX_COMPLAINTS, "$$escape_expand(\\n)Note: ")" PREFIX_COMPLAINTS = "$$join(PREFIX_COMPLAINTS, "$$escape_expand(\\n)Note: ")"
$$PREFIX_REMINDER: \ $$PREFIX_REMINDER: \
@ -821,7 +836,6 @@ defineTest(qtConfOutput_preparePaths) {
addConfStr($$config.rel_input.libexecdir) addConfStr($$config.rel_input.libexecdir)
addConfStr($$config.rel_input.bindir) addConfStr($$config.rel_input.bindir)
addConfStr($$config.rel_input.plugindir) addConfStr($$config.rel_input.plugindir)
addConfStr($$config.rel_input.importdir)
addConfStr($$config.rel_input.qmldir) addConfStr($$config.rel_input.qmldir)
addConfStr($$config.rel_input.archdatadir) addConfStr($$config.rel_input.archdatadir)
addConfStr($$config.rel_input.datadir) addConfStr($$config.rel_input.datadir)
@ -843,9 +857,6 @@ defineTest(qtConfOutput_preparePaths) {
addConfStr($$[QMAKE_SPEC]) addConfStr($$[QMAKE_SPEC])
$${currentConfig}.output.qconfigSource = \ $${currentConfig}.output.qconfigSource = \
"/* Installation date */" \
"static const char qt_configure_installation [12+11] = \"qt_instdate=2012-12-20\";" \
"" \
"/* Installation Info */" \ "/* Installation Info */" \
"static const char qt_configure_prefix_path_str [12+256] = \"qt_prfxpath=$$config.input.prefix\";" \ "static const char qt_configure_prefix_path_str [12+256] = \"qt_prfxpath=$$config.input.prefix\";" \
"$${LITERAL_HASH}ifdef QT_BUILD_QMAKE" \ "$${LITERAL_HASH}ifdef QT_BUILD_QMAKE" \
@ -867,9 +878,13 @@ defineTest(qtConfOutput_preparePaths) {
";" \ ";" \
"" \ "" \
"$${LITERAL_HASH}define QT_CONFIGURE_SETTINGS_PATH \"$$config.rel_input.sysconfdir\"" \ "$${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}ifdef QT_BUILD_QMAKE" \
"$${LITERAL_HASH} define QT_CONFIGURE_SYSROOTIFY_PREFIX $$qmake_sysrootify" \ "$${LITERAL_HASH} define QT_CONFIGURE_SYSROOTIFY_PREFIX $$qmake_sysrootify" \
"$${LITERAL_HASH} define QT_CONFIGURE_CROSSBUILD $$qmake_crossbuild" \
"$${LITERAL_HASH}endif" \ "$${LITERAL_HASH}endif" \
"" \ "" \
"$${LITERAL_HASH}define QT_CONFIGURE_PREFIX_PATH qt_configure_prefix_path_str + 12" \ "$${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 TEMPLATE = aux
global_docs.files = $$PWD/global global_docs.files = \
$$PWD/global \
$$PWD/config
global_docs.path = $$[QT_INSTALL_DOCS] global_docs.path = $$[QT_INSTALL_DOCS]
INSTALLS += global_docs INSTALLS += global_docs
!prefix_build:!equals(OUT_PWD, $$PWD): \ !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/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the documentation of the Qt Toolkit. ** 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 \externalpage http://doc.qt.io/qtcreator/creator-quick-tour.html
\title Qt Creator: User Interface \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 \externalpage http://doc.qt.io/qtcreator/creator-cli.html
\title Qt Creator: Using Command Line Options \title Qt Creator: Using Command Line Options
@ -125,7 +137,7 @@
\externalpage http://doc.qt.io/qtcreator/quick-signals.html \externalpage http://doc.qt.io/qtcreator/quick-signals.html
\title Qt Creator: Connecting Objects to Signals \title Qt Creator: Connecting Objects to Signals
*/ */
* /*! /*!
\externalpage http://doc.qt.io/qtcreator/quick-dynamic-properties.html \externalpage http://doc.qt.io/qtcreator/quick-dynamic-properties.html
\title Qt Creator: Specifying Dynamic Properties \title Qt Creator: Specifying Dynamic Properties
*/ */
@ -153,6 +165,10 @@
\externalpage http://doc.qt.io/qtcreator/creator-qml-modules-with-plugins.html \externalpage http://doc.qt.io/qtcreator/creator-qml-modules-with-plugins.html
\title Qt Creator: Using QML Modules with Plugins \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 \externalpage http://doc.qt.io/qtcreator/creator-visual-editor.html
\title Qt Creator: Developing Qt Quick Applications \title Qt Creator: Developing Qt Quick Applications
@ -553,6 +569,10 @@
\externalpage http://doc.qt.io/qtcreator/creator-cpu-usage-analyzer.html \externalpage http://doc.qt.io/qtcreator/creator-cpu-usage-analyzer.html
\title Qt Creator: Analyzing CPU Usage \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 \externalpage http://doc.qt.io/qtcreator/creator-autotest.html
\title Qt Creator: Running Autotests \title Qt Creator: Running Autotests
@ -581,3 +601,27 @@
\externalpage http://doc.qt.io/qtcreator/creator-scxml.html \externalpage http://doc.qt.io/qtcreator/creator-scxml.html
\title Qt Creator: Editing State Charts \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

@ -98,7 +98,7 @@ public:
QPoint delta; QPoint delta;
QPoint speed; QPoint speed;
FlickableTicker *ticker; FlickableTicker *ticker;
QTime timeStamp; QElapsedTimer timeStamp;
QWidget *target; QWidget *target;
QList<QEvent*> ignoreList; QList<QEvent*> ignoreList;
}; };
@ -109,7 +109,7 @@ Flickable::Flickable()
d->state = FlickablePrivate::Steady; d->state = FlickablePrivate::Steady;
d->threshold = 10; d->threshold = 10;
d->ticker = new FlickableTicker(this); d->ticker = new FlickableTicker(this);
d->timeStamp = QTime::currentTime(); d->timeStamp.start();
d->target = 0; d->target = 0;
} }
@ -208,7 +208,7 @@ void Flickable::handleMouseRelease(QMouseEvent *event)
event->accept(); event->accept();
delta = event->pos() - d->pressPos; delta = event->pos() - d->pressPos;
if (d->timeStamp.elapsed() > 100) { if (d->timeStamp.elapsed() > 100) {
d->timeStamp = QTime::currentTime(); d->timeStamp.start();
d->speed = delta - d->delta; d->speed = delta - d->delta;
d->delta = delta; d->delta = delta;
} }
@ -253,7 +253,7 @@ void Flickable::handleMouseMove(QMouseEvent *event)
delta = event->pos() - d->pressPos; delta = event->pos() - d->pressPos;
if (delta.x() > d->threshold || delta.x() < -d->threshold || if (delta.x() > d->threshold || delta.x() < -d->threshold ||
delta.y() > d->threshold || delta.y() < -d->threshold) { delta.y() > d->threshold || delta.y() < -d->threshold) {
d->timeStamp = QTime::currentTime(); d->timeStamp.start();
d->state = FlickablePrivate::ManualScroll; d->state = FlickablePrivate::ManualScroll;
d->delta = QPoint(0, 0); d->delta = QPoint(0, 0);
d->pressPos = event->pos(); d->pressPos = event->pos();
@ -266,7 +266,7 @@ void Flickable::handleMouseMove(QMouseEvent *event)
delta = event->pos() - d->pressPos; delta = event->pos() - d->pressPos;
setScrollOffset(d->offset - delta); setScrollOffset(d->offset - delta);
if (d->timeStamp.elapsed() > 100) { if (d->timeStamp.elapsed() > 100) {
d->timeStamp = QTime::currentTime(); d->timeStamp.start();
d->speed = delta - d->delta; d->speed = delta - d->delta;
d->delta = delta; d->delta = delta;
} }

View File

@ -92,7 +92,7 @@ public:
} }
void updatePlayer() { void updatePlayer() {
int interval = qBound(20, watch.elapsed(), 250); int interval = qBound(20ll, watch.elapsed(), 250ll);
watch.start(); watch.start();
angle += angleDelta * interval / 1000; angle += angleDelta * interval / 1000;
qreal step = moveDelta * interval / 1000; qreal step = moveDelta * interval / 1000;
@ -106,10 +106,10 @@ public:
} }
void showFps() { void showFps() {
static QTime frameTick; static QElapsedTimer frameTick;
static int totalFrame = 0; static int totalFrame = 0;
if (!(totalFrame & 31)) { if (!(totalFrame & 31)) {
int elapsed = frameTick.elapsed(); const qint64 elapsed = frameTick.elapsed();
frameTick.start(); frameTick.start();
int fps = 32 * 1000 / (1 + elapsed); int fps = 32 * 1000 / (1 + elapsed);
setWindowTitle(QString("Raycasting (%1 FPS)").arg(fps)); setWindowTitle(QString("Raycasting (%1 FPS)").arg(fps));
@ -355,7 +355,7 @@ protected:
} }
private: private:
QTime watch; QElapsedTimer watch;
QBasicTimer ticker; QBasicTimer ticker;
QImage buffer; QImage buffer;
qreal angle; qreal angle;

View File

@ -50,36 +50,30 @@
#include "openglwindow.h" #include "openglwindow.h"
#include <QtGui/QGuiApplication> #include <QGuiApplication>
#include <QtGui/QMatrix4x4> #include <QMatrix4x4>
#include <QtGui/QOpenGLShaderProgram> #include <QOpenGLShaderProgram>
#include <QtGui/QScreen> #include <QScreen>
#include <QtMath>
#include <QtCore/qmath.h>
//! [1] //! [1]
class TriangleWindow : public OpenGLWindow class TriangleWindow : public OpenGLWindow
{ {
public: public:
TriangleWindow(); using OpenGLWindow::OpenGLWindow;
void initialize() override; void initialize() override;
void render() override; void render() override;
private: private:
GLuint m_posAttr; GLint m_posAttr = 0;
GLuint m_colAttr; GLint m_colAttr = 0;
GLuint m_matrixUniform; GLint m_matrixUniform = 0;
QOpenGLShaderProgram *m_program; QOpenGLShaderProgram *m_program = nullptr;
int m_frame; int m_frame = 0;
}; };
TriangleWindow::TriangleWindow()
: m_program(0)
, m_frame(0)
{
}
//! [1] //! [1]
//! [2] //! [2]
@ -128,8 +122,11 @@ void TriangleWindow::initialize()
m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource); m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
m_program->link(); m_program->link();
m_posAttr = m_program->attributeLocation("posAttr"); m_posAttr = m_program->attributeLocation("posAttr");
Q_ASSERT(m_posAttr != -1);
m_colAttr = m_program->attributeLocation("colAttr"); m_colAttr = m_program->attributeLocation("colAttr");
Q_ASSERT(m_colAttr != -1);
m_matrixUniform = m_program->uniformLocation("matrix"); m_matrixUniform = m_program->uniformLocation("matrix");
Q_ASSERT(m_matrixUniform != -1);
} }
//! [4] //! [4]
@ -144,19 +141,19 @@ void TriangleWindow::render()
m_program->bind(); m_program->bind();
QMatrix4x4 matrix; QMatrix4x4 matrix;
matrix.perspective(60.0f, 4.0f/3.0f, 0.1f, 100.0f); matrix.perspective(60.0f, 4.0f / 3.0f, 0.1f, 100.0f);
matrix.translate(0, 0, -2); matrix.translate(0, 0, -2);
matrix.rotate(100.0f * m_frame / screen()->refreshRate(), 0, 1, 0); matrix.rotate(100.0f * m_frame / screen()->refreshRate(), 0, 1, 0);
m_program->setUniformValue(m_matrixUniform, matrix); m_program->setUniformValue(m_matrixUniform, matrix);
GLfloat vertices[] = { static const GLfloat vertices[] = {
0.0f, 0.707f, 0.0f, 0.707f,
-0.5f, -0.5f, -0.5f, -0.5f,
0.5f, -0.5f 0.5f, -0.5f
}; };
GLfloat colors[] = { static const GLfloat colors[] = {
1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f 0.0f, 0.0f, 1.0f
@ -165,13 +162,13 @@ void TriangleWindow::render()
glVertexAttribPointer(m_posAttr, 2, GL_FLOAT, GL_FALSE, 0, vertices); glVertexAttribPointer(m_posAttr, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glVertexAttribPointer(m_colAttr, 3, GL_FLOAT, GL_FALSE, 0, colors); glVertexAttribPointer(m_colAttr, 3, GL_FLOAT, GL_FALSE, 0, colors);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(m_posAttr);
glEnableVertexAttribArray(1); glEnableVertexAttribArray(m_colAttr);
glDrawArrays(GL_TRIANGLES, 0, 3); glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(1); glDisableVertexAttribArray(m_colAttr);
glDisableVertexAttribArray(0); glDisableVertexAttribArray(m_posAttr);
m_program->release(); m_program->release();

View File

@ -50,18 +50,13 @@
#include "openglwindow.h" #include "openglwindow.h"
#include <QtCore/QCoreApplication> #include <QOpenGLContext>
#include <QOpenGLPaintDevice>
#include <QtGui/QOpenGLContext> #include <QPainter>
#include <QtGui/QOpenGLPaintDevice>
#include <QtGui/QPainter>
//! [1] //! [1]
OpenGLWindow::OpenGLWindow(QWindow *parent) OpenGLWindow::OpenGLWindow(QWindow *parent)
: QWindow(parent) : QWindow(parent)
, m_animating(false)
, m_context(0)
, m_device(0)
{ {
setSurfaceType(QWindow::OpenGLSurface); setSurfaceType(QWindow::OpenGLSurface);
} }

View File

@ -48,8 +48,8 @@
** **
****************************************************************************/ ****************************************************************************/
#include <QtGui/QWindow> #include <QWindow>
#include <QtGui/QOpenGLFunctions> #include <QOpenGLFunctions>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QPainter; class QPainter;
@ -62,7 +62,7 @@ class OpenGLWindow : public QWindow, protected QOpenGLFunctions
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit OpenGLWindow(QWindow *parent = 0); explicit OpenGLWindow(QWindow *parent = nullptr);
~OpenGLWindow(); ~OpenGLWindow();
virtual void render(QPainter *painter); virtual void render(QPainter *painter);
@ -82,10 +82,10 @@ protected:
void exposeEvent(QExposeEvent *event) override; void exposeEvent(QExposeEvent *event) override;
private: private:
bool m_animating; bool m_animating = false;
QOpenGLContext *m_context; QOpenGLContext *m_context = nullptr;
QOpenGLPaintDevice *m_device; QOpenGLPaintDevice *m_device = nullptr;
}; };
//! [1] //! [1]

View File

@ -73,15 +73,6 @@
#endif #endif
GLWindow::GLWindow() GLWindow::GLWindow()
: m_texImageInput(0),
m_texImageTmp(0),
m_texImageProcessed(0),
m_shaderDisplay(0),
m_shaderComputeV(0),
m_shaderComputeH(0),
m_blurRadius(0.0f),
m_animate(true),
m_vao(0)
{ {
const float animationStart = 0.0; const float animationStart = 0.0;
const float animationEnd = 10.0; const float animationEnd = 10.0;
@ -324,27 +315,18 @@ void GLWindow::initializeGL()
<< ((ctx->format().renderableType() == QSurfaceFormat::OpenGLES) ? (" GLES") : (" GL")) << ((ctx->format().renderableType() == QSurfaceFormat::OpenGLES) ? (" GLES") : (" GL"))
<< " context"; << " context";
if (m_texImageInput) {
delete m_texImageInput;
m_texImageInput = 0;
}
QImage img(":/Qt-logo-medium.png"); QImage img(":/Qt-logo-medium.png");
Q_ASSERT(!img.isNull()); Q_ASSERT(!img.isNull());
delete m_texImageInput;
m_texImageInput = new QOpenGLTexture(img.convertToFormat(QImage::Format_RGBA8888).mirrored()); m_texImageInput = new QOpenGLTexture(img.convertToFormat(QImage::Format_RGBA8888).mirrored());
if (m_texImageTmp) { delete m_texImageTmp;
delete m_texImageTmp;
m_texImageTmp = 0;
}
m_texImageTmp = new QOpenGLTexture(QOpenGLTexture::Target2D); m_texImageTmp = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_texImageTmp->setFormat(m_texImageInput->format()); m_texImageTmp->setFormat(m_texImageInput->format());
m_texImageTmp->setSize(m_texImageInput->width(),m_texImageInput->height()); m_texImageTmp->setSize(m_texImageInput->width(),m_texImageInput->height());
m_texImageTmp->allocateStorage(QOpenGLTexture::RGBA,QOpenGLTexture::UInt8); // WTF? m_texImageTmp->allocateStorage(QOpenGLTexture::RGBA,QOpenGLTexture::UInt8); // WTF?
if (m_texImageProcessed) { delete m_texImageProcessed;
delete m_texImageProcessed;
m_texImageProcessed = 0;
}
m_texImageProcessed = new QOpenGLTexture(QOpenGLTexture::Target2D); m_texImageProcessed = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_texImageProcessed->setFormat(m_texImageInput->format()); m_texImageProcessed->setFormat(m_texImageInput->format());
m_texImageProcessed->setSize(m_texImageInput->width(),m_texImageInput->height()); m_texImageProcessed->setSize(m_texImageInput->width(),m_texImageInput->height());
@ -354,10 +336,7 @@ void GLWindow::initializeGL()
m_texImageProcessed->setMinificationFilter(QOpenGLTexture::Linear); m_texImageProcessed->setMinificationFilter(QOpenGLTexture::Linear);
m_texImageProcessed->setWrapMode(QOpenGLTexture::ClampToEdge); m_texImageProcessed->setWrapMode(QOpenGLTexture::ClampToEdge);
if (m_shaderDisplay) { delete m_shaderDisplay;
delete m_shaderDisplay;
m_shaderDisplay = 0;
}
m_shaderDisplay = new QOpenGLShaderProgram; m_shaderDisplay = new QOpenGLShaderProgram;
// Prepend the correct version directive to the sources. The rest is the // Prepend the correct version directive to the sources. The rest is the
// same, thanks to the common GLSL syntax. // same, thanks to the common GLSL syntax.
@ -365,18 +344,12 @@ void GLWindow::initializeGL()
m_shaderDisplay->addShaderFromSourceCode(QOpenGLShader::Fragment, versionedShaderCode(fsDisplaySource)); m_shaderDisplay->addShaderFromSourceCode(QOpenGLShader::Fragment, versionedShaderCode(fsDisplaySource));
m_shaderDisplay->link(); m_shaderDisplay->link();
if (m_shaderComputeV) { delete m_shaderComputeV;
delete m_shaderComputeV;
m_shaderComputeV = 0;
}
m_shaderComputeV = new QOpenGLShaderProgram; m_shaderComputeV = new QOpenGLShaderProgram;
m_shaderComputeV->addShaderFromSourceCode(QOpenGLShader::Compute, versionedShaderCode(csComputeSourceV)); m_shaderComputeV->addShaderFromSourceCode(QOpenGLShader::Compute, versionedShaderCode(csComputeSourceV));
m_shaderComputeV->link(); m_shaderComputeV->link();
if (m_shaderComputeH) { delete m_shaderComputeH;
delete m_shaderComputeH;
m_shaderComputeH = 0;
}
m_shaderComputeH = new QOpenGLShaderProgram; m_shaderComputeH = new QOpenGLShaderProgram;
m_shaderComputeH->addShaderFromSourceCode(QOpenGLShader::Compute, versionedShaderCode(csComputeSourceH)); m_shaderComputeH->addShaderFromSourceCode(QOpenGLShader::Compute, versionedShaderCode(csComputeSourceH));
m_shaderComputeH->link(); m_shaderComputeH->link();

View File

@ -90,21 +90,21 @@ protected:
void setAnimating(bool animate); void setAnimating(bool animate);
private: private:
QPropertyAnimation *m_animationForward; QPropertyAnimation *m_animationForward = nullptr;
QPropertyAnimation *m_animationBackward; QPropertyAnimation *m_animationBackward = nullptr;
QSequentialAnimationGroup *m_animationGroup; QSequentialAnimationGroup *m_animationGroup;
QOpenGLTexture *m_texImageInput; QOpenGLTexture *m_texImageInput = nullptr;
QOpenGLTexture *m_texImageTmp; QOpenGLTexture *m_texImageTmp = nullptr;
QOpenGLTexture *m_texImageProcessed; QOpenGLTexture *m_texImageProcessed = nullptr;
QOpenGLShaderProgram *m_shaderDisplay; QOpenGLShaderProgram *m_shaderDisplay = nullptr;
QOpenGLShaderProgram *m_shaderComputeV; QOpenGLShaderProgram *m_shaderComputeV = nullptr;
QOpenGLShaderProgram *m_shaderComputeH; QOpenGLShaderProgram *m_shaderComputeH = nullptr;
QMatrix4x4 m_proj; QMatrix4x4 m_proj;
QSizeF m_quadSize; QSizeF m_quadSize;
int m_blurRadius; int m_blurRadius = 0;
bool m_animate; bool m_animate = true;
QOpenGLVertexArrayObject *m_vao; QOpenGLVertexArrayObject *m_vao = nullptr;
}; };
#endif #endif

View File

@ -56,7 +56,7 @@
#include <QOpenGLFunctions> #include <QOpenGLFunctions>
RenderWindow::RenderWindow(const QSurfaceFormat &format) RenderWindow::RenderWindow(const QSurfaceFormat &format)
: m_context(0), : m_context(nullptr),
m_initialized(false), m_initialized(false),
m_forceGLSL110(false), m_forceGLSL110(false),
m_angle(0.0f) m_angle(0.0f)
@ -67,7 +67,7 @@ RenderWindow::RenderWindow(const QSurfaceFormat &format)
m_context->setFormat(requestedFormat()); m_context->setFormat(requestedFormat());
if (!m_context->create()) { if (!m_context->create()) {
delete m_context; delete m_context;
m_context = 0; m_context = nullptr;
} }
} }

View File

@ -64,7 +64,7 @@ class Widget : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit Widget(QWidget *parent = 0); explicit Widget(QWidget *parent = nullptr);
private slots: private slots:
void start(); void start();

View File

@ -174,6 +174,6 @@ void GeometryEngine::drawCubeGeometry(QOpenGLShaderProgram *program)
program->setAttributeBuffer(texcoordLocation, GL_FLOAT, offset, 2, sizeof(VertexData)); program->setAttributeBuffer(texcoordLocation, GL_FLOAT, offset, 2, sizeof(VertexData));
// Draw cube geometry using indices from VBO 1 // Draw cube geometry using indices from VBO 1
glDrawElements(GL_TRIANGLE_STRIP, 34, GL_UNSIGNED_SHORT, 0); glDrawElements(GL_TRIANGLE_STRIP, 34, GL_UNSIGNED_SHORT, nullptr);
} }
//! [2] //! [2]

View File

@ -52,15 +52,7 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <math.h> #include <cmath>
MainWidget::MainWidget(QWidget *parent) :
QOpenGLWidget(parent),
geometries(0),
texture(0),
angularSpeed(0)
{
}
MainWidget::~MainWidget() MainWidget::~MainWidget()
{ {

View File

@ -69,7 +69,7 @@ class MainWidget : public QOpenGLWidget, protected QOpenGLFunctions
Q_OBJECT Q_OBJECT
public: public:
explicit MainWidget(QWidget *parent = 0); using QOpenGLWidget::QOpenGLWidget;
~MainWidget(); ~MainWidget();
protected: protected:
@ -87,15 +87,15 @@ protected:
private: private:
QBasicTimer timer; QBasicTimer timer;
QOpenGLShaderProgram program; QOpenGLShaderProgram program;
GeometryEngine *geometries; GeometryEngine *geometries = nullptr;
QOpenGLTexture *texture; QOpenGLTexture *texture = nullptr;
QMatrix4x4 projection; QMatrix4x4 projection;
QVector2D mousePressPosition; QVector2D mousePressPosition;
QVector3D rotationAxis; QVector3D rotationAxis;
qreal angularSpeed; qreal angularSpeed = 0;
QQuaternion rotation; QQuaternion rotation;
}; };

View File

@ -57,11 +57,7 @@
bool GLWidget::m_transparent = false; bool GLWidget::m_transparent = false;
GLWidget::GLWidget(QWidget *parent) GLWidget::GLWidget(QWidget *parent)
: QOpenGLWidget(parent), : QOpenGLWidget(parent)
m_xRot(0),
m_yRot(0),
m_zRot(0),
m_program(0)
{ {
m_core = QSurfaceFormat::defaultFormat().profile() == QSurfaceFormat::CoreProfile; m_core = QSurfaceFormat::defaultFormat().profile() == QSurfaceFormat::CoreProfile;
// --transparent causes the clear color to be transparent. Therefore, on systems that // --transparent causes the clear color to be transparent. Therefore, on systems that
@ -133,7 +129,7 @@ void GLWidget::cleanup()
makeCurrent(); makeCurrent();
m_logoVbo.destroy(); m_logoVbo.destroy();
delete m_program; delete m_program;
m_program = 0; m_program = nullptr;
doneCurrent(); doneCurrent();
} }
@ -250,8 +246,10 @@ void GLWidget::setupVertexAttribs()
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
f->glEnableVertexAttribArray(0); f->glEnableVertexAttribArray(0);
f->glEnableVertexAttribArray(1); f->glEnableVertexAttribArray(1);
f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0); f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), reinterpret_cast<void *>(3 * sizeof(GLfloat))); nullptr);
f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
reinterpret_cast<void *>(3 * sizeof(GLfloat)));
m_logoVbo.release(); m_logoVbo.release();
} }

View File

@ -65,7 +65,7 @@ class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
Q_OBJECT Q_OBJECT
public: public:
GLWidget(QWidget *parent = 0); GLWidget(QWidget *parent = nullptr);
~GLWidget(); ~GLWidget();
static bool isTransparent() { return m_transparent; } static bool isTransparent() { return m_transparent; }
@ -96,18 +96,18 @@ private:
void setupVertexAttribs(); void setupVertexAttribs();
bool m_core; bool m_core;
int m_xRot; int m_xRot = 0;
int m_yRot; int m_yRot = 0;
int m_zRot; int m_zRot = 0;
QPoint m_lastPos; QPoint m_lastPos;
Logo m_logo; Logo m_logo;
QOpenGLVertexArrayObject m_vao; QOpenGLVertexArrayObject m_vao;
QOpenGLBuffer m_logoVbo; QOpenGLBuffer m_logoVbo;
QOpenGLShaderProgram *m_program; QOpenGLShaderProgram *m_program = nullptr;
int m_projMatrixLoc; int m_projMatrixLoc = 0;
int m_mvMatrixLoc; int m_mvMatrixLoc = 0;
int m_normalMatrixLoc; int m_normalMatrixLoc = 0;
int m_lightPosLoc; int m_lightPosLoc = 0;
QMatrix4x4 m_proj; QMatrix4x4 m_proj;
QMatrix4x4 m_camera; QMatrix4x4 m_camera;
QMatrix4x4 m_world; QMatrix4x4 m_world;

View File

@ -52,7 +52,6 @@
#include <qmath.h> #include <qmath.h>
Logo::Logo() Logo::Logo()
: m_count(0)
{ {
m_data.resize(2500 * 6); m_data.resize(2500 * 6);

View File

@ -69,7 +69,7 @@ private:
void add(const QVector3D &v, const QVector3D &n); void add(const QVector3D &v, const QVector3D &n);
QVector<GLfloat> m_data; QVector<GLfloat> m_data;
int m_count; int m_count = 0;
}; };
#endif // LOGO_H #endif // LOGO_H

View File

@ -72,5 +72,6 @@ void MainWindow::onAddNew()
if (!centralWidget()) if (!centralWidget())
setCentralWidget(new Window(this)); setCentralWidget(new Window(this));
else else
QMessageBox::information(0, tr("Cannot add new window"), tr("Already occupied. Undock first.")); QMessageBox::information(nullptr, tr("Cannot add new window"),
tr("Already occupied. Undock first."));
} }

View File

@ -121,7 +121,7 @@ void Window::keyPressEvent(QKeyEvent *e)
void Window::dockUndock() void Window::dockUndock()
{ {
if (parent()) { if (parent()) {
setParent(0); setParent(nullptr);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
move(QApplication::desktop()->width() / 2 - width() / 2, move(QApplication::desktop()->width() / 2 - width() / 2,
QApplication::desktop()->height() / 2 - height() / 2); QApplication::desktop()->height() / 2 - height() / 2);
@ -134,10 +134,12 @@ void Window::dockUndock()
dockBtn->setText(tr("Undock")); dockBtn->setText(tr("Undock"));
mainWindow->setCentralWidget(this); mainWindow->setCentralWidget(this);
} else { } else {
QMessageBox::information(0, tr("Cannot dock"), tr("Main window already closed")); QMessageBox::information(nullptr, tr("Cannot dock"),
tr("Main window already closed"));
} }
} else { } else {
QMessageBox::information(0, tr("Cannot dock"), tr("Main window already occupied")); QMessageBox::information(nullptr, tr("Cannot dock"),
tr("Main window already occupied"));
} }
} }
} }

View File

@ -57,19 +57,10 @@
#include <QOpenGLVertexArrayObject> #include <QOpenGLVertexArrayObject>
#include <QOpenGLExtraFunctions> #include <QOpenGLExtraFunctions>
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QPauseAnimation>
#include <QSequentialAnimationGroup> #include <QSequentialAnimationGroup>
#include <QTimer> #include <QTimer>
GLWindow::GLWindow() GLWindow::GLWindow()
: m_texture(0),
m_program(0),
m_vbo(0),
m_vao(0),
m_target(0, 0, -1),
m_uniformsDirty(true),
m_r(0),
m_r2(0)
{ {
m_world.setToIdentity(); m_world.setToIdentity();
m_world.translate(0, 0, -1); m_world.translate(0, 0, -1);
@ -197,18 +188,12 @@ void GLWindow::initializeGL()
{ {
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
if (m_texture) {
delete m_texture;
m_texture = 0;
}
QImage img(":/qtlogo.png"); QImage img(":/qtlogo.png");
Q_ASSERT(!img.isNull()); Q_ASSERT(!img.isNull());
delete m_texture;
m_texture = new QOpenGLTexture(img.scaled(32, 36).mirrored()); m_texture = new QOpenGLTexture(img.scaled(32, 36).mirrored());
if (m_program) { delete m_program;
delete m_program;
m_program = 0;
}
m_program = new QOpenGLShaderProgram; m_program = new QOpenGLShaderProgram;
// Prepend the correct version directive to the sources. The rest is the // Prepend the correct version directive to the sources. The rest is the
// same, thanks to the common GLSL syntax. // same, thanks to the common GLSL syntax.
@ -223,26 +208,21 @@ void GLWindow::initializeGL()
m_lightPosLoc = m_program->uniformLocation("lightPos"); m_lightPosLoc = m_program->uniformLocation("lightPos");
// Create a VAO. Not strictly required for ES 3, but it is for plain OpenGL. // Create a VAO. Not strictly required for ES 3, but it is for plain OpenGL.
if (m_vao) { delete m_vao;
delete m_vao;
m_vao = 0;
}
m_vao = new QOpenGLVertexArrayObject; m_vao = new QOpenGLVertexArrayObject;
if (m_vao->create()) if (m_vao->create())
m_vao->bind(); m_vao->bind();
if (m_vbo) {
delete m_vbo;
m_vbo = 0;
}
m_program->bind(); m_program->bind();
delete m_vbo;
m_vbo = new QOpenGLBuffer; m_vbo = new QOpenGLBuffer;
m_vbo->create(); m_vbo->create();
m_vbo->bind(); m_vbo->bind();
m_vbo->allocate(m_logo.constData(), m_logo.count() * sizeof(GLfloat)); m_vbo->allocate(m_logo.constData(), m_logo.count() * sizeof(GLfloat));
f->glEnableVertexAttribArray(0); f->glEnableVertexAttribArray(0);
f->glEnableVertexAttribArray(1); f->glEnableVertexAttribArray(1);
f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0); f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
nullptr);
f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
reinterpret_cast<void *>(3 * sizeof(GLfloat))); reinterpret_cast<void *>(3 * sizeof(GLfloat)));
m_vbo->release(); m_vbo->release();

View File

@ -90,23 +90,23 @@ public:
private slots: private slots:
void startSecondStage(); void startSecondStage();
private: private:
QOpenGLTexture *m_texture; QOpenGLTexture *m_texture = nullptr;
QOpenGLShaderProgram *m_program; QOpenGLShaderProgram *m_program = nullptr;
QOpenGLBuffer *m_vbo; QOpenGLBuffer *m_vbo = nullptr;
QOpenGLVertexArrayObject *m_vao; QOpenGLVertexArrayObject *m_vao = nullptr;
Logo m_logo; Logo m_logo;
int m_projMatrixLoc; int m_projMatrixLoc = 0;
int m_camMatrixLoc; int m_camMatrixLoc = 0;
int m_worldMatrixLoc; int m_worldMatrixLoc = 0;
int m_myMatrixLoc; int m_myMatrixLoc = 0;
int m_lightPosLoc; int m_lightPosLoc = 0;
QMatrix4x4 m_proj; QMatrix4x4 m_proj;
QMatrix4x4 m_world; QMatrix4x4 m_world;
QVector3D m_eye; QVector3D m_eye;
QVector3D m_target; QVector3D m_target = {0, 0, -1};
bool m_uniformsDirty; bool m_uniformsDirty = true;
float m_r; float m_r = 0;
float m_r2; float m_r2 = 0;
}; };
#endif #endif

View File

@ -57,15 +57,13 @@ Bubble::Bubble(const QPointF &position, qreal radius, const QPointF &velocity)
{ {
innerColor = randomColor(); innerColor = randomColor();
outerColor = randomColor(); outerColor = randomColor();
cache = 0;
updateBrush(); updateBrush();
} }
//! [0] //! [0]
void Bubble::updateCache() void Bubble::updateCache()
{ {
if (cache) delete cache;
delete cache;
cache = new QImage(qRound(radius * 2 + 2), qRound(radius * 2 + 2), QImage::Format_ARGB32_Premultiplied); cache = new QImage(qRound(radius * 2 + 2), qRound(radius * 2 + 2), QImage::Format_ARGB32_Premultiplied);
cache->fill(0x00000000); cache->fill(0x00000000);
QPainter p(cache); QPainter p(cache);
@ -80,8 +78,7 @@ void Bubble::updateCache()
Bubble::~Bubble() Bubble::~Bubble()
{ {
if (cache) delete cache;
delete cache;
} }
void Bubble::updateBrush() void Bubble::updateBrush()

View File

@ -80,7 +80,7 @@ private:
qreal radius; qreal radius;
QColor innerColor; QColor innerColor;
QColor outerColor; QColor outerColor;
QImage *cache; QImage *cache = nullptr;
}; };
#endif #endif

View File

@ -68,14 +68,6 @@ const int bubbleNum = 8;
GLWidget::GLWidget(MainWindow *mw, bool button, const QColor &background) GLWidget::GLWidget(MainWindow *mw, bool button, const QColor &background)
: m_mainWindow(mw), : m_mainWindow(mw),
m_showBubbles(true),
m_qtLogo(true),
m_frames(0),
m_program1(0),
m_program2(0),
m_texture(0),
m_transparent(false),
m_btn(0),
m_hasButton(button), m_hasButton(button),
m_background(background) m_background(background)
{ {

View File

@ -98,34 +98,34 @@ private:
void extrude(qreal x1, qreal y1, qreal x2, qreal y2); void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
MainWindow *m_mainWindow; MainWindow *m_mainWindow;
qreal m_fAngle; qreal m_fAngle = 0;
qreal m_fScale; qreal m_fScale = 1;
bool m_showBubbles; bool m_showBubbles = true;
QVector<QVector3D> m_vertices; QVector<QVector3D> m_vertices;
QVector<QVector3D> m_normals; QVector<QVector3D> m_normals;
bool m_qtLogo; bool m_qtLogo = true;
QList<Bubble *> m_bubbles; QVector<Bubble *> m_bubbles;
int m_frames; int m_frames = 0;
QElapsedTimer m_time; QElapsedTimer m_time;
QOpenGLShader *m_vshader1; QOpenGLShader *m_vshader1 = nullptr;
QOpenGLShader *m_fshader1; QOpenGLShader *m_fshader1 = nullptr;
QOpenGLShader *m_vshader2; QOpenGLShader *m_vshader2 = nullptr;
QOpenGLShader *m_fshader2; QOpenGLShader *m_fshader2 = nullptr;
QOpenGLShaderProgram *m_program1; QOpenGLShaderProgram *m_program1 = nullptr;
QOpenGLShaderProgram *m_program2; QOpenGLShaderProgram *m_program2 = nullptr;
QOpenGLTexture *m_texture; QOpenGLTexture *m_texture = nullptr;
QOpenGLBuffer m_vbo1; QOpenGLBuffer m_vbo1;
QOpenGLBuffer m_vbo2; QOpenGLBuffer m_vbo2;
int m_vertexAttr1; int m_vertexAttr1 = 0;
int m_normalAttr1; int m_normalAttr1 = 0;
int m_matrixUniform1; int m_matrixUniform1 = 0;
int m_vertexAttr2; int m_vertexAttr2 = 0;
int m_normalAttr2; int m_normalAttr2 = 0;
int m_texCoordAttr2; int m_texCoordAttr2 = 0;
int m_matrixUniform2; int m_matrixUniform2 = 0;
int m_textureUniform2; int m_textureUniform2 = 0;
bool m_transparent; bool m_transparent = false;
QPushButton *m_btn; QPushButton *m_btn = nullptr;
bool m_hasButton; bool m_hasButton;
QColor m_background; QColor m_background;
}; };

View File

@ -53,17 +53,6 @@
#include <QOpenGLTexture> #include <QOpenGLTexture>
#include <QMouseEvent> #include <QMouseEvent>
GLWidget::GLWidget(QWidget *parent)
: QOpenGLWidget(parent),
clearColor(Qt::black),
xRot(0),
yRot(0),
zRot(0),
program(0)
{
memset(textures, 0, sizeof(textures));
}
GLWidget::~GLWidget() GLWidget::~GLWidget()
{ {
makeCurrent(); makeCurrent();

View File

@ -63,7 +63,7 @@ class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
Q_OBJECT Q_OBJECT
public: public:
explicit GLWidget(QWidget *parent = 0); using QOpenGLWidget::QOpenGLWidget;
~GLWidget(); ~GLWidget();
QSize minimumSizeHint() const override; QSize minimumSizeHint() const override;
@ -85,13 +85,13 @@ protected:
private: private:
void makeObject(); void makeObject();
QColor clearColor; QColor clearColor = Qt::black;
QPoint lastPos; QPoint lastPos;
int xRot; int xRot = 0;
int yRot; int yRot = 0;
int zRot; int zRot = 0;
QOpenGLTexture *textures[6]; QOpenGLTexture *textures[6] = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
QOpenGLShaderProgram *program; QOpenGLShaderProgram *program = nullptr;
QOpenGLBuffer vbo; QOpenGLBuffer vbo;
}; };

View File

@ -115,12 +115,7 @@ void GLWidget::grabContext()
m_renderer->unlockRenderer(); m_renderer->unlockRenderer();
} }
Renderer::Renderer(GLWidget *w) Renderer::Renderer(GLWidget *w) : m_glwidget(w) {}
: m_inited(false),
m_glwidget(w),
m_exiting(false)
{
}
void Renderer::paintQtLogo() void Renderer::paintQtLogo()
{ {

View File

@ -88,29 +88,29 @@ private:
void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4); void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4);
void extrude(qreal x1, qreal y1, qreal x2, qreal y2); void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
bool m_inited; bool m_inited = false;
qreal m_fAngle; qreal m_fAngle = 0;
qreal m_fScale; qreal m_fScale = 1;
QVector<QVector3D> vertices; QVector<QVector3D> vertices;
QVector<QVector3D> normals; QVector<QVector3D> normals;
QOpenGLShaderProgram program; QOpenGLShaderProgram program;
QOpenGLBuffer vbo; QOpenGLBuffer vbo;
int vertexAttr; int vertexAttr = 0;
int normalAttr; int normalAttr = 0;
int matrixUniform; int matrixUniform = 0;
GLWidget *m_glwidget; GLWidget *m_glwidget = nullptr;
QMutex m_renderMutex; QMutex m_renderMutex;
QElapsedTimer m_elapsed; QElapsedTimer m_elapsed;
QMutex m_grabMutex; QMutex m_grabMutex;
QWaitCondition m_grabCond; QWaitCondition m_grabCond;
bool m_exiting; bool m_exiting = false;
}; };
class GLWidget : public QOpenGLWidget class GLWidget : public QOpenGLWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GLWidget(QWidget *parent = 0); explicit GLWidget(QWidget *parent = nullptr);
~GLWidget(); ~GLWidget();
protected: protected:

View File

@ -118,9 +118,9 @@ void ClassWizard::accept()
block += "public:\n"; block += "public:\n";
if (field("qobjectCtor").toBool()) { if (field("qobjectCtor").toBool()) {
block += " " + className + "(QObject *parent = 0);\n"; block += " " + className + "(QObject *parent = nullptr);\n";
} else if (field("qwidgetCtor").toBool()) { } else if (field("qwidgetCtor").toBool()) {
block += " " + className + "(QWidget *parent = 0);\n"; block += " " + className + "(QWidget *parent = nullptr);\n";
} else if (field("defaultCtor").toBool()) { } else if (field("defaultCtor").toBool()) {
block += " " + className + "();\n"; block += " " + className + "();\n";
if (field("copyCtor").toBool()) { if (field("copyCtor").toBool()) {

View File

@ -67,7 +67,7 @@ class ClassWizard : public QWizard
Q_OBJECT Q_OBJECT
public: public:
ClassWizard(QWidget *parent = 0); ClassWizard(QWidget *parent = nullptr);
void accept() override; void accept() override;
}; };
@ -79,7 +79,7 @@ class IntroPage : public QWizardPage
Q_OBJECT Q_OBJECT
public: public:
IntroPage(QWidget *parent = 0); IntroPage(QWidget *parent = nullptr);
private: private:
QLabel *label; QLabel *label;
@ -92,7 +92,7 @@ class ClassInfoPage : public QWizardPage
Q_OBJECT Q_OBJECT
public: public:
ClassInfoPage(QWidget *parent = 0); ClassInfoPage(QWidget *parent = nullptr);
private: private:
QLabel *classNameLabel; QLabel *classNameLabel;
@ -114,7 +114,7 @@ class CodeStylePage : public QWizardPage
Q_OBJECT Q_OBJECT
public: public:
CodeStylePage(QWidget *parent = 0); CodeStylePage(QWidget *parent = nullptr);
protected: protected:
void initializePage() override; void initializePage() override;
@ -135,7 +135,7 @@ class OutputFilesPage : public QWizardPage
Q_OBJECT Q_OBJECT
public: public:
OutputFilesPage(QWidget *parent = 0); OutputFilesPage(QWidget *parent = nullptr);
protected: protected:
void initializePage() override; void initializePage() override;
@ -154,7 +154,7 @@ class ConclusionPage : public QWizardPage
Q_OBJECT Q_OBJECT
public: public:
ConclusionPage(QWidget *parent = 0); ConclusionPage(QWidget *parent = nullptr);
protected: protected:
void initializePage() override; void initializePage() override;

View File

@ -64,7 +64,7 @@ int main(int argc, char *argv[])
QApplication app(argc, argv); QApplication app(argc, argv);
#ifndef QT_NO_TRANSLATION #ifndef QT_NO_TRANSLATION
QString translatorFileName = QLatin1String("qt_"); QString translatorFileName = QLatin1String("qtbase_");
translatorFileName += QLocale::system().name(); translatorFileName += QLocale::system().name();
QTranslator *translator = new QTranslator(&app); QTranslator *translator = new QTranslator(&app);
if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))

View File

@ -68,7 +68,7 @@ class FindDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
FindDialog(QWidget *parent = 0); FindDialog(QWidget *parent = nullptr);
private: private:
QLabel *label; QLabel *label;

View File

@ -68,7 +68,7 @@ class Window : public QWidget
Q_OBJECT Q_OBJECT
public: public:
Window(QWidget *parent = 0); Window(QWidget *parent = nullptr);
private slots: private slots:
void browse(); void browse();

View File

@ -72,7 +72,7 @@ public:
Page_Conclusion }; Page_Conclusion };
//! [2] //! [2]
LicenseWizard(QWidget *parent = 0); LicenseWizard(QWidget *parent = nullptr);
private slots: private slots:
void showHelp(); void showHelp();
@ -86,7 +86,7 @@ class IntroPage : public QWizardPage
Q_OBJECT Q_OBJECT
public: public:
IntroPage(QWidget *parent = 0); IntroPage(QWidget *parent = nullptr);
int nextId() const override; int nextId() const override;
@ -103,7 +103,7 @@ class EvaluatePage : public QWizardPage
Q_OBJECT Q_OBJECT
public: public:
EvaluatePage(QWidget *parent = 0); EvaluatePage(QWidget *parent = nullptr);
int nextId() const override; int nextId() const override;
@ -120,7 +120,7 @@ class RegisterPage : public QWizardPage
Q_OBJECT Q_OBJECT
public: public:
RegisterPage(QWidget *parent = 0); RegisterPage(QWidget *parent = nullptr);
int nextId() const override; int nextId() const override;
@ -136,7 +136,7 @@ class DetailsPage : public QWizardPage
Q_OBJECT Q_OBJECT
public: public:
DetailsPage(QWidget *parent = 0); DetailsPage(QWidget *parent = nullptr);
int nextId() const override; int nextId() const override;
@ -155,7 +155,7 @@ class ConclusionPage : public QWizardPage
Q_OBJECT Q_OBJECT
public: public:
ConclusionPage(QWidget *parent = 0); ConclusionPage(QWidget *parent = nullptr);
void initializePage() override; void initializePage() override;
int nextId() const override; int nextId() const override;

View File

@ -64,7 +64,7 @@ int main(int argc, char *argv[])
QApplication app(argc, argv); QApplication app(argc, argv);
#ifndef QT_NO_TRANSLATION #ifndef QT_NO_TRANSLATION
QString translatorFileName = QLatin1String("qt_"); QString translatorFileName = QLatin1String("qtbase_");
translatorFileName += QLocale::system().name(); translatorFileName += QLocale::system().name();
QTranslator *translator = new QTranslator(&app); QTranslator *translator = new QTranslator(&app);
if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))

View File

@ -66,7 +66,7 @@ class Dialog : public QWidget
Q_OBJECT Q_OBJECT
public: public:
Dialog(QWidget *parent = 0); Dialog(QWidget *parent = nullptr);
private slots: private slots:
void setInteger(); void setInteger();

View File

@ -64,7 +64,7 @@ int main(int argc, char *argv[])
QGuiApplication::setApplicationDisplayName(Dialog::tr("Standard Dialogs")); QGuiApplication::setApplicationDisplayName(Dialog::tr("Standard Dialogs"));
#ifndef QT_NO_TRANSLATION #ifndef QT_NO_TRANSLATION
QString translatorFileName = QLatin1String("qt_"); QString translatorFileName = QLatin1String("qtbase_");
translatorFileName += QLocale::system().name(); translatorFileName += QLocale::system().name();
QTranslator *translator = new QTranslator(&app); QTranslator *translator = new QTranslator(&app);
if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))

View File

@ -65,7 +65,7 @@ class GeneralTab : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit GeneralTab(const QFileInfo &fileInfo, QWidget *parent = 0); explicit GeneralTab(const QFileInfo &fileInfo, QWidget *parent = nullptr);
}; };
//! [0] //! [0]
@ -76,7 +76,7 @@ class PermissionsTab : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = 0); explicit PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = nullptr);
}; };
//! [1] //! [1]
@ -87,7 +87,7 @@ class ApplicationsTab : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = 0); explicit ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = nullptr);
}; };
//! [2] //! [2]
@ -98,7 +98,7 @@ class TabDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit TabDialog(const QString &fileName, QWidget *parent = 0); explicit TabDialog(const QString &fileName, QWidget *parent = nullptr);
private: private:
QTabWidget *tabWidget; QTabWidget *tabWidget;

View File

@ -128,7 +128,7 @@ int main(int argc, char *argv[])
QApplication app(argc, argv); QApplication app(argc, argv);
#ifndef QT_NO_TRANSLATION #ifndef QT_NO_TRANSLATION
QString translatorFileName = QLatin1String("qt_"); QString translatorFileName = QLatin1String("qtbase_");
translatorFileName += QLocale::system().name(); translatorFileName += QLocale::system().name();
QTranslator *translator = new QTranslator(&app); QTranslator *translator = new QTranslator(&app);
if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))

View File

@ -176,16 +176,16 @@
\snippet draganddrop/dropsite/dropsitewindow.cpp constructor part3 \snippet draganddrop/dropsite/dropsitewindow.cpp constructor part3
Two QPushButton objects, \c clearButton and \c quitButton, are instantiated Three QPushButton objects, \c clearButton, \c copyButton, and \c quitButton,
and added to \c buttonBox - a QDialogButtonBox object. We use are instantiated and added to \c buttonBox - a QDialogButtonBox object. We
QDialogButtonBox here to ensure that the push buttons are presented in a use QDialogButtonBox here to ensure that the push buttons are presented in a
layout that conforms to the platform's style. layout that conforms to the platform's style.
\snippet draganddrop/dropsite/dropsitewindow.cpp constructor part4 \snippet draganddrop/dropsite/dropsitewindow.cpp constructor part4
The \l{QPushButton::clicked()}{clicked()} signals for \c quitButton and The \l{QPushButton::clicked()}{clicked()} signals for \c copyButton,
\c clearButton are connected to \l{QWidget::close()}{close()} and \c clearButton, and \c quitButton are connected to \c copy(),
\c clear(), respectively. \c clear() and \l{QWidget::close()}{close()}, respectively.
For the layout, we use a QVBoxLayout, \c mainLayout, to arrange our widgets For the layout, we use a QVBoxLayout, \c mainLayout, to arrange our widgets
vertically. We also set the window title to "Drop Site" and the minimum vertically. We also set the window title to "Drop Site" and the minimum

View File

@ -142,6 +142,9 @@
pendingAdditiveOperator and \c pendingMultiplicativeOperator pendingAdditiveOperator and \c pendingMultiplicativeOperator
variables don't need to be initialized explicitly, because the variables don't need to be initialized explicitly, because the
QString constructor initializes them to empty strings. QString constructor initializes them to empty strings.
It is also possible to initialize those variable directly in the
header. This is called \c member-initializaton and avoids a long
initialization list.
\snippet widgets/calculator/calculator.cpp 1 \snippet widgets/calculator/calculator.cpp 1
\snippet widgets/calculator/calculator.cpp 2 \snippet widgets/calculator/calculator.cpp 2

View File

@ -75,7 +75,8 @@
\section1 Mouse Class Definition \section1 Mouse Class Definition
When constructing a mouse item, we first ensure that all the item's When constructing a mouse item, we first ensure that all the item's
private variables are properly initialized: private variables which were no yet initialized directly in the class
are properly initialized:
\snippet graphicsview/collidingmice/mouse.cpp 0 \snippet graphicsview/collidingmice/mouse.cpp 0

View File

@ -643,7 +643,9 @@
This function is called when the item is removed from the scene This function is called when the item is removed from the scene
and removes all arrows that are connected to this item. The arrow and removes all arrows that are connected to this item. The arrow
must be removed from the \c arrows list of both its start and end must be removed from the \c arrows list of both its start and end
item. item. Since either the start or the end item is the object where
this function is currently called, we have to make sure to work on
a copy of arrows since removeArrow() is modifying this container.
Here is the \c addArrow() function: Here is the \c addArrow() function:

View File

@ -95,7 +95,7 @@
\snippet widgets/tooltips/sortingbox.h 2 \snippet widgets/tooltips/sortingbox.h 2
We keep all the shape items in a QList, and we keep three We keep all the shape items in a QVector, and we keep three
QPainterPath objects holding the shapes of a circle, a square and QPainterPath objects holding the shapes of a circle, a square and
a triangle. We also need to have a pointer to an item when it is a triangle. We also need to have a pointer to an item when it is
moving, and we need to know its previous position. moving, and we need to know its previous position.

View File

@ -82,14 +82,21 @@ DropSiteWindow::DropSiteWindow()
//! [constructor part4] //! [constructor part4]
clearButton = new QPushButton(tr("Clear")); clearButton = new QPushButton(tr("Clear"));
copyButton = new QPushButton(tr("Copy"));
quitButton = new QPushButton(tr("Quit")); quitButton = new QPushButton(tr("Quit"));
buttonBox = new QDialogButtonBox; buttonBox = new QDialogButtonBox;
buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole); buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(copyButton, QDialogButtonBox::ActionRole);
#if !QT_CONFIG(clipboard)
copyButton->setVisible(false);
#endif
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole); buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
connect(quitButton, &QAbstractButton::clicked, this, &QWidget::close); connect(quitButton, &QAbstractButton::clicked, this, &QWidget::close);
connect(clearButton, &QAbstractButton::clicked, dropArea, &DropArea::clear); connect(clearButton, &QAbstractButton::clicked, dropArea, &DropArea::clear);
connect(copyButton, &QAbstractButton::clicked, this, &DropSiteWindow::copy);
//! [constructor part4] //! [constructor part4]
//! [constructor part5] //! [constructor part5]
@ -108,6 +115,7 @@ DropSiteWindow::DropSiteWindow()
void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData) void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData)
{ {
formatsTable->setRowCount(0); formatsTable->setRowCount(0);
copyButton->setEnabled(false);
if (!mimeData) if (!mimeData)
return; return;
//! [updateFormatsTable() part1] //! [updateFormatsTable() part1]
@ -145,5 +153,18 @@ void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData)
} }
formatsTable->resizeColumnToContents(0); formatsTable->resizeColumnToContents(0);
#if QT_CONFIG(clipboard)
copyButton->setEnabled(formatsTable->rowCount() > 0);
#endif
} }
//! [updateFormatsTable() part4] //! [updateFormatsTable() part4]
void DropSiteWindow::copy()
{
#if QT_CONFIG(clipboard)
QString text;
for (int row = 0, rowCount = formatsTable->rowCount(); row < rowCount; ++row)
text += formatsTable->item(row, 0)->text() + ": " + formatsTable->item(row, 1)->text() + '\n';
QGuiApplication::clipboard()->setText(text);
#endif
}

View File

@ -72,6 +72,7 @@ public:
public slots: public slots:
void updateFormatsTable(const QMimeData *mimeData); void updateFormatsTable(const QMimeData *mimeData);
void copy();
private: private:
DropArea *dropArea; DropArea *dropArea;
@ -79,6 +80,7 @@ private:
QTableWidget *formatsTable; QTableWidget *formatsTable;
QPushButton *clearButton; QPushButton *clearButton;
QPushButton *copyButton;
QPushButton *quitButton; QPushButton *quitButton;
QDialogButtonBox *buttonBox; QDialogButtonBox *buttonBox;
}; };

View File

@ -63,7 +63,7 @@ class BlurPicker: public QGraphicsView
Q_PROPERTY(qreal index READ index WRITE setIndex) Q_PROPERTY(qreal index READ index WRITE setIndex)
public: public:
BlurPicker(QWidget *parent = 0); BlurPicker(QWidget *parent = nullptr);
qreal index() const; qreal index() const;
void setIndex(qreal); void setIndex(qreal);

View File

@ -62,7 +62,7 @@ class FadeMessage: public QGraphicsView
Q_OBJECT Q_OBJECT
public: public:
FadeMessage(QWidget *parent = 0); FadeMessage(QWidget *parent = nullptr);
private: private:
void setupScene(); void setupScene();

View File

@ -50,26 +50,23 @@
#include "imagewidget.h" #include "imagewidget.h"
#include <QtWidgets> #include <QDir>
#include <QImageReader>
#include <QGestureEvent>
#include <QPainter>
Q_LOGGING_CATEGORY(lcExample, "qt.examples.imagegestures") Q_LOGGING_CATEGORY(lcExample, "qt.examples.imagegestures")
//! [constructor] //! [constructor]
ImageWidget::ImageWidget(QWidget *parent) ImageWidget::ImageWidget(QWidget *parent)
: QWidget(parent), : QWidget(parent), position(0), horizontalOffset(0), verticalOffset(0)
position(0), , rotationAngle(0), scaleFactor(1), currentStepScaleFactor(1)
horizontalOffset(0),
verticalOffset(0),
rotationAngle(0),
scaleFactor(1),
currentStepScaleFactor(1)
{ {
setMinimumSize(QSize(100,100)); setMinimumSize(QSize(100, 100));
} }
//! [constructor] //! [constructor]
void ImageWidget::grabGestures(const QList<Qt::GestureType> &gestures) void ImageWidget::grabGestures(const QVector<Qt::GestureType> &gestures)
{ {
//! [enable gestures] //! [enable gestures]
for (Qt::GestureType gesture : gestures) for (Qt::GestureType gesture : gestures)
@ -96,11 +93,11 @@ void ImageWidget::paintEvent(QPaintEvent*)
const qreal wh = height(); const qreal wh = height();
const qreal ww = width(); const qreal ww = width();
p.translate(ww/2, wh/2); p.translate(ww / 2, wh / 2);
p.translate(horizontalOffset, verticalOffset); p.translate(horizontalOffset, verticalOffset);
p.rotate(rotationAngle); p.rotate(rotationAngle);
p.scale(currentStepScaleFactor * scaleFactor, currentStepScaleFactor * scaleFactor); p.scale(currentStepScaleFactor * scaleFactor, currentStepScaleFactor * scaleFactor);
p.translate(-iw/2, -ih/2); p.translate(-iw / 2, -ih / 2);
p.drawImage(0, 0, currentImage); p.drawImage(0, 0, currentImage);
} }
//! [paint method] //! [paint method]
@ -198,8 +195,7 @@ void ImageWidget::openDirectory(const QString &path)
{ {
this->path = path; this->path = path;
QDir dir(path); QDir dir(path);
QStringList nameFilters; const QStringList nameFilters{"*.jpg", "*.png"};
nameFilters << "*.jpg" << "*.png";
files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name); files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name);
position = 0; position = 0;
@ -207,7 +203,7 @@ void ImageWidget::openDirectory(const QString &path)
update(); update();
} }
QImage ImageWidget::loadImage(const QString &fileName) QImage ImageWidget::loadImage(const QString &fileName) const
{ {
QImageReader reader(fileName); QImageReader reader(fileName);
reader.setAutoTransform(true); reader.setAutoTransform(true);

View File

@ -51,9 +51,9 @@
#ifndef IMAGEWIDGET_H #ifndef IMAGEWIDGET_H
#define IMAGEWIDGET_H #define IMAGEWIDGET_H
#include <QWidget>
#include <QImage> #include <QImage>
#include <QtWidgets> #include <QLoggingCategory>
#include <QWidget>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QGestureEvent; class QGestureEvent;
@ -70,9 +70,9 @@ class ImageWidget : public QWidget
Q_OBJECT Q_OBJECT
public: public:
ImageWidget(QWidget *parent = 0); ImageWidget(QWidget *parent = nullptr);
void openDirectory(const QString &path); void openDirectory(const QString &path);
void grabGestures(const QList<Qt::GestureType> &gestures); void grabGestures(const QVector<Qt::GestureType> &gestures);
protected: protected:
bool event(QEvent *event) override; bool event(QEvent *event) override;
@ -87,7 +87,7 @@ private:
void swipeTriggered(QSwipeGesture*); void swipeTriggered(QSwipeGesture*);
//! [class definition begin] //! [class definition begin]
QImage loadImage(const QString &fileName); QImage loadImage(const QString &fileName) const;
void loadImage(); void loadImage();
void goNextImage(); void goNextImage();
void goPrevImage(); void goPrevImage();

View File

@ -102,7 +102,7 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
QList<Qt::GestureType> gestures; QVector<Qt::GestureType> gestures;
if (!commandLineParser.isSet(disablePanOption)) if (!commandLineParser.isSet(disablePanOption))
gestures << Qt::PanGesture; gestures << Qt::PanGesture;
if (!commandLineParser.isSet(disablePinchOption)) if (!commandLineParser.isSet(disablePinchOption))

View File

@ -72,7 +72,7 @@ void MainWidget::openDirectory(const QString &path)
imageWidget->openDirectory(path); imageWidget->openDirectory(path);
} }
void MainWidget::grabGestures(const QList<Qt::GestureType> &gestures) void MainWidget::grabGestures(const QVector<Qt::GestureType> &gestures)
{ {
imageWidget->grabGestures(gestures); imageWidget->grabGestures(gestures);
} }

View File

@ -60,8 +60,8 @@ class MainWidget : public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
MainWidget(QWidget *parent = 0); MainWidget(QWidget *parent = nullptr);
void grabGestures(const QList<Qt::GestureType> &gestures); void grabGestures(const QVector<Qt::GestureType> &gestures);
public slots: public slots:
void openDirectory(const QString &path); void openDirectory(const QString &path);

View File

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

View File

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

View File

@ -53,23 +53,24 @@
#include <QGraphicsLayoutItem> #include <QGraphicsLayoutItem>
#include <QGraphicsItem> #include <QGraphicsItem>
#include <QPixmap>
//! [0] //! [0]
class LayoutItem : public QGraphicsLayoutItem, public QGraphicsItem class LayoutItem : public QGraphicsLayoutItem, public QGraphicsItem
{ {
public: public:
LayoutItem(QGraphicsItem *parent = 0); LayoutItem(QGraphicsItem *parent = nullptr);
~LayoutItem();
// Inherited from QGraphicsLayoutItem // Inherited from QGraphicsLayoutItem
void setGeometry(const QRectF &geom) override; void setGeometry(const QRectF &geom) override;
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override; QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override;
// Inherited from QGraphicsItem // Inherited from QGraphicsItem
QRectF boundingRect() const override; QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
private: private:
QPixmap *m_pix; QPixmap m_pix;
}; };
//! [0] //! [0]

View File

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

View File

@ -49,8 +49,6 @@
****************************************************************************/ ****************************************************************************/
#include "glbuffers.h" #include "glbuffers.h"
#include <QtGui/qmatrix4x4.h>
#include <QtCore/qmath.h>
void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
{ {
@ -65,7 +63,7 @@ void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zF
// GLTexture // // GLTexture //
//============================================================================// //============================================================================//
GLTexture::GLTexture() : m_texture(0), m_failed(false) GLTexture::GLTexture()
{ {
glGenTextures(1, &m_texture); glGenTextures(1, &m_texture);
} }
@ -83,7 +81,7 @@ GLTexture2D::GLTexture2D(int width, int height)
{ {
glBindTexture(GL_TEXTURE_2D, m_texture); glBindTexture(GL_TEXTURE_2D, m_texture);
glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0,
GL_BGRA, GL_UNSIGNED_BYTE, 0); GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
@ -95,7 +93,7 @@ GLTexture2D::GLTexture2D(int width, int height)
} }
GLTexture2D::GLTexture2D(const QString& fileName, int width, int height) GLTexture2D::GLTexture2D(const QString &fileName, int width, int height)
{ {
// TODO: Add error handling. // TODO: Add error handling.
QImage image(fileName); QImage image(fileName);
@ -162,7 +160,7 @@ GLTexture3D::GLTexture3D(int width, int height, int depth)
glBindTexture(GL_TEXTURE_3D, m_texture); glBindTexture(GL_TEXTURE_3D, m_texture);
glTexImage3D(GL_TEXTURE_3D, 0, 4, width, height, depth, 0, glTexImage3D(GL_TEXTURE_3D, 0, 4, width, height, depth, 0,
GL_BGRA, GL_UNSIGNED_BYTE, 0); GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
@ -206,7 +204,7 @@ GLTextureCube::GLTextureCube(int size)
for (int i = 0; i < 6; ++i) for (int i = 0; i < 6; ++i)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 4, size, size, 0, glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 4, size, size, 0,
GL_BGRA, GL_UNSIGNED_BYTE, 0); GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
@ -252,7 +250,7 @@ GLTextureCube::GLTextureCube(const QStringList &fileNames, int size)
// Clear remaining faces. // Clear remaining faces.
while (index < 6) { while (index < 6) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, 0, 4, size, size, 0, glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, 0, 4, size, size, 0,
GL_BGRA, GL_UNSIGNED_BYTE, 0); GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
++index; ++index;
} }
@ -291,11 +289,8 @@ void GLTextureCube::unbind()
//============================================================================// //============================================================================//
GLFrameBufferObject::GLFrameBufferObject(int width, int height) GLFrameBufferObject::GLFrameBufferObject(int width, int height)
: m_fbo(0) : m_width(width)
, m_depthBuffer(0)
, m_width(width)
, m_height(height) , m_height(height)
, m_failed(false)
{ {
GLBUFFERS_ASSERT_OPENGL("GLFrameBufferObject::GLFrameBufferObject", GLBUFFERS_ASSERT_OPENGL("GLFrameBufferObject::GLFrameBufferObject",
glGenFramebuffersEXT && glGenRenderbuffersEXT && glBindRenderbufferEXT && glRenderbufferStorageEXT, return) glGenFramebuffersEXT && glGenRenderbuffersEXT && glBindRenderbufferEXT && glRenderbufferStorageEXT, return)
@ -373,7 +368,7 @@ void GLRenderTargetCube::getViewMatrix(QMatrix4x4& mat, int face)
return; return;
} }
static int perm[6][3] = { static constexpr int perm[6][3] = {
{2, 1, 0}, {2, 1, 0},
{2, 1, 0}, {2, 1, 0},
{0, 2, 1}, {0, 2, 1},
@ -382,7 +377,7 @@ void GLRenderTargetCube::getViewMatrix(QMatrix4x4& mat, int face)
{0, 1, 2}, {0, 1, 2},
}; };
static float signs[6][3] = { static constexpr float signs[6][3] = {
{-1.0f, -1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f},
{+1.0f, -1.0f, +1.0f}, {+1.0f, -1.0f, +1.0f},
{+1.0f, +1.0f, -1.0f}, {+1.0f, +1.0f, -1.0f},

View File

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

View File

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

View File

@ -48,13 +48,11 @@
** **
****************************************************************************/ ****************************************************************************/
//#include <GL/glew.h>
#include "glextensions.h" #include "glextensions.h"
#include "scene.h" #include "scene.h"
#include <QtWidgets>
#include <QGLWidget> #include <QGLWidget>
#include <QtWidgets>
class GraphicsView : public QGraphicsView class GraphicsView : public QGraphicsView
{ {
@ -114,7 +112,7 @@ int main(int argc, char **argv)
QApplication app(argc, argv); QApplication app(argc, argv);
if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_5) == 0) { if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_5) == 0) {
QMessageBox::critical(0, "OpenGL features missing", QMessageBox::critical(nullptr, "OpenGL features missing",
"OpenGL version 1.5 or higher is required to run this demo.\n" "OpenGL version 1.5 or higher is required to run this demo.\n"
"The program will now exit."); "The program will now exit.");
return -1; return -1;
@ -125,7 +123,7 @@ int main(int argc, char **argv)
widget->makeCurrent(); widget->makeCurrent();
if (!necessaryExtensionsSupported()) { if (!necessaryExtensionsSupported()) {
QMessageBox::critical(0, "OpenGL features missing", QMessageBox::critical(nullptr, "OpenGL features missing",
"The OpenGL extensions required to run this demo are missing.\n" "The OpenGL extensions required to run this demo are missing.\n"
"The program will now exit."); "The program will now exit.");
delete widget; delete widget;
@ -134,7 +132,7 @@ int main(int argc, char **argv)
// Check if all the necessary functions are resolved. // Check if all the necessary functions are resolved.
if (!getGLExtensionFunctions().resolve(widget->context())) { if (!getGLExtensionFunctions().resolve(widget->context())) {
QMessageBox::critical(0, "OpenGL features missing", QMessageBox::critical(nullptr, "OpenGL features missing",
"Failed to resolve OpenGL functions required to run this demo.\n" "Failed to resolve OpenGL functions required to run this demo.\n"
"The program will now exit."); "The program will now exit.");
delete widget; delete widget;
@ -142,7 +140,7 @@ int main(int argc, char **argv)
} }
// TODO: Make conditional for final release // TODO: Make conditional for final release
QMessageBox::information(0, "For your information", QMessageBox::information(nullptr, "For your information",
"This demo can be GPU and CPU intensive and may\n" "This demo can be GPU and CPU intensive and may\n"
"work poorly or not at all on your system."); "work poorly or not at all on your system.");

View File

@ -50,28 +50,23 @@
#include "qtbox.h" #include "qtbox.h"
const qreal ROTATE_SPEED_X = 30.0 / 1000.0; constexpr qreal ROTATE_SPEED_X = 30.0 / 1000.0;
const qreal ROTATE_SPEED_Y = 20.0 / 1000.0; constexpr qreal ROTATE_SPEED_Y = 20.0 / 1000.0;
const qreal ROTATE_SPEED_Z = 40.0 / 1000.0; constexpr qreal ROTATE_SPEED_Z = 40.0 / 1000.0;
const int MAX_ITEM_SIZE = 512; constexpr int MAX_ITEM_SIZE = 512;
const int MIN_ITEM_SIZE = 16; constexpr int MIN_ITEM_SIZE = 16;
//============================================================================// //============================================================================//
// ItemBase // // ItemBase //
//============================================================================// //============================================================================//
ItemBase::ItemBase(int size, int x, int y) : m_size(size), m_isResizing(false) ItemBase::ItemBase(int size, int x, int y) : m_size(size), m_startTime(QTime::currentTime())
{ {
setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemIsFocusable, true); setFlag(QGraphicsItem::ItemIsFocusable, true);
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
setPos(x, y); setPos(x, y);
m_startTime = QTime::currentTime();
}
ItemBase::~ItemBase()
{
} }
QRectF ItemBase::boundingRect() const QRectF ItemBase::boundingRect() const
@ -252,10 +247,7 @@ void ItemBase::wheelEvent(QGraphicsSceneWheelEvent *event)
{ {
prepareGeometryChange(); prepareGeometryChange();
m_size = int(m_size * qExp(-event->delta() / 600.0)); m_size = int(m_size * qExp(-event->delta() / 600.0));
if (m_size > MAX_ITEM_SIZE) m_size = qBound(MIN_ITEM_SIZE, m_size, MAX_ITEM_SIZE);
m_size = MAX_ITEM_SIZE;
else if (m_size < MIN_ITEM_SIZE)
m_size = MIN_ITEM_SIZE;
} }
int ItemBase::type() const int ItemBase::type() const
@ -273,7 +265,7 @@ bool ItemBase::isInResizeArea(const QPointF &pos)
// QtBox // // QtBox //
//============================================================================// //============================================================================//
QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y), m_texture(0) QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y)
{ {
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
m_vertices[i].setX(i & 1 ? 0.5f : -0.5f); m_vertices[i].setX(i & 1 ? 0.5f : -0.5f);
@ -294,8 +286,7 @@ QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y), m_texture(0)
QtBox::~QtBox() QtBox::~QtBox()
{ {
if (m_texture) delete m_texture;
delete m_texture;
} }
ItemBase *QtBox::createNew(int size, int x, int y) ItemBase *QtBox::createNew(int size, int x, int y)
@ -337,7 +328,7 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
glEnable(GL_COLOR_MATERIAL); glEnable(GL_COLOR_MATERIAL);
glEnable(GL_NORMALIZE); glEnable(GL_NORMALIZE);
if(m_texture == 0) if (m_texture == nullptr)
m_texture = new GLTexture2D(":/res/boxes/qt-logo.jpg", 64, 64); m_texture = new GLTexture2D(":/res/boxes/qt-logo.jpg", 64, 64);
m_texture->bind(); m_texture->bind();
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
@ -405,9 +396,8 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
//============================================================================// //============================================================================//
CircleItem::CircleItem(int size, int x, int y) : ItemBase(size, x, y) CircleItem::CircleItem(int size, int x, int y) : ItemBase(size, x, y)
{ , m_color(QColor::fromHsv(QRandomGenerator::global()->bounded(360), 255, 255))
m_color = QColor::fromHsv(QRandomGenerator::global()->bounded(360), 255, 255); {}
}
void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
@ -455,9 +445,8 @@ ItemBase *CircleItem::createNew(int size, int x, int y)
//============================================================================// //============================================================================//
SquareItem::SquareItem(int size, int x, int y) : ItemBase(size, x, y) SquareItem::SquareItem(int size, int x, int y) : ItemBase(size, x, y)
{ , m_image(QPixmap(":/res/boxes/square.jpg"))
m_image = QPixmap(":/res/boxes/square.jpg"); {}
}
void SquareItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void SquareItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {

View File

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

View File

@ -51,16 +51,12 @@
#ifndef ROUNDEDBOX_H #ifndef ROUNDEDBOX_H
#define ROUNDEDBOX_H #define ROUNDEDBOX_H
//#include <GL/glew.h>
#include "glextensions.h"
#include <QtWidgets>
#include <QtOpenGL>
#include "gltrianglemesh.h"
#include <QtGui/qvector3d.h>
#include <QtGui/qvector2d.h>
#include "glbuffers.h" #include "glbuffers.h"
#include "glextensions.h"
#include "gltrianglemesh.h"
#include <QVector2D>
#include <QVector3D>
struct P3T2N3Vertex struct P3T2N3Vertex
{ {

View File

@ -48,45 +48,15 @@
** **
****************************************************************************/ ****************************************************************************/
#include <QDebug>
#include "scene.h" #include "scene.h"
#include <QtCore/QRandomGenerator>
#include <QtGui/qmatrix4x4.h> #include <QMatrix4x4>
#include <QtGui/qvector3d.h> #include <QRandomGenerator>
#include <QVector3D>
#include <qmath.h> #include <qmath.h>
#include "3rdparty/fbm.h" #include "3rdparty/fbm.h"
void checkGLErrors(const QString& prefix)
{
switch (glGetError()) {
case GL_NO_ERROR:
//qDebug() << prefix << tr("No error.");
break;
case GL_INVALID_ENUM:
qDebug() << prefix << QObject::tr("Invalid enum.");
break;
case GL_INVALID_VALUE:
qDebug() << prefix << QObject::tr("Invalid value.");
break;
case GL_INVALID_OPERATION:
qDebug() << prefix << QObject::tr("Invalid operation.");
break;
case GL_STACK_OVERFLOW:
qDebug() << prefix << QObject::tr("Stack overflow.");
break;
case GL_STACK_UNDERFLOW:
qDebug() << prefix << QObject::tr("Stack underflow.");
break;
case GL_OUT_OF_MEMORY:
qDebug() << prefix << QObject::tr("Out of memory.");
break;
default:
qDebug() << prefix << QObject::tr("Unknown error.");
break;
}
}
//============================================================================// //============================================================================//
// ColorEdit // // ColorEdit //
//============================================================================// //============================================================================//
@ -126,7 +96,7 @@ void ColorEdit::mousePressEvent(QMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton) { if (event->button() == Qt::LeftButton) {
QColor color(m_color); QColor color(m_color);
QColorDialog dialog(color, 0); QColorDialog dialog(color, nullptr);
dialog.setOption(QColorDialog::ShowAlphaChannel, true); dialog.setOption(QColorDialog::ShowAlphaChannel, true);
dialog.move(280, 120); dialog.move(280, 120);
if (dialog.exec() == QDialog::Rejected) if (dialog.exec() == QDialog::Rejected)
@ -179,17 +149,6 @@ void FloatEdit::editDone()
//============================================================================// //============================================================================//
// TwoSidedGraphicsWidget // // TwoSidedGraphicsWidget //
//============================================================================// //============================================================================//
TwoSidedGraphicsWidget::TwoSidedGraphicsWidget(QGraphicsScene *scene)
: QObject(scene)
, m_current(0)
, m_angle(0)
, m_delta(0)
{
for (int i = 0; i < 2; ++i)
m_proxyWidgets[i] = 0;
}
void TwoSidedGraphicsWidget::setWidget(int index, QWidget *widget) void TwoSidedGraphicsWidget::setWidget(int index, QWidget *widget)
{ {
if (index < 0 || index >= 2) if (index < 0 || index >= 2)
@ -201,8 +160,7 @@ void TwoSidedGraphicsWidget::setWidget(int index, QWidget *widget)
GraphicsWidget *proxy = new GraphicsWidget; GraphicsWidget *proxy = new GraphicsWidget;
proxy->setWidget(widget); proxy->setWidget(widget);
if (m_proxyWidgets[index]) delete m_proxyWidgets[index];
delete m_proxyWidgets[index];
m_proxyWidgets[index] = proxy; m_proxyWidgets[index] = proxy;
proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache); proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache);
@ -219,7 +177,7 @@ QWidget *TwoSidedGraphicsWidget::widget(int index)
if (index < 0 || index >= 2) if (index < 0 || index >= 2)
{ {
qWarning("TwoSidedGraphicsWidget::widget: Index out of bounds, index == %d", index); qWarning("TwoSidedGraphicsWidget::widget: Index out of bounds, index == %d", index);
return 0; return nullptr;
} }
return m_proxyWidgets[index]->widget(); return m_proxyWidgets[index]->widget();
} }
@ -289,7 +247,7 @@ void GraphicsWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
//============================================================================// //============================================================================//
RenderOptionsDialog::RenderOptionsDialog() RenderOptionsDialog::RenderOptionsDialog()
: QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint) : QDialog(nullptr, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
{ {
setWindowOpacity(0.75); setWindowOpacity(0.75);
setWindowTitle(tr("Options (double click to flip)")); setWindowTitle(tr("Options (double click to flip)"));
@ -423,7 +381,7 @@ void RenderOptionsDialog::mouseDoubleClickEvent(QMouseEvent *event)
//============================================================================// //============================================================================//
ItemDialog::ItemDialog() ItemDialog::ItemDialog()
: QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint) : QDialog(nullptr, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
{ {
setWindowTitle(tr("Items (double click to flip)")); setWindowTitle(tr("Items (double click to flip)"));
setWindowOpacity(0.75); setWindowOpacity(0.75);
@ -487,10 +445,10 @@ Scene::Scene(int width, int height, int maxTextureSize)
, m_currentTexture(0) , m_currentTexture(0)
, m_dynamicCubemap(false) , m_dynamicCubemap(false)
, m_updateAllCubemaps(true) , m_updateAllCubemaps(true)
, m_box(0) , m_box(nullptr)
, m_vertexShader(0) , m_vertexShader(nullptr)
, m_environmentShader(0) , m_environmentShader(nullptr)
, m_environmentProgram(0) , m_environmentProgram(nullptr)
{ {
setSceneRect(0, 0, width, height); setSceneRect(0, 0, width, height);
@ -564,9 +522,8 @@ void Scene::initGL()
const int NOISE_SIZE = 128; // for a different size, B and BM in fbm.c must also be changed const int NOISE_SIZE = 128; // for a different size, B and BM in fbm.c must also be changed
m_noise = new GLTexture3D(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE); m_noise = new GLTexture3D(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE);
QRgb *data = new QRgb[NOISE_SIZE * NOISE_SIZE * NOISE_SIZE]; QVector<QRgb> data(NOISE_SIZE * NOISE_SIZE * NOISE_SIZE, QRgb(0));
memset(data, 0, NOISE_SIZE * NOISE_SIZE * NOISE_SIZE * sizeof(QRgb)); QRgb *p = data.data();
QRgb *p = data;
float pos[3]; float pos[3];
for (int k = 0; k < NOISE_SIZE; ++k) { for (int k = 0; k < NOISE_SIZE; ++k) {
pos[2] = k * (0x20 / (float)NOISE_SIZE); pos[2] = k * (0x20 / (float)NOISE_SIZE);
@ -581,8 +538,7 @@ void Scene::initGL()
} }
} }
} }
m_noise->load(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE, data); m_noise->load(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE, data.data());
delete[] data;
m_mainCubemap = new GLRenderTargetCube(512); m_mainCubemap = new GLRenderTargetCube(512);
@ -634,7 +590,7 @@ void Scene::initGL()
m_renderOptions->addShader(file.baseName()); m_renderOptions->addShader(file.baseName());
program->bind(); program->bind();
m_cubemaps << ((program->uniformLocation("env") != -1) ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : 0); m_cubemaps << ((program->uniformLocation("env") != -1) ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : nullptr);
program->release(); program->release();
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -54,10 +54,10 @@
#include <QPainter> #include <QPainter>
#include <QRandomGenerator> #include <QRandomGenerator>
#include <QStyleOption> #include <QStyleOption>
#include <qmath.h> #include <QtMath>
const qreal Pi = M_PI; constexpr qreal Pi = M_PI;
const qreal TwoPi = 2 * M_PI; constexpr qreal TwoPi = 2 * M_PI;
static qreal normalizeAngle(qreal angle) static qreal normalizeAngle(qreal angle)
{ {
@ -69,9 +69,9 @@ static qreal normalizeAngle(qreal angle)
} }
//! [0] //! [0]
Mouse::Mouse() Mouse::Mouse() : color(QRandomGenerator::global()->bounded(256),
: angle(0), speed(0), mouseEyeDirection(0), QRandomGenerator::global()->bounded(256),
color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)) QRandomGenerator::global()->bounded(256))
{ {
setRotation(QRandomGenerator::global()->bounded(360 * 16)); setRotation(QRandomGenerator::global()->bounded(360 * 16));
} }

View File

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

View File

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

View File

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

View File

@ -58,12 +58,10 @@
//! [0] //! [0]
DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu, DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
QGraphicsItem *parent) QGraphicsItem *parent)
: QGraphicsPolygonItem(parent) : QGraphicsPolygonItem(parent), myDiagramType(diagramType)
, myContextMenu(contextMenu)
{ {
myDiagramType = diagramType;
myContextMenu = contextMenu;
QPainterPath path; QPainterPath path;
switch (myDiagramType) { switch (myDiagramType) {
case StartEnd: case StartEnd:
@ -101,17 +99,17 @@ DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
//! [1] //! [1]
void DiagramItem::removeArrow(Arrow *arrow) void DiagramItem::removeArrow(Arrow *arrow)
{ {
int index = arrows.indexOf(arrow); arrows.removeAll(arrow);
if (index != -1)
arrows.removeAt(index);
} }
//! [1] //! [1]
//! [2] //! [2]
void DiagramItem::removeArrows() void DiagramItem::removeArrows()
{ {
for (Arrow *arrow : qAsConst(arrows)) { // need a copy here since removeArrow() will
// modify the arrows container
const auto arrowsCopy = arrows;
for (Arrow *arrow : arrowsCopy) {
arrow->startItem()->removeArrow(arrow); arrow->startItem()->removeArrow(arrow);
arrow->endItem()->removeArrow(arrow); arrow->endItem()->removeArrow(arrow);
scene()->removeItem(arrow); scene()->removeItem(arrow);

View File

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

View File

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

View File

@ -74,7 +74,7 @@ class DiagramScene : public QGraphicsScene
public: public:
enum Mode { InsertItem, InsertLine, InsertText, MoveItem }; enum Mode { InsertItem, InsertLine, InsertText, MoveItem };
explicit DiagramScene(QMenu *itemMenu, QObject *parent = 0); explicit DiagramScene(QMenu *itemMenu, QObject *parent = nullptr);
QFont font() const { return myFont; } QFont font() const { return myFont; }
QColor textColor() const { return myTextColor; } QColor textColor() const { return myTextColor; }
QColor itemColor() const { return myItemColor; } QColor itemColor() const { return myItemColor; }

View File

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

View File

@ -48,10 +48,18 @@
** **
****************************************************************************/ ****************************************************************************/
#include <QtWidgets>
#include "coloritem.h" #include "coloritem.h"
#include <QApplication>
#include <QBitmap>
#include <QCursor>
#include <QDrag>
#include <QGraphicsSceneMouseEvent>
#include <QMimeData>
#include <QPainter>
#include <QRandomGenerator>
#include <QWidget>
//! [0] //! [0]
ColorItem::ColorItem() ColorItem::ColorItem()
: color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)) : color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
@ -128,7 +136,7 @@ void ColorItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
QPainter painter(&pixmap); QPainter painter(&pixmap);
painter.translate(15, 15); painter.translate(15, 15);
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::Antialiasing);
paint(&painter, 0, 0); paint(&painter, nullptr, nullptr);
painter.end(); painter.end();
pixmap.setMask(pixmap.createHeuristicMask()); pixmap.setMask(pixmap.createHeuristicMask());

View File

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

View File

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

View File

@ -62,15 +62,15 @@ QT_END_NAMESPACE
class RobotPart : public QGraphicsObject class RobotPart : public QGraphicsObject
{ {
public: public:
RobotPart(QGraphicsItem *parent = 0); RobotPart(QGraphicsItem *parent = nullptr);
protected: protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override; void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override; void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override;
void dropEvent(QGraphicsSceneDragDropEvent *event) override; void dropEvent(QGraphicsSceneDragDropEvent *event) override;
QColor color; QColor color = Qt::lightGray;
bool dragOver; bool dragOver = false;
}; };
//! [0] //! [0]
@ -78,10 +78,10 @@ protected:
class RobotHead : public RobotPart class RobotHead : public RobotPart
{ {
public: public:
RobotHead(QGraphicsItem *parent = 0); RobotHead(QGraphicsItem *parent = nullptr);
QRectF boundingRect() const override; QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
protected: protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override; void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
@ -96,10 +96,10 @@ private:
class RobotTorso : public RobotPart class RobotTorso : public RobotPart
{ {
public: public:
RobotTorso(QGraphicsItem *parent = 0); using RobotPart::RobotPart;
QRectF boundingRect() const override; QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
}; };
//! [2] //! [2]
@ -107,10 +107,10 @@ public:
class RobotLimb : public RobotPart class RobotLimb : public RobotPart
{ {
public: public:
RobotLimb(QGraphicsItem *parent = 0); RobotLimb(QGraphicsItem *parent = nullptr);
QRectF boundingRect() const override; QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
}; };
//! [3] //! [3]
@ -118,10 +118,10 @@ public:
class Robot : public RobotPart class Robot : public RobotPart
{ {
public: public:
Robot(QGraphicsItem *parent = 0); Robot(QGraphicsItem *parent = nullptr);
QRectF boundingRect() const override; QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
}; };
//! [4] //! [4]

View File

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

View File

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

View File

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

View File

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

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