22 #include "KPropertyStringEditor.h" 23 #include "KPropertyMultiLineStringEditor.h" 24 #include "KPropertyUtils.h" 25 #include "KPropertyUtils_p.h" 26 #include "KPropertyEditorDataModel_p.h" 29 bool isMultiLine(
const KProperty *property) {
30 return property->option(
"multiLine",
false).toBool();
34 class Q_DECL_HIDDEN KPropertyStringEditor::Private
39 bool slotTextChangedEnabled =
true;
43 KPropertyStringEditor::KPropertyStringEditor(
QWidget *parent)
47 setContentsMargins(0,1,0,0);
48 setClearButtonEnabled(
true);
52 KPropertyStringEditor::~KPropertyStringEditor()
57 QString KPropertyStringEditor::value()
const 62 void KPropertyStringEditor::setValue(
const QString& value)
64 d->slotTextChangedEnabled =
false;
66 d->slotTextChangedEnabled =
true;
71 void KPropertyStringEditor::slotTextChanged(
const QString & text )
74 if (!d->slotTextChangedEnabled)
76 emit commitData(this);
79 KPropertyStringDelegate::KPropertyStringDelegate()
83 QWidget* KPropertyStringDelegate::createEditor(
int type,
QWidget *parent,
88 KProperty *
property = KPropertyUtils::propertyForIndex(index);
92 if (isMultiLine(property)) {
95 return new KPropertyStringEditor(parent);
99 void KPropertyStringDelegate::paint(
QPainter *painter,
102 KProperty *
property = KPropertyUtils::propertyForIndex(index);
111 QRect r(option.rect);
112 r.setLeft(r.left() + 2);
113 r.setTop(r.top() + 1);
114 if (isMultiLine(property)) {
116 r.setLeft(r.left() + 1);
117 const KPropertyEditorDataModel *editorModel
121 propertySet = editorModel->propertySet();
123 const bool readOnly =
property->
isReadOnly() || (propertySet && propertySet->isReadOnly());
128 fillBrush = option.palette.highlight();
130 fillBrush = option.palette.window();
132 painter->
fillRect(option.rect, fillBrush);
134 const int newLineIndex =
string.indexOf(
QLatin1Char(
'\n'));
135 if (newLineIndex >= 0) {
136 string.truncate(newLineIndex);
143 const KPropertyUtilsPrivate::PainterSaver saver(painter);
144 painter->
drawText(r, align,
string);
152 return valueToLocalizedString(value);
void fillRect(const QRectF &rectangle, const QBrush &brush)
Editor for string type supporting multiple lines of plain text.
void drawText(const QPointF &position, const QString &text)
QLocale::Language language() const const
The base class representing a single property.
const QAbstractItemModel * model() const const
QVariant data(int role) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
T qobject_cast(QObject *object)
QString toString() const const