Sayonara Player
ContextMenu.h
1 /* ContextMenu.h */
2 
3 /* Copyright (C) 2011-2017 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 CONTEXTMENU_H
22 #define CONTEXTMENU_H
23 
24 #include <QMenu>
25 
26 #include "GUI/Utils/Widgets/WidgetTemplate.h"
27 #include "Utils/Pimpl.h"
28 
29 class QAction;
30 class PreferenceAction;
31 
36 using ContextMenuEntries=uint16_t;
37 
42 class ContextMenu :
43  public Gui::WidgetTemplate<QMenu>
44 {
45  Q_OBJECT
46  PIMPL(ContextMenu)
47 
48 public:
49 
53  enum Entry
54  {
55  EntryNone =0,
56  EntryNew =(1<<0),
57  EntryEdit =(1<<1),
58  EntryUndo =(1<<2),
59  EntrySave =(1<<3),
60  EntrySaveAs =(1<<4),
61  EntryRename =(1<<5),
62  EntryDelete =(1<<6),
63  EntryOpen =(1<<7),
64  EntryDefault=(1<<8)
65  };
66 
67 signals:
68  void sig_new();
69  void sig_edit();
70  void sig_undo();
71  void sig_save();
72  void sig_save_as();
73  void sig_rename();
74  void sig_delete();
75  void sig_open();
76  void sig_default();
77 
78 
79 private:
85  void show_action(bool b, QAction* action);
86 
87 
88 public:
89  explicit ContextMenu(QWidget *parent=nullptr);
90  virtual ~ContextMenu();
91 
96  void register_action(QAction* action);
97 
102  bool has_actions();
103 
109 
110 
111 protected:
112  void showEvent(QShowEvent* e) override;
113  void language_changed() override;
114  void skin_changed() override;
115 
116 
117 public slots:
122  void show_actions(ContextMenuEntries entries);
123 
129  void show_action(ContextMenu::Entry entry, bool visible);
130 
134  void show_all();
135 
136  void add_preference_action(PreferenceAction* action);
137 
138 
139 private slots:
143  void timed_out();
144 
145 };
146 
147 #endif // CONTEXTMENU_H
void show_actions(ContextMenuEntries entries)
show actions defined by ContextMenuEntry mask. Hide other actions
ContextMenuEntries get_entries() const
get all visible entries
uint16_t ContextMenuEntries
Combination of ContextMenu::Entry values.
Definition: ContextMenu.h:36
Template for Sayonara Widgets. This template is responsible for holding a reference to the settings...
Definition: WidgetTemplate.h:47
void show_all()
show all actions
Entry
The Entry enum.
Definition: ContextMenu.h:53
bool has_actions()
query, if there are visible actions
A context menu with some standard actions.
Definition: ContextMenu.h:42
Definition: PreferenceAction.h:35
void register_action(QAction *action)
register a custom action