NDEVR
API Documentation
QCustomMessageBox.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: Widgets
28File: QCustomMessageBox
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/KeyController.h>
35#include <NDEVR/Buffer.h>
36#include <NDEVR/String.h>
37#include <NDEVR/Dictionary.h>
38#include <NDEVR/UUID.h>
39#include <NDEVR/GenericOption.h>
40#include <QWidget>
41#include <QMessageBox>
42#include <QLabel>
43#include <QPointer>
44#include <functional>
45class QHBoxLayout;
46class QSize;
47namespace NDEVR
48{
49 class Button;
50 class ImageView;
51 class String;
52 struct PopupInfo;
61 class NDEVR_WIDGETS_API QCustomMessageBox : public QWidget, public BasicKeyController
62 {
63 Q_OBJECT
64 protected:
72 QCustomMessageBox(const TranslatedString& title, const TranslatedString& text, QMessageBox::StandardButtons buttons, std::function<void(QMessageBox::StandardButton, PopupInfo)> on_select = nullptr);
80 QCustomMessageBox(const TranslatedString& title, const TranslatedString& text, const Buffer<TranslatedString>& button_labels, std::function<void(TranslatedString, PopupInfo)> on_select = nullptr);
86 QCustomMessageBox(const GenericOption& entry_type, std::function<void(GenericOption, PopupInfo)> on_select);
87 virtual ~QCustomMessageBox();
88 public:
98 void setIcon(const StringView& image, fltp08 icon_size_mult = 1.0);
103 void setText(const TranslatedString& text);
108 void setButtons(QMessageBox::StandardButtons buttons);
113 void setButtons(const Buffer<TranslatedString>& button_labels);
118 void setCallback(std::function<void(QMessageBox::StandardButton, PopupInfo)> callback) { m_callback = callback; };
123 void setLabelCallback(std::function<void(TranslatedString, PopupInfo)> callback) { m_label_callback = callback; };
128 void setGenericOptionCallback(std::function<void(GenericOption, PopupInfo)> callback) { m_user_entry_callback = callback; };
137 static QCustomMessageBox* CreateMessageBox(const TranslatedString& title, const TranslatedString& text, QMessageBox::StandardButtons buttons, std::function<void(QMessageBox::StandardButton, PopupInfo)> on_select = nullptr);
146 static QCustomMessageBox* CreateMessageBox(const TranslatedString& title, const TranslatedString& text, const Buffer<TranslatedString>& button_labels, std::function<void(TranslatedString, PopupInfo)> on_select = nullptr);
153 static QCustomMessageBox* CreateMessageBox(const GenericOption& entry_type, std::function<void(GenericOption, PopupInfo)> on_select = nullptr);
158 QSize sizeHint() const override;
167 virtual bool processKeyEvent(const StringView& id, const KeyEvent& key_event, DesignObjectLookup* lookup, Camera* camera) override;
171 virtual void resetKeyControllerToDefaults() override;
172 protected:
178 void buttonPressed(QMessageBox::StandardButton button, PopupInfo);
184 void buttonPressed(const TranslatedString& button_label, PopupInfo);
189 protected:
190 QLabel* m_text;
193 QHBoxLayout* m_top_layout;
196 std::function<void(QMessageBox::StandardButton, PopupInfo)> m_callback;
200 };
201}
BasicKeyController(const TranslatedString &key_controller_title)
Constructs a BasicKeyController with the given title.
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A core widget that allows the user to click one of many button types.
Definition Button.h:68
A core object representing a user view as well as convenience functions for moving this view through ...
Definition Camera.h:95
A core class where all Design Objects including models, materials, and geometries are stored.
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
A widget that shows a raster image or icon.
Definition ImageView.h:44
Describes a user key press event used to trigger behavior in the NDEVR API.
Definition Event.h:49
virtual void resetKeyControllerToDefaults() override
Resets the key controller bindings to their default values.
void setGenericOptionCallback(std::function< void(GenericOption, PopupInfo)> callback)
Sets the callback invoked when a generic option entry is submitted.
static Dictionary< UUID, QPointer< QCustomMessageBox > > s_message_boxes
Global registry of active message boxes keyed by UUID.
void setLabelCallback(std::function< void(TranslatedString, PopupInfo)> callback)
Sets the callback invoked when a custom labeled button is pressed.
QCustomMessageBox(const TranslatedString &title, const TranslatedString &text, const Buffer< TranslatedString > &button_labels, std::function< void(TranslatedString, PopupInfo)> on_select=nullptr)
Constructs a message box with custom labeled buttons.
Buffer< Button * > m_buttons
The collection of buttons displayed in the message box.
QCustomMessageBox(const TranslatedString &title, const TranslatedString &text, QMessageBox::StandardButtons buttons, std::function< void(QMessageBox::StandardButton, PopupInfo)> on_select=nullptr)
Constructs a message box with standard Qt buttons.
void buttonPressed(const TranslatedString &button_label, PopupInfo)
Handles the event when a custom labeled button is pressed.
std::function< void(TranslatedString, PopupInfo)> m_label_callback
Callback for custom labeled button selection.
void setButtons(const Buffer< TranslatedString > &button_labels)
Replaces the current buttons with custom labeled buttons.
QLabel * m_text
The label displaying the main message text.
void setText(const TranslatedString &text)
Sets the main informational text displayed in the message box.
void clearButtons()
Removes all buttons from the message box.
String m_pixmap
The icon resource name for the message box icon.
ImageView * m_image_view
The image view widget displaying the icon.
void buttonPressed(QMessageBox::StandardButton button, PopupInfo)
Handles the event when a standard button is pressed.
void addButtonsToLayout()
Adds the current set of buttons to the message box layout.
QHBoxLayout * m_top_layout
The top horizontal layout containing the icon and text.
QCustomMessageBox(const GenericOption &entry_type, std::function< void(GenericOption, PopupInfo)> on_select)
Constructs a message box with a generic option entry for user input.
void setCallback(std::function< void(QMessageBox::StandardButton, PopupInfo)> callback)
Sets the callback invoked when a standard button is pressed.
void setButtons(QMessageBox::StandardButtons buttons)
Replaces the current buttons with a set of standard Qt buttons.
void setIcon(const StringView &image, fltp08 icon_size_mult=1.0)
Sets the icon displayed in the message box.
static QCustomMessageBox * CreateMessageBox(const GenericOption &entry_type, std::function< void(GenericOption, PopupInfo)> on_select=nullptr)
Creates a message box with a generic option entry and displays it as a popup.
static QCustomMessageBox * CreateMessageBox(const TranslatedString &title, const TranslatedString &text, const Buffer< TranslatedString > &button_labels, std::function< void(TranslatedString, PopupInfo)> on_select=nullptr)
Creates a message box with custom labeled buttons and displays it as a popup.
std::function< void(QMessageBox::StandardButton, PopupInfo)> m_callback
Callback for standard button selection.
std::function< void(GenericOption, PopupInfo)> m_user_entry_callback
Callback for generic option entry submission.
virtual bool processKeyEvent(const StringView &id, const KeyEvent &key_event, DesignObjectLookup *lookup, Camera *camera) override
Processes a key event for keyboard interaction with the message box.
static QCustomMessageBox * CreateMessageBox(const TranslatedString &title, const TranslatedString &text, QMessageBox::StandardButtons buttons, std::function< void(QMessageBox::StandardButton, PopupInfo)> on_select=nullptr)
Creates a message box with standard Qt buttons and displays it as a popup.
QSize sizeHint() const override
Returns the recommended size for the message box.
GenericOption m_generic_option
The generic option used for user input collection.
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
The primary namespace for the NDEVR SDK.
double fltp08
Defines an alias representing an 8 byte floating-point number.
Stores a generic option of any type as well as some information about how the user might interact wit...
Class which is used to pass arguments and requests for creating a popup dialog or widget.
Definition PopupInfo.h:16