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 <QAction>
25 #include <QMenu>
26 #include <QTimer>
27 
28 #include "Helper/Settings/SayonaraClass.h"
29 
30 class IconLoader;
31 
36 typedef int ContextMenuEntries;
37 
42 class ContextMenu :
43  public QMenu,
44  protected SayonaraClass
45 {
46  Q_OBJECT
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:
80  QAction* _action_new=nullptr;
81  QAction* _action_edit=nullptr;
82  QAction* _action_open=nullptr;
83  QAction* _action_undo=nullptr;
84  QAction* _action_save=nullptr;
85  QAction* _action_save_as=nullptr;
86  QAction* _action_rename=nullptr;
87  QAction* _action_delete=nullptr;
88  QAction* _action_default=nullptr;
89 
90 
91  QList<QAction*> _actions;
92  QTimer* _timer=nullptr;
93  IconLoader* _icon_loader=nullptr;
94 
100  void show_action(bool b, QAction* action);
101 
102 
103 public:
104  explicit ContextMenu(QWidget *parent=nullptr);
105  virtual ~ContextMenu();
106 
111  void register_action(QAction* action);
112 
117  bool has_actions();
118 
124 
125 
126 protected:
127  void showEvent(QShowEvent* e) override;
128 
129 
130 public slots:
135  void show_actions(ContextMenuEntries entries);
136 
142  void show_action(ContextMenu::Entry entry, bool visible);
143 
147  void show_all();
148 
149 
150 private slots:
154  void timed_out();
155  void language_changed();
156  void skin_changed();
157 };
158 
159 #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:29
void show_all()
show all actions
Entry
The Entry enum.
Definition: ContextMenu.h:53
bool has_actions()
query, if there are visible actions
The IconLoader class.
Definition: IconLoader.h:36
A context menu with some standard actions.
Definition: ContextMenu.h:42
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:30