NDEVR
API Documentation
Ruler.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: NDEVR
28File: Ruler
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/Camera.h>
35#include <NDEVR/Unit.h>
36#if NDEVR_VIEWPORT
37#include <QWidget>
38class QActionGroup;
39class QAction;
40class QMenu;
41class QWidgetAction;
42class QScrollArea;
43namespace NDEVR
44{
45 class Button;
46 class Ruler;
47 class Toggle;
53 class DESIGN_WIDGETS_API Ruler : public QWidget
54 {
55 public:
56 static const int MARGIN = 4;
66
67 public:
72 Ruler(QWidget* parent = nullptr);
79 Ruler(bool is_horizontal, bool is_left_or_top, QWidget* parent = nullptr);
88 void setCamera(const DynamicPointer<Camera>& camera);
93 QSize sizeHint() const override;
98 void paintEvent(QPaintEvent *event) override;
103 void paintBackground(QPainter& g2D);
108 void paintRuler(QPainter& g2D);
114 void setLabel(const String& label, const Vector<2, fltp08>& location = Vector<2, fltp08>(0.0));
125 void setScroller(QScrollArea* scroll_area_target, fltp08 scroll_scale = 1.0);
130 String label() const;
140 void setLabelsVisible(bool visible);
145 void setHorizontal(bool is_horizontal);
150 uint01 dimension() const { return m_is_horizontal ? X : Y; }
151 protected:
155 void setAxis();
175 fltp08 scale() const;
212 const ConstPointer<Unit>& unit() const;
213 protected:
217 QScrollArea* m_scroll_area_target = nullptr;
218 bool m_is_horizontal = true;
237 };
238
243 class DESIGN_WIDGETS_API CameraRulerMenu : public QObject
244 {
245 Q_OBJECT
246 public:
253 CameraRulerMenu(const DynamicPointer<Camera>& camera, Button* combo, const void* lock_ptr);
259 CameraRulerMenu(Button* combo, const void* lock_ptr);
269 void setLockPointer(const void* lock_ptr);
277 void setShowRuler(const TranslatedString& ruler_name, bool show_vertical, bool show_horizontal, bool show_lockable);
282 protected:
286 void init();
287 signals:
293 void requestShowRuler(bool show_vertical, bool show_horizontal);
294 protected:
298 QMenu* m_menu;
299 QWidgetAction* m_lock_act;
300 QWidgetAction* m_show_vert_act;
301 QWidgetAction* m_show_horz_act;
302 QWidgetAction* m_show_grid_act;
307 QActionGroup* m_view_mode_group;
311 const void* m_lock_ptr;
312 };
313}
314#endif
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:54
A core widget that allows the user to click one of many button types.
Definition Button.h:68
Button * m_combo
The button that opens this menu.
Definition Ruler.h:308
void setShowRuler(const TranslatedString &ruler_name, bool show_vertical, bool show_horizontal, bool show_lockable)
Configures which ruler options are available in the menu.
QWidgetAction * m_show_vert_act
The action for the vertical ruler toggle.
Definition Ruler.h:300
QWidgetAction * m_show_horz_act
The action for the horizontal ruler toggle.
Definition Ruler.h:301
Toggle * m_horz_toggle
The horizontal ruler visibility toggle.
Definition Ruler.h:304
Toggle * m_lock_toggle
The camera lock toggle.
Definition Ruler.h:305
bool m_show_lockable
Whether the lock toggle option is available.
Definition Ruler.h:295
bool m_is_locked
Whether the camera is currently locked.
Definition Ruler.h:296
TranslatedString m_ruler_name
The display name for the ruler.
Definition Ruler.h:310
CameraRulerMenu(Button *combo, const void *lock_ptr)
Constructs a CameraRulerMenu without an initial camera.
void setCamera(const DynamicPointer< Camera > &camera)
Sets the camera whose ruler settings are controlled.
QWidgetAction * m_lock_act
The action for the camera lock toggle.
Definition Ruler.h:299
void updateFromModel()
Updates the menu toggle states from the camera model.
DynamicPointer< Camera > m_camera
The camera whose settings are controlled.
Definition Ruler.h:309
QWidgetAction * m_show_grid_act
The action for the grid display toggle.
Definition Ruler.h:302
const void * m_lock_ptr
The pointer identifying the lock owner.
Definition Ruler.h:311
void setLockPointer(const void *lock_ptr)
Sets the pointer used to identify the lock owner for the camera.
CameraRulerMenu(const DynamicPointer< Camera > &camera, Button *combo, const void *lock_ptr)
Constructs a CameraRulerMenu for the given camera and button.
QActionGroup * m_view_mode_group
The action group for mutually exclusive view modes.
Definition Ruler.h:307
Toggle * m_show_grid_toggle
The grid display toggle.
Definition Ruler.h:306
bool m_is_shown
Whether the ruler is currently shown.
Definition Ruler.h:297
Toggle * m_vert_toggle
The vertical ruler visibility toggle.
Definition Ruler.h:303
void init()
Initializes the menu actions and connects signals.
QMenu * m_menu
The popup menu containing ruler options.
Definition Ruler.h:298
void requestShowRuler(bool show_vertical, bool show_horizontal)
Emitted when the user requests to change ruler visibility.
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition Pointer.hpp:276
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
A ResourceListener which will always be executed on the main UI thread and can be tied to a Qt Object...
Definition QTTools.h:493
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:57
A widget meant to be placed beside a camera view showing either directional or measurement markings d...
Definition Ruler.h:54
RGBColor labelBackground()
Returns the background color for the label.
QScrollArea * m_scroll_area_target
The scroll area this ruler is synchronized with.
Definition Ruler.h:217
Vector< 2, uint01 > m_label_axis
The axis mapping for label positioning.
Definition Ruler.h:224
LabelMode m_label_mode
The current label display mode.
Definition Ruler.h:221
String m_label_text
The current label text.
Definition Ruler.h:219
QTResourceListener * m_coordinate_listener
Listener for coordinate system changes.
Definition Ruler.h:216
Vector< 2, uint01 > m_axis
The axis mapping for ruler dimensions.
Definition Ruler.h:223
fltp08 labelPixelLocation() const
Returns the pixel location of the label along the ruler.
Bounds< 3, fltp08 > worldBounds() const
Returns the world-space bounding box visible in the camera view.
fltp08 m_last_world_offset
The world offset from the last paint operation.
Definition Ruler.h:228
const ConstPointer< Unit > & unit() const
Returns the unit associated with the ruler's camera.
fltp08 m_scroll_scale
The scale factor for scroll area synchronization.
Definition Ruler.h:230
void paintRuler(QPainter &g2D)
Paints the ruler tick marks and labels.
fltp08 scale() const
Returns the pixels-per-world-unit scale factor.
RGBColor m_label_background
The background color for the label.
Definition Ruler.h:220
Ruler(QWidget *parent=nullptr)
Constructs a horizontal Ruler widget.
QSize sizeHint() const override
Returns the recommended size for this widget.
bool m_is_opaque
Whether the ruler background is opaque.
Definition Ruler.h:233
void setLabelMode(LabelMode mode)
Sets the label display mode.
fltp08 m_last_world_spacing
The world grid spacing from the last paint operation.
Definition Ruler.h:227
LabelMode
Controls what information is displayed as a label on the ruler.
Definition Ruler.h:61
@ e_none
No label is displayed.
Definition Ruler.h:64
@ e_camera_location
Shows the current camera location on the ruler.
Definition Ruler.h:62
@ e_selection
Shows the current selection position on the ruler.
Definition Ruler.h:63
TranslatedString getFormattedTickText(fltp08 value, fltp08 spacing, uint01 dim)
Formats a tick mark value as a display string with appropriate precision.
fltp08 m_label_location
The current label position along the ruler.
Definition Ruler.h:229
Ruler(bool is_horizontal, bool is_left_or_top, QWidget *parent=nullptr)
Constructs a Ruler widget with the specified orientation and side.
bool m_is_left_or_top
Whether the ruler is on the left or top side.
Definition Ruler.h:234
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.
static const int MARGIN
The pixel margin around the ruler.
Definition Ruler.h:56
bool m_is_horizontal
Whether the ruler is oriented horizontally.
Definition Ruler.h:218
String label() const
Returns the current label text.
fltp08 m_last_paint_scale
The scale factor from the last paint operation.
Definition Ruler.h:225
void setScroller(QScrollArea *scroll_area_target, fltp08 scroll_scale=1.0)
Associates a scroll area with this ruler for synchronized scrolling.
RGBColor m_last_label_background
The label background from the last paint operation.
Definition Ruler.h:232
void setCamera(const DynamicPointer< Camera > &camera)
Sets the camera whose view this ruler reflects.
String m_last_label_text
The label text from the last paint operation.
Definition Ruler.h:231
void setHorizontal(bool is_horizontal)
Sets the orientation of the ruler.
ConstPointer< Camera > m_camera
The camera this ruler tracks.
Definition Ruler.h:222
QRect m_label_rect
The bounding rectangle for the current label.
Definition Ruler.h:214
fltp08 m_last_label_location
The label location from the last paint operation.
Definition Ruler.h:226
~Ruler()
Destroys this Ruler widget.
bool m_labels_visible
Whether tick mark labels are visible.
Definition Ruler.h:236
bool m_draw_minor
Whether to draw minor tick marks.
Definition Ruler.h:235
fltp08 worldGridSpacing() const
Returns the world-space spacing between grid lines or tick marks.
uint01 dimension() const
Returns the dimension index this ruler represents.
Definition Ruler.h:150
void setLabelsVisible(bool visible)
Sets whether tick mark labels are visible.
void setAxis()
Updates the axis mapping based on the current orientation.
QTResourceListener * m_camera_listener
Listener for camera property changes.
Definition Ruler.h:215
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.
uint04 convertModelToPixel(uint04 dim, fltp08 model)
Converts a model-space coordinate to a pixel coordinate.
void paintBackground(QPainter &g2D)
Paints the ruler background.
void paintEvent(QPaintEvent *event) override
Paints the ruler including background, tick marks, and labels.
fltp08 convertPixelToModel(uint04 dim, uint04 pixel)
Converts a pixel coordinate to a model-space coordinate.
The core String class for the NDEVR API.
Definition String.h:95
A Button that toggles between on and off.
Definition Toggle.h:50
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...