From dada19cf1c6d9ceb9cb7bb207faf0e126d04ccdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Thu, 23 Sep 2021 16:09:51 +0200 Subject: [PATCH] Various improvements for native macOS UI (#2776) --- src/CutterApplication.cpp | 4 + src/common/Configuration.cpp | 8 + src/dialogs/InitialOptionsDialog.ui | 6 + src/img/cutter_macos_simple.svg | 225 +++++++++++++++++++++++ src/resources.qrc | 1 + src/themes/native/macos-close-dark.svg | 23 +++ src/themes/native/macos-close-light.svg | 23 +++ src/themes/native/macos-float-dark.svg | 16 ++ src/themes/native/macos-float-light.svg | 16 ++ src/themes/native/native-macos-dark.qss | 31 ++++ src/themes/native/native-macos-light.qss | 30 +++ src/themes/native/native.qrc | 6 + 12 files changed, 389 insertions(+) create mode 100644 src/img/cutter_macos_simple.svg create mode 100644 src/themes/native/macos-close-dark.svg create mode 100644 src/themes/native/macos-close-light.svg create mode 100644 src/themes/native/macos-float-dark.svg create mode 100644 src/themes/native/macos-float-light.svg create mode 100644 src/themes/native/native-macos-dark.qss create mode 100644 src/themes/native/native-macos-light.qss diff --git a/src/CutterApplication.cpp b/src/CutterApplication.cpp index d0134c91..ba06c112 100644 --- a/src/CutterApplication.cpp +++ b/src/CutterApplication.cpp @@ -43,7 +43,11 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc { // Setup application information setApplicationVersion(CUTTER_VERSION_FULL); +#ifdef Q_OS_MACOS + setWindowIcon(QIcon(":/img/cutter_macos_simple.svg")); +#else setWindowIcon(QIcon(":/img/cutter.svg")); +#endif #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) setAttribute(Qt::AA_UseHighDpiPixmaps); // always enabled on Qt >= 6.0.0 #endif diff --git a/src/common/Configuration.cpp b/src/common/Configuration.cpp index 133b0610..764ecdb5 100644 --- a/src/common/Configuration.cpp +++ b/src/common/Configuration.cpp @@ -288,6 +288,14 @@ void Configuration::loadNativeStylesheet() f.open(QFile::ReadOnly | QFile::Text); QTextStream ts(&f); QString stylesheet = ts.readAll(); +#ifdef Q_OS_MACOS + QFile mf(nativeWindowIsDark() ? ":native/native-macos-dark.qss" : ":native/native-macos-light.qss"); + if (mf.exists()) { + mf.open(QFile::ReadOnly | QFile::Text); + QTextStream mts(&mf); + stylesheet += "\n" + mts.readAll(); + } +#endif qApp->setStyleSheet(stylesheet); } diff --git a/src/dialogs/InitialOptionsDialog.ui b/src/dialogs/InitialOptionsDialog.ui index 3b8cc363..481c409c 100644 --- a/src/dialogs/InitialOptionsDialog.ui +++ b/src/dialogs/InitialOptionsDialog.ui @@ -188,6 +188,12 @@ 0 + + + 0 + 24 + + 0 diff --git a/src/img/cutter_macos_simple.svg b/src/img/cutter_macos_simple.svg new file mode 100644 index 00000000..f7419c92 --- /dev/null +++ b/src/img/cutter_macos_simple.svg @@ -0,0 +1,225 @@ + + + macOS-icon + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + macOS-icon + + + + diff --git a/src/resources.qrc b/src/resources.qrc index 0f80520b..79d02948 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -107,6 +107,7 @@ img/cutter_plain.svg img/cutter_white_plain.svg img/cutter.svg + img/cutter_macos_simple.svg img/icons/copy.svg img/icons/delete.svg img/icons/previous.svg diff --git a/src/themes/native/macos-close-dark.svg b/src/themes/native/macos-close-dark.svg new file mode 100644 index 00000000..55093cde --- /dev/null +++ b/src/themes/native/macos-close-dark.svg @@ -0,0 +1,23 @@ + + + + + + + + + diff --git a/src/themes/native/macos-close-light.svg b/src/themes/native/macos-close-light.svg new file mode 100644 index 00000000..75c1cb95 --- /dev/null +++ b/src/themes/native/macos-close-light.svg @@ -0,0 +1,23 @@ + + + + + + + + + diff --git a/src/themes/native/macos-float-dark.svg b/src/themes/native/macos-float-dark.svg new file mode 100644 index 00000000..32cfad91 --- /dev/null +++ b/src/themes/native/macos-float-dark.svg @@ -0,0 +1,16 @@ + + + + + diff --git a/src/themes/native/macos-float-light.svg b/src/themes/native/macos-float-light.svg new file mode 100644 index 00000000..3d7ba826 --- /dev/null +++ b/src/themes/native/macos-float-light.svg @@ -0,0 +1,16 @@ + + + + + diff --git a/src/themes/native/native-macos-dark.qss b/src/themes/native/native-macos-dark.qss new file mode 100644 index 00000000..2f3f630c --- /dev/null +++ b/src/themes/native/native-macos-dark.qss @@ -0,0 +1,31 @@ +/* +Cocoa has no notion of Dock Widgets so Qt has to craft them itself, +but the default appearance is awful! +So let's try to make them as native as possible. +*/ +QDockWidget::title { + text-align: center; + background: palette(window); +} + +QDockWidget { + titlebar-close-icon: url(:/native/macos-close-dark.svg); + titlebar-normal-icon: url(:/native/macos-float-dark.svg); +} + +QDockWidget::close-button, +QDockWidget::float-button { + border: 1px solid transparent; + border-radius: 10px; + background: transparent; +} + +QDockWidget::close-button:hover, +QDockWidget::float-button:hover { + background: rgba(255, 255, 255, 10); +} + +QDockWidget::close-button:pressed, +QDockWidget::float-button:pressed { + background: rgba(255, 255, 255, 10); +} diff --git a/src/themes/native/native-macos-light.qss b/src/themes/native/native-macos-light.qss new file mode 100644 index 00000000..efb9e30f --- /dev/null +++ b/src/themes/native/native-macos-light.qss @@ -0,0 +1,30 @@ +/* +Cocoa has no notion of Dock Widgets so Qt has to craft them itself, +but the default appearance is awful! +So let's try to make them as native as possible. +*/ +QDockWidget::title { + text-align: center; +} + +QDockWidget { + titlebar-close-icon: url(:/native/macos-close-light.svg); + titlebar-normal-icon: url(:/native/macos-float-light.svg); +} + +QDockWidget::close-button, +QDockWidget::float-button { + border: 1px solid transparent; + border-radius: 10px; + background: transparent; +} + +QDockWidget::close-button:hover, +QDockWidget::float-button:hover { + background: rgba(0, 0, 0, 10); +} + +QDockWidget::close-button:pressed, +QDockWidget::float-button:pressed { + background: rgba(0, 0, 0, 10); +} diff --git a/src/themes/native/native.qrc b/src/themes/native/native.qrc index c81e59a7..d1eeaffb 100644 --- a/src/themes/native/native.qrc +++ b/src/themes/native/native.qrc @@ -1,5 +1,11 @@ native.qss + native-macos-dark.qss + macos-close-dark.svg + macos-float-dark.svg + native-macos-light.qss + macos-close-light.svg + macos-float-light.svg