API Documentation
Loading...
Searching...
No Matches
QTTools.h
Go to the documentation of this file.
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: Widgets
28File: QTTools
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/PopupInfo.h>
35#include <NDEVR/StringStream.h>
36#include <NDEVR/BaseValues.h>
37#include <NDEVR/Resource.h>
38#include <NDEVR/Translator.h>
39#include <NDEVR/Event.h>
40#if NDEVR_SUPPORTS_THREADING
41#include <QThread>
42#endif
43#include <QEvent>
44#include <QAbstractEventDispatcher>
45#include <QMessageBox>
46#include <QMetaEnum>
47
48class QFontMetrics;
49class QMessageBox;
50class QFont;
51class QStyle;
52class QColor;
53class QFile;
54class QSurfaceFormat;
55class QScreen;
56class QWindow;
57
58namespace NDEVR
59{
60 class RGBColor;
61 class File;
62 class Ribbon;
63 struct Font;
64 class ImageData;
65 class KeyEvent;
66 struct GenericOption;
67 struct Module;
68
69 /**--------------------------------------------------------------------------------------------------
70 \brief Manages static logic dealing with Qt and relating to the application
71 **/
73 {
74 public:
75 static void postToThread(std::function<void()>&& fun, QThread * thread = nullptr);
76 static void postToThread(QObject* target, std::function<void()>&& fun);
77 static void requestScreenOrientation(bool horizontal);
80 static QColor convert(const RGBColor& color);
81 static RGBColor convert(const QColor& color);
82 static Font convert(const QFont& q_font);
83 static QFont convert(const Font& font);
84 static void MultiplyFontSize(QFont& font, fltp08 multiplier);
85 static QSize ScaleFontSizeToFit(QFont& font, const QString& text, const QRect& rect, bool shrink = true, bool grow = false);
86 static void FitTextToRect(QString& text, QFont& font, const QRectF& size, bool allow_new_line = true);
87 static QString AutoWrapText(const QString& value, const QFontMetrics& metrics, fltp08 length);
88 static Buffer<QFont> GetFontRecursive(QWidget* widget);
89 static void SetFontRecursive(QWidget* widget, const QFont& font);
90 static void SetFontRecursive(QWidget* widget, const Buffer<QFont>& font);
91 static void SetStyleRecursive(QWidget* widget, QStyle* style);
92 static fltp08 PointSize(const QFont& font);
93 static fltp08 PixelSize(const QFont& font);
94 static fltp08 DPI();
95 static void ForceSizeCalculation(QWidget* widget, bool process_events = false);
96 static bool IsWidgetVisibleOnScreen(QWidget* widget);
97 static QScreen* ScreenForWidget(const QWidget* widget);
98 static QPixmap* DrawAnimationWidget(QWidget* widget, bool draw_background, QPixmap* pixmap = nullptr, QSize size = QSize());
99 static QPixmap* DrawFullWidget(QWidget* widget, bool draw_background, QPixmap* pixmap = nullptr, QSize size = QSize());
100 static qreal DevicePixelRatio(QWindow* window = nullptr);
101 static ProgressInfo* log();
102 static File convert(const QFile& file);
103 static QRect PopupMenuLocation(QWidget* widget, const QSize& size);
104 static QRect PopupMenuLocation(QRect popup_origin, const QSize& size);
105 static void ClearLayout(QLayout* layout, bool delete_objects = false);
106 static bool ShowDialog(QWidget* widget, const PopupInfo& info, const PopupInfo& end_location = PopupInfo());
107 static void HideDialog(QWidget* widget, const PopupInfo& end_location = PopupInfo());
108 static bool IsVisibleToUser(QWidget* widget);
109 static bool ShowMessageBox(const TranslatedString& title, const TranslatedString& text
110 , QMessageBox::StandardButtons buttons = { QMessageBox::StandardButton::Ok }
111 , std::function<void(QMessageBox::StandardButton, PopupInfo info)> on_select = nullptr
112 , const PopupInfo& popup_origin = PopupInfo());
113 static bool ShowMessageBox(const TranslatedString& title, const String& image, const TranslatedString& text
114 , QMessageBox::StandardButtons buttons = { QMessageBox::StandardButton::Ok }
115 , std::function<void(QMessageBox::StandardButton, PopupInfo info)> on_select = nullptr
116 , const PopupInfo& popup_origin = PopupInfo());
117
118 static bool ShowMessageBox(const TranslatedString& title, const TranslatedString& text
119 , const Buffer<TranslatedString, uint04, ObjectAllocator<false>>& button_labels
120 , std::function<void(TranslatedString, PopupInfo info)> on_select = nullptr
121 , const PopupInfo& popup_origin = PopupInfo());
122 static bool ShowMessageBox(const TranslatedString& title, const String& image, const TranslatedString& text
123 , const Buffer<TranslatedString, uint04, ObjectAllocator<false>>& button_labels
124 , std::function<void(TranslatedString, PopupInfo info)> on_select = nullptr
125 , const PopupInfo& popup_origin = PopupInfo());
126
127 static bool ShowMessageBox(const GenericOption& options, std::function<bool(GenericOption, PopupInfo info)> on_select
128 , const PopupInfo& popup_origin = PopupInfo());
129 static bool ShowMessageBox(const GenericOption& options, const String& image, std::function<bool(GenericOption, PopupInfo info)> on_select
130 , const PopupInfo& popup_origin = PopupInfo());
131 static void RequestExit(bool relaunch, const PopupInfo& popup_origin = PopupInfo());
134 static QSurfaceFormat DefaultSurfaceFormat();
135 static void FormatPallete(bool error, QWidget* widget);
136 static void ClearPallete(QWidget* widget);
137 static void ServiceQT();
138 static KeyEvent convert(QKeyEvent* event);
139 static Module QTModule();
141
142 template<typename EnumType>
143 static String EnumString(const EnumType& enumValue)
144 {
145 const char* enumName = qt_getEnumName(enumValue);
146 const QMetaObject* metaObject = qt_getEnumMetaObject(enumValue);
147 if (metaObject)
148 {
149 const int enumIndex = metaObject->indexOfEnumerator(enumName);
150 return String(metaObject->className()) +" : "+ String(enumName) +" : "+ String(metaObject->enumerator(enumIndex).valueToKey(enumValue));
151 }
152
153 return String(enumName) +" : "+ String(static_cast<int>(enumValue));
154 }
155 };
157 {
158 public:
159 explicit QTAbstractResourceListener(QObject* parent = nullptr);
160
162 virtual void onChanged() = 0;
163 void onValueChanged() override final;
164 bool m_has_been_posted;
165 bool m_safe_to_delete;
166 };
168 {
169 public:
170 explicit QTResourceListener(const std::function<void()>& callback, QObject* parent);
172 void onChanged() override final;
173 const std::function<void()> m_callback;
174 };
175 template class NDEVR_WIDGETS_API StringStream<QString>;
176 template class NDEVR_WIDGETS_API StringStream<QByteArray>;
177 #define _tqa(var) (_t(var).translation().getAs<QString>())//returns raw tranlation, should not be used for window titles
178 #define _tqs(var) (String(_t(var)).getAs<QString>())//returns pseudo translation. Should be used for window titles
179 #define _tdq(var, def) (_td(var, def).translation().getAs<QString>())
180}
181
#define NDEVR_WIDGETS_API
Definition DLLInfo.h:59
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
A class which describes a user key press.
Definition Event.h:49
KEY
Definition Event.h:55
Definition MemoryManager.h:261
A light-weight base class for Log that allows processes to update, without the need for additional in...
Definition ProgressInfo.hpp:48
Definition QTTools.h:157
QTAbstractResourceListener(QObject *parent=nullptr)
void onValueChanged() override final
Definition QTTools.h:168
QTResourceListener(const std::function< void()> &callback, QObject *parent)
void onChanged() override final
Manages static logic dealing with Qt and relating to the application.
Definition QTTools.h:73
static bool ShowMessageBox(const TranslatedString &title, const String &image, const TranslatedString &text, const Buffer< TranslatedString, uint04, ObjectAllocator< false > > &button_labels, std::function< void(TranslatedString, PopupInfo info)> on_select=nullptr, const PopupInfo &popup_origin=PopupInfo())
static QFont convert(const Font &font)
static File convert(const QFile &file)
static Resource< bool > is_horizontal
Definition QTTools.h:140
static bool ShowMessageBox(const TranslatedString &title, const TranslatedString &text, const Buffer< TranslatedString, uint04, ObjectAllocator< false > > &button_labels, std::function< void(TranslatedString, PopupInfo info)> on_select=nullptr, const PopupInfo &popup_origin=PopupInfo())
static QScreen * ScreenForWidget(const QWidget *widget)
static void ClearLayout(QLayout *layout, bool delete_objects=false)
static void RequestScreenResolution(const Vector< 2, uint04 > &size)
static void SetFontRecursive(QWidget *widget, const QFont &font)
static KeyEvent::KEY ConvertNativeKeyEvent(sint08 key)
static bool IsVisibleToUser(QWidget *widget)
static fltp08 DPI()
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())
static QString AutoWrapText(const QString &value, const QFontMetrics &metrics, fltp08 length)
static QPixmap * DrawFullWidget(QWidget *widget, bool draw_background, QPixmap *pixmap=nullptr, QSize size=QSize())
static void SetStyleRecursive(QWidget *widget, QStyle *style)
static Module QTModule()
static void FormatPallete(bool error, QWidget *widget)
static void ForceSizeCalculation(QWidget *widget, bool process_events=false)
static fltp08 PixelSize(const QFont &font)
static Font convert(const QFont &q_font)
static RGBColor convert(const QColor &color)
static void requestScreenOrientation(bool horizontal)
static KeyEvent convert(QKeyEvent *event)
static qreal DevicePixelRatio(QWindow *window=nullptr)
static ProgressInfo * log()
static bool ShowMessageBox(const TranslatedString &title, const String &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 void ServiceQT()
static String EnumString(const EnumType &enumValue)
Definition QTTools.h:143
static void SetFontRecursive(QWidget *widget, const Buffer< QFont > &font)
static void postToThread(std::function< void()> &&fun, QThread *thread=nullptr)
static bool IsWidgetVisibleOnScreen(QWidget *widget)
static QRect PopupMenuLocation(QRect popup_origin, const QSize &size)
static QSurfaceFormat DefaultSurfaceFormat()
static void MultiplyFontSize(QFont &font, fltp08 multiplier)
static fltp08 DefaultAnimationScale()
static void ShowExperimentalFeatureDialog(const TranslatedString &feature)
static void RequestExit(bool relaunch, const PopupInfo &popup_origin=PopupInfo())
static QColor convert(const RGBColor &color)
static fltp08 PointSize(const QFont &font)
static Buffer< QFont > GetFontRecursive(QWidget *widget)
static QRect PopupMenuLocation(QWidget *widget, const QSize &size)
static void postToThread(QObject *target, std::function< void()> &&fun)
static void ClearPallete(QWidget *widget)
static QPixmap * DrawAnimationWidget(QWidget *widget, bool draw_background, QPixmap *pixmap=nullptr, QSize size=QSize())
static QSize ScaleFontSizeToFit(QFont &font, const QString &text, const QRect &rect, bool shrink=true, bool grow=false)
static bool ShowMessageBox(const GenericOption &options, const String &image, std::function< bool(GenericOption, PopupInfo info)> on_select, const PopupInfo &popup_origin=PopupInfo())
static bool ShowMessageBox(const GenericOption &options, std::function< bool(GenericOption, PopupInfo info)> on_select, const PopupInfo &popup_origin=PopupInfo())
static void HideDialog(QWidget *widget, const PopupInfo &end_location=PopupInfo())
static void FitTextToRect(QString &text, QFont &font, const QRectF &size, bool allow_new_line=true)
static bool ShowDialog(QWidget *widget, const PopupInfo &info, const PopupInfo &end_location=PopupInfo())
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:54
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Toggle.h:41
A class that can subscribe to any number of Resources which will get updates when the Resource(s) hav...
Definition ResourceListener.h:62
The core String class for the NDEVR API.
Definition String.h:69
Logic for reading or writing to a string or a user friendly, TranslatedString.
Definition StringStream.h:230
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
Definition ACIColor.h:37
int64_t sint08
-Defines an alias representing an 8 byte, signed integer -Can represent exact integer values -9223372...
Definition BaseValues.hpp:71
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Definition File.h:211
Information for how to display text data.
Definition Font.h:46
Stores a generic option of any type as well as some information about how the user might interact wit...
Definition GenericOptions.h:57
Base class for extensions, typically added as external DLL's that can modify or enhance the behavior ...
Definition ModuleManager.h:59
Class which is used to pass arguments and requests for creating a popup dialog or widget....
Definition PopupInfo.h:15