Sayonara Player
PreferenceWidget.h
1/* PreferenceWidgetInterface.h */
2
3/* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4 *
5 * This file is part of sayonara player
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef PREFERENCEWIDGETINTERFACE_H
22#define PREFERENCEWIDGETINTERFACE_H
23
24#include "Gui/Utils/GuiClass.h"
25#include "Gui/Utils/Widgets/Widget.h"
26#include "Utils/Pimpl.h"
27
28namespace Preferences
29{
40 class Base :
41 public Gui::Widget
42 {
43 Q_OBJECT
44 PIMPL(Base)
45
46 public:
51 explicit Base(const QString& identifier);
52 virtual ~Base() override;
53
58 QString identifier() const;
59
60 private:
61 void setInitialized();
62
63 protected:
64
65 template<typename W, typename UiClass>
71 void setupParent(W* widget, UiClass** ui)
72 {
73 *ui = new UiClass();
74 (*ui)->setupUi(widget);
75
76 setInitialized();
77
78 widget->languageChanged();
79
80 skinChanged();
81 }
82
98 virtual void languageChanged() override final;
99
100
105
106
107 protected:
108
113 void showEvent(QShowEvent* e) override;
114 void closeEvent(QCloseEvent* e) override;
115
116 public:
117
122 virtual bool isUiInitialized() const final;
123
124
129 virtual QAction* action() final;
130
131
132
137 virtual QString actionName() const=0;
138
139
144 virtual bool commit()=0;
145
151 virtual void revert()=0;
152
158 virtual void initUi()=0;
159
160
164 virtual void retranslate()=0;
165
171 virtual bool hasError() const;
172
177 virtual QString errorString() const;
178
179 };
180}
181
182#endif // PREFERENCEWIDGETINTERFACE_H
Widget with Settings connection. Also contains triggers for language_changed() and skin_changed() \nT...
Definition: Widget.h:39
Abstract Interface you should use when creating a preferences item.
Definition: PreferenceWidget.h:42
QString identifier() const
return the unique identifier
virtual void revert()=0
This method is called, when cancel is clicked. So the gui should be re-initialized when this method i...
void translationAction()
Sets the new translated action name.
Base(const QString &identifier)
Standard constructor.
virtual void initUi()=0
call setup_parent(this) here. initialize compoenents and connections here. After calling setup_parent...
virtual bool hasError() const
indicates if there was an error on the settings page like an invalid expression or combination of set...
virtual bool isUiInitialized() const final
checks if ui has already been initialized.
virtual void languageChanged() override final
automatically called when language has changed. When overriding this method. Overriding this method s...
virtual QString errorString() const
A closer description of the error.
virtual QString actionName() const =0
has to be implemented and should return the translated action text
void setupParent(W *widget, UiClass **ui)
Sets up the Preference dialog. After this method, the dialog is "ready to use" This method should be ...
Definition: PreferenceWidget.h:71
virtual QAction * action() final
get action with translated text
void showEvent(QShowEvent *e) override
shows the widget and automatically calls init_ui()
virtual void retranslate()=0
call the Qt retranslateUi method here
virtual bool commit()=0
This method is called, when OK or apply is pressed. So all settings should be written there.