-
Notifications
You must be signed in to change notification settings - Fork 0
/
centralwindow.cpp
125 lines (100 loc) · 3.69 KB
/
centralwindow.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
114
115
116
117
118
119
120
121
122
123
124
#include "centralwindow.h"
#include "basecentraldock.h"
#include "projectCore/baseprojectcontroller.h"
#include "projectCore/projectsmanager.h"
#include <iostream>
#include <QTextEdit>
#include <QMenu>
#include <QGLWidget>
CentralWindow::CentralWindow(QWidget* parent) : QMainWindow(parent)
{
setObjectName("centralWindow");
setWindowTitle(tr("Graphics visualization"));
setWindowFlags(Qt::Widget);
connect(&projectsManager, &ProjectsManager::onProjectOpened, this, &CentralWindow::onProjectOpened);
//Setup openGl
QGLFormat fmt;
fmt.setSampleBuffers(true);
fmt.setSamples(16);//antialiazing
fmt.setDepthBufferSize(24);
QGLFormat::setDefaultFormat(fmt);
//Set dock options
DockOptions opts;
//opts |= AnimatedDocks;
opts |= AllowNestedDocks;
opts |= AllowTabbedDocks;
QMainWindow::setDockOptions(opts);
setCorner(Qt::Corner::TopRightCorner, Qt::RightDockWidgetArea);
setCorner(Qt::Corner::BottomRightCorner, Qt::RightDockWidgetArea);
//add first widget
//getNewDock(Qt::TopDockWidgetArea);
//getNewDock(Qt::TopDockWidgetArea);
//hide central widget
setCentralWidget(nullptr);
}
void CentralWindow::splitDockWidget(BaseCentralDock* base, BaseCentralDock* nw, Qt::Orientation o)
{
if(!base || !nw) return;
auto area = (o == Qt::Orientation::Vertical) ? Qt::BottomDockWidgetArea : Qt::RightDockWidgetArea;
QMainWindow::addDockWidget(area, nw);
if(tabifiedDockWidgets(base).size() == 0)
QMainWindow::splitDockWidget(base, nw, o);
}
void CentralWindow::tabDockWidget(BaseCentralDock* first, BaseCentralDock* second)
{
if(!first || !second) return;
QMainWindow::addDockWidget( Qt::RightDockWidgetArea, second);
QMainWindow::tabifyDockWidget(first, second);
second->show();
second->raise();
}
void CentralWindow::addNewDockWidget(BaseCentralDock* w)
{
if(!w) return;
QMainWindow::addDockWidget(Qt::DockWidgetArea::RightDockWidgetArea, w);
w->setFloating(true);
}
//---- Getters ----
//---Public slots---
void CentralWindow::onProjectOpened(BaseProjectController* const proj)
{
Q_FOREACH(auto a, proj->getAviableCentralDocks())
{
addDockWidget(a->getDefaultArea(), a);
}
}
//---Private methods---
//BaseCentralDock* CentralWindow::getNewDock(Qt::DockWidgetArea area)
//{
// BaseCentralDock *dv = createDockByType(tr("my_widget"), CentralDockTypes_t::GL_VISUALIZATOR_CENTRAL, {area});
// connect(dv, SIGNAL(onCreateDock(bool)), this, SLOT(createNewDockSlot(bool)));
// connect(dv, SIGNAL(onSplitDock(BaseCentralDock*,Qt::Orientation)), this, SLOT(splitDockSlot(BaseCentralDock*,Qt::Orientation)));
// connect(dv, SIGNAL(onTabDock(BaseCentralDock*)), this, SLOT(addTabDockSlot(BaseCentralDock*)));
// addDockWidget(area, dv);
// return dv;
//}
//void CentralWindow::splitDock(BaseCentralDock* w, Qt::Orientation o)
//{
// if(!w)
// return;
// auto area = (o == Qt::Orientation::Vertical) ? Qt::BottomDockWidgetArea : Qt::RightDockWidgetArea;
// BaseCentralDock *dv = getNewDock(area);
// if(tabifiedDockWidgets(w).size() == 0)
// splitDockWidget(w, dv, o);
// else
// addDockWidget(area, dv, o);
//}
//BaseCentralDock *CentralWindow::createDockByType(const QString& title,
// const CentralDockTypes_t& type,
// Qt::WindowFlags flags)
//{
// switch (type) {
// case EXEMPLE_CENTRAL:
// return new ExempleCentralDock(title, this, flags);
// case GL_VISUALIZATOR_CENTRAL:
// return new glCentralDock(title, this, flags);
// default:
// std::cerr << "Unknown widget type!\n";
// return nullptr;
// }
//}