summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorJanrupf <werbung.janrupf@t-online.de>2018-03-03 21:22:00 +0100
committerJanrupf <werbung.janrupf@t-online.de>2018-03-11 19:30:47 +0100
commitb8ca36372be11b9ddddb3daa3d32583d286f19e2 (patch)
treeb359357881d14e0b0871b3e5d0175234eb562b72 /application
parent2d295d5afbf6cb5ce1ca624c4aef8fd96b78992b (diff)
downloadMultiMC-b8ca36372be11b9ddddb3daa3d32583d286f19e2.tar
MultiMC-b8ca36372be11b9ddddb3daa3d32583d286f19e2.tar.gz
MultiMC-b8ca36372be11b9ddddb3daa3d32583d286f19e2.tar.lz
MultiMC-b8ca36372be11b9ddddb3daa3d32583d286f19e2.tar.xz
MultiMC-b8ca36372be11b9ddddb3daa3d32583d286f19e2.zip
GH-2124 First complete implementation, installing is working now! GH-2172 Added sorting
Diffstat (limited to 'application')
-rw-r--r--application/CMakeLists.txt10
-rw-r--r--application/FtbListModel.cpp138
-rw-r--r--application/FtbListModel.h45
-rw-r--r--application/dialogs/ChooseFtbPackDialog.cpp54
-rw-r--r--application/dialogs/ChooseFtbPackDialog.h7
-rw-r--r--application/dialogs/ChooseFtbPackDialog.ui170
-rw-r--r--application/widgets/FtbModpackListItem.cpp8
-rw-r--r--application/widgets/FtbModpackListItem.h15
8 files changed, 295 insertions, 152 deletions
diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt
index da9a42c6..148b6d9f 100644
--- a/application/CMakeLists.txt
+++ b/application/CMakeLists.txt
@@ -25,6 +25,8 @@ SET(MULTIMC_SOURCES
InstanceProxyModel.cpp
VersionProxyModel.h
VersionProxyModel.cpp
+ FtbListModel.h
+ FtbListModel.cpp
ColorCache.h
ColorCache.cpp
HoeDown.h
@@ -153,8 +155,8 @@ SET(MULTIMC_SOURCES
dialogs/VersionSelectDialog.h
dialogs/SkinUploadDialog.cpp
dialogs/SkinUploadDialog.h
- dialogs/ChooseFtbPackDialog.cpp
- dialogs/ChooseFtbPackDialog.h
+ dialogs/ChooseFtbPackDialog.cpp
+ dialogs/ChooseFtbPackDialog.h
# GUI - widgets
@@ -189,8 +191,6 @@ SET(MULTIMC_SOURCES
widgets/VersionSelectWidget.h
widgets/ProgressWidget.h
widgets/ProgressWidget.cpp
- widgets/FtbModpackListItem.h
- widgets/FtbModpackListItem.cpp
# GUI - instance group view
groupview/GroupedProxyModel.cpp
@@ -240,7 +240,7 @@ SET(MULTIMC_UIS
dialogs/UpdateDialog.ui
dialogs/NotificationDialog.ui
dialogs/SkinUploadDialog.ui
- dialogs/ChooseFtbPackDialog.ui
+ dialogs/ChooseFtbPackDialog.ui
# Widgets/other
widgets/CustomCommands.ui
diff --git a/application/FtbListModel.cpp b/application/FtbListModel.cpp
new file mode 100644
index 00000000..290767ff
--- /dev/null
+++ b/application/FtbListModel.cpp
@@ -0,0 +1,138 @@
+#include "FtbListModel.h"
+#include "MultiMC.h"
+
+#include <MMCStrings.h>
+
+#include <QtMath>
+
+FtbFilterModel::FtbFilterModel(QObject *parent) : QSortFilterProxyModel(parent)
+{
+ currentSorting = Sorting::ByGameVersion;
+ sortings.insert("Sort by name", Sorting::ByName);
+ sortings.insert("Sort by game version", Sorting::ByGameVersion);
+}
+
+bool FtbFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
+{
+ FtbModpack leftPack = sourceModel()->data(left, Qt::UserRole).value<FtbModpack>();
+ FtbModpack rightPack = sourceModel()->data(right, Qt::UserRole).value<FtbModpack>();
+
+ if(currentSorting == Sorting::ByGameVersion) {
+ QStringList leftList = leftPack.mcVersion.split(".");
+ QStringList rightList = rightPack.mcVersion.split(".");
+
+ if(leftList.size() < 1) {
+ return true;
+ } else if(rightList.size() < 1) {
+ return false;
+ } else {
+ for(int i = 0; i < qMax(leftList.size(), rightList.size()); i++) {
+ if(leftList.size() -1 < i) {
+ return true;
+ }
+
+ if(rightList.size() -1 < i) {
+ return false;
+ }
+
+ int leftV = leftList.at(i).toInt();
+ int rightV = rightList.at(i).toInt();
+
+ if(leftV != rightV) {
+ return leftV < rightV;
+ }
+
+ }
+ return false;
+ }
+
+ } else if(currentSorting == Sorting::ByName) {
+ return Strings::naturalCompare(leftPack.name, rightPack.name, Qt::CaseSensitive) >= 0;
+ }
+
+ //UHM, some inavlid value set?!
+ qWarning() << "Invalid sorting set!";
+ return true;
+}
+
+bool FtbFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
+{
+ return true;
+}
+
+const QMap<QString, FtbFilterModel::Sorting> FtbFilterModel::getAvailableSortings()
+{
+ return sortings;
+}
+
+void FtbFilterModel::setSorting(Sorting s)
+{
+ currentSorting = s;
+ invalidate();
+}
+
+FtbFilterModel::Sorting FtbFilterModel::getCurrentSorting()
+{
+ return currentSorting;
+}
+
+FtbListModel::FtbListModel(QObject *parent) : QAbstractListModel(parent)
+{
+}
+
+int FtbListModel::rowCount(const QModelIndex &parent) const
+{
+ return modpacks.size();
+}
+
+int FtbListModel::columnCount(const QModelIndex &parent) const
+{
+ return 1;
+}
+
+QVariant FtbListModel::data(const QModelIndex &index, int role) const
+{
+ int pos = index.row();
+ if(modpacks.size() < pos || pos < 0) {
+ return QString("INVALID INDEX %1").arg(pos);
+ }
+
+ FtbModpack pack = modpacks.at(pos);
+
+ if(role == Qt::DisplayRole) {
+ return pack.name;
+ } else if (role == Qt::ToolTipRole) {
+ if(pack.description.length() > 100) {
+ //some magic to prevent to long tooltips and replace html linebreaks
+ QString edit = pack.description.left(97);
+ edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
+ return edit;
+
+ }
+ return pack.description;
+ } else if(role == Qt::DecorationRole) {
+ //TODO: Add pack logos or something... but they have a weird size. This needs some design hacks
+ } else if(role == Qt::TextColorRole) {
+ if(pack.broken) {
+ return QColor(255, 0, 50);
+ } else if(pack.bugged) {
+ //bugged pack, currently only indicates bugged xml
+ return QColor(244, 229, 66);
+ }
+ } else if(role == Qt::UserRole) {
+ QVariant v;
+ v.setValue(pack);
+ return v;
+ }
+ return QVariant();
+}
+
+void FtbListModel::fill(FtbModpackList modpacks)
+{
+ this->modpacks = modpacks;
+}
+
+FtbModpack FtbListModel::at(int row)
+{
+ return modpacks.at(row);
+}
diff --git a/application/FtbListModel.h b/application/FtbListModel.h
new file mode 100644
index 00000000..e41e9b62
--- /dev/null
+++ b/application/FtbListModel.h
@@ -0,0 +1,45 @@
+#pragma once
+
+#include <QAbstractListModel>
+#include <QSortFilterProxyModel>
+#include <modplatform/PackHelpers.h>
+
+class FtbFilterModel : public QSortFilterProxyModel
+{
+public:
+ FtbFilterModel(QObject* parent = Q_NULLPTR);
+ enum Sorting {
+ ByName,
+ ByGameVersion
+ };
+ const QMap<QString, Sorting> getAvailableSortings();
+ Sorting getCurrentSorting();
+ void setSorting(Sorting sorting);
+
+protected:
+ bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
+ bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
+
+private:
+ QMap<QString, Sorting> sortings;
+ Sorting currentSorting;
+
+};
+
+class FtbListModel : public QAbstractListModel
+{
+ Q_OBJECT
+private:
+ FtbModpackList modpacks;
+
+public:
+ FtbListModel(QObject *parent);
+ int rowCount(const QModelIndex &parent) const override;
+ int columnCount(const QModelIndex &parent) const override;
+ QVariant data(const QModelIndex &index, int role) const override;
+
+ void fill(FtbModpackList modpacks);
+
+ FtbModpack at(int row);
+
+};
diff --git a/application/dialogs/ChooseFtbPackDialog.cpp b/application/dialogs/ChooseFtbPackDialog.cpp
index ae7c72e1..b1deae6e 100644
--- a/application/dialogs/ChooseFtbPackDialog.cpp
+++ b/application/dialogs/ChooseFtbPackDialog.cpp
@@ -1,33 +1,49 @@
#include "ChooseFtbPackDialog.h"
-#include "widgets/FtbModpackListItem.h"
+#include <QPushButton>
-ChooseFtbPackDialog::ChooseFtbPackDialog(FtbModpackList modpacks) : ui(new Ui::ChooseFtbPackDialog) {
+ChooseFtbPackDialog::ChooseFtbPackDialog(FtbModpackList modpacks) : ui(new Ui::ChooseFtbPackDialog)
+{
ui->setupUi(this);
- for(int i = 0; i < modpacks.size(); i++) {
- FtbModpackListItem *item = new FtbModpackListItem(ui->packList, modpacks.at(i));
+ filterModel = new FtbFilterModel(this);
+ listModel = new FtbListModel(this);
+ filterModel->setSourceModel(listModel);
+ listModel->fill(modpacks);
- item->setText(modpacks.at(i).name);
+ ui->packList->setModel(filterModel);
+ ui->packList->setSortingEnabled(true);
+ ui->packList->header()->hide();
+ ui->packList->setIndentation(0);
+
+ filterModel->setSorting(FtbFilterModel::Sorting::ByName);
+
+ for(int i = 0; i < filterModel->getAvailableSortings().size(); i++){
+ ui->sortByBox->addItem(filterModel->getAvailableSortings().keys().at(i));
}
- //TODO: Use a model/view instead of a widget
- connect(ui->packList, &QListWidget::itemClicked, this, &ChooseFtbPackDialog::onListItemClicked);
+ ui->sortByBox->setCurrentText(filterModel->getAvailableSortings().key(filterModel->getCurrentSorting()));
+
+ connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &ChooseFtbPackDialog::onSortingSelectionChanged);
connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &ChooseFtbPackDialog::onVersionSelectionItemChanged);
+ connect(ui->packList->selectionModel(), &QItemSelectionModel::currentChanged, this, &ChooseFtbPackDialog::onPackSelectionChanged);
ui->modpackInfo->setOpenExternalLinks(true);
+ ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
}
-ChooseFtbPackDialog::~ChooseFtbPackDialog(){
+ChooseFtbPackDialog::~ChooseFtbPackDialog()
+{
delete ui;
}
-void ChooseFtbPackDialog::onListItemClicked(QListWidgetItem *item){
+void ChooseFtbPackDialog::onPackSelectionChanged(QModelIndex now, QModelIndex prev)
+{
ui->packVersionSelection->clear();
- FtbModpack selectedPack = static_cast<FtbModpackListItem*>(item)->getModpack();
+ FtbModpack selectedPack = filterModel->data(now, Qt::UserRole).value<FtbModpack>();
ui->modpackInfo->setHtml("Pack by <b>" + selectedPack.author + "</b>" + "<br>Minecraft " + selectedPack.mcVersion + "<br>"
- "<br>" + selectedPack.description + "<ul><li>" + selectedPack.mods.replace(";", "</li><li>") + "</li></ul>");
+ "<br>" + selectedPack.description + "<ul><li>" + selectedPack.mods.replace(";", "</li><li>") + "</li></ul>");
bool currentAdded = false;
@@ -43,10 +59,11 @@ void ChooseFtbPackDialog::onListItemClicked(QListWidgetItem *item){
}
selected = selectedPack;
-
+ ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!selected.broken);
}
-void ChooseFtbPackDialog::onVersionSelectionItemChanged(QString data) {
+void ChooseFtbPackDialog::onVersionSelectionItemChanged(QString data)
+{
if(data.isNull() || data.isEmpty()) {
selectedVersion = "";
return;
@@ -55,10 +72,17 @@ void ChooseFtbPackDialog::onVersionSelectionItemChanged(QString data) {
selectedVersion = data;
}
-FtbModpack ChooseFtbPackDialog::getSelectedModpack() {
+FtbModpack ChooseFtbPackDialog::getSelectedModpack()
+{
return selected;
}
-QString ChooseFtbPackDialog::getSelectedVersion() {
+QString ChooseFtbPackDialog::getSelectedVersion()
+{
return selectedVersion;
}
+
+void ChooseFtbPackDialog::onSortingSelectionChanged(QString data)
+{
+ filterModel->setSorting(filterModel->getAvailableSortings().value(data));
+}
diff --git a/application/dialogs/ChooseFtbPackDialog.h b/application/dialogs/ChooseFtbPackDialog.h
index 212aa27b..0b021138 100644
--- a/application/dialogs/ChooseFtbPackDialog.h
+++ b/application/dialogs/ChooseFtbPackDialog.h
@@ -5,6 +5,7 @@
#include <modplatform/PackHelpers.h>
#include "ui_ChooseFtbPackDialog.h"
#include <modplatform/PackHelpers.h>
+#include "FtbListModel.h"
namespace Ui {
class ChooseFtbPackDialog;
@@ -18,11 +19,13 @@ private:
Ui::ChooseFtbPackDialog *ui;
FtbModpack selected;
QString selectedVersion;
+ FtbListModel* listModel;
+ FtbFilterModel* filterModel;
private slots:
- void onListItemClicked(QListWidgetItem *item);
+ void onSortingSelectionChanged(QString data);
void onVersionSelectionItemChanged(QString data);
-
+ void onPackSelectionChanged(QModelIndex first, QModelIndex second);
public:
ChooseFtbPackDialog(FtbModpackList packs);
~ChooseFtbPackDialog();
diff --git a/application/dialogs/ChooseFtbPackDialog.ui b/application/dialogs/ChooseFtbPackDialog.ui
index fdf845a9..f590a4cd 100644
--- a/application/dialogs/ChooseFtbPackDialog.ui
+++ b/application/dialogs/ChooseFtbPackDialog.ui
@@ -6,12 +6,12 @@
<rect>
<x>0</x>
<y>0</y>
- <width>730</width>
+ <width>700</width>
<height>437</height>
</rect>
</property>
<property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@@ -19,111 +19,67 @@
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="geometry">
- <rect>
- <x>540</x>
- <y>400</y>
- <width>176</width>
- <height>25</height>
- </rect>
- </property>
- <property name="standardButtons">
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
- </property>
- </widget>
- <widget class="QScrollArea" name="scrollArea">
- <property name="geometry">
- <rect>
- <x>10</x>
- <y>10</y>
- <width>261</width>
- <height>381</height>
- </rect>
- </property>
- <property name="widgetResizable">
- <bool>true</bool>
- </property>
- <widget class="QWidget" name="scrollAreaWidgetContents">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>259</width>
- <height>379</height>
- </rect>
- </property>
- <widget class="QListWidget" name="packList">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>261</width>
- <height>381</height>
- </rect>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="1" column="1">
+ <widget class="QLabel" name="selectedVersionLabel">
+ <property name="text">
+ <string>Version selected:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QTreeView" name="packList">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QComboBox" name="sortByBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="3">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="autoFillBackground">
+ <bool>false</bool>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ <property name="centerButtons">
+ <bool>false</bool>
</property>
</widget>
- </widget>
- </widget>
- <widget class="QScrollArea" name="scrollArea_2">
- <property name="geometry">
- <rect>
- <x>280</x>
- <y>10</y>
- <width>441</width>
- <height>381</height>
- </rect>
- </property>
- <property name="widgetResizable">
- <bool>true</bool>
- </property>
- <widget class="QWidget" name="scrollAreaWidgetContents_2">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>439</width>
- <height>379</height>
- </rect>
- </property>
- <widget class="QTextBrowser" name="modpackInfo">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>441</width>
- <height>381</height>
- </rect>
+ </item>
+ <item row="1" column="2">
+ <widget class="QComboBox" name="packVersionSelection">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
</property>
</widget>
- </widget>
- </widget>
- <widget class="QComboBox" name="packVersionSelection">
- <property name="geometry">
- <rect>
- <x>450</x>
- <y>400</y>
- <width>72</width>
- <height>25</height>
- </rect>
- </property>
- </widget>
- <widget class="QLabel" name="selectedVersionLabel">
- <property name="geometry">
- <rect>
- <x>340</x>
- <y>400</y>
- <width>101</width>
- <height>21</height>
- </rect>
- </property>
- <property name="text">
- <string>Version selected:</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
- </property>
- </widget>
+ </item>
+ <item row="0" column="1" colspan="3">
+ <widget class="QTextBrowser" name="modpackInfo"/>
+ </item>
+ </layout>
</widget>
<resources/>
<connections>
@@ -134,8 +90,8 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
- <x>666</x>
- <y>422</y>
+ <x>211</x>
+ <y>173</y>
</hint>
<hint type="destinationlabel">
<x>889</x>
@@ -150,8 +106,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
- <x>680</x>
- <y>411</y>
+ <x>225</x>
+ <y>162</y>
</hint>
<hint type="destinationlabel">
<x>524</x>
diff --git a/application/widgets/FtbModpackListItem.cpp b/application/widgets/FtbModpackListItem.cpp
deleted file mode 100644
index 874e0eac..00000000
--- a/application/widgets/FtbModpackListItem.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#include "FtbModpackListItem.h"
-
-FtbModpackListItem::FtbModpackListItem(QListWidget *list, FtbModpack modpack) : QListWidgetItem(list), modpack(modpack) {
-}
-
-FtbModpack FtbModpackListItem::getModpack(){
- return modpack;
-}
diff --git a/application/widgets/FtbModpackListItem.h b/application/widgets/FtbModpackListItem.h
deleted file mode 100644
index 977cad2d..00000000
--- a/application/widgets/FtbModpackListItem.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-
-#include "QListWidget"
-#include <modplatform/PackHelpers.h>
-
-class FtbModpackListItem : public QListWidgetItem {
-
-private:
- FtbModpack modpack;
-
-public:
- FtbModpackListItem(QListWidget *list, FtbModpack modpack);
- FtbModpack getModpack();
-
-};