summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2019-08-20 02:58:27 +0200
committerPetr Mrázek <peterix@gmail.com>2019-08-20 02:58:27 +0200
commit1747f413b9d9a515d8ba6f583bba5985bad5636d (patch)
tree3b964f253d0f476fe89c1ff35e6f093cedf270b5 /application
parent6d975748c0dd9ac89815fe5043c0d89b8e684bc7 (diff)
downloadMultiMC-1747f413b9d9a515d8ba6f583bba5985bad5636d.tar
MultiMC-1747f413b9d9a515d8ba6f583bba5985bad5636d.tar.gz
MultiMC-1747f413b9d9a515d8ba6f583bba5985bad5636d.tar.lz
MultiMC-1747f413b9d9a515d8ba6f583bba5985bad5636d.tar.xz
MultiMC-1747f413b9d9a515d8ba6f583bba5985bad5636d.zip
GH-851 save, load and use group expansion status
Diffstat (limited to 'application')
-rw-r--r--application/MainWindow.cpp4
-rw-r--r--application/groupview/GroupView.cpp10
-rw-r--r--application/groupview/GroupView.h12
3 files changed, 22 insertions, 4 deletions
diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp
index 1db09c6c..8457cd41 100644
--- a/application/MainWindow.cpp
+++ b/application/MainWindow.cpp
@@ -682,6 +682,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
connect(proxymodel, &InstanceProxyModel::dataChanged, this, &MainWindow::instanceDataChanged);
view->setModel(proxymodel);
+ view->setSourceOfGroupCollapseStatus([](const QString & groupName)->bool {
+ return MMC->instances()->isGroupCollapsed(groupName);
+ });
+ connect(view, &GroupView::groupStateChanged, MMC->instances().get(), &InstanceList::on_GroupStateChanged);
ui->horizontalLayout->addWidget(view);
}
// The cat background
diff --git a/application/groupview/GroupView.cpp b/application/groupview/GroupView.cpp
index bc7ef6c0..ff0daee4 100644
--- a/application/groupview/GroupView.cpp
+++ b/application/groupview/GroupView.cpp
@@ -175,6 +175,9 @@ void GroupView::updateGeometries()
else
{
auto cat = new VisualGroup(groupName, this);
+ if(fVisibility) {
+ cat->collapsed = fVisibility(groupName);
+ }
cats.insert(groupName, cat);
cat->update();
}
@@ -384,6 +387,8 @@ void GroupView::mouseReleaseEvent(QMouseEvent *event)
if (state() == ExpandingState)
{
m_pressedCategory->collapsed = false;
+ emit groupStateChanged(m_pressedCategory->text, false);
+
updateGeometries();
viewport()->update();
event->accept();
@@ -392,6 +397,8 @@ void GroupView::mouseReleaseEvent(QMouseEvent *event)
else if (state() == CollapsingState)
{
m_pressedCategory->collapsed = true;
+ emit groupStateChanged(m_pressedCategory->text, true);
+
updateGeometries();
viewport()->update();
event->accept();
@@ -607,8 +614,7 @@ void GroupView::dropEvent(QDropEvent *event)
const QString categoryText = category->text;
if (model()->dropMimeData(event->mimeData(), Qt::MoveAction, row, 0, QModelIndex()))
{
- model()->setData(model()->index(row, 0), categoryText,
- GroupViewRoles::GroupRole);
+ model()->setData(model()->index(row, 0), categoryText, GroupViewRoles::GroupRole);
event->setDropAction(Qt::MoveAction);
event->accept();
}
diff --git a/application/groupview/GroupView.h b/application/groupview/GroupView.h
index db29a0d4..13bfd234 100644
--- a/application/groupview/GroupView.h
+++ b/application/groupview/GroupView.h
@@ -20,6 +20,7 @@
#include <QScrollBar>
#include <QCache>
#include "VisualGroup.h"
+#include <functional>
struct GroupViewRoles
{
@@ -41,6 +42,11 @@ public:
void setModel(QAbstractItemModel *model) override;
+ using visibilityFunction = std::function<bool(const QString &)>;
+ void setSourceOfGroupCollapseStatus(visibilityFunction f) {
+ fVisibility = f;
+ }
+
/// return geometry rectangle occupied by the specified model item
QRect geometryRect(const QModelIndex &index) const;
/// return visual rectangle occupied by the specified model item
@@ -48,8 +54,7 @@ public:
/// get the model index at the specified visual point
virtual QModelIndex indexAt(const QPoint &point) const override;
QString groupNameAt(const QPoint &point);
- void setSelection(const QRect &rect,
- const QItemSelectionModel::SelectionFlags commands) override;
+ void setSelection(const QRect &rect, const QItemSelectionModel::SelectionFlags commands) override;
virtual int horizontalOffset() const override;
virtual int verticalOffset() const override;
@@ -80,6 +85,7 @@ protected slots:
signals:
void droppedURLs(QList<QUrl> urls);
+ void groupStateChanged(QString group, bool collapsed);
protected:
virtual bool isIndexHidden(const QModelIndex &index) const override;
@@ -103,6 +109,8 @@ private:
friend struct VisualGroup;
QList<VisualGroup *> m_groups;
+ visibilityFunction fVisibility;
+
// geometry
int m_leftMargin = 5;
int m_rightMargin = 5;