-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
258 lines (218 loc) · 8.61 KB
/
Copy pathMainWindow.cpp
File metadata and controls
258 lines (218 loc) · 8.61 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/////////////////////////////////////////////////////////////////
/// @file MainWindow.cpp
/// @author Chris L Baker (clb) <chris@chimail.net>
/// @date 2014.05.20
///
/// @attention Copyright (C) 2014
/// @attention All rights reserved
/////////////////////////////////////////////////////////////////
#include "MainWindow.h"
#include "QOSGWidget.h"
#include "TreeView.h"
#include <QtGui/QTreeView>
#include <QtGui/QActionGroup>
#include <QtGui/QCheckBox>
#include <iostream>
namespace d3
{
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
MainWindow::MainWindow() :
QMainWindow(),
m_pOsgWidget(nullptr),
m_pTree(nullptr),
m_pMenuBar(),
m_timer()
{
// the menu widget
QWidget* theMenuWidget( new QWidget() );
// the menu layout
QHBoxLayout* menuLayout( new QHBoxLayout() );
menuLayout->setContentsMargins(0,0,0,0);
menuLayout->setSpacing(0);
theMenuWidget->setLayout(menuLayout);
// the menu bar
m_pMenuBar = new QMenuBar(this);
m_pMenuBar->setSizePolicy(QSizePolicy::MinimumExpanding,
QSizePolicy::Preferred);
// add the bar to the menu layout
menuLayout->addWidget(m_pMenuBar);
// set the menu widget
setMenuWidget(theMenuWidget);
// set the main splitter
QSplitter* splitter(new QSplitter(Qt::Vertical));
splitter->setChildrenCollapsible(false);
setCentralWidget(splitter);
// add this menu
QMenu* dspMenu = m_pMenuBar->addMenu("Display Interface");
buildDisplayMenu(dspMenu);
// setup the action to toggle screen grabs
{
QAction* pAction = m_pMenuBar->addAction("Snapshot");
pAction->setShortcut(QKeySequence(Qt::Key_G));
QWidget::connect(pAction, SIGNAL(triggered(bool)), this, SLOT(grabSnapshot(bool)));
}
// setup the action for continuous frame capture for video
{
QAction* pAction = m_pMenuBar->addAction("Video");
pAction->setShortcut(QKeySequence(Qt::Key_C));
pAction->setCheckable(true);
pAction->setChecked(false);
QWidget::connect(pAction, SIGNAL(triggered(bool)), this, SLOT(continuousCapture(bool)));
}
// Quitting from the menu, and as Ctrl-Q
{
QAction* pAction = dspMenu->addAction("&Exit");
pAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
QWidget::connect(pAction, SIGNAL(triggered()), this, SLOT(close()));
}
// show everything
show();
};
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
MainWindow::~MainWindow()
{
m_timer.stop();
};
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
void MainWindow::setOsgWidget(QOSGWidget* widget)
{
if ( nullptr == widget ) return;
// Hold the widget
m_pOsgWidget = widget;
// Set the main splitter with this widget
QSplitter* splitter( static_cast<QSplitter*>(centralWidget()) );
if ( splitter ) splitter->addWidget(widget);
// set the render timer
connect(&m_timer, SIGNAL(timeout()), this, SLOT(render()));
m_timer.setInterval(33); // 33 = 30fps
m_timer.start();
};
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
void MainWindow::setTreeView(TreeView* treeView)
{
if ( nullptr == treeView ) return;
// Hold this tree view
//m_pTree = treeView;
// build a dock widget
QDockWidget *dockWidget = new QDockWidget("Displayed Items");
dockWidget->setObjectName("Dock");
dockWidget->setWidget(treeView);
dockWidget->setTitleBarWidget(nullptr);
// add the dock widget
addDockWidget(Qt::RightDockWidgetArea, dockWidget);
};
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// bool MainWindow::add(const std::string& name,
// const osg::ref_ptr<osg::Node> node,
// const bool& showNode,
// const bool& replace)
// {
// return m_pTree->add(name, node, showNode, replace);
// };
/////////////////////////////////////////////////////////////////
/////////////// SLOTS //////////////////////////////////////////
///////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
void MainWindow::setFullScreen(bool fullscreen)
{
if ( isVisible() && (isFullScreen() != fullscreen) )
setWindowState(windowState() ^ Qt::WindowFullScreen);
};
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
void MainWindow::grabSnapshot(bool)
{
m_pOsgWidget->getScreenshotCallback()->grab();
};
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
void MainWindow::continuousCapture(bool checked)
{
m_pOsgWidget->getScreenshotCallback()->setCapture(checked);
static osg::Vec4 clearColor(m_pOsgWidget->getClearColor());
if ( checked )
{
m_pOsgWidget->setClearColor(osg::Vec4(1.0, 1.0, 1.0, 1.0));
m_pMenuBar->setStyleSheet("background-color: red");
}
else
{
m_pOsgWidget->setClearColor(clearColor);
m_pMenuBar->setStyleSheet("");
}
};
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
void MainWindow::render()
{
// make sure we have valid widget and we are visible
if ( (nullptr != m_pOsgWidget) && isVisible() )
{
// try and get the lock
if ( m_pOsgWidget->try_lock() )
{
// update and unlock
m_pOsgWidget->updateGL();
m_pOsgWidget->unlock();
}
}
};
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
void MainWindow::lock() { m_pOsgWidget->lock(); };
bool MainWindow::try_lock() { return m_pOsgWidget->try_lock(); };
void MainWindow::unlock() { m_pOsgWidget->unlock(); };
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
void MainWindow::setDarkClear() { m_pOsgWidget->setClearColor(osg::Vec4(0.1, 0.1, 0.1, 1.0)); };
void MainWindow::setLightClear() { m_pOsgWidget->setClearColor(osg::Vec4(0.5, 0.5, 0.5, 1.0)); };
void MainWindow::setWhiteClear() { m_pOsgWidget->setClearColor(osg::Vec4(1.0, 1.0, 1.0, 1.0)); };
/////////////////////////////////////////////////////////////////
///////////// PRIVATES /////////////////////////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
void MainWindow::buildDisplayMenu(QMenu* dspMenu)
{
// F11 toggles fullscreen
{
QAction* pAction = dspMenu->addAction("Fullscreen");
pAction->setCheckable(true);
pAction->setChecked(false);
pAction->setShortcut(QKeySequence(Qt::Key_F11));
QWidget::connect(pAction, SIGNAL(triggered(bool)), this, SLOT(setFullScreen(bool)));
}
// setup the ability to control tracking
{
QAction* pAction = dspMenu->addAction("Enable Tracking");
pAction->setChecked(true);
pAction->setChecked(false);
pAction->setShortcut(QKeySequence(Qt::Key_T));
QWidget::connect(pAction, SIGNAL(triggered(bool)), this, SLOT(enableNodeTracking(bool)));
}
// setup the background clear color (CC)
{
QAction* pActionDark = dspMenu->addAction("CC: dark");
pActionDark->setCheckable(false);
QWidget::connect(pActionDark, SIGNAL(triggered()), this, SLOT(setDarkClear()));
QAction* pActionLight = dspMenu->addAction("CC: light");
pActionLight->setCheckable(false);
QWidget::connect(pActionLight, SIGNAL(triggered()), this, SLOT(setLightClear()));
QAction* pActionWhite = dspMenu->addAction("CC: white");
pActionWhite->setCheckable(false);
QWidget::connect(pActionWhite, SIGNAL(triggered()), this, SLOT(setWhiteClear()));
}
};
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
void MainWindow::closeEvent(QCloseEvent* theEvent)
{
QMainWindow::closeEvent(theEvent);
};
} // namespace d3