aboutsummaryrefslogtreecommitdiff
path: root/src/qt_common/abstract/frontend.h
blob: 48c7c6edd05bea95d7fced82d730d2333158179b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <QGuiApplication>
#include "qt_common/qt_common.h"

#include <QFileDialog>

/**
 * manages common functionality e.g. message boxes and such for Qt/QML
 */
namespace QtCommon::Frontend {

Q_NAMESPACE

enum StandardButton {
    // keep this in sync with QDialogButtonBox::StandardButton and
    // QPlatformDialogHelper::StandardButton
    NoButton = 0x00000000,
    Ok = 0x00000400,
    Save = 0x00000800,
    SaveAll = 0x00001000,
    Open = 0x00002000,
    Yes = 0x00004000,
    YesToAll = 0x00008000,
    No = 0x00010000,
    NoToAll = 0x00020000,
    Abort = 0x00040000,
    Retry = 0x00080000,
    Ignore = 0x00100000,
    Close = 0x00200000,
    Cancel = 0x00400000,
    Discard = 0x00800000,
    Help = 0x01000000,
    Apply = 0x02000000,
    Reset = 0x04000000,
    RestoreDefaults = 0x08000000,

    FirstButton = Ok,             // internal
    LastButton = RestoreDefaults, // internal

    YesAll = YesToAll, // obsolete
    NoAll = NoToAll,   // obsolete

    Default = 0x00000100,  // obsolete
    Escape = 0x00000200,   // obsolete
    FlagMask = 0x00000300, // obsolete
    ButtonMask = ~FlagMask // obsolete
};
Q_ENUM_NS(StandardButton)

#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
typedef StandardButton Button;
#endif
Q_DECLARE_FLAGS(StandardButtons, StandardButton)
Q_FLAG_NS(StandardButtons)

enum class Icon {
    // keep this in sync with QMessageDialogOptions::StandardIcon
    NoIcon = 0,
    Information = 1,
    Warning = 2,
    Critical = 3,
    Question = 4
};
Q_ENUM_NS(Icon)

StandardButton ShowMessage(Icon icon, const QString& title, const QString& text,
                           StandardButtons buttons = StandardButton::NoButton,
                           QObject* parent = nullptr);

#define UTIL_OVERRIDES(level)                                                                      \
    inline StandardButton level(QObject* parent, const QString& title, const QString& text,        \
                                StandardButtons buttons) {                                         \
        return ShowMessage(Icon::level, title, text, buttons, parent);                             \
    }                                                                                              \
    inline StandardButton level(QObject* parent, const QString& title, const QString& text,        \
                                int buttons = StandardButton::Ok) {                                \
        return ShowMessage(Icon::level, title, text, StandardButtons(buttons), parent);            \
    }                                                                                              \
    inline StandardButton level(const QString title, const QString& text,                          \
                                StandardButtons buttons) {                                         \
        return ShowMessage(Icon::level, title, text, buttons, rootObject);                         \
    }                                                                                              \
    inline StandardButton level(const QString& title, const QString& text,                         \
                                int buttons = StandardButton::Ok) {                                \
        return ShowMessage(Icon::level, title, text, StandardButtons(buttons), rootObject);        \
    }

UTIL_OVERRIDES(Information)
UTIL_OVERRIDES(Warning)
UTIL_OVERRIDES(Critical)
UTIL_OVERRIDES(Question)

const QString GetOpenFileName(const QString& title, const QString& dir, const QString& filter,
                              QString* selectedFilter = nullptr);

const QStringList GetOpenFileNames(const QString& title, const QString& dir, const QString& filter,
                                   QString* selectedFilter = nullptr);

const QString GetSaveFileName(const QString& title, const QString& dir, const QString& filter,
                              QString* selectedFilter = nullptr);

const QString GetExistingDirectory(const QString& caption = QString(),
                                   const QString& dir = QString());

int Choice(const QString& title = QString(), const QString& caption = QString(),
           const QStringList& options = {});

const QString GetTextInput(const QString& title = QString(), const QString& caption = QString(),
                           const QString& defaultText = QString());

} // namespace QtCommon::Frontend