Changeset View
Changeset View
Standalone View
Standalone View
src/KPropertyWidgetsFactory.cpp
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project | ||
---|---|---|---|---|---|
2 | Copyright (C) 2008-2016 Jarosław Staniek <staniek@kde.org> | 2 | Copyright (C) 2008-2017 Jarosław Staniek <staniek@kde.org> | ||
3 | 3 | | |||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. | ||
8 | 8 | | |||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | 12 | Library General Public License for more details. | ||
13 | 13 | | |||
14 | You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | * Boston, MA 02110-1301, USA. | 17 | * Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | 20 | | |||
21 | #include "KPropertyFactory.h" | 21 | #include "KPropertyFactory.h" | ||
22 | 22 | | |||
23 | #include "KDefaultPropertyFactory.h" | 23 | #include "KDefaultPropertyFactory.h" | ||
24 | #include "KPropertyEditorView.h" | 24 | #include "KPropertyEditorView.h" | ||
25 | #include "KPropertyStringEditor.h" | 25 | #include "KPropertyStringEditor.h" | ||
26 | #include "KPropertyUtils.h" | ||||
26 | #include "KPropertyUtils_p.h" | 27 | #include "KPropertyUtils_p.h" | ||
27 | 28 | | |||
28 | KPropertyLabel::KPropertyLabel(QWidget *parent, const KPropertyValueDisplayInterface *iface) | 29 | KPropertyLabel::KPropertyLabel(QWidget *parent, const KProperty *property, | ||
29 | : QLabel(parent) | 30 | const KPropertyValueDisplayInterface *iface) | ||
30 | , m_iface(iface) | 31 | : QLabel(parent), m_property(property), m_iface(iface) | ||
31 | { | 32 | { | ||
32 | setAutoFillBackground(true); | 33 | setAutoFillBackground(true); | ||
33 | 34 | | |||
34 | KPropertyEditorView* view = 0; | 35 | KPropertyEditorView *view = 0; | ||
35 | if (parent) { | 36 | if (parent) { | ||
36 | view = qobject_cast<KPropertyEditorView*>(parent->parentWidget()); | 37 | view = qobject_cast<KPropertyEditorView *>(parent->parentWidget()); | ||
37 | } | 38 | } | ||
38 | const QColor gridLineColor(view ? view->gridLineColor() : KPropertyEditorView::defaultGridLineColor()); | 39 | const QColor gridLineColor(view ? view->gridLineColor() | ||
40 | : KPropertyEditorView::defaultGridLineColor()); | ||||
39 | const int top = 1 + (gridLineColor.isValid() ? 1 : 0); | 41 | const int top = 1 + (gridLineColor.isValid() ? 1 : 0); | ||
40 | 42 | | |||
41 | setContentsMargins(0, top, 0, 0); | 43 | setContentsMargins(0, top, 0, 0); | ||
42 | setIndent(1); | 44 | setIndent(1); | ||
43 | } | 45 | } | ||
44 | 46 | | |||
45 | QVariant KPropertyLabel::value() const | 47 | QVariant KPropertyLabel::value() const | ||
46 | { | 48 | { | ||
47 | return m_value; | 49 | return m_value; | ||
48 | } | 50 | } | ||
49 | 51 | | |||
50 | void KPropertyLabel::setValue(const QVariant& value) | 52 | void KPropertyLabel::setValue(const QVariant& value) | ||
51 | { | 53 | { | ||
52 | setText( m_iface->valueToString(value, QLocale()) ); | | |||
53 | m_value = value; | 54 | m_value = value; | ||
55 | setText(m_iface->propertyValueToString(m_property, QLocale())); | ||||
54 | } | 56 | } | ||
55 | 57 | | |||
56 | void KPropertyLabel::paintEvent( QPaintEvent * event ) | 58 | void KPropertyLabel::paintEvent( QPaintEvent * event ) | ||
57 | { | 59 | { | ||
58 | QLabel::paintEvent(event); | 60 | QLabel::paintEvent(event); | ||
59 | KPropertyWidgetsFactory::paintTopGridLine(this); | 61 | KPropertyWidgetsFactory::paintTopGridLine(this); | ||
60 | } | 62 | } | ||
61 | 63 | | |||
▲ Show 20 Lines • Show All 156 Lines • ▼ Show 20 Line(s) | |||||
218 | 220 | | |||
219 | //static | 221 | //static | ||
220 | void KPropertyValuePainterInterface::paint(const KPropertyValueDisplayInterface *iface, | 222 | void KPropertyValuePainterInterface::paint(const KPropertyValueDisplayInterface *iface, | ||
221 | QPainter *painter, const QStyleOptionViewItem &option, | 223 | QPainter *painter, const QStyleOptionViewItem &option, | ||
222 | const QModelIndex &index) | 224 | const QModelIndex &index) | ||
223 | { | 225 | { | ||
224 | const KPropertyUtilsPrivate::PainterSaver saver(painter); | 226 | const KPropertyUtilsPrivate::PainterSaver saver(painter); | ||
225 | QRect r(option.rect); | 227 | QRect r(option.rect); | ||
226 | r.setLeft(r.left()+1); | 228 | r.setLeft(r.left() + 1); | ||
229 | KProperty *prop = KPropertyUtils::propertyForIndex(index); | ||||
227 | painter->drawText( r, Qt::AlignLeft | Qt::AlignVCenter, | 230 | painter->drawText(r, Qt::AlignLeft | Qt::AlignVCenter, | ||
228 | iface->valueToString(index.data(Qt::EditRole), QLocale())); | 231 | iface->propertyValueToString(prop, QLocale())); | ||
229 | } | 232 | } |