Prevent using deprecated Qt features

This commit is contained in:
Martchus 2019-05-04 22:16:46 +02:00
parent 4de0685c84
commit 2ae98f8ba4
5 changed files with 50 additions and 24 deletions

View File

@ -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->creatorLabel->setText(tr("developed by %1").arg(creator.isEmpty() ? QApplication::organizationName() : creator));
} }
m_ui->versionLabel->setText(version.isEmpty() ? QApplication::applicationVersion() : version); m_ui->versionLabel->setText(version.isEmpty() ? QApplication::applicationVersion() : version);
const auto &deps(dependencyVersions.size() ? dependencyVersions : ApplicationUtilities::dependencyVersions2); const auto &deps(dependencyVersions.size() ? dependencyVersions : ApplicationUtilities::dependencyVersions);
if (deps.size()) { if (!deps.empty()) {
QStringList linkedAgainst; QStringList linkedAgainst;
linkedAgainst.reserve(deps.size()); linkedAgainst.reserve(static_cast<int>(deps.size()));
for (const auto &dependencyVersion : deps) { for (const auto &dependencyVersion : deps) {
linkedAgainst << QString::fromUtf8(dependencyVersion); linkedAgainst << QString::fromUtf8(dependencyVersion);
} }
@ -86,8 +86,7 @@ AboutDialog::AboutDialog(QWidget *parent, const QString &applicationName, const
: new QGraphicsPixmapItem(QPixmap::fromImage(image)); : new QGraphicsPixmapItem(QPixmap::fromImage(image));
m_iconScene->addItem(item); m_iconScene->addItem(item);
m_ui->graphicsView->setScene(m_iconScene); m_ui->graphicsView->setScene(m_iconScene);
setGeometry(QStyle::alignedRect( centerWidget(this, parentWidget());
Qt::LeftToRight, Qt::AlignCenter, size(), parentWidget() ? parentWidget()->geometry() : QApplication::desktop()->availableGeometry()));
} }
AboutDialog::AboutDialog(QWidget *parent, const QString &applicationName, const QString &creator, const QString &version, const QString &website, AboutDialog::AboutDialog(QWidget *parent, const QString &applicationName, const QString &creator, const QString &version, const QString &website,

View File

@ -30,6 +30,9 @@ set(QT_REPOS ${ADDITIONAL_QT_REPOS} base)
set(QT_MODULES ${ADDITIONAL_QT_MODULES} Core) set(QT_MODULES ${ADDITIONAL_QT_MODULES} Core)
set(KF_MODULES ${ADDITIONAL_KF_MODULES}) 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 # allow specifying a custom directory for Qt plugins
set(QT_PLUGIN_DIR "" CACHE STRING "specifies the directory to install Qt plugins") set(QT_PLUGIN_DIR "" CACHE STRING "specifies the directory to install Qt plugins")

View File

@ -109,7 +109,11 @@ inline NotificationImage::NotificationImage(const QImage &image)
, hasAlpha(image.hasAlphaChannel()) , hasAlpha(image.hasAlphaChannel())
, channels(image.isGrayscale() ? 1 : hasAlpha ? 4 : 3) , channels(image.isGrayscale() ? 1 : hasAlpha ? 4 : 3)
, bitsPerSample(image.depth() / channels) , bitsPerSample(image.depth() / channels)
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
, data(reinterpret_cast<const char *>(image.bits()), static_cast<int>(image.sizeInBytes()))
#else
, data(reinterpret_cast<const char *>(image.bits()), image.byteCount()) , data(reinterpret_cast<const char *>(image.bits()), image.byteCount())
#endif
, isValid(!image.isNull()) , isValid(!image.isNull())
{ {
if (isValid) { if (isValid) {

View File

@ -1,20 +1,22 @@
#include "./dialogutils.h" #include "./dialogutils.h"
#if !defined(QT_UTILITIES_GUI_QTWIDGETS) && !defined(QT_UTILITIES_GUI_QTQUICK)
#include <QCoreApplication> #include <QCoreApplication>
#else #include <QDir>
#include <QFileInfo>
#if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined(QT_UTILITIES_GUI_QTQUICK)
#include <QGuiApplication> #include <QGuiApplication>
#include <QPalette> #include <QPalette>
#include <QStyle> #endif
#include <QWidget>
#ifdef QT_UTILITIES_GUI_QTWIDGETS #if defined(QT_UTILITIES_GUI_QTWIDGETS)
#include <QApplication> #include <QApplication>
#include <QCursor> #include <QCursor>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QScreen>
#include <QStyle>
#include <QWidget>
#endif #endif
#endif
#include <QDir>
#include <QFileInfo>
namespace Dialogs { namespace Dialogs {
@ -97,29 +99,44 @@ const QString &dialogStyle()
#ifdef QT_UTILITIES_GUI_QTWIDGETS #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 * \brief Moves the specified \a widget in the middle of the (available) screen
* area. If there are multiple * area or \a parent if specified.
* 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 centerWidget(QWidget *widget) void centerWidget(QWidget *widget, const QWidget *parent)
{ {
widget->setGeometry( widget->setGeometry(QStyle::alignedRect(
QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, widget->size(), QApplication::desktop()->availableGeometry(QCursor::pos()))); 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 * \brief Moves the specified \a widget to the corner which is closest to the
* current cursor position. * 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) void cornerWidget(QWidget *widget)
{ {
const QPoint cursorPos(QCursor::pos()); const QPoint cursorPos(QCursor::pos());
const QRect availableGeometry(QApplication::desktop()->availableGeometry(cursorPos)); const QRect availableGeometry(availableScreenGeometryAtPoint(cursorPos));
Qt::Alignment alignment = 0; Qt::Alignment alignment = nullptr;
alignment |= (cursorPos.x() - availableGeometry.left() < availableGeometry.right() - cursorPos.x() ? Qt::AlignLeft : Qt::AlignRight); 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); alignment |= (cursorPos.y() - availableGeometry.top() < availableGeometry.bottom() - cursorPos.y() ? Qt::AlignTop : Qt::AlignBottom);
widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, alignment, widget->size(), availableGeometry)); widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, alignment, widget->size(), availableGeometry));

View File

@ -8,6 +8,8 @@
QT_FORWARD_DECLARE_CLASS(QString) QT_FORWARD_DECLARE_CLASS(QString)
QT_FORWARD_DECLARE_CLASS(QWidget) QT_FORWARD_DECLARE_CLASS(QWidget)
QT_FORWARD_DECLARE_CLASS(QColor) QT_FORWARD_DECLARE_CLASS(QColor)
QT_FORWARD_DECLARE_CLASS(QPoint)
QT_FORWARD_DECLARE_CLASS(QRect)
namespace Dialogs { namespace Dialogs {
@ -33,7 +35,8 @@ QColor QT_UTILITIES_EXPORT instructionTextColor();
#endif #endif
const QString QT_UTILITIES_EXPORT &dialogStyle(); const QString QT_UTILITIES_EXPORT &dialogStyle();
#ifdef QT_UTILITIES_GUI_QTWIDGETS #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 cornerWidget(QWidget *widget);
void QT_UTILITIES_EXPORT makeHeading(QWidget *widget); void QT_UTILITIES_EXPORT makeHeading(QWidget *widget);
void QT_UTILITIES_EXPORT updateStyle(QWidget *widget); void QT_UTILITIES_EXPORT updateStyle(QWidget *widget);