Sayonara Player
PreferenceWidget.h
1 /* PreferenceWidgetInterface.h */
2 
3 /* Copyright (C) 2011-2019 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 
28 namespace 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();
53 
58  QString identifier() const;
59 
60  private:
61  void set_initialized();
62 
63  protected:
64 
65  template<typename W, typename UiClass>
71  void setup_parent(W* widget, UiClass** ui)
72  {
73  *ui = new UiClass();
74  (*ui)->setupUi(widget);
75 
76  set_initialized();
77 
78  widget->language_changed();
79  }
80 
96  virtual void language_changed() override final;
97 
98 
102  void translate_action();
103 
104 
105  protected:
106 
111  void showEvent(QShowEvent* e) override;
112 
113 
114  public:
115 
120  virtual bool is_ui_initialized() const final;
121 
122 
127  virtual QAction* action() final;
128 
129 
130 
135  virtual QString action_name() const=0;
136 
137 
142  virtual bool commit()=0;
143 
149  virtual void revert()=0;
150 
156  virtual void init_ui()=0;
157 
158 
162  virtual void retranslate_ui()=0;
163 
169  virtual bool has_error() const;
170 
175  virtual QString error_string() const;
176 
177  };
178 }
179 
180 #endif // PREFERENCEWIDGETINTERFACE_H
virtual bool commit()=0
This method is called, when OK or apply is pressed. So all settings should be written there...
virtual QString action_name() const =0
has to be implemented and should return the translated action text
Base(const QString &identifier)
Standard constructor.
virtual void revert()=0
This method is called, when cancel is clicked. So the gui should be re-initialized when this method i...
QString identifier() const
return the unique identifier
virtual bool has_error() const
indicates if there was an error on the settings page like an invalid expression or combination of set...
virtual bool is_ui_initialized() const final
checks if ui has already been initialized.
virtual void language_changed() override final
automatically called when language has changed. When overriding this method. Overriding this method s...
Definition: PreferenceAction.h:29
void showEvent(QShowEvent *e) override
shows the widget and automatically calls init_ui()
Widget with Settings connection. Also contains triggers for language_changed() and skin_changed() wi...
Definition: Widget.h:37
virtual void retranslate_ui()=0
call the Qt retranslateUi method here
virtual QString error_string() const
A closer description of the error.
void translate_action()
Sets the new translated action name.
Abstract Interface you should use when creating a preferences item.
Definition: PreferenceWidget.h:40
void setup_parent(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
virtual void init_ui()=0
call setup_parent(this) here. initialize compoenents and connections here. After calling setup_parent...