summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/MainWindow.cpp26
-rw-r--r--application/MainWindow.h8
-rw-r--r--application/groupview/GroupView.cpp91
-rw-r--r--application/groupview/GroupView.h8
4 files changed, 25 insertions, 108 deletions
diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp
index b50d0160..c7626e54 100644
--- a/application/MainWindow.cpp
+++ b/application/MainWindow.cpp
@@ -1041,7 +1041,7 @@ void MainWindow::waitForMinecraftVersions()
}
}
-void MainWindow::instanceFromZipPack(QString instName, QString instGroup, QString instIcon, QUrl url)
+InstancePtr MainWindow::instanceFromZipPack(QString instName, QString instGroup, QString instIcon, QUrl url)
{
InstancePtr newInstance;
@@ -1067,7 +1067,7 @@ void MainWindow::instanceFromZipPack(QString instName, QString instGroup, QStrin
ProgressDialog dlDialog(this);
if (dlDialog.exec(&job) != QDialog::Accepted)
{
- return;
+ return nullptr;
}
archivePath = entry->getFullPath();
}
@@ -1079,18 +1079,18 @@ void MainWindow::instanceFromZipPack(QString instName, QString instGroup, QStrin
{
CustomMessageBox::selectable(this, tr("Error"),
tr("Failed to extract modpack"), QMessageBox::Warning)->show();
- return;
+ return nullptr;
}
const QFileInfo instanceCfgFile = findRecursive(extractDir.absolutePath(), "instance.cfg");
if (!instanceCfgFile.isFile() || !instanceCfgFile.exists())
{
CustomMessageBox::selectable(this, tr("Error"), tr("Archive does not contain instance.cfg"))->show();
- return;
+ return nullptr;
}
if (!copyPath(instanceCfgFile.absoluteDir().absolutePath(), instDir))
{
CustomMessageBox::selectable(this, tr("Error"), tr("Unable to copy instance"))->show();
- return;
+ return nullptr;
}
auto error = MMC->instances()->loadInstance(newInstance, instDir);
@@ -1100,11 +1100,11 @@ void MainWindow::instanceFromZipPack(QString instName, QString instGroup, QStrin
case InstanceList::UnknownLoadError:
errorMsg += tr("Unkown error");
CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show();
- return;
+ return nullptr;
case InstanceList::NotAnInstance:
errorMsg += tr("Not an instance");
CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show();
- return;
+ return nullptr;
default:
break;
}
@@ -1136,9 +1136,10 @@ void MainWindow::instanceFromZipPack(QString instName, QString instGroup, QStrin
MMC->instances()->saveGroupList();
finalizeInstance(newInstance);
+ return newInstance;
}
-void MainWindow::instanceFromVersion(QString instName, QString instGroup, QString instIcon, BaseVersionPtr version)
+InstancePtr MainWindow::instanceFromVersion(QString instName, QString instGroup, QString instIcon, BaseVersionPtr version)
{
InstancePtr newInstance;
@@ -1156,21 +1157,21 @@ void MainWindow::instanceFromVersion(QString instName, QString instGroup, QStrin
{
errorMsg += tr("An instance with the given directory name already exists.");
CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show();
- return;
+ return nullptr;
}
case InstanceList::CantCreateDir:
{
errorMsg += tr("Failed to create the instance directory.");
CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show();
- return;
+ return nullptr;
}
default:
{
errorMsg += tr("Unknown instance loader error %1").arg(error);
CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show();
- return;
+ return nullptr;
}
}
newInstance->setName(instName);
@@ -1179,10 +1180,13 @@ void MainWindow::instanceFromVersion(QString instName, QString instGroup, QStrin
MMC->instances()->add(InstancePtr(newInstance));
MMC->instances()->saveGroupList();
finalizeInstance(newInstance);
+ return newInstance;
}
void MainWindow::finalizeInstance(InstancePtr inst)
{
+ view->updateGeometries();
+ setSelectedInstanceById(inst->id());
if (MMC->accounts()->anyAccountIsValid())
{
ProgressDialog loadDialog(this);
diff --git a/application/MainWindow.h b/application/MainWindow.h
index 7ef277db..639405c0 100644
--- a/application/MainWindow.h
+++ b/application/MainWindow.h
@@ -57,6 +57,8 @@ public:
private
slots:
+ void setSelectedInstanceById(const QString &id);
+
void onCatToggled(bool);
void on_actionAbout_triggered();
@@ -162,11 +164,9 @@ protected:
void setCatBackground(bool enabled);
void updateInstanceToolIcon(QString new_icon);
- void setSelectedInstanceById(const QString &id);
-
void waitForMinecraftVersions();
- void instanceFromVersion(QString instName, QString instGroup, QString instIcon, BaseVersionPtr version);
- void instanceFromZipPack(QString instName, QString instGroup, QString instIcon, QUrl url);
+ InstancePtr instanceFromVersion(QString instName, QString instGroup, QString instIcon, BaseVersionPtr version);
+ InstancePtr instanceFromZipPack(QString instName, QString instGroup, QString instIcon, QUrl url);
void finalizeInstance(InstancePtr inst);
void launch(InstancePtr instance, bool online = true, BaseProfilerFactory *profiler = nullptr);
diff --git a/application/groupview/GroupView.cpp b/application/groupview/GroupView.cpp
index 89694b87..ab9e71cf 100644
--- a/application/groupview/GroupView.cpp
+++ b/application/groupview/GroupView.cpp
@@ -221,7 +221,7 @@ void GroupView::mousePressEvent(QMouseEvent *event)
QPoint visualPos = event->pos();
QPoint geometryPos = event->pos() + offset();
-
+
QPersistentModelIndex index = indexAt(visualPos);
m_pressedIndex = index;
@@ -697,95 +697,6 @@ bool GroupView::isDragEventAccepted(QDropEvent *event)
QPair<VisualGroup *, int> GroupView::rowDropPos(const QPoint &pos)
{
return qMakePair<VisualGroup*, int>(nullptr, -1);
- // FIXME: PIXIE DUST.
- /*
- // check that we aren't on a category header and calculate which category we're in
- VisualGroup *category = 0;
- {
- int y = 0;
- for (auto cat : m_groups)
- {
- if (pos.y() > y && pos.y() < (y + cat->headerHeight()))
- {
- return qMakePair<VisualGroup*, int>(nullptr, -1);
- }
- y += cat->totalHeight() + m_categoryMargin;
- if (pos.y() < y)
- {
- category = cat;
- break;
- }
- }
- if (category == 0)
- {
- return qMakePair<VisualGroup*, int>(nullptr, -1);
- }
- }
-
- QList<QModelIndex> indices = category->items();
-
- // calculate the internal column
- int internalColumn = -1;
- {
- const int itemWidth = this->itemWidth();
- if (pos.x() >= (itemWidth * itemsPerRow()))
- {
- internalColumn = itemsPerRow();
- }
- else
- {
- for (int i = 0, c = 0; i < contentWidth(); i += itemWidth + 10 , ++c)
- {
- if (pos.x() > (i - itemWidth / 2) && pos.x() <= (i + itemWidth / 2))
- {
- internalColumn = c;
- break;
- }
- }
- }
- if (internalColumn == -1)
- {
- return qMakePair<VisualGroup*, int>(nullptr, -1);
- }
- }
-
- // calculate the internal row
- int internalRow = -1;
- {
- // FIXME rework the drag and drop code
- const int top = category->verticalPosition();
- for (int r = 0, h = top; r < category->numRows();
- h += itemHeightForCategoryRow(category, r), ++r)
- {
- if (pos.y() > h && pos.y() < (h + itemHeightForCategoryRow(category, r)))
- {
- internalRow = r;
- break;
- }
- }
- if (internalRow == -1)
- {
- return qMakePair<VisualGroup*, int>(nullptr, -1);
- }
- // this happens if we're in the margin between a one category and another
- // categories header
- if (internalRow > (indices.size() / itemsPerRow()))
- {
- return qMakePair<VisualGroup*, int>(nullptr, -1);
- }
- }
-
- // flaten the internalColumn/internalRow to one row
- int categoryRow = internalRow * itemsPerRow() + internalColumn;
-
- // this is used if we're past the last item
- if (categoryRow >= indices.size())
- {
- return qMakePair(category, indices.last().row() + 1);
- }
-
- return qMakePair(category, indices.at(categoryRow).row());
- */
}
QPoint GroupView::offset() const
diff --git a/application/groupview/GroupView.h b/application/groupview/GroupView.h
index 93e45ed7..b97d3a3c 100644
--- a/application/groupview/GroupView.h
+++ b/application/groupview/GroupView.h
@@ -50,13 +50,15 @@ public:
{
return m_spacing;
};
-protected
-slots:
+
+public slots:
+ virtual void updateGeometries() override;
+
+protected slots:
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
const QVector<int> &roles) override;
virtual void rowsInserted(const QModelIndex &parent, int start, int end) override;
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override;
- virtual void updateGeometries() override;
void modelReset();
protected: