forked from organicmaps/organicmaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup_menu_holder.hpp
54 lines (41 loc) · 1.46 KB
/
popup_menu_holder.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include <QtGui/QAction>
#include <QtWidgets/QToolButton>
#include <vector>
#include <type_traits>
namespace qt
{
/// Inherit from QObject to assign parents and don't worry about deleting.
class PopupMenuHolder : public QObject
{
Q_OBJECT
QToolButton * m_toolButton;
std::vector<QAction*> m_actions;
QAction * addActionImpl(QIcon const & icon, QString const & text, bool checkable);
public:
explicit PopupMenuHolder(QObject * parent = nullptr);
QAction * addAction(QIcon const & icon, QString const & text,
QObject const * receiver, char const * member, bool checkable)
{
QAction * p = addActionImpl(icon, text, checkable);
connect(p, SIGNAL(triggered()), receiver, member);
return p;
}
template <class SlotT>
QAction * addAction(QIcon const & icon, QString const & text, SlotT slot, bool checkable)
{
QAction * p = addActionImpl(icon, text, checkable);
connect(p, &QAction::triggered, std::move(slot));
return p;
}
QToolButton * create();
void setMainIcon(QIcon const & icon);
void setCurrent(size_t idx);
template <class T> typename std::enable_if<std::is_enum<T>::value, void>::type
setCurrent(T idx) { setCurrent(static_cast<size_t>(idx)); }
void setChecked(size_t idx, bool checked);
bool isChecked(size_t idx);
template <class T> typename std::enable_if<std::is_enum<T>::value, bool>::type
isChecked(T idx) { return isChecked(static_cast<size_t>(idx)); }
};
} // namespace qt