History

Dialogbox for import fully functionnal

atlante45 committed 13 years ago

Commit 24531fd1 parent b41575912 files · +270 −81Browse files

Showing the changes to interface/src/ImportDialog.cpp (1 of 12 files). Show all

Unified · Split

interface/src/ImportDialog.cpp+105−29
@@ -9,8 +9,10 @@ · 8 unmodified lines
9 9
10#include <QStandardPaths>10#include <QStandardPaths>
11#include <QGridLayout>11#include <QGridLayout>
12#include <QMouseEvent>
12 13
13const QString WINDOW_NAME = QObject::tr("Import Voxels");14const QString WINDOW_NAME = QObject::tr("Import Voxels");
15const QString IMPORT_BUTTON_NAME = QObject::tr("Import");
14const QString IMPORT_TO_CLIPBOARD_CHECKBOX_STRING = QObject::tr("Import into clipboard");16const QString IMPORT_TO_CLIPBOARD_CHECKBOX_STRING = QObject::tr("Import into clipboard");
15const QString PREVIEW_CHECKBOX_STRING = QObject::tr("Load preview");17const QString PREVIEW_CHECKBOX_STRING = QObject::tr("Load preview");
16const QString IMPORT_FILE_TYPES = QObject::tr("Sparse Voxel Octree Files, "18const QString IMPORT_FILE_TYPES = QObject::tr("Sparse Voxel Octree Files, "
@@ -20,8 +22,14 @@ const QString IMPORT_FILE_TYPES = QObject::tr("Sparse Voxel Oc · 3 unmodified lines
20 22
21const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);23const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
22 24
25
23const glm::vec3 UP = glm::vec3(0, 1, 0);26const glm::vec3 UP = glm::vec3(0, 1, 0);
24const float ANGULAR_RATE = 0.02f;27const float ANGULAR_RATE = 0.02f;
28const float VERTICAL_ANGLE = M_PI_4 / 2.0f;
29const float RETURN_RATE = 0.02f;
30const float NEAR_CLIP = 0.5f;
31const float FAR_CLIP = 10.0f;
32const float FIELD_OF_VIEW = 60.0f;
25 33
26class GLWidget : public QGLWidget {34class GLWidget : public QGLWidget {
27public:35public:
@@ -31,17 +39,25 @@ public: · 3 unmodified lines
31 39
32protected:40protected:
33 virtual void initializeGL();41 virtual void initializeGL();
34 virtual void resizeGL(int w, int h);42 virtual void resizeGL(int width, int height);
35 virtual void paintGL();43 virtual void paintGL();
36 44
45 void mousePressEvent(QMouseEvent* event);
46 void mouseMoveEvent(QMouseEvent* event);
47 void mouseReleaseEvent(QMouseEvent* event);
48
37private:49private:
38 VoxelSystem* _voxelSystem;50 VoxelSystem* _voxelSystem;
39 51
40 bool _draw;52 bool _draw;
41 53
42 float _a;54 double _a; // horizontal angle of the camera to the center of the object
43 float _h;55 double _h; // vertical angle of the camera to the center of the object
44 glm::vec3 _targetCenter;56 glm::vec3 _targetCenter;
57
58 bool _pressed;
59 int _mouseX;
60 int _mouseY;
45};61};
46 62
47GLWidget::GLWidget(QWidget *parent, VoxelSystem *voxelSystem)63GLWidget::GLWidget(QWidget *parent, VoxelSystem *voxelSystem)
@@ -49,8 +65,11 @@ GLWidget::GLWidget(QWidget *parent, VoxelSystem *voxelSystem) · 1 unmodified line
49 _voxelSystem(voxelSystem),65 _voxelSystem(voxelSystem),
50 _draw(false),66 _draw(false),
51 _a(0.0f),67 _a(0.0f),
52 _h(0.0f),68 _h(VERTICAL_ANGLE),
53 _targetCenter(0.5f, 0.5f, 0.5f) {69 _targetCenter(0.5f, 0.5f, 0.5f),
70 _pressed(false),
71 _mouseX(0),
72 _mouseY(0) {
54}73}
55 74
56void GLWidget::initializeGL() {75void GLWidget::initializeGL() {
@@ -65,12 +84,15 @@ void GLWidget::initializeGL() { · 8 unmodified lines
65 84
66}85}
67 86
68void GLWidget::resizeGL(int w, int h) {87void GLWidget::resizeGL(int width, int height) {
69 glViewport(0, 0, w, h);88 glViewport(0, 0, width, height);
70 89
71 glMatrixMode(GL_PROJECTION);90 glMatrixMode(GL_PROJECTION);
72 glLoadIdentity();91 glLoadIdentity();
73 gluPerspective(60, (float) w / h, 0.25f, 500);92 gluPerspective(FIELD_OF_VIEW,
93 (float) width / height,
94 NEAR_CLIP,
95 FAR_CLIP);
74}96}
75 97
76void GLWidget::paintGL() {98void GLWidget::paintGL() {
@@ -80,10 +102,14 @@ void GLWidget::paintGL() { · 3 unmodified lines
80 glMatrixMode(GL_MODELVIEW);102 glMatrixMode(GL_MODELVIEW);
81 glLoadIdentity();103 glLoadIdentity();
82 104
83 _a += ANGULAR_RATE;105 if (!_pressed) {
84 gluLookAt(_targetCenter.x + (glm::length(_targetCenter) + 0.5f) * cos((double) _a),106 _a += ANGULAR_RATE;
85 _targetCenter.y * 1.25f,107 _h = (1.0f - RETURN_RATE) * _h + RETURN_RATE * VERTICAL_ANGLE;
86 _targetCenter.z + (glm::length(_targetCenter) + 0.5f) * sin((double) _a),108 }
109
110 gluLookAt(_targetCenter.x + (glm::length(_targetCenter) + NEAR_CLIP) * cos(_a),
111 _targetCenter.y + (glm::length(_targetCenter) + NEAR_CLIP) * sin(_h),
112 _targetCenter.z + (glm::length(_targetCenter) + NEAR_CLIP) * sin(_a),
87 _targetCenter.x, _targetCenter.y, _targetCenter.z,113 _targetCenter.x, _targetCenter.y, _targetCenter.z,
88 UP.x, UP.y, UP.z);114 UP.x, UP.y, UP.z);
89 115
@@ -102,7 +128,7 @@ void GLWidget::paintGL() { · 12 unmodified lines
102 128
103 129
104 glColor3d(0.4f, 0.4f ,0.4f);130 glColor3d(0.4f, 0.4f ,0.4f);
105 glVertex3d(2 * _targetCenter.x, 2 * _targetCenter.y,2 * _targetCenter.z);131 glVertex3d(2 * _targetCenter.x, 2 * _targetCenter.y, 2 * _targetCenter.z);
106 glVertex3d(0 , 2 * _targetCenter.y, 2 * _targetCenter.z);132 glVertex3d(0 , 2 * _targetCenter.y, 2 * _targetCenter.z);
107 133
108 glVertex3d(2 * _targetCenter.x, 2 * _targetCenter.y, 2 * _targetCenter.z);134 glVertex3d(2 * _targetCenter.x, 2 * _targetCenter.y, 2 * _targetCenter.z);
@@ -116,18 +142,40 @@ void GLWidget::paintGL() { · 7 unmodified lines
116 }142 }
117}143}
118 144
145
146void GLWidget::mousePressEvent(QMouseEvent* event) {
147 _pressed = true;
148 _mouseX = event->globalX();
149 _mouseY = event->globalY();
150}
151
152void GLWidget::mouseMoveEvent(QMouseEvent* event) {
153 _a += (M_PI * (event->globalX() - _mouseX)) / height();
154 _h += (M_PI * (event->globalY() - _mouseY)) / height();
155 _h = glm::clamp(_h, -M_PI_4, M_PI_4);
156
157 _mouseX = event->globalX();
158 _mouseY = event->globalY();
159}
160
161void GLWidget::mouseReleaseEvent(QMouseEvent* event) {
162 _pressed = false;
163}
164
119ImportDialog::ImportDialog(QWidget *parent, VoxelSystem* voxelSystem)165ImportDialog::ImportDialog(QWidget *parent, VoxelSystem* voxelSystem)
120 : QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, IMPORT_FILE_TYPES),166 : QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, IMPORT_FILE_TYPES),
121 _clipboardImportBox (IMPORT_TO_CLIPBOARD_CHECKBOX_STRING, this),167 _importButton (IMPORT_BUTTON_NAME, this),
122 _previewBox (PREVIEW_CHECKBOX_STRING, this),168 _clipboardImportBox(IMPORT_TO_CLIPBOARD_CHECKBOX_STRING, this),
123 _previewBar (this),169 _previewBox (PREVIEW_CHECKBOX_STRING, this),
124 _glPreview (new GLWidget(this, voxelSystem)) {170 _previewBar (this),
171 _glPreview (new GLWidget(this, voxelSystem)) {
125 172
126 setOption(QFileDialog::DontUseNativeDialog, true);173 setOption(QFileDialog::DontUseNativeDialog, true);
127 setFileMode(QFileDialog::ExistingFile);174 setFileMode(QFileDialog::ExistingFile);
128 setViewMode(QFileDialog::Detail);175 setViewMode(QFileDialog::Detail);
129 176
130 QGridLayout* gridLayout = (QGridLayout*) layout();177 QGridLayout* gridLayout = (QGridLayout*) layout();
178 gridLayout->addWidget(&_importButton , 2, 2);
131 gridLayout->addWidget(&_clipboardImportBox, 2, 3);179 gridLayout->addWidget(&_clipboardImportBox, 2, 3);
132 gridLayout->addWidget(&_previewBox , 3, 3);180 gridLayout->addWidget(&_previewBox , 3, 3);
133 gridLayout->addWidget(&_previewBar , 0, 3);181 gridLayout->addWidget(&_previewBar , 0, 3);
@@ -138,43 +186,71 @@ ImportDialog::ImportDialog(QWidget *parent, VoxelSystem* voxelSystem) · 4 unmodified lines
138 _previewBar.setRange(0, 100);186 _previewBar.setRange(0, 100);
139 _previewBar.setValue(0);187 _previewBar.setValue(0);
140 188
189 connect(&_importButton, SIGNAL(pressed()), SLOT(import()));
190 connect(&_previewBox, SIGNAL(toggled(bool)), SIGNAL(previewToggled(bool)));
141 connect(&_previewBox, SIGNAL(toggled(bool)), SLOT(preview(bool)));191 connect(&_previewBox, SIGNAL(toggled(bool)), SLOT(preview(bool)));
192
142 connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString)));193 connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString)));
143 connect(&_glTimer, SIGNAL(timeout()), SLOT(timer()));194 connect(&_glTimer, SIGNAL(timeout()), SLOT(timer()));
144 195
145 connect(voxelSystem->getVoxelTree(), SIGNAL(importSize(float,float,float)), SLOT(setGLCamera(float, float, float)));196 connect(voxelSystem, SIGNAL(importSize(float,float,float)), SLOT(setGLCamera(float, float, float)));
146 connect(voxelSystem->getVoxelTree(), SIGNAL(importProgress(int)), &_previewBar, SLOT(setValue(int)));197 connect(voxelSystem, SIGNAL(importProgress(int)), &_previewBar, SLOT(setValue(int)));
147}198}
148 199
149int ImportDialog::exec() {200ImportDialog::~ImportDialog() {
150 _previewBox.setChecked(false);201 delete _glPreview;
151 _previewBar.setVisible(false);202}
152 203
153 int ret = QFileDialog::exec();204void ImportDialog::import() {
205 _importButton.setDisabled(true);
206 _clipboardImportBox.setDisabled(true);
207 _previewBox.setDisabled(true);
154 208
209 _previewBar.setValue(0);
210 _previewBar.setVisible(true);
155 211
156 ((GLWidget*) _glPreview)->setDraw(false);212 emit accepted();
157 _glTimer.stop();213}
158 _glPreview->updateGL();214
215void ImportDialog::accept() {
216 QFileDialog::accept();
217}
218
219void ImportDialog::reject() {
220 QFileDialog::reject();
221}
222
223int ImportDialog::exec() {
224 reset();
225 int ret = QFileDialog::exec();
226 preview(false);
159 227
160 return ret;228 return ret;
161}229}
162 230
163void ImportDialog::setGLCamera(float x, float y, float z) {231void ImportDialog::setGLCamera(float x, float y, float z) {
164 ((GLWidget*) _glPreview)->setTargetCenter(glm::vec3(x, y, z) / 2.0f);232 _glPreview->setTargetCenter(glm::vec3(x, y, z) / 2.0f);
165}233}
166 234
167void ImportDialog::reset() {235void ImportDialog::reset() {
236 _previewBox.setChecked(false);
237 _previewBar.setVisible(false);
168 _previewBar.setValue(0);238 _previewBar.setValue(0);
239 _importButton.setEnabled(true);
240 _clipboardImportBox.setEnabled(true);
241 _previewBox.setEnabled(true);
242
243 _glTimer.stop();
244 _glPreview->setDraw(false);
245 _glPreview->updateGL();
169}246}
170 247
171void ImportDialog::preview(bool wantPreview) {248void ImportDialog::preview(bool wantPreview) {
172 _previewBar.setValue(0);249 _previewBar.setValue(0);
173 _previewBar.setVisible(wantPreview);250 _previewBar.setVisible(wantPreview);
174 ((GLWidget*) _glPreview)->setDraw(wantPreview);251 _glPreview->setDraw(wantPreview);
175 252
176 if (wantPreview) {253 if (wantPreview) {
177 emit previewActivated(_currentFile);
178 _glTimer.start();254 _glTimer.start();
179 } else {255 } else {
180 _glTimer.stop();256 _glTimer.stop();

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t