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 <KWindowSystem> | 26 | #include <KWindowSystem> | ||
27 | 27 | | |||
28 | #include <QApplication> | 28 | #include <QApplication> | ||
29 | #include <QPainter> | 29 | #include <QPainter> | ||
30 | #include <QMenuBar> | ||||
31 | #include <QToolBar> | ||||
32 | #include <QMainWindow> | ||||
33 | #include <QScreen> | ||||
hpereiradacosta: This include is not needed any more as far as I can tell | |||||
30 | 34 | | |||
31 | #if BREEZE_HAVE_X11 | 35 | #if BREEZE_HAVE_X11 | ||
32 | #include <QX11Info> | 36 | #include <QX11Info> | ||
33 | #endif | 37 | #endif | ||
34 | 38 | | |||
35 | #include <algorithm> | 39 | #include <algorithm> | ||
36 | 40 | | |||
37 | namespace Breeze | 41 | namespace Breeze | ||
38 | { | 42 | { | ||
39 | 43 | | |||
40 | //* contrast for arrow and treeline rendering | 44 | //* contrast for arrow and treeline rendering | ||
41 | static const qreal arrowShade = 0.15; | 45 | static const qreal arrowShade = 0.15; | ||
42 | 46 | | |||
43 | //____________________________________________________________________ | 47 | //____________________________________________________________________ | ||
44 | Helper::Helper( KSharedConfig::Ptr config ): | 48 | Helper::Helper( KSharedConfig::Ptr config ): | ||
45 | _config( std::move( config ) ) | 49 | _config( std::move( config ) ) | ||
46 | {} | 50 | {} | ||
47 | 51 | | |||
48 | //____________________________________________________________________ | 52 | //____________________________________________________________________ | ||
hpereiradacosta: compiler complains about wrong initialization order | |||||
49 | KSharedConfig::Ptr Helper::config() const | 53 | KSharedConfig::Ptr Helper::config() const | ||
50 | { return _config; } | 54 | { return _config; } | ||
51 | 55 | | |||
52 | //____________________________________________________________________ | 56 | //____________________________________________________________________ | ||
53 | void Helper::loadConfig() | 57 | void Helper::loadConfig() | ||
54 | { | 58 | { | ||
55 | _viewFocusBrush = KStatefulBrush( KColorScheme::View, KColorScheme::FocusColor ); | 59 | _viewFocusBrush = KStatefulBrush( KColorScheme::View, KColorScheme::FocusColor ); | ||
56 | _viewHoverBrush = KStatefulBrush( KColorScheme::View, KColorScheme::HoverColor ); | 60 | _viewHoverBrush = KStatefulBrush( KColorScheme::View, KColorScheme::HoverColor ); | ||
57 | _viewNegativeTextBrush = KStatefulBrush( KColorScheme::View, KColorScheme::NegativeText ); | 61 | _viewNegativeTextBrush = KStatefulBrush( KColorScheme::View, KColorScheme::NegativeText ); | ||
58 | 62 | | |||
59 | const QPalette palette( QApplication::palette() ); | 63 | const QPalette palette( QApplication::palette() ); | ||
60 | const KConfigGroup group( _config->group( "WM" ) ); | 64 | const KConfigGroup group( _config->group( "WM" ) ); | ||
61 | _activeTitleBarColor = group.readEntry( "activeBackground", palette.color( QPalette::Active, QPalette::Highlight ) ); | 65 | _activeTitleBarColor = group.readEntry( "activeBackground", palette.color( QPalette::Active, QPalette::Highlight ) ); | ||
62 | _activeTitleBarTextColor = group.readEntry( "activeForeground", palette.color( QPalette::Active, QPalette::HighlightedText ) ); | 66 | _activeTitleBarTextColor = group.readEntry( "activeForeground", palette.color( QPalette::Active, QPalette::HighlightedText ) ); | ||
63 | _inactiveTitleBarColor = group.readEntry( "inactiveBackground", palette.color( QPalette::Disabled, QPalette::Highlight ) ); | 67 | _inactiveTitleBarColor = group.readEntry( "inactiveBackground", palette.color( QPalette::Disabled, QPalette::Highlight ) ); | ||
64 | _inactiveTitleBarTextColor = group.readEntry( "inactiveForeground", palette.color( QPalette::Disabled, QPalette::HighlightedText ) ); | 68 | _inactiveTitleBarTextColor = group.readEntry( "inactiveForeground", palette.color( QPalette::Disabled, QPalette::HighlightedText ) ); | ||
65 | } | 69 | } | ||
66 | 70 | | |||
67 | //____________________________________________________________________ | 71 | //____________________________________________________________________ | ||
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 | |||||
68 | QColor Helper::frameOutlineColor( const QPalette& palette, bool mouseOver, bool hasFocus, qreal opacity, AnimationMode mode ) const | 72 | QColor Helper::frameOutlineColor( const QPalette& palette, bool mouseOver, bool hasFocus, qreal opacity, AnimationMode mode ) const | ||
69 | { | 73 | { | ||
70 | 74 | | |||
71 | QColor outline( KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.25 ) ); | 75 | QColor outline( KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.25 ) ); | ||
72 | 76 | | |||
73 | // focus takes precedence over hover | 77 | // focus takes precedence over hover | ||
74 | if( mode == AnimationFocus ) | 78 | if( mode == AnimationFocus ) | ||
75 | { | 79 | { | ||
▲ Show 20 Lines • Show All 1523 Lines • ▼ Show 20 Line(s) | 1331 | } | |||
1599 | } | 1603 | } | ||
1600 | 1604 | | |||
1601 | //______________________________________________________________________________________ | 1605 | //______________________________________________________________________________________ | ||
1602 | qreal Helper::devicePixelRatio( const QPixmap& pixmap ) const | 1606 | qreal Helper::devicePixelRatio( const QPixmap& pixmap ) const | ||
1603 | { | 1607 | { | ||
1604 | return pixmap.devicePixelRatio(); | 1608 | return pixmap.devicePixelRatio(); | ||
1605 | } | 1609 | } | ||
1606 | 1610 | | |||
1611 | bool Helper::isInToolsArea(const QWidget* widget) const | ||||
1612 | { | ||||
1613 | if (shouldDrawToolsArea(widget)) return false; | ||||
1614 | | ||||
1615 | auto castedWidget = const_cast<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… | |||||
1616 | | ||||
1617 | auto grabMainWindow = [](QWidget *widget) { | ||||
1618 | auto window = qobject_cast<QMainWindow*>(widget->window()); | ||||
1619 | return window; | ||||
1620 | }; | ||||
1621 | auto checkToolbarInToolsArea = [grabMainWindow](QWidget* widget) { | ||||
1622 | auto toolbar = qobject_cast<QToolBar*>(widget); | ||||
1623 | | ||||
1624 | if (toolbar == nullptr) { | ||||
1625 | return false; | ||||
1626 | } | ||||
Coding style: hpereiradacosta: Coding style:
I would rather:
auto window = grabMainWindow( widget );
if( window ) …
This way… | |||||
1627 | | ||||
1628 | QMainWindow* window; | ||||
1629 | if (window = grabMainWindow(widget)) { | ||||
1630 | if (window->toolBarArea(toolbar) != Qt::TopToolBarArea) { | ||||
1631 | return false; | ||||
1632 | } | ||||
1633 | if (window->width() != toolbar->width()) { | ||||
1634 | return false; | ||||
1635 | } | ||||
1636 | } | ||||
1637 | | ||||
1638 | return true; | ||||
1639 | }; | ||||
hpereiradacosta: Same remark. | |||||
1640 | auto checkMenubarInToolsArea = [grabMainWindow](QWidget *widget) { | ||||
1641 | QMainWindow* window; | ||||
1642 | if (window = grabMainWindow(widget)) { | ||||
1643 | if (window->menuWidget() == widget) { | ||||
1644 | return true; | ||||
1645 | } | ||||
1646 | } | ||||
1647 | | ||||
1648 | return false; | ||||
1649 | }; | ||||
1650 | | ||||
1651 | if (!widget->isVisible()) { | ||||
1652 | return false; | ||||
1653 | } | ||||
1654 | if (checkToolbarInToolsArea(castedWidget)) { | ||||
1655 | return true; | ||||
1656 | } else if (checkMenubarInToolsArea(castedWidget)) { | ||||
1657 | return true; | ||||
hpereiradacosta: mmm shouldn't you test on parent rather than widget here ? | |||||
1658 | } else { | ||||
1659 | auto parent = castedWidget->parentWidget(); | ||||
1660 | while (parent != nullptr) { | ||||
1661 | if (checkToolbarInToolsArea(parent)) { | ||||
1662 | return true; | ||||
1663 | } | ||||
1664 | if (checkMenubarInToolsArea(parent)) { | ||||
1665 | return true; | ||||
1666 | } | ||||
1667 | parent = parent->parentWidget(); | ||||
1668 | } | ||||
1669 | } | ||||
1670 | | ||||
1671 | return false; | ||||
1672 | } | ||||
1673 | | ||||
1674 | bool Helper::toolsAreaHasToolBar (const QWidget* widget) const { | ||||
1675 | if (shouldDrawToolsArea(widget)) return false; | ||||
1676 | | ||||
1677 | auto mainWindow = qobject_cast<QMainWindow*>(widget->window()); | ||||
1678 | if (mainWindow == nullptr) { | ||||
1679 | return false; | ||||
1680 | } | ||||
1681 | | ||||
1682 | QList<QToolBar*> widgets = mainWindow->findChildren<QToolBar*>(); | ||||
1683 | for (auto widget : widgets) { | ||||
1684 | return this->isInToolsArea(widget); | ||||
1685 | } | ||||
1686 | | ||||
1687 | return false; | ||||
1688 | } | ||||
1689 | | ||||
1690 | void Helper::renderToolsAreaBorder(QPainter* painter, const QWidget* widget) const { | ||||
1691 | if (shouldDrawToolsArea(widget)) return; | ||||
1692 | | ||||
1693 | QColor outline( KColorUtils::mix( widget->palette().color( QPalette::Window ), widget->palette().color( QPalette::WindowText ), 0.75 ) ); | ||||
1694 | | ||||
1695 | painter->setPen(QPen(outline, 1*widget->screen()->devicePixelRatio())); | ||||
1696 | painter->setBrush(Qt::NoBrush); | ||||
1697 | | ||||
1698 | painter->drawLine( | ||||
1699 | widget->rect().left() - 100, | ||||
1700 | widget->rect().bottom()+1, | ||||
1701 | widget->rect().right() + 100, | ||||
1702 | widget->rect().bottom()+1 | ||||
1703 | ); | ||||
1704 | } | ||||
1705 | | ||||
hpereiradacosta: this-> is not necessary. | |||||
1706 | QToolBar* Helper::grabToolBarForToolsArea(const QWidget *widget) const { | ||||
1707 | auto mainWindow = qobject_cast<QMainWindow*>(widget->window()); | ||||
1708 | if (mainWindow == nullptr) { | ||||
1709 | return nullptr; | ||||
1710 | } | ||||
1711 | | ||||
1712 | QList<QToolBar*> widgets = mainWindow->findChildren<QToolBar*>(); | ||||
1713 | for (auto widget : widgets) { | ||||
1714 | if (this->isInToolsArea(widget)) { | ||||
1715 | return widget; | ||||
1716 | } | ||||
1717 | } | ||||
1718 | | ||||
1719 | return nullptr; | ||||
1720 | } | ||||
1721 | | ||||
1722 | bool Helper::shouldDrawToolsArea(const QWidget* widget) const { | ||||
hpereiradacosta: remove the unnecessary QPen | |||||
1723 | return widget->palette().color(QPalette::Window) == this->titleBarColor(true); | ||||
1724 | } | ||||
1607 | } | 1725 | } | ||
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… | |||||
hpereiradacosta: this-> is not necessary | |||||
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… |
This include is not needed any more as far as I can tell