From a662b818d343c13cca2f5925c6710e9a8fa98ba8 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Thu, 2 Feb 2012 13:52:52 +0100 Subject: [PATCH] Drag & Drop support. --- src/win_addJob.cpp | 2 +- src/win_addJob.h | 3 +++ src/win_main.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++-- src/win_main.h | 4 +++- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/win_addJob.cpp b/src/win_addJob.cpp index 6b53fb0..0147d85 100644 --- a/src/win_addJob.cpp +++ b/src/win_addJob.cpp @@ -335,7 +335,7 @@ void AddJobDialog::saveTemplateButtonClicked(void) forever { bool ok = false; - name = QInputDialog::getText(this, tr("Save Template"), tr("Please enter the name of the template:"), QLineEdit::Normal, name, &ok).simplified(); + name = QInputDialog::getText(this, tr("Save Template"), tr("Please enter the name of the template:").leftJustified(160, ' '), QLineEdit::Normal, name, &ok).simplified(); if(!ok) return; if(name.startsWith("<") || name.endsWith(">")) { diff --git a/src/win_addJob.h b/src/win_addJob.h index 12274ab..4c3e914 100644 --- a/src/win_addJob.h +++ b/src/win_addJob.h @@ -23,6 +23,8 @@ #include "uic_win_addJob.h" +#include + class OptionsModel; class AddJobDialog : public QDialog, private Ui::AddJobDialog @@ -41,6 +43,7 @@ public: QString params(void) { return editCustomParams->text().simplified(); } bool runImmediately(void) { return checkBoxRun->isChecked(); } void setRunImmediately(bool run) { checkBoxRun->setChecked(run); } + void setSourceFile(const QString &path) { editSource->setText(QDir::toNativeSeparators(path)); } protected: OptionsModel *m_options; diff --git a/src/win_main.cpp b/src/win_main.cpp index 40b6a1e..57afc59 100644 --- a/src/win_main.cpp +++ b/src/win_main.cpp @@ -140,10 +140,11 @@ MainWindow::~MainWindow(void) // Slots /////////////////////////////////////////////////////////////////////////////// -void MainWindow::addButtonPressed(void) +void MainWindow::addButtonPressed(const QString &filePath) { AddJobDialog *addDialog = new AddJobDialog(this, m_options); addDialog->setRunImmediately(!havePendingJobs()); + if(!filePath.isEmpty()) addDialog->setSourceFile(filePath); int result = addDialog->exec(); if(result == QDialog::Accepted) @@ -338,7 +339,7 @@ void MainWindow::init(void) } if(!binaryTypeOkay) { - QMessageBox::critical(this, tr("Invalid File!"), tr("At least on required tool is not a valid Win32 binary:
%1

Please re-install the program in order to fix the problem!
").arg(QDir::toNativeSeparators(QString("%1/toolset/%2").arg(m_appDir, current))).replace("-", "−")); + QMessageBox::critical(this, tr("Invalid File!"), tr("At least on required tool is not a valid Win32 or Win64 binary:
%1

Please re-install the program in order to fix the problem!
").arg(QDir::toNativeSeparators(QString("%1/toolset/%2").arg(m_appDir, current))).replace("-", "−")); qFatal(QString("Binary is invalid: %1/toolset/%2").arg(m_appDir, current).toLatin1().constData()); close(); qApp->exit(-1); return; } @@ -452,6 +453,48 @@ bool MainWindow::eventFilter(QObject *o, QEvent *e) return false; } +/* + * File dragged over window + */ +void MainWindow::dragEnterEvent(QDragEnterEvent *event) +{ + QStringList formats = event->mimeData()->formats(); + + if(formats.contains("application/x-qt-windows-mime;value=\"FileNameW\"", Qt::CaseInsensitive) && formats.contains("text/uri-list", Qt::CaseInsensitive)) + { + event->acceptProposedAction(); + } +} + +/* + * File dropped onto window + */ +void MainWindow::dropEvent(QDropEvent *event) +{ + QStringList droppedFiles; + QList urls = event->mimeData()->urls(); + + while(!urls.isEmpty()) + { + QUrl currentUrl = urls.takeFirst(); + QFileInfo file(currentUrl.toLocalFile()); + if(file.exists() && file.isFile()) + { + qDebug("Dropped File: %s", file.canonicalFilePath().toUtf8().constData()); + droppedFiles << file.canonicalFilePath(); + } + } + + droppedFiles.sort(); + + while(!droppedFiles.isEmpty()) + { + QString currentFile = droppedFiles.takeFirst(); + qDebug("Adding file: %s", currentFile.toUtf8().constData()); + addButtonPressed(currentFile); + } +} + /////////////////////////////////////////////////////////////////////////////// // Private functions /////////////////////////////////////////////////////////////////////////////// diff --git a/src/win_main.h b/src/win_main.h index 4e32bd4..fe829dc 100644 --- a/src/win_main.h +++ b/src/win_main.h @@ -41,6 +41,8 @@ protected: virtual void showEvent(QShowEvent *e); virtual void resizeEvent(QResizeEvent *e); virtual bool eventFilter(QObject *o, QEvent *e); + virtual void dragEnterEvent(QDragEnterEvent *event); + virtual void dropEvent(QDropEvent *event); private: bool m_firstShow; @@ -57,7 +59,7 @@ private: bool havePendingJobs(void); private slots: - void addButtonPressed(void); + void addButtonPressed(const QString &filePath = QString()); void abortButtonPressed(void); void copyLogToClipboard(bool checked); void init(void);