NOISSUE add pack import using drag&drop

Straight from the browser or the downloads folder.
This commit is contained in:
Petr Mrázek 2017-04-22 06:11:26 +02:00
parent 77a1d39f6b
commit 30863a88ab
6 changed files with 73 additions and 24 deletions

View File

@ -449,6 +449,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
view->installEventFilter(this);
view->setContextMenuPolicy(Qt::CustomContextMenu);
connect(view, &QWidget::customContextMenuRequested, this, &MainWindow::showInstanceContextMenu);
connect(view, &GroupView::droppedURLs, this, &MainWindow::droppedURLs);
proxymodel = new InstanceProxyModel(this);
proxymodel->setSourceModel(MMC->instances().get());
@ -1076,7 +1077,7 @@ void MainWindow::finalizeInstance(InstancePtr inst)
}
}
void MainWindow::on_actionAddInstance_triggered()
void MainWindow::addInstance(QString url)
{
QString groupName;
do
@ -1098,7 +1099,7 @@ void MainWindow::on_actionAddInstance_triggered()
groupName = MMC->settings()->get("LastUsedGroupForNewInstance").toString();
}
NewInstanceDialog newInstDlg(groupName, this);
NewInstanceDialog newInstDlg(groupName, url, this);
if (!newInstDlg.exec())
return;
@ -1116,6 +1117,28 @@ void MainWindow::on_actionAddInstance_triggered()
}
}
void MainWindow::on_actionAddInstance_triggered()
{
addInstance();
}
void MainWindow::droppedURLs(QList<QUrl> urls)
{
for(auto & url:urls)
{
if(url.isLocalFile())
{
addInstance(url.toLocalFile());
}
else
{
addInstance(url.toString());
}
// Only process one dropped file...
break;
}
}
void MainWindow::on_actionREDDIT_triggered()
{
DesktopServices::openUrl(QUrl("https://www.reddit.com/r/MultiMC/"));

View File

@ -161,7 +161,10 @@ private slots:
*/
void downloadUpdates(GoUpdate::Status status);
void droppedURLs(QList<QUrl> urls);
private:
void addInstance(QString url = QString());
void activateInstance(InstancePtr instance);
void setCatBackground(bool enabled);
void updateInstanceToolIcon(QString new_icon);

View File

@ -57,7 +57,7 @@ public:
}
};
NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, QWidget *parent)
NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString & url, QWidget *parent)
: QDialog(parent), ui(new Ui::NewInstanceDialog)
{
ui->setupUi(this);
@ -112,6 +112,11 @@ NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, QWidget *pare
ui->buttonBox->setFocus();
originalPlaceholderText = ui->instNameTextBox->placeholderText();
if(!url.isEmpty())
{
ui->modpackBox->setChecked(true);
ui->modpackEdit->setText(url);
}
updateDialogState();
}

View File

@ -29,7 +29,7 @@ class NewInstanceDialog : public QDialog
Q_OBJECT
public:
explicit NewInstanceDialog(const QString & initialGroup, QWidget *parent = 0);
explicit NewInstanceDialog(const QString & initialGroup, const QString & url = QString(), QWidget *parent = 0);
~NewInstanceDialog();
void updateDialogState();

View File

@ -534,31 +534,46 @@ void GroupView::dropEvent(QDropEvent *event)
stopAutoScroll();
setState(NoState);
if (event->source() != this || !(event->possibleActions() & Qt::MoveAction))
if (event->source() == this)
{
if(event->possibleActions() & Qt::MoveAction)
{
QPair<VisualGroup *, int> dropPos = rowDropPos(event->pos() + offset());
const VisualGroup *category = dropPos.first;
const int row = dropPos.second;
if (row == -1)
{
viewport()->update();
return;
}
const QString categoryText = category->text;
if (model()->dropMimeData(event->mimeData(), Qt::MoveAction, row, 0, QModelIndex()))
{
model()->setData(model()->index(row, 0), categoryText,
GroupViewRoles::GroupRole);
event->setDropAction(Qt::MoveAction);
event->accept();
}
updateGeometries();
viewport()->update();
}
}
auto mimedata = event->mimeData();
// check if the action is supported
if (!mimedata)
{
return;
}
QPair<VisualGroup *, int> dropPos = rowDropPos(event->pos() + offset());
const VisualGroup *category = dropPos.first;
const int row = dropPos.second;
if (row == -1)
// files dropped from outside?
if (mimedata->hasUrls())
{
viewport()->update();
return;
auto urls = mimedata->urls();
emit droppedURLs(urls);
}
const QString categoryText = category->text;
if (model()->dropMimeData(event->mimeData(), Qt::MoveAction, row, 0, QModelIndex()))
{
model()->setData(model()->index(row, 0), categoryText,
GroupViewRoles::GroupRole);
event->setDropAction(Qt::MoveAction);
event->accept();
}
updateGeometries();
viewport()->update();
}
void GroupView::startDrag(Qt::DropActions supportedActions)
@ -707,7 +722,7 @@ QList<QPair<QRect, QModelIndex>> GroupView::draggablePaintPairs(const QModelInde
bool GroupView::isDragEventAccepted(QDropEvent *event)
{
return false;
return true;
}
QPair<VisualGroup *, int> GroupView::rowDropPos(const QPoint &pos)

View File

@ -62,6 +62,9 @@ protected slots:
void modelReset();
void rowsRemoved();
signals:
void droppedURLs(QList<QUrl> urls);
protected:
virtual bool isIndexHidden(const QModelIndex &index) const override;
void mousePressEvent(QMouseEvent *event) override;