Skip to content

Commit

Permalink
fix: Respect dark mode using color roles for "2nd level list headings"
Browse files Browse the repository at this point in the history
Hard coded color codes are replaced by Qt's color roles. This works in light and dark mode themes.

The term "2nd level list headings" refer to the snapshot timeline widget with headings like "Now" or "Yesterday" and to the "Shortcuts" list in the file list view with headings like "Global" and "Backup folders".

Fix #1601
  • Loading branch information
buhtz committed Feb 23, 2024
1 parent afebdf4 commit ff294f7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Back In Time

Version 1.4.4-dev (development of upcoming release)
* Fix: Respect dark mode using color roles (#1601)
* Dependency: Migration to PyQt6
* Build: PyLint unit test is skipped if PyLint isn't installed, but will always run on TravisCI (#1634)
* Feature: Support rsync '--one-file-system' in Expert Options (#1598)
Expand Down
9 changes: 9 additions & 0 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,15 @@ Otherwise, kill the process. After that look into the folder

For more details see the developer documentation: [Usage of control files (locks, flocks, logs and others)](common/doc-dev/4_Control_files_usage_(locks_flocks_logs_and_others).md)

### Switching to dark or light mode in the desktop environment is ignored by BIT
After restart _Back In Time_ it should addapt to the desktops current used
color theme.

It happens because Qt does not detect theme modifications out of the
box. [Workarounds are known](https://stackoverflow.com/q/75457687), but
generate a relatively large amount of code and in our opinion are not worth
the effort.

## Error Handling

### What happens if I hibernate the computer while a backup is running?
Expand Down
16 changes: 13 additions & 3 deletions qt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from PyQt6.QtGui import (QAction,
QShortcut,
QDesktopServices,
QPalette,
QColor,
QIcon,
QFileSystemModel)
Expand Down Expand Up @@ -1058,6 +1059,10 @@ def placesChanged(self, item, previous):
self.updateFilesView(3)

def addPlace(self, name, path, icon):
"""
Dev note (buhtz, 2024-01-14): Parts of that code are redundant with
qttools.py::HeaderItem.__init__().
"""
item = QTreeWidgetItem()

item.setText(0, name)
Expand All @@ -1069,9 +1074,13 @@ def addPlace(self, name, path, icon):

if not path:
item.setFont(0, qttools.fontBold(item.font(0)))
item.setFlags(Qt.ItemFlag.ItemIsEnabled)
item.setBackground(0, QColor(196, 196, 196))
item.setForeground(0, QColor(60, 60, 60))

# item.setFlags(Qt.ItemFlag.ItemIsEnabled)
item.setFlags(Qt.ItemFlag.NoItemFlags)
item.setForeground(
0, self.palette().color(QPalette.ColorRole.PlaceholderText))
item.setBackground(
0, self.palette().color(QPalette.ColorRole.Window))

self.places.addTopLevelItem(item)

Expand All @@ -1088,6 +1097,7 @@ def updatePlaces(self):

# add backup folders
include_folders = self.config.include()

if include_folders:
folders = []
for item in include_folders:
Expand Down
17 changes: 13 additions & 4 deletions qt/qttools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
import os
import sys

from PyQt6.QtGui import (QAction, QFont, QColor, QIcon)
from PyQt6.QtGui import (QAction, QFont, QPalette, QIcon)
from PyQt6.QtCore import (QDir, Qt, pyqtSlot, pyqtSignal, QModelIndex,
QTranslator, QLocale, QLibraryInfo,
QT_VERSION_STR)
from PyQt6.QtWidgets import (QFileDialog, QAbstractItemView, QListView,
QTreeView, QDialog, QApplication, QStyleFactory,
QTreeWidget, QTreeWidgetItem, QComboBox,
QSystemTrayIcon, QWidget)
QSystemTrayIcon)
from datetime import (datetime, date, timedelta)
from calendar import monthrange
from packaging.version import Version
Expand Down Expand Up @@ -560,11 +560,20 @@ def updateText(self):

class HeaderItem(TimeLineItem):
def __init__(self, name, sid):
"""
Dev note (buhtz, 2024-01-14): Parts of that code are redundant with
app.py::MainWindow.addPlace().
"""
super(HeaderItem, self).__init__()
self.setText(0, name)
self.setFont(0, fontBold(self.font(0)))
self.setBackground(0, QColor(196, 196, 196))
self.setForeground(0, QColor(60, 60, 60))

palette = QApplication.instance().palette()
self.setForeground(
0, palette.color(QPalette.ColorRole.PlaceholderText))
self.setBackground(
0, palette.color(QPalette.ColorRole.Window))

self.setFlags(Qt.ItemFlag.NoItemFlags)

self.setData(0, Qt.ItemDataRole.UserRole, sid)
Expand Down

0 comments on commit ff294f7

Please sign in to comment.