Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui/tray: Dark mode switch #7561

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gui/tray/ActivityItemContent.qml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ RowLayout {

cache: true
fillMode: Image.PreserveAspectFit
source: Theme.darkMode ? model.darkIcon : model.lightIcon
source: Style.darkMode ? model.darkIcon : model.lightIcon
sourceSize.height: 64
sourceSize.width: 64
mipmap: true // Addresses grainy downscale
Expand Down
2 changes: 1 addition & 1 deletion src/gui/tray/CallNotificationDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ ApplicationWindow {
cache: true

source: root.usingUserAvatar ? root.talkNotificationData.userAvatar :
Theme.darkMode ? root.talkIcon + palette.windowText : root.talkIcon + Style.ncBlue
Style.darkMode ? root.talkIcon + palette.windowText : root.talkIcon + Style.ncBlue
sourceSize.width: Style.accountAvatarSize
sourceSize.height: Style.accountAvatarSize

Expand Down
6 changes: 3 additions & 3 deletions src/gui/tray/UnifiedSearchResultListItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ MouseArea {
anchors.fill: parent
title: model.resultTitle
subline: model.subline
icons: Theme.darkMode ? model.darkIcons : model.lightIcons
iconsIsThumbnail: Theme.darkMode ? model.darkIconsIsThumbnail : model.lightIconsIsThumbnail
iconPlaceholder: Theme.darkMode ? model.darkImagePlaceholder : model.lightImagePlaceholder
icons: Style.darkMode ? model.darkIcons : model.lightIcons
iconsIsThumbnail: Style.darkMode ? model.darkIconsIsThumbnail : model.lightIconsIsThumbnail
iconPlaceholder: Style.darkMode ? model.darkImagePlaceholder : model.lightImagePlaceholder
isRounded: model.isRounded && iconsIsThumbnail
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/tray/UserLine.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ AbstractButton {
Layout.leftMargin: Style.accountIconsMenuMargin
verticalAlignment: Qt.AlignCenter
cache: false
source: model.avatar !== "" ? model.avatar : Theme.darkMode ? "image://avatars/fallbackWhite" : "image://avatars/fallbackBlack"
source: model.avatar !== "" ? model.avatar : Style.darkMode ? "image://avatars/fallbackWhite" : "image://avatars/fallbackBlack"
Layout.preferredHeight: Style.accountAvatarSize
Layout.preferredWidth: Style.accountAvatarSize

Expand Down
13 changes: 6 additions & 7 deletions src/libsync/theme.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/libsync/theme.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/libsync/theme.cpp

File src/libsync/theme.cpp does not conform to Custom style guidelines. (lines 970)
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -398,9 +398,10 @@
QColor(127, 127, 127));
reserveDarkPalette.setColor(QPalette::Disabled, QPalette::WindowText,
QColor(127, 127, 127));
connectToPaletteSignal();
#endif

connectToPaletteSignal();

#ifdef APPLICATION_SERVER_URL_ENFORCE
_forceOverrideServerUrl = true;
#endif
Expand Down Expand Up @@ -964,13 +965,10 @@
return QColor{NEXTCLOUD_BACKGROUND_COLOR};
}

void Theme::connectToPaletteSignal()
void Theme::connectToPaletteSignal() const
{
if (!_paletteSignalsConnected) {
if (const auto ptr = qobject_cast<QGuiApplication*>(qApp)) {
connect(ptr->styleHints(), &QStyleHints::colorSchemeChanged, this, &Theme::darkModeChanged);
_paletteSignalsConnected = true;
}
if (const auto ptr = qobject_cast<QGuiApplication*>(qApp)) {
connect(ptr->styleHints(), &QStyleHints::colorSchemeChanged, this, &Theme::darkModeChanged, Qt::UniqueConnection);
}
}

Expand Down Expand Up @@ -1012,6 +1010,7 @@

bool Theme::darkMode() const
{
connectToPaletteSignal();
const auto isDarkFromStyle = [] {
switch (qGuiApp->styleHints()->colorScheme())
{
Expand Down
3 changes: 1 addition & 2 deletions src/libsync/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef _THEME_H
#define _THEME_H

#include <QIcon>

Check failure on line 18 in src/libsync/theme.h

View workflow job for this annotation

GitHub Actions / build

src/libsync/theme.h:18:10 [clang-diagnostic-error]

'QIcon' file not found
#include <QObject>
#include <QPalette>
#include <QGuiApplication>
Expand Down Expand Up @@ -639,14 +639,13 @@
Theme &operator=(Theme const &);

void updateMultipleOverrideServers();
void connectToPaletteSignal();
void connectToPaletteSignal() const;
#if defined(Q_OS_WIN)
QPalette reserveDarkPalette; // Windows 11 button and window dark colours
#endif

static Theme *_instance;
bool _mono = false;
bool _paletteSignalsConnected = false;

QString _overrideServerUrl;
bool _forceOverrideServerUrl = false;
Expand Down
Loading