26#include <tqobjectlist.h>
29#include <tqlineedit.h>
36IntSpinBox::IntSpinBox(
int lower,
int upper,
int step,
int value,
int base, IntEdit *parent,
const char *name)
39 editor()->setAlignment(TQt::AlignLeft);
40 installEventFilter(editor());
41 installEventFilter(
this);
42 TQObjectList *spinwidgets = queryList(
"TQSpinWidget", 0,
false,
true );
43 TQSpinWidget* spin =
static_cast<TQSpinWidget*
>(spinwidgets->first());
45 spin->installEventFilter(
this);
49void IntSpinBox::setValue(
const TQVariant &value)
51 if (
dynamic_cast<IntEdit*
>(parentWidget()) &&
dynamic_cast<IntEdit*
>(parentWidget())->isReadOnly())
56 KIntSpinBox::setValue(value.toInt());
60IntSpinBox::eventFilter(TQObject *o, TQEvent *e)
64 if(e->type() == TQEvent::KeyPress)
66 TQKeyEvent* ev =
static_cast<TQKeyEvent*
>(e);
67 if((ev->key()==Key_Up || ev->key()==Key_Down) && ev->state() !=ControlButton)
69 parentWidget()->eventFilter(o, e);
74 if ((o == editor() || o ==
this || o->parent() ==
this)
75 && e->type() == TQEvent::Wheel &&
static_cast<IntEdit*
>(parentWidget())->isReadOnly())
80 return KIntSpinBox::eventFilter(o, e);
86IntEdit::IntEdit(
Property *property, TQWidget *parent,
const char *name)
89 TQVariant minVal( property ? property->
option(
"min") : 0 );
90 TQVariant maxVal( property ? property->
option(
"max") : TQVariant() );
91 TQVariant minValueText( property ? property->
option(
"minValueText") : TQVariant() );
97 m_edit =
new IntSpinBox(minVal.toInt(), maxVal.toInt(), 1, 0, 10,
this);
98 if (!minValueText.isNull())
99 m_edit->setSpecialValueText(minValueText.toString());
100 m_edit->setMinimumHeight(5);
103 setLeavesTheSpaceForRevertButton(
true);
104 setFocusWidget(m_edit);
105 connect(m_edit, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotValueChanged(
int)));
112IntEdit::value()
const
114 if (m_edit->cleanText().isEmpty())
116 return m_edit->value();
120IntEdit::setValue(
const TQVariant &value,
bool emitChange)
122 m_edit->blockSignals(
true);
123 m_edit->setValue(value);
125 m_edit->blockSignals(
false);
127 emit valueChanged(
this);
131IntEdit::drawViewer(TQPainter *p,
const TQColorGroup &cg,
const TQRect &r,
const TQVariant &value)
133 TQString valueText = value.toString();
134 if (property() && property()->hasOptions()) {
136 TQVariant minValue( property()->option(
"min") );
137 TQVariant minValueText( property()->option(
"minValueText") );
138 if (!minValue.isNull() && !minValueText.isNull() && minValue.toInt() == value.toInt()) {
139 valueText = minValueText.toString();
149IntEdit::slotValueChanged(
int)
151 emit valueChanged(
this);
155IntEdit::updateSpinWidgets()
157 TQObjectList *spinwidgets = queryList(
"TQSpinWidget", 0,
false,
true );
158 TQSpinWidget* spin =
static_cast<TQSpinWidget*
>(spinwidgets->first());
160 spin->setUpEnabled(!isReadOnly());
161 spin->setDownEnabled(!isReadOnly());
167IntEdit::setReadOnlyInternal(
bool readOnly)
170 m_edit->editor()->setReadOnly(readOnly);
173 setLeavesTheSpaceForRevertButton(
false);
179DoubleSpinBox::DoubleSpinBox (
double lower,
double upper,
double step,
double value,
int precision, DoubleEdit *parent)
182 editor()->setAlignment(TQt::AlignLeft);
183 installEventFilter(editor());
184 installEventFilter(
this);
185 TQObjectList *spinwidgets = queryList(
"TQSpinWidget", 0,
false,
true );
186 TQSpinWidget* spin =
static_cast<TQSpinWidget*
>(spinwidgets->first());
188 spin->installEventFilter(
this);
193DoubleSpinBox::eventFilter(TQObject *o, TQEvent *e)
197 if(e->type() == TQEvent::KeyPress)
199 TQKeyEvent* ev =
static_cast<TQKeyEvent*
>(e);
200 if((ev->key()==Key_Up || ev->key()==Key_Down) && ev->state()!=ControlButton)
202 parentWidget()->eventFilter(o, e);
207 if ((o == editor() || o ==
this || o->parent() ==
this)
208 && e->type() == TQEvent::Wheel &&
static_cast<IntEdit*
>(parentWidget())->isReadOnly())
213 return KDoubleSpinBox::eventFilter(o, e);
217void DoubleSpinBox::setValue(
const TQVariant& value )
219 if (
dynamic_cast<DoubleEdit*
>(parentWidget()) &&
dynamic_cast<DoubleEdit*
>(parentWidget())->isReadOnly())
229DoubleEdit::DoubleEdit(
Property *property, TQWidget *parent,
const char *name)
232 TQVariant minVal( property ? property->
option(
"min") : 0 );
233 TQVariant maxVal( property ? property->
option(
"max") : TQVariant() );
234 TQVariant step( property ? property->
option(
"step") : TQVariant());
235 TQVariant precision( property ? property->
option(
"precision") : TQVariant());
236 TQVariant minValueText( property ? property->
option(
"minValueText") : TQVariant() );
240 maxVal = (double)(INT_MAX/100);
243 if(precision.isNull())
246 m_edit =
new DoubleSpinBox(minVal.toDouble(), maxVal.toDouble(), step.toDouble(),
247 0, precision.toInt(),
this);
248 if (!minValueText.isNull())
249 m_edit->setSpecialValueText(minValueText.toString());
250 m_edit->setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding);
251 m_edit->setMinimumHeight(5);
254 setLeavesTheSpaceForRevertButton(
true);
255 setFocusWidget(m_edit);
256 connect(m_edit, TQ_SIGNAL(valueChanged(
double)),
this, TQ_SLOT(slotValueChanged(
double)));
259DoubleEdit::~DoubleEdit()
263DoubleEdit::value()
const
265 if (m_edit->cleanText().isEmpty())
267 return m_edit->value();
271DoubleEdit::setValue(
const TQVariant &value,
bool emitChange)
273 m_edit->blockSignals(
true);
274 m_edit->setValue(value);
276 m_edit->blockSignals(
false);
278 emit valueChanged(
this);
282DoubleEdit::drawViewer(TQPainter *p,
const TQColorGroup &cg,
const TQRect &r,
const TQVariant &value)
285 if (property() && property()->hasOptions()) {
287 TQVariant minValue( property()->option(
"min") );
288 TQVariant minValueText( property()->option(
"minValueText") );
289 if (!minValue.isNull() && !minValueText.isNull() && minValue.toString().toDouble() == value.toString().toDouble()) {
290 valueText = minValueText.toString();
293 if (valueText.isEmpty())
294 valueText = TQString(value.toString()).replace(
'.', TDEGlobal::locale()->decimalSymbol());
302DoubleEdit::slotValueChanged(
double)
304 emit valueChanged(
this);
308DoubleEdit::updateSpinWidgets()
310 TQObjectList *spinwidgets = queryList(
"TQSpinWidget", 0,
false,
true );
311 TQSpinWidget* spin =
static_cast<TQSpinWidget*
>(spinwidgets->first());
313 spin->setUpEnabled(!isReadOnly());
314 spin->setDownEnabled(!isReadOnly());
320DoubleEdit::setReadOnlyInternal(
bool readOnly)
323 m_edit->editor()->setReadOnly(readOnly);
326 setLeavesTheSpaceForRevertButton(
false);
329#include "spinbox.moc"
virtual void setValue(double value)
The base class representing a single property.
TQVariant option(const char *name) const
const char * name(StdAction id)
Namespace for a set of classes implementing generic properties framework.