added Drag & Drop support
This commit is contained in:
parent
740c0ee7d8
commit
fa4f40a1f8
|
@ -37,6 +37,7 @@
|
|||
#include <QFileSystemModel>
|
||||
#include <QCompleter>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QMimeData>
|
||||
#include <QTextStream>
|
||||
#include <QWebFrame>
|
||||
#include <QWebPage>
|
||||
|
@ -129,7 +130,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
// other widgets
|
||||
updateUiStatus();
|
||||
m_ui->abortButton->setVisible(false);
|
||||
// connect signals and slots
|
||||
// connect signals and slots, install event filter
|
||||
// menu: application
|
||||
connect(m_ui->actionSettings, &QAction::triggered, this, &MainWindow::showSettingsDlg);
|
||||
connect(m_ui->actionQuit, &QAction::triggered, this, &MainWindow::close);
|
||||
|
@ -156,6 +157,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
connect(m_ui->selectNextCommandLinkButton, &QCommandLinkButton::clicked, this, &MainWindow::selectNextFile);
|
||||
connect(m_ui->abortButton, &QPushButton::clicked, [this] {m_abortClicked = true; m_ui->abortButton->setEnabled(false); });
|
||||
connect(m_ui->tagSelectionComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), m_ui->stackedWidget, &QStackedWidget::setCurrentIndex);
|
||||
// event filter
|
||||
m_ui->fileNameLabel->installEventFilter(this);
|
||||
m_ui->rightWidget->installEventFilter(this);
|
||||
// apply settings
|
||||
setCurrentDirectory(Settings::mainWindowCurrentFileBrowserDirectory());
|
||||
applySettingsFromDialog();
|
||||
|
@ -195,6 +199,38 @@ void MainWindow::closeEvent(QCloseEvent *)
|
|||
Settings::mainWindowCurrentFileBrowserDirectory() = currentDirectory();
|
||||
}
|
||||
|
||||
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if(obj == m_ui->rightWidget || obj == m_ui->fileNameLabel) {
|
||||
switch(event->type()) {
|
||||
case QEvent::DragEnter:
|
||||
case QEvent::Drop:
|
||||
if(QDropEvent *dropEvent = static_cast<QDropEvent *>(event)) {
|
||||
QString data;
|
||||
const QMimeData *mimeData = dropEvent->mimeData();
|
||||
if(mimeData->hasUrls()) {
|
||||
const QUrl url = mimeData->urls().front();
|
||||
if(url.scheme() == QLatin1String("file")) {
|
||||
data = url.path();
|
||||
}
|
||||
} else if(mimeData->hasText()) {
|
||||
data = mimeData->text();
|
||||
}
|
||||
if(!data.isEmpty()) {
|
||||
event->accept();
|
||||
if(event->type() == QEvent::Drop) {
|
||||
showFile(data, true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief This private slot is called when the entered text of m_ui->pathLineEdit which represents the current directory changes.
|
||||
* If the text is a valid path the current index of the m_ui->filesTreeView is updated to show the path. This invokes the file
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent *);
|
||||
virtual bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
private slots:
|
||||
// file selection
|
||||
|
|
|
@ -79,6 +79,9 @@
|
|||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="rightWidget" native="true">
|
||||
<property name="acceptDrops">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<property name="spacing">
|
||||
<number>3</number>
|
||||
|
@ -91,6 +94,9 @@
|
|||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="fileNameLabel">
|
||||
<property name="acceptDrops">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>No file selected</string>
|
||||
</property>
|
||||
|
@ -104,7 +110,11 @@
|
|||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<widget class="QWebView" name="infoWebView"/>
|
||||
<widget class="QWebView" name="infoWebView">
|
||||
<property name="acceptDrops">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<layout class="QVBoxLayout" name="tagEditVerticalLayout">
|
||||
<item>
|
||||
|
@ -314,7 +324,7 @@ the file reverting all unsaved changings.</string>
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1225</width>
|
||||
<height>23</height>
|
||||
<height>29</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
|
|
Loading…
Reference in New Issue