mirror of
https://github.com/redstrate/Novus.git
synced 2025-04-22 20:17:46 +00:00
karaku: Add search function to the sheet list
This commit is contained in:
parent
5a03fafd3b
commit
d58fcf7e98
4 changed files with 85 additions and 14 deletions
|
@ -5,9 +5,11 @@ add_executable(novus-karuku)
|
|||
target_sources(novus-karuku
|
||||
PRIVATE
|
||||
include/mainwindow.h
|
||||
include/sheetlistwidget.h
|
||||
|
||||
src/main.cpp
|
||||
src/mainwindow.cpp)
|
||||
src/mainwindow.cpp
|
||||
src/sheetlistwidget.cpp)
|
||||
target_include_directories(novus-karuku
|
||||
PUBLIC
|
||||
include)
|
||||
|
|
24
karuku/include/sheetlistwidget.h
Normal file
24
karuku/include/sheetlistwidget.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QListView>
|
||||
#include <QWidget>
|
||||
#include <physis.hpp>
|
||||
|
||||
class SheetListWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SheetListWidget(GameData *data, QWidget *parent = nullptr);
|
||||
|
||||
Q_SIGNALS:
|
||||
void sheetSelected(const QString &name);
|
||||
|
||||
private:
|
||||
QListView *listWidget = nullptr;
|
||||
|
||||
GameData *data = nullptr;
|
||||
};
|
|
@ -12,6 +12,7 @@
|
|||
#include <physis.hpp>
|
||||
|
||||
#include "exdpart.h"
|
||||
#include "sheetlistwidget.h"
|
||||
|
||||
MainWindow::MainWindow(GameData *data)
|
||||
: NovusMainWindow()
|
||||
|
@ -26,29 +27,20 @@ MainWindow::MainWindow(GameData *data)
|
|||
auto layout = new QHBoxLayout();
|
||||
dummyWidget->setLayout(layout);
|
||||
|
||||
auto listWidget = new QListWidget();
|
||||
|
||||
auto names = physis_gamedata_get_all_sheet_names(data);
|
||||
for (uint32_t i = 0; i < names.name_count; i++) {
|
||||
listWidget->addItem(QString::fromStdString(names.names[i]));
|
||||
}
|
||||
|
||||
auto listWidget = new SheetListWidget(data);
|
||||
listWidget->setMaximumWidth(200);
|
||||
listWidget->sortItems();
|
||||
layout->addWidget(listWidget);
|
||||
|
||||
auto exdPart = new EXDPart(data);
|
||||
layout->addWidget(exdPart);
|
||||
|
||||
connect(listWidget, &QListWidget::itemClicked, this, [data, exdPart](QListWidgetItem *item) {
|
||||
auto nameLowercase = item->text().toLower();
|
||||
|
||||
auto path = QStringLiteral("exd/%1.exh").arg(nameLowercase);
|
||||
connect(listWidget, &SheetListWidget::sheetSelected, this, [data, exdPart](const QString &name) {
|
||||
auto path = QStringLiteral("exd/%1.exh").arg(name.toLower());
|
||||
auto pathStd = path.toStdString();
|
||||
|
||||
auto file = physis_gamedata_extract_file(data, pathStd.c_str());
|
||||
|
||||
exdPart->loadSheet(item->text(), file);
|
||||
exdPart->loadSheet(name, file);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
53
karuku/src/sheetlistwidget.cpp
Normal file
53
karuku/src/sheetlistwidget.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "sheetlistwidget.h"
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStringListModel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
SheetListWidget::SheetListWidget(GameData *data, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, data(data)
|
||||
{
|
||||
auto layout = new QVBoxLayout();
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(layout);
|
||||
|
||||
auto searchModel = new QSortFilterProxyModel();
|
||||
searchModel->setRecursiveFilteringEnabled(true);
|
||||
searchModel->setFilterCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
|
||||
|
||||
auto searchEdit = new QLineEdit();
|
||||
searchEdit->setPlaceholderText(QStringLiteral("Search..."));
|
||||
searchEdit->setClearButtonEnabled(true);
|
||||
connect(searchEdit, &QLineEdit::textChanged, this, [=](const QString &text) {
|
||||
searchModel->setFilterRegularExpression(text);
|
||||
});
|
||||
layout->addWidget(searchEdit);
|
||||
|
||||
auto originalModel = new QStringListModel();
|
||||
searchModel->setSourceModel(originalModel);
|
||||
|
||||
QStringList list;
|
||||
|
||||
auto names = physis_gamedata_get_all_sheet_names(data);
|
||||
for (uint32_t i = 0; i < names.name_count; i++) {
|
||||
list.push_back(QString::fromStdString(names.names[i]));
|
||||
}
|
||||
|
||||
originalModel->setStringList(list);
|
||||
|
||||
listWidget = new QListView();
|
||||
listWidget->setModel(searchModel);
|
||||
|
||||
connect(listWidget, &QListView::clicked, [this, searchModel](const QModelIndex &index) {
|
||||
Q_EMIT sheetSelected(searchModel->mapToSource(index).data(Qt::DisplayRole).toString());
|
||||
});
|
||||
|
||||
layout->addWidget(listWidget);
|
||||
}
|
||||
|
||||
#include "moc_sheetlistwidget.cpp"
|
Loading…
Add table
Reference in a new issue