Skip to content

Commit

Permalink
Allow dropping of files onto window
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed Mar 27, 2014
1 parent d9301bb commit 5a38a2d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Window::Window(QWidget *parent) :

{
setWindowTitle("fstl");
setAcceptDrops(true);

QFile styleFile(":/qt/style.qss");
styleFile.open( QFile::ReadOnly );
Expand Down Expand Up @@ -128,3 +129,18 @@ bool Window::load_stl(const QString& filename)
loader->start();
return true;
}

void Window::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasUrls())
{
auto urls = event->mimeData()->urls();
if (urls.size() == 1 && urls.front().path().endsWith(".stl"))
event->acceptProposedAction();
}
}

void Window::dropEvent(QDropEvent *event)
{
load_stl(event->mimeData()->urls().front().toLocalFile());
}
4 changes: 4 additions & 0 deletions src/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class Window : public QMainWindow
explicit Window(QWidget* parent=0);
bool load_stl(const QString& filename);

protected:
void dragEnterEvent(QDragEnterEvent* event);
void dropEvent(QDropEvent* event);

public slots:
void on_open();
void on_about();
Expand Down

0 comments on commit 5a38a2d

Please sign in to comment.