summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-08-21 01:07:54 +0200
committerPetr Mrázek <peterix@gmail.com>2013-08-21 01:07:54 +0200
commitb78123166627139777fbd206866ee0d1c8bcd040 (patch)
tree9ea910562faae1be208cfda68f9c4f6795040524
parent524fbcdd3e359e07c1ff6e8ae05e03bc35977259 (diff)
downloadMultiMC-b78123166627139777fbd206866ee0d1c8bcd040.tar
MultiMC-b78123166627139777fbd206866ee0d1c8bcd040.tar.gz
MultiMC-b78123166627139777fbd206866ee0d1c8bcd040.tar.lz
MultiMC-b78123166627139777fbd206866ee0d1c8bcd040.tar.xz
MultiMC-b78123166627139777fbd206866ee0d1c8bcd040.zip
Contiguous selection and keyboard input for mod lists.
Tweak console to take up the sides. You can reorder mods from the keyboard.
-rw-r--r--gui/LegacyModEditDialog.cpp165
-rw-r--r--gui/LegacyModEditDialog.h6
-rw-r--r--gui/ModListView.cpp2
-rw-r--r--gui/ModListView.h2
-rw-r--r--gui/consolewindow.ui12
-rw-r--r--logic/Mod.cpp2
-rw-r--r--logic/ModList.cpp88
-rw-r--r--logic/ModList.h22
8 files changed, 256 insertions, 43 deletions
diff --git a/gui/LegacyModEditDialog.cpp b/gui/LegacyModEditDialog.cpp
index 9e0b7a46..51b21aa1 100644
--- a/gui/LegacyModEditDialog.cpp
+++ b/gui/LegacyModEditDialog.cpp
@@ -19,6 +19,8 @@
#include <pathutils.h>
#include <QFileDialog>
#include <QDebug>
+#include <QEvent>
+#include <QKeyEvent>
LegacyModEditDialog::LegacyModEditDialog( LegacyInstance* inst, QWidget* parent ) :
m_inst(inst),
@@ -34,13 +36,13 @@ LegacyModEditDialog::LegacyModEditDialog( LegacyInstance* inst, QWidget* parent
m_coremods = m_inst->coreModList();
m_jarmods = m_inst->jarModList();
- qDebug() << m_mods.data();
- qDebug() << m_coremods.data();
- qDebug() << m_jarmods.data();
-
ui->jarModsTreeView->setModel(m_jarmods.data());
ui->coreModsTreeView->setModel(m_coremods.data());
ui->mlModTreeView->setModel(m_mods.data());
+
+ ui->jarModsTreeView->installEventFilter( this );
+ ui->coreModsTreeView->installEventFilter( this );
+ ui->mlModTreeView->installEventFilter( this );
}
LegacyModEditDialog::~LegacyModEditDialog()
@@ -48,6 +50,90 @@ LegacyModEditDialog::~LegacyModEditDialog()
delete ui;
}
+bool LegacyModEditDialog::coreListFilter ( QKeyEvent* keyEvent )
+{
+ switch(keyEvent->key())
+ {
+ case Qt::Key_Delete:
+ on_rmCoreBtn_clicked();
+ return true;
+ case Qt::Key_Plus:
+ on_addCoreBtn_clicked();
+ return true;
+ default:
+ break;
+ }
+ return QDialog::eventFilter( ui->coreModsTreeView, keyEvent );
+}
+
+bool LegacyModEditDialog::jarListFilter ( QKeyEvent* keyEvent )
+{
+ switch(keyEvent->key())
+ {
+ case Qt::Key_Up:
+ {
+ if(keyEvent->modifiers() & Qt::ControlModifier)
+ {
+ on_moveJarUpBtn_clicked();
+ return true;
+ }
+ break;
+ }
+ case Qt::Key_Down:
+ {
+ if(keyEvent->modifiers() & Qt::ControlModifier)
+ {
+ on_moveJarDownBtn_clicked();
+ return true;
+ }
+ break;
+ }
+ case Qt::Key_Delete:
+ on_rmJarBtn_clicked();
+ return true;
+ case Qt::Key_Plus:
+ on_addJarBtn_clicked();
+ return true;
+ default:
+ break;
+ }
+ return QDialog::eventFilter( ui->jarModsTreeView, keyEvent );
+}
+
+bool LegacyModEditDialog::loaderListFilter ( QKeyEvent* keyEvent )
+{
+ switch(keyEvent->key())
+ {
+ case Qt::Key_Delete:
+ on_rmModBtn_clicked();
+ return true;
+ case Qt::Key_Plus:
+ on_addModBtn_clicked();
+ return true;
+ default:
+ break;
+ }
+ return QDialog::eventFilter( ui->mlModTreeView, keyEvent );
+}
+
+
+bool LegacyModEditDialog::eventFilter ( QObject* obj, QEvent* ev )
+{
+ if (ev->type() != QEvent::KeyPress)
+ {
+ return QDialog::eventFilter( obj, ev );
+ }
+ QKeyEvent *keyEvent = static_cast<QKeyEvent*>(ev);
+ if(obj == ui->jarModsTreeView)
+ return jarListFilter(keyEvent);
+ if(obj == ui->coreModsTreeView)
+ return coreListFilter(keyEvent);
+ if(obj == ui->mlModTreeView)
+ return loaderListFilter(keyEvent);
+ return QDialog::eventFilter( obj, ev );
+}
+
+
void LegacyModEditDialog::on_addCoreBtn_clicked()
{
QStringList fileNames = QFileDialog::getOpenFileNames(this, "Select Core Mods");
@@ -58,51 +144,90 @@ void LegacyModEditDialog::on_addCoreBtn_clicked()
}
void LegacyModEditDialog::on_addForgeBtn_clicked()
{
-
+
}
void LegacyModEditDialog::on_addJarBtn_clicked()
{
-
+ QStringList fileNames = QFileDialog::getOpenFileNames(this, "Select Jar Mods");
+ for(auto filename:fileNames)
+ {
+ m_jarmods->installMod(QFileInfo(filename));
+ }
}
void LegacyModEditDialog::on_addModBtn_clicked()
{
-
+ QStringList fileNames = QFileDialog::getOpenFileNames(this, "Select Loader Mods");
+ for(auto filename:fileNames)
+ {
+ m_mods->installMod(QFileInfo(filename));
+ }
}
void LegacyModEditDialog::on_addTexPackBtn_clicked()
{
}
+
+bool lastfirst (QModelIndexList & list, int & first, int & last)
+{
+ if(!list.size())
+ return false;
+ first = last = list[0].row();
+ for(auto item: list)
+ {
+ int row = item.row();
+ if(row < first)
+ first = row;
+ if(row > last)
+ last = row;
+ }
+ return true;
+}
+
void LegacyModEditDialog::on_moveJarDownBtn_clicked()
{
+ int first, last;
+ auto list = ui->jarModsTreeView->selectionModel()->selectedRows();
+
+ if(!lastfirst(list, first, last))
+ return;
+ m_jarmods->moveModsDown(first, last);
}
void LegacyModEditDialog::on_moveJarUpBtn_clicked()
{
-
+ int first, last;
+ auto list = ui->jarModsTreeView->selectionModel()->selectedRows();
+
+ if(!lastfirst(list, first, last))
+ return;
+ m_jarmods->moveModsUp(first, last);
}
void LegacyModEditDialog::on_rmCoreBtn_clicked()
{
- auto sm = ui->coreModsTreeView->selectionModel();
- auto selection = sm->selectedRows();
- if(!selection.size())
+ int first, last;
+ auto list = ui->coreModsTreeView->selectionModel()->selectedRows();
+
+ if(!lastfirst(list, first, last))
return;
- m_coremods->deleteMod(selection[0].row());
+ m_coremods->deleteMods(first, last);
}
void LegacyModEditDialog::on_rmJarBtn_clicked()
{
- auto sm = ui->jarModsTreeView->selectionModel();
- auto selection = sm->selectedRows();
- if(!selection.size())
+ int first, last;
+ auto list = ui->jarModsTreeView->selectionModel()->selectedRows();
+
+ if(!lastfirst(list, first, last))
return;
- m_jarmods->deleteMod(selection[0].row());
+ m_jarmods->deleteMods(first, last);
}
void LegacyModEditDialog::on_rmModBtn_clicked()
{
- auto sm = ui->mlModTreeView->selectionModel();
- auto selection = sm->selectedRows();
- if(!selection.size())
+ int first, last;
+ auto list = ui->mlModTreeView->selectionModel()->selectedRows();
+
+ if(!lastfirst(list, first, last))
return;
- m_mods->deleteMod(selection[0].row());
+ m_mods->deleteMods(first, last);
}
void LegacyModEditDialog::on_rmTexPackBtn_clicked()
{
diff --git a/gui/LegacyModEditDialog.h b/gui/LegacyModEditDialog.h
index 0654300f..536d402a 100644
--- a/gui/LegacyModEditDialog.h
+++ b/gui/LegacyModEditDialog.h
@@ -51,7 +51,11 @@ private slots:
void on_viewTexPackBtn_clicked();
// Questionable: SettingsDialog doesn't need this for some reason?
void on_buttonBox_rejected();
-
+protected:
+ bool eventFilter(QObject *obj, QEvent *ev);
+ bool jarListFilter( QKeyEvent* ev );
+ bool coreListFilter( QKeyEvent* ev );
+ bool loaderListFilter( QKeyEvent* ev );
private:
Ui::LegacyModEditDialog *ui;
QSharedPointer<ModList> m_mods;
diff --git a/gui/ModListView.cpp b/gui/ModListView.cpp
index dc63fcd9..34bd4af2 100644
--- a/gui/ModListView.cpp
+++ b/gui/ModListView.cpp
@@ -13,7 +13,7 @@ ModListView::ModListView ( QWidget* parent )
setRootIsDecorated ( false );
setSortingEnabled ( false );
setAlternatingRowColors ( true );
- setSelectionMode ( QAbstractItemView::SingleSelection );
+ setSelectionMode ( QAbstractItemView::ContiguousSelection );
setHeaderHidden ( false );
setSelectionBehavior(QAbstractItemView::SelectRows);
setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOn );
diff --git a/gui/ModListView.h b/gui/ModListView.h
index 1cbf86b7..a9408fe7 100644
--- a/gui/ModListView.h
+++ b/gui/ModListView.h
@@ -1,6 +1,8 @@
#pragma once
#include <QTreeView>
+class Mod;
+
class ModListView: public QTreeView
{
Q_OBJECT
diff --git a/gui/consolewindow.ui b/gui/consolewindow.ui
index f8c87aa0..9a766543 100644
--- a/gui/consolewindow.ui
+++ b/gui/consolewindow.ui
@@ -14,6 +14,15 @@
<string>MultiMC Console</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
<item>
<widget class="QPlainTextEdit" name="text">
<property name="font">
@@ -30,6 +39,9 @@
<property name="plainText">
<string notr="true"/>
</property>
+ <property name="textInteractionFlags">
+ <set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
<property name="centerOnScroll">
<bool>false</bool>
</property>
diff --git a/logic/Mod.cpp b/logic/Mod.cpp
index 4f9a1685..03c34140 100644
--- a/logic/Mod.cpp
+++ b/logic/Mod.cpp
@@ -260,5 +260,7 @@ QString Mod::version() const
return "Folder";
case MOD_SINGLEFILE:
return "File";
+ default:
+ return "VOID";
}
}
diff --git a/logic/ModList.cpp b/logic/ModList.cpp
index c968f326..c3f3ced3 100644
--- a/logic/ModList.cpp
+++ b/logic/ModList.cpp
@@ -137,9 +137,9 @@ bool ModList::isValid()
return m_dir.exists() && m_dir.isReadable();
}
-bool ModList::installMod ( const QFileInfo& filename, size_t index )
+bool ModList::installMod ( const QFileInfo& filename, int index )
{
- if(!filename.exists() || !filename.isReadable())
+ if(!filename.exists() || !filename.isReadable() || index < 0)
{
return false;
}
@@ -198,9 +198,9 @@ bool ModList::installMod ( const QFileInfo& filename, size_t index )
return false;
}
-bool ModList::deleteMod ( size_t index )
+bool ModList::deleteMod ( int index )
{
- if(index >= mods.size())
+ if(index >= mods.size() || index < 0)
return false;
Mod & m = mods[index];
if(m.destroy())
@@ -215,7 +215,23 @@ bool ModList::deleteMod ( size_t index )
return false;
}
-bool ModList::moveMod ( size_t from, size_t to )
+bool ModList::deleteMods ( int first, int last )
+{
+ for(int i = first; i <= last; i++)
+ {
+ Mod & m = mods[i];
+ m.destroy();
+ }
+ beginRemoveRows(QModelIndex(), first, last);
+ mods.erase(mods.begin() + first, mods.begin() + last + 1);
+ endRemoveRows();
+ saveListFile();
+ emit changed();
+ return true;
+}
+
+
+bool ModList::moveModTo ( int from, int to )
{
if(from < 0 || from >= mods.size())
return false;
@@ -223,18 +239,61 @@ bool ModList::moveMod ( size_t from, size_t to )
to = rowCount() - 1;
if (to == -1)
to = rowCount() - 1;
- // FIXME: this should be better, but segfaults for some reason
- //beginMoveRows(QModelIndex(), from, from, QModelIndex(), to);
-
- beginResetModel();
+ if(from == to)
+ return false;
+ int togap = to > from ? to + 1: to;
+ beginMoveRows(QModelIndex(), from, from, QModelIndex(), togap);
mods.move(from, to);
- endResetModel();
- //endMoveRows();
+ endMoveRows();
saveListFile();
emit changed();
return true;
}
+bool ModList::moveModUp ( int from )
+{
+ if(from > 0)
+ return moveModTo(from, from - 1);
+ return false;
+}
+
+bool ModList::moveModsUp ( int first, int last )
+{
+ if(first == 0)
+ return false;
+
+ beginMoveRows(QModelIndex(), first, last, QModelIndex(), first - 1);
+ mods.move(first-1, last);
+ endMoveRows();
+ saveListFile();
+ emit changed();
+ return true;
+}
+
+
+bool ModList::moveModDown ( int from )
+{
+ if(from < 0)
+ return false;
+ if(from < mods.size() - 1)
+ return moveModTo(from, from + 1);
+ return false;
+}
+
+bool ModList::moveModsDown ( int first, int last )
+{
+ if(last == mods.size() - 1)
+ return false;
+
+ beginMoveRows(QModelIndex(), first, last, QModelIndex(), last + 2);
+ mods.move(last+1, first);
+ endMoveRows();
+ saveListFile();
+ emit changed();
+ return true;
+}
+
+
int ModList::columnCount ( const QModelIndex& parent ) const
{
return 2;
@@ -329,11 +388,6 @@ QMimeData* ModList::mimeData ( const QModelIndexList& indexes ) const
data->setText(params.join('|'));
return data;
}
-bool ModList::removeRows ( int row, int count, const QModelIndex& parent )
-{
- return QAbstractItemModel::removeRows ( row, count, parent );
-}
-
bool ModList::dropMimeData ( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent )
{
if (action == Qt::IgnoreAction)
@@ -386,7 +440,7 @@ bool ModList::dropMimeData ( const QMimeData* data, Qt::DropAction action, int r
if(row == remoteIndex)
return false;
// otherwise, move the mod :D
- moveMod(remoteIndex, row);
+ moveModTo(remoteIndex, row);
return true;
}
return false;
diff --git a/logic/ModList.h b/logic/ModList.h
index 04ddaa8e..3cba69f5 100644
--- a/logic/ModList.h
+++ b/logic/ModList.h
@@ -45,16 +45,31 @@ public:
/**
* Adds the given mod to the list at the given index - if the list supports custom ordering
*/
- virtual bool installMod(const QFileInfo& filename, size_t index = 0);
+ virtual bool installMod(const QFileInfo& filename, int index = 0);
/// Deletes the mod at the given index.
- virtual bool deleteMod(size_t index);
+ virtual bool deleteMod(int index);
+
+ /// Deletes all the selected mods
+ virtual bool deleteMods( int first, int last );
/**
* move the mod at index to the position N
* 0 is the beginning of the list, length() is the end of the list.
*/
- virtual bool moveMod(size_t from, size_t to);
+ virtual bool moveModTo(int from, int to);
+
+ /**
+ * move the mod at index one position upwards
+ */
+ virtual bool moveModUp(int from);
+ virtual bool moveModsUp( int first, int last );
+
+ /**
+ * move the mod at index one position downwards
+ */
+ virtual bool moveModDown(int from);
+ virtual bool moveModsDown( int first, int last );
/// flags, mostly to support drag&drop
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
@@ -67,7 +82,6 @@ public:
/// what drag actions do we support?
virtual Qt::DropActions supportedDragActions() const;
- virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
/// what drop actions do we support?
virtual Qt::DropActions supportedDropActions() const;