414ff5db1c
* Remove --medium-border variable * Implement color palette using Sass maps I hand-picked the gray tones, the other colors are from the Tailwind CSS v3 palette. Significant changes: - light theme is brighter - dark theme is darker - borders are softer I also deleted some platform- and night-mode-specific code. * Use custom colors for note view switch * Use same placeholder color for all inputs * Skew color palette for more dark values by removing gray[3], which wasn't used anywhere. Slight adjustments were made to the darker tones. * Adjust frame- window- and border colors * Give deck browser entries --frame-bg as background color * Define styling for QComboBox and QLineEdit globally * Experiment with CSS filter for inline-colors Inside darker inputs, some colors like dark blue will be hard to read, so we could try to improve text-color contrast with global adjustments depending on the theme. * Use different map structure for _vars.scss after @hgiesel's idea: https://github.com/ankitects/anki/pull/2016#discussion_r947087871 * Move custom QLineEdit styles out of searchbar.py * Merge branch 'main' into color-palette * Revert QComboBox stylesheet override * Align gray color palette more with macOS * Adjust light theme * Add custom styling for Qt controls * Use --slightly-grey-text for options tab color * Replace gray tones with more neutral values * Improve categorization of global colors by renaming almost all of them and sorting them into separate maps. * Saturate highlight-bg in light theme * Tweak gray tones * Adjust box-shadow of EditingArea to make fields look inset * Add Sass functions to access color palette and semantic variables in response to https://github.com/ankitects/anki/pull/2016#issuecomment-1220571076 * Showcase use of access functions in several locations @hgiesel in buttons.scss I access the color palette directly. Is this what you meant by "... keep it local to the component, and possibly make it global at a later time ..."? * Fix focus box shadow transition and remove default shadow for a cleaner look I couldn't quite get the inset look the way I wanted, because inset box-shadows do not respect the border radius, therefore causing aliasing. * Tweak light theme border and shadow colors * Add functions and colors to base_lib * Add vars_lib as dependency to base_lib and button_mixins_lib * Improve uses of default-themed variables * Use old --frame-bg color and use darker tone for canvas-default * Return CSS var by default and add palette-of function for raw value * Showcase use of palette-of function The #{...} syntax is required only because the use cases are CSS var definitions. In other cases a simple palette-of(keyword, theme) would suffice. * Light theme: decrease brightness of canvas-default and adjust fg-default * Use canvas-inset variable for switch knob * Adjust light theme * Add back box-shadow to EditingArea * Light theme: darken background and flatten transition also set hue and saturation of gray-8 to 0 (like all the other grays). * Reduce flag colors to single default value * Tweak card/note accent colors * Experiment with inset look for fields again Is this too dark in night mode? It's the same color used for all other text inputs. * Dark theme: make border-default one shade darker * Tweak inset shadow color * Dark theme: make border-faint darker than canvas-default meaning two shades darker than it currently was. * Fix PlainTextInput not expanding * Dark theme: use less saturated flag colors * Adjust gray tones * Create stylesheet overrides for various Qt widgets Including QPushButton, QComboBox, QSpinBox, QLineEdit, QListWidget, QTabWidget, QTreeWidget, QToolTip, QTableView, QScrollBar and sub-widgets. * Make webview scrollbar look identical to Qt one * Add blue colors for primary buttons * Tweak disabled state of SpinBox button * Apply styles to all platforms mainly so people like @hgiesel can easily test the widget style overrides, but maybe you actually prefer them over the native ones, who knows :) * Tweak webview button borders * Add type annotations to eventFilter * Adjust padding of QComboBox and its drop-down arrow * Use isinstance for comparison * Remove reimport of Any * Revert "Merge branch 'redesign-test' into custom-qt-controls" This reverts commit ff36297456b693a0d4b4b69f5f487ac1a01c1861, reversing changes made to 6bb45355d143aa081d2d643933bd02ddc43206de. * Add missing copyright header * Left-align QTabWidget headers * Exclude macOS from stylesheet overrides * Fix failure to start on macOS (dae) * Use standard macOS theme in dark mode (dae) I believe this was originally behind a feature flag because the user had to use a hack to get it to work (https://forums.ankiweb.net/t/title-bar-dark-mode-fix-broken/1189), and it did not work correctly when the system theme was changed. Since the introduction of libankihelper and the app automatically updating as the system theme changes, these issues no longer seem to exist, and switching between light and dark appears to work consistently. Pushed into this PR because it addresses the background color issue mentioned in code review. Closes #2054
400 lines
10 KiB
Python
400 lines
10 KiB
Python
# Copyright: Ankitects Pty Ltd and contributors
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
from aqt import colors
|
|
from aqt.theme import ThemeManager
|
|
|
|
|
|
def general_styles(tm: ThemeManager, buf: str) -> str:
|
|
buf += f"""
|
|
QFrame {{
|
|
background: none;
|
|
}}
|
|
QPushButton,
|
|
QComboBox,
|
|
QSpinBox,
|
|
QLineEdit,
|
|
QListWidget,
|
|
QTreeWidget,
|
|
QListView {{
|
|
border: 1px solid {tm.color(colors.BORDER)};
|
|
border-radius: 5px;
|
|
}}
|
|
QLineEdit {{
|
|
padding: 2px;
|
|
}}
|
|
QLineEdit:focus {{
|
|
border-color: {tm.color(colors.FOCUS_BORDER)};
|
|
}}
|
|
QPushButton {{
|
|
margin-top: 1px;
|
|
}}
|
|
QPushButton,
|
|
QComboBox,
|
|
QSpinBox {{
|
|
padding: 2px 6px;
|
|
}}
|
|
QToolTip {{
|
|
background: {tm.color(colors.TOOLTIP_BG)};
|
|
}}
|
|
"""
|
|
return buf
|
|
|
|
|
|
def button_styles(tm: ThemeManager, buf: str) -> str:
|
|
buf += f"""
|
|
QPushButton,
|
|
QComboBox:!editable {{
|
|
background: qlineargradient(
|
|
spread:pad, x1:0.5, y1:0, x2:0.5, y2:1,
|
|
stop:0 {tm.color(colors.BUTTON_GRADIENT_START)},
|
|
stop:1 {tm.color(colors.BUTTON_GRADIENT_END)}
|
|
);
|
|
|
|
}}
|
|
QPushButton:hover,
|
|
QComboBox:!editable:hover {{
|
|
background: qlineargradient(
|
|
spread:pad, x1:0.5, y1:0, x2:0.5, y2:1.25,
|
|
stop:0 {tm.color(colors.BUTTON_HOVER_GRADIENT_START)},
|
|
stop:1 {tm.color(colors.BUTTON_HOVER_GRADIENT_END)}
|
|
);
|
|
}}
|
|
QPushButton:pressed,
|
|
QComboBox:!editable:pressed {{
|
|
border: 1px solid {tm.color(colors.BUTTON_PRESSED_BORDER)};
|
|
background: qlineargradient(
|
|
spread:pad, x1:0.5, y1:0, x2:0.5, y2:1,
|
|
stop:0 {tm.color(colors.BUTTON_PRESSED_SHADOW)},
|
|
stop:0.1 {tm.color(colors.BUTTON_GRADIENT_START)},
|
|
stop:0.9 {tm.color(colors.BUTTON_GRADIENT_END)},
|
|
stop:1 {tm.color(colors.BUTTON_PRESSED_SHADOW)},
|
|
);
|
|
}}
|
|
"""
|
|
return buf
|
|
|
|
|
|
def combobox_styles(tm: ThemeManager, buf: str) -> str:
|
|
buf += f"""
|
|
QComboBox {{
|
|
padding: 1px 4px 2px 6px;
|
|
}}
|
|
QComboBox:editable:on,
|
|
QComboBox:editable:focus,
|
|
QComboBox::drop-down:focus:editable,
|
|
QComboBox::drop-down:pressed {{
|
|
border-color: {tm.color(colors.FOCUS_BORDER)};
|
|
}}
|
|
QComboBox:on {{
|
|
border-bottom: none;
|
|
border-bottom-right-radius: 0;
|
|
border-bottom-left-radius: 0;
|
|
}}
|
|
QComboBox::item {{
|
|
color: {tm.color(colors.TEXT_FG)};
|
|
background: {tm.color(colors.FRAME_BG)};
|
|
}}
|
|
|
|
QComboBox::item:selected {{
|
|
background: {tm.color(colors.HIGHLIGHT_BG)};
|
|
color: {tm.color(colors.HIGHLIGHT_FG)};
|
|
}}
|
|
QComboBox::item::icon:selected {{
|
|
position: absolute;
|
|
}}
|
|
QComboBox::drop-down {{
|
|
margin: -1px;
|
|
subcontrol-origin: padding;
|
|
padding: 2px;
|
|
width: 16px;
|
|
subcontrol-position: top right;
|
|
border: 1px solid {tm.color(colors.BUTTON_BORDER)};
|
|
border-top-right-radius: 5px;
|
|
border-bottom-right-radius: 5px;
|
|
}}
|
|
QComboBox::down-arrow {{
|
|
image: url(icons:chevron-down.svg);
|
|
}}
|
|
QComboBox::drop-down {{
|
|
background: qlineargradient(
|
|
spread:pad, x1:0.5, y1:0, x2:0.5, y2:1,
|
|
stop:0 {tm.color(colors.BUTTON_PRIMARY_GRADIENT_START)},
|
|
stop:1 {tm.color(colors.BUTTON_PRIMARY_GRADIENT_END)}
|
|
);
|
|
}}
|
|
QComboBox::drop-down:hover {{
|
|
background: qlineargradient(
|
|
spread:pad, x1:0.5, y1:0, x2:0.5, y2:1.25,
|
|
stop:0 {tm.color(colors.BUTTON_PRIMARY_HOVER_GRADIENT_START)},
|
|
stop:1 {tm.color(colors.BUTTON_PRIMARY_HOVER_GRADIENT_END)}
|
|
);
|
|
}}
|
|
"""
|
|
return buf
|
|
|
|
|
|
def tabwidget_styles(tm: ThemeManager, buf: str) -> str:
|
|
buf += f"""
|
|
QTabWidget {{
|
|
border-radius: 5px;
|
|
border: none;
|
|
background: none;
|
|
}}
|
|
QTabWidget::pane {{
|
|
border: 1px solid {tm.color(colors.FRAME_BG)};
|
|
border-radius: 5px;
|
|
background: {tm.color(colors.FRAME_BG)};
|
|
}}
|
|
QTabBar::tab {{
|
|
background: none;
|
|
border-top-left-radius: 5px;
|
|
border-top-right-radius: 5px;
|
|
padding: 5px 10px;
|
|
margin-bottom: 0px;
|
|
}}
|
|
QTabBar::tab:!selected:hover,
|
|
QTabBar::tab:selected {{
|
|
background: {tm.color(colors.FRAME_BG)};
|
|
}}
|
|
QTabBar::tab:selected {{
|
|
margin-bottom: -1px;
|
|
}}
|
|
QTabBar::tab:!selected {{
|
|
margin-top: 5px;
|
|
background: {tm.color(colors.WINDOW_BG)};
|
|
}}
|
|
QTabBar::tab {{
|
|
min-width: 8ex;
|
|
padding: 5px 10px 5px 10px;
|
|
}}
|
|
QTabBar::tab:selected {{
|
|
border-bottom-color: none;
|
|
}}
|
|
QTabBar::tab:bottom:selected {{
|
|
border-top-color: none;
|
|
}}
|
|
QTabBar::tab:previous-selected {{
|
|
border-top-left-radius: 0;
|
|
}}
|
|
QTabBar::tab:next-selected {{
|
|
border-top-right-radius: 0;
|
|
}}
|
|
"""
|
|
return buf
|
|
|
|
|
|
def table_styles(tm: ThemeManager, buf: str) -> str:
|
|
buf += f"""
|
|
QTableView {{
|
|
margin: -1px -1px 1px -1px;
|
|
background: none;
|
|
border: 2px solid {tm.color(colors.WINDOW_BG)};
|
|
border-radius: 5px;
|
|
}}
|
|
QHeaderView::section {{
|
|
border: 2px solid {tm.color(colors.WINDOW_BG)};
|
|
margin: -1px;
|
|
background: qlineargradient(
|
|
spread:pad, x1:0.5, y1:0, x2:0.5, y2:1,
|
|
stop:0 {tm.color(colors.BUTTON_GRADIENT_START)},
|
|
stop:1 {tm.color(colors.BUTTON_GRADIENT_END)}
|
|
);
|
|
}}
|
|
QHeaderView::section:pressed {{
|
|
border: 1px solid {tm.color(colors.BUTTON_PRESSED_BORDER)};
|
|
background: qlineargradient(
|
|
spread:pad, x1:0.5, y1:0, x2:0.5, y2:1,
|
|
stop:0 {tm.color(colors.BUTTON_PRESSED_SHADOW)},
|
|
stop:0.1 {tm.color(colors.BUTTON_GRADIENT_START)},
|
|
stop:0.9 {tm.color(colors.BUTTON_GRADIENT_END)},
|
|
stop:1 {tm.color(colors.BUTTON_PRESSED_SHADOW)},
|
|
);
|
|
}}
|
|
QHeaderView::section:hover {{
|
|
background: qlineargradient(
|
|
spread:pad, x1:0.5, y1:0, x2:0.5, y2:1.25,
|
|
stop:0 {tm.color(colors.BUTTON_HOVER_GRADIENT_START)},
|
|
stop:1 {tm.color(colors.BUTTON_HOVER_GRADIENT_END)}
|
|
);
|
|
}}
|
|
QHeaderView::section:first {{
|
|
border-top: 2px solid {tm.color(colors.WINDOW_BG)};
|
|
border-left: 2px solid {tm.color(colors.WINDOW_BG)};
|
|
border-top-left-radius: 5px;
|
|
}}
|
|
QHeaderView::section:!first {{
|
|
border-left: none;
|
|
}}
|
|
QHeaderView::section:last {{
|
|
border-top: 2px solid {tm.color(colors.WINDOW_BG)};
|
|
border-right: 2px solid {tm.color(colors.WINDOW_BG)};
|
|
border-top-right-radius: 5px;
|
|
}}
|
|
QHeaderView::section:next-selected {{
|
|
border-right: none;
|
|
}}
|
|
QHeaderView::section:previous-selected {{
|
|
border-left: none;
|
|
}}
|
|
QHeaderView::section:only-one {{
|
|
border-left: 2px solid {tm.color(colors.WINDOW_BG)};
|
|
border-top: 2px solid {tm.color(colors.WINDOW_BG)};
|
|
border-right: 2px solid {tm.color(colors.WINDOW_BG)};
|
|
border-top-left-radius: 5px;
|
|
border-top-right-radius: 5px;
|
|
}}
|
|
QHeaderView::up-arrow,
|
|
QHeaderView::down-arrow {{
|
|
width: 20px;
|
|
height: 20px;
|
|
}}
|
|
QHeaderView::up-arrow {{
|
|
image: url(icons:menu-up.svg);
|
|
}}
|
|
QHeaderView::down-arrow {{
|
|
image: url(icons:menu-down.svg);
|
|
}}
|
|
"""
|
|
return buf
|
|
|
|
|
|
def spinbox_styles(tm: ThemeManager, buf: str) -> str:
|
|
buf += f"""
|
|
QSpinBox::up-button,
|
|
QSpinBox::down-button {{
|
|
subcontrol-origin: border;
|
|
width: 16px;
|
|
border: 1px solid {tm.color(colors.BUTTON_BORDER)};
|
|
background: qlineargradient(
|
|
spread:pad, x1:0.5, y1:0, x2:0.5, y2:1,
|
|
stop:0 {tm.color(colors.BUTTON_PRIMARY_GRADIENT_START)},
|
|
stop:1 {tm.color(colors.BUTTON_PRIMARY_GRADIENT_END)}
|
|
);
|
|
}}
|
|
QSpinBox::up-button:pressed,
|
|
QSpinBox::down-button:pressed {{
|
|
border: 1px solid {tm.color(colors.BUTTON_PRESSED_BORDER)};
|
|
background: qlineargradient(
|
|
spread:pad, x1:0.5, y1:0, x2:0.5, y2:1,
|
|
stop:0 {tm.color(colors.BUTTON_PRESSED_SHADOW)},
|
|
stop:0.1 {tm.color(colors.BUTTON_PRIMARY_GRADIENT_START)},
|
|
stop:0.9 {tm.color(colors.BUTTON_PRIMARY_GRADIENT_END)},
|
|
stop:1 {tm.color(colors.BUTTON_PRESSED_SHADOW)},
|
|
);
|
|
}}
|
|
QSpinBox::up-button:hover,
|
|
QSpinBox::down-button:hover {{
|
|
background: qlineargradient(
|
|
spread:pad, x1:0.5, y1:0, x2:0.5, y2:1.25,
|
|
stop:0 {tm.color(colors.BUTTON_PRIMARY_HOVER_GRADIENT_START)},
|
|
stop:1 {tm.color(colors.BUTTON_PRIMARY_HOVER_GRADIENT_END)}
|
|
);
|
|
}}
|
|
QSpinBox::up-button {{
|
|
margin-bottom: -1px;
|
|
subcontrol-position: top right;
|
|
border-top-right-radius: 5px;
|
|
}}
|
|
QSpinBox::down-button {{
|
|
margin-top: -1px;
|
|
subcontrol-position: bottom right;
|
|
border-bottom-right-radius: 5px;
|
|
}}
|
|
QSpinBox::up-arrow {{
|
|
image: url(icons:chevron-up.svg);
|
|
}}
|
|
QSpinBox::down-arrow {{
|
|
image: url(icons:chevron-down.svg);
|
|
}}
|
|
QSpinBox::up-arrow,
|
|
QSpinBox::down-arrow,
|
|
QSpinBox::up-arrow:pressed,
|
|
QSpinBox::down-arrow:pressed,
|
|
QSpinBox::up-arrow:disabled:hover, QSpinBox::up-arrow:off:hover,
|
|
QSpinBox::down-arrow:disabled:hover, QSpinBox::down-arrow:off:hover {{
|
|
width: 16px;
|
|
height: 16px;
|
|
}}
|
|
QSpinBox::up-arrow:hover,
|
|
QSpinBox::down-arrow:hover {{
|
|
width: 20px;
|
|
height: 20px;
|
|
}}
|
|
QSpinBox::up-button:disabled, QSpinBox::up-button:off,
|
|
QSpinBox::down-button:disabled, QSpinBox::down-button:off {{
|
|
background: {tm.color(colors.BUTTON_PRIMARY_DISABLED)};
|
|
}}
|
|
"""
|
|
return buf
|
|
|
|
|
|
def scrollbar_styles(tm: ThemeManager, buf: str) -> str:
|
|
buf += f"""
|
|
QAbstractScrollArea::corner {{
|
|
background: none;
|
|
border: none;
|
|
}}
|
|
QScrollBar {{
|
|
background-color: {tm.color(colors.WINDOW_BG)};
|
|
}}
|
|
QScrollBar::handle {{
|
|
border-radius: 5px;
|
|
background-color: {tm.color(colors.SCROLLBAR_BG)};
|
|
}}
|
|
QScrollBar::handle:hover {{
|
|
background-color: {tm.color(colors.SCROLLBAR_HOVER_BG)};
|
|
}}
|
|
QScrollBar::handle:pressed {{
|
|
background-color: {tm.color(colors.SCROLLBAR_ACTIVE_BG)};
|
|
}}
|
|
QScrollBar:horizontal {{
|
|
height: 12px;
|
|
}}
|
|
QScrollBar::handle:horizontal {{
|
|
min-width: 50px;
|
|
}}
|
|
QScrollBar:vertical {{
|
|
width: 12px;
|
|
}}
|
|
QScrollBar::handle:vertical {{
|
|
min-height: 50px;
|
|
}}
|
|
QScrollBar::add-line {{
|
|
border: none;
|
|
background: none;
|
|
}}
|
|
QScrollBar::sub-line {{
|
|
border: none;
|
|
background: none;
|
|
}}
|
|
"""
|
|
return buf
|
|
|
|
|
|
def win10_styles(tm: ThemeManager, buf: str) -> str:
|
|
|
|
# day mode is missing a bottom border; background must be
|
|
# also set for border to apply
|
|
buf += f"""
|
|
QMenuBar {{
|
|
border-bottom: 1px solid {tm.color(colors.BORDER)};
|
|
background: {tm.color(colors.WINDOW_BG) if tm.night_mode else "white"};
|
|
}}
|
|
"""
|
|
|
|
# qt bug? setting the above changes the browser sidebar
|
|
# to white as well, so set it back
|
|
buf += f"""
|
|
QTreeWidget {{
|
|
background: {tm.color(colors.WINDOW_BG)};
|
|
}}
|
|
"""
|
|
|
|
if tm.night_mode:
|
|
buf += """
|
|
QToolTip {
|
|
border: 0;
|
|
}
|
|
"""
|
|
return buf
|