NDEVR
API Documentation
FileDropFrame.h
1#pragma once
2#include <QFrame>
3#include <QMimeData>
4#include <QDragEnterEvent>
5#include <QDropEvent>
6namespace NDEVR
7{
11 class FileDropFrame : public QFrame
12 {
13 public:
18 FileDropFrame(QWidget* parent = nullptr)
19 : QFrame(parent)
20 {
21 setAcceptDrops(true);
22 }
23
27 void dragEnterEvent(QDragEnterEvent* event)
28 {
29 if(m_drop_filter == nullptr)
30 event->acceptProposedAction();
31 else if (m_drop_filter(event->mimeData()))
32 event->acceptProposedAction();
33 }
34
38 void dropEvent(QDropEvent* event)
39 {
41 m_drop_callback(event);
42 }
43
47 void setDropCallback(const std::function<void(QDropEvent* event)>& drop_callback)
48 {
49 m_drop_callback = drop_callback;
50 }
51
55 void setDropFilter(std::function<bool(const QMimeData* event)> filter)
56 {
57 m_drop_filter = filter;
58 }
59 protected:
60 std::function<void(QDropEvent* event)> m_drop_callback;
61 std::function<bool(const QMimeData* event)> m_drop_filter;
62 };
63}
void dragEnterEvent(QDragEnterEvent *event)
Handles drag enter events, accepting the drop if the filter allows it.
std::function< void(QDropEvent *event)> m_drop_callback
Callback invoked when a drop event occurs.
void setDropFilter(std::function< bool(const QMimeData *event)> filter)
Sets a filter function that determines whether a drag should be accepted.
void dropEvent(QDropEvent *event)
Handles drop events by invoking the registered drop callback.
FileDropFrame(QWidget *parent=nullptr)
Constructs a FileDropFrame.
std::function< bool(const QMimeData *event)> m_drop_filter
Filter function to accept or reject drag events.
void setDropCallback(const std::function< void(QDropEvent *event)> &drop_callback)
Sets the callback invoked when a file is dropped onto this frame.
The primary namespace for the NDEVR SDK.