Sayonara Player
ContextMenu.h
1 /* ContextMenu.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 CONTEXTMENU_H
24 #define CONTEXTMENU_H
25 
26 #include <QAction>
27 #include <QMenu>
28 #include <QTimer>
29 
30 #include "Helper/Settings/SayonaraClass.h"
31 
32 class IconLoader;
33 
38 typedef int ContextMenuEntries;
39 
44 class ContextMenu :
45  public QMenu,
46  protected SayonaraClass
47 {
48  Q_OBJECT
49 
50 public:
51 
55  enum Entry {
56  EntryNone =0,
57  EntryNew =(1<<0),
58  EntryUndo =(1<<1),
59  EntrySave =(1<<2),
60  EntrySaveAs =(1<<3),
61  EntryRename =(1<<4),
62  EntryDelete =(1<<5),
63  EntryOpen =(1<<6)
64  };
65 
66 signals:
67  void sig_new();
68  void sig_undo();
69  void sig_save();
70  void sig_save_as();
71  void sig_rename();
72  void sig_delete();
73  void sig_open();
74 
75 
76 private:
77  QAction* _action_new=nullptr;
78  QAction* _action_open=nullptr;
79  QAction* _action_undo=nullptr;
80  QAction* _action_save=nullptr;
81  QAction* _action_save_as=nullptr;
82  QAction* _action_rename=nullptr;
83  QAction* _action_delete=nullptr;
84 
85 
86  QList<QAction*> _actions;
87  QTimer* _timer=nullptr;
88  IconLoader* _icon_loader=nullptr;
89 
95  void show_action(bool b, QAction* action);
96 
97 
98 public:
99  explicit ContextMenu(QWidget *parent=nullptr);
100 
105  void register_action(QAction* action);
106 
111  bool has_actions();
112 
118 
119 
120 protected:
121  void showEvent(QShowEvent* e) override;
122 
123 
124 public slots:
129  void show_actions(ContextMenuEntries entries);
130 
136  void show_action(ContextMenu::Entry entry, bool visible);
137 
141  void show_all();
142 
143 
144 private slots:
148  void timed_out();
149  void language_changed();
150  void skin_changed();
151 };
152 
153 
154 
155 #endif // CONTEXTMENU_H
void show_actions(ContextMenuEntries entries)
show actions defined by ContextMenuEntry mask. Hide other actions
The SayonaraClass class provides access to Settings and notifications.
Definition: SayonaraClass.h:31
void show_all()
show all actions
Entry
The Entry enum.
Definition: ContextMenu.h:55
bool has_actions()
query, if there are visible actions
Definition: IconLoader.h:35
A context menu with some standard actions.
Definition: ContextMenu.h:44
void register_action(QAction *action)
register a custom action
ContextMenuEntries get_entries() const
get all visible entries
int ContextMenuEntries
Combination of ContextMenu::Entry values.
Definition: ContextMenu.h:32