API Documentation
Loading...
Searching...
No Matches
FileDropFrame.h
Go to the documentation of this file.
1#pragma once
2#include <QFrame>
3#include <QMimeData>
4#include <QDragEnterEvent>
5#include <QDropEvent>
6namespace NDEVR
7{
8 /**--------------------------------------------------------------------------------------------------
9 \brief A simple frame that allows the user to drag and drop a file into it.
10 **/
11 class FileDropFrame : public QFrame
12 {
13 public:
14 FileDropFrame(QWidget* parent = nullptr)
15 : QFrame(parent)
16 {
17 setAcceptDrops(true);
18 }
19 void dragEnterEvent(QDragEnterEvent* event)
20 {
21 if(m_drop_filter == nullptr)
22 event->acceptProposedAction();
23 else if (m_drop_filter(event->mimeData()))
24 event->acceptProposedAction();
25 }
26 void dropEvent(QDropEvent* event)
27 {
29 m_drop_callback(event);
30 }
31 void setDropCallback(const std::function<void(QDropEvent* event)>& drop_callback)
32 {
33 m_drop_callback = drop_callback;
34 }
35 void setDropFilter(std::function<bool(const QMimeData* event)> filter)
36 {
37 m_drop_filter = filter;
38 }
39 protected:
40 std::function<void(QDropEvent* event)> m_drop_callback;
41 std::function<bool(const QMimeData* event)> m_drop_filter;
42 };
43}
A simple frame that allows the user to drag and drop a file into it.
Definition FileDropFrame.h:12
std::function< bool(const QMimeData *event)> m_drop_filter
Definition FileDropFrame.h:41
void dropEvent(QDropEvent *event)
Definition FileDropFrame.h:26
void setDropCallback(const std::function< void(QDropEvent *event)> &drop_callback)
Definition FileDropFrame.h:31
void dragEnterEvent(QDragEnterEvent *event)
Definition FileDropFrame.h:19
void setDropFilter(std::function< bool(const QMimeData *event)> filter)
Definition FileDropFrame.h:35
FileDropFrame(QWidget *parent=nullptr)
Definition FileDropFrame.h:14
std::function< void(QDropEvent *event)> m_drop_callback
Definition FileDropFrame.h:40
Definition ACIColor.h:37