5#ifndef QQUICKABSTRACTSPINBOX_P_H
6#define QQUICKABSTRACTSPINBOX_P_H
19#include <private/qquickcontrol_p_p.h>
20#include <private/qquickcontrol_p.h>
21#include <private/qquicktheme_p.h>
22#include <QtQml/qjsvalue.h>
23#include <private/qquickindicatorbutton_p.h>
24#include <private/qquicktextinput_p.h>
25#include <private/qqmlengine_p.h>
26#include <QtQml/qqmlinfo.h>
27#include <QtGui/private/qlayoutpolicy_p.h>
32class QQuickIndicatorButton;
34template <
typename Derived,
typename ValueType>
49 Derived *
q_func() {
return static_cast<Derived *>(q_ptr); }
50 const Derived *
q_func()
const {
return static_cast<
const Derived *>(q_ptr); }
56 return inverted ? qBound(
to, value,
from) : qBound(
from, value,
to);
58 ValueType f = inverted ?
to :
from;
59 ValueType t = inverted ?
from :
to;
93 if (displayText == text)
97 emit q_func()->displayTextChanged();
102 const QQuickItem *upIndicator =
up->indicator();
103 return upIndicator && upIndicator->isEnabled();
108 QQuickItem *upIndicator =
up->indicator();
117 const QQuickItem *downIndicator =
down->indicator();
118 return downIndicator && downIndicator->isEnabled();
123 QQuickItem *downIndicator =
down->indicator();
132 QQuickItem *ui =
up->indicator();
133 QQuickItem *di =
down->indicator();
134 up->setHovered(ui && ui->isEnabled() && ui->contains(q_func()->mapToItem(ui, pos)));
135 down->setHovered(di && di->isEnabled() && di->contains(q_func()->mapToItem(di, pos)));
164 QQuickControlPrivate::handlePress(point, timestamp);
166 QQuickItem *ui =
up->indicator();
167 QQuickItem *di =
down->indicator();
168 up->setPressed(ui && ui->isEnabled() && ui->contains(ui->mapFromItem(q_func(), point)));
169 down->setPressed(di && di->isEnabled()
170 && di->contains(di->mapFromItem(q_func(), point)));
172 bool pressed =
up->isPressed() ||
down->isPressed();
173 q_func()->setAccessibleProperty(
"pressed", pressed);
179 bool handleMove(
const QPointF &point, ulong timestamp)
override
181 QQuickControlPrivate::handleMove(point, timestamp);
182 QQuickItem *upIndicator =
up->indicator();
183 const bool upIndicatorContainsPoint = upIndicator && upIndicator->isEnabled()
184 && upIndicator->contains(upIndicator->mapFromItem(q_func(), point));
185 up->setHovered(QQuickControlPrivate::touchId == -1 && upIndicatorContainsPoint);
186 up->setPressed(upIndicatorContainsPoint);
188 QQuickItem *downIndicator =
down->indicator();
189 const bool downIndicatorContainsPoint = downIndicator && downIndicator->isEnabled()
190 && downIndicator->contains(downIndicator->mapFromItem(q_func(), point));
191 down->setHovered(QQuickControlPrivate::touchId == -1 && downIndicatorContainsPoint);
192 down->setPressed(downIndicatorContainsPoint);
194 bool pressed =
up->isPressed() ||
down->isPressed();
195 q_func()->setAccessibleProperty(
"pressed", pressed);
203 QQuickControlPrivate::handleRelease(point, timestamp);
204 QQuickItem *ui =
up->indicator();
205 QQuickItem *di =
down->indicator();
207 double oldValue =
value;
208 if (
up->isPressed()) {
209 if (
repeatTimer <= 0 && ui && ui->contains(ui->mapFromItem(q_func(), point)))
210 q_func()->increase();
213 up->setPressed(
false);
214 }
else if (
down->isPressed()) {
215 if (
repeatTimer <= 0 && di && di->contains(di->mapFromItem(q_func(), point)))
216 q_func()->decrease();
217 down->setPressed(
false);
219 if (
value != oldValue)
220 emit q_func()->valueModified();
222 q_func()->setAccessibleProperty(
"pressed",
false);
229 QQuickControlPrivate::handleUngrab();
230 up->setPressed(
false);
231 down->setPressed(
false);
233 q_func()->setAccessibleProperty(
"pressed",
false);
239 QQuickControlPrivate::itemImplicitWidthChanged(item);
240 if (item ==
up->indicator())
241 emit up->implicitIndicatorWidthChanged();
242 else if (item ==
down->indicator())
243 emit down->implicitIndicatorWidthChanged();
248 QQuickControlPrivate::itemImplicitHeightChanged(item);
249 if (item ==
up->indicator())
250 emit up->implicitIndicatorHeightChanged();
251 else if (item ==
down->indicator())
252 emit down->implicitIndicatorHeightChanged();
257 QQuickControlPrivate::itemDestroyed(item);
258 if (item ==
up->indicator())
259 up->setIndicator(
nullptr);
260 else if (item ==
down->indicator())
261 down->setIndicator(
nullptr);
266 return QQuickTheme::palette(QQuickTheme::SpinBox);
278 QQuickIndicatorButton *
up =
nullptr;
279 QQuickIndicatorButton *
down =
nullptr;
280#if QT_CONFIG(validator)
291 auto *derived =
static_cast<Derived *>(
this);
297 const auto *derived =
static_cast<
const Derived *>(
this);
304 return d_func()->from;
314 return d_func()->value;
319 return d_func()->stepSize;
324 return d_func()->editable;
329 auto *derived =
static_cast<Derived *>(
this);
331 if (d->editable == editable)
335 if (d->contentItem) {
337 d->contentItem->setCursor(Qt::IBeamCursor);
339 d->contentItem->unsetCursor();
343 d->editable = editable;
344 d->q_func()->setAccessibleProperty(
"editable", editable);
345 emit derived->editableChanged();
348#if QT_CONFIG(validator)
368 auto *derived =
static_cast<Derived *>(
this);
370 if (!callback.isCallable()) {
371 qmlWarning(derived) <<
"textFromValue must be a callable function";
374 d->textFromValue = callback;
375 emit derived->textFromValueChanged();
380 auto *derived =
static_cast<Derived *>(
this);
382 if (!callback.isCallable()) {
383 qmlWarning(derived) <<
"valueFromText must be a callable function";
386 d->valueFromText = callback;
387 emit derived->valueFromTextChanged();
390 QQuickIndicatorButton *
up()
const
392 auto *derived =
static_cast<
const Derived *>(
this);
397 QQuickIndicatorButton *
down()
const
399 auto *derived =
static_cast<
const Derived *>(
this);
406 auto *derived =
static_cast<
const Derived *>(
this);
408 return d->inputMethodHints;
413 auto *derived =
static_cast<Derived *>(
this);
415 if (d->inputMethodHints == hints)
418 d->inputMethodHints = hints;
419 emit derived->inputMethodHintsChanged();
424 auto *derived =
static_cast<
const Derived *>(
this);
426 return d->contentItem && d->contentItem->property(
"inputMethodComposing").toBool();
431 return d_func()->wrap;
436 return d_func()->displayText;
456 if (d->editable && d->contentItem && !d->contentItem->hasActiveFocus())
457 d->contentItem->forceActiveFocus(event->reason());
464 d->updateHover(event->position());
472 d->updateHover(event->position());
480 d->down->setHovered(
false);
481 d->up->setHovered(
false);
489 switch (event->key()) {
491 if (d->upEnabled()) {
494 d->up->setPressed(
true);
501 if (d->downEnabled()) {
502 d->down->setPressed(
true);
512 d->q_func()->setAccessibleProperty(
"pressed", d->up->isPressed() || d->down->isPressed());
519 if (d->editable && (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return))
522 d->up->setPressed(
false);
523 d->down->setPressed(
false);
524 d->q_func()->setAccessibleProperty(
"pressed",
false);
531 if (event->timerId() == d->delayTimer) {
532 d->startPressRepeat();
533 }
else if (event->timerId() == d->repeatTimer) {
534 if (d->up->isPressed())
536 else if (d->down->isPressed())
541#if QT_CONFIG(wheelevent)
558 auto *derived =
static_cast<Derived *>(
this);
561 QQmlContext *context = qmlContext(derived);
563 QQmlEngine::setContextForObject(d->up, context);
564 QQmlEngine::setContextForObject(d->down, context);
572 QQuickIndicatorButtonPrivate::get(d->up)->executeIndicator(
true);
573 QQuickIndicatorButtonPrivate::get(d->down)->executeIndicator(
true);
575 if (!d->setValue(d->value,
false ,
577 d->updateDisplayText();
578 d->updateUpEnabled();
579 d->updateDownEnabled();
583 void handleItemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &value)
586 if (d->editable && change == QQuickItem::ItemActiveFocusHasChanged && !value.boolValue)
593 d->updateDisplayText();
598#if QT_CONFIG(accessibility)
613 auto *derived =
static_cast<Derived *>(
this);
615 d->up =
new QQuickIndicatorButton(derived);
616 d->down =
new QQuickIndicatorButton(derived);
617 d->setSizePolicy(QLayoutPolicy::Preferred, QLayoutPolicy::Fixed);
619 derived->setFlag(QQuickItem::ItemIsFocusScope);
620 derived->setFiltersChildMouseEvents(
true);
621 derived->setAcceptedMouseButtons(Qt::LeftButton);
623 derived->setCursor(Qt::ArrowCursor);
625#if QT_CONFIG(quicktemplates2_multitouch)
626 derived->setAcceptTouchEvents(
true);
633 d->removeImplicitSizeListener(d->up->indicator());
634 d->removeImplicitSizeListener(d->down->indicator());
const Derived * q_func() const
ValueType boundValue(ValueType value, bool wrap) const
virtual bool setValue(ValueType newValue, bool wrap, ValueStatus modified)=0
void itemImplicitHeightChanged(QQuickItem *item) override
void setDisplayText(const QString &text)
Qt::InputMethodHints inputMethodHints
bool handlePress(const QPointF &point, ulong timestamp) override
void handleUngrab() override
QQuickIndicatorButton * down
QQuickAbstractSpinBoxPrivate()
virtual void updateDisplayText()=0
void itemDestroyed(QQuickItem *item) override
void updateHover(const QPointF &pos)
bool handleRelease(const QPointF &point, ulong timestamp) override
bool stepBy(ValueType steps, ValueStatus modified)
QQuickIndicatorButton * up
void increase(ValueStatus modified)
QPalette defaultPalette() const override
static constexpr int AUTO_REPEAT_DELAY
void itemImplicitWidthChanged(QQuickItem *item) override
ValueType effectiveStepSize() const
void decrease(ValueStatus modified)
virtual void updateValue()=0
static constexpr int AUTO_REPEAT_INTERVAL
bool handleMove(const QPointF &point, ulong timestamp) override
QQuickAbstractSpinBox & operator=(const QQuickAbstractSpinBox &)=delete
void setInputMethodHints(Qt::InputMethodHints hints)
void handleTimerEvent(QTimerEvent *event)
void handleFocusInEvent(QFocusEvent *event)
void handleHoverMoveEvent(QHoverEvent *event)
void handleKeyReleaseEvent(QKeyEvent *event)
void handleComponentComplete()
QQuickIndicatorButton * down() const
void setEditable(bool editable)
QFont defaultFont() const
bool isInputMethodComposing() const
void setValueFromText(const QJSValue &callback)
QQuickIndicatorButton * up() const
Qt::InputMethodHints inputMethodHints() const
ValueType stepSize() const
void handleHoverLeaveEvent(QHoverEvent *event)
void handleLocaleChange()
QQuickAbstractSpinBox(const QQuickAbstractSpinBox &)=delete
void setTextFromValue(const QJSValue &callback)
QString displayText() const
void handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
void handleKeyPressEvent(QKeyEvent *event)
void handleHoverEnterEvent(QHoverEvent *event)