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();
34class Q_DECL_HIDDEN KPropertyStringEditor::Private
39 bool slotTextChangedEnabled =
true;
43KPropertyStringEditor::KPropertyStringEditor(
QWidget *parent)
47 setContentsMargins(0,1,0,0);
48 setClearButtonEnabled(
true);
52KPropertyStringEditor::~KPropertyStringEditor()
57QString KPropertyStringEditor::value()
const
62void KPropertyStringEditor::setValue(
const QString& value)
64 d->slotTextChangedEnabled =
false;
66 d->slotTextChangedEnabled =
true;
71void KPropertyStringEditor::slotTextChanged(
const QString & text )
74 if (!d->slotTextChangedEnabled)
76 emit commitData(
this);
79KPropertyStringDelegate::KPropertyStringDelegate()
83QWidget* KPropertyStringDelegate::createEditor(
int type,
QWidget *parent,
88 KProperty *
property = KPropertyUtils::propertyForIndex(index);
92 if (isMultiLine(property)) {
95 return new KPropertyStringEditor(parent);
99void KPropertyStringDelegate::paint(
QPainter *painter,
102 KProperty *
property = KPropertyUtils::propertyForIndex(index);
107 if (
string.isEmpty()) {
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
118 = qobject_cast<const KPropertyEditorDataModel*>(index.
model());
121 propertySet = editorModel->propertySet();
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);
137 if (
string.isEmpty()) {
143 const KPropertyUtilsPrivate::PainterSaver saver(painter);
144 painter->
drawText(r, align,
string);
Editor for string type supporting multiple lines of plain text.
static QString valueToLocalizedString(const QVariant &value)
The base class representing a single property.
Language language() const const
QVariant data(int role) const const
const QAbstractItemModel * model() const const
void drawText(const QPoint &position, const QString &text)
void fillRect(const QRect &rectangle, QGradient::Preset preset)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QString toString() const const