22 #include "KPropertyListData.h" 23 #include "KPropertyUtils.h" 24 #include "KPropertyUtils_p.h" 25 #include "kproperty_debug.h" 36 enum ThreeStateIndex {
48 stateNameString = prop ? prop->option(
"yesName",
QString()).toString() :
QString();
49 if (stateNameString.
isEmpty()) {
52 :
QObject::tr(
"Yes",
"Property value: Boolean state Yes");
56 stateNameString = prop ? prop->option(
"noName",
QString()).toString() :
QString();
57 if (stateNameString.
isEmpty()) {
60 :
QObject::tr(
"No",
"Property value: Boolean state No");
64 stateNameString = prop ? prop->option(
"3rdStateName",
QString()).toString() :
QString();
65 if (stateNameString.
isEmpty()) {
68 :
QObject::tr(
"None",
"Property value: Boolean (3rd) undefined state None");
72 return stateNameString;
80 stateName(NoneIndex,
QLocale(), prop) });
88 ThreeStateIndex valueToIndex(
const QVariant& value)
93 return value.
toBool() ? TrueIndex : FalseIndex;
108 noneIcon.addPixmap(none);
111 noneIcon.addPixmap(none);
118 Q_GLOBAL_STATIC(BoolEditGlobal, g_boolEdit)
124 : yesText( stateName(TrueIndex,
QLocale(), prop) )
125 , noText( stateName(FalseIndex,
QLocale(), prop) )
133 KPropertyBoolEditor::KPropertyBoolEditor(
const KProperty *prop,
QWidget *parent)
138 setAutoFillBackground(
true);
139 connect(
this, SIGNAL(toggled(
bool)),
this, SLOT(slotValueChanged(
bool)));
142 KPropertyBoolEditor::~KPropertyBoolEditor()
147 QVariant KPropertyBoolEditor::value()
const 152 void KPropertyBoolEditor::setValue(
const QVariant &value)
161 KPropertyBoolEditor::slotValueChanged(
bool state)
164 emit commitData(
this);
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;
182 textOffset =
QPoint(actualIconSize.
width() + 6, 0);
185 r2.moveTop(r2.top() + 2);
186 r2.setLeft(r2.left() + 3);
198 KPropertyBoolEditor::draw(&p,
rect(), v,
199 v.toBool() ? d->yesText : d->noText,
false );
202 bool KPropertyBoolEditor::eventFilter(
QObject* watched,
QEvent* e)
206 const int k = ev->
key();
217 class ThreeStateBoolIconProvider :
public KPropertyComboBoxEditorIconProviderInterface
220 ThreeStateBoolIconProvider() {}
225 return g_boolEdit->yesIcon;
227 return g_boolEdit->noIcon;
229 return g_boolEdit->noneIcon;
232 KPropertyComboBoxEditorIconProviderInterface* clone()
const override 234 return new ThreeStateBoolIconProvider();
238 static KPropertyComboBoxEditorOptions initThreeStateBoolOptions()
240 KPropertyComboBoxEditorOptions options;
241 options.iconProvider =
new ThreeStateBoolIconProvider();
252 KPropertyThreeStateBoolEditor::KPropertyThreeStateBoolEditor(
const KPropertyListData &listData,
254 : KPropertyComboBoxEditor(listData, initThreeStateBoolOptions(), parent), d(new Private)
259 setCurrentIndex(NoneIndex);
262 KPropertyThreeStateBoolEditor::~KPropertyThreeStateBoolEditor()
267 QVariant KPropertyThreeStateBoolEditor::value()
const 271 const ThreeStateIndex index
272 = (i >= TrueIndex && i <= NoneIndex) ? static_cast<ThreeStateIndex>(i) : NoneIndex;
292 void KPropertyThreeStateBoolEditor::setValue(
const QVariant &value)
299 KPropertyBoolDelegate::KPropertyBoolDelegate()
301 options()->setBordersVisible(
true);
304 QWidget * KPropertyBoolDelegate::createEditor(
int type,
QWidget *parent,
309 KProperty *prop = KPropertyUtils::propertyForIndex(index);
314 setupThreeStateListData(&threeStateListData, prop);
322 void KPropertyBoolDelegate::paint(
QPainter * painter,
325 const KPropertyUtilsPrivate::PainterSaver saver(painter);
326 KProperty *prop = KPropertyUtils::propertyForIndex(index);
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);
351 return stateName(value.
toBool() ? TrueIndex : FalseIndex,
locale);
QEvent::Type type() const const
void setNamesAsStringList(const QStringList &names)
Sets a list containing all possible keys for a property as strings.
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 ...
A bool editor supporting three states: true, false and null.
bool isNull() const const
bool isEmpty() const const
void drawText(const QPointF &position, const QString &text)
QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) const const
QLocale::Language language() const const
QRect translated(int dx, int dy) const const
virtual bool eventFilter(QObject *watched, QEvent *event)
void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment, QIcon::Mode mode, QIcon::State state) const const
The base class representing a single property.
QVariant data(int role) const const
int currentIndex() const const
bool toBool() const const
QString text() const const
QString fromLatin1(const char *str, int size)
A bool editor supporting two states: true and false.
bool isValid() const const
void setKeys(const QVariantList &keys)
Sets a list containing all possible keys for a property.
QVariant::Type type() const const
QString toString() const const
A data container for properties of list type.