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
99
1010 #include <QStandardPaths>
1111 #include <QGridLayout>
12+#include <QMouseEvent>
1213
1314 const QString WINDOW_NAME = QObject::tr("Import Voxels");
15+const QString IMPORT_BUTTON_NAME = QObject::tr("Import");
1416 const QString IMPORT_TO_CLIPBOARD_CHECKBOX_STRING = QObject::tr("Import into clipboard");
1517 const QString PREVIEW_CHECKBOX_STRING = QObject::tr("Load preview");
1618 const 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
2022
2123 const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
2224
25+
2326 const glm::vec3 UP = glm::vec3(0, 1, 0);
2427 const float ANGULAR_RATE = 0.02f;
28+const float VERTICAL_ANGLE = M_PI_4 / 2.0f;
29+const float RETURN_RATE = 0.02f;
30+const float NEAR_CLIP = 0.5f;
31+const float FAR_CLIP = 10.0f;
32+const float FIELD_OF_VIEW = 60.0f;
2533
2634 class GLWidget : public QGLWidget {
2735 public:
@@ -31,17 +39,25 @@ public: · 3 unmodified lines
3139
3240 protected:
3341 virtual void initializeGL();
34− virtual void resizeGL(int w, int h);
42+ virtual void resizeGL(int width, int height);
3543 virtual void paintGL();
3644
45+ void mousePressEvent(QMouseEvent* event);
46+ void mouseMoveEvent(QMouseEvent* event);
47+ void mouseReleaseEvent(QMouseEvent* event);
48+
3749 private:
3850 VoxelSystem* _voxelSystem;
3951
4052 bool _draw;
4153
42− float _a;
43− float _h;
54+ double _a; // horizontal angle of the camera to the center of the object
55+ double _h; // vertical angle of the camera to the center of the object
4456 glm::vec3 _targetCenter;
57+
58+ bool _pressed;
59+ int _mouseX;
60+ int _mouseY;
4561 };
4662
4763 GLWidget::GLWidget(QWidget *parent, VoxelSystem *voxelSystem)
@@ -49,8 +65,11 @@ GLWidget::GLWidget(QWidget *parent, VoxelSystem *voxelSystem) · 1 unmodified line
4965 _voxelSystem(voxelSystem),
5066 _draw(false),
5167 _a(0.0f),
52− _h(0.0f),
53− _targetCenter(0.5f, 0.5f, 0.5f) {
68+ _h(VERTICAL_ANGLE),
69+ _targetCenter(0.5f, 0.5f, 0.5f),
70+ _pressed(false),
71+ _mouseX(0),
72+ _mouseY(0) {
5473 }
5574
5675 void GLWidget::initializeGL() {
@@ -65,12 +84,15 @@ void GLWidget::initializeGL() { · 8 unmodified lines
6584
6685 }
6786
68−void GLWidget::resizeGL(int w, int h) {
69− glViewport(0, 0, w, h);
87+void GLWidget::resizeGL(int width, int height) {
88+ glViewport(0, 0, width, height);
7089
7190 glMatrixMode(GL_PROJECTION);
7291 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);
7496 }
7597
7698 void GLWidget::paintGL() {
@@ -80,10 +102,14 @@ void GLWidget::paintGL() { · 3 unmodified lines
80102 glMatrixMode(GL_MODELVIEW);
81103 glLoadIdentity();
82104
83− _a += ANGULAR_RATE;
84− gluLookAt(_targetCenter.x + (glm::length(_targetCenter) + 0.5f) * cos((double) _a),
85− _targetCenter.y * 1.25f,
86− _targetCenter.z + (glm::length(_targetCenter) + 0.5f) * sin((double) _a),
105+ if (!_pressed) {
106+ _a += ANGULAR_RATE;
107+ _h = (1.0f - RETURN_RATE) * _h + RETURN_RATE * VERTICAL_ANGLE;
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),
87113 _targetCenter.x, _targetCenter.y, _targetCenter.z,
88114 UP.x, UP.y, UP.z);
89115
@@ -102,7 +128,7 @@ void GLWidget::paintGL() { · 12 unmodified lines
102128
103129
104130 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);
106132 glVertex3d(0 , 2 * _targetCenter.y, 2 * _targetCenter.z);
107133
108134 glVertex3d(2 * _targetCenter.x, 2 * _targetCenter.y, 2 * _targetCenter.z);
@@ -116,18 +142,40 @@ void GLWidget::paintGL() { · 7 unmodified lines
116142 }
117143 }
118144
145+
146+void GLWidget::mousePressEvent(QMouseEvent* event) {
147+ _pressed = true;
148+ _mouseX = event->globalX();
149+ _mouseY = event->globalY();
150+}
151+
152+void 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+
161+void GLWidget::mouseReleaseEvent(QMouseEvent* event) {
162+ _pressed = false;
163+}
164+
119165 ImportDialog::ImportDialog(QWidget *parent, VoxelSystem* voxelSystem)
120166 : QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, IMPORT_FILE_TYPES),
121− _clipboardImportBox (IMPORT_TO_CLIPBOARD_CHECKBOX_STRING, this),
122− _previewBox (PREVIEW_CHECKBOX_STRING, this),
123− _previewBar (this),
124− _glPreview (new GLWidget(this, voxelSystem)) {
167+ _importButton (IMPORT_BUTTON_NAME, this),
168+ _clipboardImportBox(IMPORT_TO_CLIPBOARD_CHECKBOX_STRING, this),
169+ _previewBox (PREVIEW_CHECKBOX_STRING, this),
170+ _previewBar (this),
171+ _glPreview (new GLWidget(this, voxelSystem)) {
125172
126173 setOption(QFileDialog::DontUseNativeDialog, true);
127174 setFileMode(QFileDialog::ExistingFile);
128175 setViewMode(QFileDialog::Detail);
129176
130177 QGridLayout* gridLayout = (QGridLayout*) layout();
178+ gridLayout->addWidget(&_importButton , 2, 2);
131179 gridLayout->addWidget(&_clipboardImportBox, 2, 3);
132180 gridLayout->addWidget(&_previewBox , 3, 3);
133181 gridLayout->addWidget(&_previewBar , 0, 3);
@@ -138,43 +186,71 @@ ImportDialog::ImportDialog(QWidget *parent, VoxelSystem* voxelSystem) · 4 unmodified lines
138186 _previewBar.setRange(0, 100);
139187 _previewBar.setValue(0);
140188
189+ connect(&_importButton, SIGNAL(pressed()), SLOT(import()));
190+ connect(&_previewBox, SIGNAL(toggled(bool)), SIGNAL(previewToggled(bool)));
141191 connect(&_previewBox, SIGNAL(toggled(bool)), SLOT(preview(bool)));
192+
142193 connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString)));
143194 connect(&_glTimer, SIGNAL(timeout()), SLOT(timer()));
144195
145− connect(voxelSystem->getVoxelTree(), SIGNAL(importSize(float,float,float)), SLOT(setGLCamera(float, float, float)));
146− connect(voxelSystem->getVoxelTree(), SIGNAL(importProgress(int)), &_previewBar, SLOT(setValue(int)));
196+ connect(voxelSystem, SIGNAL(importSize(float,float,float)), SLOT(setGLCamera(float, float, float)));
197+ connect(voxelSystem, SIGNAL(importProgress(int)), &_previewBar, SLOT(setValue(int)));
147198 }
148199
149−int ImportDialog::exec() {
150− _previewBox.setChecked(false);
151− _previewBar.setVisible(false);
200+ImportDialog::~ImportDialog() {
201+ delete _glPreview;
202+}
152203
153− int ret = QFileDialog::exec();
204+void ImportDialog::import() {
205+ _importButton.setDisabled(true);
206+ _clipboardImportBox.setDisabled(true);
207+ _previewBox.setDisabled(true);
154208
209+ _previewBar.setValue(0);
210+ _previewBar.setVisible(true);
155211
156− ((GLWidget*) _glPreview)->setDraw(false);
157− _glTimer.stop();
158− _glPreview->updateGL();
212+ emit accepted();
213+}
214+
215+void ImportDialog::accept() {
216+ QFileDialog::accept();
217+}
218+
219+void ImportDialog::reject() {
220+ QFileDialog::reject();
221+}
222+
223+int ImportDialog::exec() {
224+ reset();
225+ int ret = QFileDialog::exec();
226+ preview(false);
159227
160228 return ret;
161229 }
162230
163231 void 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);
165233 }
166234
167235 void ImportDialog::reset() {
236+ _previewBox.setChecked(false);
237+ _previewBar.setVisible(false);
168238 _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();
169246 }
170247
171248 void ImportDialog::preview(bool wantPreview) {
172249 _previewBar.setValue(0);
173250 _previewBar.setVisible(wantPreview);
174− ((GLWidget*) _glPreview)->setDraw(wantPreview);
251+ _glPreview->setDraw(wantPreview);
175252
176253 if (wantPreview) {
177− emit previewActivated(_currentFile);
178254 _glTimer.start();
179255 } else {
180256 _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