diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 6448478f..93f5756e 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -26,28 +26,144 @@ Qt::Horizontal - + + + true + 0 0 - - - 100 - 0 - - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectItems - - - false - + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + 3 + + + 3 + + + 3 + + + + + true + + + + 0 + 0 + + + + + :/icons/sort_alphabet.ico:/icons/sort_alphabet.ico + + + + 16 + 16 + + + + QToolButton::MenuButtonPopup + + + Qt::ToolButtonIconOnly + + + true + + + Qt::NoArrow + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 24 + 20 + + + + + + + + true + + + + 0 + 0 + + + + + + + Filter maps... + + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectItems + + + false + + + + @@ -73,7 +189,7 @@ - + :/icons/map.ico:/icons/map.ico @@ -177,7 +293,7 @@ Paint - + :/icons/pencil.ico:/icons/pencil.ico @@ -203,7 +319,7 @@ Select - + :/icons/cursor.ico:/icons/cursor.ico @@ -220,7 +336,7 @@ Fill - + :/icons/fill_color.ico:/icons/fill_color.ico @@ -237,7 +353,7 @@ Dropper - + :/icons/pipette.ico:/icons/pipette.ico @@ -254,7 +370,7 @@ ... - + :/icons/move.ico:/icons/move.ico @@ -271,7 +387,7 @@ Shift - + :/icons/shift.ico:/icons/shift.ico @@ -1355,7 +1471,7 @@ New Object - + :/icons/add.ico:/icons/add.ico @@ -1384,7 +1500,7 @@ Delete - + :/icons/delete.ico:/icons/delete.ico @@ -2295,7 +2411,7 @@ - + diff --git a/src/tileseteditor.ui b/forms/tileseteditor.ui similarity index 100% rename from src/tileseteditor.ui rename to forms/tileseteditor.ui diff --git a/include/core/filterchildrenproxymodel.h b/include/core/filterchildrenproxymodel.h new file mode 100644 index 00000000..b73cbd62 --- /dev/null +++ b/include/core/filterchildrenproxymodel.h @@ -0,0 +1,17 @@ +#ifndef FILTERCHILDRENPROXYMODEL_H +#define FILTERCHILDRENPROXYMODEL_H + +#include + +class FilterChildrenProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + explicit FilterChildrenProxyModel(QObject *parent = nullptr); +protected: + bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const; + +}; + +#endif // FILTERCHILDRENPROXYMODEL_H diff --git a/include/mainwindow.h b/include/mainwindow.h index 7dd7c773..732f96b1 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -130,6 +130,7 @@ private: QMap mapListIndexes; Editor *editor = nullptr; QIcon* mapIcon; + QIcon* mapEditedIcon; void setMap(QString, bool scrollTreeView = false); void redrawMapScene(); void loadDataStructures(); diff --git a/src/ui/tileseteditor.h b/include/ui/tileseteditor.h similarity index 100% rename from src/ui/tileseteditor.h rename to include/ui/tileseteditor.h diff --git a/porymap.pro b/porymap.pro index 3a027a4c..dc94f6eb 100644 --- a/porymap.pro +++ b/porymap.pro @@ -17,6 +17,7 @@ ICON = resources/icons/porymap-icon-1.ico SOURCES += src/core/block.cpp \ src/core/blockdata.cpp \ src/core/event.cpp \ + src/core/filterchildrenproxymodel.cpp \ src/core/heallocation.cpp \ src/core/historyitem.cpp \ src/core/map.cpp \ @@ -50,6 +51,7 @@ SOURCES += src/core/block.cpp \ HEADERS += include/core/block.h \ include/core/blockdata.h \ include/core/event.h \ + include/core/filterchildrenproxymodel.h \ include/core/heallocation.h \ include/core/history.h \ include/core/historyitem.h \ diff --git a/resources/icons/folder_image.ico b/resources/icons/folder_map_edited.ico similarity index 100% rename from resources/icons/folder_image.ico rename to resources/icons/folder_map_edited.ico diff --git a/resources/icons/folder_map_opened.ico b/resources/icons/folder_map_opened.ico new file mode 100644 index 00000000..2b23226a Binary files /dev/null and b/resources/icons/folder_map_opened.ico differ diff --git a/resources/icons/image.ico b/resources/icons/map_edited.ico similarity index 100% rename from resources/icons/image.ico rename to resources/icons/map_edited.ico diff --git a/resources/icons/map_opened.ico b/resources/icons/map_opened.ico new file mode 100644 index 00000000..b0d52dae Binary files /dev/null and b/resources/icons/map_opened.ico differ diff --git a/resources/icons/sort_alphabet.ico b/resources/icons/sort_alphabet.ico new file mode 100644 index 00000000..27744f83 Binary files /dev/null and b/resources/icons/sort_alphabet.ico differ diff --git a/resources/icons/sort_map.ico b/resources/icons/sort_map.ico new file mode 100644 index 00000000..5c64e855 Binary files /dev/null and b/resources/icons/sort_map.ico differ diff --git a/resources/icons/sort_number.ico b/resources/icons/sort_number.ico new file mode 100644 index 00000000..1fa55858 Binary files /dev/null and b/resources/icons/sort_number.ico differ diff --git a/resources/images.qrc b/resources/images.qrc index ac1ff8cb..8f1a09aa 100644 --- a/resources/images.qrc +++ b/resources/images.qrc @@ -3,9 +3,7 @@ icons/folder.ico icons/folder_closed.ico icons/folder_closed_map.ico - icons/folder_image.ico icons/folder_map.ico - icons/image.ico icons/map.ico icons/cursor.ico icons/fill_color.ico @@ -23,5 +21,12 @@ icons/shift.ico icons/shift_cursor.ico icons/porymap-icon-1.ico + icons/folder_map_edited.ico + icons/folder_map_opened.ico + icons/map_edited.ico + icons/map_opened.ico + icons/sort_alphabet.ico + icons/sort_map.ico + icons/sort_number.ico diff --git a/src/core/filterchildrenproxymodel.cpp b/src/core/filterchildrenproxymodel.cpp new file mode 100644 index 00000000..faff6a23 --- /dev/null +++ b/src/core/filterchildrenproxymodel.cpp @@ -0,0 +1,35 @@ +#include "filterchildrenproxymodel.h" + +FilterChildrenProxyModel::FilterChildrenProxyModel(QObject *parent) : + QSortFilterProxyModel(parent) +{ + +} + +bool FilterChildrenProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const +{ + // custom behaviour : + if(filterRegExp().isEmpty() == false) + { + // get source-model index for current row + QModelIndex source_index = sourceModel()->index(source_row, this->filterKeyColumn(), source_parent) ; + if(source_index.isValid()) + { + // if any of children matches the filter, then current index matches the filter as well + int i, nb = sourceModel()->rowCount(source_index); + for (i = 0; i < nb; ++i) + { + if (filterAcceptsRow(i, source_index)) + { + return true; + } + } + // check current index itself + QString key = sourceModel()->data(source_index, filterRole()).toString(); + QString parentKey = sourceModel()->data(source_parent, filterRole()).toString(); + return key.contains(filterRegExp()) || parentKey.contains(filterRegExp()); + } + } + // parent call for initial behaviour + return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); +} diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 70d875f3..e5e1115e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -180,6 +180,10 @@ void MainWindow::setMap(QString map_name, bool scrollTreeView) { if (map_name.isNull()) { return; } + if (editor->map != nullptr && !editor->map->name.isNull()) { + ui->mapList->setExpanded(mapListIndexes.value(editor->map->name), false); + } + ui->mapList->setExpanded(mapListIndexes.value(map_name), true); editor->setMap(map_name); redrawMapScene(); displayMapProperties(); @@ -418,26 +422,19 @@ void MainWindow::populateMapList() { QIcon folderIcon; folderIcon.addFile(QStringLiteral(":/icons/folder_closed.ico"), QSize(), QIcon::Normal, QIcon::Off); + folderIcon.addFile(QStringLiteral(":/icons/folder.ico"), QSize(), QIcon::Normal, QIcon::On); mapIcon = new QIcon; mapIcon->addFile(QStringLiteral(":/icons/map.ico"), QSize(), QIcon::Normal, QIcon::Off); - mapIcon->addFile(QStringLiteral(":/icons/image.ico"), QSize(), QIcon::Normal, QIcon::On); + mapIcon->addFile(QStringLiteral(":/icons/map_opened.ico"), QSize(), QIcon::Normal, QIcon::On); + + mapEditedIcon = new QIcon; + mapEditedIcon->addFile(QStringLiteral(":/icons/map_edited.ico"), QSize(), QIcon::Normal, QIcon::Off); + mapEditedIcon->addFile(QStringLiteral(":/icons/map_opened.ico"), QSize(), QIcon::Normal , QIcon::On); mapListModel = new QStandardItemModel; mapGroupsModel = new QList; - QStandardItem *entry = new QStandardItem; - entry->setText(project->getProjectTitle()); - entry->setIcon(folderIcon); - entry->setEditable(false); - mapListModel->appendRow(entry); - - QStandardItem *maps = new QStandardItem; - maps->setText("maps"); - maps->setIcon(folderIcon); - maps->setEditable(false); - entry->appendRow(maps); - project->readMapGroups(); for (int i = 0; i < project->groupNames->length(); i++) { QString group_name = project->groupNames->value(i); @@ -448,7 +445,7 @@ void MainWindow::populateMapList() { group->setData(group_name, Qt::UserRole); group->setData("map_group", MapListUserRoles::TypeRole); group->setData(i, MapListUserRoles::GroupRole); - maps->appendRow(group); + mapListModel->appendRow(group); mapGroupsModel->append(group); QStringList names = project->groupedMapNames.value(i); for (int j = 0; j < names.length(); j++) { @@ -466,7 +463,7 @@ void MainWindow::populateMapList() { ui->mapList->setModel(mapListModel); ui->mapList->setUpdatesEnabled(true); - ui->mapList->expandToDepth(2); + ui->mapList->expandToDepth(0); ui->mapList->repaint(); } @@ -563,10 +560,9 @@ void MainWindow::markEdited(QModelIndex index) { QString map_name = data.toString(); if (editor->project) { if (editor->project->map_cache->contains(map_name)) { - // Just mark anything that's been opened for now. - // TODO if (project->getMap()->saved) - //ui->mapList->setExpanded(index, true); - ui->mapList->setExpanded(index, editor->project->map_cache->value(map_name)->hasUnsavedChanges()); + if (editor->project->map_cache->value(map_name)->hasUnsavedChanges()) { + mapListModel->itemFromIndex(mapListIndexes.value(map_name))->setIcon(*mapEditedIcon); + } } } }