Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ set(EDITOR_SOURCES
set(EDITOR_QML_UI
src/ui/common/CheckBox.qml
src/ui/common/ComboBox.qml
src/ui/common/PickerData.qml
src/ui/common/RadioButton.qml
src/ui/common/SpinBox.qml
src/ui/common/TextField.qml
src/ui/MainWindow.qml
src/ui/database/ActorPage.qml
src/ui/database/AttributePage.qml
src/ui/database/DatabaseEntryListPage.qml
Expand All @@ -337,23 +337,46 @@ set(EDITOR_QML_UI
src/ui/database/DatabaseWindow.qml
src/ui/database/ItemPage.qml
src/ui/database/SkillPage.qml
src/ui/database/SystemPage.qml
src/ui/database/VocabularyPage.qml
src/ui/MainWindow.qml
src/ui/picker/CharSetPicker.qml
src/ui/picker/FaceSetPicker.qml
src/ui/picker/ImagePicker.qml
src/ui/picker/MusicPicker.qml
src/ui/picker/PickerBase.qml
src/ui/picker/SoundPicker.qml
src/ui/viewer/CharSetViewer.qml
src/ui/viewer/FaceSetViewer.qml
src/ui/viewer/FileViewerBase.qml
src/ui/viewer/ImageViewer.qml
src/ui/viewer/MusicViewer.qml
src/ui/viewer/SoundViewer.qml
src/ui/viewer/ViewerBase.qml
)

set(EDITOR_QML_INTERFACE
src/qmlbinding/directory_model.cpp
src/qmlbinding/directory_model.h
src/qmlbinding/json_internals/json_t_database.cpp
src/qmlbinding/json_internals/json_t_impl.h
src/qmlbinding/json_internals/json_t_map.cpp
src/qmlbinding/json_internals/json_t_treemap.cpp
src/qmlbinding/json.h
src/qmlbinding/json_list_view.cpp
src/qmlbinding/json_list_view.h
src/qmlbinding/json_t.h
src/qmlbinding/json_view.cpp
src/qmlbinding/json_view.h
src/qmlbinding/json.h
src/qmlbinding/lcf_glaze.h
src/qmlbinding/project_data_gadget.cpp
src/qmlbinding/project_data_gadget.h
src/ui/picker/charset_painted_item.cpp
src/ui/picker/charset_painted_item.h
src/ui/picker/faceset_painted_item.cpp
src/ui/picker/faceset_painted_item.h
src/ui/picker/sprite_painted_item.cpp
src/ui/picker/sprite_painted_item.h
)

# Dependencies
Expand Down Expand Up @@ -423,6 +446,7 @@ target_include_directories(${EXE_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/qmlbinding # Required by QML build step
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/picker # QML painted items
INTERFACE
$<BUILD_INTERFACE:${AUTOGEN_INCLUDE_DIR}>
)
Expand Down
48 changes: 27 additions & 21 deletions src/common/filefinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
#include "defines.h"
#include "filefinder.h"

QString FileFinder::Find(const QDir& dir, const QString& filename, FileType type, QDir::Filter filter) {
auto fn = [&](std::initializer_list<std::string> exts) -> QString {
for (const std::string& ext: exts) {
QString file_to_find = filename + ToQString(ext);
QString FileFinder::Find(const QDir& dir, const QString& filename, FileFinder::FileType type, QDir::Filter filter) {
auto fn = [&](QStringList exts) -> QString {
for (const QString& ext: exts) {
QString file_to_find = filename + ext;
const auto& list = dir.entryList(filter);
for (const QString& item: list) {
if (item.compare(file_to_find, Qt::CaseInsensitive) == 0) {
Expand All @@ -33,23 +33,7 @@ QString FileFinder::Find(const QDir& dir, const QString& filename, FileType type
return nullptr;
};

switch (type) {
case FileType::Default:
return fn({""});
case FileType::Image:
return fn({ ".bmp", ".png", ".xyz"});
case FileType::Sound:
return fn({".opus", ".oga", ".ogg", ".wav", ".mp3"});
case FileType::Music:
return fn({".opus", ".oga", ".ogg", ".wav", ".mid", ".midi", ".mp3"});
case FileType::Video:
return fn({".webm", ".mp4", ".avi"});
case FileType::Font:
return fn({".ttf", ".ttc", ".otf", ".fon"});
}

assert(false);
return nullptr;
return fn(GetFiltersForType(type));
}

QString FileFinder::Find(const QDir& baseDir, const QString& subDir, const QString& filename, FileType type, QDir::Filter filter) {
Expand Down Expand Up @@ -77,3 +61,25 @@ bool FileFinder::IsEasyRpgProject(const QDir& directory) {
QString FileFinder::CombinePath(const QString& path1, const QString& path2) {
return path1 + QDir::separator() + path2;
}

QStringList FileFinder::GetFiltersForType(FileType type) {
switch (type) {
case FileType::Default:
return {""};
case FileType::Image:
return {".bmp", ".png", ".xyz"};
case FileType::Sound:
return {".opus", ".oga", ".ogg", ".wav", ".mp3"};
case FileType::Music:
return {".opus", ".oga", ".ogg", ".wav", ".mid", ".midi", ".mp3"};
case FileType::Video:
return {".webm", ".mp4", ".avi"};
case FileType::Font:
return {".ttf", ".ttc", ".otf", ".fon"};
default:
assert(false);
break;
}

return {};
}
2 changes: 2 additions & 0 deletions src/common/filefinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ namespace FileFinder {
bool IsEasyRpgProject(const QDir& directory);

QString CombinePath(const QString& path1, const QString& path2);

QStringList GetFiltersForType(FileType type);
};

4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) {
// Kirigami only loads a custom style when using a static build
// Lets wait for upstream to improve this
#if defined(KIRIGAMI_STATIC)
// Default to org.kde.breeze style (from qqc2-breeze style)
// Default to org.kde.breeze style (from qqc2-breeze style)
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
const char* fstyle = "KIRIGAMI_FORCE_STYLE";
if (qEnvironmentVariableIsEmpty(fstyle) || qEnvironmentVariableIntValue(fstyle) > 0) {
Expand Down Expand Up @@ -75,7 +75,7 @@ int main(int argc, char *argv[]) {
#endif

// setup qml engine
auto engine = core().qmlEngine();
//auto engine = core().qmlEngine();

/*engine->loadFromModule("org.easyrpg.editor", "MainWindow");
if (engine->rootObjects().isEmpty()) {
Expand Down
4 changes: 2 additions & 2 deletions src/model/actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ QAbstractItemModel* ActorModel::CreateEquipmentFilter(lcf::rpg::Item::Type type,
auto filter = new SortFilterProxyModelIdFilter(indices, parent);

if (!parent) {
QQmlEngine::setObjectOwnership(filter, QQmlEngine::JavaScriptOwnership);
}
QQmlEngine::setObjectOwnership(filter, QQmlEngine::JavaScriptOwnership);
}

return filter;
}
118 changes: 118 additions & 0 deletions src/qmlbinding/directory_model.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* This file is part of EasyRPG Editor.
*
* EasyRPG Editor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Editor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Editor. If not, see <http://www.gnu.org/licenses/>.
*/

#include "directory_model.h"
#include "common/filefinder.h"

DirectoryModel::DirectoryModel(QObject* parent) : QAbstractListModel(parent) {}

int DirectoryModel::rowCount(const QModelIndex& parent) const {
Q_UNUSED(parent)
return m_fileList.count();
}

QVariant DirectoryModel::data(const QModelIndex& index, int role) const {
if (!index.isValid() || index.row() < 0 ||
index.row() >= m_fileList.count())
return QVariant();

const QString& filename = m_fileList.at(index.row());

switch (role) {
case FileNameRole:
return filename;
case FullPathRole:
return QString("%1/%2").arg(m_path).arg(filename);
case BaseNameRole:
return filename.left(filename.lastIndexOf("."));
case Qt::DisplayRole:
return filename;
default:
return QVariant();
}
}

QHash<int, QByteArray> DirectoryModel::roleNames() const {
QHash<int, QByteArray> roles;
roles[FileNameRole] = "fileName";
roles[FullPathRole] = "fullPath";
roles[BaseNameRole] = "baseName";
return roles;
}

QString DirectoryModel::path() const { return m_path; }

void DirectoryModel::setPath(const QString& path) {
if (m_path == path)
return;

m_path = path;
refreshModel();
emit pathChanged();
}

FileFinder::FileType DirectoryModel::fileType() const { return m_fileType; }

void DirectoryModel::setFileType(FileFinder::FileType fileType) {
if (m_fileType == fileType)
return;

m_fileType = fileType;
refreshModel();
emit fileTypeChanged();
}

void DirectoryModel::refreshModel() {
beginResetModel();

m_fileList.clear();

if (!m_path.isEmpty()) {
QDir dir(m_path);
if (dir.exists()) {
auto entries = dir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name);

// Apply filters based on file type
QStringList filters = FileFinder::GetFiltersForType(m_fileType);

for (const QString& entry : entries) {
if (matchesFilter(entry, filters)) {
m_fileList.append(entry);
}
}
}
}

endResetModel();
emit countChanged();
}

bool DirectoryModel::matchesFilter(const QString& fileName,
const QStringList& filters) const {
if (filters.isEmpty() || filters.contains(""))
return true;

QString fileLower = fileName.toLower();

for (const QString& filter : filters) {
if (fileLower.endsWith(filter.toLower())) {
return true;
}
}

return false;
}
70 changes: 70 additions & 0 deletions src/qmlbinding/directory_model.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* This file is part of EasyRPG Editor.
*
* EasyRPG Editor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Editor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Editor. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "common/filefinder.h"
#include <QAbstractListModel>
#include <QDir>
#include <QFileInfo>
#include <QStringList>
#include <QtQmlIntegration>

class DirectoryModel : public QAbstractListModel {
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
Q_PROPERTY(FileFinder::FileType fileType READ fileType WRITE setFileType NOTIFY
fileTypeChanged)

public:
enum Roles {
FileNameRole = Qt::UserRole + 1,
FullPathRole,
BaseNameRole
};

explicit DirectoryModel(QObject* parent = nullptr);

// QAbstractItemModel interface
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const override;
Q_INVOKABLE QHash<int, QByteArray> roleNames() const override;

// Property accessors
QString path() const;
void setPath(const QString& path);

FileFinder::FileType fileType() const;
void setFileType(FileFinder::FileType fileType);

signals:
void pathChanged();
void countChanged();
void fileTypeChanged();

private:
void refreshModel();
bool matchesFilter(const QString& fileName,
const QStringList& filters) const;

QString m_path;
FileFinder::FileType m_fileType = FileFinder::FileType::Default;
QList<QString> m_fileList;
};
3 changes: 3 additions & 0 deletions src/qmlbinding/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,7 @@ class Json : public QObject {
* @return JSON string
*/
Q_INVOKABLE virtual QString toJson(QString jsonPtr) const = 0;

signals:
void valueChanged(QString jsonPtr);
};
Loading
Loading