Skip to content

Commit

Permalink
Migrate to Qt6 (v6.8.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
oclero committed Oct 12, 2024
1 parent 58022dd commit 5e123f2
Show file tree
Hide file tree
Showing 24 changed files with 69 additions and 268 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ jobs:
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: '5.15.2'
aqtversion: "==3.1.*"
version: "6.8.0"
host: linux
target: desktop
arch: gcc_64
arch: linux_gcc_64

- name: Configure CMake
run: cmake --preset linux
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ jobs:
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: '5.15.2'
aqtversion: "==3.1.*"
version: "6.8.0"
host: mac
target: desktop
arch: clang_64

- name: Configure CMake
run: cmake --preset macos -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=OFF -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY="" -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE="Manual"
run: cmake --preset macos

- name: Build the library.
run: cmake --build --preset macos
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ jobs:
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: '5.15.2'
aqtversion: "==3.1.*"
version: "6.8.0"
host: windows
target: desktop
arch: win64_msvc2019_64
arch: win64_msvc2022_64

- name: Configure CMake
run: cmake --preset windows
Expand Down
22 changes: 4 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.21.0)

# Custom CMake modules.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# Enable parallel build (not enabled by default on Windows).
set(CMAKE_BUILD_PARALLEL_LEVEL $ENV{NUMBER_OF_PROCESSORS})
Expand All @@ -15,16 +15,6 @@ project("qlementine"
set(PROJECT_COPYRIGHT "© Olivier Cléro, MIT License.")
set(PROJECT_NAMESPACE "oclero")

# Temporary hack to make it work with Qt6 <6.4.2 && >6.4.2
# With Qt5, it was "path/to/Qt/6.7.0/msvc2019_64/lib/cmake/Qt6",
# but with Qt6, it is now "path/to/Qt/6.7.0/msvc2019_64".
if(WIN32)
string(FIND "${CMAKE_PREFIX_PATH}" "/lib/cmake/Qt6" USING_Qt6_INDEX)
if(NOT ${USING_Qt6_INDEX} EQUAL -1)
string(REPLACE "/lib/cmake/Qt6" "" "${CMAKE_PREFIX_PATH}" "${CMAKE_PREFIX_PATH}")
endif()
endif()

# Global flags.
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
Expand All @@ -38,14 +28,10 @@ if (NOT CMAKE_OSX_DEPLOYMENT_TARGET)
endif()

# Find Qt.
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Svg)

if(${QT_VERSION_MAJOR} STREQUAL "6")
qt_standard_project_setup()
endif()
find_package(Qt6 REQUIRED COMPONENTS Core Widgets Svg)
qt_standard_project_setup()

include(DeployQt)
# include(DeployQt)

# The library.
add_subdirectory(lib)
Expand Down
4 changes: 2 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"generator": "Xcode",
"binaryDir": "${sourceDir}/_build",
"cacheVariables": {
"QT_DIR": "/opt/homebrew/opt/qt/lib/cmake/Qt5"
"CMAKE_PREFIX_PATH": "/opt/homebrew/opt/qt/lib/cmake/Qt6"
},
"condition": {
"type": "equals",
Expand All @@ -28,7 +28,7 @@
"generator": "Visual Studio 17 2022",
"binaryDir": "${sourceDir}/_build",
"cacheVariables": {
"CMAKE_PREFIX_PATH": "C:/Qt/5.15.2/msvc2019_64/lib/cmake/Qt5"
"CMAKE_PREFIX_PATH": "C:/Qt/6.8.0/msvc2022_64"
},
"condition": {
"type": "equals",
Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<div align="center">
<a href="https://oclero.github.io/qlementine">
<img style="margin-bottom: 2em;" src="branding/thumbnail.png">
<img style="margin-bottom: 2em;" src="branding/thumbnail.png">
</a>
</div>

# Qlementine

[![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://mit-license.org/)
[![CMake version](https://img.shields.io/badge/CMake-3.17.5+-064F8C?logo=cmake)](https://www.qt.io)
[![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://mit-license.org)
[![CMake version](https://img.shields.io/badge/CMake-3.21.0+-064F8C?logo=cmake)](https://cmake.org)
[![C++ version](https://img.shields.io/badge/C++-17-00599C?logo=++)](https://www.qt.io)
[![Qt version](https://img.shields.io/badge/Qt-5.15.3+-41CD52?logo=qt)](https://www.qt.io)
[![Qt version](https://img.shields.io/badge/Qt-6.0.0+-41CD52?logo=qt)](https://www.qt.io)
[![Qt version](https://img.shields.io/badge/Qt-6.8.0+-41CD52?logo=qt)](https://www.qt.io)

[![Linux](https://github.com/oclero/qlementine/actions/workflows/linux.yml/badge.svg)](https://github.com/oclero/qlementine/actions/workflows/linux.yml)
[![Linux](https://github.com/oclero/qlementine/actions/workflows/windows.yml/badge.svg)](https://github.com/oclero/qlementine/actions/workflows/windows.yml)
[![Linux](https://github.com/oclero/qlementine/actions/workflows/macos.yml/badge.svg)](https://github.com/oclero/qlementine/actions/workflows/macos.yml)

Modern QStyle for desktop Qt5/Qt6 applications.
Modern QStyle for desktop Qt6 applications.

See [documentation](https://oclero.github.io/qlementine) for more information.

Expand All @@ -35,8 +34,8 @@ See [documentation](https://oclero.github.io/qlementine) for more information.
## Requirements

- Windows, MacOS or Linux.
- [CMake 3.20.0+](https://cmake.org/download)
- [Qt 5.15.3+ or Qt 6.0.0+](https://www.qt.io/download-qt-installer)
- [CMake 3.21.0+](https://cmake.org/download)
- [Qt 6.8.0+](https://www.qt.io/download-qt-installer)

## Features

Expand Down
46 changes: 0 additions & 46 deletions cmake/DeployQt.cmake

This file was deleted.

6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Qlementine

[Qlementine](https://github.com/oclero/qlementine) is a modern QStyle for desktop Qt5/Qt6 applications, released under the MIT license.
[Qlementine](https://github.com/oclero/qlementine) is a modern QStyle for desktop Qt6 applications, released under the MIT license.

## Library content

Expand All @@ -17,8 +17,8 @@ This library contains:
## Requirements

- Windows, MacOS or Linux.
- [CMake 3.17.5+](https://cmake.org/download)
- [Qt 5.15.3+ or Qt 6.0.0+](https://www.qt.io/download-qt-installer)
- [CMake 3.21.0+](https://cmake.org/download)
- [Qt 6.8.0+](https://www.qt.io/download-qt-installer)

## FAQ

Expand Down
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
target_link_libraries(your_project oclero::qlementine)
```

## Usage
## Usage in code

Define the `QStyle` on your `QApplication`.

Expand Down
29 changes: 9 additions & 20 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
set(LIB_TARGET_NAME ${PROJECT_NAME})

find_package(Qt${QT_VERSION_MAJOR}
COMPONENTS
Core
Widgets
Svg
REQUIRED
)

# Declare files.
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/animation/WidgetAnimator.cpp
Expand Down Expand Up @@ -111,19 +103,16 @@ set(RESOURCES
$<$<PLATFORM_ID:Windows>:resources/qlementine_font_inter_windows.qrc>
)

# Configure target.
add_library(${LIB_TARGET_NAME} STATIC)
# Create target.
qt_add_library(${LIB_TARGET_NAME} STATIC
${HEADERS}
${SOURCES}
${RESOURCES}
)

# Create a target alias.
add_library(${PROJECT_NAMESPACE}::${LIB_TARGET_NAME} ALIAS ${LIB_TARGET_NAME})

target_sources(${LIB_TARGET_NAME}
PRIVATE
${HEADERS}
${SOURCES}
${RESOURCES}
)

target_include_directories(${LIB_TARGET_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand All @@ -132,9 +121,9 @@ target_include_directories(${LIB_TARGET_NAME}
)

target_link_libraries(${LIB_TARGET_NAME} PUBLIC
Qt::Core
Qt::Widgets
Qt::Svg
Qt6::Core
Qt6::Widgets
Qt6::Svg
)

set_target_properties(${LIB_TARGET_NAME}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ class AbstractItemListWidget : public QWidget {
void keyPressEvent(QKeyEvent* e) override;
void keyReleaseEvent(QKeyEvent* e) override;
void mousePressEvent(QMouseEvent* e) override;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void enterEvent(QEvent* e) override;
#else
void enterEvent(QEnterEvent* e) override;
#endif
void leaveEvent(QEvent* e) override;
void mouseReleaseEvent(QMouseEvent* e) override;
void mouseMoveEvent(QMouseEvent* e) override;
Expand Down
4 changes: 0 additions & 4 deletions lib/include/oclero/qlementine/widgets/Switch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ class Switch : public QAbstractButton {

protected:
void paintEvent(QPaintEvent* e) override;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void enterEvent(QEvent* e) override;
#else
void enterEvent(QEnterEvent* e) override;
#endif
void leaveEvent(QEvent* e) override;
void changeEvent(QEvent* e) override;
void focusInEvent(QFocusEvent* e) override;
Expand Down
16 changes: 0 additions & 16 deletions lib/src/style/QlementineStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1755,12 +1755,8 @@ void QlementineStyle::drawControl(ControlElement ce, const QStyleOption* opt, QP
const auto autoIconColor = this->autoIconColor(w);
const auto colorize = autoIconColor != AutoIconColor::None;
const auto iconMode = (optHeader->state & State_Enabled || colorize) ? QIcon::Normal : QIcon::Disabled;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto iconPixmap = icon.pixmap(qlementine::getWindow(w), { iconExtent, iconExtent }, iconMode);
#else
const auto iconPixmap =
icon.pixmap({ iconExtent, iconExtent }, qlementine::getWindow(w)->devicePixelRatio(), iconMode);
#endif
const auto& colorizedPixmap = colorize ? qlementine::colorizePixmap(iconPixmap, fgColor) : iconPixmap;
p->drawPixmap(iconRect, colorizedPixmap);
}
Expand Down Expand Up @@ -3759,13 +3755,7 @@ QSize QlementineStyle::sizeFromContents(

// Shortcut. NB: Some difficulties to understand what's going on. Qt changes the width so here's a hack.
const auto hasShortcut = shortcut.length() > 0;

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto reservedShortcutW = optMenuItem->tabWidth;
#else
const auto reservedShortcutW = optMenuItem->reservedShortcutWidth;
#endif

const auto shortcutW = hasShortcut ? 3 * spacing - reservedShortcutW : 0;

// Icon.
Expand Down Expand Up @@ -4098,12 +4088,6 @@ int QlementineStyle::pixelMetric(PixelMetric m, const QStyleOption* opt, const Q
return _impl->theme.iconSize.height();

// Dialog.
case PM_DialogButtonsSeparator:
break;
case PM_DialogButtonsButtonWidth:
break;
case PM_DialogButtonsButtonHeight:
return _impl->theme.controlHeightLarge;
case PM_MessageBoxIconSize:
return _impl->theme.iconSizeLarge.height();

Expand Down
11 changes: 0 additions & 11 deletions lib/src/utils/ColorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,10 @@ std::optional<QColor> tryGetColorFromHexaString(QString const& str) {
if (str.startsWith('#') && (length == RGB_LENGTH || length == RGBA_LENGTH)) {
auto success{ false };

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto r_str = str.midRef(1, 2);
const auto g_str = str.midRef(3, 2);
const auto b_str = str.midRef(5, 2);
const auto a_str = str.midRef(7, 2);
#else
const auto r_str = str.mid(1, 2);
const auto g_str = str.mid(3, 2);
const auto b_str = str.mid(5, 2);
const auto a_str = str.mid(7, 2);
#endif

const auto r = r_str.toInt(&success, HEX_BASE);
if (success) {
Expand All @@ -180,11 +173,7 @@ std::optional<QColor> tryGetColorFromHexaString(QString const& str) {
}

std::optional<QColor> tryGetColorFromVariant(QVariant const& variant) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto variantType = static_cast<QMetaType::Type>(variant.type());
#else
const auto variantType = variant.typeId();
#endif

// Channel list ([RRR, GGG, BBB, AAA]).
if (variantType == QMetaType::Type::QVariantList) {
Expand Down
Loading

0 comments on commit 5e123f2

Please sign in to comment.