22#include "KPropertyListData.h"
23#include "KPropertyUtils.h"
24#include "KPropertyUtils_p.h"
25#include "kproperty_debug.h"
48 stateNameString = prop ? prop->option(
"yesName",
QString()).toString() :
QString();
49 if (stateNameString.
isEmpty()) {
50 stateNameString = locale.language() ==
QLocale::C
52 :
QObject::tr(
"Yes",
"Property value: Boolean state Yes");
56 stateNameString = prop ? prop->option(
"noName",
QString()).toString() :
QString();
57 if (stateNameString.
isEmpty()) {
58 stateNameString = locale.language() ==
QLocale::C
60 :
QObject::tr(
"No",
"Property value: Boolean state No");
64 stateNameString = prop ? prop->option(
"3rdStateName",
QString()).toString() :
QString();
65 if (stateNameString.
isEmpty()) {
66 stateNameString = locale.language() ==
QLocale::C
68 :
QObject::tr(
"None",
"Property value: Boolean (3rd) undefined state None");
72 return stateNameString;
80 stateName(NoneIndex,
QLocale(), prop) });
88ThreeStateIndex valueToIndex(
const QVariant& value)
93 return value.
toBool() ? TrueIndex : FalseIndex;
103 : yesIcon(QIcon::fromTheme(QLatin1String(
"dialog-ok")))
104 , noIcon(QIcon::fromTheme(QLatin1String(
"kproperty-value-false")))
106 QPixmap none(16, 16);
108 noneIcon.addPixmap(none);
109 none = QPixmap(22, 22);
111 noneIcon.addPixmap(none);
118Q_GLOBAL_STATIC(BoolEditGlobal, g_boolEdit)
123 Private(
const KProperty *prop)
124 : yesText( stateName(TrueIndex, QLocale(), prop) )
125 , noText( stateName(FalseIndex, QLocale(), prop) )
133KPropertyBoolEditor::KPropertyBoolEditor(
const KProperty *prop,
QWidget *parent)
138 setAutoFillBackground(
true);
139 connect(
this, SIGNAL(toggled(
bool)),
this, SLOT(slotValueChanged(
bool)));
142KPropertyBoolEditor::~KPropertyBoolEditor()
147QVariant KPropertyBoolEditor::value()
const
152void KPropertyBoolEditor::setValue(
const QVariant &value)
161KPropertyBoolEditor::slotValueChanged(
bool state)
164 emit commitData(
this);
168 const QString& text,
bool threeState)
171 QSize actualIconSize;
173 if (threeState && valueToIndex(value) == NoneIndex) {
175 icon = g_boolEdit->noneIcon;
176 actualIconSize = g_boolEdit->yesIcon.actualSize(r.
size());
177 textOffset = QPoint(actualIconSize.
width() + 6, 0);
180 icon = value.toBool() ? g_boolEdit->yesIcon : g_boolEdit->noIcon;
181 actualIconSize =
icon.actualSize(r.
size());
182 textOffset = QPoint(actualIconSize.
width() + 6, 0);
185 r2.moveTop(r2.top() + 2);
186 r2.setLeft(r2.left() + 3);
193void KPropertyBoolEditor::paintEvent(
QPaintEvent * event )
197 const QVariant v( value() );
198 KPropertyBoolEditor::draw(&p,
rect(), v,
199 v.toBool() ? d->yesText : d->noText,
false );
202bool KPropertyBoolEditor::eventFilter(
QObject* watched,
QEvent* e)
205 QKeyEvent* ev =
static_cast<QKeyEvent*
>(e);
206 const int k = ev->
key();
217class ThreeStateBoolIconProvider :
public KPropertyComboBoxEditorIconProviderInterface
220 ThreeStateBoolIconProvider() {}
221 QIcon icon(
int index)
const override
225 return g_boolEdit->yesIcon;
227 return g_boolEdit->noIcon;
229 return g_boolEdit->noneIcon;
232 KPropertyComboBoxEditorIconProviderInterface* clone()
const override
234 return new ThreeStateBoolIconProvider();
238static KPropertyComboBoxEditorOptions initThreeStateBoolOptions()
240 KPropertyComboBoxEditorOptions options;
241 options.iconProvider =
new ThreeStateBoolIconProvider();
252KPropertyThreeStateBoolEditor::KPropertyThreeStateBoolEditor(
const KPropertyListData &listData,
254 : KPropertyComboBoxEditor(listData, initThreeStateBoolOptions(), parent), d(new Private)
259 setCurrentIndex(NoneIndex);
262KPropertyThreeStateBoolEditor::~KPropertyThreeStateBoolEditor()
267QVariant KPropertyThreeStateBoolEditor::value()
const
271 const ThreeStateIndex index
272 = (i >= TrueIndex && i <= NoneIndex) ? static_cast<ThreeStateIndex>(i) : NoneIndex;
292void KPropertyThreeStateBoolEditor::setValue(
const QVariant &value)
299KPropertyBoolDelegate::KPropertyBoolDelegate()
301 options()->setBordersVisible(
true);
304QWidget * KPropertyBoolDelegate::createEditor(
int type,
QWidget *parent,
309 KProperty *prop = KPropertyUtils::propertyForIndex(index);
313 KPropertyListData threeStateListData;
314 setupThreeStateListData(&threeStateListData, prop);
315 return new KPropertyThreeStateBoolEditor(threeStateListData, parent);
318 return new KPropertyBoolEditor(prop, parent);
322void KPropertyBoolDelegate::paint(
QPainter * painter,
325 const KPropertyUtilsPrivate::PainterSaver saver(painter);
326 KProperty *prop = KPropertyUtils::propertyForIndex(index);
331 QRect rect(option.rect);
332 const bool threeState = prop->
option(
"3State",
false).
toBool();
333 KPropertyBoolEditor::draw(painter, rect.translated(0, -2), value, propertyValueToString(prop, QLocale()), threeState);
339 const ThreeStateIndex listIndex = valueToIndex(prop->
value());
340 return stateName(listIndex, locale, prop);
345 return valueToString(prop->
value(), locale);
351 return stateName(value.
toBool() ? TrueIndex : FalseIndex, locale);
A bool editor supporting two states: true and false.
const KPropertyEditorCreatorOptions * options() const
Options for editor creating.
A data container for properties of list type.
void setKeys(const QVariantList &keys)
Sets a list containing all possible keys for a property.
void setNamesAsStringList(const QStringList &names)
Sets a list containing all possible keys for a property as strings.
A bool editor supporting three states: true, false and null.
The base class representing a single property.
QVariant option(const char *name, const QVariant &defaultValue=QVariant()) const
Returns value of given option Option is set if returned value is not null. If there is no option for ...
char * toString(const EngineQuery &query)
QVariant data(int role) const const
virtual bool event(QEvent *e)
virtual bool eventFilter(QObject *watched, QEvent *event)
void drawText(const QPoint &position, const QString &text)
QString fromLatin1(QByteArrayView str)
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool isNull() const const
bool isValid() const const
bool toBool() const const
QString toString() const const