-
Notifications
You must be signed in to change notification settings - Fork 0
/
QDockManager.h
94 lines (75 loc) · 2.04 KB
/
QDockManager.h
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
#ifndef QDOCKMANAGER_H
#define QDOCKMANAGER_H
#include <QWidget>
#include <map>
#include "QDockCommon.h"
class QDockPanel;
class QDockFrame;
class QDockNode;
class IAcceptDrop;
class QDockManager : public QObject
{
Q_OBJECT
public:
QDockManager(QWidget *parent);
~QDockManager();
QDockFrame* getDockFrame(){ return dockFrame_; }
QDockPanel* addPanel(int id, const QString& title, QPoint pos, QSize size, QWidget* contensWidget = NULL);
QDockPanel* getDockPanelByID(int id);
public slots:
bool dockPanelTo(QDockPanel* panel, QWidget* target, DockArea area);
bool dockPanelToFrame(QDockPanel* panel, DockArea area);
bool dockPanelToPanel(QDockPanel* from, QDockPanel* target, DockArea area);
bool autoHidePanel(QDockPanel* panel, bool hide);
public:
bool isRootNode(QDockNode* node);
void undockPanel(QDockPanel* panel);
private:
void onDragEnterPanel();
void onDragLeavePanel();
void onEndDragAtPanel();
bool dockPanelToFloatPanel(QDockPanel* from, QDockPanel* target, DockArea area);
bool dockPanelToDockedPanel(QDockPanel* from, QDockPanel* target, DockArea area);
template<typename T>
T* findChild(const QPoint& pos, const QWidget* except = nullptr)
{
return findChild<T>(dockFrame_, pos, except);
}
template<typename T>
T* findChild(QWidget* p, const QPoint& pos, const QWidget* except)
{
for (int i = p->children().size() - 1; i >= 0; --i)
{
QWidget *child = qobject_cast<QWidget*>(p->children().at(i));
if (!child ||
//child->isWindow() ||
child->isHidden() ||
child->testAttribute(Qt::WA_TransparentForMouseEvents)
)
{
continue;
}
T* w = nullptr;
if (w = findChild<T>(child, pos, except))
{
return w;
}
w = qobject_cast<T*>(child);
if (!w
|| !w->rect().contains(w->mapFromGlobal(pos))
|| w == except)
{
continue;
}
return w;
}
return nullptr;
}
IAcceptDrop* getDropTarget(const QPoint& pos, const QWidget* except);
private:
QDockFrame* dockFrame_;
std::map<int, QDockPanel*> dockPanels_;
friend QDockPanel;
friend QDockFrame;
};
#endif // QDOCKMANAGER_H