Sayonara Player
PlayerPlugin.h
1 /* PlayerPlugin.h */
2 
3 /* Copyright (C) 2011-2016 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 
22 
23 #ifndef PLAYERPLUGIN_H
24 #define PLAYERPLUGIN_H
25 
26 #include <QAction>
27 #include <QCloseEvent>
28 #include <QLabel>
29 #include <QPushButton>
30 #include <QLayout>
31 
32 #include "GUI/Helper/SayonaraWidget/SayonaraWidget.h"
33 #include "GUI/Helper/Shortcuts/ShortcutWidget.h"
34 #include "GUI/Helper/Shortcuts/ShortcutHandler.h"
35 
36 #include "Components/PlayManager/PlayManager.h"
37 
38 
39 
41 
49  public SayonaraWidget,
50  public ShortcutWidget
51 {
52 
53  friend class PlayerPluginHandler;
54 
55  Q_OBJECT
56 
57 public:
58  PlayerPluginInterface(QWidget *parent=nullptr);
59  virtual ~PlayerPluginInterface();
60 
61 signals:
68  void sig_action_triggered(PlayerPluginInterface* plugin, bool checked);
69 
75 
76 
77 private slots:
83  void action_triggered(bool checked);
84 
85  void _sl_lang_changed();
86 
87 private:
88  bool _pp_is_closed;
89  bool _is_initialized;
90 
91  void set_size(QSize size);
92 
93 
94 protected:
95 
100 
104  QAction* _pp_action=nullptr;
105 
106 
107 
108 
109 protected:
110 
115  void closeEvent(QCloseEvent* e) override;
116 
117 
121  virtual void language_changed()=0;
122 
126  virtual void init_ui()=0;
127 
132  bool is_ui_initialized() const;
133 
137  void set_ui_initialized();
138 
139 
140  void change_exit_icon(QPushButton* close_button);
141 
142 
143 
144  template<typename T>
145  void setup_parent(T* widget){
146 
147  QLayout* widget_layout;
148  QLabel* lab_title;
149  QPushButton* btn_close;
150 
151  widget->setupUi(widget);
152  this->set_ui_initialized();
153 
154  lab_title = get_title_label();
155  if(lab_title){
156  lab_title->setText(widget->get_display_name());
157  lab_title->setMaximumHeight(24);
158  lab_title->setMinimumHeight(24);
159  }
160 
161  widget_layout = layout();
162  if(widget_layout){
163  widget_layout->setContentsMargins(3, 3, 3, 0);
164  }
165 
166  btn_close = get_close_button();
167  if(btn_close){
168  btn_close->resize(24, 24);
169  }
170 
171  ShortcutHandler* sch = ShortcutHandler::getInstance();
172  Shortcut sc = sch->get_shortcut("close_plugin");
173  if(!sc.is_valid()){
174  sc = sch->add(Shortcut(this, "close_plugin", tr("Close plugin"), "Ctrl+Esc"));
175  }
176 
177  sc.create_qt_shortcut(this, this, SLOT(close()));
178 
179  REGISTER_LISTENER(Set::Player_Language, _sl_lang_changed);
180  REGISTER_LISTENER(Set::Player_Style, skin_changed);
181  }
182 
183 protected slots:
184 
185  virtual void skin_changed();
190  virtual void playstate_changed(PlayManager::PlayState state);
191 
195  virtual void played();
196 
200  virtual void paused();
201 
205  virtual void stopped();
206 
207 
208 
209 public:
214  virtual QSize get_size() const final;
215 
220  virtual QAction* get_action() const final;
221 
226  virtual bool is_closed() const final;
227 
232  virtual QString get_name() const=0;
233 
238  virtual QString get_display_name() const=0;
239 
244  virtual QLabel* get_title_label() const=0;
245 
250  virtual QPushButton* get_close_button() const=0;
251 
252 
256  virtual void show();
257 
258 
264  QString get_shortcut_text(const QString &shortcut_identifier) const override;
265 };
266 
267 Q_DECLARE_INTERFACE(PlayerPluginInterface, "com.sayonara-player.playerplugin")
268 
269 #endif // PLAYERPLUGIN_H
virtual QString get_name() const =0
must be overwritten
virtual void playstate_changed(PlayManager::PlayState state)
Playstate has changed, this does nothing in default implementation.
A singleton class for retrieving shortcuts.
Definition: ShortcutHandler.h:41
PlayState
Current Playing state.
Definition: PlayManager.h:79
virtual QLabel * get_title_label() const =0
must be overwritten
virtual void init_ui()=0
GUI will be initialized on first show up. Please use this to make Sayonara starting fast...
bool is_valid() const
Check if the shortcut is valid or if it was retrieved via getInvalid()
virtual void paused()
Playstate has changed to paused.
A single shortcut managed by ShortcutHandler. This class holds information about the default shortcut...
Definition: Shortcut.h:42
virtual QAction * get_action() const final
needed by the player ui, final
virtual void show()
show Plugin
Widget with Settings connection. Also contains triggers for language_changed() and skin_changed() wi...
Definition: SayonaraWidget.h:41
Global handler for current playback state (Singleton)
Definition: PlayManager.h:67
void set_ui_initialized()
mark ui as initialized
void sig_action_triggered(PlayerPluginInterface *plugin, bool checked)
signal is emitted when the plugin action is triggered also emitted for when closeEvent is fired ...
virtual QSize get_size() const final
needed by the player ui, final
QAction * _pp_action
_pp_action already allocated, displays name of the plugin by calling get_name()
Definition: PlayerPlugin.h:104
void create_qt_shortcut(QWidget *parent, T func)
create a qt shortcut for a widget
Definition: Shortcut.h:142
virtual bool is_closed() const final
needed by the player ui, final
QString get_shortcut_text(const QString &shortcut_identifier) const override
get translated text of shortcut (overridden)
Interface for PlayerPlugin classes. get_name() and language_changed() must be overwritten.
Definition: PlayerPlugin.h:48
PlayManager * _play_manager
_play_manager Notifies about playstate
Definition: PlayerPlugin.h:99
Shortcut add(const Shortcut &shortcut)
add a new shortcut instance to the handler. This is usually done by the widget the shortcut is attach...
bool is_ui_initialized() const
Check if ui already was initialized.
void sig_reload(PlayerPluginInterface *)
emitted when reloading is requested, after firing this signal the plugin will be painted new...
Shortcut get_shortcut(const QString &identifier) const
get a shortcut by its unique identifier
void closeEvent(QCloseEvent *e) override
Event fired when closed overrides QWidget::closeEvent.
virtual void language_changed()=0
language_changed Has to be implemented and is called when language has changed
virtual void stopped()
Playstate has changed to stop.
virtual QPushButton * get_close_button() const =0
must be overwritten
Definition: PlayerPluginHandler.h:34
virtual void played()
Playstate has changed to playing.
Interface that should be implemented when using configurable shortcuts.
Definition: ShortcutWidget.h:33
virtual QString get_display_name() const =0
must be overwritten