1 Commits

Author SHA1 Message Date
9296faf0ff mac menu 2025-01-08 19:13:31 +08:00
71 changed files with 6418 additions and 8254 deletions

View File

@ -1,3 +0,0 @@
# .git-blame-ignore-revs
# CR LF to LF
ed5a6023326fd2ab420ded76976501be33e0b389

5
.gitattributes vendored
View File

@ -1,5 +0,0 @@
*.txt text eol=lf
*.cpp text eol=lf
*.h text eol=lf
*.ui text eol=lf
*.qml text eol=lf

View File

@ -12,7 +12,7 @@ jobs:
- name: Install Qt - name: Install Qt
uses: jurplel/install-qt-action@v4 uses: jurplel/install-qt-action@v4
with: with:
version: '6.9.1' version: '6.8.1'
modules: 'qtimageformats' modules: 'qtimageformats'
- name: Install Conan and Dependencies - name: Install Conan and Dependencies
id: conan id: conan

View File

@ -7,11 +7,9 @@ name: REUSE Compliance Check
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
reuse-compliance-check: test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - uses: actions/checkout@v4
uses: actions/checkout@v4
- name: REUSE Compliance Check - name: REUSE Compliance Check
uses: fsfe/reuse-action@v5 uses: fsfe/reuse-action@v2

View File

@ -3,6 +3,30 @@ name: Ubuntu CI
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
ubuntu-22-04-build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Get build dept.
run: |
sudo apt update
sudo apt install cmake qtbase5-dev libqt5svg5-dev qttools5-dev libexiv2-dev
- name: Build it
run: |
mkdir build
cd build
cmake ../ -DPREFER_QT_5=ON
make
cpack -G DEB
- name: Try install it
run: |
cd build
sudo apt install ./*.deb
- uses: actions/upload-artifact@v4
with:
name: ubuntu-22.04-deb-package
path: build/*.deb
ubuntu-24-04-build: ubuntu-24-04-build:
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
steps: steps:
@ -15,7 +39,7 @@ jobs:
run: | run: |
mkdir build mkdir build
cd build cd build
cmake ../ cmake ../ -DPREFER_QT_5=OFF
make make
cpack -G DEB cpack -G DEB
- name: Try install it - name: Try install it

View File

@ -8,7 +8,7 @@ jobs:
strategy: strategy:
matrix: matrix:
include: include:
- qt_ver: '6.9.1' - qt_ver: '6.8.1'
vs: '2022' vs: '2022'
aqt_arch: 'win64_msvc2022_64' aqt_arch: 'win64_msvc2022_64'
msvc_arch: 'x64' msvc_arch: 'x64'
@ -44,7 +44,7 @@ jobs:
strategy: strategy:
matrix: matrix:
include: include:
- qt_ver: '6.9.1' - qt_ver: '6.8.1'
vs: '2022' vs: '2022'
aqt_arch: 'win64_msvc2022_64' aqt_arch: 'win64_msvc2022_64'
msvc_arch: 'x64' msvc_arch: 'x64'
@ -71,52 +71,44 @@ jobs:
:: ------ dep ------ :: ------ dep ------
set CMAKE_PREFIX_PATH=%PWD%/dependencies_bin set CMAKE_PREFIX_PATH=%PWD%/dependencies_bin
mkdir dependencies_src mkdir dependencies_src
echo ::group::===== exiv2 ===== :: ===== exiv2 =====
curl -fsSL -o exiv2_bin.zip https://github.com/Exiv2/exiv2/releases/download/v0.28.5/exiv2-0.28.5-2022msvc-AMD64.zip curl -fsSL -o exiv2_bin.zip https://github.com/Exiv2/exiv2/releases/download/v0.28.3/exiv2-0.28.3-2019msvc64.zip
7z x exiv2_bin.zip -y 7z x exiv2_bin.zip -y
ren .\exiv2-0.28.5-2022msvc-AMD64 dependencies_bin ren .\exiv2-0.28.3-2019msvc64 dependencies_bin
echo ::endgroup:: :: ===== zlib =====
echo ::group::===== zlib =====
curl -fsSL -o zlib_src.zip https://zlib.net/zlib131.zip curl -fsSL -o zlib_src.zip https://zlib.net/zlib131.zip
7z x zlib_src.zip -y -o"dependencies_src" 7z x zlib_src.zip -y -o"dependencies_src"
ren .\dependencies_src\zlib-1.3.1 zlib || goto :error ren .\dependencies_src\zlib-1.3.1 zlib || goto :error
cmake ./dependencies_src/zlib -Bbuild_dependencies/zlib -DCMAKE_INSTALL_PREFIX="dependencies_bin" || goto :error cmake ./dependencies_src/zlib -Bbuild_dependencies/zlib -DCMAKE_INSTALL_PREFIX="dependencies_bin" || goto :error
cmake --build build_dependencies/zlib --config Release --target=install || goto :error cmake --build build_dependencies/zlib --config Release --target=install || goto :error
curl -fsSL -o expat_src.zip https://github.com/libexpat/libexpat/archive/R_2_6_2.zip curl -fsSL -o expat_src.zip https://github.com/libexpat/libexpat/archive/R_2_6_2.zip
echo ::endgroup:: :: ===== AOM for libavif AVI decoding support =====
echo ::group::===== AOM for libavif AVI decoding support ===== git clone -q -b v3.10.0 --depth 1 https://aomedia.googlesource.com/aom dependencies_src/aom
git clone -q -b v3.12.0 --depth 1 https://aomedia.googlesource.com/aom dependencies_src/aom
cmake ./dependencies_src/aom -Bbuild_dependencies/aom -DCMAKE_INSTALL_PREFIX="dependencies_bin" -DENABLE_DOCS=OFF -DBUILD_SHARED_LIBS=ON -DAOM_TARGET_CPU=generic -DENABLE_TESTS=OFF -DENABLE_TESTDATA=OFF -DENABLE_TOOLS=OFF -DENABLE_EXAMPLES=0 || goto :error cmake ./dependencies_src/aom -Bbuild_dependencies/aom -DCMAKE_INSTALL_PREFIX="dependencies_bin" -DENABLE_DOCS=OFF -DBUILD_SHARED_LIBS=ON -DAOM_TARGET_CPU=generic -DENABLE_TESTS=OFF -DENABLE_TESTDATA=OFF -DENABLE_TOOLS=OFF -DENABLE_EXAMPLES=0 || goto :error
cmake --build build_dependencies/aom --config Release --target=install || goto :error cmake --build build_dependencies/aom --config Release --target=install || goto :error
echo ::endgroup:: :: ===== libavif =====
echo ::group::===== libavif ===== curl -fsSL -o libavif-v1_1_1.zip https://github.com/AOMediaCodec/libavif/archive/v1.1.1.zip
curl -fsSL -o libavif-v1_2_1.zip https://github.com/AOMediaCodec/libavif/archive/v1.2.1.zip 7z x libavif-v1_1_1.zip -y -o"dependencies_src"
7z x libavif-v1_2_1.zip -y -o"dependencies_src" ren .\dependencies_src\libavif-1.1.1 libavif || goto :error
ren .\dependencies_src\libavif-1.2.1 libavif || goto :error cmake ./dependencies_src/libavif -Bbuild_dependencies/libavif -DCMAKE_INSTALL_PREFIX="dependencies_bin" -DAVIF_CODEC_AOM=ON -DAVIF_LOCAL_LIBYUV=ON
cmake ./dependencies_src/libavif -Bbuild_dependencies/libavif -DCMAKE_INSTALL_PREFIX="dependencies_bin" -DAVIF_CODEC_AOM=ON -DAVIF_LIBYUV=LOCAL
cmake --build build_dependencies/libavif --config Release --target=install || goto :error cmake --build build_dependencies/libavif --config Release --target=install || goto :error
echo ::endgroup:: :: ===== expat =====
echo ::group::===== expat =====
7z x expat_src.zip -y -o"dependencies_src" 7z x expat_src.zip -y -o"dependencies_src"
ren .\dependencies_src\libexpat-R_2_6_2 expat || goto :error ren .\dependencies_src\libexpat-R_2_6_2 expat || goto :error
cmake ./dependencies_src/expat/expat -Bbuild_dependencies/expat -DCMAKE_INSTALL_PREFIX="dependencies_bin" || goto :error cmake ./dependencies_src/expat/expat -Bbuild_dependencies/expat -DCMAKE_INSTALL_PREFIX="dependencies_bin" || goto :error
cmake --build build_dependencies/expat --config Release --target=install || goto :error cmake --build build_dependencies/expat --config Release --target=install || goto :error
echo ::endgroup:: :: ===== ECM =====
echo ::group::===== ECM =====
git clone -q https://invent.kde.org/frameworks/extra-cmake-modules.git dependencies_src/extra-cmake-modules git clone -q https://invent.kde.org/frameworks/extra-cmake-modules.git dependencies_src/extra-cmake-modules
cmake .\dependencies_src\extra-cmake-modules -Bbuild_dependencies/extra-cmake-modules -DCMAKE_INSTALL_PREFIX="dependencies_bin" -DBUILD_TESTING=OFF || goto :error cmake .\dependencies_src\extra-cmake-modules -Bbuild_dependencies/extra-cmake-modules -DCMAKE_INSTALL_PREFIX="dependencies_bin" -DBUILD_TESTING=OFF || goto :error
cmake --build build_dependencies/extra-cmake-modules --config Release --target=install || goto :error cmake --build build_dependencies/extra-cmake-modules --config Release --target=install || goto :error
echo ::endgroup:: :: ===== KArchive =====
echo ::group::===== KArchive =====
git clone -q https://invent.kde.org/frameworks/karchive.git dependencies_src/karchive git clone -q https://invent.kde.org/frameworks/karchive.git dependencies_src/karchive
cmake .\dependencies_src\karchive -Bbuild_dependencies/karchive -DBUILD_TESTING=OFF -DWITH_LIBZSTD=OFF -DWITH_BZIP2=OFF -DWITH_LIBLZMA=OFF -DCMAKE_INSTALL_PREFIX="dependencies_bin" || goto :error cmake .\dependencies_src\karchive -Bbuild_dependencies/karchive -DWITH_LIBZSTD=OFF -DWITH_BZIP2=OFF -DWITH_LIBLZMA=OFF -DCMAKE_INSTALL_PREFIX="dependencies_bin" || goto :error
cmake --build build_dependencies/karchive --config Release --target=install || goto :error cmake --build build_dependencies/karchive --config Release --target=install || goto :error
echo ::endgroup:: :: ===== KImageFormats =====
echo ::group::===== KImageFormats =====
git clone -q https://invent.kde.org/frameworks/kimageformats.git dependencies_src/kimageformats git clone -q https://invent.kde.org/frameworks/kimageformats.git dependencies_src/kimageformats
cmake .\dependencies_src\kimageformats -Bbuild_dependencies/kimageformats -DKDE_INSTALL_QTPLUGINDIR=%QT_ROOT_DIR%\plugins || goto :error cmake .\dependencies_src\kimageformats -Bbuild_dependencies/kimageformats -DKDE_INSTALL_QTPLUGINDIR=%QT_ROOT_DIR%\plugins || goto :error
cmake --build build_dependencies/kimageformats --config Release --target=install || goto :error cmake --build build_dependencies/kimageformats --config Release --target=install || goto :error
echo ::endgroup::
:: ------ app ------ :: ------ app ------
cmake -Bbuild . -DCMAKE_INSTALL_PREFIX="%PWD%\build\" cmake -Bbuild . -DCMAKE_INSTALL_PREFIX="%PWD%\build\"
cmake --build build --config Release cmake --build build --config Release

2
.gitignore vendored
View File

@ -11,8 +11,6 @@
# Generic Build Dir # Generic Build Dir
[Bb]uild/ [Bb]uild/
cmake-build-*/
# IDE/Editor config folders # IDE/Editor config folders
.vscode/ .vscode/
.idea/

28
.reuse/dep5 Normal file
View File

@ -0,0 +1,28 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Pineapple Pictures
Source: https://github.com/BLumia/pineapple-pictures
# Config files
Files: .gitignore appveyor.yml .github/*
Copyright: None
License: CC0-1.0
# README, resource files and Metadata files
Files: README*.md NEWS assets/*.rc assets/*.qrc dist/*
Copyright: None
License: CC0-1.0
# Translation files
# See assets/plain/translators.html for a list of translators
Files: app/translations/*.ts assets/plain/translators.html
Copyright: Translators from hosted.weblate.org
License: MIT
# Assets
Files: assets/icons/*.svg
Copyright: 2022 Gary Wang
License: MIT
Files: assets/icons/app-icon.*
Copyright: 2020 Lovelyblack
License: MIT

View File

@ -1,15 +1,16 @@
# SPDX-FileCopyrightText: 2022 - 2025 Gary Wang <git@blumia.net> # SPDX-FileCopyrightText: 2022 - 2024 Gary Wang <git@blumia.net>
# #
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(pineapple-pictures VERSION 1.1.1) # don't forget to update NEWS file and AppStream metadata. project(pineapple-pictures VERSION 0.9.0) # don't forget to update NEWS file and AppStream metadata.
include(GNUInstallDirs) include (GNUInstallDirs)
include(FeatureSummary) include (FeatureSummary)
option (EXIV2_METADATA_SUPPORT "Better image metadata support via libexiv2" ON) option (EXIV2_METADATA_SUPPORT "Better image metadata support via libexiv2" ON)
option (PREFER_QT_5 "Prefer to use Qt 5" OFF)
option (TRANSLATION_RESOURCE_EMBEDDING "Embedding .qm translation files inside resource" OFF) option (TRANSLATION_RESOURCE_EMBEDDING "Embedding .qm translation files inside resource" OFF)
set (CMAKE_CXX_STANDARD 17) set (CMAKE_CXX_STANDARD 17)
@ -17,21 +18,33 @@ set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_AUTOMOC ON) set (CMAKE_AUTOMOC ON)
set (CMAKE_AUTORCC ON) set (CMAKE_AUTORCC ON)
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core) if (PREFER_QT_5)
find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core)
else ()
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
endif ()
set (QT_MINIMUM_VERSION "6.4") if (${QT_VERSION_MAJOR} EQUAL "5")
set (QT_MINIMUM_VERSION "5.15.2")
else ()
set (QT_MINIMUM_VERSION "6.4")
endif ()
find_package(Qt${QT_VERSION_MAJOR} ${QT_MINIMUM_VERSION} REQUIRED find_package(Qt${QT_VERSION_MAJOR} ${QT_MINIMUM_VERSION} REQUIRED
COMPONENTS Widgets Svg SvgWidgets LinguistTools COMPONENTS Widgets Svg LinguistTools
OPTIONAL_COMPONENTS DBus OPTIONAL_COMPONENTS DBus
) )
if (${QT_VERSION_MAJOR} EQUAL "6")
find_package(Qt${QT_DEFAULT_MAJOR_VERSION} ${QT_MINIMUM_VERSION} CONFIG REQUIRED SvgWidgets)
endif ()
if (EXIV2_METADATA_SUPPORT) if (EXIV2_METADATA_SUPPORT)
find_package(exiv2) find_package(Exiv2)
set_package_properties(exiv2 PROPERTIES set_package_properties(Exiv2 PROPERTIES
URL "https://www.exiv2.org" URL "https://www.exiv2.org"
DESCRIPTION "image metadata support" DESCRIPTION "image metadata support"
TYPE RECOMMENDED TYPE OPTIONAL
PURPOSE "Bring better image metadata support" PURPOSE "Bring better image metadata support"
) )
endif () endif ()
@ -104,36 +117,37 @@ add_executable (${EXE_NAME}
${PPIC_RC_FILES} ${PPIC_RC_FILES}
) )
set(ADD_TRANSLATIONS_ADDITIONAL_ARGS) if (${QT_VERSION_MAJOR} EQUAL "6")
if (TRANSLATION_RESOURCE_EMBEDDING)
if (Qt6_VERSION VERSION_GREATER_EQUAL "6.9.0") qt_add_translations(${EXE_NAME} TS_FILES ${PPIC_TS_FILES})
set(ADD_TRANSLATIONS_ADDITIONAL_ARGS MERGE_QT_TRANSLATIONS) else()
endif() qt_add_translations(${EXE_NAME} TS_FILES ${PPIC_TS_FILES} QM_FILES_OUTPUT_VARIABLE PPIC_QM_FILES)
endif()
if (TRANSLATION_RESOURCE_EMBEDDING)
qt_add_translations(${EXE_NAME} ${ADD_TRANSLATIONS_ADDITIONAL_ARGS} TS_FILES ${PPIC_TS_FILES})
else() else()
qt_add_translations(${EXE_NAME} ${ADD_TRANSLATIONS_ADDITIONAL_ARGS} TS_FILES ${PPIC_TS_FILES} QM_FILES_OUTPUT_VARIABLE PPIC_QM_FILES) qt_create_translation(PPIC_QM_FILES ${PPIC_CPP_FILES_FOR_I18N} ${PPIC_TS_FILES})
endif() endif()
target_sources(${EXE_NAME} PRIVATE ${PPIC_QM_FILES}) target_sources(${EXE_NAME} PRIVATE ${PPIC_QM_FILES})
target_link_libraries (${EXE_NAME} Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Svg Qt${QT_VERSION_MAJOR}::SvgWidgets) target_link_libraries (${EXE_NAME} Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Svg)
if (${QT_VERSION_MAJOR} EQUAL "6")
target_link_libraries (${EXE_NAME} Qt::SvgWidgets)
endif ()
if (exiv2_FOUND) if (Exiv2_FOUND)
if(NOT TARGET Exiv2::exiv2lib AND TARGET exiv2lib) if(NOT TARGET Exiv2::exiv2lib AND TARGET exiv2lib)
# for exiv2 0.27.x and (macOS?) conan build # for exiv2 0.27.x
add_library(Exiv2::exiv2lib ALIAS exiv2lib) add_library(Exiv2::exiv2lib ALIAS exiv2lib)
endif() endif()
target_link_libraries (${EXE_NAME} target_link_libraries (${EXE_NAME}
Exiv2::exiv2lib Exiv2::exiv2lib
) )
target_compile_definitions(${EXE_NAME} PRIVATE target_compile_definitions(${EXE_NAME} PRIVATE
HAVE_EXIV2_VERSION="${exiv2_VERSION}" HAVE_EXIV2_VERSION="${Exiv2_VERSION}"
) )
endif () endif ()
if (TARGET Qt6::DBus) if (TARGET Qt5::DBus OR TARGET Qt6::DBus)
target_link_libraries (${EXE_NAME} target_link_libraries (${EXE_NAME}
Qt${QT_VERSION_MAJOR}::DBus Qt${QT_VERSION_MAJOR}::DBus
) )

42
LICENSE
View File

@ -1,21 +1,21 @@
MIT License MIT License
Copyright (c) 2025 BLumia Copyright (c) 2025 BLumia
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.

86
NEWS
View File

@ -1,87 +1,3 @@
Version 1.1.1
~~~~~~~~~~~~~
Released: 2025-08-02
Features:
* Click dock icon should show window when it's hidden on macOS
Bugfixes:
* Ensure "Fit by Width" position the view to the beginning of the image
Miscellaneous:
* Update translations
* Update Exiv2 version for Windows binary build
Contributors:
Heimen Stoffels, VenusGirl, தமிழ்நேரம்
Version 1.1.0
~~~~~~~~~~~~~
Released: 2025-07-06
Features:
* New option to disable built-in close window animation
* New option to disable gallery looping
* Support load m3u8 as image gallery playlist
Miscellaneous:
* Drop Qt 5 support
Contributors:
Heimen Stoffels, albanobattistella, தமிழ்நேரம்
Version 1.0.0
~~~~~~~~~~~~~
Released: 2025-05-03
Features:
* Support enforces windowed mode on start-up
* Reload image automatically when current image gets updated
Bugfixes:
* Display correct text language on macOS
Miscellaneous:
* Use native text for shortcut editor's label
* Display native commandline message when possible
* Merge Qt translations into app applications as well
Contributors:
Heimen Stoffels, albanobattistella, mmahhi
Version 0.9.2
~~~~~~~~~~~~~
Released: 2025-03-05
Bugfixes:
* Refer to the right exiv2 CMake module so it can be found on Linux
Miscellaneous:
* Convert DEP5 to REUSE.toml for better REUSE compliance
* Update translations
Contributors:
Pino Toscano, TamilNeram
Version 0.9.1
~~~~~~~~~~~~~
Released: 2025-01-25
Features:
* Option to double-click to fullscreen
* Build-time option to embed translation resources
Bugfixes:
* Fix window size not adjusted when open file on macOS
* Should center window according to available screen geometry
Miscellaneous:
* Change close window bahavior on macOS
* Update translations
Contributors:
albanobattistella, Sabri Ünal
Version 0.9.0 Version 0.9.0
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
Released: 2024-12-08 Released: 2024-12-08
@ -174,7 +90,7 @@ Version 0.7.1
Released: 2023-07-08 Released: 2023-07-08
Features: Features:
* TIF and TIFF format files in the same folder will now be automatically added to the gallery * TIF and TIFF format files in the same folder will now be automatedly added to the gallery
* Built-in window resizing now also supports Linux desktop. (macOS might also works as well) * Built-in window resizing now also supports Linux desktop. (macOS might also works as well)
Bugfixes: Bugfixes:

View File

@ -21,9 +21,10 @@ Pineapple Pictures is a lightweight image viewer that allows you view JPEG, PNG,
- Archlinux AUR: [pineapple-pictures](https://aur.archlinux.org/packages/pineapple-pictures/) | [pineapple-pictures-git](https://aur.archlinux.org/packages/pineapple-pictures-git/) - Archlinux AUR: [pineapple-pictures](https://aur.archlinux.org/packages/pineapple-pictures/) | [pineapple-pictures-git](https://aur.archlinux.org/packages/pineapple-pictures-git/)
- [Itch.io Store](https://blumia.itch.io/pineapple-pictures) - [Itch.io Store](https://blumia.itch.io/pineapple-pictures)
### Maintained by contributors / certain distro's package maintainers ### Maintained by contributors / curtain distro's package maintainers
[![Packaging status](https://repology.org/badge/vertical-allrepos/pineapple-pictures.svg?columns=4)](https://repology.org/project/pineapple-pictures/versions) - Debian (since bullseye) or Ubuntu (since 21.04): `sudo apt install pineapple-pictures`
- Nix / NixOS: [pineapple-pictures](https://search.nixos.org/packages?channel=unstable&show=pineapple-pictures&from=0&size=50&sort=relevance&type=packages&query=pineapple-pictures) (maintained by @wineee)
## Help Translation! ## Help Translation!

View File

@ -16,7 +16,7 @@
### 由原作者维护 ### 由原作者维护
- [GitHub Release 页面](https://github.com/BLumia/pineapple-pictures/releases) - [GitHub Release 页面](https://github.com/BLumia/pineapple-pictures/releases) | [gitee 发布页面](https://gitee.com/blumia/pineapple-pictures/releases)
- [SourceForge](https://sourceforge.net/projects/pineapple-pictures/) - [SourceForge](https://sourceforge.net/projects/pineapple-pictures/)
- Archlinux AUR: [pineapple-pictures](https://aur.archlinux.org/packages/pineapple-pictures/) | [pineapple-pictures-git](https://aur.archlinux.org/packages/pineapple-pictures-git/) - Archlinux AUR: [pineapple-pictures](https://aur.archlinux.org/packages/pineapple-pictures/) | [pineapple-pictures-git](https://aur.archlinux.org/packages/pineapple-pictures-git/)
- [Itch.io 商店](https://blumia.itch.io/pineapple-pictures) - [Itch.io 商店](https://blumia.itch.io/pineapple-pictures)
@ -24,7 +24,8 @@
### 由贡献者/对应发行版的打包人员维护 ### 由贡献者/对应发行版的打包人员维护
[![打包状态](https://repology.org/badge/vertical-allrepos/pineapple-pictures.svg?columns=4)](https://repology.org/project/pineapple-pictures/versions) - Debian (自 bullseye 起) 或 Ubuntu (自 21.04 起): `sudo apt install pineapple-pictures`
- Nix / NixOS: [pineapple-pictures](https://search.nixos.org/packages?channel=unstable&show=pineapple-pictures&from=0&size=50&sort=relevance&type=packages&query=pineapple-pictures) (由 [@wineee](https://github.com/wineee) 维护)
## 帮助翻译! ## 帮助翻译!

View File

@ -1,33 +0,0 @@
version = 1
SPDX-PackageName = "Pineapple Pictures"
SPDX-PackageDownloadLocation = "https://github.com/BLumia/pineapple-pictures"
[[annotations]]
path = [".gitattributes", ".git-blame-ignore-revs", ".gitignore", "appveyor.yml", ".github/**"]
precedence = "aggregate"
SPDX-FileCopyrightText = "None"
SPDX-License-Identifier = "CC0-1.0"
[[annotations]]
path = ["README**.md", "NEWS", "assets/**.rc", "assets/**.qrc", "dist/**"]
precedence = "aggregate"
SPDX-FileCopyrightText = "None"
SPDX-License-Identifier = "CC0-1.0"
[[annotations]]
path = ["app/translations/**.ts", "assets/plain/translators.html"]
precedence = "aggregate"
SPDX-FileCopyrightText = "Translators from hosted.weblate.org"
SPDX-License-Identifier = "MIT"
[[annotations]]
path = "assets/icons/**.svg"
precedence = "aggregate"
SPDX-FileCopyrightText = "2022 Gary Wang"
SPDX-License-Identifier = "MIT"
[[annotations]]
path = "assets/icons/app-icon.**"
precedence = "aggregate"
SPDX-FileCopyrightText = "2020 Lovelyblack"
SPDX-License-Identifier = "MIT"

View File

@ -1,181 +1,179 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "aboutdialog.h" #include "aboutdialog.h"
#include <QAbstractButton> #include <QAbstractButton>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QTextBrowser> #include <QTextBrowser>
#include <QTabWidget> #include <QTabWidget>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QApplication> #include <QApplication>
#include <QLabel> #include <QLabel>
#include <QPushButton> #include <QPushButton>
#include <QFile> #include <QFile>
using namespace Qt::Literals::StringLiterals; AboutDialog::AboutDialog(QWidget *parent)
: QDialog(parent)
AboutDialog::AboutDialog(QWidget *parent) , m_tabWidget(new QTabWidget)
: QDialog(parent) , m_buttonBox(new QDialogButtonBox)
, m_tabWidget(new QTabWidget) , m_helpTextEdit(new QTextBrowser)
, m_buttonBox(new QDialogButtonBox) , m_aboutTextEdit(new QTextBrowser)
, m_helpTextEdit(new QTextBrowser) , m_specialThanksTextEdit(new QTextBrowser)
, m_aboutTextEdit(new QTextBrowser) , m_licenseTextEdit(new QTextBrowser)
, m_specialThanksTextEdit(new QTextBrowser) , m_3rdPartyLibsTextEdit(new QTextBrowser)
, m_licenseTextEdit(new QTextBrowser) {
, m_3rdPartyLibsTextEdit(new QTextBrowser) this->setWindowTitle(tr("About"));
{
this->setWindowTitle(tr("About")); const QStringList helpStr {
QStringLiteral("<p>%1</p>").arg(tr("Launch application with image file path as argument to load the file.")),
const QStringList helpStr { QStringLiteral("<p>%1</p>").arg(tr("Drag and drop image file onto the window is also supported.")),
u"<p>%1</p>"_s.arg(tr("Launch application with image file path as argument to load the file.")), QStringLiteral("<p>%1</p>").arg(tr("None of the operations in this application will alter the pictures on disk.")),
u"<p>%1</p>"_s.arg(tr("Drag and drop image file onto the window is also supported.")), QStringLiteral("<p>%1</p>").arg(tr("Context menu option explanation:")),
u"<p>%1</p>"_s.arg(tr("None of the operations in this application will alter the pictures on disk.")), QStringLiteral("<ul>"),
u"<p>%1</p>"_s.arg(tr("Context menu option explanation:")), // blumia: Chain two arg() here since it seems lupdate will remove one of them if we use
u"<ul>"_s, // the old `arg(QCoreApp::translate(), tr())` way, but it's worth to mention
// blumia: Chain two arg() here since it seems lupdate will remove one of them if we use // `arg(QCoreApp::translate(), this->tr())` works, but lupdate will complain about the usage.
// the old `arg(QCoreApp::translate(), tr())` way, but it's worth to mention QStringLiteral("<li><b>%1</b>:<br/>%2</li>")
// `arg(QCoreApp::translate(), this->tr())` works, but lupdate will complain about the usage. .arg(QCoreApplication::translate("MainWindow", "Stay on top"))
u"<li><b>%1</b>:<br/>%2</li>"_s .arg(tr("Make window stay on top of all other windows.")),
.arg(QCoreApplication::translate("MainWindow", "Stay on top")) QStringLiteral("<li><b>%1</b>:<br/>%2</li>")
.arg(tr("Make window stay on top of all other windows.")), .arg(QCoreApplication::translate("MainWindow", "Protected mode"))
u"<li><b>%1</b>:<br/>%2</li>"_s .arg(tr("Avoid close window accidentally. (eg. by double clicking the window)")),
.arg(QCoreApplication::translate("MainWindow", "Protected mode")) QStringLiteral("<li><b>%1</b>:<br/>%2</li>")
.arg(tr("Avoid close window accidentally. (eg. by double clicking the window)")), .arg(QCoreApplication::translate("MainWindow", "Keep transformation", "The 'transformation' means the flip/rotation status that currently applied to the image view"))
u"<li><b>%1</b>:<br/>%2</li>"_s .arg(tr("Avoid resetting the zoom/rotation/flip state that was applied to the image view when switching between images.")),
.arg(QCoreApplication::translate("MainWindow", "Keep transformation", "The 'transformation' means the flip/rotation status that currently applied to the image view")) QStringLiteral("</ul>")
.arg(tr("Avoid resetting the zoom/rotation/flip state that was applied to the image view when switching between images.")), };
u"</ul>"_s
}; const QStringList aboutStr {
QStringLiteral("<center><img width='128' height='128' src=':/icons/app-icon.svg'/><br/>"),
const QStringList aboutStr { qApp->applicationDisplayName(),
u"<center><img width='128' height='128' src=':/icons/app-icon.svg'/><br/>"_s, (QStringLiteral("<br/>") + tr("Version: %1").arg(
qApp->applicationDisplayName(), #ifdef GIT_DESCRIBE_VERSION_STRING
(u"<br/>"_s + tr("Version: %1").arg( GIT_DESCRIBE_VERSION_STRING
#ifdef GIT_DESCRIBE_VERSION_STRING #else
GIT_DESCRIBE_VERSION_STRING qApp->applicationVersion()
#else #endif // GIT_DESCRIBE_VERSION_STRING
qApp->applicationVersion() )),
#endif // GIT_DESCRIBE_VERSION_STRING QStringLiteral("<hr/>"),
)), tr("Copyright (c) %1 %2", "%1 is year, %2 is the name of copyright holder(s)")
u"<hr/>"_s, .arg(QStringLiteral("2025"), QStringLiteral("<a href='https://github.com/BLumia'>@BLumia</a>")),
tr("Copyright (c) %1 %2", "%1 is year, %2 is the name of copyright holder(s)") QStringLiteral("<br/>"),
.arg(u"2025"_s, u"<a href='https://github.com/BLumia'>@BLumia</a>"_s), tr("Logo designed by %1").arg(QStringLiteral("<a href='https://github.com/Lovelyblack'>@Lovelyblack</a>")),
u"<br/>"_s, QStringLiteral("<hr/>"),
tr("Logo designed by %1").arg(u"<a href='https://github.com/Lovelyblack'>@Lovelyblack</a>"_s), tr("Built with Qt %1 (%2)").arg(QT_VERSION_STR, QSysInfo::buildCpuArchitecture()),
u"<hr/>"_s, QStringLiteral("<br/><a href='%1'>%2</a>").arg("https://github.com/BLumia/pineapple-pictures", tr("Source code")),
tr("Built with Qt %1 (%2)").arg(QT_VERSION_STR, QSysInfo::buildCpuArchitecture()), QStringLiteral("</center>")
QStringLiteral("<br/><a href='%1'>%2</a>").arg("https://github.com/BLumia/pineapple-pictures", tr("Source code")), };
u"</center>"_s
}; QFile translaterHtml(":/plain/translators.html");
bool canOpenFile = translaterHtml.open(QIODevice::ReadOnly);
QFile translaterHtml(u":/plain/translators.html"_s); const QByteArray & translatorList = canOpenFile ? translaterHtml.readAll() : QByteArrayLiteral("");
bool canOpenFile = translaterHtml.open(QIODevice::ReadOnly);
const QByteArray & translatorList = canOpenFile ? translaterHtml.readAll() : QByteArrayLiteral(""); const QStringList specialThanksStr {
QStringLiteral("<h1 align='center'>%1</h1><a href='%2'>%3</a><p>%4</p>").arg(
const QStringList specialThanksStr { tr("Contributors"),
u"<h1 align='center'>%1</h1><a href='%2'>%3</a><p>%4</p>"_s.arg( QStringLiteral("https://github.com/BLumia/pineapple-pictures/graphs/contributors"),
tr("Contributors"), tr("List of contributors on GitHub"),
u"https://github.com/BLumia/pineapple-pictures/graphs/contributors"_s, tr("Thanks to all people who contributed to this project.")
tr("List of contributors on GitHub"), ),
tr("Thanks to all people who contributed to this project.")
), QStringLiteral("<h1 align='center'>%1</h1><p>%2</p>%3").arg(
tr("Translators"),
u"<h1 align='center'>%1</h1><p>%2</p>%3"_s.arg( tr("I would like to thank the following people who volunteered to translate this application."),
tr("Translators"), translatorList
tr("I would like to thank the following people who volunteered to translate this application."), )
translatorList };
)
}; const QStringList licenseStr {
QStringLiteral("<h1 align='center'><b>%1</b></h1>").arg(tr("Your Rights")),
const QStringList licenseStr { QStringLiteral("<p>%1</p><p>%2</p><ul><li>%3</li><li>%4</li><li>%5</li><li>%6</li></ul>").arg(
u"<h1 align='center'><b>%1</b></h1>"_s.arg(tr("Your Rights")), tr("%1 is released under the MIT License."), // %1
u"<p>%1</p><p>%2</p><ul><li>%3</li><li>%4</li><li>%5</li><li>%6</li></ul>"_s.arg( tr("This license grants people a number of freedoms:"), // %2
tr("%1 is released under the MIT License."), // %1 tr("You are free to use %1, for any purpose"), // %3
tr("This license grants people a number of freedoms:"), // %2 tr("You are free to distribute %1"), // %4
tr("You are free to use %1, for any purpose"), // %3 tr("You can study how %1 works and change it"), // %5
tr("You are free to distribute %1"), // %4 tr("You can distribute changed versions of %1") // %6
tr("You can study how %1 works and change it"), // %5 ).arg(QStringLiteral("<i>%1</i>")),
tr("You can distribute changed versions of %1") // %6 QStringLiteral("<p>%1</p>").arg(tr("The MIT license guarantees you this freedom. Nobody is ever permitted to take it away.")),
).arg(u"<i>%1</i>"_s), QStringLiteral("<hr/><pre>%2</pre>")
u"<p>%1</p>"_s.arg(tr("The MIT license guarantees you this freedom. Nobody is ever permitted to take it away.")), };
u"<hr/><pre>%2</pre>"_s
}; const QString mitLicense(QStringLiteral(R"(Expat/MIT License
const QString mitLicense(QStringLiteral(R"(Expat/MIT License Copyright (c) 2025 BLumia
Copyright (c) 2025 BLumia Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Permission is hereby granted, free of charge, to any person obtaining a copy in the Software without restriction, including without limitation the rights
of this software and associated documentation files (the "Software"), to deal to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
in the Software without restriction, including without limitation the rights copies of the Software, and to permit persons to whom the Software is
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell furnished to do so, subject to the following conditions:
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE )"));
SOFTWARE.
)")); const QStringList thirdPartyLibsStr {
QStringLiteral("<h1 align='center'><b>%1</b></h1>").arg(tr("Third-party Libraries used by %1")),
const QStringList thirdPartyLibsStr { tr("%1 is built on the following free software libraries:", "Free as in freedom"),
u"<h1 align='center'><b>%1</b></h1>"_s.arg(tr("Third-party Libraries used by %1")), QStringLiteral("<ul>"),
tr("%1 is built on the following free software libraries:", "Free as in freedom"), #ifdef HAVE_EXIV2_VERSION
u"<ul>"_s, QStringLiteral("<li><a href='%1'>%2</a>: %3</li>").arg("https://www.exiv2.org/", "Exiv2", "GPLv2"),
#ifdef HAVE_EXIV2_VERSION #endif // EXIV2_VERSION
u"<li><a href='%1'>%2</a>: %3</li>"_s.arg("https://www.exiv2.org/", "Exiv2", "GPLv2"), QStringLiteral("<li><a href='%1'>%2</a>: %3</li>").arg("https://www.qt.io/", "Qt", "GPLv2 + GPLv3 + LGPLv2.1 + LGPLv3"),
#endif // EXIV2_VERSION QStringLiteral("</ul>")
u"<li><a href='%1'>%2</a>: %3</li>"_s.arg("https://www.qt.io/", "Qt", "GPLv2 + GPLv3 + LGPLv2.1 + LGPLv3"), };
u"</ul>"_s
}; m_helpTextEdit->setText(helpStr.join('\n'));
m_helpTextEdit->setText(helpStr.join('\n')); m_aboutTextEdit->setText(aboutStr.join('\n'));
m_aboutTextEdit->setOpenExternalLinks(true);
m_aboutTextEdit->setText(aboutStr.join('\n'));
m_aboutTextEdit->setOpenExternalLinks(true); m_specialThanksTextEdit->setText(specialThanksStr.join('\n'));
m_specialThanksTextEdit->setOpenExternalLinks(true);
m_specialThanksTextEdit->setText(specialThanksStr.join('\n'));
m_specialThanksTextEdit->setOpenExternalLinks(true); m_licenseTextEdit->setText(licenseStr.join('\n').arg(qApp->applicationDisplayName(), mitLicense));
m_licenseTextEdit->setText(licenseStr.join('\n').arg(qApp->applicationDisplayName(), mitLicense)); m_3rdPartyLibsTextEdit->setText(thirdPartyLibsStr.join('\n').arg(QStringLiteral("<i>%1</i>").arg(qApp->applicationDisplayName())));
m_3rdPartyLibsTextEdit->setOpenExternalLinks(true);
m_3rdPartyLibsTextEdit->setText(thirdPartyLibsStr.join('\n').arg(u"<i>%1</i>"_s).arg(qApp->applicationDisplayName()));
m_3rdPartyLibsTextEdit->setOpenExternalLinks(true); m_tabWidget->addTab(m_helpTextEdit, tr("&Help"));
m_tabWidget->addTab(m_aboutTextEdit, tr("&About"));
m_tabWidget->addTab(m_helpTextEdit, tr("&Help")); m_tabWidget->addTab(m_specialThanksTextEdit, tr("&Special Thanks"));
m_tabWidget->addTab(m_aboutTextEdit, tr("&About")); m_tabWidget->addTab(m_licenseTextEdit, tr("&License"));
m_tabWidget->addTab(m_specialThanksTextEdit, tr("&Special Thanks")); m_tabWidget->addTab(m_3rdPartyLibsTextEdit, tr("&Third-party Libraries"));
m_tabWidget->addTab(m_licenseTextEdit, tr("&License"));
m_tabWidget->addTab(m_3rdPartyLibsTextEdit, tr("&Third-party Libraries")); m_buttonBox->setStandardButtons(QDialogButtonBox::Close);
connect(m_buttonBox, QOverload<QAbstractButton *>::of(&QDialogButtonBox::clicked), this, [this](){
m_buttonBox->setStandardButtons(QDialogButtonBox::Close); this->close();
connect(m_buttonBox, QOverload<QAbstractButton *>::of(&QDialogButtonBox::clicked), this, [this](){ });
this->close();
}); setLayout(new QVBoxLayout);
setLayout(new QVBoxLayout); layout()->addWidget(m_tabWidget);
layout()->addWidget(m_buttonBox);
layout()->addWidget(m_tabWidget);
layout()->addWidget(m_buttonBox); setMinimumSize(361, 161); // not sure why it complain "Unable to set geometry"
setWindowFlag(Qt::WindowContextHelpButtonHint, false);
setMinimumSize(361, 161); // not sure why it complain "Unable to set geometry" }
setWindowFlag(Qt::WindowContextHelpButtonHint, false);
} AboutDialog::~AboutDialog()
{
AboutDialog::~AboutDialog()
{ }
} QSize AboutDialog::sizeHint() const
{
QSize AboutDialog::sizeHint() const return QSize(520, 350);
{ }
return QSize(520, 350);
}

View File

@ -1,36 +1,36 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#ifndef ABOUTDIALOG_H #ifndef ABOUTDIALOG_H
#define ABOUTDIALOG_H #define ABOUTDIALOG_H
#include <QDialog> #include <QDialog>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QTextBrowser; class QTextBrowser;
class QTabWidget; class QTabWidget;
class QDialogButtonBox; class QDialogButtonBox;
QT_END_NAMESPACE QT_END_NAMESPACE
class AboutDialog : public QDialog class AboutDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AboutDialog(QWidget *parent = nullptr); explicit AboutDialog(QWidget *parent = nullptr);
~AboutDialog() override; ~AboutDialog() override;
QSize sizeHint() const override; QSize sizeHint() const override;
private: private:
QTabWidget * m_tabWidget = nullptr; QTabWidget * m_tabWidget = nullptr;
QDialogButtonBox * m_buttonBox = nullptr; QDialogButtonBox * m_buttonBox = nullptr;
QTextBrowser * m_helpTextEdit = nullptr; QTextBrowser * m_helpTextEdit = nullptr;
QTextBrowser * m_aboutTextEdit = nullptr; QTextBrowser * m_aboutTextEdit = nullptr;
QTextBrowser * m_specialThanksTextEdit = nullptr; QTextBrowser * m_specialThanksTextEdit = nullptr;
QTextBrowser * m_licenseTextEdit = nullptr; QTextBrowser * m_licenseTextEdit = nullptr;
QTextBrowser * m_3rdPartyLibsTextEdit = nullptr; QTextBrowser * m_3rdPartyLibsTextEdit = nullptr;
}; };
#endif // ABOUTDIALOG_H #endif // ABOUTDIALOG_H

View File

@ -1,153 +1,165 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "actionmanager.h" #include "actionmanager.h"
#include "mainwindow.h" #include "mainwindow.h"
#include <QGuiApplication> #include <QGuiApplication>
#include <QSvgRenderer> #include <QSvgRenderer>
#include <QPainter> #include <QPainter>
#define ICON_NAME(name)\ #define ICON_NAME(name)\
QStringLiteral(":/icons/" #name ".svg") QStringLiteral(":/icons/" #name ".svg")
#define ACTION_NAME(s) QStringLiteral(STRIFY(s)) #define ACTION_NAME(s) QStringLiteral(STRIFY(s))
#define STRIFY(s) #s #define STRIFY(s) #s
QIcon ActionManager::loadHidpiIcon(const QString &resp, QSize sz) ActionManager::ActionManager()
{ {
QSvgRenderer r(resp);
QPixmap pm = QPixmap(sz * qApp->devicePixelRatio()); }
pm.fill(Qt::transparent);
QPainter p(&pm); ActionManager::~ActionManager()
r.render(&p); {
pm.setDevicePixelRatio(qApp->devicePixelRatio());
return QIcon(pm); }
}
QIcon ActionManager::loadHidpiIcon(const QString &resp, QSize sz)
void ActionManager::setupAction(MainWindow *mainWindow) {
{ QSvgRenderer r(resp);
auto create_action = [] (QWidget *w, QAction **a, QString i, QString an, bool iconFromTheme = false) { QPixmap pm = QPixmap(sz * qApp->devicePixelRatio());
*a = new QAction(w); pm.fill(Qt::transparent);
if (!i.isNull()) QPainter p(&pm);
(*a)->setIcon(iconFromTheme ? QIcon::fromTheme(i) : ActionManager::loadHidpiIcon(i)); r.render(&p);
(*a)->setObjectName(an); pm.setDevicePixelRatio(qApp->devicePixelRatio());
w->addAction(*a); return QIcon(pm);
}; }
#define CREATE_NEW_ICON_ACTION(w, a, i) create_action(w, &a, ICON_NAME(i), ACTION_NAME(a))
CREATE_NEW_ICON_ACTION(mainWindow, actionActualSize, zoom-original); void ActionManager::setupAction(MainWindow *mainWindow)
CREATE_NEW_ICON_ACTION(mainWindow, actionToggleMaximize, view-fullscreen); {
CREATE_NEW_ICON_ACTION(mainWindow, actionZoomIn, zoom-in); auto create_action = [] (QWidget *w, QAction **a, QString i, QString an, bool iconFromTheme = false) {
CREATE_NEW_ICON_ACTION(mainWindow, actionZoomOut, zoom-out); *a = new QAction(w);
CREATE_NEW_ICON_ACTION(mainWindow, actionToggleCheckerboard, view-background-checkerboard); if (!i.isNull())
CREATE_NEW_ICON_ACTION(mainWindow, actionRotateClockwise, object-rotate-right); (*a)->setIcon(iconFromTheme ? QIcon::fromTheme(i) : ActionManager::loadHidpiIcon(i));
#undef CREATE_NEW_ICON_ACTION (*a)->setObjectName(an);
w->addAction(*a);
#define CREATE_NEW_ACTION(w, a) create_action(w, &a, QString(), ACTION_NAME(a)) };
#define CREATE_NEW_THEMEICON_ACTION(w, a, i) create_action(w, &a, QLatin1String(STRIFY(i)), ACTION_NAME(a), true) #define CREATE_NEW_ICON_ACTION(w, a, i) create_action(w, &a, ICON_NAME(i), ACTION_NAME(a))
CREATE_NEW_ACTION(mainWindow, actionRotateCounterClockwise); CREATE_NEW_ICON_ACTION(mainWindow, actionActualSize, zoom-original);
CREATE_NEW_ACTION(mainWindow, actionPrevPicture); CREATE_NEW_ICON_ACTION(mainWindow, actionToggleMaximize, view-fullscreen);
CREATE_NEW_ACTION(mainWindow, actionNextPicture); CREATE_NEW_ICON_ACTION(mainWindow, actionZoomIn, zoom-in);
CREATE_NEW_ICON_ACTION(mainWindow, actionZoomOut, zoom-out);
CREATE_NEW_ACTION(mainWindow, actionTogglePauseAnimation); CREATE_NEW_ICON_ACTION(mainWindow, actionToggleCheckerboard, view-background-checkerboard);
CREATE_NEW_ACTION(mainWindow, actionAnimationNextFrame); CREATE_NEW_ICON_ACTION(mainWindow, actionRotateClockwise, object-rotate-right);
#undef CREATE_NEW_ICON_ACTION
CREATE_NEW_THEMEICON_ACTION(mainWindow, actionOpen, document-open);
CREATE_NEW_ACTION(mainWindow, actionHorizontalFlip); #define CREATE_NEW_ACTION(w, a) create_action(w, &a, QString(), ACTION_NAME(a))
CREATE_NEW_ACTION(mainWindow, actionFitInView); #define CREATE_NEW_THEMEICON_ACTION(w, a, i) create_action(w, &a, QLatin1String(STRIFY(i)), ACTION_NAME(a), true)
CREATE_NEW_ACTION(mainWindow, actionFitByWidth); CREATE_NEW_ACTION(mainWindow, actionRotateCounterClockwise);
CREATE_NEW_THEMEICON_ACTION(mainWindow, actionCopyPixmap, edit-copy); CREATE_NEW_ACTION(mainWindow, actionPrevPicture);
CREATE_NEW_ACTION(mainWindow, actionCopyFilePath); CREATE_NEW_ACTION(mainWindow, actionNextPicture);
CREATE_NEW_THEMEICON_ACTION(mainWindow, actionPaste, edit-paste);
CREATE_NEW_THEMEICON_ACTION(mainWindow, actionTrash, edit-delete); CREATE_NEW_ACTION(mainWindow, actionTogglePauseAnimation);
CREATE_NEW_ACTION(mainWindow, actionToggleStayOnTop); CREATE_NEW_ACTION(mainWindow, actionAnimationNextFrame);
CREATE_NEW_ACTION(mainWindow, actionToggleProtectMode);
CREATE_NEW_ACTION(mainWindow, actionToggleAvoidResetTransform); CREATE_NEW_THEMEICON_ACTION(mainWindow, actionOpen, document-open);
CREATE_NEW_ACTION(mainWindow, actionSettings); CREATE_NEW_ACTION(mainWindow, actionHorizontalFlip);
CREATE_NEW_THEMEICON_ACTION(mainWindow, actionHelp, system-help); CREATE_NEW_ACTION(mainWindow, actionFitInView);
CREATE_NEW_THEMEICON_ACTION(mainWindow, actionLocateInFileManager, system-file-manager); CREATE_NEW_ACTION(mainWindow, actionFitByWidth);
CREATE_NEW_THEMEICON_ACTION(mainWindow, actionProperties, document-properties); CREATE_NEW_THEMEICON_ACTION(mainWindow, actionCopyPixmap, edit-copy);
CREATE_NEW_ACTION(mainWindow, actionQuitApp); CREATE_NEW_ACTION(mainWindow, actionCopyFilePath);
#undef CREATE_NEW_ACTION CREATE_NEW_THEMEICON_ACTION(mainWindow, actionPaste, edit-paste);
#undef CREATE_NEW_THEMEICON_ACTION CREATE_NEW_THEMEICON_ACTION(mainWindow, actionTrash, edit-delete);
CREATE_NEW_ACTION(mainWindow, actionToggleStayOnTop);
retranslateUi(mainWindow); CREATE_NEW_ACTION(mainWindow, actionToggleProtectMode);
CREATE_NEW_ACTION(mainWindow, actionToggleAvoidResetTransform);
QMetaObject::connectSlotsByName(mainWindow); CREATE_NEW_ACTION(mainWindow, actionSettings);
} CREATE_NEW_THEMEICON_ACTION(mainWindow, actionHelp, system-help);
CREATE_NEW_THEMEICON_ACTION(mainWindow, actionLocateInFileManager, system-file-manager);
void ActionManager::retranslateUi(MainWindow *mainWindow) CREATE_NEW_THEMEICON_ACTION(mainWindow, actionProperties, document-properties);
{ CREATE_NEW_ACTION(mainWindow, actionQuitApp);
Q_UNUSED(mainWindow); #undef CREATE_NEW_ACTION
#undef CREATE_NEW_THEMEICON_ACTION
actionOpen->setText(QCoreApplication::translate("MainWindow", "&Open...", nullptr));
actionSettings->setMenuRole(QAction::PreferencesRole);
actionActualSize->setText(QCoreApplication::translate("MainWindow", "Actual size", nullptr));
actionToggleMaximize->setText(QCoreApplication::translate("MainWindow", "Toggle maximize", nullptr)); retranslateUi(mainWindow);
actionZoomIn->setText(QCoreApplication::translate("MainWindow", "Zoom in", nullptr));
actionZoomOut->setText(QCoreApplication::translate("MainWindow", "Zoom out", nullptr)); QMetaObject::connectSlotsByName(mainWindow);
actionToggleCheckerboard->setText(QCoreApplication::translate("MainWindow", "Toggle Checkerboard", nullptr)); }
actionRotateClockwise->setText(QCoreApplication::translate("MainWindow", "Rotate right", nullptr));
actionRotateCounterClockwise->setText(QCoreApplication::translate("MainWindow", "Rotate left", nullptr)); void ActionManager::retranslateUi(MainWindow *mainWindow)
{
actionPrevPicture->setText(QCoreApplication::translate("MainWindow", "Previous image", nullptr)); Q_UNUSED(mainWindow);
actionNextPicture->setText(QCoreApplication::translate("MainWindow", "Next image", nullptr));
actionOpen->setText(QCoreApplication::translate("MainWindow", "&Open...", nullptr));
actionTogglePauseAnimation->setText(QCoreApplication::translate("MainWindow", "Pause/Resume Animation", nullptr));
actionAnimationNextFrame->setText(QCoreApplication::translate("MainWindow", "Animation Go to Next Frame", nullptr)); actionActualSize->setText(QCoreApplication::translate("MainWindow", "Actual size", nullptr));
actionToggleMaximize->setText(QCoreApplication::translate("MainWindow", "Toggle maximize", nullptr));
actionHorizontalFlip->setText(QCoreApplication::translate("MainWindow", "Flip &Horizontally", nullptr)); actionZoomIn->setText(QCoreApplication::translate("MainWindow", "Zoom in", nullptr));
actionFitInView->setText(QCoreApplication::translate("MainWindow", "Fit to view", nullptr)); actionZoomOut->setText(QCoreApplication::translate("MainWindow", "Zoom out", nullptr));
actionFitByWidth->setText(QCoreApplication::translate("MainWindow", "Fit to width", nullptr)); actionToggleCheckerboard->setText(QCoreApplication::translate("MainWindow", "Toggle Checkerboard", nullptr));
actionCopyPixmap->setText(QCoreApplication::translate("MainWindow", "Copy P&ixmap", nullptr)); actionRotateClockwise->setText(QCoreApplication::translate("MainWindow", "Rotate right", nullptr));
actionCopyFilePath->setText(QCoreApplication::translate("MainWindow", "Copy &File Path", nullptr)); actionRotateCounterClockwise->setText(QCoreApplication::translate("MainWindow", "Rotate left", nullptr));
actionPaste->setText(QCoreApplication::translate("MainWindow", "&Paste", nullptr));
actionTrash->setText(QCoreApplication::translate("MainWindow", "Move to Trash", nullptr)); actionPrevPicture->setText(QCoreApplication::translate("MainWindow", "Previous image", nullptr));
actionToggleStayOnTop->setText(QCoreApplication::translate("MainWindow", "Stay on top", nullptr)); actionNextPicture->setText(QCoreApplication::translate("MainWindow", "Next image", nullptr));
actionToggleProtectMode->setText(QCoreApplication::translate("MainWindow", "Protected mode", nullptr));
actionToggleAvoidResetTransform->setText(QCoreApplication::translate("MainWindow", "Keep transformation", "The 'transformation' means the flip/rotation status that currently applied to the image view")); actionTogglePauseAnimation->setText(QCoreApplication::translate("MainWindow", "Pause/Resume Animation", nullptr));
actionSettings->setText(QCoreApplication::translate("MainWindow", "Configure...", nullptr)); actionAnimationNextFrame->setText(QCoreApplication::translate("MainWindow", "Animation Go to Next Frame", nullptr));
actionHelp->setText(QCoreApplication::translate("MainWindow", "Help", nullptr));
#ifdef Q_OS_WIN actionHorizontalFlip->setText(QCoreApplication::translate("MainWindow", "Flip &Horizontally", nullptr));
actionLocateInFileManager->setText( actionFitInView->setText(QCoreApplication::translate("MainWindow", "Fit to view", nullptr));
QCoreApplication::translate( actionFitByWidth->setText(QCoreApplication::translate("MainWindow", "Fit to width", nullptr));
"MainWindow", "Show in File Explorer", actionCopyPixmap->setText(QCoreApplication::translate("MainWindow", "Copy P&ixmap", nullptr));
"File Explorer is the name of explorer.exe under Windows" actionCopyFilePath->setText(QCoreApplication::translate("MainWindow", "Copy &File Path", nullptr));
) actionPaste->setText(QCoreApplication::translate("MainWindow", "&Paste", nullptr));
); actionTrash->setText(QCoreApplication::translate("MainWindow", "Move to Trash", nullptr));
#else actionToggleStayOnTop->setText(QCoreApplication::translate("MainWindow", "Stay on top", nullptr));
actionLocateInFileManager->setText(QCoreApplication::translate("MainWindow", "Show in directory", nullptr)); actionToggleProtectMode->setText(QCoreApplication::translate("MainWindow", "Protected mode", nullptr));
#endif // Q_OS_WIN actionToggleAvoidResetTransform->setText(QCoreApplication::translate("MainWindow", "Keep transformation", "The 'transformation' means the flip/rotation status that currently applied to the image view"));
actionProperties->setText(QCoreApplication::translate("MainWindow", "Properties", nullptr)); actionSettings->setText(QCoreApplication::translate("MainWindow", "Configure...", nullptr));
actionQuitApp->setText(QCoreApplication::translate("MainWindow", "Quit", nullptr)); actionHelp->setText(QCoreApplication::translate("MainWindow", "Help", nullptr));
} #ifdef Q_OS_WIN
actionLocateInFileManager->setText(
void ActionManager::setupShortcuts() QCoreApplication::translate(
{ "MainWindow", "Show in File Explorer",
actionOpen->setShortcut(QKeySequence::Open); "File Explorer is the name of explorer.exe under Windows"
actionActualSize->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_0)); )
actionZoomIn->setShortcut(QKeySequence::ZoomIn); );
actionZoomOut->setShortcut(QKeySequence::ZoomOut); #else
actionPrevPicture->setShortcuts({ actionLocateInFileManager->setText(QCoreApplication::translate("MainWindow", "Show in directory", nullptr));
QKeySequence(Qt::Key_PageUp), #endif // Q_OS_WIN
QKeySequence(Qt::Key_Left), actionProperties->setText(QCoreApplication::translate("MainWindow", "Properties", nullptr));
}); actionQuitApp->setText(QCoreApplication::translate("MainWindow", "Quit", nullptr));
actionNextPicture->setShortcuts({ }
QKeySequence(Qt::Key_PageDown),
QKeySequence(Qt::Key_Right), void ActionManager::setupShortcuts()
}); {
actionHorizontalFlip->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R)); actionOpen->setShortcut(QKeySequence::Open);
actionCopyPixmap->setShortcut(QKeySequence::Copy); actionActualSize->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_0));
actionPaste->setShortcut(QKeySequence::Paste); actionZoomIn->setShortcut(QKeySequence::ZoomIn);
actionTrash->setShortcut(QKeySequence::Delete); actionZoomOut->setShortcut(QKeySequence::ZoomOut);
actionHelp->setShortcut(QKeySequence::HelpContents); actionPrevPicture->setShortcuts({
actionSettings->setShortcut(QKeySequence::Preferences); QKeySequence(Qt::Key_PageUp),
actionProperties->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_I)); QKeySequence(Qt::Key_Left),
actionQuitApp->setShortcuts({ });
QKeySequence(Qt::Key_Space), actionNextPicture->setShortcuts({
QKeySequence(Qt::Key_Escape) QKeySequence(Qt::Key_PageDown),
}); QKeySequence(Qt::Key_Right),
} });
actionHorizontalFlip->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R));
actionCopyPixmap->setShortcut(QKeySequence::Copy);
actionPaste->setShortcut(QKeySequence::Paste);
actionTrash->setShortcut(QKeySequence::Delete);
actionHelp->setShortcut(QKeySequence::HelpContents);
actionSettings->setShortcut(QKeySequence::Preferences);
actionProperties->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_I));
actionQuitApp->setShortcuts({
QKeySequence(Qt::Key_Space),
QKeySequence(Qt::Key_Escape)
});
}

View File

@ -1,58 +1,58 @@
// SPDX-FileCopyrightText: 2025 Gary Wang <git@blumia.net> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#ifndef ACTIONMANAGER_H #ifndef ACTIONMANAGER_H
#define ACTIONMANAGER_H #define ACTIONMANAGER_H
#include <QAction> #include <QAction>
class MainWindow; class MainWindow;
class ActionManager class ActionManager
{ {
public: public:
explicit ActionManager() = default; ActionManager();
~ActionManager() = default; ~ActionManager();
void setupAction(MainWindow * mainWindow); void setupAction(MainWindow * mainWindow);
void retranslateUi(MainWindow *MainWindow); void retranslateUi(MainWindow *MainWindow);
void setupShortcuts(); void setupShortcuts();
static QIcon loadHidpiIcon(const QString &resp, QSize sz = QSize(32, 32)); static QIcon loadHidpiIcon(const QString &resp, QSize sz = QSize(32, 32));
public: public:
QAction *actionOpen; QAction *actionOpen;
QAction *actionActualSize; QAction *actionActualSize;
QAction *actionToggleMaximize; QAction *actionToggleMaximize;
QAction *actionZoomIn; QAction *actionZoomIn;
QAction *actionZoomOut; QAction *actionZoomOut;
QAction *actionToggleCheckerboard; QAction *actionToggleCheckerboard;
QAction *actionRotateClockwise; QAction *actionRotateClockwise;
QAction *actionRotateCounterClockwise; QAction *actionRotateCounterClockwise;
QAction *actionPrevPicture; QAction *actionPrevPicture;
QAction *actionNextPicture; QAction *actionNextPicture;
QAction *actionTogglePauseAnimation; QAction *actionTogglePauseAnimation;
QAction *actionAnimationNextFrame; QAction *actionAnimationNextFrame;
QAction *actionHorizontalFlip; QAction *actionHorizontalFlip;
QAction *actionFitInView; QAction *actionFitInView;
QAction *actionFitByWidth; QAction *actionFitByWidth;
QAction *actionCopyPixmap; QAction *actionCopyPixmap;
QAction *actionCopyFilePath; QAction *actionCopyFilePath;
QAction *actionPaste; QAction *actionPaste;
QAction *actionTrash; QAction *actionTrash;
QAction *actionToggleStayOnTop; QAction *actionToggleStayOnTop;
QAction *actionToggleProtectMode; QAction *actionToggleProtectMode;
QAction *actionToggleAvoidResetTransform; QAction *actionToggleAvoidResetTransform;
QAction *actionSettings; QAction *actionSettings;
QAction *actionHelp; QAction *actionHelp;
QAction *actionLocateInFileManager; QAction *actionLocateInFileManager;
QAction *actionProperties; QAction *actionProperties;
QAction *actionQuitApp; QAction *actionQuitApp;
}; };
#endif // ACTIONMANAGER_H #endif // ACTIONMANAGER_H

View File

@ -1,57 +1,59 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "bottombuttongroup.h" #include "bottombuttongroup.h"
#include "opacityhelper.h" #include "opacityhelper.h"
#include <QToolButton> #include <functional>
#include <QVBoxLayout>
#include <QDebug> #include <QToolButton>
#include <QVBoxLayout>
BottomButtonGroup::BottomButtonGroup(const std::vector<QAction *> &actionList, QWidget *parent) #include <QDebug>
: QGroupBox (parent)
, m_opacityHelper(new OpacityHelper(this)) BottomButtonGroup::BottomButtonGroup(const std::vector<QAction *> &actionList, QWidget *parent)
{ : QGroupBox (parent)
QHBoxLayout * mainLayout = new QHBoxLayout(this); , m_opacityHelper(new OpacityHelper(this))
mainLayout->setSizeConstraint(QLayout::SetFixedSize); {
this->setLayout(mainLayout); QHBoxLayout * mainLayout = new QHBoxLayout(this);
this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); mainLayout->setSizeConstraint(QLayout::SetFixedSize);
this->setStyleSheet("BottomButtonGroup {" this->setLayout(mainLayout);
"border: 1px solid gray;" this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
"border-top-left-radius: 10px;" this->setStyleSheet("BottomButtonGroup {"
"border-top-right-radius: 10px;" "border: 1px solid gray;"
"border-style: none;" "border-top-left-radius: 10px;"
"background-color:rgba(0,0,0,120)" "border-top-right-radius: 10px;"
"}" "border-style: none;"
"QToolButton {" "background-color:rgba(0,0,0,120)"
"background:transparent;" "}"
"}" "QToolButton {"
"QToolButton:!focus {" "background:transparent;"
"border-style: none;" "}"
"}"); "QToolButton:!focus {"
"border-style: none;"
auto newActionBtn = [this](QAction * action) -> QToolButton * { "}");
QToolButton * btn = new QToolButton(this);
btn->setDefaultAction(action); auto newActionBtn = [this](QAction * action) -> QToolButton * {
btn->setIconSize(QSize(32, 32)); QToolButton * btn = new QToolButton(this);
btn->setFixedSize(40, 40); btn->setDefaultAction(action);
return btn; btn->setIconSize(QSize(32, 32));
}; btn->setFixedSize(40, 40);
return btn;
for (QAction * action : actionList) { };
addButton(newActionBtn(action));
} for (QAction * action : actionList) {
} addButton(newActionBtn(action));
}
void BottomButtonGroup::setOpacity(qreal opacity, bool animated) }
{
m_opacityHelper->setOpacity(opacity, animated); void BottomButtonGroup::setOpacity(qreal opacity, bool animated)
} {
m_opacityHelper->setOpacity(opacity, animated);
void BottomButtonGroup::addButton(QAbstractButton *button) }
{
layout()->addWidget(button); void BottomButtonGroup::addButton(QAbstractButton *button)
updateGeometry(); {
} layout()->addWidget(button);
updateGeometry();
}

View File

@ -1,27 +1,27 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#ifndef BOTTOMBUTTONGROUP_H #ifndef BOTTOMBUTTONGROUP_H
#define BOTTOMBUTTONGROUP_H #define BOTTOMBUTTONGROUP_H
#include <vector> #include <vector>
#include <QAbstractButton> #include <QAbstractButton>
#include <QGroupBox> #include <QGroupBox>
class OpacityHelper; class OpacityHelper;
class BottomButtonGroup : public QGroupBox class BottomButtonGroup : public QGroupBox
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit BottomButtonGroup(const std::vector<QAction *> & actionList, QWidget *parent = nullptr); explicit BottomButtonGroup(const std::vector<QAction *> & actionList, QWidget *parent = nullptr);
void setOpacity(qreal opacity, bool animated = true); void setOpacity(qreal opacity, bool animated = true);
void addButton(QAbstractButton *button); void addButton(QAbstractButton *button);
private: private:
OpacityHelper * m_opacityHelper; OpacityHelper * m_opacityHelper;
}; };
#endif // BOTTOMBUTTONGROUP_H #endif // BOTTOMBUTTONGROUP_H

View File

@ -1,138 +1,138 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "exiv2wrapper.h" #include "exiv2wrapper.h"
#ifdef HAVE_EXIV2_VERSION #ifdef HAVE_EXIV2_VERSION
#include <exiv2/exiv2.hpp> #include <exiv2/exiv2.hpp>
#else // HAVE_EXIV2_VERSION #else // HAVE_EXIV2_VERSION
namespace Exiv2 { namespace Exiv2 {
class Image {}; class Image {};
} }
#endif // HAVE_EXIV2_VERSION #endif // HAVE_EXIV2_VERSION
#include <sstream> #include <sstream>
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
Exiv2Wrapper::Exiv2Wrapper() Exiv2Wrapper::Exiv2Wrapper()
{ {
} }
Exiv2Wrapper::~Exiv2Wrapper() Exiv2Wrapper::~Exiv2Wrapper()
{ {
} }
#ifdef HAVE_EXIV2_VERSION // stupid AppleClang... #ifdef HAVE_EXIV2_VERSION // stupid AppleClang...
template<typename Collection, typename Iterator> template<typename Collection, typename Iterator>
void Exiv2Wrapper::cacheSection(Collection collection) void Exiv2Wrapper::cacheSection(Collection collection)
{ {
const Collection& exifData = collection; const Collection& exifData = collection;
Iterator it = exifData.begin(), end = exifData.end(); Iterator it = exifData.begin(), end = exifData.end();
for (; it != end; ++it) { for (; it != end; ++it) {
QString key = QString::fromUtf8(it->key().c_str()); QString key = QString::fromUtf8(it->key().c_str());
if (it->tagName().substr(0, 2) == "0x") continue; if (it->tagName().substr(0, 2) == "0x") continue;
// We might get exceptions like "No namespace info available for XMP prefix `Item'" // We might get exceptions like "No namespace info available for XMP prefix `Item'"
// when trying to get tagLabel() data from a Xmpdatum if the tag is not common-used. // when trying to get tagLabel() data from a Xmpdatum if the tag is not common-used.
// We don't care for those rare tags so let's just use a try-cache... // We don't care for those rare tags so let's just use a try-cache...
try { try {
QString label = QString::fromLocal8Bit(it->tagLabel().c_str()); QString label = QString::fromLocal8Bit(it->tagLabel().c_str());
std::ostringstream stream; std::ostringstream stream;
stream << *it; stream << *it;
QString value = QString::fromUtf8(stream.str().c_str()); QString value = QString::fromUtf8(stream.str().c_str());
m_metadataValue.insert(key, value); m_metadataValue.insert(key, value);
m_metadataLabel.insert(key, label); m_metadataLabel.insert(key, label);
qDebug() << key << label << value; qDebug() << key << label << value;
#if EXIV2_TEST_VERSION(0, 28, 0) #if EXIV2_TEST_VERSION(0, 28, 0)
} catch (Exiv2::Error & err) { } catch (Exiv2::Error & err) {
#else // 0.27.x #else // 0.27.x
} catch (Exiv2::AnyError & err) { } catch (Exiv2::AnyError & err) {
#endif // EXIV2_TEST_VERSION(0, 28, 0) #endif // EXIV2_TEST_VERSION(0, 28, 0)
qWarning() << "Error loading key" << key << ":" << err.what(); qWarning() << "Error loading key" << key << ":" << err.what();
} }
} }
} }
#endif // HAVE_EXIV2_VERSION #endif // HAVE_EXIV2_VERSION
bool Exiv2Wrapper::load(const QString &filePath) bool Exiv2Wrapper::load(const QString &filePath)
{ {
#ifdef HAVE_EXIV2_VERSION #ifdef HAVE_EXIV2_VERSION
QByteArray filePathByteArray = QFile::encodeName(filePath); QByteArray filePathByteArray = QFile::encodeName(filePath);
try { try {
m_exivImage.reset(Exiv2::ImageFactory::open(filePathByteArray.constData()).release()); m_exivImage.reset(Exiv2::ImageFactory::open(filePathByteArray.constData()).release());
m_exivImage->readMetadata(); m_exivImage->readMetadata();
} catch (const Exiv2::Error& error) { } catch (const Exiv2::Error& error) {
m_errMsg = QString::fromUtf8(error.what()); m_errMsg = QString::fromUtf8(error.what());
return false; return false;
} }
return true; return true;
#else // HAVE_EXIV2_VERSION #else // HAVE_EXIV2_VERSION
Q_UNUSED(filePath); Q_UNUSED(filePath);
return false; return false;
#endif // HAVE_EXIV2_VERSION #endif // HAVE_EXIV2_VERSION
} }
void Exiv2Wrapper::cacheSections() void Exiv2Wrapper::cacheSections()
{ {
#ifdef HAVE_EXIV2_VERSION #ifdef HAVE_EXIV2_VERSION
if (m_exivImage->checkMode(Exiv2::mdExif) & Exiv2::amRead) { if (m_exivImage->checkMode(Exiv2::mdExif) & Exiv2::amRead) {
cacheSection<Exiv2::ExifData, Exiv2::ExifData::const_iterator>(m_exivImage->exifData()); cacheSection<Exiv2::ExifData, Exiv2::ExifData::const_iterator>(m_exivImage->exifData());
} }
if (m_exivImage->checkMode(Exiv2::mdIptc) & Exiv2::amRead) { if (m_exivImage->checkMode(Exiv2::mdIptc) & Exiv2::amRead) {
cacheSection<Exiv2::IptcData, Exiv2::IptcData::const_iterator>(m_exivImage->iptcData()); cacheSection<Exiv2::IptcData, Exiv2::IptcData::const_iterator>(m_exivImage->iptcData());
} }
if (m_exivImage->checkMode(Exiv2::mdXmp) & Exiv2::amRead) { if (m_exivImage->checkMode(Exiv2::mdXmp) & Exiv2::amRead) {
cacheSection<Exiv2::XmpData, Exiv2::XmpData::const_iterator>(m_exivImage->xmpData()); cacheSection<Exiv2::XmpData, Exiv2::XmpData::const_iterator>(m_exivImage->xmpData());
} }
// qDebug() << m_metadataValue; // qDebug() << m_metadataValue;
// qDebug() << m_metadataLabel; // qDebug() << m_metadataLabel;
#endif // HAVE_EXIV2_VERSION #endif // HAVE_EXIV2_VERSION
} }
QString Exiv2Wrapper::comment() const QString Exiv2Wrapper::comment() const
{ {
#ifdef HAVE_EXIV2_VERSION #ifdef HAVE_EXIV2_VERSION
return m_exivImage->comment().c_str(); return m_exivImage->comment().c_str();
#else // HAVE_EXIV2_VERSION #else // HAVE_EXIV2_VERSION
return QString(); return QString();
#endif // HAVE_EXIV2_VERSION #endif // HAVE_EXIV2_VERSION
} }
QString Exiv2Wrapper::label(const QString &key) const QString Exiv2Wrapper::label(const QString &key) const
{ {
return m_metadataLabel.value(key); return m_metadataLabel.value(key);
} }
QString Exiv2Wrapper::value(const QString &key) const QString Exiv2Wrapper::value(const QString &key) const
{ {
return m_metadataValue.value(key); return m_metadataValue.value(key);
} }
QString Exiv2Wrapper::XmpValue(const QString &rawValue) QString Exiv2Wrapper::XmpValue(const QString &rawValue)
{ {
QString ignored; QString ignored;
return Exiv2Wrapper::XmpValue(rawValue, ignored); return Exiv2Wrapper::XmpValue(rawValue, ignored);
} }
QString Exiv2Wrapper::XmpValue(const QString &rawValue, QString &language) QString Exiv2Wrapper::XmpValue(const QString &rawValue, QString &language)
{ {
if (rawValue.size() > 6 && rawValue.startsWith(QLatin1String("lang=\""))) { if (rawValue.size() > 6 && rawValue.startsWith(QLatin1String("lang=\""))) {
int pos = rawValue.indexOf('"', 6); int pos = rawValue.indexOf('"', 6);
if (pos != -1) { if (pos != -1) {
language = rawValue.mid(6, pos - 6); language = rawValue.mid(6, pos - 6);
return (rawValue.mid(pos + 2)); return (rawValue.mid(pos + 2));
} }
} }
language.clear(); language.clear();
return rawValue; return rawValue;
} }

View File

@ -1,43 +1,43 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#ifndef EXIV2WRAPPER_H #ifndef EXIV2WRAPPER_H
#define EXIV2WRAPPER_H #define EXIV2WRAPPER_H
#include <memory> #include <memory>
#include <QString> #include <QString>
#include <QMap> #include <QMap>
namespace Exiv2 { namespace Exiv2 {
class Image; class Image;
} }
class Exiv2Wrapper class Exiv2Wrapper
{ {
public: public:
Exiv2Wrapper(); Exiv2Wrapper();
~Exiv2Wrapper(); ~Exiv2Wrapper();
bool load(const QString& filePath); bool load(const QString& filePath);
void cacheSections(); void cacheSections();
QString comment() const; QString comment() const;
QString label(const QString & key) const; QString label(const QString & key) const;
QString value(const QString & key) const; QString value(const QString & key) const;
static QString XmpValue(const QString &rawValue); static QString XmpValue(const QString &rawValue);
static QString XmpValue(const QString &rawValue, QString & language); static QString XmpValue(const QString &rawValue, QString & language);
private: private:
std::unique_ptr<Exiv2::Image> m_exivImage; std::unique_ptr<Exiv2::Image> m_exivImage;
QMap<QString, QString> m_metadataValue; QMap<QString, QString> m_metadataValue;
QMap<QString, QString> m_metadataLabel; QMap<QString, QString> m_metadataLabel;
QString m_errMsg; QString m_errMsg;
template<typename Collection, typename Iterator> template<typename Collection, typename Iterator>
void cacheSection(Collection collection); void cacheSection(Collection collection);
}; };
#endif // EXIV2WRAPPER_H #endif // EXIV2WRAPPER_H

View File

@ -1,136 +1,147 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// SPDX-FileCopyrightText: 2023 Tad Young <yyc12321@outlook.com> // SPDX-FileCopyrightText: 2023 Tad Young <yyc12321@outlook.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "framelesswindow.h" #include "framelesswindow.h"
#include <QMouseEvent> #include <QMouseEvent>
#include <QHoverEvent> #include <QHoverEvent>
#include <QApplication> #include <QApplication>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QWindow> #include <QWindow>
FramelessWindow::FramelessWindow(QWidget *parent) FramelessWindow::FramelessWindow(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, m_centralLayout(new QVBoxLayout(this)) , m_centralLayout(new QVBoxLayout(this))
, m_oldCursorShape(Qt::ArrowCursor) , m_oldCursorShape(Qt::ArrowCursor)
, m_oldEdges() , m_oldEdges()
{ {
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
this->setMouseTracking(true); this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint);
this->setAttribute(Qt::WA_Hover, true); #else
this->installEventFilter(this); // There is a bug in Qt 5 that will make pressing Meta+Up cause the app
// fullscreen under Windows, see QTBUG-91226 to learn more.
m_centralLayout->setContentsMargins(QMargins()); // The bug seems no longer exists in Qt 6 (I only tested it under Qt 6.3.0).
} this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
#endif // QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void FramelessWindow::setCentralWidget(QWidget *widget) this->setMouseTracking(true);
{ this->setAttribute(Qt::WA_Hover, true);
if (m_centralWidget) { this->installEventFilter(this);
m_centralLayout->removeWidget(m_centralWidget);
m_centralWidget->deleteLater(); m_centralLayout->setContentsMargins(QMargins());
} }
m_centralLayout->addWidget(widget); void FramelessWindow::setCentralWidget(QWidget *widget)
m_centralWidget = widget; {
} if (m_centralWidget) {
m_centralLayout->removeWidget(m_centralWidget);
void FramelessWindow::installResizeCapture(QObject* widget) m_centralWidget->deleteLater();
{ }
widget->installEventFilter(this);
} m_centralLayout->addWidget(widget);
m_centralWidget = widget;
bool FramelessWindow::eventFilter(QObject* o, QEvent* e) }
{
switch (e->type()) { void FramelessWindow::installResizeCapture(QObject* widget)
case QEvent::HoverMove: {
{ widget->installEventFilter(this);
QWidget* wg = qobject_cast<QWidget*>(o); }
if (wg != nullptr)
return mouseHover(static_cast<QHoverEvent*>(e), wg); bool FramelessWindow::eventFilter(QObject* o, QEvent* e)
{
break; switch (e->type()) {
} case QEvent::HoverMove:
case QEvent::MouseButtonPress: {
return mousePress(static_cast<QMouseEvent*>(e)); QWidget* wg = qobject_cast<QWidget*>(o);
} if (wg != nullptr)
return mouseHover(static_cast<QHoverEvent*>(e), wg);
return QWidget::eventFilter(o, e);
} break;
}
bool FramelessWindow::mouseHover(QHoverEvent* event, QWidget* wg) case QEvent::MouseButtonPress:
{ return mousePress(static_cast<QMouseEvent*>(e));
if (!isMaximized() && !isFullScreen()) { }
QWindow* win = window()->windowHandle();
Qt::Edges edges = this->getEdgesByPos(wg->mapToGlobal(event->oldPos()), win->frameGeometry()); return QWidget::eventFilter(o, e);
}
// backup & restore cursor shape
if (edges && !m_oldEdges) bool FramelessWindow::mouseHover(QHoverEvent* event, QWidget* wg)
// entering the edge. backup cursor shape {
m_oldCursorShape = win->cursor().shape(); if (!isMaximized() && !isFullScreen()) {
if (!edges && m_oldEdges) QWindow* win = window()->windowHandle();
// leaving the edge. restore cursor shape Qt::Edges edges = this->getEdgesByPos(wg->mapToGlobal(event->oldPos()), win->frameGeometry());
win->setCursor(m_oldCursorShape);
// backup & restore cursor shape
// save the latest edges status if (edges && !m_oldEdges)
m_oldEdges = edges; // entering the edge. backup cursor shape
m_oldCursorShape = win->cursor().shape();
// show resize cursor shape if cursor is within border if (!edges && m_oldEdges)
if (edges) { // leaving the edge. restore cursor shape
win->setCursor(this->getCursorByEdge(edges, Qt::ArrowCursor)); win->setCursor(m_oldCursorShape);
return true;
} // save the latest edges status
} m_oldEdges = edges;
return false; // show resize cursor shape if cursor is within border
} if (edges) {
win->setCursor(this->getCursorByEdge(edges, Qt::ArrowCursor));
bool FramelessWindow::mousePress(QMouseEvent* event) return true;
{ }
if (event->buttons() & Qt::LeftButton && !isMaximized() && !isFullScreen()) { }
QWindow* win = window()->windowHandle();
Qt::Edges edges = this->getEdgesByPos(event->globalPosition().toPoint(), win->frameGeometry()); return false;
if (edges) { }
win->startSystemResize(edges);
return true; bool FramelessWindow::mousePress(QMouseEvent* event)
} {
} if (event->buttons() & Qt::LeftButton && !isMaximized() && !isFullScreen()) {
QWindow* win = window()->windowHandle();
return false; #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
} Qt::Edges edges = this->getEdgesByPos(event->globalPosition().toPoint(), win->frameGeometry());
#else
Qt::CursorShape FramelessWindow::getCursorByEdge(const Qt::Edges& edges, Qt::CursorShape default_cursor) Qt::Edges edges = this->getEdgesByPos(event->globalPos(), win->frameGeometry());
{ #endif // QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if ((edges == (Qt::TopEdge | Qt::LeftEdge)) || (edges == (Qt::RightEdge | Qt::BottomEdge))) if (edges) {
return Qt::SizeFDiagCursor; win->startSystemResize(edges);
else if ((edges == (Qt::TopEdge | Qt::RightEdge)) || (edges == (Qt::LeftEdge | Qt::BottomEdge))) return true;
return Qt::SizeBDiagCursor; }
else if (edges & (Qt::TopEdge | Qt::BottomEdge)) }
return Qt::SizeVerCursor;
else if (edges & (Qt::LeftEdge | Qt::RightEdge)) return false;
return Qt::SizeHorCursor; }
else
return default_cursor; Qt::CursorShape FramelessWindow::getCursorByEdge(const Qt::Edges& edges, Qt::CursorShape default_cursor)
} {
if ((edges == (Qt::TopEdge | Qt::LeftEdge)) || (edges == (Qt::RightEdge | Qt::BottomEdge)))
Qt::Edges FramelessWindow::getEdgesByPos(const QPoint gpos, const QRect& winrect) return Qt::SizeFDiagCursor;
{ else if ((edges == (Qt::TopEdge | Qt::RightEdge)) || (edges == (Qt::LeftEdge | Qt::BottomEdge)))
const int borderWidth = 8; return Qt::SizeBDiagCursor;
Qt::Edges edges; else if (edges & (Qt::TopEdge | Qt::BottomEdge))
return Qt::SizeVerCursor;
int x = gpos.x() - winrect.x(); else if (edges & (Qt::LeftEdge | Qt::RightEdge))
int y = gpos.y() - winrect.y(); return Qt::SizeHorCursor;
else
if (x < borderWidth) return default_cursor;
edges |= Qt::LeftEdge; }
if (x > (winrect.width() - borderWidth))
edges |= Qt::RightEdge; Qt::Edges FramelessWindow::getEdgesByPos(const QPoint gpos, const QRect& winrect)
if (y < borderWidth) {
edges |= Qt::TopEdge; const int borderWidth = 8;
if (y > (winrect.height() - borderWidth)) Qt::Edges edges;
edges |= Qt::BottomEdge;
int x = gpos.x() - winrect.x();
return edges; int y = gpos.y() - winrect.y();
}
if (x < borderWidth)
edges |= Qt::LeftEdge;
if (x > (winrect.width() - borderWidth))
edges |= Qt::RightEdge;
if (y < borderWidth)
edges |= Qt::TopEdge;
if (y > (winrect.height() - borderWidth))
edges |= Qt::BottomEdge;
return edges;
}

View File

@ -1,39 +1,39 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#ifndef FRAMELESSWINDOW_H #ifndef FRAMELESSWINDOW_H
#define FRAMELESSWINDOW_H #define FRAMELESSWINDOW_H
#include <QWidget> #include <QWidget>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QVBoxLayout; class QVBoxLayout;
QT_END_NAMESPACE QT_END_NAMESPACE
class FramelessWindow : public QWidget class FramelessWindow : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit FramelessWindow(QWidget *parent = nullptr); explicit FramelessWindow(QWidget *parent = nullptr);
void setCentralWidget(QWidget * widget); void setCentralWidget(QWidget * widget);
void installResizeCapture(QObject* widget); void installResizeCapture(QObject* widget);
protected: protected:
bool eventFilter(QObject *o, QEvent *e) override; bool eventFilter(QObject *o, QEvent *e) override;
bool mouseHover(QHoverEvent* event, QWidget* wg); bool mouseHover(QHoverEvent* event, QWidget* wg);
bool mousePress(QMouseEvent* event); bool mousePress(QMouseEvent* event);
private: private:
Qt::Edges m_oldEdges; Qt::Edges m_oldEdges;
Qt::CursorShape m_oldCursorShape; Qt::CursorShape m_oldCursorShape;
Qt::CursorShape getCursorByEdge(const Qt::Edges& edges, Qt::CursorShape default_cursor); Qt::CursorShape getCursorByEdge(const Qt::Edges& edges, Qt::CursorShape default_cursor);
Qt::Edges getEdgesByPos(const QPoint pos, const QRect& winrect); Qt::Edges getEdgesByPos(const QPoint pos, const QRect& winrect);
QVBoxLayout * m_centralLayout = nullptr; QVBoxLayout * m_centralLayout = nullptr;
QWidget * m_centralWidget = nullptr; // just a pointer, doesn't take the ownership. QWidget * m_centralWidget = nullptr; // just a pointer, doesn't take the ownership.
}; };
#endif // FRAMELESSWINDOW_H #endif // FRAMELESSWINDOW_H

View File

@ -1,502 +1,367 @@
// SPDX-FileCopyrightText: 2025 Gary Wang <git@blumia.net> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "graphicsview.h" #include "graphicsview.h"
#include "graphicsscene.h" #include "graphicsscene.h"
#include "settings.h" #include "settings.h"
#include <QDebug> #include <QDebug>
#include <QMouseEvent> #include <QMouseEvent>
#include <QScrollBar> #include <QScrollBar>
#include <QMimeData> #include <QMimeData>
#include <QImageReader> #include <QImageReader>
#include <QStyleOptionGraphicsItem> #include <QStyleOptionGraphicsItem>
GraphicsView::GraphicsView(QWidget *parent) GraphicsView::GraphicsView(QWidget *parent)
: QGraphicsView (parent) : QGraphicsView (parent)
{ {
setDragMode(QGraphicsView::ScrollHandDrag); setDragMode(QGraphicsView::ScrollHandDrag);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setResizeAnchor(QGraphicsView::AnchorUnderMouse); setResizeAnchor(QGraphicsView::AnchorUnderMouse);
setTransformationAnchor(QGraphicsView::AnchorUnderMouse); setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setStyleSheet("background-color: rgba(0, 0, 0, 220);" setStyleSheet("background-color: rgba(0, 0, 0, 220);"
"border-radius: 3px;"); "border-radius: 3px;");
setAcceptDrops(false); setAcceptDrops(false);
setCheckerboardEnabled(false); setCheckerboardEnabled(false);
connect(horizontalScrollBar(), &QScrollBar::valueChanged, this, &GraphicsView::viewportRectChanged); connect(horizontalScrollBar(), &QScrollBar::valueChanged, this, &GraphicsView::viewportRectChanged);
connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &GraphicsView::viewportRectChanged); connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &GraphicsView::viewportRectChanged);
} }
void GraphicsView::showFileFromPath(const QString &filePath) void GraphicsView::showFileFromPath(const QString &filePath)
{ {
emit navigatorViewRequired(false, transform()); emit navigatorViewRequired(false, transform());
if (filePath.endsWith(".svg")) { if (filePath.endsWith(".svg")) {
showSvg(filePath); showSvg(filePath);
} else { } else {
QImageReader imageReader(filePath); QImageReader imageReader(filePath);
imageReader.setAutoTransform(true); imageReader.setAutoTransform(true);
imageReader.setDecideFormatFromContent(true); imageReader.setDecideFormatFromContent(true);
imageReader.setAllocationLimit(0); #if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
imageReader.setAllocationLimit(0);
// Since if the image format / plugin does not support this feature, imageFormat() will returns an invalid format. #endif //QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
// So we cannot use imageFormat() and check if it returns QImage::Format_Invalid to detect if we support the file.
// QImage::Format imageFormat = imageReader.imageFormat(); // Since if the image format / plugin does not support this feature, imageFormat() will returns an invalid format.
if (imageReader.format().isEmpty()) { // So we cannot use imageFormat() and check if it returns QImage::Format_Invalid to detect if we support the file.
showText(tr("File is not a valid image")); // QImage::Format imageFormat = imageReader.imageFormat();
} else if (imageReader.supportsAnimation() && imageReader.imageCount() > 1) { if (imageReader.format().isEmpty()) {
showAnimated(filePath); showText(tr("File is not a valid image"));
} else if (!imageReader.canRead()) { } else if (imageReader.supportsAnimation() && imageReader.imageCount() > 1) {
showText(tr("Image data is invalid or currently unsupported")); showAnimated(filePath);
} else { } else if (!imageReader.canRead()) {
QPixmap && pixmap = QPixmap::fromImageReader(&imageReader); showText(tr("Image data is invalid or currently unsupported"));
if (pixmap.isNull()) { } else {
showText(tr("Image data is invalid or currently unsupported")); QPixmap && pixmap = QPixmap::fromImageReader(&imageReader);
} else { if (pixmap.isNull()) {
pixmap.setDevicePixelRatio(devicePixelRatioF()); showText(tr("Image data is invalid or currently unsupported"));
showImage(pixmap); } else {
} pixmap.setDevicePixelRatio(devicePixelRatioF());
} showImage(pixmap);
} }
} }
}
void GraphicsView::showImage(const QPixmap &pixmap) }
{
resetTransform(); void GraphicsView::showImage(const QPixmap &pixmap)
scene()->showImage(pixmap); {
displayScene(); resetTransform();
} scene()->showImage(pixmap);
displayScene();
void GraphicsView::showImage(const QImage &image) }
{
resetTransform(); void GraphicsView::showImage(const QImage &image)
scene()->showImage(QPixmap::fromImage(image)); {
displayScene(); resetTransform();
} scene()->showImage(QPixmap::fromImage(image));
displayScene();
void GraphicsView::showText(const QString &text) }
{
resetTransform(); void GraphicsView::showText(const QString &text)
scene()->showText(text); {
displayScene(); resetTransform();
} scene()->showText(text);
displayScene();
void GraphicsView::showSvg(const QString &filepath) }
{
resetTransform(); void GraphicsView::showSvg(const QString &filepath)
scene()->showSvg(filepath); {
displayScene(); resetTransform();
} scene()->showSvg(filepath);
displayScene();
void GraphicsView::showAnimated(const QString &filepath) }
{
resetTransform(); void GraphicsView::showAnimated(const QString &filepath)
scene()->showAnimated(filepath); {
displayScene(); resetTransform();
} scene()->showAnimated(filepath);
displayScene();
GraphicsScene *GraphicsView::scene() const }
{
return qobject_cast<GraphicsScene*>(QGraphicsView::scene()); GraphicsScene *GraphicsView::scene() const
} {
return qobject_cast<GraphicsScene*>(QGraphicsView::scene());
void GraphicsView::setScene(GraphicsScene *scene) }
{
return QGraphicsView::setScene(scene); void GraphicsView::setScene(GraphicsScene *scene)
} {
return QGraphicsView::setScene(scene);
qreal GraphicsView::scaleFactor() const }
{
return QStyleOptionGraphicsItem::levelOfDetailFromTransform(transform()); qreal GraphicsView::scaleFactor() const
} {
return QStyleOptionGraphicsItem::levelOfDetailFromTransform(transform());
void GraphicsView::resetTransform() }
{
if (!shouldAvoidTransform()) { void GraphicsView::resetTransform()
QGraphicsView::resetTransform(); {
} if (!m_avoidResetTransform) {
} QGraphicsView::resetTransform();
}
void GraphicsView::zoomView(qreal scaleFactor) }
{
m_enableFitInView = false; void GraphicsView::zoomView(qreal scaleFactor)
m_longImageMode = false; {
scale(scaleFactor, scaleFactor); m_enableFitInView = false;
applyTransformationModeByScaleFactor(); scale(scaleFactor, scaleFactor);
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform()); applyTransformationModeByScaleFactor();
} emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform());
}
// This is always according to user's view.
// the direction of the rotation will NOT be clockwise because the y-axis points downwards. // This is always according to user's view.
void GraphicsView::rotateView(bool clockwise) // the direction of the rotation will NOT be clockwise because the y-axis points downwards.
{ void GraphicsView::rotateView(bool clockwise)
resetScale(); {
resetScale();
QTransform tf(0, clockwise ? 1 : -1, 0,
clockwise ? -1 : 1, 0, 0, QTransform tf(0, clockwise ? 1 : -1, 0,
0, 0, 1); clockwise ? -1 : 1, 0, 0,
tf = transform() * tf; 0, 0, 1);
setTransform(tf); tf = transform() * tf;
setTransform(tf);
// Apply transformation mode but don't emit navigator signal here }
// Let displayScene() handle the navigator visibility correctly
applyTransformationModeByScaleFactor(); void GraphicsView::flipView(bool horizontal)
} {
QTransform tf(horizontal ? -1 : 1, 0, 0,
void GraphicsView::flipView(bool horizontal) 0, horizontal ? 1 : -1, 0,
{ 0, 0, 1);
QTransform tf(horizontal ? -1 : 1, 0, 0, tf = transform() * tf;
0, horizontal ? 1 : -1, 0, setTransform(tf);
0, 0, 1);
tf = transform() * tf; // Ensure the navigation view is also flipped.
setTransform(tf); emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform());
}
// Ensure the navigation view is also flipped.
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform()); void GraphicsView::resetScale()
} {
setTransform(resetScale(transform()));
void GraphicsView::resetScale() applyTransformationModeByScaleFactor();
{ emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform());
setTransform(resetScale(transform())); }
applyTransformationModeByScaleFactor();
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform()); void GraphicsView::fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode)
} {
QGraphicsView::fitInView(rect, aspectRadioMode);
void GraphicsView::fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode) applyTransformationModeByScaleFactor();
{ }
QGraphicsView::fitInView(rect, aspectRadioMode);
applyTransformationModeByScaleFactor(); void GraphicsView::fitByOrientation(Qt::Orientation ori, bool scaleDownOnly)
} {
resetScale();
void GraphicsView::fitByOrientation(Qt::Orientation ori, bool scaleDownOnly)
{ QRectF viewRect = this->viewport()->rect().adjusted(2, 2, -2, -2);
resetScale(); QRectF imageRect = transform().mapRect(sceneRect());
QRectF viewRect = this->viewport()->rect(); qreal ratio;
QRectF imageRect = transform().mapRect(sceneRect());
QSize viewSize = viewRect.size().toSize(); if (ori == Qt::Horizontal) {
ratio = viewRect.width() / imageRect.width();
qreal ratio; } else {
ratio = viewRect.height() / imageRect.height();
if (ori == Qt::Horizontal) { }
// Horizontal fit means fit by width
if (scaleDownOnly && imageRect.width() <= viewSize.width()) { if (scaleDownOnly && ratio > 1) ratio = 1;
// Image width already fits, no scaling needed
ratio = 1; scale(ratio, ratio);
} else { centerOn(imageRect.top(), 0);
ratio = viewRect.width() / imageRect.width(); m_enableFitInView = false;
}
} else { applyTransformationModeByScaleFactor();
// Vertical fit means fit by height emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform());
if (scaleDownOnly && imageRect.height() <= viewSize.height()) { }
// Image height already fits, no scaling needed
ratio = 1; void GraphicsView::displayScene()
} else { {
ratio = viewRect.height() / imageRect.height(); if (m_avoidResetTransform) {
} emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform());
} return;
}
if (ratio != 1) {
scale(ratio, ratio); if (isSceneBiggerThanView()) {
} fitInView(sceneRect(), Qt::KeepAspectRatio);
}
// Position the image correctly based on orientation with rotation consideration
QRectF originalScene = sceneRect(); m_enableFitInView = true;
QTransform currentTransform = transform(); }
if (ori == Qt::Horizontal) { bool GraphicsView::isSceneBiggerThanView() const
// For horizontal fit (fit by width), position at top (for tall images) {
// Find the scene point that corresponds to the top-center of the transformed image if (!isThingSmallerThanWindowWith(transform())) {
QPointF sceneTopCenter; return true;
} else {
if (qFuzzyIsNull(currentTransform.m12()) && qFuzzyIsNull(currentTransform.m21())) { return false;
// 0° or 180° rotation }
if (currentTransform.m11() > 0 && currentTransform.m22() > 0) { }
// 0° rotation: use original top-center
sceneTopCenter = QPointF(originalScene.center().x(), originalScene.top()); // Automately do fit in view when viewport(window) smaller than image original size.
} else { void GraphicsView::setEnableAutoFitInView(bool enable)
// 180° rotation: the visual "top" is now at the scene bottom {
sceneTopCenter = QPointF(originalScene.center().x(), originalScene.bottom()); m_enableFitInView = enable;
} }
} else {
// 90/270 degree rotation: the "top" in view corresponds to left/right in scene bool GraphicsView::avoidResetTransform() const
if (currentTransform.m12() > 0) { {
// 90 degree: top in view = left in scene return m_avoidResetTransform;
sceneTopCenter = QPointF(originalScene.left(), originalScene.center().y()); }
} else {
// 270 degree: top in view = right in scene void GraphicsView::setAvoidResetTransform(bool avoidReset)
sceneTopCenter = QPointF(originalScene.right(), originalScene.center().y()); {
} m_avoidResetTransform = avoidReset;
} }
centerOn(sceneTopCenter);
} else { inline double zeroOrOne(double number)
// For vertical fit (fit by height), position at left (for wide images) {
// Find the scene point that corresponds to the left-center of the transformed image return qFuzzyIsNull(number) ? 0 : (number > 0 ? 1 : -1);
QPointF sceneLeftCenter; }
if (qFuzzyIsNull(currentTransform.m12()) && qFuzzyIsNull(currentTransform.m21())) { // Note: this only works if we only have 90 degree based rotation
// 0° or 180° rotation // and no shear/translate.
if (currentTransform.m11() > 0 && currentTransform.m22() > 0) { QTransform GraphicsView::resetScale(const QTransform & orig)
// 0° rotation: use original left-center {
sceneLeftCenter = QPointF(originalScene.left(), originalScene.center().y()); return QTransform(zeroOrOne(orig.m11()), zeroOrOne(orig.m12()),
} else { zeroOrOne(orig.m21()), zeroOrOne(orig.m22()),
// 180° rotation: the visual "left" is now at the scene right orig.dx(), orig.dy());
sceneLeftCenter = QPointF(originalScene.right(), originalScene.center().y()); }
}
} else { void GraphicsView::toggleCheckerboard(bool invertCheckerboardColor)
// 90/270 degree rotation: the "left" in view corresponds to top/bottom in scene {
if (currentTransform.m21() > 0) { setCheckerboardEnabled(!m_checkerboardEnabled, invertCheckerboardColor);
// 90 degree: left in view = top in scene }
sceneLeftCenter = QPointF(originalScene.center().x(), originalScene.top());
} else { void GraphicsView::mousePressEvent(QMouseEvent *event)
// 270 degree: left in view = bottom in scene {
sceneLeftCenter = QPointF(originalScene.center().x(), originalScene.bottom()); if (shouldIgnoreMousePressMoveEvent(event)) {
} event->ignore();
} // blumia: return here, or the QMouseEvent event transparency won't
centerOn(sceneLeftCenter); // work if we set a QGraphicsView::ScrollHandDrag drag mode.
} return;
}
m_enableFitInView = false;
return QGraphicsView::mousePressEvent(event);
applyTransformationModeByScaleFactor(); }
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform());
} void GraphicsView::mouseMoveEvent(QMouseEvent *event)
{
bool GraphicsView::isLongImage() const if (shouldIgnoreMousePressMoveEvent(event)) {
{ event->ignore();
// Get the transformed image size (considering rotation and other transforms) }
QRectF transformedRect = transform().mapRect(sceneRect());
QSizeF imageSize = transformedRect.size(); return QGraphicsView::mouseMoveEvent(event);
}
if (imageSize.isEmpty()) return false;
void GraphicsView::mouseReleaseEvent(QMouseEvent *event)
qreal aspectRatio = imageSize.width() / imageSize.height(); {
if (event->button() == Qt::ForwardButton || event->button() == Qt::BackButton) {
// Check if aspect ratio exceeds 5:2 (wide) or 2:5 (tall) event->ignore();
return aspectRatio > 2.5 || aspectRatio < 0.4; } else {
} QGraphicsItem *item = itemAt(event->pos());
if (!item) {
void GraphicsView::fitLongImage() event->ignore();
{ }
// Determine image orientation based on current transform }
QRectF transformedRect = transform().mapRect(sceneRect());
qreal aspectRatio = transformedRect.width() / transformedRect.height(); return QGraphicsView::mouseReleaseEvent(event);
bool isTallImage = aspectRatio < 0.4; }
bool isWideImage = aspectRatio > 2.5;
void GraphicsView::wheelEvent(QWheelEvent *event)
// Use fitByOrientation with the migrated logic {
if (isTallImage) { event->ignore();
// Tall image (height >> width): fit by width // blumia: no need for calling parent method.
fitByOrientation(Qt::Horizontal, true); // scaleDownOnly = true }
} else if (isWideImage) {
// Wide image (width >> height): fit by height void GraphicsView::resizeEvent(QResizeEvent *event)
fitByOrientation(Qt::Vertical, true); // scaleDownOnly = true {
} if (m_enableFitInView) {
} bool originalSizeSmallerThanWindow = isThingSmallerThanWindowWith(resetScale(transform()));
if (originalSizeSmallerThanWindow && scaleFactor() >= 1) {
void GraphicsView::displayScene() // no longer need to do fitInView()
{ // but we leave the m_enableFitInView value unchanged in case
if (shouldAvoidTransform()) { // user resize down the window again.
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform()); } else if (originalSizeSmallerThanWindow && scaleFactor() < 1) {
return; resetScale();
} } else {
fitInView(sceneRect(), Qt::KeepAspectRatio);
// Check if should apply long image mode }
if (Settings::instance()->autoLongImageMode() && isLongImage()) { } else {
m_longImageMode = true; emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform());
m_firstUserMediaLoaded = true; }
if (isSceneBiggerThanView()) fitLongImage(); return QGraphicsView::resizeEvent(event);
return; }
}
bool GraphicsView::isThingSmallerThanWindowWith(const QTransform &transform) const
if (isSceneBiggerThanView()) { {
// Do fit-in-view return rect().size().expandedTo(transform.mapRect(sceneRect()).size().toSize())
fitInView(sceneRect(), Qt::KeepAspectRatio); == rect().size();
// After fitInView, the image should fit the window, so hide navigator }
emit navigatorViewRequired(false, transform());
} else { bool GraphicsView::shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const
// Image is already smaller than window, no navigator needed {
emit navigatorViewRequired(false, transform()); if (event->buttons() == Qt::NoButton) {
} return true;
}
m_longImageMode = false;
m_enableFitInView = true; QGraphicsItem *item = itemAt(event->pos());
m_firstUserMediaLoaded = true; if (!item) {
} return true;
}
bool GraphicsView::isSceneBiggerThanView() const
{ if (isThingSmallerThanWindowWith(transform())) {
if (!isThingSmallerThanWindowWith(transform())) { return true;
return true; }
} else {
return false; return false;
} }
}
void GraphicsView::setCheckerboardEnabled(bool enabled, bool invertColor)
// Automately do fit in view when viewport(window) smaller than image original size. {
void GraphicsView::setEnableAutoFitInView(bool enable) m_checkerboardEnabled = enabled;
{ bool isLightCheckerboard = Settings::instance()->useLightCheckerboard() ^ invertColor;
m_enableFitInView = enable; if (m_checkerboardEnabled) {
} // Prepare background check-board pattern
QPixmap tilePixmap(0x20, 0x20);
void GraphicsView::setLongImageMode(bool enable) tilePixmap.fill(isLightCheckerboard ? QColor(220, 220, 220, 170) : QColor(35, 35, 35, 170));
{ QPainter tilePainter(&tilePixmap);
m_longImageMode = enable; constexpr QColor color(45, 45, 45, 170);
} constexpr QColor invertedColor(210, 210, 210, 170);
tilePainter.fillRect(0, 0, 0x10, 0x10, isLightCheckerboard ? invertedColor : color);
bool GraphicsView::avoidResetTransform() const tilePainter.fillRect(0x10, 0x10, 0x10, 0x10, isLightCheckerboard ? invertedColor : color);
{ tilePainter.end();
return m_avoidResetTransform;
} setBackgroundBrush(tilePixmap);
} else {
void GraphicsView::setAvoidResetTransform(bool avoidReset) setBackgroundBrush(Qt::transparent);
{ }
m_avoidResetTransform = avoidReset; }
}
void GraphicsView::applyTransformationModeByScaleFactor()
inline double zeroOrOne(double number) {
{ if (this->scaleFactor() < 1) {
return qFuzzyIsNull(number) ? 0 : (number > 0 ? 1 : -1); scene()->trySetTransformationMode(Qt::SmoothTransformation, this->scaleFactor());
} } else {
scene()->trySetTransformationMode(Qt::FastTransformation, this->scaleFactor());
// Note: this only works if we only have 90 degree based rotation }
// and no shear/translate. }
QTransform GraphicsView::resetScale(const QTransform & orig)
{
return QTransform(zeroOrOne(orig.m11()), zeroOrOne(orig.m12()),
zeroOrOne(orig.m21()), zeroOrOne(orig.m22()),
orig.dx(), orig.dy());
}
void GraphicsView::toggleCheckerboard(bool invertCheckerboardColor)
{
setCheckerboardEnabled(!m_checkerboardEnabled, invertCheckerboardColor);
}
void GraphicsView::mousePressEvent(QMouseEvent *event)
{
if (shouldIgnoreMousePressMoveEvent(event)) {
event->ignore();
// blumia: return here, or the QMouseEvent event transparency won't
// work if we set a QGraphicsView::ScrollHandDrag drag mode.
return;
}
return QGraphicsView::mousePressEvent(event);
}
void GraphicsView::mouseMoveEvent(QMouseEvent *event)
{
if (shouldIgnoreMousePressMoveEvent(event)) {
event->ignore();
}
return QGraphicsView::mouseMoveEvent(event);
}
void GraphicsView::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::ForwardButton || event->button() == Qt::BackButton) {
event->ignore();
} else {
QGraphicsItem *item = itemAt(event->pos());
if (!item) {
event->ignore();
}
}
return QGraphicsView::mouseReleaseEvent(event);
}
void GraphicsView::wheelEvent(QWheelEvent *event)
{
event->ignore();
// blumia: no need for calling parent method.
}
void GraphicsView::resizeEvent(QResizeEvent *event)
{
if (m_longImageMode) {
// In long image mode, reapply long image logic on resize
// We directly apply the long image mode logic without rechecking
// if we should enter long image mode, as the mode is already active
fitLongImage();
} else if (m_enableFitInView) {
bool originalSizeSmallerThanWindow = isThingSmallerThanWindowWith(resetScale(transform()));
if (originalSizeSmallerThanWindow && scaleFactor() >= 1) {
// no longer need to do fitInView()
// but we leave the m_enableFitInView value unchanged in case
// user resize down the window again.
} else if (originalSizeSmallerThanWindow && scaleFactor() < 1) {
resetScale();
} else {
fitInView(sceneRect(), Qt::KeepAspectRatio);
}
} else {
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform());
}
return QGraphicsView::resizeEvent(event);
}
bool GraphicsView::isThingSmallerThanWindowWith(const QTransform &transform) const
{
return rect().size().expandedTo(transform.mapRect(sceneRect()).size().toSize())
== rect().size();
}
bool GraphicsView::shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const
{
if (event->buttons() == Qt::NoButton) {
return true;
}
QGraphicsItem *item = itemAt(event->pos());
if (!item) {
return true;
}
if (isThingSmallerThanWindowWith(transform())) {
return true;
}
return false;
}
void GraphicsView::setCheckerboardEnabled(bool enabled, bool invertColor)
{
m_checkerboardEnabled = enabled;
bool isLightCheckerboard = Settings::instance()->useLightCheckerboard() ^ invertColor;
if (m_checkerboardEnabled) {
// Prepare background check-board pattern
QPixmap tilePixmap(0x20, 0x20);
tilePixmap.fill(isLightCheckerboard ? QColor(220, 220, 220, 170) : QColor(35, 35, 35, 170));
QPainter tilePainter(&tilePixmap);
constexpr QColor color(45, 45, 45, 170);
constexpr QColor invertedColor(210, 210, 210, 170);
tilePainter.fillRect(0, 0, 0x10, 0x10, isLightCheckerboard ? invertedColor : color);
tilePainter.fillRect(0x10, 0x10, 0x10, 0x10, isLightCheckerboard ? invertedColor : color);
tilePainter.end();
setBackgroundBrush(tilePixmap);
} else {
setBackgroundBrush(Qt::transparent);
}
}
void GraphicsView::applyTransformationModeByScaleFactor()
{
if (this->scaleFactor() < 1) {
scene()->trySetTransformationMode(Qt::SmoothTransformation, this->scaleFactor());
} else {
scene()->trySetTransformationMode(Qt::FastTransformation, this->scaleFactor());
}
}
bool GraphicsView::shouldAvoidTransform() const
{
return m_firstUserMediaLoaded && m_avoidResetTransform;
}

View File

@ -1,85 +1,76 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#ifndef GRAPHICSVIEW_H #ifndef GRAPHICSVIEW_H
#define GRAPHICSVIEW_H #define GRAPHICSVIEW_H
#include <QGraphicsView> #include <QGraphicsView>
#include <QUrl> #include <QUrl>
class GraphicsScene; class GraphicsScene;
class GraphicsView : public QGraphicsView class GraphicsView : public QGraphicsView
{ {
Q_OBJECT Q_OBJECT
public: public:
GraphicsView(QWidget *parent = nullptr); GraphicsView(QWidget *parent = nullptr);
void showFileFromPath(const QString &filePath); void showFileFromPath(const QString &filePath);
void showImage(const QPixmap &pixmap); void showImage(const QPixmap &pixmap);
void showImage(const QImage &image); void showImage(const QImage &image);
void showText(const QString &text); void showText(const QString &text);
void showSvg(const QString &filepath); void showSvg(const QString &filepath);
void showAnimated(const QString &filepath); void showAnimated(const QString &filepath);
GraphicsScene * scene() const; GraphicsScene * scene() const;
void setScene(GraphicsScene *scene); void setScene(GraphicsScene *scene);
qreal scaleFactor() const; qreal scaleFactor() const;
void resetTransform(); void resetTransform();
void zoomView(qreal scaleFactor); void zoomView(qreal scaleFactor);
void rotateView(bool clockwise = true); void rotateView(bool clockwise = true);
void flipView(bool horizontal = true); void flipView(bool horizontal = true);
void resetScale(); void resetScale();
void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio); void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
void fitByOrientation(Qt::Orientation ori = Qt::Horizontal, bool scaleDownOnly = false); void fitByOrientation(Qt::Orientation ori = Qt::Horizontal, bool scaleDownOnly = false);
void displayScene(); void displayScene();
bool isSceneBiggerThanView() const; bool isSceneBiggerThanView() const;
void setEnableAutoFitInView(bool enable = true); void setEnableAutoFitInView(bool enable = true);
void setLongImageMode(bool enable = true);
bool avoidResetTransform() const;
bool avoidResetTransform() const; void setAvoidResetTransform(bool avoidReset);
void setAvoidResetTransform(bool avoidReset);
static QTransform resetScale(const QTransform & orig);
static QTransform resetScale(const QTransform & orig);
signals:
// Long image mode support void navigatorViewRequired(bool required, QTransform transform);
bool isLongImage() const; void viewportRectChanged();
void fitLongImage();
public slots:
signals: void toggleCheckerboard(bool invertCheckerboardColor = false);
void navigatorViewRequired(bool required, QTransform transform);
void viewportRectChanged(); private:
void mousePressEvent(QMouseEvent * event) override;
public slots: void mouseMoveEvent(QMouseEvent * event) override;
void toggleCheckerboard(bool invertCheckerboardColor = false); void mouseReleaseEvent(QMouseEvent * event) override;
void wheelEvent(QWheelEvent *event) override;
private: void resizeEvent(QResizeEvent *event) override;
void mousePressEvent(QMouseEvent * event) override;
void mouseMoveEvent(QMouseEvent * event) override; bool isThingSmallerThanWindowWith(const QTransform &transform) const;
void mouseReleaseEvent(QMouseEvent * event) override; bool shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const;
void wheelEvent(QWheelEvent *event) override; void setCheckerboardEnabled(bool enabled, bool invertColor = false);
void resizeEvent(QResizeEvent *event) override; void applyTransformationModeByScaleFactor();
bool isThingSmallerThanWindowWith(const QTransform &transform) const; // Consider switch to 3 state for "no fit", "always fit" and "fit when view is smaller"?
bool shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const; // ... or even more? e.g. "fit/snap width" things...
void setCheckerboardEnabled(bool enabled, bool invertColor = false); // Currently it's "no fit" when it's false and "fit when view is smaller" when it's true.
void applyTransformationModeByScaleFactor(); bool m_enableFitInView = false;
bool m_avoidResetTransform = false;
inline bool shouldAvoidTransform() const; bool m_checkerboardEnabled = false;
bool m_useLightCheckerboard = false;
// Consider switch to 3 state for "no fit", "always fit" and "fit when view is smaller"? };
// ... or even more? e.g. "fit/snap width" things...
// Currently it's "no fit" when it's false and "fit when view is smaller" when it's true. #endif // GRAPHICSVIEW_H
bool m_enableFitInView = false;
bool m_longImageMode = false;
bool m_avoidResetTransform = false;
bool m_checkerboardEnabled = false;
bool m_useLightCheckerboard = false;
bool m_firstUserMediaLoaded = false;
};
#endif // GRAPHICSVIEW_H

View File

@ -1,103 +1,87 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "mainwindow.h" #include "mainwindow.h"
#include "playlistmanager.h" #include "playlistmanager.h"
#include "settings.h" #include "settings.h"
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
#include "fileopeneventhandler.h" #include "fileopeneventhandler.h"
#endif // Q_OS_MACOS #endif // Q_OS_MACOS
#include <QApplication> #include <QApplication>
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QDir> #include <QDir>
#include <QTranslator> #include <QTranslator>
#include <QUrl> #include <QUrl>
using namespace Qt::Literals::StringLiterals; int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) QCoreApplication::setApplicationName("Pineapple Pictures");
{ QCoreApplication::setApplicationVersion(PPIC_VERSION_STRING);
QCoreApplication::setApplicationName(u"Pineapple Pictures"_s); QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Settings::instance()->hiDpiScaleFactorBehavior());
QCoreApplication::setApplicationVersion(PPIC_VERSION_STRING);
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Settings::instance()->hiDpiScaleFactorBehavior()); QApplication a(argc, argv);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QApplication a(argc, argv); a.setAttribute(Qt::ApplicationAttribute::AA_UseHighDpiPixmaps);
#endif
QTranslator translator;
#if defined(TRANSLATION_RESOURCE_EMBEDDING) QTranslator translator;
const QString qmDir = u":/i18n/"_s; #if defined(TRANSLATION_RESOURCE_EMBEDDING)
#elif defined(QM_FILE_INSTALL_ABSOLUTE_DIR) const QString qmDir = QLatin1String(":/i18n/");
const QString qmDir = QT_STRINGIFY(QM_FILE_INSTALL_ABSOLUTE_DIR); #elif defined(QM_FILE_INSTALL_ABSOLUTE_DIR)
#else const QString qmDir = QT_STRINGIFY(QM_FILE_INSTALL_ABSOLUTE_DIR);
const QString qmDir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath("translations"); #else
#endif const QString qmDir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath("translations");
if (translator.load(QLocale(), u"PineapplePictures"_s, u"_"_s, qmDir)) { #endif
QCoreApplication::installTranslator(&translator); if (translator.load(QLocale(), QLatin1String("PineapplePictures"), QLatin1String("_"), qmDir)) {
} QCoreApplication::installTranslator(&translator);
}
QGuiApplication::setApplicationDisplayName(QCoreApplication::translate("main", "Pineapple Pictures"));
QGuiApplication::setApplicationDisplayName(QCoreApplication::translate("main", "Pineapple Pictures"));
// commandline options
QCommandLineOption supportedImageFormats(u"supported-image-formats"_s, QCoreApplication::translate("main", "List supported image format suffixes, and quit program.")); // commandline options
// parse commandline arguments QCommandLineOption supportedImageFormats(QStringLiteral("supported-image-formats"), QCoreApplication::translate("main", "List supported image format suffixes, and quit program."));
QCommandLineParser parser; // parse commandline arguments
parser.addOption(supportedImageFormats); QCommandLineParser parser;
parser.addPositionalArgument("File list", QCoreApplication::translate("main", "File list.")); parser.addOption(supportedImageFormats);
parser.addHelpOption(); parser.addPositionalArgument("File list", QCoreApplication::translate("main", "File list."));
parser.process(a); parser.addHelpOption();
parser.process(a);
if (parser.isSet(supportedImageFormats)) {
#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0) if (parser.isSet(supportedImageFormats)) {
fputs(qPrintable(MainWindow::supportedImageFormats().join(QChar('\n'))), stdout); fputs(qPrintable(MainWindow::supportedImageFormats().join(QChar('\n'))), stdout);
::exit(EXIT_SUCCESS); ::exit(EXIT_SUCCESS);
#else }
QCommandLineParser::showMessageAndExit(QCommandLineParser::MessageType::Information,
MainWindow::supportedImageFormats().join(QChar('\n'))); MainWindow w;
#endif w.show();
}
#ifdef Q_OS_MACOS
MainWindow w; FileOpenEventHandler * fileOpenEventHandler = new FileOpenEventHandler(&a);
w.show(); a.installEventFilter(fileOpenEventHandler);
a.connect(fileOpenEventHandler, &FileOpenEventHandler::fileOpen, [&w](const QUrl & url){
#ifdef Q_OS_MACOS if (w.isHidden()) {
FileOpenEventHandler * fileOpenEventHandler = new FileOpenEventHandler(&a); w.setWindowOpacity(1);
a.installEventFilter(fileOpenEventHandler); w.showNormal();
a.connect(fileOpenEventHandler, &FileOpenEventHandler::fileOpen, [&w](const QUrl & url){ } else {
if (w.isHidden()) { w.activateWindow();
w.setWindowOpacity(1); }
w.showNormal(); w.showUrls({url});
} else { w.initWindowSize();
w.activateWindow(); });
} #endif // Q_OS_MACOS
w.showUrls({url});
w.initWindowSize(); QStringList urlStrList = parser.positionalArguments();
}); QList<QUrl> && urlList = PlaylistManager::convertToUrlList(urlStrList);
// Handle dock icon clicks to show hidden window if (!urlList.isEmpty()) {
a.connect(&a, &QApplication::applicationStateChanged, [&w](Qt::ApplicationState state) { w.showUrls(urlList);
if (state == Qt::ApplicationActive && w.isHidden()) { }
w.showUrls({});
w.galleryCurrent(true, true); w.initWindowSize();
w.setWindowOpacity(1);
w.showNormal(); return QApplication::exec();
w.raise(); }
w.activateWindow();
}
});
#endif // Q_OS_MACOS
QStringList urlStrList = parser.positionalArguments();
QList<QUrl> && urlList = PlaylistManager::convertToUrlList(urlStrList);
if (!urlList.isEmpty()) {
w.showUrls(urlList);
}
w.initWindowSize();
return QApplication::exec();
}

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2025 Gary Wang <git@blumia.net> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
@ -32,25 +32,23 @@
#include <QFile> #include <QFile>
#include <QTimer> #include <QTimer>
#include <QFileDialog> #include <QFileDialog>
#include <QFileSystemWatcher>
#include <QStandardPaths> #include <QStandardPaths>
#include <QStringBuilder> #include <QStringBuilder>
#include <QProcess> #include <QProcess>
#include <QDesktopServices> #include <QDesktopServices>
#include <QMessageBox> #include <QMessageBox>
#include <QMenuBar>
#include <QLayout>
#ifdef HAVE_QTDBUS #ifdef HAVE_QTDBUS
#include <QDBusInterface> #include <QDBusInterface>
#include <QDBusConnectionInterface> #include <QDBusConnectionInterface>
#endif // HAVE_QTDBUS #endif // HAVE_QTDBUS
using namespace Qt::Literals::StringLiterals;
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: FramelessWindow(parent) : FramelessWindow(parent)
, m_am(new ActionManager) , m_am(new ActionManager)
, m_pm(new PlaylistManager(this)) , m_pm(new PlaylistManager(this))
, m_fileSystemWatcher(new QFileSystemWatcher(this))
{ {
if (Settings::instance()->stayOnTop()) { if (Settings::instance()->stayOnTop()) {
this->setWindowFlag(Qt::WindowStaysOnTopHint); this->setWindowFlag(Qt::WindowStaysOnTopHint);
@ -58,24 +56,28 @@ MainWindow::MainWindow(QWidget *parent)
this->setAttribute(Qt::WA_TranslucentBackground, true); this->setAttribute(Qt::WA_TranslucentBackground, true);
this->setMinimumSize(350, 330); this->setMinimumSize(350, 330);
this->setWindowIcon(QIcon(u":/icons/app-icon.svg"_s)); this->setWindowIcon(QIcon(":/icons/app-icon.svg"));
this->setMouseTracking(true); this->setMouseTracking(true);
this->setAcceptDrops(true); this->setAcceptDrops(true);
m_pm->setAutoLoadFilterSuffixes(supportedImageFormats()); m_pm->setAutoLoadFilterSuffixes(supportedImageFormats());
m_fadeOutAnimation = new QPropertyAnimation(this, "windowOpacity"_ba); m_fadeOutAnimation = new QPropertyAnimation(this, "windowOpacity");
m_fadeOutAnimation->setDuration(300); m_fadeOutAnimation->setDuration(300);
m_fadeOutAnimation->setStartValue(1); m_fadeOutAnimation->setStartValue(1);
m_fadeOutAnimation->setEndValue(0); m_fadeOutAnimation->setEndValue(0);
m_floatUpAnimation = new QPropertyAnimation(this, "geometry"_ba); m_floatUpAnimation = new QPropertyAnimation(this, "geometry");
m_floatUpAnimation->setDuration(300); m_floatUpAnimation->setDuration(300);
m_floatUpAnimation->setEasingCurve(QEasingCurve::OutCirc); m_floatUpAnimation->setEasingCurve(QEasingCurve::OutCirc);
m_exitAnimationGroup = new QParallelAnimationGroup(this); m_exitAnimationGroup = new QParallelAnimationGroup(this);
m_exitAnimationGroup->addAnimation(m_fadeOutAnimation); m_exitAnimationGroup->addAnimation(m_fadeOutAnimation);
m_exitAnimationGroup->addAnimation(m_floatUpAnimation); m_exitAnimationGroup->addAnimation(m_floatUpAnimation);
connect(m_exitAnimationGroup, &QParallelAnimationGroup::finished, connect(m_exitAnimationGroup, &QParallelAnimationGroup::finished,
this, &MainWindow::doCloseWindow); #ifdef Q_OS_MAC
this, &QWidget::hide);
#else
this, &QWidget::close);
#endif
GraphicsScene * scene = new GraphicsScene(this); GraphicsScene * scene = new GraphicsScene(this);
@ -90,7 +92,7 @@ MainWindow::MainWindow(QWidget *parent)
m_gv->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio); m_gv->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio);
connect(m_graphicsView, &GraphicsView::navigatorViewRequired, connect(m_graphicsView, &GraphicsView::navigatorViewRequired,
this, [this](bool required, const QTransform & tf){ this, [ = ](bool required, const QTransform & tf){
m_gv->setTransform(GraphicsView::resetScale(tf)); m_gv->setTransform(GraphicsView::resetScale(tf));
m_gv->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio); m_gv->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio);
m_gv->setVisible(required); m_gv->setVisible(required);
@ -126,6 +128,14 @@ MainWindow::MainWindow(QWidget *parent)
m_am->setupAction(this); m_am->setupAction(this);
QMenuBar * menuBar = new QMenuBar(this);
QMenu* fileMenu = menuBar->addMenu("File");
fileMenu->addAction(m_am->actionOpen);
fileMenu->addAction(m_am->actionSettings);
QMenu* helpMenu = menuBar->addMenu("Help");
helpMenu->addAction(m_am->actionHelp);
layout()->setMenuBar(menuBar);
m_bottomButtonGroup = new BottomButtonGroup({ m_bottomButtonGroup = new BottomButtonGroup({
m_am->actionActualSize, m_am->actionActualSize,
m_am->actionToggleMaximize, m_am->actionToggleMaximize,
@ -139,15 +149,14 @@ MainWindow::MainWindow(QWidget *parent)
m_gv->setOpacity(0, false); m_gv->setOpacity(0, false);
m_closeButton->setOpacity(0, false); m_closeButton->setOpacity(0, false);
connect(m_pm, &PlaylistManager::totalCountChanged, this, &MainWindow::updateGalleryButtonsVisibility); connect(m_pm, &PlaylistManager::totalCountChanged, this, [this](int galleryFileCount) {
m_prevButton->setVisible(galleryFileCount > 1);
m_nextButton->setVisible(galleryFileCount > 1);
});
connect(m_pm->model(), &PlaylistModel::modelReset, this, std::bind(&MainWindow::galleryCurrent, this, false, false)); connect(m_pm->model(), &PlaylistModel::modelReset, this, std::bind(&MainWindow::galleryCurrent, this, false, false));
connect(m_pm, &PlaylistManager::currentIndexChanged, this, std::bind(&MainWindow::galleryCurrent, this, true, false)); connect(m_pm, &PlaylistManager::currentIndexChanged, this, std::bind(&MainWindow::galleryCurrent, this, true, false));
connect(m_fileSystemWatcher, &QFileSystemWatcher::fileChanged, this, [this](){
QTimer::singleShot(500, this, std::bind(&MainWindow::galleryCurrent, this, false, true));
});
QShortcut * fullscreenShorucut = new QShortcut(QKeySequence(QKeySequence::FullScreen), this); QShortcut * fullscreenShorucut = new QShortcut(QKeySequence(QKeySequence::FullScreen), this);
connect(fullscreenShorucut, &QShortcut::activated, connect(fullscreenShorucut, &QShortcut::activated,
this, &MainWindow::toggleFullscreen); this, &MainWindow::toggleFullscreen);
@ -175,20 +184,10 @@ MainWindow::~MainWindow()
void MainWindow::showUrls(const QList<QUrl> &urls) void MainWindow::showUrls(const QList<QUrl> &urls)
{ {
if (!urls.isEmpty()) { if (!urls.isEmpty()) {
const QUrl & firstUrl = urls.first(); m_graphicsView->showFileFromPath(urls.first().toLocalFile());
if (urls.count() == 1) {
const QString lowerCaseUrlPath(firstUrl.path().toLower());
if (lowerCaseUrlPath.endsWith(".m3u8") || lowerCaseUrlPath.endsWith(".m3u")) {
m_pm->loadM3U8Playlist(firstUrl);
galleryCurrent(true, true);
return;
}
}
m_graphicsView->showFileFromPath(firstUrl.toLocalFile());
m_pm->loadPlaylist(urls); m_pm->loadPlaylist(urls);
} else { } else {
m_graphicsView->showText(tr("File url list is empty")); m_graphicsView->showText(tr("File url list is empty"));
m_pm->setPlaylist(urls);
return; return;
} }
@ -204,9 +203,6 @@ void MainWindow::initWindowSize()
case Settings::WindowSizeBehavior::Maximized: case Settings::WindowSizeBehavior::Maximized:
showMaximized(); showMaximized();
break; break;
case Settings::WindowSizeBehavior::Windowed:
showNormal();
break;
default: default:
adjustWindowSizeBySceneRect(); adjustWindowSizeBySceneRect();
break; break;
@ -222,7 +218,7 @@ void MainWindow::adjustWindowSizeBySceneRect()
if (m_graphicsView->scaleFactor() < 1 || size().expandedTo(sceneSizeWithMargins) != size()) { if (m_graphicsView->scaleFactor() < 1 || size().expandedTo(sceneSizeWithMargins) != size()) {
// if it scaled down by the resize policy: // if it scaled down by the resize policy:
QSize screenSize = window()->screen()->availableSize(); QSize screenSize = qApp->screenAt(QCursor::pos())->availableSize();
if (screenSize.expandedTo(sceneSize) == screenSize) { if (screenSize.expandedTo(sceneSize) == screenSize) {
// we can show the picture by increase the window size. // we can show the picture by increase the window size.
QSize finalSize = (screenSize.expandedTo(sceneSizeWithMargins) == screenSize) ? QSize finalSize = (screenSize.expandedTo(sceneSizeWithMargins) == screenSize) ?
@ -256,9 +252,6 @@ void MainWindow::clearGallery()
void MainWindow::galleryPrev() void MainWindow::galleryPrev()
{ {
const bool loopGallery = Settings::instance()->loopGallery();
if (!loopGallery && m_pm->isFirstIndex()) return;
QModelIndex index = m_pm->previousIndex(); QModelIndex index = m_pm->previousIndex();
if (index.isValid()) { if (index.isValid()) {
m_pm->setCurrentIndex(index); m_pm->setCurrentIndex(index);
@ -268,9 +261,6 @@ void MainWindow::galleryPrev()
void MainWindow::galleryNext() void MainWindow::galleryNext()
{ {
const bool loopGallery = Settings::instance()->loopGallery();
if (!loopGallery && m_pm->isLastIndex()) return;
QModelIndex index = m_pm->nextIndex(); QModelIndex index = m_pm->nextIndex();
if (index.isValid()) { if (index.isValid()) {
m_pm->setCurrentIndex(index); m_pm->setCurrentIndex(index);
@ -282,19 +272,12 @@ void MainWindow::galleryNext()
void MainWindow::galleryCurrent(bool showLoadImageHintWhenEmpty, bool reloadImage) void MainWindow::galleryCurrent(bool showLoadImageHintWhenEmpty, bool reloadImage)
{ {
QModelIndex index = m_pm->curIndex(); QModelIndex index = m_pm->curIndex();
bool shouldResetfileWatcher = true;
if (index.isValid()) { if (index.isValid()) {
const QString & localFilePath(m_pm->localFileByIndex(index)); if (reloadImage) m_graphicsView->showFileFromPath(m_pm->localFileByIndex(index));
if (reloadImage) m_graphicsView->showFileFromPath(localFilePath);
shouldResetfileWatcher = !updateFileWatcher(localFilePath);
setWindowTitle(m_pm->urlByIndex(index).fileName()); setWindowTitle(m_pm->urlByIndex(index).fileName());
} else if (showLoadImageHintWhenEmpty && m_pm->totalCount() <= 0) { } else if (showLoadImageHintWhenEmpty && m_pm->totalCount() <= 0) {
m_graphicsView->showText(QCoreApplication::translate("GraphicsScene", "Drag image here")); m_graphicsView->showText(QCoreApplication::translate("GraphicsScene", "Drag image here"));
} }
updateGalleryButtonsVisibility();
if (shouldResetfileWatcher) updateFileWatcher();
} }
QStringList MainWindow::supportedImageFormats() QStringList MainWindow::supportedImageFormats()
@ -317,7 +300,7 @@ void MainWindow::showEvent(QShowEvent *event)
return FramelessWindow::showEvent(event); return FramelessWindow::showEvent(event);
} }
void MainWindow::enterEvent(QEnterEvent *event) void MainWindow::enterEvent(QT_ENTER_EVENT *event)
{ {
m_bottomButtonGroup->setOpacity(1); m_bottomButtonGroup->setOpacity(1);
m_gv->setOpacity(1); m_gv->setOpacity(1);
@ -358,7 +341,11 @@ void MainWindow::mouseMoveEvent(QMouseEvent *event)
{ {
if (event->buttons() & Qt::LeftButton && m_clickedOnWindow && !isMaximized() && !isFullScreen()) { if (event->buttons() & Qt::LeftButton && m_clickedOnWindow && !isMaximized() && !isFullScreen()) {
if (!window()->windowHandle()->startSystemMove()) { if (!window()->windowHandle()->startSystemMove()) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
move(event->globalPosition().toPoint() - m_oldMousePos); move(event->globalPosition().toPoint() - m_oldMousePos);
#else
move(event->globalPos() - m_oldMousePos);
#endif // QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
} }
event->accept(); event->accept();
} }
@ -460,11 +447,13 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event)
QMenu * menu = new QMenu; QMenu * menu = new QMenu;
QMenu * copyMenu = new QMenu(tr("&Copy")); QMenu * copyMenu = new QMenu(tr("&Copy"));
QUrl currentFileUrl = currentImageFileUrl(); QUrl currentFileUrl = currentImageFileUrl();
QImage clipboardImage;
QUrl clipboardFileUrl;
QAction * copyPixmap = m_am->actionCopyPixmap; QAction * copyPixmap = m_am->actionCopyPixmap;
QAction * copyFilePath = m_am->actionCopyFilePath; QAction * copyFilePath = m_am->actionCopyFilePath;
copyMenu->setIcon(QIcon::fromTheme(u"edit-copy"_s)); copyMenu->setIcon(QIcon::fromTheme(QLatin1String("edit-copy")));
copyMenu->addAction(copyPixmap); copyMenu->addAction(copyPixmap);
if (currentFileUrl.isValid()) { if (currentFileUrl.isValid()) {
copyMenu->addAction(copyFilePath); copyMenu->addAction(copyFilePath);
@ -584,23 +573,19 @@ void MainWindow::centerWindow()
Qt::LeftToRight, Qt::LeftToRight,
Qt::AlignCenter, Qt::AlignCenter,
this->size(), this->size(),
window()->screen()->availableGeometry() qApp->screenAt(QCursor::pos())->availableGeometry()
) )
); );
} }
void MainWindow::closeWindow() void MainWindow::closeWindow()
{ {
if (Settings::instance()->useBuiltInCloseAnimation()) { QRect windowRect(this->geometry());
QRect windowRect(this->geometry()); m_floatUpAnimation->setStartValue(windowRect);
m_floatUpAnimation->setStartValue(windowRect); m_floatUpAnimation->setEndValue(windowRect.adjusted(0, -80, 0, 0));
m_floatUpAnimation->setEndValue(windowRect.adjusted(0, -80, 0, 0)); m_floatUpAnimation->setStartValue(QRect(this->geometry().x(), this->geometry().y(), this->geometry().width(), this->geometry().height()));
m_floatUpAnimation->setStartValue(QRect(this->geometry().x(), this->geometry().y(), this->geometry().width(), this->geometry().height())); m_floatUpAnimation->setEndValue(QRect(this->geometry().x(), this->geometry().y()-80, this->geometry().width(), this->geometry().height()));
m_floatUpAnimation->setEndValue(QRect(this->geometry().x(), this->geometry().y()-80, this->geometry().width(), this->geometry().height())); m_exitAnimationGroup->start();
m_exitAnimationGroup->start();
} else {
doCloseWindow();
}
} }
void MainWindow::updateWidgetsPosition() void MainWindow::updateWidgetsPosition()
@ -618,7 +603,8 @@ void MainWindow::toggleProtectedMode()
{ {
m_protectedMode = !m_protectedMode; m_protectedMode = !m_protectedMode;
m_closeButton->setVisible(!m_protectedMode); m_closeButton->setVisible(!m_protectedMode);
updateGalleryButtonsVisibility(); m_prevButton->setVisible(!m_protectedMode);
m_nextButton->setVisible(!m_protectedMode);
} }
void MainWindow::toggleStayOnTop() void MainWindow::toggleStayOnTop()
@ -700,7 +686,6 @@ void MainWindow::on_actionActualSize_triggered()
{ {
m_graphicsView->resetScale(); m_graphicsView->resetScale();
m_graphicsView->setEnableAutoFitInView(false); m_graphicsView->setEnableAutoFitInView(false);
m_graphicsView->setLongImageMode(false);
} }
void MainWindow::on_actionToggleMaximize_triggered() void MainWindow::on_actionToggleMaximize_triggered()
@ -729,7 +714,6 @@ void MainWindow::on_actionFitInView_triggered()
{ {
m_graphicsView->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio); m_graphicsView->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio);
m_graphicsView->setEnableAutoFitInView(m_graphicsView->scaleFactor() <= 1); m_graphicsView->setEnableAutoFitInView(m_graphicsView->scaleFactor() <= 1);
m_graphicsView->setLongImageMode(false);
} }
void MainWindow::on_actionFitByWidth_triggered() void MainWindow::on_actionFitByWidth_triggered()
@ -796,7 +780,7 @@ void MainWindow::on_actionTrash_triggered()
if (result == QMessageBox::Yes) { if (result == QMessageBox::Yes) {
bool succ = file.moveToTrash(); bool succ = file.moveToTrash();
if (!succ) { if (!succ) {
QMessageBox::warning(this, tr("Failed to move file to trash"), QMessageBox::warning(this, "Failed to move file to trash",
tr("Move to trash failed, it might caused by file permission issue, file system limitation, or platform limitation.")); tr("Move to trash failed, it might caused by file permission issue, file system limitation, or platform limitation."));
} else { } else {
m_pm->removeAt(index); m_pm->removeAt(index);
@ -815,12 +799,14 @@ void MainWindow::on_actionRotateClockwise_triggered()
{ {
m_graphicsView->rotateView(); m_graphicsView->rotateView();
m_graphicsView->displayScene(); m_graphicsView->displayScene();
m_gv->setVisible(false);
} }
void MainWindow::on_actionRotateCounterClockwise_triggered() void MainWindow::on_actionRotateCounterClockwise_triggered()
{ {
m_graphicsView->rotateView(false); m_graphicsView->rotateView(false);
m_graphicsView->displayScene(); m_graphicsView->displayScene();
m_gv->setVisible(false);
} }
void MainWindow::on_actionPrevPicture_triggered() void MainWindow::on_actionPrevPicture_triggered()
@ -905,9 +891,9 @@ void MainWindow::on_actionLocateInFileManager_triggered()
QDesktopServices::openUrl(folderUrl); QDesktopServices::openUrl(folderUrl);
return; return;
} }
QDBusInterface fm1Iface(u"org.freedesktop.FileManager1"_s, QDBusInterface fm1Iface(QStringLiteral("org.freedesktop.FileManager1"),
u"/org/freedesktop/FileManager1"_s, QStringLiteral("/org/freedesktop/FileManager1"),
u"org.freedesktop.FileManager1"_s); QStringLiteral("org.freedesktop.FileManager1"));
fm1Iface.setTimeout(1000); fm1Iface.setTimeout(1000);
fm1Iface.callWithArgumentList(QDBus::Block, "ShowItems", { fm1Iface.callWithArgumentList(QDBus::Block, "ShowItems", {
QStringList{currentFileUrl.toString()}, QStringList{currentFileUrl.toString()},
@ -925,29 +911,3 @@ void MainWindow::on_actionQuitApp_triggered()
{ {
quitAppAction(false); quitAppAction(false);
} }
void MainWindow::doCloseWindow()
{
#ifdef Q_OS_MAC
this->hide();
#else
this->close();
#endif
}
bool MainWindow::updateFileWatcher(const QString &basePath)
{
m_fileSystemWatcher->removePaths(m_fileSystemWatcher->files());
if (!basePath.isEmpty()) return m_fileSystemWatcher->addPath(basePath);
return false;
}
void MainWindow::updateGalleryButtonsVisibility()
{
const int galleryFileCount = m_pm->totalCount();
const bool loopGallery = Settings::instance()->loopGallery();
m_prevButton->setVisible(!m_protectedMode && galleryFileCount > 1);
m_nextButton->setVisible(!m_protectedMode && galleryFileCount > 1);
m_prevButton->setEnabled(loopGallery || !m_pm->isFirstIndex());
m_nextButton->setEnabled(loopGallery || !m_pm->isLastIndex());
}

View File

@ -1,134 +1,132 @@
// SPDX-FileCopyrightText: 2025 Gary Wang <git@blumia.net> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#ifndef MAINWINDOW_H #ifndef MAINWINDOW_H
#define MAINWINDOW_H #define MAINWINDOW_H
#include "framelesswindow.h" #include "framelesswindow.h"
#include <QParallelAnimationGroup> #include <QParallelAnimationGroup>
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QPushButton> #include <QPushButton>
QT_BEGIN_NAMESPACE #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
class QGraphicsOpacityEffect; typedef QEnterEvent QT_ENTER_EVENT;
class QGraphicsView; #else
class QFileSystemWatcher; typedef QEvent QT_ENTER_EVENT;
QT_END_NAMESPACE #endif // QT_VERSION_CHECK(6, 0, 0)
class ActionManager; QT_BEGIN_NAMESPACE
class PlaylistManager; class QGraphicsOpacityEffect;
class ToolButton; class QGraphicsView;
class GraphicsView; QT_END_NAMESPACE
class NavigatorView;
class BottomButtonGroup; class ActionManager;
class MainWindow : public FramelessWindow class PlaylistManager;
{ class ToolButton;
Q_OBJECT class GraphicsView;
class NavigatorView;
public: class BottomButtonGroup;
explicit MainWindow(QWidget *parent = nullptr); class MainWindow : public FramelessWindow
~MainWindow() override; {
Q_OBJECT
void showUrls(const QList<QUrl> &urls);
void initWindowSize(); public:
void adjustWindowSizeBySceneRect(); explicit MainWindow(QWidget *parent = nullptr);
QUrl currentImageFileUrl() const; ~MainWindow() override;
void clearGallery(); void showUrls(const QList<QUrl> &urls);
void galleryPrev(); void initWindowSize();
void galleryNext(); void adjustWindowSizeBySceneRect();
void galleryCurrent(bool showLoadImageHintWhenEmpty, bool reloadImage); QUrl currentImageFileUrl() const;
static QStringList supportedImageFormats(); void clearGallery();
void galleryPrev();
protected slots: void galleryNext();
void showEvent(QShowEvent *event) override; void galleryCurrent(bool showLoadImageHintWhenEmpty, bool reloadImage);
void enterEvent(QEnterEvent *event) override;
void leaveEvent(QEvent *event) override; static QStringList supportedImageFormats();
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override; protected slots:
void mouseReleaseEvent(QMouseEvent *event) override; void showEvent(QShowEvent *event) override;
void mouseDoubleClickEvent(QMouseEvent *event) override; void enterEvent(QT_ENTER_EVENT *event) override;
void wheelEvent(QWheelEvent *event) override; void leaveEvent(QEvent *event) override;
void resizeEvent(QResizeEvent *event) override; void mousePressEvent(QMouseEvent *event) override;
void contextMenuEvent(QContextMenuEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override;
void dragEnterEvent(QDragEnterEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override;
void dragMoveEvent(QDragMoveEvent *event) override; void mouseDoubleClickEvent(QMouseEvent *event) override;
void dropEvent(QDropEvent *event) override; void wheelEvent(QWheelEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
void centerWindow(); void contextMenuEvent(QContextMenuEvent *event) override;
void closeWindow(); void dragEnterEvent(QDragEnterEvent *event) override;
void updateWidgetsPosition(); void dragMoveEvent(QDragMoveEvent *event) override;
void toggleProtectedMode(); void dropEvent(QDropEvent *event) override;
void toggleStayOnTop();
void toggleAvoidResetTransform(); void centerWindow();
bool stayOnTop() const; void closeWindow();
bool canPaste() const; void updateWidgetsPosition();
void quitAppAction(bool force = false); void toggleProtectedMode();
void toggleFullscreen(); void toggleStayOnTop();
void toggleMaximize(); void toggleAvoidResetTransform();
bool stayOnTop() const;
protected: bool canPaste() const;
QSize sizeHint() const override; void quitAppAction(bool force = false);
void toggleFullscreen();
private slots: void toggleMaximize();
void on_actionOpen_triggered();
protected:
void on_actionActualSize_triggered(); QSize sizeHint() const override;
void on_actionToggleMaximize_triggered();
void on_actionZoomIn_triggered(); private slots:
void on_actionZoomOut_triggered(); void on_actionOpen_triggered();
void on_actionToggleCheckerboard_triggered();
void on_actionRotateClockwise_triggered(); void on_actionActualSize_triggered();
void on_actionRotateCounterClockwise_triggered(); void on_actionToggleMaximize_triggered();
void on_actionZoomIn_triggered();
void on_actionPrevPicture_triggered(); void on_actionZoomOut_triggered();
void on_actionNextPicture_triggered(); void on_actionToggleCheckerboard_triggered();
void on_actionRotateClockwise_triggered();
void on_actionTogglePauseAnimation_triggered(); void on_actionRotateCounterClockwise_triggered();
void on_actionAnimationNextFrame_triggered();
void on_actionPrevPicture_triggered();
void on_actionHorizontalFlip_triggered(); void on_actionNextPicture_triggered();
void on_actionFitInView_triggered();
void on_actionFitByWidth_triggered(); void on_actionTogglePauseAnimation_triggered();
void on_actionCopyPixmap_triggered(); void on_actionAnimationNextFrame_triggered();
void on_actionCopyFilePath_triggered();
void on_actionPaste_triggered(); void on_actionHorizontalFlip_triggered();
void on_actionTrash_triggered(); void on_actionFitInView_triggered();
void on_actionToggleStayOnTop_triggered(); void on_actionFitByWidth_triggered();
void on_actionToggleProtectMode_triggered(); void on_actionCopyPixmap_triggered();
void on_actionToggleAvoidResetTransform_triggered(); void on_actionCopyFilePath_triggered();
void on_actionSettings_triggered(); void on_actionPaste_triggered();
void on_actionHelp_triggered(); void on_actionTrash_triggered();
void on_actionProperties_triggered(); void on_actionToggleStayOnTop_triggered();
void on_actionLocateInFileManager_triggered(); void on_actionToggleProtectMode_triggered();
void on_actionQuitApp_triggered(); void on_actionToggleAvoidResetTransform_triggered();
void on_actionSettings_triggered();
void doCloseWindow(); void on_actionHelp_triggered();
void on_actionProperties_triggered();
private: void on_actionLocateInFileManager_triggered();
bool updateFileWatcher(const QString & basePath = QString()); void on_actionQuitApp_triggered();
void updateGalleryButtonsVisibility();
private:
private: ActionManager *m_am;
ActionManager *m_am; PlaylistManager *m_pm;
PlaylistManager *m_pm;
QPoint m_oldMousePos;
QPoint m_oldMousePos; QPropertyAnimation *m_fadeOutAnimation;
QPropertyAnimation *m_fadeOutAnimation; QPropertyAnimation *m_floatUpAnimation;
QPropertyAnimation *m_floatUpAnimation; QParallelAnimationGroup *m_exitAnimationGroup;
QParallelAnimationGroup *m_exitAnimationGroup; ToolButton *m_closeButton;
QFileSystemWatcher *m_fileSystemWatcher; ToolButton *m_prevButton;
ToolButton *m_closeButton; ToolButton *m_nextButton;
ToolButton *m_prevButton; GraphicsView *m_graphicsView;
ToolButton *m_nextButton; NavigatorView *m_gv;
GraphicsView *m_graphicsView; BottomButtonGroup *m_bottomButtonGroup;
NavigatorView *m_gv; bool m_protectedMode = false;
BottomButtonGroup *m_bottomButtonGroup; bool m_clickedOnWindow = false;
bool m_protectedMode = false; };
bool m_clickedOnWindow = false;
}; #endif // MAINWINDOW_H
#endif // MAINWINDOW_H

View File

@ -1,110 +1,110 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "metadatadialog.h" #include "metadatadialog.h"
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QPainter> #include <QPainter>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <QTreeView> #include <QTreeView>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHeaderView> #include <QHeaderView>
#include "metadatamodel.h" #include "metadatamodel.h"
class PropertyTreeView : public QTreeView class PropertyTreeView : public QTreeView
{ {
public: public:
explicit PropertyTreeView(QWidget* parent) : QTreeView(parent) {} explicit PropertyTreeView(QWidget* parent) : QTreeView(parent) {}
~PropertyTreeView() {} ~PropertyTreeView() {}
protected: protected:
void rowsInserted(const QModelIndex& parent, int start, int end) override void rowsInserted(const QModelIndex& parent, int start, int end) override
{ {
QTreeView::rowsInserted(parent, start, end); QTreeView::rowsInserted(parent, start, end);
if (!parent.isValid()) { if (!parent.isValid()) {
// we are inserting a section group // we are inserting a section group
for (int row = start; row <= end; ++row) { for (int row = start; row <= end; ++row) {
setupSection(row); setupSection(row);
} }
} else { } else {
// we are inserting a property // we are inserting a property
setRowHidden(parent.row(), QModelIndex(), false); setRowHidden(parent.row(), QModelIndex(), false);
} }
} }
void reset() override void reset() override
{ {
QTreeView::reset(); QTreeView::reset();
if (model()) { if (model()) {
for (int row = 0; row < model()->rowCount(); ++row) { for (int row = 0; row < model()->rowCount(); ++row) {
setupSection(row); setupSection(row);
} }
} }
} }
private: private:
void setupSection(int row) void setupSection(int row)
{ {
expand(model()->index(row, 0)); expand(model()->index(row, 0));
setFirstColumnSpanned(row, QModelIndex(), true); setFirstColumnSpanned(row, QModelIndex(), true);
setRowHidden(row, QModelIndex(), !model()->hasChildren(model()->index(row, 0))); setRowHidden(row, QModelIndex(), !model()->hasChildren(model()->index(row, 0)));
} }
}; };
class PropertyTreeItemDelegate : public QStyledItemDelegate class PropertyTreeItemDelegate : public QStyledItemDelegate
{ {
public: public:
PropertyTreeItemDelegate(QObject* parent) PropertyTreeItemDelegate(QObject* parent)
: QStyledItemDelegate(parent) : QStyledItemDelegate(parent)
{} {}
protected: protected:
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override
{ {
QStyleOptionViewItem opt = option; QStyleOptionViewItem opt = option;
if (!index.parent().isValid()) { if (!index.parent().isValid()) {
opt.font.setBold(true); opt.font.setBold(true);
opt.features.setFlag(QStyleOptionViewItem::Alternate); opt.features.setFlag(QStyleOptionViewItem::Alternate);
} }
QStyledItemDelegate::paint(painter, opt, index); QStyledItemDelegate::paint(painter, opt, index);
} }
}; };
MetadataDialog::MetadataDialog(QWidget *parent) MetadataDialog::MetadataDialog(QWidget *parent)
: QDialog(parent) : QDialog(parent)
, m_treeView(new PropertyTreeView(this)) , m_treeView(new PropertyTreeView(this))
{ {
m_treeView->setRootIsDecorated(false); m_treeView->setRootIsDecorated(false);
m_treeView->setIndentation(0); m_treeView->setIndentation(0);
m_treeView->setItemDelegate(new PropertyTreeItemDelegate(m_treeView)); m_treeView->setItemDelegate(new PropertyTreeItemDelegate(m_treeView));
m_treeView->header()->resizeSection(0, sizeHint().width() / 2); m_treeView->header()->resizeSection(0, sizeHint().width() / 2);
setWindowTitle(tr("Image Metadata")); setWindowTitle(tr("Image Metadata"));
QDialogButtonBox * buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); QDialogButtonBox * buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
setLayout(new QVBoxLayout); setLayout(new QVBoxLayout);
layout()->addWidget(m_treeView); layout()->addWidget(m_treeView);
layout()->addWidget(buttonBox); layout()->addWidget(buttonBox);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::close); connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::close);
setWindowFlag(Qt::WindowContextHelpButtonHint, false); setWindowFlag(Qt::WindowContextHelpButtonHint, false);
} }
MetadataDialog::~MetadataDialog() MetadataDialog::~MetadataDialog()
{ {
} }
void MetadataDialog::setMetadataModel(MetadataModel * model) void MetadataDialog::setMetadataModel(MetadataModel * model)
{ {
m_treeView->setModel(model); m_treeView->setModel(model);
} }
QSize MetadataDialog::sizeHint() const QSize MetadataDialog::sizeHint() const
{ {
return QSize(520, 350); return QSize(520, 350);
} }

View File

@ -1,30 +1,30 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#ifndef METADATADIALOG_H #ifndef METADATADIALOG_H
#define METADATADIALOG_H #define METADATADIALOG_H
#include <QDialog> #include <QDialog>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QTreeView; class QTreeView;
QT_END_NAMESPACE QT_END_NAMESPACE
class MetadataModel; class MetadataModel;
class MetadataDialog : public QDialog class MetadataDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit MetadataDialog(QWidget * parent); explicit MetadataDialog(QWidget * parent);
~MetadataDialog() override; ~MetadataDialog() override;
void setMetadataModel(MetadataModel * model); void setMetadataModel(MetadataModel * model);
QSize sizeHint() const override; QSize sizeHint() const override;
private: private:
QTreeView * m_treeView = nullptr; QTreeView * m_treeView = nullptr;
}; };
#endif // METADATADIALOG_H #endif // METADATADIALOG_H

View File

@ -1,320 +1,318 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "metadatamodel.h" #include "metadatamodel.h"
#include "exiv2wrapper.h" #include "exiv2wrapper.h"
#include <QDir> #include <QDir>
#include <QDebug> #include <QDebug>
#include <QDateTime> #include <QDateTime>
#include <QFileInfo> #include <QFileInfo>
#include <QImageReader> #include <QImageReader>
using namespace Qt::Literals::StringLiterals; MetadataModel::MetadataModel(QObject *parent)
: QAbstractItemModel(parent)
MetadataModel::MetadataModel(QObject *parent) {
: QAbstractItemModel(parent)
{ }
} MetadataModel::~MetadataModel()
{
MetadataModel::~MetadataModel()
{ }
} void MetadataModel::setFile(const QString &imageFilePath)
{
void MetadataModel::setFile(const QString &imageFilePath) QFileInfo fileInfo(imageFilePath);
{ // It'll be fine if we don't re-use the image reader we pass to the graphics scene for now.
QFileInfo fileInfo(imageFilePath); QImageReader imgReader(imageFilePath);
// It'll be fine if we don't re-use the image reader we pass to the graphics scene for now. imgReader.setAutoTransform(true);
QImageReader imgReader(imageFilePath); imgReader.setDecideFormatFromContent(true);
imgReader.setAutoTransform(true);
imgReader.setDecideFormatFromContent(true); const QString & itemTypeString = tr("%1 File").arg(QString(imgReader.format().toUpper()));
const QString & sizeString = QLocale().formattedDataSize(fileInfo.size());
const QString & itemTypeString = tr("%1 File").arg(QString(imgReader.format().toUpper())); const QString & birthTimeString = QLocale().toString(fileInfo.birthTime(), QLocale::LongFormat);
const QString & sizeString = QLocale().formattedDataSize(fileInfo.size()); const QString & lastModifiedTimeString = QLocale().toString(fileInfo.lastModified(), QLocale::LongFormat);
const QString & birthTimeString = QLocale().toString(fileInfo.birthTime(), QLocale::LongFormat); const QString & imageDimensionsString = imageSize(imgReader.size());
const QString & lastModifiedTimeString = QLocale().toString(fileInfo.lastModified(), QLocale::LongFormat); const QString & imageRatioString = imageSizeRatio(imgReader.size());
const QString & imageDimensionsString = imageSize(imgReader.size());
const QString & imageRatioString = imageSizeRatio(imgReader.size()); appendSection(QStringLiteral("Description"), tr("Description", "Section name."));
appendSection(QStringLiteral("Origin"), tr("Origin", "Section name."));
appendSection(u"Description"_s, tr("Description", "Section name.")); appendSection(QStringLiteral("Image"), tr("Image", "Section name."));
appendSection(u"Origin"_s, tr("Origin", "Section name.")); appendSection(QStringLiteral("Camera"), tr("Camera", "Section name."));
appendSection(u"Image"_s, tr("Image", "Section name.")); appendSection(QStringLiteral("AdvancedPhoto"), tr("Advanced photo", "Section name."));
appendSection(u"Camera"_s, tr("Camera", "Section name.")); appendSection(QStringLiteral("GPS"), tr("GPS", "Section name."));
appendSection(u"AdvancedPhoto"_s, tr("Advanced photo", "Section name.")); appendSection(QStringLiteral("File"), tr("File", "Section name."));
appendSection(u"GPS"_s, tr("GPS", "Section name."));
appendSection(u"File"_s, tr("File", "Section name.")); if (imgReader.supportsOption(QImageIOHandler::Size)) {
appendProperty(QStringLiteral("Image"), QStringLiteral("Image.Dimensions"),
if (imgReader.supportsOption(QImageIOHandler::Size)) { tr("Dimensions"), imageDimensionsString);
appendProperty(u"Image"_s, u"Image.Dimensions"_s, appendProperty(QStringLiteral("Image"), QStringLiteral("Image.SizeRatio"),
tr("Dimensions"), imageDimensionsString); tr("Aspect ratio"), imageRatioString);
appendProperty(u"Image"_s, u"Image.SizeRatio"_s, }
tr("Aspect ratio"), imageRatioString); if (imgReader.supportsAnimation() && imgReader.imageCount() > 1) {
} appendProperty(QStringLiteral("Image"), QStringLiteral("Image.FrameCount"),
if (imgReader.supportsAnimation() && imgReader.imageCount() > 1) { tr("Frame count"), QString::number(imgReader.imageCount()));
appendProperty(u"Image"_s, u"Image.FrameCount"_s, }
tr("Frame count"), QString::number(imgReader.imageCount()));
} appendProperty(QStringLiteral("File"), QStringLiteral("File.Name"),
tr("Name"), fileInfo.fileName());
appendProperty(u"File"_s, u"File.Name"_s, appendProperty(QStringLiteral("File"), QStringLiteral("File.ItemType"),
tr("Name"), fileInfo.fileName()); tr("Item type"), itemTypeString);
appendProperty(u"File"_s, u"File.ItemType"_s, appendProperty(QStringLiteral("File"), QStringLiteral("File.Path"),
tr("Item type"), itemTypeString); tr("Folder path"), QDir::toNativeSeparators(fileInfo.path()));
appendProperty(u"File"_s, u"File.Path"_s, appendProperty(QStringLiteral("File"), QStringLiteral("File.Size"),
tr("Folder path"), QDir::toNativeSeparators(fileInfo.path())); tr("Size"), sizeString);
appendProperty(u"File"_s, u"File.Size"_s, appendProperty(QStringLiteral("File"), QStringLiteral("File.CreatedTime"),
tr("Size"), sizeString); tr("Date created"), birthTimeString);
appendProperty(u"File"_s, u"File.CreatedTime"_s, appendProperty(QStringLiteral("File"), QStringLiteral("File.LastModified"),
tr("Date created"), birthTimeString); tr("Date modified"), lastModifiedTimeString);
appendProperty(u"File"_s, u"File.LastModified"_s,
tr("Date modified"), lastModifiedTimeString); Exiv2Wrapper wrapper;
if (wrapper.load(imageFilePath)) {
Exiv2Wrapper wrapper; wrapper.cacheSections();
if (wrapper.load(imageFilePath)) {
wrapper.cacheSections(); appendExivPropertyIfExist(wrapper, QStringLiteral("Description"),
QStringLiteral("Xmp.dc.title"), tr("Title"), true);
appendExivPropertyIfExist(wrapper, u"Description"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Description"),
u"Xmp.dc.title"_s, tr("Title"), true); QStringLiteral("Exif.Image.ImageDescription"), tr("Subject"), true);
appendExivPropertyIfExist(wrapper, u"Description"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Description"),
u"Exif.Image.ImageDescription"_s, tr("Subject"), true); QStringLiteral("Exif.Image.Rating"), tr("Rating"));
appendExivPropertyIfExist(wrapper, u"Description"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Description"),
u"Exif.Image.Rating"_s, tr("Rating")); QStringLiteral("Xmp.dc.subject"), tr("Tags"));
appendExivPropertyIfExist(wrapper, u"Description"_s, appendPropertyIfNotEmpty(QStringLiteral("Description"), QStringLiteral("Description.Comments"),
u"Xmp.dc.subject"_s, tr("Tags")); tr("Comments"), wrapper.comment());
appendPropertyIfNotEmpty(u"Description"_s, u"Description.Comments"_s,
tr("Comments"), wrapper.comment()); appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"),
QStringLiteral("Exif.Image.Artist"), tr("Authors"));
appendExivPropertyIfExist(wrapper, u"Origin"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"),
u"Exif.Image.Artist"_s, tr("Authors")); QStringLiteral("Exif.Photo.DateTimeOriginal"), tr("Date taken"));
appendExivPropertyIfExist(wrapper, u"Origin"_s, // FIXME: We may fetch the same type of metadata from different metadata collection.
u"Exif.Photo.DateTimeOriginal"_s, tr("Date taken")); // Current implementation is not pretty and may need to do a rework...
// FIXME: We may fetch the same type of metadata from different metadata collection. // appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"),
// Current implementation is not pretty and may need to do a rework... // QStringLiteral("Xmp.xmp.CreatorTool"), tr("Program name"));
// appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"), appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"),
// QStringLiteral("Xmp.xmp.CreatorTool"), tr("Program name")); QStringLiteral("Exif.Image.Software"), tr("Program name"));
appendExivPropertyIfExist(wrapper, u"Origin"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"),
u"Exif.Image.Software"_s, tr("Program name")); QStringLiteral("Exif.Image.Copyright"), tr("Copyright"));
appendExivPropertyIfExist(wrapper, u"Origin"_s,
u"Exif.Image.Copyright"_s, tr("Copyright")); appendExivPropertyIfExist(wrapper, QStringLiteral("Image"),
QStringLiteral("Exif.Image.XResolution"), tr("Horizontal resolution"));
appendExivPropertyIfExist(wrapper, u"Image"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Image"),
u"Exif.Image.XResolution"_s, tr("Horizontal resolution")); QStringLiteral("Exif.Image.YResolution"), tr("Vertical resolution"));
appendExivPropertyIfExist(wrapper, u"Image"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Image"),
u"Exif.Image.YResolution"_s, tr("Vertical resolution")); QStringLiteral("Exif.Image.ResolutionUnit"), tr("Resolution unit"));
appendExivPropertyIfExist(wrapper, u"Image"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Image"),
u"Exif.Image.ResolutionUnit"_s, tr("Resolution unit")); QStringLiteral("Exif.Photo.ColorSpace"), tr("Colour representation"));
appendExivPropertyIfExist(wrapper, u"Image"_s,
u"Exif.Photo.ColorSpace"_s, tr("Colour representation")); appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"),
QStringLiteral("Exif.Image.Make"), tr("Camera maker"));
appendExivPropertyIfExist(wrapper, u"Camera"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"),
u"Exif.Image.Make"_s, tr("Camera maker")); QStringLiteral("Exif.Image.Model"), tr("Camera model"));
appendExivPropertyIfExist(wrapper, u"Camera"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"),
u"Exif.Image.Model"_s, tr("Camera model")); QStringLiteral("Exif.Photo.FNumber"), tr("F-stop"));
appendExivPropertyIfExist(wrapper, u"Camera"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"),
u"Exif.Photo.FNumber"_s, tr("F-stop")); QStringLiteral("Exif.Photo.ExposureTime"), tr("Exposure time"));
appendExivPropertyIfExist(wrapper, u"Camera"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"),
u"Exif.Photo.ExposureTime"_s, tr("Exposure time")); QStringLiteral("Exif.Photo.ISOSpeedRatings"), tr("ISO speed"));
appendExivPropertyIfExist(wrapper, u"Camera"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"),
u"Exif.Photo.ISOSpeedRatings"_s, tr("ISO speed")); QStringLiteral("Exif.Photo.ExposureBiasValue"), tr("Exposure bias"));
appendExivPropertyIfExist(wrapper, u"Camera"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"),
u"Exif.Photo.ExposureBiasValue"_s, tr("Exposure bias")); QStringLiteral("Exif.Photo.FocalLength"), tr("Focal length"));
appendExivPropertyIfExist(wrapper, u"Camera"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"),
u"Exif.Photo.FocalLength"_s, tr("Focal length")); QStringLiteral("Exif.Photo.MaxApertureValue"), tr("Max aperture"));
appendExivPropertyIfExist(wrapper, u"Camera"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"),
u"Exif.Photo.MaxApertureValue"_s, tr("Max aperture")); QStringLiteral("Exif.Photo.MeteringMode"), tr("Metering mode"));
appendExivPropertyIfExist(wrapper, u"Camera"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"),
u"Exif.Photo.MeteringMode"_s, tr("Metering mode")); QStringLiteral("Exif.Photo.SubjectDistance"), tr("Subject distance"));
appendExivPropertyIfExist(wrapper, u"Camera"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"),
u"Exif.Photo.SubjectDistance"_s, tr("Subject distance")); QStringLiteral("Exif.Photo.Flash"), tr("Flash mode"));
appendExivPropertyIfExist(wrapper, u"Camera"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"),
u"Exif.Photo.Flash"_s, tr("Flash mode")); QStringLiteral("Exif.Photo.FocalLengthIn35mmFilm"), tr("35mm focal length"));
appendExivPropertyIfExist(wrapper, u"Camera"_s,
u"Exif.Photo.FocalLengthIn35mmFilm"_s, tr("35mm focal length")); appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"),
QStringLiteral("Exif.Photo.LensModel"), tr("Lens model"));
appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"),
u"Exif.Photo.LensModel"_s, tr("Lens model")); QStringLiteral("Exif.Photo.Contrast"), tr("Contrast"));
appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"),
u"Exif.Photo.Contrast"_s, tr("Contrast")); QStringLiteral("Exif.Photo.BrightnessValue"), tr("Brightness"));
appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"),
u"Exif.Photo.BrightnessValue"_s, tr("Brightness")); QStringLiteral("Exif.Photo.ExposureProgram"), tr("Exposure program"));
appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"),
u"Exif.Photo.ExposureProgram"_s, tr("Exposure program")); QStringLiteral("Exif.Photo.Saturation"), tr("Saturation"));
appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"),
u"Exif.Photo.Saturation"_s, tr("Saturation")); QStringLiteral("Exif.Photo.Sharpness"), tr("Sharpness"));
appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"),
u"Exif.Photo.Sharpness"_s, tr("Sharpness")); QStringLiteral("Exif.Photo.WhiteBalance"), tr("White balance"));
appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"),
u"Exif.Photo.WhiteBalance"_s, tr("White balance")); QStringLiteral("Exif.Photo.DigitalZoomRatio"), tr("Digital zoom"));
appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"),
u"Exif.Photo.DigitalZoomRatio"_s, tr("Digital zoom")); QStringLiteral("Exif.Photo.ExifVersion"), tr("EXIF version"));
appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s,
u"Exif.Photo.ExifVersion"_s, tr("EXIF version")); appendExivPropertyIfExist(wrapper, QStringLiteral("GPS"),
QStringLiteral("Exif.GPSInfo.GPSLatitudeRef"), tr("Latitude reference"));
appendExivPropertyIfExist(wrapper, u"GPS"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("GPS"),
u"Exif.GPSInfo.GPSLatitudeRef"_s, tr("Latitude reference")); QStringLiteral("Exif.GPSInfo.GPSLatitude"), tr("Latitude"));
appendExivPropertyIfExist(wrapper, u"GPS"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("GPS"),
u"Exif.GPSInfo.GPSLatitude"_s, tr("Latitude")); QStringLiteral("Exif.GPSInfo.GPSLongitudeRef"), tr("Longitude reference"));
appendExivPropertyIfExist(wrapper, u"GPS"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("GPS"),
u"Exif.GPSInfo.GPSLongitudeRef"_s, tr("Longitude reference")); QStringLiteral("Exif.GPSInfo.GPSLongitude"), tr("Longitude"));
appendExivPropertyIfExist(wrapper, u"GPS"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("GPS"),
u"Exif.GPSInfo.GPSLongitude"_s, tr("Longitude")); QStringLiteral("Exif.GPSInfo.GPSAltitudeRef"), tr("Altitude reference"));
appendExivPropertyIfExist(wrapper, u"GPS"_s, appendExivPropertyIfExist(wrapper, QStringLiteral("GPS"),
u"Exif.GPSInfo.GPSAltitudeRef"_s, tr("Altitude reference")); QStringLiteral("Exif.GPSInfo.GPSAltitude"), tr("Altitude"));
appendExivPropertyIfExist(wrapper, u"GPS"_s,
u"Exif.GPSInfo.GPSAltitude"_s, tr("Altitude")); }
}
}
} QString MetadataModel::imageSize(const QSize &size)
{
QString MetadataModel::imageSize(const QSize &size) QString imageSize;
{
QString imageSize; if (size.isValid()) {
imageSize = tr("%1 x %2").arg(QString::number(size.width()), QString::number(size.height()));
if (size.isValid()) { } else {
imageSize = tr("%1 x %2").arg(QString::number(size.width()), QString::number(size.height())); imageSize = QLatin1Char('-');
} else { }
imageSize = QLatin1Char('-');
} return imageSize;
}
return imageSize;
} int simplegcd(int a, int b) {
return b == 0 ? a : simplegcd(b, a % b);
int simplegcd(int a, int b) { }
return b == 0 ? a : simplegcd(b, a % b);
} QString MetadataModel::imageSizeRatio(const QSize &size)
{
QString MetadataModel::imageSizeRatio(const QSize &size) if (!size.isValid()) {
{ return QStringLiteral("-");
if (!size.isValid()) { }
return QStringLiteral("-"); int gcd = simplegcd(size.width(), size.height());
} return tr("%1 : %2").arg(QString::number(size.width() / gcd), QString::number(size.height() / gcd));
int gcd = simplegcd(size.width(), size.height()); }
return tr("%1 : %2").arg(QString::number(size.width() / gcd), QString::number(size.height() / gcd));
} bool MetadataModel::appendSection(const QString &sectionKey, QStringView sectionDisplayName)
{
bool MetadataModel::appendSection(const QString &sectionKey, QStringView sectionDisplayName) if (m_sections.contains(sectionKey)) {
{ return false;
if (m_sections.contains(sectionKey)) { }
return false;
} m_sections.append(sectionKey);
m_sectionProperties[sectionKey] = qMakePair<QString, QList<QString> >(sectionDisplayName.toString(), {});
m_sections.append(sectionKey);
m_sectionProperties[sectionKey] = qMakePair<QString, QList<QString> >(sectionDisplayName.toString(), {}); return true;
}
return true;
} bool MetadataModel::appendPropertyIfNotEmpty(const QString &sectionKey, const QString &propertyKey, const QString &propertyDisplayName, const QString &propertyValue)
{
bool MetadataModel::appendPropertyIfNotEmpty(const QString &sectionKey, const QString &propertyKey, const QString &propertyDisplayName, const QString &propertyValue) if (propertyValue.isEmpty()) return false;
{
if (propertyValue.isEmpty()) return false; return appendProperty(sectionKey, propertyKey, propertyDisplayName, propertyValue);
}
return appendProperty(sectionKey, propertyKey, propertyDisplayName, propertyValue);
} bool MetadataModel::appendProperty(const QString &sectionKey, const QString &propertyKey, QStringView propertyDisplayName, QStringView propertyValue)
{
bool MetadataModel::appendProperty(const QString &sectionKey, const QString &propertyKey, QStringView propertyDisplayName, QStringView propertyValue) if (!m_sections.contains(sectionKey)) {
{ return false;
if (!m_sections.contains(sectionKey)) { }
return false;
} QList<QString> & propertyList = m_sectionProperties[sectionKey].second;
if (!propertyList.contains(propertyKey)) {
QList<QString> & propertyList = m_sectionProperties[sectionKey].second; propertyList.append(propertyKey);
if (!propertyList.contains(propertyKey)) { }
propertyList.append(propertyKey);
} m_properties[propertyKey] = qMakePair<QString, QString>(propertyDisplayName.toString(), propertyValue.toString());
m_properties[propertyKey] = qMakePair<QString, QString>(propertyDisplayName.toString(), propertyValue.toString()); return true;
}
return true;
} bool MetadataModel::appendExivPropertyIfExist(const Exiv2Wrapper &wrapper, const QString &sectionKey, const QString &exiv2propertyKey, const QString &propertyDisplayName, bool isXmpString)
{
bool MetadataModel::appendExivPropertyIfExist(const Exiv2Wrapper &wrapper, const QString &sectionKey, const QString &exiv2propertyKey, const QString &propertyDisplayName, bool isXmpString) const QString & value = wrapper.value(exiv2propertyKey);
{ if (!value.isEmpty()) {
const QString & value = wrapper.value(exiv2propertyKey); appendProperty(sectionKey, exiv2propertyKey,
if (!value.isEmpty()) { propertyDisplayName.isEmpty() ? wrapper.label(exiv2propertyKey) : propertyDisplayName,
appendProperty(sectionKey, exiv2propertyKey, isXmpString ? Exiv2Wrapper::XmpValue(value) : value);
propertyDisplayName.isEmpty() ? wrapper.label(exiv2propertyKey) : propertyDisplayName, return true;
isXmpString ? Exiv2Wrapper::XmpValue(value) : value); }
return true; return false;
} }
return false;
} QModelIndex MetadataModel::index(int row, int column, const QModelIndex &parent) const
{
QModelIndex MetadataModel::index(int row, int column, const QModelIndex &parent) const if (!hasIndex(row, column, parent)) {
{ return QModelIndex();
if (!hasIndex(row, column, parent)) { }
return QModelIndex();
} if (!parent.isValid()) {
return createIndex(row, column, RowType::SectionRow);
if (!parent.isValid()) { } else {
return createIndex(row, column, RowType::SectionRow); // internalid param: row means nth section it belongs to.
} else { return createIndex(row, column, RowType::PropertyRow + parent.row());
// internalid param: row means nth section it belongs to. }
return createIndex(row, column, RowType::PropertyRow + parent.row()); }
}
} QModelIndex MetadataModel::parent(const QModelIndex &child) const
{
QModelIndex MetadataModel::parent(const QModelIndex &child) const if (!child.isValid()) {
{ return QModelIndex();
if (!child.isValid()) { }
return QModelIndex();
} if (child.internalId() == RowType::SectionRow) {
return QModelIndex();
if (child.internalId() == RowType::SectionRow) { } else {
return QModelIndex(); return createIndex(child.internalId() - RowType::PropertyRow, 0, SectionRow);
} else { }
return createIndex(child.internalId() - RowType::PropertyRow, 0, SectionRow); }
}
} int MetadataModel::rowCount(const QModelIndex &parent) const
{
int MetadataModel::rowCount(const QModelIndex &parent) const if (!parent.isValid()) {
{ return m_sections.count();
if (!parent.isValid()) { }
return m_sections.count();
} if (parent.internalId() == RowType::SectionRow) {
const QString & sectionKey = m_sections[parent.row()];
if (parent.internalId() == RowType::SectionRow) { return m_sectionProperties[sectionKey].second.count();
const QString & sectionKey = m_sections[parent.row()]; }
return m_sectionProperties[sectionKey].second.count();
} return 0;
}
return 0;
} int MetadataModel::columnCount(const QModelIndex &) const
{
int MetadataModel::columnCount(const QModelIndex &) const // Always key(display name) and value.
{ return 2;
// Always key(display name) and value. }
return 2;
} QVariant MetadataModel::data(const QModelIndex &index, int role) const
{
QVariant MetadataModel::data(const QModelIndex &index, int role) const if (!index.isValid()) {
{ return QVariant();
if (!index.isValid()) { }
return QVariant();
} if (role != Qt::DisplayRole) {
return QVariant();
if (role != Qt::DisplayRole) { }
return QVariant();
} if (index.internalId() == RowType::SectionRow) {
return (index.column() == 0) ? m_sectionProperties[m_sections[index.row()]].first
if (index.internalId() == RowType::SectionRow) { : QVariant();
return (index.column() == 0) ? m_sectionProperties[m_sections[index.row()]].first } else {
: QVariant(); int sectionIndex = index.internalId() - RowType::PropertyRow;
} else { const QString & sectionKey = m_sections[sectionIndex];
int sectionIndex = index.internalId() - RowType::PropertyRow; const QList<QString> & propertyList = m_sectionProperties[sectionKey].second;
const QString & sectionKey = m_sections[sectionIndex]; return (index.column() == 0) ? m_properties[propertyList[index.row()]].first
const QList<QString> & propertyList = m_sectionProperties[sectionKey].second; : m_properties[propertyList[index.row()]].second;
return (index.column() == 0) ? m_properties[propertyList[index.row()]].first }
: m_properties[propertyList[index.row()]].second; }
}
} QVariant MetadataModel::headerData(int section, Qt::Orientation orientation, int role) const
{
QVariant MetadataModel::headerData(int section, Qt::Orientation orientation, int role) const if (orientation == Qt::Vertical || role != Qt::DisplayRole) {
{ return QVariant();
if (orientation == Qt::Vertical || role != Qt::DisplayRole) { }
return QVariant();
} return section == 0 ? tr("Property") : tr("Value");
}
return section == 0 ? tr("Property") : tr("Value");
}

View File

@ -1,52 +1,52 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#ifndef METADATAMODEL_H #ifndef METADATAMODEL_H
#define METADATAMODEL_H #define METADATAMODEL_H
#include <QAbstractItemModel> #include <QAbstractItemModel>
class Exiv2Wrapper; class Exiv2Wrapper;
class MetadataModel : public QAbstractItemModel class MetadataModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit MetadataModel(QObject *parent = nullptr); explicit MetadataModel(QObject *parent = nullptr);
~MetadataModel(); ~MetadataModel();
void setFile(const QString & imageFilePath); void setFile(const QString & imageFilePath);
static QString imageSize(const QSize &size); static QString imageSize(const QSize &size);
static QString imageSizeRatio(const QSize &size); static QString imageSizeRatio(const QSize &size);
bool appendSection(const QString & sectionKey, QStringView sectionDisplayName); bool appendSection(const QString & sectionKey, QStringView sectionDisplayName);
bool appendPropertyIfNotEmpty(const QString & sectionKey, const QString & propertyKey, bool appendPropertyIfNotEmpty(const QString & sectionKey, const QString & propertyKey,
const QString & propertyDisplayName, const QString & propertyValue = QString()); const QString & propertyDisplayName, const QString & propertyValue = QString());
bool appendProperty(const QString & sectionKey, const QString & propertyKey, bool appendProperty(const QString & sectionKey, const QString & propertyKey,
QStringView propertyDisplayName, QStringView propertyValue = QString()); QStringView propertyDisplayName, QStringView propertyValue = QString());
bool appendExivPropertyIfExist(const Exiv2Wrapper & wrapper, const QString & sectionKey, bool appendExivPropertyIfExist(const Exiv2Wrapper & wrapper, const QString & sectionKey,
const QString & exiv2propertyKey, const QString & propertyDisplayName = QString(), const QString & exiv2propertyKey, const QString & propertyDisplayName = QString(),
bool isXmpString = false); bool isXmpString = false);
private: private:
enum RowType : quintptr { enum RowType : quintptr {
SectionRow, SectionRow,
PropertyRow, PropertyRow,
}; };
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &child) const override; QModelIndex parent(const QModelIndex &child) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex & = QModelIndex()) const override; int columnCount(const QModelIndex & = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
// [SECTION_KEY] // [SECTION_KEY]
QList<QString> m_sections; QList<QString> m_sections;
// {SECTION_KEY: (SECTION_DISPLAY_NAME, [PROPERTY_KEY])} // {SECTION_KEY: (SECTION_DISPLAY_NAME, [PROPERTY_KEY])}
QMap<QString, QPair<QString, QList<QString> > > m_sectionProperties; QMap<QString, QPair<QString, QList<QString> > > m_sectionProperties;
// {PROPERTY_KEY: (PROPERTY_DISPLAY_NAME, PROPERTY_VALUE)} // {PROPERTY_KEY: (PROPERTY_DISPLAY_NAME, PROPERTY_VALUE)}
QMap<QString, QPair<QString, QString> > m_properties; QMap<QString, QPair<QString, QString> > m_properties;
}; };
#endif // METADATAMODEL_H #endif // METADATAMODEL_H

View File

@ -1,91 +1,86 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "navigatorview.h" #include "navigatorview.h"
#include "graphicsview.h" #include "graphicsview.h"
#include "opacityhelper.h" #include "opacityhelper.h"
#include <QMouseEvent> #include <QMouseEvent>
#include <QDebug> #include <QDebug>
#include <QTimer>
NavigatorView::NavigatorView(QWidget *parent)
NavigatorView::NavigatorView(QWidget *parent) : QGraphicsView (parent)
: QGraphicsView (parent) , m_viewportRegion(this->rect())
, m_viewportRegion(this->rect()) , m_opacityHelper(new OpacityHelper(this))
, m_opacityHelper(new OpacityHelper(this)) {
{ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setStyleSheet("background-color: rgba(0, 0, 0, 120);"
setStyleSheet("background-color: rgba(0, 0, 0, 120);" "border-radius: 3px;");
"border-radius: 3px;"); }
}
// doesn't take or manage its ownership
// doesn't take or manage its ownership void NavigatorView::setMainView(GraphicsView *mainView)
void NavigatorView::setMainView(GraphicsView *mainView) {
{ m_mainView = mainView;
m_mainView = mainView; }
}
void NavigatorView::setOpacity(qreal opacity, bool animated)
void NavigatorView::setOpacity(qreal opacity, bool animated) {
{ m_opacityHelper->setOpacity(opacity, animated);
m_opacityHelper->setOpacity(opacity, animated); }
}
void NavigatorView::updateMainViewportRegion()
void NavigatorView::updateMainViewportRegion() {
{ if (m_mainView != nullptr) {
// Use QTimer::singleShot with lambda to delay the update m_viewportRegion = mapFromScene(m_mainView->mapToScene(m_mainView->rect()));
// This ensures all geometry updates are complete before calculating viewport region update();
QTimer::singleShot(0, [this]() { }
if (m_mainView != nullptr) { }
m_viewportRegion = mapFromScene(m_mainView->mapToScene(m_mainView->rect()));
update(); void NavigatorView::mousePressEvent(QMouseEvent *event)
} {
}); m_mouseDown = true;
}
if (m_mainView) {
void NavigatorView::mousePressEvent(QMouseEvent *event) m_mainView->centerOn(mapToScene(event->pos()));
{ update();
m_mouseDown = true; }
if (m_mainView) { event->accept();
m_mainView->centerOn(mapToScene(event->pos())); }
update();
} void NavigatorView::mouseMoveEvent(QMouseEvent *event)
{
event->accept(); if (m_mouseDown && m_mainView) {
} m_mainView->centerOn(mapToScene(event->pos()));
update();
void NavigatorView::mouseMoveEvent(QMouseEvent *event) event->accept();
{ } else {
if (m_mouseDown && m_mainView) { event->ignore();
m_mainView->centerOn(mapToScene(event->pos())); }
update(); }
event->accept();
} else { void NavigatorView::mouseReleaseEvent(QMouseEvent *event)
event->ignore(); {
} m_mouseDown = false;
}
event->accept();
void NavigatorView::mouseReleaseEvent(QMouseEvent *event) }
{
m_mouseDown = false; void NavigatorView::wheelEvent(QWheelEvent *event)
{
event->accept(); event->ignore();
} return QGraphicsView::wheelEvent(event);
}
void NavigatorView::wheelEvent(QWheelEvent *event)
{ void NavigatorView::paintEvent(QPaintEvent *event)
event->ignore(); {
return QGraphicsView::wheelEvent(event); QGraphicsView::paintEvent(event);
}
QPainter painter(viewport());
void NavigatorView::paintEvent(QPaintEvent *event) painter.setPen(QPen(Qt::gray, 2));
{ painter.drawRect(m_viewportRegion.boundingRect());
QGraphicsView::paintEvent(event); }
QPainter painter(viewport());
painter.setPen(QPen(Qt::gray, 2));
painter.drawRect(m_viewportRegion.boundingRect());
}

View File

@ -1,38 +1,38 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#ifndef NAVIGATORVIEW_H #ifndef NAVIGATORVIEW_H
#define NAVIGATORVIEW_H #define NAVIGATORVIEW_H
#include <QGraphicsView> #include <QGraphicsView>
class OpacityHelper; class OpacityHelper;
class GraphicsView; class GraphicsView;
class NavigatorView : public QGraphicsView class NavigatorView : public QGraphicsView
{ {
Q_OBJECT Q_OBJECT
public: public:
NavigatorView(QWidget *parent = nullptr); NavigatorView(QWidget *parent = nullptr);
void setMainView(GraphicsView *mainView); void setMainView(GraphicsView *mainView);
void setOpacity(qreal opacity, bool animated = true); void setOpacity(qreal opacity, bool animated = true);
public slots: public slots:
void updateMainViewportRegion(); void updateMainViewportRegion();
private: private:
void mousePressEvent(QMouseEvent * event) override; void mousePressEvent(QMouseEvent * event) override;
void mouseMoveEvent(QMouseEvent * event) override; void mouseMoveEvent(QMouseEvent * event) override;
void mouseReleaseEvent(QMouseEvent * event) override; void mouseReleaseEvent(QMouseEvent * event) override;
void wheelEvent(QWheelEvent *event) override; void wheelEvent(QWheelEvent *event) override;
void paintEvent(QPaintEvent *event) override; void paintEvent(QPaintEvent *event) override;
bool m_mouseDown = false; bool m_mouseDown = false;
QPolygon m_viewportRegion; QPolygon m_viewportRegion;
QGraphicsView *m_mainView = nullptr; QGraphicsView *m_mainView = nullptr;
OpacityHelper *m_opacityHelper = nullptr; OpacityHelper *m_opacityHelper = nullptr;
}; };
#endif // NAVIGATORVIEW_H #endif // NAVIGATORVIEW_H

View File

@ -1,31 +1,31 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "opacityhelper.h" #include "opacityhelper.h"
#include <QGraphicsOpacityEffect> #include <QGraphicsOpacityEffect>
#include <QPropertyAnimation> #include <QPropertyAnimation>
OpacityHelper::OpacityHelper(QWidget *parent) OpacityHelper::OpacityHelper(QWidget *parent)
: QObject(parent) : QObject(parent)
, m_opacityFx(new QGraphicsOpacityEffect(parent)) , m_opacityFx(new QGraphicsOpacityEffect(parent))
, m_opacityAnimation(new QPropertyAnimation(m_opacityFx, "opacity")) , m_opacityAnimation(new QPropertyAnimation(m_opacityFx, "opacity"))
{ {
parent->setGraphicsEffect(m_opacityFx); parent->setGraphicsEffect(m_opacityFx);
m_opacityAnimation->setDuration(300); m_opacityAnimation->setDuration(300);
} }
void OpacityHelper::setOpacity(qreal opacity, bool animated) void OpacityHelper::setOpacity(qreal opacity, bool animated)
{ {
if (!animated) { if (!animated) {
m_opacityFx->setOpacity(opacity); m_opacityFx->setOpacity(opacity);
return; return;
} }
m_opacityAnimation->stop(); m_opacityAnimation->stop();
m_opacityAnimation->setStartValue(m_opacityFx->opacity()); m_opacityAnimation->setStartValue(m_opacityFx->opacity());
m_opacityAnimation->setEndValue(opacity); m_opacityAnimation->setEndValue(opacity);
m_opacityAnimation->start(); m_opacityAnimation->start();
} }

View File

@ -1,27 +1,27 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#ifndef OPACITYHELPER_H #ifndef OPACITYHELPER_H
#define OPACITYHELPER_H #define OPACITYHELPER_H
#include <QWidget> #include <QWidget>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QGraphicsOpacityEffect; class QGraphicsOpacityEffect;
class QPropertyAnimation; class QPropertyAnimation;
QT_END_NAMESPACE QT_END_NAMESPACE
class OpacityHelper : QObject class OpacityHelper : QObject
{ {
public: public:
OpacityHelper(QWidget * parent); OpacityHelper(QWidget * parent);
void setOpacity(qreal opacity, bool animated = true); void setOpacity(qreal opacity, bool animated = true);
protected: protected:
QGraphicsOpacityEffect * m_opacityFx; QGraphicsOpacityEffect * m_opacityFx;
QPropertyAnimation * m_opacityAnimation; QPropertyAnimation * m_opacityAnimation;
}; };
#endif // OPACITYHELPER_H #endif // OPACITYHELPER_H

View File

@ -1,283 +1,255 @@
// SPDX-FileCopyrightText: 2025 Gary Wang <git@blumia.net> // SPDX-FileCopyrightText: 2024 Gary Wang <git@blumia.net>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "playlistmanager.h" #include "playlistmanager.h"
#include <QCollator> #include <QCollator>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QUrl> #include <QUrl>
PlaylistModel::PlaylistModel(QObject *parent) PlaylistModel::PlaylistModel(QObject *parent)
: QAbstractListModel(parent) : QAbstractListModel(parent)
{ {
} }
PlaylistModel::~PlaylistModel() PlaylistModel::~PlaylistModel()
= default; {
void PlaylistModel::setPlaylist(const QList<QUrl> &urls) }
{
beginResetModel(); void PlaylistModel::setPlaylist(const QList<QUrl> &urls)
m_playlist = urls; {
endResetModel(); beginResetModel();
} m_playlist = urls;
endResetModel();
QModelIndex PlaylistModel::loadPlaylist(const QList<QUrl> & urls) }
{
if (urls.isEmpty()) return {}; QModelIndex PlaylistModel::loadPlaylist(const QList<QUrl> & urls)
if (urls.count() == 1) { {
return loadPlaylist(urls.constFirst()); if (urls.isEmpty()) return QModelIndex();
} else { if (urls.count() == 1) {
setPlaylist(urls); return loadPlaylist(urls.constFirst());
return index(0); } else {
} setPlaylist(urls);
} return index(0);
}
QModelIndex PlaylistModel::loadPlaylist(const QUrl &url) }
{
QFileInfo info(url.toLocalFile()); QModelIndex PlaylistModel::loadPlaylist(const QUrl &url)
QDir dir(info.path()); {
QString && currentFileName = info.fileName(); QFileInfo info(url.toLocalFile());
QDir dir(info.path());
if (dir.path() == m_currentDir) { QString && currentFileName = info.fileName();
int idx = indexOf(url);
return idx == -1 ? appendToPlaylist(url) : index(idx); if (dir.path() == m_currentDir) {
} int idx = indexOf(url);
return idx == -1 ? appendToPlaylist(url) : index(idx);
QStringList entryList = dir.entryList( }
m_autoLoadSuffixes,
QDir::Files | QDir::NoSymLinks, QDir::NoSort); QStringList entryList = dir.entryList(
m_autoLoadSuffixes,
QCollator collator; QDir::Files | QDir::NoSymLinks, QDir::NoSort);
collator.setNumericMode(true);
QCollator collator;
std::sort(entryList.begin(), entryList.end(), collator); collator.setNumericMode(true);
QList<QUrl> playlist; std::sort(entryList.begin(), entryList.end(), collator);
int idx = -1; QList<QUrl> playlist;
for (int i = 0; i < entryList.count(); i++) {
const QString & fileName = entryList.at(i); int idx = -1;
const QString & oneEntry = dir.absoluteFilePath(fileName); for (int i = 0; i < entryList.count(); i++) {
const QUrl & url = QUrl::fromLocalFile(oneEntry); const QString & fileName = entryList.at(i);
playlist.append(url); const QString & oneEntry = dir.absoluteFilePath(fileName);
if (fileName == currentFileName) { const QUrl & url = QUrl::fromLocalFile(oneEntry);
idx = i; playlist.append(url);
} if (fileName == currentFileName) {
} idx = i;
if (idx == -1) { }
idx = playlist.count(); }
playlist.append(url); if (idx == -1) {
} idx = playlist.count();
m_currentDir = dir.path(); playlist.append(url);
}
setPlaylist(playlist); m_currentDir = dir.path();
return index(idx); setPlaylist(playlist);
}
return index(idx);
QModelIndex PlaylistModel::appendToPlaylist(const QUrl &url) }
{
const int lastIndex = rowCount(); QModelIndex PlaylistModel::appendToPlaylist(const QUrl &url)
beginInsertRows(QModelIndex(), lastIndex, lastIndex); {
m_playlist.append(url); const int lastIndex = rowCount();
endInsertRows(); beginInsertRows(QModelIndex(), lastIndex, lastIndex);
return index(lastIndex); m_playlist.append(url);
} endInsertRows();
return index(lastIndex);
bool PlaylistModel::removeAt(int index) }
{
if (index < 0 || index >= rowCount()) return false; bool PlaylistModel::removeAt(int index)
beginRemoveRows(QModelIndex(), index, index); {
m_playlist.removeAt(index); if (index < 0 || index >= rowCount()) return false;
endRemoveRows(); beginRemoveRows(QModelIndex(), index, index);
return true; m_playlist.removeAt(index);
} endRemoveRows();
return true;
int PlaylistModel::indexOf(const QUrl &url) const }
{
return m_playlist.indexOf(url); int PlaylistModel::indexOf(const QUrl &url) const
} {
return m_playlist.indexOf(url);
QUrl PlaylistModel::urlByIndex(int index) const }
{
return m_playlist.value(index); QUrl PlaylistModel::urlByIndex(int index) const
} {
return m_playlist.value(index);
QStringList PlaylistModel::autoLoadFilterSuffixes() const }
{
return m_autoLoadSuffixes; QStringList PlaylistModel::autoLoadFilterSuffixes() const
} {
return m_autoLoadSuffixes;
QHash<int, QByteArray> PlaylistModel::roleNames() const }
{
QHash<int, QByteArray> result = QAbstractListModel::roleNames(); QHash<int, QByteArray> PlaylistModel::roleNames() const
result.insert(UrlRole, "url"); {
return result; QHash<int, QByteArray> result = QAbstractListModel::roleNames();
} result.insert(UrlRole, "url");
return result;
int PlaylistModel::rowCount(const QModelIndex &parent) const }
{
return m_playlist.count(); int PlaylistModel::rowCount(const QModelIndex &parent) const
} {
return m_playlist.count();
QVariant PlaylistModel::data(const QModelIndex &index, int role) const }
{
if (!index.isValid()) return {}; QVariant PlaylistModel::data(const QModelIndex &index, int role) const
{
switch (role) { if (!index.isValid()) return QVariant();
case Qt::DisplayRole:
return m_playlist.at(index.row()).fileName(); switch (role) {
case UrlRole: case Qt::DisplayRole:
return m_playlist.at(index.row()); return m_playlist.at(index.row()).fileName();
} case UrlRole:
return m_playlist.at(index.row());
return {}; }
}
return QVariant();
PlaylistManager::PlaylistManager(QObject *parent) }
: QObject(parent)
{ PlaylistManager::PlaylistManager(QObject *parent)
connect(&m_model, &PlaylistModel::rowsRemoved, this, : QObject(parent)
[this](const QModelIndex &, int, int) { {
if (m_model.rowCount() <= m_currentIndex) { connect(&m_model, &PlaylistModel::rowsRemoved, this,
setProperty("currentIndex", m_currentIndex - 1); [this](const QModelIndex &, int, int) {
} if (m_model.rowCount() <= m_currentIndex) {
}); setProperty("currentIndex", m_currentIndex - 1);
}
auto onRowCountChanged = [this](){ });
emit totalCountChanged(m_model.rowCount());
}; auto onRowCountChanged = [this](){
emit totalCountChanged(m_model.rowCount());
connect(&m_model, &PlaylistModel::rowsInserted, this, onRowCountChanged); };
connect(&m_model, &PlaylistModel::rowsRemoved, this, onRowCountChanged);
connect(&m_model, &PlaylistModel::modelReset, this, onRowCountChanged); connect(&m_model, &PlaylistModel::rowsInserted, this, onRowCountChanged);
} connect(&m_model, &PlaylistModel::rowsRemoved, this, onRowCountChanged);
connect(&m_model, &PlaylistModel::modelReset, this, onRowCountChanged);
PlaylistManager::~PlaylistManager() }
{
PlaylistManager::~PlaylistManager()
} {
PlaylistModel *PlaylistManager::model() }
{
return &m_model; PlaylistModel *PlaylistManager::model()
} {
return &m_model;
void PlaylistManager::setPlaylist(const QList<QUrl> &urls) }
{
m_model.setPlaylist(urls); void PlaylistManager::setPlaylist(const QList<QUrl> &urls)
} {
m_model.setPlaylist(urls);
QModelIndex PlaylistManager::loadPlaylist(const QList<QUrl> &urls) }
{
QModelIndex idx = m_model.loadPlaylist(urls); QModelIndex PlaylistManager::loadPlaylist(const QList<QUrl> &urls)
setProperty("currentIndex", idx.row()); {
return idx; QModelIndex idx = m_model.loadPlaylist(urls);
} setProperty("currentIndex", idx.row());
return idx;
QModelIndex PlaylistManager::loadPlaylist(const QUrl &url) }
{
QModelIndex idx = m_model.loadPlaylist(url); QModelIndex PlaylistManager::loadPlaylist(const QUrl &url)
setProperty("currentIndex", idx.row()); {
return idx; QModelIndex idx = m_model.loadPlaylist(url);
} setProperty("currentIndex", idx.row());
return idx;
QModelIndex PlaylistManager::loadM3U8Playlist(const QUrl &url) }
{
QFile file(url.toLocalFile()); int PlaylistManager::totalCount() const
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { {
QList<QUrl> urls; return m_model.rowCount();
while (!file.atEnd()) { }
QString line = file.readLine();
if (line.startsWith('#')) { QModelIndex PlaylistManager::previousIndex() const
continue; {
} int count = totalCount();
QFileInfo fileInfo(file); if (count == 0) return QModelIndex();
QUrl item = QUrl::fromUserInput(line, fileInfo.absolutePath());
urls.append(item); return m_model.index(m_currentIndex - 1 < 0 ? count - 1 : m_currentIndex - 1);
} }
return loadPlaylist(urls);
} else { QModelIndex PlaylistManager::nextIndex() const
return {}; {
} int count = totalCount();
} if (count == 0) return QModelIndex();
int PlaylistManager::totalCount() const return m_model.index(m_currentIndex + 1 == count ? 0 : m_currentIndex + 1);
{ }
return m_model.rowCount();
} QModelIndex PlaylistManager::curIndex() const
{
QModelIndex PlaylistManager::previousIndex() const return m_model.index(m_currentIndex);
{ }
int count = totalCount();
if (count == 0) return {}; void PlaylistManager::setCurrentIndex(const QModelIndex &index)
{
return m_model.index(isFirstIndex() ? count - 1 : m_currentIndex - 1); if (index.isValid() && index.row() >= 0 && index.row() < totalCount()) {
} setProperty("currentIndex", index.row());
}
QModelIndex PlaylistManager::nextIndex() const }
{
int count = totalCount(); QUrl PlaylistManager::urlByIndex(const QModelIndex &index)
if (count == 0) return {}; {
return m_model.urlByIndex(index.row());
return m_model.index(isLastIndex() ? 0 : m_currentIndex + 1); }
}
QString PlaylistManager::localFileByIndex(const QModelIndex &index)
QModelIndex PlaylistManager::curIndex() const {
{ return urlByIndex(index).toLocalFile();
return m_model.index(m_currentIndex); }
}
bool PlaylistManager::removeAt(const QModelIndex &index)
bool PlaylistManager::isFirstIndex() const {
{ return m_model.removeAt(index.row());
return m_currentIndex == 0; }
}
void PlaylistManager::setAutoLoadFilterSuffixes(const QStringList &nameFilters)
bool PlaylistManager::isLastIndex() const {
{ m_model.setProperty("autoLoadFilterSuffixes", nameFilters);
return m_currentIndex + 1 == totalCount(); }
}
QList<QUrl> PlaylistManager::convertToUrlList(const QStringList &files)
void PlaylistManager::setCurrentIndex(const QModelIndex &index) {
{ QList<QUrl> urlList;
if (index.isValid() && index.row() >= 0 && index.row() < totalCount()) { for (const QString & str : std::as_const(files)) {
setProperty("currentIndex", index.row()); QUrl url = QUrl::fromLocalFile(str);
} if (url.isValid()) {
} urlList.append(url);
}
QUrl PlaylistManager::urlByIndex(const QModelIndex &index) }
{
return m_model.urlByIndex(index.row()); return urlList;
} }
QString PlaylistManager::localFileByIndex(const QModelIndex &index)
{
return urlByIndex(index).toLocalFile();
}
bool PlaylistManager::removeAt(const QModelIndex &index)
{
return m_model.removeAt(index.row());
}
void PlaylistManager::setAutoLoadFilterSuffixes(const QStringList &nameFilters)
{
m_model.setProperty("autoLoadFilterSuffixes", nameFilters);
}
QList<QUrl> PlaylistManager::convertToUrlList(const QStringList &files)
{
QList<QUrl> urlList;
for (const QString & str : std::as_const(files)) {
QUrl url = QUrl::fromLocalFile(str);
if (url.isValid()) {
urlList.append(url);
}
}
return urlList;
}

View File

@ -1,88 +1,85 @@
// SPDX-FileCopyrightText: 2025 Gary Wang <git@blumia.net> // SPDX-FileCopyrightText: 2024 Gary Wang <git@blumia.net>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <QUrl> #include <QUrl>
#include <QAbstractListModel> #include <QAbstractListModel>
class PlaylistModel : public QAbstractListModel class PlaylistModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
public: public:
enum PlaylistRole { enum PlaylistRole {
UrlRole = Qt::UserRole UrlRole = Qt::UserRole
}; };
Q_ENUM(PlaylistRole) Q_ENUM(PlaylistRole)
Q_PROPERTY(QStringList autoLoadFilterSuffixes MEMBER m_autoLoadSuffixes NOTIFY autoLoadFilterSuffixesChanged) Q_PROPERTY(QStringList autoLoadFilterSuffixes MEMBER m_autoLoadSuffixes NOTIFY autoLoadFilterSuffixesChanged)
explicit PlaylistModel(QObject *parent = nullptr); explicit PlaylistModel(QObject *parent = nullptr);
~PlaylistModel() override; ~PlaylistModel();
void setPlaylist(const QList<QUrl> & urls); void setPlaylist(const QList<QUrl> & urls);
QModelIndex loadPlaylist(const QList<QUrl> & urls); QModelIndex loadPlaylist(const QList<QUrl> & urls);
QModelIndex loadPlaylist(const QUrl & url); QModelIndex loadPlaylist(const QUrl & url);
QModelIndex appendToPlaylist(const QUrl & url); QModelIndex appendToPlaylist(const QUrl & url);
bool removeAt(int index); bool removeAt(int index);
int indexOf(const QUrl & url) const; int indexOf(const QUrl & url) const;
QUrl urlByIndex(int index) const; QUrl urlByIndex(int index) const;
QStringList autoLoadFilterSuffixes() const; QStringList autoLoadFilterSuffixes() const;
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
signals: signals:
void autoLoadFilterSuffixesChanged(QStringList suffixes); void autoLoadFilterSuffixesChanged(QStringList suffixes);
private: private:
// model data // model data
QList<QUrl> m_playlist; QList<QUrl> m_playlist;
// properties // properties
QStringList m_autoLoadSuffixes = {}; QStringList m_autoLoadSuffixes = {};
// internal // internal
QString m_currentDir; QString m_currentDir;
}; };
class PlaylistManager : public QObject class PlaylistManager : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
Q_PROPERTY(int currentIndex MEMBER m_currentIndex NOTIFY currentIndexChanged) Q_PROPERTY(int currentIndex MEMBER m_currentIndex NOTIFY currentIndexChanged)
Q_PROPERTY(QStringList autoLoadFilterSuffixes WRITE setAutoLoadFilterSuffixes) Q_PROPERTY(QStringList autoLoadFilterSuffixes WRITE setAutoLoadFilterSuffixes)
Q_PROPERTY(PlaylistModel * model READ model CONSTANT) Q_PROPERTY(PlaylistModel * model READ model CONSTANT)
explicit PlaylistManager(QObject *parent = nullptr); explicit PlaylistManager(QObject *parent = nullptr);
~PlaylistManager(); ~PlaylistManager();
PlaylistModel * model(); PlaylistModel * model();
void setPlaylist(const QList<QUrl> & url); void setPlaylist(const QList<QUrl> & url);
Q_INVOKABLE QModelIndex loadPlaylist(const QList<QUrl> & urls); Q_INVOKABLE QModelIndex loadPlaylist(const QList<QUrl> & urls);
Q_INVOKABLE QModelIndex loadPlaylist(const QUrl & url); Q_INVOKABLE QModelIndex loadPlaylist(const QUrl & url);
Q_INVOKABLE QModelIndex loadM3U8Playlist(const QUrl & url);
int totalCount() const;
int totalCount() const; QModelIndex previousIndex() const;
QModelIndex previousIndex() const; QModelIndex nextIndex() const;
QModelIndex nextIndex() const; QModelIndex curIndex() const;
QModelIndex curIndex() const; void setCurrentIndex(const QModelIndex & index);
bool isFirstIndex() const; QUrl urlByIndex(const QModelIndex & index);
bool isLastIndex() const; QString localFileByIndex(const QModelIndex & index);
void setCurrentIndex(const QModelIndex & index); bool removeAt(const QModelIndex & index);
QUrl urlByIndex(const QModelIndex & index);
QString localFileByIndex(const QModelIndex & index); void setAutoLoadFilterSuffixes(const QStringList &nameFilters);
bool removeAt(const QModelIndex & index);
static QList<QUrl> convertToUrlList(const QStringList & files);
void setAutoLoadFilterSuffixes(const QStringList &nameFilters);
signals:
static QList<QUrl> convertToUrlList(const QStringList & files); void currentIndexChanged(int index);
void totalCountChanged(int count);
signals:
void currentIndexChanged(int index); private:
void totalCountChanged(int count); int m_currentIndex = -1;
PlaylistModel m_model;
private: };
int m_currentIndex = -1;
PlaylistModel m_model;
};

View File

@ -1,237 +1,204 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "settings.h" #include "settings.h"
#include <QApplication> #include <QApplication>
#include <QStandardPaths> #include <QStandardPaths>
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QAction> #include <QAction>
#include <QWidget> #include <QWidget>
#include <QKeySequence> #include <QKeySequence>
#include <QMetaEnum> #include <QMetaEnum>
namespace QEnumHelper namespace QEnumHelper
{ {
template <typename E> template <typename E>
E fromString(const QString &text, const E defaultValue) E fromString(const QString &text, const E defaultValue)
{ {
bool ok; bool ok;
E result = static_cast<E>(QMetaEnum::fromType<E>().keyToValue(text.toUtf8(), &ok)); E result = static_cast<E>(QMetaEnum::fromType<E>().keyToValue(text.toUtf8(), &ok));
if (!ok) { if (!ok) {
return defaultValue; return defaultValue;
} }
return result; return result;
} }
template <typename E> template <typename E>
QString toString(E value) QString toString(E value)
{ {
const int intValue = static_cast<int>(value); const int intValue = static_cast<int>(value);
return QString::fromUtf8(QMetaEnum::fromType<E>().valueToKey(intValue)); return QString::fromUtf8(QMetaEnum::fromType<E>().valueToKey(intValue));
} }
} }
Settings *Settings::m_settings_instance = nullptr; Settings *Settings::m_settings_instance = nullptr;
Settings *Settings::instance() Settings *Settings::instance()
{ {
if (!m_settings_instance) { if (!m_settings_instance) {
m_settings_instance = new Settings; m_settings_instance = new Settings;
} }
return m_settings_instance; return m_settings_instance;
} }
bool Settings::stayOnTop() const bool Settings::stayOnTop()
{ {
return m_qsettings->value("stay_on_top", true).toBool(); return m_qsettings->value("stay_on_top", true).toBool();
} }
bool Settings::useBuiltInCloseAnimation() const bool Settings::useLightCheckerboard()
{ {
return m_qsettings->value("use_built_in_close_animation", true).toBool(); return m_qsettings->value("use_light_checkerboard", false).toBool();
} }
bool Settings::useLightCheckerboard() const Settings::DoubleClickBehavior Settings::doubleClickBehavior() const
{ {
return m_qsettings->value("use_light_checkerboard", false).toBool(); QString result = m_qsettings->value("double_click_behavior", "Close").toString();
}
return QEnumHelper::fromString<DoubleClickBehavior>(result, DoubleClickBehavior::Close);
bool Settings::loopGallery() const }
{
return m_qsettings->value("loop_gallery", true).toBool(); Settings::MouseWheelBehavior Settings::mouseWheelBehavior() const
} {
QString result = m_qsettings->value("mouse_wheel_behavior", "Zoom").toString();
bool Settings::autoLongImageMode() const
{ return QEnumHelper::fromString<MouseWheelBehavior>(result, MouseWheelBehavior::Zoom);
return m_qsettings->value("auto_long_image_mode", true).toBool(); }
}
Settings::WindowSizeBehavior Settings::initWindowSizeBehavior() const
Settings::DoubleClickBehavior Settings::doubleClickBehavior() const {
{ QString result = m_qsettings->value("init_window_size_behavior", "Auto").toString();
QString result = m_qsettings->value("double_click_behavior", "Close").toString();
return QEnumHelper::fromString<WindowSizeBehavior>(result, WindowSizeBehavior::Auto);
return QEnumHelper::fromString<DoubleClickBehavior>(result, DoubleClickBehavior::Close); }
}
Qt::HighDpiScaleFactorRoundingPolicy Settings::hiDpiScaleFactorBehavior() const
Settings::MouseWheelBehavior Settings::mouseWheelBehavior() const {
{ QString result = m_qsettings->value("hidpi_scale_factor_behavior", "PassThrough").toString();
QString result = m_qsettings->value("mouse_wheel_behavior", "Zoom").toString();
return QEnumHelper::fromString<Qt::HighDpiScaleFactorRoundingPolicy>(result, Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
return QEnumHelper::fromString<MouseWheelBehavior>(result, MouseWheelBehavior::Zoom); }
}
void Settings::setStayOnTop(bool on)
Settings::WindowSizeBehavior Settings::initWindowSizeBehavior() const {
{ m_qsettings->setValue("stay_on_top", on);
QString result = m_qsettings->value("init_window_size_behavior", "Auto").toString(); m_qsettings->sync();
}
return QEnumHelper::fromString<WindowSizeBehavior>(result, WindowSizeBehavior::Auto);
} void Settings::setUseLightCheckerboard(bool light)
{
Qt::HighDpiScaleFactorRoundingPolicy Settings::hiDpiScaleFactorBehavior() const m_qsettings->setValue("use_light_checkerboard", light);
{ m_qsettings->sync();
QString result = m_qsettings->value("hidpi_scale_factor_behavior", "PassThrough").toString(); }
return QEnumHelper::fromString<Qt::HighDpiScaleFactorRoundingPolicy>(result, Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); void Settings::setDoubleClickBehavior(DoubleClickBehavior dcb)
} {
m_qsettings->setValue("double_click_behavior", QEnumHelper::toString(dcb));
void Settings::setStayOnTop(bool on) m_qsettings->sync();
{ }
m_qsettings->setValue("stay_on_top", on);
m_qsettings->sync(); void Settings::setMouseWheelBehavior(MouseWheelBehavior mwb)
} {
m_qsettings->setValue("mouse_wheel_behavior", QEnumHelper::toString(mwb));
void Settings::setUseBuiltInCloseAnimation(bool on) m_qsettings->sync();
{ }
m_qsettings->setValue("use_built_in_close_animation", on);
m_qsettings->sync(); void Settings::setInitWindowSizeBehavior(WindowSizeBehavior wsb)
} {
m_qsettings->setValue("init_window_size_behavior", QEnumHelper::toString(wsb));
void Settings::setUseLightCheckerboard(bool light) m_qsettings->sync();
{ }
m_qsettings->setValue("use_light_checkerboard", light);
m_qsettings->sync(); void Settings::setHiDpiScaleFactorBehavior(Qt::HighDpiScaleFactorRoundingPolicy hidpi)
} {
m_qsettings->setValue("hidpi_scale_factor_behavior", QEnumHelper::toString(hidpi));
void Settings::setLoopGallery(bool on) m_qsettings->sync();
{ }
m_qsettings->setValue("loop_gallery", on);
m_qsettings->sync(); void Settings::applyUserShortcuts(QWidget *widget)
} {
m_qsettings->beginGroup("shortcuts");
void Settings::setAutoLongImageMode(bool on) const QStringList shortcutNames = m_qsettings->allKeys();
{ for (const QString & name : shortcutNames) {
m_qsettings->setValue("auto_long_image_mode", on); QList<QKeySequence> shortcuts = m_qsettings->value(name).value<QList<QKeySequence>>();
m_qsettings->sync(); setShortcutsForAction(widget, name, shortcuts, false);
} }
m_qsettings->endGroup();
void Settings::setDoubleClickBehavior(DoubleClickBehavior dcb) }
{
m_qsettings->setValue("double_click_behavior", QEnumHelper::toString(dcb)); bool Settings::setShortcutsForAction(QWidget *widget, const QString &objectName,
m_qsettings->sync(); QList<QKeySequence> shortcuts, bool writeConfig)
} {
QAction * targetAction = nullptr;
void Settings::setMouseWheelBehavior(MouseWheelBehavior mwb) for (QAction * action : widget->actions()) {
{ if (action->objectName() == objectName) {
m_qsettings->setValue("mouse_wheel_behavior", QEnumHelper::toString(mwb)); targetAction = action;
m_qsettings->sync(); } else {
} for (const QKeySequence & shortcut : std::as_const(shortcuts)) {
if (action->shortcuts().contains(shortcut)) {
void Settings::setInitWindowSizeBehavior(WindowSizeBehavior wsb) return false;
{ }
m_qsettings->setValue("init_window_size_behavior", QEnumHelper::toString(wsb)); }
m_qsettings->sync(); }
} }
void Settings::setHiDpiScaleFactorBehavior(Qt::HighDpiScaleFactorRoundingPolicy hidpi) if (targetAction) {
{ targetAction->setShortcuts(shortcuts);
m_qsettings->setValue("hidpi_scale_factor_behavior", QEnumHelper::toString(hidpi)); }
m_qsettings->sync();
} if (targetAction && writeConfig) {
m_qsettings->beginGroup("shortcuts");
void Settings::applyUserShortcuts(QWidget *widget) m_qsettings->setValue(objectName, QVariant::fromValue(shortcuts));
{ m_qsettings->endGroup();
m_qsettings->beginGroup("shortcuts"); m_qsettings->sync();
const QStringList shortcutNames = m_qsettings->allKeys(); }
for (const QString & name : shortcutNames) {
QList<QKeySequence> shortcuts = m_qsettings->value(name).value<QList<QKeySequence>>(); return true;
setShortcutsForAction(widget, name, shortcuts, false); }
}
m_qsettings->endGroup(); #if defined(FLAG_PORTABLE_MODE_SUPPORT) && defined(Q_OS_WIN)
} #include <windows.h>
// QCoreApplication::applicationDirPath() parses the "applicationDirPath" from arg0, which...
bool Settings::setShortcutsForAction(QWidget *widget, const QString &objectName, // 1. rely on a QApplication object instance
QList<QKeySequence> shortcuts, bool writeConfig) // but we need to call QGuiApplication::setHighDpiScaleFactorRoundingPolicy() before QApplication get created
{ // 2. arg0 is NOT garanteed to be the path of execution
QAction * targetAction = nullptr; // see also: https://stackoverflow.com/questions/383973/is-args0-guaranteed-to-be-the-path-of-execution
for (QAction * action : widget->actions()) { // This function is here mainly for #1.
if (action->objectName() == objectName) { QString getApplicationDirPath()
targetAction = action; {
} else { WCHAR buffer[MAX_PATH];
for (const QKeySequence & shortcut : std::as_const(shortcuts)) { GetModuleFileNameW(NULL, buffer, MAX_PATH);
if (action->shortcuts().contains(shortcut)) { QString appPath = QString::fromWCharArray(buffer);
return false;
} return appPath.left(appPath.lastIndexOf('\\'));
} }
} #endif // defined(FLAG_PORTABLE_MODE_SUPPORT) && defined(Q_OS_WIN)
}
Settings::Settings()
if (targetAction) { : QObject(qApp)
targetAction->setShortcuts(shortcuts); {
} QString configPath;
if (targetAction && writeConfig) { #if defined(FLAG_PORTABLE_MODE_SUPPORT) && defined(Q_OS_WIN)
m_qsettings->beginGroup("shortcuts"); QString portableConfigDirPath = QDir(getApplicationDirPath()).absoluteFilePath("data");
m_qsettings->setValue(objectName, QVariant::fromValue(shortcuts)); QFileInfo portableConfigDirInfo(portableConfigDirPath);
m_qsettings->endGroup(); if (portableConfigDirInfo.exists() && portableConfigDirInfo.isDir() && portableConfigDirInfo.isWritable()) {
m_qsettings->sync(); // we can use it.
} configPath = portableConfigDirPath;
}
return true; #endif // defined(FLAG_PORTABLE_MODE_SUPPORT) && defined(Q_OS_WIN)
}
if (configPath.isEmpty()) {
#if defined(FLAG_PORTABLE_MODE_SUPPORT) && defined(Q_OS_WIN) // Should be %LOCALAPPDATA%\<APPNAME> under Windows, ~/.config/<APPNAME> under Linux.
#include <windows.h> configPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
// QCoreApplication::applicationDirPath() parses the "applicationDirPath" from arg0, which... }
// 1. rely on a QApplication object instance
// but we need to call QGuiApplication::setHighDpiScaleFactorRoundingPolicy() before QApplication get created m_qsettings = new QSettings(QDir(configPath).absoluteFilePath("config.ini"), QSettings::IniFormat, this);
// 2. arg0 is NOT garanteed to be the path of execution
// see also: https://stackoverflow.com/questions/383973/is-args0-guaranteed-to-be-the-path-of-execution qRegisterMetaType<QList<QKeySequence>>();
// This function is here mainly for #1. }
QString getApplicationDirPath()
{
WCHAR buffer[MAX_PATH];
GetModuleFileNameW(NULL, buffer, MAX_PATH);
QString appPath = QString::fromWCharArray(buffer);
return appPath.left(appPath.lastIndexOf('\\'));
}
#endif // defined(FLAG_PORTABLE_MODE_SUPPORT) && defined(Q_OS_WIN)
Settings::Settings()
: QObject(qApp)
{
QString configPath;
#if defined(FLAG_PORTABLE_MODE_SUPPORT) && defined(Q_OS_WIN)
QString portableConfigDirPath = QDir(getApplicationDirPath()).absoluteFilePath("data");
QFileInfo portableConfigDirInfo(portableConfigDirPath);
if (portableConfigDirInfo.exists() && portableConfigDirInfo.isDir() && portableConfigDirInfo.isWritable()) {
// we can use it.
configPath = portableConfigDirPath;
}
#endif // defined(FLAG_PORTABLE_MODE_SUPPORT) && defined(Q_OS_WIN)
if (configPath.isEmpty()) {
// Should be %LOCALAPPDATA%\<APPNAME> under Windows, ~/.config/<APPNAME> under Linux.
configPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
}
m_qsettings = new QSettings(QDir(configPath).absoluteFilePath("config.ini"), QSettings::IniFormat, this);
qRegisterMetaType<QList<QKeySequence>>();
}

View File

@ -1,71 +1,64 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <QObject> #include <QObject>
#include <QSettings> #include <QSettings>
class Settings : public QObject class Settings : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
enum DoubleClickBehavior { enum DoubleClickBehavior {
Ignore, Ignore,
Close, Close,
Maximize, Maximize,
FullScreen, FullScreen,
}; };
Q_ENUM(DoubleClickBehavior) Q_ENUM(DoubleClickBehavior)
enum MouseWheelBehavior { enum MouseWheelBehavior {
Zoom, Zoom,
Switch, Switch,
}; };
Q_ENUM(MouseWheelBehavior) Q_ENUM(MouseWheelBehavior)
enum WindowSizeBehavior { enum WindowSizeBehavior {
Auto, Auto,
Maximized, Maximized,
Windowed, };
}; Q_ENUM(WindowSizeBehavior)
Q_ENUM(WindowSizeBehavior)
static Settings *instance();
static Settings *instance();
bool stayOnTop();
bool stayOnTop() const; bool useLightCheckerboard();
bool useBuiltInCloseAnimation() const; DoubleClickBehavior doubleClickBehavior() const;
bool useLightCheckerboard() const; MouseWheelBehavior mouseWheelBehavior() const;
bool loopGallery() const; WindowSizeBehavior initWindowSizeBehavior() const;
bool autoLongImageMode() const; Qt::HighDpiScaleFactorRoundingPolicy hiDpiScaleFactorBehavior() const;
DoubleClickBehavior doubleClickBehavior() const;
MouseWheelBehavior mouseWheelBehavior() const; void setStayOnTop(bool on);
WindowSizeBehavior initWindowSizeBehavior() const; void setUseLightCheckerboard(bool light);
Qt::HighDpiScaleFactorRoundingPolicy hiDpiScaleFactorBehavior() const; void setDoubleClickBehavior(DoubleClickBehavior dcb);
void setMouseWheelBehavior(MouseWheelBehavior mwb);
void setStayOnTop(bool on); void setInitWindowSizeBehavior(WindowSizeBehavior wsb);
void setUseBuiltInCloseAnimation(bool on); void setHiDpiScaleFactorBehavior(Qt::HighDpiScaleFactorRoundingPolicy hidpi);
void setUseLightCheckerboard(bool light);
void setLoopGallery(bool on); void applyUserShortcuts(QWidget * widget);
void setAutoLongImageMode(bool on); bool setShortcutsForAction(QWidget * widget, const QString & objectName,
void setDoubleClickBehavior(DoubleClickBehavior dcb); QList<QKeySequence> shortcuts, bool writeConfig = true);
void setMouseWheelBehavior(MouseWheelBehavior mwb);
void setInitWindowSizeBehavior(WindowSizeBehavior wsb); private:
void setHiDpiScaleFactorBehavior(Qt::HighDpiScaleFactorRoundingPolicy hidpi); Settings();
void applyUserShortcuts(QWidget * widget); static Settings *m_settings_instance;
bool setShortcutsForAction(QWidget * widget, const QString & objectName,
QList<QKeySequence> shortcuts, bool writeConfig = true); QSettings *m_qsettings;
private: signals:
Settings();
public slots:
static Settings *m_settings_instance; };
QSettings *m_qsettings;
signals:
public slots:
};

View File

@ -1,207 +1,177 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "settingsdialog.h" #include "settingsdialog.h"
#include "settings.h" #include "settings.h"
#include "shortcutedit.h" #include "shortcutedit.h"
#include <QAction> #include <QAction>
#include <QCheckBox> #include <QCheckBox>
#include <QComboBox> #include <QComboBox>
#include <QFormLayout> #include <QFormLayout>
#include <QKeySequenceEdit> #include <QKeySequenceEdit>
#include <QScrollArea> #include <QScrollArea>
#include <QSplitter> #include <QSplitter>
#include <QStringListModel> #include <QStringListModel>
#include <QMessageBox> #include <QMessageBox>
SettingsDialog::SettingsDialog(QWidget *parent) SettingsDialog::SettingsDialog(QWidget *parent)
: QDialog(parent) : QDialog(parent)
, m_stayOnTop(new QCheckBox) , m_stayOnTop(new QCheckBox)
, m_useBuiltInCloseAnimation(new QCheckBox) , m_useLightCheckerboard(new QCheckBox)
, m_useLightCheckerboard(new QCheckBox) , m_doubleClickBehavior(new QComboBox)
, m_loopGallery(new QCheckBox) , m_mouseWheelBehavior(new QComboBox)
, m_autoLongImageMode(new QCheckBox) , m_initWindowSizeBehavior(new QComboBox)
, m_doubleClickBehavior(new QComboBox) , m_hiDpiRoundingPolicyBehavior(new QComboBox)
, m_mouseWheelBehavior(new QComboBox) {
, m_initWindowSizeBehavior(new QComboBox) this->setWindowTitle(tr("Settings"));
, m_hiDpiRoundingPolicyBehavior(new QComboBox)
{ QHBoxLayout * mainLayout = new QHBoxLayout(this);
this->setWindowTitle(tr("Settings")); QTabWidget * settingsTabs = new QTabWidget(this);
mainLayout->addWidget(settingsTabs);
QHBoxLayout * mainLayout = new QHBoxLayout(this);
QTabWidget * settingsTabs = new QTabWidget(this); QWidget * settingsFormHolder = new QWidget;
mainLayout->addWidget(settingsTabs); QFormLayout * settingsForm = new QFormLayout(settingsFormHolder);
settingsTabs->addTab(settingsFormHolder, tr("Options"));
QWidget * settingsFormHolder = new QWidget;
QFormLayout * settingsForm = new QFormLayout(settingsFormHolder); QSplitter * shortcutEditorSplitter = new QSplitter;
settingsTabs->addTab(settingsFormHolder, tr("Options")); shortcutEditorSplitter->setOrientation(Qt::Vertical);
shortcutEditorSplitter->setChildrenCollapsible(false);
QSplitter * shortcutEditorSplitter = new QSplitter; QScrollArea * shortcutScrollArea = new QScrollArea;
shortcutEditorSplitter->setOrientation(Qt::Vertical); shortcutEditorSplitter->addWidget(shortcutScrollArea);
shortcutEditorSplitter->setChildrenCollapsible(false); shortcutScrollArea->setWidgetResizable(true);
QScrollArea * shortcutScrollArea = new QScrollArea; shortcutScrollArea->setMinimumHeight(200);
shortcutEditorSplitter->addWidget(shortcutScrollArea); QWidget * shortcutsFormHolder = new QWidget;
shortcutScrollArea->setWidgetResizable(true); QFormLayout * shortcutsForm = new QFormLayout(shortcutsFormHolder);
shortcutScrollArea->setMinimumHeight(200); shortcutScrollArea->setWidget(shortcutsFormHolder);
QWidget * shortcutsFormHolder = new QWidget; settingsTabs->addTab(shortcutEditorSplitter, tr("Shortcuts"));
QFormLayout * shortcutsForm = new QFormLayout(shortcutsFormHolder);
shortcutScrollArea->setWidget(shortcutsFormHolder); for (const QAction * action : parent->actions()) {
settingsTabs->addTab(shortcutEditorSplitter, tr("Shortcuts")); ShortcutEdit * shortcutEdit = new ShortcutEdit;
shortcutEdit->setObjectName(QLatin1String("shortcut_") + action->objectName());
for (const QAction * action : parent->actions()) { shortcutEdit->setShortcuts(action->shortcuts());
ShortcutEdit * shortcutEdit = new ShortcutEdit; shortcutsForm->addRow(action->text(), shortcutEdit);
shortcutEdit->setObjectName(QLatin1String("shortcut_") + action->objectName()); connect(shortcutEdit, &ShortcutEdit::editButtonClicked, this, [=](){
shortcutEdit->setShortcuts(action->shortcuts()); if (shortcutEditorSplitter->count() == 1) shortcutEditorSplitter->addWidget(new QWidget);
shortcutsForm->addRow(action->text(), shortcutEdit); ShortcutEditor * shortcutEditor = new ShortcutEditor(shortcutEdit);
connect(shortcutEdit, &ShortcutEdit::editButtonClicked, this, [=](){ shortcutEditor->setDescription(tr("Editing shortcuts for action \"%1\":").arg(action->text()));
if (shortcutEditorSplitter->count() == 1) shortcutEditorSplitter->addWidget(new QWidget); QWidget * oldEditor = shortcutEditorSplitter->replaceWidget(1, shortcutEditor);
ShortcutEditor * shortcutEditor = new ShortcutEditor(shortcutEdit); shortcutEditorSplitter->setSizes({shortcutEditorSplitter->height(), 1});
shortcutEditor->setDescription(tr("Editing shortcuts for action \"%1\":").arg(action->text())); oldEditor->deleteLater();
QWidget * oldEditor = shortcutEditorSplitter->replaceWidget(1, shortcutEditor); });
shortcutEditorSplitter->setSizes({shortcutEditorSplitter->height(), 1}); connect(shortcutEdit, &ShortcutEdit::applyShortcutsRequested, this, [=](QList<QKeySequence> newShortcuts){
oldEditor->deleteLater(); bool succ = Settings::instance()->setShortcutsForAction(parent, shortcutEdit->objectName().mid(9),
}); newShortcuts);
connect(shortcutEdit, &ShortcutEdit::applyShortcutsRequested, this, [=](QList<QKeySequence> newShortcuts){ if (!succ) {
bool succ = Settings::instance()->setShortcutsForAction(parent, shortcutEdit->objectName().mid(9), QMessageBox::warning(this, tr("Failed to set shortcuts"),
newShortcuts); tr("Please check if shortcuts are duplicated with existing shortcuts."));
if (!succ) { }
QMessageBox::warning(this, tr("Failed to set shortcuts"), shortcutEdit->setShortcuts(action->shortcuts());
tr("Please check if shortcuts are duplicated with existing shortcuts.")); });
} }
shortcutEdit->setShortcuts(action->shortcuts());
}); static QList< QPair<Settings::DoubleClickBehavior, QString> > _dc_options {
} { Settings::DoubleClickBehavior::Ignore, tr("Do nothing") },
{ Settings::DoubleClickBehavior::Close, tr("Close the window") },
static QList< QPair<Settings::DoubleClickBehavior, QString> > _dc_options { { Settings::DoubleClickBehavior::Maximize, tr("Toggle maximize") },
{ Settings::DoubleClickBehavior::Ignore, tr("Do nothing") }, { Settings::DoubleClickBehavior::FullScreen, tr("Toggle fullscreen") }
{ Settings::DoubleClickBehavior::Close, tr("Close the window") }, };
{ Settings::DoubleClickBehavior::Maximize, tr("Toggle maximize") },
{ Settings::DoubleClickBehavior::FullScreen, tr("Toggle fullscreen") } static QList< QPair<Settings::MouseWheelBehavior, QString> > _mw_options {
}; { Settings::MouseWheelBehavior::Zoom, tr("Zoom in and out") },
{ Settings::MouseWheelBehavior::Switch, tr("View next or previous item") }
static QList< QPair<Settings::MouseWheelBehavior, QString> > _mw_options { };
{ Settings::MouseWheelBehavior::Zoom, tr("Zoom in and out") },
{ Settings::MouseWheelBehavior::Switch, tr("View next or previous item") } static QList< QPair<Settings::WindowSizeBehavior, QString> > _iws_options {
}; { Settings::WindowSizeBehavior::Auto, tr("Auto size") },
{ Settings::WindowSizeBehavior::Maximized, tr("Maximized") }
static QList< QPair<Settings::WindowSizeBehavior, QString> > _iws_options { };
{ Settings::WindowSizeBehavior::Auto, tr("Auto size") },
{ Settings::WindowSizeBehavior::Maximized, tr("Maximized") }, static QList< QPair<Qt::HighDpiScaleFactorRoundingPolicy, QString> > _hidpi_options {
{ Settings::WindowSizeBehavior::Windowed, tr("Windowed") } { Qt::HighDpiScaleFactorRoundingPolicy::Round, tr("Round (Integer scaling)", "This option means round up for .5 and above") },
}; { Qt::HighDpiScaleFactorRoundingPolicy::Ceil, tr("Ceil (Integer scaling)", "This option means always round up") },
{ Qt::HighDpiScaleFactorRoundingPolicy::Floor, tr("Floor (Integer scaling)", "This option means always round down") },
static QList< QPair<Qt::HighDpiScaleFactorRoundingPolicy, QString> > _hidpi_options { { Qt::HighDpiScaleFactorRoundingPolicy::PassThrough, tr("Follow system (Fractional scaling)", "This option means don't round") }
{ Qt::HighDpiScaleFactorRoundingPolicy::Round, tr("Round (Integer scaling)", "This option means round up for .5 and above") }, };
{ Qt::HighDpiScaleFactorRoundingPolicy::Ceil, tr("Ceil (Integer scaling)", "This option means always round up") },
{ Qt::HighDpiScaleFactorRoundingPolicy::Floor, tr("Floor (Integer scaling)", "This option means always round down") }, QStringList dcbDropDown;
{ Qt::HighDpiScaleFactorRoundingPolicy::PassThrough, tr("Follow system (Fractional scaling)", "This option means don't round") } for (const QPair<Settings::DoubleClickBehavior, QString> & dcOption : _dc_options) {
}; dcbDropDown.append(dcOption.second);
}
QStringList dcbDropDown;
for (const QPair<Settings::DoubleClickBehavior, QString> & dcOption : _dc_options) { QStringList mwbDropDown;
dcbDropDown.append(dcOption.second); for (const QPair<Settings::MouseWheelBehavior, QString> & mwOption : _mw_options) {
} mwbDropDown.append(mwOption.second);
}
QStringList mwbDropDown;
for (const QPair<Settings::MouseWheelBehavior, QString> & mwOption : _mw_options) { QStringList iwsbDropDown;
mwbDropDown.append(mwOption.second); for (const QPair<Settings::WindowSizeBehavior, QString> & iwsOption : _iws_options) {
} iwsbDropDown.append(iwsOption.second);
}
QStringList iwsbDropDown;
for (const QPair<Settings::WindowSizeBehavior, QString> & iwsOption : _iws_options) { QStringList hidpiDropDown;
iwsbDropDown.append(iwsOption.second); for (const QPair<Qt::HighDpiScaleFactorRoundingPolicy, QString> & hidpiOption : _hidpi_options) {
} hidpiDropDown.append(hidpiOption.second);
}
QStringList hidpiDropDown;
for (const QPair<Qt::HighDpiScaleFactorRoundingPolicy, QString> & hidpiOption : _hidpi_options) { settingsForm->addRow(tr("Stay on top when start-up"), m_stayOnTop);
hidpiDropDown.append(hidpiOption.second); settingsForm->addRow(tr("Use light-color checkerboard"), m_useLightCheckerboard);
} settingsForm->addRow(tr("Double-click behavior"), m_doubleClickBehavior);
settingsForm->addRow(tr("Mouse wheel behavior"), m_mouseWheelBehavior);
settingsForm->addRow(tr("Stay on top when start-up"), m_stayOnTop); settingsForm->addRow(tr("Default window size"), m_initWindowSizeBehavior);
settingsForm->addRow(tr("Use built-in close window animation"), m_useBuiltInCloseAnimation); settingsForm->addRow(tr("HiDPI scale factor rounding policy"), m_hiDpiRoundingPolicyBehavior);
settingsForm->addRow(tr("Use light-color checkerboard"), m_useLightCheckerboard);
settingsForm->addRow(tr("Loop the loaded gallery"), m_loopGallery); m_stayOnTop->setChecked(Settings::instance()->stayOnTop());
settingsForm->addRow(tr("Auto long image mode"), m_autoLongImageMode); m_useLightCheckerboard->setChecked(Settings::instance()->useLightCheckerboard());
settingsForm->addRow(tr("Double-click behavior"), m_doubleClickBehavior); m_doubleClickBehavior->setModel(new QStringListModel(dcbDropDown));
settingsForm->addRow(tr("Mouse wheel behavior"), m_mouseWheelBehavior); Settings::DoubleClickBehavior dcb = Settings::instance()->doubleClickBehavior();
settingsForm->addRow(tr("Default window size"), m_initWindowSizeBehavior); m_doubleClickBehavior->setCurrentIndex(static_cast<int>(dcb));
settingsForm->addRow(tr("HiDPI scale factor rounding policy"), m_hiDpiRoundingPolicyBehavior); m_mouseWheelBehavior->setModel(new QStringListModel(mwbDropDown));
Settings::MouseWheelBehavior mwb = Settings::instance()->mouseWheelBehavior();
m_stayOnTop->setChecked(Settings::instance()->stayOnTop()); m_mouseWheelBehavior->setCurrentIndex(static_cast<int>(mwb));
m_useBuiltInCloseAnimation->setChecked(Settings::instance()->useBuiltInCloseAnimation()); m_initWindowSizeBehavior->setModel(new QStringListModel(iwsbDropDown));
m_useLightCheckerboard->setChecked(Settings::instance()->useLightCheckerboard()); Settings::WindowSizeBehavior iwsb = Settings::instance()->initWindowSizeBehavior();
m_loopGallery->setChecked(Settings::instance()->loopGallery()); m_initWindowSizeBehavior->setCurrentIndex(static_cast<int>(iwsb));
m_autoLongImageMode->setChecked(Settings::instance()->autoLongImageMode()); m_hiDpiRoundingPolicyBehavior->setModel(new QStringListModel(hidpiDropDown));
m_doubleClickBehavior->setModel(new QStringListModel(dcbDropDown)); Qt::HighDpiScaleFactorRoundingPolicy hidpi = Settings::instance()->hiDpiScaleFactorBehavior();
Settings::DoubleClickBehavior dcb = Settings::instance()->doubleClickBehavior(); for (int i = 0; i < _hidpi_options.count(); i++) {
m_doubleClickBehavior->setCurrentIndex(static_cast<int>(dcb)); if (_hidpi_options.at(i).first == hidpi) {
m_mouseWheelBehavior->setModel(new QStringListModel(mwbDropDown)); m_hiDpiRoundingPolicyBehavior->setCurrentIndex(i);
Settings::MouseWheelBehavior mwb = Settings::instance()->mouseWheelBehavior(); break;
m_mouseWheelBehavior->setCurrentIndex(static_cast<int>(mwb)); }
m_initWindowSizeBehavior->setModel(new QStringListModel(iwsbDropDown)); }
Settings::WindowSizeBehavior iwsb = Settings::instance()->initWindowSizeBehavior();
m_initWindowSizeBehavior->setCurrentIndex(static_cast<int>(iwsb)); connect(m_stayOnTop, &QCheckBox::stateChanged, this, [ = ](int state){
m_hiDpiRoundingPolicyBehavior->setModel(new QStringListModel(hidpiDropDown)); Settings::instance()->setStayOnTop(state == Qt::Checked);
Qt::HighDpiScaleFactorRoundingPolicy hidpi = Settings::instance()->hiDpiScaleFactorBehavior(); });
for (int i = 0; i < _hidpi_options.count(); i++) {
if (_hidpi_options.at(i).first == hidpi) { connect(m_useLightCheckerboard, &QCheckBox::stateChanged, this, [ = ](int state){
m_hiDpiRoundingPolicyBehavior->setCurrentIndex(i); Settings::instance()->setUseLightCheckerboard(state == Qt::Checked);
break; });
}
} connect(m_doubleClickBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
Settings::instance()->setDoubleClickBehavior(_dc_options.at(index).first);
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0) });
# define QCHECKBOX_CHECKSTATECHANGED QCheckBox::checkStateChanged
# define QT_CHECKSTATE Qt::CheckState connect(m_mouseWheelBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
#else Settings::instance()->setMouseWheelBehavior(_mw_options.at(index).first);
# define QCHECKBOX_CHECKSTATECHANGED QCheckBox::stateChanged });
# define QT_CHECKSTATE int
#endif // QT_VERSION >= QT_VERSION_CHECK(6, 7, 0) connect(m_initWindowSizeBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
Settings::instance()->setInitWindowSizeBehavior(_iws_options.at(index).first);
connect(m_stayOnTop, &QCHECKBOX_CHECKSTATECHANGED, this, [ = ](QT_CHECKSTATE state){ });
Settings::instance()->setStayOnTop(state == Qt::Checked);
}); connect(m_hiDpiRoundingPolicyBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
Settings::instance()->setHiDpiScaleFactorBehavior(_hidpi_options.at(index).first);
connect(m_useBuiltInCloseAnimation, &QCHECKBOX_CHECKSTATECHANGED, this, [ = ](QT_CHECKSTATE state){ });
Settings::instance()->setUseBuiltInCloseAnimation(state == Qt::Checked);
}); adjustSize();
setWindowFlag(Qt::WindowContextHelpButtonHint, false);
connect(m_useLightCheckerboard, &QCHECKBOX_CHECKSTATECHANGED, this, [ = ](QT_CHECKSTATE state){ }
Settings::instance()->setUseLightCheckerboard(state == Qt::Checked);
}); SettingsDialog::~SettingsDialog()
{
connect(m_loopGallery, &QCHECKBOX_CHECKSTATECHANGED, this, [ = ](QT_CHECKSTATE state){
Settings::instance()->setLoopGallery(state == Qt::Checked); }
});
connect(m_autoLongImageMode, &QCHECKBOX_CHECKSTATECHANGED, this, [ = ](QT_CHECKSTATE state){
Settings::instance()->setAutoLongImageMode(state == Qt::Checked);
});
connect(m_doubleClickBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
Settings::instance()->setDoubleClickBehavior(_dc_options.at(index).first);
});
connect(m_mouseWheelBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
Settings::instance()->setMouseWheelBehavior(_mw_options.at(index).first);
});
connect(m_initWindowSizeBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
Settings::instance()->setInitWindowSizeBehavior(_iws_options.at(index).first);
});
connect(m_hiDpiRoundingPolicyBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
Settings::instance()->setHiDpiScaleFactorBehavior(_hidpi_options.at(index).first);
});
adjustSize();
setWindowFlag(Qt::WindowContextHelpButtonHint, false);
}
SettingsDialog::~SettingsDialog()
{
}

View File

@ -1,36 +1,33 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#ifndef SETTINGSDIALOG_H #ifndef SETTINGSDIALOG_H
#define SETTINGSDIALOG_H #define SETTINGSDIALOG_H
#include <QObject> #include <QObject>
#include <QDialog> #include <QDialog>
class QCheckBox; class QCheckBox;
class QComboBox; class QComboBox;
class SettingsDialog : public QDialog class SettingsDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SettingsDialog(QWidget *parent = nullptr); explicit SettingsDialog(QWidget *parent = nullptr);
~SettingsDialog(); ~SettingsDialog();
signals: signals:
public slots: public slots:
private: private:
QCheckBox * m_stayOnTop = nullptr; QCheckBox * m_stayOnTop = nullptr;
QCheckBox * m_useBuiltInCloseAnimation = nullptr; QCheckBox * m_useLightCheckerboard = nullptr;
QCheckBox * m_useLightCheckerboard = nullptr; QComboBox * m_doubleClickBehavior = nullptr;
QCheckBox * m_loopGallery = nullptr; QComboBox * m_mouseWheelBehavior = nullptr;
QCheckBox * m_autoLongImageMode = nullptr; QComboBox * m_initWindowSizeBehavior = nullptr;
QComboBox * m_doubleClickBehavior = nullptr; QComboBox * m_hiDpiRoundingPolicyBehavior = nullptr;
QComboBox * m_mouseWheelBehavior = nullptr; };
QComboBox * m_initWindowSizeBehavior = nullptr;
QComboBox * m_hiDpiRoundingPolicyBehavior = nullptr; #endif // SETTINGSDIALOG_H
};
#endif // SETTINGSDIALOG_H

View File

@ -40,6 +40,11 @@ ShortcutEditor::ShortcutEditor(ShortcutEdit * shortcutEdit, QWidget * parent)
reloadShortcuts(); reloadShortcuts();
} }
ShortcutEditor::~ShortcutEditor()
{
}
void ShortcutEditor::setDescription(const QString &desc) void ShortcutEditor::setDescription(const QString &desc)
{ {
m_descriptionLabel->setText(desc); m_descriptionLabel->setText(desc);
@ -58,7 +63,9 @@ void ShortcutEditor::reloadShortcuts()
shortcuts.append(QKeySequence()); shortcuts.append(QKeySequence());
for (const QKeySequence & shortcut : shortcuts) { for (const QKeySequence & shortcut : shortcuts) {
QKeySequenceEdit * keyseqEdit = new QKeySequenceEdit(this); QKeySequenceEdit * keyseqEdit = new QKeySequenceEdit(this);
#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
keyseqEdit->setClearButtonEnabled(true); keyseqEdit->setClearButtonEnabled(true);
#endif // QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
keyseqEdit->setMaximumSequenceLength(1); keyseqEdit->setMaximumSequenceLength(1);
#endif // QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) #endif // QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
@ -98,8 +105,8 @@ ShortcutEdit::ShortcutEdit(QWidget *parent)
connect(this, &ShortcutEdit::shortcutsChanged, this, [=](){ connect(this, &ShortcutEdit::shortcutsChanged, this, [=](){
QStringList shortcutTexts; QStringList shortcutTexts;
for (const QKeySequence & shortcut : std::as_const(m_shortcuts)) { for (const QKeySequence & shortcut : m_shortcuts) {
shortcutTexts.append(shortcut.toString(QKeySequence::NativeText)); shortcutTexts.append(shortcut.toString());
} }
m_shortcutsLabel->setText(shortcutTexts.isEmpty() ? tr("No shortcuts") : shortcutTexts.join(", ")); m_shortcutsLabel->setText(shortcutTexts.isEmpty() ? tr("No shortcuts") : shortcutTexts.join(", "));
m_shortcutsLabel->setDisabled(shortcutTexts.isEmpty()); m_shortcutsLabel->setDisabled(shortcutTexts.isEmpty());

View File

@ -18,7 +18,7 @@ class ShortcutEditor : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit ShortcutEditor(ShortcutEdit * shortcutEdit, QWidget * parent = nullptr); explicit ShortcutEditor(ShortcutEdit * shortcutEdit, QWidget * parent = nullptr);
~ShortcutEditor() = default; ~ShortcutEditor();
void setDescription(const QString & desc); void setDescription(const QString & desc);

View File

@ -1,38 +1,38 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "toolbutton.h" #include "toolbutton.h"
#include "actionmanager.h" #include "actionmanager.h"
#include "opacityhelper.h" #include "opacityhelper.h"
#include <QPainter> #include <QPainter>
#include <QGraphicsOpacityEffect> #include <QGraphicsOpacityEffect>
#include <QPropertyAnimation> #include <QPropertyAnimation>
ToolButton::ToolButton(bool hoverColor, QWidget *parent) ToolButton::ToolButton(bool hoverColor, QWidget *parent)
: QPushButton(parent) : QPushButton(parent)
, m_opacityHelper(new OpacityHelper(this)) , m_opacityHelper(new OpacityHelper(this))
{ {
setFlat(true); setFlat(true);
QString qss = "QPushButton {" QString qss = "QPushButton {"
"background: transparent;" "background: transparent;"
"}"; "}";
if (hoverColor) { if (hoverColor) {
qss += "QPushButton:hover {" qss += "QPushButton:hover {"
"background: red;" "background: red;"
"}"; "}";
} }
setStyleSheet(qss); setStyleSheet(qss);
} }
void ToolButton::setIconResourcePath(const QString &iconp) void ToolButton::setIconResourcePath(const QString &iconp)
{ {
this->setIcon(ActionManager::loadHidpiIcon(iconp, this->iconSize())); this->setIcon(ActionManager::loadHidpiIcon(iconp, this->iconSize()));
} }
void ToolButton::setOpacity(qreal opacity, bool animated) void ToolButton::setOpacity(qreal opacity, bool animated)
{ {
m_opacityHelper->setOpacity(opacity, animated); m_opacityHelper->setOpacity(opacity, animated);
} }

View File

@ -1,25 +1,25 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#ifndef TOOLBUTTON_H #ifndef TOOLBUTTON_H
#define TOOLBUTTON_H #define TOOLBUTTON_H
#include <QPushButton> #include <QPushButton>
class OpacityHelper; class OpacityHelper;
class ToolButton : public QPushButton class ToolButton : public QPushButton
{ {
Q_OBJECT Q_OBJECT
public: public:
ToolButton(bool hoverColor = false, QWidget * parent = nullptr); ToolButton(bool hoverColor = false, QWidget * parent = nullptr);
void setIconResourcePath(const QString &iconp); void setIconResourcePath(const QString &iconp);
public slots: public slots:
void setOpacity(qreal opacity, bool animated = true); void setOpacity(qreal opacity, bool animated = true);
private: private:
OpacityHelper * m_opacityHelper; OpacityHelper * m_opacityHelper;
}; };
#endif // TOOLBUTTON_H #endif // TOOLBUTTON_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,891 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="ta">
<context>
<name>AboutDialog</name>
<message>
<location filename="../aboutdialog.cpp" line="29"/>
<source>About</source>
<translation>ி</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="32"/>
<source>Launch application with image file path as argument to load the file.</source>
<translation> .</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="33"/>
<source>Drag and drop image file onto the window is also supported.</source>
<translation> ி ி.</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="34"/>
<source>None of the operations in this application will alter the pictures on disk.</source>
<translation> ி ி .</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="35"/>
<source>Context menu option explanation:</source>
<translation> ி ி ி:</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="42"/>
<source>Make window stay on top of all other windows.</source>
<translation> .</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="45"/>
<source>Avoid close window accidentally. (eg. by double clicking the window)</source>
<translation> ி. (.. )</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="48"/>
<source>Avoid resetting the zoom/rotation/flip state that was applied to the image view when switching between images.</source>
<translation> ி ி /ி/ிி ி ி.</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="55"/>
<source>Version: %1</source>
<translation>ி: %1</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="66"/>
<source>Logo designed by %1</source>
<translation> %1 ி</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="68"/>
<source>Built with Qt %1 (%2)</source>
<translation>ிி %1 ( %2) </translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="69"/>
<source>Source code</source>
<translation> ி</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="79"/>
<source>Contributors</source>
<translation>ி</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="81"/>
<source>List of contributors on GitHub</source>
<translation>ிி ிி ி</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="82"/>
<source>Thanks to all people who contributed to this project.</source>
<translation> ிி ி ி.</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="86"/>
<source>Translators</source>
<translation>ி</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="87"/>
<source>I would like to thank the following people who volunteered to translate this application.</source>
<translation> ி ி ி ி ிி ிி.</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="131"/>
<source>%1 is built on the following free software libraries:</source>
<comment>Free as in freedom</comment>
<translation>%1 ி ி :</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="155"/>
<source>&amp;Special Thanks</source>
<translation>&amp; ி ி</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="157"/>
<source>&amp;Third-party Libraries</source>
<translation> </translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="93"/>
<source>Your Rights</source>
<translation> ி</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="63"/>
<source>Copyright (c) %1 %2</source>
<comment>%1 is year, %2 is the name of copyright holder(s)</comment>
<translation>ிி (ி) %1 %2</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="95"/>
<source>%1 is released under the MIT License.</source>
<translation>%1 ி ிி ிிி.</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="96"/>
<source>This license grants people a number of freedoms:</source>
<translation> ி ி ி:</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="97"/>
<source>You are free to use %1, for any purpose</source>
<translation> ி %1 </translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="98"/>
<source>You are free to distribute %1</source>
<translation>%1 ிிி </translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="99"/>
<source>You can study how %1 works and change it</source>
<translation>%1 ி ி </translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="100"/>
<source>You can distribute changed versions of %1</source>
<translation> ி %1 ிிி</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="102"/>
<source>The MIT license guarantees you this freedom. Nobody is ever permitted to take it away.</source>
<translation>ி ி ி ி. ிி.</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="130"/>
<source>Third-party Libraries used by %1</source>
<translation>%1 </translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="153"/>
<source>&amp;Help</source>
<translation>ி (&amp;h)</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="154"/>
<source>&amp;About</source>
<translation>&amp;ி</translation>
</message>
<message>
<location filename="../aboutdialog.cpp" line="156"/>
<source>&amp;License</source>
<translation>&amp; ி</translation>
</message>
</context>
<context>
<name>GraphicsScene</name>
<message>
<location filename="../mainwindow.cpp" line="292"/>
<location filename="../graphicsscene.cpp" line="100"/>
<source>Drag image here</source>
<translation> </translation>
</message>
</context>
<context>
<name>GraphicsView</name>
<message>
<location filename="../graphicsview.cpp" line="50"/>
<source>File is not a valid image</source>
<translation> ி </translation>
</message>
<message>
<location filename="../graphicsview.cpp" line="54"/>
<location filename="../graphicsview.cpp" line="58"/>
<source>Image data is invalid or currently unsupported</source>
<translation> ி</translation>
</message>
</context>
<context>
<name>MainWindow</name>
<message>
<location filename="../mainwindow.cpp" line="190"/>
<location filename="../mainwindow.cpp" line="561"/>
<source>File url list is empty</source>
<translation> ி ி ி </translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="461"/>
<source>&amp;Copy</source>
<translation> (&amp;c)</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="569"/>
<source>Image data is invalid</source>
<translation> </translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="576"/>
<source>Not supported mimedata: %1</source>
<translation> ிி: %1</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="777"/>
<source>Image From Clipboard</source>
<translation>ிிிி </translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="795"/>
<source>Are you sure you want to move &quot;%1&quot; to recycle bin?</source>
<translation>ி ி &quot;%1&quot; ிி?</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="799"/>
<source>Failed to move file to trash</source>
<translation> ி ி</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="800"/>
<source>Move to trash failed, it might caused by file permission issue, file system limitation, or platform limitation.</source>
<translation> ி, ி, ி .</translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="104"/>
<source>Copy P&amp;ixmap</source>
<translation>ி &amp; </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="105"/>
<source>Copy &amp;File Path</source>
<translation> </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="123"/>
<source>Properties</source>
<translation></translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="108"/>
<location filename="../aboutdialog.cpp" line="41"/>
<source>Stay on top</source>
<translation> </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="109"/>
<location filename="../aboutdialog.cpp" line="44"/>
<source>Protected mode</source>
<translation> </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="110"/>
<location filename="../aboutdialog.cpp" line="47"/>
<source>Keep transformation</source>
<comment>The &apos;transformation&apos; means the flip/rotation status that currently applied to the image view</comment>
<translation> </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="89"/>
<source>Zoom in</source>
<translation>ி</translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="90"/>
<source>Zoom out</source>
<translation>ிி</translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="98"/>
<source>Pause/Resume Animation</source>
<translation>ி/ி </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="99"/>
<source>Animation Go to Next Frame</source>
<translation>ி ி </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="101"/>
<source>Flip &amp;Horizontally</source>
<translation>ி </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="102"/>
<source>Fit to view</source>
<translation> </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="103"/>
<source>Fit to width</source>
<translation>ி </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="106"/>
<source>&amp;Paste</source>
<translation> (&amp;p)</translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="91"/>
<source>Toggle Checkerboard</source>
<translation> </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="85"/>
<source>&amp;Open...</source>
<translation>&amp; ி ...</translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="87"/>
<source>Actual size</source>
<translation> </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="88"/>
<source>Toggle maximize</source>
<translation>ி </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="92"/>
<source>Rotate right</source>
<translation> </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="93"/>
<source>Rotate left</source>
<translation> </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="95"/>
<source>Previous image</source>
<translation> </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="96"/>
<source>Next image</source>
<translation> </translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="794"/>
<location filename="../actionmanager.cpp" line="107"/>
<source>Move to Trash</source>
<translation> </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="111"/>
<source>Configure...</source>
<translation> ...</translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="112"/>
<source>Help</source>
<translation>ி</translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="115"/>
<source>Show in File Explorer</source>
<comment>File Explorer is the name of explorer.exe under Windows</comment>
<translation> ி ி</translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="121"/>
<source>Show in directory</source>
<translation>ி </translation>
</message>
<message>
<location filename="../actionmanager.cpp" line="124"/>
<source>Quit</source>
<translation>ி</translation>
</message>
</context>
<context>
<name>MetadataDialog</name>
<message>
<location filename="../metadatadialog.cpp" line="84"/>
<source>Image Metadata</source>
<translation> ி </translation>
</message>
</context>
<context>
<name>MetadataModel</name>
<message>
<location filename="../metadatamodel.cpp" line="43"/>
<source>Origin</source>
<comment>Section name.</comment>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="44"/>
<source>Image</source>
<comment>Section name.</comment>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="48"/>
<source>File</source>
<comment>Section name.</comment>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="45"/>
<source>Camera</source>
<comment>Section name.</comment>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="35"/>
<source>%1 File</source>
<translation>%1 </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="42"/>
<source>Description</source>
<comment>Section name.</comment>
<translation>ி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="46"/>
<source>Advanced photo</source>
<comment>Section name.</comment>
<translation> </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="47"/>
<source>GPS</source>
<comment>Section name.</comment>
<translation> </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="52"/>
<source>Dimensions</source>
<translation>ி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="54"/>
<source>Aspect ratio</source>
<translation> ிி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="58"/>
<source>Frame count</source>
<translation> ி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="62"/>
<source>Name</source>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="64"/>
<source>Item type</source>
<translation>ி </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="66"/>
<source>Folder path</source>
<translation> </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="68"/>
<source>Size</source>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="70"/>
<source>Date created</source>
<translation>ி </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="72"/>
<source>Date modified</source>
<translation>ி ி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="79"/>
<source>Title</source>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="81"/>
<source>Subject</source>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="83"/>
<source>Rating</source>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="85"/>
<source>Tags</source>
<translation>ி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="87"/>
<source>Comments</source>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="90"/>
<source>Authors</source>
<translation>ிி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="92"/>
<source>Date taken</source>
<translation> ி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="98"/>
<source>Program name</source>
<translation>ி </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="100"/>
<source>Copyright</source>
<translation>ிி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="103"/>
<source>Horizontal resolution</source>
<translation>ி </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="105"/>
<source>Vertical resolution</source>
<translation> </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="107"/>
<source>Resolution unit</source>
<translation>ிி </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="109"/>
<source>Colour representation</source>
<translation> ிிிி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="112"/>
<source>Camera maker</source>
<translation> ி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="114"/>
<source>Camera model</source>
<translation> ிி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="116"/>
<source>F-stop</source>
<translation>-</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="118"/>
<source>Exposure time</source>
<translation>ி </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="120"/>
<source>ISO speed</source>
<translation> ி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="122"/>
<source>Exposure bias</source>
<translation>ி </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="124"/>
<source>Focal length</source>
<translation>ி, ி </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="126"/>
<source>Max aperture</source>
<translation>ி </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="128"/>
<source>Metering mode</source>
<translation> </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="130"/>
<source>Subject distance</source>
<translation> </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="132"/>
<source>Flash mode</source>
<translation>ி </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="134"/>
<source>35mm focal length</source>
<translation>35 ி ி </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="137"/>
<source>Lens model</source>
<translation> ிி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="139"/>
<source>Contrast</source>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="141"/>
<source>Brightness</source>
<translation>ி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="143"/>
<source>Exposure program</source>
<translation>ி ி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="145"/>
<source>Saturation</source>
<translation>ி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="147"/>
<source>Sharpness</source>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="149"/>
<source>White balance</source>
<translation> </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="151"/>
<source>Digital zoom</source>
<translation>ிி </translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="153"/>
<source>EXIF version</source>
<translation>Exif ி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="156"/>
<source>Latitude reference</source>
<translation> ி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="158"/>
<source>Latitude</source>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="160"/>
<source>Longitude reference</source>
<translation> ி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="162"/>
<source>Longitude</source>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="164"/>
<source>Altitude reference</source>
<translation> ி</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="166"/>
<source>Altitude</source>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="176"/>
<source>%1 x %2</source>
<translation>%1 %2</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="194"/>
<source>%1 : %2</source>
<translation>%1: %2</translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="319"/>
<source>Property</source>
<translation></translation>
</message>
<message>
<location filename="../metadatamodel.cpp" line="319"/>
<source>Value</source>
<translation>ி</translation>
</message>
</context>
<context>
<name>SettingsDialog</name>
<message>
<location filename="../settingsdialog.cpp" line="32"/>
<source>Settings</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="40"/>
<source>Options</source>
<translation>ி</translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="52"/>
<source>Shortcuts</source>
<translation>ி</translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="62"/>
<source>Editing shortcuts for action &quot;%1&quot;:</source>
<translation> ி ி &quot;%1&quot;:</translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="71"/>
<source>Failed to set shortcuts</source>
<translation>ி ி ி</translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="72"/>
<source>Please check if shortcuts are duplicated with existing shortcuts.</source>
<translation> ி ி ி.</translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="79"/>
<source>Do nothing</source>
<translation> </translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="80"/>
<source>Close the window</source>
<translation> </translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="81"/>
<source>Toggle maximize</source>
<translation>ி </translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="82"/>
<source>Toggle fullscreen</source>
<translation> ி</translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="86"/>
<source>Zoom in and out</source>
<translation> ி ி</translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="87"/>
<source>View next or previous item</source>
<translation> ி </translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="91"/>
<source>Auto size</source>
<translation> </translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="92"/>
<source>Maximized</source>
<translation>ி</translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="93"/>
<source>Windowed</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="97"/>
<source>Round (Integer scaling)</source>
<comment>This option means round up for .5 and above</comment>
<translation> ( ி)</translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="98"/>
<source>Ceil (Integer scaling)</source>
<comment>This option means always round up</comment>
<translation> ( ி)</translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="99"/>
<source>Floor (Integer scaling)</source>
<comment>This option means always round down</comment>
<translation>ி ( ி)</translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="100"/>
<source>Follow system (Fractional scaling)</source>
<comment>This option means don&apos;t round</comment>
<translation>ிி ி (ி ி)</translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="123"/>
<source>Stay on top when start-up</source>
<translation>ி </translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="124"/>
<source>Use built-in close window animation</source>
<translation> ி </translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="125"/>
<source>Use light-color checkerboard</source>
<translation>ி- </translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="126"/>
<source>Loop the loaded gallery</source>
<translation> ி </translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="127"/>
<source>Auto long image mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="128"/>
<source>Double-click behavior</source>
<translation> </translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="129"/>
<source>Mouse wheel behavior</source>
<translation>ி </translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="130"/>
<source>Default window size</source>
<translation>ி </translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="131"/>
<source>HiDPI scale factor rounding policy</source>
<translation>HIDPI ி ி ி </translation>
</message>
</context>
<context>
<name>ShortcutEdit</name>
<message>
<location filename="../shortcutedit.cpp" line="104"/>
<source>No shortcuts</source>
<translation>ி </translation>
</message>
</context>
<context>
<name>ShortcutEditor</name>
<message>
<location filename="../shortcutedit.cpp" line="70"/>
<source>Shortcut #%1</source>
<translation>ி #%1</translation>
</message>
</context>
<context>
<name>main</name>
<message>
<location filename="../main.cpp" line="42"/>
<source>Pineapple Pictures</source>
<translation>ி </translation>
</message>
<message>
<location filename="../main.cpp" line="45"/>
<source>List supported image format suffixes, and quit program.</source>
<translation>ி ி ி ிி, ி ி.</translation>
</message>
<message>
<location filename="../main.cpp" line="49"/>
<source>File list.</source>
<translation> ி.</translation>
</message>
</context>
</TS>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -12,10 +12,18 @@ environment:
QTDIR: C:\Qt\6.8\mingw_64 QTDIR: C:\Qt\6.8\mingw_64
MINGW64: C:\Qt\Tools\mingw1310_64 MINGW64: C:\Qt\Tools\mingw1310_64
KF_BRANCH: master KF_BRANCH: master
EXIV2_VERSION: "0.28.5" EXIV2_VERSION: "0.28.3"
EXIV2_CMAKE_OPTIONS: "-DEXIV2_ENABLE_BROTLI=OFF -DEXIV2_ENABLE_INIH=OFF -DEXIV2_BUILD_EXIV2_COMMAND=OFF" EXIV2_CMAKE_OPTIONS: "-DEXIV2_ENABLE_BROTLI=OFF -DEXIV2_ENABLE_INIH=OFF -DEXIV2_BUILD_EXIV2_COMMAND=OFF"
PPIC_CMAKE_OPTIONS: "-DPREFER_QT_5=OFF" PPIC_CMAKE_OPTIONS: "-DPREFER_QT_5=OFF"
WINDEPLOYQT_ARGS: "--verbose=2 --no-quick-import --no-translations --no-opengl-sw --no-system-d3d-compiler --skip-plugin-types tls,networkinformation" WINDEPLOYQT_ARGS: "--verbose=2 --no-quick-import --no-translations --no-opengl-sw --no-system-d3d-compiler --skip-plugin-types tls,networkinformation"
- job_name: mingw81_64_qt5_15_2
QTDIR: C:\Qt\5.15.2\mingw81_64
MINGW64: C:\Qt\Tools\mingw810_64
KF_BRANCH: kf5
EXIV2_VERSION: "0.27.7"
EXIV2_CMAKE_OPTIONS: "-DEXIV2_BUILD_SAMPLES=OFF -DEXIV2_ENABLE_WIN_UNICODE=ON -DEXIV2_BUILD_EXIV2_COMMAND=OFF"
PPIC_CMAKE_OPTIONS: "-DPREFER_QT_5=ON"
WINDEPLOYQT_ARGS: "--verbose=2 --no-quick-import --no-translations --no-opengl-sw --no-angle --no-system-d3d-compiler"
install: install:
- mkdir %CMAKE_INSTALL_PREFIX% - mkdir %CMAKE_INSTALL_PREFIX%
@ -90,7 +98,7 @@ build_script:
- cd karchive - cd karchive
- mkdir build - mkdir build
- cd build - cd build
- cmake .. -G "Ninja" -DBUILD_TESTING=OFF -DWITH_LIBZSTD=OFF -DWITH_BZIP2=OFF -DWITH_LIBLZMA=OFF -DWITH_OPENSSL=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%CMAKE_INSTALL_PREFIX% - cmake .. -G "Ninja" -DWITH_LIBZSTD=OFF -DWITH_BZIP2=OFF -DWITH_LIBLZMA=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%CMAKE_INSTALL_PREFIX%
- cmake --build . --config Release - cmake --build . --config Release
- cmake --build . --config Release --target install/strip - cmake --build . --config Release --target install/strip
- cd %APPVEYOR_BUILD_FOLDER% - cd %APPVEYOR_BUILD_FOLDER%

View File

@ -13,7 +13,6 @@
<li><u>Russian</u>: Sergey Shornikov, Artem, Andrey</li> <li><u>Russian</u>: Sergey Shornikov, Artem, Andrey</li>
<li><u>Sinhala</u>: HelaBasa</li> <li><u>Sinhala</u>: HelaBasa</li>
<li><u>Spanish</u>: Toni Estévez, Génesis Toxical, William(ѕ)ⁿ, gallegonovato</li> <li><u>Spanish</u>: Toni Estévez, Génesis Toxical, William(ѕ)ⁿ, gallegonovato</li>
<li><u>Tamil</u>: தமிழ்நேரம் (TamilNeram)</li>
<li><u>Turkish</u>: E-Akcaer, Oğuz Ersen, Sabri Ünal</li> <li><u>Turkish</u>: E-Akcaer, Oğuz Ersen, Sabri Ünal</li>
<li><u>Ukrainian</u>: Dan, volkov, Сергій</li> <li><u>Ukrainian</u>: Dan, volkov, Сергій</li>
</ul> </ul>

View File

@ -1,136 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>English</string> <string>English</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string> <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key> <key>CFBundleGetInfoString</key>
<string>${MACOSX_BUNDLE_INFO_STRING}</string> <string>${MACOSX_BUNDLE_INFO_STRING}</string>
<key>CFBundleIconFile</key> <key>CFBundleIconFile</key>
<string>${MACOSX_BUNDLE_ICON_FILE}</string> <string>${MACOSX_BUNDLE_ICON_FILE}</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string> <string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key> <key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string> <string>6.0</string>
<key>CFBundleLongVersionString</key> <key>CFBundleLongVersionString</key>
<string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string> <string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string>
<key>CFBundleName</key> <key>CFBundleName</key>
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string> <string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string> <string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string> <string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<key>CSResourcesFileMapped</key> <key>CSResourcesFileMapped</key>
<true/> <true/>
<key>NSHumanReadableCopyright</key> <key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string> <string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<!-- FIXME: this list can't be automatically generated by Qt's CMake API, don't know why. --> <key>CFBundleDocumentTypes</key>
<key>CFBundleLocalizations</key> <array>
<array> <!-- JPEG -->
<string>en</string> <dict>
<string>ca</string> <key>CFBundleTypeName</key>
<string>de</string> <string>JPEG Image</string>
<string>es</string> <key>CFBundleTypeExtensions</key>
<string>fr</string> <array>
<string>id</string> <string>jpg</string>
<string>it</string> <string>jpeg</string>
<string>ja</string> <string>jfif</string>
<string>ko</string> </array>
<string>nb_NO</string> <key>CFBundleTypeMIMETypes</key>
<string>nl</string> <array>
<string>pa_PK</string> <string>image/jpeg</string>
<string>ru</string> </array>
<string>si</string> <key>CFBundleTypeRole</key>
<string>ta</string> <string>Viewer</string>
<string>tr</string> </dict>
<string>uk</string> <!-- PNG -->
<string>zh_CN</string> <dict>
</array> <key>CFBundleTypeName</key>
<key>CFBundleDocumentTypes</key> <string>PNG Image</string>
<array> <key>CFBundleTypeExtensions</key>
<!-- JPEG --> <array>
<dict> <string>png</string>
<key>CFBundleTypeName</key> </array>
<string>JPEG Image</string> <key>CFBundleTypeMIMETypes</key>
<key>CFBundleTypeExtensions</key> <array>
<array> <string>image/png</string>
<string>jpg</string> </array>
<string>jpeg</string> <key>CFBundleTypeRole</key>
<string>jfif</string> <string>Viewer</string>
</array> </dict>
<key>CFBundleTypeMIMETypes</key> <!-- WebP -->
<array> <dict>
<string>image/jpeg</string> <key>CFBundleTypeName</key>
</array> <string>WebP Image</string>
<key>CFBundleTypeRole</key> <key>CFBundleTypeExtensions</key>
<string>Viewer</string> <array>
</dict> <string>webp</string>
<!-- PNG --> </array>
<dict> <key>CFBundleTypeMIMETypes</key>
<key>CFBundleTypeName</key> <array>
<string>PNG Image</string> <string>image/webp</string>
<key>CFBundleTypeExtensions</key> </array>
<array> <key>CFBundleTypeRole</key>
<string>png</string> <string>Viewer</string>
</array> </dict>
<key>CFBundleTypeMIMETypes</key> <!-- GIF -->
<array> <dict>
<string>image/png</string> <key>CFBundleTypeName</key>
</array> <string>GIF Image</string>
<key>CFBundleTypeRole</key> <key>CFBundleTypeExtensions</key>
<string>Viewer</string> <array>
</dict> <string>gif</string>
<!-- WebP --> </array>
<dict> <key>CFBundleTypeMIMETypes</key>
<key>CFBundleTypeName</key> <array>
<string>WebP Image</string> <string>image/gif</string>
<key>CFBundleTypeExtensions</key> </array>
<array> <key>CFBundleTypeRole</key>
<string>webp</string> <string>Viewer</string>
</array> </dict>
<key>CFBundleTypeMIMETypes</key> <!-- SVG -->
<array> <dict>
<string>image/webp</string> <key>CFBundleTypeName</key>
</array> <string>SVG Image</string>
<key>CFBundleTypeRole</key> <key>CFBundleTypeExtensions</key>
<string>Viewer</string> <array>
</dict> <string>svg</string>
<!-- GIF --> </array>
<dict> <key>CFBundleTypeMIMETypes</key>
<key>CFBundleTypeName</key> <array>
<string>GIF Image</string> <string>image/svg+xml</string>
<key>CFBundleTypeExtensions</key> </array>
<array> <key>CFBundleTypeRole</key>
<string>gif</string> <string>Viewer</string>
</array> </dict>
<key>CFBundleTypeMIMETypes</key> </array>
<array> </dict>
<string>image/gif</string> </plist>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<!-- SVG -->
<dict>
<key>CFBundleTypeName</key>
<string>SVG Image</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>svg</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>image/svg+xml</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
</dict>
</plist>

View File

@ -6,7 +6,6 @@
<name xml:lang="ja">Pineapple Pictures</name> <name xml:lang="ja">Pineapple Pictures</name>
<name xml:lang="nl">Pineapple Afbeeldingen</name> <name xml:lang="nl">Pineapple Afbeeldingen</name>
<name xml:lang="ru">Pineapple Pictures</name> <name xml:lang="ru">Pineapple Pictures</name>
<name xml:lang="ta">அன்னாசி படங்கள்</name>
<name xml:lang="uk">Pineapple Pictures</name> <name xml:lang="uk">Pineapple Pictures</name>
<name xml:lang="zh-CN">菠萝看图</name> <name xml:lang="zh-CN">菠萝看图</name>
<summary>Image Viewer</summary> <summary>Image Viewer</summary>
@ -14,7 +13,6 @@
<summary xml:lang="ja">画像ビューアー</summary> <summary xml:lang="ja">画像ビューアー</summary>
<summary xml:lang="nl">Afbeeldingsweergave</summary> <summary xml:lang="nl">Afbeeldingsweergave</summary>
<summary xml:lang="ru">Просмотр изображений</summary> <summary xml:lang="ru">Просмотр изображений</summary>
<summary xml:lang="ta">பட பார்வையாளர்</summary>
<summary xml:lang="uk">Переглядач зображень</summary> <summary xml:lang="uk">Переглядач зображень</summary>
<summary xml:lang="zh-CN">图像查看器</summary> <summary xml:lang="zh-CN">图像查看器</summary>
<metadata_license>CC0-1.0</metadata_license> <metadata_license>CC0-1.0</metadata_license>
@ -25,7 +23,6 @@
<p xml:lang="ja">Pineapple Picturesは、ズームイン時に便利なナビゲーションサムネイルを備えた軽量で使いやすい画像ビューアです。画像管理のサポートは含まれていません。</p> <p xml:lang="ja">Pineapple Picturesは、ズームイン時に便利なナビゲーションサムネイルを備えた軽量で使いやすい画像ビューアです。画像管理のサポートは含まれていません。</p>
<p xml:lang="nl">Pineapple Afbeeldingen is een licht en eenvoudig te gebruiken afbeeldingsweergaveprogramma met miniatuurnavigatie na inzoomen. Het programma heeft echter geen fotobeheermogelijkheid.</p> <p xml:lang="nl">Pineapple Afbeeldingen is een licht en eenvoudig te gebruiken afbeeldingsweergaveprogramma met miniatuurnavigatie na inzoomen. Het programma heeft echter geen fotobeheermogelijkheid.</p>
<p xml:lang="ru">Pineapple Pictures - это легкий и простой в использовании просмотрщик изображений, оснащенный удобной навигацией по миниатюрам при увеличении масштаба и не содержащий никакой поддержки управления изображениями.</p> <p xml:lang="ru">Pineapple Pictures - это легкий и простой в использовании просмотрщик изображений, оснащенный удобной навигацией по миниатюрам при увеличении масштаба и не содержащий никакой поддержки управления изображениями.</p>
<p xml:lang="ta">அன்னாசி படங்கள் ஒரு இலகுரக மற்றும் பயன்படுத்த எளிதான பட பார்வையாளராகும், இது பெரிதாக்கும்போது ஒரு எளிமையான வழிசெலுத்தல் சிறுபடத்துடன் வருகிறது, மேலும் எந்த பட மேலாண்மை ஆதரவையும் கொண்டிருக்கவில்லை.</p>
<p xml:lang="uk">Pineapple Pictures це легкий і простий у використанні переглядач зображень, який постачається зі зручною навігаційною мініатюрою при збільшенні масштабу і не містить жодної підтримки керування зображеннями.</p> <p xml:lang="uk">Pineapple Pictures це легкий і простий у використанні переглядач зображень, який постачається зі зручною навігаційною мініатюрою при збільшенні масштабу і не містить жодної підтримки керування зображеннями.</p>
<p xml:lang="zh-CN">菠萝看图是一个轻量级易用的图像查看器,在图片放大时提供了方便的鸟瞰导航功能,且不包含任何图片管理功能。</p> <p xml:lang="zh-CN">菠萝看图是一个轻量级易用的图像查看器,在图片放大时提供了方便的鸟瞰导航功能,且不包含任何图片管理功能。</p>
</description> </description>
@ -51,7 +48,6 @@
<caption xml:lang="ja">画像ファイル読み込み時のメインウィンドウ</caption> <caption xml:lang="ja">画像ファイル読み込み時のメインウィンドウ</caption>
<caption xml:lang="nl">Hoofdvenster na het laden van een afbeelding</caption> <caption xml:lang="nl">Hoofdvenster na het laden van een afbeelding</caption>
<caption xml:lang="ru">Основное окно после загрузки файла изображения</caption> <caption xml:lang="ru">Основное окно после загрузки файла изображения</caption>
<caption xml:lang="ta">ஒரு படக் கோப்பு ஏற்றப்படும் போது முதன்மையான சாளரம்</caption>
<caption xml:lang="uk">Головне вікно після завантаження файлу зображення</caption> <caption xml:lang="uk">Головне вікно після завантаження файлу зображення</caption>
<caption xml:lang="zh-CN">加载图片后的主窗口</caption> <caption xml:lang="zh-CN">加载图片后的主窗口</caption>
<image type="source" width="1503" height="640">https://pineapple-pictures.sourceforge.io/ppic-gui-static.png</image> <image type="source" width="1503" height="640">https://pineapple-pictures.sourceforge.io/ppic-gui-static.png</image>
@ -62,7 +58,6 @@
<caption xml:lang="ja">ラスター画像の拡大</caption> <caption xml:lang="ja">ラスター画像の拡大</caption>
<caption xml:lang="nl">Inzoomen op een roosterafbeelding</caption> <caption xml:lang="nl">Inzoomen op een roosterafbeelding</caption>
<caption xml:lang="ru">Масштабирование растрового изображения</caption> <caption xml:lang="ru">Масштабирование растрового изображения</caption>
<caption xml:lang="ta">ராச்டர் படத்தில் பெரிதாக்குதல்</caption>
<caption xml:lang="uk">Масштабування растрового зображення</caption> <caption xml:lang="uk">Масштабування растрового зображення</caption>
<caption xml:lang="zh-CN">放大浏览位图</caption> <caption xml:lang="zh-CN">放大浏览位图</caption>
<image type="source" width="771" height="553">https://pineapple-pictures.sourceforge.io/ppic-zoom-raster.png</image> <image type="source" width="771" height="553">https://pineapple-pictures.sourceforge.io/ppic-zoom-raster.png</image>
@ -73,105 +68,12 @@
<caption xml:lang="ja">ベクター画像の拡大</caption> <caption xml:lang="ja">ベクター画像の拡大</caption>
<caption xml:lang="nl">Inzoomen op een vectorafbeelding</caption> <caption xml:lang="nl">Inzoomen op een vectorafbeelding</caption>
<caption xml:lang="ru">Масштабирование векторного изображения</caption> <caption xml:lang="ru">Масштабирование векторного изображения</caption>
<caption xml:lang="ta">ஒரு திசையன் படத்தில் பெரிதாக்குதல்</caption>
<caption xml:lang="uk">Масштабування векторного зображення</caption> <caption xml:lang="uk">Масштабування векторного зображення</caption>
<caption xml:lang="zh-CN">放大浏览矢量图</caption> <caption xml:lang="zh-CN">放大浏览矢量图</caption>
<image type="source" width="771" height="553">https://pineapple-pictures.sourceforge.io/ppic-zoom-svg.png</image> <image type="source" width="771" height="553">https://pineapple-pictures.sourceforge.io/ppic-zoom-svg.png</image>
</screenshot> </screenshot>
</screenshots> </screenshots>
<releases> <releases>
<release type="stable" version="1.1.1" date="2025-08-02T00:00:00Z">
<description>
<p>This release adds the following feature:</p>
<ul>
<li>Click dock icon should show window when it's hidden on macOS</li>
</ul>
<p>This release fixes the following bug:</p>
<ul>
<li>Ensure "Fit by Width" position the view to the beginning of the image</li>
</ul>
<p>This release includes the following changes:</p>
<ul>
<li>Update translations</li>
<li>Update Exiv2 version for Windows binary build</li>
</ul>
<p>With contributions from:</p>
<p>Heimen Stoffels, VenusGirl, தமிழ்நேரம்</p>
</description>
</release>
<release type="stable" version="1.1.0" date="2025-07-06T00:00:00Z">
<description>
<p>This release adds the following features:</p>
<ul>
<li>New option to disable built-in close window animation</li>
<li>New option to disable gallery looping</li>
<li>Support load m3u8 as image gallery playlist</li>
</ul>
<p>This release includes the following change:</p>
<ul>
<li>Drop Qt 5 support</li>
</ul>
<p>With contributions from:</p>
<p>Heimen Stoffels, albanobattistella, தமிழ்நேரம்</p>
</description>
</release>
<release type="stable" version="1.0.0" date="2025-05-03T00:00:00Z">
<description>
<p>This release adds the following features:</p>
<ul>
<li>Support enforces windowed mode on start-up</li>
<li>Reload image automatically when current image gets updated</li>
</ul>
<p>This release fixes the following bug:</p>
<ul>
<li>Display correct text language on macOS</li>
</ul>
<p>This release includes the following changes:</p>
<ul>
<li>Use native text for shortcut editor's label</li>
<li>Display native commandline message when possible</li>
<li>Merge Qt translations into app applications as well</li>
</ul>
<p>With contributions from:</p>
<p>Heimen Stoffels, albanobattistella, mmahhi</p>
</description>
</release>
<release type="stable" version="0.9.2" date="2025-03-05T00:00:00Z">
<description>
<p>This release fixes the following bug:</p>
<ul>
<li>Refer to the right exiv2 CMake module so it can be found on Linux</li>
</ul>
<p>This release includes the following changes:</p>
<ul>
<li>Convert DEP5 to REUSE.toml for better REUSE compliance</li>
<li>Update translations</li>
</ul>
<p>With contributions from:</p>
<p>Pino Toscano, TamilNeram</p>
</description>
</release>
<release type="stable" version="0.9.1" date="2025-01-25T00:00:00Z">
<description>
<p>This release adds the following features:</p>
<ul>
<li>Option to double-click to fullscreen</li>
<li>Build-time option to embed translation resources</li>
</ul>
<p>This release fixes the following bugs:</p>
<ul>
<li>Fix window size not adjusted when open file on macOS</li>
<li>Should center window according to available screen geometry</li>
</ul>
<p>This release includes the following changes:</p>
<ul>
<li>Change close window bahavior on macOS</li>
<li>Update translations</li>
</ul>
<p>With contributions from:</p>
<p>albanobattistella, Sabri Ünal</p>
</description>
</release>
<release type="stable" version="0.9.0" date="2024-12-08T00:00:00Z"> <release type="stable" version="0.9.0" date="2024-12-08T00:00:00Z">
<description> <description>
<p>This release adds the following features:</p> <p>This release adds the following features:</p>
@ -266,7 +168,7 @@
<description> <description>
<p>This release adds the following features:</p> <p>This release adds the following features:</p>
<ul> <ul>
<li>TIF and TIFF format files in the same folder will now be automatically added to the gallery</li> <li>TIF and TIFF format files in the same folder will now be automatedly added to the gallery</li>
<li>Built-in window resizing now also supports Linux desktop. (macOS might also works as well)</li> <li>Built-in window resizing now also supports Linux desktop. (macOS might also works as well)</li>
</ul> </ul>
<p>This release fixes the following bugs:</p> <p>This release fixes the following bugs:</p>

View File

@ -1,52 +0,0 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2023-08-22 18:49中国标准时间\n"
"PO-Revision-Date: 2025-01-28 09:01+0000\n"
"Last-Translator: தமிழ்நேரம் <anishprabu.t@gmail.com>\n"
"Language-Team: Tamil <https://hosted.weblate.org/projects/pineapple-pictures/"
"appstream-metadata/ta/>\n"
"Language: ta\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.10-dev\n"
#. (itstool) path: component/name
#: net.blumia.pineapple-pictures.metainfo.xml:7
msgid "Pineapple Pictures"
msgstr "அன்னாசி படங்கள்"
#. (itstool) path: component/summary
#: net.blumia.pineapple-pictures.metainfo.xml:9
msgid "Image Viewer"
msgstr "பட பார்வையாளர்"
#. (itstool) path: description/p
#: net.blumia.pineapple-pictures.metainfo.xml:12
msgid "Pineapple Pictures is a lightweight and easy-to-use image viewer that comes with a handy navigation thumbnail when zoom-in, and doesn't contain any image management support."
msgstr ""
"அன்னாசி படங்கள் ஒரு இலகுரக மற்றும் பயன்படுத்த எளிதான பட பார்வையாளராகும், இது "
"பெரிதாக்கும்போது ஒரு எளிமையான வழிசெலுத்தல் சிறுபடத்துடன் வருகிறது, மேலும் எந்த பட "
"மேலாண்மை ஆதரவையும் கொண்டிருக்கவில்லை."
#. (itstool) path: screenshot/caption
#: net.blumia.pineapple-pictures.metainfo.xml:17
msgid "Main window when an image file is loaded"
msgstr "ஒரு படக் கோப்பு ஏற்றப்படும் போது முதன்மையான சாளரம்"
#. (itstool) path: screenshot/caption
#: net.blumia.pineapple-pictures.metainfo.xml:22
msgid "Zooming in a raster image"
msgstr "ராச்டர் படத்தில் பெரிதாக்குதல்"
#. (itstool) path: screenshot/caption
#: net.blumia.pineapple-pictures.metainfo.xml:27
msgid "Zooming in a vector image"
msgstr "ஒரு திசையன் படத்தில் பெரிதாக்குதல்"
#. (itstool) path: component/developer_name
#: net.blumia.pineapple-pictures.metainfo.xml:34
msgid "Gary (BLumia) Wang et al."
msgstr "கேரி (ப்ளூமியா) வாங் மற்றும் பலர்."

View File

@ -1,101 +1,98 @@
# SPDX-FileCopyrightText: 2025 Gary Wang <git@blumia.net> # SPDX-FileCopyrightText: 2024 Gary Wang <git@blumia.net>
# #
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
QT += core widgets gui svg svgwidgets QT += core widgets gui svg
greaterThan(QT_MAJOR_VERSION, 5): QT += svgwidgets
TARGET = ppic
TEMPLATE = app TARGET = ppic
DEFINES += PPIC_VERSION_STRING=\\\"x.y.z\\\" TEMPLATE = app
DEFINES += PPIC_VERSION_STRING=\\\"x.y.z\\\"
win32 {
DEFINES += FLAG_PORTABLE_MODE_SUPPORT=1 # The following define makes your compiler emit warnings if you use
} # any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# The following define makes your compiler emit warnings if you use # deprecated API in order to know how to port your code away from it.
# any feature of Qt which has been marked as deprecated (the exact warnings DEFINES += QT_DEPRECATED_WARNINGS
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it. # You can also make your code fail to compile if you use deprecated APIs.
DEFINES += QT_DEPRECATED_WARNINGS # In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
# You can also make your code fail to compile if you use deprecated APIs. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt. CONFIG += c++17 lrelease embed_translations
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
CONFIG += c++17 lrelease embed_translations app/aboutdialog.cpp \
app/main.cpp \
SOURCES += \ app/framelesswindow.cpp \
app/aboutdialog.cpp \ app/mainwindow.cpp \
app/main.cpp \ app/graphicsview.cpp \
app/framelesswindow.cpp \ app/bottombuttongroup.cpp \
app/mainwindow.cpp \ app/graphicsscene.cpp \
app/graphicsview.cpp \ app/navigatorview.cpp \
app/bottombuttongroup.cpp \ app/opacityhelper.cpp \
app/graphicsscene.cpp \ app/toolbutton.cpp \
app/navigatorview.cpp \ app/settings.cpp \
app/opacityhelper.cpp \ app/settingsdialog.cpp \
app/toolbutton.cpp \ app/metadatamodel.cpp \
app/settings.cpp \ app/metadatadialog.cpp \
app/settingsdialog.cpp \ app/exiv2wrapper.cpp \
app/metadatamodel.cpp \ app/actionmanager.cpp \
app/metadatadialog.cpp \ app/playlistmanager.cpp \
app/exiv2wrapper.cpp \ app/shortcutedit.cpp \
app/actionmanager.cpp \ app/fileopeneventhandler.cpp
app/playlistmanager.cpp \
app/shortcutedit.cpp \ HEADERS += \
app/fileopeneventhandler.cpp app/aboutdialog.h \
app/framelesswindow.h \
HEADERS += \ app/mainwindow.h \
app/aboutdialog.h \ app/graphicsview.h \
app/framelesswindow.h \ app/bottombuttongroup.h \
app/mainwindow.h \ app/graphicsscene.h \
app/graphicsview.h \ app/navigatorview.h \
app/bottombuttongroup.h \ app/opacityhelper.h \
app/graphicsscene.h \ app/toolbutton.h \
app/navigatorview.h \ app/settings.h \
app/opacityhelper.h \ app/settingsdialog.h \
app/toolbutton.h \ app/metadatamodel.h \
app/settings.h \ app/metadatadialog.h \
app/settingsdialog.h \ app/exiv2wrapper.h \
app/metadatamodel.h \ app/actionmanager.h \
app/metadatadialog.h \ app/playlistmanager.h \
app/exiv2wrapper.h \ app/shortcutedit.h \
app/actionmanager.h \ app/fileopeneventhandler.h
app/playlistmanager.h \
app/shortcutedit.h \ TRANSLATIONS = \
app/fileopeneventhandler.h app/translations/PineapplePictures.ts \
app/translations/PineapplePictures_zh_CN.ts \
TRANSLATIONS = \ app/translations/PineapplePictures_de.ts \
app/translations/PineapplePictures_en.ts \ app/translations/PineapplePictures_es.ts \
app/translations/PineapplePictures_zh_CN.ts \ app/translations/PineapplePictures_fr.ts \
app/translations/PineapplePictures_de.ts \ app/translations/PineapplePictures_nb_NO.ts \
app/translations/PineapplePictures_es.ts \ app/translations/PineapplePictures_nl.ts \
app/translations/PineapplePictures_fr.ts \ app/translations/PineapplePictures_ru.ts \
app/translations/PineapplePictures_nb_NO.ts \ app/translations/PineapplePictures_si.ts \
app/translations/PineapplePictures_nl.ts \ app/translations/PineapplePictures_id.ts
app/translations/PineapplePictures_ru.ts \
app/translations/PineapplePictures_si.ts \ # Default rules for deployment.
app/translations/PineapplePictures_id.ts qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
# Default rules for deployment. !isEmpty(target.path): INSTALLS += target
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin RESOURCES += \
!isEmpty(target.path): INSTALLS += target assets/resources.qrc
RESOURCES += \ # Generate from svg:
assets/resources.qrc # magick convert -density 512x512 -background none app-icon.svg -define icon:auto-resize app-icon.ico
RC_ICONS = assets/icons/app-icon.ico
# Generate from svg:
# magick convert -density 512x512 -background none app-icon.svg -define icon:auto-resize app-icon.ico # Windows only, for rc file (we're not going to use the .rc file in this repo)
RC_ICONS = assets/icons/app-icon.ico QMAKE_TARGET_PRODUCT = Pineapple Pictures
QMAKE_TARGET_DESCRIPTION = Pineapple Pictures - Image Viewer
# Windows only, for rc file (we're not going to use the .rc file in this repo) QMAKE_TARGET_COPYRIGHT = MIT/Expat License - Copyright (C) 2024 Gary Wang
QMAKE_TARGET_PRODUCT = Pineapple Pictures
QMAKE_TARGET_DESCRIPTION = Pineapple Pictures - Image Viewer # MSVC only, since QMake doesn't have a CMAKE_CXX_STANDARD_LIBRARIES or cpp_winlibs similar thing
QMAKE_TARGET_COPYRIGHT = MIT/Expat License - Copyright (C) 2024 Gary Wang win32-msvc* {
LIBS += -luser32
# MSVC only, since QMake doesn't have a CMAKE_CXX_STANDARD_LIBRARIES or cpp_winlibs similar thing }
win32-msvc* {
LIBS += -luser32
}