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> | ||
62 | 66 | | |||
63 | #if BREEZE_HAVE_QTQUICK | 67 | #if BREEZE_HAVE_QTQUICK | ||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 160 | Style::Style(): | |||
159 | , _shadowHelper( new ShadowHelper( this, *_helper ) ) | 163 | , _shadowHelper( new ShadowHelper( this, *_helper ) ) | ||
160 | , _animations( new Animations( this ) ) | 164 | , _animations( new Animations( this ) ) | ||
161 | , _mnemonics( new Mnemonics( this ) ) | 165 | , _mnemonics( new Mnemonics( this ) ) | ||
162 | , _blurHelper( new BlurHelper( this ) ) | 166 | , _blurHelper( new BlurHelper( this ) ) | ||
163 | , _windowManager( new WindowManager( this ) ) | 167 | , _windowManager( new WindowManager( this ) ) | ||
164 | , _frameShadowFactory( new FrameShadowFactory( this ) ) | 168 | , _frameShadowFactory( new FrameShadowFactory( this ) ) | ||
165 | , _mdiWindowShadowFactory( new MdiWindowShadowFactory( this ) ) | 169 | , _mdiWindowShadowFactory( new MdiWindowShadowFactory( this ) ) | ||
166 | , _splitterFactory( new SplitterFactory( this ) ) | 170 | , _splitterFactory( new SplitterFactory( this ) ) | ||
171 | , _toolsAreaManager ( new ToolsAreaManager( _helper, this ) ) | ||||
167 | , _widgetExplorer( new WidgetExplorer( this ) ) | 172 | , _widgetExplorer( new WidgetExplorer( this ) ) | ||
168 | , _tabBarData( new BreezePrivate::TabBarData( this ) ) | 173 | , _tabBarData( new BreezePrivate::TabBarData( this ) ) | ||
169 | #if BREEZE_HAVE_KSTYLE | 174 | #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" ) ) ) | 175 | , SH_ArgbDndWindow( newStyleHint( QStringLiteral( "SH_ArgbDndWindow" ) ) ) | ||
171 | , CE_CapacityBar( newControlElement( QStringLiteral( "CE_CapacityBar" ) ) ) | 176 | , CE_CapacityBar( newControlElement( QStringLiteral( "CE_CapacityBar" ) ) ) | ||
172 | #endif | 177 | #endif | ||
173 | { | 178 | { | ||
174 | 179 | | |||
175 | // use DBus connection to update on breeze configuration change | 180 | // use DBus connection to update on breeze configuration change | ||
176 | auto dbus = QDBusConnection::sessionBus(); | 181 | auto dbus = QDBusConnection::sessionBus(); | ||
177 | dbus.connect( QString(), | 182 | dbus.connect( QString(), | ||
178 | QStringLiteral( "/BreezeStyle" ), | 183 | QStringLiteral( "/BreezeStyle" ), | ||
179 | QStringLiteral( "org.kde.Breeze.Style" ), | 184 | QStringLiteral( "org.kde.Breeze.Style" ), | ||
180 | QStringLiteral( "reparseConfiguration" ), this, SLOT(configurationChanged()) ); | 185 | QStringLiteral( "reparseConfiguration" ), this, SLOT(configurationChanged()) ); | ||
181 | 186 | | |||
182 | dbus.connect( QString(), | 187 | dbus.connect( QString(), | ||
183 | QStringLiteral( "/BreezeDecoration" ), | 188 | QStringLiteral( "/BreezeDecoration" ), | ||
184 | QStringLiteral( "org.kde.Breeze.Style" ), | 189 | QStringLiteral( "org.kde.Breeze.Style" ), | ||
185 | QStringLiteral( "reparseConfiguration" ), this, SLOT(configurationChanged()) ); | 190 | QStringLiteral( "reparseConfiguration" ), this, SLOT(configurationChanged()) ); | ||
191 | | ||||
192 | dbus.connect( QString(), | ||||
193 | QStringLiteral( "/KGlobalSettings" ), | ||||
194 | QStringLiteral( "org.kde.KGlobalSettings" ), | ||||
195 | QStringLiteral( "notifyChange" ), this, SLOT(configurationChanged()) ); | ||||
196 | | ||||
186 | #if QT_VERSION < 0x050D00 // Check if Qt version < 5.13 | 197 | #if QT_VERSION < 0x050D00 // Check if Qt version < 5.13 | ||
187 | this->addEventFilter(qApp); | 198 | this->addEventFilter(qApp); | ||
188 | #else | 199 | #else | ||
189 | connect(qApp, &QApplication::paletteChanged, this, &Style::configurationChanged); | 200 | connect(qApp, &QApplication::paletteChanged, this, &Style::configurationChanged); | ||
190 | #endif | 201 | #endif | ||
191 | // call the slot directly; this initial call will set up things that also | 202 | // call the slot directly; this initial call will set up things that also | ||
192 | // need to be reset when the system palette changes | 203 | // need to be reset when the system palette changes | ||
193 | loadConfiguration(); | 204 | loadConfiguration(); | ||
Show All 14 Lines | 217 | { | |||
208 | 219 | | |||
209 | // register widget to animations | 220 | // register widget to animations | ||
210 | _animations->registerWidget( widget ); | 221 | _animations->registerWidget( widget ); | ||
211 | _windowManager->registerWidget( widget ); | 222 | _windowManager->registerWidget( widget ); | ||
212 | _frameShadowFactory->registerWidget( widget, *_helper ); | 223 | _frameShadowFactory->registerWidget( widget, *_helper ); | ||
213 | _mdiWindowShadowFactory->registerWidget( widget ); | 224 | _mdiWindowShadowFactory->registerWidget( widget ); | ||
214 | _shadowHelper->registerWidget( widget ); | 225 | _shadowHelper->registerWidget( widget ); | ||
215 | _splitterFactory->registerWidget( widget ); | 226 | _splitterFactory->registerWidget( widget ); | ||
227 | _toolsAreaManager->registerWidget ( widget ); | ||||
216 | 228 | | |||
217 | // enable mouse over effects for all necessary widgets | 229 | // enable mouse over effects for all necessary widgets | ||
218 | if( | 230 | if( | ||
219 | qobject_cast<QAbstractItemView*>( widget ) | 231 | qobject_cast<QAbstractItemView*>( widget ) | ||
220 | || qobject_cast<QAbstractSpinBox*>( widget ) | 232 | || qobject_cast<QAbstractSpinBox*>( widget ) | ||
221 | || qobject_cast<QCheckBox*>( widget ) | 233 | || qobject_cast<QCheckBox*>( widget ) | ||
222 | || qobject_cast<QComboBox*>( widget ) | 234 | || qobject_cast<QComboBox*>( widget ) | ||
223 | || qobject_cast<QDial*>( widget ) | 235 | || qobject_cast<QDial*>( widget ) | ||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Line(s) | 356 | } else if( widget->inherits( "QComboBoxPrivateContainer" ) ) { | |||
345 | 357 | | |||
346 | addEventFilter( widget ); | 358 | addEventFilter( widget ); | ||
347 | setTranslucentBackground( widget ); | 359 | setTranslucentBackground( widget ); | ||
348 | 360 | | |||
349 | } else if( widget->inherits( "QTipLabel" ) ) { | 361 | } else if( widget->inherits( "QTipLabel" ) ) { | ||
350 | 362 | | |||
351 | setTranslucentBackground( widget ); | 363 | setTranslucentBackground( widget ); | ||
352 | 364 | | |||
365 | } else if ( qobject_cast<QMainWindow*> (widget) || qobject_cast<QDialog*> (widget) ) { | ||||
366 | 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 | } | 367 | } | ||
354 | | ||||
355 | // base class polishing | 368 | // base class polishing | ||
356 | ParentStyleClass::polish( widget ); | 369 | ParentStyleClass::polish( widget ); | ||
357 | 370 | | |||
358 | } | 371 | } | ||
359 | 372 | | |||
360 | //______________________________________________________________ | 373 | //______________________________________________________________ | ||
361 | void Style::polishScrollArea( QAbstractScrollArea* scrollArea ) | 374 | void Style::polishScrollArea( QAbstractScrollArea* scrollArea ) | ||
362 | { | 375 | { | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 445 | { | |||
434 | // register widget to animations | 447 | // register widget to animations | ||
435 | _animations->unregisterWidget( widget ); | 448 | _animations->unregisterWidget( widget ); | ||
436 | _frameShadowFactory->unregisterWidget( widget ); | 449 | _frameShadowFactory->unregisterWidget( widget ); | ||
437 | _mdiWindowShadowFactory->unregisterWidget( widget ); | 450 | _mdiWindowShadowFactory->unregisterWidget( widget ); | ||
438 | _shadowHelper->unregisterWidget( widget ); | 451 | _shadowHelper->unregisterWidget( widget ); | ||
439 | _windowManager->unregisterWidget( widget ); | 452 | _windowManager->unregisterWidget( widget ); | ||
440 | _splitterFactory->unregisterWidget( widget ); | 453 | _splitterFactory->unregisterWidget( widget ); | ||
441 | _blurHelper->unregisterWidget( widget ); | 454 | _blurHelper->unregisterWidget( widget ); | ||
455 | _toolsAreaManager->unregisterWidget ( widget ); | ||||
442 | 456 | | |||
443 | // remove event filter | 457 | // remove event filter | ||
444 | if( qobject_cast<QAbstractScrollArea*>( widget ) || | 458 | if( qobject_cast<QAbstractScrollArea*>( widget ) || | ||
445 | qobject_cast<QDockWidget*>( widget ) || | 459 | qobject_cast<QDockWidget*>( widget ) || | ||
446 | qobject_cast<QMdiSubWindow*>( widget ) || | 460 | qobject_cast<QMdiSubWindow*>( widget ) || | ||
447 | widget->inherits( "QComboBoxPrivateContainer" ) ) | 461 | widget->inherits( "QComboBoxPrivateContainer" ) ) | ||
448 | { widget->removeEventFilter( this ); } | 462 | { widget->removeEventFilter( this ); } | ||
449 | 463 | | |||
▲ Show 20 Lines • Show All 389 Lines • ▼ Show 20 Line(s) | 831 | { | |||
839 | case PE_Frame: fcn = &Style::drawFramePrimitive; break; | 853 | case PE_Frame: fcn = &Style::drawFramePrimitive; break; | ||
840 | case PE_FrameLineEdit: fcn = &Style::drawFrameLineEditPrimitive; break; | 854 | case PE_FrameLineEdit: fcn = &Style::drawFrameLineEditPrimitive; break; | ||
841 | case PE_FrameMenu: fcn = &Style::drawFrameMenuPrimitive; break; | 855 | case PE_FrameMenu: fcn = &Style::drawFrameMenuPrimitive; break; | ||
842 | case PE_FrameGroupBox: fcn = &Style::drawFrameGroupBoxPrimitive; break; | 856 | case PE_FrameGroupBox: fcn = &Style::drawFrameGroupBoxPrimitive; break; | ||
843 | case PE_FrameTabWidget: fcn = &Style::drawFrameTabWidgetPrimitive; break; | 857 | case PE_FrameTabWidget: fcn = &Style::drawFrameTabWidgetPrimitive; break; | ||
844 | case PE_FrameTabBarBase: fcn = &Style::drawFrameTabBarBasePrimitive; break; | 858 | case PE_FrameTabBarBase: fcn = &Style::drawFrameTabBarBasePrimitive; break; | ||
845 | case PE_FrameWindow: fcn = &Style::drawFrameWindowPrimitive; break; | 859 | case PE_FrameWindow: fcn = &Style::drawFrameWindowPrimitive; break; | ||
846 | case PE_FrameFocusRect: fcn = _frameFocusPrimitive; break; | 860 | case PE_FrameFocusRect: fcn = _frameFocusPrimitive; break; | ||
861 | case PE_Widget: fcn = &Style::drawWidgetPrimitive; break; | ||||
847 | 862 | | |||
848 | // fallback | 863 | // fallback | ||
849 | default: break; | 864 | default: break; | ||
850 | 865 | | |||
851 | } | 866 | } | ||
852 | 867 | | |||
853 | painter->save(); | 868 | painter->save(); | ||
854 | 869 | | |||
855 | // call function if implemented | 870 | // call function if implemented | ||
856 | if( !( fcn && fcn( *this, option, painter, widget ) ) ) | 871 | if( !( fcn && fcn( *this, option, painter, widget ) ) ) | ||
857 | { ParentStyleClass::drawPrimitive( element, option, painter, widget ); } | 872 | { ParentStyleClass::drawPrimitive( element, option, painter, widget ); } | ||
858 | 873 | | |||
859 | painter->restore(); | 874 | painter->restore(); | ||
860 | 875 | | |||
861 | } | 876 | } | ||
862 | 877 | | |||
878 | 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… | |||||
879 | Q_UNUSED(option) | ||||
880 | if (qobject_cast<const QMainWindow*>(widget) || qobject_cast<const QDialog*> (widget)) { | ||||
881 | if (!_helper->toolsAreaHasContents(widget) && _helper->shouldDrawToolsArea(widget)) { | ||||
Just "setPen( _helper-> ...) hpereiradacosta: Just "setPen( _helper-> ...)
you don't need the temporary QPen if it has a width 1. | |||||
882 | painter->setPen(_helper->toolsAreaBorderColor(widget)); | ||||
883 | painter->setRenderHints(QPainter::Antialiasing, false); | ||||
hpereiradacosta: Same remark | |||||
884 | painter->setBrush(Qt::NoBrush); | ||||
885 | | ||||
886 | painter->drawLine( | ||||
887 | widget->rect().left()*2, | ||||
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… | |||||
888 | widget->rect().top(), | ||||
889 | widget->rect().right()*2, | ||||
890 | widget->rect().top() | ||||
891 | ); | ||||
892 | } | ||||
893 | } | ||||
894 | return true; | ||||
895 | } | ||||
896 | | ||||
863 | //______________________________________________________________ | 897 | //______________________________________________________________ | ||
864 | void Style::drawControl( ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | 898 | void Style::drawControl( ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | ||
865 | { | 899 | { | ||
866 | 900 | | |||
867 | StyleControl fcn; | 901 | StyleControl fcn; | ||
davidre: Stray qdebug | |||||
868 | 902 | | |||
869 | #if BREEZE_HAVE_KSTYLE | 903 | #if BREEZE_HAVE_KSTYLE | ||
870 | if( element == CE_CapacityBar ) | 904 | if( element == CE_CapacityBar ) | ||
871 | { | 905 | { | ||
872 | fcn = &Style::drawProgressBarControl; | 906 | fcn = &Style::drawProgressBarControl; | ||
873 | 907 | | |||
874 | } else | 908 | } else | ||
875 | #endif | 909 | #endif | ||
876 | 910 | | |||
877 | switch( element ) { | 911 | switch( element ) { | ||
878 | 912 | | |||
879 | case CE_PushButtonBevel: fcn = &Style::drawPanelButtonCommandPrimitive; break; | 913 | case CE_PushButtonBevel: fcn = &Style::drawPanelButtonCommandPrimitive; break; | ||
880 | case CE_PushButtonLabel: fcn = &Style::drawPushButtonLabelControl; break; | 914 | case CE_PushButtonLabel: fcn = &Style::drawPushButtonLabelControl; break; | ||
881 | case CE_CheckBoxLabel: fcn = &Style::drawCheckBoxLabelControl; break; | 915 | case CE_CheckBoxLabel: fcn = &Style::drawCheckBoxLabelControl; break; | ||
882 | case CE_RadioButtonLabel: fcn = &Style::drawCheckBoxLabelControl; break; | 916 | case CE_RadioButtonLabel: fcn = &Style::drawCheckBoxLabelControl; break; | ||
883 | case CE_ToolButtonLabel: fcn = &Style::drawToolButtonLabelControl; break; | 917 | case CE_ToolButtonLabel: fcn = &Style::drawToolButtonLabelControl; break; | ||
884 | case CE_ComboBoxLabel: fcn = &Style::drawComboBoxLabelControl; break; | 918 | case CE_ComboBoxLabel: fcn = &Style::drawComboBoxLabelControl; break; | ||
885 | case CE_MenuBarEmptyArea: fcn = &Style::emptyControl; break; | 919 | case CE_MenuBarEmptyArea: fcn = &Style::drawMenuBarEmptyAreaControl; break; | ||
886 | case CE_MenuBarItem: fcn = &Style::drawMenuBarItemControl; break; | 920 | case CE_MenuBarItem: fcn = &Style::drawMenuBarItemControl; break; | ||
887 | case CE_MenuItem: fcn = &Style::drawMenuItemControl; break; | 921 | case CE_MenuItem: fcn = &Style::drawMenuItemControl; break; | ||
888 | case CE_ToolBar: fcn = &Style::emptyControl; break; | 922 | case CE_ToolBar: fcn = &Style::drawToolBarControl; break; | ||
889 | case CE_ProgressBar: fcn = &Style::drawProgressBarControl; break; | 923 | case CE_ProgressBar: fcn = &Style::drawProgressBarControl; break; | ||
890 | case CE_ProgressBarContents: fcn = &Style::drawProgressBarContentsControl; break; | 924 | case CE_ProgressBarContents: fcn = &Style::drawProgressBarContentsControl; break; | ||
891 | case CE_ProgressBarGroove: fcn = &Style::drawProgressBarGrooveControl; break; | 925 | case CE_ProgressBarGroove: fcn = &Style::drawProgressBarGrooveControl; break; | ||
892 | case CE_ProgressBarLabel: fcn = &Style::drawProgressBarLabelControl; break; | 926 | case CE_ProgressBarLabel: fcn = &Style::drawProgressBarLabelControl; break; | ||
893 | case CE_ScrollBarSlider: fcn = &Style::drawScrollBarSliderControl; break; | 927 | case CE_ScrollBarSlider: fcn = &Style::drawScrollBarSliderControl; break; | ||
894 | case CE_ScrollBarAddLine: fcn = &Style::drawScrollBarAddLineControl; break; | 928 | case CE_ScrollBarAddLine: fcn = &Style::drawScrollBarAddLineControl; break; | ||
895 | case CE_ScrollBarSubLine: fcn = &Style::drawScrollBarSubLineControl; break; | 929 | case CE_ScrollBarSubLine: fcn = &Style::drawScrollBarSubLineControl; break; | ||
896 | case CE_ScrollBarAddPage: fcn = &Style::emptyControl; break; | 930 | case CE_ScrollBarAddPage: fcn = &Style::emptyControl; break; | ||
▲ Show 20 Lines • Show All 429 Lines • ▼ Show 20 Line(s) | |||||
1326 | { | 1360 | { | ||
1327 | 1361 | | |||
1328 | // reload | 1362 | // reload | ||
1329 | StyleConfigData::self()->load(); | 1363 | StyleConfigData::self()->load(); | ||
1330 | 1364 | | |||
1331 | // reload configuration | 1365 | // reload configuration | ||
1332 | loadConfiguration(); | 1366 | loadConfiguration(); | ||
1333 | 1367 | | |||
1368 | // load new titlebar colours into tools area animations | ||||
1369 | _toolsAreaManager->updateAnimations(); | ||||
1370 | | ||||
1371 | // trigger update of tools area | ||||
1372 | emit _toolsAreaManager->toolbarUpdated(); | ||||
1373 | | ||||
1334 | } | 1374 | } | ||
1335 | 1375 | | |||
1336 | //____________________________________________________________________ | 1376 | //____________________________________________________________________ | ||
1337 | QIcon Style::standardIconImplementation( StandardPixmap standardPixmap, const QStyleOption* option, const QWidget* widget ) const | 1377 | QIcon Style::standardIconImplementation( StandardPixmap standardPixmap, const QStyleOption* option, const QWidget* widget ) const | ||
1338 | { | 1378 | { | ||
1339 | 1379 | | |||
1340 | // lookup cache | 1380 | // lookup cache | ||
1341 | if( _iconCache.contains( standardPixmap ) ) return _iconCache.value( standardPixmap ); | 1381 | if( _iconCache.contains( standardPixmap ) ) return _iconCache.value( standardPixmap ); | ||
▲ Show 20 Lines • Show All 2878 Lines • ▼ Show 20 Line(s) | |||||
4220 | bool Style::drawToolButtonLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | 4260 | bool Style::drawToolButtonLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | ||
4221 | { | 4261 | { | ||
4222 | 4262 | | |||
4223 | // cast option and check | 4263 | // cast option and check | ||
4224 | const auto toolButtonOption( qstyleoption_cast<const QStyleOptionToolButton*>(option) ); | 4264 | const auto toolButtonOption( qstyleoption_cast<const QStyleOptionToolButton*>(option) ); | ||
4225 | 4265 | | |||
4226 | // copy rect and palette | 4266 | // copy rect and palette | ||
4227 | const auto& rect = option->rect; | 4267 | const auto& rect = option->rect; | ||
4228 | const auto& palette = option->palette; | 4268 | auto palette = option->palette; | ||
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… | |||||
4269 | | ||||
4270 | if (_helper->isInToolsArea(widget)) { | ||||
4271 | palette.setColor(QPalette::ButtonText, _helper->titleBarTextColor(widget->isActiveWindow())); | ||||
4272 | palette.setColor(QPalette::WindowText, _helper->titleBarTextColor(widget->isActiveWindow())); | ||||
4273 | } | ||||
4229 | 4274 | | |||
4230 | // state | 4275 | // state | ||
4231 | const State& state( option->state ); | 4276 | const State& state( option->state ); | ||
4232 | const bool enabled( state & State_Enabled ); | 4277 | const bool enabled( state & State_Enabled ); | ||
4233 | const bool sunken( state & (State_On | State_Sunken) ); | 4278 | const bool sunken( state & (State_On | State_Sunken) ); | ||
4234 | const bool mouseOver( enabled && (option->state & State_MouseOver) ); | 4279 | const bool mouseOver( enabled && (option->state & State_MouseOver) ); | ||
4235 | const bool flat( state & State_AutoRaise ); | 4280 | const bool flat( state & State_AutoRaise ); | ||
4236 | 4281 | | |||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 4325 | } else { | |||
4299 | 4344 | | |||
4300 | textFlags |= Qt::AlignLeft | Qt::AlignVCenter; | 4345 | textFlags |= Qt::AlignLeft | Qt::AlignVCenter; | ||
4301 | 4346 | | |||
4302 | } | 4347 | } | ||
4303 | 4348 | | |||
4304 | // make sure there is enough room for icon | 4349 | // make sure there is enough room for icon | ||
4305 | if( iconRect.isValid() ) iconRect = centerRect( iconRect, iconSize ); | 4350 | if( iconRect.isValid() ) iconRect = centerRect( iconRect, iconSize ); | ||
4306 | 4351 | | |||
4307 | // render arrow or icon | 4352 | // 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() ) | 4353 | if( hasArrow && iconRect.isValid() ) | ||
4309 | { | 4354 | { | ||
4310 | 4355 | | |||
4311 | QStyleOptionToolButton copy( *toolButtonOption ); | 4356 | QStyleOptionToolButton copy( *toolButtonOption ); | ||
4312 | copy.rect = iconRect; | 4357 | copy.rect = iconRect; | ||
4313 | switch( toolButtonOption->arrowType ) | 4358 | switch( toolButtonOption->arrowType ) | ||
4314 | { | 4359 | { | ||
4315 | case Qt::LeftArrow: drawPrimitive( PE_IndicatorArrowLeft, ©, painter, widget ); break; | 4360 | case Qt::LeftArrow: drawPrimitive( PE_IndicatorArrowLeft, ©, painter, widget ); break; | ||
4316 | case Qt::RightArrow: drawPrimitive( PE_IndicatorArrowRight, ©, painter, widget ); break; | 4361 | case Qt::RightArrow: drawPrimitive( PE_IndicatorArrowRight, ©, painter, widget ); break; | ||
4317 | case Qt::UpArrow: drawPrimitive( PE_IndicatorArrowUp, ©, painter, widget ); break; | 4362 | case Qt::UpArrow: drawPrimitive( PE_IndicatorArrowUp, ©, painter, widget ); break; | ||
4318 | case Qt::DownArrow: drawPrimitive( PE_IndicatorArrowDown, ©, painter, widget ); break; | 4363 | case Qt::DownArrow: drawPrimitive( PE_IndicatorArrowDown, ©, painter, widget ); break; | ||
4319 | default: break; | 4364 | default: break; | ||
4320 | } | 4365 | } | ||
4321 | 4366 | | |||
4322 | } else if( hasIcon && iconRect.isValid() ) { | 4367 | } else if( hasIcon && iconRect.isValid() ) { | ||
4323 | 4368 | | |||
4324 | // icon state and mode | 4369 | // icon state and mode | ||
4325 | const QIcon::State iconState( sunken ? QIcon::On : QIcon::Off ); | 4370 | const QIcon::State iconState( sunken ? QIcon::On : QIcon::Off ); | ||
4326 | QIcon::Mode iconMode; | 4371 | QIcon::Mode iconMode; | ||
4327 | if( !enabled ) iconMode = QIcon::Disabled; | 4372 | if( !enabled ) iconMode = QIcon::Disabled; | ||
4328 | else if( (!flat && hasFocus) || (flat && (state & State_Sunken) && !mouseOver) ) iconMode = QIcon::Selected; | 4373 | else if( (!flat && hasFocus) || (flat && (state & State_Sunken) && !mouseOver) ) iconMode = QIcon::Selected; | ||
4329 | else if( mouseOver && flat ) iconMode = QIcon::Active; | 4374 | else if( mouseOver && flat ) iconMode = QIcon::Active; | ||
4330 | else iconMode = QIcon::Normal; | 4375 | else iconMode = QIcon::Normal; | ||
4331 | 4376 | | |||
4332 | const QPixmap pixmap = toolButtonOption->icon.pixmap( iconSize, iconMode, iconState ); | 4377 | QPixmap pixmap = toolButtonOption->icon.pixmap( iconSize, iconMode, iconState ); | ||
4378 | if (_helper->isInToolsArea(widget)) { | ||||
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. | |||||
4379 | KIconLoader::global()->setCustomPalette(widget->palette()); | ||||
4380 | pixmap = toolButtonOption->icon.pixmap( iconSize, iconMode, iconState ); | ||||
4381 | KIconLoader::global()->resetPalette(); | ||||
4382 | } | ||||
4333 | drawItemPixmap( painter, iconRect, Qt::AlignCenter, pixmap ); | 4383 | drawItemPixmap( painter, iconRect, Qt::AlignCenter, pixmap ); | ||
4334 | 4384 | | |||
4335 | } | 4385 | } | ||
4336 | 4386 | | |||
4337 | // render text | 4387 | // render text | ||
4338 | if( hasText && textRect.isValid() ) | 4388 | if( hasText && textRect.isValid() ) | ||
4339 | { | 4389 | { | ||
4340 | | ||||
4341 | QPalette::ColorRole textRole( QPalette::ButtonText ); | 4390 | QPalette::ColorRole textRole( QPalette::ButtonText ); | ||
4342 | if( flat ) textRole = ( ((hasFocus&&sunken) || (state & State_Sunken))&&!mouseOver) ? QPalette::HighlightedText: QPalette::WindowText; | 4391 | if( flat ) textRole = ( ((hasFocus&&sunken) || (state & State_Sunken))&&!mouseOver) ? QPalette::HighlightedText: QPalette::WindowText; | ||
4343 | else if( hasFocus&&!mouseOver ) textRole = QPalette::HighlightedText; | 4392 | else if( hasFocus&&!mouseOver ) textRole = QPalette::HighlightedText; | ||
4344 | 4393 | | |||
4345 | painter->setFont(toolButtonOption->font); | 4394 | painter->setFont(toolButtonOption->font); | ||
4346 | drawItemText( painter, textRect, textFlags, palette, enabled, toolButtonOption->text, textRole ); | 4395 | drawItemText( painter, textRect, textFlags, palette, enabled, toolButtonOption->text, textRole ); | ||
4347 | 4396 | | |||
4348 | } | 4397 | } | ||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Line(s) | 4521 | #endif | |||
4504 | { | 4553 | { | ||
4505 | 4554 | | |||
4506 | // cast option and check | 4555 | // cast option and check | ||
4507 | const auto menuItemOption = qstyleoption_cast<const QStyleOptionMenuItem*>( option ); | 4556 | const auto menuItemOption = qstyleoption_cast<const QStyleOptionMenuItem*>( option ); | ||
4508 | if( !menuItemOption ) return true; | 4557 | if( !menuItemOption ) return true; | ||
4509 | 4558 | | |||
4510 | // copy rect and palette | 4559 | // copy rect and palette | ||
4511 | const auto& rect( option->rect ); | 4560 | const auto& rect( option->rect ); | ||
4512 | const auto& palette( option->palette ); | 4561 | auto palette( option->palette ); | ||
4562 | | ||||
4563 | palette.setColor(QPalette::WindowText, _helper->titleBarTextColor(widget->isActiveWindow())); | ||||
4513 | 4564 | | |||
4514 | // store state | 4565 | // store state | ||
4515 | const State& state( option->state ); | 4566 | const State& state( option->state ); | ||
4516 | const bool enabled( state & State_Enabled ); | 4567 | const bool enabled( state & State_Enabled ); | ||
4517 | const bool selected( enabled && (state & State_Selected) ); | 4568 | const bool selected( enabled && (state & State_Selected) ); | ||
4518 | const bool sunken( enabled && (state & State_Sunken) ); | 4569 | const bool sunken( enabled && (state & State_Sunken) ); | ||
4519 | const bool useStrongFocus( StyleConfigData::menuItemDrawStrongFocus() ); | 4570 | const bool useStrongFocus( StyleConfigData::menuItemDrawStrongFocus() ); | ||
4520 | 4571 | | |||
4572 | painter->save(); | ||||
4573 | painter->setRenderHints( QPainter::Antialiasing ); | ||||
4574 | | ||||
4575 | painter->setPen(_helper->titleBarColor(widget->isActiveWindow())); | ||||
4576 | painter->setBrush(_helper->titleBarColor(widget->isActiveWindow())); | ||||
4577 | | ||||
4578 | painter->drawRect(option->rect); | ||||
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… | |||||
4579 | | ||||
4521 | // render hover and focus | 4580 | // render hover and focus | ||
4522 | if( useStrongFocus && ( selected || sunken ) ) | 4581 | if( useStrongFocus && ( selected || sunken ) ) | ||
4523 | { | 4582 | { | ||
4524 | 4583 | | |||
4525 | QColor outlineColor; | 4584 | QColor outlineColor; | ||
4526 | if( sunken ) outlineColor = _helper->focusColor( palette ); | 4585 | if( sunken ) outlineColor = _helper->focusColor( palette ); | ||
4527 | else if( selected ) outlineColor = _helper->hoverColor( palette ); | 4586 | else if( selected ) outlineColor = _helper->hoverColor( palette ); | ||
4528 | _helper->renderFocusRect( painter, rect, outlineColor ); | 4587 | _helper->renderFocusRect( painter, rect, outlineColor ); | ||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 4646 | { | |||
4591 | else if( selected ) outlineColor = _helper->hoverColor( palette ); | 4650 | else if( selected ) outlineColor = _helper->hoverColor( palette ); | ||
4592 | 4651 | | |||
4593 | _helper->renderFocusLine( painter, textRect, outlineColor ); | 4652 | _helper->renderFocusLine( painter, textRect, outlineColor ); | ||
4594 | 4653 | | |||
4595 | } | 4654 | } | ||
4596 | 4655 | | |||
4597 | } | 4656 | } | ||
4598 | 4657 | | |||
4599 | return true; | 4658 | if (!_helper->toolsAreaHasToolBar(widget)) { | ||
4659 | _helper->renderToolsAreaBorder(painter, widget, true); | ||||
4660 | } | ||||
4661 | | ||||
4662 | painter->restore(); | ||||
4600 | 4663 | | |||
4664 | return true; | ||||
4601 | } | 4665 | } | ||
4602 | 4666 | | |||
4603 | 4667 | | |||
4604 | //___________________________________________________________________________________ | 4668 | //___________________________________________________________________________________ | ||
4605 | bool Style::drawMenuItemControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | 4669 | bool Style::drawMenuItemControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | ||
4606 | { | 4670 | { | ||
4607 | 4671 | | |||
4608 | // cast option and check | 4672 | // cast option and check | ||
▲ Show 20 Lines • Show All 203 Lines • ▼ Show 20 Line(s) | 4837 | { | |||
4812 | 4876 | | |||
4813 | } | 4877 | } | ||
4814 | 4878 | | |||
4815 | } | 4879 | } | ||
4816 | 4880 | | |||
4817 | return true; | 4881 | return true; | ||
4818 | } | 4882 | } | ||
4819 | 4883 | | |||
4884 | bool Style::drawToolBarControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | ||||
4885 | { | ||||
4886 | auto toolbar = const_cast<QWidget*>(widget); | ||||
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… | |||||
4887 | | ||||
4888 | if (!_helper->isInToolsArea(widget)) { | ||||
4889 | if (_toolsAreaManager->widgetsWithPaletteForToolsAreaSet()->contains(toolbar)) { | ||||
4890 | toolbar->setPalette(toolbar->parentWidget()->palette()); | ||||
Same remark. This is very innefficient. hpereiradacosta: Same remark. This is very innefficient.
You need to track whether the palette actually need… | |||||
4891 | _toolsAreaManager->widgetsWithPaletteForToolsAreaSet()->removeOne(toolbar); | ||||
4892 | } | ||||
4893 | return true; | ||||
4894 | } | ||||
4895 | | ||||
4896 | if (!_toolsAreaManager->widgetsWithPaletteForToolsAreaSet()->contains(toolbar)) { | ||||
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. | |||||
4897 | auto palette = toolbar->palette(); | ||||
4898 | palette.setColor( QPalette::Window, _toolsAreaManager->background(widget) ); | ||||
hpereiradacosta: same remark | |||||
4899 | palette.setColor( QPalette::WindowText, _toolsAreaManager->foreground(widget) ); | ||||
4900 | toolbar->setPalette(palette); | ||||
4901 | _toolsAreaManager->widgetsWithPaletteForToolsAreaSet()->append(toolbar); | ||||
4902 | } | ||||
4903 | | ||||
4904 | painter->save(); | ||||
4905 | painter->setRenderHints( QPainter::Antialiasing ); | ||||
hpereiradacosta: same remark about option being unused | |||||
4906 | | ||||
hpereiradacosta: Same remark as above. | |||||
4907 | painter->setBrush(_toolsAreaManager->background(widget)); | ||||
4908 | painter->setPen(Qt::NoPen); | ||||
4909 | | ||||
4910 | painter->drawRect(option->rect); | ||||
4911 | | ||||
4912 | _helper->renderToolsAreaBorder(painter, widget); | ||||
4913 | | ||||
4914 | painter->restore(); | ||||
4915 | return true; | ||||
4916 | } | ||||
4917 | | ||||
4918 | bool Style::drawMenuBarEmptyAreaControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | ||||
4919 | { | ||||
4920 | if (!_helper->isInToolsArea(widget)) { | ||||
4921 | return true; | ||||
4922 | } | ||||
4923 | | ||||
4924 | painter->save(); | ||||
4925 | painter->setRenderHints( QPainter::Antialiasing ); | ||||
4926 | | ||||
4927 | painter->setPen(_helper->titleBarColor(widget->isActiveWindow())); | ||||
4928 | painter->setBrush(_helper->titleBarColor(widget->isActiveWindow())); | ||||
4929 | | ||||
4930 | painter->drawRect(option->rect); | ||||
4931 | | ||||
4932 | if (!_helper->toolsAreaHasToolBar(widget)) { | ||||
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. | |||||
4933 | _helper->renderToolsAreaBorder(painter, widget, true); | ||||
4934 | } | ||||
4935 | | ||||
4936 | painter->restore(); | ||||
4937 | return true; | ||||
4938 | } | ||||
4939 | | ||||
4820 | //___________________________________________________________________________________ | 4940 | //___________________________________________________________________________________ | ||
4821 | bool Style::drawProgressBarControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | 4941 | bool Style::drawProgressBarControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | ||
4822 | { | 4942 | { | ||
4823 | 4943 | | |||
4824 | const auto progressBarOption( qstyleoption_cast<const QStyleOptionProgressBar*>( option ) ); | 4944 | const auto progressBarOption( qstyleoption_cast<const QStyleOptionProgressBar*>( option ) ); | ||
4825 | if( !progressBarOption ) return true; | 4945 | if( !progressBarOption ) return true; | ||
4826 | 4946 | | |||
4827 | // render groove | 4947 | // render groove | ||
▲ Show 20 Lines • Show All 2314 Lines • Show Last 20 Lines |
Not needed