Logo    
KDWinUtils
Helper library for MFC to Qt migration
Loading...
Searching...
No Matches
kmenu.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of KDWinutils, KDAB's MFC to Qt migration tool.
4**
5** Copyright (C) 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6** All rights reserved.
7**
8** This file is intended solely for use by the migration tools and services
9** provided by Klarälvdalens Datakonsult AB.
10**
11** Any other use or distribution of this software that is not otherwise agreed
12** upon in writing and signed by an authorized representative of Klarälvdalens
13** Datakonsult AB, KDAB (USA) LLC, KDAB (Deutschland) GmbH & Co. K.G.,
14** KDAB (France) SAS, KDAB (UK), Ltd., or any future subsidiary of Klarälvdalens
15** Datakonsult AB is hereby prohibited.
16**
17** Contact info@kdab.com if any conditions stated above are unclear to you.
18**
19****************************************************************************/
20
21#pragma once
22
23#include "../corelib/kstring.h"
25
26#include <QMenu>
27
28#include <cstdint>
29
30class QAction;
31
33
34class KRect;
35
36class KDWINUTILS_EXPORT KMenu : public QMenu
37{
38 Q_OBJECT
39public:
40 explicit KMenu(QWidget *parent = nullptr);
41
42 enum class AppendType {
43 String,
44 Separator,
45 Popup,
46 };
47
48 enum class ModifyBy {
49 Command,
50 Position,
51 };
52
53 // Uses AppendToMenu to add a menu action, then connects the trigger of that action to the provided slot
54 void AppendAndConnect(KMenu::AppendType appendType, std::uintptr_t nID, const KString &label,
55 std::function<void(std::uintptr_t nID)> slot);
56
57 QAction *AppendToMenu(AppendType nFlags, std::uintptr_t nIDNewItem = 0, const KString &lpszNewItem = {});
58
59 void CheckMenuItem(unsigned int nIDCheckItem, Qt::CheckState nCheck);
60
61 bool TrackPopupMenu(unsigned int nFlags, int x, int y, QWidget *pWnd = nullptr, KRect *lpRect = 0);
62
63 bool ModifyMenuItem(unsigned int nPosition, ModifyBy nFlags, std::uintptr_t nIDNewItem = 0,
64 const KString &lpszNewItem = {});
65
66private:
67 QMap<std::uintptr_t, QAction *> m_actionMap;
68};
69
Definition kmenu.h:37
ModifyBy
Definition kmenu.h:48
bool TrackPopupMenu(unsigned int nFlags, int x, int y, QWidget *pWnd=nullptr, KRect *lpRect=0)
void CheckMenuItem(unsigned int nIDCheckItem, Qt::CheckState nCheck)
bool ModifyMenuItem(unsigned int nPosition, ModifyBy nFlags, std::uintptr_t nIDNewItem=0, const KString &lpszNewItem={})
void AppendAndConnect(KMenu::AppendType appendType, std::uintptr_t nID, const KString &label, std::function< void(std::uintptr_t nID)> slot)
QAction * AppendToMenu(AppendType nFlags, std::uintptr_t nIDNewItem=0, const KString &lpszNewItem={})
AppendType
Definition kmenu.h:42
KMenu(QWidget *parent=nullptr)
The KRect class defines a rectangle in the plane using integer precision.
Definition krect.h:40
The KString class provides a Unicode character string.
Definition kstring.h:45
#define KDWINUTILS_EXPORT
Definition kdwinutils_export.h:31
#define KDWINUTILS_BEGIN_NAMESPACE
Definition kdwinutils_global.h:27
#define KDWINUTILS_END_NAMESPACE
Definition kdwinutils_global.h:28