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 {
41  class Base :
42  public Gui::Widget
43  {
44  Q_OBJECT
45  PIMPL(Base)
46 
47  public:
52  explicit Base(const QString& identifier);
53  virtual ~Base();
54 
55  QString identifier() const;
56 
57  private:
58  void set_initialized();
59 
60  protected:
61 
62  template<typename W, typename UiClass>
68  void setup_parent(W* widget, UiClass** ui)
69  {
70  *ui = new UiClass();
71  (*ui)->setupUi(widget);
72 
73  set_initialized();
74 
75  widget->language_changed();
76  }
77 
93  virtual void language_changed() override final;
94 
95 
99  void translate_action();
100 
101 
102  protected:
103 
108  void showEvent(QShowEvent* e) override;
109 
110 
111  public:
112 
117  virtual bool is_ui_initialized() const final;
118 
119 
124  virtual QAction* action() final;
125 
126 
127 
132  virtual QString action_name() const=0;
133 
134 
139  virtual bool commit()=0;
140 
146  virtual void revert()=0;
147 
153  virtual void init_ui()=0;
154 
155 
159  virtual void retranslate_ui()=0;
160 
161 
162  virtual bool has_error() const;
163  virtual QString error_string() const;
164 
165  };
166 }
167 
168 #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...
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: GUI_PreferenceDialog.h:28
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:38
virtual void retranslate_ui()=0
call the Qt retranslateUi method here
void translate_action()
Sets the new translated action name.
Abstract Interface you should use when creating a preferences item.
Definition: PreferenceWidget.h:41
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:68
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...