This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUiManager.cpp
113 lines (93 loc) · 2.96 KB
/
UiManager.cpp
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* libHeaven - A Qt-based ui framework for strongly modularized applications
* Copyright (C) 2012-2013 Sascha Cunz <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License (Version 2) as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if
* not, see <http://www.gnu.org/licenses/>.
*
*/
#include <QWidget>
#include "libHeavenActions/UiManager.hpp"
#include "libHeavenActions/UiContainer.hpp"
namespace Heaven
{
UiManager::UiManager()
: QObject()
{
}
UiManager::~UiManager()
{
}
UiManager* UiManager::sSelf = NULL;
UiManager* UiManager::self()
{
if( sSelf == NULL )
{
sSelf = new UiManager;
}
return sSelf;
}
void UiManager::addUiObject( UiObjectPrivate* uio )
{
mUioUsage.insert( uio, QSet< UiObjectPrivate* >() );
}
void UiManager::delUiObject( UiObjectPrivate* uio )
{
QSet< UiObjectPrivate* > usage = mUioUsage.value( uio );
mUioUsage.remove( uio );
foreach( UiObjectPrivate* used, usage )
{
Q_UNUSED( used );
}
}
void UiManager::addCreatedObject( QObject* object, UiObjectPrivate* forUiObject )
{
mCreatedObjects.insert( object, forUiObject );
}
void UiManager::removeCreatedObject( QObject* object )
{
mCreatedObjects.remove( object );
}
QObject* UiManager::findActivationContext( QObject* trigger )
{
UiObjectPrivate* previous;
UiObjectPrivate* uiObject = NULL;
Q_ASSERT( trigger );
do
{
previous = uiObject;
uiObject = mCreatedObjects.value( trigger, NULL );
if( !uiObject )
{
return NULL;
}
UiObjectTypes type = uiObject->type();
if( type == ToolBarType || type == MenuType || type == MenuBarType )
{
UiContainer* container = static_cast< UiContainer* >( uiObject );
QList< UiContainer* > pathTo = container->pathTo( previous );
while( !pathTo.isEmpty() )
{
UiContainer* cur = pathTo.takeLast();
if( cur->mActivationContext )
{
return cur->mActivationContext;
}
}
}
if( uiObject->mActivationContext )
{
return uiObject->mActivationContext;
}
trigger = trigger->parent();
} while( trigger );
return NULL;
}
}