Changeset View
Standalone View
kstyle/breezehelper.cpp
Show All 21 Lines | |||||
22 | #include "breeze.h" | 22 | #include "breeze.h" | ||
23 | #include "breezestyleconfigdata.h" | 23 | #include "breezestyleconfigdata.h" | ||
24 | 24 | | |||
25 | #include <KColorUtils> | 25 | #include <KColorUtils> | ||
26 | #include <KIconLoader> | 26 | #include <KIconLoader> | ||
27 | #include <KWindowSystem> | 27 | #include <KWindowSystem> | ||
28 | 28 | | |||
29 | #include <QApplication> | 29 | #include <QApplication> | ||
30 | #include <QDBusConnection> | ||||
31 | #include <QFileInfo> | ||||
30 | #include <QPainter> | 32 | #include <QPainter> | ||
33 | #include <QMainWindow> | ||||
34 | #include <QMenuBar> | ||||
35 | #include <QMdiArea> | ||||
36 | #include <QDockWidget> | ||||
hpereiradacosta: This include is not needed any more as far as I can tell | |||||
37 | #include <QWindow> | ||||
31 | 38 | | |||
32 | #if BREEZE_HAVE_X11 | 39 | #if BREEZE_HAVE_X11 | ||
33 | #include <QX11Info> | 40 | #include <QX11Info> | ||
34 | #endif | 41 | #endif | ||
35 | 42 | | |||
36 | #include <algorithm> | 43 | #include <algorithm> | ||
37 | 44 | | |||
38 | namespace Breeze | 45 | namespace Breeze | ||
39 | { | 46 | { | ||
40 | 47 | | |||
41 | //* contrast for arrow and treeline rendering | 48 | //* contrast for arrow and treeline rendering | ||
42 | static const qreal arrowShade = 0.15; | 49 | static const qreal arrowShade = 0.15; | ||
43 | 50 | | |||
44 | //____________________________________________________________________ | 51 | //____________________________________________________________________ | ||
45 | Helper::Helper( KSharedConfig::Ptr config ): | 52 | Helper::Helper( KSharedConfig::Ptr config, QObject *parent ) : | ||
46 | _config( std::move( config ) ) | 53 | _config( std::move( config ) ), | ||
47 | {} | 54 | _kwinConfig( KSharedConfig::openConfig("kwinrc") ), | ||
hpereiradacosta: compiler complains about wrong initialization order | |||||
55 | _decorationConfig( new InternalSettings() ), | ||||
56 | QObject ( parent ) | ||||
57 | { | ||||
58 | if (qApp) { | ||||
59 | connect(qApp, &QApplication::paletteChanged, this, [=]() { | ||||
60 | if (qApp->property("KDE_COLOR_SCHEME_PATH").isValid()) { | ||||
61 | const auto path = qApp->property("KDE_COLOR_SCHEME_PATH").toString(); | ||||
62 | KConfig config(path, KConfig::SimpleConfig); | ||||
63 | KConfigGroup group( config.group("WM") ); | ||||
64 | const QPalette palette( QApplication::palette() ); | ||||
65 | _activeTitleBarColor = group.readEntry( "activeBackground", palette.color( QPalette::Active, QPalette::Highlight ) ); | ||||
66 | _activeTitleBarTextColor = group.readEntry( "activeForeground", palette.color( QPalette::Active, QPalette::HighlightedText ) ); | ||||
67 | _inactiveTitleBarColor = group.readEntry( "inactiveBackground", palette.color( QPalette::Disabled, QPalette::Highlight ) ); | ||||
68 | _inactiveTitleBarTextColor = group.readEntry( "inactiveForeground", palette.color( QPalette::Disabled, QPalette::HighlightedText ) ); | ||||
69 | } | ||||
70 | }); | ||||
71 | } | ||||
72 | } | ||||
48 | 73 | | |||
49 | //____________________________________________________________________ | 74 | //____________________________________________________________________ | ||
50 | KSharedConfig::Ptr Helper::config() const | 75 | KSharedConfig::Ptr Helper::config() const | ||
51 | { return _config; } | 76 | { return _config; } | ||
52 | 77 | | |||
78 | | ||||
79 | //____________________________________________________________________ | ||||
80 | QSharedPointer<InternalSettings> Helper::decorationConfig() const | ||||
81 | { return _decorationConfig; } | ||||
82 | | ||||
53 | //____________________________________________________________________ | 83 | //____________________________________________________________________ | ||
54 | void Helper::loadConfig() | 84 | void Helper::loadConfig() | ||
55 | { | 85 | { | ||
56 | _viewFocusBrush = KStatefulBrush( KColorScheme::View, KColorScheme::FocusColor ); | 86 | _viewFocusBrush = KStatefulBrush( KColorScheme::View, KColorScheme::FocusColor ); | ||
57 | _viewHoverBrush = KStatefulBrush( KColorScheme::View, KColorScheme::HoverColor ); | 87 | _viewHoverBrush = KStatefulBrush( KColorScheme::View, KColorScheme::HoverColor ); | ||
58 | _viewNegativeTextBrush = KStatefulBrush( KColorScheme::View, KColorScheme::NegativeText ); | 88 | _viewNegativeTextBrush = KStatefulBrush( KColorScheme::View, KColorScheme::NegativeText ); | ||
59 | 89 | | |||
60 | const QPalette palette( QApplication::palette() ); | 90 | const QPalette palette( QApplication::palette() ); | ||
61 | const KConfigGroup group( _config->group( "WM" ) ); | 91 | _config->reparseConfiguration(); | ||
62 | _activeTitleBarColor = group.readEntry( "activeBackground", palette.color( QPalette::Active, QPalette::Highlight ) ); | 92 | _kwinConfig->reparseConfiguration(); | ||
63 | _activeTitleBarTextColor = group.readEntry( "activeForeground", palette.color( QPalette::Active, QPalette::HighlightedText ) ); | 93 | _cachedAutoValid = false; | ||
64 | _inactiveTitleBarColor = group.readEntry( "inactiveBackground", palette.color( QPalette::Disabled, QPalette::Highlight ) ); | 94 | _decorationConfig->load(); | ||
I don't think you need such a big if. Loading a kconfig with empty string will load kdeglobals davidre: I don't think you need such a big if. Loading a kconfig with empty string will load kdeglobals | |||||
65 | _inactiveTitleBarTextColor = group.readEntry( "inactiveForeground", palette.color( QPalette::Disabled, QPalette::HighlightedText ) ); | 95 | KConfig config(qApp->property("KDE_COLOR_SCHEME_PATH").toString(), KConfig::SimpleConfig); | ||
96 | KConfigGroup appGroup( config.group("WM") ); | ||||
97 | KConfigGroup globalGroup( _config->group("WM") ); | ||||
98 | _activeTitleBarColor = appGroup.readEntry( "activeBackground", globalGroup.readEntry( "activeBackground", palette.color( QPalette::Active, QPalette::Highlight ) ) ); | ||||
99 | _activeTitleBarTextColor = appGroup.readEntry( "activeForeground", globalGroup.readEntry( "activeForeground", palette.color( QPalette::Active, QPalette::HighlightedText ) ) ); | ||||
100 | _inactiveTitleBarColor = appGroup.readEntry( "inactiveBackground", globalGroup.readEntry( "inactiveBackground", palette.color( QPalette::Disabled, QPalette::Highlight ) ) ); | ||||
101 | _inactiveTitleBarTextColor = appGroup.readEntry( "inactiveForeground", globalGroup.readEntry( "inactiveForeground", palette.color( QPalette::Disabled, QPalette::HighlightedText ) ) ); | ||||
66 | } | 102 | } | ||
67 | 103 | | |||
68 | //____________________________________________________________________ | 104 | //____________________________________________________________________ | ||
69 | QColor Helper::frameOutlineColor( const QPalette& palette, bool mouseOver, bool hasFocus, qreal opacity, AnimationMode mode ) const | 105 | QColor Helper::frameOutlineColor( const QPalette& palette, bool mouseOver, bool hasFocus, qreal opacity, AnimationMode mode ) const | ||
70 | { | 106 | { | ||
71 | 107 | | |||
72 | QColor outline( KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.25 ) ); | 108 | QColor outline( KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.25 ) ); | ||
73 | 109 | | |||
▲ Show 20 Lines • Show All 1521 Lines • ▼ Show 20 Line(s) | 1364 | } | |||
1595 | { | 1631 | { | ||
1596 | return pixmap.devicePixelRatio(); | 1632 | return pixmap.devicePixelRatio(); | ||
1597 | } | 1633 | } | ||
1598 | 1634 | | |||
1599 | QPixmap Helper::coloredIcon(const QIcon& icon, const QPalette& palette, const QSize &size, QIcon::Mode mode, QIcon::State state) | 1635 | QPixmap Helper::coloredIcon(const QIcon& icon, const QPalette& palette, const QSize &size, QIcon::Mode mode, QIcon::State state) | ||
1600 | { | 1636 | { | ||
1601 | const QPalette activePalette = KIconLoader::global()->customPalette(); | 1637 | const QPalette activePalette = KIconLoader::global()->customPalette(); | ||
1602 | const bool changePalette = activePalette != palette; | 1638 | const bool changePalette = activePalette != palette; | ||
1603 | if (changePalette) { | 1639 | if (changePalette) { | ||
as far as I can tell you do not need the const_cast. just check the relevant methods to take a const as input. hpereiradacosta: as far as I can tell you do not need the const_cast. just check the relevant methods to take a… | |||||
Not really done. The only place where you need the const_cast is in the window->toolbarArea part. I would do it there and there only. (line 1637) all the other call to toolbar-> work with a const. hpereiradacosta: Not really done. The only place where you need the const_cast is in the window->toolbarArea… | |||||
1604 | KIconLoader::global()->setCustomPalette(palette); | 1640 | KIconLoader::global()->setCustomPalette(palette); | ||
1605 | } | 1641 | } | ||
1606 | const QPixmap pixmap = icon.pixmap(size, mode, state); | 1642 | const QPixmap pixmap = icon.pixmap(size, mode, state); | ||
1607 | if (changePalette) { | 1643 | if (changePalette) { | ||
1608 | if (activePalette == QPalette()) { | 1644 | if (activePalette == QPalette()) { | ||
1609 | KIconLoader::global()->resetPalette(); | 1645 | KIconLoader::global()->resetPalette(); | ||
1610 | } else { | 1646 | } else { | ||
1611 | KIconLoader::global()->setCustomPalette(palette); | 1647 | KIconLoader::global()->setCustomPalette(palette); | ||
1612 | } | 1648 | } | ||
1613 | } | 1649 | } | ||
1614 | return pixmap; | 1650 | return pixmap; | ||
Coding style: hpereiradacosta: Coding style:
I would rather:
auto window = grabMainWindow( widget );
if( window ) …
This way… | |||||
1615 | } | 1651 | } | ||
1652 | | ||||
1653 | bool Helper::isInToolsArea(const QWidget* widget) const | ||||
1654 | { | ||||
1655 | if (!shouldDrawToolsArea(widget)) return false; | ||||
1656 | | ||||
1657 | auto grabMainWindow = [](const QWidget *widget) { | ||||
1658 | auto window = qobject_cast<QMainWindow*>(widget->window()); | ||||
1659 | return window; | ||||
1660 | }; | ||||
1661 | auto checkToolbarInToolsArea = [this, grabMainWindow](const QWidget* widget) { | ||||
1662 | auto toolbar = qobject_cast<const QToolBar*>(widget); | ||||
1663 | if (!toolbar) return false; | ||||
hpereiradacosta: Same remark. | |||||
1664 | | ||||
1665 | QMainWindow* window = grabMainWindow(widget); | ||||
1666 | if (window) { | ||||
1667 | auto rect = toolsAreaToolbarsRect(widget); | ||||
1668 | if (widget->parentWidget() != widget->window()) return false; | ||||
1669 | if (toolbar->isFloating()) return false; | ||||
1670 | if (toolbar->orientation() == Qt::Vertical) return false; | ||||
1671 | if (window->toolBarArea(const_cast<QToolBar*>(toolbar)) != Qt::TopToolBarArea) return false; | ||||
1672 | if (window->width() != rect.width()) return false; | ||||
1673 | } | ||||
1674 | | ||||
1675 | return true; | ||||
1676 | }; | ||||
1677 | auto checkMenubarInToolsArea = [grabMainWindow](const QWidget *widget) { | ||||
1678 | QMainWindow* window = grabMainWindow(widget); | ||||
1679 | if (window) { | ||||
1680 | if (window->menuWidget() == widget) { | ||||
1681 | return true; | ||||
hpereiradacosta: mmm shouldn't you test on parent rather than widget here ? | |||||
1682 | } | ||||
1683 | } | ||||
1684 | | ||||
1685 | return false; | ||||
1686 | }; | ||||
1687 | | ||||
1688 | if (!widget) return false; | ||||
1689 | | ||||
1690 | if (!widget->isVisible()) { | ||||
1691 | return false; | ||||
1692 | } | ||||
1693 | if (widget->window()->windowType() == Qt::Dialog) { | ||||
1694 | return false; | ||||
1695 | } | ||||
1696 | | ||||
1697 | auto parent = widget; | ||||
1698 | while (parent != nullptr) { | ||||
1699 | if (qobject_cast<const QMdiArea*>(parent) || qobject_cast<const QDockWidget*>(parent)) { | ||||
1700 | return false; | ||||
1701 | } | ||||
1702 | if (checkToolbarInToolsArea(parent)) { | ||||
1703 | return true; | ||||
1704 | } | ||||
1705 | if (checkMenubarInToolsArea(parent)) { | ||||
1706 | return true; | ||||
1707 | } | ||||
1708 | parent = parent->parentWidget(); | ||||
1709 | } | ||||
1710 | | ||||
1711 | return false; | ||||
1712 | } | ||||
1713 | | ||||
1714 | QRect Helper::toolsAreaToolbarsRect (const QWidget* widget) const { | ||||
1715 | auto window = qobject_cast<QMainWindow*>(widget->window()); | ||||
1716 | if (!window) return QRect(); | ||||
1717 | | ||||
1718 | auto handle = window->windowHandle(); | ||||
1719 | if (handle) { | ||||
1720 | if (_invalidateCachedRects) { | ||||
1721 | _cachedRects.clear(); | ||||
1722 | _invalidateCachedRects = false; | ||||
1723 | } | ||||
1724 | auto key = _cachedRects.constFind(handle); | ||||
1725 | if (key != _cachedRects.constEnd()) { | ||||
1726 | return *key; | ||||
1727 | } | ||||
1728 | } | ||||
1729 | | ||||
hpereiradacosta: this-> is not necessary. | |||||
1730 | QList<QToolBar*> widgets = window->findChildren<QToolBar*>(QString(), Qt::FindDirectChildrenOnly); | ||||
1731 | QRect rect = QRect(); | ||||
1732 | for (auto toolbar : widgets) { | ||||
1733 | auto isInSubWindow = false; | ||||
1734 | QWidget* parent = toolbar->parentWidget(); | ||||
1735 | while (parent != nullptr) { | ||||
1736 | if (qobject_cast<QMdiArea*>(parent) || qobject_cast<QDockWidget*>(parent)) { | ||||
1737 | isInSubWindow = true; | ||||
1738 | break; | ||||
1739 | } | ||||
1740 | parent = parent->parentWidget(); | ||||
1741 | } | ||||
1742 | if (!isInSubWindow) { | ||||
1743 | if (window->toolBarArea(toolbar) == Qt::TopToolBarArea) { | ||||
1744 | rect = rect.united(toolbar->geometry()); | ||||
1745 | } | ||||
1746 | } | ||||
hpereiradacosta: remove the unnecessary QPen | |||||
1747 | } | ||||
1748 | QList<QMenuBar*> menuWidgets = window->findChildren<QMenuBar*>(QString(), Qt::FindDirectChildrenOnly); | ||||
1749 | for (auto menubar : menuWidgets) { | ||||
No. Should be QPen( outline, 1) or just "outline" hpereiradacosta: No. Should be QPen( outline, 1) or just "outline"
DevicePixelRatio is handled by paint engine. | |||||
In testing, I found that this would remain 1 physical pixel regardless of scale factor. cblack: In testing, I found that this would remain 1 physical pixel regardless of scale factor. | |||||
Then shouldn't you divide device pixel ratio ? hpereiradacosta: Then shouldn't you divide device pixel ratio ?
Also, someone else should double check. To me… | |||||
Rereading. First ignore the comment above, I misunderstood your answer. hpereiradacosta: Rereading. First ignore the comment above, I misunderstood your answer.
What you meant is that… | |||||
1750 | rect = rect.united(menubar->geometry()); | ||||
1751 | } | ||||
1752 | | ||||
1753 | if (handle) { | ||||
1754 | _cachedRects.insert(handle, rect); | ||||
1755 | } | ||||
1756 | return rect; | ||||
1757 | } | ||||
1758 | | ||||
1759 | bool Helper::toolsAreaHasToolBar (const QWidget* widget) const { | ||||
1760 | if (!shouldDrawToolsArea(widget)) return false; | ||||
1761 | | ||||
1762 | auto mainWindow = qobject_cast<QMainWindow*>(widget->window()); | ||||
1763 | if (mainWindow == nullptr) { | ||||
1764 | return false; | ||||
1765 | } | ||||
1766 | | ||||
hpereiradacosta: this-> is not necessary | |||||
1767 | QList<QToolBar*> widgets = mainWindow->findChildren<QToolBar*>(QString(), Qt::FindDirectChildrenOnly); | ||||
1768 | for (auto widget : widgets) { | ||||
1769 | if (isInToolsArea(widget) == true) { | ||||
1770 | return true; | ||||
1771 | } | ||||
1772 | } | ||||
1773 | | ||||
1774 | return false; | ||||
1775 | } | ||||
1776 | | ||||
1777 | QToolBar* Helper::grabToolBarForToolsArea(const QWidget *widget) const { | ||||
1778 | auto mainWindow = qobject_cast<QMainWindow*>(widget->window()); | ||||
This check is the problem. If "Use Theme's default border size" is checked (the default) then no entry will be written in the config file because the defaults are used. This is for`BorderSizeAuto` "true" and for BorderSize "Normal" (Note however that because of the the BorderSizeAuto the default borders of the deco are used and not normal sized borders) davidre: This check is the problem. If "Use Theme's default border size" is checked (the default) then… | |||||
1779 | if (mainWindow == nullptr) { | ||||
1780 | return nullptr; | ||||
1781 | } | ||||
1782 | | ||||
1783 | QList<QToolBar*> widgets = mainWindow->findChildren<QToolBar*>(QString(), Qt::FindDirectChildrenOnly); | ||||
1784 | for (auto widget : widgets) { | ||||
1785 | if (isInToolsArea(widget)) { | ||||
1786 | return widget; | ||||
1787 | } | ||||
1788 | } | ||||
1789 | | ||||
1790 | return nullptr; | ||||
1791 | } | ||||
1792 | | ||||
1793 | bool Helper::shouldDrawToolsArea(const QWidget* widget) const { | ||||
1794 | if (!widget) return false; | ||||
1795 | if (!_toolsAreaEnabled) return false; | ||||
1796 | static bool isAuto; | ||||
1797 | static QString borderSize; | ||||
1798 | if (!_cachedAutoValid) { | ||||
1799 | KConfigGroup kdecorationGroup(_kwinConfig->group("org.kde.kdecoration2")); | ||||
1800 | isAuto = kdecorationGroup.readEntry("BorderSizeAuto", true); | ||||
1801 | borderSize = kdecorationGroup.readEntry("BorderSize", "Normal"); | ||||
1802 | _cachedAutoValid = true; | ||||
1803 | } | ||||
1804 | if (isAuto) { | ||||
1805 | auto window = widget->window(); | ||||
1806 | if (window) { | ||||
1807 | auto handle = window->windowHandle(); | ||||
1808 | if (handle) { | ||||
1809 | if (handle->frameGeometry().width() != toolsAreaToolbarsRect(widget).width()) { | ||||
1810 | return false; | ||||
1811 | } else { | ||||
1812 | auto toolbar = qobject_cast<const QToolBar*>(widget); | ||||
1813 | if (toolbar) { | ||||
1814 | if (toolbar->isFloating()) { | ||||
1815 | return false; | ||||
1816 | } | ||||
1817 | } | ||||
1818 | return true; | ||||
1819 | } | ||||
1820 | } | ||||
1821 | } else { | ||||
1822 | return false; | ||||
1823 | } | ||||
1824 | } | ||||
1825 | if (borderSize != "None" && borderSize != "NoSides") { | ||||
1826 | return false; | ||||
1827 | } | ||||
1828 | auto toolbar = qobject_cast<const QToolBar*>(widget); | ||||
1829 | if (toolbar) { | ||||
1830 | if (toolbar->isFloating()) { | ||||
1831 | return false; | ||||
1832 | } | ||||
1833 | } | ||||
1834 | return true; | ||||
1835 | } | ||||
1836 | | ||||
1837 | bool Helper::toolsAreaHasContents(const QWidget* widget) const { | ||||
1838 | QList<QWidget*> widgets = widget->window()->findChildren<QWidget*>(QString(), Qt::FindDirectChildrenOnly); | ||||
1839 | for (auto widget : widgets) { | ||||
1840 | if (isInToolsArea(widget)) { | ||||
1841 | return true; | ||||
1842 | } | ||||
1843 | } | ||||
1844 | return false; | ||||
1845 | } | ||||
1846 | | ||||
1847 | QColor Helper::toolsAreaBorderColor(const QWidget* widget) const { | ||||
1848 | QColor border( | ||||
1849 | KColorUtils::mix( | ||||
1850 | titleBarColor(widget->isActiveWindow()), | ||||
1851 | titleBarTextColor(widget->isActiveWindow()), | ||||
1852 | 0.2 | ||||
1853 | ) | ||||
1854 | ); | ||||
1855 | border.setAlpha(255); | ||||
1856 | return border; | ||||
1857 | } | ||||
1616 | } | 1858 | } |
This include is not needed any more as far as I can tell