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