1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-19 08:52:33 +02:00
openrw/rwviewer/AnimationListWidget.cpp

48 lines
1.5 KiB
C++
Raw Normal View History

2014-03-01 12:19:33 +01:00
#include "AnimationListWidget.hpp"
#include <QVBoxLayout>
AnimationListWidget::AnimationListWidget(QWidget* parent, Qt::WindowFlags flags)
2016-09-09 22:13:21 +02:00
: QDockWidget(parent, flags), filter(nullptr), model(nullptr) {
setWindowTitle("Animations");
QVBoxLayout* layout = new QVBoxLayout();
QWidget* intermediate = new QWidget();
2014-03-01 12:19:33 +01:00
2016-09-09 22:13:21 +02:00
searchbox = new QLineEdit();
searchbox->setPlaceholderText("Search");
2014-03-01 12:19:33 +01:00
2016-09-09 22:13:21 +02:00
table = new QListView();
layout->addWidget(searchbox);
layout->addWidget(table);
intermediate->setLayout(layout);
setWidget(intermediate);
2014-03-01 12:19:33 +01:00
2016-09-09 22:13:21 +02:00
filter = new QSortFilterProxyModel;
table->setModel(filter);
connect(table->selectionModel(),
SIGNAL(currentChanged(QModelIndex, QModelIndex)),
SLOT(selectedIndexChanged(QModelIndex)));
connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString)));
2014-03-01 12:19:33 +01:00
}
2016-09-09 22:13:21 +02:00
void AnimationListWidget::setAnimations(const AnimationList& archive) {
auto m = new AnimationListModel(archive);
filter->setSourceModel(m);
if (model) {
delete model;
}
model = m;
2014-03-01 12:19:33 +01:00
}
2016-09-09 22:13:21 +02:00
void AnimationListWidget::selectedIndexChanged(const QModelIndex& current) {
auto mts = filter->mapToSource(current);
2018-07-27 22:53:35 +02:00
if (mts.row() >= 0 &&
static_cast<unsigned>(mts.row()) < model->getAnimations().size()) {
2016-09-09 22:13:21 +02:00
auto& f = model->getAnimations().at(mts.row());
emit selectedAnimationChanged(f.second);
}
2014-03-01 12:19:33 +01:00
}
2016-09-09 22:13:21 +02:00
void AnimationListWidget::setFilter(const QString& f) {
filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
2014-03-01 12:19:33 +01:00
}