Debian Codegraph @

src/Gui/PropertyPage.h

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2
3 /****************************************************************************
4 * Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> *
5 * Copyright (c) 2023 FreeCAD Project Association *
6 * *
7 * This file is part of FreeCAD. *
8 * *
9 * FreeCAD is free software: you can redistribute it and/or modify it *
10 * under the terms of the GNU Lesser General Public License as *
11 * published by the Free Software Foundation, either version 2.1 of the *
12 * License, or (at your option) any later version. *
13 * *
14 * FreeCAD is distributed in the hope that it will be useful, but *
15 * WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
17 * Lesser General Public License for more details. *
18 * *
19 * You should have received a copy of the GNU Lesser General Public *
20 * License along with FreeCAD. If not, see *
21 * <https://www.gnu.org/licenses/>. *
22 * *
23 ***************************************************************************/
24
25
26 #ifndef GUI_DIALOG_PROPERTYPAGE_H
27 #define GUI_DIALOG_PROPERTYPAGE_H
28
29 #include <QWidget>
30 #include <FCGlobal.h>
31
32 namespace Gui
33 {
34 namespace Dialog
35 {
36
37 /** Base class for property pages.
38 * \author Werner Mayer
39 */
40 class GuiExport PropertyPage: public QWidget
41 {
42 Q_OBJECT
43
44 public:
45 explicit PropertyPage(QWidget* parent = nullptr);
46 ~PropertyPage() override = default;
47
48 bool isModified() const;
49 void setModified(bool b);
50 void onApply();
51 void onCancel();
52 void onReset();
53
54 protected:
55 virtual void apply();
56 virtual void cancel();
57 virtual void reset();
58
59 private:
60 bool bChanged; /**< for internal use only */
61
62 protected Q_SLOTS:
63 virtual void loadSettings() = 0;
64 virtual void saveSettings() = 0;
65 };
66
67 /** Base class for preferences pages.
68 * \author Werner Mayer
69 */
70 class GuiExport PreferencePage: public QWidget
71 {
72 Q_OBJECT
73
74 public:
75 explicit PreferencePage(QWidget* parent = nullptr);
76 ~PreferencePage() override = default;
77
78 bool isRestartRequired() const;
79 void requireRestart();
80
81 // this fixes issue with wordWrap on labels affecting size hints:
82 // https://stackoverflow.com/questions/78276854/layout-ignoring-sizehints-when-qlabel-with-text-wrap-is-present
83 bool hasHeightForWidth() const override
84 {
85 return false;
86 }
87
88 public Q_SLOTS:
89 virtual void loadSettings() = 0;
90 virtual void saveSettings() = 0;
91 virtual void resetSettingsToDefaults();
92
93 protected:
94 void changeEvent(QEvent* event) override = 0;
95
96 private:
97 bool restartRequired;
98 };
99
100 /** Subclass that embeds a form from a UI file.
101 * \author Werner Mayer
102 */
103 class GuiExport PreferenceUiForm: public PreferencePage
104 {
105 Q_OBJECT
106
107 public:
108 explicit PreferenceUiForm(const QString& fn, QWidget* parent = nullptr);
109 ~PreferenceUiForm() override;
110
111 void loadSettings() override;
112 void saveSettings() override;
113
114 QWidget* form();
115
116 protected:
117 void changeEvent(QEvent* e) override;
118
119 private:
120 template<typename PW>
121 void loadPrefWidgets();
122 template<typename PW>
123 void savePrefWidgets();
124
125 private:
126 QWidget* _form;
127 };
128
129 /** Base class for custom pages.
130 * \author Werner Mayer
131 */
132 class GuiExport CustomizeActionPage: public QWidget
133 {
134 Q_OBJECT
135
136 public:
137 explicit CustomizeActionPage(QWidget* parent = nullptr);
138 ~CustomizeActionPage() override;
139
140 protected:
141 bool event(QEvent* e) override;
142 void changeEvent(QEvent* e) override = 0;
143
144 protected Q_SLOTS:
145 virtual void onAddMacroAction(const QByteArray&) = 0;
146 virtual void onRemoveMacroAction(const QByteArray&) = 0;
147 virtual void onModifyMacroAction(const QByteArray&) = 0;
148 };
149
150 } // namespace Dialog
151 } // namespace Gui
152
153 #endif // GUI_DIALOG_PROPERTYPAGE_H