Changeset View
Changeset View
Standalone View
Standalone View
kcms/style/previewitem.cpp
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | 78 | { | |||
---|---|---|---|---|---|
85 | emit styleNameChanged(); | 85 | emit styleNameChanged(); | ||
86 | } | 86 | } | ||
87 | 87 | | |||
88 | bool PreviewItem::isValid() const | 88 | bool PreviewItem::isValid() const | ||
89 | { | 89 | { | ||
90 | return m_style && m_widget; | 90 | return m_style && m_widget; | ||
91 | } | 91 | } | ||
92 | 92 | | |||
93 | void setStyleRecursively(QWidget *widget, QStyle *style) | 93 | void setStyleRecursively(QWidget *widget, QStyle *style, const QPalette &palette) | ||
94 | { | 94 | { | ||
95 | // Don't let styles kill the palette for other styles being previewed. | 95 | // Don't let styles kill the palette for other styles being previewed. | ||
96 | widget->setPalette(QPalette()); | 96 | widget->setPalette(QPalette()); | ||
97 | 97 | widget->setPalette(palette); | |||
98 | QPalette newPalette(KColorScheme::createApplicationPalette(KSharedConfig::openConfig())); | | |||
99 | style->polish(newPalette); | | |||
100 | | ||||
101 | widget->setPalette(newPalette); | | |||
102 | 98 | | |||
103 | widget->setStyle(style); | 99 | widget->setStyle(style); | ||
104 | 100 | | |||
105 | const auto children = widget->children(); | 101 | const auto children = widget->children(); | ||
106 | for (QObject *child : children) { | 102 | for (QObject *child : children) { | ||
107 | if (child->isWidgetType()) { | 103 | if (child->isWidgetType()) { | ||
108 | setStyleRecursively(static_cast<QWidget *>(child), style); | 104 | setStyleRecursively(static_cast<QWidget *>(child), style, palette); | ||
109 | } | 105 | } | ||
110 | } | 106 | } | ||
111 | } | 107 | } | ||
112 | 108 | | |||
113 | void PreviewItem::reload() | 109 | void PreviewItem::reload() | ||
114 | { | 110 | { | ||
115 | if (!isComponentComplete()) { | 111 | if (!isComponentComplete()) { | ||
116 | return; | 112 | return; | ||
Show All 16 Lines | |||||
133 | // Do not wait for this widget to close before the app closes | 129 | // Do not wait for this widget to close before the app closes | ||
134 | m_widget->setAttribute(Qt::WA_QuitOnClose, false); | 130 | m_widget->setAttribute(Qt::WA_QuitOnClose, false); | ||
135 | 131 | | |||
136 | m_ui.setupUi(m_widget.data()); | 132 | m_ui.setupUi(m_widget.data()); | ||
137 | 133 | | |||
138 | // Prevent Qt from wrongly caching radio button images | 134 | // Prevent Qt from wrongly caching radio button images | ||
139 | QPixmapCache::clear(); | 135 | QPixmapCache::clear(); | ||
140 | 136 | | |||
141 | setStyleRecursively(m_widget.data(), m_style.data()); | 137 | QPalette palette(KColorScheme::createApplicationPalette(KSharedConfig::openConfig())); | ||
138 | m_style->polish(palette); | ||||
139 | | ||||
140 | // HACK Needed so the previews look like their window is active | ||||
141 | // The previews don't have a parent (we're in QML, after all, there is no QWidget* to parent it to) | ||||
142 | // so QWidget::isActiveWindow() always returns false making the widget look dull | ||||
143 | // You still won't get hover effects in some themes (those that don't do that for inactive windows) | ||||
144 | // but at least at a glance it looks fine... | ||||
145 | for (int i = 0; i < QPalette::NColorRoles; ++i) { | ||||
146 | const auto role = static_cast<QPalette::ColorRole>(i); | ||||
147 | palette.setColor(QPalette::Inactive, role, palette.color(QPalette::Active, role)); | ||||
148 | } | ||||
149 | | ||||
150 | setStyleRecursively(m_widget.data(), m_style.data(), palette); | ||||
142 | 151 | | |||
143 | m_widget->ensurePolished(); | 152 | m_widget->ensurePolished(); | ||
144 | 153 | | |||
145 | const auto sizeHint = m_widget->sizeHint(); | 154 | const auto sizeHint = m_widget->sizeHint(); | ||
146 | setImplicitSize(sizeHint.width(), sizeHint.height()); | 155 | setImplicitSize(sizeHint.width(), sizeHint.height()); | ||
147 | 156 | | |||
148 | m_widget->resize(qRound(width()), qRound(height())); | 157 | m_widget->resize(qRound(width()), qRound(height())); | ||
149 | 158 | | |||
▲ Show 20 Lines • Show All 146 Lines • Show Last 20 Lines |