diff --git a/src/libcalamaresui/utils/QtCompat.h b/src/libcalamaresui/utils/QtCompat.h new file mode 100644 index 000000000..d53c01e0b --- /dev/null +++ b/src/libcalamaresui/utils/QtCompat.h @@ -0,0 +1,42 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2020 Adriaan de Groot + * SPDX-License-Identifier: GPL-3.0-or-later + * Calamares is Free Software: see the License-Identifier above. + * + */ + +/**@file Handle compatibility and deprecations across Qt versions + * + * Since Calamares is supposed to work with Qt 5.9 or later, it covers a + * lot of changes in the Qt API. Especially the later Qt 5.15 (last LTS) + * versions deprecate a number of enum values and parts of the QWidgets + * API. This file adjusts for that by introducing suitable aliases + * and workaround-functions. + * + * For a similar approach for QtCore, see libcalamares/utils/String.h + */ + +#ifndef UTILS_QTCOMPAT_H +#define UTILS_QTCOMPAT_H + +#include + +/* Avoid warnings about QPalette changes */ +constexpr static const auto WindowBackground = +#if QT_VERSION < QT_VERSION_CHECK( 5, 15, 0 ) + QPalette::Background +#else + QPalette::Window +#endif + ; + +constexpr static const auto WindowText = +#if QT_VERSION < QT_VERSION_CHECK( 5, 15, 0 ) + QPalette::Foreground +#else + QPalette::WindowText +#endif + ; + +#endif diff --git a/src/modules/license/LicenseWidget.cpp b/src/modules/license/LicenseWidget.cpp index b2e66515d..a8d581ab5 100644 --- a/src/modules/license/LicenseWidget.cpp +++ b/src/modules/license/LicenseWidget.cpp @@ -13,6 +13,7 @@ #include "LicenseWidget.h" #include "utils/Logger.h" +#include "utils/QtCompat.h" #include #include @@ -48,7 +49,7 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent ) , m_isExpanded( m_entry.expandByDefault() ) { QPalette pal( palette() ); - pal.setColor( QPalette::Background, palette().window().color().lighter( 108 ) ); + pal.setColor( WindowBackground, palette().window().color().lighter( 108 ) ); setObjectName( "licenseItem" ); diff --git a/src/modules/partition/gui/BootInfoWidget.cpp b/src/modules/partition/gui/BootInfoWidget.cpp index 5d9dcf8b5..0b9d08c47 100644 --- a/src/modules/partition/gui/BootInfoWidget.cpp +++ b/src/modules/partition/gui/BootInfoWidget.cpp @@ -12,6 +12,7 @@ #include "core/PartUtils.h" #include "utils/CalamaresUtilsGui.h" +#include "utils/QtCompat.h" #include "utils/Retranslator.h" #include @@ -45,7 +46,7 @@ BootInfoWidget::BootInfoWidget( QWidget* parent ) m_bootLabel->setAlignment( Qt::AlignCenter ); QPalette palette; - palette.setBrush( QPalette::Foreground, QColor( "#4D4D4D" ) ); //dark grey + palette.setBrush( WindowText, QColor( "#4D4D4D" ) ); //dark grey m_bootIcon->setAutoFillBackground( true ); m_bootLabel->setAutoFillBackground( true ); diff --git a/src/modules/partition/gui/DeviceInfoWidget.cpp b/src/modules/partition/gui/DeviceInfoWidget.cpp index 80eacd05b..708982101 100644 --- a/src/modules/partition/gui/DeviceInfoWidget.cpp +++ b/src/modules/partition/gui/DeviceInfoWidget.cpp @@ -7,13 +7,13 @@ * */ - #include "DeviceInfoWidget.h" #include "GlobalStorage.h" #include "JobQueue.h" #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" +#include "utils/QtCompat.h" #include "utils/Retranslator.h" #include @@ -47,7 +47,7 @@ DeviceInfoWidget::DeviceInfoWidget( QWidget* parent ) m_ptLabel->setAlignment( Qt::AlignCenter ); QPalette palette; - palette.setBrush( QPalette::Foreground, QColor( "#4D4D4D" ) ); //dark grey + palette.setBrush( WindowText, QColor( "#4D4D4D" ) ); //dark grey m_ptIcon->setAutoFillBackground( true ); m_ptLabel->setAutoFillBackground( true ); diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 20c7d0f08..63227e3b7 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -34,6 +34,7 @@ #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" #include "utils/NamedEnum.h" +#include "utils/QtCompat.h" #include "utils/Retranslator.h" #include "utils/Variant.h" #include "widgets/WaitingWidget.h" @@ -273,7 +274,7 @@ PartitionViewStep::createSummaryWidget() const jobsLabel->setText( jobsLines.join( "
" ) ); jobsLabel->setMargin( CalamaresUtils::defaultFontHeight() / 2 ); QPalette pal; - pal.setColor( QPalette::Background, pal.window().color().lighter( 108 ) ); + pal.setColor( WindowBackground, pal.window().color().lighter( 108 ) ); jobsLabel->setAutoFillBackground( true ); jobsLabel->setPalette( pal ); } diff --git a/src/modules/summary/SummaryPage.cpp b/src/modules/summary/SummaryPage.cpp index d6917d962..96781c25e 100644 --- a/src/modules/summary/SummaryPage.cpp +++ b/src/modules/summary/SummaryPage.cpp @@ -19,6 +19,7 @@ #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" +#include "utils/QtCompat.h" #include "utils/Retranslator.h" #include "viewpages/ExecutionViewStep.h" @@ -183,7 +184,7 @@ SummaryPage::createBodyLabel( const QString& text ) const QLabel* label = new QLabel; label->setMargin( CalamaresUtils::defaultFontHeight() / 2 ); QPalette pal( palette() ); - pal.setColor( QPalette::Background, palette().window().color().lighter( 108 ) ); + pal.setColor( WindowBackground, palette().window().color().lighter( 108 ) ); label->setAutoFillBackground( true ); label->setPalette( pal ); label->setText( text );