Drag & Drop support.

This commit is contained in:
LoRd_MuldeR 2012-02-02 13:52:52 +01:00
parent 4ce96f7e23
commit a662b818d3
4 changed files with 52 additions and 4 deletions

View File

@ -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(">"))
{

View File

@ -23,6 +23,8 @@
#include "uic_win_addJob.h"
#include <QDir>
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;

View File

@ -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("<nobr>At least on required tool is not a valid Win32 binary:<br>%1<br><br>Please re-install the program in order to fix the problem!</nobr>").arg(QDir::toNativeSeparators(QString("%1/toolset/%2").arg(m_appDir, current))).replace("-", "&minus;"));
QMessageBox::critical(this, tr("Invalid File!"), tr("<nobr>At least on required tool is not a valid Win32 or Win64 binary:<br>%1<br><br>Please re-install the program in order to fix the problem!</nobr>").arg(QDir::toNativeSeparators(QString("%1/toolset/%2").arg(m_appDir, current))).replace("-", "&minus;"));
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<QUrl> 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
///////////////////////////////////////////////////////////////////////////////

View File

@ -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);