Changeset View
Standalone View
kstyle/breezestyle.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show All 25 Lines | |||||
26 | #include "breezemnemonics.h" | 26 | #include "breezemnemonics.h" | ||
27 | #include "breezepropertynames.h" | 27 | #include "breezepropertynames.h" | ||
28 | #include "breezeshadowhelper.h" | 28 | #include "breezeshadowhelper.h" | ||
29 | #include "breezesplitterproxy.h" | 29 | #include "breezesplitterproxy.h" | ||
30 | #include "breezestyleconfigdata.h" | 30 | #include "breezestyleconfigdata.h" | ||
31 | #include "breezewidgetexplorer.h" | 31 | #include "breezewidgetexplorer.h" | ||
32 | #include "breezewindowmanager.h" | 32 | #include "breezewindowmanager.h" | ||
33 | #include "breezeblurhelper.h" | 33 | #include "breezeblurhelper.h" | ||
34 | #include "breezetoolsareamanager.h" | ||||
34 | 35 | | |||
35 | #include <KColorUtils> | 36 | #include <KColorUtils> | ||
37 | #include <KIconLoader> | ||||
36 | 38 | | |||
37 | #include <QApplication> | 39 | #include <QApplication> | ||
40 | #include <QBitmap> | ||||
38 | #include <QCheckBox> | 41 | #include <QCheckBox> | ||
39 | #include <QComboBox> | 42 | #include <QComboBox> | ||
40 | #include <QDial> | 43 | #include <QDial> | ||
44 | #include <QDialog> | ||||
41 | #include <QDBusConnection> | 45 | #include <QDBusConnection> | ||
42 | #include <QDockWidget> | 46 | #include <QDockWidget> | ||
43 | #include <QFormLayout> | 47 | #include <QFormLayout> | ||
44 | #include <QGraphicsView> | 48 | #include <QGraphicsView> | ||
45 | #include <QGroupBox> | 49 | #include <QGroupBox> | ||
46 | #include <QLineEdit> | 50 | #include <QLineEdit> | ||
47 | #include <QMainWindow> | 51 | #include <QMainWindow> | ||
48 | #include <QMdiSubWindow> | 52 | #include <QMdiSubWindow> | ||
49 | #include <QMenu> | 53 | #include <QMenu> | ||
50 | #include <QPainter> | 54 | #include <QPainter> | ||
51 | #include <QPushButton> | 55 | #include <QPushButton> | ||
52 | #include <QRadioButton> | 56 | #include <QRadioButton> | ||
53 | #include <QScrollBar> | 57 | #include <QScrollBar> | ||
54 | #include <QItemDelegate> | 58 | #include <QItemDelegate> | ||
55 | #include <QSplitterHandle> | 59 | #include <QSplitterHandle> | ||
hpereiradacosta: Not needed | |||||
56 | #include <QTextEdit> | 60 | #include <QTextEdit> | ||
57 | #include <QToolBar> | 61 | #include <QToolBar> | ||
58 | #include <QToolBox> | 62 | #include <QToolBox> | ||
59 | #include <QToolButton> | 63 | #include <QToolButton> | ||
60 | #include <QTreeView> | 64 | #include <QTreeView> | ||
61 | #include <QWidgetAction> | 65 | #include <QWidgetAction> | ||
66 | #include <QMdiArea> | ||||
62 | 67 | | |||
63 | #if BREEZE_HAVE_QTQUICK | 68 | #if BREEZE_HAVE_QTQUICK | ||
64 | #include <QQuickWindow> | 69 | #include <QQuickWindow> | ||
65 | #endif | 70 | #endif | ||
66 | 71 | | |||
67 | namespace BreezePrivate | 72 | namespace BreezePrivate | ||
68 | { | 73 | { | ||
69 | 74 | | |||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 161 | Style::Style(): | |||
159 | , _shadowHelper( new ShadowHelper( this, *_helper ) ) | 164 | , _shadowHelper( new ShadowHelper( this, *_helper ) ) | ||
160 | , _animations( new Animations( this ) ) | 165 | , _animations( new Animations( this ) ) | ||
161 | , _mnemonics( new Mnemonics( this ) ) | 166 | , _mnemonics( new Mnemonics( this ) ) | ||
162 | , _blurHelper( new BlurHelper( this ) ) | 167 | , _blurHelper( new BlurHelper( this ) ) | ||
163 | , _windowManager( new WindowManager( this ) ) | 168 | , _windowManager( new WindowManager( this ) ) | ||
164 | , _frameShadowFactory( new FrameShadowFactory( this ) ) | 169 | , _frameShadowFactory( new FrameShadowFactory( this ) ) | ||
165 | , _mdiWindowShadowFactory( new MdiWindowShadowFactory( this ) ) | 170 | , _mdiWindowShadowFactory( new MdiWindowShadowFactory( this ) ) | ||
166 | , _splitterFactory( new SplitterFactory( this ) ) | 171 | , _splitterFactory( new SplitterFactory( this ) ) | ||
172 | , _toolsAreaManager ( new ToolsAreaManager( _helper, this ) ) | ||||
167 | , _widgetExplorer( new WidgetExplorer( this ) ) | 173 | , _widgetExplorer( new WidgetExplorer( this ) ) | ||
168 | , _tabBarData( new BreezePrivate::TabBarData( this ) ) | 174 | , _tabBarData( new BreezePrivate::TabBarData( this ) ) | ||
169 | #if BREEZE_HAVE_KSTYLE | 175 | #if BREEZE_HAVE_KSTYLE | ||
Compiler complains about variable being initialized in incorrect order. Member initialization must be in the same order as the declaration. (here toolsarea befor tabbardata) hpereiradacosta: Compiler complains about variable being initialized in incorrect order. Member initialization… | |||||
170 | , SH_ArgbDndWindow( newStyleHint( QStringLiteral( "SH_ArgbDndWindow" ) ) ) | 176 | , SH_ArgbDndWindow( newStyleHint( QStringLiteral( "SH_ArgbDndWindow" ) ) ) | ||
171 | , CE_CapacityBar( newControlElement( QStringLiteral( "CE_CapacityBar" ) ) ) | 177 | , CE_CapacityBar( newControlElement( QStringLiteral( "CE_CapacityBar" ) ) ) | ||
172 | #endif | 178 | #endif | ||
173 | { | 179 | { | ||
174 | 180 | | |||
175 | // use DBus connection to update on breeze configuration change | 181 | // use DBus connection to update on breeze configuration change | ||
176 | auto dbus = QDBusConnection::sessionBus(); | 182 | auto dbus = QDBusConnection::sessionBus(); | ||
177 | dbus.connect( QString(), | 183 | dbus.connect( QString(), | ||
178 | QStringLiteral( "/BreezeStyle" ), | 184 | QStringLiteral( "/BreezeStyle" ), | ||
179 | QStringLiteral( "org.kde.Breeze.Style" ), | 185 | QStringLiteral( "org.kde.Breeze.Style" ), | ||
180 | QStringLiteral( "reparseConfiguration" ), this, SLOT(configurationChanged()) ); | 186 | QStringLiteral( "reparseConfiguration" ), this, SLOT(configurationChanged()) ); | ||
181 | 187 | | |||
182 | dbus.connect( QString(), | 188 | dbus.connect( QString(), | ||
183 | QStringLiteral( "/BreezeDecoration" ), | 189 | QStringLiteral( "/BreezeDecoration" ), | ||
184 | QStringLiteral( "org.kde.Breeze.Style" ), | 190 | QStringLiteral( "org.kde.Breeze.Style" ), | ||
185 | QStringLiteral( "reparseConfiguration" ), this, SLOT(configurationChanged()) ); | 191 | QStringLiteral( "reparseConfiguration" ), this, SLOT(configurationChanged()) ); | ||
192 | | ||||
193 | dbus.connect( QString(), | ||||
194 | QStringLiteral( "/KGlobalSettings" ), | ||||
195 | QStringLiteral( "org.kde.KGlobalSettings" ), | ||||
196 | QStringLiteral( "notifyChange" ), this, SLOT(configurationChanged()) ); | ||||
197 | | ||||
198 | dbus.connect( QString(), | ||||
199 | QStringLiteral( "/KWin" ), | ||||
200 | QStringLiteral( "org.kde.KWin" ), | ||||
201 | QStringLiteral( "reloadConfig" ), this, SLOT(configurationChanged())); | ||||
202 | | ||||
186 | #if QT_VERSION < 0x050D00 // Check if Qt version < 5.13 | 203 | #if QT_VERSION < 0x050D00 // Check if Qt version < 5.13 | ||
187 | this->addEventFilter(qApp); | 204 | this->addEventFilter(qApp); | ||
188 | #else | 205 | #else | ||
189 | connect(qApp, &QApplication::paletteChanged, this, &Style::configurationChanged); | 206 | connect(qApp, &QApplication::paletteChanged, this, &Style::configurationChanged); | ||
190 | #endif | 207 | #endif | ||
191 | // call the slot directly; this initial call will set up things that also | 208 | // call the slot directly; this initial call will set up things that also | ||
192 | // need to be reset when the system palette changes | 209 | // need to be reset when the system palette changes | ||
193 | loadConfiguration(); | 210 | loadConfiguration(); | ||
Show All 14 Lines | 223 | { | |||
208 | 225 | | |||
209 | // register widget to animations | 226 | // register widget to animations | ||
210 | _animations->registerWidget( widget ); | 227 | _animations->registerWidget( widget ); | ||
211 | _windowManager->registerWidget( widget ); | 228 | _windowManager->registerWidget( widget ); | ||
212 | _frameShadowFactory->registerWidget( widget, *_helper ); | 229 | _frameShadowFactory->registerWidget( widget, *_helper ); | ||
213 | _mdiWindowShadowFactory->registerWidget( widget ); | 230 | _mdiWindowShadowFactory->registerWidget( widget ); | ||
214 | _shadowHelper->registerWidget( widget ); | 231 | _shadowHelper->registerWidget( widget ); | ||
215 | _splitterFactory->registerWidget( widget ); | 232 | _splitterFactory->registerWidget( widget ); | ||
233 | _toolsAreaManager->registerWidget ( widget ); | ||||
216 | 234 | | |||
217 | // enable mouse over effects for all necessary widgets | 235 | // enable mouse over effects for all necessary widgets | ||
218 | if( | 236 | if( | ||
219 | qobject_cast<QAbstractItemView*>( widget ) | 237 | qobject_cast<QAbstractItemView*>( widget ) | ||
220 | || qobject_cast<QAbstractSpinBox*>( widget ) | 238 | || qobject_cast<QAbstractSpinBox*>( widget ) | ||
221 | || qobject_cast<QCheckBox*>( widget ) | 239 | || qobject_cast<QCheckBox*>( widget ) | ||
222 | || qobject_cast<QComboBox*>( widget ) | 240 | || qobject_cast<QComboBox*>( widget ) | ||
223 | || qobject_cast<QDial*>( widget ) | 241 | || qobject_cast<QDial*>( widget ) | ||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Line(s) | 362 | } else if( widget->inherits( "QComboBoxPrivateContainer" ) ) { | |||
345 | 363 | | |||
346 | addEventFilter( widget ); | 364 | addEventFilter( widget ); | ||
347 | setTranslucentBackground( widget ); | 365 | setTranslucentBackground( widget ); | ||
348 | 366 | | |||
349 | } else if( widget->inherits( "QTipLabel" ) ) { | 367 | } else if( widget->inherits( "QTipLabel" ) ) { | ||
350 | 368 | | |||
351 | setTranslucentBackground( widget ); | 369 | setTranslucentBackground( widget ); | ||
352 | 370 | | |||
371 | } else if ( qobject_cast<QMainWindow*> (widget) || qobject_cast<QDialog*> (widget) ) { | ||||
372 | widget->setAttribute(Qt::WA_StyledBackground); | ||||
Just for my understanding: why is it necessary ? hpereiradacosta: Just for my understanding: why is it necessary ?
Here at least, nothing changes if I take this… | |||||
This causes Qt to request a background be drawn on these widgets, which is used for painting the border when there would normally be no widgets to paint on. Check systemsettings5 and spectacle. cblack: This causes Qt to request a background be drawn on these widgets, which is used for painting… | |||||
353 | } | 373 | } | ||
354 | | ||||
355 | // base class polishing | 374 | // base class polishing | ||
356 | ParentStyleClass::polish( widget ); | 375 | ParentStyleClass::polish( widget ); | ||
357 | 376 | | |||
358 | } | 377 | } | ||
359 | 378 | | |||
360 | //______________________________________________________________ | 379 | //______________________________________________________________ | ||
361 | void Style::polishScrollArea( QAbstractScrollArea* scrollArea ) | 380 | void Style::polishScrollArea( QAbstractScrollArea* scrollArea ) | ||
362 | { | 381 | { | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 451 | { | |||
434 | // register widget to animations | 453 | // register widget to animations | ||
435 | _animations->unregisterWidget( widget ); | 454 | _animations->unregisterWidget( widget ); | ||
436 | _frameShadowFactory->unregisterWidget( widget ); | 455 | _frameShadowFactory->unregisterWidget( widget ); | ||
437 | _mdiWindowShadowFactory->unregisterWidget( widget ); | 456 | _mdiWindowShadowFactory->unregisterWidget( widget ); | ||
438 | _shadowHelper->unregisterWidget( widget ); | 457 | _shadowHelper->unregisterWidget( widget ); | ||
439 | _windowManager->unregisterWidget( widget ); | 458 | _windowManager->unregisterWidget( widget ); | ||
440 | _splitterFactory->unregisterWidget( widget ); | 459 | _splitterFactory->unregisterWidget( widget ); | ||
441 | _blurHelper->unregisterWidget( widget ); | 460 | _blurHelper->unregisterWidget( widget ); | ||
461 | _toolsAreaManager->unregisterWidget ( widget ); | ||||
442 | 462 | | |||
443 | // remove event filter | 463 | // remove event filter | ||
444 | if( qobject_cast<QAbstractScrollArea*>( widget ) || | 464 | if( qobject_cast<QAbstractScrollArea*>( widget ) || | ||
445 | qobject_cast<QDockWidget*>( widget ) || | 465 | qobject_cast<QDockWidget*>( widget ) || | ||
446 | qobject_cast<QMdiSubWindow*>( widget ) || | 466 | qobject_cast<QMdiSubWindow*>( widget ) || | ||
447 | widget->inherits( "QComboBoxPrivateContainer" ) ) | 467 | widget->inherits( "QComboBoxPrivateContainer" ) ) | ||
448 | { widget->removeEventFilter( this ); } | 468 | { widget->removeEventFilter( this ); } | ||
449 | 469 | | |||
▲ Show 20 Lines • Show All 389 Lines • ▼ Show 20 Line(s) | 837 | { | |||
839 | case PE_Frame: fcn = &Style::drawFramePrimitive; break; | 859 | case PE_Frame: fcn = &Style::drawFramePrimitive; break; | ||
840 | case PE_FrameLineEdit: fcn = &Style::drawFrameLineEditPrimitive; break; | 860 | case PE_FrameLineEdit: fcn = &Style::drawFrameLineEditPrimitive; break; | ||
841 | case PE_FrameMenu: fcn = &Style::drawFrameMenuPrimitive; break; | 861 | case PE_FrameMenu: fcn = &Style::drawFrameMenuPrimitive; break; | ||
842 | case PE_FrameGroupBox: fcn = &Style::drawFrameGroupBoxPrimitive; break; | 862 | case PE_FrameGroupBox: fcn = &Style::drawFrameGroupBoxPrimitive; break; | ||
843 | case PE_FrameTabWidget: fcn = &Style::drawFrameTabWidgetPrimitive; break; | 863 | case PE_FrameTabWidget: fcn = &Style::drawFrameTabWidgetPrimitive; break; | ||
844 | case PE_FrameTabBarBase: fcn = &Style::drawFrameTabBarBasePrimitive; break; | 864 | case PE_FrameTabBarBase: fcn = &Style::drawFrameTabBarBasePrimitive; break; | ||
845 | case PE_FrameWindow: fcn = &Style::drawFrameWindowPrimitive; break; | 865 | case PE_FrameWindow: fcn = &Style::drawFrameWindowPrimitive; break; | ||
846 | case PE_FrameFocusRect: fcn = _frameFocusPrimitive; break; | 866 | case PE_FrameFocusRect: fcn = _frameFocusPrimitive; break; | ||
867 | case PE_Widget: fcn = &Style::drawWidgetPrimitive; break; | ||||
847 | 868 | | |||
848 | // fallback | 869 | // fallback | ||
849 | default: break; | 870 | default: break; | ||
850 | 871 | | |||
851 | } | 872 | } | ||
852 | 873 | | |||
853 | painter->save(); | 874 | painter->save(); | ||
854 | 875 | | |||
855 | // call function if implemented | 876 | // call function if implemented | ||
856 | if( !( fcn && fcn( *this, option, painter, widget ) ) ) | 877 | if( !( fcn && fcn( *this, option, painter, widget ) ) ) | ||
857 | { ParentStyleClass::drawPrimitive( element, option, painter, widget ); } | 878 | { ParentStyleClass::drawPrimitive( element, option, painter, widget ); } | ||
858 | 879 | | |||
859 | painter->restore(); | 880 | painter->restore(); | ||
860 | 881 | | |||
861 | } | 882 | } | ||
862 | 883 | | |||
884 | bool Style::drawWidgetPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { | ||||
"option" is unused (and compiler complains about it) hpereiradacosta: "option" is unused (and compiler complains about it)
Either add Q_UNUSED(option) just put… | |||||
885 | Q_UNUSED(option) | ||||
886 | auto parent = widget; | ||||
887 | while (parent != nullptr) { | ||||
Just "setPen( _helper-> ...) hpereiradacosta: Just "setPen( _helper-> ...)
you don't need the temporary QPen if it has a width 1. | |||||
888 | if (qobject_cast<const QDockWidget*>(parent) || qobject_cast<const QMdiArea*>(parent)) return true; | ||||
889 | parent = parent->parentWidget(); | ||||
hpereiradacosta: Same remark | |||||
890 | } | ||||
891 | if (qobject_cast<const QMainWindow*>(widget) || qobject_cast<const QDialog*> (widget)) { | ||||
892 | if (!_helper->toolsAreaHasContents(widget) && _helper->shouldDrawToolsArea(widget)) { | ||||
893 | painter->save(); | ||||
What are these + and -100 numbers ? They sound arbitrary. At the minimum there should be a comment, and an enum to define what this number is. hpereiradacosta: What are these + and -100 numbers ? They sound arbitrary. At the minimum there should be a… | |||||
894 | painter->setPen(_helper->toolsAreaBorderColor(widget)); | ||||
895 | painter->setRenderHints(QPainter::Antialiasing, false); | ||||
896 | painter->setBrush(Qt::NoBrush); | ||||
897 | | ||||
898 | painter->drawLine( | ||||
899 | widget->rect().left()*2, | ||||
900 | widget->rect().top(), | ||||
901 | widget->rect().right()*2, | ||||
902 | widget->rect().top() | ||||
903 | ); | ||||
904 | painter->restore(); | ||||
905 | } else if (_helper->shouldDrawToolsArea(widget)) { | ||||
906 | auto rect = _helper->toolsAreaToolbarsRect(widget); | ||||
907 | | ||||
davidre: Stray qdebug | |||||
908 | painter->save(); | ||||
909 | { | ||||
910 | painter->setBrush(_helper->titleBarColor(widget->isActiveWindow())); | ||||
911 | painter->setPen(Qt::NoPen); | ||||
912 | | ||||
913 | painter->drawRect(rect); | ||||
914 | } | ||||
915 | painter->restore(); | ||||
916 | | ||||
917 | painter->save(); | ||||
918 | { | ||||
919 | painter->setPen(_helper->toolsAreaBorderColor(widget)); | ||||
920 | painter->setBrush(Qt::NoBrush); | ||||
921 | painter->setRenderHints(QPainter::Antialiasing, false); | ||||
922 | | ||||
923 | painter->drawLine( | ||||
924 | rect.left()*2, | ||||
925 | rect.bottom(), | ||||
926 | rect.right()*2, | ||||
927 | rect.bottom() | ||||
928 | ); | ||||
929 | } | ||||
930 | painter->restore(); | ||||
931 | } | ||||
932 | } | ||||
933 | return true; | ||||
934 | } | ||||
935 | | ||||
863 | //______________________________________________________________ | 936 | //______________________________________________________________ | ||
864 | void Style::drawControl( ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | 937 | void Style::drawControl( ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | ||
865 | { | 938 | { | ||
866 | 939 | | |||
867 | StyleControl fcn; | 940 | StyleControl fcn; | ||
868 | 941 | | |||
869 | #if BREEZE_HAVE_KSTYLE | 942 | #if BREEZE_HAVE_KSTYLE | ||
870 | if( element == CE_CapacityBar ) | 943 | if( element == CE_CapacityBar ) | ||
Show All 9 Lines | 950 | switch( element ) { | |||
880 | case CE_PushButtonLabel: fcn = &Style::drawPushButtonLabelControl; break; | 953 | case CE_PushButtonLabel: fcn = &Style::drawPushButtonLabelControl; break; | ||
881 | case CE_CheckBoxLabel: fcn = &Style::drawCheckBoxLabelControl; break; | 954 | case CE_CheckBoxLabel: fcn = &Style::drawCheckBoxLabelControl; break; | ||
882 | case CE_RadioButtonLabel: fcn = &Style::drawCheckBoxLabelControl; break; | 955 | case CE_RadioButtonLabel: fcn = &Style::drawCheckBoxLabelControl; break; | ||
883 | case CE_ToolButtonLabel: fcn = &Style::drawToolButtonLabelControl; break; | 956 | case CE_ToolButtonLabel: fcn = &Style::drawToolButtonLabelControl; break; | ||
884 | case CE_ComboBoxLabel: fcn = &Style::drawComboBoxLabelControl; break; | 957 | case CE_ComboBoxLabel: fcn = &Style::drawComboBoxLabelControl; break; | ||
885 | case CE_MenuBarEmptyArea: fcn = &Style::emptyControl; break; | 958 | case CE_MenuBarEmptyArea: fcn = &Style::emptyControl; break; | ||
886 | case CE_MenuBarItem: fcn = &Style::drawMenuBarItemControl; break; | 959 | case CE_MenuBarItem: fcn = &Style::drawMenuBarItemControl; break; | ||
887 | case CE_MenuItem: fcn = &Style::drawMenuItemControl; break; | 960 | case CE_MenuItem: fcn = &Style::drawMenuItemControl; break; | ||
888 | case CE_ToolBar: fcn = &Style::emptyControl; break; | 961 | case CE_ToolBar: fcn = &Style::drawToolBarControl; break; | ||
889 | case CE_ProgressBar: fcn = &Style::drawProgressBarControl; break; | 962 | case CE_ProgressBar: fcn = &Style::drawProgressBarControl; break; | ||
890 | case CE_ProgressBarContents: fcn = &Style::drawProgressBarContentsControl; break; | 963 | case CE_ProgressBarContents: fcn = &Style::drawProgressBarContentsControl; break; | ||
891 | case CE_ProgressBarGroove: fcn = &Style::drawProgressBarGrooveControl; break; | 964 | case CE_ProgressBarGroove: fcn = &Style::drawProgressBarGrooveControl; break; | ||
892 | case CE_ProgressBarLabel: fcn = &Style::drawProgressBarLabelControl; break; | 965 | case CE_ProgressBarLabel: fcn = &Style::drawProgressBarLabelControl; break; | ||
893 | case CE_ScrollBarSlider: fcn = &Style::drawScrollBarSliderControl; break; | 966 | case CE_ScrollBarSlider: fcn = &Style::drawScrollBarSliderControl; break; | ||
894 | case CE_ScrollBarAddLine: fcn = &Style::drawScrollBarAddLineControl; break; | 967 | case CE_ScrollBarAddLine: fcn = &Style::drawScrollBarAddLineControl; break; | ||
895 | case CE_ScrollBarSubLine: fcn = &Style::drawScrollBarSubLineControl; break; | 968 | case CE_ScrollBarSubLine: fcn = &Style::drawScrollBarSubLineControl; break; | ||
896 | case CE_ScrollBarAddPage: fcn = &Style::emptyControl; break; | 969 | case CE_ScrollBarAddPage: fcn = &Style::emptyControl; break; | ||
▲ Show 20 Lines • Show All 429 Lines • ▼ Show 20 Line(s) | |||||
1326 | { | 1399 | { | ||
1327 | 1400 | | |||
1328 | // reload | 1401 | // reload | ||
1329 | StyleConfigData::self()->load(); | 1402 | StyleConfigData::self()->load(); | ||
1330 | 1403 | | |||
1331 | // reload configuration | 1404 | // reload configuration | ||
1332 | loadConfiguration(); | 1405 | loadConfiguration(); | ||
1333 | 1406 | | |||
1407 | // load new titlebar colours into tools area animations | ||||
1408 | _toolsAreaManager->updateAnimations(); | ||||
1409 | | ||||
1410 | // trigger update of tools area | ||||
1411 | emit _toolsAreaManager->toolbarUpdated(); | ||||
1412 | | ||||
1334 | } | 1413 | } | ||
1335 | 1414 | | |||
1336 | //____________________________________________________________________ | 1415 | //____________________________________________________________________ | ||
1337 | QIcon Style::standardIconImplementation( StandardPixmap standardPixmap, const QStyleOption* option, const QWidget* widget ) const | 1416 | QIcon Style::standardIconImplementation( StandardPixmap standardPixmap, const QStyleOption* option, const QWidget* widget ) const | ||
1338 | { | 1417 | { | ||
1339 | 1418 | | |||
1340 | // lookup cache | 1419 | // lookup cache | ||
1341 | if( _iconCache.contains( standardPixmap ) ) return _iconCache.value( standardPixmap ); | 1420 | if( _iconCache.contains( standardPixmap ) ) return _iconCache.value( standardPixmap ); | ||
Show All 34 Lines | |||||
1376 | } | 1455 | } | ||
1377 | 1456 | | |||
1378 | //_____________________________________________________________________ | 1457 | //_____________________________________________________________________ | ||
1379 | void Style::loadConfiguration() | 1458 | void Style::loadConfiguration() | ||
1380 | { | 1459 | { | ||
1381 | 1460 | | |||
1382 | // load helper configuration | 1461 | // load helper configuration | ||
1383 | _helper->loadConfig(); | 1462 | _helper->loadConfig(); | ||
1463 | _helper->setToolsAreaEnabled(StyleConfigData::toolsAreaEnabled() ); | ||||
1384 | 1464 | | |||
1385 | // reinitialize engines | 1465 | // reinitialize engines | ||
1386 | _animations->setupEngines(); | 1466 | _animations->setupEngines(); | ||
1387 | _windowManager->initialize(); | 1467 | _windowManager->initialize(); | ||
1388 | 1468 | | |||
1389 | // mnemonics | 1469 | // mnemonics | ||
1390 | _mnemonics->setMode( StyleConfigData::mnemonicsMode() ); | 1470 | _mnemonics->setMode( StyleConfigData::mnemonicsMode() ); | ||
1391 | 1471 | | |||
▲ Show 20 Lines • Show All 2827 Lines • ▼ Show 20 Line(s) | |||||
4219 | //___________________________________________________________________________________ | 4299 | //___________________________________________________________________________________ | ||
4220 | bool Style::drawToolButtonLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | 4300 | bool Style::drawToolButtonLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | ||
4221 | { | 4301 | { | ||
4222 | 4302 | | |||
4223 | // cast option and check | 4303 | // cast option and check | ||
4224 | const auto toolButtonOption( qstyleoption_cast<const QStyleOptionToolButton*>(option) ); | 4304 | const auto toolButtonOption( qstyleoption_cast<const QStyleOptionToolButton*>(option) ); | ||
4225 | 4305 | | |||
4226 | // copy rect and palette | 4306 | // copy rect and palette | ||
4227 | const auto& rect = option->rect; | 4307 | const auto& rect = option->rect; | ||
4228 | const auto& palette = option->palette; | | |||
4229 | 4308 | | |||
as far as I can tell, this palette is used only later, in "drawItemText" and only if text is shown. I would move this all block there (line 4395 or so) hpereiradacosta: as far as I can tell, this palette is used only later, in "drawItemText" and only if text is… | |||||
4230 | // state | 4309 | // state | ||
4231 | const State& state( option->state ); | 4310 | const State& state( option->state ); | ||
4232 | const bool enabled( state & State_Enabled ); | 4311 | const bool enabled( state & State_Enabled ); | ||
4233 | const bool sunken( state & (State_On | State_Sunken) ); | 4312 | const bool sunken( state & (State_On | State_Sunken) ); | ||
4234 | const bool mouseOver( enabled && (option->state & State_MouseOver) ); | 4313 | const bool mouseOver( enabled && (option->state & State_MouseOver) ); | ||
4235 | const bool flat( state & State_AutoRaise ); | 4314 | const bool flat( state & State_AutoRaise ); | ||
4236 | 4315 | | |||
4237 | // focus flag is set to match the background color in either renderButtonFrame or renderToolButtonFrame | 4316 | // focus flag is set to match the background color in either renderButtonFrame or renderToolButtonFrame | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | 4359 | } else { | |||
4299 | 4378 | | |||
4300 | textFlags |= Qt::AlignLeft | Qt::AlignVCenter; | 4379 | textFlags |= Qt::AlignLeft | Qt::AlignVCenter; | ||
4301 | 4380 | | |||
4302 | } | 4381 | } | ||
4303 | 4382 | | |||
4304 | // make sure there is enough room for icon | 4383 | // make sure there is enough room for icon | ||
4305 | if( iconRect.isValid() ) iconRect = centerRect( iconRect, iconSize ); | 4384 | if( iconRect.isValid() ) iconRect = centerRect( iconRect, iconSize ); | ||
4306 | 4385 | | |||
4307 | // render arrow or icon | 4386 | // render arrow or icon | ||
Why has this code moved ? As far as I can tell it is used only line 4396, and so the initialization should remain in the corresponding if block. hpereiradacosta: Why has this code moved ? As far as I can tell it is used only line 4396, and so the… | |||||
4308 | if( hasArrow && iconRect.isValid() ) | 4387 | if( hasArrow && iconRect.isValid() ) | ||
4309 | { | 4388 | { | ||
4310 | 4389 | | |||
4311 | QStyleOptionToolButton copy( *toolButtonOption ); | 4390 | QStyleOptionToolButton copy( *toolButtonOption ); | ||
4312 | copy.rect = iconRect; | 4391 | copy.rect = iconRect; | ||
4313 | switch( toolButtonOption->arrowType ) | 4392 | switch( toolButtonOption->arrowType ) | ||
4314 | { | 4393 | { | ||
4315 | case Qt::LeftArrow: drawPrimitive( PE_IndicatorArrowLeft, ©, painter, widget ); break; | 4394 | case Qt::LeftArrow: drawPrimitive( PE_IndicatorArrowLeft, ©, painter, widget ); break; | ||
Show All 9 Lines | 4401 | } else if( hasIcon && iconRect.isValid() ) { | |||
4325 | const QIcon::State iconState( sunken ? QIcon::On : QIcon::Off ); | 4404 | const QIcon::State iconState( sunken ? QIcon::On : QIcon::Off ); | ||
4326 | QIcon::Mode iconMode; | 4405 | QIcon::Mode iconMode; | ||
4327 | if( !enabled ) iconMode = QIcon::Disabled; | 4406 | if( !enabled ) iconMode = QIcon::Disabled; | ||
4328 | else if( (!flat && hasFocus) || (flat && (state & State_Sunken) && !mouseOver) ) iconMode = QIcon::Selected; | 4407 | else if( (!flat && hasFocus) || (flat && (state & State_Sunken) && !mouseOver) ) iconMode = QIcon::Selected; | ||
4329 | else if( mouseOver && flat ) iconMode = QIcon::Active; | 4408 | else if( mouseOver && flat ) iconMode = QIcon::Active; | ||
4330 | else iconMode = QIcon::Normal; | 4409 | else iconMode = QIcon::Normal; | ||
4331 | 4410 | | |||
4332 | const QPixmap pixmap = _helper->coloredIcon(toolButtonOption->icon, toolButtonOption->palette, iconSize, iconMode, iconState); | 4411 | const QPixmap pixmap = _helper->coloredIcon(toolButtonOption->icon, toolButtonOption->palette, iconSize, iconMode, iconState); | ||
4333 | drawItemPixmap( painter, iconRect, Qt::AlignCenter, pixmap ); | 4412 | drawItemPixmap( painter, iconRect, Qt::AlignCenter, pixmap ); | ||
updating the palette in every paint event (and calling resetPalette()) will be very innefficient. You need to track whether the palette actually needs change before calling these. hpereiradacosta: updating the palette in every paint event (and calling resetPalette()) will be very… | |||||
If the tools area is enabled and a widget is in the tools area, then the palette needs changing. It is ugly, but that's what the best you can get when KIconLoader ignores widget palettes. cblack: If the tools area is enabled and a widget is in the tools area, then the palette needs changing. | |||||
Not at every paint event. You should check if kiconloader already have a customPalette, if it matches the one you want, and update (or reset) only when necessary. hpereiradacosta: Not at every paint event. You should check if kiconloader already have a customPalette, if it… | |||||
The issue is that the QStyle only has the global icon palette to mutate for the tools area. If the custom palette were to be left intact, that would affect widgets it's not supposed to. There is no other code flow that won't result in KIconLoader using a custom palette when it shouldn't. The reason this is necessary in the first place is that KIconLoader doesn't honor the widget palettes set elsewhere in the QStyle. This code is simply working with what it's being given, and the issues that lead to this solution are deep-rooted in Qt. You simply cannot do anything else without likely breaking Qt's current APIs that are in control of this. cblack: The issue is that the QStyle only has the global icon palette to mutate for the tools area. If… | |||||
I am sorry to say this is a serious show stopper. If there is no way to make this more efficient, then as far as I am concerned this is a no-go. Maybe one could try to cache the icons ourselves ? (and trigger cache clear when appropriate ?) hpereiradacosta: I am sorry to say this is a serious show stopper.
One cannot reset/update the kiconloader… | |||||
I'll dig in KIconLoader code a bit over the week-end to see what really happens when calling setCustomPalette and resetPalette, to get a sense of how resource consuming this is ... hpereiradacosta: I'll dig in KIconLoader code a bit over the week-end to see what really happens when calling… | |||||
So, hpereiradacosta: So,
Digging into the code it seems that this might not be as big of a problem as anticipated. | |||||
4334 | 4413 | | |||
4335 | } | 4414 | } | ||
4336 | 4415 | | |||
4337 | // render text | 4416 | // render text | ||
4338 | if( hasText && textRect.isValid() ) | 4417 | if( hasText && textRect.isValid() ) | ||
4339 | { | 4418 | { | ||
4340 | | ||||
4341 | QPalette::ColorRole textRole( QPalette::ButtonText ); | 4419 | QPalette::ColorRole textRole( QPalette::ButtonText ); | ||
4342 | if( flat ) textRole = ( ((hasFocus&&sunken) || (state & State_Sunken))&&!mouseOver) ? QPalette::HighlightedText: QPalette::WindowText; | 4420 | if( flat ) textRole = ( ((hasFocus&&sunken) || (state & State_Sunken))&&!mouseOver) ? QPalette::HighlightedText: QPalette::WindowText; | ||
4343 | else if( hasFocus&&!mouseOver ) textRole = QPalette::HighlightedText; | 4421 | else if( hasFocus&&!mouseOver ) textRole = QPalette::HighlightedText; | ||
4344 | 4422 | | |||
4423 | auto palette = option->palette; | ||||
4424 | | ||||
4425 | if (_helper->isInToolsArea(widget)) { | ||||
4426 | palette.setColor(QPalette::ButtonText, _helper->titleBarTextColor(widget->isActiveWindow())); | ||||
4427 | palette.setColor(QPalette::WindowText, _helper->titleBarTextColor(widget->isActiveWindow())); | ||||
4428 | } | ||||
4429 | | ||||
4345 | painter->setFont(toolButtonOption->font); | 4430 | painter->setFont(toolButtonOption->font); | ||
4346 | drawItemText( painter, textRect, textFlags, palette, enabled, toolButtonOption->text, textRole ); | 4431 | drawItemText( painter, textRect, textFlags, palette, enabled, toolButtonOption->text, textRole ); | ||
4347 | 4432 | | |||
4348 | } | 4433 | } | ||
4349 | 4434 | | |||
4350 | return true; | 4435 | return true; | ||
4351 | 4436 | | |||
4352 | } | 4437 | } | ||
▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Line(s) | |||||
4492 | { | 4577 | { | ||
4493 | 4578 | | |||
4494 | // cast option and check | 4579 | // cast option and check | ||
4495 | const auto menuItemOption = qstyleoption_cast<const QStyleOptionMenuItem*>( option ); | 4580 | const auto menuItemOption = qstyleoption_cast<const QStyleOptionMenuItem*>( option ); | ||
4496 | if( !menuItemOption ) return true; | 4581 | if( !menuItemOption ) return true; | ||
4497 | 4582 | | |||
4498 | // copy rect and palette | 4583 | // copy rect and palette | ||
4499 | const auto& rect( option->rect ); | 4584 | const auto& rect( option->rect ); | ||
4500 | const auto& palette( option->palette ); | 4585 | auto palette( option->palette ); | ||
4586 | | ||||
4587 | if (_helper->isInToolsArea(widget)) { | ||||
4588 | palette.setColor(QPalette::WindowText, _helper->titleBarTextColor(widget->isActiveWindow())); | ||||
4589 | } | ||||
4501 | 4590 | | |||
4502 | // store state | 4591 | // store state | ||
4503 | const State& state( option->state ); | 4592 | const State& state( option->state ); | ||
4504 | const bool enabled( state & State_Enabled ); | 4593 | const bool enabled( state & State_Enabled ); | ||
4505 | const bool selected( enabled && (state & State_Selected) ); | 4594 | const bool selected( enabled && (state & State_Selected) ); | ||
4506 | const bool sunken( enabled && (state & State_Sunken) ); | 4595 | const bool sunken( enabled && (state & State_Sunken) ); | ||
4507 | const bool useStrongFocus( StyleConfigData::menuItemDrawStrongFocus() ); | 4596 | const bool useStrongFocus( StyleConfigData::menuItemDrawStrongFocus() ); | ||
4508 | 4597 | | |||
4598 | painter->save(); | ||||
4599 | painter->setRenderHints( QPainter::Antialiasing ); | ||||
4600 | | ||||
4509 | // render hover and focus | 4601 | // render hover and focus | ||
4510 | if( useStrongFocus && ( selected || sunken ) ) | 4602 | if( useStrongFocus && ( selected || sunken ) ) | ||
4511 | { | 4603 | { | ||
4512 | 4604 | | |||
Are you sure about the logic here ? geometry is relative to the parent corrdinate system while childrenRect is relative to current widget. hpereiradacosta: Are you sure about the logic here ? geometry is relative to the parent corrdinate system while… | |||||
Here at least, using opt->rect directly (no need for the copy), fixes the multiple toolbar issue, with no regression elsewhere. hpereiradacosta: Here at least, using opt->rect directly (no need for the copy), fixes the multiple toolbar… | |||||
4513 | QColor outlineColor; | 4605 | QColor outlineColor; | ||
4514 | if( sunken ) outlineColor = _helper->focusColor( palette ); | 4606 | if( sunken ) outlineColor = _helper->focusColor( palette ); | ||
4515 | else if( selected ) outlineColor = _helper->hoverColor( palette ); | 4607 | else if( selected ) outlineColor = _helper->hoverColor( palette ); | ||
4516 | _helper->renderFocusRect( painter, rect, outlineColor ); | 4608 | _helper->renderFocusRect( painter, rect, outlineColor ); | ||
4517 | 4609 | | |||
4518 | } | 4610 | } | ||
4519 | 4611 | | |||
4520 | /* | 4612 | /* | ||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | 4667 | { | |||
4579 | else if( selected ) outlineColor = _helper->hoverColor( palette ); | 4671 | else if( selected ) outlineColor = _helper->hoverColor( palette ); | ||
4580 | 4672 | | |||
4581 | _helper->renderFocusLine( painter, textRect, outlineColor ); | 4673 | _helper->renderFocusLine( painter, textRect, outlineColor ); | ||
4582 | 4674 | | |||
4583 | } | 4675 | } | ||
4584 | 4676 | | |||
4585 | } | 4677 | } | ||
4586 | 4678 | | |||
4587 | return true; | 4679 | painter->restore(); | ||
4588 | 4680 | | |||
4681 | return true; | ||||
4589 | } | 4682 | } | ||
4590 | 4683 | | |||
4591 | 4684 | | |||
4592 | //___________________________________________________________________________________ | 4685 | //___________________________________________________________________________________ | ||
4593 | bool Style::drawMenuItemControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | 4686 | bool Style::drawMenuItemControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | ||
4594 | { | 4687 | { | ||
4595 | 4688 | | |||
4596 | // cast option and check | 4689 | // cast option and check | ||
▲ Show 20 Lines • Show All 203 Lines • ▼ Show 20 Line(s) | 4854 | { | |||
4800 | 4893 | | |||
4801 | } | 4894 | } | ||
4802 | 4895 | | |||
4803 | } | 4896 | } | ||
4804 | 4897 | | |||
4805 | return true; | 4898 | return true; | ||
4806 | } | 4899 | } | ||
4807 | 4900 | | |||
4901 | bool Style::drawToolBarControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | ||||
4902 | { | ||||
4903 | Q_UNUSED(option) | ||||
as far as I can tell you dont need the cast to QToolbar. Just use the widget. hpereiradacosta: as far as I can tell you dont need the cast to QToolbar. Just use the widget.
(and in any case… | |||||
4904 | Q_UNUSED(painter) | ||||
4905 | auto toolbar = const_cast<QWidget*>(widget); | ||||
4906 | | ||||
4907 | if (!_helper->isInToolsArea(widget)) { | ||||
Same remark. This is very innefficient. hpereiradacosta: Same remark. This is very innefficient.
You need to track whether the palette actually need… | |||||
4908 | if (_toolsAreaManager->widgetHasCorrectPaletteSet(toolbar)) { | ||||
4909 | toolbar->setPalette(toolbar->parentWidget()->palette()); | ||||
4910 | } | ||||
4911 | return true; | ||||
4912 | } | ||||
4913 | | ||||
This should move in the if condition below. Creating a new palette (even by copy) is expensive. hpereiradacosta: This should move in the if condition below. Creating a new palette (even by copy) is expensive. | |||||
4914 | if (!_toolsAreaManager->widgetHasCorrectPaletteSet(widget)) { | ||||
4915 | auto palette = toolbar->palette(); | ||||
hpereiradacosta: same remark | |||||
4916 | palette.setColor( QPalette::Window, _toolsAreaManager->background(widget) ); | ||||
4917 | palette.setColor( QPalette::WindowText, _toolsAreaManager->foreground(widget) ); | ||||
4918 | toolbar->setPalette(palette); | ||||
4919 | } | ||||
4920 | | ||||
4921 | return true; | ||||
4922 | } | ||||
hpereiradacosta: same remark about option being unused | |||||
4923 | | ||||
hpereiradacosta: Same remark as above. | |||||
4808 | //___________________________________________________________________________________ | 4924 | //___________________________________________________________________________________ | ||
4809 | bool Style::drawProgressBarControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | 4925 | bool Style::drawProgressBarControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | ||
4810 | { | 4926 | { | ||
4811 | 4927 | | |||
4812 | const auto progressBarOption( qstyleoption_cast<const QStyleOptionProgressBar*>( option ) ); | 4928 | const auto progressBarOption( qstyleoption_cast<const QStyleOptionProgressBar*>( option ) ); | ||
4813 | if( !progressBarOption ) return true; | 4929 | if( !progressBarOption ) return true; | ||
4814 | 4930 | | |||
4815 | // render groove | 4931 | // render groove | ||
Show All 9 Lines | |||||
4825 | { | 4941 | { | ||
4826 | 4942 | | |||
4827 | // register QML object if defined | 4943 | // register QML object if defined | ||
4828 | if( !widget && progressBarOption->styleObject ) | 4944 | if( !widget && progressBarOption->styleObject ) | ||
4829 | { _animations->busyIndicatorEngine().registerWidget( progressBarOption->styleObject ); } | 4945 | { _animations->busyIndicatorEngine().registerWidget( progressBarOption->styleObject ); } | ||
4830 | 4946 | | |||
4831 | _animations->busyIndicatorEngine().setAnimated( styleObject, progressBarOption->maximum == 0 && progressBarOption->minimum == 0 ); | 4947 | _animations->busyIndicatorEngine().setAnimated( styleObject, progressBarOption->maximum == 0 && progressBarOption->minimum == 0 ); | ||
4832 | 4948 | | |||
4833 | } | 4949 | } | ||
another case where it is probably more correct to use option->rect directly. hpereiradacosta: another case where it is probably more correct to use option->rect directly. | |||||
4834 | 4950 | | |||
4835 | // check if animated and pass to option | 4951 | // check if animated and pass to option | ||
4836 | if( _animations->busyIndicatorEngine().isAnimated( styleObject ) ) | 4952 | if( _animations->busyIndicatorEngine().isAnimated( styleObject ) ) | ||
4837 | { progressBarOption2.progress = _animations->busyIndicatorEngine().value(); } | 4953 | { progressBarOption2.progress = _animations->busyIndicatorEngine().value(); } | ||
4838 | 4954 | | |||
4839 | // render contents | 4955 | // render contents | ||
4840 | progressBarOption2.rect = subElementRect( SE_ProgressBarContents, progressBarOption, widget ); | 4956 | progressBarOption2.rect = subElementRect( SE_ProgressBarContents, progressBarOption, widget ); | ||
4841 | drawControl( CE_ProgressBarContents, &progressBarOption2, painter, widget ); | 4957 | drawControl( CE_ProgressBarContents, &progressBarOption2, painter, widget ); | ||
▲ Show 20 Lines • Show All 2293 Lines • Show Last 20 Lines |
Not needed