File indexing completed on 2024-12-22 05:15:44
0001 /* Preview widget for KDE Display color scheme setup module 0002 SPDX-FileCopyrightText: 2007 Matthew Woehlke <mw_triad@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2007 Urs Wolfer <uwolfer@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "setpreviewwidget.h" 0009 0010 void setAutoFill(QWidget *widget) 0011 { 0012 widget->setAutoFillBackground(true); 0013 widget->setBackgroundRole(QPalette::Base); 0014 } 0015 0016 SetPreviewWidget::SetPreviewWidget(QWidget *parent) 0017 : QFrame(parent) 0018 { 0019 setupUi(this); 0020 0021 // set correct colors on... lots of things 0022 setAutoFillBackground(true); 0023 setBackgroundRole(QPalette::Base); 0024 setAutoFill(widgetBack0); 0025 setAutoFill(widgetBack1); 0026 setAutoFill(widgetBack2); 0027 setAutoFill(widgetBack3); 0028 setAutoFill(widgetBack4); 0029 setAutoFill(widgetBack5); 0030 setAutoFill(widgetBack6); 0031 setAutoFill(widgetBack7); 0032 setAutoFillBackground(true); 0033 /* 0034 frame->setBackgroundRole(QPalette::Base); 0035 viewWidget->setBackgroundRole(QPalette::Base); 0036 labelView0->setBackgroundRole(QPalette::Base); 0037 labelView3->setBackgroundRole(QPalette::Base); 0038 labelView4->setBackgroundRole(QPalette::Base); 0039 labelView2->setBackgroundRole(QPalette::Base); 0040 labelView1->setBackgroundRole(QPalette::Base); 0041 labelView5->setBackgroundRole(QPalette::Base); 0042 labelView6->setBackgroundRole(QPalette::Base); 0043 labelView7->setBackgroundRole(QPalette::Base); 0044 selectionWidget->setBackgroundRole(QPalette::Highlight); 0045 labelSelection0->setBackgroundRole(QPalette::Highlight); 0046 labelSelection3->setBackgroundRole(QPalette::Highlight); 0047 labelSelection4->setBackgroundRole(QPalette::Highlight); 0048 labelSelection2->setBackgroundRole(QPalette::Highlight); 0049 labelSelection1->setBackgroundRole(QPalette::Highlight); 0050 labelSelection5->setBackgroundRole(QPalette::Highlight); 0051 labelSelection6->setBackgroundRole(QPalette::Highlight); 0052 labelSelection7->setBackgroundRole(QPalette::Highlight); 0053 */ 0054 0055 const QList<QWidget *> widgets = findChildren<QWidget *>(); 0056 for (QWidget *widget : widgets) { 0057 widget->installEventFilter(this); 0058 widget->setFocusPolicy(Qt::NoFocus); 0059 } 0060 } 0061 0062 SetPreviewWidget::~SetPreviewWidget() 0063 { 0064 } 0065 0066 bool SetPreviewWidget::eventFilter(QObject *, QEvent *ev) 0067 { 0068 switch (ev->type()) { 0069 case QEvent::MouseButtonPress: 0070 case QEvent::MouseButtonRelease: 0071 case QEvent::MouseButtonDblClick: 0072 case QEvent::MouseMove: 0073 case QEvent::KeyPress: 0074 case QEvent::KeyRelease: 0075 case QEvent::Enter: 0076 case QEvent::Leave: 0077 case QEvent::Wheel: 0078 case QEvent::ContextMenu: 0079 return true; // ignore 0080 default: 0081 break; 0082 } 0083 return false; 0084 } 0085 0086 void SetPreviewWidget::setPalette(const KSharedConfigPtr &config, KColorScheme::ColorSet set) 0087 { 0088 QPalette palette = KColorScheme::createApplicationPalette(config); 0089 KColorScheme::adjustBackground(palette, KColorScheme::NormalBackground, QPalette::Base, set, config); 0090 QFrame::setPalette(palette); 0091 0092 #define SET_ROLE_PALETTE(n, f, b) \ 0093 KColorScheme::adjustForeground(palette, KColorScheme::f, QPalette::Text, set, config); \ 0094 labelFore##n->setPalette(palette); \ 0095 KColorScheme::adjustBackground(palette, KColorScheme::b, QPalette::Base, set, config); \ 0096 labelBack##n->setPalette(palette); \ 0097 widgetBack##n->setPalette(palette); 0098 0099 SET_ROLE_PALETTE(0, NormalText, NormalBackground); 0100 SET_ROLE_PALETTE(1, InactiveText, AlternateBackground); 0101 SET_ROLE_PALETTE(2, ActiveText, ActiveBackground); 0102 SET_ROLE_PALETTE(3, LinkText, LinkBackground); 0103 SET_ROLE_PALETTE(4, VisitedText, VisitedBackground); 0104 SET_ROLE_PALETTE(5, NegativeText, NegativeBackground); 0105 SET_ROLE_PALETTE(6, NeutralText, NeutralBackground); 0106 SET_ROLE_PALETTE(7, PositiveText, PositiveBackground); 0107 0108 KColorScheme kcs(QPalette::Active, set, config); 0109 QBrush deco; 0110 0111 #define SET_DECO_PALETTE(n, d) \ 0112 deco = kcs.decoration(KColorScheme::d); \ 0113 palette.setBrush(QPalette::Text, deco); \ 0114 labelFore##n->setPalette(palette); 0115 0116 SET_DECO_PALETTE(8, HoverColor); 0117 SET_DECO_PALETTE(9, FocusColor); 0118 }