diff --git a/CMakeLists.txt b/CMakeLists.txt index 91ca9a9..4c831ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ set (CMAKE_AUTOUIC ON) find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core) -set (QT_MINIMUM_VERSION "6.4") +set (QT_MINIMUM_VERSION "6.5") find_package(Qt${QT_VERSION_MAJOR} ${QT_MINIMUM_VERSION} REQUIRED COMPONENTS Widgets Svg SvgWidgets LinguistTools diff --git a/app/bottombuttongroup.cpp b/app/bottombuttongroup.cpp index 2e5dd49..d0b44d4 100644 --- a/app/bottombuttongroup.cpp +++ b/app/bottombuttongroup.cpp @@ -15,35 +15,25 @@ BottomButtonGroup::BottomButtonGroup(const std::vector &actionList, Q mainLayout->setSizeConstraint(QLayout::SetFixedSize); this->setLayout(mainLayout); this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - this->setStyleSheet("BottomButtonGroup {" - "border: 1px solid gray;" - "border-top-left-radius: 10px;" - "border-top-right-radius: 10px;" - "border-style: none;" - "background-color:rgba(0,0,0,120)" - "}" - "QToolButton {" - "background:transparent;" - "}" - "QToolButton:!focus {" - "border-style: none;" - "}"); + this->setStyleSheet(R"#( +BottomButtonGroup { + border-style: none; + background: transparent; +} +QToolButton { + background: transparent; + border-style: none; +} +)#"); - auto newActionBtn = [this](QAction * action) -> QToolButton * { + for (QAction * action : actionList) { + // Create button QToolButton * btn = new QToolButton(this); btn->setDefaultAction(action); btn->setIconSize(QSize(32, 32)); btn->setFixedSize(40, 40); - return btn; - }; - - for (QAction * action : actionList) { - addButton(newActionBtn(action)); + // Add button + layout()->addWidget(btn); } -} - -void BottomButtonGroup::addButton(QAbstractButton *button) -{ - layout()->addWidget(button); updateGeometry(); } diff --git a/app/bottombuttongroup.h b/app/bottombuttongroup.h index c024598..99f4eb9 100644 --- a/app/bottombuttongroup.h +++ b/app/bottombuttongroup.h @@ -15,8 +15,6 @@ class BottomButtonGroup : public QGroupBox Q_OBJECT public: explicit BottomButtonGroup(const std::vector & actionList, QWidget *parent = nullptr); - - void addButton(QAbstractButton *button); }; #endif // BOTTOMBUTTONGROUP_H diff --git a/app/graphicsscene.cpp b/app/graphicsscene.cpp index 8abf68b..50df449 100644 --- a/app/graphicsscene.cpp +++ b/app/graphicsscene.cpp @@ -6,6 +6,9 @@ #include "settings.h" +#include +#include +#include #include #include #include @@ -16,6 +19,33 @@ #include #include +static const QColor& ColorSchemaToTextForeground(Qt::ColorScheme colorScheme) { + // YYC MARK: + // If we are using Windows 10 and lower system or Qt which do not support "Windows 11" + // theme (lower than Qt 6.7), we should only support light mode. + // Because Qt's dark-mode-aware "Windows 11" theme is only well-supported on Windows 11. +#if defined(Q_OS_WIN) +#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0) + colorScheme = Qt::ColorScheme::Light; +#else + if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows11) { + colorScheme = Qt::ColorScheme::Light; + } +#endif // QT_VERSION < QT_VERSION_CHECK(6, 7, 0) +#endif // defined(Q_OS_WIN) + + switch (colorScheme) { + case Qt::ColorScheme::Dark: + static QColor WHITE = QColor("White"); + return WHITE; + case Qt::ColorScheme::Light: + case Qt::ColorScheme::Unknown: + default: + static QColor BLACK = QColor("Black"); + return BLACK; + } +} + class PGraphicsPixmapItem : public QGraphicsPixmapItem { public: @@ -100,6 +130,7 @@ GraphicsScene::GraphicsScene(QObject *parent) : QGraphicsScene(parent) { showText(tr("Drag image here")); + connect(qGuiApp->styleHints(), &QStyleHints::colorSchemeChanged, this, &GraphicsScene::updateStyle); } GraphicsScene::~GraphicsScene() @@ -121,7 +152,7 @@ void GraphicsScene::showText(const QString &text) { this->clear(); QGraphicsTextItem * textItem = this->addText(text); - textItem->setDefaultTextColor(QColor("White")); + textItem->setDefaultTextColor(ColorSchemaToTextForeground(qGuiApp->styleHints()->colorScheme())); m_theThing = textItem; this->setSceneRect(m_theThing->boundingRect()); } @@ -206,3 +237,14 @@ QPixmap GraphicsScene::renderToPixmap() return pixmap; } + +void GraphicsScene::updateStyle(Qt::ColorScheme colorScheme) { + Q_UNUSED(colorScheme) + + QGraphicsItem * item = this->m_theThing; + if (item == nullptr) return; + QGraphicsTextItem * textItem = qgraphicsitem_cast(item); + if (textItem == nullptr) return; + + textItem->setDefaultTextColor(ColorSchemaToTextForeground(colorScheme)); +} diff --git a/app/graphicsscene.h b/app/graphicsscene.h index 4ec3596..0716141 100644 --- a/app/graphicsscene.h +++ b/app/graphicsscene.h @@ -26,6 +26,9 @@ public: QPixmap renderToPixmap(); +public slots: + void updateStyle(Qt::ColorScheme colorScheme); + private: QGraphicsItem * m_theThing = nullptr; }; diff --git a/app/graphicsview.cpp b/app/graphicsview.cpp index 568a5f8..91c1ebc 100644 --- a/app/graphicsview.cpp +++ b/app/graphicsview.cpp @@ -7,6 +7,8 @@ #include "graphicsscene.h" #include "settings.h" +#include +#include #include #include #include @@ -23,11 +25,12 @@ GraphicsView::GraphicsView(QWidget *parent) setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setResizeAnchor(QGraphicsView::AnchorUnderMouse); setTransformationAnchor(QGraphicsView::AnchorUnderMouse); - setStyleSheet("background-color: rgba(0, 0, 0, 220);" - "border-radius: 3px;"); setAcceptDrops(false); setCheckerboardEnabled(false); + updateStyle(qGuiApp->styleHints()->colorScheme()); + connect(qGuiApp->styleHints(), &QStyleHints::colorSchemeChanged, this, &GraphicsView::updateStyle); + connect(horizontalScrollBar(), &QScrollBar::valueChanged, this, &GraphicsView::viewportRectChanged); connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &GraphicsView::viewportRectChanged); } @@ -344,6 +347,39 @@ void GraphicsView::toggleCheckerboard(bool invertCheckerboardColor) setCheckerboardEnabled(!m_checkerboardEnabled, invertCheckerboardColor); } +void GraphicsView::updateStyle(Qt::ColorScheme colorScheme) { + // YYC MARK: + // If we are using Windows 10 and lower system or Qt which do not support "Windows 11" + // theme (lower than Qt 6.7), we should only support light mode. + // Because Qt's dark-mode-aware "Windows 11" theme is only well-supported on Windows 11. +#if defined(Q_OS_WIN) +#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0) + colorScheme = Qt::ColorScheme::Light; +#else + if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows11) { + colorScheme = Qt::ColorScheme::Light; + } +#endif // QT_VERSION < QT_VERSION_CHECK(6, 7, 0) +#endif // defined(Q_OS_WIN) + + switch (colorScheme) { + case Qt::ColorScheme::Dark: + setStyleSheet(R"#( +border-style: none; +background-color: black; +)#"); + break; + case Qt::ColorScheme::Light: + case Qt::ColorScheme::Unknown: + default: + setStyleSheet(R"#( +border-style: none; +background-color: white; +)#"); + break; + } +} + void GraphicsView::mousePressEvent(QMouseEvent *event) { if (shouldIgnoreMousePressMoveEvent(event)) { diff --git a/app/graphicsview.h b/app/graphicsview.h index f20d0ec..d314385 100644 --- a/app/graphicsview.h +++ b/app/graphicsview.h @@ -51,6 +51,7 @@ signals: public slots: void toggleCheckerboard(bool invertCheckerboardColor = false); + void updateStyle(Qt::ColorScheme colorScheme); private: void mousePressEvent(QMouseEvent * event) override; diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 9092f13..0153921 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -51,7 +51,6 @@ MainWindow::MainWindow(QWidget *parent) , m_pm(new PlaylistManager(this)) , m_fileSystemWatcher(new QFileSystemWatcher(this)) { - this->setAttribute(Qt::WA_TranslucentBackground, true); // YYC MARK: // Blumis set original value is 350 x 330. // It is too small for modern device, diff --git a/app/navigatorview.cpp b/app/navigatorview.cpp index 9a3cef7..d7caf5a 100644 --- a/app/navigatorview.cpp +++ b/app/navigatorview.cpp @@ -6,6 +6,8 @@ #include "graphicsview.h" +#include +#include #include #include #include @@ -16,8 +18,9 @@ NavigatorView::NavigatorView(QWidget *parent) { setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setStyleSheet("background-color: rgba(0, 0, 0, 120);" - "border-radius: 3px;"); + + updateStyle(qGuiApp->styleHints()->colorScheme()); + connect(qGuiApp->styleHints(), &QStyleHints::colorSchemeChanged, this, &NavigatorView::updateStyle); } // doesn't take or manage its ownership @@ -38,6 +41,39 @@ void NavigatorView::updateMainViewportRegion() }); } +void NavigatorView::updateStyle(Qt::ColorScheme colorScheme) { + // YYC MARK: + // If we are using Windows 10 and lower system or Qt which do not support "Windows 11" + // theme (lower than Qt 6.7), we should only support light mode. + // Because Qt's dark-mode-aware "Windows 11" theme is only well-supported on Windows 11. +#if defined(Q_OS_WIN) +#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0) + colorScheme = Qt::ColorScheme::Light; +#else + if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows11) { + colorScheme = Qt::ColorScheme::Light; + } +#endif // QT_VERSION < QT_VERSION_CHECK(6, 7, 0) +#endif // defined(Q_OS_WIN) + + switch (colorScheme) { + case Qt::ColorScheme::Dark: + setStyleSheet(R"#( +border-style: none; +background-color: rgba(255, 255, 255, 70); +)#"); + break; + case Qt::ColorScheme::Light: + case Qt::ColorScheme::Unknown: + default: + setStyleSheet(R"#( +border-style: none; +background-color: rgba(0, 0, 0, 70); +)#"); + break; + } +} + void NavigatorView::mousePressEvent(QMouseEvent *event) { m_mouseDown = true; diff --git a/app/navigatorview.h b/app/navigatorview.h index e3b894e..624fdbc 100644 --- a/app/navigatorview.h +++ b/app/navigatorview.h @@ -18,6 +18,7 @@ public: public slots: void updateMainViewportRegion(); + void updateStyle(Qt::ColorScheme colorScheme); private: void mousePressEvent(QMouseEvent * event) override;