Skip to content

DialWidget

class nmeasim::app::DialWidget · Applications

Common look of the round instruments: a square widget with a bezel, a ring of ticks and a caption, painted in the colours of the current theme.

Inherits QWidget

Inherited by nmeasim::app::CompassDial, nmeasim::app::WindDial

Declared in src/app/widgets/dials.hpp (line 48)

Subclasses paint in their paintEvent with the protected helpers, which place everything by an angle in degrees clockwise from the top of the dial and a fraction of radius. The widget repaints whenever theme::Theme::changed is emitted, and prefers to stay square (heightForWidth returns the width).

Summary

Public member functions

Name Description
DialWidget() Creates a dial that expands in both directions and follows theme changes.
sizeHint() Returns the preferred size, 240 by 240 pixels.
minimumSizeHint() Returns the smallest size at which the labels stay legible, 170 by 170 pixels.
hasHeightForWidth() Tells layouts that the height depends on the width, so that the dial stays square.
heightForWidth() Returns the preferred height for a width: the width itself, keeping the dial square.

Protected member functions

Name Description
radius() Returns the radius of the tick ring in widget pixels.
centre() Returns the centre of the dial.
at() Returns a point at an angle and a distance from the centre.
draw_face() Draws the bezel and the background disc.
draw_ticks() Draws the ring of ticks just inside the edge of the face.
draw_ring_marker() Draws a marker on the ring: a filled or hollow triangle pointing at the centre.
draw_readout() Draws a large readout with a small caption above it.

Public member functions

DialWidget()

explicit DialWidget(QWidget* parent = nullptr)

Creates a dial that expands in both directions and follows theme changes.

Parameters

Name Type Description
parent QWidget* Parent widget, which owns the dial; may be null, in which case the caller owns it.

Declared in src/app/widgets/dials.hpp:56 · defined in src/app/widgets/dials.cpp:73

sizeHint()

QSize sizeHint() const override

Returns the preferred size, 240 by 240 pixels.

Returns QSize: QSize(240, 240).

Declared in src/app/widgets/dials.hpp:61

minimumSizeHint()

QSize minimumSizeHint() const override

Returns the smallest size at which the labels stay legible, 170 by 170 pixels.

Returns QSize: QSize(170, 170).

Declared in src/app/widgets/dials.hpp:65

hasHeightForWidth()

bool hasHeightForWidth() const override

Tells layouts that the height depends on the width, so that the dial stays square.

Returns bool: Always true.

Declared in src/app/widgets/dials.hpp:69

heightForWidth()

int heightForWidth(int width) const override

Returns the preferred height for a width: the width itself, keeping the dial square.

Parameters

Name Type Description
width int Available width in pixels.

Returns int: width.

Declared in src/app/widgets/dials.hpp:74

Protected member functions

radius()

double radius() const

Returns the radius of the tick ring in widget pixels.

Returns double: Half the shorter side of the widget less an 8-pixel margin that leaves room for the bezel, and never less than 10.

Declared in src/app/widgets/dials.hpp:81 · defined in src/app/widgets/dials.cpp:78

centre()

QPointF centre() const

Returns the centre of the dial.

Returns QPointF: The centre of the widget, in widget pixels.

Declared in src/app/widgets/dials.hpp:85 · defined in src/app/widgets/dials.cpp:82

at()

QPointF at(double angle_deg, double fraction) const

Returns a point at an angle and a distance from the centre.

Parameters

Name Type Description
angle_deg double Angle in degrees clockwise from the top of the dial; any finite value.
fraction double Distance from the centre as a fraction of radius; 1 is the outer edge of the tick ring.

Returns QPointF: The point in widget pixels.

Declared in src/app/widgets/dials.hpp:92 · defined in src/app/widgets/dials.cpp:86

draw_face()

void draw_face(QPainter& painter) const

Draws the bezel and the background disc.

The bezel is a disc 6 pixels larger than radius in the raised panel colour; the face inside it has the inset colour of the theme.

Parameters

Name Type Description
painter QPainter& Painter open on this widget.

Declared in src/app/widgets/dials.hpp:99 · defined in src/app/widgets/dials.cpp:91

draw_ticks()

void draw_ticks(QPainter& painter, int minor, int major) const

Draws the ring of ticks just inside the edge of the face.

Major ticks are longer and drawn in the text colour, minor ones in the dimmed text colour. Ticks start at the top of the dial.

Parameters

Name Type Description
painter QPainter& Painter open on this widget.
minor int Spacing of all ticks, in degrees; must be positive.
major int Spacing of the long ticks, in degrees; a tick is major when its angle is a multiple of major, which must be positive.

Declared in src/app/widgets/dials.hpp:109 · defined in src/app/widgets/dials.cpp:102

draw_ring_marker()

void draw_ring_marker(
    QPainter& painter,
    double angle_deg,
    const QColor& color,
    bool filled) const

Draws a marker on the ring: a filled or hollow triangle pointing at the centre.

The triangle's base lies on the edge of the ring and its tip at 0.84 of the radius.

Parameters

Name Type Description
painter QPainter& Painter open on this widget.
angle_deg double Direction of the marker, in degrees clockwise from the top of the dial.
color const QColor& Colour of the outline and, when filled, of the fill.
filled bool True for a solid triangle, false for an outline only.

Declared in src/app/widgets/dials.hpp:118 · defined in src/app/widgets/dials.cpp:111

draw_readout()

void draw_readout(
    QPainter& painter,
    const QString& caption,
    const QString& value,
    double y_fraction,
    double size_fraction,
    const QColor& color) const

Draws a large readout with a small caption above it.

The caption is bold, in the dimmed text colour; the value uses theme::Theme::readout_font. Both are centred horizontally across the dial.

Parameters

Name Type Description
painter QPainter& Painter open on this widget.
caption const QString& Caption text, such as HDG °T.
value const QString& Value text.
y_fraction double Vertical position of the value's centre as a fraction of the radius: positive below the centre of the dial, negative above.
size_fraction double Pixel height of the value text as a fraction of the radius.
color const QColor& Colour of the value text.

Declared in src/app/widgets/dials.hpp:132 · defined in src/app/widgets/dials.cpp:125