Sayonara Player
ContextMenu.h
1 /* ContextMenu.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (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 
30 namespace Gui
31 {
32  class PreferenceAction;
37  using ContextMenuEntries=uint16_t;
38 
43  class ContextMenu :
44  public Gui::WidgetTemplate<QMenu>
45  {
46  Q_OBJECT
47  PIMPL(ContextMenu)
48 
49  public:
50 
54  enum Entry
55  {
56  EntryNone =0,
57  EntryNew =(1<<0),
58  EntryEdit =(1<<1),
59  EntryUndo =(1<<2),
60  EntrySave =(1<<3),
61  EntrySaveAs =(1<<4),
62  EntryRename =(1<<5),
63  EntryDelete =(1<<6),
64  EntryOpen =(1<<7),
65  EntryDefault=(1<<8)
66  };
67 
68  signals:
69  void sigNew();
70  void sigEdit();
71  void sigUndo();
72  void sigSave();
73  void sigSaveAs();
74  void sigRename();
75  void sigDelete();
76  void sigOpen();
77  void sigDefault();
78 
79 
80  private:
86  void showAction(bool b, QAction* action);
87 
88 
89  public:
90  explicit ContextMenu(QWidget* parent=nullptr);
91  virtual ~ContextMenu() override;
92 
97  void registerAction(QAction* action);
98 
103  bool hasActions();
104 
110 
111 
112  protected:
113  void showEvent(QShowEvent* e) override;
114  void languageChanged() override;
115  void skinChanged() override;
116 
117 
118  public slots:
124 
130  void showAction(ContextMenu::Entry entry, bool visible);
131 
135  void showAll();
136 
137  void addPreferenceAction(PreferenceAction* action);
138 
139 
140  private slots:
144  void timedOut();
145 
146  };
147 }
148 
149 #endif // CONTEXTMENU_H
Gui::ContextMenu::Entry
Entry
The Entry enum.
Definition: ContextMenu.h:55
Gui::ContextMenuEntries
uint16_t ContextMenuEntries
Combination of ContextMenu::Entry values.
Definition: ContextMenu.h:37
Gui::ContextMenu::hasActions
bool hasActions()
query, if there are visible actions
Gui::ContextMenu::entries
ContextMenuEntries entries() const
get all visible entries
Gui::WidgetTemplate
Template for Sayonara Widgets. This template is responsible for holding a reference to the settings.
Definition: WidgetTemplate.h:87
Gui::PreferenceAction
A PreferenceAction can be added to each widget supporting QActions. When triggering this action,...
Definition: PreferenceAction.h:40
Gui::ContextMenu
A context menu with some standard actions.
Definition: ContextMenu.h:45
Gui::ContextMenu::showActions
void showActions(ContextMenuEntries entries)
show actions defined by ContextMenuEntry mask. Hide other actions
Gui::ContextMenu::showAction
void showAction(ContextMenu::Entry entry, bool visible)
show/hide specific action
Gui::ContextMenu::showAll
void showAll()
show all actions
Gui::ContextMenu::registerAction
void registerAction(QAction *action)
register a custom action