Changeset View
Standalone View
kstyle/breezehelper.cpp
Show All 20 Lines | |||||
21 | 21 | | |||
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 <KWindowSystem> | 26 | #include <KWindowSystem> | ||
27 | 27 | | |||
28 | #include <QApplication> | 28 | #include <QApplication> | ||
29 | #include <QFileInfo> | ||||
29 | #include <QPainter> | 30 | #include <QPainter> | ||
31 | #include <QMainWindow> | ||||
32 | #include <QMenuBar> | ||||
30 | 33 | | |||
31 | #if BREEZE_HAVE_X11 | 34 | #if BREEZE_HAVE_X11 | ||
hpereiradacosta: This include is not needed any more as far as I can tell | |||||
32 | #include <QX11Info> | 35 | #include <QX11Info> | ||
33 | #endif | 36 | #endif | ||
34 | 37 | | |||
35 | #include <algorithm> | 38 | #include <algorithm> | ||
36 | 39 | | |||
37 | namespace Breeze | 40 | namespace Breeze | ||
38 | { | 41 | { | ||
39 | 42 | | |||
40 | //* contrast for arrow and treeline rendering | 43 | //* contrast for arrow and treeline rendering | ||
41 | static const qreal arrowShade = 0.15; | 44 | static const qreal arrowShade = 0.15; | ||
42 | 45 | | |||
43 | //____________________________________________________________________ | 46 | //____________________________________________________________________ | ||
44 | Helper::Helper( KSharedConfig::Ptr config ): | 47 | Helper::Helper( KSharedConfig::Ptr config, QObject *parent ) : | ||
45 | _config( std::move( config ) ) | 48 | _config( std::move( config ) ), | ||
46 | {} | 49 | _decorationConfig( new InternalSettings() ), | ||
hpereiradacosta: compiler complains about wrong initialization order | |||||
50 | QObject ( parent ) | ||||
51 | { | ||||
52 | qDebug() << "helper construct"; | ||||
53 | if (qApp) { | ||||
54 | connect(qApp, &QApplication::paletteChanged, this, [=]() { | ||||
55 | if (qApp->property("KDE_COLOR_SCHEME_PATH").isValid()) { | ||||
56 | const auto path = qApp->property("KDE_COLOR_SCHEME_PATH").toString(); | ||||
57 | KConfig config(path, KConfig::SimpleConfig); | ||||
58 | KConfigGroup group( config.group("WM") ); | ||||
59 | const QPalette palette( QApplication::palette() ); | ||||
60 | _activeTitleBarColor = group.readEntry( "activeBackground", palette.color( QPalette::Active, QPalette::Highlight ) ); | ||||
61 | _activeTitleBarTextColor = group.readEntry( "activeForeground", palette.color( QPalette::Active, QPalette::HighlightedText ) ); | ||||
62 | _inactiveTitleBarColor = group.readEntry( "inactiveBackground", palette.color( QPalette::Disabled, QPalette::Highlight ) ); | ||||
63 | _inactiveTitleBarTextColor = group.readEntry( "inactiveForeground", palette.color( QPalette::Disabled, QPalette::HighlightedText ) ); | ||||
64 | } | ||||
65 | }); | ||||
66 | } | ||||
67 | qDebug() << "end"; | ||||
68 | } | ||||
47 | 69 | | |||
48 | //____________________________________________________________________ | 70 | //____________________________________________________________________ | ||
49 | KSharedConfig::Ptr Helper::config() const | 71 | KSharedConfig::Ptr Helper::config() const | ||
50 | { return _config; } | 72 | { return _config; } | ||
51 | 73 | | |||
74 | | ||||
75 | //____________________________________________________________________ | ||||
76 | QSharedPointer<InternalSettings> Helper::decorationConfig() const | ||||
77 | { return _decorationConfig; } | ||||
78 | | ||||
52 | //____________________________________________________________________ | 79 | //____________________________________________________________________ | ||
53 | void Helper::loadConfig() | 80 | void Helper::loadConfig() | ||
54 | { | 81 | { | ||
55 | _viewFocusBrush = KStatefulBrush( KColorScheme::View, KColorScheme::FocusColor ); | 82 | _viewFocusBrush = KStatefulBrush( KColorScheme::View, KColorScheme::FocusColor ); | ||
56 | _viewHoverBrush = KStatefulBrush( KColorScheme::View, KColorScheme::HoverColor ); | 83 | _viewHoverBrush = KStatefulBrush( KColorScheme::View, KColorScheme::HoverColor ); | ||
57 | _viewNegativeTextBrush = KStatefulBrush( KColorScheme::View, KColorScheme::NegativeText ); | 84 | _viewNegativeTextBrush = KStatefulBrush( KColorScheme::View, KColorScheme::NegativeText ); | ||
58 | 85 | | |||
59 | const QPalette palette( QApplication::palette() ); | 86 | const QPalette palette( QApplication::palette() ); | ||
87 | _config->reparseConfiguration(); | ||||
88 | _decorationConfig->load(); | ||||
89 | if (qApp && qApp->property("KDE_COLOR_SCHEME_PATH").isValid()) { | ||||
90 | const auto path = qApp->property("KDE_COLOR_SCHEME_PATH").toString(); | ||||
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 | |||||
91 | if (path.isEmpty() || !QFileInfo::exists(path)) goto otherIf; | ||||
92 | | ||||
93 | KConfig config(path, KConfig::SimpleConfig); | ||||
94 | KConfigGroup group( config.group("WM") ); | ||||
95 | _activeTitleBarColor = group.readEntry( "activeBackground", palette.color( QPalette::Active, QPalette::Highlight ) ); | ||||
96 | _activeTitleBarTextColor = group.readEntry( "activeForeground", palette.color( QPalette::Active, QPalette::HighlightedText ) ); | ||||
97 | _inactiveTitleBarColor = group.readEntry( "inactiveBackground", palette.color( QPalette::Disabled, QPalette::Highlight ) ); | ||||
98 | _inactiveTitleBarTextColor = group.readEntry( "inactiveForeground", palette.color( QPalette::Disabled, QPalette::HighlightedText ) ); | ||||
99 | } else { | ||||
100 | otherIf: | ||||
60 | const KConfigGroup group( _config->group( "WM" ) ); | 101 | const KConfigGroup group( _config->group( "WM" ) ); | ||
61 | _activeTitleBarColor = group.readEntry( "activeBackground", palette.color( QPalette::Active, QPalette::Highlight ) ); | 102 | _activeTitleBarColor = group.readEntry( "activeBackground", palette.color( QPalette::Active, QPalette::Highlight ) ); | ||
62 | _activeTitleBarTextColor = group.readEntry( "activeForeground", palette.color( QPalette::Active, QPalette::HighlightedText ) ); | 103 | _activeTitleBarTextColor = group.readEntry( "activeForeground", palette.color( QPalette::Active, QPalette::HighlightedText ) ); | ||
63 | _inactiveTitleBarColor = group.readEntry( "inactiveBackground", palette.color( QPalette::Disabled, QPalette::Highlight ) ); | 104 | _inactiveTitleBarColor = group.readEntry( "inactiveBackground", palette.color( QPalette::Disabled, QPalette::Highlight ) ); | ||
64 | _inactiveTitleBarTextColor = group.readEntry( "inactiveForeground", palette.color( QPalette::Disabled, QPalette::HighlightedText ) ); | 105 | _inactiveTitleBarTextColor = group.readEntry( "inactiveForeground", palette.color( QPalette::Disabled, QPalette::HighlightedText ) ); | ||
65 | } | 106 | } | ||
107 | } | ||||
66 | 108 | | |||
67 | //____________________________________________________________________ | 109 | //____________________________________________________________________ | ||
68 | QColor Helper::frameOutlineColor( const QPalette& palette, bool mouseOver, bool hasFocus, qreal opacity, AnimationMode mode ) const | 110 | QColor Helper::frameOutlineColor( const QPalette& palette, bool mouseOver, bool hasFocus, qreal opacity, AnimationMode mode ) const | ||
69 | { | 111 | { | ||
70 | 112 | | |||
71 | QColor outline( KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.25 ) ); | 113 | QColor outline( KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.25 ) ); | ||
72 | 114 | | |||
73 | // focus takes precedence over hover | 115 | // focus takes precedence over hover | ||
▲ Show 20 Lines • Show All 1525 Lines • ▼ Show 20 Line(s) | 1369 | } | |||
1599 | } | 1641 | } | ||
1600 | 1642 | | |||
1601 | //______________________________________________________________________________________ | 1643 | //______________________________________________________________________________________ | ||
1602 | qreal Helper::devicePixelRatio( const QPixmap& pixmap ) const | 1644 | qreal Helper::devicePixelRatio( const QPixmap& pixmap ) const | ||
1603 | { | 1645 | { | ||
1604 | return pixmap.devicePixelRatio(); | 1646 | return pixmap.devicePixelRatio(); | ||
1605 | } | 1647 | } | ||
1606 | 1648 | | |||
1649 | bool Helper::isInToolsArea(const QWidget* widget) const | ||||
1650 | { | ||||
1651 | if (!shouldDrawToolsArea(widget)) return false; | ||||
1652 | | ||||
1653 | auto grabMainWindow = [](const QWidget *widget) { | ||||
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… | |||||
1654 | auto window = qobject_cast<QMainWindow*>(widget->window()); | ||||
1655 | return window; | ||||
1656 | }; | ||||
1657 | auto checkToolbarInToolsArea = [this, grabMainWindow](const QWidget* widget) { | ||||
1658 | auto toolbar = qobject_cast<const QToolBar*>(widget); | ||||
1659 | if (!toolbar) return false; | ||||
1660 | | ||||
1661 | QMainWindow* window = grabMainWindow(widget); | ||||
1662 | if (window) { | ||||
1663 | auto rect = toolsAreaToolbarsRect(widget); | ||||
1664 | if (widget->parentWidget() != widget->window()) return false; | ||||
Coding style: hpereiradacosta: Coding style:
I would rather:
auto window = grabMainWindow( widget );
if( window ) …
This way… | |||||
1665 | if (toolbar->isFloating()) return false; | ||||
1666 | if (toolbar->orientation() == Qt::Vertical) return false; | ||||
1667 | if (window->toolBarArea(const_cast<QToolBar*>(toolbar)) != Qt::TopToolBarArea) return false; | ||||
1668 | if (window->width() != rect.width()) return false; | ||||
1669 | } | ||||
1670 | | ||||
1671 | return true; | ||||
1672 | }; | ||||
1673 | auto checkMenubarInToolsArea = [grabMainWindow](const QWidget *widget) { | ||||
1674 | QMainWindow* window = grabMainWindow(widget); | ||||
1675 | if (window) { | ||||
1676 | if (window->menuWidget() == widget) { | ||||
1677 | return true; | ||||
hpereiradacosta: Same remark. | |||||
1678 | } | ||||
1679 | } | ||||
1680 | | ||||
1681 | return false; | ||||
1682 | }; | ||||
1683 | | ||||
1684 | if (!widget) return false; | ||||
1685 | | ||||
1686 | if (!widget->isVisible()) { | ||||
1687 | return false; | ||||
1688 | } | ||||
1689 | if (widget->window()->windowType() == Qt::Dialog) { | ||||
1690 | return false; | ||||
1691 | } | ||||
1692 | | ||||
1693 | if (checkToolbarInToolsArea(widget)) { | ||||
1694 | return true; | ||||
1695 | } else if (checkMenubarInToolsArea(widget)) { | ||||
hpereiradacosta: mmm shouldn't you test on parent rather than widget here ? | |||||
1696 | return true; | ||||
1697 | } else { | ||||
1698 | auto parent = widget->parentWidget(); | ||||
1699 | while (parent != nullptr) { | ||||
1700 | if (checkToolbarInToolsArea(parent)) { | ||||
1701 | return true; | ||||
1702 | } | ||||
1703 | if (checkMenubarInToolsArea(parent)) { | ||||
1704 | return true; | ||||
1705 | } | ||||
1706 | parent = parent->parentWidget(); | ||||
1707 | } | ||||
1708 | } | ||||
1709 | | ||||
1710 | return false; | ||||
1711 | } | ||||
1712 | | ||||
1713 | QRect Helper::toolsAreaToolbarsRect (const QWidget* widget) const { | ||||
1714 | auto window = qobject_cast<QMainWindow*>(widget->window()); | ||||
1715 | if (!window) return QRect(); | ||||
1716 | | ||||
1717 | QList<QToolBar*> widgets = window->findChildren<QToolBar*>(QString(), Qt::FindDirectChildrenOnly); | ||||
1718 | QRect rect = QRect(); | ||||
1719 | for (auto toolbar : widgets) { | ||||
1720 | if (window->toolBarArea(toolbar) == Qt::TopToolBarArea) { | ||||
1721 | rect = rect.united(toolbar->geometry()); | ||||
1722 | } | ||||
1723 | } | ||||
1724 | QList<QMenuBar*> menuWidgets = window->findChildren<QMenuBar*>(QString(), Qt::FindDirectChildrenOnly); | ||||
1725 | for (auto menubar : menuWidgets) { | ||||
1726 | rect = rect.united(menubar->geometry()); | ||||
1727 | } | ||||
1728 | | ||||
1729 | return rect; | ||||
1730 | } | ||||
1731 | | ||||
1732 | bool Helper::toolsAreaHasToolBar (const QWidget* widget) const { | ||||
1733 | if (!shouldDrawToolsArea(widget)) return false; | ||||
1734 | | ||||
1735 | auto mainWindow = qobject_cast<QMainWindow*>(widget->window()); | ||||
1736 | if (mainWindow == nullptr) { | ||||
1737 | return false; | ||||
1738 | } | ||||
1739 | | ||||
1740 | QList<QToolBar*> widgets = mainWindow->findChildren<QToolBar*>(QString(), Qt::FindDirectChildrenOnly); | ||||
1741 | for (auto widget : widgets) { | ||||
1742 | if (isInToolsArea(widget) == true) { | ||||
1743 | return true; | ||||
hpereiradacosta: this-> is not necessary. | |||||
1744 | } | ||||
1745 | } | ||||
1746 | | ||||
1747 | return false; | ||||
1748 | } | ||||
1749 | | ||||
1750 | void Helper::renderToolsAreaBorder(QPainter* painter, const QWidget* widget, bool menubar) const { | ||||
1751 | if (!shouldDrawToolsArea(widget)) return; | ||||
1752 | | ||||
1753 | if (!menubar) { | ||||
1754 | auto rect = toolsAreaToolbarsRect(widget); | ||||
1755 | | ||||
1756 | if (rect.bottom() != widget->geometry().bottom()) return; | ||||
1757 | } | ||||
1758 | | ||||
1759 | painter->setPen(toolsAreaBorderColor(widget)); | ||||
1760 | painter->setRenderHints(QPainter::Antialiasing, false); | ||||
hpereiradacosta: remove the unnecessary QPen | |||||
1761 | painter->setBrush(Qt::NoBrush); | ||||
1762 | | ||||
1763 | painter->drawLine( | ||||
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… | |||||
1764 | widget->rect().left()*2, | ||||
1765 | widget->rect().bottom(), | ||||
1766 | widget->rect().right()*2, | ||||
1767 | widget->rect().bottom() | ||||
1768 | ); | ||||
1769 | } | ||||
1770 | | ||||
1771 | QToolBar* Helper::grabToolBarForToolsArea(const QWidget *widget) const { | ||||
1772 | auto mainWindow = qobject_cast<QMainWindow*>(widget->window()); | ||||
1773 | if (mainWindow == nullptr) { | ||||
1774 | return nullptr; | ||||
1775 | } | ||||
1776 | | ||||
1777 | QList<QToolBar*> widgets = mainWindow->findChildren<QToolBar*>(QString(), Qt::FindDirectChildrenOnly); | ||||
1778 | for (auto widget : widgets) { | ||||
1779 | if (isInToolsArea(widget)) { | ||||
1780 | return widget; | ||||
hpereiradacosta: this-> is not necessary | |||||
1781 | } | ||||
1782 | } | ||||
1783 | | ||||
1784 | return nullptr; | ||||
1785 | } | ||||
1786 | | ||||
1787 | bool Helper::shouldDrawToolsArea(const QWidget* widget) const { | ||||
1788 | if (!widget) return false; | ||||
1789 | auto toolbar = qobject_cast<const QToolBar*>(widget); | ||||
1790 | if (toolbar) { | ||||
1791 | if (toolbar->isFloating()) { | ||||
1792 | return false; | ||||
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… | |||||
1793 | } | ||||
1794 | } | ||||
1795 | return (widget->window()->palette().color(QPalette::Window) != titleBarColor(true)); | ||||
1796 | } | ||||
1797 | | ||||
1798 | bool Helper::toolsAreaHasContents(const QWidget* widget) const { | ||||
1799 | QList<QWidget*> widgets = widget->window()->findChildren<QWidget*>(); | ||||
1800 | for (auto widget : widgets) { | ||||
1801 | if (isInToolsArea(widget)) { | ||||
1802 | return true; | ||||
1803 | } | ||||
1804 | } | ||||
1805 | return false; | ||||
1806 | } | ||||
1807 | | ||||
1808 | QColor Helper::toolsAreaBorderColor(const QWidget* widget) const { | ||||
1809 | QColor border( | ||||
1810 | KColorUtils::mix( | ||||
1811 | titleBarColor(widget->isActiveWindow()), | ||||
1812 | titleBarTextColor(widget->isActiveWindow()), | ||||
1813 | 0.5 | ||||
1814 | ) | ||||
1815 | ); | ||||
1816 | border.setAlpha(255); | ||||
1817 | return border; | ||||
1818 | } | ||||
1607 | } | 1819 | } |
This include is not needed any more as far as I can tell