Skip to content

Commit 07d06f0

Browse files
JensAhrensmgeier
authored andcommitted
Add drag & drop of scene files to GUI
1 parent 2f48cdc commit 07d06f0

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

doc/manual/gui.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ positioning of sources. The properties ``fixed position``, ``muted`` and
245245
:ref:`4.3 <source_picture>` to see the complete list of properties
246246
this dialog shows.
247247

248+
Drag & Drop of Scenes
249+
~~~~~~~~~~~~~~~~~~~~~
250+
251+
You can also drag & drop scenes (or audio files) into the GUI to open them. Currently, you can only drag & drop one single file.
252+
253+
248254
.. _keyboard_actions:
249255

250256
Keyboard Actions

src/gui/qopenglplotter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ ssr::QOpenGLPlotter::QOpenGLPlotter(api::Publisher& controller
9595
Qt::NoModifier)), // dummy event
9696
_ctrl_pressed(false),
9797
_alt_pressed(false),
98+
_shift_pressed(false),
9899
_rubber_band_starting_point(Position()),
99100
_rubber_band_ending_point(Position()),
100101
_window_x_offset(0.0f),

src/gui/qopenglplotter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class QOpenGLPlotter : public QGLWidget
153153
QMouseEvent _previous_mouse_event;
154154
bool _ctrl_pressed;
155155
bool _alt_pressed;
156+
bool _shift_pressed;
156157

157158
int _find_selected_object(const QPoint &pos);
158159
void _get_openGL_pos(int x, int y,

src/gui/quserinterface.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <QtWidgets/QMenu>
4141
#include <QtWidgets/QMessageBox>
4242
#include <QtWidgets/QVBoxLayout>
43+
#include <QMimeData>
4344

4445
#include "quserinterface.h"
4546
#include "apf/math.h"
@@ -119,6 +120,9 @@ ssr::QUserInterface::QUserInterface(api::Publisher& controller
119120
// TODO: use screen size for initial window positions
120121
//QRect screenSize = QApplication::desktop()->screenGeometry();
121122
setGeometry(200, 70, 900, 700);
123+
124+
setAcceptDrops(true);
125+
122126
_controlsParent = new QLabel(this, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
123127
_controlsParent->setFixedSize(900, 75);
124128
_controlsParent->move(200, 780);
@@ -1191,6 +1195,7 @@ void ssr::QUserInterface::keyPressEvent(QKeyEvent *event)
11911195
break;
11921196
case Qt::Key_Return: {_controller.take_control()->calibrate_tracker(); break; }
11931197
case Qt::Key_Control: {_ctrl_pressed = true; break; }
1198+
case Qt::Key_Shift: {_shift_pressed = true; break; }
11941199
case Qt::Key_Alt: {_alt_pressed = true; break; }
11951200
case Qt::Key_F11: {if (!isFullScreen()) setWindowState(Qt::WindowFullScreen);
11961201
else setWindowState( Qt::WindowNoState );} break;
@@ -1210,6 +1215,7 @@ void ssr::QUserInterface::keyReleaseEvent(QKeyEvent *event)
12101215
switch (event->key()){
12111216
case Qt::Key_Control: {_ctrl_pressed = false; break; }
12121217
case Qt::Key_Alt: {_alt_pressed = false; break; }
1218+
case Qt::Key_Shift: {_shift_pressed = false; break; }
12131219
default: ;
12141220
}
12151221
}
@@ -1226,6 +1232,52 @@ void ssr::QUserInterface::wheelEvent(QWheelEvent *event)
12261232
(100.0f+event->delta()/100.f*5.0f) + 0.5f));
12271233
}
12281234

1235+
/** Handles Qt drag & drop events.
1236+
* @param event Qt mouse drag enter event.
1237+
*/
1238+
void ssr::QUserInterface::dragEnterEvent(QDragEnterEvent *event)
1239+
{
1240+
// make sure that the drag event contains file paths
1241+
if (event->mimeData()->hasUrls()) event->acceptProposedAction();
1242+
//if (event->mimeData()->hasFormat("text/plain"))
1243+
// event->acceptProposedAction();
1244+
}
1245+
1246+
/** Handles Qt drag & drop events.
1247+
* @param event Qt mouse drop event.
1248+
*/
1249+
void ssr::QUserInterface::dropEvent(QDropEvent *event)
1250+
{
1251+
event->acceptProposedAction();
1252+
1253+
const QMimeData* mimeData = event->mimeData();
1254+
1255+
// check for our needed mime type, here a file or a list of files
1256+
if (mimeData->hasUrls())
1257+
{
1258+
QList<QUrl> urlList = mimeData->urls();
1259+
1260+
QUrl url(urlList.at(0));
1261+
1262+
VERBOSE("Dropped file: " <<
1263+
std::string(url.toString().toStdString()));
1264+
1265+
// Remove "file://"
1266+
//this->_load_scene(url.toString().toStdString().substr(7));
1267+
this->_load_scene(url.toString().remove(0,7));
1268+
1269+
// TODO: Add source if more than one file is dragged and dropped.
1270+
//QStringList pathList;
1271+
// for (int i = 0; i < urlList.size() && i < 32; +i)
1272+
//{
1273+
// pathList.append(urlList.at(i).toLocalFile());
1274+
//}
1275+
// call a function to open all files (needs function is yet to be written)
1276+
//openFiles(pathList);
1277+
1278+
}
1279+
}
1280+
12291281
/// Displays the about window.
12301282
void ssr::QUserInterface::_show_about_window()
12311283
{

src/gui/quserinterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class QUserInterface : public QOpenGLPlotter
101101
virtual void mouseDoubleClickEvent(QMouseEvent *event);
102102
virtual void mouseReleaseEvent (QMouseEvent *event);
103103
virtual void wheelEvent(QWheelEvent * event);
104+
virtual void dragEnterEvent(QDragEnterEvent *event);
105+
virtual void dropEvent(QDropEvent *event);
104106

105107
private:
106108
scene_button_list_t _scene_button_list; ///< list which holds all quiack access scene tabs

0 commit comments

Comments
 (0)