105 lines
4.0 KiB
C++
Executable File
105 lines
4.0 KiB
C++
Executable File
#pragma once
|
|
|
|
#include "lts_widgets_export.h"
|
|
#include "lts_frameless_dialog.h"
|
|
|
|
#include <QString>
|
|
#include <QHash>
|
|
|
|
|
|
class QWidget;
|
|
class QHBoxLayout;
|
|
|
|
|
|
namespace LtsWidgets
|
|
{
|
|
|
|
/**
|
|
* @brief The Button enum describes one or more buttons, which should be shown on a Dialog which supports LtsWidgets::Button. Also this enum
|
|
* is the return type of LtsMessageDialog and provides the button clicked to close the Popup-Dialog.
|
|
*/
|
|
enum class Button
|
|
{
|
|
UNKNOWN = 0,
|
|
Ok = 1,
|
|
Yes = 2,
|
|
No = 4,
|
|
Cancel = 8,
|
|
|
|
Apply = 16,
|
|
Discard = 32,
|
|
};
|
|
Q_DECLARE_FLAGS(Buttons, Button)
|
|
inline uint qHash(LtsWidgets::Button b)
|
|
{
|
|
return ::qHash(static_cast<int>(b));
|
|
}
|
|
|
|
/**
|
|
* @brief [Please consider using LtsMessageDialogNew] The LtsMessageDialog class provides a BLOCKING Popup-Dialog (based on LtsFramelessDialog) to show a message to the user with selectable buttons. This class is static and cannot be instantiated.
|
|
* To show a message to the user class 'LtsMessageDialog::showMessage(..)'. And to get the button that was selected by the user to close the dialog, consider the return type 'LtsWidgets::Button'.
|
|
* This Popup-Dialog closes automatically if any button on it is clicked.
|
|
* The return type is an enum class instance which contains the information about the clicked button.
|
|
* If no button was specified there is no chance to close the dialog if LtsWidgets::Behaviour::Modal was specified.
|
|
*/
|
|
namespace LtsMessageDialog // in reality this is the helper, but for "naming's sake", this is not called the helper
|
|
{
|
|
/**
|
|
* @brief showMessage shows a Popup-Dialog to show a message to the user with selectable buttons - method is blocking (creates new EventLoop)!
|
|
* @param parent The widget to be covered.
|
|
* @param message The message to the user.
|
|
* @param behaviour How the Popup-Dialog should behave (see LtsFramelessDialog).
|
|
* @param buttons A list of Buttons to provide to the user.
|
|
* @param buttonTexts If set, the button texts are used from there instead the default ones
|
|
* @return The button that has been clicked by the user to close this Popup-Dialog.
|
|
*/
|
|
LTSWIDGETS_EXPORT Button showMessage(QWidget* parent,
|
|
const QString &message,
|
|
const QString &title = QString(),
|
|
const Behaviour behaviour = Behaviour::Modal,
|
|
const Buttons buttons = Button::Ok,
|
|
const QHash<Button, QString> &buttonTexts = QHash<Button, QString>());
|
|
LTSWIDGETS_EXPORT Button askApplyDiscardCancel(QWidget *parent);
|
|
} // namespace LtsMessageDialog
|
|
|
|
|
|
|
|
/**
|
|
* @brief The LtsMessageDialog class provides a NON-BLOCKING Popup-Dialog (based on LtsFramelessDialog) to show a message to the user with selectable buttons.
|
|
* To show a message to the user use: connect(new LtsMessageDialogNew(this, title, message), &LtsMessageDialogNew::ok, this, &MyDialog::mySlot);
|
|
* This Popup-Dialog closes automatically if any button on it is clicked.
|
|
* Keep in mind that as this dialog does not block, following code gets executed right afetr creating this dialog.
|
|
*/
|
|
class LTSWIDGETS_EXPORT LtsMessageDialogNew : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit LtsMessageDialogNew(QWidget* parent,
|
|
const QString &message,
|
|
const QString &title = QString(),
|
|
const Behaviour behaviour = Behaviour::Modal,
|
|
const Buttons buttons = Button::Ok,
|
|
const QHash<Button, QString> &buttonTexts = QHash<Button, QString>(),
|
|
bool deleteOnClose = true /* retain c++ conformity by this convenience bool */);
|
|
|
|
private:
|
|
LtsFramelessDialog *m_dialog;
|
|
|
|
QPushButton *addButton(const QString &text, QHBoxLayout *thatLayout, LtsFramelessDialog *dialog, const Button &button, QWidget *parent);
|
|
|
|
|
|
signals:
|
|
void ok();
|
|
void yes();
|
|
void no();
|
|
void apply();
|
|
void discard();
|
|
void cancel();
|
|
|
|
};
|
|
|
|
} // namespace LtsWidgets
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(LtsWidgets::Buttons)
|