-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmenubarchanger.cpp
More file actions
86 lines (71 loc) · 1.92 KB
/
menubarchanger.cpp
File metadata and controls
86 lines (71 loc) · 1.92 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "menubarchanger.h"
MenuBarChanger::MenuBarChanger(QMenuBar *AMenuBar) : QObject(AMenuBar)
{
FMenuBar = AMenuBar;
}
MenuBarChanger::~MenuBarChanger()
{
emit menuBarChangerDestroyed(this);
}
bool MenuBarChanger::isEmpty() const
{
return FMenu.isEmpty();
}
QMenuBar *MenuBarChanger::menuBar() const
{
return FMenuBar;
}
int MenuBarChanger::menuGroup(Menu *AMenu) const
{
QMultiMap<int, Menu *>::const_iterator it = qFind(FMenu.begin(),FMenu.end(),AMenu);
if (it != FMenu.constEnd())
return it.key();
return MBG_NULL;
}
QList<Menu *> MenuBarChanger::groupMenus(int AGroup) const
{
if (AGroup == MBG_NULL)
return FMenu.values();
return FMenu.values(AGroup);
}
void MenuBarChanger::insertMenu(Menu *AMenu, int AGroup)
{
QMultiMap<int, Menu *>::iterator it = qFind(FMenu.begin(),FMenu.end(),AMenu);
if (it != FMenu.end())
{
FMenu.erase(it);
FMenuBar->removeAction(AMenu->menuAction());
}
it = FMenu.upperBound(AGroup);
Menu *befour = it!=FMenu.end() ? it.value() : NULL;
if (befour)
FMenuBar->insertAction(befour->menuAction(),AMenu->menuAction());
else
FMenuBar->addAction(AMenu->menuAction());
FMenu.insertMulti(AGroup,AMenu);
connect(AMenu,SIGNAL(menuDestroyed(Menu *)),SLOT(onMenuDestroyed(Menu *)));
emit menuInserted(befour,AMenu,AGroup);
}
void MenuBarChanger::removeMenu(Menu *AMenu)
{
QMultiMap<int, Menu *>::iterator it = qFind(FMenu.begin(),FMenu.end(),AMenu);
if (it != FMenu.end())
{
disconnect(AMenu,SIGNAL(menuDestroyed(Menu *)),this,SLOT(onMenuDestroyed(Menu *)));
FMenu.erase(it);
FMenuBar->removeAction(AMenu->menuAction());
emit menuRemoved(AMenu);
if (AMenu->parent() == FMenuBar)
AMenu->deleteLater();
}
}
void MenuBarChanger::clear()
{
foreach(Menu *menu,FMenu.values())
removeMenu(menu);
FMenuBar->clear();
}
void MenuBarChanger::onMenuDestroyed(Menu *AMenu)
{
removeMenu(AMenu);
}