DragNumber

A draggable box of one to four numbers.

Declared in src/libs/libwidgets/components/DragNumber.hpp
Inherits QWidget
Group libwidgets

Detailed description

A press and a vertical drag on a number change it through the shared DragMotor engine. A vector shows as one box, <x, y, z>, with one prefix and one suffix, and one number takes a drag at a time (vector-drag-number §VND-1).

The default Field presentation draws the numbers in Typography::monospace() on a column grid: the decimal point of each number sits on one column, and a group of boxes that share their Columns (alignColumns()) put their points and arrows at one x (§VND-5, §VND-9). The step arrows paint on the hovered number only (§VND-6). The Paint presentation keeps paint's ModulationCell look bit for bit (§DN-2).

DragNumber

See also dragmotor, dragnumberformat::layout().

Member function documentation

DragNumber

[explicit] DragNumber::DragNumber(QWidget *parent = nullptr)

Creates a one-number box in the Field presentation with parent.

The default config is the harness-tuned baseline of §DT-5.

alignColumns

[static] void DragNumber::alignColumns(const QList<DragNumber *> &boxes)

Aligns the live boxes of boxes: columnsFor() over them, then setColumns() on each. A box that nobody aligns is a group of one.

arrowRect

QRectF DragNumber::arrowRect(int component) const

Returns where the arrows of component paint: the separator after it, or the slot for the last number (§VND-4, C8).

columnsFor

[static] QList<DragNumber::Columns> DragNumber::columnsFor(const QList<DragNumber::ColumnSource> &rows, const QFont &font)

Returns one Columns per row of rows, in order.

Rows group by component count and by whether they have a suffix, so a vector with no unit keeps its columns beside a vector with one (§VND-10). In a group, the fraction is the largest decimals, and the prefix and suffix widths are the widest, measured in font. The values do not depend on a number, so a host with no live box for a row gets the same result.

componentValue

double DragNumber::componentValue(int component) const

Returns the value of component, or 0 for an index out of range.

See also setComponentValue().

displayDecimals

int DragNumber::displayDecimals() const

Returns the decimals that the box shows: the value of setDecimals(), else 2 for a signed range, and 1 or 2 by the size of the max for an unsigned range (§VND-5).

eventFilter

[override virtual protected] bool DragNumber::eventFilter(QObject *watched, QEvent *event)

Reimplements: QObject::eventFilter(QObject *watched, QEvent *event).

Handles the editor's keys (§VND-7): Escape closes it with no change, Tab and Shift+Tab commit and open the next or the previous number, or pass the focus on from the last or the first.

Filters event for watched, and returns true when it handled the key, which stops the event there.

look

DragNumberLook DragNumber::look() const

Returns every input of the paint as a value (config-ui §CFGP-1).

minimumSizeHint

[override virtual] QSize DragNumber::minimumSizeHint() const

Reimplements an access function for property: QWidget::minimumSizeHint.

Returns the smallest useful size: three columns per number in Field. Narrower, the numbers show '#' (§VND-8).

numberColumnWidth

qreal DragNumber::numberColumnWidth() const

Returns the width of one column of the number grid.

numberFont

QFont DragNumber::numberFont() const

Returns the face of the numbers: the one setNumberFont() gave, or Typography::monospace() at the widget's size.

See also setNumberFont().

numberRect

QRectF DragNumber::numberRect(int component) const

Returns the cell of the number component, in logical px.

paintLook

[static] void DragNumber::paintLook(QPainter *painter, const QRect &rect, const DragNumberLook &look)

Paints look into rect of painter, the pixels the widget paints for the same look.

An item delegate calls it to paint a number cell with no widget (config-ui §CFGV-5a). The paint is clipped to rect.

setColumns

void DragNumber::setColumns(const DragNumber::Columns &columns)

Sets the values that this box shares with its group to columns.

setComponentCount

void DragNumber::setComponentCount(int count)

Sets the number of components to count, clamped to 1..4.

A new component takes the config's value. More than one component switches the box to Field (§VND-2).

setComponentValue

void DragNumber::setComponentValue(int component, double v)

Sets component to v: sanitized and clamped, with no step snap and no signal (§OPR-3b).

See also componentValue().

setComponentValues

void DragNumber::setComponentValues(const QList<double> &values)

Sets every component from values, with one repaint.

setConfig

void DragNumber::setConfig(const dragmotor::AxisConfig &cfg)

Sets the motor config of every component to cfg, and re-seeds every component from cfg.value.

setNumberFont

void DragNumber::setNumberFont(const QFont &font)

Sets the face of the numbers to font.

See also numberFont().

setPresentation

void DragNumber::setPresentation(DragNumber::Presentation presentation)

Sets the look to presentation.

Paint takes one number only, so it also sets the component count to 1.

sizeHint

[override virtual] QSize DragNumber::sizeHint() const

Reimplements an access function for property: QWidget::sizeHint.

Returns the size that shows the whole range at its decimals, or today's text-sized cell for Paint.

In Field the width does not depend on the value (§VND-8, D6).

In this section