Changeset View
Changeset View
Standalone View
Standalone View
src/kexiutils/style/KexiStyle.cpp
- This file was added.
1 | /* This file is part of the KDE project | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2016 Jarosław Staniek <staniek@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Library General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | * Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "KexiStyle.h" | ||||
21 | #include "KexiPropertyPaneLineEditStyle.h" | ||||
22 | #include "utils.h" | ||||
23 | | ||||
24 | #include <KLocalizedString> | ||||
25 | | ||||
26 | #include <KPropertyEditorView> | ||||
27 | | ||||
28 | #include <QApplication> | ||||
29 | #include <QComboBox> | ||||
30 | #include <QFile> | ||||
31 | #include <QFont> | ||||
32 | #include <QFormLayout> | ||||
33 | #include <QFrame> | ||||
34 | #include <QGridLayout> | ||||
35 | #include <QGuiApplication> | ||||
36 | #include <QIconEngine> | ||||
37 | #include <QLabel> | ||||
38 | #include <QLineEdit> | ||||
39 | #include <QModelIndex> | ||||
40 | #include <QPainter> | ||||
41 | #include <QStyleOptionViewItem> | ||||
42 | #include <QSvgRenderer> | ||||
43 | #include <QVBoxLayout> | ||||
44 | #include <QStyleFactory> | ||||
45 | | ||||
46 | namespace KexiStyle { | ||||
47 | | ||||
48 | KEXIUTILS_EXPORT bool setupApplication(KLocalizedString *errorMessage) | ||||
49 | { | ||||
50 | // Only this style matches current Kexi theme and can be supported. | ||||
51 | // @todo add support for more styles via theme plugins. | ||||
52 | const char *name = "breeze"; | ||||
53 | QScopedPointer<QStyle> style(QStyleFactory::create(name)); | ||||
54 | if (!style || style->objectName() != name) { | ||||
55 | *errorMessage = kxi18nc("@info", | ||||
56 | "<para>Could not find application style <resource>%1</resource>.</para>" | ||||
57 | "<para><application>Kexi</application> will not start. " | ||||
58 | "Please check if <application>Kexi</application> is properly installed.</para>") | ||||
59 | .subs(name); | ||||
60 | return false; | ||||
61 | } | ||||
62 | qApp->setStyle(style.take()); | ||||
63 | *errorMessage = KLocalizedString(); | ||||
64 | return true; | ||||
65 | } | ||||
66 | | ||||
67 | KEXIUTILS_EXPORT void setupFrame(QFrame *frame) | ||||
68 | { | ||||
69 | if (frame) { | ||||
70 | frame->setFrameStyle(QFrame::NoFrame); | ||||
71 | } | ||||
72 | } | ||||
73 | | ||||
74 | KEXIUTILS_EXPORT void setupGlobalViewModeSelector(QFrame *selector) | ||||
75 | { | ||||
76 | KexiStyle::setupFrame(selector); | ||||
77 | selector->setFont(KexiUtils::smallestReadableFont()); | ||||
78 | QPalette p(selector->palette()); | ||||
79 | p.setColor(QPalette::Window, KexiUtils::shadeBlack()); | ||||
80 | p.setColor(QPalette::Base, KexiUtils::shadeBlack()); | ||||
81 | p.setColor(QPalette::Button, KexiUtils::shadeBlack()); | ||||
82 | p.setColor(QPalette::AlternateBase, KexiUtils::shadeBlackLighter()); | ||||
83 | p.setColor(QPalette::WindowText, KexiUtils::cardboardGrey()); | ||||
84 | p.setColor(QPalette::ButtonText, KexiUtils::cardboardGrey()); | ||||
85 | p.setColor(QPalette::Text, KexiUtils::cardboardGrey()); | ||||
86 | p.setBrush(QPalette::Disabled, QPalette::Text, KexiUtils::iconGrey()); // yes, modes can be disabled | ||||
87 | //generic?? KColorScheme(QPalette::Disabled, KColorScheme::View).foreground()); | ||||
88 | p.setColor(QPalette::Highlight, KexiUtils::cardboardGrey()); | ||||
89 | p.setColor(QPalette::Active, QPalette::Highlight, KexiUtils::plasmaBlue()); // unused anyway because mode selector has no focus | ||||
90 | p.setColor(QPalette::HighlightedText, KexiUtils::charcoalGrey()); | ||||
91 | selector->setPalette(p); | ||||
92 | } | ||||
93 | | ||||
94 | KEXIUTILS_EXPORT void overpaintGlobalViewModeSelector(QWidget *widget, QPainter *painter, | ||||
95 | const QRect &selectedRect, | ||||
96 | const QColor &arrowColor) | ||||
97 | { | ||||
98 | // draw gradient | ||||
99 | painter->save(); | ||||
100 | int w = widget->fontMetrics().height() * 3 / 2; | ||||
101 | const bool rtl = QGuiApplication::isRightToLeft(); | ||||
102 | painter->translate(rtl ? 0 : (widget->width() - w), 0); | ||||
103 | QLinearGradient grad(0, 0, w, 0); | ||||
104 | QColor c(widget->palette().base().color()); | ||||
105 | c.setAlpha(0); | ||||
106 | grad.setColorAt(rtl ? 1.0 : 0.0, c); | ||||
107 | c.setAlpha(15); | ||||
108 | grad.setColorAt(0.5, c); | ||||
109 | grad.setColorAt(rtl ? 0.0 : 1.0, QColor(0, 0, 0, 50)); | ||||
110 | painter->fillRect(0, 0, w, widget->height(), QBrush(grad)); | ||||
111 | painter->restore(); | ||||
112 | | ||||
113 | // draw arrow: /| (or reversed for RTL) | ||||
114 | // \| | ||||
115 | if (!selectedRect.isNull()) { | ||||
116 | painter->save(); | ||||
117 | w = selectedRect.height() / 10; | ||||
118 | if (w % 2 == 0) { | ||||
119 | ++w; | ||||
120 | } | ||||
121 | painter->translate( | ||||
122 | selectedRect.x() + (rtl ? 0 : (selectedRect.width() - w)), | ||||
123 | selectedRect.y() + (selectedRect.height() - w * 2) / 2 - 0.5); | ||||
124 | QPolygon polygon; | ||||
125 | if (rtl) { | ||||
126 | polygon << QPoint(0, 0) << QPoint(w, w) << QPoint(0, w * 2); | ||||
127 | } else { | ||||
128 | polygon << QPoint(w, 0) << QPoint(w, w * 2) << QPoint(0, w); | ||||
129 | } | ||||
130 | painter->setPen(QPen(Qt::NoPen)); | ||||
131 | painter->setBrush(arrowColor); | ||||
132 | painter->drawPolygon(polygon); | ||||
133 | painter->restore(); | ||||
134 | } | ||||
135 | } | ||||
136 | | ||||
137 | KEXIUTILS_EXPORT void overpaintModeSelectorItem(QPainter *painter, | ||||
138 | const QStyleOptionViewItem &option, | ||||
139 | const QModelIndex &index) | ||||
140 | { | ||||
141 | Q_UNUSED(painter) | ||||
142 | Q_UNUSED(option) | ||||
143 | Q_UNUSED(index) | ||||
144 | } | ||||
145 | | ||||
146 | KEXIUTILS_EXPORT QPalette alternativePalette(const QPalette &palette) | ||||
147 | { | ||||
148 | QPalette p(palette); | ||||
149 | p.setColor(QPalette::Window, KexiUtils::charcoalGrey()); | ||||
150 | p.setColor(QPalette::Base, KexiUtils::shadeBlack()); | ||||
151 | p.setColor(QPalette::Disabled, QPalette::Base, KexiUtils::charcoalGrey()); | ||||
152 | p.setColor(QPalette::Button, KexiUtils::shadeBlack()); | ||||
153 | p.setColor(QPalette::AlternateBase, KexiUtils::shadeBlackLighter()); | ||||
154 | p.setColor(QPalette::WindowText, KexiUtils::paperWhite()); | ||||
155 | p.setColor(QPalette::Disabled, QPalette::WindowText, KexiUtils::iconGrey().lighter(125)); | ||||
156 | p.setColor(QPalette::ButtonText, KexiUtils::paperWhite()); | ||||
157 | p.setColor(QPalette::Disabled, QPalette::ButtonText, KexiUtils::cardboardGreyAlternative()); | ||||
158 | p.setColor(QPalette::Text, KexiUtils::paperWhite()); | ||||
159 | p.setColor(QPalette::Disabled, QPalette::Text, p.color(QPalette::Disabled, QPalette::WindowText)); | ||||
160 | p.setColor(QPalette::Highlight, KexiUtils::cardboardGrey()); | ||||
161 | p.setColor(QPalette::Active, QPalette::Highlight, KexiUtils::plasmaBlue()); | ||||
162 | p.setColor(QPalette::HighlightedText, KexiUtils::charcoalGrey()); | ||||
163 | p.setColor(QPalette::Active, QPalette::HighlightedText, KexiUtils::cardboardGrey()); | ||||
164 | return p; | ||||
165 | } | ||||
166 | | ||||
167 | KEXIUTILS_EXPORT QPalette sidebarsPalette(const QPalette &palette) | ||||
168 | { | ||||
169 | return alternativePalette(palette); | ||||
170 | } | ||||
171 | | ||||
172 | KEXIUTILS_EXPORT void setSidebarsPalette(QWidget *widget) | ||||
173 | { | ||||
174 | widget->setPalette(sidebarsPalette(widget->palette())); | ||||
175 | widget->setAutoFillBackground(true); | ||||
176 | } | ||||
177 | | ||||
178 | KEXIUTILS_EXPORT QFont titleFont(const QFont &font) | ||||
179 | { | ||||
180 | QFont newFont(font); | ||||
181 | newFont.setCapitalization(QFont::AllUppercase); | ||||
182 | return newFont; | ||||
183 | } | ||||
184 | | ||||
185 | static const QString g_contexts[] = { | ||||
186 | QLatin1String("actions"), // Any | ||||
187 | QLatin1String("actions"), | ||||
188 | QLatin1String("apps"), | ||||
189 | QLatin1String("devices"), | ||||
190 | QLatin1String("filesystems"), | ||||
191 | QLatin1String("mimetypes"), | ||||
192 | QLatin1String("animations"), | ||||
193 | QLatin1String("categories"), | ||||
194 | QLatin1String("emblems"), | ||||
195 | QLatin1String("emotes"), | ||||
196 | QLatin1String("intl"), | ||||
197 | QLatin1String("places"), | ||||
198 | QLatin1String("status") | ||||
199 | }; | ||||
200 | | ||||
201 | KEXIUTILS_EXPORT QIcon darkIcon(const QString &iconName, KIconLoader::Context iconContext) | ||||
202 | { | ||||
203 | Q_ASSERT(iconContext < (sizeof(g_contexts) / sizeof(g_contexts[0]))); | ||||
204 | static const QIcon::Mode modes[] = { QIcon::Normal }; //can be supported too: , QIcon::Selected }; | ||||
205 | const QString prefix(QLatin1String(":/icons/breeze/") | ||||
206 | + g_contexts[iconContext] + QLatin1Char('/')); | ||||
207 | const QString suffixes[] = { | ||||
208 | iconName + QLatin1String("@dark.svg"), | ||||
209 | iconName + QLatin1String(".svg") }; | ||||
210 | static const QString sizesStr[] = { | ||||
211 | QString::fromLatin1("32/"), // important: opposite direction | ||||
212 | QString::fromLatin1("22/"), | ||||
213 | QString::fromLatin1("16/") }; | ||||
214 | static const QSize sizes[] = { QSize(32, 32), QSize(22, 22), QSize(16, 16) }; // important: opposite direction | ||||
215 | QIcon icon; | ||||
216 | for (int mode = 0; mode < int(sizeof(modes) / sizeof(modes[0])); ++mode) { | ||||
217 | for (int size = 0; size < int(sizeof(sizes) / sizeof(sizes[0])); ++size) { | ||||
218 | const QString fileName(prefix + sizesStr[size] + suffixes[mode]); | ||||
219 | //qDebug() << fileName << sizes[size] << modes[mode]; | ||||
220 | if (QFile::exists(fileName)) { | ||||
221 | icon.addFile(fileName, sizes[size], modes[mode], QIcon::Off); | ||||
222 | icon.addFile(fileName, sizes[size], modes[mode], QIcon::On); | ||||
223 | } | ||||
224 | } | ||||
225 | } | ||||
226 | return icon; | ||||
227 | } | ||||
228 | | ||||
229 | class IconEngine : public QIconEngine | ||||
230 | { | ||||
231 | public: | ||||
232 | IconEngine(const KexiStyledIconParameters ¶meters) | ||||
233 | : m_parameters(parameters) | ||||
234 | { | ||||
235 | } | ||||
236 | inline QIconEngine *clone() const Q_DECL_OVERRIDE { | ||||
237 | return new IconEngine(*this); | ||||
238 | } | ||||
239 | | ||||
240 | //! @todo add caching? | ||||
241 | QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) Q_DECL_OVERRIDE { | ||||
242 | Q_UNUSED(state) | ||||
243 | QFile f(QLatin1String(":/icons/breeze/") + g_contexts[m_parameters.context] + QChar('/') + QString::number(size.width()) | ||||
244 | + QChar('/') + m_parameters.name + ".svg"); | ||||
245 | if (!f.open(QIODevice::ReadOnly)) { | ||||
246 | return QPixmap(); | ||||
247 | } | ||||
248 | QByteArray svg(f.readAll()); | ||||
249 | QColor color; | ||||
250 | if (mode == QIcon::Selected && m_parameters.selectedColor.isValid()) { | ||||
251 | color = m_parameters.selectedColor; | ||||
252 | } else if (mode == QIcon::Disabled && m_parameters.disabledColor.isValid()) { | ||||
253 | color = m_parameters.disabledColor; | ||||
254 | //qDebug() << m_parameters.disabledColor; | ||||
255 | } else if (m_parameters.color.isValid()) { | ||||
256 | color = m_parameters.color; | ||||
257 | } | ||||
258 | if (color.isValid()) { | ||||
259 | svg.replace(KexiUtils::iconGrey().name().toLatin1(), color.name().toLatin1()); | ||||
260 | } | ||||
261 | QSvgRenderer renderer(svg); | ||||
262 | QPixmap pm(size); | ||||
263 | pm.fill(Qt::transparent); | ||||
264 | QPainter p(&pm); | ||||
265 | renderer.render(&p, pm.rect()); | ||||
266 | return pm; | ||||
267 | } | ||||
268 | | ||||
269 | //! Nothing to paint extra here | ||||
270 | void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) Q_DECL_OVERRIDE { | ||||
271 | Q_UNUSED(painter) | ||||
272 | Q_UNUSED(rect) | ||||
273 | Q_UNUSED(mode) | ||||
274 | Q_UNUSED(state) | ||||
275 | } | ||||
276 | | ||||
277 | private: | ||||
278 | //! Needed for clone() | ||||
279 | IconEngine(const IconEngine &other) : QIconEngine(other), m_parameters(other.m_parameters) {} | ||||
280 | | ||||
281 | const KexiStyledIconParameters m_parameters; | ||||
282 | }; | ||||
283 | | ||||
284 | KEXIUTILS_EXPORT QIcon icon(const KexiStyledIconParameters ¶meters) | ||||
285 | { | ||||
286 | return QIcon(new IconEngine(parameters)); | ||||
287 | } | ||||
288 | | ||||
289 | const int propertyPaneMargin = 2; | ||||
290 | | ||||
291 | Q_GLOBAL_STATIC(PropertyPane, s_propertyPane) | ||||
292 | | ||||
293 | KEXIUTILS_EXPORT const PropertyPane& propertyPane() | ||||
294 | { | ||||
295 | return *s_propertyPane; | ||||
296 | } | ||||
297 | | ||||
298 | PropertyPane::PropertyPane() | ||||
299 | : margins(propertyPaneMargin, propertyPaneMargin * 2, propertyPaneMargin, propertyPaneMargin) //left top right bottom | ||||
300 | , verticalSpacing(5) | ||||
301 | , sectionTitleIndent(8) | ||||
302 | , horizontalSpacingAfterIcon(2) | ||||
303 | , horizontalSpacingAfterLabel(5) | ||||
304 | { | ||||
305 | } | ||||
306 | | ||||
307 | void PropertyPane::setupEditor(KPropertyEditorView *view) const | ||||
308 | { | ||||
309 | view->setGridLineColor(QColor()); | ||||
310 | view->setFrameShape(QFrame::NoFrame); | ||||
311 | } | ||||
312 | | ||||
313 | QPalette PropertyPane::sectionTitlePalette(const QPalette &palette) const | ||||
314 | { | ||||
315 | QPalette pal(palette); | ||||
316 | pal.setColor(QPalette::WindowText, KexiUtils::cardboardGreyAlternative()); | ||||
317 | return pal; | ||||
318 | } | ||||
319 | | ||||
320 | QPalette PropertyPane::labelPalette(const QPalette &palette) const | ||||
321 | { | ||||
322 | QPalette pal(palette); | ||||
323 | pal.setColor(QPalette::WindowText, QColor(0x7f8c8d)); | ||||
324 | return pal; | ||||
325 | } | ||||
326 | | ||||
327 | QPalette PropertyPane::warningLabelPalette(const QPalette &palette) const | ||||
328 | { | ||||
329 | QPalette pal(palette); | ||||
330 | QColor c(0xffa92d); // orange | ||||
331 | c.setAlpha(120); | ||||
332 | pal.setColor(QPalette::WindowText, c); | ||||
333 | return pal; | ||||
334 | } | ||||
335 | | ||||
336 | QFont PropertyPane::font() const | ||||
337 | { | ||||
338 | return KexiUtils::smallestReadableFont(); | ||||
339 | } | ||||
340 | | ||||
341 | void PropertyPane::alterLineEditStyle(QLineEdit *edit) const | ||||
342 | { | ||||
343 | alterPropertyPaneLineEditProxyStyle(edit); | ||||
344 | } | ||||
345 | | ||||
346 | void PropertyPane::alterComboBoxStyle(QComboBox *combo) const | ||||
347 | { | ||||
348 | if (combo) { | ||||
349 | combo->setContentsMargins(0, 0, 0, 0); | ||||
350 | alterPropertyPaneLineEditProxyStyle(combo); | ||||
351 | alterPropertyPaneLineEditProxyStyle(combo->lineEdit()); | ||||
352 | } | ||||
353 | } | ||||
354 | | ||||
355 | void PropertyPane::alterTitleFont(QWidget *widget) const | ||||
356 | { | ||||
357 | QFont f(widget->font()); | ||||
358 | f.setCapitalization(QFont::AllUppercase); | ||||
359 | widget->setFont(f); | ||||
360 | } | ||||
361 | | ||||
362 | QVBoxLayout* PropertyPane::createVLayout(QWidget *widget) const | ||||
363 | { | ||||
364 | QVBoxLayout *lyr = new QVBoxLayout(widget); | ||||
365 | lyr->setContentsMargins(0, 0, 0, 0); | ||||
366 | lyr->setSpacing(0); | ||||
367 | return lyr; | ||||
368 | } | ||||
369 | | ||||
370 | QGridLayout* PropertyPane::createFormLayout(QVBoxLayout *parentLayout) const | ||||
371 | { | ||||
372 | const PropertyPane &s = KexiStyle::propertyPane(); | ||||
373 | QGridLayout *formLyr = new QGridLayout; | ||||
374 | QMargins formMargins(0, 0, s.margins.right(), 0); | ||||
375 | KexiUtils::adjustIfRtl(&formMargins); | ||||
376 | formLyr->setContentsMargins(formMargins); | ||||
377 | | ||||
378 | formLyr->setVerticalSpacing(0); | ||||
379 | parentLayout->addLayout(formLyr); | ||||
380 | return formLyr; | ||||
381 | } | ||||
382 | | ||||
383 | static QLabel* createLabelInternal(const QString &labelText) | ||||
384 | { | ||||
385 | QLabel *label = new QLabel(labelText); | ||||
386 | label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); | ||||
387 | label->setWordWrap(true); | ||||
388 | label->setContentsMargins(0, 0, 0, 0); | ||||
389 | if (QGuiApplication::isRightToLeft()) { | ||||
390 | label->setAlignment(Qt::AlignRight); | ||||
391 | } | ||||
392 | return label; | ||||
393 | } | ||||
394 | | ||||
395 | QLabel* PropertyPane::createLabel(const QString &labelText) const | ||||
396 | { | ||||
397 | const PropertyPane &s = KexiStyle::propertyPane(); | ||||
398 | QLabel* label = createLabelInternal(labelText); | ||||
399 | label->setPalette(s.labelPalette(label->palette())); | ||||
400 | return label; | ||||
401 | } | ||||
402 | | ||||
403 | QLabel* PropertyPane::createWarningLabel(const QString &labelText) const | ||||
404 | { | ||||
405 | const PropertyPane &s = KexiStyle::propertyPane(); | ||||
406 | QLabel* label = createLabelInternal(labelText); | ||||
407 | label->setPalette(s.warningLabelPalette(label->palette())); | ||||
408 | return label; | ||||
409 | } | ||||
410 | | ||||
411 | QLabel* PropertyPane::createTitleLabel(const QString &title, QVBoxLayout *layout) const | ||||
412 | { | ||||
413 | const PropertyPane &s = KexiStyle::propertyPane(); | ||||
414 | QLabel *lbl = new QLabel(title); | ||||
415 | lbl->setIndent(s.sectionTitleIndent); | ||||
416 | if (QGuiApplication::isRightToLeft()) { | ||||
417 | lbl->setAlignment(Qt::AlignRight); | ||||
418 | } | ||||
419 | s.alterTitleFont(lbl); | ||||
420 | lbl->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | ||||
421 | lbl->setPalette(s.sectionTitlePalette(lbl->palette())); | ||||
422 | layout->addWidget(lbl); | ||||
423 | layout->addSpacing(verticalSpacing); | ||||
424 | return lbl; | ||||
425 | } | ||||
426 | | ||||
427 | void PropertyPane::addLabelAndWidget(const QString &labelText, QWidget *widget, | ||||
428 | QGridLayout *formLayout) const | ||||
429 | { | ||||
430 | const PropertyPane &s = KexiStyle::propertyPane(); | ||||
431 | QLabel * label = new QLabel(labelText); | ||||
432 | label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); | ||||
433 | QMargins labelMargins(s.sectionTitleIndent * 2, 0, s.horizontalSpacingAfterLabel, 0); | ||||
434 | KexiUtils::adjustIfRtl(&labelMargins); | ||||
435 | label->setContentsMargins(labelMargins); | ||||
436 | if (QGuiApplication::isRightToLeft()) { | ||||
437 | label->setAlignment(Qt::AlignRight); | ||||
438 | } | ||||
439 | label->setPalette(s.labelPalette(label->palette())); | ||||
440 | | ||||
441 | QComboBox* comboBox = qobject_cast<QComboBox*>(widget); | ||||
442 | if (comboBox) { | ||||
443 | s.alterComboBoxStyle(comboBox); | ||||
444 | } | ||||
445 | widget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); | ||||
446 | label->setBuddy(widget); | ||||
447 | formLayout->addWidget(label, formLayout->rowCount(), 0, Qt::AlignRight | Qt::AlignTop); | ||||
448 | formLayout->addWidget(widget, formLayout->rowCount() - 1, 1); | ||||
449 | formLayout->addItem(new QSpacerItem(1, verticalSpacing, QSizePolicy::Fixed, QSizePolicy::Fixed), formLayout->rowCount(), 1); | ||||
450 | } | ||||
451 | | ||||
452 | void PropertyPane::setFormLabelAndWidgetVisible(QWidget *widget, QGridLayout *formLayout, bool set) const | ||||
453 | { | ||||
454 | if (!widget) { | ||||
455 | return; | ||||
456 | } | ||||
457 | const int index = formLayout->indexOf(widget); | ||||
458 | if (index == -1) { | ||||
459 | qWarning() << "No widget" << widget << "in form layout" << formLayout; | ||||
460 | return; | ||||
461 | } | ||||
462 | int row, column, rowSpan, columnSpan; | ||||
463 | formLayout->getItemPosition(index, &row, &column, &rowSpan, &columnSpan); | ||||
464 | QLayoutItem *labelItem = formLayout->itemAtPosition(row, 0); | ||||
465 | if (labelItem->widget()) { | ||||
466 | labelItem->widget()->setVisible(set); | ||||
467 | } | ||||
468 | widget->setVisible(set); | ||||
469 | QLayoutItem *spacerItem = formLayout->itemAtPosition(row + 1, 1); | ||||
470 | if (spacerItem && spacerItem->spacerItem()) { | ||||
471 | spacerItem->spacerItem()->changeSize(set ? 1 : 0, set ? verticalSpacing : 0); | ||||
472 | } | ||||
473 | } | ||||
474 | | ||||
475 | QIcon PropertyPane::icon(const QString &iconName) const | ||||
476 | { | ||||
477 | return KexiStyle::darkIcon(iconName); | ||||
478 | } | ||||
479 | | ||||
480 | } // namespace KexiStyle |