NDEVR
API Documentation
QTTools

Manages static logic dealing with Qt and relating to the application. More...

Collaboration diagram for QTTools:
[legend]

Static Public Member Functions

static void AutosetName (QWidget *widget, const TranslatedString &title, const StringView &object_class)
 Automatically sets the object name on a widget based on the title and class.
static QString AutoWrapText (const QString &value, const QFontMetrics &metrics, fltp08 length)
 Wraps text automatically at word boundaries to fit within a given pixel length.
static void ClearLayout (QLayout *layout, bool delete_objects=false)
 Removes all items from a layout, optionally deleting the child widgets.
static void ClearPallete (QWidget *widget)
 Resets a widget's palette to the default application palette.
static QFont convert (const Font &font)
 Converts an NDEVR Font to a QFont.
static RGBColor convert (const QColor &color)
 Converts a QColor to an NDEVR RGBColor.
static File convert (const QFile &file)
 Converts a QFile to an NDEVR File.
static Font convert (const QFont &q_font)
 Converts a QFont to an NDEVR Font.
static QColor convert (const RGBColor &color)
 Converts an NDEVR RGBColor to a QColor.
static KeyEvent convert (QKeyEvent *event)
 Converts a Qt QKeyEvent to an NDEVR KeyEvent.
static KeyEvent::KEY ConvertNativeKeyEvent (sint08 key)
 Converts a native platform key code to an NDEVR KeyEvent::KEY value.
static fltp08 DefaultAnimationScale ()
 Returns the default animation time scale factor.
static QSurfaceFormat DefaultSurfaceFormat (bool debug)
 Returns the default QSurfaceFormat for OpenGL surfaces.
static qreal DevicePixelRatio (QWindow *window=nullptr)
 Returns the device pixel ratio for the given window, or the primary screen if null.
static fltp08 DPI ()
 Returns the current screen DPI.
static QPixmap * DrawAnimationWidget (QWidget *widget, bool draw_background, QPixmap *pixmap=nullptr, QSize size=QSize())
 Renders a widget into a pixmap suitable for animation snapshots.
static QPixmap * DrawFullWidget (QWidget *widget, bool draw_background, QPixmap *pixmap=nullptr, QSize size=QSize())
 Renders a complete widget and its children into a pixmap.
template<typename EnumType>
static String EnumString (const EnumType &enumValue)
 Converts a Qt enum value to a human-readable String including class and enum name.
static void FitTextToCircle (QString &text, QFont &font, const fltp08 radius, fltp08 split_y_fraction, bool allow_new_line=true)
 Adjusts text and font so the text fits within a circle.
static void FitTextToRect (QString &text, QFont &font, const QRectF &size, bool allow_new_line=true)
 Adjusts text and font so the text fits within a rectangle, potentially adding line breaks.
static void ForceSizeCalculation (QWidget *widget, bool process_events=false)
 Forces a widget to recalculate its size, optionally processing pending events.
static void FormatPallete (bool error, QWidget *widget)
 Applies an error or normal formatting to a widget's palette.
static Buffer< QFont > GetFontRecursive (QWidget *widget)
 Recursively collects the fonts used by a widget and all its children.
static void HideDialog (QWidget *widget, PopupInfo end_location=PopupInfo())
 Hides a dialog widget with an optional animation to an end location.
static bool IsVisibleToUser (QWidget *widget)
 Checks whether a widget is visible to the user, accounting for popups and tabs.
static bool IsWidgetVisibleOnScreen (QWidget *widget)
 Checks whether a widget is currently visible on any screen.
static LogPtr log ()
 Returns the global log for the Widgets module.
static void MultiplyFontSize (QFont &font, fltp08 multiplier)
 Multiplies the font size by a given factor.
static fltp08 PixelSize (const QFont &font)
 Returns the pixel size of a font, converting from point size if necessary.
static fltp08 PointSize (const QFont &font)
 Returns the point size of a font, converting from pixel size if necessary.
static QRect PopupMenuLocation (QWidget *widget, const QSize &size)
 Calculates a suitable popup menu location relative to a widget.
static QRect PopupMenuLocation (QWidget *widget, QRect popup_origin, const QSize &size)
 Calculates a suitable popup menu location relative to a widget with a given origin.
static void PostToThread (QObject *target, std::function< void()> &&fun)
 Posts a function to be executed on the thread that owns the target QObject.
static void PostToThread (std::function< void()> &&fun, QThread *thread=nullptr)
 Posts a function to be executed on the specified thread, or the main thread if none is given.
static Module QTModule ()
 Returns the Module descriptor for the Qt integration module.
static void RequestExit (bool relaunch, const PopupInfo &popup_origin=PopupInfo())
 Requests the application to exit, optionally relaunching afterward.
static void RequestScreenOrientation (bool horizontal)
 Requests the screen orientation to be horizontal or vertical.
static void RequestScreenResolution (const Vector< 2, uint04 > &size)
 Requests a specific screen resolution.
static QSize ScaleFontSizeToFit (QFont &font, const QString &text, const QRect &rect, bool shrink=true, bool grow=false)
 Scales a font size so that the given text fits within the specified rectangle.
static QScreen * ScreenForWidget (const QWidget *widget)
 Returns the QScreen that contains the given widget.
static void ServiceQT ()
 Processes pending Qt events in the current event loop.
static void SetFontRecursive (QWidget *widget, const Buffer< QFont > &font)
 Recursively restores fonts on a widget and all its children from a buffer.
static void SetFontRecursive (QWidget *widget, const QFont &font)
 Recursively sets the font on a widget and all its children.
static void SetStyleRecursive (QWidget *widget, QStyle *style)
 Recursively sets the QStyle on a widget and all its children.
static bool ShowDialog (QWidget *widget, PopupInfo info, PopupInfo end_location=PopupInfo())
 Shows a dialog widget with animation and positioning specified by PopupInfo.
static void ShowExperimentalFeatureDialog (const TranslatedString &feature)
 Shows a dialog informing the user that a feature is experimental.
static bool ShowMessageBox (const GenericOption &options, const StringView &image, std::function< bool(GenericOption, PopupInfo info)> on_select, const PopupInfo &popup_origin=PopupInfo())
 Shows a message box configured by a GenericOption with an image.
static bool ShowMessageBox (const GenericOption &options, std::function< bool(GenericOption, PopupInfo info)> on_select, const PopupInfo &popup_origin=PopupInfo())
 Shows a message box configured by a GenericOption.
static bool ShowMessageBox (const TranslatedString &title, const StringView &image, const TranslatedString &text, const TranslatedStringBuffer &button_labels, std::function< void(TranslatedString, PopupInfo info)> on_select=nullptr, const PopupInfo &popup_origin=PopupInfo())
 Shows a message box with an image and custom-labeled buttons.
static bool ShowMessageBox (const TranslatedString &title, const StringView &image, const TranslatedString &text, QMessageBox::StandardButtons buttons={ QMessageBox::StandardButton::Ok }, std::function< void(QMessageBox::StandardButton, PopupInfo info)> on_select=nullptr, const PopupInfo &popup_origin=PopupInfo())
 Shows a message box with an image and standard buttons.
static bool ShowMessageBox (const TranslatedString &title, const TranslatedString &text, const TranslatedStringBuffer &button_labels, std::function< void(TranslatedString, PopupInfo info)> on_select=nullptr, const PopupInfo &popup_origin=PopupInfo())
 Shows a message box with custom-labeled buttons.
static bool ShowMessageBox (const TranslatedString &title, const TranslatedString &text, QMessageBox::StandardButtons buttons={ QMessageBox::StandardButton::Ok }, std::function< void(QMessageBox::StandardButton, PopupInfo info)> on_select=nullptr, const PopupInfo &popup_origin=PopupInfo())
 Shows a message box with standard buttons.

Static Public Attributes

static Resource< bool > is_horizontal
 Resource tracking whether the screen is in horizontal (landscape) orientation.

Detailed Description

Manages static logic dealing with Qt and relating to the application.


Definition at line 72 of file QTTools.h.

Member Function Documentation

◆ AutosetName()

void QTTools::AutosetName ( QWidget * widget,
const TranslatedString & title,
const StringView & object_class )
static

Automatically sets the object name on a widget based on the title and class.

Parameters
[in]widgetThe widget to name.
[in]titleThe translated title.
[in]object_classThe class name prefix.

◆ AutoWrapText()

QString QTTools::AutoWrapText ( const QString & value,
const QFontMetrics & metrics,
fltp08 length )
static

Wraps text automatically at word boundaries to fit within a given pixel length.

Parameters
[in]valueThe text to wrap.
[in]metricsThe font metrics used for measuring text width.
[in]lengthThe maximum line length in pixels.
Returns
The wrapped text with newlines inserted.

◆ ClearLayout()

void QTTools::ClearLayout ( QLayout * layout,
bool delete_objects = false )
static

Removes all items from a layout, optionally deleting the child widgets.

Parameters
[in]layoutThe layout to clear.
[in]delete_objectsWhether to delete the child widget objects.

◆ ClearPallete()

void QTTools::ClearPallete ( QWidget * widget)
static

Resets a widget's palette to the default application palette.

Parameters
[in]widgetThe widget to reset.

◆ convert() [1/6]

QFont QTTools::convert ( const Font & font)
static

Converts an NDEVR Font to a QFont.

Parameters
[in]fontThe NDEVR font.
Returns
The equivalent QFont.

◆ convert() [2/6]

RGBColor QTTools::convert ( const QColor & color)
static

Converts a QColor to an NDEVR RGBColor.

Parameters
[in]colorThe Qt color.
Returns
The equivalent RGBColor.

◆ convert() [3/6]

File QTTools::convert ( const QFile & file)
static

Converts a QFile to an NDEVR File.

Parameters
[in]fileThe Qt file.
Returns
The equivalent NDEVR File.

◆ convert() [4/6]

Font QTTools::convert ( const QFont & q_font)
static

Converts a QFont to an NDEVR Font.

Parameters
[in]q_fontThe Qt font.
Returns
The equivalent NDEVR Font.

◆ convert() [5/6]

QColor QTTools::convert ( const RGBColor & color)
static

Converts an NDEVR RGBColor to a QColor.

Parameters
[in]colorThe NDEVR color.
Returns
The equivalent QColor.

◆ convert() [6/6]

KeyEvent QTTools::convert ( QKeyEvent * event)
static

Converts a Qt QKeyEvent to an NDEVR KeyEvent.

Parameters
[in]eventThe Qt key event.
Returns
The equivalent NDEVR KeyEvent.

◆ ConvertNativeKeyEvent()

KeyEvent::KEY QTTools::ConvertNativeKeyEvent ( sint08 key)
static

Converts a native platform key code to an NDEVR KeyEvent::KEY value.

Parameters
[in]keyThe native key code.
Returns
The corresponding NDEVR key enumeration value.

◆ DefaultAnimationScale()

fltp08 QTTools::DefaultAnimationScale ( )
static

Returns the default animation time scale factor.

Returns
The animation scale multiplier.

◆ DefaultSurfaceFormat()

QSurfaceFormat QTTools::DefaultSurfaceFormat ( bool debug)
static

Returns the default QSurfaceFormat for OpenGL surfaces.

Parameters
[in]debugWhether to enable debug context.
Returns
The configured QSurfaceFormat.

◆ DevicePixelRatio()

qreal QTTools::DevicePixelRatio ( QWindow * window = nullptr)
static

Returns the device pixel ratio for the given window, or the primary screen if null.

Parameters
[in]windowThe window to query, or nullptr for the default.
Returns
The device pixel ratio.

◆ DPI()

fltp08 QTTools::DPI ( )
static

Returns the current screen DPI.

Returns
The dots-per-inch value.

◆ DrawAnimationWidget()

QPixmap * QTTools::DrawAnimationWidget ( QWidget * widget,
bool draw_background,
QPixmap * pixmap = nullptr,
QSize size = QSize() )
static

Renders a widget into a pixmap suitable for animation snapshots.

Parameters
[in]widgetThe widget to render.
[in]draw_backgroundWhether to include the background.
[in]pixmapAn optional existing pixmap to reuse.
[in]sizeThe target rendering size, or default for the widget's size.
Returns
Pointer to the rendered QPixmap.

◆ DrawFullWidget()

QPixmap * QTTools::DrawFullWidget ( QWidget * widget,
bool draw_background,
QPixmap * pixmap = nullptr,
QSize size = QSize() )
static

Renders a complete widget and its children into a pixmap.

Parameters
[in]widgetThe widget to render.
[in]draw_backgroundWhether to include the background.
[in]pixmapAn optional existing pixmap to reuse.
[in]sizeThe target rendering size, or default for the widget's size.
Returns
Pointer to the rendered QPixmap.

◆ EnumString()

template<typename EnumType>
String QTTools::EnumString ( const EnumType & enumValue)
inlinestatic

Converts a Qt enum value to a human-readable String including class and enum name.

Parameters
[in]enumValueThe Qt enum value.
Returns
A formatted string such as "ClassName : EnumName : ValueName".

Definition at line 439 of file QTTools.h.

◆ FitTextToCircle()

void QTTools::FitTextToCircle ( QString & text,
QFont & font,
const fltp08 radius,
fltp08 split_y_fraction,
bool allow_new_line = true )
static

Adjusts text and font so the text fits within a circle.

Parameters
[in]textThe text to modify in-place.
[in]fontThe font to modify in-place.
[in]radiusThe circle radius.
[in]split_y_fractionVertical fraction at which to split text lines.
[in]allow_new_lineWhether line breaks may be inserted.

◆ FitTextToRect()

void QTTools::FitTextToRect ( QString & text,
QFont & font,
const QRectF & size,
bool allow_new_line = true )
static

Adjusts text and font so the text fits within a rectangle, potentially adding line breaks.

Parameters
[in]textThe text to modify in-place.
[in]fontThe font to modify in-place.
[in]sizeThe target rectangle.
[in]allow_new_lineWhether line breaks may be inserted.

◆ ForceSizeCalculation()

void QTTools::ForceSizeCalculation ( QWidget * widget,
bool process_events = false )
static

Forces a widget to recalculate its size, optionally processing pending events.

Parameters
[in]widgetThe widget to recalculate.
[in]process_eventsWhether to process pending Qt events during the calculation.

◆ FormatPallete()

void QTTools::FormatPallete ( bool error,
QWidget * widget )
static

Applies an error or normal formatting to a widget's palette.

Parameters
[in]errorWhether to apply error formatting (true) or normal formatting (false).
[in]widgetThe widget to format.

◆ GetFontRecursive()

Buffer< QFont > QTTools::GetFontRecursive ( QWidget * widget)
static

Recursively collects the fonts used by a widget and all its children.

Parameters
[in]widgetThe root widget.
Returns
A buffer of QFont objects matching the widget hierarchy.

◆ HideDialog()

void QTTools::HideDialog ( QWidget * widget,
PopupInfo end_location = PopupInfo() )
static

Hides a dialog widget with an optional animation to an end location.

Parameters
[in]widgetThe dialog widget to hide.
[in]end_locationOptional end location for the hide animation.

◆ IsVisibleToUser()

bool QTTools::IsVisibleToUser ( QWidget * widget)
static

Checks whether a widget is visible to the user, accounting for popups and tabs.

Parameters
[in]widgetThe widget to check.
Returns
True if the widget is visible to the user.

◆ IsWidgetVisibleOnScreen()

bool QTTools::IsWidgetVisibleOnScreen ( QWidget * widget)
static

Checks whether a widget is currently visible on any screen.

Parameters
[in]widgetThe widget to check.
Returns
True if the widget is visible on screen.

◆ log()

LogPtr QTTools::log ( )
static

Returns the global log for the Widgets module.

Returns
The log pointer.

Referenced by RealSenseServer::updateServer().

◆ MultiplyFontSize()

void QTTools::MultiplyFontSize ( QFont & font,
fltp08 multiplier )
static

Multiplies the font size by a given factor.

Parameters
[in]fontThe font to modify in-place.
[in]multiplierThe scaling factor to apply to the font size.

◆ PixelSize()

fltp08 QTTools::PixelSize ( const QFont & font)
static

Returns the pixel size of a font, converting from point size if necessary.

Parameters
[in]fontThe font to query.
Returns
The pixel size.

◆ PointSize()

fltp08 QTTools::PointSize ( const QFont & font)
static

Returns the point size of a font, converting from pixel size if necessary.

Parameters
[in]fontThe font to query.
Returns
The point size.

◆ PopupMenuLocation() [1/2]

QRect QTTools::PopupMenuLocation ( QWidget * widget,
const QSize & size )
static

Calculates a suitable popup menu location relative to a widget.

Parameters
[in]widgetThe anchor widget.
[in]sizeThe popup menu size.
Returns
The calculated screen rectangle for the popup.

◆ PopupMenuLocation() [2/2]

QRect QTTools::PopupMenuLocation ( QWidget * widget,
QRect popup_origin,
const QSize & size )
static

Calculates a suitable popup menu location relative to a widget with a given origin.

Parameters
[in]widgetThe anchor widget.
[in]popup_originThe origin rectangle for the popup.
[in]sizeThe popup menu size.
Returns
The calculated screen rectangle for the popup.

◆ PostToThread() [1/2]

void QTTools::PostToThread ( QObject * target,
std::function< void()> && fun )
static

Posts a function to be executed on the thread that owns the target QObject.

Parameters
[in]targetThe QObject whose thread will execute the function.
[in]funThe function to execute.

◆ PostToThread() [2/2]

void QTTools::PostToThread ( std::function< void()> && fun,
QThread * thread = nullptr )
static

Posts a function to be executed on the specified thread, or the main thread if none is given.

Parameters
[in]funThe function to execute.
[in]threadThe target thread, or nullptr for the main UI thread.

◆ QTModule()

Module QTTools::QTModule ( )
static

Returns the Module descriptor for the Qt integration module.

Returns
The QT Module.

◆ RequestExit()

void QTTools::RequestExit ( bool relaunch,
const PopupInfo & popup_origin = PopupInfo() )
static

Requests the application to exit, optionally relaunching afterward.

Parameters
[in]relaunchWhether to relaunch the application after exiting.
[in]popup_originOptional origin for the confirmation popup.

◆ RequestScreenOrientation()

void QTTools::RequestScreenOrientation ( bool horizontal)
static

Requests the screen orientation to be horizontal or vertical.

Parameters
[in]horizontalTrue for horizontal (landscape), false for vertical (portrait).

◆ RequestScreenResolution()

void QTTools::RequestScreenResolution ( const Vector< 2, uint04 > & size)
static

Requests a specific screen resolution.

Parameters
[in]sizeThe desired screen resolution in pixels.

◆ ScaleFontSizeToFit()

QSize QTTools::ScaleFontSizeToFit ( QFont & font,
const QString & text,
const QRect & rect,
bool shrink = true,
bool grow = false )
static

Scales a font size so that the given text fits within the specified rectangle.

Parameters
[in]fontThe font to modify in-place.
[in]textThe text to fit.
[in]rectThe target rectangle.
[in]shrinkWhether to allow shrinking the font.
[in]growWhether to allow growing the font.
Returns
The resulting text size after scaling.

◆ ScreenForWidget()

QScreen * QTTools::ScreenForWidget ( const QWidget * widget)
static

Returns the QScreen that contains the given widget.

Parameters
[in]widgetThe widget to query.
Returns
Pointer to the QScreen, or nullptr if not found.

◆ SetFontRecursive() [1/2]

void QTTools::SetFontRecursive ( QWidget * widget,
const Buffer< QFont > & font )
static

Recursively restores fonts on a widget and all its children from a buffer.

Parameters
[in]widgetThe root widget.
[in]fontThe buffer of fonts matching the widget hierarchy.

◆ SetFontRecursive() [2/2]

void QTTools::SetFontRecursive ( QWidget * widget,
const QFont & font )
static

Recursively sets the font on a widget and all its children.

Parameters
[in]widgetThe root widget.
[in]fontThe font to apply.

◆ SetStyleRecursive()

void QTTools::SetStyleRecursive ( QWidget * widget,
QStyle * style )
static

Recursively sets the QStyle on a widget and all its children.

Parameters
[in]widgetThe root widget.
[in]styleThe style to apply.

◆ ShowDialog()

bool QTTools::ShowDialog ( QWidget * widget,
PopupInfo info,
PopupInfo end_location = PopupInfo() )
static

Shows a dialog widget with animation and positioning specified by PopupInfo.

Parameters
[in]widgetThe dialog widget to show.
[in]infoPopup configuration for display behavior.
[in]end_locationOptional end location for the show animation.
Returns
True if the dialog was shown successfully.

Referenced by ProgressWidgetDemo::OptionsButton().

◆ ShowExperimentalFeatureDialog()

void QTTools::ShowExperimentalFeatureDialog ( const TranslatedString & feature)
static

Shows a dialog informing the user that a feature is experimental.

Parameters
[in]featureThe translated name of the experimental feature.

◆ ShowMessageBox() [1/6]

bool QTTools::ShowMessageBox ( const GenericOption & options,
const StringView & image,
std::function< bool(GenericOption, PopupInfo info)> on_select,
const PopupInfo & popup_origin = PopupInfo() )
static

Shows a message box configured by a GenericOption with an image.

Parameters
[in]optionsThe generic option configuration.
[in]imageThe icon resource to display.
[in]on_selectCallback invoked with the selected option.
[in]popup_originOptional origin for popup positioning.
Returns
True if the dialog was accepted.

◆ ShowMessageBox() [2/6]

bool QTTools::ShowMessageBox ( const GenericOption & options,
std::function< bool(GenericOption, PopupInfo info)> on_select,
const PopupInfo & popup_origin = PopupInfo() )
static

Shows a message box configured by a GenericOption.

Parameters
[in]optionsThe generic option configuration.
[in]on_selectCallback invoked with the selected option.
[in]popup_originOptional origin for popup positioning.
Returns
True if the dialog was accepted.

◆ ShowMessageBox() [3/6]

bool QTTools::ShowMessageBox ( const TranslatedString & title,
const StringView & image,
const TranslatedString & text,
const TranslatedStringBuffer & button_labels,
std::function< void(TranslatedString, PopupInfo info)> on_select = nullptr,
const PopupInfo & popup_origin = PopupInfo() )
static

Shows a message box with an image and custom-labeled buttons.

Parameters
[in]titleThe dialog title.
[in]imageThe icon resource to display.
[in]textThe dialog body text.
[in]button_labelsThe translated labels for each button.
[in]on_selectOptional callback invoked with the selected button label.
[in]popup_originOptional origin for popup positioning.
Returns
True if the dialog was accepted.

◆ ShowMessageBox() [4/6]

bool QTTools::ShowMessageBox ( const TranslatedString & title,
const StringView & image,
const TranslatedString & text,
QMessageBox::StandardButtons buttons = { QMessageBox::StandardButton::Ok },
std::function< void(QMessageBox::StandardButton, PopupInfo info)> on_select = nullptr,
const PopupInfo & popup_origin = PopupInfo() )
static

Shows a message box with an image and standard buttons.

Parameters
[in]titleThe dialog title.
[in]imageThe icon resource to display.
[in]textThe dialog body text.
[in]buttonsThe standard buttons to display.
[in]on_selectOptional callback invoked with the selected button.
[in]popup_originOptional origin for popup positioning.
Returns
True if the dialog was accepted.

◆ ShowMessageBox() [5/6]

bool QTTools::ShowMessageBox ( const TranslatedString & title,
const TranslatedString & text,
const TranslatedStringBuffer & button_labels,
std::function< void(TranslatedString, PopupInfo info)> on_select = nullptr,
const PopupInfo & popup_origin = PopupInfo() )
static

Shows a message box with custom-labeled buttons.

Parameters
[in]titleThe dialog title.
[in]textThe dialog body text.
[in]button_labelsThe translated labels for each button.
[in]on_selectOptional callback invoked with the selected button label.
[in]popup_originOptional origin for popup positioning.
Returns
True if the dialog was accepted.

◆ ShowMessageBox() [6/6]

bool QTTools::ShowMessageBox ( const TranslatedString & title,
const TranslatedString & text,
QMessageBox::StandardButtons buttons = { QMessageBox::StandardButton::Ok },
std::function< void(QMessageBox::StandardButton, PopupInfo info)> on_select = nullptr,
const PopupInfo & popup_origin = PopupInfo() )
static

Shows a message box with standard buttons.

Parameters
[in]titleThe dialog title.
[in]textThe dialog body text.
[in]buttonsThe standard buttons to display.
[in]on_selectOptional callback invoked with the selected button.
[in]popup_originOptional origin for popup positioning.
Returns
True if the dialog was accepted.

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