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  EntryDefault=(1<<7)
65  };
66 
67 signals:
68  void sig_new();
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:
79  QAction* _action_new=nullptr;
80  QAction* _action_open=nullptr;
81  QAction* _action_undo=nullptr;
82  QAction* _action_save=nullptr;
83  QAction* _action_save_as=nullptr;
84  QAction* _action_rename=nullptr;
85  QAction* _action_delete=nullptr;
86  QAction* _action_default=nullptr;
87 
88 
89  QList<QAction*> _actions;
90  QTimer* _timer=nullptr;
91  IconLoader* _icon_loader=nullptr;
92 
98  void show_action(bool b, QAction* action);
99 
100 
101 public:
102  explicit ContextMenu(QWidget *parent=nullptr);
103 
108  void register_action(QAction* action);
109 
114  bool has_actions();
115 
121 
122 
123 protected:
124  void showEvent(QShowEvent* e) override;
125 
126 
127 public slots:
132  void show_actions(ContextMenuEntries entries);
133 
139  void show_action(ContextMenu::Entry entry, bool visible);
140 
144  void show_all();
145 
146 
147 private slots:
151  void timed_out();
152  void language_changed();
153  void skin_changed();
154 };
155 
156 
157 
158 #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
The IconLoader class.
Definition: IconLoader.h:39
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