From 2ae98f8ba41d7dc2f314f553d4b65c8ec0160450 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 4 May 2019 22:16:46 +0200 Subject: [PATCH] Prevent using deprecated Qt features --- aboutdialog/aboutdialog.cpp | 9 +++--- cmake/modules/QtConfig.cmake | 3 ++ misc/dbusnotification.cpp | 4 +++ misc/dialogutils.cpp | 53 ++++++++++++++++++++++++------------ misc/dialogutils.h | 5 +++- 5 files changed, 50 insertions(+), 24 deletions(-) diff --git a/aboutdialog/aboutdialog.cpp b/aboutdialog/aboutdialog.cpp index 54c2106..c46b72c 100644 --- a/aboutdialog/aboutdialog.cpp +++ b/aboutdialog/aboutdialog.cpp @@ -65,10 +65,10 @@ AboutDialog::AboutDialog(QWidget *parent, const QString &applicationName, const m_ui->creatorLabel->setText(tr("developed by %1").arg(creator.isEmpty() ? QApplication::organizationName() : creator)); } m_ui->versionLabel->setText(version.isEmpty() ? QApplication::applicationVersion() : version); - const auto &deps(dependencyVersions.size() ? dependencyVersions : ApplicationUtilities::dependencyVersions2); - if (deps.size()) { + const auto &deps(dependencyVersions.size() ? dependencyVersions : ApplicationUtilities::dependencyVersions); + if (!deps.empty()) { QStringList linkedAgainst; - linkedAgainst.reserve(deps.size()); + linkedAgainst.reserve(static_cast(deps.size())); for (const auto &dependencyVersion : deps) { linkedAgainst << QString::fromUtf8(dependencyVersion); } @@ -86,8 +86,7 @@ AboutDialog::AboutDialog(QWidget *parent, const QString &applicationName, const : new QGraphicsPixmapItem(QPixmap::fromImage(image)); m_iconScene->addItem(item); m_ui->graphicsView->setScene(m_iconScene); - setGeometry(QStyle::alignedRect( - Qt::LeftToRight, Qt::AlignCenter, size(), parentWidget() ? parentWidget()->geometry() : QApplication::desktop()->availableGeometry())); + centerWidget(this, parentWidget()); } AboutDialog::AboutDialog(QWidget *parent, const QString &applicationName, const QString &creator, const QString &version, const QString &website, diff --git a/cmake/modules/QtConfig.cmake b/cmake/modules/QtConfig.cmake index a19f0cf..0f977f4 100644 --- a/cmake/modules/QtConfig.cmake +++ b/cmake/modules/QtConfig.cmake @@ -30,6 +30,9 @@ set(QT_REPOS ${ADDITIONAL_QT_REPOS} base) set(QT_MODULES ${ADDITIONAL_QT_MODULES} Core) set(KF_MODULES ${ADDITIONAL_KF_MODULES}) +# disable deprecated features +list(APPEND META_PRIVATE_COMPILE_DEFINITIONS QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000) + # allow specifying a custom directory for Qt plugins set(QT_PLUGIN_DIR "" CACHE STRING "specifies the directory to install Qt plugins") diff --git a/misc/dbusnotification.cpp b/misc/dbusnotification.cpp index 8e124ec..787cec1 100644 --- a/misc/dbusnotification.cpp +++ b/misc/dbusnotification.cpp @@ -109,7 +109,11 @@ inline NotificationImage::NotificationImage(const QImage &image) , hasAlpha(image.hasAlphaChannel()) , channels(image.isGrayscale() ? 1 : hasAlpha ? 4 : 3) , bitsPerSample(image.depth() / channels) +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) + , data(reinterpret_cast(image.bits()), static_cast(image.sizeInBytes())) +#else , data(reinterpret_cast(image.bits()), image.byteCount()) +#endif , isValid(!image.isNull()) { if (isValid) { diff --git a/misc/dialogutils.cpp b/misc/dialogutils.cpp index 03b663a..d8e0e13 100644 --- a/misc/dialogutils.cpp +++ b/misc/dialogutils.cpp @@ -1,20 +1,22 @@ #include "./dialogutils.h" -#if !defined(QT_UTILITIES_GUI_QTWIDGETS) && !defined(QT_UTILITIES_GUI_QTQUICK) #include -#else +#include +#include + +#if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined(QT_UTILITIES_GUI_QTQUICK) #include #include -#include -#include -#ifdef QT_UTILITIES_GUI_QTWIDGETS +#endif + +#if defined(QT_UTILITIES_GUI_QTWIDGETS) #include #include #include +#include +#include +#include #endif -#endif -#include -#include namespace Dialogs { @@ -97,29 +99,44 @@ const QString &dialogStyle() #ifdef QT_UTILITIES_GUI_QTWIDGETS +QRect availableScreenGeometryAtPoint(const QPoint &point) +{ +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) + QScreen *const screen = QGuiApplication::screenAt(point); + if (!screen) { + return QRect(); + } + return screen->availableGeometry(); +#else + return QApplication::desktop()->availableGeometry(point); +#endif +} + /*! * \brief Moves the specified \a widget in the middle of the (available) screen - * area. If there are multiple - * screens available, the screen where the cursor currently is located is - * chosen. + * area or \a parent if specified. + * + * If there are multiple screens available, the screen where the cursor currently + * is located is chosen. */ -void centerWidget(QWidget *widget) +void centerWidget(QWidget *widget, const QWidget *parent) { - widget->setGeometry( - QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, widget->size(), QApplication::desktop()->availableGeometry(QCursor::pos()))); + widget->setGeometry(QStyle::alignedRect( + Qt::LeftToRight, Qt::AlignCenter, widget->size(), parent ? parent->geometry() : availableScreenGeometryAtPoint(QCursor::pos()))); } /*! * \brief Moves the specified \a widget to the corner which is closest to the * current cursor position. - * If there are multiple screens available, the screen where the cursor - * currently is located is chosen. + * + * If there are multiple screens available, the screen where the cursor currently + * is located is chosen. */ void cornerWidget(QWidget *widget) { const QPoint cursorPos(QCursor::pos()); - const QRect availableGeometry(QApplication::desktop()->availableGeometry(cursorPos)); - Qt::Alignment alignment = 0; + const QRect availableGeometry(availableScreenGeometryAtPoint(cursorPos)); + Qt::Alignment alignment = nullptr; alignment |= (cursorPos.x() - availableGeometry.left() < availableGeometry.right() - cursorPos.x() ? Qt::AlignLeft : Qt::AlignRight); alignment |= (cursorPos.y() - availableGeometry.top() < availableGeometry.bottom() - cursorPos.y() ? Qt::AlignTop : Qt::AlignBottom); widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, alignment, widget->size(), availableGeometry)); diff --git a/misc/dialogutils.h b/misc/dialogutils.h index 1f981ab..f2ae893 100644 --- a/misc/dialogutils.h +++ b/misc/dialogutils.h @@ -8,6 +8,8 @@ QT_FORWARD_DECLARE_CLASS(QString) QT_FORWARD_DECLARE_CLASS(QWidget) QT_FORWARD_DECLARE_CLASS(QColor) +QT_FORWARD_DECLARE_CLASS(QPoint) +QT_FORWARD_DECLARE_CLASS(QRect) namespace Dialogs { @@ -33,7 +35,8 @@ QColor QT_UTILITIES_EXPORT instructionTextColor(); #endif const QString QT_UTILITIES_EXPORT &dialogStyle(); #ifdef QT_UTILITIES_GUI_QTWIDGETS -void QT_UTILITIES_EXPORT centerWidget(QWidget *widget); +QRect QT_UTILITIES_EXPORT availableScreenGeometryAtPoint(const QPoint &point); +void QT_UTILITIES_EXPORT centerWidget(QWidget *widget, const QWidget *parent = nullptr); void QT_UTILITIES_EXPORT cornerWidget(QWidget *widget); void QT_UTILITIES_EXPORT makeHeading(QWidget *widget); void QT_UTILITIES_EXPORT updateStyle(QWidget *widget);