diff options
Diffstat (limited to 'src/plugins')
68 files changed, 1098 insertions, 909 deletions
diff --git a/src/plugins/imageformats/jpeg/qjpeghandler.cpp b/src/plugins/imageformats/jpeg/qjpeghandler.cpp index 1f1675e490..dd01138722 100644 --- a/src/plugins/imageformats/jpeg/qjpeghandler.cpp +++ b/src/plugins/imageformats/jpeg/qjpeghandler.cpp @@ -248,13 +248,12 @@ static bool ensureValidImage(QImage *dest, struct jpeg_decompress_struct *info, static bool read_jpeg_image(QImage *outImage, QSize scaledSize, QRect scaledClipRect, - QRect clipRect, volatile int inQuality, + QRect clipRect, int quality, Rgb888ToRgb32Converter converter, j_decompress_ptr info, struct my_error_mgr* err ) { if (!setjmp(err->setjmp_buffer)) { // -1 means default quality. - int quality = inQuality; if (quality < 0) quality = 75; @@ -529,7 +528,14 @@ static inline void write_icc_profile(const QImage &image, j_compress_ptr cinfo) } } -static bool write_jpeg_image(const QImage &image, QIODevice *device, volatile int sourceQuality, const QString &description, bool optimize, bool progressive) +static bool do_write_jpeg_image(struct jpeg_compress_struct &cinfo, + JSAMPROW *row_pointer, + const QImage &image, + QIODevice *device, + int sourceQuality, + const QString &description, + bool optimize, + bool progressive) { bool success = false; const QVector<QRgb> cmap = image.colorTable(); @@ -537,10 +543,6 @@ static bool write_jpeg_image(const QImage &image, QIODevice *device, volatile in if (image.format() == QImage::Format_Invalid || image.format() == QImage::Format_Alpha8) return false; - struct jpeg_compress_struct cinfo; - JSAMPROW row_pointer[1]; - row_pointer[0] = 0; - struct my_jpeg_destination_mgr *iod_dest = new my_jpeg_destination_mgr(device); struct my_error_mgr jerr; @@ -713,6 +715,27 @@ static bool write_jpeg_image(const QImage &image, QIODevice *device, volatile in } delete iod_dest; + return success; +} + +static bool write_jpeg_image(const QImage &image, + QIODevice *device, + int sourceQuality, + const QString &description, + bool optimize, + bool progressive) +{ + // protect these objects from the setjmp/longjmp pair inside + // do_write_jpeg_image (by making them non-local). + struct jpeg_compress_struct cinfo; + JSAMPROW row_pointer[1]; + row_pointer[0] = 0; + + const bool success = do_write_jpeg_image(cinfo, row_pointer, + image, device, + sourceQuality, description, + optimize, progressive); + delete [] row_pointer[0]; return success; } diff --git a/src/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro index 78632a9bea..730247cd7f 100644 --- a/src/plugins/platforms/android/android.pro +++ b/src/plugins/platforms/android/android.pro @@ -1,9 +1,5 @@ TARGET = qtforandroid -# STATICPLUGIN needed because there's a Q_IMPORT_PLUGIN in androidjnimain.cpp -# Yes, the plugin imports itself statically -DEFINES += QT_STATICPLUGIN - LIBS += -ljnigraphics -landroid QT += \ @@ -19,7 +15,8 @@ INCLUDEPATH += \ $$PWD \ $$QT_SOURCE_TREE/src/3rdparty/android -SOURCES += $$PWD/androidplatformplugin.cpp \ +SOURCES += $$PWD/main.cpp \ + $$PWD/androidplatformplugin.cpp \ $$PWD/androidcontentfileengine.cpp \ $$PWD/androiddeadlockprotector.cpp \ $$PWD/androidjnimain.cpp \ @@ -92,8 +89,5 @@ qtConfig(vulkan) { } PLUGIN_TYPE = platforms +PLUGIN_CLASS_NAME = QAndroidIntegrationPlugin load(qt_plugin) - -#Non-standard install directory, QTBUG-29859 -DESTDIR = $$DESTDIR/android -target.path = $${target.path}/android diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index 915f7f0f5b..fd2644717e 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -60,6 +60,7 @@ #include "qandroideventdispatcher.h" #include <android/api-level.h> +#include <QtCore/qresource.h> #include <QtCore/qthread.h> #include <QtCore/private/qjnihelpers_p.h> #include <QtCore/private/qjni_p.h> @@ -68,8 +69,6 @@ #include <qpa/qwindowsysteminterface.h> -Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin) - QT_BEGIN_NAMESPACE static JavaVM *m_javaVM = nullptr; @@ -77,6 +76,7 @@ static jclass m_applicationClass = nullptr; static jobject m_classLoaderObject = nullptr; static jmethodID m_loadClassMethodID = nullptr; static AAssetManager *m_assetManager = nullptr; +static jobject m_assets = nullptr; static jobject m_resourcesObj = nullptr; static jobject m_activityObject = nullptr; static jmethodID m_createSurfaceMethodID = nullptr; @@ -441,6 +441,11 @@ namespace QtAndroid return block; } + jobject assets() + { + return m_assets; + } + } // namespace QtAndroid static jboolean startQtAndroidPlugin(JNIEnv *env, jobject /*object*/, jstring paramsString, jstring environmentString) @@ -521,6 +526,10 @@ static jboolean startQtApplication(JNIEnv */*env*/, jclass /*clazz*/) vm->AttachCurrentThread(&env, &args); } + // Register resources if they are available + if (QFile{QStringLiteral("assets:/android_rcc_bundle.rcc")}.exists()) + QResource::registerResource(QStringLiteral("assets:/android_rcc_bundle.rcc")); + QVarLengthArray<const char *> params(m_applicationParams.size()); for (int i = 0; i < m_applicationParams.size(); i++) params[i] = static_cast<const char *>(m_applicationParams[i].constData()); @@ -590,6 +599,8 @@ static void terminateQt(JNIEnv *env, jclass /*clazz*/) env->DeleteGlobalRef(m_RGB_565_BitmapConfigValue); if (m_bitmapDrawableClass) env->DeleteGlobalRef(m_bitmapDrawableClass); + if (m_assets) + env->DeleteGlobalRef(m_assets); m_androidPlatformIntegration = nullptr; delete m_androidAssetsFileEngineHandler; m_androidAssetsFileEngineHandler = nullptr; @@ -842,7 +853,8 @@ static int registerNatives(JNIEnv *env) if (object) { FIND_AND_CHECK_CLASS("android/content/ContextWrapper"); GET_AND_CHECK_METHOD(methodID, clazz, "getAssets", "()Landroid/content/res/AssetManager;"); - m_assetManager = AAssetManager_fromJava(env, env->CallObjectMethod(object, methodID)); + m_assets = env->NewGlobalRef(env->CallObjectMethod(object, methodID)); + m_assetManager = AAssetManager_fromJava(env, m_assets); GET_AND_CHECK_METHOD(methodID, clazz, "getResources", "()Landroid/content/res/Resources;"); m_resourcesObj = env->NewGlobalRef(env->CallObjectMethod(object, methodID)); diff --git a/src/plugins/platforms/android/androidjnimain.h b/src/plugins/platforms/android/androidjnimain.h index 08f1d50fe3..17ae30a1be 100644 --- a/src/plugins/platforms/android/androidjnimain.h +++ b/src/plugins/platforms/android/androidjnimain.h @@ -82,6 +82,7 @@ namespace QtAndroid double scaledDensity(); double pixelDensity(); JavaVM *javaVM(); + jobject assets(); AAssetManager *assetManager(); jclass applicationClass(); jobject activity(); diff --git a/src/plugins/platforms/android/main.cpp b/src/plugins/platforms/android/main.cpp new file mode 100644 index 0000000000..c304fc8d69 --- /dev/null +++ b/src/plugins/platforms/android/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2019 BogDan Vatra <bogdan@kde.org> +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <qpa/qplatformintegrationplugin.h> +#include "qandroidplatformintegration.h" + +QT_BEGIN_NAMESPACE + +class QAndroidIntegrationPlugin : public QPlatformIntegrationPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QPlatformIntegrationFactoryInterface_iid FILE "android.json") + +public: + QPlatformIntegration *create(const QString& system, const QStringList& paramList) override; +}; + +QPlatformIntegration *QAndroidIntegrationPlugin::create(const QString& system, const QStringList& paramList) +{ + if (!system.compare(QLatin1String("android"), Qt::CaseInsensitive)) + return new QAndroidPlatformIntegration(paramList); + + return nullptr; +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp index e1dcebfa4c..26e72a480f 100644 --- a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp +++ b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp @@ -39,40 +39,139 @@ #include "qandroidassetsfileenginehandler.h" #include "androidjnimain.h" +#include <optional> #include <QCoreApplication> #include <QVector> +#include <QtCore/private/qjni_p.h> QT_BEGIN_NAMESPACE -typedef QVector<QString> FilesList; +static const QLatin1String assetsPrefix("assets:"); +const static int prefixSize = 7; -struct AndroidAssetDir +static inline QString cleanedAssetPath(QString file) { - AndroidAssetDir(AAssetDir* ad) + if (file.startsWith(assetsPrefix)) + file.remove(0, prefixSize); + file.replace(QLatin1String("//"), QLatin1String("/")); + if (file.startsWith(QLatin1Char('/'))) + file.remove(0, 1); + if (file.endsWith(QLatin1Char('/'))) + file.chop(1); + return file; +} + +static inline QString prefixedPath(QString path) +{ + path = assetsPrefix + QLatin1Char('/') + path; + path.replace(QLatin1String("//"), QLatin1String("/")); + return path; +} + +struct AssetItem { + enum class Type { + File, + Folder + }; + + AssetItem (const QString &rawName) + : name(rawName) + { + if (name.endsWith(QLatin1Char('/'))) { + type = Type::Folder; + name.chop(1); + } + } + Type type = Type::File; + QString name; +}; + +using AssetItemList = QVector<AssetItem>; + +class FolderIterator : public AssetItemList +{ +public: + static QSharedPointer<FolderIterator> fromCache(const QString &path) { - if (ad) { - const char *fileName; - while ((fileName = AAssetDir_getNextFileName(ad))) - m_items.push_back(QString::fromUtf8(fileName)); - AAssetDir_close(ad); + QMutexLocker lock(&m_assetsCacheMutex); + QSharedPointer<FolderIterator> *folder = m_assetsCache.object(path); + if (!folder) { + folder = new QSharedPointer<FolderIterator>{new FolderIterator{path}}; + if (!m_assetsCache.insert(path, folder)) { + QSharedPointer<FolderIterator> res = *folder; + delete folder; + return res; + } } + return *folder; + } + + FolderIterator(const QString &path) + : m_path(path) + { + QJNIObjectPrivate files = QJNIObjectPrivate::callStaticObjectMethod(QtAndroid::applicationClass(), + "listAssetContent", + "(Landroid/content/res/AssetManager;Ljava/lang/String;)[Ljava/lang/String;", + QtAndroid::assets(), QJNIObjectPrivate::fromString(path).object()); + if (files.isValid()) { + QJNIEnvironmentPrivate env; + jobjectArray jFiles = static_cast<jobjectArray>(files.object()); + const jint nFiles = env->GetArrayLength(jFiles); + for (int i = 0; i < nFiles; ++i) + push_back({QJNIObjectPrivate(env->GetObjectArrayElement(jFiles, i)).toString()}); + } + m_path = assetsPrefix + QLatin1Char('/') + m_path + QLatin1Char('/'); + m_path.replace(QLatin1String("//"), QLatin1String("/")); + } + + QString currentFileName() const + { + if (m_index < 0 || m_index >= size()) + return {}; + return at(m_index).name; + } + QString currentFilePath() const + { + if (m_index < 0 || m_index >= size()) + return {}; + return m_path + at(m_index).name; + } + + bool hasNext() const + { + return !empty() && m_index + 1 < size(); + } + + std::optional<std::pair<QString, AssetItem>> next() + { + if (!hasNext()) + return {}; + ++m_index; + return std::pair<QString, AssetItem>(currentFileName(), at(m_index)); } - FilesList m_items; + +private: + int m_index = -1; + QString m_path; + static QCache<QString, QSharedPointer<FolderIterator>> m_assetsCache; + static QMutex m_assetsCacheMutex; }; +QCache<QString, QSharedPointer<FolderIterator>> FolderIterator::m_assetsCache(std::max(50, qEnvironmentVariableIntValue("QT_ANDROID_MAX_ASSETS_CACHE_SIZE"))); +QMutex FolderIterator::m_assetsCacheMutex; + class AndroidAbstractFileEngineIterator: public QAbstractFileEngineIterator { public: AndroidAbstractFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters, - QSharedPointer<AndroidAssetDir> asset, const QString &path) : QAbstractFileEngineIterator(filters, nameFilters) { - m_items = asset->m_items; - m_index = -1; - m_path = path; + m_stack.push_back(FolderIterator::fromCache(cleanedAssetPath(path))); + if (m_stack.last()->empty()) + m_stack.pop_back(); } QFileInfo currentFileInfo() const override @@ -82,54 +181,59 @@ public: QString currentFileName() const override { - if (m_index < 0 || m_index >= m_items.size()) - return QString(); - QString fileName = m_items[m_index]; - if (fileName.endsWith(QLatin1Char('/'))) - fileName.chop(1); - return fileName; + if (!m_currentIterator) + return {}; + return m_currentIterator->currentFileName(); } virtual QString currentFilePath() const { - return m_path + currentFileName(); + if (!m_currentIterator) + return {}; + return m_currentIterator->currentFilePath(); } bool hasNext() const override { - return m_items.size() && (m_index < m_items.size() - 1); + if (m_stack.empty()) + return false; + if (!m_stack.last()->hasNext()) { + m_stack.pop_back(); + return hasNext(); + } + return true; } QString next() override { - if (!hasNext()) - return QString(); - m_index++; - return currentFileName(); + if (m_stack.empty()) { + m_currentIterator.reset(); + return {}; + } + m_currentIterator = m_stack.last(); + auto res = m_currentIterator->next(); + if (!res) + return {}; + if (res->second.type == AssetItem::Type::Folder) { + m_stack.push_back(FolderIterator::fromCache(cleanedAssetPath(currentFilePath()))); + if (m_stack.last()->empty()) + m_stack.pop_back(); + } + return res->first; } private: - QString m_path; - FilesList m_items; - int m_index; + mutable QSharedPointer<FolderIterator> m_currentIterator; + mutable QVector<QSharedPointer<FolderIterator>> m_stack; }; class AndroidAbstractFileEngine: public QAbstractFileEngine { public: - explicit AndroidAbstractFileEngine(AAsset *asset, const QString &fileName) - { - m_assetFile = asset; - m_fileName = fileName; - } - - explicit AndroidAbstractFileEngine(QSharedPointer<AndroidAssetDir> asset, const QString &fileName) + explicit AndroidAbstractFileEngine(AAssetManager *assetManager, const QString &fileName) + : m_assetManager(assetManager) { - m_assetFile = 0; - m_assetDir = asset; - m_fileName = fileName; - if (!m_fileName.endsWith(QLatin1Char('/'))) - m_fileName += QLatin1Char('/'); + setFileName(fileName); } ~AndroidAbstractFileEngine() @@ -139,7 +243,11 @@ public: bool open(QIODevice::OpenMode openMode) override { - return m_assetFile != 0 && (openMode & QIODevice::WriteOnly) == 0; + if (m_isFolder || (openMode & QIODevice::WriteOnly)) + return false; + close(); + m_assetFile = AAssetManager_open(m_assetManager, m_fileName.toUtf8(), AASSET_MODE_BUFFER); + return m_assetFile; } bool close() override @@ -200,7 +308,7 @@ public: FileFlags flags(ReadOwnerPerm|ReadUserPerm|ReadGroupPerm|ReadOtherPerm|ExistsFlag); if (m_assetFile) flags |= FileType; - if (!m_assetDir.isNull()) + else if (m_isFolder) flags |= DirectoryType; return type & flags; @@ -213,19 +321,19 @@ public: case DefaultName: case AbsoluteName: case CanonicalName: - return m_fileName; + return prefixedPath(m_fileName); case BaseName: if ((pos = m_fileName.lastIndexOf(QChar(QLatin1Char('/')))) != -1) - return m_fileName.mid(pos); + return prefixedPath(m_fileName.mid(pos)); else - return m_fileName; + return prefixedPath(m_fileName); case PathName: case AbsolutePathName: case CanonicalPathName: if ((pos = m_fileName.lastIndexOf(QChar(QLatin1Char('/')))) != -1) - return m_fileName.left(pos); + return prefixedPath(m_fileName.left(pos)); else - return m_fileName; + return prefixedPath(m_fileName); default: return QString(); } @@ -233,164 +341,46 @@ public: void setFileName(const QString &file) override { - if (file == m_fileName) - return; - - m_fileName = file; - if (!m_fileName.endsWith(QLatin1Char('/'))) - m_fileName += QLatin1Char('/'); - close(); + m_fileName = cleanedAssetPath(file); + m_isFolder = !open(QIODevice::ReadOnly) && !FolderIterator::fromCache(m_fileName)->empty(); } Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) override { - if (!m_assetDir.isNull()) - return new AndroidAbstractFileEngineIterator(filters, filterNames, m_assetDir, m_fileName); - return 0; + if (m_isFolder) + return new AndroidAbstractFileEngineIterator(filters, filterNames, m_fileName); + return nullptr; } private: - AAsset *m_assetFile; - QSharedPointer<AndroidAssetDir> m_assetDir; + AAsset *m_assetFile = nullptr; + AAssetManager *m_assetManager; QString m_fileName; + bool m_isFolder; }; AndroidAssetsFileEngineHandler::AndroidAssetsFileEngineHandler() - : m_assetsCache(std::max(5, qEnvironmentVariableIntValue("QT_ANDROID_MAX_ASSETS_CACHE_SIZE"))) - , m_hasPrepopulatedCache(false) - , m_hasTriedPrepopulatingCache(false) { m_assetManager = QtAndroid::assetManager(); } -AndroidAssetsFileEngineHandler::~AndroidAssetsFileEngineHandler() -{ -} - -void AndroidAssetsFileEngineHandler::prepopulateCache() const -{ - Q_ASSERT(!m_hasTriedPrepopulatingCache); - m_hasTriedPrepopulatingCache = true; - - Q_ASSERT(m_assetsCache.isEmpty()); - - // Failsafe: Don't read cache files that are larger than 1MB - static qint64 maxPrepopulatedCacheSize = qMax(1024LL * 1024LL, - qgetenv("QT_ANDROID_MAX_PREPOPULATED_ASSETS_CACHE_SIZE").toLongLong()); - - const char *fileName = "--Added-by-androiddeployqt--/qt_cache_pregenerated_file_list"; - AAsset *asset = AAssetManager_open(m_assetManager, fileName, AASSET_MODE_BUFFER); - if (asset) { - m_hasPrepopulatedCache = true; - AndroidAbstractFileEngine fileEngine(asset, QString::fromLatin1(fileName)); - if (fileEngine.open(QIODevice::ReadOnly)) { - qint64 size = fileEngine.size(); - - if (size <= maxPrepopulatedCacheSize) { - QByteArray bytes(size, Qt::Uninitialized); - qint64 read = fileEngine.read(bytes.data(), size); - if (read != size) { - qWarning("Failed to read prepopulated cache"); - return; - } - - QDataStream stream(&bytes, QIODevice::ReadOnly); - stream.setVersion(QDataStream::Qt_5_3); - if (stream.status() != QDataStream::Ok) { - qWarning("Failed to read prepopulated cache"); - return; - } - - while (!stream.atEnd()) { - QString directoryName; - stream >> directoryName; - - int fileCount; - stream >> fileCount; - - QVector<QString> fileList; - fileList.reserve(fileCount); - while (fileCount--) { - QString fileName; - stream >> fileName; - fileList.append(fileName); - } - - QSharedPointer<AndroidAssetDir> *aad = new QSharedPointer<AndroidAssetDir>(new AndroidAssetDir(0)); - (*aad)->m_items = fileList; - - // Cost = 0, because we should always cache everything if there's a prepopulated cache - QByteArray key = directoryName != QLatin1String("/") - ? QByteArray("assets:/") + directoryName.toUtf8() - : QByteArray("assets:"); - - bool ok = m_assetsCache.insert(key, aad, 0); - if (!ok) - qWarning("Failed to insert in cache: %s", qPrintable(directoryName)); - } - } else { - qWarning("Prepopulated cache is too large to read.\n" - "Use environment variable QT_ANDROID_MAX_PREPOPULATED_ASSETS_CACHE_SIZE to adjust size."); - } - } - } -} - QAbstractFileEngine * AndroidAssetsFileEngineHandler::create(const QString &fileName) const { if (fileName.isEmpty()) - return 0; + return nullptr; - static QLatin1String assetsPrefix("assets:"); if (!fileName.startsWith(assetsPrefix)) - return 0; - - static int prefixSize = assetsPrefix.size() + 1; - - QByteArray path; - if (!fileName.endsWith(QLatin1Char('/'))) { - path = fileName.toUtf8(); - if (path.size() > prefixSize) { - AAsset *asset = AAssetManager_open(m_assetManager, - path.constData() + prefixSize, - AASSET_MODE_BUFFER); - if (asset) - return new AndroidAbstractFileEngine(asset, fileName); - } - } - - if (!path.size()) - path = fileName.left(fileName.length() - 1).toUtf8(); - - - m_assetsCacheMutext.lock(); - if (!m_hasTriedPrepopulatingCache) - prepopulateCache(); - - QSharedPointer<AndroidAssetDir> *aad = m_assetsCache.object(path); - m_assetsCacheMutext.unlock(); - if (!aad) { - if (!m_hasPrepopulatedCache && path.size() > prefixSize) { - AAssetDir *assetDir = AAssetManager_openDir(m_assetManager, path.constData() + prefixSize); - if (assetDir) { - if (AAssetDir_getNextFileName(assetDir)) { - AAssetDir_rewind(assetDir); - aad = new QSharedPointer<AndroidAssetDir>(new AndroidAssetDir(assetDir)); - m_assetsCacheMutext.lock(); - m_assetsCache.insert(path, aad); - m_assetsCacheMutext.unlock(); - return new AndroidAbstractFileEngine(*aad, fileName); - } else { - AAssetDir_close(assetDir); - } - } - } - } else { - return new AndroidAbstractFileEngine(*aad, fileName); - } - return 0; + return nullptr; + + QString path = fileName.mid(prefixSize); + path.replace(QLatin1String("//"), QLatin1String("/")); + if (path.startsWith(QLatin1Char('/'))) + path.remove(0, 1); + if (path.endsWith(QLatin1Char('/'))) + path.chop(1); + return new AndroidAbstractFileEngine(m_assetManager, path); } QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidassetsfileenginehandler.h b/src/plugins/platforms/android/qandroidassetsfileenginehandler.h index f99dc9a11a..51cc5b07a8 100644 --- a/src/plugins/platforms/android/qandroidassetsfileenginehandler.h +++ b/src/plugins/platforms/android/qandroidassetsfileenginehandler.h @@ -49,22 +49,14 @@ QT_BEGIN_NAMESPACE -struct AndroidAssetDir; class AndroidAssetsFileEngineHandler: public QAbstractFileEngineHandler { public: AndroidAssetsFileEngineHandler(); - virtual ~AndroidAssetsFileEngineHandler(); QAbstractFileEngine *create(const QString &fileName) const override; private: - void prepopulateCache() const; - AAssetManager *m_assetManager; - mutable QCache<QByteArray, QSharedPointer<AndroidAssetDir>> m_assetsCache; - mutable QMutex m_assetsCacheMutext; - mutable bool m_hasPrepopulatedCache; - mutable bool m_hasTriedPrepopulatingCache; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformtheme.cpp b/src/plugins/platforms/android/qandroidplatformtheme.cpp index 7fc68c3d7c..d3a8a53241 100644 --- a/src/plugins/platforms/android/qandroidplatformtheme.cpp +++ b/src/plugins/platforms/android/qandroidplatformtheme.cpp @@ -465,7 +465,8 @@ QVariant QAndroidPlatformTheme::themeHint(ThemeHint hint) const return QStringList(QLatin1String("android")); } return QStringList(QLatin1String("fusion")); - + case DialogButtonBoxLayout: + return QVariant(QPlatformDialogHelper::AndroidLayout); case MouseDoubleClickDistance: { int minimumDistance = qEnvironmentVariableIntValue("QT_ANDROID_MINIMUM_MOUSE_DOUBLE_CLICK_DISTANCE"); @@ -489,8 +490,6 @@ QVariant QAndroidPlatformTheme::themeHint(ThemeHint hint) const Q_FALLTHROUGH(); } - case DialogButtonBoxLayout: - return QVariant(QPlatformDialogHelper::AndroidLayout); default: return QPlatformTheme::themeHint(hint); } diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro index 02e00039ae..4cf9e64447 100644 --- a/src/plugins/platforms/cocoa/cocoa.pro +++ b/src/plugins/platforms/cocoa/cocoa.pro @@ -21,8 +21,6 @@ SOURCES += main.mm \ qcocoamenuloader.mm \ qcocoahelpers.mm \ qmultitouch_mac.mm \ - qcocoaaccessibilityelement.mm \ - qcocoaaccessibility.mm \ qcocoacursor.mm \ qcocoaclipboard.mm \ qcocoadrag.mm \ @@ -57,8 +55,6 @@ HEADERS += qcocoaintegration.h \ qcocoamenuloader.h \ qcocoahelpers.h \ qmultitouch_mac_p.h \ - qcocoaaccessibilityelement.h \ - qcocoaaccessibility.h \ qcocoacursor.h \ qcocoaclipboard.h \ qcocoadrag.h \ @@ -83,13 +79,21 @@ qtConfig(vulkan) { HEADERS += qcocoavulkaninstance.h } +qtConfig(accessibility) { + QT += accessibility_support-private + SOURCES += qcocoaaccessibilityelement.mm \ + qcocoaaccessibility.mm + HEADERS += qcocoaaccessibilityelement.h \ + qcocoaaccessibility.h +} + RESOURCES += qcocoaresources.qrc LIBS += -framework AppKit -framework CoreServices -framework Carbon -framework IOKit -framework QuartzCore -framework CoreVideo -framework Metal -framework IOSurface -lcups QT += \ core-private gui-private \ - accessibility_support-private clipboard_support-private theme_support-private \ + clipboard_support-private theme_support-private \ fontdatabase_support-private graphics_support-private qtConfig(vulkan): QT += vulkan_support-private @@ -99,17 +103,20 @@ CONFIG += no_app_extension_api_only qtHaveModule(widgets) { QT_FOR_CONFIG += widgets - SOURCES += \ - qpaintengine_mac.mm \ - qprintengine_mac.mm \ - qcocoaprintersupport.mm \ - qcocoaprintdevice.mm \ - - HEADERS += \ - qpaintengine_mac_p.h \ - qprintengine_mac_p.h \ - qcocoaprintersupport.h \ - qcocoaprintdevice.h \ + SOURCES += qpaintengine_mac.mm + HEADERS += qpaintengine_mac_p.h + + qtHaveModule(printsupport) { + QT += printsupport-private + SOURCES += \ + qprintengine_mac.mm \ + qcocoaprintersupport.mm \ + qcocoaprintdevice.mm + HEADERS += \ + qcocoaprintersupport.h \ + qcocoaprintdevice.h \ + qprintengine_mac_p.h + } qtConfig(colordialog) { SOURCES += qcocoacolordialoghelper.mm @@ -126,7 +133,7 @@ qtHaveModule(widgets) { HEADERS += qcocoafontdialoghelper.h } - QT += widgets-private printsupport-private + QT += widgets-private } OTHER_FILES += cocoa.json diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index 2cf6672da9..2df85c791b 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -171,12 +171,8 @@ QT_USE_NAMESPACE // This function will only be called when NSApp is actually running. - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { - // The reflection delegate gets precedence - if (reflectionDelegate) { - if ([reflectionDelegate respondsToSelector:@selector(applicationShouldTerminate:)]) - return [reflectionDelegate applicationShouldTerminate:sender]; - return NSTerminateNow; - } + if ([reflectionDelegate respondsToSelector:_cmd]) + return [reflectionDelegate applicationShouldTerminate:sender]; if ([self canQuit]) { if (!startedQuit) { @@ -228,10 +224,6 @@ QT_USE_NAMESPACE */ NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager]; [eventManager setEventHandler:self - andSelector:@selector(appleEventQuit:withReplyEvent:) - forEventClass:kCoreEventClass - andEventID:kAEQuitApplication]; - [eventManager setEventHandler:self andSelector:@selector(getUrl:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; @@ -241,7 +233,6 @@ QT_USE_NAMESPACE - (void)removeAppleEventHandlers { NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager]; - [eventManager removeEventHandlerForEventClass:kCoreEventClass andEventID:kAEQuitApplication]; [eventManager removeEventHandlerForEventClass:kInternetEventClass andEventID:kAEGetURL]; } @@ -282,26 +273,22 @@ QT_USE_NAMESPACE QWindowSystemInterface::handleFileOpenEvent(qtFileName); } - if (reflectionDelegate && - [reflectionDelegate respondsToSelector:@selector(application:openFiles:)]) + if ([reflectionDelegate respondsToSelector:_cmd]) [reflectionDelegate application:sender openFiles:filenames]; } - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { - // If we have a reflection delegate, that will get to call the shots. - if (reflectionDelegate - && [reflectionDelegate respondsToSelector: - @selector(applicationShouldTerminateAfterLastWindowClosed:)]) + if ([reflectionDelegate respondsToSelector:_cmd]) return [reflectionDelegate applicationShouldTerminateAfterLastWindowClosed:sender]; + return NO; // Someday qApp->quitOnLastWindowClosed(); when QApp and NSApp work closer together. } - (void)applicationDidBecomeActive:(NSNotification *)notification { - if (reflectionDelegate - && [reflectionDelegate respondsToSelector:@selector(applicationDidBecomeActive:)]) + if ([reflectionDelegate respondsToSelector:_cmd]) [reflectionDelegate applicationDidBecomeActive:notification]; QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationActive); @@ -309,8 +296,7 @@ QT_USE_NAMESPACE - (void)applicationDidResignActive:(NSNotification *)notification { - if (reflectionDelegate - && [reflectionDelegate respondsToSelector:@selector(applicationDidResignActive:)]) + if ([reflectionDelegate respondsToSelector:_cmd]) [reflectionDelegate applicationDidResignActive:notification]; QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationInactive); @@ -318,10 +304,7 @@ QT_USE_NAMESPACE - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag { - Q_UNUSED(theApplication); - Q_UNUSED(flag); - if (reflectionDelegate - && [reflectionDelegate respondsToSelector:@selector(applicationShouldHandleReopen:hasVisibleWindows:)]) + if ([reflectionDelegate respondsToSelector:_cmd]) return [reflectionDelegate applicationShouldHandleReopen:theApplication hasVisibleWindows:flag]; /* @@ -354,16 +337,13 @@ QT_USE_NAMESPACE - (BOOL)respondsToSelector:(SEL)aSelector { - BOOL result = [super respondsToSelector:aSelector]; - if (!result && reflectionDelegate) - result = [reflectionDelegate respondsToSelector:aSelector]; - return result; + return [super respondsToSelector:aSelector] || [reflectionDelegate respondsToSelector:aSelector]; } - (void)forwardInvocation:(NSInvocation *)invocation { SEL invocationSelector = [invocation selector]; - if (reflectionDelegate && [reflectionDelegate respondsToSelector:invocationSelector]) + if ([reflectionDelegate respondsToSelector:invocationSelector]) [invocation invokeWithTarget:reflectionDelegate]; else [self doesNotRecognizeSelector:invocationSelector]; @@ -375,14 +355,6 @@ QT_USE_NAMESPACE NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; QWindowSystemInterface::handleFileOpenEvent(QUrl(QString::fromNSString(urlString))); } - -- (void)appleEventQuit:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent -{ - Q_UNUSED(event); - Q_UNUSED(replyEvent); - [NSApp terminate:self]; -} - @end @implementation QCocoaApplicationDelegate (Menus) diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.h b/src/plugins/platforms/cocoa/qcocoabackingstore.h index 9be6814ae7..a874936ce6 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.h +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.h @@ -54,6 +54,8 @@ class QCocoaBackingStore : public QRasterBackingStore protected: QCocoaBackingStore(QWindow *window); QCFType<CGColorSpaceRef> colorSpace() const; + QMacNotificationObserver m_backingPropertiesObserver; + virtual void backingPropertiesChanged() = 0; }; class QNSWindowBackingStore : public QCocoaBackingStore @@ -69,6 +71,7 @@ private: bool windowHasUnifiedToolbar() const; QImage::Format format() const override; void redrawRoundedBottomCorners(CGRect) const; + void backingPropertiesChanged() override; }; class QCALayerBackingStore : public QCocoaBackingStore @@ -115,6 +118,8 @@ private: bool recreateBackBufferIfNeeded(); bool prepareForFlush(); + void backingPropertiesChanged() override; + std::list<std::unique_ptr<GraphicsBuffer>> m_buffers; }; diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm index 15e0236107..b17302a640 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm @@ -51,6 +51,17 @@ QT_BEGIN_NAMESPACE QCocoaBackingStore::QCocoaBackingStore(QWindow *window) : QRasterBackingStore(window) { + // Ideally this would be plumbed from the platform layer to QtGui, and + // the QBackingStore would be recreated, but we don't have that code yet, + // so at least make sure we invalidate our backingstore when the backing + // properties (color space e.g.) are changed. + NSView *view = static_cast<QCocoaWindow *>(window->handle())->view(); + m_backingPropertiesObserver = QMacNotificationObserver(view.window, + NSWindowDidChangeBackingPropertiesNotification, [this]() { + qCDebug(lcQpaBackingStore) << "Backing properties for" + << this->window() << "did change"; + backingPropertiesChanged(); + }); } QCFType<CGColorSpaceRef> QCocoaBackingStore::colorSpace() const @@ -64,6 +75,37 @@ QCFType<CGColorSpaceRef> QCocoaBackingStore::colorSpace() const QNSWindowBackingStore::QNSWindowBackingStore(QWindow *window) : QCocoaBackingStore(window) { + // Choose an appropriate window depth based on the requested surface format. + // On deep color displays the default bit depth is 16-bit, so unless we need + // that level of precision we opt out of it (and the expensive RGB32 -> RGB64 + // conversions that come with it if our backingstore depth does not match). + + NSWindow *nsWindow = static_cast<QCocoaWindow *>(window->handle())->view().window; + auto colorSpaceName = NSColorSpaceFromDepth(nsWindow.depthLimit); + + static const int kDefaultBitDepth = 8; + auto surfaceFormat = window->requestedFormat(); + auto bitsPerSample = qMax(kDefaultBitDepth, qMax(surfaceFormat.redBufferSize(), + qMax(surfaceFormat.greenBufferSize(), surfaceFormat.blueBufferSize()))); + + // NSBestDepth does not seem to guarantee a window depth deep enough for the + // given bits per sample, even if documented as such. For example, requesting + // 10 bits per sample will not give us a 16-bit format, even if that's what's + // available. Work around this by manually bumping the bit depth. + bitsPerSample = !(bitsPerSample & (bitsPerSample - 1)) + ? bitsPerSample : qNextPowerOfTwo(bitsPerSample); + + auto bestDepth = NSBestDepth(colorSpaceName, bitsPerSample, 0, NO, nullptr); + + // Disable dynamic depth limit, otherwise our depth limit will be overwritten + // by AppKit if the window moves to a screen with a different depth. We call + // this before setting the depth limit, as the call will reset the depth to 0. + [nsWindow setDynamicDepthLimit:NO]; + + qCDebug(lcQpaBackingStore) << "Using" << NSBitsPerSampleFromDepth(bestDepth) + << "bit window depth for" << nsWindow; + + nsWindow.depthLimit = bestDepth; } QNSWindowBackingStore::~QNSWindowBackingStore() @@ -212,9 +254,6 @@ void QNSWindowBackingStore::flush(QWindow *window, const QRegion ®ion, const CGRect viewRect = viewLocalRect.toCGRect(); - if (windowHasUnifiedToolbar()) - NSDrawWindowBackground(viewRect); - [backingStoreImage drawInRect:viewRect fromRect:backingStoreRect.toCGRect() operation:compositingOperation fraction:1.0 respectFlipped:YES hints:nil]; @@ -302,6 +341,11 @@ void QNSWindowBackingStore::redrawRoundedBottomCorners(CGRect windowRect) const #endif } +void QNSWindowBackingStore::backingPropertiesChanged() +{ + m_image = QImage(); +} + // ---------------------------------------------------------------------------- QCALayerBackingStore::QCALayerBackingStore(QWindow *window) @@ -516,17 +560,26 @@ void QCALayerBackingStore::flush(QWindow *flushedWindow, const QRegion ®ion, flushedView.layer.contents = nil; } - qCInfo(lcQpaBackingStore) << "Flushing" << backBufferSurface - << "to" << flushedView.layer << "of" << flushedView; - - flushedView.layer.contents = backBufferSurface; + if (flushedView == backingStoreView) { + qCInfo(lcQpaBackingStore) << "Flushing" << backBufferSurface + << "to" << flushedView.layer << "of" << flushedView; + flushedView.layer.contents = backBufferSurface; + } else { + auto subviewRect = [flushedView convertRect:flushedView.bounds toView:backingStoreView]; + auto scale = flushedView.layer.contentsScale; + subviewRect = CGRectApplyAffineTransform(subviewRect, CGAffineTransformMakeScale(scale, scale)); + + // We make a copy of the image data up front, which means we don't + // need to mark the IOSurface as being in use. FIXME: Investigate + // if there's a cheaper way to get sub-image data to a layer. + m_buffers.back()->lock(QPlatformGraphicsBuffer::SWReadAccess); + QImage subImage = m_buffers.back()->asImage()->copy(QRectF::fromCGRect(subviewRect).toRect()); + m_buffers.back()->unlock(); - if (flushedView != backingStoreView) { - const CGSize backingStoreSize = backingStoreView.bounds.size; - flushedView.layer.contentsRect = CGRectApplyAffineTransform( - [flushedView convertRect:flushedView.bounds toView:backingStoreView], - // The contentsRect is in unit coordinate system - CGAffineTransformMakeScale(1.0 / backingStoreSize.width, 1.0 / backingStoreSize.height)); + qCInfo(lcQpaBackingStore) << "Flushing" << subImage + << "to" << flushedView.layer << "of subview" << flushedView; + QCFType<CGImageRef> cgImage = subImage.toCGImage(); + flushedView.layer.contents = (__bridge id)static_cast<CGImageRef>(cgImage); } // Since we may receive multiple flushes before a new frame is started, we do not @@ -565,6 +618,12 @@ QImage QCALayerBackingStore::toImage() const return imageCopy; } +void QCALayerBackingStore::backingPropertiesChanged() +{ + m_buffers.clear(); + m_buffers.resize(1); +} + QPlatformGraphicsBuffer *QCALayerBackingStore::graphicsBuffer() const { return m_buffers.back().get(); diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index d3bb0711f0..e87fc39c42 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -881,7 +881,7 @@ void QCocoaEventDispatcherPrivate::processPostedEvents() return; } - int serial = serialNumber.load(); + int serial = serialNumber.loadRelaxed(); if (!threadData->canWait || (serial != lastSerial)) { lastSerial = serial; QCoreApplication::sendPostedEvents(); diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index 5f32400af0..03677ef0bc 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -214,7 +214,7 @@ static QString strippedText(QString s) NSString *filepath = info.filePath().toNSString(); NSURL *url = [NSURL fileURLWithPath:filepath isDirectory:info.isDir()]; bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) - || [self panel:nil shouldEnableURL:url]; + || [self panel:mOpenPanel shouldEnableURL:url]; [self updateProperties]; [mSavePanel setNameFieldStringValue:selectable ? info.fileName().toNSString() : @""]; @@ -233,7 +233,7 @@ static QString strippedText(QString s) NSString *filepath = info.filePath().toNSString(); NSURL *url = [NSURL fileURLWithPath:filepath isDirectory:info.isDir()]; bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) - || [self panel:nil shouldEnableURL:url]; + || [self panel:mSavePanel shouldEnableURL:url]; [mSavePanel setDirectoryURL: [NSURL fileURLWithPath:mCurrentDir]]; [mSavePanel setNameFieldStringValue:selectable ? info.fileName().toNSString() : @""]; @@ -263,7 +263,7 @@ static QString strippedText(QString s) NSString *filepath = info.filePath().toNSString(); NSURL *url = [NSURL fileURLWithPath:filepath isDirectory:info.isDir()]; bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) - || [self panel:nil shouldEnableURL:url]; + || [self panel:mSavePanel shouldEnableURL:url]; [self updateProperties]; [mSavePanel setDirectoryURL: [NSURL fileURLWithPath:mCurrentDir]]; diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm index 9bd19dd07c..d0e69bdca5 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm @@ -59,7 +59,7 @@ #include "qguiapplication.h" #include <qdebug.h> -#ifndef QT_NO_WIDGETS +#if !defined(QT_NO_WIDGETS) && defined(QT_PRINTSUPPORT_LIB) #include "qcocoaprintersupport.h" #include "qprintengine_mac_p.h" #include <qpa/qplatformprintersupport.h> @@ -153,24 +153,24 @@ QPlatformNativeInterface::NativeResourceForIntegrationFunction QCocoaNativeInter QPlatformPrinterSupport *QCocoaNativeInterface::createPlatformPrinterSupport() { -#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER) +#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER) && defined(QT_PRINTSUPPORT_LIB) return new QCocoaPrinterSupport(); #else - qFatal("Printing is not supported when Qt is configured with -no-widgets"); + qFatal("Printing is not supported when Qt is configured with -no-widgets or -no-feature-printer"); return nullptr; #endif } void *QCocoaNativeInterface::NSPrintInfoForPrintEngine(QPrintEngine *printEngine) { -#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER) +#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER) && defined(QT_PRINTSUPPORT_LIB) QMacPrintEnginePrivate *macPrintEnginePriv = static_cast<QMacPrintEngine *>(printEngine)->d_func(); if (macPrintEnginePriv->state == QPrinter::Idle && !macPrintEnginePriv->isPrintSessionInitialized()) macPrintEnginePriv->initialize(); return macPrintEnginePriv->printInfo; #else Q_UNUSED(printEngine); - qFatal("Printing is not supported when Qt is configured with -no-widgets"); + qFatal("Printing is not supported when Qt is configured with -no-widgets or -no-feature-printer"); return nullptr; #endif } diff --git a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm index 9b6dc94d33..cb25bd7d81 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the plugins of the Qt Toolkit. @@ -52,6 +52,8 @@ @property (class, strong, readonly) NSColor *unemphasizedSelectedTextColor NS_AVAILABLE_MAC(10_14); @property (class, strong, readonly) NSColor *unemphasizedSelectedContentBackgroundColor NS_AVAILABLE_MAC(10_14); @property (class, strong, readonly) NSArray<NSColor *> *alternatingContentBackgroundColors NS_AVAILABLE_MAC(10_14); +// Missing from non-Mojave SDKs, even if introduced in 10.10 +@property (class, strong, readonly) NSColor *linkColor NS_AVAILABLE_MAC(10_10); @end #endif @@ -111,6 +113,8 @@ QPalette * qt_mac_createSystemPalette() palette->setBrush(QPalette::ToolTipBase, qt_mac_toQBrush([NSColor controlColor])); + palette->setColor(QPalette::Normal, QPalette::Link, qt_mac_toQColor([NSColor linkColor])); + return palette; } diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.h b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.h index 6779bda491..738c40aba6 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.h +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.h @@ -65,7 +65,7 @@ public: void updateMenu(QPlatformMenu *menu) override; QRect geometry() const override; void showMessage(const QString &title, const QString &msg, - const QIcon& icon, MessageIcon iconType, int secs) override; + const QIcon& icon, MessageIcon iconType, int msecs) override; bool isSystemTrayAvailable() const override; bool supportsMessages() const override; diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm index db64702b8d..1390ace632 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm @@ -264,7 +264,7 @@ bool QCocoaSystemTrayIcon::supportsMessages() const } void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &message, - const QIcon& icon, MessageIcon, int) + const QIcon& icon, MessageIcon, int msecs) { if (!m_sys) return; @@ -282,6 +282,10 @@ void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &mess NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter; center.delegate = m_sys->item; [center deliverNotification:notification]; + if (msecs) { + NSTimeInterval timeout = msecs / 1000.0; + [center performSelector:@selector(removeDeliveredNotification:) withObject:notification afterDelay:timeout]; + } [notification release]; } QT_END_NAMESPACE @@ -434,8 +438,7 @@ QT_END_NAMESPACE } - (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification { - Q_UNUSED(center); - Q_UNUSED(notification); + [center removeDeliveredNotification:notification]; emit systray->messageClicked(); } diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 7621508bdd..f212b3e3f0 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1272,14 +1272,11 @@ void QCocoaWindow::windowWillClose() bool QCocoaWindow::windowShouldClose() { qCDebug(lcQpaWindow) << "QCocoaWindow::windowShouldClose" << window(); - // This callback should technically only determine if the window - // should (be allowed to) close, but since our QPA API to determine - // that also involves actually closing the window we do both at the - // same time, instead of doing the latter in windowWillClose. - bool accepted = false; - QWindowSystemInterface::handleCloseEvent(window(), &accepted); - QWindowSystemInterface::flushWindowSystemEvents(); - return accepted; + // This callback should technically only determine if the window + // should (be allowed to) close, but since our QPA API to determine + // that also involves actually closing the window we do both at the + // same time, instead of doing the latter in windowWillClose. + return QWindowSystemInterface::handleCloseEvent<QWindowSystemInterface::SynchronousDelivery>(window()); } // ----------------------------- QPA forwarding ----------------------------- @@ -1646,21 +1643,6 @@ QCocoaNSWindow *QCocoaWindow::createNSWindow(bool shouldBePanel) applyContentBorderThickness(nsWindow); - // Prevent CoreGraphics RGB32 -> RGB64 backing store conversions on deep color - // displays by forcing 8-bit components, unless a deep color format has been - // requested. This conversion uses significant CPU time. - QSurface::SurfaceType surfaceType = QPlatformWindow::window()->surfaceType(); - bool usesCoreGraphics = surfaceType == QSurface::RasterSurface || surfaceType == QSurface::RasterGLSurface; - QSurfaceFormat surfaceFormat = QPlatformWindow::window()->format(); - bool usesDeepColor = surfaceFormat.redBufferSize() > 8 || - surfaceFormat.greenBufferSize() > 8 || - surfaceFormat.blueBufferSize() > 8; - bool usesLayer = view().layer; - if (usesCoreGraphics && !usesDeepColor && !usesLayer) { - [nsWindow setDynamicDepthLimit:NO]; - [nsWindow setDepthLimit:NSWindowDepthTwentyfourBitRGB]; - } - if (format().colorSpace() == QSurfaceFormat::sRGBColorSpace) nsWindow.colorSpace = NSColorSpace.sRGBColorSpace; diff --git a/src/plugins/platforms/cocoa/qnsview_dragging.mm b/src/plugins/platforms/cocoa/qnsview_dragging.mm index 37e972dba9..41b96b2df6 100644 --- a/src/plugins/platforms/cocoa/qnsview_dragging.mm +++ b/src/plugins/platforms/cocoa/qnsview_dragging.mm @@ -270,6 +270,7 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin // The drag was started from within the application response = QWindowSystemInterface::handleDrop(target, nativeDrag->dragMimeData(), point, qtAllowed, buttons, modifiers); + nativeDrag->setAcceptedAction(response.acceptedAction()); } else { QCocoaDropData mimeData(sender.draggingPasteboard); response = QWindowSystemInterface::handleDrop(target, &mimeData, @@ -282,6 +283,7 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin { Q_UNUSED(session); Q_UNUSED(screenPoint); + Q_UNUSED(operation); if (!m_platformWindow) return; @@ -290,8 +292,7 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin if (!target) return; - QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag(); - nativeDrag->setAcceptedAction(qt_mac_mapNSDragOperation(operation)); + QCocoaIntegration::instance()->drag(); // Qt starts drag-and-drop on a mouse button press event. Cococa in // this case won't send the matching release event, so we have to diff --git a/src/plugins/platforms/cocoa/qnsview_drawing.mm b/src/plugins/platforms/cocoa/qnsview_drawing.mm index d2e6f848a0..ce5488ead0 100644 --- a/src/plugins/platforms/cocoa/qnsview_drawing.mm +++ b/src/plugins/platforms/cocoa/qnsview_drawing.mm @@ -43,9 +43,7 @@ - (void)initDrawing { - self.wantsLayer = [self layerExplicitlyRequested] - || [self shouldUseMetalLayer] - || [self layerEnabledByMacOS]; + [self updateLayerBacking]; // Enable high-DPI OpenGL for retina displays. Enabling has the side // effect that Cocoa will start calling glViewport(0, 0, width, height), @@ -71,22 +69,13 @@ return YES; } -- (void)drawRect:(NSRect)dirtyRect -{ - Q_UNUSED(dirtyRect); +// ----------------------- Layer setup ----------------------- - if (!m_platformWindow) - return; - - QRegion exposedRegion; - const NSRect *dirtyRects; - NSInteger numDirtyRects; - [self getRectsBeingDrawn:&dirtyRects count:&numDirtyRects]; - for (int i = 0; i < numDirtyRects; ++i) - exposedRegion += QRectF::fromCGRect(dirtyRects[i]).toRect(); - - qCDebug(lcQpaDrawing) << "[QNSView drawRect:]" << m_platformWindow->window() << exposedRegion; - m_platformWindow->handleExposeEvent(exposedRegion); +- (void)updateLayerBacking +{ + self.wantsLayer = [self layerEnabledByMacOS] + || [self layerExplicitlyRequested] + || [self shouldUseMetalLayer]; } - (BOOL)layerEnabledByMacOS @@ -123,40 +112,81 @@ return surfaceType == QWindow::MetalSurface || surfaceType == QWindow::VulkanSurface; } +/* + This method is called by AppKit when layer-backing is requested by + setting wantsLayer too YES (via -[NSView _updateLayerBackedness]), + or in cases where AppKit itself decides that a view should be + layer-backed. + + Note however that some code paths in AppKit will not go via this + method for creating the backing layer, and will instead create the + layer manually, and just call setLayer. An example of this is when + an NSOpenGLContext is attached to a view, in which case AppKit will + create a new layer in NSOpenGLContextSetLayerOnViewIfNecessary. + + For this reason we leave the implementation of this override as + minimal as possible, only focusing on creating the appropriate + layer type, and then leave it up to setLayer to do the work of + making sure the layer is set up correctly. +*/ - (CALayer *)makeBackingLayer { if ([self shouldUseMetalLayer]) { // Check if Metal is supported. If it isn't then it's most likely // too late at this point and the QWindow will be non-functional, // but we can at least print a warning. - if (![MTLCreateSystemDefaultDevice() autorelease]) { - qWarning() << "QWindow initialization error: Metal is not supported"; - return [super makeBackingLayer]; + if ([MTLCreateSystemDefaultDevice() autorelease]) { + return [CAMetalLayer layer]; + } else { + qCWarning(lcQpaDrawing) << "Failed to create QWindow::MetalSurface." + << "Metal is not supported by any of the GPUs in this system."; } - - CAMetalLayer *layer = [CAMetalLayer layer]; - - // Set the contentsScale for the layer. This is normally done in - // viewDidChangeBackingProperties, however on startup that function - // is called before the layer is created here. The layer's drawableSize - // is updated from layoutSublayersOfLayer as usual. - layer.contentsScale = self.window.backingScaleFactor; - - return layer; } return [super makeBackingLayer]; } +/* + This method is called by AppKit whenever the view is asked to change + its layer, which can happen both as a result of enabling layer-backing, + or when a layer is set explicitly. The latter can happen both when a + view is layer-hosting, or when AppKit internals are switching out the + layer-backed view, as described above for makeBackingLayer. +*/ - (void)setLayer:(CALayer *)layer { - qCDebug(lcQpaDrawing) << "Making" << self << "layer-backed with" << layer - << "due to being" << ([self layerExplicitlyRequested] ? "explicitly requested" + qCDebug(lcQpaDrawing) << "Making" << self + << (self.wantsLayer ? "layer-backed" : "layer-hosted") + << "with" << layer << "due to being" << ([self layerExplicitlyRequested] ? "explicitly requested" : [self shouldUseMetalLayer] ? "needed by surface type" : "enabled by macOS"); + + if (layer.delegate && layer.delegate != self) { + qCWarning(lcQpaDrawing) << "Layer already has delegate" << layer.delegate + << "This delegate is responsible for all view updates for" << self; + } else { + layer.delegate = self; + } + [super setLayer:layer]; - layer.delegate = self; + + // When adding a view to a view hierarchy the backing properties will change + // which results in updating the contents scale, but in case of switching the + // layer on a view that's already in a view hierarchy we need to manually ensure + // the scale is up to date. + if (self.superview) + [self updateLayerContentsScale]; + + if (self.opaque && lcQpaDrawing().isDebugEnabled()) { + // If the view claims to be opaque we expect it to fill the entire + // layer with content, in which case we want to detect any areas + // where it doesn't. + layer.backgroundColor = NSColor.magentaColor.CGColor; + } + } +// ----------------------- Layer updates ----------------------- + - (NSViewLayerContentsRedrawPolicy)layerContentsRedrawPolicy { // We need to set this explicitly since the super implementation @@ -164,64 +194,106 @@ return NSViewLayerContentsRedrawDuringViewResize; } -#if 0 // Disabled until we enable lazy backingstore resizing - (NSViewLayerContentsPlacement)layerContentsPlacement { - // Always place the layer at top left without any automatic scaling, - // so that we can re-use larger layers when resizing a window down. + // Always place the layer at top left without any automatic scaling. + // This will highlight situations where we're missing content for the + // layer by not responding to the displayLayer: request synchronously. + // It also allows us to re-use larger layers when resizing a window down. return NSViewLayerContentsPlacementTopLeft; } -#endif -- (void)updateMetalLayerDrawableSize:(CAMetalLayer *)layer +- (void)viewDidChangeBackingProperties { - CGSize drawableSize = layer.bounds.size; - drawableSize.width *= layer.contentsScale; - drawableSize.height *= layer.contentsScale; - layer.drawableSize = drawableSize; + qCDebug(lcQpaDrawing) << "Backing properties changed for" << self; + + if (self.layer) + [self updateLayerContentsScale]; + + // Ideally we would plumb this situation through QPA in a way that lets + // clients invalidate their own caches, recreate QBackingStore, etc. + // For now we trigger an expose, and let QCocoaBackingStore deal with + // buffer invalidation internally. + [self setNeedsDisplay:YES]; } -- (void)layoutSublayersOfLayer:(CALayer *)layer +- (void)updateLayerContentsScale { - if ([layer isKindOfClass:CAMetalLayer.class]) - [self updateMetalLayerDrawableSize:static_cast<CAMetalLayer* >(layer)]; + // We expect clients to fill the layer with retina aware content, + // based on the devicePixelRatio of the QWindow, so we set the + // layer's content scale to match that. By going via devicePixelRatio + // instead of applying the NSWindow's backingScaleFactor, we also take + // into account OpenGL views with wantsBestResolutionOpenGLSurface set + // to NO. In this case the window will have a backingScaleFactor of 2, + // but the QWindow will have a devicePixelRatio of 1. + auto devicePixelRatio = m_platformWindow->devicePixelRatio(); + qCDebug(lcQpaDrawing) << "Updating" << self.layer << "content scale to" << devicePixelRatio; + self.layer.contentsScale = devicePixelRatio; } -- (void)displayLayer:(CALayer *)layer +/* + This method is called by AppKit to determine whether it should update + the contentScale of the layer to match the window backing scale. + + We always return NO since we're updating the contents scale manually. +*/ +- (BOOL)layer:(CALayer *)layer shouldInheritContentsScale:(CGFloat)scale fromWindow:(NSWindow *)window { - if (!NSThread.isMainThread) { - // Qt is calling AppKit APIs such as -[NSOpenGLContext setView:] on secondary threads, - // which we shouldn't do. This may result in AppKit (wrongly) triggering a display on - // the thread where we made the call, so block it here and defer to the main thread. - qCWarning(lcQpaDrawing) << "Display non non-main thread! Deferring to main thread"; - dispatch_async(dispatch_get_main_queue(), ^{ self.needsDisplay = YES; }); - return; - } + Q_UNUSED(layer); Q_UNUSED(scale); Q_UNUSED(window); + return NO; +} - Q_ASSERT(layer == self.layer); +// ----------------------- Draw callbacks ----------------------- + +/* + This method is called by AppKit for the non-layer case, where we are + drawing into the NSWindow's surface. +*/ +- (void)drawRect:(NSRect)dirtyBoundingRect +{ + Q_ASSERT_X(!self.layer, "QNSView", + "The drawRect code path should not be hit when we are layer backed"); if (!m_platformWindow) return; - qCDebug(lcQpaDrawing) << "[QNSView displayLayer]" << m_platformWindow->window(); + QRegion exposedRegion; + const NSRect *dirtyRects; + NSInteger numDirtyRects; + [self getRectsBeingDrawn:&dirtyRects count:&numDirtyRects]; + for (int i = 0; i < numDirtyRects; ++i) + exposedRegion += QRectF::fromCGRect(dirtyRects[i]).toRect(); - // FIXME: Find out if there's a way to resolve the dirty rect like in drawRect: - m_platformWindow->handleExposeEvent(QRectF::fromCGRect(self.bounds).toRect()); + if (exposedRegion.isEmpty()) + exposedRegion = QRectF::fromCGRect(dirtyBoundingRect).toRect(); + + qCDebug(lcQpaDrawing) << "[QNSView drawRect:]" << m_platformWindow->window() << exposedRegion; + m_platformWindow->handleExposeEvent(exposedRegion); } -- (void)viewDidChangeBackingProperties +/* + This method is called by AppKit when we are layer-backed, where + we are drawing into the layer. +*/ +- (void)displayLayer:(CALayer *)layer { - CALayer *layer = self.layer; - if (!layer) - return; + Q_ASSERT_X(self.layer && layer == self.layer, "QNSView", + "The displayLayer code path should only be hit for our own layer"); - layer.contentsScale = self.window.backingScaleFactor; + if (!m_platformWindow) + return; - // Metal layers must be manually updated on e.g. screen change - if ([layer isKindOfClass:CAMetalLayer.class]) { - [self updateMetalLayerDrawableSize:static_cast<CAMetalLayer* >(layer)]; - [self setNeedsDisplay:YES]; + if (!NSThread.isMainThread) { + // Qt is calling AppKit APIs such as -[NSOpenGLContext setView:] on secondary threads, + // which we shouldn't do. This may result in AppKit (wrongly) triggering a display on + // the thread where we made the call, so block it here and defer to the main thread. + qCWarning(lcQpaDrawing) << "Display non non-main thread! Deferring to main thread"; + dispatch_async(dispatch_get_main_queue(), ^{ self.needsDisplay = YES; }); + return; } + + qCDebug(lcQpaDrawing) << "[QNSView displayLayer]" << m_platformWindow->window(); + m_platformWindow->handleExposeEvent(QRectF::fromCGRect(self.bounds).toRect()); } @end diff --git a/src/plugins/platforms/cocoa/qnsview_mouse.mm b/src/plugins/platforms/cocoa/qnsview_mouse.mm index 7c566442f0..30613eca32 100644 --- a/src/plugins/platforms/cocoa/qnsview_mouse.mm +++ b/src/plugins/platforms/cocoa/qnsview_mouse.mm @@ -394,14 +394,16 @@ } // Close the popups if the click was outside. if (!inside) { + bool selfClosed = false; Qt::WindowType type = QCocoaIntegration::instance()->activePopupWindow()->window()->type(); while (QCocoaWindow *popup = QCocoaIntegration::instance()->popPopupWindow()) { + selfClosed = self == popup->view(); QWindowSystemInterface::handleCloseEvent(popup->window()); QWindowSystemInterface::flushWindowSystemEvents(); } // Consume the mouse event when closing the popup, except for tool tips // were it's expected that the event is processed normally. - if (type != Qt::ToolTip) + if (type != Qt::ToolTip || selfClosed) return; } } diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm index 52f765eb31..6b4e110af2 100644 --- a/src/plugins/platforms/cocoa/qnswindow.mm +++ b/src/plugins/platforms/cocoa/qnswindow.mm @@ -253,20 +253,10 @@ static bool isMouseEvent(NSEvent *ev) return m_platformWindow ? m_platformWindow->isOpaque() : [super isOpaque]; } -/*! - Borderless windows need a transparent background - - Technically windows with NSWindowStyleMaskTexturedBackground - (such as windows with unified toolbars) need to draw the textured - background of the NSWindow, and can't have a transparent - background, but as NSWindowStyleMaskBorderless is 0, you can't - have a window with NSWindowStyleMaskTexturedBackground that is - also borderless. -*/ - (NSColor *)backgroundColor { - return self.styleMask == NSWindowStyleMaskBorderless - ? [NSColor clearColor] : [super backgroundColor]; + return self.styleMask == NSWindowStyleMaskBorderless ? + [NSColor clearColor] : [super backgroundColor]; } - (void)sendEvent:(NSEvent*)theEvent diff --git a/src/plugins/platforms/cocoa/qpaintengine_mac.mm b/src/plugins/platforms/cocoa/qpaintengine_mac.mm index 3677877538..00b2267f0d 100644 --- a/src/plugins/platforms/cocoa/qpaintengine_mac.mm +++ b/src/plugins/platforms/cocoa/qpaintengine_mac.mm @@ -38,14 +38,18 @@ ****************************************************************************/ #include "qpaintengine_mac_p.h" +#if defined(QT_PRINTSUPPORT_LIB) #include "qprintengine_mac_p.h" +#endif #include <qbitmap.h> #include <qpaintdevice.h> #include <qpainterpath.h> #include <qpixmapcache.h> #include <private/qpaintengine_raster_p.h> +#if defined(QT_PRINTSUPPORT_LIB) #include <qprinter.h> +#endif #include <qstack.h> #include <qwidget.h> #include <qvarlengtharray.h> diff --git a/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp b/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp index d7aba66b2f..03be44e095 100644 --- a/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp +++ b/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp @@ -941,6 +941,8 @@ public: { Q_Q(QWindowsDirect2DPaintEngine); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED // Default path (no optimization) if (!(path.shape() == QVectorPath::LinesHint || path.shape() == QVectorPath::PolygonHint) || !pen.dashBrush @@ -948,6 +950,7 @@ public: || q->state()->renderHints.testFlag(QPainter::HighQualityAntialiasing) #endif || q->state()->renderHints.testFlag(QPainter::Antialiasing)) { +QT_WARNING_POP ComPtr<ID2D1Geometry> geometry = vectorPathToID2D1PathGeometry(path); if (!geometry) { qWarning("%s: Could not convert path to d2d geometry", __FUNCTION__); diff --git a/src/plugins/platforms/eglfs/api/qeglfscursor_p.h b/src/plugins/platforms/eglfs/api/qeglfscursor_p.h index 89c2e89f58..8768f9dd8c 100644 --- a/src/plugins/platforms/eglfs/api/qeglfscursor_p.h +++ b/src/plugins/platforms/eglfs/api/qeglfscursor_p.h @@ -59,6 +59,8 @@ #include <QtGui/QOpenGLShaderProgram> #include <QtGui/private/qinputdevicemanager_p.h> +#include <QtCore/qvector.h> + QT_BEGIN_NAMESPACE class QOpenGLShaderProgram; @@ -143,7 +145,7 @@ private: int cursorsPerRow; int width, height; // width and height of the atlas int cursorWidth, cursorHeight; // width and height of cursors inside the atlas - QList<QPoint> hotSpots; + QVector<QPoint> hotSpots; QImage image; // valid until it's uploaded } m_cursorAtlas; diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h index c96dd585d3..d47b579238 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h @@ -41,7 +41,7 @@ #define QEGLFSKMSGBMCURSOR_H #include <qpa/qplatformcursor.h> -#include <QtCore/QList> +#include <QtCore/QVector> #include <QtGui/QImage> #include <QtGui/private/qinputdevicemanager_p.h> @@ -110,7 +110,7 @@ private: int cursorsPerRow; int width, height; // width and height of the atlas int cursorWidth, cursorHeight; // width and height of cursors inside the atlas - QList<QPoint> hotSpots; + QVector<QPoint> hotSpots; QImage image; } m_cursorAtlas; }; diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp index 2034632fb3..16dbfe1522 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp @@ -155,20 +155,33 @@ gbm_surface *QEglFSKmsGbmScreen::createSurface(EGLConfig eglConfig) qCDebug(qLcEglfsKmsDebug, "Creating gbm_surface for screen %s", qPrintable(name())); const auto gbmDevice = static_cast<QEglFSKmsGbmDevice *>(device())->gbmDevice(); - EGLint native_format = -1; - EGLBoolean success = eglGetConfigAttrib(display(), eglConfig, EGL_NATIVE_VISUAL_ID, &native_format); - qCDebug(qLcEglfsKmsDebug) << "Got native format" << Qt::hex << native_format << Qt::dec << "from eglGetConfigAttrib() with return code" << bool(success); - - if (success) - m_gbm_surface = gbm_surface_create(gbmDevice, - rawGeometry().width(), - rawGeometry().height(), - native_format, - GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); + // If there was no format override given in the config file, + // query the native (here, gbm) format from the EGL config. + const bool queryFromEgl = !m_output.drm_format_requested_by_user; + if (queryFromEgl) { + EGLint native_format = -1; + EGLBoolean success = eglGetConfigAttrib(display(), eglConfig, EGL_NATIVE_VISUAL_ID, &native_format); + qCDebug(qLcEglfsKmsDebug) << "Got native format" << Qt::hex << native_format << Qt::dec + << "from eglGetConfigAttrib() with return code" << bool(success); + + if (success) { + m_gbm_surface = gbm_surface_create(gbmDevice, + rawGeometry().width(), + rawGeometry().height(), + native_format, + GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); + if (m_gbm_surface) + m_output.drm_format = gbmFormatToDrmFormat(native_format); + } + } - if (!m_gbm_surface) { // fallback for older drivers + // Fallback for older drivers, and when "format" is explicitly specified + // in the output config. (not guaranteed that the requested format works + // of course, but do what we are told to) + if (!m_gbm_surface) { uint32_t gbmFormat = drmFormatToGbmFormat(m_output.drm_format); - qCDebug(qLcEglfsKmsDebug, "Could not create surface with EGL_NATIVE_VISUAL_ID, falling back to format %x", gbmFormat); + if (queryFromEgl) + qCDebug(qLcEglfsKmsDebug, "Could not create surface with EGL_NATIVE_VISUAL_ID, falling back to format %x", gbmFormat); m_gbm_surface = gbm_surface_create(gbmDevice, rawGeometry().width(), rawGeometry().height(), diff --git a/src/plugins/platforms/ios/qioseventdispatcher.mm b/src/plugins/platforms/ios/qioseventdispatcher.mm index 776343c5aa..c5856051de 100644 --- a/src/plugins/platforms/ios/qioseventdispatcher.mm +++ b/src/plugins/platforms/ios/qioseventdispatcher.mm @@ -211,6 +211,8 @@ namespace } logActivity; } +using namespace QT_PREPEND_NAMESPACE(QtPrivate); + extern "C" int qt_main_wrapper(int argc, char *argv[]) { @autoreleasepool { diff --git a/src/plugins/platforms/ios/quiview_accessibility.mm b/src/plugins/platforms/ios/quiview_accessibility.mm index 458ddcc9b8..6612dc131e 100644 --- a/src/plugins/platforms/ios/quiview_accessibility.mm +++ b/src/plugins/platforms/ios/quiview_accessibility.mm @@ -101,7 +101,7 @@ - (id)accessibilityElementAtIndex:(NSInteger)index { [self initAccessibility]; - if (index >= [m_accessibleElements count]) + if (NSUInteger(index) >= [m_accessibleElements count]) return nil; return m_accessibleElements[index]; } diff --git a/src/plugins/platforms/wasm/qwasmbackingstore.cpp b/src/plugins/platforms/wasm/qwasmbackingstore.cpp index e8eda2605f..7e8a382512 100644 --- a/src/plugins/platforms/wasm/qwasmbackingstore.cpp +++ b/src/plugins/platforms/wasm/qwasmbackingstore.cpp @@ -81,6 +81,11 @@ void QWasmBackingStore::updateTexture() if (m_dirty.isNull()) return; + if (m_recreateTexture && m_texture->isCreated()) { + m_recreateTexture = false; + m_texture->destroy(); + } + if (!m_texture->isCreated()) { m_texture->setMinificationFilter(QOpenGLTexture::Nearest); m_texture->setMagnificationFilter(QOpenGLTexture::Nearest); @@ -146,9 +151,7 @@ void QWasmBackingStore::resize(const QSize &size, const QRegion &staticContents) m_image = QImage(size * window()->devicePixelRatio(), QImage::Format_RGB32); m_image.setDevicePixelRatio(window()->devicePixelRatio()); - - if (m_texture->isCreated()) - m_texture->destroy(); + m_recreateTexture = true; } QImage QWasmBackingStore::toImage() const diff --git a/src/plugins/platforms/wasm/qwasmbackingstore.h b/src/plugins/platforms/wasm/qwasmbackingstore.h index 4bca83c457..b93c96b483 100644 --- a/src/plugins/platforms/wasm/qwasmbackingstore.h +++ b/src/plugins/platforms/wasm/qwasmbackingstore.h @@ -64,6 +64,7 @@ private: QImage m_image; QScopedPointer<QOpenGLTexture> m_texture; QRegion m_dirty; + bool m_recreateTexture = false; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp index f2eabfa486..e536bc0ee3 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.cpp +++ b/src/plugins/platforms/wasm/qwasmscreen.cpp @@ -139,6 +139,8 @@ QPlatformCursor *QWasmScreen::cursor() const void QWasmScreen::resizeMaximizedWindows() { + if (!screen()) + return; QPlatformScreen::resizeMaximizedWindows(); } diff --git a/src/plugins/platforms/windows/openglblacklists/default.json b/src/plugins/platforms/windows/openglblacklists/default.json index 3cfa7e3856..e37351f9e0 100644 --- a/src/plugins/platforms/windows/openglblacklists/default.json +++ b/src/plugins/platforms/windows/openglblacklists/default.json @@ -152,6 +152,18 @@ "features": [ "disable_program_cache" ] - } + }, + { + "id": 13, + "description": "Disable DesktopGL on Windows with Mobile Intel(R) 4 Series Express Chipset Family graphics card (QTBUG-58772)", + "vendor_id": "0x8086", + "device_id": [ "0x2A42" ], + "os": { + "type": "win" + }, + "features": [ + "disable_desktopgl" + ] + } ] } diff --git a/src/plugins/platforms/windows/qwindowsclipboard.cpp b/src/plugins/platforms/windows/qwindowsclipboard.cpp index b87e43f3f7..4e6d3306e1 100644 --- a/src/plugins/platforms/windows/qwindowsclipboard.cpp +++ b/src/plugins/platforms/windows/qwindowsclipboard.cpp @@ -115,12 +115,21 @@ static QDebug operator<<(QDebug d, const QMimeData *mimeData) IDataObject *QWindowsClipboardRetrievalMimeData::retrieveDataObject() const { + enum : int { attempts = 3 }; IDataObject * pDataObj = nullptr; - if (OleGetClipboard(&pDataObj) == S_OK) { - if (QWindowsContext::verbose > 1) - qCDebug(lcQpaMime) << __FUNCTION__ << pDataObj; - return pDataObj; + // QTBUG-53979, retry in case the other application has clipboard locked + for (int i = 1; i <= attempts; ++i) { + if (SUCCEEDED(OleGetClipboard(&pDataObj))) { + if (QWindowsContext::verbose > 1) + qCDebug(lcQpaMime) << __FUNCTION__ << pDataObj; + return pDataObj; + } + qCWarning(lcQpaMime, i == attempts + ? "Unable to obtain clipboard." + : "Retrying to obtain clipboard."); + QThread::msleep(50); } + return nullptr; } diff --git a/src/plugins/platforms/windows/qwindowsglcontext.cpp b/src/plugins/platforms/windows/qwindowsglcontext.cpp index 101db75d0b..d9521e7e08 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.cpp +++ b/src/plugins/platforms/windows/qwindowsglcontext.cpp @@ -196,6 +196,7 @@ bool QWindowsOpengl32DLL::init(bool softwareRendering) wglShareLists = reinterpret_cast<BOOL (WINAPI *)(HGLRC, HGLRC)>(resolve("wglShareLists")); wglSwapBuffers = reinterpret_cast<BOOL (WINAPI *)(HDC)>(resolve("wglSwapBuffers")); wglSetPixelFormat = reinterpret_cast<BOOL (WINAPI *)(HDC, int, const PIXELFORMATDESCRIPTOR *)>(resolve("wglSetPixelFormat")); + wglDescribePixelFormat = reinterpret_cast<int (WINAPI *)(HDC, int, UINT, PIXELFORMATDESCRIPTOR *)>(resolve("wglDescribePixelFormat")); glGetError = reinterpret_cast<GLenum (APIENTRY *)()>(resolve("glGetError")); glGetIntegerv = reinterpret_cast<void (APIENTRY *)(GLenum , GLint *)>(resolve("glGetIntegerv")); @@ -214,6 +215,11 @@ BOOL QWindowsOpengl32DLL::setPixelFormat(HDC dc, int pf, const PIXELFORMATDESCRI return moduleIsNotOpengl32() ? wglSetPixelFormat(dc, pf, pfd) : SetPixelFormat(dc, pf, pfd); } +int QWindowsOpengl32DLL::describePixelFormat(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd) +{ + return moduleIsNotOpengl32() ? wglDescribePixelFormat(dc, pf, size, pfd) : DescribePixelFormat(dc, pf, size, pfd); +} + QWindowsOpenGLContext *QOpenGLStaticContext::createContext(QOpenGLContext *context) { return new QWindowsGLContext(this, context); @@ -322,11 +328,11 @@ static inline bool static void describeFormats(HDC hdc) { - const int pfiMax = DescribePixelFormat(hdc, 0, 0, nullptr); - for (int i = 0; i < pfiMax; i++) { + const int pfiMax = QOpenGLStaticContext::opengl32.describePixelFormat(hdc, 0, 0, nullptr); + for (int i = 1; i <= pfiMax; i++) { PIXELFORMATDESCRIPTOR pfd; initPixelFormatDescriptor(&pfd); - DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd); + QOpenGLStaticContext::opengl32.describePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd); qCDebug(lcQpaGl) << '#' << i << '/' << pfiMax << ':' << pfd; } } @@ -617,7 +623,7 @@ static int choosePixelFormat(HDC hdc, // Verify if format is acceptable. Note that the returned // formats have been observed to not contain PFD_SUPPORT_OPENGL, ignore. initPixelFormatDescriptor(obtainedPfd); - DescribePixelFormat(hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), obtainedPfd); + QOpenGLStaticContext::opengl32.describePixelFormat(hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), obtainedPfd); if (!isAcceptableFormat(additional, *obtainedPfd, true)) { qCDebug(lcQpaGl) << __FUNCTION__ << " obtained px #" << pixelFormat << " not acceptable=" << *obtainedPfd; @@ -885,13 +891,6 @@ QWindowsOpenGLContextFormat QWindowsOpenGLContextFormat::current() result.profile = QSurfaceFormat::CoreProfile; else if (value & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) result.profile = QSurfaceFormat::CompatibilityProfile; - if (result.version < 0x0400) - return result; - // v4.0 onwards - value = 0; - QOpenGLStaticContext::opengl32.glGetIntegerv(RESET_NOTIFICATION_STRATEGY_ARB, &value); - if (value == LOSE_CONTEXT_ON_RESET_ARB) - result.options |= QSurfaceFormat::ResetNotification; return result; } @@ -969,6 +968,7 @@ QOpenGLTemporaryContext::~QOpenGLTemporaryContext() */ #define SAMPLE_BUFFER_EXTENSION "GL_ARB_multisample" +#define ROBUSTNESS_EXTENSION "GL_ARB_robustness" QOpenGLStaticContext::QOpenGLStaticContext() : vendor(QOpenGLStaticContext::getGlString(GL_VENDOR)), @@ -989,9 +989,31 @@ QOpenGLStaticContext::QOpenGLStaticContext() : wglGetExtensionsStringARB(reinterpret_cast<WglGetExtensionsStringARB>( reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("wglGetExtensionsStringARB")))) { - if (extensionNames.startsWith(SAMPLE_BUFFER_EXTENSION " ") - || extensionNames.indexOf(" " SAMPLE_BUFFER_EXTENSION " ") != -1) - extensions |= SampleBuffers; + if (defaultFormat.version < 0x0300) { + if (extensionNames.startsWith(SAMPLE_BUFFER_EXTENSION " ") + || extensionNames.indexOf(" " SAMPLE_BUFFER_EXTENSION " ") != -1) + extensions |= SampleBuffers; + if (extensionNames.startsWith(ROBUSTNESS_EXTENSION " ") + || extensionNames.indexOf(" " ROBUSTNESS_EXTENSION " ") != -1) + extensions |= Robustness; + } else { + typedef const GLubyte * (APIENTRY *glGetStringi_t)(GLenum, GLuint); + auto glGetStringi = reinterpret_cast<glGetStringi_t>( + reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("glGetStringi"))); + if (glGetStringi) { + GLint n = 0; + QOpenGLStaticContext::opengl32.glGetIntegerv(GL_NUM_EXTENSIONS, &n); + for (GLint i = 0; i < n; ++i) { + const char *p = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i)); + if (p) { + if (!strcmp(p, SAMPLE_BUFFER_EXTENSION)) + extensions |= SampleBuffers; + else if (!strcmp(p, ROBUSTNESS_EXTENSION)) + extensions |= Robustness; + } + } + } + } } QByteArray QOpenGLStaticContext::getGlString(unsigned int which) @@ -1230,27 +1252,11 @@ bool QWindowsGLContext::updateObtainedParams(HDC hdc, int *obtainedSwapInterval) if (m_staticContext->wglGetSwapInternalExt && obtainedSwapInterval) *obtainedSwapInterval = m_staticContext->wglGetSwapInternalExt(); - bool hasRobustness = false; - if (m_obtainedFormat.majorVersion() < 3) { - const char *exts = reinterpret_cast<const char *>(QOpenGLStaticContext::opengl32.glGetString(GL_EXTENSIONS)); - hasRobustness = exts && strstr(exts, "GL_ARB_robustness"); - } else { - typedef const GLubyte * (APIENTRY *glGetStringi_t)(GLenum, GLuint); - auto glGetStringi = reinterpret_cast<glGetStringi_t>( - reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("glGetStringi"))); - if (glGetStringi) { - GLint n = 0; - QOpenGLStaticContext::opengl32.glGetIntegerv(GL_NUM_EXTENSIONS, &n); - for (GLint i = 0; i < n; ++i) { - const char *p = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i)); - if (p && !strcmp(p, "GL_ARB_robustness")) { - hasRobustness = true; - break; - } - } - } - } - if (hasRobustness) { + if (testFlag(m_staticContext->extensions, QOpenGLStaticContext::Robustness)) { + GLint value = 0; + QOpenGLStaticContext::opengl32.glGetIntegerv(RESET_NOTIFICATION_STRATEGY_ARB, &value); + if (value == LOSE_CONTEXT_ON_RESET_ARB) + m_obtainedFormat.setOption(QSurfaceFormat::ResetNotification); m_getGraphicsResetStatus = reinterpret_cast<GlGetGraphicsResetStatusArbType>( reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("glGetGraphicsResetStatusARB"))); } diff --git a/src/plugins/platforms/windows/qwindowsglcontext.h b/src/plugins/platforms/windows/qwindowsglcontext.h index 1abe2eb390..e5f6fefd5a 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.h +++ b/src/plugins/platforms/windows/qwindowsglcontext.h @@ -107,6 +107,7 @@ struct QWindowsOpengl32DLL // Wrappers. Always use these instead of SwapBuffers/wglSwapBuffers/etc. BOOL swapBuffers(HDC dc); BOOL setPixelFormat(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd); + int describePixelFormat(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd); // WGL HGLRC (WINAPI * wglCreateContext)(HDC dc); @@ -130,6 +131,7 @@ private: // For Mesa llvmpipe shipped with a name other than opengl32.dll BOOL (WINAPI * wglSwapBuffers)(HDC dc); BOOL (WINAPI * wglSetPixelFormat)(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd); + int (WINAPI * wglDescribePixelFormat)(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd); }; class QOpenGLStaticContext : public QWindowsStaticOpenGLContext @@ -140,7 +142,8 @@ public: enum Extensions { SampleBuffers = 0x1, - sRGBCapableFramebuffer = 0x2 + sRGBCapableFramebuffer = 0x2, + Robustness = 0x4, }; typedef bool diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index 8cd09a34eb..df63adf558 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -42,6 +42,7 @@ #include "qwindowswindow.h" #include "qwindowsintegration.h" #include "qwindowscursor.h" +#include "qwindowstheme.h" #include <QtCore/qt_windows.h> @@ -543,10 +544,13 @@ bool QWindowsScreenManager::handleScreenChanges() // Look for changed monitors, add new ones const WindowsScreenDataList newDataList = monitorData(); const bool lockScreen = newDataList.size() == 1 && (newDataList.front().flags & QWindowsScreenData::LockScreen); + bool primaryScreenChanged = false; for (const QWindowsScreenData &newData : newDataList) { const int existingIndex = indexOfMonitor(m_screens, newData.name); if (existingIndex != -1) { m_screens.at(existingIndex)->handleChanges(newData); + if (existingIndex == 0) + primaryScreenChanged = true; } else { auto *newScreen = new QWindowsScreen(newData); m_screens.push_back(newScreen); @@ -563,6 +567,8 @@ bool QWindowsScreenManager::handleScreenChanges() removeScreen(i); } // for existing screens } // not lock screen + if (primaryScreenChanged) + QWindowsTheme::instance()->refreshFonts(); return true; } diff --git a/src/plugins/platforms/windows/qwindowstheme.h b/src/plugins/platforms/windows/qwindowstheme.h index 4e24308445..07120230ce 100644 --- a/src/plugins/platforms/windows/qwindowstheme.h +++ b/src/plugins/platforms/windows/qwindowstheme.h @@ -85,6 +85,8 @@ public: static bool useNativeMenus(); + void refreshFonts(); + static const char *name; private: @@ -92,7 +94,6 @@ private: void clearPalettes(); void refreshPalettes(); void clearFonts(); - void refreshFonts(); void refreshIconPixmapSizes(); static QWindowsTheme *m_instance; diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 0a97305dd4..5c13bd9650 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -1937,8 +1937,10 @@ void QWindowsWindow::handleGeometryChange() { const QRect previousGeometry = m_data.geometry; m_data.geometry = geometry_sys(); - if (testFlag(WithinDpiChanged)) - return; // QGuiApplication will send resize + if (testFlag(WithinDpiChanged) + && QWindowsContext::instance()->screenManager().screenForHwnd(m_data.hwnd) != screen()) { + return; // QGuiApplication will send resize when screen actually changes + } QWindowSystemInterface::handleGeometryChange(window(), m_data.geometry); // QTBUG-32121: OpenGL/normal windows (with exception of ANGLE) do not receive // expose events when shrinking, synthesize. @@ -2695,10 +2697,16 @@ bool QWindowsWindow::handleNonClientHitTest(const QPoint &globalPos, LRESULT *re return true; } if (localPos.y() < 0) { - const int topResizeBarPos = -frameMargins().top(); - if (localPos.y() >= topResizeBarPos) + // We want to return HTCAPTION/true only over the outer sizing frame, not the entire title bar, + // otherwise the title bar buttons (close, etc.) become unresponsive on Windows 7 (QTBUG-78262). + // However, neither frameMargins() nor GetSystemMetrics(SM_CYSIZEFRAME), etc., give the correct + // sizing frame height in all Windows versions/scales. This empirical constant seems to work, though. + const int sizingHeight = 9; + const int topResizeBarPos = sizingHeight - frameMargins().top(); + if (localPos.y() < topResizeBarPos) { *result = HTCAPTION; // Extend caption over top resize bar, let's user move the window. - return true; + return true; + } } } if (fixedWidth && (localPos.x() < 0 || localPos.x() >= size.width())) { diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp index 943c1ff368..b2b401dd40 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp @@ -670,18 +670,26 @@ HRESULT QWindowsUiaMainProvider::ElementProviderFromPoint(double x, double y, IR QPoint point; nativeUiaPointToPoint(uiaPoint, window, &point); - QAccessibleInterface *targetacc = accessible->childAt(point.x(), point.y()); - - if (targetacc) { - QAccessibleInterface *acc = targetacc; - // Controls can be embedded within grouping elements. By default returns the innermost control. - while (acc) { - targetacc = acc; - // For accessibility tools it may be better to return the text element instead of its subcomponents. - if (targetacc->textInterface()) break; - acc = acc->childAt(point.x(), point.y()); + if (auto targetacc = accessible->childAt(point.x(), point.y())) { + auto acc = accessible->childAt(point.x(), point.y()); + // Reject the cases where childAt() returns a different instance in each call for the same + // element (e.g., QAccessibleTree), as it causes an endless loop with Youdao Dictionary installed. + if (targetacc == acc) { + // Controls can be embedded within grouping elements. By default returns the innermost control. + while (acc) { + targetacc = acc; + // For accessibility tools it may be better to return the text element instead of its subcomponents. + if (targetacc->textInterface()) break; + acc = targetacc->childAt(point.x(), point.y()); + if (acc != targetacc->childAt(point.x(), point.y())) { + qCDebug(lcQpaUiAutomation) << "Non-unique childAt() for" << targetacc; + break; + } + } + *pRetVal = providerForAccessible(targetacc); + } else { + qCDebug(lcQpaUiAutomation) << "Non-unique childAt() for" << accessible; } - *pRetVal = providerForAccessible(targetacc); } return S_OK; } diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp index 8e395669f8..d8b8f7281d 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp @@ -48,6 +48,7 @@ #include <QtGui/qaccessible.h> #include <QtCore/qloggingcategory.h> #include <QtCore/qstring.h> +#include <QtCore/qvarlengtharray.h> QT_BEGIN_NAMESPACE @@ -227,7 +228,7 @@ HRESULT QWindowsUiaTextRangeProvider::GetBoundingRectangles(SAFEARRAY **pRetVal) return UIA_E_ELEMENTNOTAVAILABLE; int len = textInterface->characterCount(); - QList<QRect> rectList; + QVarLengthArray<QRect> rectList; if ((m_startOffset >= 0) && (m_endOffset <= len) && (m_startOffset < m_endOffset)) { int start, end; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp index 524000b618..355dbf7d20 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp @@ -51,6 +51,8 @@ #include <QtCore/QString> #include <QtCore/private/qeventdispatcher_winrt_p.h> +#include <memory> + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -105,19 +107,17 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaGridItemProvider::get_ContainingGrid(IIRawEle *value = nullptr; auto accid = id(); - auto elementId = QSharedPointer<QAccessible::Id>(new QAccessible::Id(0)); - auto ptrElementId = new QSharedPointer<QAccessible::Id>(elementId); + auto elementId = std::make_shared<QAccessible::Id>(0); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementId]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementId]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) { if (QAccessibleInterface *table = tableCellInterface->table()) { - **ptrElementId = idForAccessible(table); - QWinRTUiaMetadataCache::instance()->load(**ptrElementId); + *elementId = idForAccessible(table); + QWinRTUiaMetadataCache::instance()->load(*elementId); } } } - delete ptrElementId; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp index e469991de2..3bd90f6850 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp @@ -51,6 +51,8 @@ #include <QtCore/QString> #include <QtCore/private/qeventdispatcher_winrt_p.h> +#include <memory> + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -104,21 +106,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaGridProvider::GetItem(INT32 row, INT32 column *returnValue = nullptr; auto accid = id(); - auto elementId = QSharedPointer<QAccessible::Id>(new QAccessible::Id(0)); - auto ptrElementId = new QSharedPointer<QAccessible::Id>(elementId); + auto elementId = std::make_shared<QAccessible::Id>(0); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, row, column, ptrElementId]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, row, column, elementId]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) { if ((row >= 0) && (row < tableInterface->rowCount()) && (column >= 0) && (column < tableInterface->columnCount())) { if (QAccessibleInterface *cell = tableInterface->cellAt(row, column)) { - **ptrElementId = idForAccessible(cell); - QWinRTUiaMetadataCache::instance()->load(**ptrElementId); + *elementId = idForAccessible(cell); + QWinRTUiaMetadataCache::instance()->load(*elementId); } } } } - delete ptrElementId; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp index 6f3ad6dcd2..0b1db306bd 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp @@ -64,6 +64,8 @@ #include <QtCore/qfunctions_winrt.h> #include <QtCore/private/qeventdispatcher_winrt_p.h> +#include <memory> + using namespace QWinRTUiAutomation; using namespace Microsoft::WRL; using namespace Microsoft::WRL::Wrappers; @@ -179,7 +181,7 @@ HRESULT QWinRTUiaMainProvider::rawProviderForAccessibleId(QAccessible::Id elemen } // Returns an array of IIRawElementProviderSimple instances for a list of accessible interface ids. -HRESULT QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(const QList<QAccessible::Id> &elementIds, +HRESULT QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(const QVarLengthArray<QAccessible::Id> &elementIds, UINT32 *returnValueSize, IIRawElementProviderSimple ***returnValue) { @@ -190,7 +192,7 @@ HRESULT QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(const QList<Q QList<IIRawElementProviderSimple *> rawProviderList; - for (auto elementId : qAsConst(elementIds)) { + for (auto elementId : elementIds) { IIRawElementProviderSimple *rawProvider; if (SUCCEEDED(rawProviderForAccessibleId(elementId, &rawProvider))) rawProviderList.append(rawProvider); @@ -515,10 +517,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetChildrenCore(IVector<Automat *returnValue = nullptr; auto accid = id(); - auto children = QSharedPointer<QList<QAccessible::Id>>(new QList<QAccessible::Id>); - auto ptrChildren = new QSharedPointer<QList<QAccessible::Id>>(children); + auto children = std::make_shared<QVarLengthArray<QAccessible::Id>>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrChildren]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, children]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { int childCount = accessible->childCount(); for (int i = 0; i < childCount; ++i) { @@ -526,11 +527,10 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetChildrenCore(IVector<Automat QAccessible::Id childId = idForAccessible(childAcc); QWinRTUiaMetadataCache::instance()->load(childId); if (!childAcc->state().invisible) - (*ptrChildren)->append(childId); + children->append(childId); } } } - delete ptrChildren; return S_OK; }))) { return E_FAIL; @@ -538,7 +538,7 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetChildrenCore(IVector<Automat ComPtr<IVector<AutomationPeer *>> peerVector = Make<QWinRTUiaPeerVector>(); - for (auto childId : qAsConst(*children)) { + for (auto childId : *children) { if (ComPtr<QWinRTUiaMainProvider> provider = providerForAccessibleId(childId)) { IAutomationPeer *peer; if (SUCCEEDED(provider.CopyTo(&peer))) @@ -750,10 +750,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetPeerFromPointCore(ABI::Windo // Scale coordinates from High DPI screens? auto accid = id(); - auto elementId = QSharedPointer<QAccessible::Id>(new QAccessible::Id(0)); - auto ptrElementId = new QSharedPointer<QAccessible::Id>(elementId); + auto elementId = std::make_shared<QAccessible::Id>(0); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementId, point]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementId, point]() { // Controls can be embedded within grouping elements. By default returns the innermost control. QAccessibleInterface *target = accessibleForId(accid); while (QAccessibleInterface *tmpacc = target->childAt(point.X, point.Y)) { @@ -761,9 +760,8 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetPeerFromPointCore(ABI::Windo // For accessibility tools it may be better to return the text element instead of its subcomponents. if (target->textInterface()) break; } - **ptrElementId = idForAccessible(target); - QWinRTUiaMetadataCache::instance()->load(**ptrElementId); - delete ptrElementId; + *elementId = idForAccessible(target); + QWinRTUiaMetadataCache::instance()->load(*elementId); return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h index 384a166cf7..23a6e56ae7 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h @@ -69,7 +69,7 @@ public: virtual ~QWinRTUiaMainProvider(); static QWinRTUiaMainProvider *providerForAccessibleId(QAccessible::Id id); static HRESULT rawProviderForAccessibleId(QAccessible::Id elementId, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple **returnValue); - static HRESULT rawProviderArrayForAccessibleIdList(const QList<QAccessible::Id> &elementIds, UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple ***returnValue); + static HRESULT rawProviderArrayForAccessibleIdList(const QVarLengthArray<QAccessible::Id> &elementIds, UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple ***returnValue); static void notifyFocusChange(QAccessibleEvent *event); static void notifyVisibilityChange(QAccessibleEvent *event); static void notifyStateChange(QAccessibleStateChangeEvent *event); diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp index 9bc88272ba..2cb5aa685c 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp @@ -51,6 +51,8 @@ #include <QtCore/QString> #include <QtCore/private/qeventdispatcher_winrt_p.h> +#include <memory> + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -94,21 +96,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionItemProvider::get_SelectionContainer *value = nullptr; auto accid = id(); - auto elementId = QSharedPointer<QAccessible::Id>(new QAccessible::Id(0)); - auto ptrElementId = new QSharedPointer<QAccessible::Id>(elementId); + auto elementId = std::make_shared<QAccessible::Id>(0); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementId]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementId]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { // Radio buttons do not require a container. if (accessible->role() == QAccessible::ListItem) { if (QAccessibleInterface *parent = accessible->parent()) { if (parent->role() == QAccessible::List) { - **ptrElementId = idForAccessible(parent); + *elementId = idForAccessible(parent); } } } } - delete ptrElementId; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp index 9e61a8df61..4d825351c8 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp @@ -51,6 +51,8 @@ #include <QtCore/QString> #include <QtCore/private/qeventdispatcher_winrt_p.h> +#include <memory> + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -89,10 +91,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::get_IsSelectionRequired(bo *value = false; auto accid = id(); - auto selectionRequired = QSharedPointer<bool>(new bool(false)); - auto ptrSelectionRequired = new QSharedPointer<bool>(selectionRequired); + auto selectionRequired = std::make_shared<bool>(false); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrSelectionRequired]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, selectionRequired]() { // Initially returns false if none are selected. After the first selection, it may be required. bool anySelected = false; if (QAccessibleInterface *accessible = accessibleForId(accid)) { @@ -105,9 +106,8 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::get_IsSelectionRequired(bo } } } - **ptrSelectionRequired = anySelected && !accessible->state().multiSelectable && !accessible->state().extSelectable; + *selectionRequired = anySelected && !accessible->state().multiSelectable && !accessible->state().extSelectable; } - delete ptrSelectionRequired; return S_OK; }))) { return E_FAIL; @@ -128,10 +128,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::GetSelection(UINT32 *retur *returnValue = nullptr; auto accid = id(); - auto elementIds = QSharedPointer<QList<QAccessible::Id>>(new QList<QAccessible::Id>); - auto ptrElementIds = new QSharedPointer<QList<QAccessible::Id>>(elementIds); + auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { int childCount = accessible->childCount(); for (int i = 0; i < childCount; ++i) { @@ -139,12 +138,11 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::GetSelection(UINT32 *retur if (childAcc->state().selected) { QAccessible::Id childId = idForAccessible(childAcc); QWinRTUiaMetadataCache::instance()->load(childId); - (*ptrElementIds)->append(childId); + elementIds->append(childId); } } } } - delete ptrElementIds; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp index 1af74a8b72..7cd953de87 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp @@ -51,6 +51,8 @@ #include <QtCore/QString> #include <QtCore/private/qeventdispatcher_winrt_p.h> +#include <memory> + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -79,21 +81,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableItemProvider::GetColumnHeaderItems(UINT3 *returnValue = nullptr; auto accid = id(); - auto elementIds = QSharedPointer<QList<QAccessible::Id>>(new QList<QAccessible::Id>); - auto ptrElementIds = new QSharedPointer<QList<QAccessible::Id>>(elementIds); + auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) { QList<QAccessibleInterface *> headers = tableCellInterface->columnHeaderCells(); for (auto header : qAsConst(headers)) { QAccessible::Id headerId = idForAccessible(header); QWinRTUiaMetadataCache::instance()->load(headerId); - (*ptrElementIds)->append(headerId); + elementIds->append(headerId); } } } - delete ptrElementIds; return S_OK; }))) { return E_FAIL; @@ -113,21 +113,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableItemProvider::GetRowHeaderItems(UINT32 * *returnValue = nullptr; auto accid = id(); - auto elementIds = QSharedPointer<QList<QAccessible::Id>>(new QList<QAccessible::Id>); - auto ptrElementIds = new QSharedPointer<QList<QAccessible::Id>>(elementIds); + auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) { QList<QAccessibleInterface *> headers = tableCellInterface->rowHeaderCells(); for (auto header : qAsConst(headers)) { QAccessible::Id headerId = idForAccessible(header); QWinRTUiaMetadataCache::instance()->load(headerId); - (*ptrElementIds)->append(headerId); + elementIds->append(headerId); } } } - delete ptrElementIds; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp index e71ade3c1f..d763b320b1 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp @@ -51,6 +51,8 @@ #include <QtCore/QString> #include <QtCore/private/qeventdispatcher_winrt_p.h> +#include <memory> + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -91,10 +93,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetColumnHeaders(UINT32 *retur *returnValue = nullptr; auto accid = id(); - auto elementIds = QSharedPointer<QList<QAccessible::Id>>(new QList<QAccessible::Id>); - auto ptrElementIds = new QSharedPointer<QList<QAccessible::Id>>(elementIds); + auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) { for (int i = 0; i < tableInterface->columnCount(); ++i) { @@ -105,14 +106,13 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetColumnHeaders(UINT32 *retur for (auto header : qAsConst(headers)) { QAccessible::Id headerId = idForAccessible(header); QWinRTUiaMetadataCache::instance()->load(headerId); - (*ptrElementIds)->append(headerId); + elementIds->append(headerId); } } } } } } - delete ptrElementIds; return S_OK; }))) { return E_FAIL; @@ -132,10 +132,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetRowHeaders(UINT32 *returnVa *returnValue = nullptr; auto accid = id(); - auto elementIds = QSharedPointer<QList<QAccessible::Id>>(new QList<QAccessible::Id>); - auto ptrElementIds = new QSharedPointer<QList<QAccessible::Id>>(elementIds); + auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) { for (int i = 0; i < tableInterface->rowCount(); ++i) { @@ -146,14 +145,13 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetRowHeaders(UINT32 *returnVa for (auto header : qAsConst(headers)) { QAccessible::Id headerId = idForAccessible(header); QWinRTUiaMetadataCache::instance()->load(headerId); - (*ptrElementIds)->append(headerId); + elementIds->append(headerId); } } } } } } - delete ptrElementIds; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp index aa120377df..cd7420f360 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp @@ -51,6 +51,8 @@ #include <QtCore/QString> #include <QtCore/private/qeventdispatcher_winrt_p.h> +#include <memory> + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -104,26 +106,26 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::GetSelection(UINT32 *returnValu *returnValueSize = 0; *returnValue = nullptr; + struct Selection { int startOffset, endOffset; }; + auto accid = id(); - auto selections = QSharedPointer<QList<QPair<int,int>>>(new QList<QPair<int,int>>); - auto ptrSelections = new QSharedPointer<QList<QPair<int,int>>>(selections); + auto selections = std::make_shared<QVarLengthArray<Selection>>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrSelections]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, selections]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTextInterface *textInterface = accessible->textInterface()) { for (int i = 0; i < textInterface->selectionCount(); ++i) { - QPair<int,int> sel; - textInterface->selection(i, &sel.first, &sel.second); - (*ptrSelections)->append(sel); + int startOffset, endOffset; + textInterface->selection(i, &startOffset, &endOffset); + selections->append({startOffset, endOffset}); } - if ((*ptrSelections)->size() == 0) { + if (selections->size() == 0) { // If there is no selection, we return an array with a single degenerate (empty) text range at the cursor position. - QPair<int,int> sel(textInterface->cursorPosition(), textInterface->cursorPosition()); - (*ptrSelections)->append(sel); + auto cur = textInterface->cursorPosition(); + selections->append({cur, cur}); } } } - delete ptrSelections; return S_OK; }))) { return E_FAIL; @@ -137,9 +139,11 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::GetSelection(UINT32 *returnValu if (!providerArray) return E_OUTOFMEMORY; - for (int i = 0; i < selCount; ++i) { - ComPtr<QWinRTUiaTextRangeProvider> textRangeProvider = Make<QWinRTUiaTextRangeProvider>(id(), (*selections)[i].first, (*selections)[i].second); - textRangeProvider.CopyTo(&providerArray[i]); + auto dst = providerArray; + for (auto sel : *selections) { + ComPtr<QWinRTUiaTextRangeProvider> textRangeProvider + = Make<QWinRTUiaTextRangeProvider>(id(), sel.startOffset, sel.endOffset); + textRangeProvider.CopyTo(dst++); } *returnValueSize = selCount; *returnValue = providerArray; @@ -184,14 +188,12 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::RangeFromPoint(ABI::Windows::Fo const QPoint pt(screenLocation.X, screenLocation.Y); auto accid = id(); - auto offset = QSharedPointer<int>(new int); - auto ptrOffset = new QSharedPointer<int>(offset); + auto offset = std::make_shared<int>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, pt, ptrOffset]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, pt, offset]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) if (QAccessibleTextInterface *textInterface = accessible->textInterface()) - **ptrOffset = qBound(0, textInterface->offsetAtPoint(pt), textInterface->characterCount() - 1); - delete ptrOffset; + *offset = qBound(0, textInterface->offsetAtPoint(pt), textInterface->characterCount() - 1); return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp index fc3778d652..ca15feaff9 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp @@ -51,6 +51,8 @@ #include <QtCore/QString> #include <QtCore/private/qeventdispatcher_winrt_p.h> +#include <memory> + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -212,10 +214,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT auto accid = id(); auto startOffset = m_startOffset; auto endOffset = m_endOffset; - auto rects = QSharedPointer<QList<QRect>>(new QList<QRect>); - auto ptrRects = new QSharedPointer<QList<QRect>>(rects); + auto rects = std::make_shared<QVarLengthArray<QRect>>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, startOffset, endOffset, ptrRects]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, startOffset, endOffset, rects]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTextInterface *textInterface = accessible->textInterface()) { int len = textInterface->characterCount(); @@ -233,7 +234,7 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT qMin(startRect.y(), endRect.y()), qMax(startRect.x() + startRect.width(), endRect.x() + endRect.width()) - qMin(startRect.x(), endRect.x()), qMax(startRect.y() + startRect.height(), endRect.y() + endRect.height()) - qMin(startRect.y(), endRect.y())); - (*ptrRects)->append(lineRect); + rects->append(lineRect); } if (end >= len) break; textInterface->textAfterOffset(end + 1, QAccessible::LineBoundary, &start, &end); @@ -241,7 +242,6 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT } } } - delete ptrRects; return S_OK; }))) { return E_FAIL; @@ -251,11 +251,12 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT if (!doubleArray) return E_OUTOFMEMORY; - for (int i = 0; i < rects->size(); ++i) { - doubleArray[i*4] = (*rects)[i].left(); - doubleArray[i*4+1] = (*rects)[i].top(); - doubleArray[i*4+2] = (*rects)[i].width(); - doubleArray[i*4+3] = (*rects)[i].height(); + DOUBLE *dst = doubleArray; + for (auto rect : *rects) { + *dst++ = rect.left(); + *dst++ = rect.top(); + *dst++ = rect.width(); + *dst++ = rect.height(); } *returnValue = doubleArray; *returnValueSize = 4 * rects->size(); diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp index 21389b74d2..255d8ee49e 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp @@ -96,24 +96,22 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaValueProvider::SetValue(HSTRING value) qCDebug(lcQpaUiAutomation) << __FUNCTION__; auto accid = id(); - auto tmpValue = QSharedPointer<QString>(new QString); - auto ptrValue = new QSharedPointer<QString>(tmpValue); - *tmpValue = hStrToQStr(value); + QString tmpValue = hStrToQStr(value); - QEventDispatcherWinRT::runOnMainThread([accid, ptrValue]() { + QEventDispatcherWinRT::runOnMainThread([accid, tmpValue]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { // First sets the value as a text. - accessible->setText(QAccessible::Value, **ptrValue); + accessible->setText(QAccessible::Value, tmpValue); // Then, if the control supports the value interface (range value) // and the supplied text can be converted to a number, and that number // lies within the min/max limits, sets it as the control's current (numeric) value. if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) { bool ok = false; - double numval = (*ptrValue)->toDouble(&ok); + double numval = tmpValue.toDouble(&ok); if (ok) { double minimum = valueInterface->minimumValue().toDouble(); double maximum = valueInterface->maximumValue().toDouble(); @@ -124,7 +122,6 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaValueProvider::SetValue(HSTRING value) } } QWinRTUiaMetadataCache::instance()->load(accid); - delete ptrValue; return S_OK; }, 0); diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp index 5e5fefca90..2b77062b16 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp @@ -63,6 +63,7 @@ QT_BEGIN_NAMESPACE typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); +typedef const GLubyte *(*glGetStringiProc)(GLenum, GLuint); #ifndef GLX_CONTEXT_CORE_PROFILE_BIT_ARB #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 @@ -145,6 +146,27 @@ static inline QByteArray getGlString(GLenum param) return QByteArray(); } +static bool hasGlExtension(const QSurfaceFormat &format, const char *ext) +{ + if (format.majorVersion() < 3) { + auto exts = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)); + return exts && strstr(exts, ext); + } else { + auto glGetStringi = reinterpret_cast<glGetStringiProc>( + glXGetProcAddress(reinterpret_cast<const GLubyte*>("glGetStringi"))); + if (glGetStringi) { + GLint n = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &n); + for (GLint i = 0; i < n; ++i) { + const char *p = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i)); + if (p && !strcmp(p, ext)) + return true; + } + } + return false; + } +} + static void updateFormatFromContext(QSurfaceFormat &format) { // Update the version, profile, and context bit of the format @@ -163,7 +185,7 @@ static void updateFormatFromContext(QSurfaceFormat &format) format.setOption(QSurfaceFormat::StereoBuffers); if (format.renderableType() == QSurfaceFormat::OpenGL) { - if (format.version() >= qMakePair(4, 0)) { + if (hasGlExtension(format, "GL_ARB_robustness")) { GLint value = 0; glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &value); if (value == GL_LOSE_CONTEXT_ON_RESET_ARB) diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index 0fe22bd318..8da299d491 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -773,7 +773,7 @@ void QXcbScreen::updateRefreshRate(xcb_randr_mode_t mode) xcb_randr_mode_info_t *modeInfo = modesIter.data; if (modeInfo->id == mode) { const uint32_t dotCount = modeInfo->htotal * modeInfo->vtotal; - m_refreshRate = (dotCount != 0) ? modeInfo->dot_clock / dotCount : 0; + m_refreshRate = (dotCount != 0) ? modeInfo->dot_clock / qreal(dotCount) : 0; m_mode = mode; break; } diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h index 62931d2500..79698b4ef3 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.h +++ b/src/plugins/platforms/xcb/qxcbscreen.h @@ -226,7 +226,7 @@ private: QRect m_availableGeometry; Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation; QXcbCursor *m_cursor; - int m_refreshRate = 60; + qreal m_refreshRate = 60.0; QEdidParser m_edid; }; diff --git a/src/plugins/printsupport/cups/qppdprintdevice.cpp b/src/plugins/printsupport/cups/qppdprintdevice.cpp index 90411f2a2c..8bfa239dbe 100644 --- a/src/plugins/printsupport/cups/qppdprintdevice.cpp +++ b/src/plugins/printsupport/cups/qppdprintdevice.cpp @@ -40,13 +40,11 @@ #include "qppdprintdevice.h" #include "qcupsprintersupport_p.h" +#include "private/qcups_p.h" // Only needed for PDPK_* #if QT_CONFIG(mimetype) #include <QtCore/QMimeDatabase> #endif -#include <qdebug.h> - -#include "private/qcups_p.h" // Only needed for PDPK_* #ifndef QT_LINUXBASE // LSB merges everything into cups.h #include <cups/language.h> diff --git a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp index ead08dbce8..d0928fe6ab 100644 --- a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp +++ b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp @@ -40,6 +40,7 @@ #include "qsql_ibase_p.h" #include <qcoreapplication.h> #include <qdatetime.h> +#include <qdeadlinetimer.h> #include <qvariant.h> #include <qsqlerror.h> #include <qsqlfield.h> @@ -1570,10 +1571,9 @@ void QIBaseDriver::close() d->eventBuffers.clear(); #if defined(FB_API_VER) - // Workaround for Firebird crash - QTime timer; - timer.start(); - while (timer.elapsed() < 500) + // TODO check whether this workaround for Firebird crash is still needed + QDeadlineTimer timer(500); + while (!timer.hasExpired()) QCoreApplication::processEvents(); #endif } @@ -1914,7 +1914,12 @@ void QIBaseDriver::qHandleEventNotification(void *updatedResultBuffer) if (counts[0]) { if (eBuffer->subscriptionState == QIBaseEventBuffer::Subscribed) { +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED emit notification(i.key()); +QT_WARNING_POP +#endif emit notification(i.key(), QSqlDriver::UnknownSource, QVariant()); } else if (eBuffer->subscriptionState == QIBaseEventBuffer::Starting) diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp index febbe58506..0e195cfdb4 100644 --- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp +++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp @@ -65,16 +65,7 @@ Q_DECLARE_METATYPE(MYSQL_RES*) Q_DECLARE_METATYPE(MYSQL*) - -#if MYSQL_VERSION_ID >= 40108 Q_DECLARE_METATYPE(MYSQL_STMT*) -#endif - -#if MYSQL_VERSION_ID >= 40100 -# define Q_CLIENT_MULTI_STATEMENTS CLIENT_MULTI_STATEMENTS -#else -# define Q_CLIENT_MULTI_STATEMENTS 0 -#endif // MySQL above version 8 removed my_bool typedef while MariaDB kept it, // by redefining it we can regain source compatibility. @@ -199,10 +190,8 @@ protected: bool nextResult() override; void detachFromResultSet() override; -#if MYSQL_VERSION_ID >= 40108 bool prepare(const QString &stmt) override; bool exec() override; -#endif }; class QMYSQLResultPrivate: public QSqlResultPrivate @@ -217,9 +206,7 @@ public: result(0), rowsAffected(0), hasBlobs(false) -#if MYSQL_VERSION_ID >= 40108 , stmt(0), meta(0), inBinds(0), outBinds(0) -#endif , preparedQuery(false) { } @@ -247,13 +234,11 @@ public: QVector<QMyField> fields; -#if MYSQL_VERSION_ID >= 40108 MYSQL_STMT* stmt; MYSQL_RES* meta; MYSQL_BIND *inBinds; MYSQL_BIND *outBinds; -#endif bool preparedQuery; }; @@ -261,11 +246,9 @@ public: #if QT_CONFIG(textcodec) static QTextCodec* codec(MYSQL* mysql) { -#if MYSQL_VERSION_ID >= 32321 QTextCodec* heuristicCodec = QTextCodec::codecForName(mysql_character_set_name(mysql)); if (heuristicCodec) return heuristicCodec; -#endif return QTextCodec::codecForLocale(); } #endif // textcodec @@ -350,8 +333,6 @@ static QSqlField qToField(MYSQL_FIELD *field, QTextCodec *tc) return f; } -#if MYSQL_VERSION_ID >= 40108 - static QSqlError qMakeStmtError(const QString& err, QSqlError::ErrorType type, MYSQL_STMT* stmt) { @@ -445,7 +426,6 @@ bool QMYSQLResultPrivate::bindInValues() } return true; } -#endif QMYSQLResult::QMYSQLResult(const QMYSQLDriver* db) : QSqlResult(*new QMYSQLResultPrivate(this, db)) @@ -460,11 +440,9 @@ QMYSQLResult::~QMYSQLResult() QVariant QMYSQLResult::handle() const { Q_D(const QMYSQLResult); -#if MYSQL_VERSION_ID >= 40108 if(d->preparedQuery) return d->meta ? QVariant::fromValue(d->meta) : QVariant::fromValue(d->stmt); else -#endif return QVariant::fromValue(d->result); } @@ -476,15 +454,12 @@ void QMYSQLResult::cleanup() // must iterate trough leftover result sets from multi-selects or stored procedures // if this isn't done subsequent queries will fail with "Commands out of sync" -#if MYSQL_VERSION_ID >= 40100 while (driver() && d->drv_d_func()->mysql && mysql_next_result(d->drv_d_func()->mysql) == 0) { MYSQL_RES *res = mysql_store_result(d->drv_d_func()->mysql); if (res) mysql_free_result(res); } -#endif -#if MYSQL_VERSION_ID >= 40108 if (d->stmt) { if (mysql_stmt_close(d->stmt)) qWarning("QMYSQLResult::cleanup: unable to free statement handle"); @@ -509,7 +484,6 @@ void QMYSQLResult::cleanup() delete[] d->inBinds; d->inBinds = 0; } -#endif d->hasBlobs = false; d->fields.clear(); @@ -536,7 +510,6 @@ bool QMYSQLResult::fetch(int i) if (at() == i) return true; if (d->preparedQuery) { -#if MYSQL_VERSION_ID >= 40108 mysql_stmt_data_seek(d->stmt, i); int nRC = mysql_stmt_fetch(d->stmt); @@ -550,9 +523,6 @@ bool QMYSQLResult::fetch(int i) "Unable to fetch data"), QSqlError::StatementError, d->stmt)); return false; } -#else - return false; -#endif } else { mysql_data_seek(d->result, i); d->row = mysql_fetch_row(d->result); @@ -570,7 +540,6 @@ bool QMYSQLResult::fetchNext() if (!driver()) return false; if (d->preparedQuery) { -#if MYSQL_VERSION_ID >= 40108 int nRC = mysql_stmt_fetch(d->stmt); if (nRC) { #ifdef MYSQL_DATA_TRUNCATED @@ -582,9 +551,6 @@ bool QMYSQLResult::fetchNext() "Unable to fetch data"), QSqlError::StatementError, d->stmt)); return false; } -#else - return false; -#endif } else { d->row = mysql_fetch_row(d->result); if (!d->row) @@ -607,11 +573,7 @@ bool QMYSQLResult::fetchLast() my_ulonglong numRows; if (d->preparedQuery) { -#if MYSQL_VERSION_ID >= 40108 numRows = mysql_stmt_num_rows(d->stmt); -#else - numRows = 0; -#endif } else { numRows = mysql_num_rows(d->result); } @@ -788,11 +750,7 @@ int QMYSQLResult::size() Q_D(const QMYSQLResult); if (driver() && isSelect()) if (d->preparedQuery) -#if MYSQL_VERSION_ID >= 40108 return mysql_stmt_num_rows(d->stmt); -#else - return -1; -#endif else return int(mysql_num_rows(d->result)); else @@ -821,11 +779,9 @@ QVariant QMYSQLResult::lastInsertId() const return QVariant(); if (d->preparedQuery) { -#if MYSQL_VERSION_ID >= 40108 quint64 id = mysql_stmt_insert_id(d->stmt); if (id) return QVariant(id); -#endif } else { quint64 id = mysql_insert_id(d->drv_d_func()->mysql); if (id) @@ -842,11 +798,7 @@ QSqlRecord QMYSQLResult::record() const if (!isActive() || !isSelect() || !driver()) return info; -#if MYSQL_VERSION_ID >= 40108 res = d->preparedQuery ? d->meta : d->result; -#else - res = d->result; -#endif if (!mysql_errno(d->drv_d_func()->mysql)) { mysql_field_seek(res, 0); @@ -865,7 +817,7 @@ bool QMYSQLResult::nextResult() Q_D(QMYSQLResult); if (!driver()) return false; -#if MYSQL_VERSION_ID >= 40100 + setAt(-1); setActive(false); @@ -908,9 +860,6 @@ bool QMYSQLResult::nextResult() setActive(true); return true; -#else - return false; -#endif } void QMYSQLResult::virtual_hook(int id, void *data) @@ -918,9 +867,6 @@ void QMYSQLResult::virtual_hook(int id, void *data) QSqlResult::virtual_hook(id, data); } - -#if MYSQL_VERSION_ID >= 40108 - static MYSQL_TIME *toMySqlDate(QDate date, QTime time, QVariant::Type type) { Q_ASSERT(type == QVariant::Time || type == QVariant::Date @@ -949,7 +895,7 @@ bool QMYSQLResult::prepare(const QString& query) Q_D(QMYSQLResult); if (!driver()) return false; -#if MYSQL_VERSION_ID >= 40108 + cleanup(); if (!d->drv_d_func()->preparedQuerysEnabled) return QSqlResult::prepare(query); @@ -983,9 +929,6 @@ bool QMYSQLResult::prepare(const QString& query) setSelect(d->bindInValues()); d->preparedQuery = true; return true; -#else - return false; -#endif } bool QMYSQLResult::exec() @@ -1155,7 +1098,7 @@ bool QMYSQLResult::exec() setActive(true); return true; } -#endif + ///////////////////////////////////////////////////////// static int qMySqlConnectionCount = 0; @@ -1164,18 +1107,16 @@ static bool qMySqlInitHandledByUser = false; static void qLibraryInit() { #ifndef Q_NO_MYSQL_EMBEDDED -# if MYSQL_VERSION_ID >= 40000 if (qMySqlInitHandledByUser || qMySqlConnectionCount > 1) return; -# if (MYSQL_VERSION_ID >= 40110 && MYSQL_VERSION_ID < 50000) || MYSQL_VERSION_ID >= 50003 +# if MYSQL_VERSION_ID >= 50003 if (mysql_library_init(0, 0, 0)) { # else if (mysql_server_init(0, 0, 0)) { # endif qWarning("QMYSQLDriver::qServerInit: unable to start server."); } -# endif // MYSQL_VERSION_ID #endif // Q_NO_MYSQL_EMBEDDED #if defined(MARIADB_BASE_VERSION) || defined(MARIADB_VERSION_ID) @@ -1187,12 +1128,10 @@ static void qLibraryEnd() { #if !defined(MARIADB_BASE_VERSION) && !defined(MARIADB_VERSION_ID) # if !defined(Q_NO_MYSQL_EMBEDDED) -# if MYSQL_VERSION_ID > 40000 -# if (MYSQL_VERSION_ID >= 40110 && MYSQL_VERSION_ID < 50000) || MYSQL_VERSION_ID >= 50003 - mysql_library_end(); -# else - mysql_server_end(); -# endif +# if MYSQL_VERSION_ID >= 50003 + mysql_library_end(); +# else + mysql_server_end(); # endif # endif #endif @@ -1271,17 +1210,9 @@ bool QMYSQLDriver::hasFeature(DriverFeature f) const return true; case PreparedQueries: case PositionalPlaceholders: -#if MYSQL_VERSION_ID >= 40108 return d->preparedQuerysEnabled; -#else - return false; -#endif case MultipleResultSets: -#if MYSQL_VERSION_ID >= 40100 return true; -#else - return false; -#endif } return false; } @@ -1322,7 +1253,7 @@ bool QMYSQLDriver::open(const QString& db, we have to enable CLIEN_MULTI_STATEMENTS here, otherwise _any_ stored procedure call will fail. */ - unsigned int optionFlags = Q_CLIENT_MULTI_STATEMENTS; + unsigned int optionFlags = CLIENT_MULTI_STATEMENTS; const QStringList opts(connOpts.split(QLatin1Char(';'), QString::SkipEmptyParts)); QString unixSocket; QString sslCert; @@ -1330,12 +1261,10 @@ bool QMYSQLDriver::open(const QString& db, QString sslKey; QString sslCAPath; QString sslCipher; -#if MYSQL_VERSION_ID >= 50000 my_bool reconnect=false; uint connectTimeout = 0; uint readTimeout = 0; uint writeTimeout = 0; -#endif // extract the real options from the string for (int i = 0; i < opts.count(); ++i) { @@ -1346,18 +1275,15 @@ bool QMYSQLDriver::open(const QString& db, QString opt = tmp.left(idx).simplified(); if (opt == QLatin1String("UNIX_SOCKET")) unixSocket = val; -#if MYSQL_VERSION_ID >= 50000 else if (opt == QLatin1String("MYSQL_OPT_RECONNECT")) { if (val == QLatin1String("TRUE") || val == QLatin1String("1") || val.isEmpty()) reconnect = true; - } else if (opt == QLatin1String("MYSQL_OPT_CONNECT_TIMEOUT")) { + } else if (opt == QLatin1String("MYSQL_OPT_CONNECT_TIMEOUT")) connectTimeout = val.toInt(); - } else if (opt == QLatin1String("MYSQL_OPT_READ_TIMEOUT")) { + else if (opt == QLatin1String("MYSQL_OPT_READ_TIMEOUT")) readTimeout = val.toInt(); - } else if (opt == QLatin1String("MYSQL_OPT_WRITE_TIMEOUT")) { + else if (opt == QLatin1String("MYSQL_OPT_WRITE_TIMEOUT")) writeTimeout = val.toInt(); - } -#endif else if (opt == QLatin1String("SSL_KEY")) sslKey = val; else if (opt == QLatin1String("SSL_CERT")) @@ -1442,7 +1368,7 @@ bool QMYSQLDriver::open(const QString& db, return false; } -#if (MYSQL_VERSION_ID >= 40113 && MYSQL_VERSION_ID < 50000) || MYSQL_VERSION_ID >= 50007 +#if MYSQL_VERSION_ID >= 50007 if (mysql_get_client_version() >= 50503 && mysql_get_server_version(d->mysql) >= 50503) { // force the communication to be utf8mb4 (only utf8mb4 supports 4-byte characters) mysql_set_character_set(d->mysql, "utf8mb4"); @@ -1457,20 +1383,15 @@ bool QMYSQLDriver::open(const QString& db, d->tc = codec(d->mysql); #endif } -#endif +#endif // MYSQL_VERSION_ID >= 50007 -#if MYSQL_VERSION_ID >= 40108 d->preparedQuerysEnabled = mysql_get_client_version() >= 40108 && mysql_get_server_version(d->mysql) >= 40100; -#else - d->preparedQuerysEnabled = false; -#endif #if QT_CONFIG(thread) mysql_thread_init(); #endif - setOpen(true); setOpenError(false); return true; @@ -1499,46 +1420,21 @@ QStringList QMYSQLDriver::tables(QSql::TableType type) const { Q_D(const QMYSQLDriver); QStringList tl; -#if MYSQL_VERSION_ID >= 40100 - if( mysql_get_server_version(d->mysql) < 50000) - { -#endif - if (!isOpen()) - return tl; - if (!(type & QSql::Tables)) - return tl; - - MYSQL_RES* tableRes = mysql_list_tables(d->mysql, NULL); - MYSQL_ROW row; - int i = 0; - while (tableRes) { - mysql_data_seek(tableRes, i); - row = mysql_fetch_row(tableRes); - if (!row) - break; - tl.append(toUnicode(d->tc, row[0])); - i++; - } - mysql_free_result(tableRes); -#if MYSQL_VERSION_ID >= 40100 - } else { - QSqlQuery q(createResult()); - if(type & QSql::Tables) { - QString sql = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'BASE TABLE'"); - q.exec(sql); + QSqlQuery q(createResult()); + if (type & QSql::Tables) { + QString sql = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'BASE TABLE'"); + q.exec(sql); - while(q.next()) - tl.append(q.value(0).toString()); - } - if(type & QSql::Views) { - QString sql = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'VIEW'"); - q.exec(sql); + while (q.next()) + tl.append(q.value(0).toString()); + } + if (type & QSql::Views) { + QString sql = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'VIEW'"); + q.exec(sql); - while(q.next()) - tl.append(q.value(0).toString()); - } + while (q.next()) + tl.append(q.value(0).toString()); } -#endif return tl; } diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index 0bae45382d..b85a1ac4c7 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -428,12 +428,14 @@ static QVariant::Type qDecodePSQLType(int t) void QPSQLResultPrivate::deallocatePreparedStmt() { - const QString stmt = QStringLiteral("DEALLOCATE ") + preparedStmtId; - PGresult *result = drv_d_func()->exec(stmt); + if (drv_d_func()) { + const QString stmt = QStringLiteral("DEALLOCATE ") + preparedStmtId; + PGresult *result = drv_d_func()->exec(stmt); - if (PQresultStatus(result) != PGRES_COMMAND_OK) - qWarning("Unable to free statement: %s", PQerrorMessage(drv_d_func()->connection)); - PQclear(result); + if (PQresultStatus(result) != PGRES_COMMAND_OK) + qWarning("Unable to free statement: %s", PQerrorMessage(drv_d_func()->connection)); + PQclear(result); + } preparedStmtId.clear(); } @@ -810,8 +812,8 @@ QSqlRecord QPSQLResult::record() const return info; int count = PQnfields(d->result); + QSqlField f; for (int i = 0; i < count; ++i) { - QSqlField f; if (d->drv_d_func()->isUtf8) f.setName(QString::fromUtf8(PQfname(d->result, i))); else @@ -831,6 +833,8 @@ QSqlRecord QPSQLResult::record() const } } f.setTableName(tableName); + } else { + f.setTableName(QString()); } int ptype = PQftype(d->result, i); f.setType(qDecodePSQLType(ptype)); @@ -1690,7 +1694,12 @@ void QPSQLDriver::_q_handleNotification(int) if (notify->extra) payload = d->isUtf8 ? QString::fromUtf8(notify->extra) : QString::fromLatin1(notify->extra); #endif +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED emit notification(name); +QT_WARNING_POP +#endif QSqlDriver::NotificationSource source = (notify->be_pid == PQbackendPID(d->connection)) ? QSqlDriver::SelfSource : QSqlDriver::OtherSource; emit notification(name, source, payload); } diff --git a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp index 001bd673fc..65d3f0a580 100644 --- a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp +++ b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp @@ -1044,7 +1044,12 @@ void QSQLiteDriver::handleNotification(const QString &tableName, qint64 rowid) { Q_D(const QSQLiteDriver); if (d->notificationid.contains(tableName)) { +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED emit notification(tableName); +QT_WARNING_POP +#endif emit notification(tableName, QSqlDriver::UnknownSource, QVariant(rowid)); } } diff --git a/src/plugins/styles/android/qandroidstyle.cpp b/src/plugins/styles/android/qandroidstyle.cpp index 086df92322..1d0838daec 100644 --- a/src/plugins/styles/android/qandroidstyle.cpp +++ b/src/plugins/styles/android/qandroidstyle.cpp @@ -248,7 +248,7 @@ QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::PrimitiveElement primit case QStyle::PE_FrameLineEdit: return QC_EditText; - case QStyle::PE_IndicatorViewItemCheck: + case QStyle::PE_IndicatorItemViewItemCheck: case QStyle::PE_IndicatorCheckBox: return QC_Checkbox; diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index ec3bb91ebf..7fa330beab 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -328,6 +328,20 @@ static const int closeButtonSize = 14; static const qreal closeButtonCornerRadius = 2.0; #endif // QT_CONFIG(tabbar) +#ifndef QT_NO_ACCESSIBILITY // This ifdef to avoid "unused function" warning. +QBrush brushForToolButton(bool isOnKeyWindow) +{ + // When a toolbutton in a toolbar is in the 'ON' state, we draw a + // partially transparent background. The colors must be different + // for 'Aqua' and 'DarkAqua' appearances though. + if (isDarkMode()) + return isOnKeyWindow ? QColor(73, 73, 73, 100) : QColor(56, 56, 56, 100); + + return isOnKeyWindow ? QColor(0, 0, 0, 28) : QColor(0, 0, 0, 21); +} +#endif // QT_NO_ACCESSIBILITY + + static const int headerSectionArrowHeight = 6; static const int headerSectionSeparatorInset = 2; @@ -555,10 +569,10 @@ QRect rotateTabPainter(QPainter *p, QTabBar::Shape shape, QRect tabRect) newRot = -90; } tabRect.setRect(0, 0, tabRect.height(), tabRect.width()); - QMatrix m; - m.translate(newX, newY); - m.rotate(newRot); - p->setMatrix(m, true); + QTransform transform; + transform.translate(newX, newY); + transform.rotate(newRot); + p->setTransform(transform, true); } return tabRect; } @@ -2951,24 +2965,24 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai } #endif - QMatrix matrix; - matrix.translate(opt->rect.center().x() + xOffset, opt->rect.center().y() + 2); + QTransform transform; + transform.translate(opt->rect.center().x() + xOffset, opt->rect.center().y() + 2); QPainterPath path; switch(pe) { default: case PE_IndicatorArrowDown: break; case PE_IndicatorArrowUp: - matrix.rotate(180); + transform.rotate(180); break; case PE_IndicatorArrowLeft: - matrix.rotate(90); + transform.rotate(90); break; case PE_IndicatorArrowRight: - matrix.rotate(-90); + transform.rotate(-90); break; } - p->setMatrix(matrix); + p->setTransform(transform); path.moveTo(-halfSize, -halfSize * 0.5); path.lineTo(0.0, halfSize * 0.5); @@ -3211,7 +3225,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai CGContextRestoreGState(cg); break; } - case PE_IndicatorViewItemCheck: + case PE_IndicatorItemViewItemCheck: case PE_IndicatorRadioButton: case PE_IndicatorCheckBox: { const bool isEnabled = opt->state & State_Enabled; @@ -3462,6 +3476,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter { Q_D(const QMacStyle); const AppearanceSync sync; + const QMacAutoReleasePool pool; QMacCGContext cg(p); QWindow *window = w && w->window() ? w->window()->windowHandle() : nullptr; d->resolveCurrentNSView(window); @@ -4326,7 +4341,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter break; case CE_ProgressBarContents: if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) { - QMacAutoReleasePool pool; const bool isIndeterminate = (pb->minimum == 0 && pb->maximum == 0); const bool vertical = pb->orientation == Qt::Vertical; const bool inverted = pb->invertedAppearance; @@ -5603,8 +5617,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex if (view) isKey = [view.window isKeyWindow]; - QBrush brush(isKey ? QColor(0, 0, 0, 28) - : QColor(0, 0, 0, 21)); + QBrush brush(brushForToolButton(isKey)); QPainterPath path; path.addRoundedRect(QRectF(tb->rect.x(), tb->rect.y(), tb->rect.width(), tb->rect.height() + 4), 4, 4); p->setRenderHint(QPainter::Antialiasing); diff --git a/src/plugins/styles/windowsvista/main.cpp b/src/plugins/styles/windowsvista/main.cpp index d5048e45b7..5e7bcf5e6e 100644 --- a/src/plugins/styles/windowsvista/main.cpp +++ b/src/plugins/styles/windowsvista/main.cpp @@ -48,7 +48,7 @@ class QWindowsVistaStylePlugin : public QStylePlugin Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "windowsvistastyle.json") public: - QStyle *create(const QString &key); + QStyle *create(const QString &key) override; }; QStyle *QWindowsVistaStylePlugin::create(const QString &key) @@ -56,7 +56,7 @@ QStyle *QWindowsVistaStylePlugin::create(const QString &key) if (key.compare(QLatin1String("windowsvista"), Qt::CaseInsensitive) == 0) return new QWindowsVistaStyle(); - return 0; + return nullptr; } QT_END_NAMESPACE diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp index c4ada66ca9..e213d65946 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp @@ -44,7 +44,6 @@ #include <qwindow.h> #include <private/qstyleanimation_p.h> #include <private/qstylehelper_p.h> -#include <private/qapplication_p.h> #include <qpa/qplatformnativeinterface.h> QT_BEGIN_NAMESPACE @@ -84,15 +83,14 @@ static const int windowsRightBorder = 15; // right border on windows */ bool QWindowsVistaStylePrivate::useVista() { - return QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista - && QWindowsVistaStylePrivate::useXP(); + return QWindowsVistaStylePrivate::useXP(); } /* \internal Checks and returns the style object */ inline QObject *styleObject(const QStyleOption *option) { - return option ? option->styleObject : 0; + return option ? option->styleObject : nullptr; } /* \internal @@ -117,7 +115,7 @@ static inline QImage createAnimationBuffer(const QStyleOption *option, const QWi Used by animations to clone a styleoption and shift its offset */ QStyleOption *clonedAnimationStyleOption(const QStyleOption*option) { - QStyleOption *styleOption = 0; + QStyleOption *styleOption = nullptr; if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider*>(option)) styleOption = new QStyleOptionSlider(*slider); else if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox*>(option)) @@ -298,7 +296,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt int oldState = styleObject->property("_q_stylestate").toInt(); oldRect = styleObject->property("_q_stylerect").toRect(); newRect = option->rect; - styleObject->setProperty("_q_stylestate", (int)option->state); + styleObject->setProperty("_q_stylestate", int(option->state)); styleObject->setProperty("_q_stylerect", option->rect); bool doTransition = oldState && @@ -316,7 +314,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt if (doTransition) { QStyleOption *styleOption = clonedAnimationStyleOption(option); - styleOption->state = (QStyle::State)oldState; + styleOption->state = QStyle::State(oldState); QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject)); QWindowsVistaTransition *t = new QWindowsVistaTransition(styleObject); @@ -341,7 +339,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt // The end state of the transition is simply the result we would have painted // if the style was not animated. - styleOption->styleObject = 0; + styleOption->styleObject = nullptr; styleOption->state = option->state; proxy()->drawPrimitive(element, styleOption, &endPainter, widget); @@ -356,7 +354,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt //translate state flags to UXTHEME states : if (element == PE_FrameLineEdit) { - theme = OpenThemeData(0, L"Edit"); + theme = OpenThemeData(nullptr, L"Edit"); partId = EP_EDITBORDER_NOSCROLL; if (oldState & State_MouseOver) @@ -374,7 +372,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt toState = ETS_NORMAL; } else { - theme = OpenThemeData(0, L"Button"); + theme = OpenThemeData(nullptr, L"Button"); if (element == PE_IndicatorRadioButton) partId = BP_RADIOBUTTON; else if (element == PE_IndicatorCheckBox) @@ -390,7 +388,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt if (theme && SUCCEEDED(GetThemeTransitionDuration(theme, partId, fromState, toState, TMT_TRANSITIONDURATIONS, &duration))) { - t->setDuration(duration); + t->setDuration(int(duration)); } t->setStartTime(QTime::currentTime()); @@ -535,7 +533,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt else if (state & State_MouseOver) stateId = EBS_HOT; - XPThemeData theme(0, painter, QWindowsXPStylePrivate::EditTheme, + XPThemeData theme(nullptr, painter, QWindowsXPStylePrivate::EditTheme, partId, stateId, rect); if (!theme.isValid()) { QWindowsStyle::drawPrimitive(element, option, painter, widget); @@ -582,27 +580,26 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt p->drawRect(option->rect.adjusted(0, 0, -1, -1)); p->setPen(oldPen); return; - } else { - int stateId = ETS_NORMAL; - if (!(state & State_Enabled)) - stateId = ETS_DISABLED; - else if (state & State_ReadOnly) - stateId = ETS_READONLY; - else if (state & State_MouseOver) - stateId = ETS_HOT; - else if (state & State_HasFocus) - stateId = ETS_SELECTED; - XPThemeData theme(widget, painter, - QWindowsXPStylePrivate::EditTheme, - EP_EDITBORDER_NOSCROLL, stateId, option->rect); - theme.noContent = true; - painter->save(); - QRegion clipRegion = option->rect; - clipRegion -= option->rect.adjusted(2, 2, -2, -2); - painter->setClipRegion(clipRegion); - d->drawBackground(theme); - painter->restore(); } + int stateId = ETS_NORMAL; + if (!(state & State_Enabled)) + stateId = ETS_DISABLED; + else if (state & State_ReadOnly) + stateId = ETS_READONLY; + else if (state & State_MouseOver) + stateId = ETS_HOT; + else if (state & State_HasFocus) + stateId = ETS_SELECTED; + XPThemeData theme(widget, painter, + QWindowsXPStylePrivate::EditTheme, + EP_EDITBORDER_NOSCROLL, stateId, option->rect); + theme.noContent = true; + painter->save(); + QRegion clipRegion = option->rect; + clipRegion -= option->rect.adjusted(2, 2, -2, -2); + painter->setClipRegion(clipRegion); + d->drawBackground(theme); + painter->restore(); } break; @@ -725,7 +722,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt d->drawBackground(theme); } else { QWindowsXPStyle::drawPrimitive(PE_PanelItemViewItem, option, painter, widget); - break;; + break; } QPixmapCache::insert(key, pixmap); } @@ -771,7 +768,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt case PE_Widget: { #if QT_CONFIG(dialogbuttonbox) - const QDialogButtonBox *buttonBox = 0; + const QDialogButtonBox *buttonBox = nullptr; if (qobject_cast<const QMessageBox *> (widget)) buttonBox = widget->findChild<const QDialogButtonBox *>(QLatin1String("qt_msgbox_buttonbox")); @@ -845,7 +842,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption int oldState = styleObject->property("_q_stylestate").toInt(); oldRect = styleObject->property("_q_stylerect").toRect(); newRect = option->rect; - styleObject->setProperty("_q_stylestate", (int)option->state); + styleObject->setProperty("_q_stylestate", int(option->state)); styleObject->setProperty("_q_stylerect", option->rect); bool wasDefault = false; @@ -871,7 +868,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption QWindowsVistaTransition *t = new QWindowsVistaTransition(styleObject); QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject)); QStyleOption *styleOption = clonedAnimationStyleOption(option); - styleOption->state = (QStyle::State)oldState; + styleOption->state = QStyle::State(oldState); QImage startImage = createAnimationBuffer(option, widget); QPainter startPainter(&startImage); @@ -893,12 +890,12 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption DWORD duration = 0; - const HTHEME theme = OpenThemeData(0, L"Button"); + const HTHEME theme = OpenThemeData(nullptr, L"Button"); int fromState = buttonStateId(oldState, BP_PUSHBUTTON); int toState = buttonStateId(option->state, BP_PUSHBUTTON); if (GetThemeTransitionDuration(theme, BP_PUSHBUTTON, fromState, toState, TMT_TRANSITIONDURATIONS, &duration) == S_OK) - t->setDuration(duration); + t->setDuration(int(duration)); else t->setDuration(0); t->setStartTime(QTime::currentTime()); @@ -984,7 +981,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption if (btn->features & QStyleOptionButton::HasMenu) { int mbiw = 0, mbih = 0; - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::ToolBarTheme, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::ToolBarTheme, TP_DROPDOWNBUTTON); if (theme.isValid()) { const QSizeF size = theme.size() * QStyleHelper::dpiScaled(1, option); @@ -993,7 +990,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption mbih = qRound(size.height()); } } - QRect ir = subElementRect(SE_PushButtonContents, option, 0); + QRect ir = subElementRect(SE_PushButtonContents, option, nullptr); QStyleOptionButton newBtn = *btn; newBtn.rect = QStyle::visualRect(option->direction, option->rect, QRect(ir.right() - mbiw - 2, @@ -1138,7 +1135,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption QPalette::ColorRole textRole = disabled ? QPalette::Text : QPalette::ButtonText; QPixmap pix = mbi->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), QIcon::Normal); - uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; + int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget)) alignment |= Qt::TextHideMnemonic; @@ -1178,7 +1175,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption int checkcol = qRound(qreal(25) * factor); const int gutterWidth = qRound(qreal(3) * factor); { - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::MenuTheme, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::MenuTheme, MENU_POPUPCHECKBACKGROUND, MBI_HOT); XPThemeData themeSize = theme; themeSize.partId = MENU_POPUPCHECK; @@ -1395,7 +1392,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption int mw = proxy()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, dwOpt, widget); int fw = proxy()->pixelMetric(PM_DockWidgetFrameWidth, dwOpt, widget); const QDockWidget *dw = qobject_cast<const QDockWidget *>(widget); - bool isFloating = dw != 0 && dw->isFloating(); + bool isFloating = dw && dw->isFloating(); QRect r = option->rect.adjusted(0, 2, -1, -3); QRect titleRect = r; @@ -1412,7 +1409,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption if (isFloating) { titleRect.adjust(0, -fw, 0, 0); - if (widget != 0 && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) + if (widget && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) titleRect.adjust(titleRect.height() + mw, 0, 0, 0); } else { titleRect.adjust(mw, 0, 0, 0); @@ -1518,8 +1515,8 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle int oldActiveControls = styleObject->property("_q_stylecontrols").toInt(); QRect oldRect = styleObject->property("_q_stylerect").toRect(); - styleObject->setProperty("_q_stylestate", (int)option->state); - styleObject->setProperty("_q_stylecontrols", (int)option->activeSubControls); + styleObject->setProperty("_q_stylestate", int(option->state)); + styleObject->setProperty("_q_stylecontrols", int(option->activeSubControls)); styleObject->setProperty("_q_stylerect", option->rect); bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken) || @@ -1563,8 +1560,8 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle // Draw transition source if (!anim) { - styleOption->state = (QStyle::State)oldState; - styleOption->activeSubControls = (QStyle::SubControl)oldActiveControls; + styleOption->state = QStyle::State(oldState); + styleOption->activeSubControls = QStyle::SubControl(oldActiveControls); proxy()->drawComplexControl(control, styleOption, &startPainter, widget); } else { anim->paint(&startPainter, option); @@ -1815,7 +1812,7 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle // That however breaks with QtQuickControls where this results in transparent // spinbox background, so if there's no "widget" passed (QtQuickControls case), // let ftheme.noContent be false, which fixes the spinbox rendering in QQC - ftheme.noContent = (widget != NULL); + ftheme.noContent = (widget != nullptr); d->drawBackground(ftheme); } if (sub & SC_SpinBoxUp) { @@ -1872,7 +1869,7 @@ QSize QWindowsVistaStyle::sizeFromContents(ContentsType type, const QStyleOption sz = QWindowsXPStyle::sizeFromContents(type, option, size, widget); int minimumHeight; { - XPThemeData theme(widget, 0, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::MenuTheme, MENU_POPUPCHECKBACKGROUND, MBI_HOT); XPThemeData themeSize = theme; @@ -1940,7 +1937,7 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption case SE_PushButtonContents: if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) { MARGINS borderSize; - const HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : 0, L"Button"); + const HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : nullptr, L"Button"); if (theme) { int stateId = PBS_NORMAL; if (!(option->state & State_Enabled)) @@ -1955,7 +1952,7 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption int border = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget); rect = option->rect.adjusted(border, border, -border, -border); - if (SUCCEEDED(GetThemeMargins(theme, NULL, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, NULL, &borderSize))) { + if (SUCCEEDED(GetThemeMargins(theme, nullptr, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, nullptr, &borderSize))) { rect.adjust(borderSize.cxLeftWidth, borderSize.cyTopHeight, -borderSize.cxRightWidth, -borderSize.cyBottomHeight); rect = visualRect(option->direction, option->rect, rect); @@ -1973,7 +1970,7 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption int y = option->rect.y(); int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, option, widget); - XPThemeData theme(widget, 0, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::HeaderTheme, HP_HEADERSORTARROW, HSAS_SORTEDDOWN, option->rect); @@ -2046,7 +2043,7 @@ static bool buttonVisible(const QStyle::SubControl sc, const QStyleOptionTitleBa bool isMinimized = tb->titleBarState & Qt::WindowMinimized; bool isMaximized = tb->titleBarState & Qt::WindowMaximized; - const uint flags = tb->titleBarFlags; + const auto flags = tb->titleBarFlags; bool retVal = false; switch (sc) { case QStyle::SC_TitleBarContextHelpButton: @@ -2104,7 +2101,7 @@ int QWindowsVistaStyle::styleHint(StyleHint hint, const QStyleOption *option, co if (option) { if (QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) { ret = true; - XPThemeData themeData(widget, 0, + XPThemeData themeData(widget, nullptr, QWindowsXPStylePrivate::ToolTipTheme, TTP_STANDARD, TTSS_NORMAL, option->rect); mask->region = d->region(themeData); @@ -2113,7 +2110,7 @@ int QWindowsVistaStyle::styleHint(StyleHint hint, const QStyleOption *option, co break; case SH_Table_GridLineColor: if (option) - ret = option->palette.color(QPalette::Base).darker(118).rgb(); + ret = int(option->palette.color(QPalette::Base).darker(118).rgb()); else ret = -1; break; @@ -2324,7 +2321,7 @@ void QWindowsVistaStyle::polish(QWidget *widget) //we do not have to care about unpolishing widget->setContentsMargins(3, 0, 4, 0); COLORREF bgRef; - HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : 0, L"TOOLTIP"); + HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : nullptr, L"TOOLTIP"); if (theme && SUCCEEDED(GetThemeColor(theme, TTP_STANDARD, TTSS_NORMAL, TMT_TEXTCOLOR, &bgRef))) { QColor textColor = QColor::fromRgb(bgRef); QPalette pal; @@ -2464,7 +2461,7 @@ QIcon QWindowsVistaStyle::standardIcon(StandardPixmap standardIcon, switch(standardIcon) { case SP_CommandLink: { - XPThemeData theme(0, 0, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_COMMANDLINKGLYPH, CMDLGS_NORMAL); if (theme.isValid()) { diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h index d66b17e9f8..8fef9f9927 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h @@ -162,7 +162,7 @@ class QWindowsVistaAnimation : public QBlendStyleAnimation public: QWindowsVistaAnimation(Type type, QObject *target) : QBlendStyleAnimation(type, target) { } - virtual bool isUpdateNeeded() const; + bool isUpdateNeeded() const override; void paint(QPainter *painter, const QStyleOption *option); }; diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp index e2c5bdc924..bf80138b32 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp @@ -117,7 +117,7 @@ static inline QBackingStore *backingStoreForWidget(const QWidget *widget) if (const QWidget *topLevel = widget->nativeParentWidget()) if (QBackingStore *topLevelBackingStore = topLevel->backingStore()) return topLevelBackingStore; - return 0; + return nullptr; } static inline HDC hdcForWidgetBackingStore(const QWidget *widget) @@ -127,7 +127,7 @@ static inline HDC hdcForWidgetBackingStore(const QWidget *widget) if (nativeInterface) return static_cast<HDC>(nativeInterface->nativeResourceForBackingStore(QByteArrayLiteral("getDC"), backingStore)); } - return 0; + return nullptr; } // Theme data helper ------------------------------------------------------------------------------ @@ -148,7 +148,7 @@ bool XPThemeData::isValid() HTHEME XPThemeData::handle() { if (!QWindowsXPStylePrivate::useXP()) - return 0; + return nullptr; if (!htheme) htheme = QWindowsXPStylePrivate::createTheme(theme, QWindowsXPStylePrivate::winId(widget)); @@ -175,10 +175,10 @@ RECT XPThemeData::toRECT(const QRect &qr) HRGN XPThemeData::mask(QWidget *widget) { if (!IsThemeBackgroundPartiallyTransparent(handle(), partId, stateId)) - return 0; + return nullptr; HRGN hrgn; - HDC dc = 0; + HDC dc = nullptr; if (widget) dc = hdcForWidgetBackingStore(widget); RECT nativeRect = toRECT(rect); @@ -188,7 +188,7 @@ HRGN XPThemeData::mask(QWidget *widget) // QWindowsXPStylePrivate ------------------------------------------------------------------------- // Static initializations -HWND QWindowsXPStylePrivate::m_vistaTreeViewHelper = 0; +HWND QWindowsXPStylePrivate::m_vistaTreeViewHelper = nullptr; HTHEME QWindowsXPStylePrivate::m_themes[NThemes]; bool QWindowsXPStylePrivate::use_xp = false; QBasicAtomicInt QWindowsXPStylePrivate::ref = Q_BASIC_ATOMIC_INITIALIZER(-1); // -1 based refcounting @@ -227,7 +227,7 @@ bool QWindowsXPStylePrivate::useXP(bool update) { if (!update) return use_xp; - return use_xp = IsThemeActive() && (IsAppThemed() || !QApplication::instance()); + return use_xp = IsThemeActive() && (IsAppThemed() || !QCoreApplication::instance()); } /* \internal @@ -241,7 +241,7 @@ void QWindowsXPStylePrivate::init(bool force) ref.ref(); useXP(true); - std::fill(m_themes, m_themes + NThemes, HTHEME(0)); + std::fill(m_themes, m_themes + NThemes, nullptr); } /* \internal @@ -253,12 +253,12 @@ void QWindowsXPStylePrivate::cleanup(bool force) if (bufferDC && nullBitmap) SelectObject(bufferDC, nullBitmap); DeleteObject(bufferBitmap); - bufferBitmap = 0; + bufferBitmap = nullptr; } if(bufferDC) DeleteDC(bufferDC); - bufferDC = 0; + bufferDC = nullptr; if (ref.deref() && !force) return; @@ -282,7 +282,7 @@ void QWindowsXPStylePrivate::cleanup(bool force) static inline HWND createTreeViewHelperWindow() { if (QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface()) { - void *hwnd = 0; + void *hwnd = nullptr; void *wndProc = reinterpret_cast<void *>(DefWindowProc); if (QMetaObject::invokeMethod(ni, "createMessageWindow", Qt::DirectConnection, Q_RETURN_ARG(void*, hwnd), @@ -292,7 +292,7 @@ static inline HWND createTreeViewHelperWindow() return reinterpret_cast<HWND>(hwnd); } } - return 0; + return nullptr; } bool QWindowsXPStylePrivate::initVistaTreeViewTheming() @@ -305,7 +305,7 @@ bool QWindowsXPStylePrivate::initVistaTreeViewTheming() qWarning("Unable to create the treeview helper window."); return false; } - if (FAILED(SetWindowTheme(m_vistaTreeViewHelper, L"explorer", NULL))) { + if (FAILED(SetWindowTheme(m_vistaTreeViewHelper, L"explorer", nullptr))) { qErrnoWarning("SetWindowTheme() failed."); cleanupVistaTreeViewTheming(); return false; @@ -317,7 +317,7 @@ void QWindowsXPStylePrivate::cleanupVistaTreeViewTheming() { if (m_vistaTreeViewHelper) { DestroyWindow(m_vistaTreeViewHelper); - m_vistaTreeViewHelper = 0; + m_vistaTreeViewHelper = nullptr; } } @@ -328,11 +328,12 @@ void QWindowsXPStylePrivate::cleanupVistaTreeViewTheming() */ void QWindowsXPStylePrivate::cleanupHandleMap() { - for (int i = 0; i < NThemes; ++i) - if (m_themes[i]) { - CloseThemeData(m_themes[i]); - m_themes[i] = 0; + for (auto &theme : m_themes) { + if (theme) { + CloseThemeData(theme); + theme = nullptr; } + } QWindowsXPStylePrivate::cleanupVistaTreeViewTheming(); } @@ -340,7 +341,7 @@ HTHEME QWindowsXPStylePrivate::createTheme(int theme, HWND hwnd) { if (Q_UNLIKELY(theme < 0 || theme >= NThemes || !hwnd)) { qWarning("Invalid parameters #%d, %p", theme, hwnd); - return 0; + return nullptr; } if (!m_themes[theme]) { const wchar_t *name = themeNames[theme]; @@ -427,16 +428,16 @@ HBITMAP QWindowsXPStylePrivate::buffer(int w, int h) if (bufferDC && nullBitmap) SelectObject(bufferDC, nullBitmap); DeleteObject(bufferBitmap); - bufferBitmap = 0; + bufferBitmap = nullptr; } w = qMax(bufferW, w); h = qMax(bufferH, h); if (!bufferDC) { - HDC displayDC = GetDC(0); + HDC displayDC = GetDC(nullptr); bufferDC = CreateCompatibleDC(displayDC); - ReleaseDC(0, displayDC); + ReleaseDC(nullptr, displayDC); } // Define the header @@ -450,22 +451,22 @@ HBITMAP QWindowsXPStylePrivate::buffer(int w, int h) bmi.bmiHeader.biCompression = BI_RGB; // Create the pixmap - bufferPixels = 0; - bufferBitmap = CreateDIBSection(bufferDC, &bmi, DIB_RGB_COLORS, (void **) &bufferPixels, 0, 0); + bufferPixels = nullptr; + bufferBitmap = CreateDIBSection(bufferDC, &bmi, DIB_RGB_COLORS, reinterpret_cast<void **>(&bufferPixels), nullptr, 0); GdiFlush(); - nullBitmap = (HBITMAP)SelectObject(bufferDC, bufferBitmap); + nullBitmap = static_cast<HBITMAP>(SelectObject(bufferDC, bufferBitmap)); if (Q_UNLIKELY(!bufferBitmap)) { qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() failed.", w, h); bufferW = 0; bufferH = 0; - return 0; + return nullptr; } if (Q_UNLIKELY(!bufferPixels)) { qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() did not allocate pixel data.", w, h); bufferW = 0; bufferH = 0; - return 0; + return nullptr; } bufferW = w; bufferH = h; @@ -493,7 +494,7 @@ bool QWindowsXPStylePrivate::isTransparent(XPThemeData &themeData) */ QRegion QWindowsXPStylePrivate::region(XPThemeData &themeData) { - HRGN hRgn = 0; + HRGN hRgn = nullptr; const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(themeData.widget); RECT rect = themeData.toRECT(QRect(themeData.rect.topLeft() / factor, themeData.rect.size() / factor)); if (!SUCCEEDED(GetThemeBackgroundRegion(themeData.handle(), bufferHDC(), themeData.partId, @@ -502,12 +503,12 @@ QRegion QWindowsXPStylePrivate::region(XPThemeData &themeData) } HRGN dest = CreateRectRgn(0, 0, 0, 0); - const bool success = CombineRgn(dest, hRgn, 0, RGN_COPY) != ERROR; + const bool success = CombineRgn(dest, hRgn, nullptr, RGN_COPY) != ERROR; QRegion region; if (success) { - int numBytes = GetRegionData(dest, 0, 0); + const auto numBytes = GetRegionData(dest, 0, nullptr); if (numBytes == 0) return QRegion(); @@ -551,7 +552,7 @@ bool QWindowsXPStylePrivate::hasAlphaChannel(const QRect &rect) int firstAlpha = -1; for (int y = startY; y < h/2; ++y) { - DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW); + auto buffer = reinterpret_cast<const DWORD *>(bufferPixels) + (y * bufferW); for (int x = startX; x < w; ++x, ++buffer) { int alpha = (*buffer) >> 24; if (firstAlpha == -1) @@ -580,7 +581,7 @@ bool QWindowsXPStylePrivate::fixAlphaChannel(const QRect &rect) bool hasFixedAlphaValue = false; for (int y = startY; y < h; ++y) { - DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW); + auto buffer = reinterpret_cast<DWORD *>(bufferPixels) + (y * bufferW); for (int x = startX; x < w; ++x, ++buffer) { uint pixel = *buffer; int alpha = qAlpha(pixel); @@ -612,7 +613,7 @@ bool QWindowsXPStylePrivate::swapAlphaChannel(const QRect &rect, bool allPixels) // Flip the alphas, so that 255-alpha pixels are 0, and 0-alpha are 255. for (int y = startY; y < h; ++y) { - DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW); + auto buffer = reinterpret_cast<DWORD *>(bufferPixels) + (y * bufferW); for (int x = startX; x < w; ++x, ++buffer) { if (allPixels) { *buffer |= 0xFF000000; @@ -668,7 +669,7 @@ bool QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData) return true; QPainter *painter = themeData.painter; - Q_ASSERT_X(painter != 0, "QWindowsXPStylePrivate::drawBackground()", "Trying to draw a theme part without a painter"); + Q_ASSERT_X(painter != nullptr, "QWindowsXPStylePrivate::drawBackground()", "Trying to draw a theme part without a painter"); if (!painter || !painter->isActive()) return false; @@ -706,7 +707,7 @@ bool QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData) } } - const HDC dc = canDrawDirectly ? hdcForWidgetBackingStore(themeData.widget) : HDC(0); + const HDC dc = canDrawDirectly ? hdcForWidgetBackingStore(themeData.widget) : nullptr; const bool result = dc ? drawBackgroundDirectly(dc, themeData, aditionalDevicePixelRatio) : drawBackgroundThruNativeBuffer(themeData, aditionalDevicePixelRatio); @@ -740,7 +741,7 @@ bool QWindowsXPStylePrivate::drawBackgroundDirectly(HDC dc, XPThemeData &themeDa { QPainter *painter = themeData.painter; - const auto deviceTransform = painter->deviceTransform(); + const auto &deviceTransform = painter->deviceTransform(); const QPointF redirectionDelta(deviceTransform.dx(), deviceTransform.dy()); const QRect area = scaleRect(QRectF(themeData.rect), additionalDevicePixelRatio).translated(redirectionDelta).toRect(); @@ -771,7 +772,7 @@ bool QWindowsXPStylePrivate::drawBackgroundDirectly(HDC dc, XPThemeData &themeDa | (themeData.mirrorHorizontally ? DTBG_MIRRORDC : 0); const HRESULT result = DrawThemeBackgroundEx(themeData.handle(), dc, themeData.partId, themeData.stateId, &(drawRECT), &drawOptions); - SelectClipRgn(dc, 0); + SelectClipRgn(dc, nullptr); DeleteObject(hrgn); return SUCCEEDED(result); } @@ -1099,9 +1100,7 @@ QWindowsXPStyle::QWindowsXPStyle() /*! Destroys the style. */ -QWindowsXPStyle::~QWindowsXPStyle() -{ -} +QWindowsXPStyle::~QWindowsXPStyle() = default; /*! \reimp */ void QWindowsXPStyle::unpolish(QApplication *app) @@ -1157,7 +1156,7 @@ void QWindowsXPStyle::polish(QWidget *widget) if (!d->hasInitColors) { // Get text color for group box labels COLORREF cref; - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::ButtonTheme, 0, 0); + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, 0, 0); GetThemeColor(theme.handle(), BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, &cref); d->groupBoxTextColor = qRgb(GetRValue(cref), GetGValue(cref), GetBValue(cref)); GetThemeColor(theme.handle(), BP_GROUPBOX, GBS_DISABLED, TMT_TEXTCOLOR, &cref); @@ -1270,7 +1269,7 @@ QRect QWindowsXPStyle::subElementRect(SubElement sr, const QStyleOption *option, if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) { MARGINS borderSize; if (widget) { - XPThemeData buttontheme(widget, 0, QWindowsXPStylePrivate::ButtonTheme); + XPThemeData buttontheme(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme); HTHEME theme = buttontheme.handle(); if (theme) { int stateId; @@ -1288,7 +1287,7 @@ QRect QWindowsXPStyle::subElementRect(SubElement sr, const QStyleOption *option, int border = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget); rect = option->rect.adjusted(border, border, -border, -border); - if (SUCCEEDED(GetThemeMargins(theme, NULL, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, NULL, &borderSize))) { + if (SUCCEEDED(GetThemeMargins(theme, nullptr, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, nullptr, &borderSize))) { rect.adjust(borderSize.cxLeftWidth, borderSize.cyTopHeight, -borderSize.cxRightWidth, -borderSize.cyBottomHeight); rect = visualRect(option->direction, option->rect, rect); @@ -1468,7 +1467,7 @@ case PE_Frame: return; themeNumber = QWindowsXPStylePrivate::ListViewTheme; partId = LVP_LISTGROUP; - XPThemeData theme(widget, 0, themeNumber, partId, 0); + XPThemeData theme(widget, nullptr, themeNumber, partId); if (!(flags & State_Enabled)) stateId = ETS_DISABLED; @@ -1496,9 +1495,9 @@ case PE_Frame: p->drawRect(QRectF(option->rect).adjusted(0, 0, -topLevelAdjustment, -topLevelAdjustment)); p->setPen(oldPen); return; - } else if (fillType == BT_NONE) { - return; } + if (fillType == BT_NONE) + return; } break; } @@ -1514,7 +1513,8 @@ case PE_Frame: p->drawRect(option->rect.adjusted(0, 0, -1, -1)); p->setPen(oldPen); return; - } else if (qstyleoption_cast<const QStyleOptionFrame *>(option)) { + } + if (qstyleoption_cast<const QStyleOptionFrame *>(option)) { themeNumber = QWindowsXPStylePrivate::EditTheme; partId = EP_EDITTEXT; noContent = true; @@ -1538,7 +1538,7 @@ case PE_Frame: if (QWindowsXPStylePrivate::isLineEditBaseColorSet(option, widget)) { p->fillRect(panel->rect, panel->palette.brush(QPalette::Base)); } else { - XPThemeData theme(0, p, themeNumber, partId, stateId, rect); + XPThemeData theme(nullptr, p, themeNumber, partId, stateId, rect); if (!theme.isValid()) { QWindowsStyle::drawPrimitive(pe, option, p, widget); return; @@ -1587,9 +1587,9 @@ case PE_Frame: wchar_t themeFileName[maxlength]; wchar_t themeColor[maxlength]; // Due to a a scaling issue with the XP Silver theme, tab gradients are not used with it - if (GetCurrentThemeName(themeFileName, maxlength, themeColor, maxlength, NULL, 0) == S_OK) { - wchar_t *offset = 0; - if ((offset = wcsrchr(themeFileName, QChar(QLatin1Char('\\')).unicode())) != NULL) { + if (GetCurrentThemeName(themeFileName, maxlength, themeColor, maxlength, nullptr, 0) == S_OK) { + wchar_t *offset = nullptr; + if ((offset = wcsrchr(themeFileName, QChar(QLatin1Char('\\')).unicode())) != nullptr) { offset++; if (!lstrcmp(offset, L"Luna.msstyles") && !lstrcmp(offset, L"Metallic")) { useGradient = false; @@ -1820,7 +1820,7 @@ case PE_Frame: bef_v -= delta; aft_h += delta; aft_v += delta; - XPThemeData theme(0, p, QWindowsXPStylePrivate::XpTreeViewTheme); + XPThemeData theme(nullptr, p, QWindowsXPStylePrivate::XpTreeViewTheme); theme.rect = QRect(bef_h, bef_v, decoration_size, decoration_size); theme.partId = TVP_GLYPH; theme.stateId = flags & QStyle::State_Open ? GLPS_OPENED : GLPS_CLOSED; @@ -1912,7 +1912,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op { themeNumber = QWindowsXPStylePrivate::StatusTheme; partId = SP_GRIPPER; - XPThemeData theme(0, p, themeNumber, partId, 0); + XPThemeData theme(nullptr, p, themeNumber, partId); QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); size.rheight()--; if (const QStyleOptionSizeGrip *sg = qstyleoption_cast<const QStyleOptionSizeGrip *>(option)) { @@ -1980,7 +1980,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op if (btn->features & QStyleOptionButton::HasMenu) { int mbiw = 0, mbih = 0; - XPThemeData theme(widget, 0, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::ToolBarTheme, TP_SPLITBUTTONDROPDOWN); if (theme.isValid()) { @@ -2309,7 +2309,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op if (isFloating) { titleRect.adjust(0, -fw, 0, 0); - if (widget != 0 && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) + if (widget != nullptr && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) titleRect.adjust(titleRect.height() + mw, 0, 0, 0); } else { titleRect.adjust(mw, 0, 0, 0); @@ -2775,7 +2775,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo break; v = nextInterval; } - if (lines.size() > 0) { + if (!lines.isEmpty()) { p->save(); p->translate(slrect.topLeft()); p->drawLines(lines.constData(), lines.size()); @@ -2923,7 +2923,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo p->save(); p->setClipRect(menuarea); tool.rect = option->rect; - proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, p, 0); + proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, p, nullptr); p->restore(); } // Draw arrow @@ -3223,7 +3223,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo } } -static inline Qt::Orientation progressBarOrientation(const QStyleOption *option = 0) +static inline Qt::Orientation progressBarOrientation(const QStyleOption *option = nullptr) { if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) return pb->orientation; @@ -3234,27 +3234,27 @@ int QWindowsXPStylePrivate::pixelMetricFromSystemDp(QStyle::PixelMetric pm, cons { switch (pm) { case QStyle::PM_IndicatorWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).width(); case QStyle::PM_IndicatorHeight: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).height(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).height(); case QStyle::PM_ExclusiveIndicatorWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).width(); case QStyle::PM_ExclusiveIndicatorHeight: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).height(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).height(); case QStyle::PM_ProgressBarChunkWidth: return progressBarOrientation(option) == Qt::Horizontal - ? XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNK).width() - : XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNKVERT).height(); + ? XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNK).width() + : XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNKVERT).height(); case QStyle::PM_SliderThickness: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::TrackBarTheme, TKP_THUMB).height(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::TrackBarTheme, TKP_THUMB).height(); case QStyle::PM_TitleBarHeight: return widget && (widget->windowType() == Qt::Tool) ? GetSystemMetrics(SM_CYSMCAPTION) + GetSystemMetrics(SM_CXSIZEFRAME) : GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CXSIZEFRAME); case QStyle::PM_MdiSubWindowFrameWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_FRAMELEFT, FS_ACTIVE).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_FRAMELEFT, FS_ACTIVE).width(); case QStyle::PM_DockWidgetFrameWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_SMALLFRAMERIGHT, FS_ACTIVE).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLFRAMERIGHT, FS_ACTIVE).width(); default: break; } @@ -3620,7 +3620,7 @@ QSize QWindowsXPStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt case CT_LineEdit: case CT_ComboBox: { - XPThemeData buttontheme(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_PUSHBUTTON, PBS_NORMAL); + XPThemeData buttontheme(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_PUSHBUTTON, PBS_NORMAL); if (buttontheme.isValid()) { const qreal factor = QWindowsXPStylePrivate::nativeMetricScaleFactor(widget); const QMarginsF borderSize = buttontheme.margins() * factor; @@ -3741,11 +3741,11 @@ int QWindowsXPStyle::styleHint(StyleHint hint, const QStyleOption *option, const titleBarRect.setHeight(tbHeight); XPThemeData themeData; if (titlebar->titleBarState & Qt::WindowMinimized) { - themeData = XPThemeData(widget, 0, + themeData = XPThemeData(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_MINCAPTION, CS_ACTIVE, titleBarRect); } else - themeData = XPThemeData(widget, 0, + themeData = XPThemeData(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_CAPTION, CS_ACTIVE, titleBarRect); mask->region = d->region(themeData) + @@ -3774,10 +3774,8 @@ int QWindowsXPStyle::styleHint(StyleHint hint, const QStyleOption *option, const /*! \reimp */ QPalette QWindowsXPStyle::standardPalette() const { - if (QWindowsXPStylePrivate::useXP() && QApplicationPrivate::sys_pal) - return *QApplicationPrivate::sys_pal; - else - return QWindowsStyle::standardPalette(); + return QWindowsXPStylePrivate::useXP() && QApplicationPrivate::sys_pal + ? *QApplicationPrivate::sys_pal : QWindowsStyle::standardPalette(); } /*! @@ -3795,7 +3793,7 @@ QPixmap QWindowsXPStyle::standardPixmap(StandardPixmap standardPixmap, const QSt if (qstyleoption_cast<const QStyleOptionDockWidget *>(option)) { if (widget && widget->isWindow()) { - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); if (theme.isValid()) { const QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); return QIcon(QWindowsStyle::standardPixmap(standardPixmap, option, widget)).pixmap(size); @@ -3826,9 +3824,9 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon, if (qstyleoption_cast<const QStyleOptionDockWidget *>(option)) { if (d->dockFloat.isNull()) { - XPThemeData themeSize(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData themeSize(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); - XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_MAXBUTTON, MAXBS_NORMAL); if (theme.isValid()) { const QSize size = (themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); @@ -3862,7 +3860,7 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon, if (qstyleoption_cast<const QStyleOptionDockWidget *>(option)) { if (d->dockClose.isNull()) { - XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); if (theme.isValid()) { const QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); @@ -3896,9 +3894,9 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon, if (qstyleoption_cast<const QStyleOptionDockWidget *>(option)) { if (d->dockFloat.isNull()) { - XPThemeData themeSize(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData themeSize(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); - XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_RESTOREBUTTON, RBS_NORMAL); if (theme.isValid()) { const QSize size = (themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h b/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h index 60f9d7e9b7..ad7754e3d4 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h @@ -100,11 +100,11 @@ class QDebug; class XPThemeData { public: - explicit XPThemeData(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, + explicit XPThemeData(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0, const QRect &r = QRect()) - : widget(w), painter(p), theme(themeIn), htheme(0), partId(part), stateId(state), + : widget(w), painter(p), theme(themeIn), partId(part), stateId(state), mirrorHorizontally(false), mirrorVertically(false), noBorder(false), - noContent(false), rotate(0), rect(r) + noContent(false), rect(r) {} HRGN mask(QWidget *widget); @@ -117,17 +117,17 @@ public: QMarginsF margins(const QRect &rect, int propId = TMT_CONTENTMARGINS); QMarginsF margins(int propId = TMT_CONTENTMARGINS); - static QSizeF themeSize(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, int part = 0, int state = 0); - static QMarginsF themeMargins(const QRect &rect, const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, + static QSizeF themeSize(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0); + static QMarginsF themeMargins(const QRect &rect, const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS); - static QMarginsF themeMargins(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, + static QMarginsF themeMargins(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS); const QWidget *widget; QPainter *painter; int theme; - HTHEME htheme; + HTHEME htheme = nullptr; int partId; int stateId; @@ -135,18 +135,18 @@ public: uint mirrorVertically : 1; uint noBorder : 1; uint noContent : 1; - uint rotate; + uint rotate = 0; QRect rect; }; struct ThemeMapKey { - int theme; - int partId; - int stateId; - bool noBorder; - bool noContent; + int theme = 0; + int partId = -1; + int stateId = -1; + bool noBorder = false; + bool noContent = false; - ThemeMapKey() : partId(-1), stateId(-1) {} + ThemeMapKey() = default; ThemeMapKey(const XPThemeData &data) : theme(data.theme), partId(data.partId), stateId(data.stateId), noBorder(data.noBorder), noContent(data.noContent) {} @@ -171,7 +171,7 @@ enum AlphaChannelType { }; struct ThemeMapData { - AlphaChannelType alphaType; // Which type of alpha on part & state + AlphaChannelType alphaType = UnknownAlpha; // Which type of alpha on part & state bool dataValid : 1; // Only used to detect if hash value is ok bool partIsTransparent : 1; @@ -217,15 +217,13 @@ public: }; QWindowsXPStylePrivate() - : QWindowsStylePrivate(), hasInitColors(false), bufferDC(0), bufferBitmap(0), nullBitmap(0), - bufferPixels(0), bufferW(0), bufferH(0) { init(); } ~QWindowsXPStylePrivate() { cleanup(); } - static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option = 0, const QWidget *widget = 0); - static int fixedPixelMetric(QStyle::PixelMetric pm, const QStyleOption *option = 0, const QWidget *widget = 0); + static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr); + static int fixedPixelMetric(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr); static HWND winId(const QWidget *widget); @@ -251,10 +249,10 @@ public: bool fixAlphaChannel(const QRect &rect); bool swapAlphaChannel(const QRect &rect, bool allPixels = false); - QRgb groupBoxTextColor; - QRgb groupBoxTextColorDisabled; - QRgb sliderTickColor; - bool hasInitColors; + QRgb groupBoxTextColor = 0; + QRgb groupBoxTextColorDisabled = 0; + QRgb sliderTickColor = 0; + bool hasInitColors = false; static HTHEME createTheme(int theme, HWND hwnd); static QString themeName(int theme); @@ -277,11 +275,12 @@ private: static bool use_xp; QHash<ThemeMapKey, ThemeMapData> alphaCache; - HDC bufferDC; - HBITMAP bufferBitmap; - HBITMAP nullBitmap; - uchar *bufferPixels; - int bufferW, bufferH; + HDC bufferDC = nullptr; + HBITMAP bufferBitmap = nullptr; + HBITMAP nullBitmap = nullptr; + uchar *bufferPixels = nullptr; + int bufferW = 0; + int bufferH = 0; static HWND m_vistaTreeViewHelper; static HTHEME m_themes[NThemes]; @@ -292,7 +291,7 @@ inline QSizeF XPThemeData::size() QSizeF result(0, 0); if (isValid()) { SIZE size; - if (SUCCEEDED(GetThemePartSize(handle(), 0, partId, stateId, 0, TS_TRUE, &size))) + if (SUCCEEDED(GetThemePartSize(handle(), nullptr, partId, stateId, nullptr, TS_TRUE, &size))) result = QSize(size.cx, size.cy); } return result; @@ -304,7 +303,7 @@ inline QMarginsF XPThemeData::margins(const QRect &qRect, int propId) if (isValid()) { MARGINS margins; RECT rect = XPThemeData::toRECT(qRect); - if (SUCCEEDED(GetThemeMargins(handle(), 0, partId, stateId, propId, &rect, &margins))) + if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, &rect, &margins))) result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight); } return result; @@ -315,7 +314,7 @@ inline QMarginsF XPThemeData::margins(int propId) QMarginsF result(0, 0, 0 ,0); if (isValid()) { MARGINS margins; - if (SUCCEEDED(GetThemeMargins(handle(), 0, partId, stateId, propId, NULL, &margins))) + if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, nullptr, &margins))) result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight); } return result; |