NDEVR
API Documentation
Ruler

A widget meant to be placed beside a camera view showing either directional or measurement markings depending on whether or not a camera is orthographic. More...

Collaboration diagram for Ruler:
[legend]

Public Types

enum  LabelMode { e_camera_location , e_selection , e_none }
 Controls what information is displayed as a label on the ruler. More...

Public Member Functions

 Ruler (bool is_horizontal, bool is_left_or_top, QWidget *parent=nullptr)
 Constructs a Ruler widget with the specified orientation and side.
 Ruler (QWidget *parent=nullptr)
 Constructs a horizontal Ruler widget.
 ~Ruler ()
 Destroys this Ruler widget.
uint01 dimension () const
 Returns the dimension index this ruler represents.
String label () const
 Returns the current label text.
RGBColor labelBackground ()
 Returns the background color for the label.
void paintBackground (QPainter &g2D)
 Paints the ruler background.
void paintEvent (QPaintEvent *event) override
 Paints the ruler including background, tick marks, and labels.
void paintRuler (QPainter &g2D)
 Paints the ruler tick marks and labels.
void setCamera (const DynamicPointer< Camera > &camera)
 Sets the camera whose view this ruler reflects.
void setHorizontal (bool is_horizontal)
 Sets the orientation of the ruler.
void setLabel (const String &label, const Vector< 2, fltp08 > &location=Vector< 2, fltp08 >(0.0))
 Sets a label to display on the ruler at the given location.
void setLabelMode (LabelMode mode)
 Sets the label display mode.
void setLabelsVisible (bool visible)
 Sets whether tick mark labels are visible.
void setScroller (QScrollArea *scroll_area_target, fltp08 scroll_scale=1.0)
 Associates a scroll area with this ruler for synchronized scrolling.
QSize sizeHint () const override
 Returns the recommended size for this widget.

Static Public Attributes

static const int MARGIN = 4
 The pixel margin around the ruler.

Protected Member Functions

uint04 convertModelToPixel (uint04 dim, fltp08 model)
 Converts a model-space coordinate to a pixel coordinate.
fltp08 convertPixelToModel (uint04 dim, uint04 pixel)
 Converts a pixel coordinate to a model-space coordinate.
TranslatedString getFormattedTickText (fltp08 value, fltp08 spacing, uint01 dim)
 Formats a tick mark value as a display string with appropriate precision.
fltp08 labelPixelLocation () const
 Returns the pixel location of the label along the ruler.
fltp08 scale () const
 Returns the pixels-per-world-unit scale factor.
void setAxis ()
 Updates the axis mapping based on the current orientation.
const ConstPointer< Unit > & unit () const
 Returns the unit associated with the ruler's camera.
Bounds< 3, fltp08worldBounds () const
 Returns the world-space bounding box visible in the camera view.
fltp08 worldGridSpacing () const
 Returns the world-space spacing between grid lines or tick marks.
fltp08 worldOffset () const
 Returns the world-space offset for the start of the ruler.
fltp08 worldSpan () const
 Returns the world-space span along this ruler's dimension.

Protected Attributes

Vector< 2, uint01m_axis
 The axis mapping for ruler dimensions.
ConstPointer< Cameram_camera
 The camera this ruler tracks.
QTResourceListenerm_camera_listener = nullptr
 Listener for camera property changes.
QTResourceListenerm_coordinate_listener = nullptr
 Listener for coordinate system changes.
bool m_draw_minor
 Whether to draw minor tick marks.
bool m_is_horizontal = true
 Whether the ruler is oriented horizontally.
bool m_is_left_or_top
 Whether the ruler is on the left or top side.
bool m_is_opaque
 Whether the ruler background is opaque.
Vector< 2, uint01m_label_axis
 The axis mapping for label positioning.
RGBColor m_label_background
 The background color for the label.
fltp08 m_label_location
 The current label position along the ruler.
LabelMode m_label_mode
 The current label display mode.
QRect m_label_rect
 The bounding rectangle for the current label.
String m_label_text
 The current label text.
bool m_labels_visible
 Whether tick mark labels are visible.
RGBColor m_last_label_background
 The label background from the last paint operation.
fltp08 m_last_label_location
 The label location from the last paint operation.
String m_last_label_text
 The label text from the last paint operation.
fltp08 m_last_paint_scale
 The scale factor from the last paint operation.
fltp08 m_last_world_offset
 The world offset from the last paint operation.
fltp08 m_last_world_spacing
 The world grid spacing from the last paint operation.
QScrollArea * m_scroll_area_target = nullptr
 The scroll area this ruler is synchronized with.
fltp08 m_scroll_scale = 1.0
 The scale factor for scroll area synchronization.

Detailed Description

A widget meant to be placed beside a camera view showing either directional or measurement markings depending on whether or not a camera is orthographic.


Definition at line 53 of file Ruler.h.

Member Enumeration Documentation

◆ LabelMode

Controls what information is displayed as a label on the ruler.

Enumerator
e_camera_location 

Shows the current camera location on the ruler.

e_selection 

Shows the current selection position on the ruler.

e_none 

No label is displayed.

Definition at line 60 of file Ruler.h.

Constructor & Destructor Documentation

◆ Ruler() [1/2]

Ruler::Ruler ( QWidget * parent = nullptr)

Constructs a horizontal Ruler widget.

Parameters
[in]parentThe parent widget.

◆ Ruler() [2/2]

Ruler::Ruler ( bool is_horizontal,
bool is_left_or_top,
QWidget * parent = nullptr )

Constructs a Ruler widget with the specified orientation and side.

Parameters
[in]is_horizontalWhether the ruler is horizontal (true) or vertical (false).
[in]is_left_or_topWhether the ruler is on the left/top side of the viewport.
[in]parentThe parent widget.

Member Function Documentation

◆ convertModelToPixel()

uint04 Ruler::convertModelToPixel ( uint04 dim,
fltp08 model )
protected

Converts a model-space coordinate to a pixel coordinate.

Parameters
[in]dimThe dimension index.
[in]modelThe model-space coordinate.
Returns
The pixel coordinate.

◆ convertPixelToModel()

fltp08 Ruler::convertPixelToModel ( uint04 dim,
uint04 pixel )
protected

Converts a pixel coordinate to a model-space coordinate.

Parameters
[in]dimThe dimension index.
[in]pixelThe pixel coordinate.
Returns
The model-space coordinate.

◆ dimension()

uint01 Ruler::dimension ( ) const
inline

Returns the dimension index this ruler represents.

Returns
X (0) for horizontal rulers, Y (1) for vertical rulers.

Definition at line 150 of file Ruler.h.

References m_is_horizontal.

◆ getFormattedTickText()

TranslatedString Ruler::getFormattedTickText ( fltp08 value,
fltp08 spacing,
uint01 dim )
protected

Formats a tick mark value as a display string with appropriate precision.

Parameters
[in]valueThe world-space value to format.
[in]spacingThe current tick spacing, used to determine precision.
[in]dimThe dimension index.
Returns
The formatted tick label text.

◆ label()

String Ruler::label ( ) const

Returns the current label text.

Returns
The label text.

Referenced by setLabel().

◆ labelBackground()

RGBColor Ruler::labelBackground ( )

Returns the background color for the label.

Returns
The label background color.

◆ labelPixelLocation()

fltp08 Ruler::labelPixelLocation ( ) const
protected

Returns the pixel location of the label along the ruler.

Returns
The label position in pixels.

◆ paintBackground()

void Ruler::paintBackground ( QPainter & g2D)

Paints the ruler background.

Parameters
[in]g2DThe painter to draw with.

◆ paintEvent()

void Ruler::paintEvent ( QPaintEvent * event)
override

Paints the ruler including background, tick marks, and labels.

Parameters
[in]eventThe paint event.

◆ paintRuler()

void Ruler::paintRuler ( QPainter & g2D)

Paints the ruler tick marks and labels.

Parameters
[in]g2DThe painter to draw with.

◆ scale()

fltp08 Ruler::scale ( ) const
protected

Returns the pixels-per-world-unit scale factor.

Returns
The scale factor.

◆ setCamera()

void Ruler::setCamera ( const DynamicPointer< Camera > & camera)

Sets the camera whose view this ruler reflects.

Parameters
[in]cameraThe camera to track.

◆ setHorizontal()

void Ruler::setHorizontal ( bool is_horizontal)

Sets the orientation of the ruler.

Parameters
[in]is_horizontalWhether the ruler is horizontal (true) or vertical (false).

◆ setLabel()

void Ruler::setLabel ( const String & label,
const Vector< 2, fltp08 > & location = Vector< 2, fltp08 >(0.0) )

Sets a label to display on the ruler at the given location.

Parameters
[in]labelThe label text.
[in]locationThe 2D position for the label in normalized coordinates.

References label().

◆ setLabelMode()

void Ruler::setLabelMode ( LabelMode mode)

Sets the label display mode.

Parameters
[in]modeThe label mode to use.

◆ setLabelsVisible()

void Ruler::setLabelsVisible ( bool visible)

Sets whether tick mark labels are visible.

Parameters
[in]visibleWhether labels should be shown.

◆ setScroller()

void Ruler::setScroller ( QScrollArea * scroll_area_target,
fltp08 scroll_scale = 1.0 )

Associates a scroll area with this ruler for synchronized scrolling.

Parameters
[in]scroll_area_targetThe scroll area to synchronize with.
[in]scroll_scaleThe scale factor applied to scroll offset calculations.

◆ sizeHint()

QSize Ruler::sizeHint ( ) const
override

Returns the recommended size for this widget.

Returns
The size hint.

◆ unit()

const ConstPointer< Unit > & Ruler::unit ( ) const
protected

Returns the unit associated with the ruler's camera.

Returns
The unit.

◆ worldBounds()

Bounds< 3, fltp08 > Ruler::worldBounds ( ) const
protected

Returns the world-space bounding box visible in the camera view.

Returns
The 3D world bounds.

◆ worldGridSpacing()

fltp08 Ruler::worldGridSpacing ( ) const
protected

Returns the world-space spacing between grid lines or tick marks.

Returns
The grid spacing in world units.

◆ worldOffset()

fltp08 Ruler::worldOffset ( ) const
protected

Returns the world-space offset for the start of the ruler.

Returns
The world offset.

◆ worldSpan()

fltp08 Ruler::worldSpan ( ) const
protected

Returns the world-space span along this ruler's dimension.

Returns
The world span.

The documentation for this class was generated from the following file: