0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 00:31:02 +08:00

GUI: Added drag and drop of files into GUI window. NOTICE: You have to launch gui NOT as Administrator on Windows, otherwise Windows will block drag and drops from explorer.

This commit is contained in:
Victor Zarubkin 2016-11-19 05:39:41 +03:00
parent 65be64fb51
commit 141b0f99a4
4 changed files with 42 additions and 0 deletions

View File

@ -148,6 +148,8 @@ public:
void keyReleaseEvent(QKeyEvent* _event) override;
void resizeEvent(QResizeEvent* _event) override;
void dragEnterEvent(QDragEnterEvent*) override {}
public:
// Public non-virtual methods
@ -262,6 +264,8 @@ public:
void keyPressEvent(QKeyEvent* _event) override;
void keyReleaseEvent(QKeyEvent* _event) override;
void dragEnterEvent(QDragEnterEvent*) override {}
void clear();
const EasyGraphicsView* view() const

View File

@ -155,6 +155,8 @@ public:
void resizeEvent(QResizeEvent* _event) override;
void contextMenuEvent(QContextMenuEvent* _event) override;
void dragEnterEvent(QDragEnterEvent*) override {}
public:
// Public non-virtual methods

View File

@ -76,6 +76,11 @@
#include <QDialog>
#include <QVBoxLayout>
#include <QFile>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QDragLeaveEvent>
#include <QDropEvent>
#include <QMimeData>
#include "main_window.h"
#include "blocks_tree_widget.h"
@ -119,6 +124,7 @@ EasyMainWindow::EasyMainWindow() : Parent(), m_lastAddress("127.0.0.1"), m_lastP
setObjectName("ProfilerGUI_MainWindow");
setWindowTitle("EasyProfiler");
setDockNestingEnabled(true);
setAcceptDrops(true);
resize(800, 600);
setStatusBar(new QStatusBar());
@ -431,6 +437,32 @@ EasyMainWindow::~EasyMainWindow()
//////////////////////////////////////////////////////////////////////////
void EasyMainWindow::dragEnterEvent(QDragEnterEvent* drag_event)
{
if (drag_event->mimeData()->hasUrls())
drag_event->acceptProposedAction();
}
void EasyMainWindow::dragMoveEvent(QDragMoveEvent* drag_event)
{
if (drag_event->mimeData()->hasUrls())
drag_event->acceptProposedAction();
}
void EasyMainWindow::dragLeaveEvent(QDragLeaveEvent* drag_event)
{
drag_event->accept();
}
void EasyMainWindow::dropEvent(QDropEvent* drop_event)
{
const auto& urls = drop_event->mimeData()->urls();
if (!urls.empty())
loadFile(urls.front().toLocalFile());
}
//////////////////////////////////////////////////////////////////////////
void EasyMainWindow::onOpenFileClicked(bool)
{
auto filename = QFileDialog::getOpenFileName(this, "Open profiler log", m_lastFile, "Profiler Log File (*.prof);;All Files (*.*)");

View File

@ -216,6 +216,10 @@ public:
// Public virtual methods
void closeEvent(QCloseEvent* close_event) override;
void dragEnterEvent(QDragEnterEvent* drag_event) override;
void dragMoveEvent(QDragMoveEvent* drag_event) override;
void dragLeaveEvent(QDragLeaveEvent* drag_event) override;
void dropEvent(QDropEvent* drop_event) override;
protected slots: