forked from nedrysoft/regex101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsDialog.h
185 lines (167 loc) · 7.15 KB
/
SettingsDialog.h
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* Copyright (C) 2020 Adrian Carpenter
*
* This file is part of a regex101.com offline application.
*
* https://github.com/fizzyade/regex101
*
* =====================================================================
* The regex101 web content is owned and used with permission from
* Firas Dib at regex101.com. This application is an unofficial
* tool to provide an offline application version of the website.
* =====================================================================
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SETTINGSDIALOG_H
#define SETTINGSDIALOG_H
#include <QIcon>
#include <QMap>
#include <QWidget>
#if defined(Q_OS_MACOS)
class QMacToolBar;
#endif
class QHBoxLayout;
class QLabel;
class QMacToolBarItem;
class QParallelAnimationGroup;
class QPushButton;
class QStackedWidget;
class QTreeWidget;
class QVBoxLayout;
namespace Nedrysoft {
class TransparentWidget;
class ISettingsPage;
/**
* @brief Settings page class
*
* @details Describes an individual page of the application settings
*/
class SettingsPage
{
public:
enum Icon {
General,
Database
};
public:
QString m_name; //! display name of the settings category page
QString m_description; //! description of the settings category page
#if defined(Q_OS_MACOS)
TransparentWidget *m_widget; //! the widget that contains the settings for this category
#else
QWidget *m_widget; //! the widget that contains the settings for this category
#endif
ISettingsPage *m_pageSettings; //! pointer to the page interface
Icon m_icon; //! the icon of the page
QMacToolBarItem *m_toolBarItem; //! toolbar item
};
/**
* @brief Settings dialog class
*
* @details Provides the settings dialog to modify preferences. On macOS the dialog
* is presented in a native style, under Windows & Linux the dialog uses a
* format which is consistent and has a standard appearance for those OS's.
*/
class SettingsDialog :
public QWidget
{
private:
Q_OBJECT
public:
/**
* @brief Constructs a settings window
*
* @param[in] parent is the the owner of the window.
*/
explicit SettingsDialog(QWidget *parent=nullptr);
/**
* @brief Destroys a settings window
*/
~SettingsDialog();
/**
* @brief Close event
*
* @details Called when the dialog is closed
*
* @returns true if closed; otherwise false.
*/
bool close();
public:
/**
* @brief Closed signal
*
* @details Emmited when the dialog is closed
*/
Q_SIGNAL void closed();
private:
/**
* @brief Returns the QWindow handle from native widget
*
* @returns The QWindow handle of the native window
*/
QWindow *nativeWindowHandle();
/**
* @brief Returns the platform specific icon for the given icon type
*
* @param[in] icon the icon to get
* @returns the requested icon
*/
QIcon getIcon(SettingsPage::Icon icon);
protected:
/**
* @brief Window resize event
*
* @details Called when the widget is resized, allows child widgets to be manually resized
*
* @params[in] event is the event containing the resize information
*/
virtual void resizeEvent(QResizeEvent *event) override;
/**
* @brief Adds a setting page
*
* @details Adds the given page to the settings dialog
*
* @params[in] section is the displayed name of the section
* @params[in] category is the category within the section
* @params[in] description is the description of the purpose of the page
* @params[in] icon is the icon of the page
* @params[in] widget is the widget containing the page content
* @params[in] defaultPage true if page is the default shown page; otherwise false
*
* @returns the settings page structure
*/
SettingsPage *addPage(QString section, QString category, QString description, SettingsPage::Icon icon, QWidget *widget, bool defaultPage=false);
private:
#if defined(Q_OS_MACOS)
QMacToolBar *m_toolBar; //! A native macOS toolbar (unified style)
SettingsPage *m_currentPage; //! current widget
int m_toolbarHeight; //! the height of the unified toolbar
QParallelAnimationGroup *m_animationGroup; //! the currently active animation
#else
QVBoxLayout *m_layout; //! details layout + main layout + control layout
QVBoxLayout *m_detailLayout; //! detail layout
QHBoxLayout *m_mainLayout; //! detail layout + tree widget
QHBoxLayout *m_controlsLayout; //! apply/ok/cancel layout
QTreeWidget *m_treeWidget; //! tree widget for categories
QStackedWidget *m_stackedWidget; //! stacked widget for page content
QLabel *m_categoryLabel; //! category label
QPushButton *m_okButton; //! ok button, saves and dismisses the dialog (if changes valud)
QPushButton *m_cancelButton; //! cancel button, fogets any changes made since last apply
QPushButton *m_applyButton; //! apply button, saves changes but keeps dialog open
#endif
QMap<QMacToolBarItem *, SettingsPage *> m_pages; //! The list of settings widgets
};
}
#endif // SETTINGSDIALOG_H