diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml new file mode 100644 index 0000000..4429bdc --- /dev/null +++ b/.github/workflows/linux.yml @@ -0,0 +1,48 @@ +name: linux + +on: + pull_request: + push: + release: + types: published + +jobs: + build: + runs-on: ubuntu-22.04 + + strategy: + matrix: + buildtype: [Debug, Release] + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y libglx-dev libgl1-mesa-dev + sudo apt-get install -y qt6-base-dev + sudo apt-get install -y libqt6opengl6-dev + + - name: Configure FSStudio + run: | + cmake -B build -G "Unix Makefiles" + + - name: Build FSStudio + run: | + cd build + make + + - name: Pack FSStudio + run: | + cd build + make package + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: FSStudio-${{ matrix.buildtype }} + path: ./build/FSStudio-0.1.0-Linux.tar.* diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml new file mode 100644 index 0000000..af47d6d --- /dev/null +++ b/.github/workflows/macos.yml @@ -0,0 +1,45 @@ +name: macos + +on: + pull_request: + push: + release: + types: published + +jobs: + build: + runs-on: macos-latest + + strategy: + matrix: + buildtype: [Debug, Release] + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Install dependencies + run: | + brew install qt6 + + - name: Configure FSStudio + run: | + cmake -B build -G "Unix Makefiles" + + - name: Build FSStudio + run: | + cd build + make + + - name: Pack FSStudio + run: | + cd build + make package + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: FSStudio-${{ matrix.buildtype }} + path: ./build/FSStudio.dmg diff --git a/.github/workflows/vcpkg.json b/.github/workflows/vcpkg.json new file mode 100644 index 0000000..d99f98a --- /dev/null +++ b/.github/workflows/vcpkg.json @@ -0,0 +1,7 @@ +{ + "name": "fsstudio", + "version-string": "0.1.0", + "dependencies": [ + "qtbase" + ] +} diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 0000000..e81489d --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,58 @@ +name: windows + +on: + pull_request: + push: + release: + types: published + +jobs: + build: + runs-on: windows-latest + + strategy: + matrix: + buildtype: [Debug, Release] + architecture: [x64] + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Setup environment + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: ${{ matrix.architecture }} + + - name: Install dependencies + uses: jurplel/install-qt-action@v4 + with: + version: '6.2.0' + host: 'windows' + target: 'desktop' + arch: "win64_msvc2019_64" + cache: true + + - name: Configure FSStudio + run: | + cmake -B build -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.buildtype }} + + - name: Build FSStudio + shell: bash + run: | + cd build + nmake + + - name: Pack FSStudio + shell: bash + run: | + cd build + nmake package + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: FSStudio-${{ matrix.architecture }}-${{ matrix.buildtype }} + path: ./build/FSStudio-${{ matrix.architecture }}-${{ matrix.buildtype }}.exe diff --git a/.gitignore b/.gitignore index 3e543df..29b5e6e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ Makefile* debug release .qmake.stash +.DS_Store diff --git a/.gitmodules b/.gitmodules index fa17dcf..4c39c2f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "freeserf"] path = freeserf - url = git://github.com/freeserf/freeserf + url = https://github.com/freeserf/freeserf.git diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7d948b9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -language: cpp - -matrix: - include: - - os: linux - compiler: gcc - sudo: required - dist: trusty - - os: osx - compiler: clang - -before_install: - - if [[ $TRAVIS_OS_NAME == 'linux' ]]; then sudo add-apt-repository -y ppa:beineri/opt-qt58-trusty; fi - - if [[ $TRAVIS_OS_NAME == 'linux' ]]; then sudo apt-get update -qq; fi - - if [[ $TRAVIS_OS_NAME == 'osx' ]]; then brew update; fi - -install: - - if [[ $TRAVIS_OS_NAME == 'linux' ]]; then sudo apt-get install qt58base qt58x11extras qt58tools qt58multimedia libpulse-dev; fi - - if [[ $TRAVIS_OS_NAME == 'osx' ]]; then brew install qt; fi - -before_script: - - if [[ $TRAVIS_OS_NAME == 'linux' ]]; then source /opt/qt58/bin/qt58-env.sh; fi - - if [[ $TRAVIS_OS_NAME == 'osx' ]]; then export QTDIR="/usr/local/opt/qt"; fi - - if [[ $TRAVIS_OS_NAME == 'osx' ]]; then export PATH="$QTDIR/bin:$PATH"; fi - -script: - - qmake - - make - -deploy: - provider: s3 - access_key_id: $AWS_ACCESS_KEY_ID - secret_access_key: $AWS_SECRET_ACCESS_KEY - bucket: "fsstudio" - skip_cleanup: true diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..76b269c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,47 @@ +cmake_minimum_required(VERSION 3.16) + +project(FSStudio VERSION 0.1.0 LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_OSX_DEPLOYMENT_TARGET 12.0) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +include_directories(${INCLUDE_DIRECTORIES} ${CMAKE_CURRENT_SOURCE_DIR} freeserf) + +set(FREESERF_DATA_SOURCES ./freeserf/src/data.cc + ./freeserf/src/data-source-dos.cc + ./freeserf/src/data-source-amiga.cc + ./freeserf/src/data-source-custom.cc + ./freeserf/src/data-source-legacy.cc + ./freeserf/src/tpwm.cc + ./freeserf/src/sfx2wav.cc + ./freeserf/src/xmi2mid.cc + ./freeserf/src/data-source.cc + ./freeserf/src/log.cc + ./freeserf/src/configfile.cc + ./freeserf/src/buffer.cc + ./freeserf/src/pcm2wav.cc + ./freeserf/src/debug.cc) + +set(FREESERF_DATA_HEADERS ./freeserf/src/data.h + ./freeserf/src/misc.h + ./freeserf/src/freeserf_endian.h + ./freeserf/src/data-source-dos.h + ./freeserf/src/data-source-amiga.h + ./freeserf/src/data-source-custom.h + ./freeserf/src/data-source-legacy.h + ./freeserf/src/tpwm.h + ./freeserf/src/sfx2wav.h + ./freeserf/src/xmi2mid.h + ./freeserf/src/data-source.h + ./freeserf/src/log.h + ./freeserf/src/configfile.h + ./freeserf/src/buffer.h + ./freeserf/src/pcm2wav.h + ./freeserf/src/debug.h) + +add_library(freeserf_data STATIC ${FREESERF_DATA_SOURCES} ${FREESERF_DATA_HEADERS}) + +add_subdirectory(src) diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 3d4fecd..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,46 +0,0 @@ -os: Visual Studio 2017 - -platform: - - x86 - - x64 - -configuration: - - Debug - - Release - -install: - - git submodule update --init --recursive - - if "%platform%" == "x86" call set QTDIR=C:\Qt\5.13\msvc2017 - - if "%platform%" == "x64" call set QTDIR=C:\Qt\5.13\msvc2017_64 - - if "%platform%" == "x86" call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" - - if "%platform%" == "x64" call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64 - - set PATH=%PATH%;%QTDIR%\bin - -build_script: - - qmake fsstudio.pro - - nmake /f Makefile.%CONFIGURATION% - -after_build: - - ps: | - $ZIP_BASE = "fsstudio-VC-$env:PLATFORM-$env:CONFIGURATION" - $ZIP_FILE = "$($ZIP_BASE).zip" - md $ZIP_BASE - Copy-Item -Path $env:CONFIGURATION\FSStudio.exe -Destination $ZIP_BASE\ - Copy-Item -Path README.md -Destination $ZIP_BASE\README.txt - If ($env:CONFIGURATION -Like "Release") { - $QT_SUFFIX = ".dll" - } Else { - $QT_SUFFIX = "d.dll" - } - Copy-Item -Path $env:QTDIR\bin\Qt5Core$QT_SUFFIX -Destination $ZIP_BASE\ - Copy-Item -Path $env:QTDIR\bin\Qt5Gui$QT_SUFFIX -Destination $ZIP_BASE\ - Copy-Item -Path $env:QTDIR\bin\Qt5Multimedia$QT_SUFFIX -Destination $ZIP_BASE\ - Copy-Item -Path $env:QTDIR\bin\Qt5Network$QT_SUFFIX -Destination $ZIP_BASE\ - Copy-Item -Path $env:QTDIR\bin\Qt5Widgets$QT_SUFFIX -Destination $ZIP_BASE\ - md $ZIP_BASE\platforms - Copy-Item -Path $env:QTDIR\plugins\platforms\qwindows$QT_SUFFIX -Destination $ZIP_BASE\platforms - 7z a $ZIP_FILE $ZIP_BASE\* - -artifacts: - - path: "fsstudio-VC-$(PLATFORM)-$(CONFIGURATION).zip" - name: archive diff --git a/freeserf b/freeserf index d4231e9..0f1a94f 160000 --- a/freeserf +++ b/freeserf @@ -1 +1 @@ -Subproject commit d4231e925f4486a023a561183337e6cdddc2fa87 +Subproject commit 0f1a94f16c4877ff2d715fe7cd450b73710b5a17 diff --git a/fsstudio.pro b/fsstudio.pro deleted file mode 100644 index b392919..0000000 --- a/fsstudio.pro +++ /dev/null @@ -1,93 +0,0 @@ -# -# fs_studio.pro - FSStudio Qt project file -# -# Copyright (C) 2016 Wicked_Digger -# -# This file is part of FSViewer. -# -# FSStudio 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. -# -# FSStudio 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 FSStudio. If not, see . -# - -QT += core gui multimedia - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets xml - -TARGET = FSStudio -TEMPLATE = app - -SOURCES += src/main.cpp\ - src/mainwindow.cpp \ - freeserf/src/data.cc \ - freeserf/src/log.cc \ - freeserf/src/sfx2wav.cc \ - freeserf/src/xmi2mid.cc \ - freeserf/src/data-source-amiga.cc \ - freeserf/src/data-source-dos.cc \ - freeserf/src/data-source.cc \ - freeserf/src/tpwm.cc \ - src/resourcemodel.cpp \ - src/resourceview.cpp \ - src/sourcesview.cpp \ - src/spriteview.cpp \ - src/audioview.cpp \ - src/animationview.cpp \ - src/exporter.cpp \ - src/exportdialog.cpp \ - src/qpathedit.cpp \ - src/sourcesdialog.cpp \ - freeserf/src/data-source-custom.cc \ - freeserf/src/configfile.cc \ - src/datamodel.cpp \ - src/sprite-file-qt.cpp \ - src/colorlabel.cpp \ - freeserf/src/data-source-legacy.cc \ - freeserf/src/buffer.cc \ - freeserf/src/pcm2wav.cc \ - freeserf/src/debug.cc - -HEADERS += src/mainwindow.h \ - freeserf/src/data-source-amiga.h \ - freeserf/src/data-source-dos.h \ - freeserf/src/data-source.h \ - freeserf/src/data.h \ - freeserf/src/log.h \ - freeserf/src/misc.h \ - freeserf/src/sfx2wav.h \ - freeserf/src/xmi2mid.h \ - freeserf/src/tpwm.h \ - src/resourcemodel.h \ - src/resourceview.h \ - src/sourcesview.h \ - src/spriteview.h \ - src/audioview.h \ - src/animationview.h \ - src/exporter.h \ - src/exportdialog.h \ - src/qpathedit.h \ - src/sourcesdialog.h \ - freeserf/src/data-source-custom.h \ - freeserf/src/configfile.h \ - src/datamodel.h \ - freeserf/src/sprite-file.h \ - src/colorlabel.h \ - freeserf/src/data-source-legacy.h \ - freeserf/src/buffer.h \ - freeserf/src/pcm2wav.h \ - freeserf/src/debug.h - -INCLUDEPATH += . -INCLUDEPATH += freeserf - -RESOURCES += \ - res/resources.qrc diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..8979b22 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,89 @@ +cmake_minimum_required(VERSION 3.16) + +find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +set(FSSTUDIO_SOURCES animationview.cpp + audioview.cpp + colorlabel.cpp + datamodel.cpp + exportdialog.cpp + exporter.cpp + main.cpp + mainwindow.cpp + qpathedit.cpp + resourcemodel.cpp + resourceview.cpp + sourcesdialog.cpp + sourcesview.cpp + spriteview.cpp + sprite-file-qt.cpp + ../res/resources.qrc) + +set(FSSTUDIO_HEADERS animationview.h + audioview.h + colorlabel.h + datamodel.h + exportdialog.h + exporter.h + mainwindow.h + qpathedit.h + resourcemodel.h + resourceview.h + sourcesdialog.h + sourcesview.h + spriteview.h) + +qt_add_executable(${PROJECT_NAME} WIN32 ${FSSTUDIO_SOURCES} ${FSSTUDIO_HEADERS}) +target_link_libraries(${PROJECT_NAME} PRIVATE freeserf_data Qt6::Core Qt6::Gui Qt6::Widgets) +set_target_properties(${PROJECT_NAME} PROPERTIES + WIN32_EXECUTABLE ON + MACOSX_BUNDLE ON + XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "" +) + +if(APPLE) + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND "${MACDEPLOYQT_EXECUTABLE}" + ARGS $ "-always-overwrite" + COMMENT "Execute macdeployqt to create macOS bundle") +endif() + +install(TARGETS ${PROJECT_NAME} DESTINATION ".") + +set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) +if(WIN32) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(WIN_ARCH_STRING x64) + else() + set(WIN_ARCH_STRING x86) + endif() + set(CPACK_GENERATOR "NSIS") + if("${CMAKE_BUILD_TYPE}" STREQUAL "") + set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${WIN_ARCH_STRING}-Develop") + else() + set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${WIN_ARCH_STRING}-${CMAKE_BUILD_TYPE}") + endif() + set(CPACK_PACKAGE_INSTALL_DIRECTORY ${PROJECT_NAME}) + set(CPACK_NSIS_EXECUTABLES_DIRECTORY ".") + set(CPACK_PACKAGE_EXECUTABLES "${PROJECT_NAME};${PROJECT_NAME}") + # install VC redistributables + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CMAKE_INSTALL_DEBUG_LIBRARIES TRUE) + set(CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY TRUE) + endif(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE) + set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .) + include(InstallRequiredSystemLibraries) +elseif(APPLE) + set(CPACK_GENERATOR "DragNDrop") + set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}") +else() + set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}") +endif() +include(CPack) diff --git a/src/animationview.cpp b/src/animationview.cpp index 27f7d95..0040eef 100644 --- a/src/animationview.cpp +++ b/src/animationview.cpp @@ -20,27 +20,28 @@ */ #include "src/animationview.h" +#include "freeserf/src/data.h" FSSAnimationView::FSSAnimationView(QWidget *pParent) : QLabel(pParent) { - index = 0; + animation = nullptr; } FSSAnimationView::~FSSAnimationView() { } void -FSSAnimationView::setAnimation(PDataSource data_source, size_t index) { +FSSAnimationView::setAnimation(Data::PSource data_source, size_t index) { this->data_source = data_source; this->index = index; - if (!data_source) { + if (animation == nullptr) { return; } QString text; for (size_t i = 0; i < data_source->get_animation_phase_count(index); i++) { - Animation stage = data_source->get_animation(index, i << 3); + Data::Animation stage = data_source->get_animation(index, i << 3); QString line = QString("%1\tsprite = %2\tx = %3\ty = %4\n").arg(i).arg(stage.sprite).arg(stage.x).arg(stage.y); text += line; } diff --git a/src/animationview.h b/src/animationview.h index 1d4627e..1994617 100644 --- a/src/animationview.h +++ b/src/animationview.h @@ -24,20 +24,21 @@ #include -#include "src/data-source.h" +#include "src/data.h" class FSSAnimationView : public QLabel { Q_OBJECT protected: - PDataSource data_source; + Data::PSource data_source; size_t index; + void *animation; public: explicit FSSAnimationView(QWidget *pParent = NULL); virtual ~FSSAnimationView(); - void setAnimation(PDataSource data_source, size_t index); + void setAnimation(Data::PSource data_source, size_t index); }; #endif // SRC_ANIMATIONVIEW_H_ diff --git a/src/audioview.cpp b/src/audioview.cpp index 5b8219a..31d113a 100644 --- a/src/audioview.cpp +++ b/src/audioview.cpp @@ -21,16 +21,17 @@ #include "src/audioview.h" -#include +//#include #include #include #include #include #include +#include "src/buffer.h" + FSSAudioView::FSSAudioView(QWidget *pParent) : QWidget(pParent) { - file = NULL; - player = new QMediaPlayer(this); + file = nullptr; QHBoxLayout *main_layout = new QHBoxLayout(this); setLayout(main_layout); @@ -39,47 +40,30 @@ FSSAudioView::FSSAudioView(QWidget *pParent) : QWidget(pParent) { buttonPlay->setText("Play"); buttonPlay->setEnabled(false); main_layout->addWidget(buttonPlay); - connect(buttonPlay, &QPushButton::clicked, - this, &FSSAudioView::on_play); slider = new QSlider(this); slider->setOrientation(Qt::Horizontal); slider->setEnabled(false); main_layout->addWidget(slider); - - connect(player, &QMediaPlayer::mediaStatusChanged, - this, &FSSAudioView::on_media_status_changed); - connect(player, &QMediaPlayer::durationChanged, - this, &FSSAudioView::on_duration_changed); - connect(player, &QMediaPlayer::positionChanged, - this, &FSSAudioView::on_position_changed); - connect(player, &QMediaPlayer::stateChanged, - this, &FSSAudioView::on_state_changed); } FSSAudioView::~FSSAudioView() { - player->disconnect(); - player->stop(); - player->setMedia(QMediaContent()); - - if (file != NULL) { + if (file != nullptr) { delete file; - file = NULL; + file = nullptr; } } void -FSSAudioView::setAudioData(void *data, size_t size, const QString &format) { - player->stop(); - player->setMedia(QMediaContent()); - if (file != NULL) { +FSSAudioView::setAudioData(PBuffer data, const QString &format) { + if (file != nullptr) { delete file; - file = NULL; + file = nullptr; } buttonPlay->setEnabled(false); slider->setEnabled(false); - if (data == NULL) { + if (!data) { return; } @@ -88,89 +72,21 @@ FSSAudioView::setAudioData(void *data, size_t size, const QString &format) { qDebug() << "Failed to open temporary file"; return; } - if (file->write((char*)data, size) != (qint64)size) { + qint64 size = data->get_size(); + if (file->write((const char*)data->get_data(), size) != size) { qDebug() << "Failed to write to temporary file"; return; } file->close(); - - QUrl url = QUrl::fromLocalFile(file->fileName()); - qDebug() << "Sound writed to temporary file '" << url.toDisplayString() << "'"; - - player->setMedia(url); - player->setVolume(50); - player->setNotifyInterval(200); - qDebug() << player->mediaStatus(); -} - -void -FSSAudioView::on_media_status_changed(QMediaPlayer::MediaStatus status) { - qDebug() << player->mediaStatus(); - - switch (status) { - case QMediaPlayer::UnknownMediaStatus: - break; - case QMediaPlayer::NoMedia: - break; - case QMediaPlayer::LoadingMedia: - break; - case QMediaPlayer::LoadedMedia: - buttonPlay->setText("Play"); - buttonPlay->setEnabled(true); - slider->setEnabled(true); - break; - case QMediaPlayer::StalledMedia: - break; - case QMediaPlayer::BufferingMedia: - break; - case QMediaPlayer::BufferedMedia: - break; - case QMediaPlayer::EndOfMedia: - player->setPosition(0); - break; - case QMediaPlayer::InvalidMedia: - qDebug() << player->error(); - break; - } } void FSSAudioView::on_duration_changed(qint64 duration) { slider->setMinimum(0); - slider->setMaximum(duration); + slider->setMaximum((int)duration); } void FSSAudioView::on_position_changed(qint64 position) { - slider->setValue(position); -} - -void -FSSAudioView::on_state_changed(QMediaPlayer::State state) { - switch(state) { - case QMediaPlayer::StoppedState: - case QMediaPlayer::PausedState: - buttonPlay->setText("Play"); - buttonPlay->setEnabled(true); - slider->setEnabled(true); - break; - case QMediaPlayer::PlayingState: - buttonPlay->setText("Stop"); - buttonPlay->setEnabled(true); - slider->setEnabled(true); - break; - } -} - -void -FSSAudioView::on_play() { - switch(player->state()) { - case QMediaPlayer::StoppedState: - case QMediaPlayer::PausedState: - player->play(); - break; - case QMediaPlayer::PlayingState: - player->stop(); - break; - } + slider->setValue((int)position); } diff --git a/src/audioview.h b/src/audioview.h index 20e74fb..9e535a2 100644 --- a/src/audioview.h +++ b/src/audioview.h @@ -23,7 +23,7 @@ #define SRC_AUDIOVIEW_H_ #include -#include +//#include #include "src/data-source.h" @@ -36,7 +36,7 @@ class FSSAudioView : public QWidget { protected: QTemporaryFile *file; - QMediaPlayer *player; +// QMediaPlayer *player; QSlider *slider; QPushButton *buttonPlay; @@ -44,14 +44,14 @@ class FSSAudioView : public QWidget { explicit FSSAudioView(QWidget *pParent = NULL); virtual ~FSSAudioView(); - void setAudioData(void *data, size_t size, const QString &format); + void setAudioData(PBuffer data, const QString &format); public slots: - void on_media_status_changed(QMediaPlayer::MediaStatus status); +// void on_media_status_changed(QMediaPlayer::MediaStatus status); void on_duration_changed(qint64 duration); void on_position_changed(qint64 position); - void on_state_changed(QMediaPlayer::State state); - void on_play(); +// void on_state_changed(QMediaPlayer::State state); +// void on_play(); }; #endif // SRC_AUDIOVIEW_H_ diff --git a/src/datamodel.cpp b/src/datamodel.cpp index 438df47..73461c0 100644 --- a/src/datamodel.cpp +++ b/src/datamodel.cpp @@ -24,19 +24,22 @@ #include #include +#include "src/data.h" #include "src/data-source-dos.h" #include "src/data-source-amiga.h" #include "src/data-source-custom.h" FSSDataModel::FSSDataModel(QObject *parent) : QObject(parent) { - QString base_path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); + QString base_path = QStandardPaths::writableLocation( + QStandardPaths::HomeLocation); base_path += "/.local/share/freeserf"; QSettings settings; settings.sync(); - QString path = settings.value("sources/dos", base_path + "/spae.pa").toString(); + QString path = settings.value("sources/dos", + base_path + "/spae.pa").toString(); addDataSource(DataSourceTypeDos, path); path = settings.value("sources/amiga", base_path).toString(); @@ -47,13 +50,13 @@ FSSDataModel::FSSDataModel(QObject *parent) } FSSDataModel::~FSSDataModel() { - for (PDataSource dataSource : data_sources) { + for (Data::PSource dataSource : data_sources) { saveSetting(dataSource); } } size_t -FSSDataModel::addDataSource(PDataSource source) { +FSSDataModel::addDataSource(Data::PSource source) { size_t index = data_sources.count(); data_sources.push_back(source); saveSetting(source); @@ -63,7 +66,7 @@ FSSDataModel::addDataSource(PDataSource source) { size_t FSSDataModel::addDataSource(DataSourceType type, const QString &path) { - PDataSource source; + Data::PSource source; switch (type) { case DataSourceTypeDos: @@ -85,7 +88,7 @@ FSSDataModel::addDataSource(DataSourceType type, const QString &path) { return std::numeric_limits::max(); } -PDataSource +Data::PSource FSSDataModel::getDataSource(size_t index) const { if (index >= (size_t)data_sources.count()) { return nullptr; @@ -94,7 +97,7 @@ FSSDataModel::getDataSource(size_t index) const { } void -FSSDataModel::setDataSource(PDataSource source, size_t index) { +FSSDataModel::setDataSource(Data::PSource source, size_t index) { if (index >= (size_t)data_sources.count()) { return; } @@ -104,7 +107,7 @@ FSSDataModel::setDataSource(PDataSource source, size_t index) { } FSSDataModel::DataSourceType -FSSDataModel::getType(PDataSource source) { +FSSDataModel::getType(Data::PSource source) { std::string name = source->get_name(); if (name == "DOS") { @@ -117,7 +120,7 @@ FSSDataModel::getType(PDataSource source) { } void -FSSDataModel::saveSetting(PDataSource source) { +FSSDataModel::saveSetting(Data::PSource source) { QSettings settings; switch (getType(source)) { case DataSourceTypeDos: diff --git a/src/datamodel.h b/src/datamodel.h index 550ce13..71205bf 100644 --- a/src/datamodel.h +++ b/src/datamodel.h @@ -24,10 +24,7 @@ #include -#include - -class DataSource; -typedef std::shared_ptr PDataSource; +#include "src/data.h" class FSSDataModel : public QObject { Q_OBJECT @@ -40,21 +37,21 @@ class FSSDataModel : public QObject { }; protected: - QList data_sources; + QList data_sources; public: explicit FSSDataModel(QObject *parent = 0); virtual ~FSSDataModel(); size_t dataSourceCount() const { return data_sources.count(); } - size_t addDataSource(PDataSource source); + size_t addDataSource(Data::PSource source); size_t addDataSource(DataSourceType type, const QString &path); - PDataSource getDataSource(size_t index) const; - void setDataSource(PDataSource source, size_t index); - static DataSourceType getType(PDataSource source); + Data::PSource getDataSource(size_t index) const; + void setDataSource(Data::PSource source, size_t index); + static DataSourceType getType(Data::PSource source); protected: - void saveSetting(PDataSource source); + void saveSetting(Data::PSource source); signals: void sourceChanged(size_t index); diff --git a/src/exportdialog.cpp b/src/exportdialog.cpp index 6856c3e..b5032c0 100644 --- a/src/exportdialog.cpp +++ b/src/exportdialog.cpp @@ -33,9 +33,7 @@ #include "src/qpathedit.h" #include "src/exporter.h" -#include "src/data-source.h" #include "src/datamodel.h" -#include "src/colorlabel.h" FSSExportDialog::FSSExportDialog(FSSDataModel *_dataModel, QWidget *parent) : QDialog(parent) @@ -61,7 +59,8 @@ FSSExportDialog::FSSExportDialog(FSSDataModel *_dataModel, QWidget *parent) field_folder = new QPathEdit(this); field_folder->setAllowEmptyPath(false); field_folder->setPathMode(QPathEdit::ExistingFolder); - field_folder->setPath(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); + field_folder->setPath(QStandardPaths::writableLocation( + QStandardPaths::DocumentsLocation)); field_folder->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); layout->addRow("Target folder:", field_folder); @@ -86,7 +85,7 @@ FSSExportDialog::FSSExportDialog(FSSDataModel *_dataModel, QWidget *parent) hLayout->addWidget(button_export); for (size_t i = 0; i < dataModel->dataSourceCount(); i++) { - PDataSource data_source = dataModel->getDataSource(i); + Data::PSource data_source = dataModel->getDataSource(i); add_source(data_source); } @@ -99,7 +98,7 @@ FSSExportDialog::~FSSExportDialog() { } void -FSSExportDialog::add_source(PDataSource data_source) { +FSSExportDialog::add_source(Data::PSource data_source) { if (data_source == nullptr) { return; } @@ -118,7 +117,7 @@ FSSExportDialog::do_export() { button_cancel->setEnabled(false); button_export->setEnabled(false); source_num = field_source->currentIndex(); - PDataSource source = dataModel->getDataSource(source_num); + Data::PSource source = dataModel->getDataSource(source_num); FSSExporter exporter(source, field_folder->path(), field_scale->value()); exporter.set_name(field_name->text().toLocal8Bit().data()); exporter.do_export(); diff --git a/src/exportdialog.h b/src/exportdialog.h index 359e5d1..5090ccd 100644 --- a/src/exportdialog.h +++ b/src/exportdialog.h @@ -25,7 +25,7 @@ #include #include -#include +#include "src/data.h" class QComboBox; class QPathEdit; @@ -36,9 +36,6 @@ class QLineEdit; class FSSColorLabel; class FSSDataModel; -class DataSource; -typedef std::shared_ptr PDataSource; - class FSSExportDialog : public QDialog { Q_OBJECT @@ -57,7 +54,7 @@ class FSSExportDialog : public QDialog { virtual ~FSSExportDialog(); protected: - void add_source(PDataSource data_source); + void add_source(Data::PSource data_source); public slots: void do_export(); diff --git a/src/exporter.cpp b/src/exporter.cpp index 9e96e94..6bf1b5b 100644 --- a/src/exporter.cpp +++ b/src/exporter.cpp @@ -27,7 +27,8 @@ #include "src/data-source.h" #include "src/buffer.h" -FSSExporter::FSSExporter(PDataSource _source, QString _path, unsigned int _scale) { +FSSExporter::FSSExporter(Data::PSource _source, QString _path, + unsigned int _scale) { source = _source; path = _path; scale = _scale; @@ -72,7 +73,8 @@ FSSExporter::do_export() { break; } } - meta_file.setValue(QString("resources/") + Data::get_resource_name(res).c_str(), + meta_file.setValue(QString("resources/") + + Data::get_resource_name(res).c_str(), Data::get_resource_name(res).c_str()); } @@ -95,7 +97,8 @@ FSSExporter::exportResourceData(Data::Resource res, QString ext) { ext = "mid"; } if (data != nullptr) { - QString file_name = QString("%1").arg(i, 3, 10, QChar('0')); + QString file_name; + file_name.asprintf("%03zu", i); QString file_path = res_name + "/" + file_name + "." + ext; QFile file(dir.path() + "/" + file_path); if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { @@ -116,40 +119,51 @@ FSSExporter::exportResourceSprite(Data::Resource res) { QSettings meta_file(path + "/meta.ini", QSettings::IniFormat); for (size_t i = 0; i < Data::get_resource_count(res); i++) { - QString file_name = QString("%1").arg(i, 3, 10, QChar('0')); - DataSource::MaskImage pair = source->get_sprite_parts(res, i); + QString file_name; + file_name.asprintf("%03zu", i); + Data::MaskImage pair = source->get_sprite_parts(res, i); bool meta_saved = false; if (std::get<0>(pair)) { - PSprite mask = std::get<0>(pair); + Data::PSprite mask = std::get<0>(pair); QImage image(reinterpret_cast(mask->get_data()), - mask->get_width(), - mask->get_height(), + (int)mask->get_width(), + (int)mask->get_height(), QImage::Format_ARGB32); if (scale != 1) { image = image.scaled(image.width() * scale, image.height() * scale); } image.save(path + "/" + file_name + "m.png", "png"); meta_file.setValue(file_name + "/mask_path", file_name + "m.png"); - meta_file.setValue(file_name + "/delta_x", (int)(mask->get_delta_x() * scale)); - meta_file.setValue(file_name + "/delta_y", (int)(mask->get_delta_y() * scale)); - meta_file.setValue(file_name + "/offset_x", (int)(mask->get_offset_x() * scale)); - meta_file.setValue(file_name + "/offset_y", (int)(mask->get_offset_y() * scale)); + meta_file.setValue(file_name + "/delta_x", + (int)(mask->get_delta_x() * scale)); + meta_file.setValue(file_name + "/delta_y", + (int)(mask->get_delta_y() * scale)); + meta_file.setValue(file_name + "/offset_x", + (int)(mask->get_offset_x() * scale)); + meta_file.setValue(file_name + "/offset_y", + (int)(mask->get_offset_y() * scale)); meta_saved = true; } if (std::get<1>(pair)) { - PSprite front = std::get<1>(pair); - QImage image(reinterpret_cast(front->get_data()), front->get_width(), front->get_height(), QImage::Format_ARGB32); + Data::PSprite front = std::get<1>(pair); + QImage image(reinterpret_cast(front->get_data()), + (int)front->get_width(), (int)front->get_height(), + QImage::Format_ARGB32); if (scale != 1.) { image = image.scaled(image.width() * scale, image.height() * scale); } image.save(path + "/" + file_name + ".png", "png"); meta_file.setValue(file_name + "/image_path", file_name + ".png"); if (!meta_saved) { - meta_file.setValue(file_name + "/delta_x", (int)(front->get_delta_x() * scale)); - meta_file.setValue(file_name + "/delta_y", (int)(front->get_delta_y() * scale)); - meta_file.setValue(file_name + "/offset_x", (int)(front->get_offset_x() * scale)); - meta_file.setValue(file_name + "/offset_y", (int)(front->get_offset_y() * scale)); + meta_file.setValue(file_name + "/delta_x", + (int)(front->get_delta_x() * scale)); + meta_file.setValue(file_name + "/delta_y", + (int)(front->get_delta_y() * scale)); + meta_file.setValue(file_name + "/offset_x", + (int)(front->get_offset_x() * scale)); + meta_file.setValue(file_name + "/offset_y", + (int)(front->get_offset_y() * scale)); } } } @@ -163,15 +177,17 @@ FSSExporter::exportResourceAnimation(Data::Resource res) { QSettings meta_file(path + "/meta.ini", QSettings::IniFormat); for (size_t i = 0; i < Data::get_resource_count(res); i++) { - QString file_name = QString("%1").arg(i, 3, 10, QChar('0')); + QString file_name; + file_name.asprintf("%03zu", i); meta_file.setValue(file_name + "/path", file_name + ".ini"); QSettings data_file(path + "/" + file_name + ".ini", QSettings::IniFormat); size_t count = source->get_animation_phase_count(i); data_file.setValue("count", (unsigned int)count); for (size_t j = 0; j < count; j++) { - Animation animation = source->get_animation(i, j << 3); - QString phase_name = QString("%1").arg(j, 3, 10, QChar('0')); + Data::Animation animation = source->get_animation(i, j); + QString phase_name; + phase_name.asprintf("%03zu", j); data_file.setValue(phase_name + "/sprite", animation.sprite); data_file.setValue(phase_name + "/x", animation.x * (int)scale); data_file.setValue(phase_name + "/y", animation.y * (int)scale); diff --git a/src/exporter.h b/src/exporter.h index 8c87d3c..f48d69a 100644 --- a/src/exporter.h +++ b/src/exporter.h @@ -28,20 +28,18 @@ #include "src/data.h" -class DataSource; - class FSSExporter : public QObject { Q_OBJECT protected: - std::shared_ptr source; + Data::PSource source; QString path; int scale; QDir dir; std::string name; public: - FSSExporter(PDataSource source, QString path, unsigned int scale = 1); + FSSExporter(Data::PSource source, QString path, unsigned int scale = 1); virtual ~FSSExporter(); void set_name(const std::string &_name) { name = _name; } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1bd8af1..92ff76d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -28,7 +28,6 @@ #include "src/sourcesview.h" #include "src/data.h" -#include "src/data-source.h" #include "src/exportdialog.h" #include "src/sourcesdialog.h" #include "src/datamodel.h" @@ -54,14 +53,17 @@ FSSMainWindow::FSSMainWindow(FSSDataModel *_dataModel, QWidget *parent) QMenu *menuFile = new QMenu("File", this); menuFile->addAction("Export", this, SLOT(exportSource())); menuBar->addMenu(menuFile); - QAction *action_src = menuFile->addAction("Sources", this, SLOT(openSources())); + QAction *action_src = menuFile->addAction("Sources", this, + SLOT(openSources())); action_src->setMenuRole(QAction::PreferencesRole); QMenu *menuView = new QMenu("View", this); menuBar->addMenu(menuView); - QAction *action = menuView->addAction("Resources", dockResources, SLOT(setVisible(bool))); + QAction *action = menuView->addAction("Resources", dockResources, + SLOT(setVisible(bool))); action->setCheckable(true); - connect(dockResources, SIGNAL(visibilityChanged(bool)), action, SLOT(setChecked(bool))); + connect(dockResources, SIGNAL(visibilityChanged(bool)), action, + SLOT(setChecked(bool))); menuView->addSeparator(); @@ -69,21 +71,21 @@ FSSMainWindow::FSSMainWindow(FSSDataModel *_dataModel, QWidget *parent) viewSources->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); for (size_t i = 0; i < dataModel->dataSourceCount(); i++) { - PDataSource data_source = dataModel->getDataSource(i); + Data::PSource data_source = dataModel->getDataSource(i); viewSources->addSource(data_source); - QAction *action = menuView->addAction(data_source->get_name().c_str(), this, SLOT(switchSource(bool))); + QAction *action = menuView->addAction(data_source->get_name().c_str(), + this, SLOT(switchSource(bool))); action->setCheckable(true); action->setChecked(true); actions[action] = data_source; } connect(treeResources->selectionModel(), - SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), - SLOT(onCurrentChanged(const QModelIndex&, const QModelIndex&))); + SIGNAL(currentChanged(QModelIndex,QModelIndex)), + SLOT(onCurrentChanged(QModelIndex,QModelIndex))); - connect(this, SIGNAL(resourceSelected(Data::Resource, unsigned int)), - viewSources, SLOT(onResourceSelected(Data::Resource, - unsigned int))); + connect(this, SIGNAL(resourceSelected(Data::Resource,uint)), + viewSources, SLOT(onResourceSelected(Data::Resource,uint))); } FSSMainWindow::~FSSMainWindow() { @@ -120,6 +122,6 @@ FSSMainWindow::openSources() { void FSSMainWindow::switchSource(bool checked) { QAction *action = (QAction*)sender(); - PDataSource source = actions[action]; + Data::PSource source = actions[action]; viewSources->showSource(source, checked); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 25f45d3..5f91aac 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -43,7 +43,7 @@ class FSSMainWindow : public QMainWindow { QTreeView *treeResources; FSSResourceModel *resourceModel; FSSSourcesView *viewSources; - QMap actions; + QMap actions; FSSDataModel *dataModel; signals: diff --git a/src/qpathedit.cpp b/src/qpathedit.cpp index 331b0a9..6774575 100644 --- a/src/qpathedit.cpp +++ b/src/qpathedit.cpp @@ -12,21 +12,20 @@ #include #include #include -#include #include //HELPER CLASSES void masterDialog(QDialog *dialog); -class PathValidator : public QValidator -{ -public: +class PathValidator : public QValidator { + public: PathValidator(QObject *parent); void setMode(QPathEdit::PathMode mode); void setAllowEmpty(bool allow); State validate(QString &text, int &) const Q_DECL_OVERRIDE; -private: + + private: QPathEdit::PathMode mode; bool allowEmpty; }; @@ -34,13 +33,14 @@ class PathValidator : public QValidator //QPATHEDIT IMPLEMENTATION QPathEdit::QPathEdit(QWidget *parent, QPathEdit::Style style) : - QPathEdit(ExistingFile, parent, style) -{} + QPathEdit(ExistingFile, parent, style) { +} -QPathEdit::QPathEdit(QPathEdit::PathMode pathMode, QWidget *parent, QPathEdit::Style style) : - QWidget(parent), - edit(new QLineEdit(this)), - pathCompleter(new QCompleter(this)), +QPathEdit::QPathEdit(QPathEdit::PathMode pathMode, QWidget *parent, + QPathEdit::Style style) + : QWidget(parent) + , edit(new QLineEdit(this)) + , pathCompleter(new QCompleter(this)), completerModel(new QFileSystemModel(this)), pathValidator(new PathValidator(this)), dialog(new QFileDialog(this)), @@ -55,7 +55,6 @@ QPathEdit::QPathEdit(QPathEdit::PathMode pathMode, QWidget *parent, QPathEdit::S hasCustomIcon(false) { //setup dialog - dialog->setOptions(0); masterDialog(dialog); setPathMode(pathMode); connect(dialog, &QFileDialog::fileSelected, this, &QPathEdit::dialogFileSelected); @@ -63,9 +62,8 @@ QPathEdit::QPathEdit(QPathEdit::PathMode pathMode, QWidget *parent, QPathEdit::S //setup completer completerModel->setRootPath(""); completerModel->setNameFilterDisables(false); - connect(completerModel, &QFileSystemModel::directoryLoaded, pathCompleter, [this](QString){ - pathCompleter->complete(); - }); + connect(completerModel, &QFileSystemModel::directoryLoaded, pathCompleter, + [this](QString){ pathCompleter->complete(); }); pathCompleter->setModel(completerModel); //setup this @@ -92,13 +90,13 @@ QPathEdit::QPathEdit(QPathEdit::PathMode pathMode, QWidget *parent, QPathEdit::S #endif toolButton->setFixedSize(height, height); switch(style) { - case JoinedButton: - edit->addAction(dialogAction, QLineEdit::TrailingPosition); - case NoButton: - toolButton->setVisible(false); - break; - default: - break; + case JoinedButton: + edit->addAction(dialogAction, QLineEdit::TrailingPosition); + case NoButton: + toolButton->setVisible(false); + break; + default: + break; } QWidget::setTabOrder(edit, toolButton); @@ -106,218 +104,200 @@ QPathEdit::QPathEdit(QPathEdit::PathMode pathMode, QWidget *parent, QPathEdit::S setFocusProxy(edit); } -QPathEdit::QPathEdit(QPathEdit::PathMode pathMode, QString defaultDirectory, QWidget *parent, QPathEdit::Style style) : - QPathEdit(pathMode, parent, style) -{ +QPathEdit::QPathEdit(QPathEdit::PathMode pathMode, QString defaultDirectory, + QWidget *parent, QPathEdit::Style style) + : QPathEdit(pathMode, parent, style) { setDefaultDirectory(defaultDirectory); } -QPathEdit::PathMode QPathEdit::pathMode() const -{ +QPathEdit::PathMode QPathEdit::pathMode() const { return mode; } -void QPathEdit::setPathMode(PathMode pathMode) -{ +void QPathEdit::setPathMode(PathMode pathMode) { mode = pathMode; pathValidator->setMode(pathMode); currentValidPath.clear(); emit pathChanged(QString()); edit->clear(); switch(pathMode) { - case ExistingFile: - dialog->setAcceptMode(QFileDialog::AcceptOpen); - dialog->setFileMode(QFileDialog::ExistingFile); - completerModel->setFilter(QDir::AllEntries | QDir::AllDirs | QDir::NoDotAndDotDot); - break; - case ExistingFolder: - dialog->setAcceptMode(QFileDialog::AcceptOpen); - dialog->setFileMode(QFileDialog::Directory); - completerModel->setFilter(QDir::Drives | QDir::Dirs | QDir::NoDotAndDotDot); - break; - case AnyFile: - dialog->setAcceptMode(QFileDialog::AcceptSave); - dialog->setFileMode(QFileDialog::AnyFile); - completerModel->setFilter(QDir::AllEntries | QDir::AllDirs | QDir::NoDotAndDotDot); - break; - default: - Q_UNREACHABLE(); + case ExistingFile: + dialog->setAcceptMode(QFileDialog::AcceptOpen); + dialog->setFileMode(QFileDialog::ExistingFile); + completerModel->setFilter(QDir::AllEntries | QDir::AllDirs + | QDir::NoDotAndDotDot); + break; + case ExistingFolder: + dialog->setAcceptMode(QFileDialog::AcceptOpen); + dialog->setFileMode(QFileDialog::Directory); + completerModel->setFilter(QDir::Drives | QDir::Dirs + | QDir::NoDotAndDotDot); + break; + case AnyFile: + dialog->setAcceptMode(QFileDialog::AcceptSave); + dialog->setFileMode(QFileDialog::AnyFile); + completerModel->setFilter(QDir::AllEntries | QDir::AllDirs + | QDir::NoDotAndDotDot); + break; + default: + Q_UNREACHABLE(); } } -QFileDialog::Options QPathEdit::dialogOptions() const -{ +QFileDialog::Options QPathEdit::dialogOptions() const { return dialog->options(); } -void QPathEdit::setDialogOptions(QFileDialog::Options dialogOptions) -{ +void QPathEdit::setDialogOptions(QFileDialog::Options dialogOptions) { dialog->setOptions(dialogOptions); } -bool QPathEdit::isEmptyPathAllowed() const -{ +bool QPathEdit::isEmptyPathAllowed() const { return allowEmpty; } -void QPathEdit::setAllowEmptyPath(bool allowEmptyPath) -{ +void QPathEdit::setAllowEmptyPath(bool allowEmptyPath) { allowEmpty = allowEmptyPath; pathValidator->setAllowEmpty(allowEmptyPath); } -QString QPathEdit::defaultDirectory() const -{ +QString QPathEdit::defaultDirectory() const { return defaultDir; } -void QPathEdit::setDefaultDirectory(QString defaultDirectory) -{ +void QPathEdit::setDefaultDirectory(QString defaultDirectory) { defaultDir = defaultDirectory; } -QString QPathEdit::path() const -{ +QString QPathEdit::path() const { return currentValidPath; } -QUrl QPathEdit::pathUrl() const -{ +QUrl QPathEdit::pathUrl() const { return QUrl::fromLocalFile(currentValidPath); } -bool QPathEdit::setPath(QString path, bool allowInvalid) -{ - if (edit->text() == path) +bool QPathEdit::setPath(QString path, bool allowInvalid) { + if (edit->text() == path) { return true; + } - if(allowInvalid) + if(allowInvalid) { edit->setText(path); + } int pseudo = 0; if(pathValidator->validate(path, pseudo) == QValidator::Acceptable) { currentValidPath = path.replace(QStringLiteral("\\"), QStringLiteral("/")); - if(!allowInvalid) + if(!allowInvalid) { edit->setText(path); + } emit pathChanged(path); return true; - } else + } else { return false; + } } -void QPathEdit::clear() -{ +void QPathEdit::clear() { edit->clear(); currentValidPath.clear(); emit pathChanged(QString()); } -QString QPathEdit::placeholder() const -{ +QString QPathEdit::placeholder() const { return edit->placeholderText(); } -void QPathEdit::setPlaceholder(QString placeholder) -{ +void QPathEdit::setPlaceholder(QString placeholder) { edit->setPlaceholderText(placeholder); } -QStringList QPathEdit::nameFilters() const -{ +QStringList QPathEdit::nameFilters() const { return dialog->nameFilters(); } -void QPathEdit::setNameFilters(QStringList nameFilters) -{ +void QPathEdit::setNameFilters(QStringList nameFilters) { dialog->setNameFilters(nameFilters); QStringList tmp = modelFilters(nameFilters); completerModel->setNameFilters(tmp); } -QStringList QPathEdit::mimeTypeFilters() const -{ +QStringList QPathEdit::mimeTypeFilters() const { return dialog->mimeTypeFilters(); } -void QPathEdit::setMimeTypeFilters(QStringList mimeFilters) -{ +void QPathEdit::setMimeTypeFilters(QStringList mimeFilters) { dialog->setMimeTypeFilters(mimeFilters); QStringList tmp = modelFilters(dialog->nameFilters()); completerModel->setNameFilters(tmp); } -bool QPathEdit::isEditable() const -{ +bool QPathEdit::isEditable() const { return !edit->isReadOnly(); } -void QPathEdit::setEditable(bool editable) -{ +void QPathEdit::setEditable(bool editable) { edit->setReadOnly(!editable); } -bool QPathEdit::useCompleter() const -{ +bool QPathEdit::useCompleter() const { return edit->completer(); } -void QPathEdit::setUseCompleter(bool useCompleter) -{ +void QPathEdit::setUseCompleter(bool useCompleter) { edit->setCompleter(useCompleter ? pathCompleter : nullptr); } -QPathEdit::Style QPathEdit::style() const -{ +QPathEdit::Style QPathEdit::style() const { return uiStyle; } -void QPathEdit::setStyle(QPathEdit::Style style, QLineEdit::ActionPosition position) -{ - if (uiStyle == style) +void QPathEdit::setStyle(QPathEdit::Style style, + QLineEdit::ActionPosition position) { + if (uiStyle == style) { return; + } switch(style) { - case SeperatedButton: - edit->removeAction(dialogAction); - toolButton->setVisible(true); - break; - case JoinedButton: - edit->addAction(dialogAction, position); - toolButton->setVisible(false); - break; - case NoButton: - edit->removeAction(dialogAction); - toolButton->setVisible(false); - break; - default: - Q_UNREACHABLE(); - break; + case SeperatedButton: + edit->removeAction(dialogAction); + toolButton->setVisible(true); + break; + case JoinedButton: + edit->addAction(dialogAction, position); + toolButton->setVisible(false); + break; + case NoButton: + edit->removeAction(dialogAction); + toolButton->setVisible(false); + break; + default: + Q_UNREACHABLE(); + break; } uiStyle = style; - if(!hasCustomIcon) + if(!hasCustomIcon) { dialogAction->setIcon(getDefaultIcon()); + } } -QIcon QPathEdit::dialogButtonIcon() const -{ +QIcon QPathEdit::dialogButtonIcon() const { return dialogAction->icon(); } -void QPathEdit::setDialogButtonIcon(const QIcon &icon) -{ +void QPathEdit::setDialogButtonIcon(const QIcon &icon) { dialogAction->setIcon(icon); hasCustomIcon = true; } -void QPathEdit::resetDialogButtonIcon() -{ +void QPathEdit::resetDialogButtonIcon() { dialogAction->setIcon(QPathEdit::getDefaultIcon()); hasCustomIcon = false; } -void QPathEdit::showDialog() -{ +void QPathEdit::showDialog() { if(dialog->isVisible()) { dialog->raise(); dialog->activateWindow(); @@ -325,16 +305,16 @@ void QPathEdit::showDialog() } QString oldPath = edit->text(); - if(oldPath.isEmpty()) + if(oldPath.isEmpty()) { dialog->setDirectory(defaultDir); - else { - if(mode == ExistingFolder) + } else { + if(mode == ExistingFolder) { dialog->setDirectory(oldPath); - else { + } else { QFileInfo info(oldPath); - if(info.isDir()) + if(info.isDir()) { dialog->setDirectory(oldPath); - else { + } else { dialog->setDirectory(info.dir()); dialog->selectFile(info.fileName()); } @@ -344,9 +324,9 @@ void QPathEdit::showDialog() dialog->open(); } -void QPathEdit::updateValidInfo(const QString &path) -{ - completerModel->index(QFileInfo(path).dir().absolutePath());//enforce "directory loading" +void QPathEdit::updateValidInfo(const QString &path) { + // enforce "directory loading" + completerModel->index(QFileInfo(path).dir().absolutePath()); if(edit->hasAcceptableInput()) { if(!wasPathValid) { wasPathValid = true; @@ -362,10 +342,10 @@ void QPathEdit::updateValidInfo(const QString &path) } } -void QPathEdit::editTextUpdate() -{ +void QPathEdit::editTextUpdate() { if(edit->hasAcceptableInput()) { - QString newPath = edit->text().replace(QStringLiteral("\\"), QStringLiteral("/")); + QString newPath = edit->text() + .replace(QStringLiteral("\\"), QStringLiteral("/")); if(currentValidPath != newPath) { currentValidPath = newPath; emit pathChanged(currentValidPath); @@ -373,83 +353,81 @@ void QPathEdit::editTextUpdate() } } -void QPathEdit::dialogFileSelected(const QString &file) -{ +void QPathEdit::dialogFileSelected(const QString &file) { if(!file.isEmpty()) { - edit->setText(dialog->selectedFiles() - .first() - .replace(QStringLiteral("\\"), QStringLiteral("/"))); + QStringList files = dialog->selectedFiles(); + edit->setText(files.first() + .replace(QStringLiteral("\\"), + QStringLiteral("/"))); editTextUpdate(); } } -QStringList QPathEdit::modelFilters(const QStringList &normalFilters) -{ +QStringList QPathEdit::modelFilters(const QStringList &normalFilters) { QStringList res; - foreach(QString filter, normalFilters) { - QRegularExpressionMatch match = QRegularExpression(QStringLiteral("^.*\\((.*)\\)$")) - .match(filter); - if(match.hasMatch()) - res.append(match.captured(1).split(QRegularExpression(QStringLiteral("\\s")))); + static QRegularExpression re = QRegularExpression("^.*\\((.*)\\)$"); + static QRegularExpression re2 = QRegularExpression("\\s"); + foreach(QString filter, normalFilters) { + QRegularExpressionMatch match = re.match(filter); + if(match.hasMatch()) { + res.append(match.captured(1).split(re2)); + } } return res; } -QIcon QPathEdit::getDefaultIcon() -{ +QIcon QPathEdit::getDefaultIcon() { switch(uiStyle) { - case SeperatedButton: { - QImage image(16, 16, QImage::Format_ARGB32); - image.fill(Qt::transparent); - QPainter painter(&image); - painter.setFont(font()); - painter.setPen(palette().color(QPalette::ButtonText)); - painter.drawText(QRect(0, 0, 16, 16), Qt::AlignCenter, "…"); - return QPixmap::fromImage(image); - } - case JoinedButton: - return QIcon(QStringLiteral(":/qpathedit/icons/dialog.ico")); - case NoButton: - return QIcon(); - default: - Q_UNREACHABLE(); + case SeperatedButton: { + QImage image(16, 16, QImage::Format_ARGB32); + image.fill(Qt::transparent); + QPainter painter(&image); + painter.setFont(font()); + painter.setPen(palette().color(QPalette::ButtonText)); + painter.drawText(QRect(0, 0, 16, 16), Qt::AlignCenter, "…"); + return QPixmap::fromImage(image); + } + case JoinedButton: + return QIcon(QStringLiteral(":/qpathedit/icons/dialog.ico")); + case NoButton: + return QIcon(); + default: + Q_UNREACHABLE(); } } -bool QPathEdit::eventFilter(QObject *watched, QEvent *event) -{ +bool QPathEdit::eventFilter(QObject *watched, QEvent *event) { if (event->type() == QEvent::KeyPress){ QKeyEvent *keyEvent = static_cast(event); if(keyEvent->key() == Qt::Key_Space && keyEvent->modifiers() == Qt::ControlModifier){ pathCompleter->complete(); return true; - } else + } else { return QObject::eventFilter(watched, event); - } else + } + } else { return QObject::eventFilter(watched, event); + } } //HELPER CLASSES IMPLEMENTATION -PathValidator::PathValidator(QObject *parent) : - QValidator(parent), - mode(QPathEdit::ExistingFile), - allowEmpty(true) -{} +PathValidator::PathValidator(QObject *parent) + : QValidator(parent) + , mode(QPathEdit::ExistingFile) + , allowEmpty(true) { +} -void PathValidator::setMode(QPathEdit::PathMode mode) -{ - this->mode = mode; +void PathValidator::setMode(QPathEdit::PathMode _mode) { + mode = _mode; } -void PathValidator::setAllowEmpty(bool allow) -{ +void PathValidator::setAllowEmpty(bool allow) { allowEmpty = allow; } -QValidator::State PathValidator::validate(QString &text, int &) const -{ +QValidator::State PathValidator::validate(QString &text, int &) const { //check if empty is accepted if(text.isEmpty()) return allowEmpty ? QValidator::Acceptable : QValidator::Intermediate; @@ -460,33 +438,32 @@ QValidator::State PathValidator::validate(QString &text, int &) const return QValidator::Invalid; switch(mode) { - case QPathEdit::AnyFile://acceptable, as long as it's not an directoy - if(pathInfo.isDir()) - return QValidator::Intermediate; - else - return QValidator::Acceptable; - case QPathEdit::ExistingFile://must be an existing file - if(pathInfo.exists() && pathInfo.isFile()) - return QValidator::Acceptable; - else - return QValidator::Intermediate; - case QPathEdit::ExistingFolder://must be an existing folder - if(pathInfo.exists() && pathInfo.isDir()) - return QValidator::Acceptable; - else - return QValidator::Intermediate; - default: - Q_UNREACHABLE(); + case QPathEdit::AnyFile://acceptable, as long as it's not an directoy + if(pathInfo.isDir()) + return QValidator::Intermediate; + else + return QValidator::Acceptable; + case QPathEdit::ExistingFile://must be an existing file + if(pathInfo.exists() && pathInfo.isFile()) + return QValidator::Acceptable; + else + return QValidator::Intermediate; + case QPathEdit::ExistingFolder://must be an existing folder + if(pathInfo.exists() && pathInfo.isDir()) + return QValidator::Acceptable; + else + return QValidator::Intermediate; + default: + Q_UNREACHABLE(); } return QValidator::Invalid; } -void masterDialog(QDialog *dialog) -{ +void masterDialog(QDialog *dialog) { Qt::WindowFlags flags = Qt::WindowTitleHint | - Qt::WindowSystemMenuHint | - Qt::WindowCloseButtonHint; + Qt::WindowSystemMenuHint | + Qt::WindowCloseButtonHint; dialog->setSizeGripEnabled(true); if(dialog->parentWidget()) { diff --git a/src/resourcemodel.cpp b/src/resourcemodel.cpp index af4d465..2a67f9d 100644 --- a/src/resourcemodel.cpp +++ b/src/resourcemodel.cpp @@ -56,7 +56,7 @@ FSSResourceModel::headerData(int section, QModelIndex FSSResourceModel::index(int row, int column, - const QModelIndex &parent) const { + const QModelIndex &parent) const { if (parent.isValid()) { return createIndex(row, column, ((row+1) << 16) | @@ -68,7 +68,7 @@ FSSResourceModel::index(int row, int column, QModelIndex FSSResourceModel::parent(const QModelIndex &index) const { - int sub_row = index.internalId() >> 16; + int sub_row = (int)(index.internalId() >> 16); if (sub_row == 0) { return QModelIndex(); } diff --git a/src/resourceview.cpp b/src/resourceview.cpp index cd62653..4e2eb73 100644 --- a/src/resourceview.cpp +++ b/src/resourceview.cpp @@ -35,8 +35,7 @@ #include "src/animationview.h" #include "src/colorlabel.h" -FSSResourceView::FSSResourceView(PDataSource source, - QWidget *parent) +FSSResourceView::FSSResourceView(Data::PSource source, QWidget *parent) : QWidget(parent) { theSource = source; @@ -67,8 +66,10 @@ FSSResourceView::FSSResourceView(PDataSource source, resourcesStack->addWidget(viewAnimation); QToolBar *toolBar = new QToolBar(this); - toolBar->addAction(QIcon(":/icons/Actions-document-save-as-icon.png"), "Save", this, &FSSResourceView::on_save); - toolBar->addAction(QIcon(":/icons/Actions-edit-paste-icon.png"), "Copy", this, &FSSResourceView::on_copy); + toolBar->addAction(QIcon(":/icons/Actions-document-save-as-icon.png"), "Save", + this, &FSSResourceView::on_save); + toolBar->addAction(QIcon(":/icons/Actions-edit-paste-icon.png"), "Copy", + this, &FSSResourceView::on_copy); field_color = new FSSColorLabel(QColor(0x00, 0x00, 0xFF), this); field_color->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); toolBar->addWidget(field_color); @@ -83,7 +84,7 @@ FSSResourceView::~FSSResourceView() { } QString -spriteInfo(PSprite sprite) { +spriteInfo(Data::PSprite sprite) { QString str("Sprite:\n"); if (NULL != sprite) { str += "width = "; @@ -112,12 +113,12 @@ FSSResourceView::selectResource(Data::Resource resource_class, switch (Data::get_resource_type(resource_class)) { case Data::TypeSprite: { QColor c = field_color->color(); - Sprite::Color color; + Data::Sprite::Color color; color.red = c.red(); color.green = c.green(); color.blue = c.blue(); color.alpha = 0xFF; - PSprite sprite = theSource->get_sprite(resource_class, index, color); + Data::PSprite sprite = theSource->get_sprite(resource_class, index, color); viewSprite->setSprite(sprite); if (sprite) { info = spriteInfo(sprite); @@ -133,7 +134,7 @@ FSSResourceView::selectResource(Data::Resource resource_class, case Data::TypeSound: { PBuffer data = theSource->get_sound(index); if (data) { - viewAudio->setAudioData(data->get_data(), data->get_size(), "wav"); + viewAudio->setAudioData(data, "wav"); resView = viewAudio; } break; @@ -141,7 +142,7 @@ FSSResourceView::selectResource(Data::Resource resource_class, case Data::TypeMusic: { PBuffer data = theSource->get_music(index); if (data) { - viewAudio->setAudioData(data->get_data(), data->get_size(), "mid"); + viewAudio->setAudioData(data, "mid"); resView = viewAudio; } break; diff --git a/src/resourceview.h b/src/resourceview.h index 5410c36..0ae4f2e 100644 --- a/src/resourceview.h +++ b/src/resourceview.h @@ -26,7 +26,6 @@ #include "src/data.h" -class DataSource; class QTextBrowser; class FSSSpriteView; class FSSAudioView; @@ -39,7 +38,7 @@ class FSSResourceView : public QWidget { Q_OBJECT protected: - PDataSource theSource; + Data::PSource theSource; QLabel *labelName; QStackedLayout *resourcesStack; @@ -52,10 +51,10 @@ class FSSResourceView : public QWidget { QWidget *viewEmpty; public: - explicit FSSResourceView(PDataSource source, QWidget *parent = 0); + explicit FSSResourceView(Data::PSource source, QWidget *parent = 0); virtual ~FSSResourceView(); - PDataSource source() { return theSource; } + Data::PSource source() { return theSource; } public slots: void selectResource(Data::Resource resource_class, diff --git a/src/sourcesdialog.cpp b/src/sourcesdialog.cpp index edfc97d..ca2715a 100644 --- a/src/sourcesdialog.cpp +++ b/src/sourcesdialog.cpp @@ -27,7 +27,6 @@ #include #include -#include "src/data-source.h" #include "src/qpathedit.h" #include "src/datamodel.h" @@ -72,7 +71,7 @@ FSSSourcesDialog::~FSSSourcesDialog() { } void -FSSSourcesDialog::add_source(PDataSource source) { +FSSSourcesDialog::add_source(Data::PSource source) { QHBoxLayout *line_layout = new QHBoxLayout(); layout->addRow(source->get_name().c_str(), line_layout); diff --git a/src/sourcesdialog.h b/src/sourcesdialog.h index 6bc8764..8e77b00 100644 --- a/src/sourcesdialog.h +++ b/src/sourcesdialog.h @@ -24,16 +24,13 @@ #include -#include +#include "src/data.h" class QFormLayout; class QPathEdit; class FSSDataModel; -class DataSource; -typedef std::shared_ptr PDataSource; - class FSSSourcesDialog : public QDialog { Q_OBJECT @@ -46,7 +43,7 @@ class FSSSourcesDialog : public QDialog { virtual ~FSSSourcesDialog(); protected: - void add_source(PDataSource source); + void add_source(Data::PSource source); }; #endif // SRC_SOURCESDIALOG_H_ diff --git a/src/sourcesview.cpp b/src/sourcesview.cpp index cebda5a..1061ca2 100644 --- a/src/sourcesview.cpp +++ b/src/sourcesview.cpp @@ -30,14 +30,14 @@ FSSSourcesView::FSSSourcesView(QWidget *parent) } void -FSSSourcesView::addSource(PDataSource source) { +FSSSourcesView::addSource(Data::PSource source) { FSSResourceView *resView = new FSSResourceView(source, this); resView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); resView->setMinimumWidth(250); sourceViews.push_back(resView); - connect(this, SIGNAL(resourceSelected(Data::Resource, unsigned int)), - resView, SLOT(selectResource(Data::Resource, unsigned int))); + connect(this, SIGNAL(resourceSelected(Data::Resource,uint)), + resView, SLOT(selectResource(Data::Resource,uint))); } void @@ -47,14 +47,14 @@ FSSSourcesView::onResourceSelected(Data::Resource resource_class, } void -FSSSourcesView::showSource(PDataSource source, bool show) { +FSSSourcesView::showSource(Data::PSource source, bool show) { FSSResourceView *view; foreach (view, sourceViews) { if (view->source() == source) { if (show) { - view->show(); + view->show(); } else { - view->hide(); + view->hide(); } return; } diff --git a/src/sourcesview.h b/src/sourcesview.h index 1e85979..c33be2f 100644 --- a/src/sourcesview.h +++ b/src/sourcesview.h @@ -42,9 +42,9 @@ class FSSSourcesView : public QSplitter { void resourceSelected(Data::Resource resource_class, unsigned int index); public slots: - void addSource(PDataSource source); + void addSource(Data::PSource source); void onResourceSelected(Data::Resource resource_class, unsigned int index); - void showSource(PDataSource source, bool show); + void showSource(Data::PSource source, bool show); }; #endif // SRC_SOURCESVIEW_H_ diff --git a/src/spriteview.cpp b/src/spriteview.cpp index aa78728..744df19 100644 --- a/src/spriteview.cpp +++ b/src/spriteview.cpp @@ -77,7 +77,7 @@ FSSSpriteView::~FSSSpriteView() { } void -FSSSpriteView::setSprite(PSprite _sprite) { +FSSSpriteView::setSprite(Data::PSprite _sprite) { sprite = _sprite; labelImage->setBackgroundRole(QPalette::LinkVisited); @@ -107,7 +107,7 @@ FSSSpriteView::getImage() { } QImage image(reinterpret_cast(sprite->get_data()), - sprite->get_width(), sprite->get_height(), + (int)sprite->get_width(), (int)sprite->get_height(), QImage::Format_ARGB32); return image; @@ -151,7 +151,8 @@ FSSSpriteView::save() { return; } - QString path = QFileDialog::getSaveFileName(this, "Save sprite", QString(), "Image File (*.png)"); + QString path = QFileDialog::getSaveFileName(this, "Save sprite", + QString(), "Image File (*.png)"); if (path.isEmpty()) { return; } diff --git a/src/spriteview.h b/src/spriteview.h index 682b649..f7a06e6 100644 --- a/src/spriteview.h +++ b/src/spriteview.h @@ -26,7 +26,7 @@ #include #include -#include "src/data-source.h" +#include "src/data.h" class FSSClickableLabel : public QLabel { Q_OBJECT @@ -36,7 +36,7 @@ class FSSClickableLabel : public QLabel { QTimer click_timer; public: - explicit FSSClickableLabel(QWidget *pParent = NULL); + explicit FSSClickableLabel(QWidget *pParent = nullptr); virtual ~FSSClickableLabel(); protected: @@ -54,14 +54,14 @@ class FSSSpriteView : public QScrollArea { Q_OBJECT protected: - PSprite sprite; + Data::PSprite sprite; FSSClickableLabel *labelImage; public: - explicit FSSSpriteView(QWidget *pParent = NULL); + explicit FSSSpriteView(QWidget *pParent = nullptr); virtual ~FSSSpriteView(); - void setSprite(PSprite sprite); + void setSprite(Data::PSprite sprite); protected: QImage getImage();