From a4416cd77c184ecfe1db0e3003bfd01af29057a3 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Sat, 2 Oct 2021 19:57:42 +0800 Subject: [PATCH] chore: initial Qt6 build support --- app/framelesswindow.cpp | 4 ++-- app/framelesswindow.h | 8 +++++++- app/mainwindow.cpp | 3 ++- app/mainwindow.h | 8 +++++++- app/metadatamodel.cpp | 8 ++++---- app/metadatamodel.h | 4 ++-- pineapple-pictures.pro | 1 + 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/framelesswindow.cpp b/app/framelesswindow.cpp index ee98597..a4bba04 100644 --- a/app/framelesswindow.cpp +++ b/app/framelesswindow.cpp @@ -17,7 +17,7 @@ FramelessWindow::FramelessWindow(QWidget *parent) // https://bugreports.qt.io/browse/QTBUG-91226 this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint); - m_centralLayout->setMargin(0); + m_centralLayout->setContentsMargins(QMargins()); } void FramelessWindow::setCentralWidget(QWidget *widget) @@ -31,7 +31,7 @@ void FramelessWindow::setCentralWidget(QWidget *widget) m_centralWidget = widget; } -bool FramelessWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) +bool FramelessWindow::nativeEvent(const QByteArray &eventType, void *message, NATIVE_RESULT *result) { #ifdef _WIN32 // https://stackoverflow.com/questions/43505580/qt-windows-resizable-frameless-window diff --git a/app/framelesswindow.h b/app/framelesswindow.h index 15ea473..48c02d9 100644 --- a/app/framelesswindow.h +++ b/app/framelesswindow.h @@ -3,6 +3,12 @@ #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + typedef qintptr NATIVE_RESULT; +#else + typedef long NATIVE_RESULT; +#endif // QT_VERSION_CHECK(6, 0, 0) + QT_BEGIN_NAMESPACE class QVBoxLayout; QT_END_NAMESPACE @@ -16,7 +22,7 @@ public: void setCentralWidget(QWidget * widget); protected: - bool nativeEvent(const QByteArray& eventType, void* message, long* result) override; + bool nativeEvent(const QByteArray& eventType, void* message, NATIVE_RESULT* result) override; private: QVBoxLayout * m_centralLayout = nullptr; diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 418c8f8..a657b88 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include MainWindow::MainWindow(QWidget *parent) @@ -245,7 +246,7 @@ void MainWindow::showEvent(QShowEvent *event) return FramelessWindow::showEvent(event); } -void MainWindow::enterEvent(QEvent *event) +void MainWindow::enterEvent(QT_ENTER_EVENT *event) { m_bottomButtonGroup->setOpacity(1); m_gv->setOpacity(1); diff --git a/app/mainwindow.h b/app/mainwindow.h index da8475f..d97224e 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -7,6 +7,12 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + typedef QEnterEvent QT_ENTER_EVENT; +#else + typedef QEvent QT_ENTER_EVENT; +#endif // QT_VERSION_CHECK(6, 0, 0) + QT_BEGIN_NAMESPACE class QGraphicsOpacityEffect; class QGraphicsView; @@ -37,7 +43,7 @@ public: protected slots: void showEvent(QShowEvent *event) override; - void enterEvent(QEvent *event) override; + void enterEvent(QT_ENTER_EVENT *event) override; void leaveEvent(QEvent *event) override; void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; diff --git a/app/metadatamodel.cpp b/app/metadatamodel.cpp index 7353c3b..75b28a8 100644 --- a/app/metadatamodel.cpp +++ b/app/metadatamodel.cpp @@ -183,14 +183,14 @@ QString MetadataModel::imageSizeRatio(const QSize &size) return tr("%1 : %2").arg(QString::number(size.width() / gcd), QString::number(size.height() / gcd)); } -bool MetadataModel::appendSection(const QString §ionKey, const QString §ionDisplayName) +bool MetadataModel::appendSection(const QString §ionKey, QStringView sectionDisplayName) { if (m_sections.contains(sectionKey)) { return false; } m_sections.append(sectionKey); - m_sectionProperties[sectionKey] = qMakePair >(sectionDisplayName, {}); + m_sectionProperties[sectionKey] = qMakePair >(sectionDisplayName.toString(), {}); return true; } @@ -202,7 +202,7 @@ bool MetadataModel::appendPropertyIfNotEmpty(const QString §ionKey, const QS return appendProperty(sectionKey, propertyKey, propertyDisplayName, propertyValue); } -bool MetadataModel::appendProperty(const QString §ionKey, const QString &propertyKey, const QString &propertyDisplayName, const QString &propertyValue) +bool MetadataModel::appendProperty(const QString §ionKey, const QString &propertyKey, QStringView propertyDisplayName, QStringView propertyValue) { if (!m_sections.contains(sectionKey)) { return false; @@ -213,7 +213,7 @@ bool MetadataModel::appendProperty(const QString §ionKey, const QString &pro propertyList.append(propertyKey); } - m_properties[propertyKey] = qMakePair(propertyDisplayName, propertyValue); + m_properties[propertyKey] = qMakePair(propertyDisplayName.toString(), propertyValue.toString()); return true; } diff --git a/app/metadatamodel.h b/app/metadatamodel.h index 4535aed..51de2f5 100644 --- a/app/metadatamodel.h +++ b/app/metadatamodel.h @@ -15,11 +15,11 @@ public: void setFile(const QString & imageFilePath); static QString imageSize(const QSize &size); static QString imageSizeRatio(const QSize &size); - bool appendSection(const QString & sectionKey, const QString & sectionDisplayName); + bool appendSection(const QString & sectionKey, QStringView sectionDisplayName); bool appendPropertyIfNotEmpty(const QString & sectionKey, const QString & propertyKey, const QString & propertyDisplayName, const QString & propertyValue = QString()); bool appendProperty(const QString & sectionKey, const QString & propertyKey, - const QString & propertyDisplayName, const QString & propertyValue = QString()); + QStringView propertyDisplayName, QStringView propertyValue = QString()); bool appendExivPropertyIfExist(const Exiv2Wrapper & wrapper, const QString & sectionKey, const QString & exiv2propertyKey, const QString & propertyDisplayName = QString(), bool isXmpString = false); diff --git a/pineapple-pictures.pro b/pineapple-pictures.pro index 3ecc8a1..5b9fefe 100644 --- a/pineapple-pictures.pro +++ b/pineapple-pictures.pro @@ -1,4 +1,5 @@ QT += core widgets gui svg +greaterThan(QT_MAJOR_VERSION, 5): QT += svgwidgets TARGET = ppic TEMPLATE = app