pax_global_header00006660000000000000000000000064141442450040014510gustar00rootroot0000000000000052 comment=02e825f27a7ccb41bed2d7d3173cf1aa0f5cbb69 kImageAnnotator-0.5.3/000077500000000000000000000000001414424500400146005ustar00rootroot00000000000000kImageAnnotator-0.5.3/.github/000077500000000000000000000000001414424500400161405ustar00rootroot00000000000000kImageAnnotator-0.5.3/.github/FUNDING.yml000066400000000000000000000001451414424500400177550ustar00rootroot00000000000000# These are supported funding model platforms github: [DamirPorobic] custom: paypal.me/damirporobic kImageAnnotator-0.5.3/.github/workflows/000077500000000000000000000000001414424500400201755ustar00rootroot00000000000000kImageAnnotator-0.5.3/.github/workflows/build.yml000066400000000000000000000015631414424500400220240ustar00rootroot00000000000000name: Build on: push: branches: [ master ] pull_request: branches: [ master ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup Qt run: sudo apt-get install qtbase5-dev qttools5-dev extra-cmake-modules libqt5svg5-dev xvfb - name: Setup kColorPicker run: | git clone --depth 1 git://github.com/ksnip/kColorPicker cd kColorPicker mkdir build && cd build cmake .. make && sudo make install - name: Build working-directory: ${{github.workspace}} run: | mkdir build && cd build cmake .. -DBUILD_TESTS=ON && make VERBOSE=1 - name: Test working-directory: ${{github.workspace}}/build run: xvfb-run --auto-servernum --server-num=1 --server-args="-screen 0 1024x768x24" make test CTEST_OUTPUT_ON_FAILURE=1 kImageAnnotator-0.5.3/.gitignore000066400000000000000000000012241414424500400165670ustar00rootroot00000000000000# C++ objects and libs *.slo *.lo *.o *.a *.la *.lai *.so *.dll *.dylib # Qt-es /.qmake.cache /.qmake.stash *.pro.user *.pro.user.* *.qbs.user *.qbs.user.* *.moc moc_*.cpp qrc_*.cpp ui_*.h Makefile* *build-* # QtCreator *.autosave # QtCtreator Qml *.qmlproject.user *.qmlproject.user.* # QtCtreator CMake CMakeLists.txt.user # kdevelop apidocs .kdev4 build *~ *.kdev4 *.bak *.orig *.rej doxygen.log Doxyfile *.kdevelop *.kdevelop.filelist *.kdevelop.pcs *.kdevses .*kate-swp build/ mem.log.* massif.* callgrind.* perf.data* # from kdiff3 *.BACKUP.* *.BASE.* *.LOCAL.* *.REMOTE.* # visual studio code *.vscode/ # clion *.idea *.idea/ # misc .directorykImageAnnotator-0.5.3/CHANGELOG.md000066400000000000000000000400611414424500400164120ustar00rootroot00000000000000# Change log ## Release 0.5.3 * Fixed: Crash while typing text on wayland. ([#256](https://github.com/ksnip/kImageAnnotator/issues/256)) * Changed: Show scrollbar when not all tools visible. ([#258](https://github.com/ksnip/kImageAnnotator/issues/258)) ## Release 0.5.2 * Fixed: Memory leaks caught by ASAN. ([#243](https://github.com/ksnip/kImageAnnotator/issues/243)) * Changed: Use system font provided by QGuiApplication as default for text tool. ([#247](https://github.com/ksnip/kImageAnnotator/issues/247)) ## Release 0.5.1 * Fixed: Crashes on destruction. ([#242](https://github.com/ksnip/kImageAnnotator/issues/242)) ## Release 0.5.0 * New: Add function for loading translations. ([#173](https://github.com/ksnip/kImageAnnotator/issues/173)) * New: Add a new tool for creating resizable movable duplicates of regions. ([#131](https://github.com/ksnip/kImageAnnotator/issues/131)) * New: Add support for hiding annotation settings panel. ([#182](https://github.com/ksnip/kImageAnnotator/issues/182)) * New: Add config option for numbering tool to only set next number. ([#42](https://github.com/ksnip/kImageAnnotator/issues/42)) * New: Allow manually changing canvas size. ([#92](https://github.com/ksnip/kImageAnnotator/issues/92)) * New: Canvas background color configurable. ([#91](https://github.com/ksnip/kImageAnnotator/issues/91)) * New: Zoom in and out with keyboard shortcuts. ([#192](https://github.com/ksnip/kImageAnnotator/issues/192)) * New: Zoom in and out via buttons from UI. ([#197](https://github.com/ksnip/kImageAnnotator/issues/197)) * New: Add reset zoom keyboard shortcut with tooltip. ([#209](https://github.com/ksnip/kImageAnnotator/issues/209)) * New: Add keyboard shortcut support for text tool. ([#183](https://github.com/ksnip/kImageAnnotator/issues/183)) * New: Allow rotating background image. ([#199](https://github.com/ksnip/kImageAnnotator/issues/199)) * New: Allow flipping background image horizontally and vertically. ([#221](https://github.com/ksnip/kImageAnnotator/issues/221)) * New: Configurable UI with dockable settings widgets. ([#102](https://github.com/ksnip/kImageAnnotator/issues/102)) * New: Add invert color image effect. ([#228](https://github.com/ksnip/kImageAnnotator/issues/228)) * New: Allow disabling item shadow per item from UI. ([#223](https://github.com/ksnip/kImageAnnotator/issues/223)) * New: Add a font selection to UI. ([#130](https://github.com/ksnip/kImageAnnotator/issues/130)) * New: Add zoom in/out capability to crop view. ([#212](https://github.com/ksnip/kImageAnnotator/issues/212)) * New: Allow to zoom in modify canvas view. ([#229](https://github.com/ksnip/kImageAnnotator/issues/229)) * New: Select item after drawing it and allow changing settings. ([#230](https://github.com/ksnip/kImageAnnotator/issues/230)) * Changed: Change drop shadow to cover all sites. ([#202](https://github.com/ksnip/kImageAnnotator/issues/202)) * Fixed: Deleting item outside image doesn't decrease canvas size. ([#164](https://github.com/ksnip/kImageAnnotator/issues/164)) * Fixed: Duplicate region of grayscale image has color. ([#214](https://github.com/ksnip/kImageAnnotator/issues/214)) * Fixed: Marker shows fill and width config when modifying existing item. ([#225](https://github.com/ksnip/kImageAnnotator/issues/225)) * Fixed: Highlighter/Marker washed out color and overlapping. ([#227](https://github.com/ksnip/kImageAnnotator/issues/227)) * Fixed: Popup menus shown outside screen. ([#226](https://github.com/ksnip/kImageAnnotator/issues/226)) * Fixed: Not possible to enter value in the width tool. ([#233](https://github.com/ksnip/kImageAnnotator/issues/233)) * Fixed: Obfuscation tool shows fonts settings when switching from tool with font. ([#231](https://github.com/ksnip/kImageAnnotator/issues/231)) * Fixed: Annotation tools are not displayed if application starts with docks hidden. ([#237](https://github.com/ksnip/kImageAnnotator/issues/237)) * Fixed: Vertical scrollbar missing after using Paste embedded and moving the image. ([#232](https://github.com/ksnip/kImageAnnotator/issues/232)) * Fixed: Not possible to disable tool automatically deselected after drawn. ([#238](https://github.com/ksnip/kImageAnnotator/issues/238)) * Fixed: Annotation tool shortcuts do not work if the panel is hidden. ([#239](https://github.com/ksnip/kImageAnnotator/issues/239)) ## Release 0.4.2 * Fixed: Fetching image from annotator with HiDPI enabled pixelates image. ([#218](https://github.com/ksnip/kImageAnnotator/issues/218)) * Fixed: Keep aspect ratio only work when pressing CTRL before moving resize handle. ([#219](https://github.com/ksnip/kImageAnnotator/issues/219)) ## Release 0.4.1 * Changed: Horizontally align text inside spin box. ([#203](https://github.com/ksnip/kImageAnnotator/issues/203)) * Changed: Change zoom with mouse wheel to CTRL+Wheel. ([#210](https://github.com/ksnip/kImageAnnotator/issues/210)) * Fixed: Brazilian Portuguese translation not loaded. ([#176](https://github.com/ksnip/kImageAnnotator/issues/176)) * Fixed: error: control reaches end of non-void function. ([#177](https://github.com/ksnip/kImageAnnotator/issues/177)) * Fixed: Cursor in Text tool have too bad visibility. ([#184](https://github.com/ksnip/kImageAnnotator/issues/184)) * Fixed: bumped SONAME without name change. ([#185](https://github.com/ksnip/kImageAnnotator/issues/185)) * Fixed: Entering multiple characters at once moves the text cursor only for one character. ([#186](https://github.com/ksnip/kImageAnnotator/issues/186)) * Fixed: Activating context menu while drawing item leaves item in error state. ([#196](https://github.com/ksnip/kImageAnnotator/issues/196)) * Fixed: Icons not scaled on gnome with hdpi enabled. ([#201](https://github.com/ksnip/kImageAnnotator/issues/201)) * Fixed: Text/Number Pointer and Text/Number Arrow don't inherit Text/Number Font in Settings. ([#208](https://github.com/ksnip/kImageAnnotator/issues/208)) ## Release 0.4.0 * New: Add Pixelate image area tool. ([#140](https://github.com/ksnip/kImageAnnotator/issues/140)) * New: Zoom in and out. ([#123](https://github.com/ksnip/kImageAnnotator/issues/123)) * New: Add interface for adding custom tab context menu actions. ([#96](https://github.com/ksnip/kImageAnnotator/issues/96)) * New: Add drop shadow to captured images. ([#133](https://github.com/ksnip/kImageAnnotator/issues/133)) * New: Add grayscale image effect. ([#151](https://github.com/ksnip/kImageAnnotator/issues/151)) * New: Add numeric pointer with arrow annotation item. ([#152](https://github.com/ksnip/kImageAnnotator/issues/152)) * New: Add text pointer annotation item. ([#154](https://github.com/ksnip/kImageAnnotator/issues/154)) * New: Add text pointer with arrow annotation item. ([#153](https://github.com/ksnip/kImageAnnotator/issues/153)) * New: Add option to automatically switching to select tool after drawing item. ([#161](https://github.com/ksnip/kImageAnnotator/issues/161)) * New: Edit Text box with double click. ([#60](https://github.com/ksnip/kImageAnnotator/issues/60)) * New: Resize elements while keeping aspect ratio. ([#170](https://github.com/ksnip/kImageAnnotator/issues/170)) * Changed: Draw point when clicking and releasing without moving cursor. ([#136](https://github.com/ksnip/kImageAnnotator/issues/136)) * Changed: Zoom out less than 100%. ([#150](https://github.com/ksnip/kImageAnnotator/issues/150)) * Changed: Change to select tool after adding new annotation item. ([#155](https://github.com/ksnip/kImageAnnotator/issues/155)) * Changed: Move current zoom text to left side config panel. ([#157](https://github.com/ksnip/kImageAnnotator/issues/157)) * Fixed: Blur radius not updated when changing current items settings. ([#142](https://github.com/ksnip/kImageAnnotator/issues/142)) * Fixed: Text tool opens many unix sockets. ([#144](https://github.com/ksnip/kImageAnnotator/issues/144)) * Fixed: Text No Border and No Fill shows shadow beneath text. ([#148](https://github.com/ksnip/kImageAnnotator/issues/148)) * Fixed: Item properties remain displayed after item is removed or deselected. ([#168](https://github.com/ksnip/kImageAnnotator/issues/168)) * Fixed: Changing text box through editing text doesn't update resize handles. ([#171](https://github.com/ksnip/kImageAnnotator/issues/171)) * Fixed kColorPicker: Border around colors is not centered. ([#6](https://github.com/ksnip/kColorPicker/issues/6)) ## Release 0.3.2 * Fixed: Tests fail to build with shared library. ([#128](https://github.com/ksnip/kImageAnnotator/issues/128)) ## Release 0.3.1 * Fixed: Crashes after undoing a number annotation. ([#114](https://github.com/ksnip/kImageAnnotator/issues/114)) * Fixed: Text overlapping when resizing text box. ([#53](https://github.com/ksnip/kImageAnnotator/issues/53)) * Fixed: Snap lines to degrees not working when CTRL pressed before clicking annotation area. ([#113](https://github.com/ksnip/kImageAnnotator/issues/113)) * Fixed: "Border and Fill" submenu cutting off text under windows. ([#117](https://github.com/ksnip/kImageAnnotator/issues/117)) * Fixed: Undo removes several or all items. ([#121](https://github.com/ksnip/kImageAnnotator/issues/121)) * Fixed: Marker Rect and Ellipse draw only border but no fill. ([#126](https://github.com/ksnip/kImageAnnotator/issues/126)) ## Release 0.3.0 * New: Tabs for images. ([#48](https://github.com/ksnip/kImageAnnotator/issues/48)) * New: Add option to translate UI. ([#54](https://github.com/ksnip/kImageAnnotator/issues/54)) * New: Saved image expand to include annotations out of border. ([#90](https://github.com/ksnip/kImageAnnotator/issues/90)) * New: Add support for stickers. ([#74](https://github.com/ksnip/kImageAnnotator/issues/74)) * New: Add tab context menu for close all tabs and close other tabs. ([#93](https://github.com/ksnip/kImageAnnotator/issues/93)) * New: Add Number with Arrow/pointer tool. ([#79](https://github.com/ksnip/kImageAnnotator/issues/79)) * Changed: Make dropdown buttons show popup on click. ([#89](https://github.com/ksnip/kImageAnnotator/issues/89)) * Changed: Hide unavailable setting widgets. ([#101](https://github.com/ksnip/kImageAnnotator/issues/101)) * Changed: Make arrow size decrease with stroke size. ([#84](https://github.com/ksnip/kImageAnnotator/issues/84)) * Fixed: Using select tool marks image as changed. ([#97](https://github.com/ksnip/kImageAnnotator/issues/97)) * Fixed: Emoticon selector shows a half of current emoticon. ([#104](https://github.com/ksnip/kImageAnnotator/issues/104)) * Fixed: FillPicker text or icon sometimes not visible. ([#105](https://github.com/ksnip/kImageAnnotator/issues/105)) * Fixed: Wrong image scaling on hdpi screen. ([#81](https://github.com/ksnip/kImageAnnotator/issues/81)) * Fixed: Copy area size differs from last capture. ([#107](https://github.com/ksnip/kImageAnnotator/issues/107)) * Fixed: Number Tool not reset when switching between tabs. ([#106](https://github.com/ksnip/kImageAnnotator/issues/106)) ## Release 0.2.1 * Fixed: Edit border around text box doesn't disappear when done with editing. ([#71](https://github.com/ksnip/kImageAnnotator/issues/71)) * Fixed: Edit border not shown under Windows when NoFillNoBorder selected for Text Tool. ([#72](https://github.com/ksnip/kImageAnnotator/issues/72)) * Fixed: When adding text with background under Windows a filled rect is show in top left corner. ([#73](https://github.com/ksnip/kImageAnnotator/issues/73)) * Fixed: Drawing text tool rect from right to left and bottom top create no rect. ([#76](https://github.com/ksnip/kImageAnnotator/issues/76)) * Fixed: Text Tool FillType selection not saved. ([#75](https://github.com/ksnip/kImageAnnotator/issues/75)) * Fixed: Icons not scaled with HiDPI. ([#77](https://github.com/ksnip/kImageAnnotator/issues/77)) * Fixed: Text Cursor not show on Linux. ([#70](https://github.com/ksnip/kImageAnnotator/issues/70)) ## Release 0.2.0 * New: Add image item and interface for adding them externally. ([#45](https://github.com/ksnip/kImageAnnotator/issues/45)) * New: Edit text box content. ([#51](https://github.com/ksnip/kImageAnnotator/issues/51)) * New: Add cmake uninstall target. ([#47](https://github.com/ksnip/kImageAnnotator/issues/47)) * New: Panning image by holding space or mouse middle button and dragging. ([#9](https://github.com/ksnip/kImageAnnotator/issues/9)) * New: Change annotation element config after drawing. ([#44](https://github.com/ksnip/kImageAnnotator/issues/44)) * Changed: Increase blur level so that large text is not visible. ([#62](https://github.com/ksnip/kImageAnnotator/issues/62)) * Changed: Crop widget updates shows via cursor if something is movable. ([#64](https://github.com/ksnip/kImageAnnotator/issues/64)) * Changed: Multi-tool buttons select current (last) tool on single click. ([#66](https://github.com/ksnip/kImageAnnotator/issues/66)) * Fixed: Ctrl Modifier stuck on second or third screenshot with Ctrl-N. ([#58](https://github.com/ksnip/kImageAnnotator/issues/58)) * Fixed: Unable to select number annotation when clicking on the number without background. ([#46](https://github.com/ksnip/kImageAnnotator/issues/46)) * Fixed: Undo/Redo is now disabled during crop and scale operation. ([#56](https://github.com/ksnip/kImageAnnotator/issues/56)) * Fixed: Mess with russian letters in text tool when typing in Russian. ([#59](https://github.com/ksnip/kImageAnnotator/issues/59)) * Fixed: Text tool does not allow me to type accents. ([#57](https://github.com/ksnip/kImageAnnotator/issues/57)) * Fixed: Highlighter rect and ellipse have only border but no fill. ([#65](https://github.com/ksnip/kImageAnnotator/issues/65)) * Fixed: Saved tool selection not loaded on startup. ([#67](https://github.com/ksnip/kImageAnnotator/issues/67)) * Fixed: On startup does not highlight tool, when this tool not the first item in the list. ([#63](https://github.com/ksnip/kImageAnnotator/issues/63)) * Fixed: Cursor image cannot be grabbed for moving. ([#69](https://github.com/ksnip/kImageAnnotator/issues/69)) * Fixed: Accents still not work in text tool on Linux. ([#61](https://github.com/ksnip/kImageAnnotator/issues/61)) ## Release 0.1.0 * New: Double Arrow annotation tool. ([#23](https://github.com/ksnip/kImageAnnotator/issues/23)) * New: Marker Rectangle and Ellipse annotation tool. ([#26](https://github.com/ksnip/kImageAnnotator/issues/26)) * New: Add icons for dark theme. ([#37](https://github.com/ksnip/kImageAnnotator/issues/37)) * New: Add config option to setup blur radius. ([#25](https://github.com/ksnip/kImageAnnotator/issues/25)) * Changed: Blur tool is now preciser and fits the rect. ([#28](https://github.com/ksnip/kImageAnnotator/issues/28)) * Changed: Enter finishes text input and shift-enter adds new line in Text Tool. ([#30](https://github.com/ksnip/kImageAnnotator/issues/30)) * Changed: Text item draws border around the text when in text edit mode. ([#34](https://github.com/ksnip/kImageAnnotator/issues/34)) * Fixed: Double-click on annotation area causes SIGSEGV crash. ([#29](https://github.com/ksnip/kImageAnnotator/issues/29)) * Fixed: CAPS LOCK doesnt work on image editor. ([#27](https://github.com/ksnip/kImageAnnotator/issues/27)) * Fixed: Unable to select text item when clicking on text. ([#32](https://github.com/ksnip/kImageAnnotator/issues/32)) * Fixed: Some blurs get removed when losing focus. ([#35](https://github.com/ksnip/kImageAnnotator/issues/35)) * Fixed: Items cannot be resized when drawn from bottom right to top left. ([#38](https://github.com/ksnip/kImageAnnotator/issues/38)) * Fixed: Right click on annotation items selects item but doesn't switch tool. ([#40](https://github.com/ksnip/kImageAnnotator/issues/40)) * Fixed: Copy number annotation item doesn't increment number. ([#41](https://github.com/ksnip/kImageAnnotator/issues/41)) * Fixed: Crash on startup after adding Blur Radius Picker. ([#43](https://github.com/ksnip/kImageAnnotator/issues/43)) ## Release 0.0.2 * New: Added blur annotation tool. ([#20](https://github.com/ksnip/kImageAnnotator/issues/20)) * New: Keep number tool sequence consecutive after deleting item. ([#7](https://github.com/ksnip/kImageAnnotator/issues/7)) * New: Added control for setting first number for numbering tool. ([#7](https://github.com/ksnip/kImageAnnotator/issues/7)) * New: Text and Number tool have now noBorderAndNoFill type. ([#22](https://github.com/ksnip/kImageAnnotator/issues/22)) ## Release 0.0.1 * New: Initial release kImageAnnotator-0.5.3/CMakeLists.txt000066400000000000000000000104371414424500400173450ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.5) project(kImageAnnotator LANGUAGES CXX VERSION 0.5.3) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) option(BUILD_TESTS "Build Unit Tests" OFF) option(BUILD_EXAMPLE "Build Example Application" ON) include(GNUInstallDirs) if (WIN32) set(KIMAGEANNOTATOR_LANG_INSTALL_DIR "translations") elseif (APPLE) set(KIMAGEANNOTATOR_LANG_INSTALL_DIR "../Resources") elseif (UNIX) set(KIMAGEANNOTATOR_LANG_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/kImageAnnotator/translations") string(REGEX REPLACE "//" "/" KIMAGEANNOTATOR_LANG_INSTALL_DIR "${KIMAGEANNOTATOR_LANG_INSTALL_DIR}") endif () set(QT_MIN_VERSION "5.9.4") find_package(Qt5 ${QT_MIN_VERSION} REQUIRED Widgets Svg) if (UNIX AND NOT APPLE) find_package(X11 REQUIRED) endif () include(FeatureSummary) set(KCOLORPICKER_MIN_VERSION "0.1.6") find_package(kColorPicker ${KCOLORPICKER_MIN_VERSION} REQUIRED) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(src) add_subdirectory(translations) if (BUILD_EXAMPLE) add_subdirectory(example) endif (BUILD_EXAMPLE) if (BUILD_TESTS) find_package(Qt5 ${QT_MIN_VERSION} REQUIRED Test) enable_testing() add_subdirectory(tests) endif (BUILD_TESTS) include(CMakePackageConfigHelpers) add_library(kImageAnnotator ${KIMAGEANNOTATOR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/include/kImageAnnotator/KImageAnnotator.h ${CMAKE_CURRENT_SOURCE_DIR}/resources/kImageAnnotator_resources.qrc ) add_library(kImageAnnotator::kImageAnnotator ALIAS kImageAnnotator) target_include_directories(kImageAnnotator PUBLIC $ $ $ ) target_link_libraries(kImageAnnotator PUBLIC Qt5::Widgets Qt5::Svg PRIVATE kColorPicker::kColorPicker) if (UNIX AND NOT APPLE) if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.14.0) target_link_libraries(kImageAnnotator PRIVATE X11::X11) else() target_link_libraries(kImageAnnotator PRIVATE X11) endif() endif () target_compile_definitions(kImageAnnotator PRIVATE KIMAGEANNOTATOR_LIB) target_compile_definitions(kImageAnnotator PRIVATE KIMAGEANNOTATOR_LANG_INSTALL_DIR="${KIMAGEANNOTATOR_LANG_INSTALL_DIR}") set_target_properties(kImageAnnotator PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin VERSION ${PROJECT_VERSION} SOVERSION 0 ) install(TARGETS kImageAnnotator EXPORT kImageAnnotator-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/kImageAnnotator DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) configure_package_config_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/kImageAnnotatorConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/kImageAnnotatorConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kImageAnnotator ) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/cmake/kImageAnnotatorConfig-version.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/kImageAnnotatorConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmake/kImageAnnotatorConfig-version.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kImageAnnotator ) export( EXPORT kImageAnnotator-targets FILE ${CMAKE_CURRENT_BINARY_DIR}/cmake/kImageAnnotator-targets.cmake NAMESPACE kImageAnnotator:: ) install( EXPORT kImageAnnotator-targets FILE kImageAnnotator-targets.cmake NAMESPACE kImageAnnotator:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kImageAnnotator ) # uninstall target if(NOT TARGET uninstall) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) endif() kImageAnnotator-0.5.3/LICENSE000066400000000000000000000167441414424500400156210ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. kImageAnnotator-0.5.3/README.md000066400000000000000000000046461414424500400160710ustar00rootroot00000000000000# kImageAnnotator [![Build Status][github-badge]][github-url] [![Translation status][weblate-badge]][weblate-url] Tool for annotating images Version 0.5.3 ![kImageAnnotator](https://i.imgur.com/4vlPDUn.png "kImageAnnotator") ### Dependencies kImageAnnotator depends on [kColorPicker](https://github.com/ksnip/kColorPicker) which needs to be installed before building kImageAnnotator. Install instructions can be found on the github page. ### Building from source 1. Get latest release from GitHub by cloning the repo: `$ git clone https://github.com/ksnip/kImageAnnotator` 2. Change to repo directory: `$ cd kImageAnnotator` 3. Make new build directory and enter it: `$ mkdir build && cd build` 4. Create the makefile and build the project: `$ cmake .. && make` 5. Install shared library (not required when only using the example): `$ sudo make install` 6. Run the example application: `$ ./example/kImageAnnotator-example` ### Shared vs Static You can either build the project as shared library by providing the flag `-DBUILD_SHARED_LIBS=ON` to cmake or `-DBUILD_SHARED_LIBS=OFF` to build as static library. When no flag is provided a static library is build. For windows we currently only support building as static library. ### Integrate library 1. Let cmake find the shared library, optionally with version `set(KIMAGEANNOTATOR_MIN_VERSION "0.x.x")` `find_package(kImageAnnotator ${KIMAGEANNOTATOR_MIN_VERSION} REQUIRED)` 2. Link the library with your application `target_link_libraries(myApp kImageAnnotator)` ### Translations We are always looking for help with translations, contributors are welcome! For translations we use [Weblate](https://hosted.weblate.org/projects/kimageannotator/kimageannotator/)! [![Translation status](https://hosted.weblate.org/widgets/kimageannotator/-/kimageannotator/multi-green.svg)](https://hosted.weblate.org/engage/kimageannotator/?utm_source=widget) ### Acknowledgement Stickers designed by [OpenMoji](https://openmoji.org/) – the open-source emoji and icon project. [github-badge]: https://github.com/ksnip/kImageAnnotator/actions/workflows/build.yml/badge.svg [github-url]: https://github.com/ksnip/kImageAnnotator/actions [weblate-badge]: https://hosted.weblate.org/widgets/kimageannotator/-/kimageannotator/svg-badge.svg [weblate-url]: https://hosted.weblate.org/engage/kimageannotator/?utm_source=widgetkImageAnnotator-0.5.3/cmake/000077500000000000000000000000001414424500400156605ustar00rootroot00000000000000kImageAnnotator-0.5.3/cmake/cmake_uninstall.cmake.in000066400000000000000000000017551414424500400224500ustar00rootroot00000000000000if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) string(REGEX REPLACE "\n" ";" files "${files}") foreach(file ${files}) message(STATUS "Uninstalling $ENV{DESTDIR}${file}") if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") exec_program( "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" OUTPUT_VARIABLE rm_out RETURN_VALUE rm_retval ) if(NOT "${rm_retval}" STREQUAL 0) message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") endif(NOT "${rm_retval}" STREQUAL 0) else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") message(STATUS "File $ENV{DESTDIR}${file} does not exist.") endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") endforeach(file) kImageAnnotator-0.5.3/cmake/kImageAnnotatorConfig.cmake.in000066400000000000000000000003511414424500400234770ustar00rootroot00000000000000include(CMakeFindDependencyMacro) @PACKAGE_INIT@ find_dependency(Qt5 @QT_MIN_VERSION@ COMPONENTS Widgets) if(NOT TARGET kImageAnnotator::kImageAnnotator) include("${CMAKE_CURRENT_LIST_DIR}/kImageAnnotator-targets.cmake") endif() kImageAnnotator-0.5.3/example/000077500000000000000000000000001414424500400162335ustar00rootroot00000000000000kImageAnnotator-0.5.3/example/CMakeLists.txt000066400000000000000000000001611414424500400207710ustar00rootroot00000000000000add_executable(kImageAnnotator-example main.cpp) target_link_libraries(kImageAnnotator-example kImageAnnotator) kImageAnnotator-0.5.3/example/main.cpp000066400000000000000000000065601414424500400176720ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include #include #include #include using kImageAnnotator::KImageAnnotator; int main(int argc, char **argv) { QApplication app(argc, argv); auto settingsCollapsed = false; QPixmap pixmap(QSize(500, 500)); pixmap.fill(QColor(Qt::darkGreen)); auto kImageAnnotator = new KImageAnnotator(); kImageAnnotator->setTabBarAutoHide(true); kImageAnnotator->addTab(pixmap, QLatin1String("image1"), QLatin1String("image1")); kImageAnnotator->addTab(pixmap, QLatin1String("image2"), QLatin1String("image2")); kImageAnnotator->adjustSize(); QMainWindow mainWindow; mainWindow.setCentralWidget(kImageAnnotator); auto menuBar = mainWindow.menuBar(); auto menu = new QMenu(QLatin1String("Edit"), &mainWindow); auto annotationAction = new QAction(QLatin1String("Annotation"), &mainWindow); auto cropAction = new QAction(QLatin1String("Crop"), &mainWindow); auto scaleAction = new QAction(QLatin1String("Scale"), &mainWindow); auto rotateAction = new QAction(QLatin1String("Rotate"), &mainWindow); auto modifyCanvasAction = new QAction(QLatin1String("Modify Canvas"), &mainWindow); auto toggleDocksAction = new QAction(QLatin1String("Toggle Docks"), &mainWindow); mainWindow.connect(annotationAction, &QAction::triggered, kImageAnnotator, &KImageAnnotator::showAnnotator); mainWindow.connect(cropAction, &QAction::triggered, kImageAnnotator, &KImageAnnotator::showCropper); mainWindow.connect(scaleAction, &QAction::triggered, kImageAnnotator, &KImageAnnotator::showScaler); mainWindow.connect(rotateAction, &QAction::triggered, kImageAnnotator, &KImageAnnotator::showRotator); mainWindow.connect(modifyCanvasAction, &QAction::triggered, kImageAnnotator, &KImageAnnotator::showCanvasModifier); mainWindow.connect(toggleDocksAction, &QAction::triggered, [kImageAnnotator, settingsCollapsed]() mutable { settingsCollapsed = !settingsCollapsed; kImageAnnotator->setSettingsCollapsed(settingsCollapsed); }); mainWindow.connect(kImageAnnotator, &KImageAnnotator::tabCloseRequested, [kImageAnnotator](int tabId) { kImageAnnotator->removeTab(tabId); }); menu->addAction(annotationAction); menu->addAction(cropAction); menu->addAction(scaleAction); menu->addAction(rotateAction); menu->addAction(modifyCanvasAction); menu->addAction(toggleDocksAction); menuBar->addMenu(menu); mainWindow.show(); mainWindow.setMinimumSize(kImageAnnotator->sizeHint()); QPixmap imageItem(QSize(100, 100)); imageItem.fill(QColor(Qt::yellow)); kImageAnnotator->insertImageItem(QPointF(100,100), imageItem); return app.exec(); } kImageAnnotator-0.5.3/include/000077500000000000000000000000001414424500400162235ustar00rootroot00000000000000kImageAnnotator-0.5.3/include/kImageAnnotator/000077500000000000000000000000001414424500400213065ustar00rootroot00000000000000kImageAnnotator-0.5.3/include/kImageAnnotator/KImageAnnotator.h000066400000000000000000000055201414424500400245040ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_KIMAGEANNOTATOR_H #define KIMAGEANNOTATOR_KIMAGEANNOTATOR_H #include #include namespace kImageAnnotator { KIMAGEANNOTATOR_EXPORT void loadTranslations(); class KImageAnnotatorPrivate; class KIMAGEANNOTATOR_EXPORT KImageAnnotator : public QWidget { Q_OBJECT Q_DECLARE_PRIVATE(KImageAnnotator) public: explicit KImageAnnotator(); ~KImageAnnotator() override; QImage image() const; QImage imageAt(int index) const; QAction *undoAction(); QAction *redoAction(); QSize sizeHint() const override; void showAnnotator(); void showCropper(); void showScaler(); void showRotator(); void showCanvasModifier(); public Q_SLOTS: void loadImage(const QPixmap &pixmap); int addTab(const QPixmap &pixmap, const QString &title, const QString &toolTip); void updateTabInfo(int index, const QString &title, const QString &toolTip); void insertImageItem(const QPointF &position, const QPixmap &pixmap); Q_DECL_DEPRECATED void setTextFont(const QFont &font); Q_DECL_DEPRECATED void setNumberFont(const QFont &font); Q_DECL_DEPRECATED void setItemShadowEnabled(bool enabled); void setSmoothPathEnabled(bool enabled); void setSaveToolSelection(bool enabled); void setSmoothFactor(int factor); void setSwitchToSelectToolAfterDrawingItem(bool enabled); void setNumberToolSeedChangeUpdatesAllItems(bool enabled); void setTabBarAutoHide(bool enabled); void removeTab(int index); void setStickers(const QStringList &stickerPaths, bool keepDefault); void addTabContextMenuActions(const QList & actions); void setSettingsCollapsed(bool isCollapsed); void setCanvasColor(const QColor &color); void setSelectItemAfterDrawing(bool enabled); Q_SIGNALS: void imageChanged() const; void currentTabChanged(int index) const; void tabCloseRequested(int index) const; void tabMoved(int fromIndex, int toIndex); void tabContextMenuOpened(int index) const; private: QScopedPointer const d_ptr; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_KIMAGEANNOTATOR_H kImageAnnotator-0.5.3/include/kImageAnnotator/KImageAnnotatorExport.h000066400000000000000000000022611414424500400257050ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_KIMAGEANNOTATOR_EXPORT_H #define KIMAGEANNOTATOR_KIMAGEANNOTATOR_EXPORT_H #include #if defined(_WIN32) # define KIMAGEANNOTATOR_EXPORT #else #if defined(KIMAGEANNOTATOR_LIB) # define KIMAGEANNOTATOR_EXPORT Q_DECL_EXPORT #else # define KIMAGEANNOTATOR_EXPORT Q_DECL_IMPORT #endif #endif #endif // KIMAGEANNOTATOR_KIMAGEANNOTATOR_EXPORT_HkImageAnnotator-0.5.3/resources/000077500000000000000000000000001414424500400166125ustar00rootroot00000000000000kImageAnnotator-0.5.3/resources/icons/000077500000000000000000000000001414424500400177255ustar00rootroot00000000000000kImageAnnotator-0.5.3/resources/icons/dark/000077500000000000000000000000001414424500400206465ustar00rootroot00000000000000kImageAnnotator-0.5.3/resources/icons/dark/arrow.svg000066400000000000000000000066431414424500400225320ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/blur.svg000066400000000000000000000157771414424500400223540ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/bold.svg000066400000000000000000000056521414424500400223170ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/border.svg000066400000000000000000000036761414424500400226600ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/check.svg000066400000000000000000000035741414424500400224550ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/color.svg000066400000000000000000000047201414424500400225100ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/disabled.svg000066400000000000000000000046531414424500400231460ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/doubleArrow.svg000066400000000000000000000123421414424500400236560ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/dragHandle.svg000066400000000000000000000103521414424500400234210ustar00rootroot00000000000000 image/svg+xmlkImageAnnotator-0.5.3/resources/icons/dark/dropShadow.svg000066400000000000000000000070631414424500400235070ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/duplicate.svg000066400000000000000000001006111414424500400233400ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/effect.svg000066400000000000000000000154041414424500400226270ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/ellipse.svg000066400000000000000000000036431414424500400230320ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/fillType.svg000066400000000000000000000114071414424500400231620ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/fillType_borderAndFill.svg000066400000000000000000000037121414424500400257510ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/fillType_borderAndNoFill.svg000066400000000000000000000055311414424500400262470ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/fillType_noBorderAndNoFill.svg000066400000000000000000000037351414424500400265500ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/grayscale.svg000066400000000000000000000112231414424500400233400ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/invertColor.svg000066400000000000000000000060761414424500400237060ustar00rootroot00000000000000 image/svg+xmlkImageAnnotator-0.5.3/resources/icons/dark/italic.svg000066400000000000000000000051411414424500400226350ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/line.svg000066400000000000000000000037161414424500400223250ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/markerEllipse.svg000066400000000000000000000155501414424500400241740ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/markerPen.svg000066400000000000000000000122521414424500400233150ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/markerRect.svg000066400000000000000000000151211414424500400234660ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/number.svg000066400000000000000000000055071414424500400226660ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/numberArrow.svg000066400000000000000000000257571414424500400237120ustar00rootroot00000000000000 image/svg+xml   1 kImageAnnotator-0.5.3/resources/icons/dark/numberPointer.svg000066400000000000000000000100471414424500400242220ustar00rootroot00000000000000 image/svg+xml   kImageAnnotator-0.5.3/resources/icons/dark/obfuscateFactor.svg000066400000000000000000000101171414424500400245010ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/pen.svg000066400000000000000000000153561414424500400221630ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/pixelate.svg000066400000000000000000000132341414424500400232050ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/rect.svg000066400000000000000000000036471414424500400223360ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/select.svg000066400000000000000000000074331414424500400226550ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/sticker.svg000066400000000000000000000061111414424500400230320ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/text.svg000066400000000000000000000042701414424500400223560ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/textArrow.svg000066400000000000000000000265311414424500400233750ustar00rootroot00000000000000 image/svg+xml     kImageAnnotator-0.5.3/resources/icons/dark/textColor.svg000066400000000000000000000062231414424500400233550ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/textPointer.svg000066400000000000000000000074471414424500400237300ustar00rootroot00000000000000 image/svg+xml   kImageAnnotator-0.5.3/resources/icons/dark/underline.svg000066400000000000000000000057371414424500400233700ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/width.svg000066400000000000000000000114201414424500400225040ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/dark/zoom.svg000066400000000000000000000047401414424500400223600ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/000077500000000000000000000000001414424500400210345ustar00rootroot00000000000000kImageAnnotator-0.5.3/resources/icons/light/arrow.svg000066400000000000000000000066431414424500400227200ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/blur.svg000066400000000000000000000136361414424500400225320ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/bold.svg000066400000000000000000000056501414424500400225030ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/border.svg000066400000000000000000000036731414424500400230430ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/check.svg000066400000000000000000000036031414424500400226340ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/color.svg000066400000000000000000000047141414424500400227010ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/disabled.svg000066400000000000000000000046501414424500400233310ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/doubleArrow.svg000066400000000000000000000124051414424500400240440ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/dragHandle.svg000066400000000000000000000140141414424500400236060ustar00rootroot00000000000000 image/svg+xmlkImageAnnotator-0.5.3/resources/icons/light/dropShadow.svg000066400000000000000000000070601414424500400236720ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/duplicate.svg000066400000000000000000001005061414424500400235310ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/effect.svg000066400000000000000000000155311414424500400230160ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/ellipse.svg000066400000000000000000000036521414424500400232200ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/fillType.svg000066400000000000000000000114351414424500400233510ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/fillType_borderAndFill.svg000066400000000000000000000037241414424500400261420ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/fillType_borderAndNoFill.svg000066400000000000000000000055311414424500400264350ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/fillType_noBorderAndNoFill.svg000066400000000000000000000037351414424500400267360ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/grayscale.svg000066400000000000000000000111351414424500400235300ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/invertColor.svg000066400000000000000000000061071414424500400240670ustar00rootroot00000000000000 image/svg+xmlkImageAnnotator-0.5.3/resources/icons/light/italic.svg000066400000000000000000000051561414424500400230310ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/line.svg000066400000000000000000000037131414424500400225100ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/markerEllipse.svg000066400000000000000000000155411414424500400243620ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/markerPen.svg000066400000000000000000000122471414424500400235070ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/markerRect.svg000066400000000000000000000151251414424500400236600ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/number.svg000066400000000000000000000054671414424500400230610ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/numberArrow.svg000066400000000000000000000256651414424500400240760ustar00rootroot00000000000000 image/svg+xml   1 kImageAnnotator-0.5.3/resources/icons/light/numberPointer.svg000066400000000000000000000101701414424500400244050ustar00rootroot00000000000000 image/svg+xml   kImageAnnotator-0.5.3/resources/icons/light/obfuscateFactor.svg000066400000000000000000000100451414424500400246670ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/pen.svg000066400000000000000000000155251414424500400223470ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/pixelate.svg000066400000000000000000000132421414424500400233720ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/rect.svg000066400000000000000000000036521414424500400225200ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/select.svg000066400000000000000000000075141414424500400230430ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/sticker.svg000066400000000000000000000062041414424500400232230ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/text.svg000066400000000000000000000042711414424500400225450ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/textArrow.svg000066400000000000000000000265311414424500400235630ustar00rootroot00000000000000 image/svg+xml     kImageAnnotator-0.5.3/resources/icons/light/textColor.svg000066400000000000000000000062521414424500400235450ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/textPointer.svg000066400000000000000000000073351414424500400241120ustar00rootroot00000000000000 image/svg+xml   kImageAnnotator-0.5.3/resources/icons/light/underline.svg000066400000000000000000000060101414424500400235370ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/width.svg000066400000000000000000000115401414424500400226750ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/icons/light/zoom.svg000066400000000000000000000050111414424500400225360ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/kImageAnnotator_resources.qrc000066400000000000000000000160721414424500400245040ustar00rootroot00000000000000 icons/dark/arrow.svg icons/dark/duplicate.svg icons/dark/doubleArrow.svg icons/dark/number.svg icons/dark/numberPointer.svg icons/dark/numberArrow.svg icons/dark/markerPen.svg icons/dark/markerRect.svg icons/dark/markerEllipse.svg icons/dark/line.svg icons/dark/pen.svg icons/dark/rect.svg icons/dark/select.svg icons/dark/sticker.svg icons/dark/text.svg icons/dark/textPointer.svg icons/dark/textArrow.svg icons/dark/ellipse.svg icons/dark/blur.svg icons/dark/pixelate.svg icons/dark/obfuscateFactor.svg icons/dark/color.svg icons/dark/width.svg icons/dark/textColor.svg icons/dark/fillType.svg icons/dark/fillType_borderAndFill.svg icons/dark/fillType_borderAndNoFill.svg icons/dark/fillType_noBorderAndNoFill.svg icons/dark/effect.svg icons/dark/border.svg icons/dark/dropShadow.svg icons/dark/grayscale.svg icons/dark/invertColor.svg icons/dark/disabled.svg icons/dark/zoom.svg icons/dark/dragHandle.svg icons/dark/check.svg icons/dark/bold.svg icons/dark/italic.svg icons/dark/underline.svg icons/light/arrow.svg icons/light/duplicate.svg icons/light/doubleArrow.svg icons/light/number.svg icons/light/numberPointer.svg icons/light/numberArrow.svg icons/light/markerPen.svg icons/light/markerRect.svg icons/light/markerEllipse.svg icons/light/line.svg icons/light/pen.svg icons/light/rect.svg icons/light/select.svg icons/light/sticker.svg icons/light/text.svg icons/light/textPointer.svg icons/light/textArrow.svg icons/light/ellipse.svg icons/light/blur.svg icons/light/pixelate.svg icons/light/obfuscateFactor.svg icons/light/color.svg icons/light/width.svg icons/light/textColor.svg icons/light/fillType.svg icons/light/fillType_borderAndFill.svg icons/light/fillType_borderAndNoFill.svg icons/light/fillType_noBorderAndNoFill.svg icons/light/effect.svg icons/light/border.svg icons/light/dropShadow.svg icons/light/grayscale.svg icons/light/invertColor.svg icons/light/disabled.svg icons/light/zoom.svg icons/light/dragHandle.svg icons/light/check.svg icons/light/bold.svg icons/light/italic.svg icons/light/underline.svg stickers/face_blowing_a_kiss.svg stickers/face_savoring_food.svg stickers/grinning_face_with_big_eyes.svg stickers/grinning_face_with_smiling_eyes.svg stickers/grinning_face_with_sweat.svg stickers/grinning_squinting_face.svg stickers/hushed_face.svg stickers/nerd_face.svg stickers/neutral_face.svg stickers/smiling_face_with_heart_eyes.svg stickers/smiling_face_with_hearts.svg stickers/confused_face.svg stickers/face_with_symbols_on_mouth.svg stickers/pouting_face.svg stickers/smiling_face_with_sunglasses.svg stickers/check_mark.svg stickers/cross_mark.svg kImageAnnotator-0.5.3/resources/stickers/000077500000000000000000000000001414424500400204415ustar00rootroot00000000000000kImageAnnotator-0.5.3/resources/stickers/check_mark.svg000066400000000000000000000041001414424500400232440ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/confused_face.svg000066400000000000000000000055071414424500400237550ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/cross_mark.svg000066400000000000000000000046241414424500400233330ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/face_blowing_a_kiss.svg000066400000000000000000000120211414424500400251260ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/face_savoring_food.svg000066400000000000000000000074001414424500400250000ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/face_with_symbols_on_mouth.svg000066400000000000000000000122361414424500400265770ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/grinning_face_with_big_eyes.svg000066400000000000000000000065711414424500400266650ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/grinning_face_with_smiling_eyes.svg000066400000000000000000000072451414424500400275650ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/grinning_face_with_sweat.svg000066400000000000000000000104741414424500400262170ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/grinning_squinting_face.svg000066400000000000000000000070511414424500400260570ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/hushed_face.svg000066400000000000000000000077001414424500400234240ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/nerd_face.svg000066400000000000000000000134541414424500400230770ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/neutral_face.svg000066400000000000000000000054071414424500400236200ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/pouting_face.svg000066400000000000000000000065211414424500400236310ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/smiling_face_with_heart_eyes.svg000066400000000000000000000114321414424500400270460ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/smiling_face_with_hearts.svg000066400000000000000000000152231414424500400262060ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/resources/stickers/smiling_face_with_sunglasses.svg000066400000000000000000000140601414424500400271050ustar00rootroot00000000000000 image/svg+xml kImageAnnotator-0.5.3/src/000077500000000000000000000000001414424500400153675ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/CMakeLists.txt000066400000000000000000000254671414424500400201450ustar00rootroot00000000000000set(KIMAGEANNOTATOR_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/gui/KImageAnnotator.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/CoreView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/AnnotationWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/AnnotationView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/scrollAndZoomView/ScrollAndZoomView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/scrollAndZoomView/ViewZoomer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/settings/ItemSettingsWidgetConfigurator.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/settings/AnnotationSettingsAdapter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/settings/AnnotationItemSettings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/settings/AnnotationImageSettings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/settings/AnnotationGeneralSettings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/settings/AnnotationToolSelection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/docks/AnnotationDockWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/docks/AnnotationDockWidgetDragHandle.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/docks/AbstractAnnotationDockWidgetContent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/tabs/AnnotationTabContent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/tabs/AnnotationTabWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/tabs/AnnotationTabContextMenu.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/tabs/AnnotationTabCloser.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/canvasModifier/ModifyCanvasView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/canvasModifier/ModifyCanvasWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/canvasModifier/ModifyCanvasSelectionRestrictor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/cropper/CropWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/cropper/CropView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/cropper/CropSelectionRestrictor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/selection/SelectionHandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/selection/SelectionMoveHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/selection/SelectionHandles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/selection/BaseSelectionView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/rotator/RotateDialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/rotator/RotateWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/scaler/ScaleDialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/scaler/ScaleWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/scaler/ScaleSizeHandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/core/ZoomValueProvider.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/core/AnnotationArea.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/core/AnnotationItemFactory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/core/AnnotationPropertiesFactory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/core/AbstractSettingsProvider.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/core/imageEffects/ImageEffectFactory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/core/imageEffects/NoImageEffect.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/core/imageEffects/DropShadowImageEffect.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/core/imageEffects/BorderImageEffect.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/core/imageEffects/GrayscaleImageEffect.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/core/imageEffects/InvertColorImageEffect.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/properties/AnnotationProperties.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/properties/AnnotationPathProperties.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/properties/AnnotationTextProperties.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/properties/AnnotationObfuscateProperties.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/properties/AnnotationStickerProperties.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/AnnotationItemModifier.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/AnnotationItemResizer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/AnnotationMultiItemResizer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/AnnotationItemSelector.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/AnnotationItemMover.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/AnnotationItemArranger.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/AnnotationItemEditor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/resizeHandles/AbstractItemResizeHandles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/resizeHandles/AbstractRectResizeHandles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/resizeHandles/LineResizeHandles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/resizeHandles/RectResizeHandles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/resizeHandles/PathResizeHandles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/resizeHandles/PointerRectResizeHandles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/resizeHandles/ResizeHandle.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/resizeHandles/ResizeHandlesFactory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AbstractAnnotationItem.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AbstractAnnotationLine.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AbstractAnnotationObfuscate.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AbstractAnnotationRect.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AbstractAnnotationPointerRect.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AbstractAnnotationPath.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationLine.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationMarkerEllipse.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationMarkerPen.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationMarkerRect.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationArrow.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationDoubleArrow.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationRect.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationEllipse.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationNumber.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationNumberPointer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationNumberArrow.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationPen.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationPixelate.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationText.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationTextPointer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationTextArrow.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationBlur.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationImage.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationSticker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationDuplicate.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/BaseAnnotationNumber.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/text/AnnotationTextHandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/text/KeyInputHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/text/TextCursor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/text/CapsLockStatusChecker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/helper/NumberRectHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/helper/AnnotationShapeCreator.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/AddCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/DeleteCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/FlipCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/MoveCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/ResizeCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/ArrangeCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/CropCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/ScaleCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/RotateCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/PasteCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/ChangePropertiesCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/ModifyCanvasCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/misc/ShadowEffect.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/misc/ImageBlurrer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/misc/AnnotationItemClipboard.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/misc/AnnotationContextMenu.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/misc/NumberManager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/misc/CanvasPainter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/backend/Config.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/provider/DevicePixelRatioScaler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/provider/ScaledSizeProvider.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/helper/CursorHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/helper/KeyHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/helper/MathHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/helper/ItemHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/helper/ShapeHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/helper/ConfigNameHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/helper/IconLoader.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/helper/PathHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/filter/IgnoreShortcutsFilter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/filter/KeyEventListener.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/platform/PlatformChecker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/ToolPicker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/CustomFontComboBox.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/CustomSpinBox.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/CustomToolButton.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/CustomToolButtonAction.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/ToggleButton.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/ColorDialogButton.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/settingsPicker/ColorPicker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/settingsPicker/NumberPicker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/settingsPicker/BoolPicker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/settingsPicker/FillModePicker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/settingsPicker/FontPicker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/settingsPicker/SettingsPickerWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/settingsPicker/StickerPicker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/settingsPicker/ImageEffectPicker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/settingsPicker/ZoomPicker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/menuButtons/GridMenu.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/menuButtons/GridMenuButton.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/menuButtons/GridMenuToolButton.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/menuButtons/ListMenuToolButton.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/menuButtons/ListMenu.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/menuButtons/ListMenuItem.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/menuButtons/ListItemGroup.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/misc/AbstractExpandingWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/misc/FlowLayout.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/misc/AttachedSeparator.cpp ) set(KIMAGEANNOTATOR_SRCS ${KIMAGEANNOTATOR_SRCS} PARENT_SCOPE) kImageAnnotator-0.5.3/src/annotations/000077500000000000000000000000001414424500400177245ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/annotations/core/000077500000000000000000000000001414424500400206545ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/annotations/core/AbstractSettingsProvider.cpp000066400000000000000000000043151414424500400263620ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AbstractSettingsProvider.h" namespace kImageAnnotator { AbstractSettingsProvider::AbstractSettingsProvider() : mSettingsListener(nullptr), mZoomValueProvider(nullptr) { } void AbstractSettingsProvider::toolChanged(Tools tool) { if(mSettingsListener != nullptr) { mSettingsListener->toolChanged(tool); } } void AbstractSettingsProvider::numberToolSeedChanged(int numberToolSeed) { if(mSettingsListener != nullptr) { mSettingsListener->numberToolSeedChanged(numberToolSeed); } } void AbstractSettingsProvider::itemSettingChanged() { if(mSettingsListener != nullptr) { mSettingsListener->itemSettingsChanged(); } } void AbstractSettingsProvider::setActiveListener(ISettingsListener *settingsListener) { mSettingsListener = settingsListener; if(mSettingsListener != nullptr) { updateNumberToolSeed(mSettingsListener->numberToolSeed()); } } void AbstractSettingsProvider::setActiveZoomValueProvider(ZoomValueProvider *zoomValueProvider) { mZoomValueProvider = zoomValueProvider; if(mZoomValueProvider != nullptr) { updateZoomLevel(mZoomValueProvider->zoomValue()); } } void AbstractSettingsProvider::effectChanged(ImageEffects effect) { if(mSettingsListener != nullptr) { mSettingsListener->imageEffectChanged(effect); } } void AbstractSettingsProvider::zoomValueChanged(double value) { if(mZoomValueProvider != nullptr) { mZoomValueProvider->setZoomValue(value); } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/core/AbstractSettingsProvider.h000066400000000000000000000045301414424500400260260ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ABSTRACTSETTINGSPROVIDER_H #define KIMAGEANNOTATOR_ABSTRACTSETTINGSPROVIDER_H #include #include #include "ISettingsListener.h" #include "ZoomValueProvider.h" #include "src/common/enum/FillModes.h" #include "src/annotations/items/AbstractAnnotationItem.h" namespace kImageAnnotator { class AbstractSettingsProvider { public: AbstractSettingsProvider(); ~AbstractSettingsProvider() = default; virtual void editItem(AbstractAnnotationItem *item) = 0; virtual void activateSelectTool() = 0; virtual Tools toolType() const = 0; virtual QColor toolColor() const = 0; virtual QColor textColor() const = 0; virtual int toolWidth() const = 0; virtual QFont font() const = 0; virtual FillModes fillType() const = 0; virtual int obfuscationFactor() const = 0; virtual QString sticker() const = 0; virtual ImageEffects effect() const = 0; virtual bool shadowEnabled() const = 0; virtual void updateNumberToolSeed(int numberToolSeed) = 0; virtual void updateZoomLevel(double value) = 0; void setActiveListener(ISettingsListener *settingsListener); void setActiveZoomValueProvider(ZoomValueProvider *zoomValueProvider); protected: virtual void toolChanged(Tools tool); virtual void numberToolSeedChanged(int numberToolSeed); virtual void itemSettingChanged(); virtual void effectChanged(ImageEffects effect); virtual void zoomValueChanged(double value); private: ISettingsListener *mSettingsListener; ZoomValueProvider *mZoomValueProvider; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ABSTRACTSETTINGSPROVIDER_H kImageAnnotator-0.5.3/src/annotations/core/AnnotationArea.cpp000066400000000000000000000317701414424500400242730ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationArea.h" namespace kImageAnnotator { AnnotationArea::AnnotationArea( Config *config, AbstractSettingsProvider *settingsProvider, IDevicePixelRatioScaler *devicePixelRatioScaler, ZoomValueProvider *zoomValueProvider, QWidget *parent) : QGraphicsScene(parent), mUndoStack(new UndoStack), mBackgroundImage(nullptr), mCurrentItem(nullptr), mUndoAction(nullptr), mRedoAction(nullptr), mConfig(config), mKeyHelper(new KeyHelper), mSettingsProvider(settingsProvider), mItemModifier(new AnnotationItemModifier(zoomValueProvider)), mPropertiesFactory(new AnnotationPropertiesFactory(config, mSettingsProvider)), mItemFactory(new AnnotationItemFactory(mPropertiesFactory, mSettingsProvider, mConfig)), mItems(new QList()), mItemCopier(new AnnotationItemClipboard(mItemModifier)), mDevicePixelRatioScaler(devicePixelRatioScaler), mCanvasColor(config->canvasColor()) { Q_ASSERT(mSettingsProvider != nullptr); Q_ASSERT(mConfig != nullptr); addItem(mItemModifier); connect(mItemModifier, &AnnotationItemModifier::newCommand, mUndoStack, &UndoStack::push); connect(mItemModifier, &AnnotationItemModifier::itemsSelected, this, &AnnotationArea::itemsSelected); connect(mItemModifier, &AnnotationItemModifier::itemsDeselected, this, &AnnotationArea::itemsDeselected); connect(mItemModifier, &AnnotationItemModifier::itemModified, this, &AnnotationArea::imageChanged); connect(mUndoStack, &UndoStack::indexChanged, this, &AnnotationArea::update); connect(mKeyHelper, &KeyHelper::deleteReleased, this, &AnnotationArea::deleteSelectedItems); connect(mKeyHelper, &KeyHelper::escapeReleased, mItemModifier, &AnnotationItemModifier::clear); connect(mKeyHelper, &KeyHelper::undoPressed, mUndoStack, &UndoStack::undo); connect(mKeyHelper, &KeyHelper::redoPressed, mUndoStack, &UndoStack::redo); connect(&mKeyListener, &KeyEventListener::keyPressed, mKeyHelper, &KeyHelper::keyPress); connect(&mKeyListener, &KeyEventListener::keyReleased, mKeyHelper, &KeyHelper::keyRelease); } AnnotationArea::~AnnotationArea() { delete mPropertiesFactory; delete mItemFactory; delete mItems; delete mKeyHelper; delete mUndoStack; delete mItemModifier; delete mItemCopier; delete mDevicePixelRatioScaler; } void AnnotationArea::loadImage(const QPixmap &image) { if (image.isNull()) { return; } resetAnnotationArea(); replaceBackgroundImage(image); imageEffectChanged(mSettingsProvider->effect()); } void AnnotationArea::insertImageItem(const QPointF &position, const QPixmap &image) { auto imageItem = mItemFactory->create(position, image); mUndoStack->push(new AddCommand(imageItem, this)); toolChanged(mSettingsProvider->toolType()); } void AnnotationArea::replaceBackgroundImage(const QPixmap &image) { mBackgroundImage = QSharedPointer(addPixmap(image)); setSceneRect(QRect()); } QImage AnnotationArea::image() { if (mBackgroundImage == nullptr) { return QImage(); } mItemModifier->clear(); setSceneRect(canvasRect()); auto scaleFactor = mDevicePixelRatioScaler->scaleFactor(); auto sceneRect = this->sceneRect(); auto scaledSceneSize = sceneRect.size().toSize() * scaleFactor; auto scaledSceneRect = QRectF(sceneRect.topLeft(), scaledSceneSize); QImage image(scaledSceneSize, QImage::Format_ARGB32_Premultiplied); image.fill(mCanvasColor); image.setDevicePixelRatio(scaleFactor); QPainter painter(&image); painter.setRenderHint(QPainter::Antialiasing); render(&painter, QRectF(), scaledSceneRect); setSceneRect(QRect()); // Reset scene rect return image; } QAction *AnnotationArea::undoAction() { if(mUndoAction == nullptr) { mUndoAction = mUndoStack->createUndoAction(this); } return mUndoAction; } QAction *AnnotationArea::redoAction() { if(mRedoAction == nullptr) { mRedoAction = mUndoStack->createRedoAction(this); } return mRedoAction; } void AnnotationArea::addAnnotationItem(AbstractAnnotationItem *item) { mItems->prepend(item); addItem(item); emit imageChanged(); } void AnnotationArea::removeAnnotationItem(AbstractAnnotationItem *item) { removeItem(item); mItems->removeOne(item); emit imageChanged(); } void AnnotationArea::crop(const QRectF &rect) { auto scaledRect = mDevicePixelRatioScaler->scale(rect); mUndoStack->push(new CropCommand(mBackgroundImage.data(), scaledRect, this)); emit imageChanged(); } void AnnotationArea::scale(const QSize &size) { mUndoStack->push(new ScaleCommand(mBackgroundImage.data(), size, this)); emit imageChanged(); } void AnnotationArea::rotate(qreal angel) { mUndoStack->push(new RotateCommand(mBackgroundImage.data(), angel, this)); emit imageChanged(); } void AnnotationArea::flip(FlipDirection direction) { mUndoStack->push(new FlipCommand(mBackgroundImage.data(), direction)); emit imageChanged(); } void AnnotationArea::clearSelection() { mItemModifier->clear(); QGraphicsScene::clearSelection(); } void AnnotationArea::itemSettingsChanged() { auto selectedItems = mItemModifier->selectedItems(); if(selectedItems.count() == 1) { auto item = selectedItems.first(); auto properties = mPropertiesFactory->create(item->toolType()); mUndoStack->push(new ChangePropertiesCommand(item, properties)); } } void AnnotationArea::numberToolSeedChanged(int numberToolSeed) { mItemFactory->setNumberToolSeed(numberToolSeed); } int AnnotationArea::numberToolSeed() const { return mItemFactory->numberToolSeed(); } void AnnotationArea::imageEffectChanged(ImageEffects effect) { auto graphicsEffect = ImageEffectFactory::create(effect); mBackgroundImage->setGraphicsEffect(graphicsEffect); } void AnnotationArea::setCanvasRect(const QRectF &rect) { mCanvasRect = rect; } QRectF AnnotationArea::canvasRect() const { if(!isCustomCanvasRect()) { auto backgroundImageRect = mBackgroundImage->graphicsEffect()->boundingRect(); return annotationItemsBoundingRect().united(backgroundImageRect); } else { return mCanvasRect; } } bool AnnotationArea::isCustomCanvasRect() const { return !mCanvasRect.isNull(); } void AnnotationArea::setCanvasColor(const QColor &color) { mCanvasColor = color; } QColor AnnotationArea::canvasColor() const { return mCanvasColor; } void AnnotationArea::modifyCanvas(const QRectF &canvasRect, const QColor &color) { mUndoStack->push(new ModifyCanvasCommand(canvasRect, color, this)); emit imageChanged(); } QRectF AnnotationArea::backgroundImageRect() const { return mBackgroundImage->boundingRect(); } void AnnotationArea::update() { mItemModifier->updateSelection(); QGraphicsScene::update(); } void AnnotationArea::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { if (mSettingsProvider->toolType() == Tools::Select) { mItemModifier->handleMousePress(event->scenePos(), mItems, mKeyHelper->isControlPressed()); } else { mItemModifier->clear(); addItemAtPosition(event->scenePos()); } } QGraphicsScene::mousePressEvent(event); } void AnnotationArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (event->buttons() == Qt::LeftButton) { if (mCurrentItem) { addPointToCurrentItem(event->scenePos()); } else { mItemModifier->handleMouseMove(event->scenePos(), mKeyHelper->isControlPressed()); } } QGraphicsScene::mouseMoveEvent(event); } void AnnotationArea::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { if (mSettingsProvider->toolType() == Tools::Select) { mItemModifier->handleMouseRelease(mItems); } finishDrawingItem(event->scenePos()); } QGraphicsScene::mouseReleaseEvent(event); } void AnnotationArea::finishDrawingItem(const QPointF &pos) { if(mCurrentItem != nullptr) { mCurrentItem->finish(); auto isSelectToolAfterDrawingEnabled = mConfig->switchToSelectToolAfterDrawingItem() && mConfig->selectItemAfterDrawing(); if (mCurrentItem->requiresSelectionAfterCreation() || isSelectToolAfterDrawingEnabled) { mItemModifier->selectItem(mCurrentItem); } else if (mConfig->switchToSelectToolAfterDrawingItem()) { mSettingsProvider->activateSelectTool(); } mCurrentItem = nullptr; } } QRectF AnnotationArea::annotationItemsBoundingRect() const { QRectF boundingRect; for(auto item : *mItems) { boundingRect = boundingRect.united(item->boundingRect()); } return boundingRect; } void AnnotationArea::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton && mSettingsProvider->toolType() == Tools::Select) { mItemModifier->handleMouseDoubleClick(event->scenePos(), mItems); } } void AnnotationArea::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { finishDrawingItem(event->scenePos()); mItemModifier->handleSelectionAt(event->scenePos(), mItems, mKeyHelper->isControlPressed()); auto selectedItems = mItemModifier->selectedItems(); AnnotationContextMenu contextMenu; auto isMenuOverItem = !selectedItems.isEmpty(); contextMenu.setOverItem(isMenuOverItem); contextMenu.setPastEnabled(!mItemCopier->isEmpty()); contextMenu.setEditVisible(selectedEditableItem() != nullptr); AnnotationItemArranger itemArranger(selectedItems, mItems); connect(&itemArranger, &AnnotationItemArranger::newCommand, mUndoStack, &UndoStack::push); connect(&contextMenu, &AnnotationContextMenu::bringToFront, &itemArranger, &AnnotationItemArranger::bringToFront); connect(&contextMenu, &AnnotationContextMenu::bringForward, &itemArranger, &AnnotationItemArranger::bringForward); connect(&contextMenu, &AnnotationContextMenu::sendBackward, &itemArranger, &AnnotationItemArranger::sendBackward); connect(&contextMenu, &AnnotationContextMenu::sendToBack, &itemArranger, &AnnotationItemArranger::sendToBack); connect(&contextMenu, &AnnotationContextMenu::copy, mItemCopier, &AnnotationItemClipboard::copyItems); connect(&contextMenu, &AnnotationContextMenu::paste, this, &AnnotationArea::pasteCopiedItems); connect(&contextMenu, &AnnotationContextMenu::erase, this, &AnnotationArea::deleteSelectedItems); connect(&contextMenu, &AnnotationContextMenu::edit, this, &AnnotationArea::enableEditing); contextMenu.exec(event->screenPos()); } void AnnotationArea::addItemAtPosition(const QPointF &position) { mCurrentItem = mItemFactory->create(position); mUndoStack->push(new AddCommand(mCurrentItem, this)); } void AnnotationArea::addPointToCurrentItem(const QPointF &position) { mCurrentItem->addPoint(position, mKeyHelper->isControlPressed()); } void AnnotationArea::toolChanged(Tools toolType) { auto isSelectTool = toolType == Tools::Select; for (auto item : *mItems) { if (isSelectTool) { item->setCursor(CursorHelper::movableCursor()); } else { item->unsetCursor(); } } if (!isSelectTool) { mItemModifier->clear(); } } void AnnotationArea::resetAnnotationArea() { removeAllItems(); mItemModifier->clear(); mItemCopier->clear(); mUndoStack->clear(); mItemFactory->reset(); mKeyHelper->reset(); } void AnnotationArea::removeAllItems() { for (auto item : *mItems) { removeAnnotationItem(item); } } void AnnotationArea::deleteSelectedItems() { auto selectedItems = mItemModifier->selectedItems(); mItemModifier->clear(); mUndoStack->push(new DeleteCommand(selectedItems, this)); if (mSettingsProvider->toolType() == Tools::Select) { mSettingsProvider->activateSelectTool(); } } void AnnotationArea::pasteCopiedItems(const QPointF &position) { auto copiedItems = mItemCopier->copiedItemsWithOffset(); mUndoStack->push(new PasteCommand(copiedItems, position, mItemFactory, this)); } void AnnotationArea::enableEditing() { auto editableItem = selectedEditableItem(); if(editableItem != nullptr) { mItemModifier->clear(); editableItem->enableEditing(); itemsDeselected(); } } EditableItem* AnnotationArea::selectedEditableItem() const { auto selectedItems = mItemModifier->selectedItems(); return selectedItems.length() != 1 ? nullptr : dynamic_cast(selectedItems[0]); } void AnnotationArea::itemsSelected(const QList &items) const { if(items.count() != 1) { mSettingsProvider->activateSelectTool(); return; } auto item = items.first(); mSettingsProvider->editItem(item); } void AnnotationArea::itemsDeselected() { mSettingsProvider->activateSelectTool(); } void AnnotationArea::dragMoveEvent(QGraphicsSceneDragDropEvent *event) { Q_UNUSED(event) // Overriding default dragMoveEvent in order to accept drops without items under them } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/core/AnnotationArea.h000066400000000000000000000123621414424500400237340ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONAREA_H #define KIMAGEANNOTATOR_ANNOTATIONAREA_H #include #include #include #include #include #include #include "AnnotationItemFactory.h" #include "AbstractSettingsProvider.h" #include "ISettingsListener.h" #include "src/annotations/modifiers/AnnotationItemModifier.h" #include "src/annotations/modifiers/AnnotationItemArranger.h" #include "src/annotations/misc/AnnotationItemClipboard.h" #include "src/annotations/misc/AnnotationContextMenu.h" #include "src/backend/Config.h" #include "src/common/enum/Tools.h" #include "src/common/enum/FlipDirection.h" #include "src/common/helper/CursorHelper.h" #include "src/common/helper/KeyHelper.h" #include "src/common/provider/IDevicePixelRatioScaler.h" #include "src/common/filter/KeyEventListener.h" #include "src/annotations/undo/UndoStack.h" #include "src/annotations/undo/CropCommand.h" #include "src/annotations/undo/FlipCommand.h" #include "src/annotations/undo/ScaleCommand.h" #include "src/annotations/undo/PasteCommand.h" #include "src/annotations/undo/ChangePropertiesCommand.h" #include "src/annotations/undo/ModifyCanvasCommand.h" #include "src/annotations/undo/RotateCommand.h" #include "src/annotations/core/ZoomValueProvider.h" #include "src/annotations/core/imageEffects/ImageEffectFactory.h" namespace kImageAnnotator { class AnnotationArea : public QGraphicsScene, public ISettingsListener { Q_OBJECT public: explicit AnnotationArea(Config *config, AbstractSettingsProvider *settingsProvider, IDevicePixelRatioScaler *devicePixelRatioScaler, ZoomValueProvider *zoomValueProvider, QWidget *parent); ~AnnotationArea() override; virtual void loadImage(const QPixmap &image); virtual void insertImageItem(const QPointF &position, const QPixmap &image); QImage image(); QAction* undoAction(); QAction* redoAction(); virtual void addAnnotationItem(AbstractAnnotationItem *item); virtual void removeAnnotationItem(AbstractAnnotationItem *item); virtual void crop(const QRectF& rect); virtual void scale(const QSize& size); virtual void rotate(qreal angel); virtual void flip(FlipDirection direction); virtual void clearSelection(); virtual void toolChanged(Tools toolType) override; void itemSettingsChanged() override; void numberToolSeedChanged(int numberToolSeed) override; int numberToolSeed() const override; void imageEffectChanged(ImageEffects effect) override; void setCanvasRect(const QRectF &rect); QRectF canvasRect() const; bool isCustomCanvasRect() const; void setCanvasColor(const QColor &color); QColor canvasColor() const; void modifyCanvas(const QRectF &canvasRect, const QColor &color); QRectF backgroundImageRect() const; public slots: virtual void update(); signals: void imageChanged() const; protected: void mousePressEvent(QGraphicsSceneMouseEvent* event) override; void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override; void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override; void dragMoveEvent(QGraphicsSceneDragDropEvent *event) override; void contextMenuEvent(QGraphicsSceneContextMenuEvent * event) override; private: Config *mConfig; AbstractSettingsProvider *mSettingsProvider; AnnotationPropertiesFactory *mPropertiesFactory; AnnotationItemFactory *mItemFactory; QSharedPointer mBackgroundImage; AbstractAnnotationItem *mCurrentItem; AnnotationItemModifier *mItemModifier; QList *mItems; KeyHelper *mKeyHelper; UndoStack *mUndoStack; AnnotationItemClipboard *mItemCopier; QAction *mUndoAction; QAction *mRedoAction; IDevicePixelRatioScaler *mDevicePixelRatioScaler; KeyEventListener mKeyListener; QRectF mCanvasRect; QColor mCanvasColor; void addItemAtPosition(const QPointF& position); void addPointToCurrentItem(const QPointF& position); void resetAnnotationArea(); void removeAllItems(); void replaceBackgroundImage(const QPixmap &image); void finishDrawingItem(const QPointF &pos); QRectF annotationItemsBoundingRect() const; private slots: void deleteSelectedItems(); void pasteCopiedItems(const QPointF &position); void enableEditing(); EditableItem* selectedEditableItem() const; void itemsSelected(const QList &items) const; void itemsDeselected(); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONAREA_H kImageAnnotator-0.5.3/src/annotations/core/AnnotationItemFactory.cpp000066400000000000000000000212371414424500400256460ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemFactory.h" namespace kImageAnnotator { AnnotationItemFactory::AnnotationItemFactory(AnnotationPropertiesFactory *propertiesFactory, AbstractSettingsProvider *settingsProvider, Config *config) : mPropertiesFactory(propertiesFactory), mSettingsProvider(settingsProvider), mConfig(config), mNumberManager(new NumberManager), mNextZValue(1) { Q_ASSERT(mSettingsProvider != nullptr); Q_ASSERT(mConfig != nullptr); connect(mConfig, &Config::numberUpdateModeChanged, this, &AnnotationItemFactory::setNumberUpdateMode); connect(mNumberManager, &NumberManager::numberSeedChanged, this, &AnnotationItemFactory::numberSeedChanged); setNumberUpdateMode(mConfig->numberUpdateMode()); reset(); } AnnotationItemFactory::~AnnotationItemFactory() { delete mNumberManager; } void AnnotationItemFactory::reset() { mNextZValue = 1; mNumberManager->reset(); } void AnnotationItemFactory::setNumberToolSeed(int numberSeed) { mNumberManager->setNumberSeed(numberSeed); } int AnnotationItemFactory::numberToolSeed() const { return mNumberManager->numberSeed(); } void AnnotationItemFactory::setNumberUpdateMode(NumberUpdateMode numberUpdateMode) { mNumberManager->setNumberUpdateMode(numberUpdateMode); } AbstractAnnotationItem *AnnotationItemFactory::create(const QPointF &initPosition) { auto toolType = mSettingsProvider->toolType(); auto properties = mPropertiesFactory->create(toolType); auto newItem = createItem(initPosition, toolType, properties); setZValue(newItem); return newItem; } AbstractAnnotationItem *AnnotationItemFactory::create(const QPointF &initPosition, const QPixmap &image) { auto properties = mPropertiesFactory->createFromConfig(Tools::Image); auto newItem = new AnnotationImage(initPosition, image, properties); setZValue(newItem); return newItem; } AbstractAnnotationItem *AnnotationItemFactory::clone(const AbstractAnnotationItem *item) { Q_ASSERT(item != nullptr); auto newItem = cloneItem(item); setZValue(newItem); return newItem; } AbstractAnnotationItem *AnnotationItemFactory::createItem(const QPointF &initPosition, const Tools &toolType, const PropertiesPtr &properties) { AbstractAnnotationItem *newItem = nullptr; switch (toolType) { case Tools::Duplicate: newItem = new AnnotationDuplicate(initPosition, properties); break; case Tools::Pen: newItem = new AnnotationPen(initPosition, properties.staticCast()); break; case Tools::MarkerPen: newItem = new AnnotationMarkerPen(initPosition, properties.staticCast()); break; case Tools::MarkerRect: newItem = new AnnotationMarkerRect(initPosition, properties); break; case Tools::MarkerEllipse: newItem = new AnnotationMarkerEllipse(initPosition, properties); break; case Tools::Line: newItem = new AnnotationLine(initPosition, properties); break; case Tools::Ellipse: newItem = new AnnotationEllipse(initPosition, properties); break; case Tools::Rect: newItem = new AnnotationRect(initPosition, properties); break; case Tools::Arrow: newItem = new AnnotationArrow(initPosition, properties); break; case Tools::DoubleArrow: newItem = new AnnotationDoubleArrow(initPosition, properties); break; case Tools::Number: newItem = new AnnotationNumber(initPosition, properties.staticCast()); mNumberManager->addItem(dynamic_cast(newItem)); break; case Tools::NumberPointer: newItem = new AnnotationNumberPointer(initPosition, properties.staticCast()); mNumberManager->addItem(dynamic_cast(newItem)); break; case Tools::NumberArrow: newItem = new AnnotationNumberArrow(initPosition, properties.staticCast()); mNumberManager->addItem(dynamic_cast(newItem)); break; case Tools::Text: newItem = new AnnotationText(initPosition, properties.staticCast()); break; case Tools::TextPointer: newItem = new AnnotationTextPointer(initPosition, properties.staticCast()); break; case Tools::TextArrow: newItem = new AnnotationTextArrow(initPosition, properties.staticCast()); break; case Tools::Blur: newItem = new AnnotationBlur(initPosition, properties.staticCast()); break; case Tools::Pixelate: newItem = new AnnotationPixelate(initPosition, properties.staticCast()); break; case Tools::Sticker: newItem = new AnnotationSticker(initPosition, properties.staticCast()); break; default: qCritical("Cannot create item for provided tool type."); } return newItem; } AbstractAnnotationItem *AnnotationItemFactory::cloneItem(const AbstractAnnotationItem *item) { Q_ASSERT(item != nullptr); AbstractAnnotationItem *newItem = nullptr; switch (item->toolType()) { case Tools::Duplicate: newItem = new AnnotationDuplicate(*(dynamic_cast(item))); break; case Tools::Pen: newItem = new AnnotationPen(*(dynamic_cast(item))); break; case Tools::MarkerPen: newItem = new AnnotationMarkerPen(*(dynamic_cast(item))); break; case Tools::MarkerRect: newItem = new AnnotationMarkerRect(*(dynamic_cast(item))); break; case Tools::MarkerEllipse: newItem = new AnnotationMarkerEllipse(*(dynamic_cast(item))); break; case Tools::Line: newItem = new AnnotationLine(*(dynamic_cast(item))); break; case Tools::Ellipse: newItem = new AnnotationEllipse(*(dynamic_cast(item))); break; case Tools::Rect: newItem = new AnnotationRect(*(dynamic_cast(item))); break; case Tools::Arrow: newItem = new AnnotationArrow(*(dynamic_cast(item))); break; case Tools::DoubleArrow: newItem = new AnnotationDoubleArrow(*(dynamic_cast(item))); break; case Tools::Number: newItem = new AnnotationNumber(*(dynamic_cast(item))); mNumberManager->addItem(dynamic_cast(newItem)); break; case Tools::NumberPointer: newItem = new AnnotationNumberPointer(*(dynamic_cast(item))); mNumberManager->addItem(dynamic_cast(newItem)); break; case Tools::NumberArrow: newItem = new AnnotationNumberArrow(*(dynamic_cast(item))); mNumberManager->addItem(dynamic_cast(newItem)); break; case Tools::Text: newItem = new AnnotationText(*(dynamic_cast(item))); break; case Tools::TextPointer: newItem = new AnnotationTextPointer(*(dynamic_cast(item))); break; case Tools::TextArrow: newItem = new AnnotationTextArrow(*(dynamic_cast(item))); break; case Tools::Blur: newItem = new AnnotationBlur(*(dynamic_cast(item))); break; case Tools::Pixelate: newItem = new AnnotationPixelate(*(dynamic_cast(item))); break; case Tools::Image: newItem = new AnnotationImage(*(dynamic_cast(item))); break; case Tools::Sticker: newItem = new AnnotationSticker(*(dynamic_cast(item))); break; default: qCritical("Cannot create item for provided tool type."); } return newItem; } void AnnotationItemFactory::setZValue(AbstractAnnotationItem *item) { if (item != nullptr) { item->setZValue(mNextZValue++); } } void AnnotationItemFactory::numberSeedChanged(int newNumberSeed) { mSettingsProvider->updateNumberToolSeed(newNumberSeed); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/core/AnnotationItemFactory.h000066400000000000000000000064401414424500400253120ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMFACTORY_H #define KIMAGEANNOTATOR_ANNOTATIONITEMFACTORY_H #include #include "AnnotationPropertiesFactory.h" #include "src/annotations/items/AnnotationDuplicate.h" #include "src/annotations/items/AnnotationPen.h" #include "src/annotations/items/AnnotationPixelate.h" #include "src/annotations/items/AnnotationLine.h" #include "src/annotations/items/AnnotationMarkerEllipse.h" #include "src/annotations/items/AnnotationMarkerPen.h" #include "src/annotations/items/AnnotationMarkerRect.h" #include "src/annotations/items/AnnotationArrow.h" #include "src/annotations/items/AnnotationDoubleArrow.h" #include "src/annotations/items/AnnotationRect.h" #include "src/annotations/items/AnnotationEllipse.h" #include "src/annotations/items/AnnotationNumber.h" #include "src/annotations/items/AnnotationNumberPointer.h" #include "src/annotations/items/AnnotationNumberArrow.h" #include "src/annotations/items/AnnotationText.h" #include "src/annotations/items/AnnotationTextPointer.h" #include "src/annotations/items/AnnotationTextArrow.h" #include "src/annotations/items/AnnotationBlur.h" #include "src/annotations/items/AnnotationImage.h" #include "src/annotations/items/AnnotationSticker.h" #include "src/annotations/misc/NumberManager.h" #include "src/common/enum/Tools.h" #include "src/common/enum/NumberUpdateMode.h" namespace kImageAnnotator { class AnnotationItemFactory : public QObject { Q_OBJECT public: explicit AnnotationItemFactory(AnnotationPropertiesFactory *propertiesFactory, AbstractSettingsProvider *settingsProvider, Config *config); ~AnnotationItemFactory() override; void reset(); void setNumberToolSeed(int numberSeed); int numberToolSeed() const; AbstractAnnotationItem *create(const QPointF &initPosition); AbstractAnnotationItem *create(const QPointF &initPosition, const QPixmap &image); AbstractAnnotationItem *clone(const AbstractAnnotationItem *item); private slots: void setNumberUpdateMode(NumberUpdateMode numberUpdateMode); private: int mNextZValue; AnnotationPropertiesFactory *mPropertiesFactory; AbstractSettingsProvider *mSettingsProvider; NumberManager *mNumberManager; Config *mConfig; AbstractAnnotationItem *createItem(const QPointF &initPosition, const Tools &toolType, const PropertiesPtr &properties); AbstractAnnotationItem *cloneItem(const AbstractAnnotationItem *item); void setZValue(AbstractAnnotationItem *item); void numberSeedChanged(int newNumberSeed); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONITEMFACTORY_H kImageAnnotator-0.5.3/src/annotations/core/AnnotationPropertiesFactory.cpp000066400000000000000000000115601414424500400271020ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationPropertiesFactory.h" namespace kImageAnnotator { AnnotationPropertiesFactory::AnnotationPropertiesFactory(Config *config, AbstractSettingsProvider *settingsProvider) : mConfig(config), mSettingsProvider(settingsProvider) { Q_ASSERT(mConfig != nullptr); Q_ASSERT(mSettingsProvider != nullptr); } PropertiesPtr AnnotationPropertiesFactory::create(Tools tool) const { return create(tool, false); } PropertiesPtr AnnotationPropertiesFactory::createFromConfig(Tools tool) const { return create(tool, true); } PropertiesPtr AnnotationPropertiesFactory::create(Tools tool, bool fromConfig) const { auto properties = createPropertiesObject(tool); setColor(properties, tool); setTextColor(properties); setWidthSize(properties); setFill(properties, tool); setShadowEnabled(properties, tool, fromConfig); setPathProperties(properties); setTextProperties(properties, tool); setObfuscateProperties(properties); setStickerProperties(properties); return properties; } PropertiesPtr AnnotationPropertiesFactory::createPropertiesObject(Tools toolType) { switch (toolType) { case Tools::Pen: case Tools::MarkerPen: return PropertiesPtr(new AnnotationPathProperties()); case Tools::Number: case Tools::NumberPointer: case Tools::NumberArrow: case Tools::Text: case Tools::TextPointer: case Tools::TextArrow: return PropertiesPtr(new AnnotationTextProperties()); case Tools::Blur: case Tools::Pixelate: return PropertiesPtr(new AnnotationObfuscateProperties()); case Tools ::Sticker: return PropertiesPtr(new AnnotationStickerProperties()); default: return PropertiesPtr(new AnnotationProperties()); } } void AnnotationPropertiesFactory::setColor(const PropertiesPtr &properties, Tools toolType) const { auto color = mSettingsProvider->toolColor(); if(toolType == Tools::Duplicate) { color.setAlpha(30); } properties->setColor(color); } void AnnotationPropertiesFactory::setTextColor(const PropertiesPtr &properties) const { properties->setTextColor(mSettingsProvider->textColor()); } void AnnotationPropertiesFactory::setWidthSize(const PropertiesPtr &properties) const { properties->setWidth(mSettingsProvider->toolWidth()); } void AnnotationPropertiesFactory::setFill(const PropertiesPtr &properties, Tools toolType) const { switch (toolType) { case Tools::MarkerPen: case Tools::MarkerRect: case Tools::MarkerEllipse: case Tools::Image: case Tools::Sticker: case Tools::NumberPointer: case Tools::TextPointer: case Tools::Duplicate: properties->setFillType(mConfig->toolFillType(toolType)); break; default: properties->setFillType(mSettingsProvider->fillType()); } } void AnnotationPropertiesFactory::setShadowEnabled(const PropertiesPtr &properties, Tools tool, bool fromConfig) const { auto enabled = fromConfig ? mConfig->shadowEnabled(tool) : mSettingsProvider->shadowEnabled(); properties->setShadowEnabled(enabled); } void AnnotationPropertiesFactory::setPathProperties(const PropertiesPtr &properties) const { auto pathProperties = properties.dynamicCast(); if (pathProperties != nullptr) { pathProperties->setSmoothPathEnabled(mConfig->smoothPathEnabled()); pathProperties->setSmoothFactor(mConfig->smoothFactor()); } } void AnnotationPropertiesFactory::setTextProperties(const PropertiesPtr &properties, Tools toolType) const { auto textProperties = properties.dynamicCast(); if (textProperties != nullptr) { textProperties->setFont(mSettingsProvider->font()); } } void AnnotationPropertiesFactory::setObfuscateProperties(const PropertiesPtr &properties) const { auto obfuscateProperties = properties.dynamicCast(); if (obfuscateProperties != nullptr) { obfuscateProperties->setFactor(mSettingsProvider->obfuscationFactor()); } } void AnnotationPropertiesFactory::setStickerProperties(const PropertiesPtr &properties) const { auto stickerProperties = properties.dynamicCast(); if (stickerProperties != nullptr) { stickerProperties->setPath(mSettingsProvider->sticker()); } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/core/AnnotationPropertiesFactory.h000066400000000000000000000050201414424500400265410ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONPROPERTIESFACTORY_H #define KIMAGEANNOTATOR_ANNOTATIONPROPERTIESFACTORY_H #include "src/annotations/properties/AnnotationProperties.h" #include "src/annotations/properties/AnnotationPathProperties.h" #include "src/annotations/properties/AnnotationTextProperties.h" #include "src/annotations/properties/AnnotationObfuscateProperties.h" #include "src/annotations/properties/AnnotationStickerProperties.h" #include "src/backend/Config.h" #include "src/common/enum/Tools.h" #include "AbstractSettingsProvider.h" namespace kImageAnnotator { class AnnotationPropertiesFactory { public: explicit AnnotationPropertiesFactory(Config *config, AbstractSettingsProvider *settingsProvider); ~AnnotationPropertiesFactory() = default; PropertiesPtr create(Tools tool) const; PropertiesPtr createFromConfig(Tools tool) const; private: Config *mConfig; AbstractSettingsProvider *mSettingsProvider; PropertiesPtr create(Tools tool, bool fromConfig) const; static PropertiesPtr createPropertiesObject(Tools toolType); void setShadowEnabled(const PropertiesPtr &properties, Tools tool, bool fromConfig) const; void setColor(const PropertiesPtr &properties, Tools toolType) const; void setTextColor(const PropertiesPtr &properties) const; void setWidthSize(const PropertiesPtr &properties) const; void setFill(const PropertiesPtr &properties, Tools toolType) const; void setPathProperties(const PropertiesPtr &properties) const; void setTextProperties(const PropertiesPtr &properties, Tools toolType) const; void setObfuscateProperties(const PropertiesPtr &properties) const; void setStickerProperties(const PropertiesPtr &properties) const; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONPROPERTIESFACTORY_H kImageAnnotator-0.5.3/src/annotations/core/ISettingsListener.h000066400000000000000000000025261414424500400244510ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ISETTINGSLISTENER_H #define KIMAGEANNOTATOR_ISETTINGSLISTENER_H #include "src/common/enum/Tools.h" #include "src/common/enum/ImageEffects.h" namespace kImageAnnotator { class ISettingsListener { public: virtual void toolChanged(Tools toolType) = 0; virtual void itemSettingsChanged() = 0; virtual void numberToolSeedChanged(int numberToolSeed) = 0; virtual int numberToolSeed() const = 0; virtual void imageEffectChanged(ImageEffects effect) = 0; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ISETTINGSLISTENER_H kImageAnnotator-0.5.3/src/annotations/core/ZoomValueProvider.cpp000066400000000000000000000017421414424500400250200ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ZoomValueProvider.h" namespace kImageAnnotator { kImageAnnotator::ZoomValueProvider::ZoomValueProvider(QObject *parent) : QObject(parent) { } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/core/ZoomValueProvider.h000066400000000000000000000024531414424500400244650ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ZOOMVALUEPROVIDER_H #define KIMAGEANNOTATOR_ZOOMVALUEPROVIDER_H #include namespace kImageAnnotator { class ZoomValueProvider : public QObject { Q_OBJECT public: explicit ZoomValueProvider(QObject *parent = nullptr); ~ZoomValueProvider() override = default; virtual double zoomValue() const = 0; virtual void setZoomValue(double zoomValue) = 0; signals: void zoomValueChanged(double value); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ZOOMVALUEPROVIDER_H kImageAnnotator-0.5.3/src/annotations/core/imageEffects/000077500000000000000000000000001414424500400232365ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/annotations/core/imageEffects/BorderImageEffect.cpp000066400000000000000000000021061414424500400272360ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "BorderImageEffect.h" namespace kImageAnnotator { void BorderImageEffect::draw(QPainter *painter) { QPoint offset; const auto pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset); painter->drawPixmap(offset, pixmap); painter->drawRect(pixmap.rect()); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/core/imageEffects/BorderImageEffect.h000066400000000000000000000023331414424500400267050ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_BORDERIMAGEEFFECT_H #define KIMAGEANNOTATOR_BORDERIMAGEEFFECT_H #include #include namespace kImageAnnotator { class BorderImageEffect : public QGraphicsEffect { Q_OBJECT public: explicit BorderImageEffect() = default; ~BorderImageEffect() override = default; protected: void draw(QPainter * painter) override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_BORDERIMAGEEFFECT_H kImageAnnotator-0.5.3/src/annotations/core/imageEffects/DropShadowImageEffect.cpp000066400000000000000000000017651414424500400301050ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "DropShadowImageEffect.h" namespace kImageAnnotator { DropShadowImageEffect::DropShadowImageEffect() { setColor(QColor(0, 0, 0)); setBlurRadius(30); setOffset(QPoint(0, 2)); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/core/imageEffects/DropShadowImageEffect.h000066400000000000000000000022641414424500400275450ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_DROPSHADOWIMAGEEFFECT_H #define KIMAGEANNOTATOR_DROPSHADOWIMAGEEFFECT_H #include namespace kImageAnnotator { class DropShadowImageEffect : public QGraphicsDropShadowEffect { Q_OBJECT public: explicit DropShadowImageEffect(); ~DropShadowImageEffect() override = default; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_DROPSHADOWIMAGEEFFECT_H kImageAnnotator-0.5.3/src/annotations/core/imageEffects/GrayscaleImageEffect.cpp000066400000000000000000000021341414424500400277340ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "GrayscaleImageEffect.h" namespace kImageAnnotator { void GrayscaleImageEffect::draw(QPainter *painter) { QPoint offset; const auto pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset); painter->drawImage(offset, pixmap.toImage().convertToFormat(QImage::Format_Grayscale8)); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/core/imageEffects/GrayscaleImageEffect.h000066400000000000000000000023551414424500400274060ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_GRAYSCALEIMAGEEFFECT_H #define KIMAGEANNOTATOR_GRAYSCALEIMAGEEFFECT_H #include #include namespace kImageAnnotator { class GrayscaleImageEffect : public QGraphicsEffect { Q_OBJECT public: explicit GrayscaleImageEffect() = default; ~GrayscaleImageEffect() override = default; protected: void draw(QPainter * painter) override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_GRAYSCALEIMAGEEFFECT_H kImageAnnotator-0.5.3/src/annotations/core/imageEffects/ImageEffectFactory.cpp000066400000000000000000000023561414424500400274370ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ImageEffectFactory.h" QGraphicsEffect *kImageAnnotator::ImageEffectFactory::create(kImageAnnotator::ImageEffects effect) { switch (effect) { case ImageEffects::DropShadow: return new DropShadowImageEffect; case ImageEffects::Border: return new BorderImageEffect; case ImageEffects::Grayscale: return new GrayscaleImageEffect; case ImageEffects::InvertColor: return new InvertColorImageEffect; default: return new NoImageEffect; } } kImageAnnotator-0.5.3/src/annotations/core/imageEffects/ImageEffectFactory.h000066400000000000000000000025611414424500400271020ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_IMAGEEFFECTFACTORY_H #define KIMAGEANNOTATOR_IMAGEEFFECTFACTORY_H #include #include "NoImageEffect.h" #include "DropShadowImageEffect.h" #include "GrayscaleImageEffect.h" #include "BorderImageEffect.h" #include "InvertColorImageEffect.h" #include "src/common/enum/ImageEffects.h" namespace kImageAnnotator { class ImageEffectFactory { public: explicit ImageEffectFactory() = default; ~ImageEffectFactory() = default; static QGraphicsEffect* create(ImageEffects effect); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_IMAGEEFFECTFACTORY_H kImageAnnotator-0.5.3/src/annotations/core/imageEffects/InvertColorImageEffect.cpp000066400000000000000000000021041414424500400302650ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "InvertColorImageEffect.h" namespace kImageAnnotator { void InvertColorImageEffect::draw(QPainter *painter) { QPoint offset; auto image = sourcePixmap(Qt::LogicalCoordinates, &offset).toImage(); image.invertPixels(); painter->drawImage(offset, image); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/core/imageEffects/InvertColorImageEffect.h000066400000000000000000000023721414424500400277410ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_INVERTCOLORIMAGEEFFECT_H #define KIMAGEANNOTATOR_INVERTCOLORIMAGEEFFECT_H #include #include namespace kImageAnnotator { class InvertColorImageEffect : public QGraphicsEffect { Q_OBJECT public: explicit InvertColorImageEffect() = default; ~InvertColorImageEffect() override = default; protected: void draw(QPainter * painter) override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_INVERTCOLORIMAGEEFFECT_H kImageAnnotator-0.5.3/src/annotations/core/imageEffects/NoImageEffect.cpp000066400000000000000000000020321414424500400263730ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "NoImageEffect.h" namespace kImageAnnotator { void NoImageEffect::draw(QPainter *painter) { QPoint offset; const auto pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset); painter->drawPixmap(offset, pixmap); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/core/imageEffects/NoImageEffect.h000066400000000000000000000023031414424500400260410ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_NOIMAGEEFFECT_H #define KIMAGEANNOTATOR_NOIMAGEEFFECT_H #include #include namespace kImageAnnotator { class NoImageEffect : public QGraphicsEffect { Q_OBJECT public: explicit NoImageEffect() = default; ~NoImageEffect() override = default; protected: void draw(QPainter * painter) override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_NOIMAGEEFFECT_H kImageAnnotator-0.5.3/src/annotations/items/000077500000000000000000000000001414424500400210455ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/annotations/items/AbstractAnnotationItem.cpp000066400000000000000000000115041414424500400261670ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AbstractAnnotationItem.h" namespace kImageAnnotator { AbstractAnnotationItem::AbstractAnnotationItem(const PropertiesPtr &properties) { Q_ASSERT(properties != nullptr); updateProperties(properties); mPainterPen.setCapStyle(Qt::RoundCap); mPainterPen.setJoinStyle(Qt::RoundJoin); mShape = new QPainterPath(); mStroker = new QPainterPathStroker(mPainterPen); updateShadow(); } AbstractAnnotationItem::AbstractAnnotationItem(const AbstractAnnotationItem &other) { mProperties = other.mProperties->clone(); mShape = new QPainterPath(*other.mShape); mPainterPen = other.mPainterPen; mStroker = new QPainterPathStroker(mPainterPen); setZValue(other.zValue()); setCursor(other.cursor()); updateShadow(); } AbstractAnnotationItem::~AbstractAnnotationItem() { delete mShape; delete mStroker; } QRectF AbstractAnnotationItem::boundingRect() const { auto width = 0; if (mShape->elementCount() > 0) { width = mProperties->width() * 0.5; } return mShape->boundingRect().adjusted(-width, -width, width, width); } QPainterPath AbstractAnnotationItem::shape() const { auto path = mStroker->createStroke(*mShape); if (hasFill()) { path.addPath(*mShape); } return path; } bool AbstractAnnotationItem::intersects(const QRectF &rect) const { return shape().intersects(rect); } void AbstractAnnotationItem::setShape(QPainterPath &newShape) { mShape->swap(newShape); } QPointF AbstractAnnotationItem::position() { return boundingRect().topLeft(); } PropertiesPtr AbstractAnnotationItem::properties() const { return mProperties; } void AbstractAnnotationItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { if (mShape->elementCount() == 0) { return; } adjustPainter(painter); if (mShape->elementCount() == 1 && hasBorder()) { drawPoint(painter); } else { drawPath(painter); } } void AbstractAnnotationItem::adjustPainter(QPainter *painter) const { painter->setRenderHint(QPainter::Antialiasing, true); shiftPainterForAllOddShapeWidth(painter); } QPen AbstractAnnotationItem::painterPen() const { return mPainterPen; } void AbstractAnnotationItem::drawPoint(QPainter *painter) const { painter->setPen(Qt::NoPen); painter->setBrush(mPainterPen.color()); const auto element = mShape->elementAt(0); const auto width = mPainterPen.widthF(); const auto x = element.x - 0.5 * width; const auto y = element.y - 0.5 * width; if (mPainterPen.capStyle() == Qt::RoundCap) { painter->drawEllipse(x, y, width, width); } else { painter->drawRect(x, y, width, width); } } void AbstractAnnotationItem::drawPath(QPainter *painter) const { if (hasBorder()) { painter->setPen(mPainterPen); } else { painter->setPen(Qt::NoPen); } if (hasFill()) { painter->setBrush(mProperties->color()); } painter->drawPath(*mShape); } void AbstractAnnotationItem::updateProperties(const PropertiesPtr &properties) { mProperties = properties; mPainterPen.setColor(mProperties->color()); mPainterPen.setWidth(mProperties->width()); updateShadow(); } void AbstractAnnotationItem::shiftPainterForAllOddShapeWidth(QPainter *painter) const { if (mPainterPen.width() % 2 != 0) { painter->translate(0.5, 0.5); } } bool AbstractAnnotationItem::hasFill() const { auto fillType = mProperties->fillType(); return fillType == FillModes::BorderAndFill || fillType == FillModes::NoBorderAndFill; } bool AbstractAnnotationItem::hasBorder() const { auto fillType = mProperties->fillType(); return fillType == FillModes::BorderAndFill || fillType == FillModes::BorderAndNoFill; } void AbstractAnnotationItem::finish() { // By default, does nothing } bool AbstractAnnotationItem::requiresSelectionAfterCreation() const { return false; } void AbstractAnnotationItem::setProperties(const PropertiesPtr &properties) { Q_ASSERT(properties != nullptr); prepareGeometryChange(); updateProperties(properties); } void AbstractAnnotationItem::updateShadow() { if (mProperties->shadowEnabled()) { if(graphicsEffect() == nullptr) { setGraphicsEffect(new ShadowEffect()); } } else { setGraphicsEffect(nullptr); } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AbstractAnnotationItem.h000066400000000000000000000054441414424500400256420ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ABSTRACTANNOTATIONITEM_H #define KIMAGEANNOTATOR_ABSTRACTANNOTATIONITEM_H #include #include #include #include #include "src/annotations/properties/AnnotationProperties.h" #include "src/common/enum/FillModes.h" #include "src/common/enum/Tools.h" #include "src/annotations/misc/ShadowEffect.h" namespace kImageAnnotator { class AbstractAnnotationItem : public QGraphicsWidget { public: explicit AbstractAnnotationItem(const PropertiesPtr &properties); AbstractAnnotationItem(const AbstractAnnotationItem &other); ~AbstractAnnotationItem() override; QRectF boundingRect() const override; QPainterPath shape() const override; virtual bool intersects(const QRectF &rect) const; virtual void addPoint(const QPointF &position, bool modified) = 0; virtual void setPointAt(const QPointF &point, int index, bool keepAspectRatio) = 0; virtual QPointF pointAt(int index) const = 0; virtual void setPosition(const QPointF &newPosition) = 0; virtual QPointF position(); virtual PropertiesPtr properties() const; virtual void finish(); virtual bool requiresSelectionAfterCreation() const; virtual void scale(qreal sx, qreal sy) = 0; virtual Tools toolType() const = 0; virtual void setProperties(const PropertiesPtr &properties); protected: void setShape(QPainterPath &newShape); virtual void updateShape() = 0; void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override; virtual void updateProperties(const PropertiesPtr &properties); bool hasFill() const; bool hasBorder() const; void adjustPainter(QPainter *painter) const; QPen painterPen() const; private: PropertiesPtr mProperties; QPainterPath *mShape; QPainterPathStroker *mStroker; QPen mPainterPen; void shiftPainterForAllOddShapeWidth(QPainter *painter) const; void updateShadow(); void drawPath(QPainter *painter) const; void drawPoint(QPainter *painter) const; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ABSTRACTANNOTATIONITEM_H kImageAnnotator-0.5.3/src/annotations/items/AbstractAnnotationLine.cpp000066400000000000000000000056011414424500400261610ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AbstractAnnotationLine.h" namespace kImageAnnotator { AbstractAnnotationLine::AbstractAnnotationLine(const QPointF &startPosition, const PropertiesPtr &properties) : AbstractAnnotationItem(properties) { mLine = new QLineF(); mLine->setP1(startPosition); } AbstractAnnotationLine::AbstractAnnotationLine(const AbstractAnnotationLine &other) : AbstractAnnotationItem(other) { mLine = new QLineF(*other.mLine); } AbstractAnnotationLine::~AbstractAnnotationLine() { delete mLine; } void AbstractAnnotationLine::addPoint(const QPointF &position, bool modified) { prepareGeometryChange(); mLine->setP2(position); snapToAngle(modified); updateShape(); } void AbstractAnnotationLine::setPosition(const QPointF &newPosition) { prepareGeometryChange(); mLine->translate(newPosition - position()); updateShape(); } QLineF AbstractAnnotationLine::line() const { return *mLine; } void AbstractAnnotationLine::setPointAt(const QPointF &point, int index, bool snapToAngle) { prepareGeometryChange(); if (index <= 0) { if (snapToAngle) { mLine->setP1(getSnapPoint(mLine->p2(), point)); } else { mLine->setP1(point); } } else { if (snapToAngle) { mLine->setP2(getSnapPoint(mLine->p1(), point)); } else { mLine->setP2(point); } } updateShape(); } QPointF AbstractAnnotationLine::pointAt(int index) const { if (index <= 0) { return mLine->p1(); } else { return mLine->p2(); } } void AbstractAnnotationLine::scale(qreal sx, qreal sy) { prepareGeometryChange(); QTransform transform; transform.scale(sx, sy); auto scaledLine = transform.map(*mLine); mLine->setP1(scaledLine.p1()); mLine->setP2(scaledLine.p2()); updateShape(); } void AbstractAnnotationLine::snapToAngle(bool enabled) { if (enabled) { auto newAngle = MathHelper::roundAngleTo(mLine->angle(), 45); mLine->setAngle(newAngle); } } QPointF AbstractAnnotationLine::getSnapPoint(QPointF from, QPointF to) const { QLineF line = QLineF(from, to); const auto angle = line.angle(); auto newAngle = MathHelper::roundAngleTo(angle, 45); line.setAngle(newAngle); return line.p2(); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AbstractAnnotationLine.h000066400000000000000000000033661414424500400256340ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ABSTRACTANNOTATIONLINE_H #define KIMAGEANNOTATOR_ABSTRACTANNOTATIONLINE_H #include "AbstractAnnotationItem.h" #include "src/common/helper/MathHelper.h" namespace kImageAnnotator { class AbstractAnnotationLine : public AbstractAnnotationItem { public: AbstractAnnotationLine(const QPointF &startPosition, const PropertiesPtr &properties); AbstractAnnotationLine(const AbstractAnnotationLine &other); ~AbstractAnnotationLine() override; void addPoint(const QPointF &position, bool modified) override; void setPosition(const QPointF &newPosition) override; QLineF line() const; void setPointAt(const QPointF &point, int index, bool snapToAngle) override; QPointF pointAt(int index) const override; void scale(qreal sx, qreal sy) override; protected: QLineF *mLine; void snapToAngle(bool enabled); QPointF getSnapPoint(QPointF from, QPointF to) const; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ABSTRACTANNOTATIONLINE_H kImageAnnotator-0.5.3/src/annotations/items/AbstractAnnotationObfuscate.cpp000066400000000000000000000050471414424500400272110ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AbstractAnnotationObfuscate.h" namespace kImageAnnotator { AbstractAnnotationObfuscate::AbstractAnnotationObfuscate(const QPointF &startPosition, const PropertiesPtr &properties) : AbstractAnnotationRect(startPosition, properties) { } AbstractAnnotationObfuscate::AbstractAnnotationObfuscate(const AbstractAnnotationObfuscate &other) : AbstractAnnotationRect(other) { } ObfuscatePropertiesPtr AbstractAnnotationObfuscate::obfuscateProperties() const { return AbstractAnnotationItem::properties().staticCast(); } void AbstractAnnotationObfuscate::setProperties(const PropertiesPtr &properties) { AbstractAnnotationItem::setProperties(properties); updateShape(); } void AbstractAnnotationObfuscate::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { // We need to update the image here, otherwise the scene is not ready // to be painted and we only draw the background if (mObfuscationUpdateRequired) { updateOverlayImage(); mObfuscationUpdateRequired = false; } painter->drawImage(mRect->normalized(), mObfuscatedImage); } void AbstractAnnotationObfuscate::updateShape() { mObfuscationUpdateRequired = true; QPainterPath path; path.addRect(*mRect); setShape(path); } void AbstractAnnotationObfuscate::updateOverlayImage() { auto parentScene = scene(); if (parentScene != nullptr) { auto sceneSize = parentScene->sceneRect().size().toSize(); QImage image(sceneSize, QImage::Format_ARGB32_Premultiplied); image.fill(Qt::transparent); QPainter imagePainter(&image); parentScene->render(&imagePainter); auto itemRect = mRect->normalized().toRect(); auto sceneBehindItem = image.copy(itemRect); mObfuscatedImage = obfuscateBackground(sceneBehindItem); } } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/items/AbstractAnnotationObfuscate.h000066400000000000000000000035331414424500400266540ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ABSTRACTANNOTATIONOBFUSCATE_H #define KIMAGEANNOTATOR_ABSTRACTANNOTATIONOBFUSCATE_H #include #include "AbstractAnnotationRect.h" #include "src/annotations/properties/AnnotationObfuscateProperties.h" namespace kImageAnnotator { class AbstractAnnotationObfuscate : public AbstractAnnotationRect { public: AbstractAnnotationObfuscate(const QPointF &startPosition, const PropertiesPtr &properties); AbstractAnnotationObfuscate(const AbstractAnnotationObfuscate &other); ~AbstractAnnotationObfuscate() override = default; ObfuscatePropertiesPtr obfuscateProperties() const; void setProperties(const PropertiesPtr &properties) override; protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override; void updateShape() override; virtual QImage obfuscateBackground(const QImage &sceneBehindItem) const = 0; private: QImage mObfuscatedImage; bool mObfuscationUpdateRequired; void updateOverlayImage(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ABSTRACTANNOTATIONOBFUSCATE_H kImageAnnotator-0.5.3/src/annotations/items/AbstractAnnotationPath.cpp000066400000000000000000000062241414424500400261700ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AbstractAnnotationPath.h" namespace kImageAnnotator { AbstractAnnotationPath::AbstractAnnotationPath(const QPointF &startPosition, const PropertiesPtr &properties) : AbstractAnnotationItem(properties) { mPath = new QPainterPath(); mPath->moveTo(startPosition); mPath->lineTo(startPosition); } AbstractAnnotationPath::AbstractAnnotationPath(const AbstractAnnotationPath &other) : AbstractAnnotationItem(other) { mPath = new QPainterPath(*other.mPath); } AbstractAnnotationPath::~AbstractAnnotationPath() { delete mPath; } void AbstractAnnotationPath::addPoint(const QPointF &position, bool modified) { Q_UNUSED(modified) prepareGeometryChange(); mPath->lineTo(position); updateShape(); } void AbstractAnnotationPath::setPosition(const QPointF &newPosition) { prepareGeometryChange(); mPath->translate(newPosition - position()); updateShape(); } void AbstractAnnotationPath::setPointAt(const QPointF &point, int handleIndex, bool keepAspectRatio) { auto oppositeIndex = (handleIndex + 4) % 8; auto currentPos = ShapeHelper::rectPointAtIndex(boundingRect(), oppositeIndex); auto rect = ShapeHelper::setRectPointAtIndex(boundingRect(), handleIndex, point, keepAspectRatio); if (rect.width() >= Constants::MinPathResizeRectSize && rect.height() >= Constants::MinPathResizeRectSize) { prepareGeometryChange(); scalePath(rect); mPath->translate(currentPos - ShapeHelper::rectPointAtIndex(boundingRect(), oppositeIndex)); updateShape(); } } QPointF AbstractAnnotationPath::pointAt(int index) const { return ShapeHelper::rectPointAtIndex(mPath->boundingRect(), index); } void AbstractAnnotationPath::finish() { if (pathProperties()->smoothPathEnabled()) { prepareGeometryChange(); auto smoothPath = ShapeHelper::smoothOut(*mPath, pathProperties()->smoothFactor()); mPath->swap(smoothPath); updateShape(); } } void AbstractAnnotationPath::scale(qreal sx, qreal sy) { prepareGeometryChange(); QTransform transform; transform.scale(sx, sy); auto scaledPath = transform.map(*mPath); mPath->swap(scaledPath); updateShape(); } void AbstractAnnotationPath::scalePath(const QRectF &rect) { scale(rect.width() / boundingRect().width(), rect.height() / boundingRect().height()); } PathPropertiesPtr AbstractAnnotationPath::pathProperties() const { return AbstractAnnotationItem::properties().staticCast(); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AbstractAnnotationPath.h000066400000000000000000000035671414424500400256440ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ABSTRACTANNOTATIONPATH_H #define KIMAGEANNOTATOR_ABSTRACTANNOTATIONPATH_H #include "AbstractAnnotationItem.h" #include "src/annotations/properties/AnnotationPathProperties.h" #include "src/common/helper/ShapeHelper.h" #include "src/common/constants/Constants.h" namespace kImageAnnotator { class AbstractAnnotationPath : public AbstractAnnotationItem { public: AbstractAnnotationPath(const QPointF &startPosition, const PropertiesPtr &properties); AbstractAnnotationPath(const AbstractAnnotationPath &other); ~AbstractAnnotationPath() override; void addPoint(const QPointF &position, bool modified) override; void setPosition(const QPointF &newPosition) override; void setPointAt(const QPointF &point, int handleIndex, bool keepAspectRatio) override; QPointF pointAt(int index) const override; void finish() override; void scale(qreal sx, qreal sy) override; PathPropertiesPtr pathProperties() const; protected: QPainterPath *mPath; private: void scalePath(const QRectF &rect); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ABSTRACTANNOTATIONPATH_H kImageAnnotator-0.5.3/src/annotations/items/AbstractAnnotationPointerRect.cpp000066400000000000000000000047351414424500400275370ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AbstractAnnotationPointerRect.h" namespace kImageAnnotator { AbstractAnnotationPointerRect::AbstractAnnotationPointerRect(const QPointF &startPosition, const kImageAnnotator::PropertiesPtr &properties) : AbstractAnnotationRect(startPosition, properties), mPointerIndex(8), mPointer(startPosition) { } AbstractAnnotationPointerRect::AbstractAnnotationPointerRect(const AbstractAnnotationPointerRect &other) : AbstractAnnotationRect(other), mPointer(QPointF(other.mPointer)), mPointerIndex(8) { } void AbstractAnnotationPointerRect::addPoint(const QPointF &position, bool modified) { prepareGeometryChange(); mPointer = position; updateShape(); } void AbstractAnnotationPointerRect::setPosition(const QPointF &newPosition) { auto offset = AbstractAnnotationRect::position() - newPosition; mPointer -= offset; AbstractAnnotationRect::setPosition(newPosition); } void AbstractAnnotationPointerRect::setPointAt(const QPointF &point, int index, bool keepAspectRatio) { Q_UNUSED(keepAspectRatio); if(isPointer(index)){ mPointer = point; prepareGeometryChange(); updateShape(); } else { AbstractAnnotationRect::setPointAt(point, index, false); } } QPointF AbstractAnnotationPointerRect::pointAt(int index) const { return isPointer(index) ? mPointer : AbstractAnnotationRect::pointAt(index); } void AbstractAnnotationPointerRect::finish() { auto rectWidth = mRect->width(); if(mRect->contains(mPointer)) { auto offset = rectWidth * 0.8; mPointer += QPointF(offset, -offset); prepareGeometryChange(); updateShape(); } AbstractAnnotationItem::finish(); } bool AbstractAnnotationPointerRect::isPointer(int index) const { return index == mPointerIndex; } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AbstractAnnotationPointerRect.h000066400000000000000000000032751414424500400272020ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ABSTRACTANNOTATIONPOINTERRECT_H #define KIMAGEANNOTATOR_ABSTRACTANNOTATIONPOINTERRECT_H #include "AbstractAnnotationRect.h" namespace kImageAnnotator { class AbstractAnnotationPointerRect : public AbstractAnnotationRect { public: AbstractAnnotationPointerRect(const QPointF &startPosition, const PropertiesPtr &properties); AbstractAnnotationPointerRect(const AbstractAnnotationPointerRect &other); ~AbstractAnnotationPointerRect() override = default; void addPoint(const QPointF &position, bool modified) override; void setPosition(const QPointF &newPosition) override; void setPointAt(const QPointF &point, int index, bool keepAspectRatio) override; QPointF pointAt(int index) const override; void finish() override; protected: QPointF mPointer; int mPointerIndex; bool isPointer(int index) const; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ABSTRACTANNOTATIONPOINTERRECT_H kImageAnnotator-0.5.3/src/annotations/items/AbstractAnnotationRect.cpp000066400000000000000000000052631414424500400261730ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AbstractAnnotationRect.h" namespace kImageAnnotator { AbstractAnnotationRect::AbstractAnnotationRect(const QPointF &startPosition, const PropertiesPtr &properties) : AbstractAnnotationItem(properties), mRect(new QRectF()) { mRect->setTopLeft(startPosition); mRect->setBottomRight(startPosition); } AbstractAnnotationRect::AbstractAnnotationRect(const AbstractAnnotationRect &other) : AbstractAnnotationItem(other), mRect(new QRectF(*other.mRect)) { } AbstractAnnotationRect::~AbstractAnnotationRect() { delete mRect; } void AbstractAnnotationRect::addPoint(const QPointF &position, bool modified) { prepareGeometryChange(); mRect->setBottomRight(position); makeSymmetric(modified); updateShape(); } void AbstractAnnotationRect::setPosition(const QPointF &newPosition) { prepareGeometryChange(); mRect->translate(newPosition - position()); updateShape(); } QRectF AbstractAnnotationRect::rect() const { return *mRect; } void AbstractAnnotationRect::setPointAt(const QPointF &point, int index, bool keepAspectRatio) { prepareGeometryChange(); auto newRect = ShapeHelper::setRectPointAtIndex(*mRect, index, point, keepAspectRatio); mRect->setRect(newRect.x(), newRect.y(), newRect.width(), newRect.height()); updateShape(); } QPointF AbstractAnnotationRect::pointAt(int index) const { return ShapeHelper::rectPointAtIndex(*mRect, index); } void AbstractAnnotationRect::scale(qreal sx, qreal sy) { prepareGeometryChange(); QTransform transform; transform.scale(sx, sy); auto scaledRect = transform.mapRect(*mRect); mRect->setRect(scaledRect.x(), scaledRect.y(), scaledRect.width(), scaledRect.height()); updateShape(); } void AbstractAnnotationRect::makeSymmetric(bool enabled) { if (enabled) { mRect->setHeight(MathHelper::smallerValue(mRect->height(), mRect->width())); mRect->setWidth(MathHelper::smallerValue(mRect->width(), mRect->height())); } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AbstractAnnotationRect.h000066400000000000000000000034341414424500400256360ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ABSTRACTANNOTATIONRECT_H #define KIMAGEANNOTATOR_ABSTRACTANNOTATIONRECT_H #include "AbstractAnnotationItem.h" #include "src/common/helper/MathHelper.h" #include "src/common/helper/ShapeHelper.h" #include "src/common/constants/Constants.h" namespace kImageAnnotator { class AbstractAnnotationRect : public AbstractAnnotationItem { public: AbstractAnnotationRect(const QPointF &startPosition, const PropertiesPtr &properties); AbstractAnnotationRect(const AbstractAnnotationRect &other); ~AbstractAnnotationRect() override; void addPoint(const QPointF &position, bool modified) override; void setPosition(const QPointF &newPosition) override; QRectF rect() const; void setPointAt(const QPointF &point, int index, bool keepAspectRatio) override; QPointF pointAt(int index) const override; void scale(qreal sx, qreal sy) override; protected: QRectF *mRect; void makeSymmetric(bool enabled); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ABSTRACTANNOTATIONRECT_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationArrow.cpp000066400000000000000000000031061414424500400246760ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationArrow.h" namespace kImageAnnotator { AnnotationArrow::AnnotationArrow(const QPointF &startPosition, const PropertiesPtr &properties) : AbstractAnnotationLine(startPosition, properties) { } AnnotationArrow::AnnotationArrow(const AnnotationArrow &other) : AbstractAnnotationLine(other) { } Tools AnnotationArrow::toolType() const { return Tools::Arrow; } void AnnotationArrow::updateShape() { QLineF shaft(*mLine); shaft.setLength(shaft.length() - 5); auto arrow = AnnotationShapeCreator::createArrowHead(properties()->width() / 2); arrow = AnnotationShapeCreator::translate(arrow, mLine->p2(), -mLine->angle()); QPainterPath path(shaft.p1()); path.lineTo(shaft.p2()); path.addPolygon(arrow); path.closeSubpath(); setShape(path); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AnnotationArrow.h000066400000000000000000000026341414424500400243500ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONARROW_H #define KIMAGEANNOTATOR_ANNOTATIONARROW_H #include "src/annotations/items/AbstractAnnotationLine.h" #include "src/annotations/items/helper/AnnotationShapeCreator.h" namespace kImageAnnotator { class AnnotationArrow : public AbstractAnnotationLine { public: AnnotationArrow(const QPointF &startPosition, const PropertiesPtr &properties); AnnotationArrow(const AnnotationArrow &other); ~AnnotationArrow() override = default; Tools toolType() const override; protected: void updateShape() override; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONARROW_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationBlur.cpp000066400000000000000000000025671414424500400245220ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationBlur.h" namespace kImageAnnotator { AnnotationBlur::AnnotationBlur(const QPointF &startPosition, const ObfuscatePropertiesPtr &properties) : AbstractAnnotationObfuscate(startPosition, properties) { } AnnotationBlur::AnnotationBlur(const AnnotationBlur &other) : AbstractAnnotationObfuscate(other) { } Tools AnnotationBlur::toolType() const { return Tools::Blur; } QImage AnnotationBlur::obfuscateBackground(const QImage &sceneBehindItem) const { return mItemBlurrer.blurred(sceneBehindItem, obfuscateProperties()->factor(), false); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AnnotationBlur.h000066400000000000000000000027161414424500400241630ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONBLUR_H #define KIMAGEANNOTATOR_ANNOTATIONBLUR_H #include "AbstractAnnotationObfuscate.h" #include "src/annotations/misc/ImageBlurrer.h" namespace kImageAnnotator { class AnnotationBlur : public AbstractAnnotationObfuscate { public: AnnotationBlur(const QPointF &startPosition, const ObfuscatePropertiesPtr &properties); AnnotationBlur(const AnnotationBlur &other); ~AnnotationBlur() override = default; Tools toolType() const override; protected: QImage obfuscateBackground(const QImage &sceneBehindItem) const override; private: ImageBlurrer mItemBlurrer; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONBLUR_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationDoubleArrow.cpp000066400000000000000000000035441414424500400260370ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationDoubleArrow.h" namespace kImageAnnotator { AnnotationDoubleArrow::AnnotationDoubleArrow(const QPointF &startPosition, const PropertiesPtr &properties) : AnnotationArrow(startPosition, properties) { } AnnotationDoubleArrow::AnnotationDoubleArrow(const AnnotationArrow &other) : AnnotationArrow(other) { } Tools AnnotationDoubleArrow::toolType() const { return Tools::DoubleArrow; } void AnnotationDoubleArrow::updateShape() { QLineF shaft(mLine->p2(), mLine->p1()); shaft.setLength(shaft.length() - 5); shaft.setPoints(shaft.p2(), shaft.p1()); shaft.setLength(shaft.length() - 5); auto arrow = AnnotationShapeCreator::createArrowHead(properties()->width() / 2); auto startArrowHead = AnnotationShapeCreator::translate(arrow, mLine->p2(), -mLine->angle()); auto endArrowHead = AnnotationShapeCreator::translate(arrow, mLine->p1(), -mLine->angle() + 180); QPainterPath path(shaft.p1()); path.lineTo(shaft.p2()); path.addPolygon(startArrowHead); path.addPolygon(endArrowHead); path.closeSubpath(); setShape(path); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/items/AnnotationDoubleArrow.h000066400000000000000000000025461414424500400255050ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONDOUBLEARROW_H #define KIMAGEANNOTATOR_ANNOTATIONDOUBLEARROW_H #include "AnnotationArrow.h" namespace kImageAnnotator { class AnnotationDoubleArrow : public AnnotationArrow { public: AnnotationDoubleArrow(const QPointF &startPosition, const PropertiesPtr &properties); explicit AnnotationDoubleArrow(const AnnotationArrow &other); ~AnnotationDoubleArrow() override = default; Tools toolType() const override; protected: void updateShape() override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONDOUBLEARROW_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationDuplicate.cpp000066400000000000000000000043301414424500400255160ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationDuplicate.h" namespace kImageAnnotator { AnnotationDuplicate::AnnotationDuplicate(const QPointF &startPosition, const PropertiesPtr &properties) : AbstractAnnotationRect(startPosition, properties) { } Tools AnnotationDuplicate::toolType() const { return Tools::Duplicate; } bool AnnotationDuplicate::requiresSelectionAfterCreation() const { return true; } void AnnotationDuplicate::updateShape() { QPainterPath path; path.addRect(*mRect); setShape(path); } void AnnotationDuplicate::finish() { prepareGeometryChange(); captureScene(); } void AnnotationDuplicate::captureScene() { auto parentScene = scene(); if (parentScene != nullptr) { *mRect = parentScene->sceneRect().intersected(*mRect); updateShape(); mSceneSelectionImage = QImage(mRect->normalized().size().toSize(), QImage::Format_ARGB32_Premultiplied); mSceneSelectionImage.fill(Qt::transparent); QPainter imagePainter(&mSceneSelectionImage); QRectF targetRect; targetRect.setSize(mRect->normalized().size()); targetRect.setTopLeft(QPointF(0, 0)); parentScene->render(&imagePainter, targetRect, mRect->normalized()); } } void AnnotationDuplicate::paint(QPainter *painter, const QStyleOptionGraphicsItem *style, QWidget *widget) { if (mSceneSelectionImage.isNull()) { AbstractAnnotationItem::paint(painter, style, widget); } else { painter->drawImage(mRect->normalized(), mSceneSelectionImage); } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AnnotationDuplicate.h000066400000000000000000000030641414424500400251660ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONDUPLICATE_H #define KIMAGEANNOTATOR_ANNOTATIONDUPLICATE_H #include #include "AbstractAnnotationRect.h" namespace kImageAnnotator { class AnnotationDuplicate : public AbstractAnnotationRect { public: AnnotationDuplicate(const QPointF &startPosition, const PropertiesPtr &properties); ~AnnotationDuplicate() override = default; Tools toolType() const override; void finish() override; bool requiresSelectionAfterCreation() const override; protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *style, QWidget *widget) override; void updateShape() override; private: QImage mSceneSelectionImage; void captureScene(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONDUPLICATE_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationEllipse.cpp000066400000000000000000000024731414424500400252070ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationEllipse.h" namespace kImageAnnotator { AnnotationEllipse::AnnotationEllipse(const QPointF &startPosition, const PropertiesPtr &properties) : AbstractAnnotationRect(startPosition, properties) { } AnnotationEllipse::AnnotationEllipse(const AnnotationEllipse &other) : AbstractAnnotationRect(other) { } Tools AnnotationEllipse::toolType() const { return Tools::Ellipse; } void AnnotationEllipse::updateShape() { QPainterPath path; path.addEllipse(*mRect); setShape(path); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AnnotationEllipse.h000066400000000000000000000025251414424500400246520ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONELLIPSE_H #define KIMAGEANNOTATOR_ANNOTATIONELLIPSE_H #include "AbstractAnnotationRect.h" namespace kImageAnnotator { class AnnotationEllipse : public AbstractAnnotationRect { public: AnnotationEllipse(const QPointF &startPosition, const PropertiesPtr &properties); AnnotationEllipse(const AnnotationEllipse &other); ~AnnotationEllipse() override = default; Tools toolType() const override; protected: void updateShape() override; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONELLIPSE_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationImage.cpp000066400000000000000000000030361414424500400246300ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationImage.h" namespace kImageAnnotator { kImageAnnotator::AnnotationImage::AnnotationImage(const QPointF &startPosition, const QPixmap &image, const PropertiesPtr &properties) : AnnotationRect(startPosition, properties) { mImage = image; mRect->setRect(mRect->x(), mRect->y(), image.width(), image.height()); updateShape(); } AnnotationImage::AnnotationImage(const AnnotationImage &other) : AnnotationRect(other) { this->mImage = other.mImage; updateShape(); } Tools AnnotationImage::toolType() const { return Tools::Image; } void AnnotationImage::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { painter->drawPixmap(mRect->toRect().normalized(), mImage); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AnnotationImage.h000066400000000000000000000026541414424500400243020ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONIMAGE_H #define KIMAGEANNOTATOR_ANNOTATIONIMAGE_H #include "AnnotationRect.h" namespace kImageAnnotator { class AnnotationImage : public AnnotationRect { public: AnnotationImage(const QPointF &startPosition, const QPixmap &image, const PropertiesPtr &properties); AnnotationImage(const AnnotationImage &other); ~AnnotationImage() override = default; Tools toolType() const override; protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override; private: QPixmap mImage; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONIMAGE_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationLine.cpp000066400000000000000000000024561414424500400245020ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationLine.h" namespace kImageAnnotator { AnnotationLine::AnnotationLine(const QPointF &startPosition, const PropertiesPtr &properties) : AbstractAnnotationLine(startPosition, properties) { } AnnotationLine::AnnotationLine(const AnnotationLine &other) : AbstractAnnotationLine(other) { } Tools AnnotationLine::toolType() const { return Tools::Line; } void AnnotationLine::updateShape() { QPainterPath path(mLine->p1()); path.lineTo(mLine->p2()); setShape(path); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AnnotationLine.h000066400000000000000000000024351414424500400241440ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONLINE_H #define KIMAGEANNOTATOR_ANNOTATIONLINE_H #include "AbstractAnnotationLine.h" namespace kImageAnnotator { class AnnotationLine : public AbstractAnnotationLine { public: AnnotationLine(const QPointF &startPosition, const PropertiesPtr &properties); AnnotationLine(const AnnotationLine &other); ~AnnotationLine() override = default; Tools toolType() const override; protected: void updateShape() override; }; } #endif // KIMAGEANNOTATOR_ANNOTATIONLINE_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationMarkerEllipse.cpp000066400000000000000000000025531414424500400263500ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationMarkerEllipse.h" namespace kImageAnnotator { AnnotationMarkerEllipse::AnnotationMarkerEllipse(const QPointF &startPosition, const PropertiesPtr &properties) : AnnotationEllipse(startPosition, properties) { } Tools AnnotationMarkerEllipse::toolType() const { return Tools::MarkerEllipse; } void AnnotationMarkerEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { painter->setCompositionMode(QPainter::CompositionMode_Multiply); AnnotationEllipse::paint(painter, option, widget); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/items/AnnotationMarkerEllipse.h000066400000000000000000000027161414424500400260160ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONMARKERELLIPSE_H #define KIMAGEANNOTATOR_ANNOTATIONMARKERELLIPSE_H #include "AnnotationEllipse.h" namespace kImageAnnotator { class AnnotationMarkerEllipse : public AnnotationEllipse { Q_OBJECT public: AnnotationMarkerEllipse(const QPointF &startPosition, const PropertiesPtr &properties); AnnotationMarkerEllipse(const AnnotationMarkerEllipse &other) = default; ~AnnotationMarkerEllipse() override = default; Tools toolType() const override; protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONMARKERELLIPSE_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationMarkerPen.cpp000066400000000000000000000025121414424500400254700ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationMarkerPen.h" namespace kImageAnnotator { AnnotationMarkerPen::AnnotationMarkerPen(const QPointF &startPosition, const PropertiesPtr &properties) : AnnotationPen(startPosition, properties) { } Tools AnnotationMarkerPen::toolType() const { return Tools::MarkerPen; } void AnnotationMarkerPen::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { painter->setCompositionMode(QPainter::CompositionMode_Multiply); AnnotationPen::paint(painter, option, widget); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/items/AnnotationMarkerPen.h000066400000000000000000000026461414424500400251450ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONMARKERPEN_H #define KIMAGEANNOTATOR_ANNOTATIONMARKERPEN_H #include "AnnotationPen.h" namespace kImageAnnotator { class AnnotationMarkerPen : public AnnotationPen { Q_OBJECT public: AnnotationMarkerPen(const QPointF &startPosition, const PropertiesPtr &properties); AnnotationMarkerPen(const AnnotationMarkerPen &other) = default; ~AnnotationMarkerPen() override = default; Tools toolType() const override; protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONMARKERPEN_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationMarkerRect.cpp000066400000000000000000000025241414424500400256460ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationMarkerRect.h" namespace kImageAnnotator { AnnotationMarkerRect::AnnotationMarkerRect(const QPointF &startPosition, const PropertiesPtr &properties) : AnnotationRect(startPosition, properties) { } Tools AnnotationMarkerRect::toolType() const { return Tools::MarkerRect; } void AnnotationMarkerRect::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { painter->setCompositionMode(QPainter::CompositionMode_Multiply); AnnotationRect::paint(painter, option, widget); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AnnotationMarkerRect.h000066400000000000000000000026601414424500400253140ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONMARKERRECT_H #define KIMAGEANNOTATOR_ANNOTATIONMARKERRECT_H #include "AnnotationRect.h" namespace kImageAnnotator { class AnnotationMarkerRect : public AnnotationRect { Q_OBJECT public: AnnotationMarkerRect(const QPointF &startPosition, const PropertiesPtr &properties); AnnotationMarkerRect(const AnnotationMarkerRect &other) = default; ~AnnotationMarkerRect() override = default; Tools toolType() const override; protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONMARKERRECT_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationNumber.cpp000066400000000000000000000046431414424500400250430ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationNumber.h" namespace kImageAnnotator { AnnotationNumber::AnnotationNumber(const QPointF ¢erPosition, const TextPropertiesPtr &properties) : AbstractAnnotationRect(centerPosition, properties) { mRect->moveCenter(centerPosition); } AnnotationNumber::AnnotationNumber(const AnnotationNumber &other) : AbstractAnnotationRect(other), BaseAnnotationNumber(other) { updateShape(); } void AnnotationNumber::addPoint(const QPointF &position, bool modified) { Q_UNUSED(position); Q_UNUSED(modified); // Nothing to do here } Tools AnnotationNumber::toolType() const { return Tools::Number; } QPainterPath AnnotationNumber::shape() const { auto path = AbstractAnnotationItem::shape(); path.addRect(*mRect); return path; } TextPropertiesPtr AnnotationNumber::textProperties() const { return AbstractAnnotationItem::properties().staticCast(); } void AnnotationNumber::updateShape() { QPainterPath path; path.addEllipse(*mRect); setShape(path); } void AnnotationNumber::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { AbstractAnnotationRect::paint(painter, option, widget); painter->setFont(textProperties()->font()); painter->setPen(properties()->textColor()); painter->drawText(boundingRect(), Qt::AlignCenter, numberString()); } void AnnotationNumber::updateProperties(const PropertiesPtr &properties) { AbstractAnnotationItem::updateProperties(properties); updateRect(); } void AnnotationNumber::updateRect() { prepareGeometryChange(); BaseAnnotationNumber::updateRect(mRect, textProperties()->font()); updateShape(); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AnnotationNumber.h000066400000000000000000000035411414424500400245040ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONNUMBER_H #define KIMAGEANNOTATOR_ANNOTATIONNUMBER_H #include "src/annotations/items/AbstractAnnotationRect.h" #include "src/annotations/items/BaseAnnotationNumber.h" #include "src/annotations/properties/AnnotationTextProperties.h" namespace kImageAnnotator { class AnnotationNumber : public AbstractAnnotationRect, public BaseAnnotationNumber { Q_OBJECT public: AnnotationNumber(const QPointF ¢erPosition, const TextPropertiesPtr& properties); AnnotationNumber(const AnnotationNumber &other); ~AnnotationNumber() override = default; void addPoint(const QPointF &position, bool modified) override; Tools toolType() const override; QPainterPath shape() const override; TextPropertiesPtr textProperties() const; protected: void updateShape() override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; void updateProperties(const PropertiesPtr &properties) override; private: void updateRect() override; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONNUMBER_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationNumberArrow.cpp000066400000000000000000000050011414424500400260430ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationNumberArrow.h" namespace kImageAnnotator { AnnotationNumberArrow::AnnotationNumberArrow(const QPointF &startPosition, const kImageAnnotator::TextPropertiesPtr &properties) : AnnotationNumberPointer(startPosition, properties) { } AnnotationNumberArrow::AnnotationNumberArrow(const kImageAnnotator::AnnotationNumberArrow &other) : AnnotationNumberPointer(other) { } Tools AnnotationNumberArrow::toolType() const { return Tools::NumberArrow; } void AnnotationNumberArrow::updateShape() { QLineF tmpLine(mPointer, mRect->center()); tmpLine.setLength(tmpLine.length() - mRect->width() / 2); QLineF shaft(tmpLine.p2(), tmpLine.p1()); shaft.setLength(tmpLine.length() - 5); auto arrow = AnnotationShapeCreator::createArrowHead(properties()->width() / 2); arrow = AnnotationShapeCreator::translate(arrow, mPointer, -shaft.angle()); mRect->moveCenter(mRect->center()); mArrowShape = QPainterPath(shaft.p1()); mArrowShape.setFillRule(Qt::WindingFill); mArrowShape.lineTo(shaft.p2()); mArrowShape.addPolygon(arrow); QPainterPath path(mArrowShape); path.addEllipse(*mRect); path.closeSubpath(); setShape(path); } void AnnotationNumberArrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { adjustPainter(painter); painter->setPen(painterPen()); painter->setBrush(properties()->color()); // Draw Arrow painter->drawPath(mArrowShape); // Draw Ellipse if(!hasFill()) { painter->setBrush(Qt::NoBrush); } if(!hasBorder()) { painter->setPen(Qt::NoPen); } painter->drawEllipse(*mRect); // Draw Number painter->setFont(textProperties()->font()); painter->setPen(properties()->textColor()); painter->drawText(*mRect, Qt::AlignCenter, numberString()); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/items/AnnotationNumberArrow.h000066400000000000000000000030171414424500400255150ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONNUMBERARROW_H #define KIMAGEANNOTATOR_ANNOTATIONNUMBERARROW_H #include "src/annotations/items/AnnotationNumberPointer.h" namespace kImageAnnotator { class AnnotationNumberArrow : public AnnotationNumberPointer { Q_OBJECT public: AnnotationNumberArrow(const QPointF &startPosition, const TextPropertiesPtr& properties); AnnotationNumberArrow(const AnnotationNumberArrow &other); ~AnnotationNumberArrow() override = default; Tools toolType() const override; protected: void updateShape() override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; private: QPainterPath mArrowShape; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONNUMBERARROW_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationNumberPointer.cpp000066400000000000000000000053311414424500400263770ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationNumberPointer.h" namespace kImageAnnotator { AnnotationNumberPointer::AnnotationNumberPointer(const QPointF &startPosition, const TextPropertiesPtr &properties) : AbstractAnnotationPointerRect(startPosition, properties) { } AnnotationNumberPointer::AnnotationNumberPointer(const AnnotationNumberPointer &other) : AbstractAnnotationPointerRect(other), BaseAnnotationNumber(other) { BaseAnnotationNumber::updateRect(mRect, textProperties()->font()); updateShape(); } Tools AnnotationNumberPointer::toolType() const { return Tools::NumberPointer; } TextPropertiesPtr AnnotationNumberPointer::textProperties() const { return AbstractAnnotationItem::properties().staticCast(); } void AnnotationNumberPointer::updateShape() { auto line = QLineF(mRect->center(), mPointer); auto pointerWidth = qMin(mRect->width(), mRect->height()) * 0.7; auto pointer = AnnotationShapeCreator::createPointer(pointerWidth, line.length()); auto finishedPointer = AnnotationShapeCreator::translate(pointer, mPointer, -line.angle()); QPainterPath path(mRect->center()); path.setFillRule(Qt::WindingFill); path.addPolygon(finishedPointer); path.closeSubpath(); path.addEllipse(*mRect); auto painterPath = path.simplified(); setShape(painterPath); } void AnnotationNumberPointer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { AbstractAnnotationPointerRect::paint(painter, option, widget); painter->setFont(textProperties()->font()); painter->setPen(properties()->textColor()); painter->drawText(*mRect, Qt::AlignCenter, numberString()); } void AnnotationNumberPointer::updateProperties(const PropertiesPtr &properties) { AbstractAnnotationItem::updateProperties(properties); updateRect(); } void AnnotationNumberPointer::updateRect() { prepareGeometryChange(); BaseAnnotationNumber::updateRect(mRect, textProperties()->font()); updateShape(); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AnnotationNumberPointer.h000066400000000000000000000035771414424500400260560ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONNUMBERPOINTER_H #define KIMAGEANNOTATOR_ANNOTATIONNUMBERPOINTER_H #include "src/annotations/items/AbstractAnnotationPointerRect.h" #include "src/annotations/items/BaseAnnotationNumber.h" #include "src/annotations/items/helper/AnnotationShapeCreator.h" #include "src/annotations/properties/AnnotationTextProperties.h" namespace kImageAnnotator { class AnnotationNumberPointer : public AbstractAnnotationPointerRect, public BaseAnnotationNumber { Q_OBJECT public: AnnotationNumberPointer(const QPointF &startPosition, const TextPropertiesPtr& properties); AnnotationNumberPointer(const AnnotationNumberPointer &other); ~AnnotationNumberPointer() override = default; Tools toolType() const override; TextPropertiesPtr textProperties() const; protected: void updateShape() override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; void updateProperties(const PropertiesPtr &properties) override; private: void updateRect() override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONNUMBERPOINTER_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationPen.cpp000066400000000000000000000024251414424500400243310ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationPen.h" namespace kImageAnnotator { AnnotationPen::AnnotationPen(const QPointF &startPosition, const PropertiesPtr &properties) : AbstractAnnotationPath(startPosition, properties) { updateShape(); } AnnotationPen::AnnotationPen(const AnnotationPen &other) : AbstractAnnotationPath(other) { } Tools AnnotationPen::toolType() const { return Tools::Pen; } void AnnotationPen::updateShape() { QPainterPath path(*mPath); setShape(path); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AnnotationPen.h000066400000000000000000000024611414424500400237760ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONPEN_H #define KIMAGEANNOTATOR_ANNOTATIONPEN_H #include "AbstractAnnotationPath.h" namespace kImageAnnotator { class AnnotationPen : public AbstractAnnotationPath { public: AnnotationPen(const QPointF &startPosition, const PropertiesPtr &properties); AnnotationPen(const AnnotationPen &other); ~AnnotationPen() override = default; Tools toolType() const override; protected: void updateShape() override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONPEN_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationPixelate.cpp000066400000000000000000000035141414424500400253620ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationPixelate.h" namespace kImageAnnotator { AnnotationPixelate::AnnotationPixelate(const QPointF &startPosition, const ObfuscatePropertiesPtr &properties) : AbstractAnnotationObfuscate(startPosition, properties) { } AnnotationPixelate::AnnotationPixelate(const AnnotationPixelate &other) : AbstractAnnotationObfuscate(other) { } Tools AnnotationPixelate::toolType() const { return Tools::Pixelate; } QImage AnnotationPixelate::obfuscateBackground(const QImage &sceneBehindItem) const { auto result = sceneBehindItem.convertToFormat( QImage::Format_ARGB32_Premultiplied ); auto factor = obfuscateProperties()->factor(); int width = sceneBehindItem.width() * (0.5 / qMax(1, factor)); int height = sceneBehindItem.height() * (0.5 / qMax(1, factor)); QSize size = QSize(qMax(width, 1), qMax(height, 1)); result = result.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); result = result.scaled(sceneBehindItem.width(), sceneBehindItem.height()); return result; } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AnnotationPixelate.h000066400000000000000000000026311414424500400250260ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONPIXELATE_H #define KIMAGEANNOTATOR_ANNOTATIONPIXELATE_H #include "AbstractAnnotationObfuscate.h" namespace kImageAnnotator { class AnnotationPixelate : public AbstractAnnotationObfuscate { public: AnnotationPixelate(const QPointF &startPosition, const ObfuscatePropertiesPtr &properties); AnnotationPixelate(const AnnotationPixelate &other); ~AnnotationPixelate() override = default; Tools toolType() const override; protected: QImage obfuscateBackground(const QImage &sceneBehindItem) const override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONPIXELATE_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationRect.cpp000066400000000000000000000024341414424500400245040ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationRect.h" namespace kImageAnnotator { AnnotationRect::AnnotationRect(const QPointF &startPosition, const PropertiesPtr &properties) : AbstractAnnotationRect(startPosition, properties) { } AnnotationRect::AnnotationRect(const AnnotationRect &other) : AbstractAnnotationRect(other) { } Tools AnnotationRect::toolType() const { return Tools::Rect; } void AnnotationRect::updateShape() { QPainterPath path; path.addRect(*mRect); setShape(path); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AnnotationRect.h000066400000000000000000000025041414424500400241470ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONRECT_H #define KIMAGEANNOTATOR_ANNOTATIONRECT_H #include "AbstractAnnotationRect.h" namespace kImageAnnotator { class AnnotationRect : public AbstractAnnotationRect { Q_OBJECT public: AnnotationRect(const QPointF &startPosition, const PropertiesPtr &properties); AnnotationRect(const AnnotationRect &other); ~AnnotationRect() override = default; Tools toolType() const override; protected: void updateShape() override; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONRECT_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationSticker.cpp000066400000000000000000000042561414424500400252170ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationSticker.h" namespace kImageAnnotator { AnnotationSticker::AnnotationSticker(const QPointF ¢erPosition, const StickerPropertiesPtr &properties) : AbstractAnnotationRect(centerPosition, properties) { mSvgRenderer.load(properties->path()); prepareGeometryChange(); auto center = mRect->center(); auto size = QSize(100,100); mRect->setSize(size); mRect->moveCenter(center); updateShape(); } AnnotationSticker::AnnotationSticker(const AnnotationSticker &other) : AbstractAnnotationRect(other) { mSvgRenderer.load(other.stickerProperties()->path()); } void AnnotationSticker::addPoint(const QPointF &position, bool modified) { Q_UNUSED(position); Q_UNUSED(modified); // Nothing to do here } Tools AnnotationSticker::toolType() const { return Tools::Sticker; } StickerPropertiesPtr AnnotationSticker::stickerProperties() const { return AbstractAnnotationItem::properties().staticCast(); } void AnnotationSticker::setProperties(const PropertiesPtr &properties) { AbstractAnnotationItem::setProperties(properties); mSvgRenderer.load(stickerProperties()->path()); } void AnnotationSticker::updateShape() { QPainterPath path; path.addEllipse(*mRect); setShape(path); } void AnnotationSticker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { mSvgRenderer.render(painter, mRect->toRect()); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AnnotationSticker.h000066400000000000000000000033411414424500400246560ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONSTICKER_H #define KIMAGEANNOTATOR_ANNOTATIONSTICKER_H #include #include "AbstractAnnotationRect.h" #include "src/annotations/properties/AnnotationStickerProperties.h" namespace kImageAnnotator { class AnnotationSticker : public AbstractAnnotationRect { public: AnnotationSticker(const QPointF ¢erPosition, const StickerPropertiesPtr& properties); AnnotationSticker(const AnnotationSticker &other); ~AnnotationSticker() override = default; void addPoint(const QPointF &position, bool modified) override; Tools toolType() const override; StickerPropertiesPtr stickerProperties() const; void setProperties(const PropertiesPtr &properties) override; protected: void updateShape() override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; private: QSvgRenderer mSvgRenderer; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONSTICKER_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationText.cpp000066400000000000000000000065151414424500400245370ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationText.h" namespace kImageAnnotator { AnnotationText::AnnotationText(const QPointF &startPosition, const TextPropertiesPtr &properties) : AbstractAnnotationRect(startPosition, properties) { setupFlags(); connectSlots(); } AnnotationText::AnnotationText(const AnnotationText &other) : AbstractAnnotationRect(other), mTextHandler(other.mTextHandler) { setupFlags(); connectSlots(); } void AnnotationText::updateShape() { QPainterPath path; path.addRect(*mRect); setShape(path); } void AnnotationText::focusOutEvent(QFocusEvent *event) { disableEditing(); QGraphicsWidget::focusOutEvent(event); } void AnnotationText::keyPressEvent(QKeyEvent *event) { mTextHandler.handleKeyEvent(event); } void AnnotationText::inputMethodEvent(QInputMethodEvent *event) { mTextHandler.insertText(event->commitString()); } void AnnotationText::paint(QPainter *painter, const QStyleOptionGraphicsItem *style, QWidget *widget) { // Paint border AbstractAnnotationRect::paint(painter, style, widget); // Paint Text auto font = textProperties()->font(); auto color = textProperties()->textColor(); auto margin = textProperties()->width(); auto isShadowEnabled = properties()->shadowEnabled(); mTextHandler.paintText(painter, mRect, font, color, margin, isShadowEnabled); } void AnnotationText::finish() { enableEditing(); } Tools AnnotationText::toolType() const { return Tools::Text; } QPainterPath AnnotationText::shape() const { auto path = AbstractAnnotationItem::shape(); auto font = textProperties()->font(); auto margin = textProperties()->width(); path.addRect(mTextHandler.getTextRect(mRect, font, margin)); return path; } void AnnotationText::escape() { clearFocus(); } void AnnotationText::refresh() { prepareGeometryChange(); auto font = textProperties()->font(); auto margin = textProperties()->width(); mTextHandler.updateRect(mRect, font, margin); updateShape(); } void AnnotationText::connectSlots() { connect(&mTextHandler, &AnnotationTextHandler::changed, this, &AnnotationText::refresh); connect(&mTextHandler, &AnnotationTextHandler::finished, this, &AnnotationText::escape); } void AnnotationText::enableEditing() { setFocus(); mTextHandler.enableEditing(); } void AnnotationText::disableEditing() { mTextHandler.disableEditing(); } TextPropertiesPtr AnnotationText::textProperties() const { return AbstractAnnotationItem::properties().staticCast(); } void AnnotationText::setupFlags() { setFlag(ItemIsFocusable, true); setFlag(ItemAcceptsInputMethod, true); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/AnnotationText.h000066400000000000000000000041111414424500400241720ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONTEXT_H #define KIMAGEANNOTATOR_ANNOTATIONTEXT_H #include "AbstractAnnotationRect.h" #include "src/annotations/items/interfaces/EditableItem.h" #include "src/annotations/items/text/AnnotationTextHandler.h" #include "src/annotations/properties/AnnotationTextProperties.h" namespace kImageAnnotator { class AnnotationText : public AbstractAnnotationRect, public EditableItem { Q_OBJECT public: AnnotationText(const QPointF &startPosition, const TextPropertiesPtr &properties); AnnotationText(const AnnotationText &other); ~AnnotationText() override = default; void finish() override; Tools toolType() const override; QPainterPath shape() const override; void enableEditing() override; void disableEditing() override; TextPropertiesPtr textProperties() const; protected: void updateShape() override; void focusOutEvent(QFocusEvent *event) override; void keyPressEvent(QKeyEvent *event) override; void inputMethodEvent(QInputMethodEvent *event) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *style, QWidget *widget) override; private: AnnotationTextHandler mTextHandler; void connectSlots(); void setupFlags(); private slots: void escape(); void refresh(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONTEXT_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationTextArrow.cpp000066400000000000000000000051331414424500400255450ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationTextArrow.h" namespace kImageAnnotator { AnnotationTextArrow::AnnotationTextArrow(const QPointF &startPosition, const TextPropertiesPtr &properties) : AnnotationTextPointer(startPosition, properties) { } AnnotationTextArrow::AnnotationTextArrow(const AnnotationTextArrow &other) : AnnotationTextPointer(other) { } Tools AnnotationTextArrow::toolType() const { return Tools::TextArrow; } void AnnotationTextArrow::updateShape() { QLineF tmpLine(mPointer, mRect->center()); QPointF intersectionPoint = ShapeHelper::intersectionBetweenRectAndLineFromCenter(tmpLine, *mRect); QLineF shaft(intersectionPoint, mPointer); shaft.setLength(shaft.length() - 5); auto arrow = AnnotationShapeCreator::createArrowHead(properties()->width() / 2); arrow = AnnotationShapeCreator::translate(arrow, mPointer, -shaft.angle()); mRect->moveCenter(mRect->center()); mArrowShape = QPainterPath(shaft.p1()); mArrowShape.setFillRule(Qt::WindingFill); mArrowShape.lineTo(shaft.p2()); mArrowShape.addPolygon(arrow); QPainterPath path(mArrowShape); path.addRect(*mRect); path.closeSubpath(); setShape(path); } void AnnotationTextArrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *style, QWidget *widget) { adjustPainter(painter); painter->setPen(painterPen()); painter->setBrush(properties()->color()); // Draw Arrow painter->drawPath(mArrowShape); // Border and fill if(!hasFill()) { painter->setBrush(Qt::NoBrush); } if(!hasBorder()) { painter->setPen(Qt::NoPen); } painter->drawRect(*mRect); // Paint Text auto font = textProperties()->font(); auto color = textProperties()->textColor(); auto margin = textProperties()->width(); auto isShadowEnabled = properties()->shadowEnabled(); mTextHandler.paintText(painter, mRect, font, color, margin, isShadowEnabled); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/items/AnnotationTextArrow.h000066400000000000000000000027441414424500400252170ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONTEXTARROW_H #define KIMAGEANNOTATOR_ANNOTATIONTEXTARROW_H #include "AnnotationTextPointer.h" namespace kImageAnnotator { class AnnotationTextArrow : public AnnotationTextPointer { Q_OBJECT public: AnnotationTextArrow(const QPointF &startPosition, const TextPropertiesPtr &properties); AnnotationTextArrow(const AnnotationTextArrow &other); ~AnnotationTextArrow() override = default; Tools toolType() const override; protected: void updateShape() override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *style, QWidget *widget) override; private: QPainterPath mArrowShape; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONTEXTARROW_H kImageAnnotator-0.5.3/src/annotations/items/AnnotationTextPointer.cpp000066400000000000000000000101061414424500400260670ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationTextPointer.h" namespace kImageAnnotator { AnnotationTextPointer::AnnotationTextPointer(const QPointF &startPosition, const TextPropertiesPtr &properties) : AbstractAnnotationPointerRect(startPosition, properties) { setupFlags(); connectSlots(); mRect->setWidth(20); mRect->setHeight(properties->font().pixelSize()); } AnnotationTextPointer::AnnotationTextPointer(const AnnotationTextPointer &other) : AbstractAnnotationPointerRect(other), mTextHandler(other.mTextHandler) { setupFlags(); connectSlots(); } void AnnotationTextPointer::finish() { enableEditing(); AbstractAnnotationPointerRect::finish(); } Tools AnnotationTextPointer::toolType() const { return Tools::TextPointer; } QPainterPath AnnotationTextPointer::shape() const { auto path = AbstractAnnotationItem::shape(); if(!hasFill()){ auto font = textProperties()->font(); auto margin = textProperties()->width(); path.addRect(mTextHandler.getTextRect(mRect, font, margin)); } return path; } void AnnotationTextPointer::enableEditing() { setFocus(); mTextHandler.enableEditing(); } void AnnotationTextPointer::disableEditing() { mTextHandler.disableEditing(); } TextPropertiesPtr AnnotationTextPointer::textProperties() const { return AbstractAnnotationItem::properties().staticCast(); } void AnnotationTextPointer::updateShape() { auto line = QLineF(mRect->center(), mPointer); auto pointerWidth = qMin(mRect->width(), mRect->height()) * 0.7; auto pointer = AnnotationShapeCreator::createPointer(pointerWidth, line.length()); auto finishedPointer = AnnotationShapeCreator::translate(pointer, mPointer, -line.angle()); QPainterPath path(mRect->center()); path.setFillRule(Qt::WindingFill); path.addPolygon(finishedPointer); path.closeSubpath(); path.addRect(*mRect); auto painterPath = path.simplified(); setShape(painterPath); } void AnnotationTextPointer::focusOutEvent(QFocusEvent *event) { disableEditing(); QGraphicsWidget::focusOutEvent(event); } void AnnotationTextPointer::keyPressEvent(QKeyEvent *event) { mTextHandler.handleKeyEvent(event); } void AnnotationTextPointer::inputMethodEvent(QInputMethodEvent *event) { mTextHandler.insertText(event->commitString()); } void AnnotationTextPointer::paint(QPainter *painter, const QStyleOptionGraphicsItem *style, QWidget *widget) { // Paint border and fill AbstractAnnotationRect::paint(painter, style, widget); // Paint Text auto font = textProperties()->font(); auto color = textProperties()->textColor(); auto margin = textProperties()->width(); auto isShadowEnabled = properties()->shadowEnabled(); mTextHandler.paintText(painter, mRect, font, color, margin, isShadowEnabled); } void AnnotationTextPointer::connectSlots() { connect(&mTextHandler, &AnnotationTextHandler::changed, this, &AnnotationTextPointer::refresh); connect(&mTextHandler, &AnnotationTextHandler::finished, this, &AnnotationTextPointer::escape); } void AnnotationTextPointer::setupFlags() { setFlag(ItemIsFocusable, true); setFlag(ItemAcceptsInputMethod, true); } void AnnotationTextPointer::escape() { clearFocus(); } void AnnotationTextPointer::refresh() { prepareGeometryChange(); auto font = textProperties()->font(); auto margin = textProperties()->width(); mTextHandler.updateRect(mRect, font, margin); updateShape(); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/items/AnnotationTextPointer.h000066400000000000000000000043021414424500400255350ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONTEXTPOINTER_H #define KIMAGEANNOTATOR_ANNOTATIONTEXTPOINTER_H #include "AbstractAnnotationPointerRect.h" #include "src/annotations/items/interfaces/EditableItem.h" #include "src/annotations/items/text/AnnotationTextHandler.h" #include "src/annotations/items/helper/AnnotationShapeCreator.h" #include "src/annotations/properties/AnnotationTextProperties.h" namespace kImageAnnotator { class AnnotationTextPointer : public AbstractAnnotationPointerRect, public EditableItem { Q_OBJECT public: AnnotationTextPointer(const QPointF &startPosition, const TextPropertiesPtr &properties); AnnotationTextPointer(const AnnotationTextPointer &other); ~AnnotationTextPointer() override = default; void finish() override; Tools toolType() const override; QPainterPath shape() const override; void enableEditing() override; void disableEditing() override; TextPropertiesPtr textProperties() const; protected: AnnotationTextHandler mTextHandler; void updateShape() override; void focusOutEvent(QFocusEvent *event) override; void keyPressEvent(QKeyEvent *event) override; void inputMethodEvent(QInputMethodEvent *event) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *style, QWidget *widget) override; private: void connectSlots(); void setupFlags(); private slots: void escape(); void refresh(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONTEXTPOINTER_H kImageAnnotator-0.5.3/src/annotations/items/BaseAnnotationNumber.cpp000066400000000000000000000024331414424500400256310ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "BaseAnnotationNumber.h" namespace kImageAnnotator { void BaseAnnotationNumber::setNumber(int number) { mNumberString = QString::number(number); updateRect(); } int BaseAnnotationNumber::number() const { return mNumberString.toInt(); } QString BaseAnnotationNumber::numberString() const { return mNumberString; } void BaseAnnotationNumber::updateRect(QRectF *rect, const QFont &font) const { mNumberRectHelper.updateRect(rect, mNumberString, font); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/items/BaseAnnotationNumber.h000066400000000000000000000030051414424500400252720ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_BASEANNOTATIONNUMBER_H #define KIMAGEANNOTATOR_BASEANNOTATIONNUMBER_H #include #include #include "src/annotations/items/helper/NumberRectHelper.h" namespace kImageAnnotator { class BaseAnnotationNumber { public: BaseAnnotationNumber() = default; ~BaseAnnotationNumber() = default; BaseAnnotationNumber(const BaseAnnotationNumber &other) = default; void setNumber(int number); int number() const; protected: QString numberString() const; void updateRect(QRectF *rect, const QFont &font) const; virtual void updateRect() = 0; private: QString mNumberString; NumberRectHelper mNumberRectHelper; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_BASEANNOTATIONNUMBER_H kImageAnnotator-0.5.3/src/annotations/items/helper/000077500000000000000000000000001414424500400223245ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/annotations/items/helper/AnnotationShapeCreator.cpp000066400000000000000000000032621414424500400274460ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationShapeCreator.h" namespace kImageAnnotator { QPolygonF AnnotationShapeCreator::createPointer(qreal width, qreal length) { QPointF p0(0, 0); QPointF p1(-length, width / 2); QPointF p2(-length, -width / 2); QPolygonF pointer; return pointer << p0 << p1 << p2 << p0; } QPolygonF AnnotationShapeCreator::createArrowHead(int scaleFactor) { auto arrowHeadLength = 15 + scaleFactor; auto arrowHeadWidth = 5 + scaleFactor; auto arrowHeadMid = 13 + scaleFactor; QPointF p0(0, 0); QPointF p1(-arrowHeadLength, arrowHeadWidth); QPointF p2(-arrowHeadMid, 0); QPointF p3(-arrowHeadLength, -arrowHeadWidth); QPolygonF arrow; return arrow << p0 << p1 << p2 << p3 << p0; } QPolygonF AnnotationShapeCreator::translate(const QPolygonF &shape, const QPointF &pos, qreal angle) { return QTransform().translate(pos.x(), pos.y()).rotate(angle).map(shape); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/items/helper/AnnotationShapeCreator.h000066400000000000000000000024251414424500400271130ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONSHAPECREATOR_H #define KIMAGEANNOTATOR_ANNOTATIONSHAPECREATOR_H #include #include namespace kImageAnnotator { class AnnotationShapeCreator { public: static QPolygonF createPointer(qreal width, qreal length); static QPolygonF createArrowHead(int scaleFactor); static QPolygonF translate(const QPolygonF &shape, const QPointF &pos, qreal angle); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONSHAPECREATOR_H kImageAnnotator-0.5.3/src/annotations/items/helper/NumberRectHelper.cpp000066400000000000000000000026671414424500400262510ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "NumberRectHelper.h" namespace kImageAnnotator { void NumberRectHelper::updateRect(QRectF *rect, const QString &text, const QFont &font) const { auto center = rect->center(); auto size = getTextRectSize(text, font); rect->setSize(size); rect->moveCenter(center); } QSizeF NumberRectHelper::getTextRectSize(const QString &text, const QFont &font) const { QFontMetricsF metrics(font); auto boundingRect = metrics.boundingRect(text).adjusted(-5, -5, 5, 5); auto largestSite = boundingRect.width() > boundingRect.height() ? boundingRect.width() : boundingRect.height(); return { largestSite, largestSite }; } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/helper/NumberRectHelper.h000066400000000000000000000025151414424500400257060ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_NUMBERRECTHELPER_H #define KIMAGEANNOTATOR_NUMBERRECTHELPER_H #include #include #include #include #include namespace kImageAnnotator { class NumberRectHelper { public: NumberRectHelper() = default; ~NumberRectHelper() = default; void updateRect(QRectF *rect, const QString &text, const QFont &font) const; protected: QSizeF getTextRectSize(const QString &text, const QFont &font) const; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_NUMBERRECTHELPER_H kImageAnnotator-0.5.3/src/annotations/items/interfaces/000077500000000000000000000000001414424500400231705ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/annotations/items/interfaces/EditableItem.h000066400000000000000000000020131414424500400256650ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_EDITABLEITEM_H #define KIMAGEANNOTATOR_EDITABLEITEM_H class EditableItem { public: virtual void enableEditing() = 0; virtual void disableEditing() = 0; }; #endif //KIMAGEANNOTATOR_EDITABLEITEM_H kImageAnnotator-0.5.3/src/annotations/items/text/000077500000000000000000000000001414424500400220315ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/annotations/items/text/AnnotationTextHandler.cpp000066400000000000000000000137141414424500400270200ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationTextHandler.h" namespace kImageAnnotator { AnnotationTextHandler::AnnotationTextHandler() : mIsInEditMode(false) { setupEditModeOutlinePen(); connectSlots(); } AnnotationTextHandler::AnnotationTextHandler(const AnnotationTextHandler &other) : mText(other.mText), mTextCursor(other.mTextCursor), mIsInEditMode(false) { setupEditModeOutlinePen(); connectSlots(); } void AnnotationTextHandler::insertText(const QString &text) { mText.insert(mTextCursor.position(), text); mTextCursor.moveForwardBy(mText, text.length()); emit changed(); } void AnnotationTextHandler::removeText(TextPositions direction) { auto currentCursorPos = mTextCursor.position(); if (direction == TextPositions::Previous) { if (currentCursorPos == 0) { return; } mText.remove(currentCursorPos - 1, 1); moveCursor(TextPositions::Previous); } else if (direction == TextPositions::Next) { if (currentCursorPos >= mText.length()) { return; } mText.remove(currentCursorPos, 1); } } void AnnotationTextHandler::moveCursor(TextPositions direction) { mTextCursor.move(direction, mText); } void AnnotationTextHandler::pasteText() { auto clipboard = QApplication::clipboard(); if (clipboard->text().isEmpty()) { return; } mText.insert(mTextCursor.position(), clipboard->text()); mTextCursor.setPosition(mTextCursor.position() + clipboard->text().length()); } void AnnotationTextHandler::enableEditing() { mTextCursor.start(); mIgnoreShortcutsFilter.apply(); mIsInEditMode = true; emit changed(); } void AnnotationTextHandler::disableEditing() { mTextCursor.stop(); mIgnoreShortcutsFilter.remove(); mIsInEditMode = false; emit changed(); } void AnnotationTextHandler::paintText(QPainter *painter, QRectF *rect, const QFont &font, const QColor &color, int margin, bool isShadowEnabled) { auto textArea = rect->toRect(); if (mIsInEditMode && textArea.isValid()) { painter->setBrush(Qt::NoBrush); painter->setPen(mEditModeOutlinePen); painter->drawRect(textArea); } // Workaround for issue #70 / #184 -> Cursor not drawn with with Qt 5.9 // https://bugreports.qt.io/browse/QTBUG-82022 if (mIsInEditMode && isShadowEnabled) { painter->setBrush(QColor(255,255,255,50)); painter->drawRect(*rect); } // Paint text painter->setPen(color); painter->setClipRect(rect->adjusted(margin, margin, -margin, -margin)); QFontMetrics fontMetrics(font); auto boxHeight = 0; QTextDocument document(mText); for (auto block = document.begin(); block != document.end(); block = block.next()) { auto blockPosition = block.position(); auto blockLength = block.length(); QTextLayout textLayout(block); textLayout.setCacheEnabled(true); textLayout.setFont(font); auto blockHeight = 0; textLayout.setCacheEnabled(true); textLayout.beginLayout(); while (true) { auto line = textLayout.createLine(); if (!line.isValid()) { break; } line.setLineWidth(textArea.width() - margin * 2); blockHeight += fontMetrics.leading(); line.setPosition(textArea.adjusted(margin, margin, 0, 0).topLeft()); blockHeight += line.height(); } textLayout.endLayout(); textLayout.draw(painter, QPoint(0, boxHeight)); if (mTextCursor.isVisible() && isCursorInBlock(blockPosition, blockLength)) { textLayout.drawCursor(painter, QPointF(0, boxHeight), mTextCursor.position() - blockPosition, 1); } boxHeight += blockHeight; } } void AnnotationTextHandler::updateRect(QRectF *rect, const QFont &font, int margin) const { auto newRect = getTextRect(rect, font, margin).normalized(); auto currentRect = rect->normalized(); if (newRect.width() > currentRect.width()) { currentRect.setWidth(newRect.width()); } if (newRect.height() > currentRect.height()) { currentRect.setHeight(newRect.height()); } rect->setRect(currentRect.x(), currentRect.y(), currentRect.width(), currentRect.height()); } bool AnnotationTextHandler::isCursorInBlock(int blockPosition, int blockLength) const { return mTextCursor.position() >= blockPosition && mTextCursor.position() < blockPosition + blockLength; } void AnnotationTextHandler::setupEditModeOutlinePen() { mEditModeOutlinePen.setColor(Qt::white); mEditModeOutlinePen.setWidthF(1); mEditModeOutlinePen.setStyle(Qt::DotLine); } QRect AnnotationTextHandler::getTextRect(QRectF *rect, const QFont& font, int margin) const { QFontMetrics fontMetrics(font); auto newRect = fontMetrics.boundingRect(rect->toRect().normalized(), Qt::AlignLeft, mText); newRect.adjust(0, 2, (margin * 2) + 2, margin * 2); return newRect; } void AnnotationTextHandler::handleKeyEvent(QKeyEvent *event) { mKeyInputHelper.handleKeyPress(event); emit changed(); } void AnnotationTextHandler::connectSlots() { connect(&mKeyInputHelper, &KeyInputHelper::move, this, &AnnotationTextHandler::moveCursor); connect(&mKeyInputHelper, &KeyInputHelper::insert, this, &AnnotationTextHandler::insertText); connect(&mKeyInputHelper, &KeyInputHelper::remove, this, &AnnotationTextHandler::removeText); connect(&mKeyInputHelper, &KeyInputHelper::paste, this, &AnnotationTextHandler::pasteText); connect(&mKeyInputHelper, &KeyInputHelper::escape, this, &AnnotationTextHandler::finished); connect(&mTextCursor, &TextCursor::tick, this, &AnnotationTextHandler::changed); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/text/AnnotationTextHandler.h000066400000000000000000000043601414424500400264620ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONTEXTHANDLER_H #define KIMAGEANNOTATOR_ANNOTATIONTEXTHANDLER_H #include #include #include #include "src/annotations/items/text/TextCursor.h" #include "src/common/filter/IgnoreShortcutsFilter.h" #include "src/annotations/items/text/KeyInputHelper.h" namespace kImageAnnotator { class AnnotationTextHandler : public QObject { Q_OBJECT public: explicit AnnotationTextHandler(); AnnotationTextHandler(const AnnotationTextHandler &other); ~AnnotationTextHandler() override = default; void insertText(const QString &text); void enableEditing(); void disableEditing(); void paintText(QPainter *painter, QRectF *rect, const QFont &font, const QColor &color, int margin, bool isShadowEnabled); void updateRect(QRectF *rect, const QFont &font, int margin) const; QRect getTextRect(QRectF *rect, const QFont& font, int margin) const; void handleKeyEvent(QKeyEvent *event); signals: void changed() const; void finished() const; private: QString mText; TextCursor mTextCursor; IgnoreShortcutsFilter mIgnoreShortcutsFilter; bool mIsInEditMode; QPen mEditModeOutlinePen; KeyInputHelper mKeyInputHelper; bool isCursorInBlock(int blockPosition, int blockLength) const; void setupEditModeOutlinePen(); void connectSlots(); void removeText(TextPositions direction); void moveCursor(TextPositions direction); void pasteText(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONTEXTHANDLER_H kImageAnnotator-0.5.3/src/annotations/items/text/CapsLockStatusChecker.cpp000066400000000000000000000030201414424500400267200ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "CapsLockStatusChecker.h" #if defined(_WIN32) #include #endif #if defined(__linux__) #include "src/common/platform/PlatformChecker.h" #include #include #endif namespace kImageAnnotator { bool CapsLockStatusChecker::isCapsLockEnabled() { #if defined(_WIN32) return GetKeyState(VK_CAPITAL) == 1; #elif defined(__linux__) if (PlatformChecker::instance()->isWayland()) { return false; } else { auto display = XOpenDisplay(nullptr); auto capsState = false; if (display) { unsigned n; XkbGetIndicatorState(display, XkbUseCoreKbd, &n); capsState = (n & 0x01) == 1; } XCloseDisplay(display); return capsState; } #else return false; #endif } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/items/text/CapsLockStatusChecker.h000066400000000000000000000022371414424500400263760ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CAPSLOCKSTATUSCHECKER_H #define KIMAGEANNOTATOR_CAPSLOCKSTATUSCHECKER_H namespace kImageAnnotator { class CapsLockStatusChecker { public: static bool isCapsLockEnabled(); protected: explicit CapsLockStatusChecker() = default; ~CapsLockStatusChecker() = default; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_CAPSLOCKSTATUSCHECKER_H kImageAnnotator-0.5.3/src/annotations/items/text/KeyInputHelper.cpp000066400000000000000000000056711414424500400254560ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KeyInputHelper.h" namespace kImageAnnotator { void KeyInputHelper::handleKeyPress(const QKeyEvent *event) const { switch (event->key()) { case Qt::Key_Backspace: emit remove(TextPositions::Previous); break; case Qt::Key_Return: case Qt::Key_Enter: if (isShiftPressed(event)) { emit insert(QLatin1String("\n")); } else { emit escape(); } break; case Qt::Key_Delete: emit remove(TextPositions::Next); break; case Qt::Key_Escape: emit escape(); return; case Qt::Key_Left: if (isControlPressed(event)) { emit move(TextPositions::PreviousWordBeginning); } else { emit move(TextPositions::Previous); } break; case Qt::Key_Right: if (isControlPressed(event)) { emit move(TextPositions::NextWordBeginning); } else { emit move(TextPositions::Next); } break; case Qt::Key_Up: emit move(TextPositions::Up); break; case Qt::Key_Down: emit move(TextPositions::Down); break; case Qt::Key::Key_Home: emit move(TextPositions::Beginning); break; case Qt::Key::Key_End: emit move(TextPositions::End); break; case Qt::Key_Paste: emit paste(); break; default: if (event->matches(QKeySequence::Paste)) { emit paste(); break; } if (event->text().isEmpty()) { return; } emit insert(getTextWithCorrectCase(event)); } } QString KeyInputHelper::getTextWithCorrectCase(const QKeyEvent *event) const { auto text = event->text(); bool capsLockEnabled = CapsLockStatusChecker::isCapsLockEnabled(); bool shiftPressed = isShiftPressed(event); if (shiftPressed && capsLockEnabled) { return text.toLower(); } else if (!shiftPressed && capsLockEnabled) { return text.toUpper(); } return text; } bool KeyInputHelper::isShiftPressed(const QKeyEvent *event) const { return isModifierPressed(event, Qt::ShiftModifier); } bool KeyInputHelper::isControlPressed(const QKeyEvent *event) const { return isModifierPressed(event, Qt::ControlModifier); } bool KeyInputHelper::isModifierPressed(const QKeyEvent *event, Qt::KeyboardModifier modifier) const { return static_cast(event->modifiers() & modifier); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/text/KeyInputHelper.h000066400000000000000000000032601414424500400251130ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_KEYINPUTHELPER_H #define KIMAGEANNOTATOR_KEYINPUTHELPER_H #include #include "TextPositions.h" #include "CapsLockStatusChecker.h" namespace kImageAnnotator { class KeyInputHelper : public QObject { Q_OBJECT public: explicit KeyInputHelper() = default; ~KeyInputHelper() override = default; void handleKeyPress(const QKeyEvent *event) const; bool isShiftPressed(const QKeyEvent *event) const; bool isControlPressed(const QKeyEvent *event) const; QString getTextWithCorrectCase(const QKeyEvent *event) const; signals: void remove(TextPositions position) const; void insert(const QString &text) const; void move(TextPositions position) const; void paste() const; void escape() const; private: bool isModifierPressed(const QKeyEvent *event, Qt::KeyboardModifier modifier) const; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_KEYINPUTHELPER_H kImageAnnotator-0.5.3/src/annotations/items/text/TextCursor.cpp000066400000000000000000000133271414424500400246650ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "TextCursor.h" namespace kImageAnnotator { TextCursor::TextCursor() : mBlinkTimer(new QTimer(this)), mLineFeedChar(QChar::LineFeed) { connectSlots(); } TextCursor::TextCursor(const TextCursor &other) : mBlinkTimer(new QTimer(this)), mPosition(other.mPosition), mLineFeedChar(QChar::LineFeed) { connectSlots(); } TextCursor::~TextCursor() { delete mBlinkTimer; } void TextCursor::move(TextPositions direction, const QString &text) { switch (direction) { case TextPositions::Beginning: moveCursorToBeginning(); break; case TextPositions::End: moveCursorToEnd(text); break; case TextPositions::NextWordBeginning: moveCursorToNextWordBeginning(text); break; case TextPositions::Next: moveCursorForwardBy(text, 1); break; case TextPositions::PreviousWordBeginning: moveCursorToPreviousWordBeginning(text); break; case TextPositions::Previous: moveCursorBack(text); break; case TextPositions::Up: moveCursorUp(text); break; case TextPositions::Down: moveCursorDown(text); break; } mIsVisible = true; } void TextCursor::moveForwardBy(const QString &text, int moveBy) { moveCursorForwardBy(text, moveBy); mIsVisible = true; } void TextCursor::start() { mIsVisible = true; mBlinkTimer->start(mBlinkIntervalInMs); } void TextCursor::stop() { mBlinkTimer->stop(); mIsVisible = false; } int TextCursor::position() const { return mPosition; } void TextCursor::setPosition(int newPosition) { mPosition = newPosition; } bool TextCursor::isVisible() const { return mIsVisible; } void TextCursor::moveCursorToBeginning() { mPosition = 0; } void TextCursor::moveCursorToEnd(const QString &text) { mPosition = text.length(); } void TextCursor::moveCursorToNextWordBeginning(const QString &text) { auto lastSpacePos = -1; auto currentPos = mPosition; while (currentPos < text.length()) { auto currentChar = text.at(currentPos); if (currentChar == mLineFeedChar && currentPos != mPosition) { break; } if (currentChar.isSpace()) { lastSpacePos = currentPos; } else if (lastSpacePos >= 0) { break; } currentPos++; } mPosition = currentPos; } void TextCursor::moveCursorForwardBy(const QString &text, int moveBy) { mPosition += moveBy; if (mPosition > text.length()) { mPosition = text.length(); } } void TextCursor::moveCursorToPreviousWordBeginning(const QString &text) { auto lastNonSpacePos = -1; auto currentPos = mPosition - 1; while (currentPos >= 0) { auto currentChar = text.at(currentPos); if (currentChar == mLineFeedChar) { lastNonSpacePos = currentPos; if (lastNonSpacePos + 1 != mPosition) { lastNonSpacePos++; } break; } if (currentChar.isSpace()) { if (lastNonSpacePos >= 0) { break; } } else { lastNonSpacePos = currentPos; } currentPos--; } if (lastNonSpacePos >= 0) { mPosition = lastNonSpacePos; } else { mPosition = 0; } } void TextCursor::moveCursorBack(const QString &text) { mPosition--; if (mPosition < 0) { mPosition = 0; } } void TextCursor::moveCursorUp(const QString &text) { QTextDocument document(text); auto currentBlock = document.findBlock(mPosition); if (currentBlock == document.firstBlock()) { return; } auto positionInBlock = currentBlock.position(); auto previousBlock = currentBlock.previous(); fitPositionToNewBlock(positionInBlock, previousBlock); } void TextCursor::moveCursorDown(const QString &text) { QTextDocument document(text); auto currentBlock = document.findBlock(mPosition); if (currentBlock == document.lastBlock()) { return; } auto positionInBlock = currentBlock.position(); auto nextBlock = currentBlock.next(); fitPositionToNewBlock(positionInBlock, nextBlock); } void TextCursor::fitPositionToNewBlock(int positionInBlock, const QTextBlock &targetBlock) { if ((mPosition - positionInBlock) < targetBlock.length()) { moveToSamePositionInNewBlock(positionInBlock, targetBlock); } else { movePositionToEndOfBlock(targetBlock); } } void TextCursor::moveToSamePositionInNewBlock(int positionInBlock, const QTextBlock &targetBlock) { mPosition = targetBlock.position() + mPosition - positionInBlock; } void TextCursor::movePositionToEndOfBlock(const QTextBlock &targetBlock) { mPosition = targetBlock.position() + targetBlock.length() - 1; } void TextCursor::connectSlots() { connect(mBlinkTimer, &QTimer::timeout, [this]() { mIsVisible = !mIsVisible; emit tick(); }); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/items/text/TextCursor.h000066400000000000000000000044171414424500400243320ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_TEXTCURSOR_H #define KIMAGEANNOTATOR_TEXTCURSOR_H #include #include #include #include "TextPositions.h" namespace kImageAnnotator { class TextCursor : public QObject { Q_OBJECT public: explicit TextCursor(); TextCursor(const TextCursor &other); ~TextCursor() override; void move(TextPositions direction, const QString &text); void moveForwardBy(const QString &text, int moveBy); void start(); void stop(); int position() const; void setPosition(int newPosition); bool isVisible() const; signals: void tick() const; private: int mBlinkIntervalInMs = 800; QTimer *mBlinkTimer; int mPosition = 0; bool mIsVisible = false; QChar mLineFeedChar; void moveCursorToBeginning(); void moveCursorToEnd(const QString &text); void moveCursorToNextWordBeginning(const QString &text); void moveCursorForwardBy(const QString &text, int moveBy); void moveCursorToPreviousWordBeginning(const QString &text); void moveCursorBack(const QString &text); void moveCursorUp(const QString &text); void moveCursorDown(const QString &text); void fitPositionToNewBlock(int positionInBlock, const QTextBlock &targetBlock); void movePositionToEndOfBlock(const QTextBlock &targetBlock); void moveToSamePositionInNewBlock(int positionInBlock, const QTextBlock &targetBlock); void connectSlots(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_TEXTCURSOR_H kImageAnnotator-0.5.3/src/annotations/items/text/TextPositions.h000066400000000000000000000022711414424500400250400ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_TEXTPOSITIONS_H #define KIMAGEANNOTATOR_TEXTPOSITIONS_H #include namespace kImageAnnotator { enum class TextPositions { Beginning, End, PreviousWordBeginning, NextWordBeginning, Next, Previous, Up, Down }; } // namespace kImageAnnotator Q_DECLARE_METATYPE(kImageAnnotator::TextPositions) #endif //KIMAGEANNOTATOR_TEXTPOSITIONS_H kImageAnnotator-0.5.3/src/annotations/misc/000077500000000000000000000000001414424500400206575ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/annotations/misc/AbstractCloneableItemEffect.cpp000066400000000000000000000015161414424500400266720ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AbstractClonableItemEffect.h" kImageAnnotator-0.5.3/src/annotations/misc/AbstractCloneableItemEffect.h000066400000000000000000000020601414424500400263320ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ABSTRACTITEMEFFECT_H #define KIMAGEANNOTATOR_ABSTRACTITEMEFFECT_H #include namespace kImageAnnotator { class AbstractClonableItemEffect { }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ABSTRACTITEMEFFECT_H kImageAnnotator-0.5.3/src/annotations/misc/AnnotationContextMenu.cpp000066400000000000000000000045351414424500400256760ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationContextMenu.h" namespace kImageAnnotator { AnnotationContextMenu::AnnotationContextMenu() { mArrangeMenu = addMenu(tr("Arrange")); mArrangeMenu->addAction(tr("Bring to Front"), this, &AnnotationContextMenu::bringToFront); mArrangeMenu->addAction(tr("Bring Forward"), this, &AnnotationContextMenu::bringForward); mArrangeMenu->addAction(tr("Send Backward"), this, &AnnotationContextMenu::sendBackward); mArrangeMenu->addAction(tr("Send to Back"), this, &AnnotationContextMenu::sendToBack); addSeparator(); mSelectThisAction = addAction(tr("Select This")); addSeparator(); mCopyAction = addAction(tr("Copy")); mPastAction = addAction(tr("Paste")); addSeparator(); mEditAction = addAction(tr("Edit"), this, &AnnotationContextMenu::edit); mDeleteAction = addAction(tr("Delete"), this, &AnnotationContextMenu::erase); } void AnnotationContextMenu::setOverItem(bool isOverItem) { mArrangeMenu->setEnabled(isOverItem); mCopyAction->setEnabled(isOverItem); mDeleteAction->setEnabled(isOverItem); mSelectThisAction->setEnabled(isOverItem); } void AnnotationContextMenu::setPastEnabled(bool enabled) { mPastAction->setEnabled(enabled); } void AnnotationContextMenu::setEditVisible(bool enabled) { mEditAction->setVisible(enabled); } void AnnotationContextMenu::exec(const QPointF &position) { auto selectedAction = QMenu::exec(position.toPoint()); if (selectedAction && selectedAction == mPastAction) { emit paste(position); } if (selectedAction && selectedAction == mCopyAction) { emit copy(position); } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/misc/AnnotationContextMenu.h000066400000000000000000000032761414424500400253440ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONCONTEXTMENU_H #define KIMAGEANNOTATOR_ANNOTATIONCONTEXTMENU_H #include namespace kImageAnnotator { class AnnotationContextMenu : public QMenu { Q_OBJECT public: explicit AnnotationContextMenu(); ~AnnotationContextMenu() override = default; void setOverItem(bool isOverItem); void setPastEnabled(bool enabled); void setEditVisible(bool enabled); void exec(const QPointF &position); signals: void bringToFront() const; void bringForward() const; void sendBackward() const; void sendToBack() const; void copy(const QPointF &position) const; void paste(const QPointF &position) const; void erase() const; void edit() const; private: QMenu *mArrangeMenu; QAction *mCopyAction; QAction *mPastAction; QAction *mSelectThisAction; QAction *mDeleteAction; QAction *mEditAction; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONCONTEXTMENU_H kImageAnnotator-0.5.3/src/annotations/misc/AnnotationItemClipboard.cpp000066400000000000000000000030341414424500400261340ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemClipboard.h" namespace kImageAnnotator { AnnotationItemClipboard::AnnotationItemClipboard(const AnnotationItemModifier *itemModifier) { Q_ASSERT(itemModifier != nullptr); mItemModifier = itemModifier; } bool AnnotationItemClipboard::isEmpty() const { return mCopiedItemsToOffset.count() == 0; } void AnnotationItemClipboard::copyItems(const QPointF &position) { clear(); for (auto item : mItemModifier->selectedItems()) { mCopiedItemsToOffset[item] = item->position() - position; } } QHash AnnotationItemClipboard::copiedItemsWithOffset() const { return mCopiedItemsToOffset; } void AnnotationItemClipboard::clear() { mCopiedItemsToOffset.clear(); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/misc/AnnotationItemClipboard.h000066400000000000000000000031521414424500400256020ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMCLIPBOARD_H #define KIMAGEANNOTATOR_ANNOTATIONITEMCLIPBOARD_H #include #include "src/annotations/modifiers/AnnotationItemModifier.h" #include "src/annotations/core/AnnotationItemFactory.h" namespace kImageAnnotator { class AnnotationItemClipboard : public QObject { Q_OBJECT public: explicit AnnotationItemClipboard(const AnnotationItemModifier *itemModifier); ~AnnotationItemClipboard() override = default; bool isEmpty() const; QHash copiedItemsWithOffset() const; public slots: void copyItems(const QPointF &position); void clear(); private: const AnnotationItemModifier *mItemModifier; QHash mCopiedItemsToOffset; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONITEMCLIPBOARD_H kImageAnnotator-0.5.3/src/annotations/misc/CanvasPainter.cpp000066400000000000000000000030701414424500400241210ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "CanvasPainter.h" namespace kImageAnnotator { CanvasPainter::CanvasPainter() : mCanvasBackground(new QImage(QSize(20, 20), QImage::Format_ARGB32_Premultiplied)) { createTiledBackground(); } CanvasPainter::~CanvasPainter() { delete mCanvasBackground; } void CanvasPainter::paint(QPainter *painter, const QRectF &rect, const QColor &color) { painter->setPen(Qt::NoPen); painter->setBrush(*mCanvasBackground); painter->drawRect(rect); painter->setBrush(color); painter->drawRect(rect); } void CanvasPainter::createTiledBackground() { mCanvasBackground->fill(Qt::white); QPainter painter(mCanvasBackground); painter.setPen(Qt::NoPen); painter.setBrush(Qt::gray); painter.drawRect(0, 0, 10, 10); painter.drawRect(10, 10, 20, 20); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/misc/CanvasPainter.h000066400000000000000000000023071414424500400235700ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CANVASPAINTER_H #define KIMAGEANNOTATOR_CANVASPAINTER_H #include namespace kImageAnnotator { class CanvasPainter { public: CanvasPainter(); ~CanvasPainter(); void paint(QPainter *painter, const QRectF &rect, const QColor &color); private: QImage *mCanvasBackground; void createTiledBackground(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_CANVASPAINTER_H kImageAnnotator-0.5.3/src/annotations/misc/ImageBlurrer.cpp000066400000000000000000000054241414424500400237500ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ImageBlurrer.h" /* * Solution provided by liuyanghejerry * See: https://stackoverflow.com/questions/3903223/qt4-how-to-blur-qpixmap-image */ namespace kImageAnnotator { QImage ImageBlurrer::blurred(const QImage &image, int radius, bool alphaOnly) const { auto alpha = getAlpha(radius); auto result = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); auto r1 = image.rect().top(); auto r2 = image.rect().bottom(); auto c1 = image.rect().left(); auto c2 = image.rect().right(); auto bpl = result.bytesPerLine(); int rgba[4]; unsigned char *p; auto i1 = 0; auto i2 = 3; if (alphaOnly) { i1 = i2 = 3; } for (auto col = c1; col <= c2; col++) { p = result.scanLine(r1) + col * 4; for (auto i = i1; i <= i2; i++) { rgba[i] = p[i] << 4; } p += bpl; for (auto j = r1; j < r2; j++, p += bpl) { for (auto i = i1; i <= i2; i++) { p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 64) >> 4; } } } for (auto row = r1; row <= r2; row++) { p = result.scanLine(row) + c1 * 4; for (auto i = i1; i <= i2; i++) { rgba[i] = p[i] << 4; } p += 4; for (auto j = c1; j < c2; j++, p += 4) { for (auto i = i1; i <= i2; i++) { p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 64) >> 4; } } } for (auto col = c1; col <= c2; col++) { p = result.scanLine(r2) + col * 4; for (auto i = i1; i <= i2; i++) { rgba[i] = p[i] << 4; } p -= bpl; for (auto j = r1; j < r2; j++, p -= bpl) { for (auto i = i1; i <= i2; i++) { p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 64) >> 4; } } } for (auto row = r1; row <= r2; row++) { p = result.scanLine(row) + c2 * 4; for (auto i = i1; i <= i2; i++) { rgba[i] = p[i] << 4; } p -= 4; for (auto j = c1; j < c2; j++, p -= 4) { for (auto i = i1; i <= i2; i++) { p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 64) >> 4; } } } return result; } int ImageBlurrer::getAlpha(int radius) const { return abs(radius - 21); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/misc/ImageBlurrer.h000066400000000000000000000023021414424500400234050ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_IMAGEBLURRER_H #define KIMAGEANNOTATOR_IMAGEBLURRER_H #include namespace kImageAnnotator { class ImageBlurrer { public: explicit ImageBlurrer() = default; ~ImageBlurrer() = default; QImage blurred(const QImage &image, int radius, bool alphaOnly) const; private: int getAlpha(int radius) const; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_IMAGEBLURRER_H kImageAnnotator-0.5.3/src/annotations/misc/NumberManager.cpp000066400000000000000000000050471414424500400241140ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "NumberManager.h" namespace kImageAnnotator { NumberManager::NumberManager() : mNumberSeed(1), mNumberUpdateMode(NumberUpdateMode::UpdateAllNumbers) { } void kImageAnnotator::NumberManager::addItem(AnnotationNumber *item) { addItemInner(item); } void kImageAnnotator::NumberManager::addItem(AnnotationNumberPointer *item) { addItemInner(item); } void NumberManager::addItem(AnnotationNumberArrow *item) { addItemInner(item); } void NumberManager::addItemInner(AbstractAnnotationItem *item) { Q_ASSERT(item != nullptr); mItems.append(item); if (mNumberUpdateMode == NumberUpdateMode::UpdateAllNumbers) { connect(item, &AbstractAnnotationItem::visibleChanged, this, &NumberManager::updateExistingNumbersIfRequired); updateExistingNumbers(); } else { initItemNumber(item); emit numberSeedChanged(mNumberSeed); } } void NumberManager::initItemNumber(AbstractAnnotationItem *item) { auto numberItem = dynamic_cast(item); numberItem->setNumber(mNumberSeed++); } void NumberManager::reset() { mItems.clear(); } void NumberManager::updateExistingNumbersIfRequired() { if(mNumberUpdateMode == NumberUpdateMode::UpdateAllNumbers) { updateExistingNumbers(); } } void NumberManager::updateExistingNumbers() { auto number = mNumberSeed; for (auto item : mItems) { if (item->isVisible()) { auto numberItem = dynamic_cast(item); numberItem->setNumber(number++); } } } void NumberManager::setNumberSeed(int numberSeed) { mNumberSeed = numberSeed; updateExistingNumbersIfRequired(); } int NumberManager::numberSeed() const { return mNumberSeed; } void NumberManager::setNumberUpdateMode(NumberUpdateMode numberUpdateMode) { mNumberUpdateMode = numberUpdateMode; } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/misc/NumberManager.h000066400000000000000000000036541414424500400235630ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_NUMBERMANAGER_H #define KIMAGEANNOTATOR_NUMBERMANAGER_H #include #include "src/common/enum/NumberUpdateMode.h" #include "src/annotations/items/AnnotationNumber.h" #include "src/annotations/items/AnnotationNumberPointer.h" #include "src/annotations/items/AnnotationNumberArrow.h" namespace kImageAnnotator { class NumberManager : public QObject { Q_OBJECT public: explicit NumberManager(); ~NumberManager() override = default; void addItem(AnnotationNumber *item); void addItem(AnnotationNumberPointer *item); void addItem(AnnotationNumberArrow *item); void reset(); void setNumberSeed(int numberSeed); int numberSeed() const; void setNumberUpdateMode(NumberUpdateMode numberUpdateMode); signals: void numberSeedChanged(int numberSeed); public slots: void updateExistingNumbersIfRequired(); private: int mNumberSeed; QList mItems; NumberUpdateMode mNumberUpdateMode; void addItemInner(AbstractAnnotationItem *item); void initItemNumber(AbstractAnnotationItem *item); void updateExistingNumbers(); }; } // namepsace kImageAnnotator #endif //KIMAGEANNOTATOR_NUMBERMANAGER_H kImageAnnotator-0.5.3/src/annotations/misc/ShadowEffect.cpp000066400000000000000000000017711414424500400237330ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ShadowEffect.h" namespace kImageAnnotator { ShadowEffect::ShadowEffect() { setColor(QColor(63, 63, 63, 190)); setBlurRadius(7); setOffset(QPoint(2, 2)); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/misc/ShadowEffect.h000066400000000000000000000022111414424500400233660ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SHADOWEFFECT_H #define KIMAGEANNOTATOR_SHADOWEFFECT_H #include namespace kImageAnnotator { class ShadowEffect : public QGraphicsDropShadowEffect { public: explicit ShadowEffect(); ~ShadowEffect() override = default; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_SHADOWEFFECT_H kImageAnnotator-0.5.3/src/annotations/modifiers/000077500000000000000000000000001414424500400217055ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/annotations/modifiers/AnnotationItemArranger.cpp000066400000000000000000000053461414424500400270340ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemArranger.h" namespace kImageAnnotator { AnnotationItemArranger::AnnotationItemArranger(const QList &selectedItems, QList *items) : mSelectedItems(selectedItems), mItems(items) { } void AnnotationItemArranger::bringToFront() { moveForward(true); } void AnnotationItemArranger::bringForward() { moveForward(false); } void AnnotationItemArranger::sendBackward() { moveBackward(false); } void AnnotationItemArranger::sendToBack() { moveBackward(true); } void AnnotationItemArranger::moveForward(bool toFront) { QList> itemToSwap; for (auto selected : mSelectedItems) { for (auto i = mItems->count() - 1; i >= 0; i--) { auto item = mItems->value(i); if (ItemHelper::zValueGreaterThen(item, selected) && !mSelectedItems.contains(item)) { itemToSwap.append(qMakePair(selected, item)); if (!toFront) { break; } } } } createAndEmitArrangeCommand(itemToSwap); } void AnnotationItemArranger::moveBackward(bool toBack) { QList> itemToSwap; for (auto i = mSelectedItems.count() - 1; i >= 0; i--) { auto selected = mSelectedItems.value(i); for (auto item : *mItems) { if (item->zValue() < selected->zValue() && !mSelectedItems.contains(item)) { itemToSwap.append(qMakePair(selected, item)); if (!toBack) { break; } } } } createAndEmitArrangeCommand(itemToSwap); } void AnnotationItemArranger::createAndEmitArrangeCommand(const QList> &itemToSwap) const { emit newCommand(new ArrangeCommand(itemToSwap, mItems)); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/modifiers/AnnotationItemArranger.h000066400000000000000000000036001414424500400264700ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMARRANGER_H #define KIMAGEANNOTATOR_ANNOTATIONITEMARRANGER_H #include #include "src/annotations/items/AbstractAnnotationItem.h" #include "src/annotations/undo/ArrangeCommand.h" #include "src/common/helper/ItemHelper.h" namespace kImageAnnotator { class AnnotationItemArranger : public QObject { Q_OBJECT public: explicit AnnotationItemArranger(const QList &selectedItems, QList *items); ~AnnotationItemArranger() override = default; signals: void newCommand(ArrangeCommand *arrange) const; public slots: void bringToFront(); void bringForward(); void sendBackward(); void sendToBack(); private: QList mSelectedItems; QList *mItems; void moveForward(bool toFront); void moveBackward(bool toBack); void createAndEmitArrangeCommand(const QList> &itemToSwap) const; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONITEMARRANGER_H kImageAnnotator-0.5.3/src/annotations/modifiers/AnnotationItemEditor.cpp000066400000000000000000000033171414424500400265150ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemEditor.h" namespace kImageAnnotator { AnnotationItemEditor::AnnotationItemEditor() : mCurrentEditItem(nullptr) { } void AnnotationItemEditor::handleEditAt(const QPointF &pos, QList *items) { mCurrentEditItem = findEditableItemAt(pos, items); if (mCurrentEditItem != nullptr) { mCurrentEditItem->enableEditing(); } } bool AnnotationItemEditor::isEditing() const { return mCurrentEditItem != nullptr; } void AnnotationItemEditor::clear() { mCurrentEditItem = nullptr; } EditableItem *AnnotationItemEditor::findEditableItemAt(const QPointF &position, QList *items) { QRectF rect(position - QPointF(2, 2), QSize(4, 4)); for (auto item : *items) { auto editableItem = dynamic_cast(item); if (editableItem != nullptr && item->intersects(rect)) { return editableItem; } } return nullptr; } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/modifiers/AnnotationItemEditor.h000066400000000000000000000027611414424500400261640ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMEDITOR_H #define KIMAGEANNOTATOR_ANNOTATIONITEMEDITOR_H #include #include "src/annotations/items/AbstractAnnotationItem.h" #include "src/annotations/items/interfaces/EditableItem.h" namespace kImageAnnotator { class AnnotationItemEditor : public QObject { Q_OBJECT public: explicit AnnotationItemEditor(); void handleEditAt(const QPointF &pos, QList *items); bool isEditing() const; void clear(); private: EditableItem *mCurrentEditItem; static EditableItem *findEditableItemAt(const QPointF &position, QList *items); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONITEMEDITOR_H kImageAnnotator-0.5.3/src/annotations/modifiers/AnnotationItemModifier.cpp000066400000000000000000000120151414424500400270200ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemModifier.h" namespace kImageAnnotator { AnnotationItemModifier::AnnotationItemModifier(ZoomValueProvider *zoomValueProvider) : mItemSelector(new AnnotationItemSelector(zoomValueProvider)), mItemResizer(new AnnotationMultiItemResizer(zoomValueProvider)), mItemMover(new AnnotationItemMover), mItemEditor(new AnnotationItemEditor) { addToGroup(mItemSelector); addToGroup(mItemResizer); setZValue(1000); setAcceptHoverEvents(true); connect(mItemMover, &AnnotationItemMover::newCommand, this, &AnnotationItemModifier::itemChanged); connect(mItemResizer, &AnnotationMultiItemResizer::newCommand, this, &AnnotationItemModifier::itemChanged); } AnnotationItemModifier::~AnnotationItemModifier() { delete mItemResizer; delete mItemSelector; delete mItemMover; delete mItemEditor; } void AnnotationItemModifier::handleMousePress(const QPointF &pos, QList *items, bool isCtrlPressed) { mItemEditor->clear(); mItemResizer->grabHandle(pos); if (mItemResizer->isResizing()) { mItemResizer->hideCurrentResizer(); return; } mItemSelector->handleSelectionOrShowSelectionRectAt(pos, items, isCtrlPressed); if (mItemSelector->isSelecting()) { mItemResizer->detach(); return; } auto selectedItems = mItemSelector->selectedItems(); mItemMover->setOffset(pos, selectedItems); mItemResizer->hide(); handleSelection(); updateCursor(mItemMover->cursor()); } void AnnotationItemModifier::handleMouseMove(const QPointF &pos, bool isCtrlPressed) { if (mItemResizer->isResizing()) { mItemResizer->moveHandle(pos, isCtrlPressed); updateCursor(mItemResizer->cursorForCurrentHandle()); } else if (mItemSelector->isSelecting()) { mItemSelector->extendSelectionRectWhenShown(pos); } else { mItemMover->moveItems(pos); mItemSelector->refresh(); } } void AnnotationItemModifier::handleMouseRelease(QList *items) { if (mItemResizer->isResizing()) { mItemResizer->releaseHandle(); mItemResizer->showCurrentResizer(); } else if (mItemSelector->isSelecting()) { mItemSelector->finishSelectionRectWhenShown(items); } else { mItemMover->clearOffset(); mItemResizer->show(); updateCursor(mItemMover->cursor()); } handleSelection(); } void AnnotationItemModifier::handleMouseDoubleClick(const QPointF &pos, QList *items) { mItemEditor->handleEditAt(pos, items); if (mItemEditor->isEditing()) { clear(); } } void AnnotationItemModifier::handleSelectionAt(const QPointF &pos, QList *items, bool isCtrlPressed) { mItemSelector->handleSelectionAt(pos, items, isCtrlPressed); handleSelection(); } QList AnnotationItemModifier::selectedItems() const { return mItemSelector->selectedItems(); } QRectF AnnotationItemModifier::boundingRect() const { if (mItemResizer->hasItemsAttached()) { return mItemResizer->boundingRect(); } return mItemSelector->boundingRect(); } void AnnotationItemModifier::selectItem(AbstractAnnotationItem *item) { mItemSelector->selectItem(item); handleSelection(); } void AnnotationItemModifier::clear() { mItemSelector->clearSelection(); mItemResizer->detach(); } void AnnotationItemModifier::updateSelection() { mItemSelector->update(); mItemResizer->update(); mItemResizer->refresh(); } void AnnotationItemModifier::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_UNUSED(event) // Move Cursor disappears when we let this event propagate } void AnnotationItemModifier::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { if (mItemMover->isMoving()) { return; } updateCursor(mItemResizer->cursorForPos(event->scenePos())); QGraphicsItemGroup::hoverMoveEvent(event); } void AnnotationItemModifier::handleSelection() { auto selectedItems = mItemSelector->selectedItems(); auto count = selectedItems.count(); if (count == 0) { clear(); emit itemsDeselected(); } else { mItemResizer->attachTo(selectedItems); emit itemsSelected(selectedItems); } } void AnnotationItemModifier::updateCursor(Qt::CursorShape cursor) { if (cursor == CursorHelper::defaultCursor()) { unsetCursor(); } else { setCursor(cursor); } } void AnnotationItemModifier::itemChanged(QUndoCommand *command) { emit itemModified(); emit newCommand(command); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/modifiers/AnnotationItemModifier.h000066400000000000000000000052711414424500400264730ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMMODIFIER_H #define KIMAGEANNOTATOR_ANNOTATIONITEMMODIFIER_H #include #include #include #include #include "AnnotationMultiItemResizer.h" #include "AnnotationItemSelector.h" #include "AnnotationItemMover.h" #include "AnnotationItemEditor.h" namespace kImageAnnotator { class AnnotationItemModifier : public QObject, public QGraphicsItemGroup { Q_OBJECT public: explicit AnnotationItemModifier(ZoomValueProvider *zoomValueProvider); ~AnnotationItemModifier() override; void handleMousePress(const QPointF &pos, QList *items, bool isCtrlPressed); void handleMouseMove(const QPointF &pos, bool isCtrlPressed); void handleMouseRelease(QList *items); void handleMouseDoubleClick(const QPointF &pos, QList *items); void handleSelectionAt(const QPointF &pos, QList *items, bool isCtrlPressed); QList selectedItems() const; QRectF boundingRect() const override; void selectItem(AbstractAnnotationItem *item); public slots: void clear(); void updateSelection(); signals: void newCommand(QUndoCommand *command); void itemsSelected(const QList &items) const; void itemsDeselected(); void itemModified() const; void itemEdit(); protected: void mousePressEvent(QGraphicsSceneMouseEvent *event) override; void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override; private: AnnotationMultiItemResizer *mItemResizer; AnnotationItemSelector *mItemSelector; AnnotationItemMover *mItemMover; AnnotationItemEditor *mItemEditor; void handleSelection(); void updateCursor(Qt::CursorShape cursor); private slots: void itemChanged(QUndoCommand *command); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONITEMMODIFIER_H kImageAnnotator-0.5.3/src/annotations/modifiers/AnnotationItemMover.cpp000066400000000000000000000032561414424500400263610ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemMover.h" namespace kImageAnnotator { void AnnotationItemMover::setOffset(const QPointF &pos, const QList &selectedItems) { for (auto item : selectedItems) { mItemToOffset[item] = QPointF(pos - item->position()); } } void AnnotationItemMover::moveItems(const QPointF &pos) { QHash itemToNewPos; for (auto item : mItemToOffset.keys()) { if (item != nullptr) { itemToNewPos[item] = pos - mItemToOffset[item]; } } emit newCommand(new MoveCommand(itemToNewPos)); } void AnnotationItemMover::clearOffset() { mItemToOffset.clear(); } bool AnnotationItemMover::isMoving() { return !mItemToOffset.isEmpty(); } Qt::CursorShape AnnotationItemMover::cursor() { if (isMoving()) { return CursorHelper::movingCursor(); } else { return CursorHelper::defaultCursor(); } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/modifiers/AnnotationItemMover.h000066400000000000000000000032301414424500400260160ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMMOVER_H #define KIMAGEANNOTATOR_ANNOTATIONITEMMOVER_H #include #include #include "src/annotations/items/AbstractAnnotationItem.h" #include "src/annotations/undo/MoveCommand.h" #include "src/common/helper/CursorHelper.h" namespace kImageAnnotator { class AnnotationItemMover : public QObject { Q_OBJECT public: explicit AnnotationItemMover() = default; ~AnnotationItemMover() override = default; void setOffset(const QPointF &pos, const QList &selectedItems); void moveItems(const QPointF &pos); void clearOffset(); bool isMoving(); Qt::CursorShape cursor(); signals: void newCommand(MoveCommand *move) const; private: QHash mItemToOffset; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONITEMMOVER_H kImageAnnotator-0.5.3/src/annotations/modifiers/AnnotationItemResizer.cpp000066400000000000000000000062051414424500400267110ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemResizer.h" namespace kImageAnnotator { AnnotationItemResizer::AnnotationItemResizer(AbstractAnnotationItem *item, ZoomValueProvider *zoomValueProvider) : mAnnotationItem(item), mZoomValueProvider(zoomValueProvider), mCurrentHandle(-1) { mResizeHandles = ResizeHandlesFactory::createResizeHandles(item, zoomValueProvider->zoomValue()); connect(zoomValueProvider, &ZoomValueProvider::zoomValueChanged, this, &AnnotationItemResizer::applyZoomValue); prepareGeometryChange(); } AnnotationItemResizer::~AnnotationItemResizer() { mAnnotationItem = nullptr; delete mResizeHandles; } QRectF AnnotationItemResizer::boundingRect() const { auto size = mResizeHandles->handleSize() / 2; return mAnnotationItem->boundingRect().normalized().adjusted(-size, -size, size, size); } void AnnotationItemResizer::grabHandle(const QPointF &pos) { mCurrentHandle = mResizeHandles->indexOfHandleAt(pos); if (mCurrentHandle != -1) { mClickOffset = pos - mResizeHandles->handle(mCurrentHandle).anchor(); } } void AnnotationItemResizer::moveHandle(const QPointF &pos, bool isCtrlPressed) { if (mCurrentHandle != -1) { emit newCommand(new ResizeCommand(mAnnotationItem, mCurrentHandle, pos - mClickOffset, isCtrlPressed)); } } void AnnotationItemResizer::releaseHandle() { mCurrentHandle = -1; } bool AnnotationItemResizer::isResizing() const { return mCurrentHandle != -1; } void AnnotationItemResizer::refresh() { prepareGeometryChange(); mResizeHandles->update(); } bool AnnotationItemResizer::isItemVisible() const { return mAnnotationItem != nullptr && mAnnotationItem->isVisible(); } Qt::CursorShape AnnotationItemResizer::cursorForPos(const QPointF &pos) { return mResizeHandles->cursorForPos(pos); } Qt::CursorShape AnnotationItemResizer::cursorForCurrentHandle() { return mResizeHandles->cursorForHandle(mCurrentHandle); } void AnnotationItemResizer::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { painter->setPen(QPen(Qt::white, 1.0 / mZoomValueProvider->zoomValue())); painter->setBrush(Qt::gray); auto handles = mResizeHandles->handles(); for (auto &handle : handles) { painter->drawRect(handle); } } void AnnotationItemResizer::applyZoomValue(double value) { mResizeHandles->applyZoomValue(value); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/modifiers/AnnotationItemResizer.h000066400000000000000000000041601414424500400263540ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMRESIZER_H #define KIMAGEANNOTATOR_ANNOTATIONITEMRESIZER_H #include #include "resizeHandles/ResizeHandlesFactory.h" #include "src/annotations/undo/ResizeCommand.h" #include "src/annotations/core/ZoomValueProvider.h" namespace kImageAnnotator { class AnnotationItemResizer : public QGraphicsWidget { Q_OBJECT public: AnnotationItemResizer(AbstractAnnotationItem *item, ZoomValueProvider *zoomValueProvider); ~AnnotationItemResizer() override; QRectF boundingRect() const override; void grabHandle(const QPointF &pos); void moveHandle(const QPointF &pos, bool isCtrlPressed); void releaseHandle(); bool isResizing() const; void refresh(); bool isItemVisible() const; Qt::CursorShape cursorForPos(const QPointF &pos); Qt::CursorShape cursorForCurrentHandle(); signals: void newCommand(ResizeCommand *resize) const; protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; private: AbstractItemResizeHandles *mResizeHandles; AbstractAnnotationItem *mAnnotationItem; ZoomValueProvider *mZoomValueProvider; int mCurrentHandle; QPointF mClickOffset; void applyZoomValue(double value); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONITEMRESIZER_H kImageAnnotator-0.5.3/src/annotations/modifiers/AnnotationItemSelector.cpp000066400000000000000000000124651414424500400270530ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemSelector.h" namespace kImageAnnotator { AnnotationItemSelector::AnnotationItemSelector(ZoomValueProvider *zoomValueProvider) { mSelectedItems = new QList(); mShowSelectionRect = false; mSelectionPen.setStyle(Qt::DashLine); mSelectionPen.setColor(Qt::gray); applyZoomValue(zoomValueProvider->zoomValue()); connect(zoomValueProvider, &ZoomValueProvider::zoomValueChanged, this, &AnnotationItemSelector::applyZoomValue); } AnnotationItemSelector::~AnnotationItemSelector() { delete mSelectedItems; } QRectF AnnotationItemSelector::boundingRect() const { if (isSelecting()) { return mSelectionRect.normalized(); } else { return mSelectedItemsBoundingRect; } } void AnnotationItemSelector::handleSelectionOrShowSelectionRectAt(const QPointF &pos, QList *items, bool isModifying) { handleSelectionAt(pos, items, isModifying); if (mSelectedItems->count() > 0) { return; } initSelectionRectAt(pos); mShowSelectionRect = true; } void AnnotationItemSelector::handleSelectionAt(const QPointF &pos, QList *items, bool modifying) { prepareGeometryChange(); if (modifying) { toggleItemSelectionAt(pos, items); } else { selectItemAt(pos, items); } } void AnnotationItemSelector::extendSelectionRectWhenShown(const QPointF &pos) { if (!mShowSelectionRect) { return; } prepareGeometryChange(); updateSelectionRect(pos); } void AnnotationItemSelector::finishSelectionRectWhenShown(QList *items) { if (!mShowSelectionRect) { return; } prepareGeometryChange(); mShowSelectionRect = false; selectItemsUnderRect(items); } void AnnotationItemSelector::clearSelection() { prepareGeometryChange(); mSelectedItems->clear(); mSelectedItemsBoundingRect = QRectF(); } QList AnnotationItemSelector::selectedItems() const { return *mSelectedItems; } bool AnnotationItemSelector::isSelecting() const { return mShowSelectionRect; } void AnnotationItemSelector::refresh() { prepareGeometryChange(); mSelectedItemsBoundingRect = QRectF(); for (auto item : *mSelectedItems) { mSelectedItemsBoundingRect = mSelectedItemsBoundingRect.united(item->boundingRect()); } } void AnnotationItemSelector::update() { for (auto item : *mSelectedItems) { if (!item->isVisible()) { unselectItem(item); } } } void AnnotationItemSelector::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option) Q_UNUSED(widget) if (mShowSelectionRect) { painter->setPen(QPen(Qt::darkBlue, mSelectionPen.widthF())); painter->setBrush(QColor(0, 0, 255, 60)); painter->drawRect(mSelectionRect); } painter->setPen(mSelectionPen); painter->setBrush(Qt::NoBrush); for (auto item : *mSelectedItems) { painter->drawRect(item->boundingRect()); } } void AnnotationItemSelector::initSelectionRectAt(const QPointF &position) { mSelectionRect.setTopLeft(position); updateSelectionRect(position); } void AnnotationItemSelector::updateSelectionRect(const QPointF &position) { mSelectionRect.setBottomRight(position); } void AnnotationItemSelector::selectItemAt(const QPointF &position, QList *items) { auto item = findItemAt(position, items); if (item == nullptr) { clearSelection(); return; } if (!mSelectedItems->contains(item)) { clearSelection(); selectItem(item); } } void AnnotationItemSelector::toggleItemSelectionAt(const QPointF &position, QList *items) { auto item = findItemAt(position, items); if (item == nullptr) { clearSelection(); return; } if (mSelectedItems->contains(item)) { unselectItem(item); } else { selectItem(item); } } void AnnotationItemSelector::selectItemsUnderRect(QList *items) { clearSelection(); for (auto item : *items) { if (item->intersects(mSelectionRect)) { selectItem(item); } } } void AnnotationItemSelector::selectItem(AbstractAnnotationItem *item) { mSelectedItems->append(item); refresh(); } void AnnotationItemSelector::unselectItem(AbstractAnnotationItem *item) { mSelectedItems->removeOne(item); refresh(); } AbstractAnnotationItem *AnnotationItemSelector::findItemAt(const QPointF &position, QList *items) { QRectF rect(position - QPointF(2, 2), QSize(4, 4)); for (auto item : *items) { if (item->intersects(rect)) { return item; } } return nullptr; } void AnnotationItemSelector::applyZoomValue(double value) { mSelectionPen.setWidthF(1.0 / value); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/modifiers/AnnotationItemSelector.h000066400000000000000000000052541414424500400265160ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMSELECTOR_H #define KIMAGEANNOTATOR_ANNOTATIONITEMSELECTOR_H #include #include "src/annotations/items/AbstractAnnotationItem.h" #include "src/annotations/core/ZoomValueProvider.h" namespace kImageAnnotator { class AnnotationItemSelector : public QGraphicsWidget { public: explicit AnnotationItemSelector(ZoomValueProvider *zoomValueProvider); ~AnnotationItemSelector() override; QRectF boundingRect() const override; void handleSelectionOrShowSelectionRectAt(const QPointF &pos, QList *items, bool isModifying); void extendSelectionRectWhenShown(const QPointF &pos); void finishSelectionRectWhenShown(QList *items); void handleSelectionAt(const QPointF &pos, QList *items, bool modifying); void clearSelection(); QList selectedItems() const; bool isSelecting() const; void refresh(); void update(); void selectItem(AbstractAnnotationItem *item); protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; private: QRectF mSelectionRect; QRectF mSelectedItemsBoundingRect; QList *mSelectedItems; bool mShowSelectionRect; QPen mSelectionPen; void initSelectionRectAt(const QPointF &position); void updateSelectionRect(const QPointF &position); void selectItemAt(const QPointF &position, QList *items); void toggleItemSelectionAt(const QPointF &position, QList *items); void selectItemsUnderRect(QList *items); void unselectItem(AbstractAnnotationItem *item); AbstractAnnotationItem *findItemAt(const QPointF &position, QList *items); void applyZoomValue(double value); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONITEMSELECTOR_H kImageAnnotator-0.5.3/src/annotations/modifiers/AnnotationMultiItemResizer.cpp000066400000000000000000000107601414424500400277250ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationMultiItemResizer.h" namespace kImageAnnotator { AnnotationMultiItemResizer::AnnotationMultiItemResizer(ZoomValueProvider *zoomValueProvider) { mZoomValueProvider = zoomValueProvider; mCurrentResizer = nullptr; } QRectF AnnotationMultiItemResizer::boundingRect() const { QRectF rect; for (auto resizer : childItems()) { rect = rect.united(resizer->boundingRect()); } return rect; } void AnnotationMultiItemResizer::attachTo(const QList& items) { detach(); for (auto item : items) { auto resizer = getResizerForItem(item); showResizer(resizer); } } void AnnotationMultiItemResizer::detach() { for (auto resizer : childItems()) { hideResizer(resizer); } mCurrentResizer = nullptr; } void AnnotationMultiItemResizer::grabHandle(const QPointF &pos) { for (auto item : childItems()) { auto resizer = castToResizer(item); resizer->grabHandle(pos); if (resizer->isResizing()) { mCurrentResizer = resizer; return; } } mCurrentResizer = nullptr; } void AnnotationMultiItemResizer::moveHandle(const QPointF &pos, bool isCtrlPressed) { if (mCurrentResizer == nullptr) { return; } mCurrentResizer->moveHandle(pos, isCtrlPressed); } void AnnotationMultiItemResizer::releaseHandle() { if (mCurrentResizer == nullptr) { return; } mCurrentResizer->releaseHandle(); } bool AnnotationMultiItemResizer::isResizing() const { return mCurrentResizer != nullptr && mCurrentResizer->isResizing(); } void AnnotationMultiItemResizer::refresh() { for (auto item : childItems()) { auto resizer = castToResizer(item); resizer->refresh(); } } void AnnotationMultiItemResizer::update() { for (auto item : childItems()) { auto resizer = castToResizer(item); if (!resizer->isItemVisible()) { hideResizer(resizer); } } } bool AnnotationMultiItemResizer::hasItemsAttached() const { return childItems().count() > 0; } Qt::CursorShape AnnotationMultiItemResizer::cursorForPos(const QPointF &pos) { for (auto item : childItems()) { auto resizer = castToResizer(item); if (resizer->boundingRect().contains(pos)) { return resizer->cursorForPos(pos); } } return CursorHelper::defaultCursor(); } Qt::CursorShape AnnotationMultiItemResizer::cursorForCurrentHandle() { if (mCurrentResizer == nullptr) { return CursorHelper::defaultCursor(); } return mCurrentResizer->cursorForCurrentHandle(); } void AnnotationMultiItemResizer::hideCurrentResizer() { if (mCurrentResizer == nullptr) { return; } mCurrentResizer->hide(); } void AnnotationMultiItemResizer::showCurrentResizer() { if (mCurrentResizer == nullptr) { return; } mCurrentResizer->show(); } AnnotationItemResizer *AnnotationMultiItemResizer::getResizerForItem(AbstractAnnotationItem *item) { if (!mItemToResizer.contains(item)) { mItemToResizer[item] = new AnnotationItemResizer(item, mZoomValueProvider); connect(mItemToResizer[item], &AnnotationItemResizer::newCommand, this, &AnnotationMultiItemResizer::newCommand); } return mItemToResizer[item]; } void AnnotationMultiItemResizer::hideResizer(QGraphicsItem *resizer) { removeFromGroup(resizer); resizer->hide(); } void AnnotationMultiItemResizer::showResizer(AnnotationItemResizer *resizer) { addToGroup(resizer); resizer->refresh(); resizer->show(); } AnnotationItemResizer *AnnotationMultiItemResizer::castToResizer(QGraphicsItem *item) { return dynamic_cast(item); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/modifiers/AnnotationMultiItemResizer.h000066400000000000000000000045101414424500400273660ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONMULTIITEMRESIZER_H #define KIMAGEANNOTATOR_ANNOTATIONMULTIITEMRESIZER_H #include #include #include "AnnotationItemResizer.h" namespace kImageAnnotator { class ZoomValueProvider; class AnnotationMultiItemResizer : public QObject, public QGraphicsItemGroup { Q_OBJECT public: explicit AnnotationMultiItemResizer(ZoomValueProvider *zoomValueProvider); ~AnnotationMultiItemResizer() override = default; QRectF boundingRect() const override; void attachTo(const QList& items); void detach(); void grabHandle(const QPointF &pos); void moveHandle(const QPointF &pos, bool isCtrlPressed); void releaseHandle(); bool isResizing() const; void refresh(); void update(); bool hasItemsAttached() const; Qt::CursorShape cursorForPos(const QPointF &pos); Qt::CursorShape cursorForCurrentHandle(); void hideCurrentResizer(); void showCurrentResizer(); signals: void newCommand(ResizeCommand *resize) const; private: ZoomValueProvider *mZoomValueProvider; QHash mItemToResizer; AnnotationItemResizer *mCurrentResizer; AnnotationItemResizer *getResizerForItem(AbstractAnnotationItem *item); void showResizer(AnnotationItemResizer *resizer); void hideResizer(QGraphicsItem *resizer); static AnnotationItemResizer *castToResizer(QGraphicsItem *item) ; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONMULTIITEMRESIZER_H kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/000077500000000000000000000000001414424500400245055ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/AbstractItemResizeHandles.cpp000066400000000000000000000047501414424500400322620ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AbstractItemResizeHandles.h" namespace kImageAnnotator { AbstractItemResizeHandles::AbstractItemResizeHandles() { } int AbstractItemResizeHandles::indexOfHandleAt(const QPointF &pos) const { for (auto handle : mHandles) { if (handle.contains(pos)) { return mHandles.indexOf(handle); } } return -1; } int AbstractItemResizeHandles::indexOfHandleWithAnchorAt(const QPointF &pos) const { for (auto handle : mHandles) { if (handle.anchor() == pos) { return mHandles.indexOf(handle); } } return -1; } ResizeHandle AbstractItemResizeHandles::handle(int index) const { if (index < 0 || index >= mHandles.count()) { return ResizeHandle(); } return mHandles[index]; } QList AbstractItemResizeHandles::handles() const { return mHandles; } Qt::CursorShape AbstractItemResizeHandles::cursorForPos(const QPointF &pos) const { auto index = indexOfHandleAt(pos); return cursorForHandle(index); } Qt::CursorShape AbstractItemResizeHandles::cursorForHandle(int index) const { if (index == -1 || mCursors.isEmpty()) { return CursorHelper::defaultCursor(); } return mCursors[index]; } void AbstractItemResizeHandles::initHandles(int count, double zoomValue) { mHandles.clear(); for (auto i = 0; i < count; i++) { mHandles.append(ResizeHandle(zoomValue)); } } double AbstractItemResizeHandles::handleSize() const { return mHandles.empty() ? 0.0 : mHandles.first().handleSize(); } void AbstractItemResizeHandles::applyZoomValue(double value) { for (auto &handle : mHandles) { handle.applyZoomValue(value); } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/AbstractItemResizeHandles.h000066400000000000000000000036021414424500400317220ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ABSTRACTITEMRESIZEHANDLES_H #define KIMAGEANNOTATOR_ABSTRACTITEMRESIZEHANDLES_H #include "ResizeHandle.h" #include "src/annotations/items/AbstractAnnotationItem.h" #include "src/common/helper/CursorHelper.h" namespace kImageAnnotator { class AbstractItemResizeHandles { public: AbstractItemResizeHandles(); virtual ~AbstractItemResizeHandles() = default; virtual void update() = 0; virtual int indexOfHandleAt(const QPointF &pos) const; virtual int indexOfHandleWithAnchorAt(const QPointF &pos) const; virtual ResizeHandle handle(int index) const; virtual QList handles() const; virtual Qt::CursorShape cursorForPos(const QPointF &pos) const; virtual Qt::CursorShape cursorForHandle(int index) const; double handleSize() const; void applyZoomValue(double value); protected: QList mHandles; QList mCursors; virtual void initHandles(int count, double zoomValue); virtual void initCursors() = 0; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ABSTRACTITEMRESIZEHANDLES_H kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/AbstractRectResizeHandles.cpp000066400000000000000000000060721414424500400322600ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AbstractRectResizeHandles.h" namespace kImageAnnotator { void AbstractRectResizeHandles::update() { auto rect = getRect(); auto offset = getOffset(); mHandles[0].moveCenter(ShapeHelper::rectTopLeftWithOffset(rect, offset)); mHandles[0].setAnchor(rect.topLeft()); mHandles[1].moveCenter(ShapeHelper::rectTopWithOffset(rect, offset)); mHandles[1].setAnchor(ShapeHelper::rectTop(rect)); mHandles[2].moveCenter(ShapeHelper::rectTopRightWithOffset(rect, offset)); mHandles[2].setAnchor(rect.topRight()); mHandles[3].moveCenter(ShapeHelper::rectRightWithOffset(rect, offset)); mHandles[3].setAnchor(ShapeHelper::rectRight(rect)); mHandles[4].moveCenter(ShapeHelper::rectBottomRightWithOffset(rect, offset)); mHandles[4].setAnchor(rect.bottomRight()); mHandles[5].moveCenter(ShapeHelper::rectBottomWithOffset(rect, offset)); mHandles[5].setAnchor(ShapeHelper::rectBottom(rect)); mHandles[6].moveCenter(ShapeHelper::rectBottomLeftWithOffset(rect, offset)); mHandles[6].setAnchor(rect.bottomLeft()); mHandles[7].moveCenter(ShapeHelper::rectLeftWithOffset(rect, offset)); mHandles[7].setAnchor(ShapeHelper::rectLeft(rect)); updateRectCursors(); } void AbstractRectResizeHandles::initCursors() { mCursors.clear(); mCursors.append(CursorHelper::fDiagResizeCursor()); mCursors.append(CursorHelper::verticalResizeCursor()); mCursors.append(CursorHelper::bDiagResizeCursor()); mCursors.append(CursorHelper::horizontalResizeCursor()); mCursors.append(CursorHelper::fDiagResizeCursor()); mCursors.append(CursorHelper::verticalResizeCursor()); mCursors.append(CursorHelper::bDiagResizeCursor()); mCursors.append(CursorHelper::horizontalResizeCursor()); } void AbstractRectResizeHandles::updateRectCursors() { if (mCursors.isEmpty()) { return; } auto rect = getItemBoundingRect(); mCursors[indexOfHandleWithAnchorAt(rect.topLeft())] = CursorHelper::fDiagResizeCursor(); mCursors[indexOfHandleWithAnchorAt(rect.topRight())] = CursorHelper::bDiagResizeCursor(); mCursors[indexOfHandleWithAnchorAt(rect.bottomRight())] = CursorHelper::fDiagResizeCursor(); mCursors[indexOfHandleWithAnchorAt(rect.bottomLeft())] = CursorHelper::bDiagResizeCursor(); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/AbstractRectResizeHandles.h000066400000000000000000000030661414424500400317250ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ABSTRACTRECTRESIZEHANDLES_H #define KIMAGEANNOTATOR_ABSTRACTRECTRESIZEHANDLES_H #include "AbstractItemResizeHandles.h" #include "src/annotations/items/AbstractAnnotationRect.h" #include "src/common/helper/ShapeHelper.h" namespace kImageAnnotator { class AbstractRectResizeHandles : public AbstractItemResizeHandles { public: AbstractRectResizeHandles() = default; ~AbstractRectResizeHandles() override = default; void update() override; protected: void initCursors() override; virtual QRectF getRect() const = 0; virtual double getOffset() const = 0; virtual QRectF getItemBoundingRect() const = 0; private: void updateRectCursors(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ABSTRACTRECTRESIZEHANDLES_H kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/LineResizeHandles.cpp000066400000000000000000000031341414424500400305620ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "LineResizeHandles.h" namespace kImageAnnotator { LineResizeHandles::LineResizeHandles(AbstractAnnotationLine *lineItem, double zoomValue) : mLineItem(lineItem) { initHandles(2, zoomValue); initCursors(); update(); } void LineResizeHandles::update() { auto line = mLineItem->line(); auto offset = mLineItem->properties()->width(); auto outerLine = ShapeHelper::extendLine(line, offset); mHandles[0].moveCenter(QPointF(outerLine.p1().x(), outerLine.p1().y())); mHandles[0].setAnchor(line.p1()); mHandles[1].moveCenter(QPointF(outerLine.p2().x(), outerLine.p2().y())); mHandles[1].setAnchor(line.p2()); } void LineResizeHandles::initCursors() { mCursors.clear(); mCursors.append(CursorHelper::allResizeCursor()); mCursors.append(CursorHelper::allResizeCursor()); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/LineResizeHandles.h000066400000000000000000000026611414424500400302330ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_LINERESIZEHANDLES_H #define KIMAGEANNOTATOR_LINERESIZEHANDLES_H #include "AbstractItemResizeHandles.h" #include "src/annotations/items/AbstractAnnotationLine.h" #include "src/common/helper/ShapeHelper.h" namespace kImageAnnotator { class LineResizeHandles : public AbstractItemResizeHandles { public: LineResizeHandles(AbstractAnnotationLine *lineItem, double zoomValue); ~LineResizeHandles() override = default; void update() override; protected: void initCursors() override; private: AbstractAnnotationLine *mLineItem; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_LINERESIZEHANDLES_H kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/PathResizeHandles.cpp000066400000000000000000000024521414424500400305710ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "PathResizeHandles.h" namespace kImageAnnotator { PathResizeHandles::PathResizeHandles(AbstractAnnotationPath *pathItem, double zoomValue) : mPathItem(pathItem) { initHandles(8, zoomValue); initCursors(); update(); } QRectF PathResizeHandles::getRect() const { return getItemBoundingRect(); } double PathResizeHandles::getOffset() const { return 0.0; } QRectF PathResizeHandles::getItemBoundingRect() const { return mPathItem->boundingRect(); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/PathResizeHandles.h000066400000000000000000000027061414424500400302400ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_PATHRESIZEHANDLES_H #define KIMAGEANNOTATOR_PATHRESIZEHANDLES_H #include "AbstractRectResizeHandles.h" #include "src/annotations/items/AbstractAnnotationPath.h" namespace kImageAnnotator { class PathResizeHandles : public AbstractRectResizeHandles { public: PathResizeHandles(AbstractAnnotationPath *pathItem, double zoomValue); ~PathResizeHandles() override = default; protected: QRectF getRect() const override; double getOffset() const override; QRectF getItemBoundingRect() const override; private: AbstractAnnotationPath *mPathItem; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_PATHRESIZEHANDLES_H kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/PointerRectResizeHandles.cpp000066400000000000000000000027001414424500400321270ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "PointerRectResizeHandles.h" namespace kImageAnnotator { PointerRectResizeHandles::PointerRectResizeHandles(AbstractAnnotationPointerRect *pointerRectItem, double zoomValue) : RectResizeHandles(pointerRectItem, zoomValue), mPointerRectItem(pointerRectItem) { initHandles(9, zoomValue); initCursors(); update(); } void PointerRectResizeHandles::update() { RectResizeHandles::update(); mHandles[8].moveCenter(mPointerRectItem->pointAt(8)); mHandles[8].setAnchor(mPointerRectItem->pointAt(8)); } void PointerRectResizeHandles::initCursors() { RectResizeHandles::initCursors(); mCursors.append(CursorHelper::allResizeCursor()); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/PointerRectResizeHandles.h000066400000000000000000000026461414424500400316050ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_POINTERRECTRESIZEHANDLES_H #define KIMAGEANNOTATOR_POINTERRECTRESIZEHANDLES_H #include "RectResizeHandles.h" #include "src/annotations/items/AbstractAnnotationPointerRect.h" namespace kImageAnnotator { class PointerRectResizeHandles : public RectResizeHandles { public: PointerRectResizeHandles(AbstractAnnotationPointerRect *pointerRectItem, double zoomValue); ~PointerRectResizeHandles() override = default; void update() override; protected: void initCursors() override; private: AbstractAnnotationPointerRect *mPointerRectItem; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_POINTERRECTRESIZEHANDLES_H kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/RectResizeHandles.cpp000066400000000000000000000024741414424500400305760ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "RectResizeHandles.h" namespace kImageAnnotator { RectResizeHandles::RectResizeHandles(AbstractAnnotationRect *rectItem, double zoomValue) : mRectItem(rectItem) { initHandles(8, zoomValue); initCursors(); update(); } QRectF RectResizeHandles::getRect() const { return mRectItem->rect(); } double RectResizeHandles::getOffset() const { return 0.5 * mRectItem->properties()->width(); } QRectF RectResizeHandles::getItemBoundingRect() const { return mRectItem->rect().normalized(); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/RectResizeHandles.h000066400000000000000000000027061414424500400302410ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_RECTRESIZEHANDLES_H #define KIMAGEANNOTATOR_RECTRESIZEHANDLES_H #include "AbstractRectResizeHandles.h" #include "src/annotations/items/AbstractAnnotationRect.h" namespace kImageAnnotator { class RectResizeHandles : public AbstractRectResizeHandles { public: RectResizeHandles(AbstractAnnotationRect *rectItem, double zoomValue); ~RectResizeHandles() override = default; protected: QRectF getRect() const override; double getOffset() const override; QRectF getItemBoundingRect() const override; private: AbstractAnnotationRect *mRectItem; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_RECTRESIZEHANDLES_H kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/ResizeHandle.cpp000066400000000000000000000026771414424500400276020ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ResizeHandle.h" namespace kImageAnnotator { double ResizeHandle::mDefaultHandleSize = 10.0; ResizeHandle::ResizeHandle(double zoomValue) : QRectF(0, 0, mDefaultHandleSize / zoomValue, mDefaultHandleSize / zoomValue) { } QPointF ResizeHandle::anchor() const { return center() + mOffset; } void ResizeHandle::setAnchor(const QPointF &pos) { mOffset = pos - center(); } void ResizeHandle::applyZoomValue(double value) { const auto offset = 0.5 * (handleSize() - mDefaultHandleSize / value); adjust(offset, offset, -offset, -offset); } double ResizeHandle::handleSize() const { return width(); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/ResizeHandle.h000066400000000000000000000024521414424500400272360ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_RESIZEHANDLE_H #define KIMAGEANNOTATOR_RESIZEHANDLE_H #include namespace kImageAnnotator { class ResizeHandle : public QRectF { public: explicit ResizeHandle(double zoomValue = 1.0); ~ResizeHandle() = default; QPointF anchor() const; void setAnchor(const QPointF &pos); void applyZoomValue(double value); double handleSize() const; private: static double mDefaultHandleSize; QPointF mOffset; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_RESIZEHANDLE_H kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/ResizeHandlesFactory.cpp000066400000000000000000000052441414424500400313060ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ResizeHandlesFactory.h" namespace kImageAnnotator { AbstractItemResizeHandles *ResizeHandlesFactory::createResizeHandles(AbstractAnnotationItem *item, double zoomValue) { auto resizeHandles = GetLineResizeHandles(item, zoomValue); if (resizeHandles != nullptr) { return resizeHandles; } resizeHandles = GetPointerRectResizeHandles(item, zoomValue); if (resizeHandles != nullptr) { return resizeHandles; } resizeHandles = GetRectResizeHandles(item, zoomValue); if (resizeHandles != nullptr) { return resizeHandles; } resizeHandles = GetPathResizeHandles(item, zoomValue); return resizeHandles; } AbstractItemResizeHandles *ResizeHandlesFactory::GetLineResizeHandles(AbstractAnnotationItem *item, double zoomValue) { auto lineItem = dynamic_cast(item); if (lineItem != nullptr) { return new LineResizeHandles(lineItem, zoomValue); } return nullptr; } AbstractItemResizeHandles *ResizeHandlesFactory::GetRectResizeHandles(AbstractAnnotationItem *item, double zoomValue) { auto rectItem = dynamic_cast(item); if (rectItem != nullptr) { return new RectResizeHandles(rectItem, zoomValue); } return nullptr; } AbstractItemResizeHandles *ResizeHandlesFactory::GetPointerRectResizeHandles(AbstractAnnotationItem *item, double zoomValue) { auto rectItem = dynamic_cast(item); if (rectItem != nullptr) { return new PointerRectResizeHandles(rectItem, zoomValue); } return nullptr; } AbstractItemResizeHandles *ResizeHandlesFactory::GetPathResizeHandles(AbstractAnnotationItem *item, double zoomValue) { auto pathItem = dynamic_cast(item); if (pathItem != nullptr) { return new PathResizeHandles(pathItem, zoomValue); } return nullptr; } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/modifiers/resizeHandles/ResizeHandlesFactory.h000066400000000000000000000033131414424500400307460ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_RESIZEHANDLESFACTORY_H #define KIMAGEANNOTATOR_RESIZEHANDLESFACTORY_H #include "LineResizeHandles.h" #include "RectResizeHandles.h" #include "PathResizeHandles.h" #include "PointerRectResizeHandles.h" namespace kImageAnnotator { class ResizeHandlesFactory { public: static AbstractItemResizeHandles *createResizeHandles(AbstractAnnotationItem *item, double zoomValue); private: static AbstractItemResizeHandles *GetPathResizeHandles(AbstractAnnotationItem *item, double zoomValue); static AbstractItemResizeHandles *GetRectResizeHandles(AbstractAnnotationItem *item, double zoomValue); static AbstractItemResizeHandles *GetLineResizeHandles(AbstractAnnotationItem *item, double zoomValue); static AbstractItemResizeHandles *GetPointerRectResizeHandles(AbstractAnnotationItem *item, double zoomValue); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_RESIZEHANDLESFACTORY_H kImageAnnotator-0.5.3/src/annotations/properties/000077500000000000000000000000001414424500400221205ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/annotations/properties/AnnotationObfuscateProperties.cpp000066400000000000000000000025341414424500400306530ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationObfuscateProperties.h" namespace kImageAnnotator { AnnotationObfuscateProperties::AnnotationObfuscateProperties(const AnnotationObfuscateProperties &other) : AnnotationProperties(other), mFactor(1) { mFactor = other.mFactor; } PropertiesPtr AnnotationObfuscateProperties::clone() const { return PropertiesPtr(new AnnotationObfuscateProperties(*this)); } int AnnotationObfuscateProperties::factor() const { return mFactor; } void AnnotationObfuscateProperties::setFactor(int factor) { mFactor = factor; } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/properties/AnnotationObfuscateProperties.h000066400000000000000000000030231414424500400303120ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONOBFUSCATEPROPERTIES_H #define KIMAGEANNOTATOR_ANNOTATIONOBFUSCATEPROPERTIES_H #include "AnnotationProperties.h" namespace kImageAnnotator { class AnnotationObfuscateProperties; typedef QSharedPointer ObfuscatePropertiesPtr; class AnnotationObfuscateProperties : public AnnotationProperties { public: AnnotationObfuscateProperties() = default; AnnotationObfuscateProperties(const AnnotationObfuscateProperties &other); ~AnnotationObfuscateProperties() override = default; PropertiesPtr clone() const override; int factor() const; void setFactor(int factor); private: int mFactor; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONOBFUSCATEPROPERTIES_H kImageAnnotator-0.5.3/src/annotations/properties/AnnotationPathProperties.cpp000066400000000000000000000032141414424500400276300ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationPathProperties.h" namespace kImageAnnotator { AnnotationPathProperties::AnnotationPathProperties(const QColor &color, int size) : AnnotationProperties(color, size) { } AnnotationPathProperties::AnnotationPathProperties(const PathPropertiesPtr &other) : AnnotationProperties(other) { mSmootPathEnabled = other->mSmootPathEnabled; mSmootFactor = other->mSmootFactor; } PropertiesPtr AnnotationPathProperties::clone() const { return PropertiesPtr(new AnnotationPathProperties(*this)); } bool AnnotationPathProperties::smoothPathEnabled() const { return mSmootPathEnabled; } void AnnotationPathProperties::setSmoothPathEnabled(bool enabled) { mSmootPathEnabled = enabled; } int AnnotationPathProperties::smoothFactor() const { return mSmootFactor; } void AnnotationPathProperties::setSmoothFactor(int factor) { mSmootFactor = factor; } } kImageAnnotator-0.5.3/src/annotations/properties/AnnotationPathProperties.h000066400000000000000000000032151414424500400272760ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONPATHPROPERTIES_H #define KIMAGEANNOTATOR_ANNOTATIONPATHPROPERTIES_H #include "AnnotationProperties.h" namespace kImageAnnotator { class AnnotationPathProperties; typedef QSharedPointer PathPropertiesPtr; class AnnotationPathProperties : public AnnotationProperties { public: AnnotationPathProperties() = default; AnnotationPathProperties(const QColor &color, int size); explicit AnnotationPathProperties(const PathPropertiesPtr &other); ~AnnotationPathProperties() override = default; PropertiesPtr clone() const override; bool smoothPathEnabled() const; void setSmoothPathEnabled(bool enabled); int smoothFactor() const; void setSmoothFactor(int factor); private: bool mSmootPathEnabled; int mSmootFactor; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONPATHPROPERTIES_H kImageAnnotator-0.5.3/src/annotations/properties/AnnotationProperties.cpp000066400000000000000000000041441414424500400270160ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationProperties.h" namespace kImageAnnotator { AnnotationProperties::AnnotationProperties(const QColor &color, int size) { mColor = color; mTextColor = color; mWidth = size; } AnnotationProperties::AnnotationProperties(const PropertiesPtr &other) { mColor = other->mColor; mTextColor = other->mTextColor; mWidth = other->mWidth; mFillType = other->mFillType; mShadowEnabled = other->mShadowEnabled; } QColor AnnotationProperties::color() const { return mColor; } void AnnotationProperties::setColor(const QColor &color) { mColor = qMove(color); } QColor AnnotationProperties::textColor() const { return mTextColor; } void AnnotationProperties::setTextColor(const QColor &color) { mTextColor = qMove(color); } int AnnotationProperties::width() const { return mWidth; } void AnnotationProperties::setWidth(int size) { mWidth = size; } FillModes AnnotationProperties::fillType() const { return mFillType; } void AnnotationProperties::setFillType(FillModes fillType) { mFillType = fillType; } bool AnnotationProperties::shadowEnabled() const { return mShadowEnabled; } void AnnotationProperties::setShadowEnabled(bool enabled) { mShadowEnabled = enabled; } PropertiesPtr AnnotationProperties::clone() const { return PropertiesPtr(new AnnotationProperties(*this)); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/properties/AnnotationProperties.h000066400000000000000000000035151414424500400264640ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONPROPERTIES_H #define KIMAGEANNOTATOR_ANNOTATIONPROPERTIES_H #include #include #include "src/common/enum/FillModes.h" namespace kImageAnnotator { class AnnotationProperties; typedef QSharedPointer PropertiesPtr; class AnnotationProperties { public: AnnotationProperties() = default; AnnotationProperties(const QColor &color, int size); explicit AnnotationProperties(const PropertiesPtr &other); virtual ~AnnotationProperties() = default; QColor color() const; void setColor(const QColor &color); QColor textColor() const; void setTextColor(const QColor &color); int width() const; void setWidth(int size); FillModes fillType() const; void setFillType(FillModes fillType); bool shadowEnabled() const; void setShadowEnabled(bool enabled); virtual PropertiesPtr clone() const; private: QColor mColor; QColor mTextColor; int mWidth; FillModes mFillType; bool mShadowEnabled; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONPROPERTIES_H kImageAnnotator-0.5.3/src/annotations/properties/AnnotationStickerProperties.cpp000066400000000000000000000025301414424500400303400ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationStickerProperties.h" namespace kImageAnnotator { AnnotationStickerProperties::AnnotationStickerProperties(const kImageAnnotator::AnnotationStickerProperties &other) : AnnotationProperties(other) { this->mPath = other.mPath; } PropertiesPtr kImageAnnotator::AnnotationStickerProperties::clone() const { return PropertiesPtr(new AnnotationStickerProperties(*this)); } QString AnnotationStickerProperties::path() const { return mPath; } void AnnotationStickerProperties::setPath(const QString &path) { mPath = path; } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/properties/AnnotationStickerProperties.h000066400000000000000000000027271414424500400300150ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONSTICKERPROPERTIES_H #define KIMAGEANNOTATOR_ANNOTATIONSTICKERPROPERTIES_H #include "AnnotationProperties.h" namespace kImageAnnotator { class AnnotationStickerProperties : public AnnotationProperties { public: AnnotationStickerProperties() = default; AnnotationStickerProperties(const AnnotationStickerProperties &other); ~AnnotationStickerProperties() override = default; PropertiesPtr clone() const override; QString path() const; void setPath(const QString &path); private: QString mPath; }; typedef QSharedPointer StickerPropertiesPtr; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONSTICKERPROPERTIES_H kImageAnnotator-0.5.3/src/annotations/properties/AnnotationTextProperties.cpp000066400000000000000000000026001414424500400276560ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationTextProperties.h" namespace kImageAnnotator { AnnotationTextProperties::AnnotationTextProperties(const QColor &color, int size) : AnnotationProperties(color, size) { } AnnotationTextProperties::AnnotationTextProperties(const AnnotationTextProperties &other) : AnnotationProperties(other) { mFont = other.mFont; } PropertiesPtr AnnotationTextProperties::clone() const { return PropertiesPtr(new AnnotationTextProperties(*this)); } QFont AnnotationTextProperties::font() const { return mFont; } void AnnotationTextProperties::setFont(const QFont &font) { mFont = font; } }kImageAnnotator-0.5.3/src/annotations/properties/AnnotationTextProperties.h000066400000000000000000000030561414424500400273310ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONTEXTPROPERTIES_H #define KIMAGEANNOTATOR_ANNOTATIONTEXTPROPERTIES_H #include #include "AnnotationProperties.h" namespace kImageAnnotator { class AnnotationTextProperties; typedef QSharedPointer TextPropertiesPtr; class AnnotationTextProperties : public AnnotationProperties { public: AnnotationTextProperties() = default; AnnotationTextProperties(const QColor &color, int size); AnnotationTextProperties(const AnnotationTextProperties &other); ~AnnotationTextProperties() override = default; PropertiesPtr clone() const override; QFont font() const; void setFont(const QFont &font); private: QFont mFont; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONTEXTPROPERTIES_H kImageAnnotator-0.5.3/src/annotations/undo/000077500000000000000000000000001414424500400206715ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/annotations/undo/AddCommand.cpp000066400000000000000000000023161414424500400233660ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AddCommand.h" namespace kImageAnnotator { AddCommand::AddCommand(AbstractAnnotationItem *item, AnnotationArea *annotationArea) { mItem = item; mAnnotationArea = annotationArea; } void AddCommand::undo() { mAnnotationArea->removeAnnotationItem(mItem); mItem->hide(); } void AddCommand::redo() { mAnnotationArea->addAnnotationItem(mItem); mItem->show(); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/undo/AddCommand.h000066400000000000000000000026461414424500400230410ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ADDCOMMAND_H #define KIMAGEANNOTATOR_ADDCOMMAND_H #include #include "src/annotations/items/AbstractAnnotationItem.h" #include "src/annotations/core/AnnotationArea.h" namespace kImageAnnotator { class AnnotationArea; class AddCommand : public QUndoCommand { public: AddCommand(AbstractAnnotationItem *item, AnnotationArea *annotationArea); ~AddCommand() = default; virtual void undo() override; virtual void redo() override; private: AbstractAnnotationItem *mItem; AnnotationArea *mAnnotationArea; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ADDCOMMAND_H kImageAnnotator-0.5.3/src/annotations/undo/ArrangeCommand.cpp000066400000000000000000000032751414424500400242620ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ArrangeCommand.h" namespace kImageAnnotator { ArrangeCommand::ArrangeCommand(QList> itemToSwap, QList *allItems) { mItemToSwap = itemToSwap; mAllItems = allItems; } void ArrangeCommand::undo() { for (auto i = mItemToSwap.count() - 1; i >= 0; i--) { auto pair = mItemToSwap[i]; swapZValues(pair.first, pair.second); } ItemHelper::sortItemsByZValueDesc(mAllItems); } void ArrangeCommand::redo() { for (auto pair : mItemToSwap) { swapZValues(pair.first, pair.second); } ItemHelper::sortItemsByZValueDesc(mAllItems); } void ArrangeCommand::swapZValues(AbstractAnnotationItem *item1, AbstractAnnotationItem *item2) const { auto tmpZValue = item1->zValue(); item1->setZValue(item2->zValue()); item2->setZValue(tmpZValue); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/undo/ArrangeCommand.h000066400000000000000000000031161414424500400237210ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ARRANGECOMMAND_H #define KIMAGEANNOTATOR_ARRANGECOMMAND_H #include #include "src/annotations/items/AbstractAnnotationItem.h" #include "src/common/helper/ItemHelper.h" namespace kImageAnnotator { class ArrangeCommand : public QUndoCommand { public: ArrangeCommand(QList> itemToSwap, QList *allItems); virtual void undo() override; virtual void redo() override; private: QList> mItemToSwap; QList *mAllItems; void swapZValues(AbstractAnnotationItem *item1, AbstractAnnotationItem *item2) const; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ARRANGECOMMAND_H kImageAnnotator-0.5.3/src/annotations/undo/ChangePropertiesCommand.cpp000066400000000000000000000023621414424500400261410ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ChangePropertiesCommand.h" namespace kImageAnnotator { ChangePropertiesCommand::ChangePropertiesCommand(AbstractAnnotationItem *item, const PropertiesPtr &properties) { mItem = item; mNewProperties = properties; mOldProperties = mItem->properties(); } void ChangePropertiesCommand::undo() { mItem->setProperties(mOldProperties); } void ChangePropertiesCommand::redo() { mItem->setProperties(mNewProperties); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/undo/ChangePropertiesCommand.h000066400000000000000000000027561414424500400256150ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CHANGEPROPERTIESCOMMAND_H #define KIMAGEANNOTATOR_CHANGEPROPERTIESCOMMAND_H #include #include "src/annotations/items/AbstractAnnotationItem.h" #include "src/annotations/properties/AnnotationProperties.h" namespace kImageAnnotator { class ChangePropertiesCommand : public QUndoCommand { public: ChangePropertiesCommand(AbstractAnnotationItem *item, const PropertiesPtr &properties); ~ChangePropertiesCommand() override = default; void undo() override; void redo() override; private: AbstractAnnotationItem *mItem; PropertiesPtr mNewProperties; PropertiesPtr mOldProperties; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_CHANGEPROPERTIESCOMMAND_H kImageAnnotator-0.5.3/src/annotations/undo/CropCommand.cpp000066400000000000000000000036251414424500400236050ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "CropCommand.h" namespace kImageAnnotator { CropCommand::CropCommand(QGraphicsPixmapItem *backgroundImage, const QRectF &cropRect, AnnotationArea *annotationArea) { mAnnotationArea = annotationArea; mBackgroundImage = backgroundImage; mOriginalImage = QPixmap(backgroundImage->pixmap()); mCroppedImage = QPixmap(backgroundImage->pixmap().copy(cropRect.toRect())); mNewItemOffset = cropRect.topLeft(); } void CropCommand::undo() { for (auto item : mAnnotationArea->items()) { auto baseItem = dynamic_cast(item); if (baseItem != nullptr) { baseItem->setPosition(baseItem->position() + mNewItemOffset); } } mBackgroundImage->setPixmap(mOriginalImage); mAnnotationArea->setSceneRect(mBackgroundImage->boundingRect()); } void CropCommand::redo() { for (auto item : mAnnotationArea->items()) { auto baseItem = dynamic_cast(item); if (baseItem != nullptr) { baseItem->setPosition(baseItem->position() - mNewItemOffset); } } mBackgroundImage->setPixmap(mCroppedImage); mAnnotationArea->setSceneRect(mBackgroundImage->boundingRect()); } } kImageAnnotator-0.5.3/src/annotations/undo/CropCommand.h000066400000000000000000000026271414424500400232530ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CROPCOMMAND_H #define KIMAGEANNOTATOR_CROPCOMMAND_H #include #include "src/annotations/core/AnnotationArea.h" namespace kImageAnnotator { class CropCommand : public QUndoCommand { public: CropCommand(QGraphicsPixmapItem *backgroundImage, const QRectF &cropRect, AnnotationArea *annotationArea); ~CropCommand() override = default; void undo() override; void redo() override; private: AnnotationArea *mAnnotationArea; QPixmap mOriginalImage; QPixmap mCroppedImage; QGraphicsPixmapItem *mBackgroundImage; QPointF mNewItemOffset; }; } #endif //KIMAGEANNOTATOR_CROPCOMMAND_H kImageAnnotator-0.5.3/src/annotations/undo/DeleteCommand.cpp000066400000000000000000000024761414424500400241070ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "DeleteCommand.h" namespace kImageAnnotator { DeleteCommand::DeleteCommand(QList items, AnnotationArea *annotationArea) { mItems = items; mAnnotationArea = annotationArea; } void DeleteCommand::undo() { for (auto item : mItems) { mAnnotationArea->addAnnotationItem(item); item->show(); } } void DeleteCommand::redo() { for (auto item : mItems) { mAnnotationArea->removeAnnotationItem(item); item->hide(); } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/undo/DeleteCommand.h000066400000000000000000000026521414424500400235500ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_DELETECOMMAND_H #define KIMAGEANNOTATOR_DELETECOMMAND_H #include #include "src/annotations/items/AbstractAnnotationItem.h" #include "src/annotations/core/AnnotationArea.h" namespace kImageAnnotator { class AnnotationArea; class DeleteCommand : public QUndoCommand { public: DeleteCommand(QList items, AnnotationArea *annotationArea); virtual void undo() override; virtual void redo() override; private: QList mItems; AnnotationArea *mAnnotationArea; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_DELETECOMMAND_H kImageAnnotator-0.5.3/src/annotations/undo/FlipCommand.cpp000066400000000000000000000030711414424500400235670ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "FlipCommand.h" namespace kImageAnnotator { FlipCommand::FlipCommand(QGraphicsPixmapItem *backgroundImage, FlipDirection direction) : mBackgroundImage(backgroundImage), mOldPixmap(backgroundImage->pixmap()) { mNewPixmap = flipPixmap(mOldPixmap, direction); } void FlipCommand::undo() { mBackgroundImage->setPixmap(mOldPixmap); } void FlipCommand::redo() { mBackgroundImage->setPixmap(mNewPixmap); } QPixmap FlipCommand::flipPixmap(const QPixmap &sourcePixmap, FlipDirection direction) { auto flipHorizontal = direction == FlipDirection::Horizontal; auto flipVertical = direction == FlipDirection::Vertical; auto flippedImage = sourcePixmap.toImage().mirrored(flipHorizontal, flipVertical); return QPixmap::fromImage(flippedImage); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/undo/FlipCommand.h000066400000000000000000000026771414424500400232470ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_FLIPCOMMAND_H #define KIMAGEANNOTATOR_FLIPCOMMAND_H #include #include #include "src/common/enum/FlipDirection.h" namespace kImageAnnotator { class FlipCommand : public QUndoCommand { public: FlipCommand(QGraphicsPixmapItem *backgroundImage, FlipDirection direction); ~FlipCommand() override = default; void undo() override; void redo() override; private: QGraphicsPixmapItem *mBackgroundImage; QPixmap mOldPixmap; QPixmap mNewPixmap; static QPixmap flipPixmap(const QPixmap &sourcePixmap, FlipDirection direction); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_FLIPCOMMAND_H kImageAnnotator-0.5.3/src/annotations/undo/ModifyCanvasCommand.cpp000066400000000000000000000031171414424500400252610ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ModifyCanvasCommand.h" namespace kImageAnnotator { ModifyCanvasCommand::ModifyCanvasCommand(const QRectF &canvasRect, const QColor &color, AnnotationArea *annotationArea) : mAnnotationArea(annotationArea), mNewCanvasColor(color), mOriginalCanvasColor(annotationArea->canvasColor()) { mOriginalCanvasRect = mAnnotationArea->isCustomCanvasRect() ? annotationArea->canvasRect() : QRectF(); mNewCanvasRect = canvasRect == annotationArea->canvasRect() ? QRectF() : canvasRect; } void ModifyCanvasCommand::undo() { mAnnotationArea->setCanvasRect(mOriginalCanvasRect); mAnnotationArea->setCanvasColor(mOriginalCanvasColor); } void ModifyCanvasCommand::redo() { mAnnotationArea->setCanvasRect(mNewCanvasRect); mAnnotationArea->setCanvasColor(mNewCanvasColor); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/undo/ModifyCanvasCommand.h000066400000000000000000000027301414424500400247260ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_MODIFYCANVASCOMMAND_H #define KIMAGEANNOTATOR_MODIFYCANVASCOMMAND_H #include #include "src/annotations/core/AnnotationArea.h" namespace kImageAnnotator { class ModifyCanvasCommand : public QUndoCommand { public: explicit ModifyCanvasCommand(const QRectF &canvasRect, const QColor &color, AnnotationArea *annotationArea); ~ModifyCanvasCommand() override = default; void undo() override; void redo() override; private: AnnotationArea *mAnnotationArea; QRectF mNewCanvasRect; QRectF mOriginalCanvasRect; QColor mNewCanvasColor; QColor mOriginalCanvasColor; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_MODIFYCANVASCOMMAND_H kImageAnnotator-0.5.3/src/annotations/undo/MoveCommand.cpp000066400000000000000000000033311414424500400236020ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "MoveCommand.h" namespace kImageAnnotator { MoveCommand::MoveCommand(QHash itemToNewPos) { mNewPos = itemToNewPos; for (auto item : itemToNewPos.keys()) { mOriginalPos[item] = item->position(); } } void MoveCommand::undo() { moveItems(mOriginalPos); } void MoveCommand::redo() { moveItems(mNewPos); } bool MoveCommand::mergeWith(const QUndoCommand *command) { const auto moveCommand = dynamic_cast(command); auto mergedNewPos = moveCommand->mNewPos; if (mNewPos.keys() != mergedNewPos.keys()) { return false; } mNewPos = mergedNewPos; return true; } int MoveCommand::id() const { return Id; } void MoveCommand::moveItems(QHash &itemToPos) const { for (auto item : itemToPos.keys()) { item->setPosition(itemToPos[item]); } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/undo/MoveCommand.h000066400000000000000000000031571414424500400232550ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_MOVECOMMAND_H #define KIMAGEANNOTATOR_MOVECOMMAND_H #include #include "src/annotations/items/AbstractAnnotationItem.h" namespace kImageAnnotator { class MoveCommand : public QUndoCommand { public: enum { Id = 1234 }; explicit MoveCommand(QHash itemToNewPos); ~MoveCommand() = default; virtual void undo() override; virtual void redo() override; virtual bool mergeWith(const QUndoCommand *command) override; virtual int id() const override; private: QHash mOriginalPos; QHash mNewPos; void moveItems(QHash &itemToPos) const; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_MOVECOMMAND_H kImageAnnotator-0.5.3/src/annotations/undo/PasteCommand.cpp000066400000000000000000000035011414424500400237470ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "PasteCommand.h" namespace kImageAnnotator { PasteCommand::PasteCommand(const QHash &itemsWithOffset, const QPointF &position, AnnotationItemFactory *itemFactory, kImageAnnotator::AnnotationArea *annotationArea) { Q_ASSERT(annotationArea != nullptr); Q_ASSERT(itemFactory != nullptr); mAnnotationArea = annotationArea; mItemFactory = itemFactory; for (auto item : itemsWithOffset.keys()) { auto pastedItem = itemFactory->clone(item); pastedItem->setPosition(position + itemsWithOffset[item]); mPastedItems.append(pastedItem); } } PasteCommand::~PasteCommand() { // Deleting with the annotation area } void PasteCommand::undo() { for (auto item : mPastedItems) { mAnnotationArea->removeAnnotationItem(item); item->hide(); } } void PasteCommand::redo() { for (auto item : mPastedItems) { mAnnotationArea->addAnnotationItem(item); item->show(); } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/undo/PasteCommand.h000066400000000000000000000027131414424500400234200ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_PASTECOMMAND_H #define KIMAGEANNOTATOR_PASTECOMMAND_H #include #include "src/annotations/core/AnnotationArea.h" namespace kImageAnnotator { class PasteCommand : public QUndoCommand { public: PasteCommand(const QHash &itemsWithOffset, const QPointF &position, AnnotationItemFactory *itemFactory, AnnotationArea *annotationArea); ~PasteCommand(); void undo() override; void redo() override; private: AnnotationArea *mAnnotationArea; AnnotationItemFactory *mItemFactory; QVector mPastedItems; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_PASTECOMMAND_H kImageAnnotator-0.5.3/src/annotations/undo/ResizeCommand.cpp000066400000000000000000000032701414424500400241370ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ResizeCommand.h" namespace kImageAnnotator { ResizeCommand::ResizeCommand(AbstractAnnotationItem *item, int handleIndex, QPointF newPos, bool keepAspectRatio) { mItem = item; mHandleIndex = handleIndex; mNewPos = newPos; mOriginalPos = item->pointAt(handleIndex); mKeepAspectRatio = keepAspectRatio; } void ResizeCommand::undo() { mItem->setPointAt(mOriginalPos, mHandleIndex, false); } void ResizeCommand::redo() { mItem->setPointAt(mNewPos, mHandleIndex, mKeepAspectRatio); } bool ResizeCommand::mergeWith(const QUndoCommand *command) { const auto resizeCommand = dynamic_cast(command); if (mItem != resizeCommand->mItem || mHandleIndex != resizeCommand->mHandleIndex) { return false; } mNewPos = resizeCommand->mNewPos; return true; } int ResizeCommand::id() const { return Id; } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/undo/ResizeCommand.h000066400000000000000000000031301414424500400235770ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_RESIZECOMMAND_H #define KIMAGEANNOTATOR_RESIZECOMMAND_H #include #include "src/annotations/items/AbstractAnnotationItem.h" namespace kImageAnnotator { class ResizeCommand : public QUndoCommand { public: enum { Id = 1235 }; explicit ResizeCommand(AbstractAnnotationItem *item, int handleIndex, QPointF newPos, bool keepAspectRatio); ~ResizeCommand() = default; virtual void undo() override; virtual void redo() override; virtual bool mergeWith(const QUndoCommand *command) override; virtual int id() const override; private: AbstractAnnotationItem *mItem; int mHandleIndex; QPointF mNewPos; QPointF mOriginalPos; bool mKeepAspectRatio; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_RESIZECOMMAND_H kImageAnnotator-0.5.3/src/annotations/undo/RotateCommand.cpp000066400000000000000000000036241414424500400241370ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "RotateCommand.h" namespace kImageAnnotator { RotateCommand::RotateCommand(QGraphicsPixmapItem *backgroundImage, qreal angel, AnnotationArea *annotationArea) : mBackgroundImage(backgroundImage), mAnnotationArea(annotationArea), mOldPixmap(mBackgroundImage->pixmap()) { mNewPixmap = rotatePixmap(mOldPixmap, angel); } void RotateCommand::undo() { mBackgroundImage->setPixmap(mOldPixmap); mAnnotationArea->setSceneRect(mBackgroundImage->boundingRect()); } void RotateCommand::redo() { mBackgroundImage->setPixmap(mNewPixmap); mAnnotationArea->setSceneRect(mBackgroundImage->boundingRect()); } QPixmap RotateCommand::rotatePixmap(const QPixmap &sourcePixmap, qreal angel) { auto center = sourcePixmap.rect().center(); QTransform transform; transform.translate(center.x(), center.y()); transform.rotate(angel); transform.translate(-center.x(), -center.y()); auto rotatedPixmap = sourcePixmap.transformed(transform, Qt::SmoothTransformation); auto nonTransparentContentRect = QRegion(rotatedPixmap.mask()).boundingRect(); return rotatedPixmap.copy(nonTransparentContentRect); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/undo/RotateCommand.h000066400000000000000000000027611414424500400236050ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ROTATECOMMAND_H #define KIMAGEANNOTATOR_ROTATECOMMAND_H #include #include #include "src/annotations/core/AnnotationArea.h" namespace kImageAnnotator { class RotateCommand : public QUndoCommand { public: RotateCommand(QGraphicsPixmapItem *backgroundImage, qreal angel, AnnotationArea *annotationArea); ~RotateCommand() override = default; void undo() override; void redo() override; private: QGraphicsPixmapItem *mBackgroundImage; AnnotationArea *mAnnotationArea; QPixmap mOldPixmap; QPixmap mNewPixmap; static QPixmap rotatePixmap(const QPixmap &sourcePixmap, qreal angel); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ROTATECOMMAND_H kImageAnnotator-0.5.3/src/annotations/undo/ScaleCommand.cpp000066400000000000000000000043621414424500400237300ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ScaleCommand.h" namespace kImageAnnotator { kImageAnnotator::ScaleCommand::ScaleCommand(QGraphicsPixmapItem *backgroundImage, const QSize &newSize, kImageAnnotator::AnnotationArea *annotationArea) { mAnnotationArea = annotationArea; mBackgroundImage = backgroundImage; auto currentSize = backgroundImage->boundingRect().size(); mWidthScaleFactor = (qreal) newSize.width() / currentSize.width(); mHeightScaleFactor = (qreal) newSize.height() / currentSize.height(); mOldImage = new QPixmap(backgroundImage->pixmap()); mNewImage = new QPixmap(mOldImage->scaled(newSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); } ScaleCommand::~ScaleCommand() { delete mOldImage; delete mNewImage; } void ScaleCommand::undo() { scaleItems(1 / mWidthScaleFactor, 1 / mHeightScaleFactor); mBackgroundImage->resetTransform(); mBackgroundImage->setPixmap(*mOldImage); mAnnotationArea->setSceneRect(mBackgroundImage->boundingRect()); } void ScaleCommand::redo() { scaleItems(mWidthScaleFactor, mHeightScaleFactor); mBackgroundImage->resetTransform(); mBackgroundImage->setPixmap(*mNewImage); mAnnotationArea->setSceneRect(mBackgroundImage->boundingRect()); } void ScaleCommand::scaleItems(qreal widthScaleFactor, qreal heightScaleFactor) { for (auto base : mAnnotationArea->items()) { auto item = dynamic_cast(base); if (item != nullptr) { item->scale(widthScaleFactor, heightScaleFactor); } } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/annotations/undo/ScaleCommand.h000066400000000000000000000027761414424500400234040ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SCALECOMMAND_H #define KIMAGEANNOTATOR_SCALECOMMAND_H #include #include "src/annotations/core/AnnotationArea.h" namespace kImageAnnotator { class ScaleCommand : public QUndoCommand { public: ScaleCommand(QGraphicsPixmapItem *backgroundImage, const QSize &newSize, AnnotationArea *annotationArea); ~ScaleCommand(); void undo() override; void redo() override; private: AnnotationArea *mAnnotationArea; QGraphicsPixmapItem *mBackgroundImage; QPixmap *mOldImage; QPixmap *mNewImage; qreal mWidthScaleFactor; qreal mHeightScaleFactor; void scaleItems(qreal widthScaleFactor, qreal heightScaleFactor); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_SCALECOMMAND_H kImageAnnotator-0.5.3/src/annotations/undo/UndoStack.cpp000066400000000000000000000015711414424500400232740ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "UndoStack.h" namespace kImageAnnotator { } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/annotations/undo/UndoStack.h000066400000000000000000000022271414424500400227400ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_UNDOSTACK_H #define KIMAGEANNOTATOR_UNDOSTACK_H #include #include "AddCommand.h" #include "DeleteCommand.h" namespace kImageAnnotator { class UndoStack : public QUndoStack { public: explicit UndoStack() = default; ~UndoStack() override = default; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_UNDOSTACK_H kImageAnnotator-0.5.3/src/backend/000077500000000000000000000000001414424500400167565ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/backend/Config.cpp000066400000000000000000000313441414424500400206740ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include "Config.h" namespace kImageAnnotator { Config::Config() : mSelectTool(Tools::Pen), mSmoothPathEnabled(false), mSaveToolSelection(false), mSmoothFactor(0), mSwitchToSelectToolAfterDrawingItem(true), mSelectItemAfterDrawing(true), mNumberUpdateMode(NumberUpdateMode::UpdateOnlyNewNumbers) { mAllTools = QList{ Tools::Pen, Tools::MarkerPen, Tools::MarkerRect, Tools::MarkerEllipse, Tools::Line, Tools::Arrow, Tools::DoubleArrow, Tools::Rect, Tools::Ellipse, Tools::Number, Tools::NumberPointer, Tools::NumberArrow, Tools::Text, Tools::TextPointer, Tools::TextArrow, Tools::Blur, Tools::Pixelate, Tools::Image, Tools::Sticker, Tools::Duplicate }; initGeneralSettings(); initToolSettings(); } Tools Config::selectedTool() const { return mSelectTool; } void Config::setSelectedToolType(Tools tool) { if (selectedTool() == tool) { return; } mSelectTool = tool; saveToolType(tool); } QColor Config::toolColor(Tools tool) const { return mToolToColor[tool]; } void Config::setToolColor(const QColor &color, Tools tool) { if (toolColor(tool) == color) { return; } mToolToColor[tool] = color; saveToolColor(tool, color); } QColor Config::toolTextColor(Tools tool) const { return mToolToTextColor[tool]; } void Config::setToolTextColor(const QColor &color, Tools tool) { if (toolTextColor(tool) == color) { return; } mToolToTextColor[tool] = color; saveToolTextColor(tool, color); } int Config::toolWidth(Tools tool) const { return mToolToWidth[tool]; } void Config::setToolWidth(int width, Tools tool) { if (toolWidth(tool) == width) { return; } mToolToWidth[tool] = width; saveToolWidth(tool, width); } FillModes Config::toolFillType(Tools tool) const { return mToolToFillType[tool]; } void Config::setToolFillType(FillModes fillType, Tools tool) { if (toolFillType(tool) == fillType) { return; } mToolToFillType[tool] = fillType; saveToolFillType(tool, fillType); } QFont Config::toolFont(Tools tool) const { return mToolToFont[tool]; } void Config::setToolFont(const QFont &font, Tools tool) { if (toolFont(tool) == font) { return; } mToolToFont[tool] = font; saveToolFont(tool, font); } bool Config::shadowEnabled(Tools tool) const { return mToolToShadowEnabled[tool]; } void Config::setShadowEnabled(bool enabled, Tools tool) { if (shadowEnabled(tool) == enabled) { return; } mToolToShadowEnabled[tool] = enabled; saveToolShadowEnabled(tool, enabled); } bool Config::smoothPathEnabled() const { return mSmoothPathEnabled; } void Config::setSmoothPathEnabled(bool enabled) { mSmoothPathEnabled = enabled; } void Config::setSaveToolSelection(bool enabled) { if (mSaveToolSelection == enabled) { return; } mSaveToolSelection = enabled; initToolSettings(); } int Config::smoothFactor() const { return mSmoothFactor; } void Config::setSmoothFactor(int factor) { mSmoothFactor = factor; } bool Config::switchToSelectToolAfterDrawingItem() const { return mSwitchToSelectToolAfterDrawingItem; } void Config::setSwitchToSelectToolAfterDrawingItem(bool enabled) { mSwitchToSelectToolAfterDrawingItem = enabled; } NumberUpdateMode Config::numberUpdateMode() const { return mNumberUpdateMode; } void Config::setNumberToolUpdateMode(enum NumberUpdateMode numberUpdateMode) { if (numberUpdateMode != mNumberUpdateMode) { mNumberUpdateMode = numberUpdateMode; emit numberUpdateModeChanged(numberUpdateMode); } } int Config::obfuscationFactor(Tools toolType) const { return mToolToObfuscationFactor[toolType]; } void Config::setObfuscationFactor(int factor, Tools toolType) { if (obfuscationFactor(toolType) == factor) { return; } mToolToObfuscationFactor[toolType] = factor; saveToolObfuscateFactor(toolType, factor); } QColor Config::canvasColor() const { return mCanvasColor; } void Config::setCanvasColor(const QColor &color) { mCanvasColor = color; } QByteArray Config::annotatorDockWidgetsState() const { return mConfig.value(ConfigNameHelper::annotatorDockWidgetsState()).toByteArray(); } void Config::setAnnotatorDockWidgetsState(const QByteArray &state) { mConfig.setValue(ConfigNameHelper::annotatorDockWidgetsState(), state); mConfig.sync(); } bool Config::selectItemAfterDrawing() const { return mSelectItemAfterDrawing; } void Config::setSelectItemAfterDrawing(bool enabled) { mSelectItemAfterDrawing = enabled; } // Private Methods void Config::initToolSettings() { initSelectedTool(); initToolColors(); initToolTextColors(); initToolWidths(); initToolFillTypes(); initToolFonts(); initObfuscateFactor(); initShadowEnabled(); } void Config::initSelectedTool() { mSelectTool = loadToolType(); }; void Config::initToolColors() { for (auto toolType : mAllTools) { mToolToColor[toolType] = loadToolColor(toolType); } } void Config::initToolTextColors() { for (auto toolType : mAllTools) { mToolToTextColor[toolType] = loadToolTextColor(toolType); } } void Config::initToolWidths() { for (auto toolType : mAllTools) { mToolToWidth[toolType] = loadToolWidth(toolType); } } void Config::initToolFillTypes() { for (auto toolType : mAllTools) { mToolToFillType[toolType] = loadToolFillType(toolType); } } void Config::initToolFonts() { for (auto toolType : mAllTools) { mToolToFont[toolType] = loadToolFont(toolType); } } void Config::initObfuscateFactor() { for (auto toolType : mAllTools) { mToolToObfuscationFactor[toolType] = loadToolObfuscateFactor(toolType); } } void Config::initShadowEnabled() { for (auto toolType : mAllTools) { mToolToShadowEnabled[toolType] = loadToolShadowEnabled(toolType); } } void Config::initGeneralSettings() { mSaveToolSelection = false; mSmoothPathEnabled = true; mSmoothFactor = 7; mSwitchToSelectToolAfterDrawingItem = false; mSelectItemAfterDrawing = true; mNumberUpdateMode = NumberUpdateMode::UpdateOnlyNewNumbers; mCanvasColor = Qt::white; } QColor Config::loadToolColor(Tools toolType) { if (mSaveToolSelection) { return mConfig.value(ConfigNameHelper::toolColor(toolType), defaultToolColor(toolType)).value(); } else { return defaultToolColor(toolType); } } void Config::saveToolColor(Tools toolType, const QColor &color) { if (mSaveToolSelection) { mConfig.setValue(ConfigNameHelper::toolColor(toolType), color); mConfig.sync(); } } QColor Config::loadToolTextColor(Tools toolType) { if (mSaveToolSelection) { return mConfig.value(ConfigNameHelper::toolTextColor(toolType), defaultToolTextColor(toolType)).value(); } else { return defaultToolTextColor(toolType); } } void Config::saveToolTextColor(Tools toolType, const QColor &color) { if (mSaveToolSelection) { mConfig.setValue(ConfigNameHelper::toolTextColor(toolType), color); mConfig.sync(); } } int Config::loadToolWidth(Tools toolType) { if (mSaveToolSelection) { return mConfig.value(ConfigNameHelper::toolWidth(toolType), defaultToolWidth(toolType)).value(); } else { return defaultToolWidth(toolType); } } void Config::saveToolWidth(Tools toolType, int size) { if (mSaveToolSelection) { mConfig.setValue(ConfigNameHelper::toolWidth(toolType), size); mConfig.sync(); } } FillModes Config::loadToolFillType(Tools toolType) { if (mSaveToolSelection) { return mConfig.value(ConfigNameHelper::toolFillType(toolType), static_cast(defaultToolFillMode(toolType))).value(); } else { return defaultToolFillMode(toolType); } } void Config::saveToolFillType(Tools toolType, FillModes fillType) { if (mSaveToolSelection) { mConfig.setValue(ConfigNameHelper::toolFillType(toolType), static_cast(fillType)); mConfig.sync(); } } QFont Config::loadToolFont(Tools tool) const { if (mSaveToolSelection) { return mConfig.value(ConfigNameHelper::toolFont(tool), defaultToolFont(tool)).value(); } else { return defaultToolFont(tool); } } void Config::saveToolFont(Tools tool, const QFont &font) { if (mSaveToolSelection) { mConfig.setValue(ConfigNameHelper::toolFont(tool), font); mConfig.sync(); } } Tools Config::loadToolType() { if (mSaveToolSelection) { return mConfig.value(ConfigNameHelper::toolType(), static_cast(defaultToolType())).value(); } else { return defaultToolType(); } } void Config::saveToolType(Tools toolType) { if (mSaveToolSelection) { mConfig.setValue(ConfigNameHelper::toolType(), static_cast(toolType)); mConfig.sync(); } } int Config::loadToolObfuscateFactor(Tools toolType) { if (mSaveToolSelection) { return mConfig.value(ConfigNameHelper::obfuscateFactor(toolType), defaultObfuscateFactor()).value(); } else { return defaultObfuscateFactor(); } } void Config::saveToolObfuscateFactor(Tools toolType, int radius) { if (mSaveToolSelection) { mConfig.setValue(ConfigNameHelper::obfuscateFactor(toolType), radius); mConfig.sync(); } } bool Config::loadToolShadowEnabled(Tools tool) { if (mSaveToolSelection) { return mConfig.value(ConfigNameHelper::shadowEnabled(tool), defaultShadowEnabled(tool)).toBool(); } else { return defaultShadowEnabled(tool); } } void Config::saveToolShadowEnabled(Tools tool, bool enabled) { if (mSaveToolSelection) { mConfig.setValue(ConfigNameHelper::shadowEnabled(tool), enabled); mConfig.sync(); } } QColor Config::defaultToolColor(Tools toolType) { switch (toolType) { case Tools::MarkerPen: case Tools::MarkerRect: case Tools::MarkerEllipse: return { Qt::yellow }; case Tools::Line: return { Qt::blue }; case Tools::Rect: return { Qt::gray }; case Tools::Text: return { Qt::black }; case Tools::Blur: case Tools::Pixelate: return { Qt::white }; case Tools::Duplicate: return { Qt::green }; default: return { Qt::red }; } } QColor Config::defaultToolTextColor(Tools toolType) { switch (toolType) { case Tools::Text: case Tools::TextPointer: case Tools::TextArrow: case Tools::Number: case Tools::NumberPointer: case Tools::NumberArrow: return { Qt::white }; default: return { Qt::blue }; } } int Config::defaultToolWidth(Tools toolType) { switch (toolType) { case Tools::MarkerPen: return 30; case Tools::Arrow: case Tools::DoubleArrow: return 6; case Tools::Number: return 5; case Tools::Text: case Tools::TextArrow: return 2; case Tools::NumberPointer: case Tools::TextPointer: case Tools::Duplicate: return 1; default: return 3; } } FillModes Config::defaultToolFillMode(Tools toolType) { switch (toolType) { case Tools::Arrow: case Tools::DoubleArrow: case Tools::Rect: case Tools::Number: case Tools::NumberPointer: case Tools::Blur: case Tools::Pixelate: case Tools::TextPointer: case Tools::Image: case Tools::Sticker: return FillModes::BorderAndFill; case Tools::MarkerRect: case Tools::MarkerEllipse: case Tools::Duplicate: return FillModes::NoBorderAndFill; case Tools::NumberArrow: case Tools::TextArrow: return FillModes::NoBorderAndNoFill; default: return FillModes::BorderAndNoFill; } } QFont Config::defaultToolFont(Tools tool) { auto textFont = QFont(QGuiApplication::font().family(), 15, QFont::Bold); auto numberFont = QFont(QGuiApplication::font().family(), 20, QFont::Bold); switch (tool) { case Tools::Number: case Tools::NumberPointer: case Tools::NumberArrow: return numberFont; case Tools::Text: case Tools::TextPointer: case Tools::TextArrow: default: return textFont; } } Tools Config::defaultToolType() { return Tools::Pen; } int Config::defaultObfuscateFactor() { return 10; } bool Config::defaultShadowEnabled(Tools tool) { switch (tool) { case Tools::Pen: case Tools::Line: case Tools::Number: case Tools::NumberPointer: case Tools::NumberArrow: case Tools::Arrow: case Tools::DoubleArrow: case Tools::Rect: case Tools::Ellipse: case Tools::Sticker: return true; case Tools::Text: case Tools::TextPointer: case Tools::TextArrow: case Tools::Blur: case Tools::Pixelate: case Tools::MarkerPen: case Tools::MarkerRect: case Tools::MarkerEllipse: case Tools::Duplicate: case Tools::Image: case Tools::Select: default: return false; } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/backend/Config.h000066400000000000000000000112401414424500400203320ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CONFIG_H #define KIMAGEANNOTATOR_CONFIG_H #include #include #include #include #include #include #include "src/common/enum/Tools.h" #include "src/common/enum/FillModes.h" #include "src/common/enum/NumberUpdateMode.h" #include "src/common/helper/ConfigNameHelper.h" namespace kImageAnnotator { class Config : public QObject { Q_OBJECT public: explicit Config(); ~Config() override = default; public slots: Tools selectedTool() const; void setSelectedToolType(Tools tool); QColor toolColor(Tools tool) const; void setToolColor(const QColor &color, Tools tool); QColor toolTextColor(Tools tool) const; void setToolTextColor(const QColor &color, Tools tool); int toolWidth(Tools tool) const; void setToolWidth(int width, Tools tool); FillModes toolFillType(Tools tool) const; void setToolFillType(FillModes fillType, Tools tool); QFont toolFont(Tools tool) const; void setToolFont(const QFont &font, Tools tool); bool shadowEnabled(Tools tool) const; void setShadowEnabled(bool enabled, Tools tool); bool smoothPathEnabled() const; void setSmoothPathEnabled(bool enabled); void setSaveToolSelection(bool enabled); int smoothFactor() const; void setSmoothFactor(int factor); bool switchToSelectToolAfterDrawingItem() const; void setSwitchToSelectToolAfterDrawingItem(bool enabled); NumberUpdateMode numberUpdateMode() const; void setNumberToolUpdateMode(enum NumberUpdateMode numberUpdateMode); int obfuscationFactor(Tools toolType) const; void setObfuscationFactor(int factor, Tools toolType); QColor canvasColor() const; void setCanvasColor(const QColor &color); QByteArray annotatorDockWidgetsState() const; void setAnnotatorDockWidgetsState(const QByteArray &state); bool selectItemAfterDrawing() const; void setSelectItemAfterDrawing(bool enabled); signals: void numberUpdateModeChanged(enum NumberUpdateMode numberUpdateMode) const; private: QSettings mConfig; QList mAllTools; Tools mSelectTool; QHash mToolToColor; QHash mToolToTextColor; QHash mToolToWidth; QHash mToolToFillType; QHash mToolToFont; QHash mToolToObfuscationFactor; QHash mToolToShadowEnabled; bool mSmoothPathEnabled; bool mSaveToolSelection; int mSmoothFactor; bool mSwitchToSelectToolAfterDrawingItem; bool mSelectItemAfterDrawing; NumberUpdateMode mNumberUpdateMode; QColor mCanvasColor; void initToolSettings(); void initSelectedTool(); void initToolColors(); void initToolTextColors(); void initToolWidths(); void initToolFillTypes(); void initToolFonts(); void initObfuscateFactor(); void initShadowEnabled(); void initGeneralSettings(); QColor loadToolColor(Tools toolType); void saveToolColor(Tools toolType, const QColor &color); QColor loadToolTextColor(Tools toolType); void saveToolTextColor(Tools toolType, const QColor &color); int loadToolWidth(Tools toolType); void saveToolWidth(Tools toolType, int size); FillModes loadToolFillType(Tools toolType); void saveToolFillType(Tools toolType, FillModes fillType); QFont loadToolFont(Tools tool) const; void saveToolFont(Tools tool, const QFont &font); Tools loadToolType(); void saveToolType(Tools toolType); int loadToolObfuscateFactor(Tools toolType); void saveToolObfuscateFactor(Tools toolType, int radius); bool loadToolShadowEnabled(Tools tool); void saveToolShadowEnabled(Tools tool, bool enabled); static QColor defaultToolColor(Tools toolType); static QColor defaultToolTextColor(Tools toolType); static int defaultToolWidth(Tools toolType); static FillModes defaultToolFillMode(Tools toolType); static QFont defaultToolFont(Tools tool); static Tools defaultToolType(); static int defaultObfuscateFactor(); static bool defaultShadowEnabled(Tools tool); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_CONFIG_H kImageAnnotator-0.5.3/src/common/000077500000000000000000000000001414424500400166575ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/common/constants/000077500000000000000000000000001414424500400206735ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/common/constants/Constants.h000066400000000000000000000025601414424500400230230ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONCONSTANTS_H #define KIMAGEANNOTATOR_ANNOTATIONCONSTANTS_H #include #include namespace kImageAnnotator { inline namespace Constants { const int MinPathResizeRectSize = 20; const int ResizeHandleSize = 16; const QSize SettingsWidgetSize(64, 32); const QSize ToolButtonIconSize(28, 28); const QSize MenuItemIconSize(20, 20); const QSize SettingsWidgetIconSize(20, 20); const QColor HoverColor(173, 216, 230); // "#add8e6" } // namespace Constants } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONCONSTANTS_H kImageAnnotator-0.5.3/src/common/enum/000077500000000000000000000000001414424500400176235ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/common/enum/FillModes.h000066400000000000000000000021731414424500400216550ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_FILLMODES_H #define KIMAGEANNOTATOR_FILLMODES_H #include namespace kImageAnnotator { enum class FillModes { BorderAndNoFill, BorderAndFill, NoBorderAndNoFill, NoBorderAndFill }; } // namespace kImageAnnotator Q_DECLARE_METATYPE(kImageAnnotator::FillModes); #endif // KIMAGEANNOTATOR_FILLMODES_H kImageAnnotator-0.5.3/src/common/enum/FlipDirection.h000066400000000000000000000021101414424500400225210ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_FLIPDIRECTION_H #define KIMAGEANNOTATOR_FLIPDIRECTION_H namespace kImageAnnotator { enum class FlipDirection { Horizontal, Vertical }; } // namespace kImageAnnotator Q_DECLARE_METATYPE(kImageAnnotator::FlipDirection); #endif //KIMAGEANNOTATOR_FLIPDIRECTION_H kImageAnnotator-0.5.3/src/common/enum/ImageEffects.h000066400000000000000000000021761414424500400223240ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_IMAGEEFFECTS_H #define KIMAGEANNOTATOR_IMAGEEFFECTS_H #include namespace kImageAnnotator { enum class ImageEffects { NoEffect, DropShadow, Grayscale, Border, InvertColor, }; } // namespace kImageAnnotator Q_DECLARE_METATYPE(kImageAnnotator::ImageEffects); #endif // KIMAGEANNOTATOR_IMAGEEFFECTS_H kImageAnnotator-0.5.3/src/common/enum/NumberUpdateMode.h000066400000000000000000000021161414424500400231740ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_NUMBERUPDATEMODE_H #define KIMAGEANNOTATOR_NUMBERUPDATEMODE_H #include namespace kImageAnnotator { enum class NumberUpdateMode { UpdateAllNumbers, UpdateOnlyNewNumbers }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_NUMBERUPDATEMODE_H kImageAnnotator-0.5.3/src/common/enum/Tools.h000066400000000000000000000025431414424500400211000ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_TOOLS_H #define KIMAGEANNOTATOR_TOOLS_H #include namespace kImageAnnotator { enum class Tools { Select, Pen, MarkerPen, MarkerRect, MarkerEllipse, Line, Arrow, DoubleArrow, Rect, Ellipse, Number, NumberPointer, NumberArrow, Text, TextPointer, TextArrow, Blur, Image, Sticker, Pixelate, Duplicate }; inline uint qHash(const Tools &tool, uint seed) { Q_UNUSED(seed) return static_cast(tool); } } // namespace kImageAnnotator Q_DECLARE_METATYPE(kImageAnnotator::Tools) #endif // KIMAGEANNOTATOR_TOOLS_H kImageAnnotator-0.5.3/src/common/filter/000077500000000000000000000000001414424500400201445ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/common/filter/IgnoreShortcutsFilter.cpp000066400000000000000000000024511414424500400251620ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "IgnoreShortcutsFilter.h" namespace kImageAnnotator { void IgnoreShortcutsFilter::apply() { QCoreApplication::instance()->installEventFilter(this); } void IgnoreShortcutsFilter::remove() { QCoreApplication::instance()->removeEventFilter(this); } bool IgnoreShortcutsFilter::eventFilter(QObject *watched, QEvent *event) { if(event->type() == QEvent::ShortcutOverride) { event->accept(); return true; } return QObject::eventFilter(watched, event); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/common/filter/IgnoreShortcutsFilter.h000066400000000000000000000024761414424500400246360ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_IGNORESHORTCUTSFILTER_H #define KIMAGEANNOTATOR_IGNORESHORTCUTSFILTER_H #include #include namespace kImageAnnotator { class IgnoreShortcutsFilter : public QObject { Q_OBJECT public: explicit IgnoreShortcutsFilter() = default; ~IgnoreShortcutsFilter() override = default; void apply(); void remove(); protected: bool eventFilter(QObject *watched, QEvent *event) override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_IGNORESHORTCUTSFILTER_H kImageAnnotator-0.5.3/src/common/filter/KeyEventListener.cpp000066400000000000000000000034671414424500400241220ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KeyEventListener.h" namespace kImageAnnotator { KeyEventListener::KeyEventListener() { QCoreApplication::instance()->installEventFilter(this); } KeyEventListener::~KeyEventListener() { QCoreApplication::instance()->removeEventFilter(this); } bool KeyEventListener::eventFilter(QObject *watched, QEvent *event) { if (event->type() == QEvent::KeyPress) { handleKeyPressed(event); } else if (event->type() == QEvent::KeyRelease) { handleKeyReleased(event); } return QObject::eventFilter(watched, event); } void KeyEventListener::handleKeyReleased(QEvent *event) { auto keyEvent = dynamic_cast(event); if(mPressedKeyCodes.contains(keyEvent->key())) { mPressedKeyCodes.removeAll(keyEvent->key()); emit keyReleased(keyEvent); } } void KeyEventListener::handleKeyPressed(QEvent *event) { auto keyEvent = dynamic_cast(event); if(!mPressedKeyCodes.contains(keyEvent->key())) { mPressedKeyCodes.append(keyEvent->key()); emit keyPressed(keyEvent); } } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/common/filter/KeyEventListener.h000066400000000000000000000027141414424500400235610ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_KEYEVENTLISTENER_H #define KIMAGEANNOTATOR_KEYEVENTLISTENER_H #include #include #include #include namespace kImageAnnotator { class KeyEventListener : public QObject { Q_OBJECT public: explicit KeyEventListener(); ~KeyEventListener() override; signals: void keyPressed(QKeyEvent *event); void keyReleased(QKeyEvent *event); protected: bool eventFilter(QObject *watched, QEvent *event) override; private: QList mPressedKeyCodes; void handleKeyPressed(QEvent *event); void handleKeyReleased(QEvent *event); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_KEYEVENTLISTENER_H kImageAnnotator-0.5.3/src/common/helper/000077500000000000000000000000001414424500400201365ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/common/helper/ConfigNameHelper.cpp000066400000000000000000000043631414424500400240160ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ConfigNameHelper.h" namespace kImageAnnotator { QString ConfigNameHelper::kImageAnnotator() { return QLatin1String("KImageAnnotator/"); } QString ConfigNameHelper::toolType() { return kImageAnnotator() + QLatin1String("ToolType"); } QString ConfigNameHelper::toolWidth(Tools tool) { return kImageAnnotator() + QLatin1String("ToolWidth_") + QString::number(static_cast(tool)); } QString ConfigNameHelper::toolColor(Tools tool) { return kImageAnnotator() + QLatin1String("ToolColor_") + QString::number(static_cast(tool)); } QString ConfigNameHelper::toolTextColor(Tools tool) { return kImageAnnotator() + QLatin1String("ToolTextColor_") + QString::number(static_cast(tool)); } QString ConfigNameHelper::toolFillType(Tools tool) { return kImageAnnotator() + QLatin1String("ToolFillType_") + QString::number(static_cast(tool)); } QString ConfigNameHelper::toolFont(Tools tool) { return kImageAnnotator() + QLatin1String("ToolFont_") + QString::number(static_cast(tool)); } QString ConfigNameHelper::obfuscateFactor(Tools tool) { return kImageAnnotator() + QLatin1String("ToolObfuscateFactor_") + QString::number(static_cast(tool)); } QString ConfigNameHelper::shadowEnabled(Tools tool) { return kImageAnnotator() + QLatin1String("ToolShadowEnabled_") + QString::number(static_cast(tool)); } QString ConfigNameHelper::annotatorDockWidgetsState() { return kImageAnnotator() + QLatin1String("AnnotatorDockWidgetsState"); } }kImageAnnotator-0.5.3/src/common/helper/ConfigNameHelper.h000066400000000000000000000026741414424500400234660ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CONFIGNAMEFORMATTER_H #define KIMAGEANNOTATOR_CONFIGNAMEFORMATTER_H #include #include "src/common/enum/Tools.h" namespace kImageAnnotator { class ConfigNameHelper { public: static QString kImageAnnotator(); static QString toolType(); static QString toolWidth(Tools tool); static QString toolColor(Tools tool); static QString toolTextColor(Tools tool); static QString toolFillType(Tools tool); static QString toolFont(Tools tool); static QString obfuscateFactor(Tools tool); static QString shadowEnabled(Tools tool); static QString annotatorDockWidgetsState(); }; } #endif //KIMAGEANNOTATOR_CONFIGNAMEFORMATTER_H kImageAnnotator-0.5.3/src/common/helper/CursorHelper.cpp000066400000000000000000000030431414424500400232570ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "CursorHelper.h" namespace kImageAnnotator { Qt::CursorShape CursorHelper::defaultCursor() { return Qt::ArrowCursor; } Qt::CursorShape CursorHelper::allResizeCursor() { return Qt::SizeAllCursor; } Qt::CursorShape CursorHelper::horizontalResizeCursor() { return Qt::SizeHorCursor; } Qt::CursorShape CursorHelper::verticalResizeCursor() { return Qt::SizeVerCursor; } Qt::CursorShape CursorHelper::bDiagResizeCursor() { return Qt::SizeBDiagCursor; } Qt::CursorShape CursorHelper::fDiagResizeCursor() { return Qt::SizeFDiagCursor; } Qt::CursorShape CursorHelper::movableCursor() { return Qt::OpenHandCursor; } Qt::CursorShape CursorHelper::movingCursor() { return Qt::ClosedHandCursor; } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/common/helper/CursorHelper.h000066400000000000000000000025641414424500400227330ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CURSORHELPER_H #define KIMAGEANNOTATOR_CURSORHELPER_H #include namespace kImageAnnotator { class CursorHelper { public: Qt::CursorShape static defaultCursor(); Qt::CursorShape static verticalResizeCursor(); Qt::CursorShape static horizontalResizeCursor(); Qt::CursorShape static bDiagResizeCursor(); Qt::CursorShape static fDiagResizeCursor(); Qt::CursorShape static allResizeCursor(); Qt::CursorShape static movableCursor(); Qt::CursorShape static movingCursor(); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_CURSORHELPER_H kImageAnnotator-0.5.3/src/common/helper/IconLoader.cpp000066400000000000000000000030011414424500400226530ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "IconLoader.h" namespace kImageAnnotator { QIcon IconLoader::load(const QString &name) { auto type = getThemePrefix(); return QIcon(QLatin1String(":/icons/") + type + name); } QPixmap IconLoader::loadAsPixmap(const QString &name) { auto type = getThemePrefix(); return QPixmap(QLatin1String(":/icons/") + type + name); } QString IconLoader::getThemePrefix() { return isDarkTheme() ? QLatin1String("dark/") : QLatin1String("light/"); } double IconLoader::getThemeLuma() { auto color = QApplication::palette().background().color(); return 0.2126 * color.redF() + 0.7152 * color.greenF() + 0.0722 * color.blueF(); } bool IconLoader::isDarkTheme() { return getThemeLuma() > 0.4; } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/common/helper/IconLoader.h000066400000000000000000000024471414424500400223350ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ICONLOADER_H #define KIMAGEANNOTATOR_ICONLOADER_H #include #include #include namespace kImageAnnotator { class IconLoader { public: static QIcon load(const QString &name); static QPixmap loadAsPixmap(const QString &name); private: IconLoader() = default; ~IconLoader() = default; static bool isDarkTheme(); static QString getThemePrefix(); static double getThemeLuma(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ICONLOADER_H kImageAnnotator-0.5.3/src/common/helper/ItemHelper.cpp000066400000000000000000000022671414424500400227070ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ItemHelper.h" namespace kImageAnnotator { bool ItemHelper::zValueGreaterThen(const AbstractAnnotationItem *item1, const AbstractAnnotationItem *item2) { return item1->zValue() > item2->zValue(); } void ItemHelper::sortItemsByZValueDesc(QList *items) { qSort(items->begin(), items->end(), ItemHelper::zValueGreaterThen); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/common/helper/ItemHelper.h000066400000000000000000000023521414424500400223470ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ITEMHELPER_H #define KIMAGEANNOTATOR_ITEMHELPER_H #include "src/annotations/items/AbstractAnnotationItem.h" namespace kImageAnnotator { class ItemHelper { public: static bool zValueGreaterThen(const AbstractAnnotationItem *item1, const AbstractAnnotationItem *item2); static void sortItemsByZValueDesc(QList *items); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ITEMHELPER_H kImageAnnotator-0.5.3/src/common/helper/KeyHelper.cpp000066400000000000000000000051361414424500400225370ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KeyHelper.h" namespace kImageAnnotator { KeyHelper::KeyHelper() { reset(); } void KeyHelper::keyPress(QKeyEvent *keyEvent) { auto key = static_cast(keyEvent->key()); if (mKeyToIsPressed.contains(key)) { mKeyToIsPressed[key] = true; emitPressSignal(key); } } void KeyHelper::keyRelease(QKeyEvent *keyEvent) { auto key = static_cast(keyEvent->key()); if (mKeyToIsPressed.contains(key)) { mKeyToIsPressed[key] = false; emitReleaseSignal(key); } } bool KeyHelper::isControlPressed() const { return mKeyToIsPressed[Qt::Key_Control]; } bool KeyHelper::isShiftPressed() const { return mKeyToIsPressed[Qt::Key_Shift]; } bool KeyHelper::isSpacePressed() const { return mKeyToIsPressed[Qt::Key_Space]; } void KeyHelper::reset() { mKeyToIsPressed[Qt::Key_Delete] = false; mKeyToIsPressed[Qt::Key_Escape] = false; mKeyToIsPressed[Qt::Key_Enter] = false; mKeyToIsPressed[Qt::Key_Return] = false; mKeyToIsPressed[Qt::Key_Control] = false; mKeyToIsPressed[Qt::Key_Shift] = false; mKeyToIsPressed[Qt::Key_Space] = false; mKeyToIsPressed[Qt::Key_Z] = false; } void KeyHelper::emitReleaseSignal(Qt::Key key) { switch (key) { case Qt::Key_Delete: emit deleteReleased(); break; case Qt::Key_Escape: emit escapeReleased(); break; case Qt::Key_Return: emit returnReleased(); break; case Qt::Key_Enter: emit enterReleased(); break; } } void KeyHelper::emitPressSignal(Qt::Key key) { if (key == Qt::Key_Z && isControlPressed()) { if (isShiftPressed()) { emit redoPressed(); } else { emit undoPressed(); } } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/common/helper/KeyHelper.h000066400000000000000000000031451414424500400222020ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_KEYHELPER_H #define KIMAGEANNOTATOR_KEYHELPER_H #include #include namespace kImageAnnotator { class KeyHelper : public QObject { Q_OBJECT public: explicit KeyHelper(); ~KeyHelper() override = default; bool isControlPressed() const; bool isShiftPressed() const; bool isSpacePressed() const; void reset(); signals: void deleteReleased() const; void escapeReleased() const; void undoPressed() const; void redoPressed() const; void enterReleased() const; void returnReleased() const; public slots: void keyPress(QKeyEvent *keyEvent); void keyRelease(QKeyEvent *keyEvent); private: QHash mKeyToIsPressed; void emitReleaseSignal(Qt::Key key); void emitPressSignal(Qt::Key key); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_KEYHELPER_H kImageAnnotator-0.5.3/src/common/helper/MathHelper.cpp000066400000000000000000000032651414424500400227010ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include "MathHelper.h" namespace kImageAnnotator { qreal MathHelper::roundAngleTo(const qreal currentAngle, const int increments) { auto modulo = (int) currentAngle % increments; auto requiredRoundup = modulo < increments / 2 ? -modulo : increments - modulo; auto newAngle = qFloor(currentAngle + requiredRoundup); return newAngle; } qreal MathHelper::smallerValue(qreal value1, qreal value2) { qreal value = (qAbs(value1) < qAbs(value2)) ? qAbs(value1) : qAbs(value2); return (value1 < 0) ? -value : value; } qreal MathHelper::distanceBetweenPoints(const QPointF &point1, const QPointF &point2) { auto horizontalDistance = (point1.x() - point2.x()) * (point1.x() - point2.x()); auto verticalDistance = (point1.y() - point2.y()) * (point1.y() - point2.y()); return qSqrt(horizontalDistance + verticalDistance); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/common/helper/MathHelper.h000066400000000000000000000023331414424500400223410ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_MATHHELPER_H #define KIMAGEANNOTATOR_MATHHELPER_H #include namespace kImageAnnotator { class MathHelper { public: static qreal roundAngleTo(qreal currentAngle, int increments); static qreal smallerValue(qreal value1, qreal value2); static qreal distanceBetweenPoints(const QPointF &point1, const QPointF &point2); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_MATHHELPER_H kImageAnnotator-0.5.3/src/common/helper/PathHelper.cpp000066400000000000000000000027611414424500400227040ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "PathHelper.h" namespace kImageAnnotator { QString PathHelper::extractFilename(const QString& path) { auto filename = extractFilenameWithFormat(path); if (filename.contains(QLatin1Char('.'))) { return filename.section(QLatin1Char('.'), 0, -2); } else { return filename; } } QString PathHelper::extractFilenameWithFormat(const QString &path) { return path.section(QLatin1Char('/'), -1); } QString PathHelper::prettyFilename(const QString &filename) { auto parts = filename.split(QLatin1Char('_'), QString::SkipEmptyParts); for (auto i = 0; i < parts.size() ; i++) { parts[i].replace(0, 1, parts[i][0].toUpper()); } return parts.join(QLatin1Char(' ')); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/common/helper/PathHelper.h000066400000000000000000000023151414424500400223440ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_PATHHELPER_H #define KIMAGEANNOTATOR_PATHHELPER_H #include #include namespace kImageAnnotator { class PathHelper { public: static QString extractFilename(const QString &path); static QString extractFilenameWithFormat(const QString &path); static QString prettyFilename(const QString &filename); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_PATHHELPER_H kImageAnnotator-0.5.3/src/common/helper/ShapeHelper.cpp000066400000000000000000000231321414424500400230430ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include #include "ShapeHelper.h" namespace kImageAnnotator { QPointF ShapeHelper::rectTopLeftWithOffset(const QRectF &rect, int offset) { auto xOffset = invertOffsetIfLeftSmallerThenRight(rect, offset); auto yOffset = invertOffsetIfTopSmallerThenBottom(rect, offset); return { rect.topLeft().x() + xOffset, rect.topLeft().y() + yOffset }; } QPointF ShapeHelper::rectTop(const QRectF &rect) { return { rect.center().x(), rect.top() }; } QPointF ShapeHelper::rectTopWithOffset(const QRectF &rect, int offset) { offset = invertOffsetIfTopSmallerThenBottom(rect, offset); return { rect.center().x(), rect.top() + offset }; } QPointF ShapeHelper::rectTopRightWithOffset(const QRectF &rect, int offset) { auto xOffset = invertOffsetIfLeftSmallerThenRight(rect, -offset); auto yOffset = invertOffsetIfTopSmallerThenBottom(rect, offset); return { rect.topRight().x() + xOffset, rect.topRight().y() + yOffset }; } QPointF ShapeHelper::rectRight(const QRectF &rect) { return { rect.right(), rect.center().y() }; } QPointF ShapeHelper::rectRightWithOffset(const QRectF &rect, int offset) { offset = invertOffsetIfLeftSmallerThenRight(rect, -offset); return { rect.right() + offset, rect.center().y() }; } QPointF ShapeHelper::rectBottomRightWithOffset(const QRectF &rect, int offset) { auto xOffset = invertOffsetIfLeftSmallerThenRight(rect, -offset); auto yOffset = invertOffsetIfTopSmallerThenBottom(rect, -offset); return { rect.bottomRight().x() + xOffset, rect.bottomRight().y() + yOffset }; } QPointF ShapeHelper::rectBottom(const QRectF &rect) { return { rect.center().x(), rect.bottom() }; } QPointF ShapeHelper::rectBottomWithOffset(const QRectF &rect, int offset) { offset = invertOffsetIfTopSmallerThenBottom(rect, -offset); return { rect.center().x(), rect.bottom() + offset }; } QPointF ShapeHelper::rectBottomLeftWithOffset(const QRectF &rect, int offset) { auto xOffset = invertOffsetIfLeftSmallerThenRight(rect, offset); auto yOffset = invertOffsetIfTopSmallerThenBottom(rect, -offset); return { rect.bottomLeft().x() + xOffset, rect.bottomLeft().y() + yOffset }; } QPointF ShapeHelper::rectLeft(const QRectF &rect) { return { rect.left(), rect.center().y() }; } QPointF ShapeHelper::rectLeftWithOffset(const QRectF &rect, int offset) { offset = invertOffsetIfLeftSmallerThenRight(rect, offset); return { rect.left() + offset, rect.center().y() }; } QLineF ShapeHelper::extendLine(const QLineF &line, int extendBy) { QLineF newLine(line.p2().x(), line.p2().y(), line.p1().x(), line.p1().y()); newLine.setLength(newLine.length() + extendBy / 2); newLine.setLine(newLine.p2().x(), newLine.p2().y(), newLine.p1().x(), newLine.p1().y()); newLine.setLength(newLine.length() + extendBy / 2); return newLine; } QPointF ShapeHelper::rectPointAtIndex(const QRectF &rect, int index) { if (index == 0) { return rect.topLeft(); } else if (index == 1) { return ShapeHelper::rectTop(rect); } else if (index == 2) { return rect.topRight(); } else if (index == 3) { return ShapeHelper::rectRight(rect); } else if (index == 4) { return rect.bottomRight(); } else if (index == 5) { return ShapeHelper::rectBottom(rect); } else if (index == 6) { return rect.bottomLeft(); } else if (index == 7) { return ShapeHelper::rectLeft(rect); } else { qCritical("Invalid rectangle index provided, returning empty point."); return {}; } } QRectF ShapeHelper::setRectPointAtIndex(const QRectF &rect, int index, const QPointF &pos, bool keepAspectRatio) { auto updatedRect = rect; if (index == 0) { if (!keepAspectRatio) { updatedRect.setTopLeft(pos); } else { const auto xDif = updatedRect.topLeft().x() - pos.x(); const auto yDif = updatedRect.topLeft().y() - pos.y(); const auto min = qMin(xDif, yDif); const auto newX = updatedRect.topLeft().x() - min; const auto newY = updatedRect.topLeft().y() - min; updatedRect.setTopLeft(QPointF(newX, newY)); } } else if (index == 1) { updatedRect.setTop(pos.y()); } else if (index == 2) { if (!keepAspectRatio) { updatedRect.setTopRight(pos); } else { const auto xDif = pos.x() - updatedRect.topRight().x(); const auto yDif = updatedRect.topRight().y() - pos.y(); const auto min = qMin(xDif, yDif); const auto newX = updatedRect.topRight().x() + min; const auto newY = updatedRect.topRight().y() - min; updatedRect.setTopRight(QPointF(newX, newY)); } } else if (index == 3) { updatedRect.setRight(pos.x()); } else if (index == 4) { if (!keepAspectRatio) { updatedRect.setBottomRight(pos); } else { const auto xDif = pos.x() - updatedRect.bottomRight().x(); const auto yDif = pos.y() - updatedRect.bottomRight().y(); const auto min = qMin(xDif, yDif); const auto newX = updatedRect.bottomRight().x() + min; const auto newY = updatedRect.bottomRight().y() + min; updatedRect.setBottomRight(QPointF(newX, newY)); } } else if (index == 5) { updatedRect.setBottom(pos.y()); } else if (index == 6) { if (!keepAspectRatio) { updatedRect.setBottomLeft(pos); } else { const auto xDif = updatedRect.bottomLeft().x() - pos.x(); const auto yDif = pos.y() - updatedRect.bottomLeft().y(); const auto min = qMin(xDif, yDif); const auto newX = updatedRect.bottomLeft().x() - min; const auto newY = updatedRect.bottomLeft().y() + min; updatedRect.setBottomLeft(QPointF(newX, newY)); } } else if (index == 7) { updatedRect.setLeft(pos.x()); } else { qCritical("Invalid rectangle index provided, returning unchanged rectangle."); } return updatedRect; } QPainterPath ShapeHelper::smoothOut(const QPainterPath &path, int smoothFactor) { auto points = getPathPoints(path, smoothFactor); // Don't proceed if we only have 3 or less points. if (points.count() < 3) { return path; } return createSmoothPath(points); } QPainterPath ShapeHelper::createSmoothPath(const QList &points) { QPointF point1, point2; QPainterPath smoothPath; smoothPath.moveTo(points[0]); smoothPath.lineTo(points[1]); for (auto i = 2; i < points.count() - 2; i++) { point1 = getBeginOfRounding(points[i], points[i + 1]); smoothPath.quadTo(points[i], point1); point2 = getEndOfRounding(points[i], points[i + 1]); smoothPath.lineTo(point2); } smoothPath.lineTo(points[points.count() - 1]); return smoothPath; } QList ShapeHelper::getPathPoints(const QPainterPath &path, int smootFactor) { QList points; QPointF p; for (auto i = 0; i < path.elementCount() - 1; i++) { p = QPointF(path.elementAt(i).x, path.elementAt(i).y); // Except for first and last points, check what the distance between two // points is and if its less the min, don't add them to the list. if (points.count() > 1 && (i < path.elementCount() - 2) && (MathHelper::distanceBetweenPoints(points.last(), p) < smootFactor)) { continue; } points.append(p); } return points; } int ShapeHelper::invertOffsetIfLeftSmallerThenRight(const QRectF &rect, int xOffset) { if (rect.left() < rect.right()) { xOffset *= -1; } return xOffset; } int ShapeHelper::invertOffsetIfTopSmallerThenBottom(const QRectF &rect, int yOffset) { if (rect.top() < rect.bottom()) { yOffset *= -1; } return yOffset; } QPointF ShapeHelper::getBeginOfRounding(const QPointF &point1, const QPointF &point2) { QPointF startPoint; auto rat = getRoundingRate(point1, point2); startPoint.setX((1.0 - rat) * point1.x() + rat * point2.x()); startPoint.setY((1.0 - rat) * point1.y() + rat * point2.y()); return startPoint; } QPointF ShapeHelper::getEndOfRounding(const QPointF &point1, const QPointF &point2) { QPointF endPoint; auto rat = getRoundingRate(point1, point2); endPoint.setX(rat * point1.x() + (1.0 - rat) * point2.x()); endPoint.setY(rat * point1.y() + (1.0 - rat) * point2.y()); return endPoint; } double ShapeHelper::getRoundingRate(const QPointF &point1, const QPointF &point2) { auto rat = 10.0 / MathHelper::distanceBetweenPoints(point1, point2); if (rat > 0.5) { rat = 0.5; } return rat; } QPointF ShapeHelper::intersectionBetweenRectAndLineFromCenter(const QLineF &line, const QRectF &rect) { QLineF leftLine(rect.bottomLeft(), rect.topLeft()); QLineF topLine(rect.topLeft(), rect.topRight()); QLineF rightLine(rect.topRight(), rect.bottomRight()); QLineF bottomLine(rect.bottomLeft(), rect.bottomRight()); QPointF intersectionPoint; if(linesIntersect(line, leftLine, intersectionPoint)) { return intersectionPoint; } else if(linesIntersect(line, topLine, intersectionPoint)) { return intersectionPoint; } else if(linesIntersect(line, rightLine, intersectionPoint)) { return intersectionPoint; } else if(linesIntersect(line, bottomLine, intersectionPoint)) { return intersectionPoint; } return intersectionPoint; } bool ShapeHelper::linesIntersect(const QLineF &line1, const QLineF &line2, QPointF &intersection) { return line1.intersect(line2, &intersection) == QLineF::BoundedIntersection; } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/common/helper/ShapeHelper.h000066400000000000000000000056601414424500400225160ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SHAPEHELPER_H #define KIMAGEANNOTATOR_SHAPEHELPER_H #include #include #include #include "src/common/helper/MathHelper.h" #include "src/common/constants/Constants.h" namespace kImageAnnotator { class ShapeHelper { public: static QPointF rectTopLeftWithOffset(const QRectF &rect, int offset); static QPointF rectTop(const QRectF &rect); static QPointF rectTopWithOffset(const QRectF &rect, int offset); static QPointF rectTopRightWithOffset(const QRectF &rect, int offset); static QPointF rectRight(const QRectF &rect); static QPointF rectRightWithOffset(const QRectF &rect, int offset); static QPointF rectBottomRightWithOffset(const QRectF &rect, int offset); static QPointF rectBottom(const QRectF &rect); static QPointF rectBottomWithOffset(const QRectF &rect, int offset); static QPointF rectBottomLeftWithOffset(const QRectF &rect, int offset); static QPointF rectLeft(const QRectF &rect); static QPointF rectLeftWithOffset(const QRectF &rect, int offset); static QLineF extendLine(const QLineF &line, int extendBy); static QPointF rectPointAtIndex(const QRectF &rect, int index); static QRectF setRectPointAtIndex(const QRectF &rect, int index, const QPointF &pos, bool keepAspectRatio = false); static QPainterPath smoothOut(const QPainterPath &path, int smoothFactor); static QPointF intersectionBetweenRectAndLineFromCenter(const QLineF &line, const QRectF &rect); private: static int invertOffsetIfTopSmallerThenBottom(const QRectF &rect, int yOffset); static int invertOffsetIfLeftSmallerThenRight(const QRectF &rect, int xOffset); static QPointF getBeginOfRounding(const QPointF &point1, const QPointF &point2); static QPointF getEndOfRounding(const QPointF &point1, const QPointF &point2); static double getRoundingRate(const QPointF &point1, const QPointF &point2); static QList getPathPoints(const QPainterPath &path, int smootFactor); static QPainterPath createSmoothPath(const QList &points); static bool linesIntersect(const QLineF &line1, const QLineF &line2, QPointF &intersection); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_SHAPEHELPER_H kImageAnnotator-0.5.3/src/common/platform/000077500000000000000000000000001414424500400205035ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/common/platform/PlatformChecker.cpp000066400000000000000000000022511414424500400242600ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "PlatformChecker.h" namespace kImageAnnotator { PlatformChecker *PlatformChecker::instance() { static PlatformChecker instance; return &instance; } bool PlatformChecker::isWayland() const { return mIsWayland; } PlatformChecker::PlatformChecker() { auto output = qgetenv("XDG_CURRENT_DESKTOP"); mIsWayland = output.contains("wayland"); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/common/platform/PlatformChecker.h000066400000000000000000000022631414424500400237300ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_PLATFORMCHECKER_H #define KIMAGEANNOTATOR_PLATFORMCHECKER_H #include namespace kImageAnnotator { class PlatformChecker { public: virtual ~PlatformChecker() = default; static PlatformChecker *instance(); bool isWayland() const; private: bool mIsWayland; PlatformChecker(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_PLATFORMCHECKER_H kImageAnnotator-0.5.3/src/common/provider/000077500000000000000000000000001414424500400205115ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/common/provider/DevicePixelRatioScaler.cpp000066400000000000000000000023371414424500400255540ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "DevicePixelRatioScaler.h" namespace kImageAnnotator { QRectF DevicePixelRatioScaler::scale(const QRectF &rect) const { auto factor = scaleFactor(); return {rect.left() * factor, rect.top() * factor, rect.width() * factor, rect.height() * factor}; } qreal DevicePixelRatioScaler::scaleFactor() const { auto desktopWidget = QApplication::desktop(); return desktopWidget->devicePixelRatioF(); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/common/provider/DevicePixelRatioScaler.h000066400000000000000000000025141414424500400252160ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_DEVICEPIXELRATIOSCALER_H #define KIMAGEANNOTATOR_DEVICEPIXELRATIOSCALER_H #include #include #include "IDevicePixelRatioScaler.h" namespace kImageAnnotator { class DevicePixelRatioScaler : public IDevicePixelRatioScaler { public: DevicePixelRatioScaler() = default; ~DevicePixelRatioScaler() override = default; QRectF scale(const QRectF &rect) const override; qreal scaleFactor() const override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_DEVICEPIXELRATIOSCALER_H kImageAnnotator-0.5.3/src/common/provider/IDevicePixelRatioScaler.h000066400000000000000000000022631414424500400253300ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_IDEVICEPIXELRATIOSCALER_H #define KIMAGEANNOTATOR_IDEVICEPIXELRATIOSCALER_H namespace kImageAnnotator { class IDevicePixelRatioScaler { public: virtual ~IDevicePixelRatioScaler() = default; virtual QRectF scale(const QRectF &rect) const = 0; virtual qreal scaleFactor() const = 0; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_IDEVICEPIXELRATIOSCALER_H kImageAnnotator-0.5.3/src/common/provider/ScaledSizeProvider.cpp000066400000000000000000000044741414424500400247670ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ScaledSizeProvider.h" namespace kImageAnnotator { int ScaledSizeProvider::scaledWidth(int width) { return (int)(width * scaleFactor()); } QSize ScaledSizeProvider::scaledSize(const QSize &size) { return size * scaleFactor(); } QSize ScaledSizeProvider::toolButtonIconSize() { return scaledSize(Constants::ToolButtonIconSize); } QSize ScaledSizeProvider::settingsWidgetSize() { return scaledSize(Constants::SettingsWidgetSize); } QSize ScaledSizeProvider::settingsWidgetIconSize() { return scaledSize(Constants::SettingsWidgetIconSize); } QSize ScaledSizeProvider::menuItemIconSize() { return scaledSize(Constants::MenuItemIconSize); } int ScaledSizeProvider::resizeHandleSize() { return scaledWidth(Constants::ResizeHandleSize); } qreal ScaledSizeProvider::scaleFactor() { static auto scaleFactor = getScaleFactor(); return scaleFactor; } qreal ScaledSizeProvider::getScaleFactor() { #if defined(__linux__) if(isGnomeEnvironment()) { auto screen = QApplication::primaryScreen(); auto logicalDotsPerInch = (int) screen->logicalDotsPerInch(); auto physicalDotsPerInch = (int) screen->physicalDotsPerInch(); return (qreal)logicalDotsPerInch / (qreal)physicalDotsPerInch; } #endif return 1; } #if defined(__linux__) bool ScaledSizeProvider::isGnomeEnvironment() { auto currentDesktop = QString(qgetenv("XDG_CURRENT_DESKTOP")); return currentDesktop.contains(QLatin1String("gnome"), Qt::CaseInsensitive) || currentDesktop.contains(QLatin1String("unity"), Qt::CaseInsensitive); } #endif } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/common/provider/ScaledSizeProvider.h000066400000000000000000000031541414424500400244260ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SCALEDSIZEPROVIDER_H #define KIMAGEANNOTATOR_SCALEDSIZEPROVIDER_H #include #if defined(__linux__) #include #include #endif #include "src/common/constants/Constants.h" namespace kImageAnnotator { class ScaledSizeProvider { public: static int scaledWidth(int width); static QSize scaledSize(const QSize &size); static QSize toolButtonIconSize(); static QSize settingsWidgetSize(); static QSize settingsWidgetIconSize(); static QSize menuItemIconSize(); static int resizeHandleSize(); private: static qreal scaleFactor(); static qreal getScaleFactor(); #if defined(__linux__) static bool isGnomeEnvironment(); #endif ScaledSizeProvider() = default; ~ScaledSizeProvider() = default; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_SCALEDSIZEPROVIDER_H kImageAnnotator-0.5.3/src/gui/000077500000000000000000000000001414424500400161535ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/gui/CoreView.cpp000066400000000000000000000113041414424500400204010ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "CoreView.h" namespace kImageAnnotator { CoreView::CoreView(Config *config) : mConfig(config), mAnnotationWidget(new AnnotationWidget(mConfig)), mCropWidget(new CropWidget), mScaleWidget(new ScaleWidget), mRotateWidget(new RotateWidget), mModifyCanvasWidget(new ModifyCanvasWidget) { addWidget(mAnnotationWidget); addWidget(mCropWidget); addWidget(mScaleWidget); addWidget(mRotateWidget); addWidget(mModifyCanvasWidget); connect(mAnnotationWidget, &AnnotationWidget::imageChanged, this, &CoreView::imageChanged); connect(mAnnotationWidget, &AnnotationWidget::currentTabChanged, this, &CoreView::currentTabChanged); connect(mAnnotationWidget, &AnnotationWidget::tabCloseRequested, this, &CoreView::tabCloseRequested); connect(mAnnotationWidget, &AnnotationWidget::tabMoved, this, &CoreView::tabMoved); connect(mAnnotationWidget, &AnnotationWidget::tabContextMenuOpened, this, &CoreView::tabContextMenuOpened); connect(mCropWidget, &CropWidget::closing, this, &CoreView::showAnnotator); connect(mScaleWidget, &ScaleWidget::closing, this, &CoreView::showAnnotator); connect(mRotateWidget, &RotateWidget::closing, this, &CoreView::showAnnotator); connect(mModifyCanvasWidget, &ModifyCanvasWidget::closing, this, &CoreView::showAnnotator); } CoreView::~CoreView() { delete mAnnotationWidget; delete mCropWidget; delete mScaleWidget; delete mRotateWidget; delete mModifyCanvasWidget; } QImage CoreView::image() const { return mAnnotationWidget->image(); } QImage CoreView::imageAt(int index) const { return mAnnotationWidget->imageAt(index); } void CoreView::loadImage(const QPixmap &pixmap) { mAnnotationWidget->loadImage(pixmap); } int CoreView::addTab(const QPixmap &pixmap, const QString &title, const QString &toolTip) { return mAnnotationWidget->addTab(pixmap, title, toolTip); } void CoreView::updateTabInfo(int index, const QString &title, const QString &toolTip) { mAnnotationWidget->updateTabInfo(index, title, toolTip); } void CoreView::insertImageItem(const QPointF &position, const QPixmap &pixmap) { mAnnotationWidget->insertImageItem(position, pixmap); } void CoreView::removeTab(int index) { mAnnotationWidget->removeTab(index); } void CoreView::showAnnotator() { mAnnotationWidget->setUndoEnabled(true); setCurrentWidget(mAnnotationWidget); } void CoreView::showCropper() { mAnnotationWidget->setUndoEnabled(false); mAnnotationWidget->clearSelection(); setCurrentWidget(mCropWidget); mCropWidget->activate(mAnnotationWidget->annotationArea()); } void CoreView::showScaler() { mAnnotationWidget->setUndoEnabled(false); mAnnotationWidget->clearSelection(); setCurrentWidget(mScaleWidget); mScaleWidget->activate(mAnnotationWidget->annotationArea()); } void CoreView::showRotator() { mAnnotationWidget->setUndoEnabled(false); mAnnotationWidget->clearSelection(); setCurrentWidget(mRotateWidget); mRotateWidget->activate(mAnnotationWidget->annotationArea()); } void CoreView::showCanvasModifier() { mAnnotationWidget->setUndoEnabled(false); mAnnotationWidget->clearSelection(); setCurrentWidget(mModifyCanvasWidget); mModifyCanvasWidget->activate(mAnnotationWidget->annotationArea()); } void CoreView::setSettingsCollapsed(bool isCollapsed) { mAnnotationWidget->setSettingsCollapsed(isCollapsed); } void CoreView::setTabBarAutoHide(bool enabled) { mAnnotationWidget->setTabBarAutoHide(enabled); } QAction *CoreView::undoAction() { return mAnnotationWidget->undoAction(); } QAction *CoreView::redoAction() { return mAnnotationWidget->redoAction(); } QSize CoreView::sizeHint() const { return mAnnotationWidget->sizeHint(); } void CoreView::reloadConfig() { mAnnotationWidget->reloadConfig(); } void CoreView::setStickers(const QStringList &stickerPaths, bool keepDefault) { mAnnotationWidget->setStickers(stickerPaths, keepDefault); } void CoreView::addTabContextMenuActions(const QList &actions) { mAnnotationWidget->addTabContextMenuActions(actions); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/CoreView.h000066400000000000000000000050601414424500400200500ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SWITCHER_H #define KIMAGEANNOTATOR_SWITCHER_H #include #include "src/annotations/core/AnnotationArea.h" #include "src/gui/annotator/AnnotationWidget.h" #include "src/gui/cropper/CropWidget.h" #include "src/gui/scaler/ScaleWidget.h" #include "src/gui/rotator/RotateWidget.h" #include "src/gui/canvasModifier/ModifyCanvasWidget.h" namespace kImageAnnotator { class CoreView : public QStackedWidget { Q_OBJECT public: explicit CoreView(Config *config); ~CoreView() override; QImage image() const; QImage imageAt(int index) const; QAction *undoAction(); QAction *redoAction(); QSize sizeHint() const override; void reloadConfig(); signals: void imageChanged() const; void currentTabChanged(int index) const; void tabCloseRequested(int index) const; void tabMoved(int fromIndex, int toIndex); void tabContextMenuOpened(int index) const; public slots: void loadImage(const QPixmap &pixmap); int addTab(const QPixmap &pixmap, const QString &title, const QString &toolTip); void updateTabInfo(int index, const QString &title, const QString &toolTip); void insertImageItem(const QPointF &position, const QPixmap &pixmap); void removeTab(int index); void showAnnotator(); void showCropper(); void showScaler(); void showRotator(); void showCanvasModifier(); void setSettingsCollapsed(bool isCollapsed); void setTabBarAutoHide(bool enabled); void setStickers(const QStringList &stickerPaths, bool keepDefault); void addTabContextMenuActions(const QList & actions); private: Config *mConfig; AnnotationWidget *mAnnotationWidget; CropWidget *mCropWidget; ScaleWidget *mScaleWidget; RotateWidget *mRotateWidget; ModifyCanvasWidget *mModifyCanvasWidget; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_SWITCHER_H kImageAnnotator-0.5.3/src/gui/KImageAnnotator.cpp000066400000000000000000000153311414424500400217050ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include #include #include #include "CoreView.h" inline void initResource() { Q_INIT_RESOURCE(kImageAnnotator_resources); } namespace kImageAnnotator { void loadTranslations() { static QTranslator *existingTranslator = nullptr; auto translator = new QTranslator(QCoreApplication::instance()); auto translationsLoaded = translator->load(QLocale(), QLatin1String("kImageAnnotator"), QLatin1String("_"), QLatin1String(KIMAGEANNOTATOR_LANG_INSTALL_DIR)); if (translationsLoaded) { if (existingTranslator != nullptr) { QCoreApplication::removeTranslator(existingTranslator); delete existingTranslator; } QCoreApplication::installTranslator(translator); existingTranslator = translator; } } class KImageAnnotatorPrivate { Q_DISABLE_COPY(KImageAnnotatorPrivate) Q_DECLARE_PUBLIC(KImageAnnotator) explicit KImageAnnotatorPrivate(KImageAnnotator *kImageAnnotator); KImageAnnotator *const q_ptr; Config mConfig; CoreView mCoreView; QHBoxLayout mMainLayout; }; KImageAnnotator::KImageAnnotator() : d_ptr(new KImageAnnotatorPrivate(this)) {} KImageAnnotator::~KImageAnnotator() {} QImage KImageAnnotator::image() const { Q_D(const KImageAnnotator); return d->mCoreView.image(); } QImage KImageAnnotator::imageAt(int index) const { Q_D(const KImageAnnotator); return d->mCoreView.imageAt(index); } QAction *KImageAnnotator::undoAction() { Q_D(KImageAnnotator); return d->mCoreView.undoAction(); } QAction *KImageAnnotator::redoAction() { Q_D(KImageAnnotator); return d->mCoreView.redoAction(); } void KImageAnnotator::loadImage(const QPixmap &pixmap) { Q_D(KImageAnnotator); d->mCoreView.loadImage(pixmap); if (isHidden()) { show(); } } int KImageAnnotator::addTab(const QPixmap &pixmap, const QString &title, const QString &toolTip) { Q_D(KImageAnnotator); auto newTabIndex = d->mCoreView.addTab(pixmap, title, toolTip); if (isHidden()) { show(); } return newTabIndex; } void KImageAnnotator::updateTabInfo(int index, const QString &title, const QString &toolTip) { Q_D(KImageAnnotator); d->mCoreView.updateTabInfo(index, title, toolTip); } void KImageAnnotator::insertImageItem(const QPointF &position, const QPixmap &pixmap) { Q_D(KImageAnnotator); d->mCoreView.insertImageItem(position, pixmap); } QSize KImageAnnotator::sizeHint() const { Q_D(const KImageAnnotator); return d->mCoreView.sizeHint(); } void KImageAnnotator::setTextFont(const QFont &font) { Q_UNUSED(font) // Deprecated, will be removed with the next major release } void KImageAnnotator::setNumberFont(const QFont &font) { Q_UNUSED(font) // Deprecated, will be removed with the next major release } void KImageAnnotator::setItemShadowEnabled(bool enabled) { Q_UNUSED(enabled) // Deprecated, will be removed with the next major release } void KImageAnnotator::setSmoothPathEnabled(bool enabled) { Q_D(KImageAnnotator); d->mConfig.setSmoothPathEnabled(enabled); } void KImageAnnotator::setSaveToolSelection(bool enabled) { Q_D(KImageAnnotator); d->mConfig.setSaveToolSelection(enabled); d->mCoreView.reloadConfig(); } void KImageAnnotator::setSmoothFactor(int factor) { Q_D(KImageAnnotator); d->mConfig.setSmoothFactor(factor); } void KImageAnnotator::setSwitchToSelectToolAfterDrawingItem(bool enabled) { Q_D(KImageAnnotator); d->mConfig.setSwitchToSelectToolAfterDrawingItem(enabled); } void KImageAnnotator::setNumberToolSeedChangeUpdatesAllItems(bool enabled) { Q_D(KImageAnnotator); auto mode = enabled ? NumberUpdateMode::UpdateAllNumbers : NumberUpdateMode::UpdateOnlyNewNumbers; d->mConfig.setNumberToolUpdateMode(mode); } void KImageAnnotator::setTabBarAutoHide(bool enabled) { Q_D(KImageAnnotator); d->mCoreView.setTabBarAutoHide(enabled); } void KImageAnnotator::removeTab(int index) { Q_D(KImageAnnotator); d->mCoreView.removeTab(index); } void KImageAnnotator::showAnnotator() { Q_D(KImageAnnotator); d->mCoreView.showAnnotator(); } void KImageAnnotator::showCropper() { Q_D(KImageAnnotator); d->mCoreView.showCropper(); } void KImageAnnotator::showScaler() { Q_D(KImageAnnotator); d->mCoreView.showScaler(); } void KImageAnnotator::showRotator() { Q_D(KImageAnnotator); d->mCoreView.showRotator(); } void KImageAnnotator::showCanvasModifier() { Q_D(KImageAnnotator); d->mCoreView.showCanvasModifier(); } void KImageAnnotator::setSettingsCollapsed(bool isCollapsed) { Q_D(KImageAnnotator); d->mCoreView.setSettingsCollapsed(isCollapsed); } void KImageAnnotator::setStickers(const QStringList &stickerPaths, bool keepDefault) { Q_D(KImageAnnotator); d->mCoreView.setStickers(stickerPaths, keepDefault); } void KImageAnnotator::addTabContextMenuActions(const QList &actions) { Q_D(KImageAnnotator); d->mCoreView.addTabContextMenuActions(actions); } void KImageAnnotator::setCanvasColor(const QColor &color) { Q_D(KImageAnnotator); d->mConfig.setCanvasColor(color); } void KImageAnnotator::setSelectItemAfterDrawing(bool enabled) { Q_D(KImageAnnotator); d->mConfig.setSelectItemAfterDrawing(enabled); } // KImageAnnotatorPrivate KImageAnnotatorPrivate::KImageAnnotatorPrivate(KImageAnnotator *kImageAnnotator) : q_ptr(kImageAnnotator), mCoreView(&mConfig) { initResource(); mMainLayout.addWidget(&mCoreView); kImageAnnotator->setLayout(&mMainLayout); kImageAnnotator->hide(); kImageAnnotator->connect(&mCoreView, &CoreView::imageChanged, kImageAnnotator, &KImageAnnotator::imageChanged); kImageAnnotator->connect(&mCoreView, &CoreView::currentTabChanged, kImageAnnotator, &KImageAnnotator::currentTabChanged); kImageAnnotator->connect(&mCoreView, &CoreView::tabCloseRequested, kImageAnnotator, &KImageAnnotator::tabCloseRequested); kImageAnnotator->connect(&mCoreView, &CoreView::tabMoved, kImageAnnotator, &KImageAnnotator::tabMoved); kImageAnnotator->connect(&mCoreView, &CoreView::tabContextMenuOpened, kImageAnnotator, &KImageAnnotator::tabContextMenuOpened); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/annotator/000077500000000000000000000000001414424500400201605ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/gui/annotator/AnnotationView.cpp000066400000000000000000000022771414424500400236410ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationView.h" namespace kImageAnnotator { AnnotationView::AnnotationView(QWidget *parent) : ScrollAndZoomView(parent) { } void AnnotationView::drawBackground(QPainter *painter, const QRectF &rect) { auto annotationArea = dynamic_cast(scene()); mCanvasPainter.paint(painter, annotationArea->canvasRect(), annotationArea->canvasColor()); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/annotator/AnnotationView.h000066400000000000000000000030641414424500400233010ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONVIEW_H #define KIMAGEANNOTATOR_ANNOTATIONVIEW_H #include #include #include #include "src/gui/scrollAndZoomView/ScrollAndZoomView.h" #include "src/common/helper/KeyHelper.h" #include "src/annotations/core/AnnotationArea.h" #include "src/annotations/misc/CanvasPainter.h" #include "src/gui/scrollAndZoomView/ViewZoomer.h" namespace kImageAnnotator { class AnnotationView : public ScrollAndZoomView { Q_OBJECT public: explicit AnnotationView(QWidget *parent); ~AnnotationView() override = default; protected: void drawBackground(QPainter *painter, const QRectF &rect) override; private: CanvasPainter mCanvasPainter; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONVIEW_H kImageAnnotator-0.5.3/src/gui/annotator/AnnotationWidget.cpp000066400000000000000000000132171414424500400241460ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationWidget.h" namespace kImageAnnotator { AnnotationWidget::AnnotationWidget(Config *config) : mConfig(config), mItemSettings(new AnnotationItemSettings()), mGeneralSettings(new AnnotationGeneralSettings), mToolSelection(new AnnotationToolSelection), mImageSettings(new AnnotationImageSettings), mSettingsAdapter(new AnnotationSettingsAdapter(mGeneralSettings, mItemSettings, mToolSelection, mImageSettings, config)), mAnnotationTabWidget(new AnnotationTabWidget(config, mSettingsAdapter)) { initGui(); restoreDockWidgets(); } AnnotationWidget::~AnnotationWidget() { delete mSettingsAdapter; delete mItemSettings; delete mToolSelection; delete mImageSettings; delete mGeneralSettings; } QSize AnnotationWidget::sizeHint() const { auto offset = ScaledSizeProvider::scaledSize(QSize(100, 100)); return QMainWindow::sizeHint() + offset; } void AnnotationWidget::initGui() { setCentralWidget(mAnnotationTabWidget); insertDockWidget(Qt::LeftDockWidgetArea, mToolSelection); insertDockWidget(Qt::TopDockWidgetArea, mItemSettings); insertDockWidget(Qt::BottomDockWidgetArea, mGeneralSettings); insertDockWidget(Qt::BottomDockWidgetArea, mImageSettings); setFocusPolicy(Qt::ClickFocus); connect(mAnnotationTabWidget, &AnnotationTabWidget::imageChanged, this, &AnnotationWidget::imageChanged); connect(mAnnotationTabWidget, &AnnotationTabWidget::currentChanged, this, &AnnotationWidget::currentTabChanged); connect(mAnnotationTabWidget, &AnnotationTabWidget::tabCloseRequested, this, &AnnotationWidget::tabCloseRequested); connect(mAnnotationTabWidget, &AnnotationTabWidget::tabMoved, this, &AnnotationWidget::tabMoved); connect(mAnnotationTabWidget, &AnnotationTabWidget::tabContextMenuOpened, this, &AnnotationWidget::tabContextMenuOpened); connect(qApp, &QCoreApplication::aboutToQuit, this, &AnnotationWidget::persistDockWidgets); } void AnnotationWidget::insertDockWidget(Qt::DockWidgetArea area, AbstractAnnotationDockWidgetContent *content) { auto dockWidget = new AnnotationDockWidget(content); mDockWidgets.append(dockWidget); addDockWidget(area, dockWidget); } QImage AnnotationWidget::image() const { auto currentAnnotationArea = annotationArea(); return currentAnnotationArea != nullptr ? currentAnnotationArea->image() : QImage(); } QImage AnnotationWidget::imageAt(int index) const { auto annotationArea = annotationAreaAt(index); return annotationArea != nullptr ? annotationArea->image() : QImage(); } void AnnotationWidget::loadImage(const QPixmap &pixmap) { auto currentAnnotationArea = annotationArea(); if(currentAnnotationArea == nullptr) { addTab(pixmap, QString(), QString()); } else { currentAnnotationArea->loadImage(pixmap); } } int AnnotationWidget::addTab(const QPixmap &pixmap, const QString &title, const QString &toolTip) { return mAnnotationTabWidget->addTab(pixmap, title, toolTip); } void AnnotationWidget::updateTabInfo(int index, const QString &title, const QString &toolTip) { mAnnotationTabWidget->updateTabInfo(index, title, toolTip); } void AnnotationWidget::insertImageItem(const QPointF &position, const QPixmap &pixmap) const { auto currentAnnotationArea = annotationArea(); if(currentAnnotationArea != nullptr) { currentAnnotationArea->insertImageItem(position, pixmap); } } void AnnotationWidget::removeTab(int index) { mAnnotationTabWidget->removeTab(index); } void AnnotationWidget::setUndoEnabled(bool enabled) { mAnnotationTabWidget->setUndoRedoEnabled(enabled); } QAction *AnnotationWidget::undoAction() const { return mAnnotationTabWidget->undoAction(); } QAction *AnnotationWidget::redoAction() const { return mAnnotationTabWidget->redoAction(); } void AnnotationWidget::clearSelection() const { auto currentAnnotationArea = annotationArea(); if(currentAnnotationArea != nullptr) { annotationArea()->clearSelection(); } } AnnotationArea *AnnotationWidget::annotationArea() const { return mAnnotationTabWidget->currentAnnotationArea(); } AnnotationArea *AnnotationWidget::annotationAreaAt(int index) const { return mAnnotationTabWidget->annotationAreaAt(index); } void AnnotationWidget::reloadConfig() { mSettingsAdapter->reloadConfig(); } void AnnotationWidget::setTabBarAutoHide(bool enabled) { mAnnotationTabWidget->setTabBarAutoHide(enabled); } void AnnotationWidget::setStickers(const QStringList &stickerPaths, bool keepDefault) { mItemSettings->setStickers(stickerPaths, keepDefault); } void AnnotationWidget::addTabContextMenuActions(const QList &actions) { mAnnotationTabWidget->addContextMenuActions(actions); } void AnnotationWidget::setSettingsCollapsed(bool isCollapsed) { for(auto dockWidget : mDockWidgets) { dockWidget->setCollapsed(isCollapsed); } } void AnnotationWidget::persistDockWidgets() { mConfig->setAnnotatorDockWidgetsState(saveState()); } void AnnotationWidget::restoreDockWidgets() { restoreState(mConfig->annotatorDockWidgetsState()); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/annotator/AnnotationWidget.h000066400000000000000000000060411414424500400236100ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONWIDGET_H #define KIMAGEANNOTATOR_ANNOTATIONWIDGET_H #include #include #include #include #include "src/gui/annotator/settings/AnnotationSettingsAdapter.h" #include "src/gui/annotator/docks/AnnotationDockWidget.h" #include "src/gui/annotator/tabs/AnnotationTabWidget.h" #include "src/annotations/core/AnnotationArea.h" #include "src/common/provider/ScaledSizeProvider.h" namespace kImageAnnotator { class AnnotationWidget : public QMainWindow { Q_OBJECT public: explicit AnnotationWidget(Config *config); ~AnnotationWidget() override; QSize sizeHint() const override; QImage image() const; QImage imageAt(int index) const; void loadImage(const QPixmap &pixmap); int addTab(const QPixmap &pixmap, const QString &title, const QString &toolTip); void updateTabInfo(int index, const QString &title, const QString &toolTip); void insertImageItem(const QPointF &position, const QPixmap &pixmap) const; void removeTab(int index); void setUndoEnabled(bool enabled); QAction* undoAction() const; QAction* redoAction() const; void clearSelection() const; AnnotationArea* annotationArea() const; AnnotationArea *annotationAreaAt(int index) const; void reloadConfig(); void setTabBarAutoHide(bool enabled); void setStickers(const QStringList &stickerPaths, bool keepDefault); void addTabContextMenuActions(const QList & actions); void setSettingsCollapsed(bool isCollapsed); signals: void imageChanged() const; void currentTabChanged(int index) const; void tabCloseRequested(int index) const; void tabMoved(int fromIndex, int toIndex); void tabContextMenuOpened(int index) const; private: Config *mConfig; AnnotationItemSettings *mItemSettings; AnnotationGeneralSettings *mGeneralSettings; AnnotationToolSelection *mToolSelection; AnnotationImageSettings *mImageSettings; AnnotationSettingsAdapter *mSettingsAdapter; AnnotationTabWidget *mAnnotationTabWidget; QList mDockWidgets; void initGui(); void insertDockWidget(Qt::DockWidgetArea area, AbstractAnnotationDockWidgetContent *content); private slots: void persistDockWidgets(); void restoreDockWidgets(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONWIDGET_H kImageAnnotator-0.5.3/src/gui/annotator/docks/000077500000000000000000000000001414424500400212635ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/gui/annotator/docks/AbstractAnnotationDockWidgetContent.cpp000066400000000000000000000031371414424500400310710ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AbstractAnnotationDockWidgetContent.h" namespace kImageAnnotator { void AbstractAnnotationDockWidgetContent::setOrientation(Qt::Orientation orientation) { auto mainLayout = dynamic_cast(layout()); if(mainLayout != nullptr) { if(orientation == Qt::Horizontal) { mainLayout->setDirection(QBoxLayout::LeftToRight); mainLayout->setAlignment(Qt::AlignLeft | Qt::AlignCenter); } else { mainLayout->setDirection(QBoxLayout::TopToBottom); mainLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter); } for (auto widget : mExpandingWidget) { widget->setExpanding(orientation != Qt::Horizontal); } adjustSize(); } } void AbstractAnnotationDockWidgetContent::addExpandingWidget(AbstractExpandingWidget *widget) { mExpandingWidget.append(widget); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/gui/annotator/docks/AbstractAnnotationDockWidgetContent.h000066400000000000000000000031011414424500400305250ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ABSTRACTANNOTATIONDOCKWIDGETCONTENT_H #define KIMAGEANNOTATOR_ABSTRACTANNOTATIONDOCKWIDGETCONTENT_H #include #include #include #include #include "src/widgets/misc/AbstractExpandingWidget.h" namespace kImageAnnotator { class AbstractAnnotationDockWidgetContent : public QWidget { public: AbstractAnnotationDockWidgetContent() = default; ~AbstractAnnotationDockWidgetContent() override = default; virtual void setOrientation(Qt::Orientation orientation); virtual QString name() const = 0; protected: void addExpandingWidget(AbstractExpandingWidget *widget); private: QList mExpandingWidget; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ABSTRACTANNOTATIONDOCKWIDGETCONTENT_H kImageAnnotator-0.5.3/src/gui/annotator/docks/AnnotationDockWidget.cpp000066400000000000000000000056101414424500400260500ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationDockWidget.h" namespace kImageAnnotator { AnnotationDockWidget::AnnotationDockWidget(AbstractAnnotationDockWidgetContent *content) : QDockWidget(content->name()), mContent(content), mDragHandle(new AnnotationDockWidgetDragHandle(this)), mVerticalFeatures(features() ^ QDockWidget::DockWidgetFloatable), mHorizontalFeatures(QDockWidget::DockWidgetVerticalTitleBar | mVerticalFeatures) { setObjectName(content->name()); setAllowedAreas(Qt::AllDockWidgetAreas); setSizePolicy(QSizePolicy::Policy::Ignored, QSizePolicy::Policy::Ignored); setTitleBarWidget(mDragHandle); setToolTip(mContent->name()); setWidget(content); connect(this, &QDockWidget::dockLocationChanged, this, &AnnotationDockWidget::updateDockLocation); } AnnotationDockWidget::~AnnotationDockWidget() { delete mDragHandle; } void AnnotationDockWidget::setCollapsed(bool isCollapsed) { if (isCollapsed) { mSizeBeforeCollapse = size(); setFixedSize(0, 0); } else if (mSizeBeforeCollapse.isValid()){ // Workaround for issue Issue #240 that prevents the bug on auto hide panels setFixedSize(mSizeBeforeCollapse); setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); mSizeBeforeCollapse = QSize(); } } void AnnotationDockWidget::updateDockLocation(Qt::DockWidgetArea area) { if(area == Qt::TopDockWidgetArea || area == Qt::BottomDockWidgetArea) { setOrientation(Qt::Horizontal, mHorizontalFeatures); } else if (area == Qt::LeftDockWidgetArea || area == Qt::RightDockWidgetArea) { setOrientation(Qt::Vertical, mVerticalFeatures); } else { resizeToDragHandle(); } } void AnnotationDockWidget::setOrientation(Qt::Orientation orientation, QDockWidget::DockWidgetFeatures &features) { mContent->setOrientation(orientation); mDragHandle->setOrientation(orientation); setFeatures(features); resizeToContent(); } void AnnotationDockWidget::resizeToDragHandle() { auto offset = ScaledSizeProvider::scaledSize(QSize(2, 3)); setFixedSize(mDragHandle->sizeHint() + offset); } void AnnotationDockWidget::resizeToContent() { setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); setMinimumSize(0, 0); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/annotator/docks/AnnotationDockWidget.h000066400000000000000000000035001414424500400255110ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONDOCKWIDGET_H #define KIMAGEANNOTATOR_ANNOTATIONDOCKWIDGET_H #include #include "AbstractAnnotationDockWidgetContent.h" #include "AnnotationDockWidgetDragHandle.h" #include "src/common/provider/ScaledSizeProvider.h" namespace kImageAnnotator { class AnnotationDockWidget : public QDockWidget { Q_OBJECT public: explicit AnnotationDockWidget(AbstractAnnotationDockWidgetContent *content); ~AnnotationDockWidget() override; void setCollapsed(bool isCollapsed); private: AbstractAnnotationDockWidgetContent *mContent; AnnotationDockWidgetDragHandle *mDragHandle; QDockWidget::DockWidgetFeatures mVerticalFeatures; QDockWidget::DockWidgetFeatures mHorizontalFeatures; QSize mSizeBeforeCollapse; void resizeToContent(); private slots: void updateDockLocation(Qt::DockWidgetArea area); void setOrientation(Qt::Orientation orientation, QDockWidget::DockWidgetFeatures &features); void resizeToDragHandle(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONDOCKWIDGET_H kImageAnnotator-0.5.3/src/gui/annotator/docks/AnnotationDockWidgetDragHandle.cpp000066400000000000000000000051521414424500400277630ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationDockWidgetDragHandle.h" namespace kImageAnnotator { AnnotationDockWidgetDragHandle::AnnotationDockWidgetDragHandle(QWidget *parent) : QWidget(parent), mLabel(new QLabel(this)), mLayout(new QHBoxLayout(this)) { QTransform t; t.rotate(90); mHorizontalHandlerImage = IconLoader::loadAsPixmap(QLatin1String("dragHandle.svg")); mVerticalHandlerImage = mHorizontalHandlerImage.transformed(t); setContextMenuPolicy(Qt::PreventContextMenu); initGui(); } QSize AnnotationDockWidgetDragHandle::sizeHint() const { return QWidget::sizeHint(); } QSize AnnotationDockWidgetDragHandle::minimumSizeHint() const { return QWidget::sizeHint(); } void AnnotationDockWidgetDragHandle::paintEvent(QPaintEvent *event) { QWidget::paintEvent(event); } void AnnotationDockWidgetDragHandle::mouseDoubleClickEvent(QMouseEvent *event) { event->ignore(); } void AnnotationDockWidgetDragHandle::mouseMoveEvent(QMouseEvent *event) { event->ignore(); } void AnnotationDockWidgetDragHandle::mousePressEvent(QMouseEvent *event) { event->ignore(); } void AnnotationDockWidgetDragHandle::mouseReleaseEvent(QMouseEvent *event) { event->ignore(); } void AnnotationDockWidgetDragHandle::setOrientation(Qt::Orientation orientation) { if (orientation == Qt::Horizontal) { mLabel->setPixmap(mHorizontalHandlerImage); } else { mLabel->setPixmap(mVerticalHandlerImage); } } void AnnotationDockWidgetDragHandle::initGui() { auto leftMargin = ScaledSizeProvider::scaledWidth(5); auto topMargin = ScaledSizeProvider::scaledWidth(5); auto rightMargin = 0; auto bottomMargin = ScaledSizeProvider::scaledWidth(2); mLayout->addWidget(mLabel); mLayout->setAlignment(Qt::AlignCenter); mLayout->setContentsMargins(leftMargin, topMargin, rightMargin, bottomMargin); setCursor(Qt::SizeAllCursor); setLayout(mLayout); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/annotator/docks/AnnotationDockWidgetDragHandle.h000066400000000000000000000036311414424500400274300ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONDOCKWIDGETDRAGHANDLE_H #define KIMAGEANNOTATOR_ANNOTATIONDOCKWIDGETDRAGHANDLE_H #include #include #include #include #include "src/common/helper/IconLoader.h" #include "src/common/provider/ScaledSizeProvider.h" namespace kImageAnnotator { class AnnotationDockWidgetDragHandle : public QWidget { Q_OBJECT public: explicit AnnotationDockWidgetDragHandle(QWidget *parent); ~AnnotationDockWidgetDragHandle() override = default; QSize sizeHint() const override; QSize minimumSizeHint() const override; void setOrientation(Qt::Orientation orientation); protected: void paintEvent(QPaintEvent *event) override; void mouseDoubleClickEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; private: QPixmap mVerticalHandlerImage; QPixmap mHorizontalHandlerImage; QLabel *mLabel; QHBoxLayout *mLayout; void initGui(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONDOCKWIDGETDRAGHANDLE_H kImageAnnotator-0.5.3/src/gui/annotator/settings/000077500000000000000000000000001414424500400220205ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/gui/annotator/settings/AnnotationGeneralSettings.cpp000066400000000000000000000032101414424500400276510ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationGeneralSettings.h" namespace kImageAnnotator { AnnotationGeneralSettings::AnnotationGeneralSettings() : mMainLayout(new QBoxLayout(QBoxLayout::LeftToRight)), mZoomPicker(new ZoomPicker(this)) { initGui(); } AnnotationGeneralSettings::~AnnotationGeneralSettings() { delete mZoomPicker; } void AnnotationGeneralSettings::initGui() { mMainLayout->addWidget(mZoomPicker); mMainLayout->setContentsMargins(3, 0, 3, 0); addExpandingWidget(mZoomPicker); setLayout(mMainLayout); setFocusPolicy(Qt::ClickFocus); connect(mZoomPicker, &ZoomPicker::zoomValueChanged, this, &AnnotationGeneralSettings::zoomValueChanged); } void AnnotationGeneralSettings::updateZoomLevel(double value) { mZoomPicker->setZoomValue(value); } QString AnnotationGeneralSettings::name() const { return tr("General Settings"); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/annotator/settings/AnnotationGeneralSettings.h000066400000000000000000000027661414424500400273350ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONGENERALSETTINGS_H #define KIMAGEANNOTATOR_ANNOTATIONGENERALSETTINGS_H #include "src/gui/annotator/docks/AbstractAnnotationDockWidgetContent.h" #include "src/widgets/settingsPicker/ZoomPicker.h" namespace kImageAnnotator { class AnnotationGeneralSettings : public AbstractAnnotationDockWidgetContent { Q_OBJECT public: explicit AnnotationGeneralSettings(); ~AnnotationGeneralSettings() override; void updateZoomLevel(double value); QString name() const override; signals: void zoomValueChanged(double value); private: QBoxLayout *mMainLayout; ZoomPicker *mZoomPicker; void initGui(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONGENERALSETTINGS_H kImageAnnotator-0.5.3/src/gui/annotator/settings/AnnotationImageSettings.cpp000066400000000000000000000033421414424500400273240ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationImageSettings.h" namespace kImageAnnotator { AnnotationImageSettings::AnnotationImageSettings() : mMainLayout(new QBoxLayout(QBoxLayout::LeftToRight)), mEffectPicker(new ImageEffectPicker(this)) { initGui(); } AnnotationImageSettings::~AnnotationImageSettings() { delete mEffectPicker; } ImageEffects AnnotationImageSettings::effect() const { return mEffectPicker->effect(); } void AnnotationImageSettings::setEffect(ImageEffects effect) { mEffectPicker->setEffect(effect); } QString AnnotationImageSettings::name() const { return tr("Image Settings"); } void AnnotationImageSettings::initGui() { mMainLayout->addWidget(mEffectPicker); mMainLayout->setContentsMargins(3, 0, 3, 0); addExpandingWidget(mEffectPicker); setLayout(mMainLayout); setFocusPolicy(Qt::ClickFocus); connect(mEffectPicker, &ImageEffectPicker::effectSelected, this, &AnnotationImageSettings::effectChanged); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/gui/annotator/settings/AnnotationImageSettings.h000066400000000000000000000030351414424500400267700ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONIMAGESETTINGS_H #define KIMAGEANNOTATOR_ANNOTATIONIMAGESETTINGS_H #include "src/gui/annotator/docks/AbstractAnnotationDockWidgetContent.h" #include "src/widgets/settingsPicker/ImageEffectPicker.h" namespace kImageAnnotator { class AnnotationImageSettings : public AbstractAnnotationDockWidgetContent { Q_OBJECT public: explicit AnnotationImageSettings(); ~AnnotationImageSettings() override; ImageEffects effect() const; void setEffect(ImageEffects effect); QString name() const override; signals: void effectChanged(ImageEffects effect); private: QBoxLayout *mMainLayout; ImageEffectPicker *mEffectPicker; void initGui(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONIMAGESETTINGS_H kImageAnnotator-0.5.3/src/gui/annotator/settings/AnnotationItemSettings.cpp000066400000000000000000000154101414424500400271770ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemSettings.h" namespace kImageAnnotator { AnnotationItemSettings::AnnotationItemSettings() : mMainLayout(new QBoxLayout(QBoxLayout::LeftToRight)), mColorPicker(new ColorPicker(this)), mWidthPicker(new NumberPicker(this)), mTextColorPicker(new ColorPicker(this)), mFillModePicker(new FillModePicker(this)), mNumberToolSeedPicker(new NumberPicker(this)), mObfuscateFactorPicker(new NumberPicker(this)), mStickerPicker(new StickerPicker(this)), mShadowPicker(new BoolPicker(this)), mFontPicker(new FontPicker(this)) { initGui(); } AnnotationItemSettings::~AnnotationItemSettings() { delete mColorPicker; delete mWidthPicker; delete mTextColorPicker; delete mFillModePicker; delete mNumberToolSeedPicker; delete mObfuscateFactorPicker; delete mStickerPicker; delete mShadowPicker; delete mFontPicker; qDeleteAll(mSeparators); } void AnnotationItemSettings::initGui() { mColorPicker->setIcon(IconLoader::load(QLatin1String("color.svg"))); mColorPicker->setToolTip(tr("Color")); mTextColorPicker->setIcon(IconLoader::load(QLatin1String("textColor.svg"))); mTextColorPicker->setToolTip(tr("Text Color")); mWidthPicker->setIcon(IconLoader::load(QLatin1String("width.svg"))); mWidthPicker->setToolTip(tr("Width")); mNumberToolSeedPicker->setIcon(IconLoader::load(QLatin1String("number.svg"))); mNumberToolSeedPicker->setToolTip(tr("Number Seed")); mNumberToolSeedPicker->setRange(1, 100); mObfuscateFactorPicker->setIcon(IconLoader::load(QLatin1String("obfuscateFactor.svg"))); mObfuscateFactorPicker->setToolTip(tr("Obfuscation Factor")); mShadowPicker->setIcon(IconLoader::load(QLatin1String("dropShadow.svg"))); mShadowPicker->setToolTip(tr("Item Shadow")); insertPickerWidget(mColorPicker); insertPickerWidget(mWidthPicker); insertPickerWidget(mFillModePicker); insertPickerWidget(mTextColorPicker); insertPickerWidget(mFontPicker); insertPickerWidget(mNumberToolSeedPicker); insertPickerWidget(mObfuscateFactorPicker); insertPickerWidget(mStickerPicker); insertPickerWidget(mShadowPicker); mWidgetConfigurator.setColorWidget(mColorPicker); mWidgetConfigurator.setTextColorWidget(mTextColorPicker); mWidgetConfigurator.setWidthWidget(mWidthPicker); mWidgetConfigurator.setFillTypeWidget(mFillModePicker); mWidgetConfigurator.setFirstNumberWidget(mNumberToolSeedPicker); mWidgetConfigurator.setObfuscateFactorWidget(mObfuscateFactorPicker); mWidgetConfigurator.setStickerWidget(mStickerPicker); mWidgetConfigurator.setShadowWidget(mShadowPicker); mWidgetConfigurator.setFontWidget(mFontPicker); mMainLayout->setContentsMargins(3, 0, 3, 0); setLayout(mMainLayout); setFocusPolicy(Qt::ClickFocus); connect(mColorPicker, &ColorPicker::colorSelected, this, &AnnotationItemSettings::toolColorChanged); connect(mWidthPicker, &NumberPicker::numberSelected, this, &AnnotationItemSettings::toolWidthChanged); connect(mTextColorPicker, &ColorPicker::colorSelected, this, &AnnotationItemSettings::toolTextColorChanged); connect(mFillModePicker, &FillModePicker::fillSelected, this, &AnnotationItemSettings::toolFillTypeChanged); connect(mNumberToolSeedPicker, &NumberPicker::numberSelected, this, &AnnotationItemSettings::notifyNumberToolSeedChanged); connect(mObfuscateFactorPicker, &NumberPicker::numberSelected, this, &AnnotationItemSettings::obfuscateFactorChanged); connect(mStickerPicker, &StickerPicker::stickerSelected, this, &AnnotationItemSettings::stickerChanged); connect(mShadowPicker, &BoolPicker::enabledStateChanged, this, &AnnotationItemSettings::shadowEnabledChanged); connect(mFontPicker, &FontPicker::fontChanged, this, &AnnotationItemSettings::fontChanged); } void AnnotationItemSettings::insertPickerWidget(SettingsPickerWidget *pickerWidget) { auto separator = new AttachedSeparator(pickerWidget); mMainLayout->addWidget(pickerWidget); mMainLayout->addWidget(separator); addExpandingWidget(pickerWidget); mSeparators.append(separator); } void AnnotationItemSettings::setUpForTool(Tools tool) { mWidgetConfigurator.setCurrentTool(tool); } QColor AnnotationItemSettings::toolColor() const { return mColorPicker->color(); } void AnnotationItemSettings::setToolColor(const QColor &color) { mColorPicker->setColor(color); } QColor AnnotationItemSettings::textColor() const { return mTextColorPicker->color(); } void AnnotationItemSettings::setTextColor(const QColor &color) { mTextColorPicker->setColor(color); } int AnnotationItemSettings::toolWidth() const { return mWidthPicker->number(); } void AnnotationItemSettings::setToolWidth(int width) { mWidthPicker->setNumber(width); } FillModes AnnotationItemSettings::fillMode() const { return mFillModePicker->fillType(); } void AnnotationItemSettings::setFillMode(FillModes mode) { mFillModePicker->setFillType(mode); } int AnnotationItemSettings::obfuscationFactor() const { return mObfuscateFactorPicker->number(); } void AnnotationItemSettings::setObfuscationFactor(int factor) { mObfuscateFactorPicker->setNumber(factor); } QString AnnotationItemSettings::sticker() const { return mStickerPicker->sticker(); } void AnnotationItemSettings::setStickers(const QStringList &stickerPaths, bool keepDefault) { mStickerPicker->setStickers(stickerPaths, keepDefault); } bool AnnotationItemSettings::shadowEnabled() const { return mShadowPicker->enabledState(); } void AnnotationItemSettings::setShadowEnabled(bool enabled) { mShadowPicker->setEnabledState(enabled); } void AnnotationItemSettings::updateNumberToolSeed(int numberToolSeed) { mNumberToolSeedPicker->setNumber(numberToolSeed); } QFont AnnotationItemSettings::font() const { return mFontPicker->currentFont(); } void AnnotationItemSettings::setFont(const QFont &font) { mFontPicker->setCurrentFont(font); } QString AnnotationItemSettings::name() const { return tr("Item Settings"); } void AnnotationItemSettings::setOrientation(Qt::Orientation orientation) { for(auto separator : mSeparators) { separator->setEnabled(orientation == Qt::Horizontal); } AbstractAnnotationDockWidgetContent::setOrientation(orientation); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/annotator/settings/AnnotationItemSettings.h000066400000000000000000000066711414424500400266550ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMSETTINGS_H #define KIMAGEANNOTATOR_ANNOTATIONITEMSETTINGS_H #include "ItemSettingsWidgetConfigurator.h" #include "src/backend/Config.h" #include "src/widgets/settingsPicker/ColorPicker.h" #include "src/widgets/settingsPicker/NumberPicker.h" #include "src/widgets/settingsPicker/FillModePicker.h" #include "src/widgets/settingsPicker/StickerPicker.h" #include "src/widgets/settingsPicker/BoolPicker.h" #include "src/widgets/settingsPicker/FontPicker.h" #include "src/widgets/misc/AttachedSeparator.h" #include "src/gui/annotator/docks/AbstractAnnotationDockWidgetContent.h" #include "src/annotations/properties/AnnotationTextProperties.h" #include "src/annotations/properties/AnnotationObfuscateProperties.h" #include "src/annotations/items/AbstractAnnotationItem.h" namespace kImageAnnotator { class AnnotationItemSettings : public AbstractAnnotationDockWidgetContent { Q_OBJECT public: explicit AnnotationItemSettings(); ~AnnotationItemSettings() override; void setUpForTool(Tools tool); QColor toolColor() const; void setToolColor(const QColor &color); QColor textColor() const; void setTextColor(const QColor &color); int toolWidth() const; void setToolWidth(int width); FillModes fillMode() const; void setFillMode(FillModes mode); int obfuscationFactor() const; void setObfuscationFactor(int factor); QString sticker() const; void setStickers(const QStringList &stickerPaths, bool keepDefault); bool shadowEnabled() const; void setShadowEnabled(bool enabled); void updateNumberToolSeed(int numberToolSeed); QFont font() const; void setFont(const QFont &font); QString name() const override; void setOrientation(Qt::Orientation orientation) override; signals: void toolColorChanged(const QColor &color); void toolTextColorChanged(const QColor &color); void toolWidthChanged(int width); void toolFillTypeChanged(FillModes fill); void notifyNumberToolSeedChanged(int newNumberToolSeed); void obfuscateFactorChanged(int factor); void stickerChanged(const QString &sticker); void shadowEnabledChanged(bool enabled); void fontChanged(const QFont &font); private: QBoxLayout *mMainLayout; ColorPicker *mColorPicker; NumberPicker *mWidthPicker; ColorPicker *mTextColorPicker; FillModePicker *mFillModePicker; NumberPicker *mNumberToolSeedPicker; NumberPicker *mObfuscateFactorPicker; StickerPicker *mStickerPicker; BoolPicker *mShadowPicker; FontPicker *mFontPicker; ItemSettingsWidgetConfigurator mWidgetConfigurator; QList mSeparators; void initGui(); void insertPickerWidget(SettingsPickerWidget *pickerWidget); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONITEMSETTINGS_H kImageAnnotator-0.5.3/src/gui/annotator/settings/AnnotationSettingsAdapter.cpp000066400000000000000000000173221414424500400276650ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationSettingsAdapter.h" namespace kImageAnnotator { AnnotationSettingsAdapter::AnnotationSettingsAdapter( AnnotationGeneralSettings *generalSettings, AnnotationItemSettings *itemSettings, AnnotationToolSelection *toolSettings, AnnotationImageSettings *imageSettings, Config *config) : mGeneralSettings(generalSettings), mItemSettings(itemSettings), mToolSettings(toolSettings), mImageSettings(imageSettings), mConfig(config) { connect(mToolSettings, &AnnotationToolSelection::toolTypeChanged, this, &AnnotationSettingsAdapter::toolTypeChanged); connect(mImageSettings, &AnnotationImageSettings::effectChanged, this, &AnnotationSettingsAdapter::effectChanged); connect(mGeneralSettings, &AnnotationGeneralSettings::zoomValueChanged, this, &AnnotationSettingsAdapter::zoomValueChanged); connect(mItemSettings, &AnnotationItemSettings::toolColorChanged, this, &AnnotationSettingsAdapter::toolColorChanged); connect(mItemSettings, &AnnotationItemSettings::toolWidthChanged, this, &AnnotationSettingsAdapter::toolWidthChanged); connect(mItemSettings, &AnnotationItemSettings::toolTextColorChanged, this, &AnnotationSettingsAdapter::toolTextColorChanged); connect(mItemSettings, &AnnotationItemSettings::toolFillTypeChanged, this, &AnnotationSettingsAdapter::toolFillTypeChanged); connect(mItemSettings, &AnnotationItemSettings::notifyNumberToolSeedChanged, this, &AnnotationSettingsAdapter::notifyNumberToolSeedChanged); connect(mItemSettings, &AnnotationItemSettings::obfuscateFactorChanged, this, &AnnotationSettingsAdapter::obfuscateFactorChanged); connect(mItemSettings, &AnnotationItemSettings::stickerChanged, this, &AnnotationSettingsAdapter::stickerChanged); connect(mItemSettings, &AnnotationItemSettings::shadowEnabledChanged, this, &AnnotationSettingsAdapter::shadowEnabledChanged); connect(mItemSettings, &AnnotationItemSettings::fontChanged, this, &AnnotationSettingsAdapter::fontChanged); reloadConfig(); } void AnnotationSettingsAdapter::editItem(AbstractAnnotationItem *item) { activateSelectTool(); loadFromItem(item); mExistingItemEditInfo.startEdit(item->toolType()); } void AnnotationSettingsAdapter::activateSelectTool() { mToolSettings->setToolType(Tools::Select); mItemSettings->setUpForTool(Tools::Select); } Tools AnnotationSettingsAdapter::toolType() const { return mToolSettings->toolType(); } QColor AnnotationSettingsAdapter::toolColor() const { return mItemSettings->toolColor(); } QColor AnnotationSettingsAdapter::textColor() const { return mItemSettings->textColor(); } int AnnotationSettingsAdapter::toolWidth() const { return mItemSettings->toolWidth(); } QFont AnnotationSettingsAdapter::font() const { return mItemSettings->font(); } FillModes AnnotationSettingsAdapter::fillType() const { return mItemSettings->fillMode(); } int AnnotationSettingsAdapter::obfuscationFactor() const { return mItemSettings->obfuscationFactor(); } QString AnnotationSettingsAdapter::sticker() const { return mItemSettings->sticker(); } ImageEffects AnnotationSettingsAdapter::effect() const { return mImageSettings->effect(); } bool AnnotationSettingsAdapter::shadowEnabled() const { return mItemSettings->shadowEnabled(); } void AnnotationSettingsAdapter::updateNumberToolSeed(int numberToolSeed) { mItemSettings->updateNumberToolSeed(numberToolSeed); } void AnnotationSettingsAdapter::updateZoomLevel(double value) { mGeneralSettings->updateZoomLevel(value); } void AnnotationSettingsAdapter::reloadConfig() { mToolSettings->setToolType(mConfig->selectedTool()); mImageSettings->setEffect(ImageEffects::NoEffect); mItemSettings->setUpForTool(toolType()); } void AnnotationSettingsAdapter::effectChanged(ImageEffects effect) { AbstractSettingsProvider::effectChanged(effect); } void AnnotationSettingsAdapter::zoomValueChanged(double value) { AbstractSettingsProvider::zoomValueChanged(value); } void AnnotationSettingsAdapter::loadFromConfig(Tools tool) { mItemSettings->setUpForTool(tool); mItemSettings->setToolColor(mConfig->toolColor(tool)); mItemSettings->setTextColor(mConfig->toolTextColor(tool)); mItemSettings->setToolWidth(mConfig->toolWidth(tool)); mItemSettings->setFillMode(mConfig->toolFillType(tool)); mItemSettings->setFont(mConfig->toolFont(tool)); mItemSettings->setObfuscationFactor(mConfig->obfuscationFactor(tool)); mItemSettings->setShadowEnabled(mConfig->shadowEnabled(tool)); } void AnnotationSettingsAdapter::loadFromItem(const AbstractAnnotationItem *item) { auto properties = item->properties(); mItemSettings->setUpForTool(item->toolType()); mItemSettings->setToolColor(properties->color()); mItemSettings->setTextColor(properties->textColor()); mItemSettings->setToolWidth(properties->width()); mItemSettings->setFillMode(properties->fillType()); mItemSettings->setShadowEnabled(properties->shadowEnabled()); auto textProperties = properties.dynamicCast(); if(textProperties != nullptr) { mItemSettings->setFont(textProperties->font()); } auto obfuscateProperties = properties.dynamicCast(); if(obfuscateProperties != nullptr) { mItemSettings->setObfuscationFactor(obfuscateProperties->factor()); } } void AnnotationSettingsAdapter::toolTypeChanged(Tools toolType) { mExistingItemEditInfo.stopEdit(); mConfig->setSelectedToolType(toolType); if(!mExistingItemEditInfo.isEdit()) { loadFromConfig(toolType); } toolChanged(toolType); } void AnnotationSettingsAdapter::toolColorChanged(const QColor &color) { configChanged([&](Tools tool){ mConfig->setToolColor(color, tool); }); } void AnnotationSettingsAdapter::toolTextColorChanged(const QColor &color) { configChanged([&](Tools tool){ mConfig->setToolTextColor(color, tool); }); } void AnnotationSettingsAdapter::toolWidthChanged(int width) { configChanged([&](Tools tool){ mConfig->setToolWidth(width, tool); }); } void AnnotationSettingsAdapter::toolFillTypeChanged(FillModes fill) { configChanged([&](Tools tool){ mConfig->setToolFillType(fill, tool); }); } void AnnotationSettingsAdapter::notifyNumberToolSeedChanged(int newNumberToolSeed) { numberToolSeedChanged(newNumberToolSeed); } void AnnotationSettingsAdapter::obfuscateFactorChanged(int factor) { configChanged([&](Tools tool){ mConfig->setObfuscationFactor(factor, tool); }); } void AnnotationSettingsAdapter::stickerChanged(const QString &sticker) { if(mExistingItemEditInfo.isEdit()) { itemSettingChanged(); } } void AnnotationSettingsAdapter::shadowEnabledChanged(bool enabled) { configChanged([&](Tools tool){ mConfig->setShadowEnabled(enabled, tool); }); } void AnnotationSettingsAdapter::fontChanged(const QFont &font) { configChanged([&](Tools tool){ mConfig->setToolFont(font, tool); }); } void AnnotationSettingsAdapter::configChanged(const std::function &configChangedMethod) { if(mExistingItemEditInfo.isEdit()) { itemSettingChanged(); configChangedMethod(mExistingItemEditInfo.toolType()); } else { configChangedMethod(toolType()); } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/annotator/settings/AnnotationSettingsAdapter.h000066400000000000000000000061701414424500400273310ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONSETTINGSADAPTER_H #define KIMAGEANNOTATOR_ANNOTATIONSETTINGSADAPTER_H #include "AnnotationGeneralSettings.h" #include "AnnotationItemSettings.h" #include "AnnotationToolSelection.h" #include "AnnotationImageSettings.h" #include "ExistingItemEditInfo.h" #include "src/annotations/core/AbstractSettingsProvider.h" namespace kImageAnnotator { class AnnotationSettingsAdapter : public QObject, public AbstractSettingsProvider { Q_OBJECT public: explicit AnnotationSettingsAdapter( AnnotationGeneralSettings *generalSettings, AnnotationItemSettings *itemSettings, AnnotationToolSelection *toolSettings, AnnotationImageSettings *imageSettings, Config *config); ~AnnotationSettingsAdapter() override = default; void editItem(AbstractAnnotationItem *item) override; void activateSelectTool() override; Tools toolType() const override; QColor toolColor() const override; QColor textColor() const override; int toolWidth() const override; QFont font() const override; FillModes fillType() const override; int obfuscationFactor() const override; QString sticker() const override; ImageEffects effect() const override; bool shadowEnabled() const override; void updateNumberToolSeed(int numberToolSeed) override; void updateZoomLevel(double value) override; void reloadConfig(); private: AnnotationGeneralSettings *mGeneralSettings; AnnotationItemSettings *mItemSettings; AnnotationToolSelection *mToolSettings; AnnotationImageSettings *mImageSettings; Config *mConfig; ExistingItemEditInfo mExistingItemEditInfo; void configChanged(const std::function& configChangedMethod); private slots: void effectChanged(ImageEffects effect) override; void zoomValueChanged(double value) override; void toolTypeChanged(Tools toolType); void loadFromConfig(Tools tool); void loadFromItem(const AbstractAnnotationItem *item); void toolColorChanged(const QColor &color); void toolTextColorChanged(const QColor &color); void toolWidthChanged(int width); void toolFillTypeChanged(FillModes fill); void notifyNumberToolSeedChanged(int newNumberToolSeed); void obfuscateFactorChanged(int factor); void stickerChanged(const QString &sticker); void shadowEnabledChanged(bool enabled); void fontChanged(const QFont &font); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONSETTINGSADAPTER_H kImageAnnotator-0.5.3/src/gui/annotator/settings/AnnotationToolSelection.cpp000066400000000000000000000036461414424500400273530ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationToolSelection.h" namespace kImageAnnotator { AnnotationToolSelection::AnnotationToolSelection() : mMainLayout(new QVBoxLayout), mToolPicker(new ToolPicker(this)), mScrollAreaToolPicker(new QScrollArea(this)) { mScrollAreaToolPicker->setWidgetResizable(true); mScrollAreaToolPicker->setFrameShape(QFrame::NoFrame); mScrollAreaToolPicker->setWidget(mToolPicker); mMainLayout->addWidget(mScrollAreaToolPicker); mMainLayout->setContentsMargins(0, 0, 0, 0); setLayout(mMainLayout); setFocusPolicy(Qt::ClickFocus); connect(mToolPicker, &ToolPicker::toolSelected, this, &AnnotationToolSelection::toolTypeChanged); } AnnotationToolSelection::~AnnotationToolSelection() { delete mToolPicker; } Tools AnnotationToolSelection::toolType() const { return mToolPicker->tool(); } void AnnotationToolSelection::setToolType(Tools tool) { mToolPicker->setTool(tool); } void AnnotationToolSelection::setOrientation(Qt::Orientation orientation) { AbstractAnnotationDockWidgetContent::setOrientation(orientation); } QString AnnotationToolSelection::name() const { return tr("Tool Selection"); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/annotator/settings/AnnotationToolSelection.h000066400000000000000000000030661414424500400270140ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONTOOLSELECTION_H #define KIMAGEANNOTATOR_ANNOTATIONTOOLSELECTION_H #include "src/gui/annotator/docks/AbstractAnnotationDockWidgetContent.h" #include "src/widgets/ToolPicker.h" namespace kImageAnnotator { class AnnotationToolSelection : public AbstractAnnotationDockWidgetContent { Q_OBJECT public: AnnotationToolSelection(); ~AnnotationToolSelection() override; Tools toolType() const; void setToolType(Tools tool); void setOrientation(Qt::Orientation orientation) override; QString name() const override; signals: void toolTypeChanged(Tools toolType); private: QVBoxLayout *mMainLayout; ToolPicker *mToolPicker; QScrollArea *mScrollAreaToolPicker; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONTOOLSELECTION_H kImageAnnotator-0.5.3/src/gui/annotator/settings/ExistingItemEditInfo.h000066400000000000000000000025521414424500400262300ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_EXISTINGITEMEDITINFO_H #define KIMAGEANNOTATOR_EXISTINGITEMEDITINFO_H namespace kImageAnnotator { struct ExistingItemEditInfo { public: ExistingItemEditInfo() { mIsEdit = false; mToolType = Tools::Select; } void startEdit(Tools tool) { mIsEdit = true; mToolType = tool; } void stopEdit() { mIsEdit = false; } bool isEdit() const { return mIsEdit; } Tools toolType() const { return mToolType; } private: bool mIsEdit; Tools mToolType; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_EXISTINGITEMEDITINFO_H kImageAnnotator-0.5.3/src/gui/annotator/settings/ItemSettingsWidgetConfigurator.cpp000066400000000000000000000245701414424500400307020ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ItemSettingsWidgetConfigurator.h" namespace kImageAnnotator { ItemSettingsWidgetConfigurator::ItemSettingsWidgetConfigurator() : mColorWidget(nullptr), mTextColorWidget(nullptr), mWidthWidget(nullptr), mFillModeWidget(nullptr), mFirstNumberWidget(nullptr), mObfuscateFactorWidget(nullptr), mStickerWidget(nullptr), mShadowPicker(nullptr), mFontPicker(nullptr) { mCurrentTool = Tools::Select; } void ItemSettingsWidgetConfigurator::setCurrentTool(Tools tool) { if (mCurrentTool == tool) { return; } mCurrentTool = tool; updateWidgets(); } void ItemSettingsWidgetConfigurator::setColorWidget(ColorPicker *widget) { mColorWidget = widget; updateWidgets(); } void ItemSettingsWidgetConfigurator::setTextColorWidget(ColorPicker *widget) { mTextColorWidget = widget; updateWidgets(); } void ItemSettingsWidgetConfigurator::setWidthWidget(NumberPicker *widget) { mWidthWidget = widget; updateWidgets(); } void ItemSettingsWidgetConfigurator::setFillTypeWidget(FillModePicker *widget) { mFillModeWidget = widget; updateWidgets(); } void ItemSettingsWidgetConfigurator::setFirstNumberWidget(NumberPicker *widget) { mFirstNumberWidget = widget; updateWidgets(); } void ItemSettingsWidgetConfigurator::setObfuscateFactorWidget(NumberPicker *widget) { mObfuscateFactorWidget = widget; updateWidgets(); } void ItemSettingsWidgetConfigurator::setStickerWidget(StickerPicker *widget) { mStickerWidget = widget; updateWidgets(); } void ItemSettingsWidgetConfigurator::setShadowWidget(BoolPicker *widget) { mShadowPicker = widget; updateWidgets(); } void ItemSettingsWidgetConfigurator::setFontWidget(FontPicker *widget) { mFontPicker = widget; updateWidgets(); } void ItemSettingsWidgetConfigurator::updateWidgets() const { updateProperties(); updateVisibility(); } void ItemSettingsWidgetConfigurator::updateProperties() const { switch (mCurrentTool) { case Tools::Text: case Tools::Number: case Tools::NumberArrow: setNoFillAndNoBorderVisible(true); break; case Tools::MarkerPen: setWidthRange(1, 100); break; default: setNoFillAndNoBorderVisible(false); setWidthRange(1, 20); } } void ItemSettingsWidgetConfigurator::updateVisibility() const { switch (mCurrentTool) { case Tools::Select: setColorWidgetVisible(false); setTextColorWidgetVisible(false); setWidthWidgetVisible(false); setFillWidgetVisible(false); setFirstNumberWidgetVisible(false); setObfuscateFactorWidgetVisible(false); setStickerWidgetVisible(false); setShadowWidgetVisible(false); setFontWidgetVisible(false); break; case Tools::Image: setColorWidgetVisible(false); setTextColorWidgetVisible(false); setWidthWidgetVisible(false); setFillWidgetVisible(false); setFirstNumberWidgetVisible(false); setObfuscateFactorWidgetVisible(false); setStickerWidgetVisible(false); setShadowWidgetVisible(true); setFontWidgetVisible(false); break; case Tools::Pen: setColorWidgetVisible(true); setTextColorWidgetVisible(false); setWidthWidgetVisible(true); setFillWidgetVisible(false); setFirstNumberWidgetVisible(false); setObfuscateFactorWidgetVisible(false); setStickerWidgetVisible(false); setShadowWidgetVisible(true); setFontWidgetVisible(false); break; case Tools::MarkerPen: setColorWidgetVisible(true); setTextColorWidgetVisible(false); setWidthWidgetVisible(true); setFillWidgetVisible(false); setFirstNumberWidgetVisible(false); setObfuscateFactorWidgetVisible(false); setStickerWidgetVisible(false); setShadowWidgetVisible(false); setFontWidgetVisible(false); break; case Tools::MarkerRect: case Tools::MarkerEllipse: setColorWidgetVisible(true); setTextColorWidgetVisible(false); setWidthWidgetVisible(false); setFillWidgetVisible(false); setFirstNumberWidgetVisible(false); setObfuscateFactorWidgetVisible(false); setStickerWidgetVisible(false); setShadowWidgetVisible(false); setFontWidgetVisible(false); break; case Tools::Line: case Tools::Arrow: case Tools::DoubleArrow: setColorWidgetVisible(true); setTextColorWidgetVisible(false); setWidthWidgetVisible(true); setFillWidgetVisible(false); setFirstNumberWidgetVisible(false); setObfuscateFactorWidgetVisible(false); setStickerWidgetVisible(false); setShadowWidgetVisible(true); setFontWidgetVisible(false); break; case Tools::Ellipse: case Tools::Rect: setColorWidgetVisible(true); setTextColorWidgetVisible(false); setWidthWidgetVisible(true); setFillWidgetVisible(true); setFirstNumberWidgetVisible(false); setObfuscateFactorWidgetVisible(false); setStickerWidgetVisible(false); setShadowWidgetVisible(true); setFontWidgetVisible(false); break; case Tools::Number: setColorWidgetVisible(true); setTextColorWidgetVisible(true); setWidthWidgetVisible(true); setFillWidgetVisible(true); setFirstNumberWidgetVisible(true); setObfuscateFactorWidgetVisible(false); setStickerWidgetVisible(false); setShadowWidgetVisible(true); setFontWidgetVisible(true); break; case Tools::NumberPointer: setColorWidgetVisible(true); setTextColorWidgetVisible(true); setWidthWidgetVisible(false); setFillWidgetVisible(false); setFirstNumberWidgetVisible(true); setObfuscateFactorWidgetVisible(false); setStickerWidgetVisible(false); setShadowWidgetVisible(true); setFontWidgetVisible(true); break; case Tools::NumberArrow: setColorWidgetVisible(true); setTextColorWidgetVisible(true); setWidthWidgetVisible(true); setFillWidgetVisible(true); setFirstNumberWidgetVisible(true); setObfuscateFactorWidgetVisible(false); setStickerWidgetVisible(false); setShadowWidgetVisible(true); setFontWidgetVisible(true); break; case Tools::Text: setColorWidgetVisible(true); setTextColorWidgetVisible(true); setWidthWidgetVisible(true); setFillWidgetVisible(true); setFirstNumberWidgetVisible(false); setObfuscateFactorWidgetVisible(false); setStickerWidgetVisible(false); setShadowWidgetVisible(true); setFontWidgetVisible(true); break; case Tools::TextPointer: setColorWidgetVisible(true); setTextColorWidgetVisible(true); setWidthWidgetVisible(false); setFillWidgetVisible(false); setFirstNumberWidgetVisible(false); setObfuscateFactorWidgetVisible(false); setStickerWidgetVisible(false); setShadowWidgetVisible(true); setFontWidgetVisible(true); break; case Tools::TextArrow: setColorWidgetVisible(true); setTextColorWidgetVisible(true); setWidthWidgetVisible(true); setFillWidgetVisible(true); setFirstNumberWidgetVisible(false); setObfuscateFactorWidgetVisible(false); setStickerWidgetVisible(false); setShadowWidgetVisible(true); setFontWidgetVisible(true); break; case Tools::Blur: case Tools::Pixelate: setColorWidgetVisible(false); setTextColorWidgetVisible(false); setWidthWidgetVisible(false); setFillWidgetVisible(false); setFirstNumberWidgetVisible(false); setObfuscateFactorWidgetVisible(true); setStickerWidgetVisible(false); setShadowWidgetVisible(false); setFontWidgetVisible(false); break; case Tools::Sticker: setColorWidgetVisible(false); setTextColorWidgetVisible(false); setWidthWidgetVisible(false); setFillWidgetVisible(false); setFirstNumberWidgetVisible(false); setObfuscateFactorWidgetVisible(false); setStickerWidgetVisible(true); setShadowWidgetVisible(true); setFontWidgetVisible(false); break; case Tools::Duplicate: setColorWidgetVisible(false); setTextColorWidgetVisible(false); setWidthWidgetVisible(false); setFillWidgetVisible(false); setFirstNumberWidgetVisible(false); setObfuscateFactorWidgetVisible(false); setStickerWidgetVisible(false); setShadowWidgetVisible(false); setFontWidgetVisible(false); break; default: qCritical("Unknown tooltype in WidgetConfigurator"); } } void ItemSettingsWidgetConfigurator::setColorWidgetVisible(bool enabled) const { if (mColorWidget) { mColorWidget->setVisible(enabled); } } void ItemSettingsWidgetConfigurator::setTextColorWidgetVisible(bool enabled) const { if (mTextColorWidget) { mTextColorWidget->setVisible(enabled); } } void ItemSettingsWidgetConfigurator::setWidthWidgetVisible(bool enabled) const { if (mWidthWidget) { mWidthWidget->setVisible(enabled); } } void ItemSettingsWidgetConfigurator::setFillWidgetVisible(bool enabled) const { if (mFillModeWidget) { mFillModeWidget->setVisible(enabled); } } void ItemSettingsWidgetConfigurator::setFirstNumberWidgetVisible(bool enabled) const { if (mFirstNumberWidget) { mFirstNumberWidget->setVisible(enabled); } } void ItemSettingsWidgetConfigurator::setNoFillAndNoBorderVisible(bool enabled) const { if (mFillModeWidget) { if (enabled) { mFillModeWidget->addNoFillAndNoBorderToList(); } else { mFillModeWidget->removeNoFillAndNoBorderToList(); } } } void ItemSettingsWidgetConfigurator::setObfuscateFactorWidgetVisible(bool enabled) const { if (mObfuscateFactorWidget) { mObfuscateFactorWidget->setVisible(enabled); } } void ItemSettingsWidgetConfigurator::setStickerWidgetVisible(bool enabled) const { if (mStickerWidget) { mStickerWidget->setVisible(enabled); } } void ItemSettingsWidgetConfigurator::setShadowWidgetVisible(bool enabled) const { if (mShadowPicker) { mShadowPicker->setVisible(enabled); } } void ItemSettingsWidgetConfigurator::setFontWidgetVisible(bool enabled) const { if (mFontPicker) { mFontPicker->setVisible(enabled); } } void ItemSettingsWidgetConfigurator::setWidthRange(int min, int max) const { if (mWidthWidget) { mWidthWidget->setRange(min, max); } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/annotator/settings/ItemSettingsWidgetConfigurator.h000066400000000000000000000056701414424500400303470ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_WIDGETCONFIGURATORSWITCHER_H #define KIMAGEANNOTATOR_WIDGETCONFIGURATORSWITCHER_H #include #include "src/common/enum/Tools.h" #include "src/widgets/settingsPicker/ColorPicker.h" #include "src/widgets/settingsPicker/FillModePicker.h" #include "src/widgets/ToolPicker.h" #include "src/widgets/settingsPicker/NumberPicker.h" #include "src/widgets/settingsPicker/StickerPicker.h" #include "src/widgets/settingsPicker/BoolPicker.h" #include "src/widgets/settingsPicker/FontPicker.h" namespace kImageAnnotator { class ItemSettingsWidgetConfigurator { public: explicit ItemSettingsWidgetConfigurator(); ~ItemSettingsWidgetConfigurator() = default; void setCurrentTool(Tools tool); void setColorWidget(ColorPicker *widget); void setTextColorWidget(ColorPicker *widget); void setWidthWidget(NumberPicker *widget); void setFillTypeWidget(FillModePicker *widget); void setFirstNumberWidget(NumberPicker *widget); void setObfuscateFactorWidget(NumberPicker *widget); void setStickerWidget(StickerPicker *widget); void setShadowWidget(BoolPicker *widget); void setFontWidget(FontPicker *widget); private: Tools mCurrentTool; ColorPicker *mColorWidget; ColorPicker *mTextColorWidget; NumberPicker *mWidthWidget; FillModePicker *mFillModeWidget; NumberPicker *mFirstNumberWidget; NumberPicker *mObfuscateFactorWidget; StickerPicker *mStickerWidget; BoolPicker *mShadowPicker; FontPicker *mFontPicker; void updateWidgets() const; void updateProperties() const; void updateVisibility() const; void setColorWidgetVisible(bool enabled) const; void setTextColorWidgetVisible(bool enabled) const; void setWidthWidgetVisible(bool enabled) const; void setFillWidgetVisible(bool enabled) const; void setFirstNumberWidgetVisible(bool enabled) const; void setNoFillAndNoBorderVisible(bool enabled) const; void setObfuscateFactorWidgetVisible(bool enabled) const; void setStickerWidgetVisible(bool enabled) const; void setShadowWidgetVisible(bool enabled) const; void setFontWidgetVisible(bool enabled) const; void setWidthRange(int min, int max) const; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_WIDGETCONFIGURATORSWITCHER_H kImageAnnotator-0.5.3/src/gui/annotator/tabs/000077500000000000000000000000001414424500400211115ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/gui/annotator/tabs/AnnotationTabCloser.cpp000066400000000000000000000041631414424500400255320ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationTabCloser.h" namespace kImageAnnotator { AnnotationTabCloser::AnnotationTabCloser(QTabWidget *parent) : QObject(parent), mTabWidget(parent) { Q_ASSERT(mTabWidget != nullptr); } void AnnotationTabCloser::closeTabTriggered(int index) { mTabWidget->tabCloseRequested(getValidIndex(index)); } void AnnotationTabCloser::closeOtherTabsTriggered(int index) { auto selectedWidget = mTabWidget->widget(getValidIndex(index)); auto tabCount = mTabWidget->count(); for(auto i = tabCount - 1; i >= 0; i--) { auto currentWidget = mTabWidget->widget(i); if(currentWidget != selectedWidget) { mTabWidget->tabCloseRequested(i); } } } void AnnotationTabCloser::closeAllTabsTriggered() { auto tabCount = mTabWidget->count(); for(auto i = tabCount - 1; i >= 0; i--) { mTabWidget->tabCloseRequested(i); } } void AnnotationTabCloser::closeAllTabsToLeftTriggered(int index) { for(auto i = index - 1; i >= 0; i--) { mTabWidget->tabCloseRequested(i); } } void AnnotationTabCloser::closeAllTabsToRightTriggered(int index) { auto tabCount = mTabWidget->count(); for(auto i = tabCount - 1; i > index; i--) { mTabWidget->tabCloseRequested(i); } } int AnnotationTabCloser::getValidIndex(int index) const { return index >= 0 && index < mTabWidget->count() ? index : mTabWidget->currentIndex(); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/annotator/tabs/AnnotationTabCloser.h000066400000000000000000000027541414424500400252030ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONTABCLOSER_H #define KIMAGEANNOTATOR_ANNOTATIONTABCLOSER_H #include #include namespace kImageAnnotator { class AnnotationTabCloser : public QObject { Q_OBJECT public: explicit AnnotationTabCloser(QTabWidget *parent); ~AnnotationTabCloser() override = default; public slots: void closeTabTriggered(int index); void closeOtherTabsTriggered(int index); void closeAllTabsTriggered(); void closeAllTabsToLeftTriggered(int index); void closeAllTabsToRightTriggered(int index); private: QTabWidget *mTabWidget; int getValidIndex(int index) const; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONTABCLOSER_H kImageAnnotator-0.5.3/src/gui/annotator/tabs/AnnotationTabContent.cpp000066400000000000000000000035641414424500400257210ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationTabContent.h" namespace kImageAnnotator { AnnotationTabContent::AnnotationTabContent(const QPixmap &pixmap, Config *config, AbstractSettingsProvider *settingsProvider) : mAnnotationView(new AnnotationView(this)), mZoomValueProvider(mAnnotationView->zoomValueProvider()), mAnnotationArea(new AnnotationArea(config, settingsProvider, new DevicePixelRatioScaler, mZoomValueProvider, this)), mMainLayout(new QHBoxLayout(this)), mSettingsProvider(settingsProvider) { mAnnotationView->setScene(mAnnotationArea); mAnnotationArea->loadImage(pixmap); mMainLayout->addWidget(mAnnotationView); setLayout(mMainLayout); connect(mZoomValueProvider, &ZoomValueProvider::zoomValueChanged, this, &AnnotationTabContent::zoomValueChange); } AnnotationArea* AnnotationTabContent::annotationArea() const { return mAnnotationArea; } ZoomValueProvider *AnnotationTabContent::zoomValueProvider() const { return mAnnotationView->zoomValueProvider(); } void AnnotationTabContent::zoomValueChange(double value) { mSettingsProvider->updateZoomLevel(value); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/annotator/tabs/AnnotationTabContent.h000066400000000000000000000034101414424500400253540ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef ANNOTATIONTAB_H #define ANNOTATIONTAB_H #include #include #include "src/gui/annotator/AnnotationView.h" #include "src/gui/annotator/settings/AnnotationItemSettings.h" #include "src/annotations/core/AnnotationArea.h" #include "src/common/provider/DevicePixelRatioScaler.h" #include "src/gui/scrollAndZoomView/ViewZoomer.h" namespace kImageAnnotator { class AnnotationTabContent : public QWidget { Q_OBJECT public: AnnotationTabContent(const QPixmap &pixmap, Config *config, AbstractSettingsProvider *settingsProvider); ~AnnotationTabContent() override = default; AnnotationArea* annotationArea() const; ZoomValueProvider* zoomValueProvider() const; private: AnnotationView *mAnnotationView; ZoomValueProvider *mZoomValueProvider; AnnotationArea *mAnnotationArea; QHBoxLayout *mMainLayout; AbstractSettingsProvider *mSettingsProvider; private slots: void zoomValueChange(double value); }; } // namespace kImageAnnotator #endif //ANNOTATIONTAB_H kImageAnnotator-0.5.3/src/gui/annotator/tabs/AnnotationTabContextMenu.cpp000066400000000000000000000104321414424500400265500ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationTabContextMenu.h" namespace kImageAnnotator { AnnotationTabContextMenu::AnnotationTabContextMenu(QWidget *parent) : QMenu(parent), mCloseTab(new QAction(this)), mClosedOtherTabs(new QAction(this)), mCloseAllTabs(new QAction(this)), mCloseAllTabsToLeft(new QAction(this)), mCloseAllTabsToRight(new QAction(this)), mTabIndex(-1) { mCloseTab->setText(tr("Close")); mClosedOtherTabs->setText(tr("Close Other")); mCloseAllTabs->setText(tr("Close All")); mCloseAllTabsToLeft->setText(tr("Close All to the Left")); mCloseAllTabsToRight->setText(tr("Close All to the Right")); mCloseTab->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_W)); mCloseTab->setShortcutContext(Qt::ApplicationShortcut); parent->addAction(mCloseTab); connect(mCloseTab, &QAction::triggered, this, &AnnotationTabContextMenu::closeTabTriggered); connect(mClosedOtherTabs, &QAction::triggered, this, &AnnotationTabContextMenu::closeOtherTabsTriggered); connect(mCloseAllTabs, &QAction::triggered, this, &AnnotationTabContextMenu::closeAllTabsTriggered); connect(mCloseAllTabsToLeft, &QAction::triggered, this, &AnnotationTabContextMenu::closeAllTabsToLeftTriggered); connect(mCloseAllTabsToRight, &QAction::triggered, this, &AnnotationTabContextMenu::closeAllTabsToRightTriggered); addAction(mCloseTab); addAction(mClosedOtherTabs); addAction(mCloseAllTabs); addAction(mCloseAllTabsToLeft); addAction(mCloseAllTabsToRight); } AnnotationTabContextMenu::~AnnotationTabContextMenu() { delete mCloseTab; delete mClosedOtherTabs; delete mCloseAllTabs; qDeleteAll(mCustomActionMap.keys()); } void AnnotationTabContextMenu::show(int tabIndex, const QPoint &pos) { mTabIndex = tabIndex; exec(pos); mTabIndex = -1; } void AnnotationTabContextMenu::closeTabTriggered() const { emit closeTab(mTabIndex); } void AnnotationTabContextMenu::closeOtherTabsTriggered() const { emit closeOtherTabs(mTabIndex); } void AnnotationTabContextMenu::closeAllTabsTriggered() const { emit closeAllTabs(); } void AnnotationTabContextMenu::closeAllTabsToLeftTriggered() const { emit closeAllTabsToLeft(mTabIndex); } void AnnotationTabContextMenu::closeAllTabsToRightTriggered() const { emit closeAllTabsToRight(mTabIndex); } void AnnotationTabContextMenu::addCustomActions(const QList &customActions) { addSeparator(); for(auto innerAction : customActions) { if(innerAction->isSeparator()) { addSeparator(); } else { addCustomAction(innerAction); } } } void AnnotationTabContextMenu::addCustomAction(QAction *innerAction) { auto outerAction = new QAction(this); outerAction->setText(innerAction->text()); outerAction->setIcon(innerAction->icon()); outerAction->setToolTip(innerAction->toolTip()); outerAction->setEnabled(innerAction->isEnabled()); mCustomActionMap[outerAction] = innerAction; connect(innerAction, &QAction::changed, this, &AnnotationTabContextMenu::customActionChanged); connect(outerAction, &QAction::triggered, this, &AnnotationTabContextMenu::customActionTriggered); addAction(outerAction); } void AnnotationTabContextMenu::customActionTriggered() { auto outerAction = dynamic_cast(sender()); auto innerAction = mCustomActionMap.value(outerAction); innerAction->setData(mTabIndex); innerAction->trigger(); } void AnnotationTabContextMenu::customActionChanged() { auto innerAction = dynamic_cast(sender()); auto outerAction = mCustomActionMap.key(innerAction); outerAction->setEnabled(innerAction->isEnabled()); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/gui/annotator/tabs/AnnotationTabContextMenu.h000066400000000000000000000037671414424500400262320ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONTABCONTEXTMENU_H #define KIMAGEANNOTATOR_ANNOTATIONTABCONTEXTMENU_H #include namespace kImageAnnotator { class AnnotationTabContextMenu : public QMenu { Q_OBJECT public: explicit AnnotationTabContextMenu(QWidget *parent); ~AnnotationTabContextMenu() override; void show(int tabIndex, const QPoint &pos); void addCustomActions(const QList & customActions); signals: void closeTab(int index) const; void closeOtherTabs(int index) const; void closeAllTabs() const; void closeAllTabsToLeft(int index) const; void closeAllTabsToRight(int index) const; private: int mTabIndex; QAction *mCloseTab; QAction *mClosedOtherTabs; QAction *mCloseAllTabs; QAction *mCloseAllTabsToLeft; QAction *mCloseAllTabsToRight; QHash mCustomActionMap; void closeTabTriggered() const; void closeOtherTabsTriggered() const; void closeAllTabsTriggered() const; void closeAllTabsToLeftTriggered() const; void closeAllTabsToRightTriggered() const; private slots: void customActionTriggered(); void customActionChanged(); void addCustomAction(QAction *innerAction); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONTABCONTEXTMENU_H kImageAnnotator-0.5.3/src/gui/annotator/tabs/AnnotationTabWidget.cpp000066400000000000000000000116351414424500400255300ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationTabWidget.h" namespace kImageAnnotator { AnnotationTabWidget::AnnotationTabWidget(Config *config, AbstractSettingsProvider *settingsProvider) : mConfig(config), mTabBar(tabBar()), mSettingsProvider(settingsProvider), mRedoAction(new QAction(this)), mUndoAction(new QAction(this)), mTabContextMenu(new AnnotationTabContextMenu(this)), mTabCloser(new AnnotationTabCloser(this)) { setTabBarAutoHide(true); setMovable(true); setTabsClosable(true); mTabBar->setContextMenuPolicy(Qt::CustomContextMenu); connect(mUndoAction, &QAction::triggered, this, &AnnotationTabWidget::undoTriggered); connect(mRedoAction, &QAction::triggered, this, &AnnotationTabWidget::redoTriggered); connect(mTabBar, &QTabBar::tabMoved, this, &AnnotationTabWidget::tabMoved); connect(mTabBar, &QTabBar::customContextMenuRequested, this, &AnnotationTabWidget::showTabContextMenu); connect(mTabBar, &QTabBar::currentChanged, this, &AnnotationTabWidget::tabChanged); connect(mTabContextMenu, &AnnotationTabContextMenu::closeTab, mTabCloser, &AnnotationTabCloser::closeTabTriggered); connect(mTabContextMenu, &AnnotationTabContextMenu::closeOtherTabs, mTabCloser, &AnnotationTabCloser::closeOtherTabsTriggered); connect(mTabContextMenu, &AnnotationTabContextMenu::closeAllTabs, mTabCloser, &AnnotationTabCloser::closeAllTabsTriggered); connect(mTabContextMenu, &AnnotationTabContextMenu::closeAllTabsToLeft, mTabCloser, &AnnotationTabCloser::closeAllTabsToLeftTriggered); connect(mTabContextMenu, &AnnotationTabContextMenu::closeAllTabsToRight, mTabCloser, &AnnotationTabCloser::closeAllTabsToRightTriggered); } int AnnotationTabWidget::addTab(const QPixmap &image, const QString &title, const QString &toolTip) { auto content = new AnnotationTabContent(image, mConfig, mSettingsProvider); connect(content->annotationArea(), &AnnotationArea::imageChanged, this, &AnnotationTabWidget::imageChanged); return QTabWidget::addTab(content, title); } AnnotationArea* AnnotationTabWidget::currentAnnotationArea() const { return currentWidget() != nullptr ? dynamic_cast(currentWidget())->annotationArea() : nullptr; } AnnotationArea *AnnotationTabWidget::annotationAreaAt(int index) const { return widget(index) != nullptr ? dynamic_cast(widget(index))->annotationArea() : nullptr; } ZoomValueProvider *AnnotationTabWidget::currentZoomValueProvider() const { return currentWidget() != nullptr ? dynamic_cast(currentWidget())->zoomValueProvider() : nullptr; } QAction *AnnotationTabWidget::undoAction() const { return mUndoAction; } QAction *AnnotationTabWidget::redoAction() const { return mRedoAction; } void AnnotationTabWidget::updateTabInfo(int index, const QString &title, const QString &toolTip) { setTabText(index, title); setTabToolTip(index, toolTip); } void AnnotationTabWidget::setUndoRedoEnabled(bool enabled) { mUndoAction->setEnabled(enabled); mRedoAction->setEnabled(enabled); } void AnnotationTabWidget::tabInserted(int index) { updateCurrentWidget(index); QTabWidget::tabInserted(index); } void AnnotationTabWidget::tabRemoved(int index) { QTabWidget::tabRemoved(index); } void AnnotationTabWidget::undoTriggered() const { auto annotationArea = currentAnnotationArea(); if(annotationArea != nullptr) { annotationArea->undoAction()->trigger(); } } void AnnotationTabWidget::redoTriggered() const { auto annotationArea = currentAnnotationArea(); if(annotationArea != nullptr) { annotationArea->redoAction()->trigger(); } } void AnnotationTabWidget::updateCurrentWidget(int index) { setCurrentIndex(index); } void AnnotationTabWidget::showTabContextMenu(const QPoint &pos) { if (!pos.isNull()) { int tabIndex = mTabBar->tabAt(pos); emit tabContextMenuOpened(tabIndex); mTabContextMenu->show(tabIndex, mTabBar->mapToGlobal(pos)); } } void AnnotationTabWidget::tabChanged() { mSettingsProvider->setActiveListener(currentAnnotationArea()); mSettingsProvider->setActiveZoomValueProvider(currentZoomValueProvider()); } void AnnotationTabWidget::addContextMenuActions(const QList &actions) { mTabContextMenu->addCustomActions(actions); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/gui/annotator/tabs/AnnotationTabWidget.h000066400000000000000000000045351414424500400251760ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef ANNOTATIONTABWIDGET_H #define ANNOTATIONTABWIDGET_H #include #include #include "AnnotationTabContent.h" #include "AnnotationTabContextMenu.h" #include "AnnotationTabCloser.h" namespace kImageAnnotator { class AnnotationTabWidget : public QTabWidget { Q_OBJECT public: AnnotationTabWidget(Config *config, AbstractSettingsProvider *settingsProvider); ~AnnotationTabWidget() override = default; int addTab(const QPixmap &image, const QString &title, const QString &toolTip); AnnotationArea* currentAnnotationArea() const; AnnotationArea *annotationAreaAt(int index) const; ZoomValueProvider* currentZoomValueProvider() const; QAction* undoAction() const; QAction* redoAction() const; void updateTabInfo(int index, const QString &title, const QString &toolTip); void setUndoRedoEnabled(bool enabled); void addContextMenuActions(const QList & actions); signals: void imageChanged() const; void tabMoved(int fromIndex, int toIndex) const; void tabContextMenuOpened(int index) const; protected: void tabInserted(int index) override; void tabRemoved(int index) override; private: Config *mConfig; QTabBar *mTabBar; AbstractSettingsProvider *mSettingsProvider; QAction *mUndoAction; QAction *mRedoAction; AnnotationTabContextMenu *mTabContextMenu; AnnotationTabCloser *mTabCloser; private slots: void undoTriggered() const; void redoTriggered() const; void updateCurrentWidget(int index); void showTabContextMenu(const QPoint &pos); void tabChanged(); }; } // namespace kImageAnnotator #endif //ANNOTATIONTABWIDGET_H kImageAnnotator-0.5.3/src/gui/canvasModifier/000077500000000000000000000000001414424500400211055ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/gui/canvasModifier/ModifyCanvasSelectionRestrictor.cpp000066400000000000000000000041571414424500400301320ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ModifyCanvasSelectionRestrictor.h" namespace kImageAnnotator { QRectF &ModifyCanvasSelectionRestrictor::restrictResize(QRectF &newRect, const QRectF ¤tRect, const QRectF &rectLimit) const { if (newRect.x() > rectLimit.x()) { newRect.setX(rectLimit.x()); } if (newRect.y() > rectLimit.y()) { newRect.setY(rectLimit.y()); } if (newRect.right() < rectLimit.right()) { newRect.setRight(rectLimit.right()); } if (newRect.height() < rectLimit.height()) { newRect.setHeight(rectLimit.height()); } if (newRect.x() + newRect.width() < rectLimit.width()) { newRect.setWidth(rectLimit.width() - newRect.x()); } if (newRect.y() + newRect.height() < rectLimit.height()) { newRect.setHeight(rectLimit.height() - newRect.y()); } return newRect; } QRectF &ModifyCanvasSelectionRestrictor::restrictMove(QRectF &newRect, const QRectF &rectLimit) const { if (newRect.x() > rectLimit.x()) { newRect.moveLeft(rectLimit.x()); } if (newRect.y() > rectLimit.y()) { newRect.moveTop(rectLimit.y()); } if ((newRect.x() + newRect.width()) < rectLimit.width()) { newRect.moveTo(rectLimit.width() - newRect.width(), newRect.y()); } if ((newRect.y() + newRect.height()) < rectLimit.height()) { newRect.moveTo(newRect.x(), rectLimit.height() - newRect.height()); } return newRect; } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/gui/canvasModifier/ModifyCanvasSelectionRestrictor.h000066400000000000000000000027351414424500400275770ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CANVASMDIFIERSELECTIONRESTRICTOR_H #define KIMAGEANNOTATOR_CANVASMDIFIERSELECTIONRESTRICTOR_H #include #include "src/gui/selection/ISelectionRestrictor.h" namespace kImageAnnotator { class ModifyCanvasSelectionRestrictor : public ISelectionRestrictor { public: explicit ModifyCanvasSelectionRestrictor() = default; ~ModifyCanvasSelectionRestrictor() override = default; QRectF &restrictResize(QRectF &newRect, const QRectF ¤tRect, const QRectF &rectLimit) const override; QRectF &restrictMove(QRectF &newRect, const QRectF &rectLimit) const override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_CANVASMDIFIERSELECTIONRESTRICTOR_H kImageAnnotator-0.5.3/src/gui/canvasModifier/ModifyCanvasView.cpp000066400000000000000000000033211414424500400250260ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ModifyCanvasView.h" namespace kImageAnnotator { ModifyCanvasView::ModifyCanvasView(SelectionHandler *selectionHandler, KeyHelper *keyHelper, QWidget *parent) : BaseSelectionView(selectionHandler, keyHelper, parent) { setViewportUpdateMode(ViewportUpdateMode::FullViewportUpdate); } void ModifyCanvasView::setCanvasRect(const QRectF &rect) { mCanvasRect = rect; } void ModifyCanvasView::setCanvasColor(const QColor &color) { mCanvasColor = color; } void ModifyCanvasView::drawForeground(QPainter *painter, const QRectF &rect) { painter->setClipRegion(QRegion(rect.toRect()).subtracted(QRegion(currentSelection().toRect()))); painter->setBrush(QColor(0, 0, 0, 150)); painter->drawRect(rect); BaseSelectionView::drawForeground(painter, rect); } void ModifyCanvasView::drawBackground(QPainter *painter, const QRectF &rect) { mCanvasPainter.paint(painter, mCanvasRect, mCanvasColor); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/canvasModifier/ModifyCanvasView.h000066400000000000000000000031411414424500400244730ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_MODIFYCANVASVIEW_H #define KIMAGEANNOTATOR_MODIFYCANVASVIEW_H #include "src/gui/selection/BaseSelectionView.h" #include "src/annotations/misc/CanvasPainter.h" namespace kImageAnnotator { class ModifyCanvasView : public BaseSelectionView { Q_OBJECT public: explicit ModifyCanvasView(SelectionHandler *selectionHandler, KeyHelper *keyHelper, QWidget *parent); ~ModifyCanvasView() override = default; void setCanvasRect(const QRectF &rect); void setCanvasColor(const QColor &color); protected: void drawForeground(QPainter *painter, const QRectF &rect) override; void drawBackground(QPainter *painter, const QRectF &rect) override; private: CanvasPainter mCanvasPainter; QRectF mCanvasRect; QColor mCanvasColor; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_MODIFYCANVASVIEW_H kImageAnnotator-0.5.3/src/gui/canvasModifier/ModifyCanvasWidget.cpp000066400000000000000000000170431414424500400253450ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ModifyCanvasWidget.h" namespace kImageAnnotator { ModifyCanvasWidget::ModifyCanvasWidget() : mAnnotationArea(nullptr), mSelectionHandler(new SelectionHandler(new ModifyCanvasSelectionRestrictor)), mModifyCanvasView(new ModifyCanvasView(mSelectionHandler, mKeyHelper, this)), mKeyHelper(new KeyHelper()), mApplyButton(new QPushButton(this)), mCancelButton(new QPushButton(this)), mPanelLayout(new QHBoxLayout), mPositionXLabel(new QLabel(this)), mPositionYLabel(new QLabel(this)), mHeightLabel(new QLabel(this)), mWidthLabel(new QLabel(this)), mColorLabel(new QLabel(this)), mPositionXLineEdit(new QLineEdit(this)), mPositionYLineEdit(new QLineEdit(this)), mWidthLineEdit(new QLineEdit(this)), mHeightLineEdit(new QLineEdit(this)), mMainLayout(new QVBoxLayout(this)), mInputValidator(new QIntValidator(-9999, 9999, this)), mRestrictCheckBox(new QCheckBox(this)), mColorDialogButton(new ColorDialogButton(this)), mZoomPicker(new ZoomPicker(this)) { initSelectionHandler(); initKeyHelper(); initGui(); initZoomPicker(); } ModifyCanvasWidget::~ModifyCanvasWidget() { delete mKeyHelper; delete mColorDialogButton; delete mZoomPicker; delete mSelectionHandler; } void ModifyCanvasWidget::activate(AnnotationArea *annotationArea) { Q_ASSERT(annotationArea != nullptr); mAnnotationArea = annotationArea; mSelectionHandler->init(annotationArea); mModifyCanvasView->init(annotationArea); reset(); setFocus(); } void ModifyCanvasWidget::keyReleaseEvent(QKeyEvent *event) { mKeyHelper->keyRelease(event); QWidget::keyReleaseEvent(event); } void ModifyCanvasWidget::initGui() { mRestrictCheckBox->setText(tr("Restricted")); mRestrictCheckBox->setToolTip(tr("When enabled enforces the canvas\n" "to include the background image.")); mRestrictCheckBox->setChecked(mSelectionHandler->restrictionEnabled()); connect(mRestrictCheckBox, &QCheckBox::stateChanged, this, &ModifyCanvasWidget::restrictionChanged); auto width = ScaledSizeProvider::scaledWidth(80); mPositionXLabel->setText(tr("X:")); mPositionXLineEdit->setValidator(mInputValidator); mPositionXLineEdit->setFixedSize(width, mPositionXLineEdit->minimumSizeHint().height()); connect(mPositionXLineEdit, &QLineEdit::textEdited, this, &ModifyCanvasWidget::xChanged); mPositionYLabel->setText(tr("Y:")); mPositionYLineEdit->setValidator(mInputValidator); mPositionYLineEdit->setFixedSize(width, mPositionYLineEdit->minimumSizeHint().height()); connect(mPositionYLineEdit, &QLineEdit::textEdited, this, &ModifyCanvasWidget::yChanged); mWidthLabel->setText(tr("W:")); mWidthLineEdit->setValidator(mInputValidator); mWidthLineEdit->setFixedSize(width, mWidthLineEdit->minimumSizeHint().height()); connect(mWidthLineEdit, &QLineEdit::textEdited, this, &ModifyCanvasWidget::widthChanged); mHeightLabel->setText(tr("H:")); mHeightLineEdit->setValidator(mInputValidator); mHeightLineEdit->setFixedSize(width, mHeightLineEdit->minimumSizeHint().height()); connect(mHeightLineEdit, &QLineEdit::textEdited, this, &ModifyCanvasWidget::heightChanged); mColorLabel->setText(tr("Color:")); mColorLabel->setToolTip(tr("Canvas Background Color")); connect(mColorDialogButton, &ColorDialogButton::colorChanged, mModifyCanvasView, &ModifyCanvasView::setCanvasColor); mApplyButton->setText(tr("Apply")); connect(mApplyButton, &QPushButton::clicked, this, &ModifyCanvasWidget::apply); mCancelButton->setText(tr("Cancel")); connect(mCancelButton, &QPushButton::clicked, this, &ModifyCanvasWidget::closing); mPanelLayout->setAlignment(Qt::AlignCenter); mPanelLayout->addWidget(mZoomPicker); mPanelLayout->addStretch(1); mPanelLayout->addWidget(mRestrictCheckBox); mPanelLayout->addSpacing(10); mPanelLayout->addWidget(mColorLabel); mPanelLayout->addWidget(mColorDialogButton); mPanelLayout->addSpacing(10); mPanelLayout->addWidget(mPositionXLabel); mPanelLayout->addWidget(mPositionXLineEdit); mPanelLayout->addWidget(mPositionYLabel); mPanelLayout->addWidget(mPositionYLineEdit); mPanelLayout->addWidget(mWidthLabel); mPanelLayout->addWidget(mWidthLineEdit); mPanelLayout->addWidget(mHeightLabel); mPanelLayout->addWidget(mHeightLineEdit); mPanelLayout->addStretch(1); mPanelLayout->addWidget(mApplyButton); mPanelLayout->addWidget(mCancelButton); mMainLayout->addWidget(mModifyCanvasView); mMainLayout->addLayout(mPanelLayout); setLayout(mMainLayout); } void ModifyCanvasWidget::initKeyHelper() { connect(mKeyHelper, &KeyHelper::escapeReleased, this, &ModifyCanvasWidget::closing); connect(mKeyHelper, &KeyHelper::returnReleased, this, &ModifyCanvasWidget::apply); connect(mKeyHelper, &KeyHelper::enterReleased, this, &ModifyCanvasWidget::apply); } void ModifyCanvasWidget::initSelectionHandler() const { connect(mSelectionHandler, &SelectionHandler::selectionChanged, this, &ModifyCanvasWidget::selectionChanged); connect(mSelectionHandler, &SelectionHandler::selectionChanged, mModifyCanvasView, &ModifyCanvasView::setCanvasRect); } void ModifyCanvasWidget::reset() { auto selection = mAnnotationArea->canvasRect(); auto selectionLimit = mAnnotationArea->sceneRect(); mSelectionHandler->resetSelection(selection, selectionLimit); mColorDialogButton->setColor(mAnnotationArea->canvasColor()); mModifyCanvasView->setCanvasColor(mAnnotationArea->canvasColor()); mModifyCanvasView->setCanvasRect(mAnnotationArea->canvasRect()); } void ModifyCanvasWidget::initZoomPicker() { auto zoomValueProvider = mModifyCanvasView->zoomValueProvider(); connect(zoomValueProvider, &ZoomValueProvider::zoomValueChanged, mZoomPicker, &ZoomPicker::setZoomValue); connect(mZoomPicker, &ZoomPicker::zoomValueChanged, zoomValueProvider, &ZoomValueProvider::setZoomValue); mZoomPicker->setZoomValue(zoomValueProvider->zoomValue()); } void ModifyCanvasWidget::apply() { mAnnotationArea->modifyCanvas(mSelectionHandler->selection(), mColorDialogButton->color()); emit closing(); } void ModifyCanvasWidget::selectionChanged(const QRectF &rect) { mPositionXLineEdit->setText(QString::number(rect.topLeft().x())); mPositionYLineEdit->setText(QString::number(rect.topLeft().y())); mWidthLineEdit->setText(QString::number(rect.width())); mHeightLineEdit->setText(QString::number(rect.height())); } void ModifyCanvasWidget::xChanged(const QString &text) { auto x = text.toInt(); mSelectionHandler->setPositionX(x); } void ModifyCanvasWidget::yChanged(const QString &text) { auto y = text.toInt(); mSelectionHandler->setPositionY(y); } void ModifyCanvasWidget::widthChanged(const QString &text) { auto width = text.toInt(); mSelectionHandler->setWidth(width); } void ModifyCanvasWidget::heightChanged(const QString &text) { auto height = text.toInt(); mSelectionHandler->setHeight(height); } void ModifyCanvasWidget::restrictionChanged() { mSelectionHandler->setRestrictionEnabled(mRestrictCheckBox->isChecked()); } } // kImageAnnotator namespace kImageAnnotator-0.5.3/src/gui/canvasModifier/ModifyCanvasWidget.h000066400000000000000000000053111414424500400250050ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_MODIFYCANVASWIDGET_H #define KIMAGEANNOTATOR_MODIFYCANVASWIDGET_H #include #include #include #include #include #include #include #include #include "ModifyCanvasView.h" #include "ModifyCanvasSelectionRestrictor.h" #include "src/annotations/core/AnnotationArea.h" #include "src/common/helper/KeyHelper.h" #include "src/gui/selection/SelectionHandler.h" #include "src/widgets/ColorDialogButton.h" #include "src/widgets/settingsPicker/ZoomPicker.h" namespace kImageAnnotator { class ModifyCanvasWidget : public QWidget { Q_OBJECT public: explicit ModifyCanvasWidget(); ~ModifyCanvasWidget() override; void activate(AnnotationArea *annotationArea); signals: void closing() const; protected: void keyReleaseEvent(QKeyEvent *event) override; private: AnnotationArea *mAnnotationArea; KeyHelper *mKeyHelper; SelectionHandler *mSelectionHandler; ModifyCanvasView *mModifyCanvasView; QVBoxLayout *mMainLayout; QHBoxLayout *mPanelLayout; QPushButton *mApplyButton; QPushButton *mCancelButton; QLineEdit *mPositionXLineEdit; QLineEdit *mPositionYLineEdit; QLineEdit *mWidthLineEdit; QLineEdit *mHeightLineEdit; QLabel *mPositionXLabel; QLabel *mPositionYLabel; QLabel *mWidthLabel; QLabel *mHeightLabel; QLabel *mColorLabel; QIntValidator *mInputValidator; QCheckBox *mRestrictCheckBox; ColorDialogButton *mColorDialogButton; ZoomPicker *mZoomPicker; void initGui(); void initKeyHelper(); void initSelectionHandler() const; void reset(); void initZoomPicker(); private slots: void apply(); void selectionChanged(const QRectF &rect); void xChanged(const QString &text); void yChanged(const QString &text); void widthChanged(const QString &text); void heightChanged(const QString &text); void restrictionChanged(); }; } // kImageAnnotator namespace #endif //KIMAGEANNOTATOR_MODIFYCANVASWIDGET_H kImageAnnotator-0.5.3/src/gui/cropper/000077500000000000000000000000001414424500400176255ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/gui/cropper/CropSelectionRestrictor.cpp000066400000000000000000000041431414424500400251650ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "CropSelectionRestrictor.h" namespace kImageAnnotator { QRectF &CropSelectionRestrictor::restrictResize(QRectF &newRect, const QRectF ¤tRect, const QRectF &rectLimit) const { if (newRect.x() < rectLimit.x()) { newRect.setX(rectLimit.x()); } if (newRect.y() < rectLimit.y()) { newRect.setY(rectLimit.y()); } if (newRect.width() < 0) { newRect.setWidth(0); newRect.moveLeft(currentRect.left()); } if (newRect.height() < 0) { newRect.setHeight(0); newRect.moveTop(currentRect.top()); } if (newRect.x() + newRect.width() > rectLimit.width()) { newRect.setWidth(rectLimit.width() - newRect.x()); } if (newRect.y() + newRect.height() > rectLimit.height()) { newRect.setHeight(rectLimit.height() - newRect.y()); } return newRect; } QRectF &CropSelectionRestrictor::restrictMove(QRectF &newRect, const QRectF &rectLimit) const { if (newRect.x() < rectLimit.x()) { newRect.moveLeft(rectLimit.x()); } if (newRect.y() < rectLimit.y()) { newRect.moveTop(rectLimit.y()); } if ((newRect.x() + newRect.width()) > rectLimit.width()) { newRect.moveTo(rectLimit.width() - newRect.width(), newRect.y()); } if ((newRect.y() + newRect.height()) > rectLimit.height()) { newRect.moveTo(newRect.x(), rectLimit.height() - newRect.height()); } return newRect; } } // namespave kImageAnnotatorkImageAnnotator-0.5.3/src/gui/cropper/CropSelectionRestrictor.h000066400000000000000000000026521414424500400246350ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CROPSELECTIONRESTRICTOR_H #define KIMAGEANNOTATOR_CROPSELECTIONRESTRICTOR_H #include #include "src/gui/selection/ISelectionRestrictor.h" namespace kImageAnnotator { class CropSelectionRestrictor : public ISelectionRestrictor { public: explicit CropSelectionRestrictor() = default; ~CropSelectionRestrictor() override = default; QRectF &restrictResize(QRectF &newRect, const QRectF ¤tRect, const QRectF &rectLimit) const override; QRectF &restrictMove(QRectF &newRect, const QRectF &rectLimit) const override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_CROPSELECTIONRESTRICTOR_H kImageAnnotator-0.5.3/src/gui/cropper/CropView.cpp000066400000000000000000000033121414424500400220660ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "CropView.h" namespace kImageAnnotator { CropView::CropView(SelectionHandler *cropSelectionHandler, KeyHelper *keyHelper, QWidget *parent) : BaseSelectionView(cropSelectionHandler, keyHelper, parent) { } void CropView::drawForeground(QPainter *painter, const QRectF &rect) { auto annotationArea = dynamic_cast(scene()); auto backgroundImageRect = annotationArea->backgroundImageRect(); painter->setClipRegion(QRegion(backgroundImageRect.toRect()).subtracted(QRegion(currentSelection().toRect()))); painter->setBrush(QColor(0, 0, 0, 150)); painter->drawRect(backgroundImageRect); BaseSelectionView::drawForeground(painter, rect); } void CropView::drawBackground(QPainter *painter, const QRectF &rect) { auto annotationArea = dynamic_cast(scene()); mCanvasPainter.paint(painter, annotationArea->canvasRect(), annotationArea->canvasColor()); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/cropper/CropView.h000066400000000000000000000026621414424500400215420ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CROPVIEW_H #define KIMAGEANNOTATOR_CROPVIEW_H #include "src/gui/selection/BaseSelectionView.h" #include "src/annotations/misc/CanvasPainter.h" namespace kImageAnnotator { class CropView : public BaseSelectionView { Q_OBJECT public: explicit CropView(SelectionHandler *selectionHandler, KeyHelper *keyHelper, QWidget *parent); ~CropView() override = default; protected: void drawForeground(QPainter *painter, const QRectF &rect) override; void drawBackground(QPainter *painter, const QRectF &rect) override; private: CanvasPainter mCanvasPainter; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_CROPVIEW_H kImageAnnotator-0.5.3/src/gui/cropper/CropWidget.cpp000066400000000000000000000137101414424500400224020ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "CropWidget.h" namespace kImageAnnotator { CropWidget::CropWidget() : mAnnotationArea(nullptr), mKeyHelper(new KeyHelper()), mSelectionHandler(new SelectionHandler(new CropSelectionRestrictor)), mCropView(new CropView(mSelectionHandler, mKeyHelper, this)), mCropButton(new QPushButton(this)), mCancelButton(new QPushButton(this)), mPanelLayout(new QHBoxLayout), mPositionXLabel(new QLabel(this)), mPositionYLabel(new QLabel(this)), mHeightLabel(new QLabel(this)), mWidthLabel(new QLabel(this)), mPositionXLineEdit(new QLineEdit(this)), mPositionYLineEdit(new QLineEdit(this)), mWidthLineEdit(new QLineEdit(this)), mHeightLineEdit(new QLineEdit(this)), mMainLayout(new QVBoxLayout(this)), mInputValidator(new QIntValidator(0, 9999, this)), mZoomPicker(new ZoomPicker(this)) { initSelectionHandler(); initKeyHelper(); initGui(); initZoomPicker(); } CropWidget::~CropWidget() { delete mKeyHelper; delete mSelectionHandler; delete mCropView; delete mZoomPicker; } void CropWidget::activate(AnnotationArea *annotationArea) { Q_ASSERT(annotationArea != nullptr); mAnnotationArea = annotationArea; mSelectionHandler->init(annotationArea); mCropView->init(annotationArea); reset(); setFocus(); } void CropWidget::initGui() { mCropButton->setText(tr("Apply")); connect(mCropButton, &QPushButton::clicked, this, &CropWidget::crop); mCancelButton->setText(tr("Cancel")); connect(mCancelButton, &QPushButton::clicked, this, &CropWidget::closing); auto width = ScaledSizeProvider::scaledWidth(80); mPositionXLabel->setText(tr("X:")); mPositionXLineEdit->setValidator(mInputValidator); mPositionXLineEdit->setFixedSize(width, mPositionXLineEdit->minimumSizeHint().height()); connect(mPositionXLineEdit, &QLineEdit::textEdited, this, &CropWidget::xChanged); mPositionYLabel->setText(tr("Y:")); mPositionYLineEdit->setValidator(mInputValidator); mPositionYLineEdit->setFixedSize(width, mPositionYLineEdit->minimumSizeHint().height()); connect(mPositionYLineEdit, &QLineEdit::textEdited, this, &CropWidget::yChanged); mWidthLabel->setText(tr("W:")); mWidthLineEdit->setValidator(mInputValidator); mWidthLineEdit->setFixedSize(width, mWidthLineEdit->minimumSizeHint().height()); connect(mWidthLineEdit, &QLineEdit::textEdited, this, &CropWidget::widthChanged); mHeightLabel->setText(tr("H:")); mHeightLineEdit->setValidator(mInputValidator); mHeightLineEdit->setFixedSize(width, mHeightLineEdit->minimumSizeHint().height()); connect(mHeightLineEdit, &QLineEdit::textEdited, this, &CropWidget::heightChanged); mPanelLayout->setAlignment(Qt::AlignCenter); mPanelLayout->addWidget(mZoomPicker); mPanelLayout->addStretch(1); mPanelLayout->addWidget(mPositionXLabel); mPanelLayout->addWidget(mPositionXLineEdit); mPanelLayout->addWidget(mPositionYLabel); mPanelLayout->addWidget(mPositionYLineEdit); mPanelLayout->addWidget(mWidthLabel); mPanelLayout->addWidget(mWidthLineEdit); mPanelLayout->addWidget(mHeightLabel); mPanelLayout->addWidget(mHeightLineEdit); mPanelLayout->addStretch(1); mPanelLayout->addWidget(mCropButton); mPanelLayout->addWidget(mCancelButton); mMainLayout->addWidget(mCropView); mMainLayout->addLayout(mPanelLayout); setLayout(mMainLayout); } void CropWidget::keyReleaseEvent(QKeyEvent *event) { mKeyHelper->keyRelease(event); QWidget::keyReleaseEvent(event); } void CropWidget::crop() { Q_ASSERT(mAnnotationArea != nullptr); mAnnotationArea->crop(mSelectionHandler->selection()); emit closing(); } void CropWidget::selectionChanged(const QRectF &rect) { mPositionXLineEdit->setText(QString::number(rect.topLeft().x())); mPositionYLineEdit->setText(QString::number(rect.topLeft().y())); mWidthLineEdit->setText(QString::number(rect.width())); mHeightLineEdit->setText(QString::number(rect.height())); } void kImageAnnotator::CropWidget::xChanged(const QString &text) { auto x = text.toInt(); mSelectionHandler->setPositionX(x); } void CropWidget::yChanged(const QString &text) { auto y = text.toInt(); mSelectionHandler->setPositionY(y); } void CropWidget::widthChanged(const QString &text) { auto width = text.toInt(); mSelectionHandler->setWidth(width); } void CropWidget::heightChanged(const QString &text) { auto height = text.toInt(); mSelectionHandler->setHeight(height); } void CropWidget::reset() { auto selection = mAnnotationArea->backgroundImageRect(); mSelectionHandler->resetSelection(selection, selection); } void CropWidget::initZoomPicker() const { auto zoomValueProvider = mCropView->zoomValueProvider(); connect(zoomValueProvider, &ZoomValueProvider::zoomValueChanged, mZoomPicker, &ZoomPicker::setZoomValue); connect(mZoomPicker, &ZoomPicker::zoomValueChanged, zoomValueProvider, &ZoomValueProvider::setZoomValue); mZoomPicker->setZoomValue(zoomValueProvider->zoomValue()); } void CropWidget::initSelectionHandler() const { connect(mSelectionHandler, &SelectionHandler::selectionChanged, this, &CropWidget::selectionChanged); } void CropWidget::initKeyHelper() { connect(mKeyHelper, &KeyHelper::escapeReleased, this, &CropWidget::closing); connect(mKeyHelper, &KeyHelper::returnReleased, this, &CropWidget::crop); connect(mKeyHelper, &KeyHelper::enterReleased, this, &CropWidget::crop); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/cropper/CropWidget.h000066400000000000000000000046741414424500400220600ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CROPWIDGET_H #define KIMAGEANNOTATOR_CROPWIDGET_H #include #include #include #include #include #include #include "CropView.h" #include "src/gui/selection/SelectionHandler.h" #include "src/annotations/core/AnnotationArea.h" #include "src/common/helper/KeyHelper.h" #include "src/common/provider/ScaledSizeProvider.h" #include "src/widgets/settingsPicker/ZoomPicker.h" namespace kImageAnnotator { class CropWidget : public QWidget { Q_OBJECT public: explicit CropWidget(); ~CropWidget() override; void activate(AnnotationArea *annotationArea); signals: void closing() const; protected: void keyReleaseEvent(QKeyEvent *event) override; private: AnnotationArea *mAnnotationArea; KeyHelper *mKeyHelper; SelectionHandler *mSelectionHandler; CropView *mCropView; QVBoxLayout *mMainLayout; QHBoxLayout *mPanelLayout; QPushButton *mCropButton; QPushButton *mCancelButton; QLineEdit *mPositionXLineEdit; QLineEdit *mPositionYLineEdit; QLineEdit *mWidthLineEdit; QLineEdit *mHeightLineEdit; QLabel *mPositionXLabel; QLabel *mPositionYLabel; QLabel *mWidthLabel; QLabel *mHeightLabel; QIntValidator *mInputValidator; ZoomPicker *mZoomPicker; void initGui(); void initKeyHelper(); void initSelectionHandler() const; void reset(); void initZoomPicker() const; private slots: void crop(); void selectionChanged(const QRectF &rect); void xChanged(const QString &text); void yChanged(const QString &text); void widthChanged(const QString &text); void heightChanged(const QString &text); }; } // kImageAnnotator namespace #endif //KIMAGEANNOTATOR_CROPWIDGET_H kImageAnnotator-0.5.3/src/gui/rotator/000077500000000000000000000000001414424500400176455ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/gui/rotator/RotateDialog.cpp000066400000000000000000000122141414424500400227270ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "RotateDialog.h" namespace kImageAnnotator { RotateDialog::RotateDialog(QWidget *parent) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint), m180RadioButton(new QRadioButton(this)), m90ClockwiseRadioButton(new QRadioButton(this)), m90CounterClockwiseRadioButton(new QRadioButton(this)), mArbitraryRotationRadioButton(new QRadioButton(this)), mFlipHorizontalRadioButton(new QRadioButton(this)), mFlipVerticalRadioButton(new QRadioButton(this)), mArbitraryRotationSpinBox(new CustomSpinBox(this)), mOkButton(new QPushButton(this)), mCancelButton(new QPushButton(this)), mRotateRadioButtonLayout(new QGridLayout), mFlipRadioButtonLayout(new QGridLayout), mRotateButtonGroupBox(new QGroupBox(this)), mFlipButtonGroupBox(new QGroupBox(this)), mButtonRowLayout(new QHBoxLayout), mMainLayout(new QVBoxLayout), mButtonGroup(new QButtonGroup(this)) { setWindowTitle(tr("Rotate Image")); initGui(); setDefault(); } void RotateDialog::initGui() { m180RadioButton->setText(tr("180°")); m180RadioButton->setChecked(true); mButtonGroup->addButton(m180RadioButton); m90ClockwiseRadioButton->setText(tr("90° Clockwise")); mButtonGroup->addButton(m90ClockwiseRadioButton); m90CounterClockwiseRadioButton->setText(tr("90° Counter Clockwise")); mButtonGroup->addButton(m90CounterClockwiseRadioButton); mArbitraryRotationRadioButton->setText(tr("Arbitrary")); mArbitraryRotationRadioButton->setToolTip(tr("Positive values rotate clockwise, negative values counter clockwise.\n" "Rotating by non 90° multipliers might introduce loss of quality.")); mButtonGroup->addButton(mArbitraryRotationRadioButton); mArbitraryRotationSpinBox->setSuffix(QString::fromUtf8("°")); mArbitraryRotationSpinBox->setToolTip(mArbitraryRotationRadioButton->toolTip()); mArbitraryRotationSpinBox->setMinimum(-360); mArbitraryRotationSpinBox->setMaximum(360); mFlipHorizontalRadioButton->setText(tr("Horizontal")); mButtonGroup->addButton(mFlipHorizontalRadioButton); mFlipVerticalRadioButton->setText(tr("Vertical")); mButtonGroup->addButton(mFlipVerticalRadioButton); mOkButton->setText(tr("OK")); connect(mOkButton, &QPushButton::clicked, this, &RotateDialog::finish); mCancelButton->setText(tr("Cancel")); connect(mCancelButton, &QPushButton::clicked, this, &RotateDialog::cancel); connect(mButtonGroup, QOverload::of(&QButtonGroup::buttonClicked), this, &RotateDialog::selectionChanged); mRotateRadioButtonLayout->setColumnMinimumWidth(0, 20); mRotateRadioButtonLayout->addWidget(m180RadioButton, 0, 0, 1, 2); mRotateRadioButtonLayout->addWidget(m90ClockwiseRadioButton, 1, 0, 1, 2); mRotateRadioButtonLayout->addWidget(m90CounterClockwiseRadioButton, 2, 0, 1, 2); mRotateRadioButtonLayout->addWidget(mArbitraryRotationRadioButton, 3, 0, 1, 2); mRotateRadioButtonLayout->addWidget(mArbitraryRotationSpinBox, 4, 1, 1, 1); mFlipRadioButtonLayout->addWidget(mFlipHorizontalRadioButton, 0, 0); mFlipRadioButtonLayout->addWidget(mFlipVerticalRadioButton, 1, 0); mRotateButtonGroupBox->setTitle(tr("Rotate")); mRotateButtonGroupBox->setLayout(mRotateRadioButtonLayout); mFlipButtonGroupBox->setTitle(tr("Flip")); mFlipButtonGroupBox->setLayout(mFlipRadioButtonLayout); mButtonRowLayout->addWidget(mOkButton); mButtonRowLayout->addWidget(mCancelButton); mButtonRowLayout->setAlignment(Qt::AlignRight); mMainLayout->addWidget(mRotateButtonGroupBox); mMainLayout->addWidget(mFlipButtonGroupBox); mMainLayout->addLayout(mButtonRowLayout); setLayout(mMainLayout); } void RotateDialog::setDefault() { m180RadioButton->setChecked(true); mArbitraryRotationSpinBox->setValue(45); selectionChanged(); } void RotateDialog::finish() { if (m180RadioButton->isChecked()) { emit rotate(180); } else if (m90ClockwiseRadioButton->isChecked()) { emit rotate(90); } else if (m90CounterClockwiseRadioButton->isChecked()) { emit rotate(-90); } else if (mArbitraryRotationRadioButton->isChecked()) { emit rotate(mArbitraryRotationSpinBox->value()); } else if (mFlipHorizontalRadioButton->isChecked()) { emit flip(FlipDirection::Horizontal); } else if (mFlipVerticalRadioButton->isChecked()) { emit flip(FlipDirection::Vertical); } close(); } void RotateDialog::cancel() { close(); } void RotateDialog::selectionChanged() { mArbitraryRotationSpinBox->setEnabled(mArbitraryRotationRadioButton->isChecked()); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/gui/rotator/RotateDialog.h000066400000000000000000000042111414424500400223720ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ROTATEDIALOG_H #define KIMAGEANNOTATOR_ROTATEDIALOG_H #include #include #include #include #include #include #include #include #include "src/widgets/CustomSpinBox.h" #include "src/common/enum/FlipDirection.h" namespace kImageAnnotator { class RotateDialog : public QDialog { Q_OBJECT public: explicit RotateDialog(QWidget *parent = nullptr); ~RotateDialog() override = default; signals: void rotate(qreal angle) const; void flip(FlipDirection direction) const; private: QRadioButton *m180RadioButton; QRadioButton *m90ClockwiseRadioButton; QRadioButton *m90CounterClockwiseRadioButton; QRadioButton *mArbitraryRotationRadioButton; QRadioButton *mFlipHorizontalRadioButton; QRadioButton *mFlipVerticalRadioButton; CustomSpinBox *mArbitraryRotationSpinBox; QPushButton *mOkButton; QPushButton *mCancelButton; QGridLayout *mRotateRadioButtonLayout; QGridLayout *mFlipRadioButtonLayout; QGroupBox *mRotateButtonGroupBox; QGroupBox *mFlipButtonGroupBox; QHBoxLayout *mButtonRowLayout; QVBoxLayout *mMainLayout; QButtonGroup *mButtonGroup; void initGui(); void setDefault(); private slots: void finish(); void cancel(); void selectionChanged(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ROTATEDIALOG_H kImageAnnotator-0.5.3/src/gui/rotator/RotateWidget.cpp000066400000000000000000000035121414424500400227540ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "RotateWidget.h" namespace kImageAnnotator { RotateWidget::RotateWidget() : mAnnotationArea(nullptr), mView(new QGraphicsView), mMainLayout(new QVBoxLayout(this)) { initGui(); } RotateWidget::~RotateWidget() { delete mView; } void RotateWidget::activate(AnnotationArea *annotationArea) { Q_ASSERT(annotationArea != nullptr); mAnnotationArea = annotationArea; mView->setScene(annotationArea); showDialog(); } void RotateWidget::initGui() { mMainLayout->addWidget(mView); setLayout(mMainLayout); } void RotateWidget::showDialog() { RotateDialog rotateDialog(this); connect(&rotateDialog, &RotateDialog::rotate, this, &RotateWidget::rotate); connect(&rotateDialog, &RotateDialog::flip, this, &RotateWidget::flip); rotateDialog.exec(); emit closing(); } void RotateWidget::rotate(qreal angel) { Q_ASSERT(mAnnotationArea != nullptr); mAnnotationArea->rotate(angel); } void RotateWidget::flip(FlipDirection direction) { Q_ASSERT(mAnnotationArea != nullptr); mAnnotationArea->flip(direction); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/gui/rotator/RotateWidget.h000066400000000000000000000027571414424500400224330ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ROTATEWIDGET_H #define KIMAGEANNOTATOR_ROTATEWIDGET_H #include #include #include #include "RotateDialog.h" #include "src/annotations/core/AnnotationArea.h" namespace kImageAnnotator { class RotateWidget : public QWidget { Q_OBJECT public: explicit RotateWidget(); ~RotateWidget() override; void activate(AnnotationArea *annotationArea); signals: void closing() const; private: AnnotationArea *mAnnotationArea; QGraphicsView *mView; QVBoxLayout *mMainLayout; void initGui(); void showDialog(); void rotate(qreal angel); void flip(FlipDirection direction); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ROTATEWIDGET_H kImageAnnotator-0.5.3/src/gui/scaler/000077500000000000000000000000001414424500400174245ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/gui/scaler/ScaleDialog.cpp000066400000000000000000000125311414424500400223010ustar00rootroot00000000000000/* * Copyright (C) 2017 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ScaleDialog.h" namespace kImageAnnotator { ScaleDialog::ScaleDialog(const QSize &imageSize, QWidget *parent) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint), mKeepAspectRatioCheckBox(new QCheckBox), mWidthPixelLabel(new QLabel(this)), mHeightPixelLabel(new QLabel(this)), mWidthPercentLabel(new QLabel(this)), mHeightPercentLabel(new QLabel(this)), mWidthPixelSpinBox(new CustomSpinBox(this)), mHeightPixelSpinBox(new CustomSpinBox(this)), mWidthPercentSpinBox(new CustomSpinBox(this)), mOkButton(new QPushButton(this)), mCancelButton(new QPushButton(this)), mHeightPercentSpinBox(new CustomSpinBox(this)), mPixelGridLayout(new QGridLayout), mPercentGridLayout(new QGridLayout), mPixelGroupBox(new QGroupBox(this)), mPercentGroupBox(new QGroupBox(this)), mButtonRowLayout(new QHBoxLayout), mMainLayout(new QVBoxLayout(this)) { setWindowTitle(tr("Scale Image")); mSizeHandler.setSize(imageSize); initGui(); } void ScaleDialog::initGui() { mKeepAspectRatioCheckBox->setText(tr("Keep Aspect Ratio")); connect(mKeepAspectRatioCheckBox, &QCheckBox::toggled, &mSizeHandler, &ScaleSizeHandler::setAspectRatio); mKeepAspectRatioCheckBox->setChecked(true); mWidthPixelLabel->setText(tr("Width:")); mHeightPixelLabel->setText(tr("Height:")); mWidthPercentLabel->setText(tr("Width:")); mHeightPercentLabel->setText(tr("Height:")); mWidthPixelSpinBox->setSuffix(QLatin1String("px")); mWidthPixelSpinBox->setMinimum(1); mWidthPixelSpinBox->setMaximum(4000); mWidthPixelSpinBox->setValueSilent(mSizeHandler.size().width()); mWidthPixelSpinBox->setWrapping(false); connect(mWidthPixelSpinBox, &CustomSpinBox::valueChanged, &mSizeHandler, &ScaleSizeHandler::setWidthPixel); connect(&mSizeHandler, &ScaleSizeHandler::widthPixelChanged, mWidthPixelSpinBox, &CustomSpinBox::setValueSilent); mHeightPixelSpinBox->setSuffix(QLatin1String("px")); mHeightPixelSpinBox->setMinimum(1); mHeightPixelSpinBox->setMaximum(4000); mHeightPixelSpinBox->setValueSilent(mSizeHandler.size().height()); mHeightPixelSpinBox->setWrapping(false); connect(mHeightPixelSpinBox, &CustomSpinBox::valueChanged, &mSizeHandler, &ScaleSizeHandler::setHeightPixel); connect(&mSizeHandler, &ScaleSizeHandler::heightPixelChanged, mHeightPixelSpinBox, &CustomSpinBox::setValueSilent); mWidthPercentSpinBox->setSuffix(QLatin1String("%")); mWidthPercentSpinBox->setMinimum(1); mWidthPercentSpinBox->setMaximum(400); mWidthPercentSpinBox->setValueSilent(100); mWidthPercentSpinBox->setWrapping(false); connect(mWidthPercentSpinBox, &CustomSpinBox::valueChanged, &mSizeHandler, &ScaleSizeHandler::setWidthPercent); connect(&mSizeHandler, &ScaleSizeHandler::widthPercentChanged, mWidthPercentSpinBox, &CustomSpinBox::setValueSilent); mHeightPercentSpinBox->setSuffix(QLatin1String("%")); mHeightPercentSpinBox->setMinimum(1); mHeightPercentSpinBox->setMaximum(400); mHeightPercentSpinBox->setValueSilent(100); mHeightPercentSpinBox->setWrapping(false); connect(mHeightPercentSpinBox, &CustomSpinBox::valueChanged, &mSizeHandler, &ScaleSizeHandler::setHeightPercent); connect(&mSizeHandler, &ScaleSizeHandler::heightPercentChanged, mHeightPercentSpinBox, &CustomSpinBox::setValueSilent); mOkButton->setText(tr("OK")); connect(mOkButton, &QPushButton::clicked, this, &ScaleDialog::scale); mCancelButton->setText(tr("Cancel")); connect(mCancelButton, &QPushButton::clicked, this, &ScaleDialog::cancel); mPixelGridLayout->addWidget(mWidthPixelLabel, 0, 0); mPixelGridLayout->addWidget(mWidthPixelSpinBox, 0, 1); mPixelGridLayout->addWidget(mHeightPixelLabel, 1, 0); mPixelGridLayout->addWidget(mHeightPixelSpinBox, 1, 1); mPercentGridLayout->addWidget(mWidthPercentLabel, 0, 0); mPercentGridLayout->addWidget(mWidthPercentSpinBox, 0, 1); mPercentGridLayout->addWidget(mHeightPercentLabel, 1, 0); mPercentGridLayout->addWidget(mHeightPercentSpinBox, 1, 1); mPixelGroupBox->setTitle(tr("Pixel")); mPixelGroupBox->setLayout(mPixelGridLayout); mPercentGroupBox->setTitle(tr("Percent")); mPercentGroupBox->setLayout(mPercentGridLayout); mButtonRowLayout->addWidget(mOkButton); mButtonRowLayout->addWidget(mCancelButton); mButtonRowLayout->setAlignment(Qt::AlignRight); mMainLayout->addWidget(mKeepAspectRatioCheckBox); mMainLayout->addWidget(mPixelGroupBox); mMainLayout->addWidget(mPercentGroupBox); mMainLayout->addLayout(mButtonRowLayout); setLayout(mMainLayout); } void ScaleDialog::scale() { QSize newSize(mWidthPixelSpinBox->value(), mHeightPixelSpinBox->value()); emit finished(newSize); close(); } void ScaleDialog::cancel() { close(); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/gui/scaler/ScaleDialog.h000066400000000000000000000040651414424500400217510ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SCALEDIALOG_H #define KIMAGEANNOTATOR_SCALEDIALOG_H #include #include #include #include #include #include #include #include #include "ScaleSizeHandler.h" #include "src/widgets/CustomSpinBox.h" namespace kImageAnnotator { class ScaleDialog : public QDialog { Q_OBJECT public: explicit ScaleDialog(const QSize &imageSize, QWidget *parent = nullptr); ~ScaleDialog() override = default; signals: void finished(const QSize &newSize) const; private: ScaleSizeHandler mSizeHandler; QCheckBox *mKeepAspectRatioCheckBox; QLabel *mWidthPixelLabel; QLabel *mHeightPixelLabel; QLabel *mWidthPercentLabel; QLabel *mHeightPercentLabel; CustomSpinBox *mWidthPixelSpinBox; CustomSpinBox *mHeightPixelSpinBox; CustomSpinBox *mWidthPercentSpinBox; CustomSpinBox *mHeightPercentSpinBox; QPushButton *mOkButton; QPushButton *mCancelButton; QGridLayout *mPixelGridLayout; QGridLayout *mPercentGridLayout; QGroupBox *mPixelGroupBox; QGroupBox *mPercentGroupBox; QHBoxLayout *mButtonRowLayout; QVBoxLayout *mMainLayout; void initGui(); private slots: void scale(); void cancel(); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_SCALEDIALOG_H kImageAnnotator-0.5.3/src/gui/scaler/ScaleSizeHandler.cpp000066400000000000000000000046121414424500400233130ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ScaleSizeHandler.h" namespace kImageAnnotator { ScaleSizeHandler::ScaleSizeHandler() : mKeepAspectRatio(true) { } void ScaleSizeHandler::setSize(QSize size) { mSize = size; } QSize ScaleSizeHandler::size() const { return mSize; } void ScaleSizeHandler::setAspectRatio(bool keepAspectRatio) { mKeepAspectRatio = keepAspectRatio; } void ScaleSizeHandler::setWidthPixel(int width) { auto percent = calculatePercent(width, mSize.width()); emit widthPercentChanged(percent * 100); if (mKeepAspectRatio) { setHeight(percent); } } void ScaleSizeHandler::setWidthPercent(float width) { auto percent = calculatePercent(width, 100); emit widthPixelChanged(percent * mSize.width()); if (mKeepAspectRatio) { setHeight(percent); } } void ScaleSizeHandler::setHeightPixel(int height) { auto percent = calculatePercent(height, mSize.height()); emit heightPercentChanged(percent * 100); if (mKeepAspectRatio) { setWidth(percent); } } void ScaleSizeHandler::setHeightPercent(float height) { auto percent = calculatePercent(height, 100); emit heightPixelChanged(percent * mSize.height()); if (mKeepAspectRatio) { setWidth(percent); } } float ScaleSizeHandler::calculatePercent(int newValue, int baseValue) const { return (float) newValue / (float) baseValue; } void ScaleSizeHandler::setHeight(float percent) const { emit heightPixelChanged(percent * mSize.height()); emit heightPercentChanged(percent * 100); } void ScaleSizeHandler::setWidth(float percent) const { emit widthPixelChanged(percent * mSize.width()); emit widthPercentChanged(percent * 100); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/gui/scaler/ScaleSizeHandler.h000066400000000000000000000033761414424500400227660ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SCALESIZEHANDLER_H #define KIMAGEANNOTATOR_SCALESIZEHANDLER_H #include #include namespace kImageAnnotator { class ScaleSizeHandler : public QObject { Q_OBJECT public: explicit ScaleSizeHandler(); ~ScaleSizeHandler() override = default; void setSize(QSize size); QSize size() const; signals: void widthPixelChanged(int width) const; void widthPercentChanged(float width) const; void heightPixelChanged(int height) const; void heightPercentChanged(float height) const; public slots: void setAspectRatio(bool keepAspectRatio); void setWidthPixel(int width); void setWidthPercent(float width); void setHeightPixel(int height); void setHeightPercent(float height); private: bool mKeepAspectRatio; QSize mSize; float calculatePercent(int newValue, int baseValue) const; void setHeight(float percent) const; void setWidth(float percent) const; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_SCALESIZEHANDLER_H kImageAnnotator-0.5.3/src/gui/scaler/ScaleWidget.cpp000066400000000000000000000032601414424500400223240ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ScaleWidget.h" namespace kImageAnnotator { kImageAnnotator::ScaleWidget::ScaleWidget() : mAnnotationArea(nullptr), mView(new QGraphicsView), mMainLayout(new QVBoxLayout(this)) { initGui(); } ScaleWidget::~ScaleWidget() { delete mView; } void ScaleWidget::activate(AnnotationArea *annotationArea) { Q_ASSERT(annotationArea != nullptr); mAnnotationArea = annotationArea; mView->setScene(annotationArea); showDialog(); } void ScaleWidget::initGui() { mMainLayout->addWidget(mView); setLayout(mMainLayout); } void ScaleWidget::showDialog() { auto sceneSize = mAnnotationArea->sceneRect().size(); ScaleDialog scaleDialog(sceneSize.toSize(), this); connect(&scaleDialog, &ScaleDialog::finished, this, &ScaleWidget::scale); scaleDialog.exec(); emit closing(); } void ScaleWidget::scale(const QSize &newSize) { mAnnotationArea->scale(newSize); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/scaler/ScaleWidget.h000066400000000000000000000027131414424500400217730ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SCALEWIDGET_H #define KIMAGEANNOTATOR_SCALEWIDGET_H #include #include #include #include "ScaleDialog.h" #include "src/annotations/core/AnnotationArea.h" namespace kImageAnnotator { class ScaleWidget : public QWidget { Q_OBJECT public: explicit ScaleWidget(); ~ScaleWidget() override; void activate(AnnotationArea *annotationArea); signals: void closing() const; private: AnnotationArea *mAnnotationArea; QGraphicsView *mView; QVBoxLayout *mMainLayout; void initGui(); void showDialog(); void scale(const QSize &newSize); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_SCALEWIDGET_H kImageAnnotator-0.5.3/src/gui/scrollAndZoomView/000077500000000000000000000000001414424500400215745ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/gui/scrollAndZoomView/ScrollAndZoomView.cpp000066400000000000000000000062621414424500400256670ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ScrollAndZoomView.h" namespace kImageAnnotator { ScrollAndZoomView::ScrollAndZoomView(QWidget *parent) : QGraphicsView(parent), mIsDragging(false), mViewZoomer(new ViewZoomer(this)) { setTransformationAnchor(QGraphicsView::NoAnchor); disableDragging(); setViewportUpdateMode(ViewportUpdateMode::FullViewportUpdate); } ScrollAndZoomView::~ScrollAndZoomView() { delete mViewZoomer; } ZoomValueProvider *ScrollAndZoomView::zoomValueProvider() const { return mViewZoomer; } void ScrollAndZoomView::keyPressEvent(QKeyEvent *event) { mKeyHelper.keyPress(event); if(mKeyHelper.isSpacePressed()) { enableDragging(mapFromGlobal(QCursor::pos())); } QGraphicsView::keyPressEvent(event); } void ScrollAndZoomView::keyReleaseEvent(QKeyEvent *event) { mKeyHelper.keyRelease(event); if(!mKeyHelper.isSpacePressed()) { disableDragging(); } QGraphicsView::keyReleaseEvent(event); } void ScrollAndZoomView::mouseMoveEvent(QMouseEvent *event) { if (mIsDragging) { scrollTo(event->pos()); } else { QGraphicsView::mouseMoveEvent(event); } } void ScrollAndZoomView::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::MidButton) { enableDragging(event->pos()); } else { QGraphicsView::mousePressEvent(event); } } void ScrollAndZoomView::mouseReleaseEvent(QMouseEvent *event) { if (event->button() == Qt::MidButton) { disableDragging(); } else { QGraphicsView::mouseReleaseEvent(event); } } void ScrollAndZoomView::wheelEvent(QWheelEvent *event) { if (event->modifiers() & Qt::ControlModifier ) { mViewZoomer->wheelZoom(event); } else { QGraphicsView::wheelEvent(event); } } void ScrollAndZoomView::scrollTo(const QPoint &pos) { auto delta = pos - mLastPosition; scrollByDelta(horizontalScrollBar(), delta.x()); scrollByDelta(verticalScrollBar(), delta.y()); mLastPosition = pos; } void ScrollAndZoomView::scrollByDelta(QScrollBar *scrollBar, int delta) const { scrollBar->setValue(scrollBar->value() - delta); } void ScrollAndZoomView::enableDragging(const QPoint &pos) { mIsDragging = true; mLastPosition = pos; setDragCursorEnabled(true); } void ScrollAndZoomView::disableDragging() { mIsDragging = false; mLastPosition = {}; setDragCursorEnabled(false); } void ScrollAndZoomView::setDragCursorEnabled(bool enabled) const { enabled ? QGuiApplication::setOverrideCursor(Qt::SizeAllCursor) : QGuiApplication::restoreOverrideCursor(); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/scrollAndZoomView/ScrollAndZoomView.h000066400000000000000000000037031414424500400253310ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SCROLLANDZOOMVIEW_H #define KIMAGEANNOTATOR_SCROLLANDZOOMVIEW_H #include #include #include #include #include "ViewZoomer.h" #include "src/common/helper/KeyHelper.h" namespace kImageAnnotator { class ScrollAndZoomView : public QGraphicsView { Q_OBJECT public: explicit ScrollAndZoomView(QWidget *parent); ~ScrollAndZoomView() override; ZoomValueProvider *zoomValueProvider() const; protected: void keyPressEvent(QKeyEvent *event) override; void keyReleaseEvent(QKeyEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; void wheelEvent(QWheelEvent *event) override; private: ViewZoomer *mViewZoomer; bool mIsDragging; QPoint mLastPosition; KeyHelper mKeyHelper; void scrollTo(const QPoint &pos); void scrollByDelta(QScrollBar *scrollBar, int delta) const; void enableDragging(const QPoint &pos); void disableDragging(); void setDragCursorEnabled(bool enabled) const; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_SCROLLANDZOOMVIEW_H kImageAnnotator-0.5.3/src/gui/scrollAndZoomView/ViewZoomer.cpp000066400000000000000000000036421414424500400244130ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ViewZoomer.h" namespace kImageAnnotator { ViewZoomer::ViewZoomer(QGraphicsView *view) : ZoomValueProvider(view), mView(view), mMinScale(0.1), mMaxScale(8.0) { } double ViewZoomer::zoomValue() const { return mView->transform().m11(); } void ViewZoomer::zoom(double factor) { auto currentZoomValue = zoomValue(); auto newZoomValue = currentZoomValue + factor; if(newZoomValue >= mMinScale && newZoomValue <= mMaxScale) { mView->resetMatrix(); mView->scale(newZoomValue, newZoomValue); emit zoomValueChanged(zoomValue()); } } void ViewZoomer::zoomToPoint(double factor, const QPoint &viewPoint) { const auto scenePoint = mView->mapToScene(viewPoint); zoom(factor); const auto delta = mView->mapToScene(viewPoint) - scenePoint; mView->translate(delta.x(), delta.y()); } void ViewZoomer::wheelZoom(QWheelEvent *event) { auto zoomInFactor = 0.1; const auto factor = event->angleDelta().y() < 0.0 ? -zoomInFactor : zoomInFactor; zoomToPoint(factor, event->pos()); event->accept(); // supress scrolling } void ViewZoomer::setZoomValue(double value) { zoom(value - zoomValue()); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/scrollAndZoomView/ViewZoomer.h000066400000000000000000000027571414424500400240660ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_VIEWZOOMER_H #define KIMAGEANNOTATOR_VIEWZOOMER_H #include "src/annotations/core/ZoomValueProvider.h" #include #include class QPoint; namespace kImageAnnotator { class ViewZoomer : public ZoomValueProvider { Q_OBJECT public: explicit ViewZoomer(QGraphicsView *view); ~ViewZoomer() override = default; double zoomValue() const override; void setZoomValue(double value) override; void zoom(double factor); void zoomToPoint(double factor, const QPoint &viewPoint); void wheelZoom(QWheelEvent *event); private: QGraphicsView *mView; double mMinScale; double mMaxScale; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_VIEWZOOMER_H kImageAnnotator-0.5.3/src/gui/selection/000077500000000000000000000000001414424500400201405ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/gui/selection/BaseSelectionView.cpp000066400000000000000000000070451414424500400242250ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "BaseSelectionView.h" namespace kImageAnnotator { BaseSelectionView::BaseSelectionView(SelectionHandler *cropSelectionHandler, KeyHelper *keyHelper, QWidget *parent) : ScrollAndZoomView(parent), mKeyHelper(keyHelper), mSelectionHandler(cropSelectionHandler) { connect(zoomValueProvider(), &ZoomValueProvider::zoomValueChanged, this, &BaseSelectionView::applyZoomValue); } void BaseSelectionView::init(AnnotationArea *annotationArea) { Q_ASSERT(annotationArea != nullptr); setScene(annotationArea); } void BaseSelectionView::keyPressEvent(QKeyEvent *event) { mKeyHelper->keyPress(event); ScrollAndZoomView::keyPressEvent(event); } void BaseSelectionView::keyReleaseEvent(QKeyEvent *event) { mKeyHelper->keyRelease(event); ScrollAndZoomView::keyReleaseEvent(event); } void BaseSelectionView::mouseMoveEvent(QMouseEvent *event) { if (mSelectionHandler->isInMotion()) { mSelectionHandler->move(mapToScene(event->pos())); } else { ScrollAndZoomView::mouseMoveEvent(event); } updateCursor(mapToScene(event->pos())); } void BaseSelectionView::mousePressEvent(QMouseEvent *event) { if(event->button() == Qt::LeftButton) { mSelectionHandler->grab(mapToScene(event->pos())); } else { ScrollAndZoomView::mousePressEvent(event); } updateCursor(mapToScene(event->pos())); } void BaseSelectionView::mouseReleaseEvent(QMouseEvent *event) { if (mSelectionHandler->isInMotion()) { mSelectionHandler->release(); } else { ScrollAndZoomView::mouseReleaseEvent(event); } updateCursor(mapToScene(event->pos())); } void BaseSelectionView::drawForeground(QPainter *painter, const QRectF &rect) { auto selection = mSelectionHandler->selection(); auto zoomValue = zoomValueProvider()->zoomValue(); auto lineWidth = 1 / zoomValue; // Draw border around selected are painter->setClipRect(rect); painter->setBrush(Qt::NoBrush); painter->setPen(QPen(Qt::gray, lineWidth, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin)); painter->drawRect(selection); if (!mSelectionHandler->isInMotion()) { painter->setPen(QPen(Qt::white, lineWidth, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin)); painter->setBrush(QColor(Qt::gray)); auto handles = mSelectionHandler->selectionHandles(); for (auto handle : handles) { painter->drawRect(handle); } } QGraphicsView::drawForeground(painter, rect); } QRectF BaseSelectionView::currentSelection() const { return mSelectionHandler->selection(); } void BaseSelectionView::updateCursor(const QPointF &pos) { if(mSelectionHandler->isInMotion()) { setCursor(Qt::ClosedHandCursor); } else if(mSelectionHandler->selectionContains(pos)) { setCursor(Qt::OpenHandCursor); } else { unsetCursor(); } } void BaseSelectionView::applyZoomValue(double value) { mSelectionHandler->applyZoomValue(value); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/selection/BaseSelectionView.h000066400000000000000000000036441414424500400236730ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_BASESELECTIONVIEW_H #define KIMAGEANNOTATOR_BASESELECTIONVIEW_H #include "src/gui/scrollAndZoomView/ScrollAndZoomView.h" #include "src/gui/selection/SelectionHandler.h" #include "src/annotations/core/AnnotationArea.h" namespace kImageAnnotator { class BaseSelectionView : public ScrollAndZoomView { Q_OBJECT public: explicit BaseSelectionView(SelectionHandler *selectionHandler, KeyHelper *keyHelper, QWidget *parent); ~BaseSelectionView() override = default; void init(AnnotationArea *annotationArea); protected: void keyPressEvent(QKeyEvent *event) override; void keyReleaseEvent(QKeyEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; void drawForeground(QPainter *painter, const QRectF &rect) override; QRectF currentSelection() const; private: KeyHelper *mKeyHelper; SelectionHandler *mSelectionHandler; void updateCursor(const QPointF &pos); private slots: void applyZoomValue(double value); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_BASESELECTIONVIEW_H kImageAnnotator-0.5.3/src/gui/selection/ISelectionRestrictor.h000066400000000000000000000024671414424500400244410ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ISELECTIONRESTRICTOR_H #define KIMAGEANNOTATOR_ISELECTIONRESTRICTOR_H namespace kImageAnnotator { class ISelectionRestrictor { public: explicit ISelectionRestrictor() = default; virtual ~ISelectionRestrictor() = default; virtual QRectF &restrictResize(QRectF &newRect, const QRectF ¤tRect, const QRectF &rectLimit) const = 0; virtual QRectF &restrictMove(QRectF &newRect, const QRectF &rectLimit) const = 0; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ISELECTIONRESTRICTOR_H kImageAnnotator-0.5.3/src/gui/selection/SelectionHandler.cpp000066400000000000000000000105341414424500400240720ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "SelectionHandler.h" namespace kImageAnnotator { SelectionHandler::SelectionHandler(ISelectionRestrictor *selectionRestrictor) : mAnnotationArea(nullptr), mSelectionRestrictor(selectionRestrictor), mRestrictionEnabled(true) { } SelectionHandler::~SelectionHandler() { delete mSelectionRestrictor; } void SelectionHandler::init(AnnotationArea *annotationArea) { mAnnotationArea = annotationArea; } QRectF SelectionHandler::selection() const { return mSelection; } QVector SelectionHandler::selectionHandles() const { return mHandles.handles(); } void SelectionHandler::grab(const QPointF &position) { mHandles.grabHandle(position, mSelection); if (!mHandles.isHandleGrabbed()) { mMoveHelper.grabSelection(position, mSelection); } if (isInMotion()) { update(); } } void SelectionHandler::move(const QPointF &position) { if (mHandles.isHandleGrabbed()) { auto selection = ShapeHelper::setRectPointAtIndex(mSelection, mHandles.grabbedIndex(), position - mHandles.grabOffset()); setSelection(restrictResize(selection)); } else if (mMoveHelper.isSelectionGabbed()) { auto selection = mSelection; selection.moveTopLeft(position - mMoveHelper.grabOffset()); setSelection(restrictMove(selection)); } if (isInMotion()) { update(); } } void SelectionHandler::release() { if (isInMotion()) { mHandles.releaseHandle(); mMoveHelper.releaseSelection(); update(); } } void SelectionHandler::resetSelection(const QRectF &selection, const QRectF &selectionLimit) { Q_ASSERT(mAnnotationArea != nullptr); setSelection(selection); mSelectionLimit = selectionLimit; } bool SelectionHandler::isInMotion() const { return mMoveHelper.isSelectionGabbed() || mHandles.isHandleGrabbed(); } void SelectionHandler::setWidth(int width) { QRectF selection(mSelection.x(), mSelection.y(), width, mSelection.height()); setSelection(restrictResize(selection)); } void SelectionHandler::setHeight(int height) { QRectF selection(mSelection.x(), mSelection.y(), mSelection.width(), height); setSelection(restrictResize(selection)); } void SelectionHandler::setPositionX(int x) { QRectF selection(x, mSelection.y(), mSelection.width(), mSelection.height()); setSelection(restrictMove(selection)); } void SelectionHandler::setPositionY(int y) { QRectF selection(mSelection.x(), y, mSelection.width(), mSelection.height()); setSelection(restrictMove(selection)); } void SelectionHandler::update() { Q_ASSERT(mAnnotationArea != nullptr); mHandles.updateHandles(mSelection); mAnnotationArea->update(); notifyAboutChange(); } void SelectionHandler::notifyAboutChange() const { emit selectionChanged(mSelection); } void SelectionHandler::setSelection(const QRectF &rect) { mSelection = rect; update(); } bool SelectionHandler::selectionContains(const QPointF &pos) const { return mSelection.contains(pos); } void SelectionHandler::setRestrictionEnabled(bool enabled) { mRestrictionEnabled = enabled; restrictResize(mSelection); update(); } QRectF &SelectionHandler::restrictResize(QRectF &selection) { if(mRestrictionEnabled) { return mSelectionRestrictor->restrictResize(selection, mSelection, mSelectionLimit) ; } else { return selection.isValid() ? selection : mSelection; } } QRectF &SelectionHandler::restrictMove(QRectF &selection) const { return mRestrictionEnabled ? mSelectionRestrictor->restrictMove(selection, mSelectionLimit) : selection; } bool SelectionHandler::restrictionEnabled() const { return mRestrictionEnabled; } void SelectionHandler::applyZoomValue(double value) { mHandles.applyZoomValue(value); mHandles.updateHandles(mSelection); } }kImageAnnotator-0.5.3/src/gui/selection/SelectionHandler.h000066400000000000000000000045571414424500400235470ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CROPHANDLES_H #define KIMAGEANNOTATOR_CROPHANDLES_H #include #include #include "src/gui/cropper/CropSelectionRestrictor.h" #include "src/gui/selection/SelectionHandles.h" #include "SelectionMoveHelper.h" #include "src/annotations/core/AnnotationArea.h" namespace kImageAnnotator { class SelectionHandler : public QObject { Q_OBJECT public: explicit SelectionHandler(ISelectionRestrictor *selectionRestrictor); ~SelectionHandler() override; void init(AnnotationArea *annotationArea); QRectF selection() const; QVector selectionHandles() const; void grab(const QPointF &position); void move(const QPointF &position); void release(); void setWidth(int width); void setHeight(int height); void setPositionX(int x); void setPositionY(int y); void resetSelection(const QRectF &selection, const QRectF &selectionLimit); bool isInMotion() const; bool selectionContains(const QPointF &pos) const; void setRestrictionEnabled(bool enabled); bool restrictionEnabled() const; void applyZoomValue(double value); signals: void selectionChanged(const QRectF &rect) const; private: AnnotationArea *mAnnotationArea; QRectF mSelection; QRectF mSelectionLimit; ISelectionRestrictor *mSelectionRestrictor; SelectionHandles mHandles; SelectionMoveHelper mMoveHelper; bool mRestrictionEnabled; void update(); void notifyAboutChange() const; void setSelection(const QRectF &rect); QRectF &restrictResize(QRectF &selection); QRectF &restrictMove(QRectF &selection) const; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_CROPHANDLES_H kImageAnnotator-0.5.3/src/gui/selection/SelectionHandles.cpp000066400000000000000000000055301414424500400240730ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "SelectionHandles.h" namespace kImageAnnotator { SelectionHandles::SelectionHandles() : mGrabbedIndex(-1), mHandleSize(ScaledSizeProvider::resizeHandleSize()) { for (auto i = 0; i < 8; i++) { mHandles.append(QRectF(0, 0, mHandleSize, mHandleSize)); } } QVector SelectionHandles::handles() const { return mHandles; } void SelectionHandles::grabHandle(const QPointF &position, const QRectF &selection) { for (auto handle : mHandles) { if (handle.contains(position)) { mGrabbedIndex = mHandles.indexOf(handle); mGrabOffset = position - ShapeHelper::rectPointAtIndex(selection, mGrabbedIndex); return; } } mGrabbedIndex = -1; } void SelectionHandles::releaseHandle() { mGrabbedIndex = -1; } int SelectionHandles::grabbedIndex() const { return mGrabbedIndex; } void SelectionHandles::updateHandles(const QRectF &selection) { auto offset = mHandleSize * 0.5; mHandles[0].moveTopLeft(ShapeHelper::rectTopLeftWithOffset(selection, 0).toPoint()); mHandles[1].moveCenter(ShapeHelper::rectTopWithOffset(selection, -offset).toPoint()); mHandles[2].moveTopRight(ShapeHelper::rectTopRightWithOffset(selection, 0).toPoint()); mHandles[3].moveCenter(ShapeHelper::rectRightWithOffset(selection, -offset).toPoint()); mHandles[4].moveBottomRight(ShapeHelper::rectBottomRightWithOffset(selection, 0).toPoint()); mHandles[5].moveCenter(ShapeHelper::rectBottomWithOffset(selection, -offset).toPoint()); mHandles[6].moveBottomLeft(ShapeHelper::rectBottomLeftWithOffset(selection, 0).toPoint()); mHandles[7].moveCenter(ShapeHelper::rectLeftWithOffset(selection, -offset).toPoint()); } bool SelectionHandles::isHandleGrabbed() const { return mGrabbedIndex != -1; } QPointF SelectionHandles::grabOffset() const { return mGrabOffset; } void SelectionHandles::applyZoomValue(double value) { auto oldHandleSize = mHandleSize; mHandleSize = ScaledSizeProvider::resizeHandleSize() / value; auto offset = 0.5 * (oldHandleSize - mHandleSize); for (auto &handle : mHandles) { handle.adjust(offset, offset, -offset, -offset); } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/gui/selection/SelectionHandles.h000066400000000000000000000031121414424500400235320ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CROPHANDELS_H #define KIMAGEANNOTATOR_CROPHANDELS_H #include #include #include "src/common/provider/ScaledSizeProvider.h" #include "src/common/helper/ShapeHelper.h" namespace kImageAnnotator { class SelectionHandles { public: explicit SelectionHandles(); ~SelectionHandles() = default; QVector handles() const; void grabHandle(const QPointF &position, const QRectF &selection); void releaseHandle(); int grabbedIndex() const; void updateHandles(const QRectF &selection); bool isHandleGrabbed() const; QPointF grabOffset() const; void applyZoomValue(double value); private: QVector mHandles; int mGrabbedIndex; QPointF mGrabOffset; double mHandleSize; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_CROPHANDELS_H kImageAnnotator-0.5.3/src/gui/selection/SelectionMoveHelper.cpp000066400000000000000000000026571414424500400245720ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "SelectionMoveHelper.h" namespace kImageAnnotator { SelectionMoveHelper::SelectionMoveHelper() : mIsSelectionGabbed(false) { } void SelectionMoveHelper::grabSelection(const QPointF &position, const QRectF &selection) { if (selection.contains(position)) { mGrabOffset = position - selection.topLeft(); mIsSelectionGabbed = true; } else { mIsSelectionGabbed = false; } } void SelectionMoveHelper::releaseSelection() { mIsSelectionGabbed = false; } bool SelectionMoveHelper::isSelectionGabbed() const { return mIsSelectionGabbed; } QPointF kImageAnnotator::SelectionMoveHelper::grabOffset() const { return mGrabOffset; } } kImageAnnotator-0.5.3/src/gui/selection/SelectionMoveHelper.h000066400000000000000000000025341414424500400242310ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SELECTIONMOVEHELPER_H #define KIMAGEANNOTATOR_SELECTIONMOVEHELPER_H #include #include namespace kImageAnnotator { class SelectionMoveHelper { public: explicit SelectionMoveHelper(); ~SelectionMoveHelper() = default; void grabSelection(const QPointF &position, const QRectF &selection); void releaseSelection(); bool isSelectionGabbed() const; QPointF grabOffset() const; private: bool mIsSelectionGabbed{}; QPointF mGrabOffset; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_SELECTIONMOVEHELPER_H kImageAnnotator-0.5.3/src/widgets/000077500000000000000000000000001414424500400170355ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/widgets/ColorDialogButton.cpp000066400000000000000000000045041414424500400231360ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ColorDialogButton.h" namespace kImageAnnotator { ColorDialogButton::ColorDialogButton(QWidget* parent) : QPushButton(parent) { connect(this, &ColorDialogButton::clicked, this, &ColorDialogButton::openDialog); setIconSize(QSize(48, iconSize().height())); } QColor ColorDialogButton::color() const { return mColor; } void ColorDialogButton::setColor(const QColor& color) { mColor = color; auto pixmapIcon = createPixmapFromColor(mColor); setIcon(pixmapIcon); setToolTip(mColor.name(QColor::HexArgb)); } QPixmap ColorDialogButton::createPixmapFromColor(const QColor& color) const { QImage tiledBackground(QSize(10, 10), QImage::Format_ARGB32_Premultiplied); tiledBackground.fill(Qt::white); QPainter tiledBackgroundPainter(&tiledBackground); tiledBackgroundPainter.setPen(Qt::NoPen); tiledBackgroundPainter.setBrush(Qt::gray); tiledBackgroundPainter.drawRect(0, 0, 5, 5); tiledBackgroundPainter.drawRect(5, 5, 10, 10); QPixmap pixmap(iconSize()); QPainter pixmapPainter(&pixmap); pixmapPainter.setPen(Qt::gray); pixmapPainter.setBrush(tiledBackground); pixmapPainter.drawRect(0,0, iconSize().width() - 1, iconSize().height() - 1); pixmapPainter.setBrush(color); pixmapPainter.drawRect(0,0, iconSize().width() - 1, iconSize().height() - 1); return pixmap; } void ColorDialogButton::openDialog() { auto color = QColorDialog::getColor(mColor, parentWidget(), QString(), QColorDialog::ShowAlphaChannel); if (color.isValid() && color != mColor) { setColor(color); emit colorChanged(color); } } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/widgets/ColorDialogButton.h000066400000000000000000000026621414424500400226060ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_COLORDIALOGBUTTON_H #define KIMAGEANNOTATOR_COLORDIALOGBUTTON_H #include #include #include namespace kImageAnnotator { class ColorDialogButton : public QPushButton { Q_OBJECT public: explicit ColorDialogButton(QWidget *parent); ~ColorDialogButton() override = default; void setColor(const QColor &color); QColor color() const; signals: void colorChanged(const QColor &color); private: QColor mColor; QPixmap createPixmapFromColor(const QColor &color) const; private slots: void openDialog(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_COLORDIALOGBUTTON_H kImageAnnotator-0.5.3/src/widgets/CustomFontComboBox.cpp000066400000000000000000000030361414424500400232750ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "CustomFontComboBox.h" namespace kImageAnnotator { CustomFontComboBox::CustomFontComboBox(QWidget *parent) : QFontComboBox(parent) { connect(this, QOverload::of(&QComboBox::currentIndexChanged), this, &CustomFontComboBox::elideCurrentText); elideCurrentText(); } QString CustomFontComboBox::selectItemText() const { return itemText(currentIndex()); } void CustomFontComboBox::resizeEvent(QResizeEvent *event) { elideCurrentText(); QComboBox::resizeEvent(event); } void CustomFontComboBox::elideCurrentText() { auto buttonsWidth = ScaledSizeProvider::scaledWidth(30); auto elidedText = fontMetrics().elidedText(selectItemText(), Qt::ElideRight, width() - buttonsWidth); setCurrentText(elidedText); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/widgets/CustomFontComboBox.h000066400000000000000000000025751414424500400227510ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CUSTOMFONTCOMBOBOX_H #define KIMAGEANNOTATOR_CUSTOMFONTCOMBOBOX_H #include #include #include "src/common/provider/ScaledSizeProvider.h" namespace kImageAnnotator { class CustomFontComboBox : public QFontComboBox { Q_OBJECT public: explicit CustomFontComboBox(QWidget *parent); ~CustomFontComboBox() override = default; QString selectItemText() const; protected: void resizeEvent(QResizeEvent *event) override; private slots: void elideCurrentText(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_CUSTOMFONTCOMBOBOX_H kImageAnnotator-0.5.3/src/widgets/CustomSpinBox.cpp000066400000000000000000000023461414424500400223230ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "CustomSpinBox.h" namespace kImageAnnotator { kImageAnnotator::CustomSpinBox::CustomSpinBox(QWidget *parent) : QSpinBox(parent) { setAlignment(Qt::AlignHCenter); connect(this, static_cast(&QSpinBox::valueChanged), this, &CustomSpinBox::valueChanged); } void CustomSpinBox::setValueSilent(int value) { blockSignals(true); QSpinBox::setValue(value); blockSignals(false); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/widgets/CustomSpinBox.h000066400000000000000000000023231414424500400217630ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CUSTOMSPINBOX_H #define KIMAGEANNOTATOR_CUSTOMSPINBOX_H #include namespace kImageAnnotator { class CustomSpinBox : public QSpinBox { Q_OBJECT public: explicit CustomSpinBox(QWidget *parent = nullptr); ~CustomSpinBox() override = default; void setValueSilent(int value); signals: void valueChanged(int) const; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_CUSTOMSPINBOX_H kImageAnnotator-0.5.3/src/widgets/CustomToolButton.cpp000066400000000000000000000035371414424500400230550ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "CustomToolButton.h" namespace kImageAnnotator { CustomToolButton::CustomToolButton(QWidget *parent) : QToolButton(parent) { setCheckable(true); setAutoRaise(true); setIconSize(ScaledSizeProvider::scaledSize(QSize(24, 24))); setFocusPolicy(Qt::NoFocus); connect(this, &CustomToolButton::triggered, this, &CustomToolButton::setActiveAction); } void CustomToolButton::setButtonText(const QString &text) { mButtonText = text; refreshText(); } void CustomToolButton::setActiveAction(QAction *action) { QToolButton::setDefaultAction(action); refreshText(); } void CustomToolButton::trigger() { if (defaultAction() != nullptr) { defaultAction()->trigger(); } } void CustomToolButton::refreshText() { QToolButton::setText(mButtonText); } void CustomToolButton::setMenu(QMenu *menu) { setPopupMode(QToolButton::MenuButtonPopup); QToolButton::setMenu(menu); setActiveAction(menu->actions().first()); } void CustomToolButton::setAction(QAction *action) { setPopupMode(QToolButton::DelayedPopup); setDefaultAction(action); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/widgets/CustomToolButton.h000066400000000000000000000027371414424500400225230ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CUSTOMTOOLBUTTON_H #define KIMAGEANNOTATOR_CUSTOMTOOLBUTTON_H #include #include #include #include "src/common/provider/ScaledSizeProvider.h" namespace kImageAnnotator { class CustomToolButton : public QToolButton { Q_OBJECT public: explicit CustomToolButton(QWidget *parent = nullptr); ~CustomToolButton() override = default; void setButtonText(const QString &text); void setMenu(QMenu *menu); void setAction(QAction *action); public slots: void setActiveAction(QAction *action); void trigger(); void refreshText(); private: QString mButtonText; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_CUSTOMTOOLBUTTON_H kImageAnnotator-0.5.3/src/widgets/CustomToolButtonAction.cpp000066400000000000000000000033121414424500400242020ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "CustomToolButtonAction.h" namespace kImageAnnotator { CustomToolButtonAction::CustomToolButtonAction(QObject *parent) : QWidgetAction(parent) { initDefaultWidget(); } CustomToolButtonAction::~CustomToolButtonAction() { delete mText; delete mImage; delete mLayout; delete mMenuItem; } void CustomToolButtonAction::updateDefaultWidget() { mText->setText(toolTip()); mImage->setPixmap(icon().pixmap(ScaledSizeProvider::menuItemIconSize())); mMenuItem->setToolTip(toolTip()); setDefaultWidget(mMenuItem); } void CustomToolButtonAction::initDefaultWidget() { mMenuItem = new QWidget; mText = new QLabel(mMenuItem); mImage = new QLabel(mMenuItem); mLayout = new QHBoxLayout(mMenuItem); mLayout->setAlignment(Qt::AlignLeft); mLayout->addWidget(mImage); mLayout->addWidget(mText); mMenuItem->setLayout(mLayout); mMenuItem->setStyleSheet(QLatin1String(":hover{background-color:palette(highlight);}")); } } kImageAnnotator-0.5.3/src/widgets/CustomToolButtonAction.h000066400000000000000000000026471414424500400236610ustar00rootroot00000000000000/* * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CUSTOMTOOLBUTTONMENU_H #define KIMAGEANNOTATOR_CUSTOMTOOLBUTTONMENU_H #include #include #include #include #include "src/common/provider/ScaledSizeProvider.h" namespace kImageAnnotator { class CustomToolButtonAction : public QWidgetAction { public: explicit CustomToolButtonAction(QObject *parent); ~CustomToolButtonAction() override; void updateDefaultWidget(); private: QLabel *mImage; QLabel *mText; QHBoxLayout *mLayout; QWidget *mMenuItem; void initDefaultWidget(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_CUSTOMTOOLBUTTONMENU_H kImageAnnotator-0.5.3/src/widgets/ToggleButton.cpp000066400000000000000000000017521414424500400221630ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ToggleButton.h" namespace kImageAnnotator { ToggleButton::ToggleButton(QWidget *parent) : QToolButton(parent) { setCheckable(true); setFocusPolicy(Qt::NoFocus); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/widgets/ToggleButton.h000066400000000000000000000021621414424500400216240ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_TOGGLEBUTTON_H #define KIMAGEANNOTATOR_TOGGLEBUTTON_H #include namespace kImageAnnotator { class ToggleButton : public QToolButton { Q_OBJECT public: explicit ToggleButton(QWidget *parent); ~ToggleButton() override = default; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_TOGGLEBUTTON_H kImageAnnotator-0.5.3/src/widgets/ToolPicker.cpp000066400000000000000000000135471414424500400216260ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ToolPicker.h" namespace kImageAnnotator { ToolPicker::ToolPicker(QWidget *parent) : QWidget(parent), mLayout(new FlowLayout(this)), mActionGroup(new QActionGroup(this)), mSelectedToolType(Tools::Select) { initGui(); setFocusPolicy(Qt::ClickFocus); } void ToolPicker::setTool(Tools newTool) { auto action = mActionToTool.key(newTool); auto button = mActionToButton[action]; button->setDefaultAction(action); action->setChecked(true); setToolAndNotify(newTool); } Tools ToolPicker::tool() { return mSelectedToolType; } void ToolPicker::initGui() { connect(mActionGroup, &QActionGroup::triggered, this, &ToolPicker::actionTriggered); auto action = createAction(tr("Select"), IconLoader::load(QLatin1String("select.svg")), Qt::Key_S, Tools::Select); createButton(action); action = createAction(tr("Duplicate"), IconLoader::load(QLatin1String("duplicate.svg")), Qt::Key_U, Tools::Duplicate); createButton(action); auto menu = new QMenu(this); action = createAction(tr("Arrow"), IconLoader::load(QLatin1String("arrow.svg")), Qt::Key_A, Tools::Arrow); menu->addAction(action); action = createAction(tr("Double Arrow"), IconLoader::load(QLatin1String("doubleArrow.svg")), Qt::Key_D, Tools::DoubleArrow); menu->addAction(action); action = createAction(tr("Line"), IconLoader::load(QLatin1String("line.svg")), Qt::Key_L, Tools::Line); menu->addAction(action); createButton(menu); action = createAction(tr("Pen"), IconLoader::load(QLatin1String("pen.svg")), Qt::Key_P, Tools::Pen); createButton(action); menu = new QMenu(this); action = createAction(tr("Marker Pen"), IconLoader::load(QLatin1String("markerPen.svg")), Qt::Key_M, Tools::MarkerPen); menu->addAction(action); action = createAction(tr("Marker Rectangle"), IconLoader::load(QLatin1String("markerRect.svg")), Qt::Key_J, Tools::MarkerRect); menu->addAction(action); action = createAction(tr("Marker Ellipse"), IconLoader::load(QLatin1String("markerEllipse.svg")), Qt::Key_K, Tools::MarkerEllipse); menu->addAction(action); createButton(menu); menu = new QMenu(this); action = createAction(tr("Text"), IconLoader::load(QLatin1String("text.svg")), Qt::Key_T, Tools::Text); menu->addAction(action); action = createAction(tr("Text Pointer"), IconLoader::load(QLatin1String("textPointer.svg")), Qt::Key_C, Tools::TextPointer); menu->addAction(action); action = createAction(tr("Text Arrow"), IconLoader::load(QLatin1String("textArrow.svg")), Qt::Key_H, Tools::TextArrow); menu->addAction(action); createButton(menu); menu = new QMenu(this); action = createAction(tr("Number"), IconLoader::load(QLatin1String("number.svg")), Qt::Key_N, Tools::Number); menu->addAction(action); action = createAction(tr("Number Pointer"), IconLoader::load(QLatin1String("numberPointer.svg")), Qt::Key_O, Tools::NumberPointer); menu->addAction(action); action = createAction(tr("Number Arrow"), IconLoader::load(QLatin1String("numberArrow.svg")), Qt::Key_W, Tools::NumberArrow); menu->addAction(action); createButton(menu); menu = new QMenu(this); action = createAction(tr("Blur"), IconLoader::load(QLatin1String("blur.svg")), Qt::Key_B, Tools::Blur); menu->addAction(action); action = createAction(tr("Pixelate"), IconLoader::load(QLatin1String("pixelate.svg")), Qt::Key_X, Tools::Pixelate); menu->addAction(action); createButton(menu); menu = new QMenu(this); action = createAction(tr("Rectangle"), IconLoader::load(QLatin1String("rect.svg")), Qt::Key_R, Tools::Rect); menu->addAction(action); action = createAction(tr("Ellipse"), IconLoader::load(QLatin1String("ellipse.svg")), Qt::Key_E, Tools::Ellipse); menu->addAction(action); createButton(menu); action = createAction(tr("Sticker"), IconLoader::load(QLatin1String("sticker.svg")), Qt::Key_I, Tools::Sticker); createButton(action); mLayout->setContentsMargins(3, 0, 0, 3); mLayout->setSpacing(2, 2); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setLayout(mLayout); } QAction *ToolPicker::createAction(const QString &tooltip, const QIcon &icon, Qt::Key shortcut, Tools toolType) { auto action = new CustomToolButtonAction(this); action->setCheckable(true); action->setIcon(icon); action->setShortcut(shortcut); action->setToolTip(tooltip + QLatin1String(" (") + shortcut + QLatin1String(")")); action->updateDefaultWidget(); mActionToTool[action] = toolType; mActionGroup->addAction(action); return action; } CustomToolButton *ToolPicker::createButton(QAction *defaultAction) { auto button = new CustomToolButton(this); button->setAction(defaultAction); mActionToButton[defaultAction] = button; mLayout->addWidget(button); return button; } CustomToolButton *ToolPicker::createButton(QMenu *menu) { auto button = new CustomToolButton(this); button->setMenu(menu); for(auto action : menu->actions()) { mActionToButton[action] = button; } mLayout->addWidget(button); return button; } void ToolPicker::actionTriggered(QAction *action) { auto newTool = mActionToTool.value(action); setToolAndNotify(newTool); } void ToolPicker::setToolAndNotify(Tools newTool) { mSelectedToolType = newTool; emit toolSelected(mSelectedToolType); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/widgets/ToolPicker.h000066400000000000000000000036621414424500400212700ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_TOOLPICKER_H #define KIMAGEANNOTATOR_TOOLPICKER_H #include #include #include #include #include "CustomToolButton.h" #include "CustomToolButtonAction.h" #include "src/common/enum/Tools.h" #include "src/common/helper/IconLoader.h" #include "src/widgets/misc/FlowLayout.h" namespace kImageAnnotator { class ToolPicker : public QWidget { Q_OBJECT public: explicit ToolPicker(QWidget *parent); ~ToolPicker() override = default; void setTool(Tools newTool); Tools tool(); signals: void toolSelected(Tools newTool); private: QActionGroup *mActionGroup; FlowLayout *mLayout; Tools mSelectedToolType; QHash mActionToTool; QHash mActionToButton; void initGui(); QAction *createAction(const QString &tooltip, const QIcon &icon, Qt::Key shortcut, Tools toolType); CustomToolButton *createButton(QAction *defaultAction); CustomToolButton *createButton(QMenu *menu); private slots: void actionTriggered(QAction *action); void setToolAndNotify(Tools newTool); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_TOOLPICKER_H kImageAnnotator-0.5.3/src/widgets/menuButtons/000077500000000000000000000000001414424500400213605ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/widgets/menuButtons/GridMenu.cpp000066400000000000000000000061371414424500400236050ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "GridMenu.h" namespace kImageAnnotator { GridMenu::GridMenu(QWidget *parent) : QMenu(parent), mLayout(new QGridLayout(this)), mButtonGroup(new QButtonGroup(this)) { setLayout(mLayout); mLayout->setSpacing(0); mLayout->setContentsMargins(4, 4, 4, 4); } GridMenu::~GridMenu() { qDeleteAll(mButtonGroup->buttons()); } void GridMenu::addItem(const QIcon &icon, const QString &toolTip, const QVariant &data) { auto button = createButton(icon, toolTip, data); addButtonToLayout(button); if(mLayout->count() == 1) { button->setChecked(true); emit selectionChanged(); } } void GridMenu::addButtonToLayout(GridMenuButton *button) { auto itemCount = mLayout->count(); auto row = itemCount / 4; auto column = (itemCount % 4) + 1; mLayout->addWidget(button, row, column); } GridMenuButton *GridMenu::createButton(const QIcon &icon, const QString &toolTip, const QVariant &data) const { auto button = new GridMenuButton(icon, toolTip, data); connect(button, &QToolButton::clicked, this, &GridMenu::buttonClicked); mButtonGroup->addButton(button); return button; } void kImageAnnotator::GridMenu::setCurrentData(const QVariant &data) { for(auto button : mButtonGroup->buttons()) { auto gridMenuButton = dynamic_cast(button); if(gridMenuButton != nullptr && gridMenuButton->data() == data) { gridMenuButton->setChecked(true); emit selectionChanged(); return; } } } QIcon kImageAnnotator::GridMenu::currentIcon() const { auto button = mButtonGroup->checkedButton(); return button != nullptr ? button->icon() : QIcon(); } QVariant kImageAnnotator::GridMenu::currentData() const { auto button = dynamic_cast(mButtonGroup->checkedButton()); return button != nullptr ? button->data() : QVariant(); } QString kImageAnnotator::GridMenu::currentToolTip() const { auto button = mButtonGroup->checkedButton(); return button != nullptr ? button->toolTip() : QString(); } void GridMenu::clear() { auto buttons = mButtonGroup->buttons(); for(auto button : buttons) { mButtonGroup->removeButton(button); mLayout->removeWidget(button); } qDeleteAll(buttons); QMenu::clear(); emit selectionChanged(); } QSize GridMenu::sizeHint() const { return mLayout->sizeHint(); } void kImageAnnotator::GridMenu::buttonClicked() { close(); emit selectionChanged(); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/widgets/menuButtons/GridMenu.h000066400000000000000000000033701414424500400232460ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_GRIDMENU_H #define KIMAGEANNOTATOR_GRIDMENU_H #include #include #include #include #include "GridMenuButton.h" #include "src/common/provider/DevicePixelRatioScaler.h" namespace kImageAnnotator { class GridMenu : public QMenu { Q_OBJECT public: explicit GridMenu(QWidget *parent); ~GridMenu() override; void addItem(const QIcon &icon, const QString &toolTip, const QVariant &data); void setCurrentData(const QVariant &data); QIcon currentIcon() const; QVariant currentData() const; QString currentToolTip() const; void clear(); QSize sizeHint() const override; signals: void selectionChanged(); private: QButtonGroup *mButtonGroup; QGridLayout *mLayout; void buttonClicked(); GridMenuButton *createButton(const QIcon &icon, const QString &toolTip, const QVariant &data) const; void addButtonToLayout(GridMenuButton *button); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_GRIDMENU_H kImageAnnotator-0.5.3/src/widgets/menuButtons/GridMenuButton.cpp000066400000000000000000000035741414424500400250030ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "GridMenuButton.h" namespace kImageAnnotator { GridMenuButton::GridMenuButton(const QIcon &icon, const QString &toolTip, QVariant data) : mData(std::move(data)) { setIcon(icon); setToolTip(toolTip); setIconSize(ScaledSizeProvider::scaledSize(QSize(32, 32))); setCheckable(true); setFixedSize(iconSize() + ScaledSizeProvider::scaledSize(QSize(4,4))); } QVariant kImageAnnotator::GridMenuButton::data() const { return mData; } void GridMenuButton::paintEvent(QPaintEvent *event) { QPainter painter(this); QStyleOption styleOption; styleOption.initFrom(this); auto buttonRect = event->rect().adjusted(0, 0, -1, -1); if(styleOption.state & QStyle::State_MouseOver) { auto defaultPen = painter.pen(); auto defaultBrush = painter.brush(); painter.setPen(Constants::HoverColor); painter.setBrush(Constants::HoverColor); painter.drawRect(buttonRect); painter.setPen(defaultPen); painter.setBrush(defaultBrush); } painter.drawPixmap(buttonRect.topLeft() + QPointF(2, 2), icon().pixmap(iconSize())); if(isChecked()) { painter.drawRect(buttonRect); } } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/widgets/menuButtons/GridMenuButton.h000066400000000000000000000026351414424500400244450ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_GRIDMENUBUTTON_H #define KIMAGEANNOTATOR_GRIDMENUBUTTON_H #include #include #include #include #include #include "src/common/provider/ScaledSizeProvider.h" namespace kImageAnnotator { class GridMenuButton : public QToolButton { Q_OBJECT public: GridMenuButton(const QIcon &icon, const QString &toolTip, QVariant data); ~GridMenuButton() override = default; QVariant data() const; protected slots: void paintEvent(QPaintEvent *event) override; private: QVariant mData; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_GRIDMENUBUTTON_H kImageAnnotator-0.5.3/src/widgets/menuButtons/GridMenuToolButton.cpp000066400000000000000000000033631414424500400256350ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "GridMenuToolButton.h" namespace kImageAnnotator { GridMenuToolButton::GridMenuToolButton(QWidget *parent) : QToolButton(parent), mMenu(new GridMenu(this)) { setMenu(mMenu); connect(mMenu, &GridMenu::selectionChanged, this, &GridMenuToolButton::selectionChanged); connect(mMenu, &GridMenu::selectionChanged, this, &GridMenuToolButton::updateIconAndToolTip); } GridMenuToolButton::~GridMenuToolButton() { delete mMenu; } void GridMenuToolButton::addItem(const QIcon &icon, const QString &toolTip, const QVariant &data) { mMenu->addItem(icon, toolTip, data); } QVariant GridMenuToolButton::currentData() const { return mMenu->currentData(); } void kImageAnnotator::GridMenuToolButton::setCurrentData(const QVariant &data) { mMenu->setCurrentData(data); } void GridMenuToolButton::clear() { mMenu->clear(); } void GridMenuToolButton::updateIconAndToolTip() { setIcon(mMenu->currentIcon()); setToolTip(mMenu->currentToolTip()); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/widgets/menuButtons/GridMenuToolButton.h000066400000000000000000000027221414424500400253000ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_GRIDMENUTOOLBUTTON_H #define KIMAGEANNOTATOR_GRIDMENUTOOLBUTTON_H #include #include "src/widgets/menuButtons/GridMenu.h" namespace kImageAnnotator { class GridMenuToolButton : public QToolButton { Q_OBJECT public: explicit GridMenuToolButton(QWidget *parent); ~GridMenuToolButton() override; void addItem(const QIcon &icon, const QString &toolTip, const QVariant &data); QVariant currentData() const; void setCurrentData(const QVariant &data); void clear(); signals: void selectionChanged(); private: GridMenu *mMenu; private slots: void updateIconAndToolTip(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_GRIDMENUTOOLBUTTON_H kImageAnnotator-0.5.3/src/widgets/menuButtons/ListItemGroup.cpp000066400000000000000000000031051414424500400246320ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ListItemGroup.h" namespace kImageAnnotator { ListItemGroup::ListItemGroup(QObject *parent) : QObject(parent), mCheckedItem(nullptr) { } void ListItemGroup::addItem(ListMenuItem *item) { mItems.append(item); connect(item, &ListMenuItem::toggled, this, &ListItemGroup::updateCheckedItem); if(mCheckedItem == nullptr) { mCheckedItem = item; mCheckedItem->setIsChecked(true); } } ListMenuItem *ListItemGroup::checkedItem() const { return mCheckedItem; } QList ListItemGroup::items() const { return mItems; } void ListItemGroup::updateCheckedItem() { auto item = dynamic_cast(sender()); if(item != nullptr && item->isChecked()) { mCheckedItem->setIsChecked(false); mCheckedItem = item; emit checkedItemChanged(); } } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/widgets/menuButtons/ListItemGroup.h000066400000000000000000000026651414424500400243110ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_LISTITEMGROUP_H #define KIMAGEANNOTATOR_LISTITEMGROUP_H #include #include #include "src/widgets/menuButtons/ListMenuItem.h" namespace kImageAnnotator { class ListItemGroup : public QObject { Q_OBJECT public: explicit ListItemGroup(QObject *parent); ~ListItemGroup() override = default; void addItem(ListMenuItem *item); ListMenuItem* checkedItem() const; QList items() const; signals: void checkedItemChanged(); private: QList mItems; ListMenuItem *mCheckedItem; private slots: void updateCheckedItem(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_LISTITEMGROUP_H kImageAnnotator-0.5.3/src/widgets/menuButtons/ListMenu.cpp000066400000000000000000000044701414424500400236310ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ListMenu.h" namespace kImageAnnotator { ListMenu::ListMenu(QWidget *parent) : QMenu(parent), mLayout(new QVBoxLayout(this)), mListItemGroup(new ListItemGroup(this)) { setLayout(mLayout); mLayout->setContentsMargins(0, 0, 0, 0); mLayout->setSpacing(0); connect(mListItemGroup, &ListItemGroup::checkedItemChanged, this, &ListMenu::selectionChanged); } ListMenu::~ListMenu() { qDeleteAll(mListItemGroup->items()); } void ListMenu::addItem(const QIcon &icon, const QString &text, const QVariant &data) { auto item = new ListMenuItem(icon, text, data, this); mLayout->addWidget(item); mListItemGroup->addItem(item); } QVariant ListMenu::currentData() const { auto item = mListItemGroup->checkedItem(); return item != nullptr ? item->data() : QVariant(); } void ListMenu::setCurrentData(const QVariant &data) { for(auto item : mListItemGroup->items()) { if(item->data() == data){ item->setIsChecked(true); return; } } } QIcon ListMenu::currentIcon() const { auto item = mListItemGroup->checkedItem(); return item != nullptr ? item->icon() : QIcon(); } QString ListMenu::currentText() const { auto item = mListItemGroup->checkedItem(); return item != nullptr ? item->text() : QString(); } void ListMenu::setDataVisible(const QVariant &data, bool isVisible) { for(auto item : mListItemGroup->items()) { if(item->data() == data){ item->setVisible(isVisible); setMinimumSize(mLayout->minimumSize()); return; } } } QSize ListMenu::sizeHint() const { return mLayout->sizeHint(); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/widgets/menuButtons/ListMenu.h000066400000000000000000000032161414424500400232730ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_LISTMENU_H #define KIMAGEANNOTATOR_LISTMENU_H #include #include #include "src/widgets/menuButtons/ListMenuItem.h" #include "src/widgets/menuButtons/ListItemGroup.h" #include "src/common/provider/DevicePixelRatioScaler.h" namespace kImageAnnotator { class ListMenu : public QMenu { Q_OBJECT public: explicit ListMenu(QWidget *parent); ~ListMenu() override; void addItem(const QIcon &icon, const QString &text, const QVariant &data); QVariant currentData() const; void setCurrentData(const QVariant &data); QIcon currentIcon() const; QString currentText() const; void setDataVisible(const QVariant &data, bool isVisible); QSize sizeHint() const override; signals: void selectionChanged(); private: QVBoxLayout *mLayout; ListItemGroup *mListItemGroup; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_LISTMENU_H kImageAnnotator-0.5.3/src/widgets/menuButtons/ListMenuItem.cpp000066400000000000000000000062541414424500400244520ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include "ListMenuItem.h" namespace kImageAnnotator { ListMenuItem::ListMenuItem(const QIcon &icon, const QString &text, const QVariant &data, QWidget *parent) : QWidget(parent), mIcon(icon), mText(text), mData(data), mIsChecked(false), mSpacer(6), mMargin(5) { setMouseTracking(true); mIconSize = ScaledSizeProvider::menuItemIconSize(); auto offsetForTextWidth = 1.15; // Width not correct calculated on windows #117 mTextSize = QSize(fontMetrics().width(mText) * offsetForTextWidth, fontMetrics().height()); mIconOffset = QPoint(mMargin, mMargin); mTextOffset = QPoint(mIconSize.width() + mIconOffset.x() + mSpacer, (mIconSize.height() - mTextSize.height()) / 2 + mIconOffset.y()); mSize = QSize(mIconSize.width() + mTextSize.width() + mMargin * 2 + mSpacer, mIconSize.height() + mMargin * 2); } QVariant ListMenuItem::data() const { return mData; } QIcon ListMenuItem::icon() const { return mIcon; } QString ListMenuItem::text() const { return mText; } QSize ListMenuItem::minimumSizeHint() const { return mSize; } bool ListMenuItem::isChecked() const { return mIsChecked; } void ListMenuItem::setIsChecked(bool isChecked) { mIsChecked = isChecked; emit toggled(isChecked); update(); } void ListMenuItem::paintEvent(QPaintEvent *event) { QPainter painter(this); QStyleOption styleOption; styleOption.initFrom(this); auto rect = event->rect().adjusted(0,0,-1,-1); if(styleOption.state & QStyle::State_MouseOver) { auto defaultBrush = painter.brush(); auto defaultPen = painter.pen(); painter.setBrush(Constants::HoverColor); painter.setPen(Constants::HoverColor); painter.drawRect(rect); painter.setBrush(defaultBrush); painter.setPen(defaultPen); } painter.drawPixmap(rect.topLeft() + mIconOffset, mIcon.pixmap(mIconSize)); painter.drawText(QRect(rect.topLeft() + mTextOffset, mTextSize), Qt::AlignLeft | Qt::AlignVCenter, mText); if(mIsChecked) { painter.drawRect(rect); } } void ListMenuItem::mouseMoveEvent(QMouseEvent *event) { update(); QWidget::mouseMoveEvent(event); } void ListMenuItem::leaveEvent(QEvent *event) { update(); QWidget::leaveEvent(event); } void ListMenuItem::mouseReleaseEvent(QMouseEvent* event) { QWidget::mouseReleaseEvent(event); QRect itemRect(QPoint(0, 0), mSize); if (isEnabled() && itemRect.contains(mapFromGlobal(QCursor::pos()))) { mIsChecked = true; emit toggled(mIsChecked); } } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/widgets/menuButtons/ListMenuItem.h000066400000000000000000000036161414424500400241160ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_LISTMENUITEM_H #define KIMAGEANNOTATOR_LISTMENUITEM_H #include #include #include #include #include "src/common/provider/ScaledSizeProvider.h" namespace kImageAnnotator { class ListMenuItem : public QWidget { Q_OBJECT public: explicit ListMenuItem(const QIcon &icon, const QString &text, const QVariant &data, QWidget *parent); ~ListMenuItem() override = default; QVariant data() const; QIcon icon() const; QString text() const; QSize minimumSizeHint() const override; bool isChecked() const; void setIsChecked(bool isChecked); signals: void toggled(bool isChecked); protected: void paintEvent(QPaintEvent* event) override; void mouseMoveEvent(QMouseEvent *event) override; void leaveEvent(QEvent *event) override; void mouseReleaseEvent(QMouseEvent* event) override; private: QString mText; QIcon mIcon; bool mIsChecked; QVariant mData; QSize mIconSize; QSize mTextSize; QPoint mIconOffset; QPoint mTextOffset; int mMargin; int mSpacer; QSize mSize; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_LISTMENUITEM_H kImageAnnotator-0.5.3/src/widgets/menuButtons/ListMenuToolButton.cpp000066400000000000000000000035111414424500400256560ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ListMenuToolButton.h" namespace kImageAnnotator { ListMenuToolButton::ListMenuToolButton(QWidget *parent) : QToolButton(parent), mMenu(new ListMenu(this)) { setPopupMode(QToolButton::InstantPopup); setMenu(mMenu); connect(mMenu, &ListMenu::selectionChanged, this, &ListMenuToolButton::selectionChanged); connect(mMenu, &ListMenu::selectionChanged, this, &ListMenuToolButton::updateIconAndToolTip); } ListMenuToolButton::~ListMenuToolButton() { delete mMenu; } void ListMenuToolButton::addItem(const QIcon &icon, const QString &text, const QVariant &data) { mMenu->addItem(icon, text, data); } QVariant ListMenuToolButton::currentData() const { return mMenu->currentData(); } void ListMenuToolButton::setCurrentData(const QVariant &data) { mMenu->setCurrentData(data); } void ListMenuToolButton::setDataVisible(const QVariant &data, bool isVisible) { mMenu->setDataVisible(data, isVisible); } void ListMenuToolButton::updateIconAndToolTip() { setIcon(mMenu->currentIcon()); setToolTip(mMenu->currentText()); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/widgets/menuButtons/ListMenuToolButton.h000066400000000000000000000027741414424500400253350ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_LISTMENUTOOLBUTTON_H #define KIMAGEANNOTATOR_LISTMENUTOOLBUTTON_H #include #include "src/widgets/menuButtons/ListMenu.h" namespace kImageAnnotator { class ListMenuToolButton : public QToolButton { Q_OBJECT public: explicit ListMenuToolButton(QWidget *parent); ~ListMenuToolButton() override; void addItem(const QIcon &icon, const QString &text, const QVariant &data); QVariant currentData() const; void setCurrentData(const QVariant &data); void setDataVisible(const QVariant &data, bool isVisible); signals: void selectionChanged(); private: ListMenu *mMenu; private slots: void updateIconAndToolTip(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_LISTMENUTOOLBUTTON_H kImageAnnotator-0.5.3/src/widgets/misc/000077500000000000000000000000001414424500400177705ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/widgets/misc/AbstractExpandingWidget.cpp000066400000000000000000000021461414424500400252440ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AbstractExpandingWidget.h" namespace kImageAnnotator { void AbstractExpandingWidget::setExpanding(bool enabled) { auto horizontalPolicy = enabled ? QSizePolicy::Expanding : QSizePolicy::Preferred; expandingWidget()->setSizePolicy(horizontalPolicy, QSizePolicy::Preferred); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/widgets/misc/AbstractExpandingWidget.h000066400000000000000000000023471414424500400247140ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ABSTRACTEXPANDINGWIDGET_H #define KIMAGEANNOTATOR_ABSTRACTEXPANDINGWIDGET_H #include namespace kImageAnnotator { class AbstractExpandingWidget { public: AbstractExpandingWidget() = default; ~AbstractExpandingWidget() = default; virtual void setExpanding(bool enabled); protected: virtual QWidget* expandingWidget() = 0; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ABSTRACTEXPANDINGWIDGET_H kImageAnnotator-0.5.3/src/widgets/misc/AttachedSeparator.cpp000066400000000000000000000031321414424500400240710ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AttachedSeparator.h" namespace kImageAnnotator { AttachedSeparator::AttachedSeparator(SettingsPickerWidget *target) : QFrame(target), mTarget(target) { Q_ASSERT(mTarget != nullptr); setContentsMargins(0, 3, 0, 3); setFrameShape(QFrame::VLine); setFrameShadow(QFrame::Sunken); connect(mTarget, &SettingsPickerWidget::visibilityChanged, this, &AttachedSeparator::targetVisibilityChanged); updateVisibility(); } void AttachedSeparator::targetVisibilityChanged(bool visible) { setVisible(visible && isEnabled()); } void AttachedSeparator::changeEvent(QEvent *event) { if(event->type() == QEvent::EnabledChange) { updateVisibility(); } QFrame::changeEvent(event); } void AttachedSeparator::updateVisibility() { targetVisibilityChanged(mTarget->isVisible()); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/widgets/misc/AttachedSeparator.h000066400000000000000000000026511414424500400235430ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ATTACHEDSEPARATOR_H #define KIMAGEANNOTATOR_ATTACHEDSEPARATOR_H #include #include #include "src/widgets/settingsPicker/SettingsPickerWidget.h" namespace kImageAnnotator { class AttachedSeparator : public QFrame { Q_OBJECT public: explicit AttachedSeparator(SettingsPickerWidget *target); ~AttachedSeparator() override = default; protected: void changeEvent(QEvent *event) override; private: SettingsPickerWidget *mTarget; void updateVisibility(); private slots: void targetVisibilityChanged(bool visible); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ATTACHEDSEPARATOR_H kImageAnnotator-0.5.3/src/widgets/misc/FlowLayout.cpp000066400000000000000000000104221414424500400226000ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "FlowLayout.h" /* * Implementation based on Qt FlowLayout Example https://doc.qt.io/qt-5/qtwidgets-layouts-flowlayout-example.html */ namespace kImageAnnotator { FlowLayout::FlowLayout(QWidget *parent) : QLayout(parent), mHorizontalSpacing(-1), mVerticalSpacing(-1) { } FlowLayout::~FlowLayout() { qDeleteAll(mItems); } void FlowLayout::addItem(QLayoutItem *item) { mItems.append(item); } int FlowLayout::horizontalSpacing() const { return mHorizontalSpacing >= 0 ? mHorizontalSpacing : smartSpacing(QStyle::PM_LayoutHorizontalSpacing); } int FlowLayout::verticalSpacing() const { return mVerticalSpacing >= 0 ? mVerticalSpacing : smartSpacing(QStyle::PM_LayoutVerticalSpacing); } int FlowLayout::count() const { return mItems.size(); } QLayoutItem *FlowLayout::itemAt(int index) const { return mItems.value(index); } QLayoutItem *FlowLayout::takeAt(int index) { if (index < 0 || index >= count()) { return nullptr; } return mItems.takeAt(index); } void FlowLayout::setSpacing(int horizontal, int vertical) { mHorizontalSpacing = horizontal; mVerticalSpacing = vertical; } Qt::Orientations FlowLayout::expandingDirections() const { return { }; } bool FlowLayout::hasHeightForWidth() const { return true; } int FlowLayout::heightForWidth(int width) const { auto rect = QRect(0, 0, width, 0); auto height = calculateLayout(rect, false); return height; } void FlowLayout::setGeometry(const QRect &rect) { QLayout::setGeometry(rect); calculateLayout(rect, true); } QSize FlowLayout::sizeHint() const { return minimumSize(); } QSize FlowLayout::minimumSize() const { QSize size; for (auto item : qAsConst(mItems)) { size = size.expandedTo(item->minimumSize()); } auto margins = contentsMargins(); size += QSize(margins.left() + margins.right(), margins.top() + margins.bottom()); return size; } int FlowLayout::calculateLayout(const QRect &rect, bool applyChanged) const { auto margins = contentsMargins(); auto effectiveRect = rect.adjusted(+margins.left(), +margins.top(), -margins.right(), -margins.bottom()); auto x = effectiveRect.x(); auto y = effectiveRect.y(); auto spaceX = horizontalSpacing(); auto spaceY = verticalSpacing(); auto lineHeight = 0; auto largestItemWidth = 0; auto largestItemHeight = 0; auto minHorizontalWidth = 0; for (auto item : qAsConst(mItems)) { largestItemWidth = qMax(item->sizeHint().width(), largestItemWidth); largestItemHeight = qMax(item->sizeHint().height(), largestItemHeight); minHorizontalWidth += item->sizeHint().width(); } auto isEqualWidthPerItemRequired = largestItemHeight * 2 > effectiveRect.height() || effectiveRect.width() >= minHorizontalWidth ; for (auto item : qAsConst(mItems)) { auto width = isEqualWidthPerItemRequired ? item->sizeHint().width() : largestItemWidth; auto nextX = x + width + spaceX; auto isOutsideCurrentRow = nextX - spaceX > effectiveRect.right() && lineHeight > 0; if (isOutsideCurrentRow) { x = effectiveRect.x(); y = y + lineHeight + spaceY; nextX = x + width + spaceX; lineHeight = 0; } if (applyChanged) { item->setGeometry(QRect(QPoint(x, y), item->sizeHint())); } x = nextX; lineHeight = qMax(lineHeight, item->sizeHint().height()); } return y + lineHeight - rect.y() + margins.bottom(); } int FlowLayout::smartSpacing(QStyle::PixelMetric pixelMetric) const { auto parent = this->parent(); auto parentWidget = dynamic_cast(parent); return parentWidget->style()->pixelMetric(pixelMetric, nullptr, parentWidget); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/widgets/misc/FlowLayout.h000066400000000000000000000035431414424500400222530ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_FLOWLAYOUT_H #define KIMAGEANNOTATOR_FLOWLAYOUT_H #include #include #include namespace kImageAnnotator { class FlowLayout : public QLayout { public: explicit FlowLayout(QWidget *parent); ~FlowLayout() override; void addItem(QLayoutItem *item) override; int horizontalSpacing() const; int verticalSpacing() const; Qt::Orientations expandingDirections() const override; bool hasHeightForWidth() const override; int heightForWidth(int) const override; int count() const override; QLayoutItem *itemAt(int index) const override; QSize minimumSize() const override; void setGeometry(const QRect &rect) override; QSize sizeHint() const override; QLayoutItem *takeAt(int index) override; void setSpacing(int horizontal, int vertical); private: QList mItems; int mHorizontalSpacing; int mVerticalSpacing; int calculateLayout(const QRect &rect, bool applyChanged) const; int smartSpacing(QStyle::PixelMetric pixelMetric) const; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_FLOWLAYOUT_H kImageAnnotator-0.5.3/src/widgets/settingsPicker/000077500000000000000000000000001414424500400220335ustar00rootroot00000000000000kImageAnnotator-0.5.3/src/widgets/settingsPicker/BoolPicker.cpp000066400000000000000000000045421414424500400245750ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "BoolPicker.h" namespace kImageAnnotator { BoolPicker::BoolPicker(QWidget *parent) : SettingsPickerWidget(parent), mToolButton(new ListMenuToolButton(this)), mLayout(new QHBoxLayout(this)), mLabel(new QLabel(this)) { initGui(); } void BoolPicker::setEnabledState(bool enabled) { mToolButton->setCurrentData(static_cast(enabled)); } bool BoolPicker::enabledState() const { return mToolButton->currentData().value(); } void BoolPicker::setToolTip(const QString &toolTip) { mLabel->setToolTip(toolTip); QWidget::setToolTip(toolTip); } void BoolPicker::setIcon(const QIcon &icon) { mLabel->setPixmap(icon.pixmap(ScaledSizeProvider::settingsWidgetIconSize())); } QWidget *BoolPicker::expandingWidget() { return mToolButton; } void BoolPicker::initGui() { mLayout->setContentsMargins(0, 0, 0, 0); insertItem(true, QLatin1String("check.svg"), tr("Enabled")); insertItem(false, QLatin1String("disabled.svg"), tr("Disabled")); mToolButton->setFocusPolicy(Qt::NoFocus); connect(mToolButton, &ListMenuToolButton::selectionChanged, this, &BoolPicker::selectionChanged); mLayout->addWidget(mLabel); mLayout->addWidget(mToolButton); mLayout->setAlignment(Qt::AlignLeft); setLayout(mLayout); } void BoolPicker::insertItem(bool enabled, const QString &iconName, const QString &text) { auto icon = IconLoader::load(iconName); mToolButton->addItem(icon, text, static_cast(enabled)); } void BoolPicker::selectionChanged() { auto enabled = mToolButton->currentData().value(); emit enabledStateChanged(enabled); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/widgets/settingsPicker/BoolPicker.h000066400000000000000000000034601414424500400242400ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_BOOLPICKER_H #define KIMAGEANNOTATOR_BOOLPICKER_H #include #include #include #include "SettingsPickerWidget.h" #include "src/widgets/menuButtons/ListMenuToolButton.h" #include "src/common/helper/IconLoader.h" #include "src/common/provider/ScaledSizeProvider.h" namespace kImageAnnotator { class BoolPicker : public SettingsPickerWidget { Q_OBJECT public: explicit BoolPicker(QWidget *parent); ~BoolPicker() override = default; void setEnabledState(bool enabled); bool enabledState() const; void setToolTip(const QString &toolTip); void setIcon(const QIcon &icon); signals: void enabledStateChanged(bool enabled) const; protected: QWidget* expandingWidget() override; private: QHBoxLayout *mLayout; QLabel *mLabel; ListMenuToolButton *mToolButton; void initGui(); void insertItem(bool enabled, const QString &iconName, const QString &text); private slots: void selectionChanged(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_BOOLPICKER_H kImageAnnotator-0.5.3/src/widgets/settingsPicker/ColorPicker.cpp000066400000000000000000000041121414424500400247510ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ColorPicker.h" namespace kImageAnnotator { ColorPicker::ColorPicker(QWidget *parent) : SettingsPickerWidget(parent), mLayout(new QHBoxLayout(this)), mLabel(new QLabel(this)), mkColorPicker(new KColorPicker) { initGui(); connect(mkColorPicker, &KColorPicker::colorChanged, this, &ColorPicker::colorChanged); } ColorPicker::~ColorPicker() { delete mkColorPicker; } void ColorPicker::setColor(const QColor &color) { mkColorPicker->setColor(color); emit colorSelected(color); } QColor ColorPicker::color() const { return mkColorPicker->color(); } void ColorPicker::setToolTip(const QString &toolTip) { mLabel->setToolTip(toolTip); mkColorPicker->setToolTip(toolTip); } void ColorPicker::setIcon(const QIcon &icon) { mLabel->setPixmap(icon.pixmap(ScaledSizeProvider::settingsWidgetIconSize())); } QWidget *ColorPicker::expandingWidget() { return mkColorPicker; } void ColorPicker::initGui() { mLayout->setContentsMargins(0, 0, 0, 0); mLabel->setFixedSize(ScaledSizeProvider::settingsWidgetIconSize()); mkColorPicker->setFocusPolicy(Qt::NoFocus); mLayout->addWidget(mLabel); mLayout->addWidget(mkColorPicker); mLayout->setAlignment(Qt::AlignLeft); setLayout(mLayout); } void ColorPicker::colorChanged(const QColor &color) { setColor(color); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/widgets/settingsPicker/ColorPicker.h000066400000000000000000000033111414424500400244160ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_COLORPICKER_H #define KIMAGEANNOTATOR_COLORPICKER_H #include #include #include #include #include "SettingsPickerWidget.h" #include "src/common/provider/ScaledSizeProvider.h" using kColorPicker::KColorPicker; namespace kImageAnnotator { class ColorPicker : public SettingsPickerWidget { Q_OBJECT public: explicit ColorPicker(QWidget *parent); ~ColorPicker() override; void setColor(const QColor &color); QColor color() const; void setToolTip(const QString &toolTip); void setIcon(const QIcon &icon); signals: void colorSelected(const QColor &color); protected: QWidget* expandingWidget() override; private: QHBoxLayout *mLayout; QLabel *mLabel; KColorPicker *mkColorPicker; void initGui(); private slots: void colorChanged(const QColor &color); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_COLORPICKER_H kImageAnnotator-0.5.3/src/widgets/settingsPicker/FillModePicker.cpp000066400000000000000000000055261414424500400254000ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "FillModePicker.h" namespace kImageAnnotator { FillModePicker::FillModePicker(QWidget *parent) : SettingsPickerWidget(parent), mToolButton(new ListMenuToolButton(this)), mLayout(new QHBoxLayout(this)), mLabel(new QLabel(this)) { initGui(); } void FillModePicker::setFillType(FillModes fillType) { mToolButton->setCurrentData(static_cast(fillType)); } void FillModePicker::addNoFillAndNoBorderToList() { mToolButton->setDataVisible(static_cast(FillModes::NoBorderAndNoFill), true); } void FillModePicker::removeNoFillAndNoBorderToList() { mToolButton->setDataVisible(static_cast(FillModes::NoBorderAndNoFill), false); } FillModes FillModePicker::fillType() const { return mToolButton->currentData().value(); } QWidget *FillModePicker::expandingWidget() { return mToolButton; } void FillModePicker::initGui() { mLayout->setContentsMargins(0, 0, 0, 0); auto icon = IconLoader::load(QLatin1String("fillType.svg")); mLabel->setPixmap(icon.pixmap(ScaledSizeProvider::settingsWidgetIconSize())); mLabel->setToolTip(tr("Border And Fill Visibility")); insertItem(FillModes::BorderAndFill, QLatin1String("fillType_borderAndFill.svg"), tr("Border and Fill")); insertItem(FillModes::BorderAndNoFill, QLatin1String("fillType_borderAndNoFill.svg"), tr("Border and No Fill")); insertItem(FillModes::NoBorderAndNoFill, QLatin1String("fillType_noBorderAndNoFill.svg"), tr("No Border and No Fill")); mToolButton->setFocusPolicy(Qt::NoFocus); connect(mToolButton, &ListMenuToolButton::selectionChanged, this, &FillModePicker::selectionChanged); mLayout->addWidget(mLabel); mLayout->addWidget(mToolButton); mLayout->setAlignment(Qt::AlignLeft); setLayout(mLayout); } void FillModePicker::insertItem(FillModes fillType, const QString &iconName, const QString &text) { auto icon = IconLoader::load(iconName); mToolButton->addItem(icon, text, static_cast(fillType)); } void FillModePicker::selectionChanged() { auto fillType = mToolButton->currentData().value(); emit fillSelected(fillType); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/widgets/settingsPicker/FillModePicker.h000066400000000000000000000036631414424500400250450ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_FILLMODEPICKER_H #define KIMAGEANNOTATOR_FILLMODEPICKER_H #include #include #include #include #include #include #include "SettingsPickerWidget.h" #include "src/widgets/menuButtons/ListMenuToolButton.h" #include "src/common/enum/FillModes.h" #include "src/common/helper/IconLoader.h" #include "src/common/provider/ScaledSizeProvider.h" namespace kImageAnnotator { class FillModePicker : public SettingsPickerWidget { Q_OBJECT public: explicit FillModePicker(QWidget *parent); ~FillModePicker() override = default; void setFillType(FillModes fillType); void addNoFillAndNoBorderToList(); void removeNoFillAndNoBorderToList(); FillModes fillType() const; signals: void fillSelected(FillModes fillType) const; protected: QWidget* expandingWidget() override; private: QHBoxLayout *mLayout; QLabel *mLabel; ListMenuToolButton *mToolButton; void initGui(); void insertItem(FillModes fillType, const QString &iconName, const QString &text); private slots: void selectionChanged(); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_FILLMODEPICKER_H kImageAnnotator-0.5.3/src/widgets/settingsPicker/FontPicker.cpp000066400000000000000000000071131414424500400246050ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "FontPicker.h" namespace kImageAnnotator { FontPicker::FontPicker(QWidget *parent) : SettingsPickerWidget(parent), mLayout(new QBoxLayout(QBoxLayout::LeftToRight, this)), mButtonLayout(new QHBoxLayout), mFontComboBox(new CustomFontComboBox(this)), mSizeSpinBox(new CustomSpinBox(this)), mBoldToggle(new ToggleButton(this)), mItalicToggle(new ToggleButton(this)), mUnderlineToggle(new ToggleButton(this)) { initGui(); } void FontPicker::setCurrentFont(const QFont &font) { mBoldToggle->setChecked(font.bold()); mItalicToggle->setChecked(font.italic()); mUnderlineToggle->setChecked(font.underline()); mSizeSpinBox->setValue(font.pointSize()); mFontComboBox->setCurrentFont(font); } QFont FontPicker::currentFont() const { auto font = mFontComboBox->currentFont(); font.setPointSize(mSizeSpinBox->value()); font.setBold(mBoldToggle->isChecked()); font.setItalic(mItalicToggle->isChecked()); font.setUnderline(mUnderlineToggle->isChecked()); return font; } void FontPicker::setExpanding(bool enabled) { mLayout->setDirection(enabled ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight); AbstractExpandingWidget::setExpanding(enabled); } QWidget *FontPicker::expandingWidget() { return mFontComboBox; } void FontPicker::initGui() { mLayout->setContentsMargins(0, 0, 0, 0); mFontComboBox->setFocusPolicy(Qt::NoFocus); mFontComboBox->setLayoutDirection(Qt::LeftToRight); mFontComboBox->setMinimumWidth(ScaledSizeProvider::scaledWidth(100)); connect(mFontComboBox, &QFontComboBox::currentFontChanged, this, &FontPicker::selectionChanged); mSizeSpinBox->setSuffix(QLatin1String("pt")); mSizeSpinBox->setToolTip(tr("Font Size")); mSizeSpinBox->setRange(5, 50); connect(mSizeSpinBox, &CustomSpinBox::valueChanged, this, &FontPicker::selectionChanged); mBoldToggle->setIcon(IconLoader::load(QLatin1String("bold.svg"))); mBoldToggle->setToolTip(tr("Bold")); connect(mBoldToggle, &ToggleButton::toggled, this, &FontPicker::selectionChanged); mItalicToggle->setIcon(IconLoader::load(QLatin1String("italic.svg"))); mItalicToggle->setToolTip(tr("Italic")); connect(mItalicToggle, &ToggleButton::toggled, this, &FontPicker::selectionChanged); mUnderlineToggle->setIcon(IconLoader::load(QLatin1String("underline.svg"))); mUnderlineToggle->setToolTip(tr("Underline")); connect(mUnderlineToggle, &ToggleButton::toggled, this, &FontPicker::selectionChanged); mButtonLayout->addWidget(mBoldToggle); mButtonLayout->addWidget(mItalicToggle); mButtonLayout->addWidget(mUnderlineToggle); mLayout->addWidget(mFontComboBox); mLayout->addWidget(mSizeSpinBox); mLayout->addLayout(mButtonLayout); mLayout->setAlignment(Qt::AlignLeft); setLayout(mLayout); } void FontPicker::selectionChanged() { setToolTip(mFontComboBox->selectItemText()); emit fontChanged(currentFont()); } } // namespace kImageAnnotatorkImageAnnotator-0.5.3/src/widgets/settingsPicker/FontPicker.h000066400000000000000000000034571414424500400242610ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_FONTPICKER_H #define KIMAGEANNOTATOR_FONTPICKER_H #include #include "SettingsPickerWidget.h" #include "src/widgets/ToggleButton.h" #include "src/widgets/CustomSpinBox.h" #include "src/widgets/CustomFontComboBox.h" #include "src/common/helper/IconLoader.h" namespace kImageAnnotator { class FontPicker : public SettingsPickerWidget { Q_OBJECT public: explicit FontPicker(QWidget *parent); ~FontPicker() override = default; void setCurrentFont(const QFont &font); QFont currentFont() const; void setExpanding(bool enabled) override; signals: void fontChanged(const QFont &font) const; protected: QWidget* expandingWidget() override; private: QBoxLayout *mLayout; QHBoxLayout *mButtonLayout; CustomFontComboBox *mFontComboBox; CustomSpinBox *mSizeSpinBox; ToggleButton *mBoldToggle; ToggleButton *mItalicToggle; ToggleButton *mUnderlineToggle; void initGui(); private slots: void selectionChanged(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_FONTPICKER_H kImageAnnotator-0.5.3/src/widgets/settingsPicker/ImageEffectPicker.cpp000066400000000000000000000051661414424500400260440ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ImageEffectPicker.h" namespace kImageAnnotator { ImageEffectPicker::ImageEffectPicker(QWidget *parent) : SettingsPickerWidget(parent), mToolButton(new ListMenuToolButton(this)), mLayout(new QHBoxLayout(this)), mLabel(new QLabel(this)) { initGui(); } void ImageEffectPicker::setEffect(ImageEffects effect) { mToolButton->setCurrentData(static_cast(effect)); } ImageEffects ImageEffectPicker::effect() const { return mToolButton->currentData().value(); } QWidget *ImageEffectPicker::expandingWidget() { return mToolButton; } void ImageEffectPicker::initGui() { mLayout->setContentsMargins(1, 0, 0, 0); auto icon = IconLoader::load(QLatin1String("effect.svg")); mLabel->setPixmap(icon.pixmap(ScaledSizeProvider::settingsWidgetIconSize())); mLabel->setToolTip(tr("Image Effects")); insertItem(ImageEffects::NoEffect, QLatin1String("disabled.svg"), tr("No Effect")); insertItem(ImageEffects::DropShadow, QLatin1String("dropShadow.svg"), tr("Drop Shadow")); insertItem(ImageEffects::Grayscale, QLatin1String("grayscale.svg"), tr("Grayscale")); insertItem(ImageEffects::InvertColor, QLatin1String("invertColor.svg"), tr("Invert Color")); insertItem(ImageEffects::Border, QLatin1String("border.svg"), tr("Border")); mToolButton->setFocusPolicy(Qt::NoFocus); connect(mToolButton, &ListMenuToolButton::selectionChanged, this, &ImageEffectPicker::selectionChanged); mLayout->addWidget(mLabel); mLayout->addWidget(mToolButton); setLayout(mLayout); } void ImageEffectPicker::insertItem(ImageEffects effects, const QString &iconName, const QString &text) { auto icon = IconLoader::load(iconName); mToolButton->addItem(icon, text, static_cast(effects)); } void ImageEffectPicker::selectionChanged() { auto effect = mToolButton->currentData().value(); emit effectSelected(effect); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/widgets/settingsPicker/ImageEffectPicker.h000066400000000000000000000035631414424500400255100ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_IMAGEEFFECTPICKER_H #define KIMAGEANNOTATOR_IMAGEEFFECTPICKER_H #include #include #include #include #include #include #include "SettingsPickerWidget.h" #include "src/widgets/menuButtons/ListMenuToolButton.h" #include "src/common/provider/ScaledSizeProvider.h" #include "src/common/enum/ImageEffects.h" #include "src/common/helper/IconLoader.h" namespace kImageAnnotator { class ImageEffectPicker : public SettingsPickerWidget { Q_OBJECT public: explicit ImageEffectPicker(QWidget *parent); ~ImageEffectPicker() override = default; void setEffect(ImageEffects effect); ImageEffects effect() const; signals: void effectSelected(ImageEffects effect) const; protected: QWidget* expandingWidget() override; private: QHBoxLayout *mLayout; QLabel *mLabel; ListMenuToolButton *mToolButton; void initGui(); private slots: void insertItem(ImageEffects effects, const QString &iconName, const QString &text); void selectionChanged(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_IMAGEEFFECTPICKER_H kImageAnnotator-0.5.3/src/widgets/settingsPicker/NumberPicker.cpp000066400000000000000000000045121414424500400251270ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "NumberPicker.h" namespace kImageAnnotator { NumberPicker::NumberPicker(QWidget *parent) : SettingsPickerWidget(parent), mLayout(new QHBoxLayout(this)), mLabel(new QLabel(this)), mSpinBox(new CustomSpinBox(this)) { initGui(); connect(mSpinBox, &CustomSpinBox::valueChanged, this, &NumberPicker::selectionChanged); } void NumberPicker::setNumber(int number) { mSpinBox->setValue(number); } void NumberPicker::initGui() { mLayout->setContentsMargins(0, 0, 0, 0); mLabel->setFixedSize(ScaledSizeProvider::settingsWidgetIconSize()); mSpinBox->setMinimum(1); mSpinBox->setMaximum(20); setFocusPolicy(Qt::NoFocus); mLayout->addWidget(mLabel); mLayout->addWidget(mSpinBox); mLayout->setAlignment(Qt::AlignLeft); setLayout(mLayout); } void NumberPicker::setNumberAndNotify(int number) const { emit numberSelected(number); } void NumberPicker::selectionChanged() { setNumberAndNotify(mSpinBox->value()); } void NumberPicker::setRange(int min, int max) { auto oldState = mSpinBox->blockSignals(true); if (min > 0 && max >= min) { mSpinBox->setMinimum(min); mSpinBox->setMaximum(max); } mSpinBox->blockSignals(oldState); } int NumberPicker::number() const { return mSpinBox->value(); } void NumberPicker::setToolTip(const QString &toolTip) { mLabel->setToolTip(toolTip); mSpinBox->setToolTip(toolTip); } void NumberPicker::setIcon(const QIcon &icon) { mLabel->setPixmap(icon.pixmap(ScaledSizeProvider::settingsWidgetIconSize())); } QWidget *NumberPicker::expandingWidget() { return mSpinBox; } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/widgets/settingsPicker/NumberPicker.h000066400000000000000000000033661414424500400246020ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_NUMBERPICKER_H #define KIMAGEANNOTATOR_NUMBERPICKER_H #include #include #include #include #include "src/widgets/CustomSpinBox.h" #include "SettingsPickerWidget.h" #include "src/common/provider/ScaledSizeProvider.h" namespace kImageAnnotator { class NumberPicker : public SettingsPickerWidget { Q_OBJECT public: explicit NumberPicker(QWidget *parent); ~NumberPicker() override = default; void setNumber(int number); void setRange(int min, int max); int number() const; void setToolTip(const QString &toolTip); void setIcon(const QIcon &icon); signals: void numberSelected(int number) const; protected: QWidget* expandingWidget() override; private: QHBoxLayout *mLayout; CustomSpinBox *mSpinBox; QLabel *mLabel; void initGui(); void setNumberAndNotify(int number) const; private slots: void selectionChanged(); }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_NUMBERPICKER_H kImageAnnotator-0.5.3/src/widgets/settingsPicker/SettingsPickerWidget.cpp000066400000000000000000000023131414424500400266400ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "SettingsPickerWidget.h" namespace kImageAnnotator { SettingsPickerWidget::SettingsPickerWidget(QWidget *parent) : QWidget(parent) { } void SettingsPickerWidget::showEvent(QShowEvent *event) { emit visibilityChanged(true); QWidget::showEvent(event); } void SettingsPickerWidget::hideEvent(QHideEvent *event) { emit visibilityChanged(false); QWidget::hideEvent(event); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/widgets/settingsPicker/SettingsPickerWidget.h000066400000000000000000000026251414424500400263130ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SETTINGSPICKERWIDGET_H #define KIMAGEANNOTATOR_SETTINGSPICKERWIDGET_H #include #include "src/widgets/misc/AbstractExpandingWidget.h" namespace kImageAnnotator { class SettingsPickerWidget : public QWidget, public AbstractExpandingWidget { Q_OBJECT public: explicit SettingsPickerWidget(QWidget *parent); ~SettingsPickerWidget() override = default; signals: void visibilityChanged(bool visible); protected: void showEvent(QShowEvent *event) override; void hideEvent(QHideEvent *event) override; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_SETTINGSPICKERWIDGET_H kImageAnnotator-0.5.3/src/widgets/settingsPicker/StickerPicker.cpp000066400000000000000000000070051414424500400253030ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "StickerPicker.h" namespace kImageAnnotator { StickerPicker::StickerPicker(QWidget *parent) : SettingsPickerWidget(parent), mLayout(new QHBoxLayout(this)), mLabel(new QLabel(this)), mToolButton(new GridMenuToolButton(this)) { init(); } void StickerPicker::setSticker(const QString &name) { mToolButton->setCurrentData(name); } QString StickerPicker::sticker() const { return mToolButton->currentData().toString(); } void StickerPicker::setStickers(const QStringList &stickerPaths, bool keepDefault) { mToolButton->clear(); if(keepDefault) { addDefaultStickers(); } for(const auto& stickerPath : stickerPaths) { addItem(stickerPath); } } QWidget *StickerPicker::expandingWidget() { return mToolButton; } void StickerPicker::init() { mLayout->setContentsMargins(0, 0, 0, 0); auto icon = IconLoader::load(QLatin1String("sticker.svg")); mLabel->setPixmap(icon.pixmap(ScaledSizeProvider::settingsWidgetIconSize())); mLabel->setToolTip(tr("Sticker")); mLabel->setMargin(0); mToolButton->setFocusPolicy(Qt::NoFocus); mToolButton->setPopupMode(QToolButton::InstantPopup); connect(mToolButton, &GridMenuToolButton::selectionChanged, this, &StickerPicker::selectionChanged); addDefaultStickers(); mLayout->addWidget(mLabel); mLayout->addWidget(mToolButton); mLayout->setAlignment(Qt::AlignLeft); setLayout(mLayout); } void StickerPicker::addDefaultStickers() { QStringList defaultStickers{ QLatin1String("face_blowing_a_kiss"), QLatin1String("face_savoring_food"), QLatin1String("grinning_face_with_big_eyes"), QLatin1String("grinning_face_with_smiling_eyes"), QLatin1String("grinning_face_with_sweat"), QLatin1String("grinning_squinting_face"), QLatin1String("hushed_face"), QLatin1String("nerd_face"), QLatin1String("neutral_face"), QLatin1String("smiling_face_with_heart_eyes"), QLatin1String("smiling_face_with_hearts"), QLatin1String("confused_face"), QLatin1String("face_with_symbols_on_mouth"), QLatin1String("pouting_face"), QLatin1String("smiling_face_with_sunglasses"), QLatin1String("check_mark"), QLatin1String("cross_mark") }; for(const auto& sticker : defaultStickers) { addItem(getResourcePath(sticker)); } } QString StickerPicker::getResourcePath(const QString &name) { return QLatin1String(":/stickers/") + name + QLatin1String(".svg"); } void StickerPicker::addItem(const QString &path) { auto icon = QIcon(path); auto filename = PathHelper::extractFilename(path); filename = PathHelper::prettyFilename(filename); mToolButton->addItem(icon, filename, path); } void StickerPicker::selectionChanged() const { emit stickerSelected(sticker()); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/widgets/settingsPicker/StickerPicker.h000066400000000000000000000035251414424500400247530ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_STICKERPICKER_H #define KIMAGEANNOTATOR_STICKERPICKER_H #include #include #include #include "SettingsPickerWidget.h" #include "src/widgets/menuButtons/GridMenuToolButton.h" #include "src/common/helper/IconLoader.h" #include "src/common/helper/PathHelper.h" namespace kImageAnnotator { class StickerPicker : public SettingsPickerWidget { Q_OBJECT public: explicit StickerPicker(QWidget *parent); ~StickerPicker() override = default; void setSticker(const QString &name); QString sticker() const; void setStickers(const QStringList &stickerPaths, bool keepDefault); signals: void stickerSelected(const QString &sticker) const; protected: QWidget* expandingWidget() override; private: QHBoxLayout *mLayout; QLabel *mLabel; GridMenuToolButton *mToolButton; void init(); void addItem(const QString &path); private slots: void selectionChanged() const; static QString getResourcePath(const QString &name); void addDefaultStickers(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_STICKERPICKER_H kImageAnnotator-0.5.3/src/widgets/settingsPicker/ZoomPicker.cpp000066400000000000000000000062401414424500400246230ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ZoomPicker.h" namespace kImageAnnotator { ZoomPicker::ZoomPicker(QWidget *parent) : SettingsPickerWidget(parent), mLayout(new QHBoxLayout), mLabel(new QLabel(this)), mSpinBox(new CustomSpinBox(this)), mZoomInAction(new QAction(this)), mZoomOutAction(new QAction(this)), mResetZoomAction(new QAction(this)) { initGui(); } QWidget *ZoomPicker::expandingWidget() { return mSpinBox; } void ZoomPicker::initGui() { mLayout->setContentsMargins(1, 0, 0, 0); auto icon = IconLoader::load(QLatin1String("zoom.svg")); mLabel->setPixmap(icon.pixmap(ScaledSizeProvider::settingsWidgetIconSize())); mSpinBox->setFocusPolicy(Qt::NoFocus); mSpinBox->setRange(10, 800); mSpinBox->setSingleStep(10); mSpinBox->setSuffix(QLatin1String("%")); mSpinBox->setWrapping(false); mZoomInAction->setShortcut(QKeySequence::ZoomIn); mZoomOutAction->setShortcut(QKeySequence::ZoomOut); mResetZoomAction->setShortcut(Qt::CTRL + Qt::Key_0); setToolTip(getToolTip()); connect(mZoomInAction, &QAction::triggered, this, &ZoomPicker::zoomIn); connect(mZoomOutAction, &QAction::triggered, this, &ZoomPicker::zoomOut); connect(mResetZoomAction, &QAction::triggered, this, &ZoomPicker::resetZoomOut); addAction(mZoomInAction); addAction(mZoomOutAction); addAction(mResetZoomAction); connect(mSpinBox, &CustomSpinBox::valueChanged, this, &ZoomPicker::notifyZoomValueChanged); mLayout->addWidget(mLabel); mLayout->addWidget(mSpinBox); mLayout->setAlignment(Qt::AlignLeft); setLayout(mLayout); } QString ZoomPicker::getToolTip() const { auto newLine = QLatin1String("\n"); auto zoomIn = tr("Zoom In (%1)").arg(mZoomInAction->shortcut().toString()); auto zoomOut = tr("Zoom Out (%1)").arg(mZoomOutAction->shortcut().toString()); auto resetZoom = tr("Reset Zoom (%1)").arg(mResetZoomAction->shortcut().toString()); return zoomIn + newLine + zoomOut + newLine + resetZoom; } void ZoomPicker::setZoomValue(double value) { auto zoomValue = qRound(value * 100); mSpinBox->setValueSilent(zoomValue); } void ZoomPicker::notifyZoomValueChanged(double value) { emit zoomValueChanged(value / 100.0); } void ZoomPicker::zoomIn() { int currentZoom = mSpinBox->value(); notifyZoomValueChanged(currentZoom + 10); } void ZoomPicker::zoomOut() { auto currentZoom = mSpinBox->value(); notifyZoomValueChanged(currentZoom - 10); } void ZoomPicker::resetZoomOut() { notifyZoomValueChanged(100); } } // namespace kImageAnnotator kImageAnnotator-0.5.3/src/widgets/settingsPicker/ZoomPicker.h000066400000000000000000000034751414424500400242770ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ZOOMPICKER_H #define KIMAGEANNOTATOR_ZOOMPICKER_H #include #include #include #include #include "src/widgets/CustomSpinBox.h" #include "src/widgets/settingsPicker/SettingsPickerWidget.h" #include "src/common/helper/IconLoader.h" #include "src/common/provider/ScaledSizeProvider.h" namespace kImageAnnotator { class ZoomPicker : public SettingsPickerWidget { Q_OBJECT public: explicit ZoomPicker(QWidget *parent); ~ZoomPicker() override = default; public slots: void setZoomValue(double value); signals: void zoomValueChanged(double zoomLevel); protected: QWidget* expandingWidget() override; private: QHBoxLayout *mLayout; QLabel *mLabel; CustomSpinBox *mSpinBox; QAction *mZoomInAction; QAction *mZoomOutAction; QAction *mResetZoomAction; void initGui(); private slots: void notifyZoomValueChanged(double value); void zoomIn(); void zoomOut(); void resetZoomOut(); QString getToolTip() const; }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ZOOMPICKER_H kImageAnnotator-0.5.3/tests/000077500000000000000000000000001414424500400157425ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/CMakeLists.txt000066400000000000000000000061601414424500400205050ustar00rootroot00000000000000set(UNITTEST_SRC annotations/core/AnnotationAreaTest.cpp annotations/core/AnnotationItemFactoryTest.cpp annotations/core/AnnotationPropertiesFactoryTest.cpp annotations/modifiers/AnnotationItemResizerTest.cpp annotations/modifiers/AnnotationMultiItemResizerTest.cpp annotations/modifiers/AnnotationItemSelectorTest.cpp annotations/modifiers/AnnotationItemModifierTest.cpp annotations/modifiers/AnnotationItemArrangerTest.cpp annotations/modifiers/AnnotationItemMoverTest.cpp annotations/modifiers/resizeHandles/LineResizeHandlesTest.cpp annotations/modifiers/resizeHandles/RectResizeHandlesTest.cpp annotations/modifiers/resizeHandles/PointerRectResizeHandlesTest.cpp annotations/undo/AddCommandTest.cpp annotations/undo/DeleteCommandTest.cpp annotations/undo/ModifyCanvasCommandTest.cpp annotations/undo/MoveCommandTest.cpp annotations/undo/ResizeCommandTest.cpp annotations/undo/ArrangeCommandTest.cpp annotations/undo/CropCommandTest.cpp annotations/undo/ScaleCommandTest.cpp annotations/undo/PasteCommandTest.cpp annotations/undo/RotateCommandTest.cpp annotations/items/helper/KeyInputHelperTest.cpp annotations/items/helper/TextCursorTest.cpp annotations/misc/AnnotationItemClipboardTest.cpp annotations/misc/NumberManagerTest.cpp backend/ConfigTest.cpp common/helper/KeyHelperTest.cpp common/helper/MathHelperTest.cpp common/helper/ItemHelperTest.cpp common/helper/ShapeHelperTest.cpp common/helper/PathHelperTest.cpp gui/cropper/CropSelectionRestrictorTest.cpp gui/canvasModifier/ModifyCanvasSelectionRestrictorTest.cpp gui/selection/SelectionMoveHelperTest.cpp gui/selection/SelectionHandlerTest.cpp gui/selection/SelectionHandlesTest.cpp gui/scaler/ScaleSizeHandlerTest.cpp gui/annotator/tabs/AnnotationTabCloserTest.cpp gui/annotator/tabs/AnnotationTabContextMenuTest.cpp widgets/CustomSpinBoxTest.cpp widgets/misc/AttachedSeparatorTest.cpp widgets/settingsPicker/ToolPickerTest.cpp widgets/settingsPicker/ColorPickerTest.cpp widgets/settingsPicker/NumberPickerTest.cpp widgets/settingsPicker/FillModePickerTest.cpp widgets/settingsPicker/ImageEffectPickerTest.cpp widgets/settingsPicker/StickerPickerTest.cpp widgets/settingsPicker/ZoomPickerTest.cpp ) set(TESTUTILS_SRC mocks/MockZoomValueProvider.cpp mocks/MockSettingsProvider.cpp mocks/MockDevicePixelRatioScaler.cpp mocks/MockDefaultParameters.h mocks/MockSelectionRestrictor.cpp ) add_library(KIMAGEANNOTATOR_STATIC STATIC ${KIMAGEANNOTATOR_SRCS}) target_link_libraries(KIMAGEANNOTATOR_STATIC Qt5::Widgets Qt5::Svg kImageAnnotator kColorPicker::kColorPicker) if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.14.0) target_link_libraries(KIMAGEANNOTATOR_STATIC X11::X11) else() target_link_libraries(KIMAGEANNOTATOR_STATIC X11) endif() target_compile_definitions(KIMAGEANNOTATOR_STATIC PRIVATE KIMAGEANNOTATOR_LANG_INSTALL_DIR="${KIMAGEANNOTATOR_LANG_INSTALL_DIR}") foreach (UnitTest ${UNITTEST_SRC}) get_filename_component(UnitTestName ${UnitTest} NAME_WE) add_executable(${UnitTestName} ${UnitTest} ${TESTUTILS_SRC}) target_link_libraries(${UnitTestName} KIMAGEANNOTATOR_STATIC Qt5::Test) add_test(${UnitTestName} ${UnitTestName}) endforeach (UnitTest) kImageAnnotator-0.5.3/tests/annotations/000077500000000000000000000000001414424500400202775ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/annotations/core/000077500000000000000000000000001414424500400212275ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/annotations/core/AnnotationAreaTest.cpp000066400000000000000000000130211414424500400254730ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationAreaTest.h" void AnnotationAreaTest::ExportAsImage_Should_ExportImage_When_ImageSet() { QPixmap pixmap(QSize(400, 400)); pixmap.fill(QColor(Qt::green)); MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); annotationArea.loadImage(pixmap); auto resultImage = annotationArea.image(); auto expectedImage = pixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied); QCOMPARE(expectedImage, resultImage); } void AnnotationAreaTest::ExportAsImage_Should_ExportEmptyImage_When_NoImageSet() { MockDefaultParameters p; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(&p.config, &p.settingsProvider, scalerMock, &p.zoomValueProvider, nullptr); auto resultImage = annotationArea.image(); QCOMPARE(QImage(), resultImage); } void AnnotationAreaTest::ExportAsImage_Should_ExportScaledImage_When_ScalingEnabled() { auto scaleFactor = 1.5; QPixmap pixmap(QSize(400, 400)); pixmap.fill(QColor(Qt::green)); MockDefaultParameters p; auto scalerMock = new MockDevicePixelRatioScaler(); scalerMock->setScaleFactor(scaleFactor); AnnotationArea annotationArea(&p.config, &p.settingsProvider, scalerMock, &p.zoomValueProvider, nullptr); annotationArea.loadImage(pixmap); auto resultImage = annotationArea.image(); auto expectedImage = pixmap.scaled(pixmap.size() * scaleFactor).toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied); expectedImage.setDevicePixelRatio(scaleFactor); QCOMPARE(resultImage, expectedImage); } void AnnotationAreaTest::AddAnnotationItem_Should_AddAnnotationItemToScene() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QPointF p1(10, 10); QPointF p2(20, 20); auto lineItem = new AnnotationLine(p1, properties); lineItem->addPoint(p2, false); MockDefaultParameters p; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(&p.config, &p.settingsProvider, scalerMock, &p.zoomValueProvider, nullptr); annotationArea.addAnnotationItem(lineItem); QCOMPARE(annotationArea.items().contains(lineItem), true); } void AnnotationAreaTest::RemoveAnnotationItem_Should_RemoveAnnotationItemFromScene() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QPointF p1(10, 10); QPointF p2(20, 20); auto lineItem = new AnnotationLine(p1, properties); lineItem->addPoint(p2, false); MockDefaultParameters p; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(&p.config, &p.settingsProvider, scalerMock, &p.zoomValueProvider, nullptr); annotationArea.addAnnotationItem(lineItem); QCOMPARE(annotationArea.items().contains(lineItem), true); annotationArea.removeAnnotationItem(lineItem); QCOMPARE(annotationArea.items().contains(lineItem), false); } void AnnotationAreaTest::CanvasRect_Should_ReturnRectUnionOfAllItems_When_NoCanvasRectSet() { QRectF backgroundImageBoundingRect(0,0,400,400); QPixmap pixmap(backgroundImageBoundingRect.size().toSize()); pixmap.fill(QColor(Qt::green)); MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); annotationArea.loadImage(pixmap); auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QPointF p1(10, 10); QPointF p2(600, 600); auto lineItem = new AnnotationLine(p1, properties); lineItem->addPoint(p2, false); annotationArea.addAnnotationItem(lineItem); auto defaultCanvasRect = backgroundImageBoundingRect.united(lineItem->boundingRect().toRect()); auto canvasRect = annotationArea.canvasRect(); QCOMPARE(canvasRect, defaultCanvasRect); } void AnnotationAreaTest::CanvasRect_Should_ReturnUserDefinedRect_When_CanvasRectSet() { QRect backgroundImageBoundingRect(0,0,400,400); QPixmap pixmap(backgroundImageBoundingRect.size()); pixmap.fill(QColor(Qt::green)); MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); annotationArea.loadImage(pixmap); auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QPointF p1(10, 10); QPointF p2(600, 600); auto lineItem = new AnnotationLine(p1, properties); lineItem->addPoint(p2, false); annotationArea.addAnnotationItem(lineItem); auto userDefinedCanvasRect = QRectF(100, 100, 300, 300); annotationArea.setCanvasRect(userDefinedCanvasRect); auto canvasRect = annotationArea.canvasRect(); QCOMPARE(canvasRect, userDefinedCanvasRect); } QTEST_MAIN(AnnotationAreaTest); kImageAnnotator-0.5.3/tests/annotations/core/AnnotationAreaTest.h000066400000000000000000000036151414424500400251500ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONAREATEST_H #define KIMAGEANNOTATOR_ANNOTATIONAREATEST_H #include #include "src/annotations/core/AnnotationArea.h" #include "src/annotations/items/AnnotationLine.h" #include "src/annotations/modifiers/resizeHandles/ResizeHandle.h" #include "tests/mocks/MockDefaultParameters.h" using kImageAnnotator::AnnotationArea; using kImageAnnotator::AnnotationLine; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::Config; using kImageAnnotator::PropertiesPtr; using kImageAnnotator::ResizeHandle; class AnnotationAreaTest : public QObject { Q_OBJECT private slots: void ExportAsImage_Should_ExportImage_When_ImageSet(); void ExportAsImage_Should_ExportEmptyImage_When_NoImageSet(); void ExportAsImage_Should_ExportScaledImage_When_ScalingEnabled(); void AddAnnotationItem_Should_AddAnnotationItemToScene(); void RemoveAnnotationItem_Should_RemoveAnnotationItemFromScene(); void CanvasRect_Should_ReturnRectUnionOfAllItems_When_NoCanvasRectSet(); void CanvasRect_Should_ReturnUserDefinedRect_When_CanvasRectSet(); }; #endif // KIMAGEANNOTATOR_ANNOTATIONAREATEST_H kImageAnnotator-0.5.3/tests/annotations/core/AnnotationItemFactoryTest.cpp000066400000000000000000000166631414424500400270700ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemFactoryTest.h" void AnnotationItemFactoryTest::initTestCase() { QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QLatin1String("/tmp")); } void AnnotationItemFactoryTest::cleanupTestCase() { QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QLatin1String("$HOME/.config")); } void AnnotationItemFactoryTest::TestCreate_Should_CreateItemAtProvidedPosition() { QPointF position(10, 10); auto toolType = Tools::Line; auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(toolType); settingsProvider->setToolWidth(0); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); AnnotationItemFactory itemFactory(&propertiesFactory, settingsProvider, config); auto item = itemFactory.create(position); item->addPoint(QPoint(20, 20), false); QCOMPARE(item->position(), position); } void AnnotationItemFactoryTest::TestCreate_Should_CreateImageItemAtProvidedPosition() { QPointF position(10, 10); QPixmap image(200,200); auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(Tools::Image); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); AnnotationItemFactory itemFactory(&propertiesFactory, settingsProvider, config); auto item = itemFactory.create(position, image); QVERIFY(dynamic_cast(item) != nullptr); QCOMPARE(item->position(), position); } void AnnotationItemFactoryTest::TestCreate_Should_ReturnNullPtrForUnknownType() { auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType((Tools) 21); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); AnnotationItemFactory itemFactory(&propertiesFactory, settingsProvider, config); auto item = itemFactory.create(QPoint(0, 0)); QVERIFY(item == nullptr); } void AnnotationItemFactoryTest::TestCreate_Should_ReturnAnnotationLine_When_TypeIsLine() { auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(Tools::Line); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); AnnotationItemFactory itemFactory(&propertiesFactory, settingsProvider, config); auto item = itemFactory.create(QPoint(0, 0)); auto result = dynamic_cast(item); QVERIFY(result != nullptr); } void AnnotationItemFactoryTest::TestCreate_Should_ReturnAnnotationArrow_When_TypeIsArrow() { auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(Tools::Arrow); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); AnnotationItemFactory itemFactory(&propertiesFactory, settingsProvider, config); auto item = itemFactory.create(QPoint(0, 0)); auto result = dynamic_cast(item); QVERIFY(result != nullptr); } void AnnotationItemFactoryTest::TestCreate_Should_ReturnAnnotationRect_When_TypeIsRect() { auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(Tools::Rect); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); AnnotationItemFactory itemFactory(&propertiesFactory, settingsProvider, config); auto item = itemFactory.create(QPoint(0, 0)); auto result = dynamic_cast(item); QVERIFY(result != nullptr); } void AnnotationItemFactoryTest::TestCreate_Should_ReturnAnnotationEllipse_When_TypeIsEllipse() { auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(Tools::Ellipse); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); AnnotationItemFactory itemFactory(&propertiesFactory, settingsProvider, config); auto item = itemFactory.create(QPoint(0, 0)); auto result = dynamic_cast(item); QVERIFY(result != nullptr); } void AnnotationItemFactoryTest::TestCreate_Should_ReturnAnnotationNumber_When_TypeIsNumber() { auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(Tools::Number); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); AnnotationItemFactory itemFactory(&propertiesFactory, settingsProvider, config); auto item = itemFactory.create(QPoint(0, 0)); auto result = dynamic_cast(item); QVERIFY(result != nullptr); } void AnnotationItemFactoryTest::TestCreate_Should_ReturnAnnotationSticker_When_TypeIsSticker() { auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(Tools::Sticker); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); AnnotationItemFactory itemFactory(&propertiesFactory, settingsProvider, config); auto item = itemFactory.create(QPoint(0, 0)); auto result = dynamic_cast(item); QVERIFY(result != nullptr); } void AnnotationItemFactoryTest::TestCreate_Should_ReturnAnnotationNumberPointer_When_TypeIsNumberPointer() { auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(Tools::NumberPointer); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); AnnotationItemFactory itemFactory(&propertiesFactory, settingsProvider, config); auto item = itemFactory.create(QPoint(0, 0)); auto result = dynamic_cast(item); QVERIFY(result != nullptr); } void AnnotationItemFactoryTest::TestClone_Should_ReturnNewItemOfSameType() { QPointF position(10, 10); auto tool = Tools::Line; auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(tool); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); AnnotationItemFactory itemFactory(&propertiesFactory, settingsProvider, config); auto item = itemFactory.create(position); item->addPoint(QPoint(20, 20), false); auto clonedItem = itemFactory.clone(item); QVERIFY(clonedItem != item); QCOMPARE(clonedItem->toolType(), item->toolType()); } void AnnotationItemFactoryTest::TestClone_Should_IncrementZValueForClonedItem() { QPointF position(10, 10); auto tool = Tools::Line; auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(tool); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); AnnotationItemFactory itemFactory(&propertiesFactory, settingsProvider, config); auto item = itemFactory.create(position); item->addPoint(QPoint(20, 20), false); auto clonedItem = itemFactory.clone(item); QVERIFY(clonedItem->zValue() > item->zValue()); } QTEST_MAIN(AnnotationItemFactoryTest); kImageAnnotator-0.5.3/tests/annotations/core/AnnotationItemFactoryTest.h000066400000000000000000000047211414424500400265250ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMFACTORYTEST_H #define KIMAGEANNOTATOR_ANNOTATIONITEMFACTORYTEST_H #include #include "src/annotations/core/AnnotationItemFactory.h" #include "tests/mocks/MockSettingsProvider.h" using kImageAnnotator::AnnotationItemFactory; using kImageAnnotator::AnnotationLine; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::AnnotationArrow; using kImageAnnotator::AnnotationRect; using kImageAnnotator::AnnotationNumber; using kImageAnnotator::AnnotationEllipse; using kImageAnnotator::AnnotationImage; using kImageAnnotator::AnnotationSticker; using kImageAnnotator::AnnotationNumberPointer; using kImageAnnotator::Tools; using kImageAnnotator::Config; using kImageAnnotator::AnnotationPropertiesFactory; class AnnotationItemFactoryTest : public QObject { Q_OBJECT private slots: void initTestCase(); void cleanupTestCase(); void TestCreate_Should_CreateItemAtProvidedPosition(); void TestCreate_Should_CreateImageItemAtProvidedPosition(); void TestCreate_Should_ReturnNullPtrForUnknownType(); void TestCreate_Should_ReturnAnnotationLine_When_TypeIsLine(); void TestCreate_Should_ReturnAnnotationArrow_When_TypeIsArrow(); void TestCreate_Should_ReturnAnnotationRect_When_TypeIsRect(); void TestCreate_Should_ReturnAnnotationEllipse_When_TypeIsEllipse(); void TestCreate_Should_ReturnAnnotationNumber_When_TypeIsNumber(); void TestCreate_Should_ReturnAnnotationSticker_When_TypeIsSticker(); void TestCreate_Should_ReturnAnnotationNumberPointer_When_TypeIsNumberPointer(); void TestClone_Should_ReturnNewItemOfSameType(); void TestClone_Should_IncrementZValueForClonedItem(); }; #endif // KIMAGEANNOTATOR_ANNOTATIONITEMFACTORYTEST_H kImageAnnotator-0.5.3/tests/annotations/core/AnnotationPropertiesFactoryTest.cpp000066400000000000000000000172101414424500400303130ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationPropertiesFactoryTest.h" void AnnotationPropertiesFactoryTest::initTestCase() { QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QLatin1Literal("/tmp")); } void AnnotationPropertiesFactoryTest::cleanupTestCase() { QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QLatin1Literal("$HOME/.config")); } void AnnotationPropertiesFactoryTest::TestCreate_Should_SetPropertiesSizeBasedOnConfiguration() { const int size = 13; auto tool = Tools::Line; auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolWidth(size); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); auto properties = propertiesFactory.create(tool); QCOMPARE(properties->width(), size); } void AnnotationPropertiesFactoryTest::TestCreate_Should_SetPropertiesColorBasedOnConfiguration() { const QColor color(Qt::darkMagenta); auto tool = Tools::Line; auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(tool); settingsProvider->setToolColor(color); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); auto properties = propertiesFactory.create(tool); QCOMPARE(properties->color(), color); } void AnnotationPropertiesFactoryTest::TestCreate_Should_SetPropertiesTextColorBasedOnConfiguration() { const QColor textColor(Qt::darkMagenta); auto tool = Tools::Number; auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(tool); settingsProvider->setTextColor(textColor); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); auto properties = propertiesFactory.create(tool); QCOMPARE(properties->textColor(), textColor); } void AnnotationPropertiesFactoryTest::TestCreate_Should_SetPropertiesFillTypeBasedOnConfiguration() { auto fill = FillModes::BorderAndNoFill; auto tool = Tools::Rect; auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(tool); settingsProvider->setFillType(fill); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); auto properties = propertiesFactory.create(tool); QCOMPARE(properties->fillType(), fill); } void AnnotationPropertiesFactoryTest::TestCreate_Should_SetShadowEnabledBasedOnConfiguration() { auto tool = Tools::Pen; auto config = new Config; auto enabled = true; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setShadowEnabled(enabled); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); auto properties = propertiesFactory.create(tool); QCOMPARE(properties->shadowEnabled(), enabled); } void AnnotationPropertiesFactoryTest::TestCreate_Should_CreatePathPropertiesWhenItemPen() { auto tool = Tools::Pen; auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(tool); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); auto properties = propertiesFactory.create(tool); auto pathProperties = properties.dynamicCast(); QVERIFY(pathProperties != nullptr); } void AnnotationPropertiesFactoryTest::TestCreate_Should_CreatePathPropertiesWhenItemMarker() { auto tool = Tools::MarkerPen; auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(tool); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); auto properties = propertiesFactory.create(tool); auto pathProperties = properties.dynamicCast(); QVERIFY(pathProperties != nullptr); } void AnnotationPropertiesFactoryTest::TestCreate_Should_CreateTextPropertiesWhenItemNumber() { auto tool = Tools::Number; auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(tool); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); auto properties = propertiesFactory.create(tool); auto textProperties = properties.dynamicCast(); QVERIFY(textProperties != nullptr); } void AnnotationPropertiesFactoryTest::TestCreate_Should_CreateTextPropertiesWhenItemNumberPointer() { auto tool = Tools::NumberPointer; auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(tool); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); auto properties = propertiesFactory.create(tool); auto textProperties = properties.dynamicCast(); QVERIFY(textProperties != nullptr); } void AnnotationPropertiesFactoryTest::TestCreate_Should_CreateTextPropertiesWhenItemText() { auto tool = Tools::Text; auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(tool); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); auto properties = propertiesFactory.create(tool); auto textProperties = properties.dynamicCast(); QVERIFY(textProperties != nullptr); } void AnnotationPropertiesFactoryTest::TestCreate_Should_SetSmoothPathBasedOnConfiguration() { auto tool = Tools::Pen; auto config = new Config; auto smoothPathEnabled = true; auto smoothPathFactor = 99; config->setSmoothPathEnabled(smoothPathEnabled); config->setSmoothFactor(smoothPathFactor); auto settingsProvider = new MockSettingsProvider(); settingsProvider->setToolType(tool); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); auto properties = propertiesFactory.create(tool); auto pathProperties = properties.dynamicCast(); QCOMPARE(pathProperties->smoothPathEnabled(), smoothPathEnabled); QCOMPARE(pathProperties->smoothFactor(), smoothPathFactor); } void AnnotationPropertiesFactoryTest::TestCreate_Should_SetToolFontBasedOnSettings() { auto tool = Tools::Number; auto config = new Config; auto font = QFont("Helvetica [Cronyx]", 8, QFont::StyleItalic); auto settingsProvider = new MockSettingsProvider(); settingsProvider->setFont(font); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); auto properties = propertiesFactory.create(tool); auto textProperties = properties.dynamicCast(); QCOMPARE(textProperties->font(), font); } void AnnotationPropertiesFactoryTest::TestCreate_Should_StickerPathBasedOnSettings() { auto tool = Tools::Sticker; auto path = QLatin1Literal("/my/path/to/sticker"); auto config = new Config; auto settingsProvider = new MockSettingsProvider(); settingsProvider->setSticker(path); AnnotationPropertiesFactory propertiesFactory(config, settingsProvider); auto properties = propertiesFactory.create(tool); auto stickerProperties = properties.dynamicCast(); QCOMPARE(stickerProperties->path(), path); } QTEST_MAIN(AnnotationPropertiesFactoryTest); kImageAnnotator-0.5.3/tests/annotations/core/AnnotationPropertiesFactoryTest.h000066400000000000000000000045221414424500400277620ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONPROPERTIESFACTORYTEST_H #define KIMAGEANNOTATOR_ANNOTATIONPROPERTIESFACTORYTEST_H #include #include "src/annotations/core/AnnotationPropertiesFactory.h" #include "tests/mocks/MockSettingsProvider.h" using kImageAnnotator::AnnotationPropertiesFactory; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::AnnotationTextProperties; using kImageAnnotator::AnnotationPathProperties; using kImageAnnotator::AnnotationStickerProperties; using kImageAnnotator::Tools; using kImageAnnotator::FillModes; using kImageAnnotator::Config; class AnnotationPropertiesFactoryTest : public QObject { Q_OBJECT private slots: void initTestCase(); void cleanupTestCase(); void TestCreate_Should_SetPropertiesSizeBasedOnConfiguration(); void TestCreate_Should_SetPropertiesColorBasedOnConfiguration(); void TestCreate_Should_SetPropertiesTextColorBasedOnConfiguration(); void TestCreate_Should_SetPropertiesFillTypeBasedOnConfiguration(); void TestCreate_Should_SetShadowEnabledBasedOnConfiguration(); void TestCreate_Should_CreatePathPropertiesWhenItemPen(); void TestCreate_Should_CreatePathPropertiesWhenItemMarker(); void TestCreate_Should_CreateTextPropertiesWhenItemNumber(); void TestCreate_Should_CreateTextPropertiesWhenItemNumberPointer(); void TestCreate_Should_CreateTextPropertiesWhenItemText(); void TestCreate_Should_SetSmoothPathBasedOnConfiguration(); void TestCreate_Should_SetToolFontBasedOnSettings(); void TestCreate_Should_StickerPathBasedOnSettings(); }; #endif // ANNOTATIONPROPERTIESFACTORYTEST_H kImageAnnotator-0.5.3/tests/annotations/items/000077500000000000000000000000001414424500400214205ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/annotations/items/helper/000077500000000000000000000000001414424500400226775ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/annotations/items/helper/KeyInputHelperTest.cpp000066400000000000000000000213221414424500400271530ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KeyInputHelperTest.h" void KeyInputHelperTest::TestHandleKeyPress_Should_EmitRemoveSignal_When_KeyIsBackspace() { qRegisterMetaType("TextPositions"); KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::remove); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); auto resultDirection = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultDirection, TextPositions::Previous); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitRemoveSignal_When_KeyIsDelete() { qRegisterMetaType("TextPositions"); KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::remove); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Delete, Qt::NoModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); auto resultDirection = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultDirection, TextPositions::Next); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitInsertSignalWithNewLine_When_KeyIsReturnAndModifierShift() { KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::insert); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Return, Qt::ShiftModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); auto resultText = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultText, QStringLiteral("\n")); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitInsertSignalWithNewLine_When_KeyIsEnterAndModifierShift() { KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::insert); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Enter, Qt::ShiftModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); auto resultText = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultText, QStringLiteral("\n")); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitEscape_When_KeyIsReturnAndNoModifier() { KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::escape); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitEscape_When_KeyIsEnterAndNoModifier() { KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::escape); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitEscapeSignal_When_KeyIsEscape() { KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::escape); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsHome() { qRegisterMetaType("TextPositions"); KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::move); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Home, Qt::NoModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); auto resultDirection = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultDirection, TextPositions::Beginning); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsEnd() { qRegisterMetaType("TextPositions"); KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::move); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_End, Qt::NoModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); auto resultDirection = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultDirection, TextPositions::End); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsArrowLeft() { qRegisterMetaType("TextPositions"); KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::move); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Left, Qt::NoModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); auto resultDirection = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultDirection, TextPositions::Previous); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsArrowLeftAndModifierCtrl() { qRegisterMetaType("TextPositions"); KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::move); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Left, Qt::ControlModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); auto resultDirection = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultDirection, TextPositions::PreviousWordBeginning); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsArrowRight() { qRegisterMetaType("TextPositions"); KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::move); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Right, Qt::NoModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); auto resultDirection = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultDirection, TextPositions::Next); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsArrowRightAndModifierCtrl() { qRegisterMetaType("TextPositions"); KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::move); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Right, Qt::ControlModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); auto resultDirection = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultDirection, TextPositions::NextWordBeginning); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsArrowUp() { qRegisterMetaType("TextPositions"); KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::move); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); auto resultDirection = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultDirection, TextPositions::Up); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsArrowDown() { qRegisterMetaType("TextPositions"); KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::move); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); auto resultDirection = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultDirection, TextPositions::Down); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitPasteSignal_When_KeyIsPaste() { KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::paste); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Paste, Qt::NoModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitPasteSignal_When_KeySequenceIsPaste() { KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::paste); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_V, Qt::ControlModifier); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); } void KeyInputHelperTest::TestHandleKeyPress_Should_EmitInsertSignal_When_KeyIsCharacter() { KeyInputHelper keyInputHelper; QSignalSpy spy(&keyInputHelper, &KeyInputHelper::insert); QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_J, Qt::NoModifier, QStringLiteral("j")); keyInputHelper.handleKeyPress(&keyEvent); QCOMPARE(spy.count(), 1); auto resultText = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultText, QStringLiteral("j")); } QTEST_MAIN(KeyInputHelperTest); kImageAnnotator-0.5.3/tests/annotations/items/helper/KeyInputHelperTest.h000066400000000000000000000047231414424500400266260ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_KEYINPUTHELPERTEST_H #define KIMAGEANNOTATOR_KEYINPUTHELPERTEST_H #include #include "src/annotations/items/text/KeyInputHelper.h" using kImageAnnotator::KeyInputHelper; using kImageAnnotator::TextPositions; class KeyInputHelperTest : public QObject { Q_OBJECT private slots: void TestHandleKeyPress_Should_EmitRemoveSignal_When_KeyIsBackspace(); void TestHandleKeyPress_Should_EmitRemoveSignal_When_KeyIsDelete(); void TestHandleKeyPress_Should_EmitInsertSignalWithNewLine_When_KeyIsReturnAndModifierShift(); void TestHandleKeyPress_Should_EmitInsertSignalWithNewLine_When_KeyIsEnterAndModifierShift(); void TestHandleKeyPress_Should_EmitEscape_When_KeyIsReturnAndNoModifier(); void TestHandleKeyPress_Should_EmitEscape_When_KeyIsEnterAndNoModifier(); void TestHandleKeyPress_Should_EmitEscapeSignal_When_KeyIsEscape(); void TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsHome(); void TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsEnd(); void TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsArrowLeft(); void TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsArrowLeftAndModifierCtrl(); void TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsArrowRight(); void TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsArrowRightAndModifierCtrl(); void TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsArrowUp(); void TestHandleKeyPress_Should_EmitMoveSignal_When_KeyIsArrowDown(); void TestHandleKeyPress_Should_EmitPasteSignal_When_KeyIsPaste(); void TestHandleKeyPress_Should_EmitPasteSignal_When_KeySequenceIsPaste(); void TestHandleKeyPress_Should_EmitInsertSignal_When_KeyIsCharacter(); }; #endif // KIMAGEANNOTATOR_KEYINPUTHELPERTEST_H kImageAnnotator-0.5.3/tests/annotations/items/helper/TextCursorTest.cpp000066400000000000000000000177171414424500400264020ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "TextCursorTest.h" void TextCursorTest::TestMove_Should_MoveCursorToBeginning_When_DirectionBeginning() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); textCursor.setPosition(16); textCursor.move(TextPositions::Beginning, text); QCOMPARE(textCursor.position(), 0); } void TextCursorTest::TestMove_Should_MoveCursorToEnd_When_DirectionEnd() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); QCOMPARE(textCursor.position(), 0); textCursor.move(TextPositions::End, text); QCOMPARE(textCursor.position(), 16); } void TextCursorTest::TestMove_Should_MoveCursorByOnePointToRight_When_DirectionNext() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); QCOMPARE(textCursor.position(), 0); textCursor.move(TextPositions::Next, text); QCOMPARE(textCursor.position(), 1); } void TextCursorTest::TestMove_Should_MoveCursorToNextWordBeginning_When_DirectionNextAndModifierCtrl() { TextCursor textCursor; QString text = QLatin1String(" This is a string\n" "spanning multiple lines " " 123 1 "); QCOMPARE(textCursor.position(), 0); QVector nextPositionList{ 1, 6, 10, 12, 18, 19, 28, 37, 44, 48, 51, 51 }; for(int nextPosition : nextPositionList) { textCursor.move(TextPositions::NextWordBeginning, text); QCOMPARE(textCursor.position(), nextPosition); } } void TextCursorTest::TestMove_Should_MoveCursorByOnePointToLeft_When_DirectionPrevious() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); textCursor.move(TextPositions::Next, text); QCOMPARE(textCursor.position(), 1); textCursor.move(TextPositions::Previous, text); QCOMPARE(textCursor.position(), 0); } void TextCursorTest::TestMove_Should_MoveCursorToPreviousWordBeginning_When_DirectionPreviousAndModifierCtrl() { TextCursor textCursor; QString text = QLatin1String(" This is a string\n" "spanning multiple lines " " 123 1 "); textCursor.setPosition(51); QCOMPARE(textCursor.position(), 51); QVector prevPositionList{ 48, 44, 37, 28, 19, 18, 12, 10, 6, 1, 0, 0 }; for(int prevPosition : prevPositionList) { textCursor.move(TextPositions::PreviousWordBeginning, text); QCOMPARE(textCursor.position(), prevPosition); } } void TextCursorTest::TestMove_Should_MoveCursorToStart_When_DirectionPreviousAndCurrentPositionAtStart() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); QCOMPARE(textCursor.position(), 0); textCursor.move(TextPositions::Previous, text); QCOMPARE(textCursor.position(), 0); } void TextCursorTest::TestMove_Should_MoveCursorToEnd_When_DirectionNextAndCurrentPositionAtEnd() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); textCursor.setPosition(text.length()); textCursor.move(TextPositions::Next, text); QCOMPARE(textCursor.position(), text.length()); } void TextCursorTest::TestMove_Should_MoveCursorToNextLineSamePosition_When_DirectionDown() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); QCOMPARE(textCursor.position(), 0); textCursor.move(TextPositions::Down, text); QCOMPARE(textCursor.position(), 5); } void TextCursorTest::TestMove_Should_NotMoveCursor_When_DirectionDownAndInLastLine() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); textCursor.setPosition(9); textCursor.move(TextPositions::Down, text); QCOMPARE(textCursor.position(), 9); } void TextCursorTest::TestMove_Should_NotMoveCursor_When_DirectionUpAndInFirstLine() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); QCOMPARE(textCursor.position(), 0); textCursor.move(TextPositions::Up, text); QCOMPARE(textCursor.position(), 0); } void TextCursorTest::TestMove_Should_MoveCursorToPreviousLineSamePosition_When_DirectionUpAndNotInFirstLine() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); textCursor.setPosition(9); textCursor.move(TextPositions::Up, text); QCOMPARE(textCursor.position(), 5); } void TextCursorTest::TestMove_Should_MoveCursorToEndOfNextLine_When_DirectionDownAndPositionAtEndOfLineAndLineBelowIsSmaller() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); textCursor.setPosition(4); textCursor.move(TextPositions::Down, text); QCOMPARE(textCursor.position(), 8); } void TextCursorTest::TestMove_Should_MoveCursorToEndOfPreviousLine_When_DirectionUpAndPositionAtEndOfLineAndLineAboveIsSmaller() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); textCursor.setPosition(16); textCursor.move(TextPositions::Up, text); QCOMPARE(textCursor.position(), 8); } void TextCursorTest::TestMove_Should_MoveCursorToSamePositionOfPreviousLine_When_DirectionUpAndPositionAtEndOfLineAndLineAboveIsLarger() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); textCursor.setPosition(8); textCursor.move(TextPositions::Up, text); QCOMPARE(textCursor.position(), 3); } void TextCursorTest::TestMove_Should_MoveCursorToSamePositionOfNextLine_When_DirectionDownAndPositionAtEndOfLineAndLineBelowIsLarger() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); textCursor.setPosition(8); textCursor.move(TextPositions::Down, text); QCOMPARE(textCursor.position(), 12); } void TextCursorTest::TestMoveForwardBy_Should_MoveCursorForwardByRequestedSteps() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); QCOMPARE(textCursor.position(), 0); textCursor.moveForwardBy(text, 2); QCOMPARE(textCursor.position(), 2); } void TextCursorTest::TestMoveForwardBy_Should_MoveCursorToEnd_When_RequestedStepsLargerThenTextLength() { TextCursor textCursor; QString text = QLatin1String("Test\n" "123\n" "test123"); textCursor.setPosition(2); textCursor.moveForwardBy(text, 20); QCOMPARE(textCursor.position(), text.length()); } QTEST_MAIN(TextCursorTest); kImageAnnotator-0.5.3/tests/annotations/items/helper/TextCursorTest.h000066400000000000000000000052471414424500400260420ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_TEXTCURSORTEST_H #define KIMAGEANNOTATOR_TEXTCURSORTEST_H #include #include "src/annotations/items/text/TextCursor.h" using kImageAnnotator::TextCursor; using kImageAnnotator::TextPositions; class TextCursorTest : public QObject { Q_OBJECT private slots: void TestMove_Should_MoveCursorToBeginning_When_DirectionBeginning(); void TestMove_Should_MoveCursorToEnd_When_DirectionEnd(); void TestMove_Should_MoveCursorByOnePointToRight_When_DirectionNext(); void TestMove_Should_MoveCursorToNextWordBeginning_When_DirectionNextAndModifierCtrl(); void TestMove_Should_MoveCursorByOnePointToLeft_When_DirectionPrevious(); void TestMove_Should_MoveCursorToPreviousWordBeginning_When_DirectionPreviousAndModifierCtrl(); void TestMove_Should_MoveCursorToStart_When_DirectionPreviousAndCurrentPositionAtStart(); void TestMove_Should_MoveCursorToEnd_When_DirectionNextAndCurrentPositionAtEnd(); void TestMove_Should_MoveCursorToNextLineSamePosition_When_DirectionDown(); void TestMove_Should_NotMoveCursor_When_DirectionDownAndInLastLine(); void TestMove_Should_NotMoveCursor_When_DirectionUpAndInFirstLine(); void TestMove_Should_MoveCursorToPreviousLineSamePosition_When_DirectionUpAndNotInFirstLine(); void TestMove_Should_MoveCursorToEndOfNextLine_When_DirectionDownAndPositionAtEndOfLineAndLineBelowIsSmaller(); void TestMove_Should_MoveCursorToEndOfPreviousLine_When_DirectionUpAndPositionAtEndOfLineAndLineAboveIsSmaller(); void TestMove_Should_MoveCursorToSamePositionOfPreviousLine_When_DirectionUpAndPositionAtEndOfLineAndLineAboveIsLarger(); void TestMove_Should_MoveCursorToSamePositionOfNextLine_When_DirectionDownAndPositionAtEndOfLineAndLineBelowIsLarger(); void TestMoveForwardBy_Should_MoveCursorForwardByRequestedSteps(); void TestMoveForwardBy_Should_MoveCursorToEnd_When_RequestedStepsLargerThenTextLength(); }; #endif // KIMAGEANNOTATOR_TEXTCURSORTEST_H kImageAnnotator-0.5.3/tests/annotations/misc/000077500000000000000000000000001414424500400212325ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/annotations/misc/AnnotationItemClipboardTest.cpp000066400000000000000000000043311414424500400273500ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemClipboardTest.h" #include "tests/mocks/MockZoomValueProvider.h" void AnnotationItemClipboardTest::TestCopyItems_Should_StoreSelectedItems() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); AnnotationRect rect(QPointF(0, 0), properties); rect.addPoint(QPointF(50, 50), false); QPointF position(50, 50); QList items; items.append(&rect); MockZoomValueProvider zoomValueProvider; AnnotationItemModifier modifier(&zoomValueProvider); modifier.handleSelectionAt(position, &items, false); AnnotationItemClipboard clipboard(&modifier); clipboard.copyItems(QPointF()); QCOMPARE(clipboard.copiedItemsWithOffset().count(), 1); QCOMPARE(clipboard.copiedItemsWithOffset().keys().first(), &rect); } void AnnotationItemClipboardTest::TestCopyItems_Should_SetCorrectOffset() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); AnnotationRect rect(QPointF(0, 0), properties); rect.addPoint(QPointF(50, 50), false); QPointF position(50, 50); QList items; items.append(&rect); MockZoomValueProvider zoomValueProvider; AnnotationItemModifier modifier(&zoomValueProvider); modifier.handleSelectionAt(position, &items, false); AnnotationItemClipboard clipboard(&modifier); clipboard.copyItems(QPointF(20, 20)); QCOMPARE(clipboard.copiedItemsWithOffset()[&rect], QPointF(-20, -20)); } QTEST_MAIN(AnnotationItemClipboardTest); kImageAnnotator-0.5.3/tests/annotations/misc/AnnotationItemClipboardTest.h000066400000000000000000000027211414424500400270160ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTTIONITEMCLIPBOARDTEST_H #define KIMAGEANNOTATOR_ANNOTTIONITEMCLIPBOARDTEST_H #include #include "src/annotations/misc/AnnotationItemClipboard.h" using kImageAnnotator::AnnotationItemClipboard; using kImageAnnotator::AnnotationItemModifier; using kImageAnnotator::AbstractAnnotationItem; using kImageAnnotator::AnnotationRect; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::PropertiesPtr; class AnnotationItemClipboardTest : public QObject { Q_OBJECT private slots: void TestCopyItems_Should_StoreSelectedItems(); void TestCopyItems_Should_SetCorrectOffset(); }; #endif // KIMAGEANNOTATOR_ANNOTTIONITEMCLIPBOARDTEST_H kImageAnnotator-0.5.3/tests/annotations/misc/NumberManagerTest.cpp000066400000000000000000000155571414424500400253360ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "NumberManagerTest.h" void NumberManagerTest::TestAddItem_Should_AssignCorrectNumbers_When_UpdateAllNumbersModeSelected() { auto properties1 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); auto properties2 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); auto properties3 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); AnnotationNumber item1(QPointF(0, 0), properties1); AnnotationNumber item2(QPointF(0, 0), properties2); AnnotationNumber item3(QPointF(0, 0), properties3); NumberManager numberManager; numberManager.setNumberUpdateMode(NumberUpdateMode::UpdateAllNumbers); numberManager.addItem(&item1); numberManager.addItem(&item2); numberManager.addItem(&item3); QCOMPARE(item1.number(), 1); QCOMPARE(item2.number(), 2); QCOMPARE(item3.number(), 3); } void NumberManagerTest::TestAddItem_Should_AssignCorrectNumbers_When_UpdateOnlyNewNumbers() { auto properties1 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); auto properties2 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); auto properties3 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); AnnotationNumber item1(QPointF(0, 0), properties1); AnnotationNumber item2(QPointF(0, 0), properties2); AnnotationNumber item3(QPointF(0, 0), properties3); NumberManager numberManager; numberManager.setNumberUpdateMode(NumberUpdateMode::UpdateOnlyNewNumbers); numberManager.addItem(&item1); numberManager.addItem(&item2); numberManager.addItem(&item3); QCOMPARE(item1.number(), 1); QCOMPARE(item2.number(), 2); QCOMPARE(item3.number(), 3); } void NumberManagerTest::TestUpdateNumbers_Should_BeTriggered_When_ItemIsHiddenAndUpdateAllNumbersModeSelected() { auto properties1 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); auto properties2 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); auto properties3 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); AnnotationNumber item1(QPointF(0, 0), properties1); AnnotationNumber item2(QPointF(0, 0), properties2); AnnotationNumber item3(QPointF(0, 0), properties3); NumberManager numberManager; numberManager.setNumberUpdateMode(NumberUpdateMode::UpdateAllNumbers); numberManager.addItem(&item1); numberManager.addItem(&item2); numberManager.addItem(&item3); QCOMPARE(item1.number(), 1); QCOMPARE(item2.number(), 2); QCOMPARE(item3.number(), 3); item2.hide(); QCOMPARE(item1.number(), 1); QCOMPARE(item3.number(), 2); } void NumberManagerTest::TestUpdateNumbers_Should_NotBeTriggered_When_ItemIsHiddenAndUpdateOnlyNewNumbersModeSelected() { auto properties1 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); auto properties2 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); auto properties3 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); AnnotationNumber item1(QPointF(0, 0), properties1); AnnotationNumber item2(QPointF(0, 0), properties2); AnnotationNumber item3(QPointF(0, 0), properties3); NumberManager numberManager; numberManager.setNumberUpdateMode(NumberUpdateMode::UpdateOnlyNewNumbers); numberManager.addItem(&item1); numberManager.addItem(&item2); numberManager.addItem(&item3); QCOMPARE(item1.number(), 1); QCOMPARE(item2.number(), 2); QCOMPARE(item3.number(), 3); item2.hide(); QCOMPARE(item1.number(), 1); QCOMPARE(item3.number(), 3); } void NumberManagerTest::TestNumberSeedChanged_Should_TriggerUpdateOfAllNumber_When_UpdateAllNumbersModeSelected() { auto properties1 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); auto properties2 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); auto properties3 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); AnnotationNumber item1(QPointF(0, 0), properties1); AnnotationNumber item2(QPointF(0, 0), properties2); AnnotationNumber item3(QPointF(0, 0), properties3); NumberManager numberManager; numberManager.setNumberUpdateMode(NumberUpdateMode::UpdateAllNumbers); numberManager.addItem(&item1); numberManager.addItem(&item2); numberManager.addItem(&item3); QCOMPARE(item1.number(), 1); QCOMPARE(item2.number(), 2); QCOMPARE(item3.number(), 3); numberManager.setNumberSeed(4); QCOMPARE(item1.number(), 4); QCOMPARE(item2.number(), 5); QCOMPARE(item3.number(), 6); } void NumberManagerTest::TestNumberSeedChanged_Should_NotTriggerUpdateOfAllNumber_When_UpdateOnlyNewNumbersModeSelected() { auto properties1 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); auto properties2 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); auto properties3 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); AnnotationNumber item1(QPointF(0, 0), properties1); AnnotationNumber item2(QPointF(0, 0), properties2); AnnotationNumber item3(QPointF(0, 0), properties3); NumberManager numberManager; numberManager.setNumberUpdateMode(NumberUpdateMode::UpdateOnlyNewNumbers); numberManager.addItem(&item1); numberManager.addItem(&item2); numberManager.addItem(&item3); QCOMPARE(item1.number(), 1); QCOMPARE(item2.number(), 2); QCOMPARE(item3.number(), 3); numberManager.setNumberSeed(4); QCOMPARE(item1.number(), 1); QCOMPARE(item2.number(), 2); QCOMPARE(item3.number(), 3); } void NumberManagerTest::TestNumberSeedChanged_Should_AffectOnlyNewItems_When_UpdateOnlyNewNumbersModeSelected() { auto properties1 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); auto properties2 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); auto properties3 = TextPropertiesPtr(new AnnotationTextProperties(2, Qt::red)); AnnotationNumber item1(QPointF(0, 0), properties1); AnnotationNumber item2(QPointF(0, 0), properties2); AnnotationNumber item3(QPointF(0, 0), properties3); NumberManager numberManager; numberManager.setNumberUpdateMode(NumberUpdateMode::UpdateOnlyNewNumbers); numberManager.addItem(&item1); numberManager.addItem(&item2); QCOMPARE(item1.number(), 1); QCOMPARE(item2.number(), 2); numberManager.setNumberSeed(5); numberManager.addItem(&item3); QCOMPARE(item1.number(), 1); QCOMPARE(item2.number(), 2); QCOMPARE(item3.number(), 5); } QTEST_MAIN(NumberManagerTest); kImageAnnotator-0.5.3/tests/annotations/misc/NumberManagerTest.h000066400000000000000000000037101414424500400247670ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_NUMBERMANAGERTEST_H #define KIMAGEANNOTATOR_NUMBERMANAGERTEST_H #include #include using kImageAnnotator::NumberManager; using kImageAnnotator::AnnotationNumber; using kImageAnnotator::AnnotationTextProperties; using kImageAnnotator::TextPropertiesPtr; using kImageAnnotator::NumberUpdateMode; #include "src/annotations/misc/NumberManager.h" class NumberManagerTest : public QObject { Q_OBJECT private slots: void TestAddItem_Should_AssignCorrectNumbers_When_UpdateAllNumbersModeSelected(); void TestAddItem_Should_AssignCorrectNumbers_When_UpdateOnlyNewNumbers(); void TestUpdateNumbers_Should_BeTriggered_When_ItemIsHiddenAndUpdateAllNumbersModeSelected(); void TestUpdateNumbers_Should_NotBeTriggered_When_ItemIsHiddenAndUpdateOnlyNewNumbersModeSelected(); void TestNumberSeedChanged_Should_TriggerUpdateOfAllNumber_When_UpdateAllNumbersModeSelected(); void TestNumberSeedChanged_Should_NotTriggerUpdateOfAllNumber_When_UpdateOnlyNewNumbersModeSelected(); void TestNumberSeedChanged_Should_AffectOnlyNewItems_When_UpdateOnlyNewNumbersModeSelected(); }; #endif // KIMAGEANNOTATOR_NUMBERMANAGERTEST_H kImageAnnotator-0.5.3/tests/annotations/modifiers/000077500000000000000000000000001414424500400222605ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/annotations/modifiers/AnnotationItemArrangerTest.cpp000066400000000000000000000203721414424500400302430ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemArrangerTest.h" void AnnotationItemArrangerTest::TestBringToFront_Should_BringAllSelectedItemsToFront() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties3 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties4 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); AnnotationLine item1(QPointF(0, 0), properties1); AnnotationLine item2(QPointF(0, 0), properties2); AnnotationLine item3(QPointF(0, 0), properties3); AnnotationLine item4(QPointF(0, 0), properties4); item1.setZValue(1); item2.setZValue(2); item3.setZValue(3); item4.setZValue(4); QList items; QList selectedItems; items.append(&item4); items.append(&item3); items.append(&item2); items.append(&item1); selectedItems.append(&item2); selectedItems.append(&item1); AnnotationItemArranger arranger(selectedItems, &items); QUndoStack undoStack; connect(&arranger, &AnnotationItemArranger::newCommand, &undoStack, &QUndoStack::push); arranger.bringToFront(); QCOMPARE((int) item1.zValue(), 3); QCOMPARE((int) item2.zValue(), 4); QCOMPARE((int) item3.zValue(), 1); QCOMPARE((int) item4.zValue(), 2); } void AnnotationItemArrangerTest::TestBringForward_Should_MoveAllSelectedItemsOnePositionUp() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties3 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties4 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); AnnotationLine item1(QPointF(0, 0), properties1); AnnotationLine item2(QPointF(0, 0), properties2); AnnotationLine item3(QPointF(0, 0), properties3); AnnotationLine item4(QPointF(0, 0), properties4); item1.setZValue(1); item2.setZValue(2); item3.setZValue(3); item4.setZValue(4); QList items; QList selectedItems; items.append(&item4); items.append(&item3); items.append(&item2); items.append(&item1); selectedItems.append(&item2); selectedItems.append(&item1); AnnotationItemArranger arranger(selectedItems, &items); QUndoStack undoStack; connect(&arranger, &AnnotationItemArranger::newCommand, &undoStack, &QUndoStack::push); arranger.bringForward(); QCOMPARE((int) item1.zValue(), 2); QCOMPARE((int) item2.zValue(), 3); QCOMPARE((int) item3.zValue(), 1); QCOMPARE((int) item4.zValue(), 4); } void AnnotationItemArrangerTest::TestSendBackward_Should_MoveAllSelectedItemsOnePositionBack() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties3 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties4 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); AnnotationLine item1(QPointF(0, 0), properties1); AnnotationLine item2(QPointF(0, 0), properties2); AnnotationLine item3(QPointF(0, 0), properties3); AnnotationLine item4(QPointF(0, 0), properties4); item1.setZValue(1); item2.setZValue(2); item3.setZValue(3); item4.setZValue(4); QList items; QList selectedItems; items.append(&item4); items.append(&item3); items.append(&item2); items.append(&item1); selectedItems.append(&item4); selectedItems.append(&item3); AnnotationItemArranger arranger(selectedItems, &items); QUndoStack undoStack; connect(&arranger, &AnnotationItemArranger::newCommand, &undoStack, &QUndoStack::push); arranger.sendBackward(); QCOMPARE((int) item1.zValue(), 1); QCOMPARE((int) item2.zValue(), 4); QCOMPARE((int) item3.zValue(), 2); QCOMPARE((int) item4.zValue(), 3); } void AnnotationItemArrangerTest::TestSendToBack_Should_SendAllSelectedItemToBack() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties3 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties4 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); AnnotationLine item1(QPointF(0, 0), properties1); AnnotationLine item2(QPointF(0, 0), properties2); AnnotationLine item3(QPointF(0, 0), properties3); AnnotationLine item4(QPointF(0, 0), properties4); item1.setZValue(1); item2.setZValue(2); item3.setZValue(3); item4.setZValue(4); QList items; QList selectedItems; items.append(&item4); items.append(&item3); items.append(&item2); items.append(&item1); selectedItems.append(&item4); selectedItems.append(&item3); AnnotationItemArranger arranger(selectedItems, &items); QUndoStack undoStack; connect(&arranger, &AnnotationItemArranger::newCommand, &undoStack, &QUndoStack::push); arranger.sendToBack(); QCOMPARE((int) item1.zValue(), 3); QCOMPARE((int) item2.zValue(), 4); QCOMPARE((int) item3.zValue(), 1); QCOMPARE((int) item4.zValue(), 2); } void AnnotationItemArrangerTest::TestAnnotationItemArranger_Should_SortAllItemsByZValue_When_PositionHaveBeenSwapped() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties3 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties4 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); AnnotationLine item1(QPointF(0, 0), properties1); AnnotationLine item2(QPointF(0, 0), properties2); AnnotationLine item3(QPointF(0, 0), properties3); AnnotationLine item4(QPointF(0, 0), properties4); item1.setZValue(1); item2.setZValue(2); item3.setZValue(3); item4.setZValue(4); QList items; QList selectedItems; items.append(&item4); items.append(&item3); items.append(&item2); items.append(&item1); selectedItems.append(&item2); selectedItems.append(&item1); AnnotationItemArranger arranger(selectedItems, &items); QUndoStack undoStack; connect(&arranger, &AnnotationItemArranger::newCommand, &undoStack, &QUndoStack::push); arranger.bringToFront(); QCOMPARE((int) items[0]->zValue(), 4); QCOMPARE((int) items[1]->zValue(), 3); QCOMPARE((int) items[2]->zValue(), 2); QCOMPARE((int) items[3]->zValue(), 1); } void AnnotationItemArrangerTest::TestAnnotationItemArranger_Should_NotSwapAnyPosition_When_NoItemsHaveBeenSelected() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties3 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties4 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); AnnotationLine item1(QPointF(0, 0), properties1); AnnotationLine item2(QPointF(0, 0), properties2); AnnotationLine item3(QPointF(0, 0), properties3); AnnotationLine item4(QPointF(0, 0), properties4); item1.setZValue(1); item2.setZValue(2); item3.setZValue(3); item4.setZValue(4); QList items; QList selectedItems; items.append(&item4); items.append(&item3); items.append(&item2); items.append(&item1); AnnotationItemArranger arranger(selectedItems, &items); QUndoStack undoStack; connect(&arranger, &AnnotationItemArranger::newCommand, &undoStack, &QUndoStack::push); arranger.bringToFront(); QCOMPARE((int) item1.zValue(), 1); QCOMPARE((int) item2.zValue(), 2); QCOMPARE((int) item3.zValue(), 3); QCOMPARE((int) item4.zValue(), 4); } QTEST_MAIN(AnnotationItemArrangerTest); kImageAnnotator-0.5.3/tests/annotations/modifiers/AnnotationItemArrangerTest.h000066400000000000000000000035021414424500400277040ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMARRANGERTEST_H #define KIMAGEANNOTATOR_ANNOTATIONITEMARRANGERTEST_H #include #include #include "src/annotations/modifiers/AnnotationItemArranger.h" #include "src/annotations/items/AnnotationLine.h" using kImageAnnotator::AnnotationItemArranger; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::AnnotationLine; using kImageAnnotator::AbstractAnnotationItem; using kImageAnnotator::PropertiesPtr; class AnnotationItemArrangerTest : public QObject { Q_OBJECT private slots: void TestBringToFront_Should_BringAllSelectedItemsToFront(); void TestBringForward_Should_MoveAllSelectedItemsOnePositionUp(); void TestSendBackward_Should_MoveAllSelectedItemsOnePositionBack(); void TestSendToBack_Should_SendAllSelectedItemToBack(); void TestAnnotationItemArranger_Should_SortAllItemsByZValue_When_PositionHaveBeenSwapped(); void TestAnnotationItemArranger_Should_NotSwapAnyPosition_When_NoItemsHaveBeenSelected(); }; #endif // KIMAGEANNOTATOR_ANNOTATIONITEMARRANGERTEST_H kImageAnnotator-0.5.3/tests/annotations/modifiers/AnnotationItemModifierTest.cpp000066400000000000000000000135331414424500400302410ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemModifierTest.h" #include "tests/mocks/MockZoomValueProvider.h" void AnnotationItemModifierTest::HandleMousePressMoveRelease_Should_MoveResizerHandle_When_ClickedOnResizerHandle() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QPointF p1(10, 10); QPointF p2(10, 20); QPointF p3(30, 30); AnnotationLine line(p1, properties); line.addPoint(p2, false); QList items; items.append(&line); MockZoomValueProvider zoomValueProvider; AnnotationItemModifier modifer(&zoomValueProvider); QUndoStack undoStack; connect(&modifer, &AnnotationItemModifier::newCommand, &undoStack, &QUndoStack::push); modifer.handleMousePress(p1, &items, false); modifer.handleMouseRelease(&items); modifer.handleMousePress(p1, &items, false); modifer.handleMouseMove(p3, false); QCOMPARE(line.line().p1(), p3); QCOMPARE(line.line().p2(), p2); } void AnnotationItemModifierTest::HandleMousePressMove_Should_NotMoveResizerHandle_When_NotClickedOnResizerHandle() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QPointF p1(10, 10); QPointF p2(10, 20); QPointF p3(30, 30); QPointF p4(40, 40); AnnotationLine line(p1, properties); line.addPoint(p2, false); QList items; items.append(&line); MockZoomValueProvider zoomValueProvider; AnnotationItemModifier modifer(&zoomValueProvider); modifer.handleMousePress(p1, &items, false); modifer.handleMouseRelease(&items); modifer.handleMousePress(p3, &items, false); modifer.handleMouseMove(p4, false); QCOMPARE(line.line().p1(), p1); QCOMPARE(line.line().p2(), p2); } void AnnotationItemModifierTest::HandleMousePressMoveRelease_Should_SelectMultipleItems_When_ClickedNotOnItem() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QPointF p1(10, 10); QPointF p2(10, 20); QPointF p3(15, 15); QPointF p4(20, 20); AnnotationLine line1(p1, properties1); AnnotationLine line2(p3, properties2); line1.addPoint(p2, false); line2.addPoint(p4, false); QList items; items.append(&line1); items.append(&line2); MockZoomValueProvider zoomValueProvider; AnnotationItemModifier modifer(&zoomValueProvider); modifer.handleMousePress(p1 + QPointF(-5, -5), &items, false); modifer.handleMouseMove(p4 + QPointF(5, 5), false); modifer.handleMouseRelease(&items); auto results = modifer.selectedItems(); QCOMPARE(results.count(), 2); QCOMPARE(results.contains(&line1), true); QCOMPARE(results.contains(&line2), true); } void AnnotationItemModifierTest::HandleMousePressMove_Should_MoveClickedItem_When_ClickedOnItemAndMoved() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QPointF p1(10, 10); QPointF p2(20, 20); QPointF clickPos(15, 15); QPointF movePos(30, 30); AnnotationLine line(p1, properties); line.addPoint(p2, false); QList items; items.append(&line); MockZoomValueProvider zoomValueProvider; AnnotationItemModifier modifer(&zoomValueProvider); QUndoStack undoStack; connect(&modifer, &AnnotationItemModifier::newCommand, &undoStack, &QUndoStack::push); modifer.handleMousePress(clickPos, &items, false); modifer.handleMouseMove(movePos, false); QCOMPARE(line.boundingRect().topLeft(), movePos - (clickPos - p1)); } void AnnotationItemModifierTest::HandleMousePressMove_Should_MoveSelectedItems_When_ClickedOnOfSelectedItemsAndMoved() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QPointF p1(10, 10); QPointF p2(30, 30); QPointF p3(45, 45); QPointF p4(60, 60); QPointF clickPos(20, 20); QPointF movePos(80, 80); AnnotationLine line1(p1, properties1); AnnotationLine line2(p3, properties2); line1.addPoint(p2, false); line2.addPoint(p4, false); QList items; items.append(&line1); items.append(&line2); MockZoomValueProvider zoomValueProvider; AnnotationItemModifier modifer(&zoomValueProvider); QUndoStack undoStack; connect(&modifer, &AnnotationItemModifier::newCommand, &undoStack, &QUndoStack::push); modifer.handleMousePress(p1 + QPointF(-5, -5), &items, false); modifer.handleMouseMove(p4 + QPointF(5, 5), false); modifer.handleMouseRelease(&items); QCOMPARE(modifer.selectedItems().count(), 2); modifer.handleMousePress(clickPos, &items, false); modifer.handleMouseMove(movePos, false); QCOMPARE(line1.boundingRect().topLeft(), movePos - (clickPos - p1)); QCOMPARE(line2.boundingRect().topLeft(), movePos - (clickPos - p3)); } void AnnotationItemModifierTest::SelectItem_Should_SelectProvidedItem() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); AnnotationLine line(QPointF(10, 10), properties); line.addPoint(QPointF(20, 20), false); MockZoomValueProvider zoomValueProvider; AnnotationItemModifier modifer(&zoomValueProvider); modifer.selectItem(&line); QCOMPARE(modifer.selectedItems().count(), 1); QCOMPARE(modifer.selectedItems().first(), &line); } QTEST_MAIN(AnnotationItemModifierTest); kImageAnnotator-0.5.3/tests/annotations/modifiers/AnnotationItemModifierTest.h000066400000000000000000000035571414424500400277130ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMMODIFIERTEST_H #define KIMAGEANNOTATOR_ANNOTATIONITEMMODIFIERTEST_H #include #include #include "src/annotations/modifiers/AnnotationItemModifier.h" #include "src/annotations/items/AnnotationLine.h" using kImageAnnotator::AnnotationItemModifier; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::AnnotationLine; using kImageAnnotator::AbstractAnnotationItem; using kImageAnnotator::PropertiesPtr; class AnnotationItemModifierTest : public QObject { Q_OBJECT private slots: void HandleMousePressMoveRelease_Should_MoveResizerHandle_When_ClickedOnResizerHandle(); void HandleMousePressMove_Should_NotMoveResizerHandle_When_NotClickedOnResizerHandle(); void HandleMousePressMoveRelease_Should_SelectMultipleItems_When_ClickedNotOnItem(); void HandleMousePressMove_Should_MoveClickedItem_When_ClickedOnItemAndMoved(); void HandleMousePressMove_Should_MoveSelectedItems_When_ClickedOnOfSelectedItemsAndMoved(); void SelectItem_Should_SelectProvidedItem(); }; #endif // KIMAGEANNOTATOR_ANNOTATIONITEMMODIFIERTEST_H kImageAnnotator-0.5.3/tests/annotations/modifiers/AnnotationItemMoverTest.cpp000066400000000000000000000034351414424500400275730ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemMoverTest.h" void AnnotationItemMoverTest::TestMoveItems_Should_MoveItemsToNewPosition() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QPointF p1(10, 10); QPointF p2(10, 20); QPointF p3(15, 15); QPointF p4(20, 20); QPointF clickPos(p1 + QPointF(5, 5)); QPointF newPos(QPointF(50, 50)); AnnotationLine line1(p1, properties1); AnnotationLine line2(p3, properties2); line1.addPoint(p2, false); line2.addPoint(p4, false); QList items; items.append(&line1); items.append(&line2); AnnotationItemMover mover; QUndoStack undoStack; connect(&mover, &AnnotationItemMover::newCommand, &undoStack, &QUndoStack::push); mover.setOffset(clickPos, items); mover.moveItems(newPos); QCOMPARE(line1.boundingRect().topLeft(), newPos - (clickPos - p1)); QCOMPARE(line2.boundingRect().topLeft(), newPos - (clickPos - p3)); } QTEST_MAIN(AnnotationItemMoverTest); kImageAnnotator-0.5.3/tests/annotations/modifiers/AnnotationItemMoverTest.h000066400000000000000000000026561414424500400272440ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMMOVERTEST_H #define KIMAGEANNOTATOR_ANNOTATIONITEMMOVERTEST_H #include #include #include "src/annotations/modifiers/AnnotationItemMover.h" #include "src/annotations/items/AnnotationLine.h" using kImageAnnotator::AnnotationItemMover; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::AnnotationLine; using kImageAnnotator::AbstractAnnotationItem; using kImageAnnotator::PropertiesPtr; class AnnotationItemMoverTest : public QObject { Q_OBJECT private slots: void TestMoveItems_Should_MoveItemsToNewPosition(); }; #endif // KIMAGEANNOTATOR_ANNOTATIONITEMMOVERTEST_H kImageAnnotator-0.5.3/tests/annotations/modifiers/AnnotationItemResizerTest.cpp000066400000000000000000000070451414424500400301270ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemResizerTest.h" #include "tests/mocks/MockZoomValueProvider.h" void AnnotationItemResizerTest::TestGrabHandle_Should_GrabHandle_When_ProvidedPointIsAtHandlePosition() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QPointF p1(10, 10); QPointF p2(20, 20); AnnotationLine lineItem(p1, properties); lineItem.addPoint(p2, false); MockZoomValueProvider zoomValueProvider; AnnotationItemResizer itemResizer(&lineItem, &zoomValueProvider); itemResizer.grabHandle(p1 + QPointF(2, 2)); auto isResizing = itemResizer.isResizing(); QCOMPARE(isResizing, true); } void AnnotationItemResizerTest::TestGrabHandle_Should_NotGrabHandle_When_ProvidedPointIsNotAtHandlePosition() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QPointF p1(10, 10); QPointF p2(20, 20); AnnotationLine lineItem(p1, properties); lineItem.addPoint(p2, false); MockZoomValueProvider zoomValueProvider; AnnotationItemResizer itemResizer(&lineItem, &zoomValueProvider); itemResizer.grabHandle(QPointF(0, 0)); auto isResizing = itemResizer.isResizing(); QCOMPARE(isResizing, false); } void AnnotationItemResizerTest::TestGrabHandle_Should_MoveResizeHandle_When_HandleGrabbed() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QPointF p1(10, 10); QPointF p2(20, 20); QPointF p3(30, 30); AnnotationLine lineItem(p1, properties); lineItem.addPoint(p2, false); MockZoomValueProvider zoomValueProvider; AnnotationItemResizer itemResizer(&lineItem, &zoomValueProvider); QUndoStack undoStack; connect(&itemResizer, &AnnotationItemResizer::newCommand, &undoStack, &QUndoStack::push); itemResizer.grabHandle(p1); itemResizer.moveHandle(p3, false); QCOMPARE(lineItem.line().p1(), p3); } void AnnotationItemResizerTest::TestReleaseHandle_Should_ReleaseHandle() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QPointF p1(10, 10); QPointF p2(20, 20); AnnotationLine lineItem(p1, properties); lineItem.addPoint(p2, false); MockZoomValueProvider zoomValueProvider; AnnotationItemResizer itemResizer(&lineItem, &zoomValueProvider); itemResizer.grabHandle(p1); QCOMPARE(itemResizer.isResizing(), true); itemResizer.releaseHandle(); QCOMPARE(itemResizer.isResizing(), false); } void AnnotationItemResizerTest::TestIsItemVisible_Should_ReturnFalse_When_ItemIsHidden() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QPointF p1(10, 10); QPointF p2(20, 20); AnnotationLine lineItem(p1, properties); lineItem.addPoint(p2, false); MockZoomValueProvider zoomValueProvider; AnnotationItemResizer itemResizer(&lineItem, &zoomValueProvider); lineItem.hide(); auto result = itemResizer.isItemVisible(); QCOMPARE(result, false); } QTEST_MAIN(AnnotationItemResizerTest); kImageAnnotator-0.5.3/tests/annotations/modifiers/AnnotationItemResizerTest.h000066400000000000000000000032561414424500400275740ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMRESIZERTEST_H #define KIMAGEANNOTATOR_ANNOTATIONITEMRESIZERTEST_H #include #include #include "src/annotations/modifiers/AnnotationItemResizer.h" #include "src/annotations/items/AnnotationLine.h" using kImageAnnotator::AnnotationItemResizer; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::AnnotationLine; using kImageAnnotator::PropertiesPtr; class AnnotationItemResizerTest : public QObject { Q_OBJECT private slots: void TestGrabHandle_Should_GrabHandle_When_ProvidedPointIsAtHandlePosition(); void TestGrabHandle_Should_NotGrabHandle_When_ProvidedPointIsNotAtHandlePosition(); void TestGrabHandle_Should_MoveResizeHandle_When_HandleGrabbed(); void TestReleaseHandle_Should_ReleaseHandle(); void TestIsItemVisible_Should_ReturnFalse_When_ItemIsHidden(); }; #endif // KIMAGEANNOTATOR_ANNOTATIONITEMRESIZERTEST_H kImageAnnotator-0.5.3/tests/annotations/modifiers/AnnotationItemSelectorTest.cpp000066400000000000000000000351741414424500400302700ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationItemSelectorTest.h" #include "tests/mocks/MockZoomValueProvider.h" void AnnotationItemSelectorTest::TestHandleSelectionRectAt_Should_SelectItem_When_ItemUnderProvidedPosition() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); QPointF p1(10, 10); QPointF p2(10, 20); AnnotationLine line(p1, properties); line.addPoint(p2, false); QList items; items.append(&line); MockZoomValueProvider zoomValueProvider; AnnotationItemSelector selector(&zoomValueProvider); selector.handleSelectionOrShowSelectionRectAt(p1 + QPointF(0, 5), &items, false); auto results = selector.selectedItems(); QCOMPARE(results.count(), 1); QCOMPARE(results.first(), &line); } void AnnotationItemSelectorTest::TestHandleSelectionRectAt_Should_NotSelectItem_When_ItemNotUnderProvidedPosition() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); QPointF p1(10, 10); QPointF p2(10, 20); AnnotationLine line(p1, properties); line.addPoint(p2, false); QList items; items.append(&line); MockZoomValueProvider zoomValueProvider; AnnotationItemSelector selector(&zoomValueProvider); selector.handleSelectionOrShowSelectionRectAt(p1 + QPointF(0, -5), &items, false); auto results = selector.selectedItems(); QCOMPARE(results.count(), 0); QCOMPARE(results.contains(&line), false); } void AnnotationItemSelectorTest::TestHandleSelectionRectAt_Should_UnselectAllItems_When_ProvidedPositionNotOverAnyItem() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); QPointF p1(10, 10); QPointF p2(10, 20); QPointF p3(15, 15); QPointF p4(20, 20); AnnotationLine line1(p1, properties1); AnnotationLine line2(p3, properties2); line1.addPoint(p2, false); line2.addPoint(p4, false); QList items; items.append(&line1); items.append(&line2); MockZoomValueProvider zoomValueProvider; AnnotationItemSelector selector(&zoomValueProvider); selector.handleSelectionOrShowSelectionRectAt(p1 + QPointF(-5, -5), &items, false); selector.extendSelectionRectWhenShown(p4 + QPointF(5, 5)); selector.finishSelectionRectWhenShown(&items); QCOMPARE(selector.selectedItems().count(), 2); selector.handleSelectionOrShowSelectionRectAt(QPointF(0, 0), &items, false); auto results = selector.selectedItems(); QCOMPARE(results.count(), 0); } void AnnotationItemSelectorTest::TestHandleSelectionRectAt_Should_NotUnselectAnyItem_When_ProvidedPositionIsOverSelectedItem() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); QPointF p1(10, 10); QPointF p2(10, 20); QPointF p3(15, 15); QPointF p4(20, 20); AnnotationLine line1(p1, properties1); AnnotationLine line2(p3, properties2); line1.addPoint(p2, false); line2.addPoint(p4, false); QList items; items.append(&line1); items.append(&line2); MockZoomValueProvider zoomValueProvider; AnnotationItemSelector selector(&zoomValueProvider); selector.handleSelectionOrShowSelectionRectAt(p1 + QPointF(-5, -5), &items, false); selector.extendSelectionRectWhenShown(p4 + QPointF(5, 5)); selector.finishSelectionRectWhenShown(&items); QCOMPARE(selector.selectedItems().count(), 2); selector.handleSelectionOrShowSelectionRectAt(p1 + QPointF(0, 5), &items, false); auto results = selector.selectedItems(); QCOMPARE(results.count(), 2); } void AnnotationItemSelectorTest::TestHandleSelectionRectAt_Should_UnselectItemsNotUnderPosition_When_ProvidedPositionIsOverNotSelectedItem() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); QPointF p1(10, 10); QPointF p2(12, 12); QPointF p3(15, 15); QPointF p4(20, 20); AnnotationLine line1(p1, properties1); AnnotationLine line2(p3, properties2); line1.addPoint(p2, false); line2.addPoint(p4, false); QList items; items.append(&line1); items.append(&line2); MockZoomValueProvider zoomValueProvider; AnnotationItemSelector selector(&zoomValueProvider); selector.handleSelectionOrShowSelectionRectAt(p1 + QPointF(-5, -5), &items, false); selector.extendSelectionRectWhenShown(p2 + QPointF(1, 1)); selector.finishSelectionRectWhenShown(&items); QCOMPARE(selector.selectedItems().count(), 1); QCOMPARE(selector.selectedItems().contains(&line1), true); QCOMPARE(selector.selectedItems().contains(&line2), false); selector.handleSelectionOrShowSelectionRectAt(p3 + QPointF(2, 2), &items, false); auto results = selector.selectedItems(); QCOMPARE(results.count(), 1); QCOMPARE(results.contains(&line1), false); QCOMPARE(results.contains(&line2), true); } void AnnotationItemSelectorTest::TestHandleSelectionRectAt_Should_NotShowRect_When_InitialPositionNotOnItem() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); QPointF p1(10, 10); QPointF p2(10, 20); AnnotationLine line(p1, properties); line.addPoint(p2, false); QList items; items.append(&line); MockZoomValueProvider zoomValueProvider; AnnotationItemSelector selector(&zoomValueProvider); selector.handleSelectionOrShowSelectionRectAt(QPointF(2, 2), &items, false); QCOMPARE(selector.selectedItems().count(), 0); QCOMPARE(selector.isSelecting(), true); } void AnnotationItemSelectorTest::TestHandleSelectionRectAt_Should_ShowRect_When_InitialPositionOnItem() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); QPointF p1(10, 10); QPointF p2(10, 20); AnnotationLine line(p1, properties); line.addPoint(p2, false); QList items; items.append(&line); MockZoomValueProvider zoomValueProvider; AnnotationItemSelector selector(&zoomValueProvider); selector.handleSelectionOrShowSelectionRectAt(p1 + QPointF(0, 5), &items, false); QCOMPARE(selector.selectedItems().count(), 1); QCOMPARE(selector.isSelecting(), false); } void AnnotationItemSelectorTest::TestHandleSelectionRectAt_Should_UnselectItem_When_WhenCtrlPressedAndItemUnderProvidedPositionWasSelected() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QPointF p1(10, 10); QPointF p2(10, 20); AnnotationLine line(p1, properties); line.addPoint(p2, false); QList items; items.append(&line); MockZoomValueProvider zoomValueProvider; AnnotationItemSelector selector(&zoomValueProvider); selector.handleSelectionOrShowSelectionRectAt(p1, &items, false); QCOMPARE(selector.selectedItems().first(), &line); selector.handleSelectionOrShowSelectionRectAt(p1, &items, true); auto results = selector.selectedItems(); QCOMPARE(results.count(), 0); } void AnnotationItemSelectorTest::TestHandleSelectionRectAt_Should_SelectItem_When_WhenCtrlPressedAndItemUnderProvidedPositionWasNotSelected() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QPointF p1(10, 10); QPointF p2(10, 20); AnnotationLine line(p1, properties); line.addPoint(p2, false); QList items; items.append(&line); MockZoomValueProvider zoomValueProvider; AnnotationItemSelector selector(&zoomValueProvider); QCOMPARE(selector.selectedItems().count(), 0); selector.handleSelectionOrShowSelectionRectAt(p1, &items, true); auto results = selector.selectedItems(); QCOMPARE(results.count(), 1); QCOMPARE(results.first(), &line); } void AnnotationItemSelectorTest::TestFinishSelectionRectWhenShown_Should_SelectItems_When_ItemsWithinSelectionRect() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); QPointF p1(10, 10); QPointF p2(10, 20); QPointF p3(15, 15); QPointF p4(20, 20); AnnotationLine line1(p1, properties1); AnnotationLine line2(p3, properties2); line1.addPoint(p2, false); line2.addPoint(p4, false); QList items; items.append(&line1); items.append(&line2); MockZoomValueProvider zoomValueProvider; AnnotationItemSelector selector(&zoomValueProvider); selector.handleSelectionOrShowSelectionRectAt(p1 + QPointF(-5, -5), &items, false); selector.extendSelectionRectWhenShown(p4 + QPointF(5, 5)); selector.finishSelectionRectWhenShown(&items); auto results = selector.selectedItems(); QCOMPARE(results.count(), 2); QCOMPARE(results.contains(&line1), true); QCOMPARE(results.contains(&line2), true); } void AnnotationItemSelectorTest::TestFinishSelectionRectWhenShown_Should_SelectOnlyItemWithinSelectionRect() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); QPointF p1(10, 10); QPointF p2(10, 20); QPointF p3(25, 25); QPointF p4(30, 30); AnnotationLine line1(p1, properties1); AnnotationLine line2(p3, properties2); line1.addPoint(p2, false); line2.addPoint(p4, false); QList items; items.append(&line1); items.append(&line2); MockZoomValueProvider zoomValueProvider; AnnotationItemSelector selector(&zoomValueProvider); selector.handleSelectionOrShowSelectionRectAt(p1 + QPointF(-5, -5), &items, false); selector.extendSelectionRectWhenShown(p2 + QPointF(5, 5)); selector.finishSelectionRectWhenShown(&items); auto results = selector.selectedItems(); QCOMPARE(results.count(), 1); QCOMPARE(results.contains(&line1), true); QCOMPARE(results.contains(&line2), false); } void AnnotationItemSelectorTest::TestClearSelection_Should_UnselectAllSelectedItems() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); QPointF p1(10, 10); QPointF p2(10, 20); QPointF p3(15, 15); QPointF p4(20, 20); AnnotationLine line1(p1, properties1); AnnotationLine line2(p3, properties2); line1.addPoint(p2, false); line2.addPoint(p4, false); QList items; items.append(&line1); items.append(&line2); MockZoomValueProvider zoomValueProvider; AnnotationItemSelector selector(&zoomValueProvider); selector.handleSelectionOrShowSelectionRectAt(p1 + QPointF(-5, -5), &items, false); selector.extendSelectionRectWhenShown(p4 + QPointF(5, 5)); selector.finishSelectionRectWhenShown(&items); QCOMPARE(selector.selectedItems().count(), 2); QCOMPARE(selector.selectedItems().contains(&line1), true); QCOMPARE(selector.selectedItems().contains(&line2), true); selector.clearSelection(); auto results = selector.selectedItems(); QCOMPARE(results.count(), 0); } void AnnotationItemSelectorTest::TestBoundRect_Should_ReturnRectCoveringSelectedItems_When_ItemsSelected() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); QPointF p1(10, 10); QPointF p2(10, 20); QPointF p3(25, 25); QPointF p4(30, 30); AnnotationLine line1(p1, properties1); AnnotationLine line2(p3, properties2); line1.addPoint(p2, false); line2.addPoint(p4, false); QList items; items.append(&line1); items.append(&line2); MockZoomValueProvider zoomValueProvider; AnnotationItemSelector selector(&zoomValueProvider); selector.handleSelectionOrShowSelectionRectAt(p1 + QPointF(-5, -5), &items, false); selector.extendSelectionRectWhenShown(p4); selector.finishSelectionRectWhenShown(&items); auto boundingRect = selector.boundingRect(); auto results = selector.selectedItems(); QCOMPARE(results.count(), 2); QCOMPARE(results.contains(&line1), true); QCOMPARE(results.contains(&line2), true); QCOMPARE(boundingRect, line1.boundingRect().united(line2.boundingRect())); } void AnnotationItemSelectorTest::TestRefresh_Should_UpdateBoundingRect_When_CalledAfterItemsHaveBeenMoved() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); QPointF p1(10, 10); QPointF p2(10, 20); QPointF p3(25, 25); QPointF p4(30, 30); QPointF p5(50, 50); AnnotationLine line1(p1, properties1); AnnotationLine line2(p3, properties2); line1.addPoint(p2, false); line2.addPoint(p4, false); QList items; items.append(&line1); items.append(&line2); MockZoomValueProvider zoomValueProvider; AnnotationItemSelector selector(&zoomValueProvider); selector.handleSelectionOrShowSelectionRectAt(p1 + QPointF(-5, -5), &items, false); selector.extendSelectionRectWhenShown(p4); selector.finishSelectionRectWhenShown(&items); line1.setPosition(p5); QVERIFY(selector.boundingRect() != line1.boundingRect().united(line2.boundingRect())); selector.refresh(); auto boundingRect = selector.boundingRect(); auto results = selector.selectedItems(); QCOMPARE(results.count(), 2); QCOMPARE(results.contains(&line1), true); QCOMPARE(results.contains(&line2), true); QCOMPARE(boundingRect, line1.boundingRect().united(line2.boundingRect())); } void AnnotationItemSelectorTest::TestUpdate_Should_UnselectItemsThatAreNotVisible() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 3)); QPointF p1(10, 10); QPointF p2(10, 20); QPointF p3(25, 25); QPointF p4(30, 30); AnnotationLine line1(p1, properties1); AnnotationLine line2(p3, properties2); line1.addPoint(p2, false); line2.addPoint(p4, false); QList items; items.append(&line1); items.append(&line2); MockZoomValueProvider zoomValueProvider; AnnotationItemSelector selector(&zoomValueProvider); selector.handleSelectionOrShowSelectionRectAt(QPointF(0, 0), &items, false); selector.extendSelectionRectWhenShown(p4); selector.finishSelectionRectWhenShown(&items); QCOMPARE(selector.selectedItems().count(), 2); line2.hide(); selector.update(); auto results = selector.selectedItems(); QCOMPARE(results.count(), 1); QCOMPARE(results.contains(&line1), true); QCOMPARE(results.contains(&line2), false); } QTEST_MAIN(AnnotationItemSelectorTest); kImageAnnotator-0.5.3/tests/annotations/modifiers/AnnotationItemSelectorTest.h000066400000000000000000000052521414424500400277270ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONITEMSELECTORTEST_H #define KIMAGEANNOTATOR_ANNOTATIONITEMSELECTORTEST_H #include #include "src/annotations/modifiers/AnnotationItemSelector.h" #include "src/annotations/items/AnnotationLine.h" using kImageAnnotator::AnnotationItemSelector; using kImageAnnotator::AnnotationLine; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::AbstractAnnotationItem; using kImageAnnotator::PropertiesPtr; class AnnotationItemSelectorTest : public QObject { Q_OBJECT private slots: void TestHandleSelectionRectAt_Should_SelectItem_When_ItemUnderProvidedPosition(); void TestHandleSelectionRectAt_Should_NotSelectItem_When_ItemNotUnderProvidedPosition(); void TestHandleSelectionRectAt_Should_UnselectAllItems_When_ProvidedPositionNotOverAnyItem(); void TestHandleSelectionRectAt_Should_NotUnselectAnyItem_When_ProvidedPositionIsOverSelectedItem(); void TestHandleSelectionRectAt_Should_UnselectItemsNotUnderPosition_When_ProvidedPositionIsOverNotSelectedItem(); void TestHandleSelectionRectAt_Should_NotShowRect_When_InitialPositionNotOnItem(); void TestHandleSelectionRectAt_Should_ShowRect_When_InitialPositionOnItem(); void TestHandleSelectionRectAt_Should_UnselectItem_When_WhenCtrlPressedAndItemUnderProvidedPositionWasSelected(); void TestHandleSelectionRectAt_Should_SelectItem_When_WhenCtrlPressedAndItemUnderProvidedPositionWasNotSelected(); void TestFinishSelectionRectWhenShown_Should_SelectItems_When_ItemsWithinSelectionRect(); void TestFinishSelectionRectWhenShown_Should_SelectOnlyItemWithinSelectionRect(); void TestClearSelection_Should_UnselectAllSelectedItems(); void TestBoundRect_Should_ReturnRectCoveringSelectedItems_When_ItemsSelected(); void TestRefresh_Should_UpdateBoundingRect_When_CalledAfterItemsHaveBeenMoved(); void TestUpdate_Should_UnselectItemsThatAreNotVisible(); }; #endif // KIMAGEANNOTATOR_ANNOTATIONITEMSELECTORTEST_H kImageAnnotator-0.5.3/tests/annotations/modifiers/AnnotationMultiItemResizerTest.cpp000066400000000000000000000136031414424500400311370ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationMultiItemResizerTest.h" #include "tests/mocks/MockZoomValueProvider.h" void AnnotationMultiItemResizerTest::TestGrabHandle_Should_GrabHandle_When_ProvidedPointIsAtHandlePosition() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line1(10, 10, 20, 20); AnnotationLine item1(line1.p1(), properties); item1.addPoint(line1.p2(), false); QList items = { &item1 }; MockZoomValueProvider zoomValueProvider; AnnotationMultiItemResizer itemResizer(&zoomValueProvider); itemResizer.attachTo(items); itemResizer.grabHandle(line1.p1()); QCOMPARE(itemResizer.isResizing(), true); } void AnnotationMultiItemResizerTest::TestGrabHandle_Should_NotGrabHandle_When_ProvidedPointIsNotAtHandlePosition() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line1(10, 10, 20, 20); AnnotationLine item1(line1.p1(), properties); item1.addPoint(line1.p2(), false); QList items = { &item1 }; MockZoomValueProvider zoomValueProvider; AnnotationMultiItemResizer itemResizer(&zoomValueProvider); itemResizer.attachTo(items); itemResizer.grabHandle(line1.p1() + QPointF(-10, -10)); QCOMPARE(itemResizer.isResizing(), false); } void AnnotationMultiItemResizerTest::TestGrabHandle_Should_MoveResizeHandle_When_HandleGrabbed() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line1(10, 10, 20, 20); QPointF newPoint(30, 30); AnnotationLine item1(line1.p1(), properties); item1.addPoint(line1.p2(), false); QList items = { &item1 }; MockZoomValueProvider zoomValueProvider; AnnotationMultiItemResizer itemResizer(&zoomValueProvider); QUndoStack undoStack; connect(&itemResizer, &AnnotationMultiItemResizer::newCommand, &undoStack, &QUndoStack::push); itemResizer.attachTo(items); itemResizer.grabHandle(line1.p1()); itemResizer.moveHandle(newPoint, false); QCOMPARE(item1.line().p1(), newPoint); } void AnnotationMultiItemResizerTest::TestGrabHandle_Should_OnlyMoveOneResizeHandle_When_MultipleItemsInList() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line1(10, 10, 20, 20); QPointF newPoint(30, 30); AnnotationLine item1(line1.p1(), properties1); AnnotationLine item2(line1.p1(), properties2); item1.addPoint(line1.p2(), false); item2.addPoint(line1.p2(), false); QList items = { &item1, &item2 }; MockZoomValueProvider zoomValueProvider; AnnotationMultiItemResizer itemResizer(&zoomValueProvider); QUndoStack undoStack; connect(&itemResizer, &AnnotationMultiItemResizer::newCommand, &undoStack, &QUndoStack::push); itemResizer.attachTo(items); itemResizer.grabHandle(line1.p1()); itemResizer.moveHandle(newPoint, false); QCOMPARE(item1.line().p1(), newPoint); QCOMPARE(item1.line().p2(), line1.p2()); QCOMPARE(item2.line().p1(), line1.p1()); QCOMPARE(item2.line().p2(), line1.p2()); } void AnnotationMultiItemResizerTest::TestReleaseHandle_Should_ReleaseHandle() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line1(10, 10, 20, 20); AnnotationLine item1(line1.p1(), properties); item1.addPoint(line1.p2(), false); QList items = { &item1 }; MockZoomValueProvider zoomValueProvider; AnnotationMultiItemResizer itemResizer(&zoomValueProvider); itemResizer.attachTo(items); itemResizer.grabHandle(line1.p1()); QCOMPARE(itemResizer.isResizing(), true); itemResizer.releaseHandle(); QCOMPARE(itemResizer.isResizing(), false); } void AnnotationMultiItemResizerTest::TestHasItemsAttached_Should_ReturnFalse_When_NoItemsInList() { QList items; MockZoomValueProvider zoomValueProvider; AnnotationMultiItemResizer itemResizer(&zoomValueProvider); itemResizer.attachTo(items); auto result = itemResizer.hasItemsAttached(); QCOMPARE(result, false); } void AnnotationMultiItemResizerTest::TestHasItemsAttached_Should_ReturnTrue_When_ItemsInList() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line1(10, 10, 20, 20); AnnotationLine item1(line1.p1(), properties); item1.addPoint(line1.p2(), false); QList items = { &item1 }; MockZoomValueProvider zoomValueProvider; AnnotationMultiItemResizer itemResizer(&zoomValueProvider); itemResizer.attachTo(items); auto result = itemResizer.hasItemsAttached(); QCOMPARE(result, true); } void AnnotationMultiItemResizerTest::TestUpdate_Should_HideResizers_When_ItemsOfResizersNotVisible() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line1(10, 10, 20, 20); AnnotationLine item1(line1.p1(), properties); item1.addPoint(line1.p2(), false); QList items = { &item1 }; MockZoomValueProvider zoomValueProvider; AnnotationMultiItemResizer itemResizer(&zoomValueProvider); itemResizer.attachTo(items); QCOMPARE(itemResizer.hasItemsAttached(), true); item1.hide(); itemResizer.update(); QCOMPARE(itemResizer.hasItemsAttached(), false); } QTEST_MAIN(AnnotationMultiItemResizerTest); kImageAnnotator-0.5.3/tests/annotations/modifiers/AnnotationMultiItemResizerTest.h000066400000000000000000000037261414424500400306110ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONMULTIITEMRESIZERTEST_H #define KIMAGEANNOTATOR_ANNOTATIONMULTIITEMRESIZERTEST_H #include #include #include "src/annotations/modifiers/AnnotationMultiItemResizer.h" #include "src/annotations/items/AnnotationLine.h" using kImageAnnotator::AnnotationMultiItemResizer; using kImageAnnotator::AnnotationLine; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::AbstractAnnotationItem; using kImageAnnotator::PropertiesPtr; class AnnotationMultiItemResizerTest : public QObject { Q_OBJECT private slots: void TestGrabHandle_Should_GrabHandle_When_ProvidedPointIsAtHandlePosition(); void TestGrabHandle_Should_NotGrabHandle_When_ProvidedPointIsNotAtHandlePosition(); void TestGrabHandle_Should_MoveResizeHandle_When_HandleGrabbed(); void TestGrabHandle_Should_OnlyMoveOneResizeHandle_When_MultipleItemsInList(); void TestReleaseHandle_Should_ReleaseHandle(); void TestHasItemsAttached_Should_ReturnFalse_When_NoItemsInList(); void TestHasItemsAttached_Should_ReturnTrue_When_ItemsInList(); void TestUpdate_Should_HideResizers_When_ItemsOfResizersNotVisible(); }; #endif // KIMAGEANNOTATOR_ANNOTATIONMULTIITEMRESIZERTEST_H kImageAnnotator-0.5.3/tests/annotations/modifiers/resizeHandles/000077500000000000000000000000001414424500400250605ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/annotations/modifiers/resizeHandles/LineResizeHandlesTest.cpp000066400000000000000000000115501414424500400317760ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "LineResizeHandlesTest.h" void LineResizeHandlesTest::TestInitHandles_Should_PositionTwoHandles() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QPointF p1(10, 10); QPointF p2(20, 20); AnnotationLine lineItem(p1, properties); lineItem.addPoint(p2, false); LineResizeHandles lineResizeHandles(&lineItem, 1.0); QCOMPARE(lineResizeHandles.handles().count(), 2); QCOMPARE(lineResizeHandles.handles()[0].anchor(), p1); QCOMPARE(lineResizeHandles.handles()[1].anchor(), p2); } void LineResizeHandlesTest::TestIndexOfHandleAt_Should_ReturnIndexOfHandle_When_HandleIsAtProvidedPosition() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QPointF p1(10, 10); QPointF p2(20, 20); AnnotationLine lineItem(p1, properties); lineItem.addPoint(p2, false); LineResizeHandles lineResizeHandles(&lineItem, 1.0); auto resultP1 = lineResizeHandles.indexOfHandleAt(p1 + QPointF(2, 2)); auto resultP2 = lineResizeHandles.indexOfHandleAt(p2 + QPointF(-2, -2)); QCOMPARE(lineResizeHandles.handles().count(), 2); QCOMPARE(resultP1, 0); QCOMPARE(resultP2, 1); } void LineResizeHandlesTest::TestIndexOfHandleAt_Should_NotReturnAnyIndex_When_HandleIsNotAtProvidedPosition() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QPointF p1(10, 10); QPointF p2(20, 20); AnnotationLine lineItem(p1, properties); lineItem.addPoint(p2, false); LineResizeHandles lineResizeHandles(&lineItem, 1.0); auto resultP1 = lineResizeHandles.indexOfHandleAt(QPointF(50, 50)); QCOMPARE(lineResizeHandles.handles().count(), 2); QCOMPARE(resultP1, -1); } void LineResizeHandlesTest::TestHandle_Should_ReturnRectAtIndex_When_HandleAtIndexExists() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QPointF p1(10, 10); QPointF p2(20, 20); AnnotationLine lineItem(p1, properties); lineItem.addPoint(p2, false); LineResizeHandles lineResizeHandles(&lineItem, 1.0); auto result = lineResizeHandles.handle(1); QVERIFY(result != QRectF()); QCOMPARE(result.anchor(), p2); } void LineResizeHandlesTest::TestHandle_Should_NotReturnRect_When_HandleAtIndexDoesntExists() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QPointF p1(10, 10); QPointF p2(20, 20); AnnotationLine lineItem(p1, properties); lineItem.addPoint(p2, false); LineResizeHandles lineResizeHandles(&lineItem, 1.0); auto result = lineResizeHandles.handle(3); QCOMPARE(result, ResizeHandle()); } void LineResizeHandlesTest::TestGetCursorForHandle_Should_NotReturnDefaultCursor_When_ProvidedPositionOnHandle() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QPointF p1(10, 10); QPointF p2(20, 20); AnnotationLine lineItem(p1, properties); lineItem.addPoint(p2, false); LineResizeHandles lineResizeHandles(&lineItem, 1.0); auto result = lineResizeHandles.cursorForPos(p1); QVERIFY(result != CursorHelper::defaultCursor()); } void LineResizeHandlesTest::TestGetCursorForHandle_Should_ReturnDefaultCursor_When_ProvidedPositionNotOnHandle() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QPointF p1(10, 10); QPointF p2(20, 20); QPointF p3(50, 50); AnnotationLine lineItem(p1, properties); lineItem.addPoint(p2, false); LineResizeHandles lineResizeHandles(&lineItem, 1.0); auto result = lineResizeHandles.cursorForPos(p3); QCOMPARE(result, CursorHelper::defaultCursor()); } void LineResizeHandlesTest::TestUpdate_Should_SetMoveHandlesToNewPositions() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QPointF p1(10, 10); QPointF p2(20, 20); QPointF p3(50, 50); QPointF p4(60, 60); AnnotationLine lineItem(p1, properties); lineItem.addPoint(p2, false); LineResizeHandles lineResizeHandles(&lineItem, 1.0); QCOMPARE(lineResizeHandles.handles()[0].center(), p1); QCOMPARE(lineResizeHandles.handles()[1].center(), p2); lineItem.setPointAt(p3, 0, false); lineItem.setPointAt(p4, 1, false); lineResizeHandles.update(); QCOMPARE(lineResizeHandles.handles()[0].center(), p3); QCOMPARE(lineResizeHandles.handles()[1].center(), p4); } QTEST_MAIN(LineResizeHandlesTest); kImageAnnotator-0.5.3/tests/annotations/modifiers/resizeHandles/LineResizeHandlesTest.h000066400000000000000000000040171414424500400314430ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_LINERESIZEHANDLESTEST_H #define KIMAGEANNOTATOR_LINERESIZEHANDLESTEST_H #include #include "src/annotations/modifiers/resizeHandles/LineResizeHandles.h" #include "src/annotations/items/AnnotationLine.h" #include "src/common/helper/CursorHelper.h" using kImageAnnotator::LineResizeHandles; using kImageAnnotator::CursorHelper; using kImageAnnotator::AnnotationLine; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::ResizeHandle; using kImageAnnotator::PropertiesPtr; class LineResizeHandlesTest : public QObject { Q_OBJECT private slots: void TestInitHandles_Should_PositionTwoHandles(); void TestIndexOfHandleAt_Should_ReturnIndexOfHandle_When_HandleIsAtProvidedPosition(); void TestIndexOfHandleAt_Should_NotReturnAnyIndex_When_HandleIsNotAtProvidedPosition(); void TestHandle_Should_ReturnRectAtIndex_When_HandleAtIndexExists(); void TestHandle_Should_NotReturnRect_When_HandleAtIndexDoesntExists(); void TestGetCursorForHandle_Should_NotReturnDefaultCursor_When_ProvidedPositionOnHandle(); void TestGetCursorForHandle_Should_ReturnDefaultCursor_When_ProvidedPositionNotOnHandle(); void TestUpdate_Should_SetMoveHandlesToNewPositions(); }; #endif // KIMAGEANNOTATOR_LINERESIZEHANDLESTEST_H kImageAnnotator-0.5.3/tests/annotations/modifiers/resizeHandles/PointerRectResizeHandlesTest.cpp000066400000000000000000000122311414424500400333420ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "PointerRectResizeHandlesTest.h" void PointerRectResizeHandlesTest::TestInitHandles_Should_PositionPointerHandle_When_PointerRectItemProvided() { auto properties = TextPropertiesPtr(new AnnotationTextProperties(Qt::red, 4)); QPointF startPosition(10,10); QPointF pointerPosition(50,50); AnnotationNumberPointer rectItem(startPosition, properties); rectItem.addPoint(pointerPosition, false); PointerRectResizeHandles resizeHandles(&rectItem, 1.0); QCOMPARE(resizeHandles.handles()[8].anchor(), pointerPosition); } void PointerRectResizeHandlesTest::TestIndexOfHandleAt_Should_ReturnIndexOfPointerHandle_When_HandleIsAtProvidedPosition() { auto properties = TextPropertiesPtr(new AnnotationTextProperties(Qt::red, 4)); QPointF startPosition(10,10); QPointF pointerPosition(50,50); AnnotationNumberPointer rectItem(startPosition, properties); rectItem.addPoint(pointerPosition, false); PointerRectResizeHandles resizeHandles(&rectItem, 1.0); auto result = resizeHandles.indexOfHandleAt(pointerPosition + QPointF(2, 2)); QCOMPARE(resizeHandles.handles().count(), 9); QCOMPARE(result, 8); } void PointerRectResizeHandlesTest::TestIndexOfHandleAt_Should_NotReturnAnyIndex_When_HandleIsNotAtProvidedPosition() { auto properties = TextPropertiesPtr(new AnnotationTextProperties(Qt::red, 4)); QPointF startPosition(10,10); QPointF pointerPosition(50,50); AnnotationNumberPointer rectItem(startPosition, properties); rectItem.addPoint(pointerPosition, false); PointerRectResizeHandles resizeHandles(&rectItem, 1.0); auto result = resizeHandles.indexOfHandleAt(QPointF(100, 100)); QCOMPARE(resizeHandles.handles().count(), 9); QCOMPARE(result, -1); } void PointerRectResizeHandlesTest::TestHandle_Should_ReturnPointerRectAtIndex_When_HandleAtIndexExists() { auto properties = TextPropertiesPtr(new AnnotationTextProperties(Qt::red, 4)); QPointF startPosition(10,10); QPointF pointerPosition(50,50); AnnotationNumberPointer rectItem(startPosition, properties); rectItem.addPoint(pointerPosition, false); PointerRectResizeHandles resizeHandles(&rectItem, 1.0); auto result = resizeHandles.handle(8); QVERIFY(result != QRectF()); QCOMPARE(result.anchor(), pointerPosition); } void PointerRectResizeHandlesTest::TestHandle_Should_NotReturnRect_When_HandleAtIndexDoesntExists() { auto properties = TextPropertiesPtr(new AnnotationTextProperties(Qt::red, 4)); QPointF startPosition(10,10); QPointF pointerPosition(50,50); AnnotationNumberPointer rectItem(startPosition, properties); rectItem.addPoint(pointerPosition, false); PointerRectResizeHandles resizeHandles(&rectItem, 1.0); auto result = resizeHandles.handle(10); QCOMPARE(result, ResizeHandle()); } void PointerRectResizeHandlesTest::TestGetCursorForHandle_Should_NotReturnDefaultCursor_When_ProvidedPositionOnHandle() { auto properties = TextPropertiesPtr(new AnnotationTextProperties(Qt::red, 4)); QPointF startPosition(10,10); QPointF pointerPosition(50,50); AnnotationNumberPointer rectItem(startPosition, properties); rectItem.addPoint(pointerPosition, false); PointerRectResizeHandles resizeHandles(&rectItem, 1.0); auto result = resizeHandles.cursorForPos(pointerPosition); QVERIFY(result != CursorHelper::defaultCursor()); } void PointerRectResizeHandlesTest::TestGetCursorForHandle_Should_ReturnDefaultCursor_When_ProvidedPositionNotOnHandle() { auto properties = TextPropertiesPtr(new AnnotationTextProperties(Qt::red, 4)); QPointF startPosition(10,10); QPointF pointerPosition(50,50); AnnotationNumberPointer rectItem(startPosition, properties); rectItem.addPoint(pointerPosition, false); PointerRectResizeHandles resizeHandles(&rectItem, 1.0); auto result = resizeHandles.cursorForPos(QPointF(100,100)); QCOMPARE(result, CursorHelper::defaultCursor()); } void PointerRectResizeHandlesTest::TestUpdate_Should_MovePointerHandlesToNewPosition() { auto properties = TextPropertiesPtr(new AnnotationTextProperties(Qt::red, 4)); QPointF startPosition(10,10); QPointF pointerPosition(50,50); QPointF newPointerPosition(80,80); AnnotationNumberPointer rectItem(startPosition, properties); rectItem.addPoint(pointerPosition, false); PointerRectResizeHandles resizeHandles(&rectItem, 1.0); QCOMPARE(resizeHandles.handles()[8].anchor(), pointerPosition); rectItem.addPoint(newPointerPosition, false); resizeHandles.update(); QCOMPARE(resizeHandles.handles()[8].anchor(), newPointerPosition); } QTEST_MAIN(PointerRectResizeHandlesTest) kImageAnnotator-0.5.3/tests/annotations/modifiers/resizeHandles/PointerRectResizeHandlesTest.h000066400000000000000000000043101414424500400330060ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_POINTERRECTRESIZEHANDLESTEST_H #define KIMAGEANNOTATOR_POINTERRECTRESIZEHANDLESTEST_H #include #include "src/annotations/modifiers/resizeHandles/PointerRectResizeHandles.h" #include "src/annotations/items/AnnotationNumberPointer.h" #include "src/common/helper/CursorHelper.h" using kImageAnnotator::PointerRectResizeHandles; using kImageAnnotator::AnnotationNumberPointer; using kImageAnnotator::AnnotationTextProperties; using kImageAnnotator::AbstractAnnotationItem; using kImageAnnotator::CursorHelper; using kImageAnnotator::ShapeHelper; using kImageAnnotator::ResizeHandle; using kImageAnnotator::TextPropertiesPtr; class PointerRectResizeHandlesTest : public QObject { Q_OBJECT private slots: void TestInitHandles_Should_PositionPointerHandle_When_PointerRectItemProvided(); void TestIndexOfHandleAt_Should_ReturnIndexOfPointerHandle_When_HandleIsAtProvidedPosition(); void TestIndexOfHandleAt_Should_NotReturnAnyIndex_When_HandleIsNotAtProvidedPosition(); void TestHandle_Should_ReturnPointerRectAtIndex_When_HandleAtIndexExists(); void TestHandle_Should_NotReturnRect_When_HandleAtIndexDoesntExists(); void TestGetCursorForHandle_Should_NotReturnDefaultCursor_When_ProvidedPositionOnHandle(); void TestGetCursorForHandle_Should_ReturnDefaultCursor_When_ProvidedPositionNotOnHandle(); void TestUpdate_Should_MovePointerHandlesToNewPosition(); }; #endif //KIMAGEANNOTATOR_POINTERRECTRESIZEHANDLESTEST_H kImageAnnotator-0.5.3/tests/annotations/modifiers/resizeHandles/RectResizeHandlesTest.cpp000066400000000000000000000167311414424500400320120ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "RectResizeHandlesTest.h" void RectResizeHandlesTest::TestInitHandles_Should_PositionEightHandles_When_RectItemProvided() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 4)); QRectF rect(QPointF(10, 15), QPointF(20, 25)); AnnotationRect rectItem(rect.topLeft(), properties); rectItem.addPoint(rect.bottomRight(), false); RectResizeHandles rectResizeHandles(&rectItem, 1.0); QCOMPARE(rectResizeHandles.handles().count(), 8); QCOMPARE(rectResizeHandles.handles()[0].anchor(), rect.topLeft()); QCOMPARE(rectResizeHandles.handles()[1].anchor(), QPointF(rect.center().x(), rect.top())); QCOMPARE(rectResizeHandles.handles()[2].anchor(), rect.topRight()); QCOMPARE(rectResizeHandles.handles()[3].anchor(), QPointF(rect.right(), rect.center().y())); QCOMPARE(rectResizeHandles.handles()[4].anchor(), rect.bottomRight()); QCOMPARE(rectResizeHandles.handles()[5].anchor(), QPointF(rect.center().x(), rect.bottom())); QCOMPARE(rectResizeHandles.handles()[6].anchor(), rect.bottomLeft()); QCOMPARE(rectResizeHandles.handles()[7].anchor(), QPointF(rect.left(), rect.center().y())); } void RectResizeHandlesTest::TestIndexOfHandleAt_Should_ReturnIndexOfHandle_When_HandleIsAtProvidedPosition() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QRectF rect(QPointF(10, 15), QPointF(80, 95)); AnnotationRect rectItem(rect.topLeft(), properties); rectItem.addPoint(rect.bottomRight(), false); RectResizeHandles rectResizeHandles(&rectItem, 1.0); auto resultP1 = rectResizeHandles.indexOfHandleAt(rect.topLeft() + QPointF(2, 2)); auto resultP2 = rectResizeHandles.indexOfHandleAt(ShapeHelper::rectTop(rect) + QPointF(-2, -2)); auto resultP3 = rectResizeHandles.indexOfHandleAt(rect.topRight() + QPointF(-2, -2)); auto resultP4 = rectResizeHandles.indexOfHandleAt(ShapeHelper::rectRight(rect) + QPointF(-2, -2)); auto resultP5 = rectResizeHandles.indexOfHandleAt(rect.bottomRight() + QPointF(-2, -2)); auto resultP6 = rectResizeHandles.indexOfHandleAt(ShapeHelper::rectBottom(rect) + QPointF(-2, -2)); auto resultP7 = rectResizeHandles.indexOfHandleAt(rect.bottomLeft() + QPointF(-2, -2)); auto resultP8 = rectResizeHandles.indexOfHandleAt(ShapeHelper::rectLeft(rect) + QPointF(-2, -2)); QCOMPARE(rectResizeHandles.handles().count(), 8); QCOMPARE(resultP1, 0); QCOMPARE(resultP2, 1); QCOMPARE(resultP3, 2); QCOMPARE(resultP4, 3); QCOMPARE(resultP5, 4); QCOMPARE(resultP6, 5); QCOMPARE(resultP7, 6); QCOMPARE(resultP8, 7); } void RectResizeHandlesTest::TestIndexOfHandleAt_Should_NotReturnAnyIndex_When_HandleIsNotAtProvidedPosition() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QRectF rect(QPointF(10, 15), QPointF(20, 25)); AnnotationRect rectItem(rect.topLeft(), properties); rectItem.addPoint(rect.bottomRight(), false); RectResizeHandles rectResizeHandles(&rectItem, 1.0); auto resultP1 = rectResizeHandles.indexOfHandleAt(QPointF(50, 50)); QCOMPARE(rectResizeHandles.handles().count(), 8); QCOMPARE(resultP1, -1); } void RectResizeHandlesTest::TestHandle_Should_ReturnRectAtIndex_When_HandleAtIndexExists() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QRectF rect(QPointF(10, 15), QPointF(20, 25)); AnnotationRect rectItem(rect.topLeft(), properties); rectItem.addPoint(rect.bottomRight(), false); RectResizeHandles rectResizeHandles(&rectItem, 1.0); auto result = rectResizeHandles.handle(2); QVERIFY(result != QRectF()); QCOMPARE(result.anchor(), rect.topRight()); } void RectResizeHandlesTest::TestHandle_Should_NotReturnRect_When_HandleAtIndexDoesntExists() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QRectF rect(QPointF(10, 15), QPointF(20, 25)); AnnotationRect rectItem(rect.topLeft(), properties); rectItem.addPoint(rect.bottomRight(), false); RectResizeHandles rectResizeHandles(&rectItem, 1.0); auto result = rectResizeHandles.handle(10); QCOMPARE(result, ResizeHandle()); } void RectResizeHandlesTest::TestGetCursorForHandle_Should_NotReturnDefaultCursor_When_ProvidedPositionOnHandle() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QRectF rect(QPointF(10, 15), QPointF(20, 25)); AnnotationRect rectItem(rect.topLeft(), properties); rectItem.addPoint(rect.bottomRight(), false); RectResizeHandles rectResizeHandles(&rectItem, 1.0); auto result = rectResizeHandles.cursorForPos(rect.bottomLeft()); QVERIFY(result != CursorHelper::defaultCursor()); } void RectResizeHandlesTest::TestGetCursorForHandle_Should_ReturnDefaultCursor_When_ProvidedPositionNotOnHandle() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QRectF rect(QPointF(10, 15), QPointF(20, 25)); QPointF otherPos(90, 90); AnnotationRect rectItem(rect.topLeft(), properties); rectItem.addPoint(rect.bottomRight(), false); RectResizeHandles rectResizeHandles(&rectItem, 1.0); auto result = rectResizeHandles.cursorForPos(otherPos); QCOMPARE(result, CursorHelper::defaultCursor()); } void RectResizeHandlesTest::TestUpdate_Should_MoveHandlesToNewPosition() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2)); QRectF rect(QPointF(10, 15), QPointF(80, 95)); QRectF newRect(QPointF(60, 75), QPointF(120, 125)); AnnotationRect rectItem(rect.topLeft(), properties); rectItem.addPoint(rect.bottomRight(), false); RectResizeHandles rectResizeHandles(&rectItem, 1.0); QCOMPARE(rectResizeHandles.handles()[0].anchor(), rect.topLeft()); QCOMPARE(rectResizeHandles.handles()[1].anchor(), ShapeHelper::rectTop(rect)); QCOMPARE(rectResizeHandles.handles()[2].anchor(), rect.topRight()); QCOMPARE(rectResizeHandles.handles()[3].anchor(), ShapeHelper::rectRight(rect)); QCOMPARE(rectResizeHandles.handles()[4].anchor(), rect.bottomRight()); QCOMPARE(rectResizeHandles.handles()[5].anchor(), ShapeHelper::rectBottom(rect)); QCOMPARE(rectResizeHandles.handles()[6].anchor(), rect.bottomLeft()); QCOMPARE(rectResizeHandles.handles()[7].anchor(), ShapeHelper::rectLeft(rect)); rectItem.setPointAt(newRect.topLeft(), 0, false); rectItem.addPoint(newRect.bottomRight(), false); rectResizeHandles.update(); QCOMPARE(rectResizeHandles.handles()[0].anchor(), newRect.topLeft()); QCOMPARE(rectResizeHandles.handles()[1].anchor(), ShapeHelper::rectTop(newRect)); QCOMPARE(rectResizeHandles.handles()[2].anchor(), newRect.topRight()); QCOMPARE(rectResizeHandles.handles()[3].anchor(), ShapeHelper::rectRight(newRect)); QCOMPARE(rectResizeHandles.handles()[4].anchor(), newRect.bottomRight()); QCOMPARE(rectResizeHandles.handles()[5].anchor(), ShapeHelper::rectBottom(newRect)); QCOMPARE(rectResizeHandles.handles()[6].anchor(), newRect.bottomLeft()); QCOMPARE(rectResizeHandles.handles()[7].anchor(), ShapeHelper::rectLeft(newRect)); } QTEST_MAIN(RectResizeHandlesTest); kImageAnnotator-0.5.3/tests/annotations/modifiers/resizeHandles/RectResizeHandlesTest.h000066400000000000000000000041651414424500400314550ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_RECTRESIZEHANDLESTEST_H #define KIMAGEANNOTATOR_RECTRESIZEHANDLESTEST_H #include #include "src/annotations/modifiers/resizeHandles/RectResizeHandles.h" #include "src/annotations/items/AnnotationRect.h" #include "src/common/helper/CursorHelper.h" using kImageAnnotator::RectResizeHandles; using kImageAnnotator::AnnotationRect; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::AbstractAnnotationItem; using kImageAnnotator::CursorHelper; using kImageAnnotator::ShapeHelper; using kImageAnnotator::ResizeHandle; using kImageAnnotator::PropertiesPtr; class RectResizeHandlesTest : public QObject { Q_OBJECT private slots: void TestInitHandles_Should_PositionEightHandles_When_RectItemProvided(); void TestIndexOfHandleAt_Should_ReturnIndexOfHandle_When_HandleIsAtProvidedPosition(); void TestIndexOfHandleAt_Should_NotReturnAnyIndex_When_HandleIsNotAtProvidedPosition(); void TestHandle_Should_ReturnRectAtIndex_When_HandleAtIndexExists(); void TestHandle_Should_NotReturnRect_When_HandleAtIndexDoesntExists(); void TestGetCursorForHandle_Should_NotReturnDefaultCursor_When_ProvidedPositionOnHandle(); void TestGetCursorForHandle_Should_ReturnDefaultCursor_When_ProvidedPositionNotOnHandle(); void TestUpdate_Should_MoveHandlesToNewPosition(); }; #endif // KIMAGEANNOTATOR_RECTRESIZEHANDLESTEST_H kImageAnnotator-0.5.3/tests/annotations/undo/000077500000000000000000000000001414424500400212445ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/annotations/undo/AddCommandTest.cpp000066400000000000000000000042711414424500400246030ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AddCommandTest.h" #include "tests/mocks/MockDefaultParameters.h" void AddCommandTest::TestRedo_Should_ApplyOperation() { // arrange MockDefaultParameters p; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(&p.config, &p.settingsProvider, scalerMock, &p.zoomValueProvider, nullptr); auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line(10, 10, 20, 20); auto item = new AnnotationLine(line.p1(), properties); item->addPoint(line.p2(), false); AddCommand addCommand(item, &annotationArea); QCOMPARE(annotationArea.items().contains(item), false); // act addCommand.redo(); // arrange QCOMPARE(annotationArea.items().contains(item), true); } void AddCommandTest::TestUndo_Should_UndoOperation() { // arrange MockDefaultParameters p; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(&p.config, &p.settingsProvider, scalerMock, &p.zoomValueProvider, nullptr); auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line(10, 10, 20, 20); auto item = new AnnotationLine(line.p1(), properties); item->addPoint(line.p2(), false); AddCommand addCommand(item, &annotationArea); addCommand.redo(); QCOMPARE(annotationArea.items().contains(item), true); // act addCommand.undo(); // assert QCOMPARE(annotationArea.items().contains(item), false); } QTEST_MAIN(AddCommandTest); kImageAnnotator-0.5.3/tests/annotations/undo/AddCommandTest.h000066400000000000000000000030421414424500400242430ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ADDCOMMANDTEST_H #define KIMAGEANNOTATOR_ADDCOMMANDTEST_H #include #include "src/annotations/undo/AddCommand.h" #include "src/annotations/core/AnnotationArea.h" #include "src/annotations/items/AnnotationLine.h" #include "tests/mocks/MockSettingsProvider.h" #include "tests/mocks/MockDevicePixelRatioScaler.h" using kImageAnnotator::AddCommand; using kImageAnnotator::AnnotationArea; using kImageAnnotator::AnnotationLine; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::Config; using kImageAnnotator::PropertiesPtr; class AddCommandTest : public QObject { Q_OBJECT private slots: void TestRedo_Should_ApplyOperation(); void TestUndo_Should_UndoOperation(); }; #endif // KIMAGEANNOTATOR_ADDCOMMANDTEST_H kImageAnnotator-0.5.3/tests/annotations/undo/ArrangeCommandTest.cpp000066400000000000000000000106131414424500400254670ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ArrangeCommandTest.h" void ArrangeCommandTest::TestRedo_Should_SwapItemPosition() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QPointF pos(10, 10); AnnotationLine item1(pos, properties1); AnnotationLine item2(pos, properties2); item1.setZValue(1); item2.setZValue(2); QList> itemToSwap; itemToSwap.append(qMakePair(&item1, &item2)); QList emptyItemList; ArrangeCommand arrangeCommand(itemToSwap, &emptyItemList); QCOMPARE((int) item1.zValue(), 1); QCOMPARE((int) item2.zValue(), 2); arrangeCommand.redo(); QCOMPARE((int) item1.zValue(), 2); QCOMPARE((int) item2.zValue(), 1); } void ArrangeCommandTest::TestRedo_Should_SortItemByZValue() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties3= PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QPointF pos(10, 10); AnnotationLine item1(pos, properties1); AnnotationLine item2(pos, properties2); AnnotationLine item3(pos, properties3); item1.setZValue(1); item2.setZValue(2); item3.setZValue(3); QList> emptySwapList; QList allItems; allItems.append(&item2); allItems.append(&item1); allItems.append(&item3); ArrangeCommand arrangeCommand(emptySwapList, &allItems); QCOMPARE((int) allItems[0]->zValue(), 2); QCOMPARE((int) allItems[1]->zValue(), 1); QCOMPARE((int) allItems[2]->zValue(), 3); arrangeCommand.redo(); QCOMPARE((int) allItems[0]->zValue(), 3); QCOMPARE((int) allItems[1]->zValue(), 2); QCOMPARE((int) allItems[2]->zValue(), 1); } void ArrangeCommandTest::TestUndo_Should_SwapItemPositionBack() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QPointF pos(10, 10); AnnotationLine item1(pos, properties1); AnnotationLine item2(pos, properties2); item1.setZValue(1); item2.setZValue(2); QList> itemToSwap; itemToSwap.append(qMakePair(&item1, &item2)); QList emptyItemList; ArrangeCommand arrangeCommand(itemToSwap, &emptyItemList); arrangeCommand.redo(); QCOMPARE((int) item1.zValue(), 2); QCOMPARE((int) item2.zValue(), 1); arrangeCommand.redo(); QCOMPARE((int) item1.zValue(), 1); QCOMPARE((int) item2.zValue(), 2); } void ArrangeCommandTest::TestUndo_Should_SortItemByZValue() { auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto properties3 = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QPointF pos(10, 10); AnnotationLine item1(pos, properties1); AnnotationLine item2(pos, properties2); AnnotationLine item3(pos, properties3); item1.setZValue(1); item2.setZValue(2); item3.setZValue(3); QList> emptySwapList; QList allItems; allItems.append(&item2); allItems.append(&item1); allItems.append(&item3); ArrangeCommand arrangeCommand(emptySwapList, &allItems); QCOMPARE((int) allItems[0]->zValue(), 2); QCOMPARE((int) allItems[1]->zValue(), 1); QCOMPARE((int) allItems[2]->zValue(), 3); arrangeCommand.undo(); QCOMPARE((int) allItems[0]->zValue(), 3); QCOMPARE((int) allItems[1]->zValue(), 2); QCOMPARE((int) allItems[2]->zValue(), 1); } QTEST_MAIN(ArrangeCommandTest); kImageAnnotator-0.5.3/tests/annotations/undo/ArrangeCommandTest.h000066400000000000000000000027571414424500400251460ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGETANNOTATOR_ARRANGECOMMANDTEST_H #define KIMAGETANNOTATOR_ARRANGECOMMANDTEST_H #include #include "src/annotations/undo/ArrangeCommand.h" #include "src/annotations/items/AnnotationLine.h" using kImageAnnotator::ArrangeCommand; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::AnnotationLine; using kImageAnnotator::AbstractAnnotationItem; using kImageAnnotator::PropertiesPtr; class ArrangeCommandTest : public QObject { Q_OBJECT private slots: void TestRedo_Should_SwapItemPosition(); void TestRedo_Should_SortItemByZValue(); void TestUndo_Should_SwapItemPositionBack(); void TestUndo_Should_SortItemByZValue(); }; #endif //KIMAGETANNOTATOR_ARRANGECOMMANDTEST_H kImageAnnotator-0.5.3/tests/annotations/undo/CropCommandTest.cpp000066400000000000000000000076431414424500400250240ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "CropCommandTest.h" void CropCommandTest::TestRedo_Should_CropImageAndScene() { // arrange MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); QPixmap image(400, 400); QGraphicsPixmapItem graphicsPixmapItem(image); QRectF cropRect(100, 100, 200, 200); CropCommand cropCommand(&graphicsPixmapItem, cropRect, &annotationArea); // act cropCommand.redo(); // assert QCOMPARE(annotationArea.sceneRect().size(), cropRect.size()); QCOMPARE(graphicsPixmapItem.boundingRect().size(), cropRect.size()); } void CropCommandTest::TestRedo_Should_MoveItemToNewPosition() { // arrange MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); QPixmap image(400, 400); QGraphicsPixmapItem graphicsPixmapItem(image); QRectF cropRect(100, 100, 200, 200); auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QRectF rect(150, 150, 300, 300); auto item = new AnnotationRect(rect.topLeft(), properties); item->addPoint(rect.bottomRight(), false); annotationArea.addAnnotationItem(item); CropCommand cropCommand(&graphicsPixmapItem, cropRect, &annotationArea); // act cropCommand.redo(); // assert QCOMPARE(item->position(), QPointF(50, 50)); QCOMPARE(item->boundingRect().size(), rect.size()); } void CropCommandTest::TestUndo_Should_RestoreOriginalImageAndSceneSize() { // arrange MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); QPixmap image(400, 400); QGraphicsPixmapItem graphicsPixmapItem(image); QRectF cropRect(100, 100, 200, 200); CropCommand cropCommand(&graphicsPixmapItem, cropRect, &annotationArea); cropCommand.redo(); // act cropCommand.undo(); // assert QVERIFY(annotationArea.sceneRect().size() == image.size()); QVERIFY(graphicsPixmapItem.boundingRect().size() == image.size()); } void CropCommandTest::TestUndo_Should_MoveItemBackToPreviousPosition() { // arrange MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); QPixmap image(400, 400); QGraphicsPixmapItem graphicsPixmapItem(image); QRectF cropRect(100, 100, 200, 200); auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QRectF rect(150, 150, 300, 300); auto item = new AnnotationRect(rect.topLeft(), properties); item->addPoint(rect.bottomRight(), false); annotationArea.addAnnotationItem(item); CropCommand cropCommand(&graphicsPixmapItem, cropRect, &annotationArea); cropCommand.redo(); // act cropCommand.undo(); // assert QCOMPARE(item->position(), rect.topLeft()); QCOMPARE(item->boundingRect().size(), rect.size()); } QTEST_MAIN(CropCommandTest); kImageAnnotator-0.5.3/tests/annotations/undo/CropCommandTest.h000066400000000000000000000033221414424500400244570ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CROPCOMMANDTEST_H #define KIMAGEANNOTATOR_CROPCOMMANDTEST_H #include #include "src/annotations/undo/AddCommand.h" #include "src/annotations/core/AnnotationArea.h" #include "src/annotations/items/AnnotationLine.h" #include "tests/mocks/MockSettingsProvider.h" #include "tests/mocks/MockDevicePixelRatioScaler.h" #include "tests/mocks/MockDefaultParameters.h" using kImageAnnotator::CropCommand; using kImageAnnotator::AnnotationArea; using kImageAnnotator::AnnotationRect; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::Config; using kImageAnnotator::PropertiesPtr; class CropCommandTest : public QObject { Q_OBJECT private slots: void TestRedo_Should_CropImageAndScene(); void TestRedo_Should_MoveItemToNewPosition(); void TestUndo_Should_RestoreOriginalImageAndSceneSize(); void TestUndo_Should_MoveItemBackToPreviousPosition(); }; #endif // KIMAGEANNOTATOR_CROPCOMMANDTEST_H kImageAnnotator-0.5.3/tests/annotations/undo/DeleteCommandTest.cpp000066400000000000000000000046031414424500400253140ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "DeleteCommandTest.h" #include "tests/mocks/MockDefaultParameters.h" void DeleteCommandTest::TestRedo_Should_ApplyOperation() { // arrange MockDefaultParameters p; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(&p.config, &p.settingsProvider, scalerMock, &p.zoomValueProvider, nullptr); auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line(10, 10, 20, 20); AnnotationLine item(line.p1(), properties); item.addPoint(line.p2(), false); annotationArea.addAnnotationItem(&item); QCOMPARE(annotationArea.items().contains(&item), true); QList items = { &item }; DeleteCommand deleteCommand(items, &annotationArea); // act deleteCommand.redo(); // assert QCOMPARE(annotationArea.items().contains(&item), false); } void DeleteCommandTest::TestUndo_Should_UndoOperation() { // arrange MockDefaultParameters p; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(&p.config, &p.settingsProvider, scalerMock, &p.zoomValueProvider, nullptr); auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line(10, 10, 20, 20); AnnotationLine item(line.p1(), properties); item.addPoint(line.p2(), false); annotationArea.addAnnotationItem(&item); QList items = { &item }; DeleteCommand deleteCommand(items, &annotationArea); deleteCommand.redo(); QCOMPARE(annotationArea.items().contains(&item), false); // act deleteCommand.undo(); // assert QCOMPARE(annotationArea.items().contains(&item), true); } QTEST_MAIN(DeleteCommandTest); kImageAnnotator-0.5.3/tests/annotations/undo/DeleteCommandTest.h000066400000000000000000000031431414424500400247570ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_DELETECOMMANDTEST_H #define KIMAGEANNOTATOR_DELETECOMMANDTEST_H #include #include "src/annotations/undo/DeleteCommand.h" #include "src/annotations/core/AnnotationArea.h" #include "src/annotations/items/AnnotationLine.h" #include "tests/mocks/MockSettingsProvider.h" #include "tests/mocks/MockDevicePixelRatioScaler.h" using kImageAnnotator::DeleteCommand; using kImageAnnotator::AnnotationArea; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::AnnotationLine; using kImageAnnotator::AbstractAnnotationItem; using kImageAnnotator::Config; using kImageAnnotator::PropertiesPtr; class DeleteCommandTest : public QObject { Q_OBJECT private slots: void TestRedo_Should_ApplyOperation(); void TestUndo_Should_UndoOperation(); }; #endif // KIMAGEANNOTATOR_DELETECOMMANDTEST_H kImageAnnotator-0.5.3/tests/annotations/undo/ModifyCanvasCommandTest.cpp000066400000000000000000000105671414424500400265030ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ModifyCanvasCommandTest.h" void ModifyCanvasCommandTest::Redo_Should_ModifyCanvasSizeAndColor_When_SizeAndColorChanged() { MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); QPixmap image(400, 400); annotationArea.loadImage(image); QRectF newCanvasRect(100, 100, 200, 200); QColor newCanvasColor(Qt::red); ModifyCanvasCommand modifyCanvasCommand(newCanvasRect, newCanvasColor, &annotationArea); modifyCanvasCommand.redo(); QCOMPARE(annotationArea.canvasRect(), newCanvasRect); QCOMPARE(annotationArea.canvasColor(), newCanvasColor); QCOMPARE(annotationArea.isCustomCanvasRect(), true); } void ModifyCanvasCommandTest::Redo_Should_OnlyModifyCanvasColor_When_OnlyColorChanged() { MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); QPixmap image(400, 400); annotationArea.loadImage(image); QColor newCanvasColor(Qt::red); auto originalCanvasRect = annotationArea.canvasRect(); ModifyCanvasCommand modifyCanvasCommand(originalCanvasRect, newCanvasColor, &annotationArea); modifyCanvasCommand.redo(); QCOMPARE(annotationArea.canvasRect(), originalCanvasRect); QCOMPARE(annotationArea.canvasColor(), newCanvasColor); QCOMPARE(annotationArea.isCustomCanvasRect(), false); } void ModifyCanvasCommandTest::Undo_Should_RevertCanvasSizeAndColor_When_SizeAndColorChanged() { MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); QPixmap image(400, 400); annotationArea.loadImage(image); auto originalCanvasRect = annotationArea.canvasRect(); auto originalCanvasColor = annotationArea.canvasColor(); QRectF newCanvasRect(100, 100, 200, 200); QColor newCanvasColor(Qt::red); ModifyCanvasCommand modifyCanvasCommand(newCanvasRect, newCanvasColor, &annotationArea); modifyCanvasCommand.redo(); QCOMPARE(annotationArea.canvasRect(), newCanvasRect); QCOMPARE(annotationArea.canvasColor(), newCanvasColor); QCOMPARE(annotationArea.isCustomCanvasRect(), true); modifyCanvasCommand.undo(); QCOMPARE(annotationArea.canvasRect(), originalCanvasRect); QCOMPARE(annotationArea.canvasColor(), originalCanvasColor); QCOMPARE(annotationArea.isCustomCanvasRect(), false); } void ModifyCanvasCommandTest::Undo_Should_RevertOnlyColor_When_OnlyColorChanged() { MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); QPixmap image(400, 400); annotationArea.loadImage(image); QColor newCanvasColor(Qt::red); auto originalCanvasRect = annotationArea.canvasRect(); auto originalCanvasColor = annotationArea.canvasColor(); ModifyCanvasCommand modifyCanvasCommand(originalCanvasRect, newCanvasColor, &annotationArea); modifyCanvasCommand.redo(); QCOMPARE(annotationArea.canvasRect(), originalCanvasRect); QCOMPARE(annotationArea.canvasColor(), newCanvasColor); QCOMPARE(annotationArea.isCustomCanvasRect(), false); modifyCanvasCommand.undo(); QCOMPARE(annotationArea.canvasRect(), originalCanvasRect); QCOMPARE(annotationArea.canvasColor(), originalCanvasColor); QCOMPARE(annotationArea.isCustomCanvasRect(), false); } QTEST_MAIN(ModifyCanvasCommandTest); kImageAnnotator-0.5.3/tests/annotations/undo/ModifyCanvasCommandTest.h000066400000000000000000000033051414424500400261400ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_MODIFYCANVASCOMMANDTEST_H #define KIMAGEANNOTATOR_MODIFYCANVASCOMMANDTEST_H #include #include "src/annotations/undo/AddCommand.h" #include "src/annotations/core/AnnotationArea.h" #include "src/annotations/items/AnnotationLine.h" #include "tests/mocks/MockSettingsProvider.h" #include "tests/mocks/MockDevicePixelRatioScaler.h" #include "tests/mocks/MockDefaultParameters.h" using kImageAnnotator::ModifyCanvasCommand; using kImageAnnotator::AnnotationArea; using kImageAnnotator::PropertiesPtr; class ModifyCanvasCommandTest : public QObject { Q_OBJECT private slots: void Redo_Should_ModifyCanvasSizeAndColor_When_SizeAndColorChanged(); void Redo_Should_OnlyModifyCanvasColor_When_OnlyColorChanged(); void Undo_Should_RevertCanvasSizeAndColor_When_SizeAndColorChanged(); void Undo_Should_RevertOnlyColor_When_OnlyColorChanged(); }; #endif //KIMAGEANNOTATOR_MODIFYCANVASCOMMANDTEST_H kImageAnnotator-0.5.3/tests/annotations/undo/MoveCommandTest.cpp000066400000000000000000000112051414424500400250140ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "MoveCommandTest.h" void MoveCommandTest::TestRedo_Should_MoveItemToNewPosition() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line(10, 10, 20, 20); auto item = new AnnotationLine(line.p1(), properties); item->addPoint(line.p2(), false); auto oldPosition = item->position(); QPointF newPosition(50, 50); QHash itemToPosition; itemToPosition[item] = newPosition; MoveCommand moveCommand(itemToPosition); QCOMPARE(item->position(), oldPosition); moveCommand.redo(); QCOMPARE(item->position(), newPosition); } void MoveCommandTest::TestUndo_Should_MoveItemToInitialPosition() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line(10, 10, 20, 20); auto item = new AnnotationLine(line.p1(), properties); item->addPoint(line.p2(), false); auto oldPosition = item->position(); QPointF newPosition(50, 50); QHash itemToPosition; itemToPosition[item] = newPosition; MoveCommand moveCommand(itemToPosition); moveCommand.redo(); QCOMPARE(item->position(), newPosition); moveCommand.undo(); QCOMPARE(item->position(), oldPosition); } void MoveCommandTest::TestMergeWith_Should_TakeNewPositionFromLastMoveCommand() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line(10, 10, 20, 20); auto item = new AnnotationLine(line.p1(), properties); item->addPoint(line.p2(), false); auto oldPosition = item->position(); QPointF firstPosition(50, 50); QPointF secondPosition(70, 70); QHash itemToPositionFirst; QHash itemToPositionSecond; itemToPositionFirst[item] = firstPosition; itemToPositionFirst[item] = secondPosition; MoveCommand moveCommandFirst(itemToPositionFirst); MoveCommand moveCommandSecond(itemToPositionSecond); moveCommandFirst.mergeWith(&moveCommandSecond); QCOMPARE(item->position(), oldPosition); moveCommandFirst.redo(); QCOMPARE(item->position(), secondPosition); } void MoveCommandTest::TestMergeWith_Should_KeepInitialPositionFromFirstMoveCommand() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line(10, 10, 20, 20); auto item = new AnnotationLine(line.p1(), properties); item->addPoint(line.p2(), false); auto oldPosition = item->position(); QPointF firstPosition(50, 50); QPointF secondPosition(70, 70); QHash itemToPositionFirst; QHash itemToPositionSecond; itemToPositionFirst[item] = firstPosition; itemToPositionFirst[item] = secondPosition; MoveCommand moveCommandFirst(itemToPositionFirst); MoveCommand moveCommandSecond(itemToPositionSecond); moveCommandFirst.mergeWith(&moveCommandSecond); moveCommandFirst.redo(); QCOMPARE(item->position(), secondPosition); moveCommandFirst.undo(); QCOMPARE(item->position(), oldPosition); } void MoveCommandTest::TestMergeWith_Should_NotMergeMoveCommands_When_ItemsAreNotTheSame() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line1(10, 10, 20, 20); QLineF line2(15, 15, 25, 25); auto item1 = new AnnotationLine(line1.p1(), properties); auto item2 = new AnnotationLine(line2.p1(), properties); item1->addPoint(line1.p2(), false); item2->addPoint(line2.p2(), false); QPointF newPosition1(50, 50); QPointF newPosition2(60, 60); QHash item1ToPosition; QHash item2ToPosition; item1ToPosition[item1] = newPosition1; item2ToPosition[item2] = newPosition2; MoveCommand moveCommand1(item1ToPosition); MoveCommand moveCommand2(item2ToPosition); moveCommand1.mergeWith(&moveCommand2); moveCommand1.redo(); moveCommand2.redo(); QCOMPARE(item1->position(), newPosition1); QCOMPARE(item2->position(), newPosition2); } QTEST_MAIN(MoveCommandTest); kImageAnnotator-0.5.3/tests/annotations/undo/MoveCommandTest.h000066400000000000000000000031431414424500400244630ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_MOVECOMMANDTEST_H #define KIMAGEANNOTATOR_MOVECOMMANDTEST_H #include #include "src/annotations/undo/MoveCommand.h" #include "src/annotations/items/AnnotationLine.h" using kImageAnnotator::MoveCommand; using kImageAnnotator::AnnotationLine; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::AbstractAnnotationItem; using kImageAnnotator::PropertiesPtr; class MoveCommandTest : public QObject { Q_OBJECT private slots: void TestRedo_Should_MoveItemToNewPosition(); void TestUndo_Should_MoveItemToInitialPosition(); void TestMergeWith_Should_TakeNewPositionFromLastMoveCommand(); void TestMergeWith_Should_KeepInitialPositionFromFirstMoveCommand(); void TestMergeWith_Should_NotMergeMoveCommands_When_ItemsAreNotTheSame(); }; #endif // KIMAGEANNOTATOR_MOVECOMMANDTEST_H kImageAnnotator-0.5.3/tests/annotations/undo/PasteCommandTest.cpp000066400000000000000000000076521414424500400251750ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "PasteCommandTest.h" #include "src/annotations/undo/PasteCommand.h" #include "src/annotations/core/AnnotationArea.h" #include "src/annotations/items/AnnotationLine.h" #include "src/annotations/core/AnnotationPropertiesFactory.h" #include "tests/mocks/MockDefaultParameters.h" using kImageAnnotator::PasteCommand; using kImageAnnotator::AnnotationArea; using kImageAnnotator::AbstractAnnotationItem; using kImageAnnotator::AnnotationLine; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::Config; using kImageAnnotator::AnnotationItemFactory; using kImageAnnotator::PropertiesPtr; using kImageAnnotator::AnnotationPropertiesFactory; void PasteCommandTest::TestRedo_Should_AddPastedItemsToAnnotationAreaAtGivenPosition() { // arrange auto offset = QPointF(10, 10); auto position = QPointF(50, 50); MockDefaultParameters mockParameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationPropertiesFactory propertiesFactory(&mockParameters.config, &mockParameters.settingsProvider); AnnotationArea annotationArea(&mockParameters.config, &mockParameters.settingsProvider, scalerMock, &mockParameters.zoomValueProvider, nullptr); AnnotationItemFactory itemFactory(&propertiesFactory, &mockParameters.settingsProvider, &mockParameters.config); auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line(10, 10, 20, 20); auto item = new AnnotationLine(line.p1(), properties); item->addPoint(line.p2(), false); QHash itemsWithOffset; itemsWithOffset[item] = offset; PasteCommand pasteCommand(itemsWithOffset, position, &itemFactory, &annotationArea); QVERIFY(dynamic_cast(annotationArea.items().last()) == nullptr); // act pasteCommand.redo(); // assert auto lastItem = dynamic_cast(annotationArea.items().last()); QVERIFY(lastItem != nullptr); QCOMPARE(lastItem->position(), position + offset); } void PasteCommandTest::TestUndo_Should_RemovePastedItemsFromAnnotationArea() { // arrange auto offset = QPointF(10, 10); auto position = QPointF(50, 50); MockDefaultParameters mockParameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationPropertiesFactory propertiesFactory(&mockParameters.config, &mockParameters.settingsProvider); AnnotationArea annotationArea(&mockParameters.config, &mockParameters.settingsProvider, scalerMock, &mockParameters.zoomValueProvider, nullptr); AnnotationItemFactory itemFactory(&propertiesFactory, &mockParameters.settingsProvider, &mockParameters.config); auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line(10, 10, 20, 20); auto item = new AnnotationLine(line.p1(), properties); item->addPoint(line.p2(), false); QHash itemsWithOffset; itemsWithOffset[item] = offset; PasteCommand pasteCommand(itemsWithOffset, position, &itemFactory, &annotationArea); pasteCommand.redo(); QVERIFY(dynamic_cast(annotationArea.items().last()) != nullptr); // act pasteCommand.undo(); // arrange QVERIFY(dynamic_cast(annotationArea.items().last()) == nullptr); } QTEST_MAIN(PasteCommandTest); kImageAnnotator-0.5.3/tests/annotations/undo/PasteCommandTest.h000066400000000000000000000022101414424500400246230ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_PASTECOMMANDTEST_H #define KIMAGEANNOTATOR_PASTECOMMANDTEST_H #include class PasteCommandTest : public QObject { Q_OBJECT private slots: void TestRedo_Should_AddPastedItemsToAnnotationAreaAtGivenPosition(); void TestUndo_Should_RemovePastedItemsFromAnnotationArea(); }; #endif // KIMAGEANNOTATOR_PASTECOMMANDTEST_H kImageAnnotator-0.5.3/tests/annotations/undo/ResizeCommandTest.cpp000066400000000000000000000103661414424500400253560ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ResizeCommandTest.h" void ResizeCommandTest::TestRedo_Should_MoveProvidedHandleToNewPosition() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line(10, 10, 20, 20); auto item = new AnnotationLine(line.p1(), properties); item->addPoint(line.p2(), false); QPointF newPosition(50, 50); ResizeCommand resize(item, 1, newPosition, false); QCOMPARE(item->line().p2(), line.p2()); resize.redo(); QCOMPARE(item->line().p2(), newPosition); } void ResizeCommandTest::TestUndo_Should_MoveProvidedHandleToInitialPosition() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line(10, 10, 20, 20); auto item = new AnnotationLine(line.p1(), properties); item->addPoint(line.p2(), false); QPointF newPosition(50, 50); ResizeCommand resize(item, 1, newPosition, false); resize.redo(); QCOMPARE(item->line().p2(), newPosition); resize.undo(); QCOMPARE(item->line().p2(), line.p2()); } void ResizeCommandTest::TestMergeWith_Should_TakeNewHandlePositionFromLastResizeCommand() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line(10, 10, 20, 20); auto item = new AnnotationLine(line.p1(), properties); item->addPoint(line.p2(), false); QPointF newPosition1(50, 50); QPointF newPosition2(60, 60); ResizeCommand resize1(item, 1, newPosition1, false); ResizeCommand resize2(item, 1, newPosition2, false); QCOMPARE(item->line().p2(), line.p2()); resize1.mergeWith(&resize2); resize1.redo(); QCOMPARE(item->line().p2(), newPosition2); } void ResizeCommandTest::TestMergeWith_Should_KeepInitialPositionFromFirstResizeCommand() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line(10, 10, 20, 20); auto item = new AnnotationLine(line.p1(), properties); item->addPoint(line.p2(), false); QPointF newPosition1(50, 50); QPointF newPosition2(60, 60); ResizeCommand resize1(item, 1, newPosition1, false); ResizeCommand resize2(item, 1, newPosition2, false); resize1.mergeWith(&resize2); resize1.redo(); QCOMPARE(item->line().p2(), newPosition2); resize1.undo(); QCOMPARE(item->line().p2(), line.p2()); } void ResizeCommandTest::TestMergeWith_Should_NotMergeResizeCommands_When_ItemsAreNotTheSame() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line1(10, 10, 20, 20); QLineF line2(15, 15, 25, 25); auto item1 = new AnnotationLine(line1.p1(), properties); auto item2 = new AnnotationLine(line2.p1(), properties); item1->addPoint(line1.p2(), false); item2->addPoint(line2.p2(), false); QPointF newPosition1(50, 50); QPointF newPosition2(60, 60); ResizeCommand resize1(item1, 1, newPosition1, false); ResizeCommand resize2(item2, 1, newPosition2, false); QCOMPARE(item1->line().p2(), line1.p2()); resize1.mergeWith(&resize2); resize1.redo(); QCOMPARE(item1->line().p2(), newPosition1); } void ResizeCommandTest::TestMergeWith_Should_NotMergeResizeCommands_When_HandlesAreNotTheSame() { auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); QLineF line1(10, 10, 20, 20); auto item1 = new AnnotationLine(line1.p1(), properties); item1->addPoint(line1.p2(), false); QPointF newPosition1(50, 50); QPointF newPosition2(60, 60); ResizeCommand resize1(item1, 1, newPosition1, false); ResizeCommand resize2(item1, 3, newPosition2, false); QCOMPARE(item1->line().p2(), line1.p2()); resize1.mergeWith(&resize2); resize1.redo(); QCOMPARE(item1->line().p2(), newPosition1); } QTEST_MAIN(ResizeCommandTest); kImageAnnotator-0.5.3/tests/annotations/undo/ResizeCommandTest.h000066400000000000000000000033361414424500400250220ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_RESIZECOMMANDTEST_H #define KIMAGEANNOTATOR_RESIZECOMMANDTEST_H #include #include "src/annotations/undo/ResizeCommand.h" #include "src/annotations/items/AnnotationLine.h" using kImageAnnotator::ResizeCommand; using kImageAnnotator::AnnotationLine; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::AbstractAnnotationItem; using kImageAnnotator::PropertiesPtr; class ResizeCommandTest : public QObject { Q_OBJECT private slots: void TestRedo_Should_MoveProvidedHandleToNewPosition(); void TestUndo_Should_MoveProvidedHandleToInitialPosition(); void TestMergeWith_Should_TakeNewHandlePositionFromLastResizeCommand(); void TestMergeWith_Should_KeepInitialPositionFromFirstResizeCommand(); void TestMergeWith_Should_NotMergeResizeCommands_When_ItemsAreNotTheSame(); void TestMergeWith_Should_NotMergeResizeCommands_When_HandlesAreNotTheSame(); }; #endif // KIMAGEANNOTATOR_RESIZECOMMANDTEST_H kImageAnnotator-0.5.3/tests/annotations/undo/RotateCommandTest.cpp000066400000000000000000000064261414424500400253550ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "RotateCommandTest.h" #include "tests/mocks/MockDefaultParameters.h" void RotateCommandTest::Redo_Should_RotatePixmapByProvidedAngel() { // arrange auto oldSize = QSizeF(100, 50); auto newSize = QSizeF(50, 100); auto angel = 90; QPixmap pixmap(oldSize.toSize()); QGraphicsPixmapItem image(pixmap); MockDefaultParameters defaultParameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(&defaultParameters.config, &defaultParameters.settingsProvider, scalerMock, &defaultParameters.zoomValueProvider, nullptr); RotateCommand rotateCommand(&image, angel, &annotationArea); // act rotateCommand.redo(); // assert QCOMPARE(image.boundingRect().size(), newSize); QCOMPARE(annotationArea.sceneRect().size(), newSize); } void RotateCommandTest::Redo_Should_TrimPixmapAndRemoveTransparentPart_WhenRotatedBy45DegreeTwice() { // arrange auto oldSize = QSizeF(100, 50); auto newSize = QSizeF(50, 100) + QSize(3, 3); // Rotating by non 90° multipliers creates fuzzy edges due to antialiasing. auto angel = 45; QPixmap pixmap(oldSize.toSize()); pixmap.fill(Qt::green); QGraphicsPixmapItem image(pixmap); MockDefaultParameters defaultParameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(&defaultParameters.config, &defaultParameters.settingsProvider, scalerMock, &defaultParameters.zoomValueProvider, nullptr); RotateCommand rotate1Command(&image, angel, &annotationArea); rotate1Command.redo(); RotateCommand rotate2Command(&image, angel, &annotationArea); // act rotate2Command.redo(); // assert QCOMPARE(image.boundingRect().size(), newSize); QCOMPARE(annotationArea.sceneRect().size(), newSize); } void RotateCommandTest::Undo_Should_RevertBackToInitialImage() { // arrange auto oldSize = QSizeF(100, 50); auto angel = 90; QPixmap pixmap(oldSize.toSize()); QGraphicsPixmapItem image(pixmap); MockDefaultParameters defaultParameters; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(&defaultParameters.config, &defaultParameters.settingsProvider, scalerMock, &defaultParameters.zoomValueProvider, nullptr); RotateCommand rotateCommand(&image, angel, &annotationArea); rotateCommand.redo(); QVERIFY(image.pixmap().toImage() != pixmap.toImage()); // act rotateCommand.undo(); // assert QCOMPARE(image.pixmap().toImage(), pixmap.toImage()); QCOMPARE(image.boundingRect().size(), oldSize); QCOMPARE(annotationArea.sceneRect().size(), oldSize); } QTEST_MAIN(RotateCommandTest) kImageAnnotator-0.5.3/tests/annotations/undo/RotateCommandTest.h000066400000000000000000000026321414424500400250150ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ROTATECOMMANDTEST_H #define KIMAGEANNOTATOR_ROTATECOMMANDTEST_H #include #include "src/annotations/undo/RotateCommand.h" #include "tests/mocks/MockSettingsProvider.h" #include "tests/mocks/MockDevicePixelRatioScaler.h" using kImageAnnotator::RotateCommand; using kImageAnnotator::AnnotationArea; class RotateCommandTest : public QObject { Q_OBJECT private slots: void Redo_Should_RotatePixmapByProvidedAngel(); void Redo_Should_TrimPixmapAndRemoveTransparentPart_WhenRotatedBy45DegreeTwice(); void Undo_Should_RevertBackToInitialImage(); }; #endif //KIMAGEANNOTATOR_ROTATECOMMANDTEST_H kImageAnnotator-0.5.3/tests/annotations/undo/ScaleCommandTest.cpp000066400000000000000000000073301414424500400251410ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ScaleCommandTest.h" #include "tests/mocks/MockDefaultParameters.h" void ScaleCommandTest::TestRedo_Should_ScaleImageToNewSize() { // arrange auto oldSize = QSize(500, 500); auto newSize = QSize(250, 250); QPixmap pixmap(oldSize); QGraphicsPixmapItem image(pixmap); MockDefaultParameters p; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(&p.config, &p.settingsProvider, scalerMock, &p.zoomValueProvider, nullptr); ScaleCommand scaleCommand(&image, newSize, &annotationArea); // act scaleCommand.redo(); // assert QCOMPARE(image.boundingRect().size().toSize(), newSize); } void ScaleCommandTest::TestUndo_Should_ScaleImageBackToOldSize() { // arrange auto oldSize = QSize(500, 500); auto newSize = QSize(250, 250); QPixmap pixmap(oldSize); QGraphicsPixmapItem image(pixmap); MockDefaultParameters p; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(&p.config, &p.settingsProvider, scalerMock, &p.zoomValueProvider, nullptr); ScaleCommand scaleCommand(&image, newSize, &annotationArea); scaleCommand.redo(); QCOMPARE(image.boundingRect().size().toSize(), newSize); // act scaleCommand.undo(); // assert QCOMPARE(image.boundingRect().size().toSize(), oldSize); } void ScaleCommandTest::TestRedo_Should_ScaleItemsBySameFactorAsImage() { // arrange auto oldSize = QSize(500, 500); auto newSize = QSize(250, 250); QPixmap pixmap(oldSize); QGraphicsPixmapItem image(pixmap); MockDefaultParameters p; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(&p.config, &p.settingsProvider, scalerMock, &p.zoomValueProvider, nullptr); auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto rectItem = new AnnotationRect(QPointF(0, 0), properties); rectItem->addPoint(QPointF(50, 50), false); annotationArea.addAnnotationItem(rectItem); ScaleCommand scaleCommand(&image, newSize, &annotationArea); // act scaleCommand.redo(); // assert QCOMPARE(rectItem->boundingRect().size().toSize(), QSize(25, 25)); } void ScaleCommandTest::TestUndo_Should_ScaleItemsBackToOriginalSize() { // arrange auto oldSize = QSize(500, 500); auto newSize = QSize(250, 250); QPixmap pixmap(oldSize); QGraphicsPixmapItem image(pixmap); MockDefaultParameters p; auto scalerMock = new MockDevicePixelRatioScaler(); AnnotationArea annotationArea(&p.config, &p.settingsProvider, scalerMock, &p.zoomValueProvider, nullptr); auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1)); auto rectItem = new AnnotationRect(QPointF(0, 0), properties); rectItem->addPoint(QPointF(50, 50), false); annotationArea.addAnnotationItem(rectItem); ScaleCommand scaleCommand(&image, newSize, &annotationArea); scaleCommand.redo(); QCOMPARE(rectItem->boundingRect().size().toSize(), QSize(25, 25)); // act scaleCommand.undo(); // assert QCOMPARE(rectItem->boundingRect().size().toSize(), QSize(50, 50)); } QTEST_MAIN(ScaleCommandTest) kImageAnnotator-0.5.3/tests/annotations/undo/ScaleCommandTest.h000066400000000000000000000031061414424500400246030ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SCALECOMMANDTEST_H #define KIMAGEANNOTATOR_SCALECOMMANDTEST_H #include #include "src/annotations/undo/ScaleCommand.h" #include "tests/mocks/MockSettingsProvider.h" #include "tests/mocks/MockDevicePixelRatioScaler.h" using kImageAnnotator::ScaleCommand; using kImageAnnotator::AnnotationArea; using kImageAnnotator::Config; using kImageAnnotator::AnnotationRect; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::PropertiesPtr; class ScaleCommandTest : public QObject { Q_OBJECT private slots: void TestRedo_Should_ScaleImageToNewSize(); void TestUndo_Should_ScaleImageBackToOldSize(); void TestRedo_Should_ScaleItemsBySameFactorAsImage(); void TestUndo_Should_ScaleItemsBackToOriginalSize(); }; #endif // KIMAGEANNOTATOR_SCALECOMMANDTEST_H kImageAnnotator-0.5.3/tests/backend/000077500000000000000000000000001414424500400173315ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/backend/ConfigTest.cpp000066400000000000000000000040651414424500400221070ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ConfigTest.h" void ConfigTest::initTestCase() { QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QStringLiteral("/tmp")); } void ConfigTest::cleanupTestCase() { QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QStringLiteral("$HOME/.config")); } void ConfigTest::TestSetSelectedTool_Should_NotSaveSelection_When_SaveToolSelectionDisabled() { qRegisterMetaType("ToolTypes"); auto defaultTool = Tools::Pen; QSettings settings; settings.remove(ConfigNameHelper::toolType()); auto config = new Config; config->setSaveToolSelection(false); config->setSelectedToolType(Tools::Ellipse); auto saveTool = settings.value(ConfigNameHelper::toolType(), static_cast(defaultTool)).value(); QCOMPARE(saveTool, defaultTool); } void ConfigTest::TestSetSelectedTool_Should_SaveSelection_When_SaveToolSelectionEnabled() { qRegisterMetaType("ToolTypes"); auto defaultTool = Tools::Pen; auto selectedTool = Tools::Ellipse; QSettings settings; auto config = new Config; config->setSaveToolSelection(true); config->setSelectedToolType(selectedTool); auto saveTool = settings.value(ConfigNameHelper::toolType(), static_cast(defaultTool)).value(); QCOMPARE(saveTool, selectedTool); } QTEST_MAIN(ConfigTest); kImageAnnotator-0.5.3/tests/backend/ConfigTest.h000066400000000000000000000026001414424500400215450ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CONFIGTEST_H #define KIMAGEANNOTATOR_CONFIGTEST_H #include #include #include "src/backend/Config.h" #include "src/common/enum/Tools.h" using kImageAnnotator::Config; using kImageAnnotator::ConfigNameHelper; using kImageAnnotator::Tools; class ConfigTest : public QObject { Q_OBJECT private slots: void initTestCase(); void cleanupTestCase(); void TestSetSelectedTool_Should_NotSaveSelection_When_SaveToolSelectionDisabled(); void TestSetSelectedTool_Should_SaveSelection_When_SaveToolSelectionEnabled(); }; #endif // KIMAGEANNOTATOR_CONFIGTEST_H kImageAnnotator-0.5.3/tests/common/000077500000000000000000000000001414424500400172325ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/common/helper/000077500000000000000000000000001414424500400205115ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/common/helper/ItemHelperTest.cpp000066400000000000000000000061221414424500400241140ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ItemHelperTest.h" void ItemHelperTest::TestZValueGreaterThen_Should_ReturnTrue_When_OtherItemHasLowerZValue() { QPointF pos(10, 10); AnnotationLine item1(pos, PropertiesPtr(new AnnotationProperties(Qt::red, 1))); AnnotationLine item2(pos, PropertiesPtr(new AnnotationProperties(Qt::red, 1))); item1.setZValue(100); item2.setZValue(50); auto result = ItemHelper::zValueGreaterThen(&item1, &item2); QCOMPARE(result, true); } void ItemHelperTest::TestZValueGreaterThen_Should_ReturnFalse_When_OtherItemHasHigherZValue() { QPointF pos(10, 10); AnnotationLine item1(pos, PropertiesPtr(new AnnotationProperties(Qt::red, 1))); AnnotationLine item2(pos, PropertiesPtr(new AnnotationProperties(Qt::red, 1))); item1.setZValue(50); item2.setZValue(100); auto result = ItemHelper::zValueGreaterThen(&item1, &item2); QCOMPARE(result, false); } void ItemHelperTest::TestZValueGreaterThen_Should_ReturnFalse_When_OtherItemHasEqualZValue() { QPointF pos(10, 10); AnnotationLine item1(pos, PropertiesPtr(new AnnotationProperties(Qt::red, 1))); AnnotationLine item2(pos, PropertiesPtr(new AnnotationProperties(Qt::red, 1))); item1.setZValue(100); item2.setZValue(100); auto result = ItemHelper::zValueGreaterThen(&item1, &item2); QCOMPARE(result, false); } void ItemHelperTest::TestSortItemsByZValueDesc_Should_SortItemsByZValueInDescendingOrder() { QPointF pos(10, 10); AnnotationLine item1(pos, PropertiesPtr(new AnnotationProperties(Qt::red, 1))); AnnotationLine item2(pos, PropertiesPtr(new AnnotationProperties(Qt::red, 1))); AnnotationLine item3(pos, PropertiesPtr(new AnnotationProperties(Qt::red, 1))); AnnotationLine item4(pos, PropertiesPtr(new AnnotationProperties(Qt::red, 1))); AnnotationLine item5(pos, PropertiesPtr(new AnnotationProperties(Qt::red, 1))); item1.setZValue(100); item2.setZValue(80); item3.setZValue(2); item4.setZValue(60); item5.setZValue(90); QList items; items.append(&item3); items.append(&item1); items.append(&item4); items.append(&item5); items.append(&item2); ItemHelper::sortItemsByZValueDesc(&items); QCOMPARE((int) items[0]->zValue(), 100); QCOMPARE((int) items[1]->zValue(), 90); QCOMPARE((int) items[2]->zValue(), 80); QCOMPARE((int) items[3]->zValue(), 60); QCOMPARE((int) items[4]->zValue(), 2); } QTEST_MAIN(ItemHelperTest); kImageAnnotator-0.5.3/tests/common/helper/ItemHelperTest.h000066400000000000000000000031401414424500400235560ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ITEMHELPERTEST_H #define KIMAGEANNOTATOR_ITEMHELPERTEST_H #include #include "src/annotations/items/AnnotationLine.h" #include "src/common/helper/ItemHelper.h" using kImageAnnotator::ItemHelper; using kImageAnnotator::AnnotationProperties; using kImageAnnotator::AnnotationLine; using kImageAnnotator::AbstractAnnotationItem; using kImageAnnotator::PropertiesPtr; class ItemHelperTest : public QObject { Q_OBJECT private slots: void TestZValueGreaterThen_Should_ReturnTrue_When_OtherItemHasLowerZValue(); void TestZValueGreaterThen_Should_ReturnFalse_When_OtherItemHasHigherZValue(); void TestZValueGreaterThen_Should_ReturnFalse_When_OtherItemHasEqualZValue(); void TestSortItemsByZValueDesc_Should_SortItemsByZValueInDescendingOrder(); }; #endif // KIMAGEANNOTATOR_ITEMHELPERTEST_H kImageAnnotator-0.5.3/tests/common/helper/KeyHelperTest.cpp000066400000000000000000000111671414424500400237530ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KeyHelperTest.h" void KeyHelperTest::TestKeyPress_Should_EmitUndoSignal_When_ControlAndZKeyArePressed() { QKeyEvent pressCtrlKeyEvent(QEvent::KeyPress, Qt::Key_Control, Qt::NoModifier); QKeyEvent pressZKeyEvent(QEvent::KeyPress, Qt::Key_Z, Qt::NoModifier); KeyHelper keyHelper; QSignalSpy spy(&keyHelper, &KeyHelper::undoPressed); keyHelper.keyPress(&pressCtrlKeyEvent); keyHelper.keyPress(&pressZKeyEvent); QCOMPARE(spy.count(), 1); } void KeyHelperTest::TestKeyPress_Should_EmitRedoSignal_When_ControlAndShiftAndZKeyArePressed() { QKeyEvent pressCtrlKeyEvent(QEvent::KeyPress, Qt::Key_Control, Qt::NoModifier); QKeyEvent pressShiftKeyEvent(QEvent::KeyPress, Qt::Key_Shift, Qt::NoModifier); QKeyEvent pressZKeyEvent(QEvent::KeyPress, Qt::Key_Z, Qt::NoModifier); KeyHelper keyHelper; QSignalSpy spy(&keyHelper, &KeyHelper::redoPressed); keyHelper.keyPress(&pressCtrlKeyEvent); keyHelper.keyPress(&pressShiftKeyEvent); keyHelper.keyPress(&pressZKeyEvent); QCOMPARE(spy.count(), 1); } void KeyHelperTest::TestKeyRelease_Should_EmitSignal_When_DeleteKeyReleased() { QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_Delete, Qt::NoModifier); KeyHelper keyHelper; QSignalSpy spy(&keyHelper, &KeyHelper::deleteReleased); keyHelper.keyRelease(&keyEvent); QCOMPARE(spy.count(), 1); } void KeyHelperTest::TestKeyRelease_Should_EmitSignal_When_EscapeKeyReleased() { QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_Escape, Qt::NoModifier); KeyHelper keyHelper; QSignalSpy spy(&keyHelper, &KeyHelper::escapeReleased); keyHelper.keyRelease(&keyEvent); QCOMPARE(spy.count(), 1); } void KeyHelperTest::TestIsControlPressed_ShouldReturnTrue_When_ControlWasPressed() { QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Control, Qt::NoModifier); KeyHelper keyHelper; QCOMPARE(keyHelper.isControlPressed(), false); keyHelper.keyPress(&keyEvent); QCOMPARE(keyHelper.isControlPressed(), true); } void KeyHelperTest::TestIsControlPressed_ShouldReturnFalse_When_ControlWasReleased() { QKeyEvent keyPressEvent(QEvent::KeyPress, Qt::Key_Control, Qt::NoModifier); QKeyEvent keyReleaseEvent(QEvent::KeyRelease, Qt::Key_Control, Qt::NoModifier); KeyHelper keyHelper; keyHelper.keyPress(&keyPressEvent); QCOMPARE(keyHelper.isControlPressed(), true); keyHelper.keyRelease(&keyReleaseEvent); QCOMPARE(keyHelper.isControlPressed(), false); } void KeyHelperTest::TestIsShiftPressed_Should_ReturnTrue_When_ShiftWasPressed() { QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Shift, Qt::NoModifier); KeyHelper keyHelper; QCOMPARE(keyHelper.isShiftPressed(), false); keyHelper.keyPress(&keyEvent); QCOMPARE(keyHelper.isShiftPressed(), true); } void KeyHelperTest::TestIsShiftPressed_Should_ReturnFalse_When_ShiftWasReleased() { QKeyEvent keyPressEvent(QEvent::KeyPress, Qt::Key_Shift, Qt::NoModifier); QKeyEvent keyReleaseEvent(QEvent::KeyRelease, Qt::Key_Shift, Qt::NoModifier); KeyHelper keyHelper; keyHelper.keyPress(&keyPressEvent); QCOMPARE(keyHelper.isShiftPressed(), true); keyHelper.keyRelease(&keyReleaseEvent); QCOMPARE(keyHelper.isShiftPressed(), false); } void KeyHelperTest::TestKeyReleased_Should_EmitReturnReleased_When_ReturnWasReleased() { QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_Return, Qt::NoModifier); KeyHelper keyHelper; QSignalSpy spy(&keyHelper, &KeyHelper::returnReleased); keyHelper.keyRelease(&keyEvent); QCOMPARE(spy.count(), 1); } void KeyHelperTest::TestKeyReleased_Should_EmitEnterReleased_When_EnterWasReleased() { QKeyEvent keyEvent(QEvent::KeyRelease, Qt::Key_Enter, Qt::NoModifier); KeyHelper keyHelper; QSignalSpy spy(&keyHelper, &KeyHelper::enterReleased); keyHelper.keyRelease(&keyEvent); QCOMPARE(spy.count(), 1); } QTEST_MAIN(KeyHelperTest); kImageAnnotator-0.5.3/tests/common/helper/KeyHelperTest.h000066400000000000000000000034421414424500400234150ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_KEYHELPERTEST_H #define KIMAGEANNOTATOR_KEYHELPERTEST_H #include #include #include "src/common/helper/KeyHelper.h" using kImageAnnotator::KeyHelper; class KeyHelperTest : public QObject { Q_OBJECT private slots: void TestKeyPress_Should_EmitUndoSignal_When_ControlAndZKeyArePressed(); void TestKeyPress_Should_EmitRedoSignal_When_ControlAndShiftAndZKeyArePressed(); void TestKeyRelease_Should_EmitSignal_When_DeleteKeyReleased(); void TestKeyRelease_Should_EmitSignal_When_EscapeKeyReleased(); void TestIsControlPressed_ShouldReturnTrue_When_ControlWasPressed(); void TestIsControlPressed_ShouldReturnFalse_When_ControlWasReleased(); void TestIsShiftPressed_Should_ReturnTrue_When_ShiftWasPressed(); void TestIsShiftPressed_Should_ReturnFalse_When_ShiftWasReleased(); void TestKeyReleased_Should_EmitReturnReleased_When_ReturnWasReleased(); void TestKeyReleased_Should_EmitEnterReleased_When_EnterWasReleased(); }; #endif // KIMAGEANNOTATOR_KEYHELPERTEST_H kImageAnnotator-0.5.3/tests/common/helper/MathHelperTest.cpp000066400000000000000000000061531414424500400241130ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "MathHelperTest.h" void MathHelperTest::TestRoundAngleTo_Should_ReturnAngleRoundedUpToIncrement() { QFETCH(qreal, angle); QFETCH(qreal, increment); QFETCH(qreal, result); auto newAngle = MathHelper::roundAngleTo(angle, increment); QCOMPARE(newAngle, result); } void MathHelperTest::TestRoundAngleTo_Should_ReturnAngleRoundedUpToIncrement_data() { QTest::addColumn("angle"); QTest::addColumn("increment"); QTest::addColumn("result"); QTest::newRow("set1") << 50.0 << 45.0 << 45.0; QTest::newRow("set2") << 87.0 << 45.0 << 90.0; QTest::newRow("set3") << 0.0 << 45.0 << 0.0; QTest::newRow("set4") << 355.0 << 45.0 << 360.0; QTest::newRow("set5") << 360.0 << 45.0 << 360.0; QTest::newRow("set6") << -2.0 << 45.0 << 0.0; } void MathHelperTest::TestSmallerValue_Should_AlwaysSmallerOfTwoValues() { QFETCH(qreal, width); QFETCH(qreal, height); QFETCH(qreal, result); auto smallest = MathHelper::smallerValue(width, height); QCOMPARE(smallest, result); } void MathHelperTest::TestSmallerValue_Should_AlwaysSmallerOfTwoValues_data() { QTest::addColumn("width"); QTest::addColumn("height"); QTest::addColumn("result"); QTest::newRow("set1") << 50.0 << 49.0 << 49.0; QTest::newRow("set2") << -87.0 << 1.0 << -1.0; QTest::newRow("set3") << 0.0 << -1.0 << 0.0; QTest::newRow("set4") << 400.0 << -500.0 << 400.0; QTest::newRow("set5") << -3.0 << 2.0 << -2.0; QTest::newRow("set6") << -2.0 << 2.0 << -2.0; } void MathHelperTest::TestDistanceBetweenPoints_Should_ReturnCorrectDistance() { QFETCH(QPointF, point1); QFETCH(QPointF, point2); QFETCH(double, expected); auto result = MathHelper::distanceBetweenPoints(point1, point2); QCOMPARE(result, expected); } void MathHelperTest::TestDistanceBetweenPoints_Should_ReturnCorrectDistance_data() { QTest::addColumn("point1"); QTest::addColumn("point2"); QTest::addColumn("expected"); QTest::newRow("set1") << QPointF(10, 10) << QPointF(20, 10) << 10.0; QTest::newRow("set2") << QPointF(10, 10) << QPointF(10, 20) << 10.0; QTest::newRow("set3") << QPointF(-10, 10) << QPointF(10, 10) << 20.0; QTest::newRow("set4") << QPointF(-4, -3) << QPointF(8, 6) << 15.0; } QTEST_MAIN(MathHelperTest); kImageAnnotator-0.5.3/tests/common/helper/MathHelperTest.h000066400000000000000000000027441414424500400235620ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_MATHHELPERTEST_H #define KIMAGEANNOTATOR_MATHHELPERTEST_H #include #include "src/common/helper/MathHelper.h" using kImageAnnotator::MathHelper; class MathHelperTest : public QObject { Q_OBJECT private slots: void TestRoundAngleTo_Should_ReturnAngleRoundedUpToIncrement(); void TestRoundAngleTo_Should_ReturnAngleRoundedUpToIncrement_data(); void TestSmallerValue_Should_AlwaysSmallerOfTwoValues(); void TestSmallerValue_Should_AlwaysSmallerOfTwoValues_data(); void TestDistanceBetweenPoints_Should_ReturnCorrectDistance(); void TestDistanceBetweenPoints_Should_ReturnCorrectDistance_data(); }; #endif // KIMAGEANNOTATOR_MATHHELPERTEST_H kImageAnnotator-0.5.3/tests/common/helper/PathHelperTest.cpp000066400000000000000000000047401414424500400241160ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "PathHelperTest.h" void PathHelperTest::TestExtractFilename_Should_ReturnOnlyFilename_When_FilenameHasFormat() { auto expected = QStringLiteral("myFile"); auto filename = PathHelper::extractFilename(QStringLiteral("/home/kimageannotator/") + expected + QStringLiteral(".png")); QCOMPARE(filename, expected); } void PathHelperTest::TestExtractFilename_Should_ReturnOnlyFilename_When_FilenameHasNoFormat() { auto expected = QStringLiteral("myFile"); auto filename = PathHelper::extractFilename(QStringLiteral("/home/kimageannotator/") + expected); QCOMPARE(filename, expected); } void PathHelperTest::TestExtractFilename_Should_ReturnOnlyFilename_When_FilenameWithoutPathWasProvided() { auto expected = QStringLiteral("myFile"); auto filename = PathHelper::extractFilename(expected); QCOMPARE(filename, expected); } void PathHelperTest::TestExtractFilenameWithFormat_Should_ReturnOnlyFilename_When_FilenameHasFormat() { auto expected = QStringLiteral("myFile.png"); auto filename = PathHelper::extractFilenameWithFormat(QStringLiteral("/home/kimageannotator/") + expected); QCOMPARE(filename, expected); } void PathHelperTest::TestExtractFilenameWithFormat_Should_ReturnOnlyFilename_When_FilenameWithoutPathWasProvided() { auto expected = QStringLiteral("myFile.png"); auto filename = PathHelper::extractFilenameWithFormat(expected); QCOMPARE(filename, expected); } void PathHelperTest::TestPrettyFilename_Should_ReplaceUnderscoresWithSpacesAndCapitalizeFirstLetters() { auto input = QStringLiteral("my_test_File.png"); auto expected = QStringLiteral("My Test File.png"); auto filename = PathHelper::prettyFilename(input); QCOMPARE(filename, expected); } QTEST_MAIN(PathHelperTest); kImageAnnotator-0.5.3/tests/common/helper/PathHelperTest.h000066400000000000000000000031311414424500400235540ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_PATHHELPERTEST_H #define KIMAGEANNOTATOR_PATHHELPERTEST_H #include #include "src/common/helper/PathHelper.h" using kImageAnnotator::PathHelper; class PathHelperTest : public QObject { Q_OBJECT private slots: void TestExtractFilename_Should_ReturnOnlyFilename_When_FilenameHasFormat(); void TestExtractFilename_Should_ReturnOnlyFilename_When_FilenameHasNoFormat(); void TestExtractFilename_Should_ReturnOnlyFilename_When_FilenameWithoutPathWasProvided(); void TestExtractFilenameWithFormat_Should_ReturnOnlyFilename_When_FilenameHasFormat(); void TestExtractFilenameWithFormat_Should_ReturnOnlyFilename_When_FilenameWithoutPathWasProvided(); void TestPrettyFilename_Should_ReplaceUnderscoresWithSpacesAndCapitalizeFirstLetters(); }; #endif //KIMAGEANNOTATOR_PATHHELPERTEST_H kImageAnnotator-0.5.3/tests/common/helper/ShapeHelperTest.cpp000066400000000000000000000263131414424500400242620ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ShapeHelperTest.h" void ShapeHelperTest::TestRectTop_Should_ReturnPointAtTopCentered() { QRectF rect(10, 10, 50, 50); auto top = ShapeHelper::rectTop(rect); QCOMPARE(top, QPointF(rect.center().x(), rect.top())); } void ShapeHelperTest::TestRectRight_Should_ReturnPointAtRightCentered() { QRectF rect(10, 10, 50, 50); auto right = ShapeHelper::rectRight(rect); QCOMPARE(right, QPointF(rect.right(), rect.center().y())); } void ShapeHelperTest::TestRectLeft_Should_ReturnPointAtLeftCentered() { QRectF rect(10, 10, 50, 50); auto left = ShapeHelper::rectLeft(rect); QCOMPARE(left, QPointF(rect.left(), rect.center().y())); } void ShapeHelperTest::TestRectBottom_Should_ReturnPointAtBottomCentered() { QRectF rect(10, 10, 50, 50); auto bottom = ShapeHelper::rectBottom(rect); QCOMPARE(bottom, QPointF(rect.center().x(), rect.bottom())); } void ShapeHelperTest::TestRectTopWithOffset_Should_ReturnPointAtTopWithAddedOffset_When_TopSmallerThenBottom() { QRectF rect(10, 10, 50, 50); rect.setTop(rect.bottom() + 20); auto offset = 5; auto top = ShapeHelper::rectTopWithOffset(rect, offset); QCOMPARE(top, QPointF(rect.center().x(), rect.top() + offset)); } void ShapeHelperTest::TestRectTopWithOffset_Should_ReturnPointAtTopWithSubtractedOffset_When_TopLargerThenBottom() { QRectF rect(10, 10, 50, 50); auto offset = 5; auto top = ShapeHelper::rectTopWithOffset(rect, offset); QCOMPARE(top, QPointF(rect.center().x(), rect.top() - offset)); } void ShapeHelperTest::TestRectRightWithOffset_Should_ReturnPointAtRightWithSubtracedOffset_When_RightSmallerThenLeft() { QRectF rect(10, 10, 50, 50); rect.setRight(rect.left() - 20); auto offset = 5; auto right = ShapeHelper::rectRightWithOffset(rect, offset); QCOMPARE(right, QPointF(rect.right() - offset, rect.center().y())); } void ShapeHelperTest::TestRectRightWithOffset_Should_ReturnPointAtRightWithAddedOffset_When_RightLargerThenLeft() { QRectF rect(10, 10, 50, 50); auto offset = 5; auto right = ShapeHelper::rectRightWithOffset(rect, offset); QCOMPARE(right, QPointF(rect.right() + offset, rect.center().y())); } void ShapeHelperTest::TestRectBottomWithOffset_Should_ReturnPointAtBottomWithSubtracedOffset_When_BottomSmallerThenTop() { QRectF rect(10, 10, 50, 50); rect.setBottom(rect.top() - 20); auto offset = 5; auto bottom = ShapeHelper::rectBottomWithOffset(rect, offset); QCOMPARE(bottom, QPointF(rect.center().x(), rect.bottom() - offset)); } void ShapeHelperTest::TestRectBottomWithOffset_Should_ReturnPointAtBottomWithAddedOffset_When_BottomLargerThenTop() { QRectF rect(10, 10, 50, 50); auto offset = 5; auto bottom = ShapeHelper::rectBottomWithOffset(rect, offset); QCOMPARE(bottom, QPointF(rect.center().x(), rect.bottom() + offset)); } void ShapeHelperTest::TestRectLeftWithOffset_Should_ReturnPointAtLeftWithAddedOffset_When_LeftSmallerThenRight() { QRectF rect(10, 10, 50, 50); rect.setLeft(rect.right() + 20); auto offset = 5; auto left = ShapeHelper::rectLeftWithOffset(rect, offset); QCOMPARE(left, QPointF(rect.left() + offset, rect.center().y())); } void ShapeHelperTest::TestRectLeftWithOffset_Should_ReturnPointAtLeftWithSubtracedOffset_When_LeftLargerThenRight() { QRectF rect(10, 10, 50, 50); auto offset = 5; auto left = ShapeHelper::rectLeftWithOffset(rect, offset); QCOMPARE(left, QPointF(rect.left() - offset, rect.center().y())); } void ShapeHelperTest::TestRectTopLeftWithOffset_Should_ReturnPointWithCorrectOffset() { QFETCH(int, addToRight); QFETCH(int, addToBottom); QFETCH(int, expectedOffsetX); QFETCH(int, expectedOffsetY); QRectF rect(10, 10, 50, 50); rect.setRight(rect.left() + addToRight); rect.setBottom(rect.top() + addToBottom); auto offset = 5; auto topLeft = ShapeHelper::rectTopLeftWithOffset(rect, offset); QCOMPARE(topLeft, QPointF(rect.topLeft().x() + expectedOffsetX, rect.topLeft().y() + expectedOffsetY)); } void ShapeHelperTest::TestRectTopLeftWithOffset_Should_ReturnPointWithCorrectOffset_data() { QTest::addColumn("addToRight"); QTest::addColumn("addToBottom"); QTest::addColumn("expectedOffsetX"); QTest::addColumn("expectedOffsetY"); QTest::newRow("set1") << 10 << 10 << -5 << -5; QTest::newRow("set2") << -10 << 10 << 5 << -5; QTest::newRow("set3") << 10 << -10 << -5 << 5; QTest::newRow("set4") << -10 << -10 << 5 << 5; } void ShapeHelperTest::TestRectTopRightWithOffset_Should_ReturnPointWithCorrectOffset() { QFETCH(int, addToRight); QFETCH(int, addToBottom); QFETCH(int, expectedOffsetX); QFETCH(int, expectedOffsetY); QRectF rect(10, 10, 50, 50); rect.setRight(rect.left() + addToRight); rect.setBottom(rect.top() + addToBottom); auto offset = 5; auto topRight = ShapeHelper::rectTopRightWithOffset(rect, offset); QCOMPARE(topRight, QPointF(rect.topRight().x() + expectedOffsetX, rect.topRight().y() + expectedOffsetY)); } void ShapeHelperTest::TestRectTopRightWithOffset_Should_ReturnPointWithCorrectOffset_data() { QTest::addColumn("addToRight"); QTest::addColumn("addToBottom"); QTest::addColumn("expectedOffsetX"); QTest::addColumn("expectedOffsetY"); QTest::newRow("set1") << 10 << 10 << 5 << -5; QTest::newRow("set2") << -10 << 10 << -5 << -5; QTest::newRow("set3") << 10 << -10 << 5 << 5; QTest::newRow("set4") << -10 << -10 << -5 << 5; } void ShapeHelperTest::TestRectBottomLeftWithOffset_Should_ReturnPointWithCorrectOffset() { QFETCH(int, addToRight); QFETCH(int, addToBottom); QFETCH(int, expectedOffsetX); QFETCH(int, expectedOffsetY); QRectF rect(10, 10, 50, 50); rect.setRight(rect.left() + addToRight); rect.setBottom(rect.top() + addToBottom); auto offset = 5; auto bottomLeft = ShapeHelper::rectBottomLeftWithOffset(rect, offset); QCOMPARE(bottomLeft, QPointF(rect.bottomLeft().x() + expectedOffsetX, rect.bottomLeft().y() + expectedOffsetY)); } void ShapeHelperTest::TestRectBottomLeftWithOffset_Should_ReturnPointWithCorrectOffset_data() { QTest::addColumn("addToRight"); QTest::addColumn("addToBottom"); QTest::addColumn("expectedOffsetX"); QTest::addColumn("expectedOffsetY"); QTest::newRow("set1") << 10 << 10 << -5 << 5; QTest::newRow("set2") << -10 << 10 << 5 << 5; QTest::newRow("set3") << 10 << -10 << -5 << -5; QTest::newRow("set4") << -10 << -10 << 5 << -5; } void ShapeHelperTest::TestRectBottomRightWithOffset_Should_ReturnPointWithCorrectOffset() { QFETCH(int, addToRight); QFETCH(int, addToBottom); QFETCH(int, expectedOffsetX); QFETCH(int, expectedOffsetY); QRectF rect(10, 10, 50, 50); rect.setRight(rect.left() + addToRight); rect.setBottom(rect.top() + addToBottom); auto offset = 5; auto bottomRight = ShapeHelper::rectBottomRightWithOffset(rect, offset); QCOMPARE(bottomRight, QPointF(rect.bottomRight().x() + expectedOffsetX, rect.bottomRight().y() + expectedOffsetY)); } void ShapeHelperTest::TestRectBottomRightWithOffset_Should_ReturnPointWithCorrectOffset_data() { QTest::addColumn("addToRight"); QTest::addColumn("addToBottom"); QTest::addColumn("expectedOffsetX"); QTest::addColumn("expectedOffsetY"); QTest::newRow("set1") << 10 << 10 << 5 << 5; QTest::newRow("set2") << -10 << 10 << -5 << 5; QTest::newRow("set3") << 10 << -10 << 5 << -5; QTest::newRow("set4") << -10 << -10 << -5 << -5; } void ShapeHelperTest::TestExtendLine_Should_ReturnNewLineExtendBySizeWithSameAngle() { QLineF line(10, 10, 20, 20); auto extendBy = 12; auto result = ShapeHelper::extendLine(line, extendBy); QLineF lineExtendP1(line.p2(), line.p1()); lineExtendP1.setLength(line.length() + extendBy / 2); lineExtendP1.setLine(lineExtendP1.p2().x(), lineExtendP1.p2().y(), lineExtendP1.p1().x(), lineExtendP1.p1().y()); auto lineExtendP2 = line; lineExtendP2.setLength(line.length() + extendBy / 2); QCOMPARE(result.length(), line.length() + extendBy); QCOMPARE(result.angle(), line.angle()); QCOMPARE(result.p1(), lineExtendP1.p1()); QCOMPARE(result.p2(), lineExtendP2.p2()); } void ShapeHelperTest::TestRectPointAtIndex_Should_ReturnPointAtIndexPosition() { QFETCH(QRectF, rect); QFETCH(int, index); QFETCH(QPointF, expected); auto result = ShapeHelper::rectPointAtIndex(rect, index); QCOMPARE(result, expected); } void ShapeHelperTest::TestRectPointAtIndex_Should_ReturnPointAtIndexPosition_data() { QTest::addColumn("rect"); QTest::addColumn("index"); QTest::addColumn("expected"); QTest::newRow("set1") << QRectF(10, 10, 10, 10) << 0 << QPointF(10, 10); QTest::newRow("set2") << QRectF(10, 10, 10, 10) << 1 << QPointF(15, 10); QTest::newRow("set3") << QRectF(10, 10, 10, 10) << 2 << QPointF(20, 10); QTest::newRow("set4") << QRectF(10, 10, 10, 10) << 3 << QPointF(20, 15); QTest::newRow("set5") << QRectF(10, 10, 10, 10) << 4 << QPointF(20, 20); QTest::newRow("set6") << QRectF(10, 10, 10, 10) << 5 << QPointF(15, 20); QTest::newRow("set7") << QRectF(10, 10, 10, 10) << 6 << QPointF(10, 20); QTest::newRow("set8") << QRectF(10, 10, 10, 10) << 7 << QPointF(10, 15); } void ShapeHelperTest::TestSetRectPointAtIndex_Should_SetRectPointAtIndexToProvidedPoint() { QFETCH(QRectF, rectInitial); QFETCH(int, index); QFETCH(QPointF, point); QFETCH(QRectF, expected); auto result = ShapeHelper::setRectPointAtIndex(rectInitial, index, point); QCOMPARE(result, expected); } void ShapeHelperTest::TestSetRectPointAtIndex_Should_SetRectPointAtIndexToProvidedPoint_data() { QTest::addColumn("rectInitial"); QTest::addColumn("index"); QTest::addColumn("point"); QTest::addColumn("expected"); QTest::newRow("set1") << QRectF(10, 10, 10, 10) << 0 << QPointF(5, 5) << QRectF(5, 5, 15, 15); QTest::newRow("set2") << QRectF(10, 10, 10, 10) << 1 << QPointF(15, 5) << QRectF(10, 5, 10, 15); QTest::newRow("set3") << QRectF(10, 10, 10, 10) << 2 << QPointF(25, 5) << QRectF(10, 5, 15, 15); QTest::newRow("set4") << QRectF(10, 10, 10, 10) << 3 << QPointF(25, 15) << QRectF(10, 10, 15, 10); QTest::newRow("set5") << QRectF(10, 10, 10, 10) << 4 << QPointF(25, 25) << QRectF(10, 10, 15, 15); QTest::newRow("set6") << QRectF(10, 10, 10, 10) << 5 << QPointF(15, 25) << QRectF(10, 10, 10, 15); QTest::newRow("set7") << QRectF(10, 10, 10, 10) << 6 << QPointF(5, 25) << QRectF(5, 10, 15, 15); QTest::newRow("set8") << QRectF(10, 10, 10, 10) << 7 << QPointF(5, 15) << QRectF(5, 10, 15, 10); } void ShapeHelperTest::TestSmoothOut_Should_RetunSamePath_When_PathHasOnlyThreeElement() { QPainterPath path; path.moveTo(10, 10); path.lineTo(20, -10); path.lineTo(30, 10); auto result = ShapeHelper::smoothOut(path, 0); QCOMPARE(result, path); } QTEST_MAIN(ShapeHelperTest); kImageAnnotator-0.5.3/tests/common/helper/ShapeHelperTest.h000066400000000000000000000062561414424500400237330ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SHAPEHELPERTEST_H #define KIMAGEANNOTATOR_SHAPEHELPERTEST_H #include #include "src/common/helper/ShapeHelper.h" using kImageAnnotator::ShapeHelper; class ShapeHelperTest : public QObject { Q_OBJECT private slots: void TestRectTop_Should_ReturnPointAtTopCentered(); void TestRectRight_Should_ReturnPointAtRightCentered(); void TestRectLeft_Should_ReturnPointAtLeftCentered(); void TestRectBottom_Should_ReturnPointAtBottomCentered(); void TestRectTopWithOffset_Should_ReturnPointAtTopWithAddedOffset_When_TopSmallerThenBottom(); void TestRectTopWithOffset_Should_ReturnPointAtTopWithSubtractedOffset_When_TopLargerThenBottom(); void TestRectRightWithOffset_Should_ReturnPointAtRightWithSubtracedOffset_When_RightSmallerThenLeft(); void TestRectRightWithOffset_Should_ReturnPointAtRightWithAddedOffset_When_RightLargerThenLeft(); void TestRectBottomWithOffset_Should_ReturnPointAtBottomWithSubtracedOffset_When_BottomSmallerThenTop(); void TestRectBottomWithOffset_Should_ReturnPointAtBottomWithAddedOffset_When_BottomLargerThenTop(); void TestRectLeftWithOffset_Should_ReturnPointAtLeftWithAddedOffset_When_LeftSmallerThenRight(); void TestRectLeftWithOffset_Should_ReturnPointAtLeftWithSubtracedOffset_When_LeftLargerThenRight(); void TestRectTopLeftWithOffset_Should_ReturnPointWithCorrectOffset(); void TestRectTopLeftWithOffset_Should_ReturnPointWithCorrectOffset_data(); void TestRectTopRightWithOffset_Should_ReturnPointWithCorrectOffset(); void TestRectTopRightWithOffset_Should_ReturnPointWithCorrectOffset_data(); void TestRectBottomLeftWithOffset_Should_ReturnPointWithCorrectOffset(); void TestRectBottomLeftWithOffset_Should_ReturnPointWithCorrectOffset_data(); void TestRectBottomRightWithOffset_Should_ReturnPointWithCorrectOffset(); void TestRectBottomRightWithOffset_Should_ReturnPointWithCorrectOffset_data(); void TestExtendLine_Should_ReturnNewLineExtendBySizeWithSameAngle(); void TestRectPointAtIndex_Should_ReturnPointAtIndexPosition(); void TestRectPointAtIndex_Should_ReturnPointAtIndexPosition_data(); void TestSetRectPointAtIndex_Should_SetRectPointAtIndexToProvidedPoint(); void TestSetRectPointAtIndex_Should_SetRectPointAtIndexToProvidedPoint_data(); void TestSmoothOut_Should_RetunSamePath_When_PathHasOnlyThreeElement(); }; #endif //KIMAGEANNOTATOR_SHAPEHELPERTEST_H kImageAnnotator-0.5.3/tests/gui/000077500000000000000000000000001414424500400165265ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/gui/annotator/000077500000000000000000000000001414424500400205335ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/gui/annotator/tabs/000077500000000000000000000000001414424500400214645ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/gui/annotator/tabs/AnnotationTabCloserTest.cpp000066400000000000000000000076671414424500400267610ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationTabCloserTest.h" void AnnotationTabCloserTest::TestCloseTabTriggered_Should_CallMethodForRequestingTabCloseWithProvidedIndex_When_ProvidedIndexValid() { auto tabWidget = getTabWidgetMock(); QSignalSpy spy(tabWidget.data(), &QTabWidget::tabCloseRequested); AnnotationTabCloser tabCloser(tabWidget.data()); tabCloser.closeTabTriggered(3); QCOMPARE(spy.count(), 1); auto arguments = spy.takeFirst(); QCOMPARE(arguments.at(0).toInt(), 3); } void AnnotationTabCloserTest::TestCloseTabTriggered_Should_CallMethodForRequestingTabCloseWithCurrentIndex_When_ProvidedIndexInvalid() { auto tabWidget = getTabWidgetMock(); QSignalSpy spy(tabWidget.data(), &QTabWidget::tabCloseRequested); AnnotationTabCloser tabCloser(tabWidget.data()); tabCloser.closeTabTriggered(7); QCOMPARE(spy.count(), 1); auto arguments = spy.takeFirst(); QCOMPARE(arguments.at(0).toInt(), 2); } void AnnotationTabCloserTest::TestCloseOtherTabsTriggered_Should_CallMethodForRequestingTabCloseForAllButProvidedIndex() { auto tabWidget = getTabWidgetMock(); QSignalSpy spy(tabWidget.data(), &QTabWidget::tabCloseRequested); AnnotationTabCloser tabCloser(tabWidget.data()); tabCloser.closeOtherTabsTriggered(2); QCOMPARE(spy.count(), 4); QCOMPARE(spy[0].at(0).toInt(), 4); QCOMPARE(spy[1].at(0).toInt(), 3); QCOMPARE(spy[2].at(0).toInt(), 1); QCOMPARE(spy[3].at(0).toInt(), 0); } void AnnotationTabCloserTest::TestCloseAllTabsTriggered_Should_CallMethodForRequestingTabCloseForAllIndex() { auto tabWidget = getTabWidgetMock(); QSignalSpy spy(tabWidget.data(), &QTabWidget::tabCloseRequested); AnnotationTabCloser tabCloser(tabWidget.data()); tabCloser.closeAllTabsTriggered(); QCOMPARE(spy.count(), 5); QCOMPARE(spy[0].at(0).toInt(), 4); QCOMPARE(spy[1].at(0).toInt(), 3); QCOMPARE(spy[2].at(0).toInt(), 2); QCOMPARE(spy[3].at(0).toInt(), 1); QCOMPARE(spy[4].at(0).toInt(), 0); } void AnnotationTabCloserTest::TestCloseAllTabsToLeftTriggered_Should_CallMethodForRequestingTabCloseForAllSmallerIndex() { auto tabWidget = getTabWidgetMock(); QSignalSpy spy(tabWidget.data(), &QTabWidget::tabCloseRequested); AnnotationTabCloser tabCloser(tabWidget.data()); tabCloser.closeAllTabsToLeftTriggered(2); QCOMPARE(spy.count(), 2); QCOMPARE(spy[0].at(0).toInt(), 1); QCOMPARE(spy[1].at(0).toInt(), 0); } void AnnotationTabCloserTest::TestCloseAllTabsToRightTriggered_Should_CallMethodForRequestingTabCloseForAllLargerIndex() { auto tabWidget = getTabWidgetMock(); QSignalSpy spy(tabWidget.data(), &QTabWidget::tabCloseRequested); AnnotationTabCloser tabCloser(tabWidget.data()); tabCloser.closeAllTabsToRightTriggered(2); QCOMPARE(spy.count(), 2); QCOMPARE(spy[0].at(0).toInt(), 4); QCOMPARE(spy[1].at(0).toInt(), 3); } QSharedPointer AnnotationTabCloserTest::getTabWidgetMock() const { auto tabWidget = QSharedPointer(new QTabWidget); tabWidget->addTab(new QWidget(), QString()); tabWidget->addTab(new QWidget(), QString()); tabWidget->addTab(new QWidget(), QString()); tabWidget->addTab(new QWidget(), QString()); tabWidget->addTab(new QWidget(), QString()); tabWidget->setCurrentIndex(2); return tabWidget; } QTEST_MAIN(AnnotationTabCloserTest);kImageAnnotator-0.5.3/tests/gui/annotator/tabs/AnnotationTabCloserTest.h000066400000000000000000000035171414424500400264140ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONTABCLOSERTEST_H #define KIMAGEANNOTATOR_ANNOTATIONTABCLOSERTEST_H #include #include #include #include "src/gui/annotator/tabs/AnnotationTabCloser.h" using kImageAnnotator::AnnotationTabCloser; class AnnotationTabCloserTest : public QObject { Q_OBJECT private slots: void TestCloseTabTriggered_Should_CallMethodForRequestingTabCloseWithProvidedIndex_When_ProvidedIndexValid(); void TestCloseTabTriggered_Should_CallMethodForRequestingTabCloseWithCurrentIndex_When_ProvidedIndexInvalid(); void TestCloseOtherTabsTriggered_Should_CallMethodForRequestingTabCloseForAllButProvidedIndex(); void TestCloseAllTabsTriggered_Should_CallMethodForRequestingTabCloseForAllIndex(); void TestCloseAllTabsToLeftTriggered_Should_CallMethodForRequestingTabCloseForAllSmallerIndex(); void TestCloseAllTabsToRightTriggered_Should_CallMethodForRequestingTabCloseForAllLargerIndex(); private: QSharedPointer getTabWidgetMock() const; }; #endif //KIMAGEANNOTATOR_ANNOTATIONTABCLOSERTEST_H kImageAnnotator-0.5.3/tests/gui/annotator/tabs/AnnotationTabContextMenuTest.cpp000066400000000000000000000051141414424500400277640ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationTabContextMenuTest.h" void AnnotationTabContextMenuTest::TestCustomActionTriggered_Should_CallInnerActionWithCorrectTabIndexSetInData() { auto tabIndex = 22; QAction customAction; QSignalSpy spy(&customAction, &QAction::triggered); QWidget parent; AnnotationTabContextMenu menu(&parent); menu.addCustomActions(QList{&customAction}); auto outerAction = menu.actions().last(); QTimer::singleShot(300, outerAction, &QAction::trigger); QTimer::singleShot(400, &menu, &QMenu::close); menu.show(tabIndex, {}); QCOMPARE(customAction.data().toInt(), tabIndex); QCOMPARE(spy.count(), 1); } void AnnotationTabContextMenuTest::TestAddCustomActions_Should_SetTextIconAndToolTipInOuterAction() { QAction customAction; customAction.setText(QLatin1Literal("LaLa")); customAction.setToolTip(QLatin1Literal("Hello Hello")); customAction.setIcon(QIcon()); QWidget parent; AnnotationTabContextMenu menu(&parent); menu.addCustomActions(QList{&customAction}); auto outerAction = menu.actions().last(); QCOMPARE(customAction.text(), outerAction->text()); QCOMPARE(customAction.toolTip(), outerAction->toolTip()); QCOMPARE(customAction.icon(), outerAction->icon()); } void AnnotationTabContextMenuTest::TestCustomActionChanged_Should_UpdateEnabledStateOfOuterAction() { QAction customAction; customAction.setEnabled(false); QWidget parent; AnnotationTabContextMenu menu(&parent); menu.addCustomActions(QList{&customAction}); auto outerAction = menu.actions().last(); QCOMPARE(customAction.isEnabled(), outerAction->isEnabled()); customAction.setEnabled(true); QCOMPARE(customAction.isEnabled(), outerAction->isEnabled()); } QTEST_MAIN(AnnotationTabContextMenuTest);kImageAnnotator-0.5.3/tests/gui/annotator/tabs/AnnotationTabContextMenuTest.h000066400000000000000000000026441414424500400274360ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONTABCONTEXTMENUTEST_H #define KIMAGEANNOTATOR_ANNOTATIONTABCONTEXTMENUTEST_H #include #include #include "src/gui/annotator/tabs/AnnotationTabContextMenu.h" using kImageAnnotator::AnnotationTabContextMenu; class AnnotationTabContextMenuTest : public QObject { Q_OBJECT private slots: void TestCustomActionTriggered_Should_CallInnerActionWithCorrectTabIndexSetInData(); void TestAddCustomActions_Should_SetTextIconAndToolTipInOuterAction(); void TestCustomActionChanged_Should_UpdateEnabledStateOfOuterAction(); }; #endif //KIMAGEANNOTATOR_ANNOTATIONTABCONTEXTMENUTEST_H kImageAnnotator-0.5.3/tests/gui/canvasModifier/000077500000000000000000000000001414424500400214605ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/gui/canvasModifier/ModifyCanvasSelectionRestrictorTest.cpp000066400000000000000000000077561414424500400313550ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ModifyCanvasSelectionRestrictorTest.h" void ModifyCanvasSelectionRestrictorTest::TestRestrictResize_Should_ChangeResize_When_NewSizeSmallerThenMinRect() { QRectF newRect(50, 50, 400, 400); QRectF currentRect(100, 100, 200, 200); QRectF minRect(0, 0, 500, 500); ModifyCanvasSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictResize(newRect, currentRect, minRect); QCOMPARE(resizeRect, minRect); } void ModifyCanvasSelectionRestrictorTest::TestRestrictResize_Should_NotChangeResize_When_NewSizeLargerThenMinRect() { QRectF newRect(0, 0, 600, 600); QRectF currentRect(100, 100, 200, 200); QRectF minRect(0, 0, 500, 500); ModifyCanvasSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictResize(newRect, currentRect, minRect); QCOMPARE(resizeRect, newRect); } void ModifyCanvasSelectionRestrictorTest::TestRestrictResize_Should_NotChangeResize_When_NewPositionIsOutsideMinRect() { QRectF newRect(-50, -50, 400, 400); QRectF currentRect(100, 100, 200, 200); QRectF minRect(0, 0, 500, 500); ModifyCanvasSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictResize(newRect, currentRect, minRect); QCOMPARE(resizeRect, newRect); } void ModifyCanvasSelectionRestrictorTest::TestRestrictResize_Should_ChangeResize_When_NewPositionIsInsideMinRect() { QRectF newRect(50, 50, 450, 450); QRectF currentRect(-50, -50, 550, 550); QRectF minRect(0, 0, 500, 500); ModifyCanvasSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictResize(newRect, currentRect, minRect); QCOMPARE(resizeRect, minRect); } void ModifyCanvasSelectionRestrictorTest::TestRestrictMove_Should_ChangeMove_When_NewPositionAndSizeWithinMinRect() { QRectF newRect(50, 50, 500, 500); QRectF minRect(0, 0, 500, 500); ModifyCanvasSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictMove(newRect, minRect); QCOMPARE(resizeRect, minRect); } void ModifyCanvasSelectionRestrictorTest::TestRestrictMove_Should_NotChangeMove_When_NewPositionOutsideMinRect() { QRectF newRect(-50, -50, 200, 200); QRectF minRect(0, 0, 500, 500); ModifyCanvasSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictMove(newRect, minRect); QCOMPARE(resizeRect, newRect); } void ModifyCanvasSelectionRestrictorTest::TestRestrictMove_Should_ChangeMove_When_NewPositionInsideMinRect() { QRectF newRect(50, 50, 500, 500); QRectF minRect(0, 0, 500, 500); ModifyCanvasSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictMove(newRect, minRect); QCOMPARE(resizeRect, minRect); } void ModifyCanvasSelectionRestrictorTest::TestRestrictMove_Should_NotChangeMove_When_NewSizeOutsideMinRect() { QRectF newRect(300, 300, 300, 300); QRectF minRect(0, 0, 500, 500); ModifyCanvasSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictMove(newRect, minRect); QCOMPARE(resizeRect, newRect); } void ModifyCanvasSelectionRestrictorTest::TestRestrictMove_Should_ChangeMove_When_NewSizeInsideMinRect() { QRectF newRect(300, 300, 500, 500); QRectF minRect(0, 0, 500, 500); ModifyCanvasSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictMove(newRect, minRect); QCOMPARE(resizeRect, minRect); } QTEST_MAIN(ModifyCanvasSelectionRestrictorTest); kImageAnnotator-0.5.3/tests/gui/canvasModifier/ModifyCanvasSelectionRestrictorTest.h000066400000000000000000000035621414424500400310110ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CROPSELECTIONRESTRICTORTEST_H #define KIMAGEANNOTATOR_CROPSELECTIONRESTRICTORTEST_H #include #include "src/gui/canvasModifier/ModifyCanvasSelectionRestrictor.h" using kImageAnnotator::ModifyCanvasSelectionRestrictor; class ModifyCanvasSelectionRestrictorTest : public QObject { Q_OBJECT private slots: void TestRestrictResize_Should_ChangeResize_When_NewSizeSmallerThenMinRect(); void TestRestrictResize_Should_NotChangeResize_When_NewSizeLargerThenMinRect(); void TestRestrictResize_Should_NotChangeResize_When_NewPositionIsOutsideMinRect(); void TestRestrictResize_Should_ChangeResize_When_NewPositionIsInsideMinRect(); void TestRestrictMove_Should_ChangeMove_When_NewPositionAndSizeWithinMinRect(); void TestRestrictMove_Should_NotChangeMove_When_NewPositionOutsideMinRect(); void TestRestrictMove_Should_ChangeMove_When_NewPositionInsideMinRect(); void TestRestrictMove_Should_NotChangeMove_When_NewSizeOutsideMinRect(); void TestRestrictMove_Should_ChangeMove_When_NewSizeInsideMinRect(); }; #endif // KIMAGEANNOTATOR_CROPSELECTIONRESTRICTORTEST_H kImageAnnotator-0.5.3/tests/gui/cropper/000077500000000000000000000000001414424500400202005ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/gui/cropper/CropSelectionRestrictorTest.cpp000066400000000000000000000073261414424500400264060ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "CropSelectionRestrictorTest.h" void CropSelectionRestrictorTest::TestRestrictResize_Should_NotChangeResize_When_NewSizeSmallerThenMaxRect() { QRectF newRect(50, 50, 400, 400); QRectF currentRect(100, 100, 200, 200); QRectF maxRect(0, 0, 500, 500); CropSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictResize(newRect, currentRect, maxRect); QCOMPARE(resizeRect, QRectF(50, 50, 400, 400)); } void CropSelectionRestrictorTest::TestRestrictResize_Should_ChangeResize_When_NewSizeLargerThenMaxRect() { QRectF newRect(0, 0, 600, 600); QRectF currentRect(100, 100, 200, 200); QRectF maxRect(0, 0, 500, 500); CropSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictResize(newRect, currentRect, maxRect); QCOMPARE(resizeRect, QRectF(0, 0, 500, 500)); } void CropSelectionRestrictorTest::TestRestrictResize_Should_ChangeResize_When_NewPositionIsOutsideMaxRect() { QRectF newRect(-50, -50, 400, 400); QRectF currentRect(100, 100, 200, 200); QRectF maxRect(0, 0, 500, 500); CropSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictResize(newRect, currentRect, maxRect); QCOMPARE(resizeRect, QRectF(0, 0, 350, 350)); } void CropSelectionRestrictorTest::TestRestrictResize_Should_ChangeResize_When_NewPositionHasNegativeWidth() { QRectF newRect(50, 50, -400, 400); QRectF currentRect(50, 50, 200, 200); QRectF maxRect(0, 0, 500, 500); CropSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictResize(newRect, currentRect, maxRect); QCOMPARE(resizeRect, QRectF(50, 50, 0, 400)); } void CropSelectionRestrictorTest::TestRestrictResize_Should_ChangeResize_When_NewPositionHasNegativeHeight() { QRectF newRect(50, 50, 400, -400); QRectF currentRect(50, 50, 200, 200); QRectF maxRect(0, 0, 500, 500); CropSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictResize(newRect, currentRect, maxRect); QCOMPARE(resizeRect, QRectF(50, 50, 400, 0)); } void CropSelectionRestrictorTest::TestRestrictMove_Should_NotChangeMove_When_NewPositionAndSizeWithinMaxRect() { QRectF newRect(50, 50, 400, 400); QRectF maxRect(0, 0, 500, 500); CropSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictMove(newRect, maxRect); QCOMPARE(resizeRect, QRectF(50, 50, 400, 400)); } void CropSelectionRestrictorTest::TestRestrictMove_Should_ChangeMove_When_NewPositionOutsideMaxRect() { QRectF newRect(-50, -50, 200, 200); QRectF maxRect(0, 0, 500, 500); CropSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictMove(newRect, maxRect); QCOMPARE(resizeRect, QRectF(0, 0, 200, 200)); } void CropSelectionRestrictorTest::TestRestrictMove_Should_ChangeMove_When_NewSizeOutsideMaxRect() { QRectF newRect(300, 300, 300, 300); QRectF maxRect(0, 0, 500, 500); CropSelectionRestrictor restrictor; auto resizeRect = restrictor.restrictMove(newRect, maxRect); QCOMPARE(resizeRect, QRectF(200, 200, 300, 300)); } QTEST_MAIN(CropSelectionRestrictorTest); kImageAnnotator-0.5.3/tests/gui/cropper/CropSelectionRestrictorTest.h000066400000000000000000000034201414424500400260420ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CROPSELECTIONRESTRICTORTEST_H #define KIMAGEANNOTATOR_CROPSELECTIONRESTRICTORTEST_H #include #include "src/gui/cropper/CropSelectionRestrictor.h" using kImageAnnotator::CropSelectionRestrictor; class CropSelectionRestrictorTest : public QObject { Q_OBJECT private slots: void TestRestrictResize_Should_NotChangeResize_When_NewSizeSmallerThenMaxRect(); void TestRestrictResize_Should_ChangeResize_When_NewSizeLargerThenMaxRect(); void TestRestrictResize_Should_ChangeResize_When_NewPositionIsOutsideMaxRect(); void TestRestrictResize_Should_ChangeResize_When_NewPositionHasNegativeWidth(); void TestRestrictResize_Should_ChangeResize_When_NewPositionHasNegativeHeight(); void TestRestrictMove_Should_NotChangeMove_When_NewPositionAndSizeWithinMaxRect(); void TestRestrictMove_Should_ChangeMove_When_NewPositionOutsideMaxRect(); void TestRestrictMove_Should_ChangeMove_When_NewSizeOutsideMaxRect(); }; #endif // KIMAGEANNOTATOR_CROPSELECTIONRESTRICTORTEST_H kImageAnnotator-0.5.3/tests/gui/scaler/000077500000000000000000000000001414424500400177775ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/gui/scaler/ScaleSizeHandlerTest.cpp000066400000000000000000000153021414424500400245240ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ScaleSizeHandlerTest.h" void ScaleSizeHandlerTest::TestSetWidthPixel_Should_UpdatePercentCorrectly() { QSize size(500, 500); ScaleSizeHandler sizeHandler; sizeHandler.setSize(size); QSignalSpy spy(&sizeHandler, &ScaleSizeHandler::widthPercentChanged); sizeHandler.setWidthPixel(250); QCOMPARE(spy.count(), 1); auto resultValue = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultValue, 50); } void ScaleSizeHandlerTest::TestSetHeightPixel_Should_UpdatePercentCorrectly() { QSize size(500, 500); ScaleSizeHandler sizeHandler; sizeHandler.setSize(size); QSignalSpy spy(&sizeHandler, &ScaleSizeHandler::heightPercentChanged); sizeHandler.setHeightPixel(250); QCOMPARE(spy.count(), 1); auto resultValue = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultValue, 50); } void ScaleSizeHandlerTest::TestSetWidthPercent_Should_UpdatePixelCorrectly() { QSize size(500, 500); ScaleSizeHandler sizeHandler; sizeHandler.setSize(size); QSignalSpy spy(&sizeHandler, &ScaleSizeHandler::widthPixelChanged); sizeHandler.setWidthPercent(50); QCOMPARE(spy.count(), 1); auto resultValue = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultValue, 250); } void ScaleSizeHandlerTest::TestSetHeightPercent_Should_UpdatePixelCorrectly() { QSize size(500, 500); ScaleSizeHandler sizeHandler; sizeHandler.setSize(size); QSignalSpy spy(&sizeHandler, &ScaleSizeHandler::heightPixelChanged); sizeHandler.setHeightPercent(50); QCOMPARE(spy.count(), 1); auto resultValue = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultValue, 250); } void ScaleSizeHandlerTest::TestSetWidthPixel_Should_NotUpdateHeight_When_KeepAspectRatioNotSet() { QSize size(500, 500); ScaleSizeHandler sizeHandler; sizeHandler.setSize(size); sizeHandler.setAspectRatio(false); QSignalSpy percentSpy(&sizeHandler, &ScaleSizeHandler::heightPercentChanged); QSignalSpy pixelSpy(&sizeHandler, &ScaleSizeHandler::heightPixelChanged); sizeHandler.setWidthPixel(250); QCOMPARE(percentSpy.count(), 0); QCOMPARE(pixelSpy.count(), 0); } void ScaleSizeHandlerTest::TestSetWidthPixel_Should_UpdateHeight_When_KeepAspectRatioIsSet() { QSize size(500, 500); ScaleSizeHandler sizeHandler; sizeHandler.setSize(size); sizeHandler.setAspectRatio(true); QSignalSpy percentSpy(&sizeHandler, &ScaleSizeHandler::heightPercentChanged); QSignalSpy pixelSpy(&sizeHandler, &ScaleSizeHandler::heightPixelChanged); sizeHandler.setWidthPixel(250); QCOMPARE(percentSpy.count(), 1); QCOMPARE(pixelSpy.count(), 1); auto percent = qvariant_cast(percentSpy.at(0).at(0)); auto pixel = qvariant_cast(pixelSpy.at(0).at(0)); QCOMPARE(percent, 50); QCOMPARE(pixel, 250); } void ScaleSizeHandlerTest::TestSetWidthPercent_Should_NotUpdateHeight_When_KeepAspectRatioNotSet() { QSize size(500, 500); ScaleSizeHandler sizeHandler; sizeHandler.setSize(size); sizeHandler.setAspectRatio(false); QSignalSpy percentSpy(&sizeHandler, &ScaleSizeHandler::heightPercentChanged); QSignalSpy pixelSpy(&sizeHandler, &ScaleSizeHandler::heightPixelChanged); sizeHandler.setWidthPercent(50); QCOMPARE(percentSpy.count(), 0); QCOMPARE(pixelSpy.count(), 0); } void ScaleSizeHandlerTest::TestSetWidthPercent_Should_UpdateHeight_When_KeepAspectRatioIsSet() { QSize size(500, 500); ScaleSizeHandler sizeHandler; sizeHandler.setSize(size); sizeHandler.setAspectRatio(true); QSignalSpy percentSpy(&sizeHandler, &ScaleSizeHandler::heightPercentChanged); QSignalSpy pixelSpy(&sizeHandler, &ScaleSizeHandler::heightPixelChanged); sizeHandler.setWidthPercent(50); QCOMPARE(percentSpy.count(), 1); QCOMPARE(pixelSpy.count(), 1); auto percent = qvariant_cast(percentSpy.at(0).at(0)); auto pixel = qvariant_cast(pixelSpy.at(0).at(0)); QCOMPARE(percent, 50); QCOMPARE(pixel, 250); } void ScaleSizeHandlerTest::TestSetHeightPixel_Should_NotUpdateWidth_When_KeepAspectRatioNotSet() { QSize size(500, 500); ScaleSizeHandler sizeHandler; sizeHandler.setSize(size); sizeHandler.setAspectRatio(false); QSignalSpy percentSpy(&sizeHandler, &ScaleSizeHandler::widthPercentChanged); QSignalSpy pixelSpy(&sizeHandler, &ScaleSizeHandler::widthPixelChanged); sizeHandler.setHeightPixel(250); QCOMPARE(percentSpy.count(), 0); QCOMPARE(pixelSpy.count(), 0); } void ScaleSizeHandlerTest::TestSetHeightPixel_Should_UpdateWidth_When_KeepAspectRatioIsSet() { QSize size(500, 500); ScaleSizeHandler sizeHandler; sizeHandler.setSize(size); sizeHandler.setAspectRatio(true); QSignalSpy percentSpy(&sizeHandler, &ScaleSizeHandler::widthPercentChanged); QSignalSpy pixelSpy(&sizeHandler, &ScaleSizeHandler::widthPixelChanged); sizeHandler.setHeightPixel(250); QCOMPARE(percentSpy.count(), 1); QCOMPARE(pixelSpy.count(), 1); auto percent = qvariant_cast(percentSpy.at(0).at(0)); auto pixel = qvariant_cast(pixelSpy.at(0).at(0)); QCOMPARE(percent, 50); QCOMPARE(pixel, 250); } void ScaleSizeHandlerTest::TestSetHeightPercent_Should_NotUpdateWidth_When_KeepAspectRatioNotSet() { QSize size(500, 500); ScaleSizeHandler sizeHandler; sizeHandler.setSize(size); sizeHandler.setAspectRatio(false); QSignalSpy percentSpy(&sizeHandler, &ScaleSizeHandler::widthPercentChanged); QSignalSpy pixelSpy(&sizeHandler, &ScaleSizeHandler::widthPixelChanged); sizeHandler.setHeightPercent(50); QCOMPARE(percentSpy.count(), 0); QCOMPARE(pixelSpy.count(), 0); } void ScaleSizeHandlerTest::TestSetHeightPercent_Should_UpdateWidth_When_KeepAspectRatioIsSet() { QSize size(500, 500); ScaleSizeHandler sizeHandler; sizeHandler.setSize(size); sizeHandler.setAspectRatio(true); QSignalSpy percentSpy(&sizeHandler, &ScaleSizeHandler::widthPercentChanged); QSignalSpy pixelSpy(&sizeHandler, &ScaleSizeHandler::widthPixelChanged); sizeHandler.setHeightPercent(50); QCOMPARE(percentSpy.count(), 1); QCOMPARE(pixelSpy.count(), 1); auto percent = qvariant_cast(percentSpy.at(0).at(0)); auto pixel = qvariant_cast(pixelSpy.at(0).at(0)); QCOMPARE(percent, 50); QCOMPARE(pixel, 250); } QTEST_MAIN(ScaleSizeHandlerTest); kImageAnnotator-0.5.3/tests/gui/scaler/ScaleSizeHandlerTest.h000066400000000000000000000036621414424500400241770ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SCALESIZEHANDLERTEST_H #define KIMAGEANNOTATOR_SCALESIZEHANDLERTEST_H #include #include "src/gui/scaler/ScaleSizeHandler.h" using kImageAnnotator::ScaleSizeHandler; class ScaleSizeHandlerTest : public QObject { Q_OBJECT private slots: void TestSetWidthPixel_Should_UpdatePercentCorrectly(); void TestSetHeightPixel_Should_UpdatePercentCorrectly(); void TestSetWidthPercent_Should_UpdatePixelCorrectly(); void TestSetHeightPercent_Should_UpdatePixelCorrectly(); void TestSetWidthPixel_Should_NotUpdateHeight_When_KeepAspectRatioNotSet(); void TestSetWidthPixel_Should_UpdateHeight_When_KeepAspectRatioIsSet(); void TestSetWidthPercent_Should_NotUpdateHeight_When_KeepAspectRatioNotSet(); void TestSetWidthPercent_Should_UpdateHeight_When_KeepAspectRatioIsSet(); void TestSetHeightPixel_Should_NotUpdateWidth_When_KeepAspectRatioNotSet(); void TestSetHeightPixel_Should_UpdateWidth_When_KeepAspectRatioIsSet(); void TestSetHeightPercent_Should_NotUpdateWidth_When_KeepAspectRatioNotSet(); void TestSetHeightPercent_Should_UpdateWidth_When_KeepAspectRatioIsSet(); }; #endif // KIMAGEANNOTATOR_SCALESIZEHANDLERTEST_H kImageAnnotator-0.5.3/tests/gui/selection/000077500000000000000000000000001414424500400205135ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/gui/selection/SelectionHandlerTest.cpp000066400000000000000000000207611414424500400253100ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "SelectionHandlerTest.h" void SelectionHandlerTest::TestSetWidth_Should_EmitSelectionChangedSignal() { // arrange MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); auto selectionRestrictor = new MockSelectionRestrictor(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); SelectionHandler selectionHandler(selectionRestrictor); selectionHandler.init(&annotationArea); QSignalSpy spy(&selectionHandler, &SelectionHandler::selectionChanged); // act selectionHandler.setWidth(30); // assert QCOMPARE(spy.count(), 1); } void SelectionHandlerTest::TestSetHeight_Should_EmitSelectionChangedSignal() { // arrange MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); auto selectionRestrictor = new MockSelectionRestrictor(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); SelectionHandler selectionHandler(selectionRestrictor); selectionHandler.init(&annotationArea); QSignalSpy spy(&selectionHandler, &SelectionHandler::selectionChanged); // act selectionHandler.setHeight(30); // assert QCOMPARE(spy.count(), 1); } void SelectionHandlerTest::TestSetPositionX_Should_EmitSelectionChangedSignal() { // arrange MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); auto selectionRestrictor = new MockSelectionRestrictor(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); SelectionHandler selectionHandler(selectionRestrictor); selectionHandler.init(&annotationArea); QSignalSpy spy(&selectionHandler, &SelectionHandler::selectionChanged); // act selectionHandler.setPositionY(30); // assert QCOMPARE(spy.count(), 1); } void SelectionHandlerTest::TestSetPositionY_Should_EmitSelectionChangedSignal() { // arrange MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); auto selectionRestrictor = new MockSelectionRestrictor(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); SelectionHandler selectionHandler(selectionRestrictor); selectionHandler.init(&annotationArea); QSignalSpy spy(&selectionHandler, &SelectionHandler::selectionChanged); // act selectionHandler.setPositionX(30); // assert QCOMPARE(spy.count(), 1); } void SelectionHandlerTest::TestResetSelection_Should_SetSelectionToProvidedRect() { // arrange MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); auto selectionRestrictor = new MockSelectionRestrictor(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); auto sceneRect = QRectF(0, 0, 500, 500); annotationArea.setSceneRect(sceneRect); SelectionHandler selectionHandler(selectionRestrictor); selectionHandler.init(&annotationArea); selectionHandler.setWidth(400); QVERIFY(selectionHandler.selection() != sceneRect); // act selectionHandler.resetSelection(sceneRect, sceneRect); // assert QCOMPARE(selectionHandler.selection(), sceneRect); } void SelectionHandlerTest::TestIsInMotion_Should_ReturnTrue_WhenClickedOnSelection() { // arrange MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); auto selectionRestrictor = new MockSelectionRestrictor(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); auto sceneRect = QRectF(0, 0, 500, 500); auto position = QPointF(150, 150); annotationArea.setSceneRect(sceneRect); SelectionHandler selectionHandler(selectionRestrictor); selectionHandler.init(&annotationArea); selectionHandler.resetSelection(sceneRect, sceneRect); selectionHandler.grab(position); // act auto isInMotion = selectionHandler.isInMotion(); // assert QCOMPARE(isInMotion, true); } void SelectionHandlerTest::TestIsInMotion_Should_ReturnTrue_WhenClickedOnHandle() { // arrange MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); auto selectionRestrictor = new MockSelectionRestrictor(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); auto sceneRect = QRectF(0, 0, 500, 500); auto position = QPointF(2, 2); annotationArea.setSceneRect(sceneRect); SelectionHandler selectionHandler(selectionRestrictor); selectionHandler.init(&annotationArea); selectionHandler.grab(position); // act auto isInMotion = selectionHandler.isInMotion(); // assert QCOMPARE(isInMotion, true); } void SelectionHandlerTest::TestIsInMotion_Should_ReturnFalse_WhenClickedOutsideSelectionAndHandle() { // arrange MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); auto selectionRestrictor = new MockSelectionRestrictor(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); auto sceneRect = QRectF(0, 0, 500, 500); auto position = QPointF(400, 400); annotationArea.setSceneRect(sceneRect); SelectionHandler selectionHandler(selectionRestrictor); selectionHandler.init(&annotationArea); selectionHandler.setWidth(200); selectionHandler.grab(position); // act auto isInMotion = selectionHandler.isInMotion(); // assert QCOMPARE(isInMotion, false); } void SelectionHandlerTest::TestSelectionHandles_Should_ReturnEightItems() { // arrange MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); auto selectionRestrictor = new MockSelectionRestrictor(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); SelectionHandler selectionHandler(selectionRestrictor); selectionHandler.init(&annotationArea); // act auto handles = selectionHandler.selectionHandles(); // assert QCOMPARE(handles.length(), 8); } void SelectionHandlerTest::TestRestrictResize_Should_KeepCurrentSelection_When_NewSelectionHasNegativeWidthAndRestrictionDisabled() { // arrange MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); auto selectionRestrictor = new MockSelectionRestrictor(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); SelectionHandler selectionHandler(selectionRestrictor); selectionHandler.init(&annotationArea); selectionHandler.setRestrictionEnabled(false); auto selectionBefore = selectionHandler.selection(); // act selectionHandler.setWidth(-30); // assert auto selectionAfter = selectionHandler.selection(); QCOMPARE(selectionBefore, selectionAfter); QVERIFY(selectionAfter.width() >= 0); } void SelectionHandlerTest::TestRestrictResize_Should_KeepCurrentSelection_When_NewSelectionHasNegativeHeightAndRestrictionDisabled() { // arrange MockDefaultParameters parameters; auto scalerMock = new MockDevicePixelRatioScaler(); auto selectionRestrictor = new MockSelectionRestrictor(); AnnotationArea annotationArea(¶meters.config, ¶meters.settingsProvider, scalerMock, ¶meters.zoomValueProvider, nullptr); SelectionHandler selectionHandler(selectionRestrictor); selectionHandler.init(&annotationArea); selectionHandler.setRestrictionEnabled(false); auto selectionBefore = selectionHandler.selection(); // act selectionHandler.setHeight(-30); // assert auto selectionAfter = selectionHandler.selection(); QCOMPARE(selectionBefore, selectionAfter); QVERIFY(selectionAfter.height() >= 0.0); } QTEST_MAIN(SelectionHandlerTest) kImageAnnotator-0.5.3/tests/gui/selection/SelectionHandlerTest.h000066400000000000000000000040641414424500400247530ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SELECTIONHANDLERTEST_H #define KIMAGEANNOTATOR_SELECTIONHANDLERTEST_H #include #include "src/annotations/core/AnnotationArea.h" #include "src/gui/selection/SelectionHandler.h" #include "tests/mocks/MockDefaultParameters.h" #include "tests/mocks/MockSelectionRestrictor.h" using kImageAnnotator::AnnotationArea; using kImageAnnotator::SelectionHandler; class SelectionHandlerTest : public QObject { Q_OBJECT private slots: void TestSetWidth_Should_EmitSelectionChangedSignal(); void TestSetHeight_Should_EmitSelectionChangedSignal(); void TestSetPositionX_Should_EmitSelectionChangedSignal(); void TestSetPositionY_Should_EmitSelectionChangedSignal(); void TestResetSelection_Should_SetSelectionToProvidedRect(); void TestIsInMotion_Should_ReturnTrue_WhenClickedOnSelection(); void TestIsInMotion_Should_ReturnTrue_WhenClickedOnHandle(); void TestIsInMotion_Should_ReturnFalse_WhenClickedOutsideSelectionAndHandle(); void TestSelectionHandles_Should_ReturnEightItems(); void TestRestrictResize_Should_KeepCurrentSelection_When_NewSelectionHasNegativeWidthAndRestrictionDisabled(); void TestRestrictResize_Should_KeepCurrentSelection_When_NewSelectionHasNegativeHeightAndRestrictionDisabled(); }; #endif // KIMAGEANNOTATOR_SELECTIONHANDLERTEST_H kImageAnnotator-0.5.3/tests/gui/selection/SelectionHandlesTest.cpp000066400000000000000000000073321414424500400253100ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "SelectionHandlesTest.h" void SelectionHandlesTest::TestIsHandleGrabbed_Should_ReturnTrue_When_ClickedOnHandle() { QRectF selection(0, 0, 500, 500); auto halfHandle = ResizeHandleSize / 2; QPointF position(halfHandle, halfHandle); SelectionHandles handles; handles.updateHandles(selection); handles.grabHandle(position, selection); auto isHandleGrabbed = handles.isHandleGrabbed(); QCOMPARE(isHandleGrabbed, true); } void SelectionHandlesTest::TestIsHandleGrabbed_Should_ReturnFalse_When_ClickedOutsideHandle() { QRectF selection(0, 0, 500, 500); QPointF position(300, 300); SelectionHandles handles; handles.updateHandles(selection); handles.grabHandle(position, selection); auto isHandleGrabbed = handles.isHandleGrabbed(); QCOMPARE(isHandleGrabbed, false); } void SelectionHandlesTest::TestGrabbedIndex_Should_ReturnIndexOfHandle_When_ClickedOnHandle() { QRectF selection(0, 0, 500, 500); auto halfHandle = ResizeHandleSize / 2; QPointF position(halfHandle, halfHandle); SelectionHandles handles; handles.updateHandles(selection); handles.grabHandle(position, selection); auto grabbedIndex = handles.grabbedIndex(); QCOMPARE(grabbedIndex, 0); } void SelectionHandlesTest::TestGrabbedIndex_Should_ReturnMinusOne_When_ClickedOutsideHandle() { QRectF selection(0, 0, 500, 500); QPointF position(300, 300); SelectionHandles handles; handles.updateHandles(selection); handles.grabHandle(position, selection); auto grabbedIndex = handles.grabbedIndex(); QCOMPARE(grabbedIndex, -1); } void SelectionHandlesTest::TestGrabOffset_Should_ReturnClickOffsetForHandle() { QRectF selection(0, 0, 500, 500); auto halfHandle = ResizeHandleSize / 2; QPointF position(halfHandle, halfHandle); SelectionHandles handles; handles.updateHandles(selection); handles.grabHandle(position, selection); auto grabOffset = handles.grabOffset(); QCOMPARE(grabOffset, QPointF(halfHandle, halfHandle)); } void SelectionHandlesTest::TestUpdateHandles_Should_PositionHandlesOnCorrectPlaces() { QRectF selection(0, 0, 500, 500); SelectionHandles selectionHandles; selectionHandles.updateHandles(selection); auto handles = selectionHandles.handles(); QCOMPARE(handles[0].topLeft(), QPointF(0, 0)); QCOMPARE(handles[1].topLeft(), QPointF(selection.width() / 2 - ResizeHandleSize / 2, 0)); QCOMPARE(handles[2].topLeft(), QPointF(selection.width() - ResizeHandleSize, 0)); QCOMPARE(handles[3].topLeft(), QPointF(selection.width() - ResizeHandleSize, selection.height() / 2 - ResizeHandleSize / 2)); QCOMPARE(handles[4].topLeft(), QPointF(selection.width() - ResizeHandleSize, selection.height() - ResizeHandleSize)); QCOMPARE(handles[5].topLeft(), QPointF(selection.width() / 2 - ResizeHandleSize / 2, selection.height() - ResizeHandleSize)); QCOMPARE(handles[6].topLeft(), QPointF(0, selection.height() - ResizeHandleSize)); QCOMPARE(handles[7].topLeft(), QPointF(0, selection.height() / 2 - ResizeHandleSize / 2)); } QTEST_MAIN(SelectionHandlesTest); kImageAnnotator-0.5.3/tests/gui/selection/SelectionHandlesTest.h000066400000000000000000000030771414424500400247570ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SELECTIONHANDLESTEST_H #define KIMAGEANNOTATOR_SELECTIONHANDLESTEST_H #include #include "src/gui/selection/SelectionHandles.h" using kImageAnnotator::SelectionHandles; using kImageAnnotator::Constants::ResizeHandleSize; class SelectionHandlesTest : public QObject { Q_OBJECT private slots: void TestIsHandleGrabbed_Should_ReturnTrue_When_ClickedOnHandle(); void TestIsHandleGrabbed_Should_ReturnFalse_When_ClickedOutsideHandle(); void TestGrabbedIndex_Should_ReturnIndexOfHandle_When_ClickedOnHandle(); void TestGrabbedIndex_Should_ReturnMinusOne_When_ClickedOutsideHandle(); void TestGrabOffset_Should_ReturnClickOffsetForHandle(); void TestUpdateHandles_Should_PositionHandlesOnCorrectPlaces(); }; #endif // KIMAGEANNOTATOR_SELECTIONHANDLESTEST_H kImageAnnotator-0.5.3/tests/gui/selection/SelectionMoveHelperTest.cpp000066400000000000000000000041361414424500400257770ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "SelectionMoveHelperTest.h" void SelectionMoveHelperTest::TestGrabSelection_Should_GrabSelection_WhenPositionWithinSelection() { QRectF selection(100, 100, 300, 300); QPointF position(150, 150); SelectionMoveHelper moveHelper; moveHelper.grabSelection(position, selection); QCOMPARE(moveHelper.isSelectionGabbed(), true); } void SelectionMoveHelperTest::TestGrabSelection_Should_NotGrabSelection_WhenPositionOutsideSelection() { QRectF selection(100, 100, 300, 300); QPointF position(50, 50); SelectionMoveHelper moveHelper; moveHelper.grabSelection(position, selection); QCOMPARE(moveHelper.isSelectionGabbed(), false); } void SelectionMoveHelperTest::TestGrabSelection_Should_SetCorrectOffset() { QRectF selection(100, 100, 300, 300); QPointF position(150, 150); SelectionMoveHelper moveHelper; moveHelper.grabSelection(position, selection); QCOMPARE(moveHelper.grabOffset(), QPointF(50, 50)); } void SelectionMoveHelperTest::TestReleaseSelection_Should_ReleaseSelection() { QRectF selection(100, 100, 300, 300); QPointF position(150, 150); SelectionMoveHelper moveHelper; moveHelper.grabSelection(position, selection); QCOMPARE(moveHelper.isSelectionGabbed(), true); moveHelper.releaseSelection(); QCOMPARE(moveHelper.isSelectionGabbed(), false); } QTEST_MAIN(SelectionMoveHelperTest); kImageAnnotator-0.5.3/tests/gui/selection/SelectionMoveHelperTest.h000066400000000000000000000026061414424500400254440ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_SELECTIONMOVEHELPERTEST_H #define KIMAGEANNOTATOR_SELECTIONMOVEHELPERTEST_H #include #include "src/gui/selection/SelectionMoveHelper.h" using kImageAnnotator::SelectionMoveHelper; class SelectionMoveHelperTest : public QObject { Q_OBJECT private slots: void TestGrabSelection_Should_GrabSelection_WhenPositionWithinSelection(); void TestGrabSelection_Should_NotGrabSelection_WhenPositionOutsideSelection(); void TestGrabSelection_Should_SetCorrectOffset(); void TestReleaseSelection_Should_ReleaseSelection(); }; #endif // KIMAGEANNOTATOR_SELECTIONMOVEHELPERTEST_H kImageAnnotator-0.5.3/tests/mocks/000077500000000000000000000000001414424500400170565ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/mocks/MockDefaultParameters.h000066400000000000000000000023661414424500400234600ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_MOCKDEFAULTPARAMETERS_H #define KIMAGEANNOTATOR_MOCKDEFAULTPARAMETERS_H #include "MockZoomValueProvider.h" #include "MockSettingsProvider.h" #include "MockDevicePixelRatioScaler.h" #include "src/backend/Config.h" using kImageAnnotator::Config; struct MockDefaultParameters { Config config; MockSettingsProvider settingsProvider; MockZoomValueProvider zoomValueProvider; }; #endif // KIMAGEANNOTATOR_MOCKDEFAULTPARAMETERS_H kImageAnnotator-0.5.3/tests/mocks/MockDevicePixelRatioScaler.cpp000066400000000000000000000024041414424500400247260ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "MockDevicePixelRatioScaler.h" MockDevicePixelRatioScaler::MockDevicePixelRatioScaler() : mScaleFactor(1.0) { } QRectF MockDevicePixelRatioScaler::scale(const QRectF &rect) const { return {rect.left() * mScaleFactor, rect.top() * mScaleFactor, rect.width() * mScaleFactor, rect.height() * mScaleFactor}; } qreal MockDevicePixelRatioScaler::scaleFactor() const { return mScaleFactor; } void MockDevicePixelRatioScaler::setScaleFactor(qreal factor) { mScaleFactor = factor; } kImageAnnotator-0.5.3/tests/mocks/MockDevicePixelRatioScaler.h000066400000000000000000000025641414424500400244020ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_MOCKDEVICEPIXELRATIOSCALER_H #define KIMAGEANNOTATOR_MOCKDEVICEPIXELRATIOSCALER_H #include #include "src/common/provider/IDevicePixelRatioScaler.h" using kImageAnnotator::IDevicePixelRatioScaler; class MockDevicePixelRatioScaler : public IDevicePixelRatioScaler { public: MockDevicePixelRatioScaler(); ~MockDevicePixelRatioScaler() override = default; QRectF scale(const QRectF &rect) const override; qreal scaleFactor() const override; void setScaleFactor(qreal factor); private: qreal mScaleFactor; }; #endif //KIMAGEANNOTATOR_MOCKDEVICEPIXELRATIOSCALER_H kImageAnnotator-0.5.3/tests/mocks/MockSelectionRestrictor.cpp000066400000000000000000000021201414424500400243750ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "MockSelectionRestrictor.h" QRectF &MockSelectionRestrictor::restrictResize(QRectF &newRect, const QRectF ¤tRect, const QRectF &rectLimit) const { return newRect; } QRectF &MockSelectionRestrictor::restrictMove(QRectF &newRect, const QRectF &rectLimit) const { return newRect; } kImageAnnotator-0.5.3/tests/mocks/MockSelectionRestrictor.h000066400000000000000000000026341414424500400240540ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_MOCKSELECTIONRESTRICTOR_H #define KIMAGEANNOTATOR_MOCKSELECTIONRESTRICTOR_H #include #include "src/gui/selection/ISelectionRestrictor.h" using kImageAnnotator::ISelectionRestrictor; class MockSelectionRestrictor : public ISelectionRestrictor { public: explicit MockSelectionRestrictor() = default; ~MockSelectionRestrictor() override = default; QRectF &restrictResize(QRectF &newRect, const QRectF ¤tRect, const QRectF &rectLimit) const override; QRectF &restrictMove(QRectF &newRect, const QRectF &rectLimit) const override; }; #endif //KIMAGEANNOTATOR_MOCKSELECTIONRESTRICTOR_H kImageAnnotator-0.5.3/tests/mocks/MockSettingsProvider.cpp000066400000000000000000000051311414424500400237070ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "MockSettingsProvider.h" void MockSettingsProvider::editItem(AbstractAnnotationItem *item) { } void MockSettingsProvider::activateSelectTool() { } Tools MockSettingsProvider::toolType() const { return mToolType; } QColor MockSettingsProvider::toolColor() const { return mToolColor; } QColor MockSettingsProvider::textColor() const { return mTextColor; } int MockSettingsProvider::toolWidth() const { return mToolWidth; } QFont MockSettingsProvider::font() const { return mFont; } FillModes MockSettingsProvider::fillType() const { return mFillType; } int MockSettingsProvider::obfuscationFactor() const { return mBlurRadius; } void MockSettingsProvider::setToolType(Tools tool) { mToolType = tool; } void MockSettingsProvider::setToolColor(const QColor &toolColor) { mToolColor = toolColor; } void MockSettingsProvider::setTextColor(const QColor &textColor) { mTextColor = textColor; } void MockSettingsProvider::setToolWidth(int toolWidth) { mToolWidth = toolWidth; } void MockSettingsProvider::setFont(const QFont &font) { mFont = font; } void MockSettingsProvider::setFillType(FillModes fillMode) { mFillType = fillMode; } void MockSettingsProvider::setBlurRadius(int blurRadius) { mBlurRadius = blurRadius; } QString MockSettingsProvider::sticker() const { return mStickerPath; } ImageEffects MockSettingsProvider::effect() const { return ImageEffects::NoEffect; } bool MockSettingsProvider::shadowEnabled() const { return mShadowEnabled; } void MockSettingsProvider::setSticker(const QString &stickerPath) { mStickerPath = stickerPath; } void MockSettingsProvider::updateZoomLevel(double value) { mZoomLevel = value; } void MockSettingsProvider::updateNumberToolSeed(int numberToolSeed) { } void MockSettingsProvider::setShadowEnabled(bool enabled) { mShadowEnabled = enabled; } kImageAnnotator-0.5.3/tests/mocks/MockSettingsProvider.h000066400000000000000000000045301414424500400233560ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_MOCKSETTINGSPROVIDER_H #define KIMAGEANNOTATOR_MOCKSETTINGSPROVIDER_H #include "src/annotations/core/AbstractSettingsProvider.h" using kImageAnnotator::AbstractSettingsProvider; using kImageAnnotator::AbstractAnnotationItem; using kImageAnnotator::Tools; using kImageAnnotator::FillModes; using kImageAnnotator::ImageEffects; class MockSettingsProvider : public AbstractSettingsProvider { public: void editItem(AbstractAnnotationItem *item) override; void activateSelectTool() override; Tools toolType() const override; void setToolType(Tools tool); QColor toolColor() const override; void setToolColor(const QColor &toolColor); QColor textColor() const override; void setTextColor(const QColor &textColor); int toolWidth() const override; void setToolWidth(int toolWidth); QFont font() const override; void setFont(const QFont &font); FillModes fillType() const override; void setFillType(FillModes fillMode); int obfuscationFactor() const override; void setBlurRadius(int blurRadius); QString sticker() const override; void setSticker(const QString &stickerPath); ImageEffects effect() const override; bool shadowEnabled() const override; void setShadowEnabled(bool enabled); void updateNumberToolSeed(int numberToolSeed) override; void updateZoomLevel(double value) override; private: Tools mToolType; QColor mToolColor; QColor mTextColor; int mToolWidth; QFont mFont; FillModes mFillType; int mBlurRadius; QString mStickerPath; double mZoomLevel; bool mShadowEnabled; }; #endif //KIMAGEANNOTATOR_MOCKSETTINGSPROVIDER_H kImageAnnotator-0.5.3/tests/mocks/MockZoomValueProvider.cpp000066400000000000000000000022261414424500400240320ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "MockZoomValueProvider.h" MockZoomValueProvider::MockZoomValueProvider(QObject *parent) : ZoomValueProvider(parent), mZoomValue(1.0) { } double MockZoomValueProvider::zoomValue() const { return mZoomValue; } void MockZoomValueProvider::setZoomValue(double value) { if (value == mZoomValue) return; mZoomValue = value; emit zoomValueChanged(value); } kImageAnnotator-0.5.3/tests/mocks/MockZoomValueProvider.h000066400000000000000000000024211414424500400234740ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_MOCKZOOMVALUEPROVIDER_H #define KIMAGEANNOTATOR_MOCKZOOMVALUEPROVIDER_H #include "src/annotations/core/ZoomValueProvider.h" using kImageAnnotator::ZoomValueProvider; class MockZoomValueProvider : public ZoomValueProvider { Q_OBJECT public: explicit MockZoomValueProvider(QObject *parent = nullptr); double zoomValue() const override; void setZoomValue(double value) override; private: double mZoomValue; }; #endif // KIMAGEANNOTATOR_MOCKZOOMVALUEPROVIDER_H kImageAnnotator-0.5.3/tests/widgets/000077500000000000000000000000001414424500400174105ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/widgets/CustomSpinBoxTest.cpp000066400000000000000000000026101414424500400235300ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "CustomSpinBoxTest.h" void CustomSpinBoxTest::TestSetValue_Should_EmitValueChangedSignal() { auto newValue = 23; CustomSpinBox spinBox; QSignalSpy spy(&spinBox, &CustomSpinBox::valueChanged); spinBox.setValue(newValue); QCOMPARE(spy.count(), 1); auto resultValue = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultValue, newValue); } void CustomSpinBoxTest::TestSetValueSilent_Should_NotEmitValueChangedSignal() { CustomSpinBox spinBox; QSignalSpy spy(&spinBox, &CustomSpinBox::valueChanged); spinBox.setValueSilent(23); QCOMPARE(spy.count(), 0); } QTEST_MAIN(CustomSpinBoxTest); kImageAnnotator-0.5.3/tests/widgets/CustomSpinBoxTest.h000066400000000000000000000023101414424500400231720ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_CUSTOMSPINBOXTEST_H #define KIMAGEANNOTATOR_CUSTOMSPINBOXTEST_H #include #include "src/widgets/CustomSpinBox.h" using kImageAnnotator::CustomSpinBox; class CustomSpinBoxTest : public QObject { Q_OBJECT private slots: void TestSetValue_Should_EmitValueChangedSignal(); void TestSetValueSilent_Should_NotEmitValueChangedSignal(); }; #endif // KIMAGEANNOTATOR_CUSTOMSPINBOXTEST_H kImageAnnotator-0.5.3/tests/widgets/misc/000077500000000000000000000000001414424500400203435ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/widgets/misc/AttachedSeparatorTest.cpp000066400000000000000000000050421414424500400253060ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AttachedSeparatorTest.h" void AttachedSeparatorTest::Constructor_Should_SetupInitialVisibilityToFalse_When_TargetPickerInitiallyNotVisible() { // arrange BoolPicker picker(nullptr); picker.setVisible(false); // act AttachedSeparator separator(&picker); // assert QCOMPARE(separator.isVisible(), false); } void AttachedSeparatorTest::Constructor_Should_SetupInitialVisibilityToTrue_When_TargetPickerInitiallyVisible() { // arrange BoolPicker picker(nullptr); picker.setVisible(true); // act AttachedSeparator separator(&picker); // assert QCOMPARE(separator.isVisible(), true); } void AttachedSeparatorTest::UpdateVisibility_Should_ChangeVisibility_When_TargetPickerVisibilityChanged() { // arrange BoolPicker picker(nullptr); picker.setVisible(true); AttachedSeparator separator(&picker); QCOMPARE(separator.isVisible(), true); // act picker.setVisible(false); // assert QCOMPARE(separator.isVisible(), false); } void AttachedSeparatorTest::UpdateVisibility_Should_NotChangeVisibility_When_TargetPickerVisibilityChangedButSeparatorIsDisabled() { // arrange BoolPicker picker(nullptr); picker.setVisible(false); AttachedSeparator separator(&picker); QCOMPARE(separator.isVisible(), false); separator.setEnabled(false); // act picker.setVisible(true); // assert QCOMPARE(separator.isVisible(), false); } void AttachedSeparatorTest::SetEnabled_Should_UpdateVisibilityToFalse_When_Disabled() { // arrange BoolPicker picker(nullptr); picker.setVisible(true); AttachedSeparator separator(&picker); QCOMPARE(separator.isVisible(), true); // act separator.setEnabled(false); separator.setEnabled(false); // assert QCOMPARE(separator.isVisible(), false); QCOMPARE(picker.isVisible(), true); } QTEST_MAIN(AttachedSeparatorTest) kImageAnnotator-0.5.3/tests/widgets/misc/AttachedSeparatorTest.h000066400000000000000000000032101414424500400247460ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ATTACHEDSEPARATORTEST_H #define KIMAGEANNOTATOR_ATTACHEDSEPARATORTEST_H #include #include "src/widgets/misc/AttachedSeparator.h" #include "src/widgets/settingsPicker/BoolPicker.h" using kImageAnnotator::AttachedSeparator; using kImageAnnotator::BoolPicker; class AttachedSeparatorTest : public QObject { Q_OBJECT private slots: void Constructor_Should_SetupInitialVisibilityToFalse_When_TargetPickerInitiallyNotVisible(); void Constructor_Should_SetupInitialVisibilityToTrue_When_TargetPickerInitiallyVisible(); void UpdateVisibility_Should_ChangeVisibility_When_TargetPickerVisibilityChanged(); void UpdateVisibility_Should_NotChangeVisibility_When_TargetPickerVisibilityChangedButSeparatorIsDisabled(); void SetEnabled_Should_UpdateVisibilityToFalse_When_Disabled(); }; #endif //KIMAGEANNOTATOR_ATTACHEDSEPARATORTEST_H kImageAnnotator-0.5.3/tests/widgets/settingsPicker/000077500000000000000000000000001414424500400224065ustar00rootroot00000000000000kImageAnnotator-0.5.3/tests/widgets/settingsPicker/ColorPickerTest.cpp000066400000000000000000000023641414424500400261730ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ColorPickerTest.h" void ColorPickerTest::TestSelectColor_Should_EmitSignal_When_ColorChanged() { ColorPicker colorPicker(nullptr); QSignalSpy spy(&colorPicker, &ColorPicker::colorSelected); auto expectedColor = QColor(Qt::blue); colorPicker.setColor(expectedColor); QCOMPARE(spy.count(), 1); auto resultColor = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultColor, expectedColor); } QTEST_MAIN(ColorPickerTest); kImageAnnotator-0.5.3/tests/widgets/settingsPicker/ColorPickerTest.h000066400000000000000000000022321414424500400256320ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_COLORPICKERTEST_H #define KIMAGEANNOTATOR_COLORPICKERTEST_H #include #include "src/widgets/settingsPicker/ColorPicker.h" using kImageAnnotator::ColorPicker; class ColorPickerTest : public QObject { Q_OBJECT private slots: void TestSelectColor_Should_EmitSignal_When_ColorChanged(); }; #endif // KIMAGEANNOTATOR_COLORPICKERTEST_H kImageAnnotator-0.5.3/tests/widgets/settingsPicker/FillModePickerTest.cpp000066400000000000000000000024371414424500400266110ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "FillModePickerTest.h" void FillModePickerTest::TestSelectFill_Should_EmitSignal_When_FillChanged() { qRegisterMetaType("FillModes"); FillModePicker fillPicker(nullptr); QSignalSpy spy(&fillPicker, &FillModePicker::fillSelected); auto expectedFill = FillModes::BorderAndNoFill; fillPicker.setFillType(expectedFill); QCOMPARE(spy.count(), 1); auto resultFill = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultFill, expectedFill); } QTEST_MAIN(FillModePickerTest); kImageAnnotator-0.5.3/tests/widgets/settingsPicker/FillModePickerTest.h000066400000000000000000000022751414424500400262560ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_FILLPICKERTEST_H #define KIMAGEANNOTATOR_FILLPICKERTEST_H #include #include "src/widgets/settingsPicker/FillModePicker.h" using kImageAnnotator::FillModePicker; using kImageAnnotator::FillModes; class FillModePickerTest : public QObject { Q_OBJECT private slots: void TestSelectFill_Should_EmitSignal_When_FillChanged(); }; #endif // KIMAGEANNOTATOR_FILLPICKERTEST_H kImageAnnotator-0.5.3/tests/widgets/settingsPicker/ImageEffectPickerTest.cpp000066400000000000000000000024671414424500400272600ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ImageEffectPickerTest.h" void ImageEffectPickerTest::TestSelectEffect_Should_EmitSignal_When_EffectChanged() { qRegisterMetaType("ImageEffects"); ImageEffectPicker effectPicker(nullptr); QSignalSpy spy(&effectPicker, &ImageEffectPicker::effectSelected); auto expectedEffect = ImageEffects::DropShadow; effectPicker.setEffect(expectedEffect); QCOMPARE(spy.count(), 1); auto resultFill = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultFill, expectedEffect); } QTEST_MAIN(ImageEffectPickerTest); kImageAnnotator-0.5.3/tests/widgets/settingsPicker/ImageEffectPickerTest.h000066400000000000000000000023231414424500400267140ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_IMAGEEFFECTPICKERTEST_H #define KIMAGEANNOTATOR_IMAGEEFFECTPICKERTEST_H #include #include "src/widgets/settingsPicker/ImageEffectPicker.h" using kImageAnnotator::ImageEffectPicker; using kImageAnnotator::ImageEffects; class ImageEffectPickerTest : public QObject { Q_OBJECT private slots: void TestSelectEffect_Should_EmitSignal_When_EffectChanged(); }; #endif //KIMAGEANNOTATOR_IMAGEEFFECTPICKERTEST_H kImageAnnotator-0.5.3/tests/widgets/settingsPicker/NumberPickerTest.cpp000066400000000000000000000023431414424500400263420ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "NumberPickerTest.h" void NumberPickerTest::TestSelectNumber_Should_EmitSignal_When_NumberChanged() { NumberPicker sizePicker(nullptr); QSignalSpy spy(&sizePicker, &NumberPicker::numberSelected); auto expectedSize = 8; sizePicker.setNumber(expectedSize); QCOMPARE(spy.count(), 1); auto resultSize = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultSize, expectedSize); } QTEST_MAIN(NumberPickerTest); kImageAnnotator-0.5.3/tests/widgets/settingsPicker/NumberPickerTest.h000066400000000000000000000022371414424500400260110ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_NUMBERPICKERTEST_H #define KIMAGEANNOTATOR_NUMBERPICKERTEST_H #include #include "src/widgets/settingsPicker/NumberPicker.h" using kImageAnnotator::NumberPicker; class NumberPickerTest : public QObject { Q_OBJECT private slots: void TestSelectNumber_Should_EmitSignal_When_NumberChanged(); }; #endif // KIMAGEANNOTATOR_NUMBERPICKERTEST_H kImageAnnotator-0.5.3/tests/widgets/settingsPicker/StickerPickerTest.cpp000066400000000000000000000024231414424500400265150ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "StickerPickerTest.h" void StickerPickerTest::TestSelectSticker_Should_EmitSignal_When_StickerChanged() { StickerPicker stickerPicker(nullptr); QSignalSpy spy(&stickerPicker, &StickerPicker::stickerSelected); auto expectedStickerPath = QLatin1Literal(":/stickers/nerd_face.svg"); stickerPicker.setSticker(expectedStickerPath); QCOMPARE(spy.count(), 1); auto resultSize = qvariant_cast(spy.at(0).at(0)); QCOMPARE(resultSize, expectedStickerPath); } QTEST_MAIN(StickerPickerTest);kImageAnnotator-0.5.3/tests/widgets/settingsPicker/StickerPickerTest.h000066400000000000000000000022301414424500400261560ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_STICKERPICKERTEST_H #define KIMAGEANNOTATOR_STICKERPICKERTEST_H #include #include "src/widgets/settingsPicker/StickerPicker.h" using kImageAnnotator::StickerPicker; class StickerPickerTest : public QObject { Q_OBJECT private slots: void TestSelectSticker_Should_EmitSignal_When_StickerChanged(); }; #endif //KIMAGEANNOTATOR_STICKERPICKERTEST_H kImageAnnotator-0.5.3/tests/widgets/settingsPicker/ToolPickerTest.cpp000066400000000000000000000026061414424500400260310ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ToolPickerTest.h" void ToolPickerTest::TestSelectTool_Should_EmitSignal_When_ToolChanged() { qRegisterMetaType("Tools"); ToolPicker toolPicker(nullptr); QSignalSpy spy(&toolPicker, &ToolPicker::toolSelected); toolPicker.setTool(Tools::Arrow); QCOMPARE(spy.count(), 1); auto type = qvariant_cast(spy.at(0).at(0)); QCOMPARE(type, Tools::Arrow); } void ToolPickerTest::TestTool_Should_ReturnSelectedTool() { ToolPicker toolPicker(nullptr); toolPicker.setTool(Tools::Arrow); auto result = toolPicker.tool(); QCOMPARE(result, Tools::Arrow); } QTEST_MAIN(ToolPickerTest); kImageAnnotator-0.5.3/tests/widgets/settingsPicker/ToolPickerTest.h000066400000000000000000000023541414424500400254760ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_TOOLPICKERTEST_H #define KIMAGEANNOTATOR_TOOLPICKERTEST_H #include #include "src/widgets/ToolPicker.h" #include "src/common/enum/Tools.h" using kImageAnnotator::ToolPicker; using kImageAnnotator::Tools; class ToolPickerTest : public QObject { Q_OBJECT private slots: void TestSelectTool_Should_EmitSignal_When_ToolChanged(); void TestTool_Should_ReturnSelectedTool(); }; #endif // KIMAGEANNOTATOR_TOOLPICKERTEST_H kImageAnnotator-0.5.3/tests/widgets/settingsPicker/ZoomPickerTest.cpp000066400000000000000000000021061414424500400260330ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ZoomPickerTest.h" void ZoomPickerTest::SetZoomValue_Should_NotEmitSignalForChangedZoomValue() { ZoomPicker zoomIndicator(nullptr); QSignalSpy spy(&zoomIndicator, &ZoomPicker::zoomValueChanged); zoomIndicator.setZoomValue(7.77); QCOMPARE(spy.count(), 0); } QTEST_MAIN(ZoomPickerTest); kImageAnnotator-0.5.3/tests/widgets/settingsPicker/ZoomPickerTest.h000066400000000000000000000022021414424500400254750ustar00rootroot00000000000000/* * Copyright (C) 2020 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ZOOMPICKERTEST_H #define KIMAGEANNOTATOR_ZOOMPICKERTEST_H #include #include "src/widgets/settingsPicker/ZoomPicker.h" using kImageAnnotator::ZoomPicker; class ZoomPickerTest : public QObject { Q_OBJECT private slots: void SetZoomValue_Should_NotEmitSignalForChangedZoomValue(); }; #endif //KIMAGEANNOTATOR_ZOOMPICKERTEST_H kImageAnnotator-0.5.3/translations/000077500000000000000000000000001414424500400173215ustar00rootroot00000000000000kImageAnnotator-0.5.3/translations/CMakeLists.txt000066400000000000000000000021271414424500400220630ustar00rootroot00000000000000find_package(Qt5LinguistTools) set(KIMAGEANNOTATOR_LANG_TS kImageAnnotator_cs.ts kImageAnnotator_da.ts kImageAnnotator_de.ts kImageAnnotator_el.ts kImageAnnotator_es.ts kImageAnnotator_eu.ts kImageAnnotator_fr.ts kImageAnnotator_fr_CA.ts kImageAnnotator_gl.ts kImageAnnotator_hr.ts kImageAnnotator_hu.ts kImageAnnotator_id.ts kImageAnnotator_it.ts kImageAnnotator_ja.ts kImageAnnotator_nl.ts kImageAnnotator_no.ts kImageAnnotator_pl.ts kImageAnnotator_pt.ts kImageAnnotator_pt_BR.ts kImageAnnotator_ro.ts kImageAnnotator_ru.ts kImageAnnotator_si.ts kImageAnnotator_sv.ts kImageAnnotator_tr.ts kImageAnnotator_uk.ts kImageAnnotator_zh_CN.ts) if (DEFINED UPDATE_TS_FILES) qt5_create_translation(KIMAGEANNOTATOR_LANG_QM ${CMAKE_SOURCE_DIR}/translations ${KIMAGEANNOTATOR_SRCS} ${KIMAGEANNOTATOR_LANG_TS} OPTIONS "-no-obsolete") else () qt5_add_translation(KIMAGEANNOTATOR_LANG_QM ${KIMAGEANNOTATOR_LANG_TS}) endif () add_custom_target(translations ALL DEPENDS ${KIMAGEANNOTATOR_LANG_QM}) install(FILES ${KIMAGEANNOTATOR_LANG_QM} DESTINATION ${KIMAGEANNOTATOR_LANG_INSTALL_DIR}) kImageAnnotator-0.5.3/translations/kImageAnnotator_cs.ts000066400000000000000000000322001414424500400234360ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Bring to Front Bring Forward Send Backward Send to Back Select This Copy Paste Edit Delete kImageAnnotator::AnnotationGeneralSettings General Settings kImageAnnotator::AnnotationImageSettings Image Settings kImageAnnotator::AnnotationItemSettings Color Text Color Width Number Seed Obfuscation Factor Item Shadow Item Settings kImageAnnotator::AnnotationTabContextMenu Close Close Other Close All Close All to the Left Close All to the Right kImageAnnotator::AnnotationToolSelection Tool Selection kImageAnnotator::BoolPicker Enabled Disabled kImageAnnotator::CropWidget Cancel X: Y: W: H: Apply kImageAnnotator::FillModePicker Border And Fill Visibility Border and Fill Border and No Fill No Border and No Fill kImageAnnotator::FontPicker Font Size Bold Italic Underline kImageAnnotator::ImageEffectPicker Image Effects No Effect Drop Shadow Grayscale Border Invert Color kImageAnnotator::ModifyCanvasWidget Restricted When enabled enforces the canvas to include the background image. X: Y: W: H: Apply Cancel Color: Canvas Background Color kImageAnnotator::RotateDialog Rotate Image 180° 90° Clockwise 90° Counter Clockwise Arbitrary Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Horizontal Vertical OK Cancel Rotate Flip kImageAnnotator::ScaleDialog Scale Image Keep Aspect Ratio Width: Height: OK Cancel Pixel Percent kImageAnnotator::StickerPicker Sticker kImageAnnotator::ToolPicker Select Pen Number Marker Rectangle Marker Ellipse Marker Pen Text Arrow Double Arrow Line Blur Rectangle Ellipse Number Pointer Sticker Pixelate Text Pointer Text Arrow Number Arrow Duplicate kImageAnnotator::ZoomPicker Zoom In (%1) Zoom Out (%1) Reset Zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_da.ts000066400000000000000000000322001414424500400234150ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Bring to Front Bring Forward Send Backward Send to Back Select This Copy Paste Edit Delete kImageAnnotator::AnnotationGeneralSettings General Settings kImageAnnotator::AnnotationImageSettings Image Settings kImageAnnotator::AnnotationItemSettings Color Text Color Width Number Seed Obfuscation Factor Item Shadow Item Settings kImageAnnotator::AnnotationTabContextMenu Close Close Other Close All Close All to the Left Close All to the Right kImageAnnotator::AnnotationToolSelection Tool Selection kImageAnnotator::BoolPicker Enabled Disabled kImageAnnotator::CropWidget Cancel X: Y: W: H: Apply kImageAnnotator::FillModePicker Border And Fill Visibility Border and Fill Border and No Fill No Border and No Fill kImageAnnotator::FontPicker Font Size Bold Italic Underline kImageAnnotator::ImageEffectPicker Image Effects No Effect Drop Shadow Grayscale Border Invert Color kImageAnnotator::ModifyCanvasWidget Restricted When enabled enforces the canvas to include the background image. X: Y: W: H: Apply Cancel Color: Canvas Background Color kImageAnnotator::RotateDialog Rotate Image 180° 90° Clockwise 90° Counter Clockwise Arbitrary Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Horizontal Vertical OK Cancel Rotate Flip kImageAnnotator::ScaleDialog Scale Image Keep Aspect Ratio Width: Height: OK Cancel Pixel Percent kImageAnnotator::StickerPicker Sticker kImageAnnotator::ToolPicker Select Pen Number Marker Rectangle Marker Ellipse Marker Pen Text Arrow Double Arrow Line Blur Rectangle Ellipse Number Pointer Sticker Pixelate Text Pointer Text Arrow Number Arrow Duplicate kImageAnnotator::ZoomPicker Zoom In (%1) Zoom Out (%1) Reset Zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_de.ts000066400000000000000000000313601414424500400234270ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Anordnen Bring to Front Ganz nach vorn Bring Forward Nach vorn Send Backward Nach hinten Send to Back Ganz nach hinten Select This Dieses auswählen Copy Kopieren Paste Einfügen Edit Ändern Delete Löschen kImageAnnotator::AnnotationGeneralSettings General Settings Allgemeine Einstellungen kImageAnnotator::AnnotationImageSettings Image Settings Bild Einstellungen kImageAnnotator::AnnotationItemSettings Color Farbe Text Color Textfarbe Width Breite Number Seed Nummerierung ab Obfuscation Factor Unschärfe Faktor Item Shadow Objekt-Schatten Item Settings Objekt-Einstellungen kImageAnnotator::AnnotationTabContextMenu Close Schließen Close Other Andere schließen Close All Alle schließen Close All to the Left Alle linksseitig schließen Close All to the Right Alle rechtsseitig schließen kImageAnnotator::AnnotationToolSelection Tool Selection Werkzeugauswahl kImageAnnotator::BoolPicker Enabled Aktiviert Disabled Deaktiviert kImageAnnotator::CropWidget Cancel Abbrechen X: X: Y: Y: W: B: H: H: Apply Anwenden kImageAnnotator::FillModePicker Border And Fill Visibility Sichtbarkeit von Rahmen und Füllungen Border and Fill Rahmen und Füllung Border and No Fill Rahmen und keine Füllung No Border and No Fill Kein Rahmen und keine Füllung kImageAnnotator::FontPicker Font Size Schriftgröße Bold Fett Italic Kursiv Underline Unterstrichen kImageAnnotator::ImageEffectPicker Image Effects Bild-Effekte No Effect Kein Effekt Drop Shadow Schlagschatten Grayscale Graustufen Border Rand Invert Color Farbe invertieren kImageAnnotator::ModifyCanvasWidget Restricted Gesperrt When enabled enforces the canvas to include the background image. Wenn aktiviert, wird erzwungen, dass die Zeichenfläche das Hintergrundbild beinhaltet. X: X: Y: Y: W: B: H: H: Apply Anwenden Cancel Abbrechen Color: Farbe: Canvas Background Color Hintergrundfarbe der Zeichenfläche kImageAnnotator::RotateDialog Rotate Image Bild drehen 180° 180° 90° Clockwise 90° im Uhrzeigersinn 90° Counter Clockwise 90° gegen den Uhrzeigersinn Arbitrary Beliebig Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Positive Werte rotieren im Uhrzeigersinn, negative Werte gegen den Uhrzeigersinn. Das Drehen um nicht 90°-Multiplikatoren kann zu Qualitätsverlusten führen. Horizontal Horizontal Vertical Vertikal OK OK Cancel Abbrechen Rotate Drehen Flip Umdrehen kImageAnnotator::ScaleDialog Scale Image Bild skalieren Keep Aspect Ratio Seitenverhältnis beibehalten Width: Breite: Height: Höhe: OK OK Cancel Abbrechen Pixel Pixel Percent Prozentzahl kImageAnnotator::StickerPicker Sticker Aufkleber kImageAnnotator::ToolPicker Select Auswählen Pen Stift Number Nummer Marker Rectangle Rechteckige Markierung Marker Ellipse Ellipsen Markierung Marker Pen Stift Markierung Text Text Arrow Pfeil Double Arrow Doppelpfeil Line Strich Blur Verschwommenheit Rectangle Rechteck Ellipse Ellipse Number Pointer Nummer mit Zeiger Sticker Aufkleber Pixelate Verpixelung Text Pointer Sprechblase Text Arrow Text mit Pfeil Number Arrow Nummer mit Pfeil Duplicate Duplizieren kImageAnnotator::ZoomPicker Zoom In (%1) Vergrößern (%1) Zoom Out (%1) Verkleinern (%1) Reset Zoom (%1) Zoom zurücksetzen (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_el.ts000066400000000000000000000344171414424500400234450ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Διάταξη Bring to Front Μετακίνηση στο προσκήνιο Bring Forward Μετακίνηση προς τα εμπρός Send Backward Μετακίνηση προς τα πίσω Send to Back Μετακίνηση στο παρασκήνιο Select This Επιλογή Copy Αντιγραφή Paste Επικόλληση Edit Επεξεργασία Delete Διαγραφή kImageAnnotator::AnnotationGeneralSettings General Settings Γενικές ρυθμίσεις kImageAnnotator::AnnotationImageSettings Image Settings Ρυθμίσεις εικόνας kImageAnnotator::AnnotationItemSettings Color Χρώμα Text Color Χρώμα κειμένου Width Πλάτος Number Seed Αρχικός αριθμός Obfuscation Factor Συντελεστής θόλωσης Item Shadow Σκιά αντικειμένου Item Settings Ρυθμίσεις αντικειμένου kImageAnnotator::AnnotationTabContextMenu Close Κλείσιμο Close Other Κλείσιμο των άλλων Close All Κλείσιμο όλων Close All to the Left Κλείσιμο όλων στα αριστερά Close All to the Right Κλείσιμο όλων στα δεξιά kImageAnnotator::AnnotationToolSelection Tool Selection Επιλογή εργαλείου kImageAnnotator::BoolPicker Enabled Ενεργοποιημένο Disabled Απενεργοποιημένο kImageAnnotator::CropWidget Cancel Άκυρο X: X: Y: Y: W: Π: H: Υ: Apply Εφαρμογή kImageAnnotator::FillModePicker Border And Fill Visibility Ορατότητα περιγράμματος και γέμισης Border and Fill Περίγραμμα και γέμιση Border and No Fill Περίγραμμα χωρίς γέμιση No Border and No Fill Χωρίς περίγραμμα και χωρίς γέμιση kImageAnnotator::FontPicker Font Size Μέγεθος γραμματοσειράς Bold Έντονα Italic Πλάγια Underline Υπογράμμιση kImageAnnotator::ImageEffectPicker Image Effects Τεχνάσματα εικόνας No Effect Κανένα τέχνασμα Drop Shadow Σκίαση Grayscale Διαβαθμίσεις του γκρι Border Περίγραμμα Invert Color Αντιστροφή χρωμάτων kImageAnnotator::ModifyCanvasWidget Restricted Με περιορισμούς When enabled enforces the canvas to include the background image. Όταν είναι ενεργοποιημένο, εξαναγκάζει τον καμβά να συμπεριλάβει την εικόνα παρασκηνίου. X: X: Y: Y: W: Π: H: Υ: Apply Εφαρμογή Cancel Ακύρωση Color: Χρώμα: Canvas Background Color Χρώμα παρασκηνίου του καμβά kImageAnnotator::RotateDialog Rotate Image Περιστροφή εικόνας 180° 180° 90° Clockwise 90° Δεξιόστροφα 90° Counter Clockwise 90° Αριστερόστροφα Arbitrary Αυθαίρετα Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Οι θετικές τιμές περιστρέφουν σύμφωνα με τους δείκτες του ρολογιού, και οι αρνητικές τιμές αντίστροφα. Η περιστροφή με πολλαπλασιαστές διαφορετικούς των 90° μπορεί να προκαλέσει απώλεια στην ποιότητα. Horizontal Οριζόντια Vertical Κατακόρυφα OK Εντάξει Cancel Ακύρωση Rotate Περιστροφή Flip Αναστροφή kImageAnnotator::ScaleDialog Scale Image Κλιμάκωση της εικόνας Keep Aspect Ratio Διατήρηση της αναλογίας διαστάσεων Width: Πλάτος: Height: Ύψος: OK Εντάξει Cancel Άκυρο Pixel Εικονοστοιχείο Percent Ποσοστό kImageAnnotator::StickerPicker Sticker Αυτοκόλλητο kImageAnnotator::ToolPicker Select Επιλογή Pen Γραφίδα Number Αριθμός Marker Rectangle Σημαδευτής ορθογωνίου Marker Ellipse Σημαδευτής έλλειψης Marker Pen Σημαδευτής γραφίδας Text Κείμενο Arrow Βέλος Double Arrow Διπλό βέλος Line Γραμμή Blur Θόλωση Rectangle Ορθογώνιο Ellipse Έλλειψη Number Pointer Δρομέας αριθμού Sticker Αυτοκόλλητο Pixelate Παραμόρφωση εικονοστοιχείων Text Pointer Δρομέας κειμένου Text Arrow Βέλος κειμένου Number Arrow Βέλος αριθμού Duplicate Δημιουργία αντιγράφου kImageAnnotator::ZoomPicker Zoom In (%1) Μεγέθυνση (%1) Zoom Out (%1) Σμίκρυνση (%1) Reset Zoom (%1) Επαναφορά εστίασης (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_es.ts000066400000000000000000000316461414424500400234550ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Organizar Bring to Front Traer al frente Bring Forward Traer adelante Send Backward Enviar atrás Send to Back Enviar al fondo Select This Seleccionar esto Copy Copiar Paste Pegar Edit Editar Delete Eliminar kImageAnnotator::AnnotationGeneralSettings General Settings kImageAnnotator::AnnotationImageSettings Image Settings kImageAnnotator::AnnotationItemSettings Color Color Text Color Color de texto Width Anchura Number Seed Obfuscation Factor Item Shadow Item Settings kImageAnnotator::AnnotationTabContextMenu Close Cerrar Close Other Cerrar otros Close All Cerrar todo Close All to the Left Cerrar todos a la izquierda Close All to the Right Cerrar todos a la derecha kImageAnnotator::AnnotationToolSelection Tool Selection kImageAnnotator::BoolPicker Enabled Disabled kImageAnnotator::CropWidget Cancel Cancelar X: X: Y: Y: W: ↔: H: ↕: Apply kImageAnnotator::FillModePicker Border And Fill Visibility Visibilidad de borde y relleno No Border and No Fill Sin borde ni relleno Border and Fill Borde y relleno Border and No Fill Borde sin relleno kImageAnnotator::FontPicker Font Size Tamaño de letra Bold Italic Underline kImageAnnotator::ImageEffectPicker Image Effects No Effect Drop Shadow Grayscale Border Invert Color kImageAnnotator::ModifyCanvasWidget Restricted When enabled enforces the canvas to include the background image. X: X: Y: Y: W: ↔: H: ↕: Apply Cancel Cancelar Color: Canvas Background Color kImageAnnotator::RotateDialog Rotate Image 180° 90° Clockwise 90° Counter Clockwise Arbitrary Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Horizontal Vertical OK Aceptar Cancel Cancelar Rotate Flip kImageAnnotator::ScaleDialog Scale Image Redimensionar imagen Keep Aspect Ratio Mantener relación de aspecto Width: Anchura: Height: Altura: OK Aceptar Cancel Cancelar Pixel Píxel Percent Porcentaje kImageAnnotator::StickerPicker Sticker Adhesivo kImageAnnotator::ToolPicker Select Seleccionar Pen Pluma Number Número Marker Rectangle Marcador, rectángulo Marker Ellipse Marcador, elipse Marker Pen Marcador, pluma Text Texto Arrow Flecha Double Arrow Flecha doble Line Línea Blur Desenfoque Rectangle Rectángulo Ellipse Elipse Number Pointer Apuntador numérico Sticker Adhesivo Pixelate Text Pointer Text Arrow Number Arrow Duplicate kImageAnnotator::ZoomPicker Zoom In (%1) Zoom Out (%1) Reset Zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_eu.ts000066400000000000000000000322001414424500400234420ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Bring to Front Bring Forward Send Backward Send to Back Select This Copy Paste Edit Delete kImageAnnotator::AnnotationGeneralSettings General Settings kImageAnnotator::AnnotationImageSettings Image Settings kImageAnnotator::AnnotationItemSettings Color Text Color Width Number Seed Obfuscation Factor Item Shadow Item Settings kImageAnnotator::AnnotationTabContextMenu Close Close Other Close All Close All to the Left Close All to the Right kImageAnnotator::AnnotationToolSelection Tool Selection kImageAnnotator::BoolPicker Enabled Disabled kImageAnnotator::CropWidget Cancel X: Y: W: H: Apply kImageAnnotator::FillModePicker Border And Fill Visibility Border and Fill Border and No Fill No Border and No Fill kImageAnnotator::FontPicker Font Size Bold Italic Underline kImageAnnotator::ImageEffectPicker Image Effects No Effect Drop Shadow Grayscale Border Invert Color kImageAnnotator::ModifyCanvasWidget Restricted When enabled enforces the canvas to include the background image. X: Y: W: H: Apply Cancel Color: Canvas Background Color kImageAnnotator::RotateDialog Rotate Image 180° 90° Clockwise 90° Counter Clockwise Arbitrary Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Horizontal Vertical OK Cancel Rotate Flip kImageAnnotator::ScaleDialog Scale Image Keep Aspect Ratio Width: Height: OK Cancel Pixel Percent kImageAnnotator::StickerPicker Sticker kImageAnnotator::ToolPicker Select Pen Number Marker Rectangle Marker Ellipse Marker Pen Text Arrow Double Arrow Line Blur Rectangle Ellipse Number Pointer Sticker Pixelate Text Pointer Text Arrow Number Arrow Duplicate kImageAnnotator::ZoomPicker Zoom In (%1) Zoom Out (%1) Reset Zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_fr.ts000066400000000000000000000321151414424500400234450ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Disposer Bring to Front Envoyer à l'avant Bring Forward Envoyer vers l'avant Send Backward Envoyer vers l'arrière Send to Back Envoyer à l'arrière Select This Sélectionner ceci Copy Copier Paste Coller Edit Modifier Delete Supprimer kImageAnnotator::AnnotationGeneralSettings General Settings kImageAnnotator::AnnotationImageSettings Image Settings kImageAnnotator::AnnotationItemSettings Color Couleur Text Color Couleur du texte Width Largeur Number Seed Obfuscation Factor Facteur d'obfuscation Item Shadow Item Settings kImageAnnotator::AnnotationTabContextMenu Close Fermer Close Other Fermer les autres Close All Tout fermer Close All to the Left Fermer tous ceux de gauche Close All to the Right Fermer tous ceux de droite kImageAnnotator::AnnotationToolSelection Tool Selection kImageAnnotator::BoolPicker Enabled Disabled kImageAnnotator::CropWidget Cancel Annuler X: X : Y: Y : W: L : H: H : Apply Appliquer kImageAnnotator::FillModePicker Border And Fill Visibility Visibilité de la bordure et du remplissage Border and Fill Bordure et remplissage Border and No Fill Bordure sans remplissage No Border and No Fill Ni bordure ni remplissage kImageAnnotator::FontPicker Font Size Taille de la police Bold Italic Underline kImageAnnotator::ImageEffectPicker Image Effects Effets d'image No Effect Aucun effet Drop Shadow Ombre portée Grayscale Niveaux de gris Border Bordure Invert Color kImageAnnotator::ModifyCanvasWidget Restricted Restreint When enabled enforces the canvas to include the background image. Si activé, applique le canevas pour inclure l’image d'arrière-plan. X: X : Y: Y : W: L : H: H : Apply Appliquer Cancel Annuler Color: Couleur : Canvas Background Color kImageAnnotator::RotateDialog Rotate Image Pivoter l'image 180° 180° 90° Clockwise 90° horaire 90° Counter Clockwise 90° anti-horaire Arbitrary Aléatoirement Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Les valeurs positives tournent dans le sens des aiguilles d'une montre, les valeurs négatives dans le sens inverse. La rotation par des multiplicateurs autres que 90° peut entraîner une perte de qualité. Horizontal Horizontale Vertical Verticale OK OK Cancel Annuler Rotate Pivoter Flip Retourner kImageAnnotator::ScaleDialog Scale Image Redimensionner l'image Keep Aspect Ratio Conserver le ratio Width: Largeur : Height: Hauteur : OK OK Cancel Annuler Pixel Pixel Percent Pourcentage kImageAnnotator::StickerPicker Sticker Autocollant kImageAnnotator::ToolPicker Select Sélectionner Pen Crayon Number Numéro Marker Rectangle Marqueur rectangle Marker Ellipse Marqueur ellipse Marker Pen Surligneur Text Texte Arrow Flèche Double Arrow Flèche double Line Ligne Blur Flou Rectangle Rectangle Ellipse Ellipse Number Pointer Pointeur de numéro Sticker Autocollant Pixelate Pixéliser Text Pointer Pointeur de texte Text Arrow Flèche de texte Number Arrow Flèche de nombre Duplicate Dupliquer kImageAnnotator::ZoomPicker Zoom In (%1) Zoom avant (%1) Zoom Out (%1) Zoom arrière (%1) Reset Zoom (%1) Réinitialiser le zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_fr_CA.ts000066400000000000000000000322001414424500400240030ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Bring to Front Bring Forward Send Backward Send to Back Select This Copy Paste Edit Delete kImageAnnotator::AnnotationGeneralSettings General Settings kImageAnnotator::AnnotationImageSettings Image Settings kImageAnnotator::AnnotationItemSettings Color Text Color Width Number Seed Obfuscation Factor Item Shadow Item Settings kImageAnnotator::AnnotationTabContextMenu Close Close Other Close All Close All to the Left Close All to the Right kImageAnnotator::AnnotationToolSelection Tool Selection kImageAnnotator::BoolPicker Enabled Disabled kImageAnnotator::CropWidget Cancel X: Y: W: H: Apply kImageAnnotator::FillModePicker Border And Fill Visibility Border and Fill Border and No Fill No Border and No Fill kImageAnnotator::FontPicker Font Size Bold Italic Underline kImageAnnotator::ImageEffectPicker Image Effects No Effect Drop Shadow Grayscale Border Invert Color kImageAnnotator::ModifyCanvasWidget Restricted When enabled enforces the canvas to include the background image. X: Y: W: H: Apply Cancel Color: Canvas Background Color kImageAnnotator::RotateDialog Rotate Image 180° 90° Clockwise 90° Counter Clockwise Arbitrary Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Horizontal Vertical OK Cancel Rotate Flip kImageAnnotator::ScaleDialog Scale Image Keep Aspect Ratio Width: Height: OK Cancel Pixel Percent kImageAnnotator::StickerPicker Sticker kImageAnnotator::ToolPicker Select Pen Number Marker Rectangle Marker Ellipse Marker Pen Text Arrow Double Arrow Line Blur Rectangle Ellipse Number Pointer Sticker Pixelate Text Pointer Text Arrow Number Arrow Duplicate kImageAnnotator::ZoomPicker Zoom In (%1) Zoom Out (%1) Reset Zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_gl.ts000066400000000000000000000322001414424500400234330ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Bring to Front Bring Forward Send Backward Send to Back Select This Copy Paste Edit Delete kImageAnnotator::AnnotationGeneralSettings General Settings kImageAnnotator::AnnotationImageSettings Image Settings kImageAnnotator::AnnotationItemSettings Color Text Color Width Number Seed Obfuscation Factor Item Shadow Item Settings kImageAnnotator::AnnotationTabContextMenu Close Close Other Close All Close All to the Left Close All to the Right kImageAnnotator::AnnotationToolSelection Tool Selection kImageAnnotator::BoolPicker Enabled Disabled kImageAnnotator::CropWidget Cancel X: Y: W: H: Apply kImageAnnotator::FillModePicker Border And Fill Visibility Border and Fill Border and No Fill No Border and No Fill kImageAnnotator::FontPicker Font Size Bold Italic Underline kImageAnnotator::ImageEffectPicker Image Effects No Effect Drop Shadow Grayscale Border Invert Color kImageAnnotator::ModifyCanvasWidget Restricted When enabled enforces the canvas to include the background image. X: Y: W: H: Apply Cancel Color: Canvas Background Color kImageAnnotator::RotateDialog Rotate Image 180° 90° Clockwise 90° Counter Clockwise Arbitrary Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Horizontal Vertical OK Cancel Rotate Flip kImageAnnotator::ScaleDialog Scale Image Keep Aspect Ratio Width: Height: OK Cancel Pixel Percent kImageAnnotator::StickerPicker Sticker kImageAnnotator::ToolPicker Select Pen Number Marker Rectangle Marker Ellipse Marker Pen Text Arrow Double Arrow Line Blur Rectangle Ellipse Number Pointer Sticker Pixelate Text Pointer Text Arrow Number Arrow Duplicate kImageAnnotator::ZoomPicker Zoom In (%1) Zoom Out (%1) Reset Zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_hr.ts000066400000000000000000000312101414424500400234420ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Rasporedi Bring to Front Premjesti skroz naprijed Bring Forward Premjesti prema naprijed Send Backward Premjesti prema natrag Send to Back Premjesti skroz natrag Select This Odaberi ovo Copy Kopiraj Paste Umetni Edit Uredi Delete Izbriši kImageAnnotator::AnnotationGeneralSettings General Settings Opće postavke kImageAnnotator::AnnotationImageSettings Image Settings Postavke slike kImageAnnotator::AnnotationItemSettings Color Boja Text Color Boja teksta Width Širina Number Seed Brojač Obfuscation Factor Faktor zamućenja Item Shadow Sjena elementa Item Settings Postavke elementa kImageAnnotator::AnnotationTabContextMenu Close Zatvori Close Other Zatvori ostale Close All Zatvori sve Close All to the Left Zatvori sve na lijevo Close All to the Right Zatvori sve na desno kImageAnnotator::AnnotationToolSelection Tool Selection Odabir alata kImageAnnotator::BoolPicker Enabled Aktivirano Disabled Deaktivirano kImageAnnotator::CropWidget Cancel Odustani X: X: Y: Y: W: Š: H: V: Apply Primijeni kImageAnnotator::FillModePicker Border And Fill Visibility Vidljivost ruba i ispune Border and Fill Rub i ispuna Border and No Fill Rub i bez ispune No Border and No Fill Bez ruba i bez ispune kImageAnnotator::FontPicker Font Size Veličina fonta Bold Podebljano Italic Kurziv Underline Podcrtano kImageAnnotator::ImageEffectPicker Image Effects Slikovni efekti No Effect Bez efekta Drop Shadow Odmaknuta sjena Grayscale Crno-bijela Border Rub Invert Color Invertiraj boju kImageAnnotator::ModifyCanvasWidget Restricted Ograničeno When enabled enforces the canvas to include the background image. Kad je aktivirano, područje crtanja uključuje sliku pozadine. X: X: Y: Y: W: Š: H: V: Apply Primijeni Cancel Odustani Color: Boja: Canvas Background Color Boja pozadine patna kImageAnnotator::RotateDialog Rotate Image Okreni sliku 180° 180° 90° Clockwise 90° nadesno 90° Counter Clockwise 90° nalijevo Arbitrary Proizvoljno Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Pozitivne vrijednosti okreću sliku u smjeru kazaljke na satu, negativne u suprotnom smjeru kazaljke na satu. Okretanje množiteljima koji nisu 90° može smanjiti kvalitetu slike. Horizontal Vodoravno Vertical Okomito OK U redu Cancel Odustani Rotate Okreni Flip Preokreni kImageAnnotator::ScaleDialog Scale Image Skaliraj sliku Keep Aspect Ratio Zadrži omjer Width: Širina: Height: Visina: OK U redu Cancel Odustani Pixel Piksel Percent Postotak kImageAnnotator::StickerPicker Sticker Naljepnica kImageAnnotator::ToolPicker Select Odaberi Pen Olovka Number Broj Marker Rectangle Pravokutni odabir Marker Ellipse Ovalni odabir Marker Pen Prostoručni odabir Text Tekst Arrow Strelica Double Arrow Dvostruka strelica Line Crta Blur Mutnoća Rectangle Pravokutnik Ellipse Oval Number Pointer Pokazivač s brojem Sticker Naljepnica Duplicate Dupliciraj Text Pointer Pokazivač s tekstom Text Arrow Strelica s tekstom Number Arrow Strelica s brojem Pixelate Pikseliziraj kImageAnnotator::ZoomPicker Zoom In (%1) Povećaj (%1) Zoom Out (%1) Smanji (%1) Reset Zoom (%1) Poništi zumiranje (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_hu.ts000066400000000000000000000321751414424500400234600ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Bring to Front Bring Forward Send Backward Send to Back Select This Copy Paste Edit Delete kImageAnnotator::AnnotationGeneralSettings General Settings kImageAnnotator::AnnotationImageSettings Image Settings kImageAnnotator::AnnotationItemSettings Color Text Color Width Number Seed Obfuscation Factor Item Shadow Item Settings kImageAnnotator::AnnotationTabContextMenu Close Close Other Close All Close All to the Left Close All to the Right kImageAnnotator::AnnotationToolSelection Tool Selection kImageAnnotator::BoolPicker Enabled Disabled kImageAnnotator::CropWidget Cancel X: Y: W: H: Apply kImageAnnotator::FillModePicker Border And Fill Visibility Border and Fill Border and No Fill No Border and No Fill kImageAnnotator::FontPicker Font Size Bold Italic Underline kImageAnnotator::ImageEffectPicker Image Effects No Effect Drop Shadow Grayscale Border Invert Color kImageAnnotator::ModifyCanvasWidget Restricted When enabled enforces the canvas to include the background image. X: Y: W: H: Apply Cancel Color: Canvas Background Color kImageAnnotator::RotateDialog Rotate Image 180° 90° Clockwise 90° Counter Clockwise Arbitrary Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Horizontal Vertical OK Cancel Rotate Flip kImageAnnotator::ScaleDialog Scale Image Keep Aspect Ratio Width: Height: OK Cancel Pixel Percent kImageAnnotator::StickerPicker Sticker kImageAnnotator::ToolPicker Select Pen Number Marker Rectangle Marker Ellipse Marker Pen Text Arrow Double Arrow Line Blur Rectangle Ellipse Number Pointer Sticker Pixelate Text Pointer Text Arrow Number Arrow Duplicate kImageAnnotator::ZoomPicker Zoom In (%1) Zoom Out (%1) Reset Zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_id.ts000066400000000000000000000310171414424500400234320ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Atur Bring to Front Bawa ke Depan Bring Forward Bawa paling depan Send Backward Kirim paling belakang Send to Back Kirim ke belakang Select This Pilih ini Copy Salin Paste Tempel Edit Sunting Delete Hapus kImageAnnotator::AnnotationGeneralSettings General Settings Pengaturan Umum kImageAnnotator::AnnotationImageSettings Image Settings Pengaturan Gambar kImageAnnotator::AnnotationItemSettings Color Warna Text Color Warna Teks Width Lebar Number Seed Nomor Seed Obfuscation Factor Faktor Obfuscation Item Shadow Bayangan item Item Settings Pengaturan item kImageAnnotator::AnnotationTabContextMenu Close Tutup Close Other Tutup lainnya Close All Tutup semua Close All to the Left Tutup semua ke kiri Close All to the Right Tutup semua ke kanan kImageAnnotator::AnnotationToolSelection Tool Selection Seleksi Alat kImageAnnotator::BoolPicker Enabled Aktifkan Disabled Nonaktifkan kImageAnnotator::CropWidget Cancel Batal X: X: Y: Y: W: L: H: T: Apply Terapkan kImageAnnotator::FillModePicker Border And Fill Visibility Batas dan visibilitas isian Border and Fill Batas dan Isian Border and No Fill Batas dan Tanpa Isian No Border and No Fill Tanpa Batas dan Tanpa Isian kImageAnnotator::FontPicker Font Size Ukuran font Bold Tebal Italic Miring Underline Garis bawah kImageAnnotator::ImageEffectPicker Image Effects Efek gambar No Effect Tanpa Efek Drop Shadow Bayangan Jatuh Grayscale Skala Abu-abu Border Batas Invert Color Balikkan Warna kImageAnnotator::ModifyCanvasWidget Restricted Dibatasi When enabled enforces the canvas to include the background image. Saat diaktifkan akan membuat kanvas menyertakan gambar latar belakang. X: X: Y: Y: W: L: H: T: Apply Terapkan Cancel Batal Color: Warna: Canvas Background Color Warna Latar Belakang Kanvas kImageAnnotator::RotateDialog Rotate Image Putar gambar 180° 180° 90° Clockwise 90° Serarah jarum jam 90° Counter Clockwise 90° Berlawanan jarum jam Arbitrary Sembarang Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Nilai positif berputar searah jarum jam, nilai negatif berlawanan arah jarum jam. Memutar dengan pengganda non 90° mungkin mengurangi kualitasnya. Horizontal Horisontal Vertical Vertikal OK OK Cancel Batal Rotate Putar Flip Balik kImageAnnotator::ScaleDialog Scale Image Skala gambar Keep Aspect Ratio Jaga Rasio Aspek Width: Lebar: Height: Tinggi: OK Ok Cancel Batal Pixel Piksel Percent Persen kImageAnnotator::StickerPicker Sticker Stiker kImageAnnotator::ToolPicker Select Pilih Pen Pena Number Nomor Marker Rectangle Marker Persegi Panjang Marker Ellipse Penanda Elips Marker Pen Spidol Text Teks Arrow Anak panah Double Arrow Panah Ganda Line Garis Blur Blur Rectangle Persegi Ellipse Elips Number Pointer Penunjuk Angka Sticker Stiker Pixelate Pixelate Text Pointer Penunjuk Teks Text Arrow Panah Teks Number Arrow Panah Angka Duplicate Duplikat kImageAnnotator::ZoomPicker Zoom In (%1) Perbesar (%1) Zoom Out (%1) Perkecil (%1) Reset Zoom (%1) Setel Ulang Zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_it.ts000066400000000000000000000313561414424500400234600ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Disponi Bring to Front Porta in primo piano Bring Forward Invia in avanti Send Backward Manda indietro Send to Back Manda indietro Select This Seleziona questo Copy Copia Paste Incolla Edit Modifica Delete Elimina kImageAnnotator::AnnotationGeneralSettings General Settings Impostazioni Generali kImageAnnotator::AnnotationImageSettings Image Settings Impostazioni immagine kImageAnnotator::AnnotationItemSettings Color Colore Text Color Colore del testo Width Larghezza Number Seed Numero seme Obfuscation Factor Fattore di offuscamento Item Shadow Ombreggiatura elemento Item Settings Impostazione elemento kImageAnnotator::AnnotationTabContextMenu Close Chiudi Close Other Chiudi altro Close All Chiudi tutto Close All to the Left Chiudi tutto a sinistra Close All to the Right Chiudi tutto a destra kImageAnnotator::AnnotationToolSelection Tool Selection Selezione strumento kImageAnnotator::BoolPicker Enabled Abilitato Disabled Disabilitato kImageAnnotator::CropWidget Cancel Annulla X: X: Y: Y: W: L: H: A: Apply Applica kImageAnnotator::FillModePicker Border And Fill Visibility Visibilità bordo e riempimento Border and Fill Bordo e riempimento Border and No Fill Bordo e nessun riempimento No Border and No Fill Nessun bordo e nessun riempimento kImageAnnotator::FontPicker Font Size Dimensione caratteri Bold Grassetto Italic Corsivo Underline Sottolineatura kImageAnnotator::ImageEffectPicker Image Effects Effetti immagine No Effect Nessun effetto Drop Shadow Ombra esterna Grayscale Scala di grigi Border Bordo Invert Color Inverti colore kImageAnnotator::ModifyCanvasWidget Restricted Limitato When enabled enforces the canvas to include the background image. Quando abilitato impone la tela per includere l'immagine di sfondo. X: X: Y: Y: W: L: H: A: Apply Applica Cancel Annulla Color: Colore: Canvas Background Color Colore di sfondo della tela kImageAnnotator::RotateDialog Rotate Image Ruota immagine 180° 180° 90° Clockwise 90° in senso orario 90° Counter Clockwise 90° in senso antiorario Arbitrary Arbitrario Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. I valori positivi ruotano in senso orario, i valori negativi in senso antiorario. La rotazione di moltiplicatori diversi da 90° potrebbe introdurre una perdita di qualità. Horizontal Orizzontale Vertical Verticale OK OK Cancel Annulla Rotate Ruotare Flip Capovolgere kImageAnnotator::ScaleDialog Scale Image Scala immagine Keep Aspect Ratio Mantenere proporzioni Width: Larghezza: Height: Altezza: OK OK Cancel Annulla Pixel Pixel Percent Percentuale kImageAnnotator::StickerPicker Sticker Adesivo kImageAnnotator::ToolPicker Select Seleziona Pen Penna Number Numero Marker Rectangle Marcatore rettangolo Marker Ellipse Marcatore ellisse Marker Pen Marcatore penna Text Testo Arrow Freccia Double Arrow Doppia freccia Line Linea Blur Sfocatura Rectangle Rettangolo Ellipse Ellisse Number Pointer Puntatore numerico Sticker Adesivo Pixelate Pixellato Text Pointer Puntatore testo Text Arrow Freccia testo Number Arrow Numero freccia Duplicate Duplicare kImageAnnotator::ZoomPicker Zoom In (%1) Ingrandisci (%1) Zoom Out (%1) Rimpicciolisci (%1) Reset Zoom (%1) Reimposta zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_ja.ts000066400000000000000000000322001414424500400234230ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Bring to Front Bring Forward Send Backward Send to Back Select This Copy Paste Edit Delete kImageAnnotator::AnnotationGeneralSettings General Settings kImageAnnotator::AnnotationImageSettings Image Settings kImageAnnotator::AnnotationItemSettings Color Text Color Width Number Seed Obfuscation Factor Item Shadow Item Settings kImageAnnotator::AnnotationTabContextMenu Close Close Other Close All Close All to the Left Close All to the Right kImageAnnotator::AnnotationToolSelection Tool Selection kImageAnnotator::BoolPicker Enabled Disabled kImageAnnotator::CropWidget Cancel X: Y: W: H: Apply kImageAnnotator::FillModePicker Border And Fill Visibility Border and Fill Border and No Fill No Border and No Fill kImageAnnotator::FontPicker Font Size Bold Italic Underline kImageAnnotator::ImageEffectPicker Image Effects No Effect Drop Shadow Grayscale Border Invert Color kImageAnnotator::ModifyCanvasWidget Restricted When enabled enforces the canvas to include the background image. X: Y: W: H: Apply Cancel Color: Canvas Background Color kImageAnnotator::RotateDialog Rotate Image 180° 90° Clockwise 90° Counter Clockwise Arbitrary Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Horizontal Vertical OK Cancel Rotate Flip kImageAnnotator::ScaleDialog Scale Image Keep Aspect Ratio Width: Height: OK Cancel Pixel Percent kImageAnnotator::StickerPicker Sticker kImageAnnotator::ToolPicker Select Pen Number Marker Rectangle Marker Ellipse Marker Pen Text Arrow Double Arrow Line Blur Rectangle Ellipse Number Pointer Sticker Pixelate Text Pointer Text Arrow Number Arrow Duplicate kImageAnnotator::ZoomPicker Zoom In (%1) Zoom Out (%1) Reset Zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_nl.ts000066400000000000000000000312551414424500400234530ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Organiseren Bring to Front Op voorgrond plaatsen Bring Forward Op voorgrond plaatsen Send Backward Op achtergrond plaatsen Send to Back Op achtergrond plaatsen Select This Dit selecteren Copy Kopiëren Paste Plakken Edit Bewerken Delete Verwijderen kImageAnnotator::AnnotationGeneralSettings General Settings Algemene instellingen kImageAnnotator::AnnotationImageSettings Image Settings Afbeeldingsinstellingen kImageAnnotator::AnnotationItemSettings Color Kleur Text Color Tekstkleur Width Breedte Number Seed Aantal Obfuscation Factor Maskeerfactor Item Shadow Itemschaduw Item Settings Iteminstellingen kImageAnnotator::AnnotationTabContextMenu Close Sluiten Close Other Overige sluiten Close All Alles sluiten Close All to the Left Alles links hiervan sluiten Close All to the Right Alles rechts hiervan sluiten kImageAnnotator::AnnotationToolSelection Tool Selection Gereedschapskeuze kImageAnnotator::BoolPicker Enabled Ingeschakeld Disabled Uitgeschakeld kImageAnnotator::CropWidget Cancel Annuleren X: X: Y: Y: W: B: H: H: Apply Toepassen kImageAnnotator::FillModePicker Border And Fill Visibility Rand- en opvulzichtbaarheid Border and Fill Rand met opvulling Border and No Fill Rand zonder opvulling No Border and No Fill Geen rand, geen opvulling kImageAnnotator::FontPicker Font Size Tekstgrootte Bold Vetgedrukt Italic Cursief Underline Onderstrepen kImageAnnotator::ImageEffectPicker Image Effects Afbeeldingseffecten No Effect Geen effect Drop Shadow Vallende schaduw Grayscale Grijswaarden Border Rand Invert Color Kleuren omkeren kImageAnnotator::ModifyCanvasWidget Restricted Beperkt When enabled enforces the canvas to include the background image. Schakel in om het canvas gedwongen de achtergrondafbeelding te laten tonen. X: X: Y: Y: W: B: H: H: Apply Toepassen Cancel Annuleren Color: Kleur: Canvas Background Color Achtergrondkleur van canvas kImageAnnotator::RotateDialog Rotate Image Afbeelding draaien 180° 180° 90° Clockwise 90° naar rechts 90° Counter Clockwise 90° naar links Arbitrary Willekeurig Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Positieve waarde = naar rechts draaien - Negatieve waarde = naar links draaien. Een waarde die afwijkt van 90° kan kwaliteitsverlies veroorzaken. Horizontal Horizontaal Vertical Verticaal OK Oké Cancel Annuleren Rotate Draaien Flip Spiegelen kImageAnnotator::ScaleDialog Scale Image Afmetingen aanpassen Keep Aspect Ratio Beeldverhouding behouden Width: Breedte: Height: Hoogte: OK Oké Cancel Annuleren Pixel Pixel Percent Procent kImageAnnotator::StickerPicker Sticker Sticker kImageAnnotator::ToolPicker Select Kiezen Pen Pen Number Getal Marker Rectangle Markeerrechthoek Marker Ellipse Markeerellips Marker Pen Markeerstift Text Tekst Arrow Pijl Double Arrow Dubbele pijl Line Lijn Blur Vervaging Rectangle Rechthoek Ellipse Ellips Number Pointer Getalaanwijzer Sticker Sticker Pixelate Pixelvorming Text Pointer Tekstaanwijzer Text Arrow Tekstuele pijl Number Arrow Getalpijl Duplicate Klonen kImageAnnotator::ZoomPicker Zoom In (%1) Inzoomen (%1) Zoom Out (%1) Uitzoomen (%1) Reset Zoom (%1) Standaard zoomniveau (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_no.ts000066400000000000000000000316031414424500400234530ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Tilpass Bring to Front Ta til forgrunnen Bring Forward Ta forover Send Backward Send bakover Send to Back Send bakerst Select This Velg dette Copy Kopier Paste Lim inn Edit Rediger Delete Slett kImageAnnotator::AnnotationGeneralSettings General Settings kImageAnnotator::AnnotationImageSettings Image Settings kImageAnnotator::AnnotationItemSettings Color Farge Text Color Tekstfarge Width Bredde Number Seed Såtall Obfuscation Factor Dekkevnefaktor Item Shadow Item Settings kImageAnnotator::AnnotationTabContextMenu Close Lukk Close Other Lukk andre Close All Lukk alle Close All to the Left Lukk alle til venstre Close All to the Right Lukk alle til høyre kImageAnnotator::AnnotationToolSelection Tool Selection kImageAnnotator::BoolPicker Enabled Disabled kImageAnnotator::CropWidget Cancel Avbryt X: X: Y: Y: W: B: H: H: Apply Bruk kImageAnnotator::FillModePicker Border And Fill Visibility Kantlinje og utfyllingssynlighet Border and Fill Kantlinje og utfylling Border and No Fill Kantlinje og ingen utfylling No Border and No Fill Ingen kantlinje og ingen utfylling kImageAnnotator::FontPicker Font Size Skriftstørrelse Bold Italic Underline kImageAnnotator::ImageEffectPicker Image Effects Bildeeffekter No Effect Ingen effekt Drop Shadow Kastskygge Grayscale Gråskala Border Kantlinje Invert Color kImageAnnotator::ModifyCanvasWidget Restricted Begrenset When enabled enforces the canvas to include the background image. Påtvinger bruk av bakgrunnsbilde i kanvas når påslått. X: X: Y: Y: W: B: H: H: Apply Bruk Cancel Avbryt Color: Canvas Background Color kImageAnnotator::RotateDialog Rotate Image 180° 90° Clockwise 90° Counter Clockwise Arbitrary Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Horizontal Vertical OK OK Cancel Avbryt Rotate Flip kImageAnnotator::ScaleDialog Scale Image Skaler bilde Keep Aspect Ratio Behold sideforhold Width: Bredde: Height: Høyde: OK OK Cancel Avbryt Pixel Piksel Percent Prosent kImageAnnotator::StickerPicker Sticker Klistremerke kImageAnnotator::ToolPicker Select Velg Pen Penn Number Tall Marker Rectangle Peker-rektangel Marker Ellipse Peker-ellipse Marker Pen Peker-penn Text Tekst Arrow Pil Double Arrow Dobbelpil Line Linje Blur Tilsløring Rectangle Rektangel Ellipse Ellipse Number Pointer Nummerpeker Sticker Klistremerke Pixelate Pikseler Text Pointer Tekstpeker Text Arrow Tekstpil Number Arrow Nummerpil Duplicate Dupliser kImageAnnotator::ZoomPicker Zoom In (%1) Zoom Out (%1) Reset Zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_pl.ts000066400000000000000000000314671414424500400234620ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Aranżacja Bring to Front Przesuń na wierzch Bring Forward Przesuń do przodu Send Backward Przesuń do tyłu Send to Back Przesuń na spód Select This Wybierz to Copy Kopiuj Paste Wklej Edit Edycja Delete Usuń kImageAnnotator::AnnotationGeneralSettings General Settings Ustawienia główne kImageAnnotator::AnnotationImageSettings Image Settings Ustawienia obrazu kImageAnnotator::AnnotationItemSettings Color Kolor Text Color Kolor tekstu Width Szerokość Number Seed Numer ziarna Obfuscation Factor Współczynnik zaciemniania Item Shadow Cień elementu Item Settings Ustawienia elementów kImageAnnotator::AnnotationTabContextMenu Close Zamknij Close Other Zamknij Inne Close All Zamknij wszystko Close All to the Left Zamknij wszystko po lewej stronie Close All to the Right Zamknij wszystkie po prawej stronie kImageAnnotator::AnnotationToolSelection Tool Selection Wybór narzędzia kImageAnnotator::BoolPicker Enabled Włączone Disabled Wyłączone kImageAnnotator::CropWidget Cancel Anuluj X: X: Y: Y: W: W: H: H: Apply Zastosuj kImageAnnotator::FillModePicker Border And Fill Visibility Widoczność krawędzi i wypełnienia Border and Fill Obramowanie i wypełnienie Border and No Fill Obramowanie i brak wypełnienia No Border and No Fill Bez obramowania i bez wypełnienia kImageAnnotator::FontPicker Font Size Rozmiar czcionki Bold Pogrubienie Italic Pochylenie Underline Podkreślenie kImageAnnotator::ImageEffectPicker Image Effects Efekty obrazu No Effect Bez efektu Drop Shadow Cień Grayscale Skala szarości Border Obramowanie Invert Color Odwróć kolor kImageAnnotator::ModifyCanvasWidget Restricted Ograniczone When enabled enforces the canvas to include the background image. Po włączeniu wymusza kanwę, aby uwzględnić obraz tła. X: X: Y: Y: W: W: H: H: Apply Zastosuj Cancel Anuluj Color: Kolor: Canvas Background Color Kolor tła płótna kImageAnnotator::RotateDialog Rotate Image Obróć obraz 180° 180° 90° Clockwise 90° zgodnie z ruchem wskazówek zegara 90° Counter Clockwise 90° przeciwnie do ruchu wskazówek zegara Arbitrary Dowolnie Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Wartości dodatnie obracają zgodnie z ruchem wskazówek zegara, wartości ujemne przeciwnie do ruchu wskazówek zegara. Obracanie przez mnożniki inne niż 90° może spowodować utratę jakości. Horizontal Poziomo Vertical Pionowo OK OK Cancel Anuluj Rotate Obróć Flip Przerzut kImageAnnotator::ScaleDialog Scale Image Skaluj obraz Keep Aspect Ratio Zachowaj proporcje Width: Szerokość: Height: Wysokość: OK OK Cancel Anuluj Pixel Pikseli Percent Procent kImageAnnotator::StickerPicker Sticker Naklejka kImageAnnotator::ToolPicker Select Wybierz Pen Pióro Number Numer Marker Rectangle Znacznik prostokątny Marker Ellipse Znacznik eliptyczny Marker Pen Zakreślacz Text Tekst Arrow Strzałka Double Arrow Podwójna strzałka Line Linia Blur Rozmycie Rectangle Prostokąt Ellipse Elipsa Number Pointer Wskaźnik numeryczny Sticker Naklejka Pixelate Pikslowanie Text Pointer Wskaźnik tekstu Text Arrow Strzałka tekstu Number Arrow Strzałka numeryczna Duplicate Zduplikowane kImageAnnotator::ZoomPicker Zoom In (%1) Powiększ (%1) Zoom Out (%1) Pomniejsz (%1) Reset Zoom (%1) Resetuj powiększenie (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_pt.ts000066400000000000000000000314341414424500400234640ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Organizar Bring to Front Trazer para frente Bring Forward Avançar um nível Send Backward Recuar um nível Send to Back Enviar para trás Select This Selecione isto Copy Copiar Paste Colar Edit Editar Delete Apagar kImageAnnotator::AnnotationGeneralSettings General Settings Configurações Gerais kImageAnnotator::AnnotationImageSettings Image Settings Configurações de imagem kImageAnnotator::AnnotationItemSettings Color Cor Text Color Cor do texto Width Tamanho / Espessura da Ferramenta atual Number Seed Número Obfuscation Factor Fator de Obfuscação Item Shadow Sombra do Item Item Settings Configurações do item kImageAnnotator::AnnotationTabContextMenu Close Fechar aba Close Other Fechar outras abas Close All Fechar todas as abas Close All to the Left Fechar abas à esquerda Close All to the Right Fechar abas à direita kImageAnnotator::AnnotationToolSelection Tool Selection Seleção de ferramentas kImageAnnotator::BoolPicker Enabled Ativado Disabled Desativado kImageAnnotator::CropWidget Cancel Cancelar X: X: Y: Y: W: Largura: H: Altura: Apply Aplicar kImageAnnotator::FillModePicker Border And Fill Visibility Exibição de borda e preenchimento Border and Fill Com borda e com preenchimento Border and No Fill Com borda e sem preenchimento No Border and No Fill Sem borda e sem preenchimento kImageAnnotator::FontPicker Font Size Tamanho da fonte Bold Negrito Italic Itálico Underline Sublinhado kImageAnnotator::ImageEffectPicker Image Effects Efeitos da imagem No Effect Sem efeito Drop Shadow Sombreado Grayscale Escala de cinza Border Borda Invert Color Inverter cor kImageAnnotator::ModifyCanvasWidget Restricted RestritO When enabled enforces the canvas to include the background image. Quando ativado, impõe a tela para incluir a imagem de fundo. X: X: Y: Y: W: Largura: H: Altura: Apply Aplicar Cancel Cancelar Color: Cor: Canvas Background Color Cor de fundo da tela kImageAnnotator::RotateDialog Rotate Image Rotacionar Imagem 180° 180º 90° Clockwise 90° no sentido horário 90° Counter Clockwise 90° no sentido anti-horário Arbitrary Arbitrário Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Os valores positivos giram no sentido horário, os valores negativos no sentido anti-horário. Rotacionar por multiplicadores diferentes de 90° pode causar perda de qualidade. Horizontal Horizontal Vertical Vertical OK OK Cancel Cancelar Rotate Rotacionar Flip Girar - Inverter kImageAnnotator::ScaleDialog Scale Image Redimensionar imagem Keep Aspect Ratio Manter proporção Width: Largura: Height: Altura: OK OK Cancel Cancelar Pixel Pixel Percent Percentagem kImageAnnotator::StickerPicker Sticker Adesivo kImageAnnotator::ToolPicker Select Seleção Pen Caneta Number Número Marker Rectangle Marcador Retangular Marker Ellipse Marcador Elíptico Marker Pen Caneta Marcadora Text Texto Arrow Seta Double Arrow Seta Dupla Line Linha Blur Ofuscar Rectangle Retângulo Ellipse Elipse Number Pointer Número com ponteiro Sticker Adesivo Pixelate Pixelar Text Pointer Texto com ponteiro Text Arrow Texto com seta Number Arrow Número com seta Duplicate Duplicar kImageAnnotator::ZoomPicker Zoom In (%1) Zoom + (%1) Zoom Out (%1) Zoom - (%1) Reset Zoom (%1) Redefinir Zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_pt_BR.ts000066400000000000000000000315241414424500400240470ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Organizar Bring to Front Trazer para frente Bring Forward Avançar um nível Send Backward Recuar um nível Send to Back Enviar para trás Select This Selecione isto Copy Copiar Paste Colar Edit Editar Delete Excluir kImageAnnotator::AnnotationGeneralSettings General Settings Configurações Gerais kImageAnnotator::AnnotationImageSettings Image Settings Configurações de imagem kImageAnnotator::AnnotationItemSettings Color Cor Text Color Cor do texto Width Tamanho / Espessura da Ferramenta atual Number Seed Número Obfuscation Factor Fator de Obfuscação Item Shadow Sombra do Item Item Settings Configurações do item kImageAnnotator::AnnotationTabContextMenu Close Fechar aba Close Other Fechar outras abas Close All Fechar todas as abas Close All to the Left Fechar abas à esquerda Close All to the Right Fechar abas à direita kImageAnnotator::AnnotationToolSelection Tool Selection Ferramenta Seleção kImageAnnotator::BoolPicker Enabled Habilitado Disabled Desabilitado kImageAnnotator::CropWidget Cancel Cancelar X: X: Y: Y: W: Largura: H: Altura: Apply Aplicar kImageAnnotator::FillModePicker Border And Fill Visibility Modo de desenho da borda e do preenchimento Border and Fill Com borda e com preenchimento Border and No Fill Com borda e sem preenchimento No Border and No Fill Sem borda e sem preenchimento kImageAnnotator::FontPicker Font Size Tamanho da fonte Bold Negrito Italic Itálico Underline Sublinhado kImageAnnotator::ImageEffectPicker Image Effects Efeitos para a imagem No Effect Sem Efeito Drop Shadow Sombreado Grayscale Escala de cinza Border Borda Invert Color Inverter cor kImageAnnotator::ModifyCanvasWidget Restricted RestritO When enabled enforces the canvas to include the background image. Quando ativado, impõe a tela para incluir a imagem de fundo. X: X: Y: Y: W: Largura: H: Altura: Apply Aplicar Cancel Cancelar Color: Cor: Canvas Background Color Cor de fundo da tela kImageAnnotator::RotateDialog Rotate Image Rotacionar Imagem 180° 180º 90° Clockwise 90° no sentido horário 90° Counter Clockwise 90° no sentido anti-horário Arbitrary Arbitrário Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Os valores positivos giram no sentido horário, os valores negativos no sentido anti-horário. Rotacionar por multiplicadores diferentes de 90° pode causar perda de qualidade. Horizontal Horizontal Vertical Vertical OK OK Cancel Cancelar Rotate Rotacionar Flip Girar - Inverter kImageAnnotator::ScaleDialog Scale Image Redimensionar imagem Keep Aspect Ratio Manter proporção Width: Largura: Height: Altura: OK OK Cancel Cancelar Pixel Pixel Percent Porcentagem kImageAnnotator::StickerPicker Sticker Figurinha kImageAnnotator::ToolPicker Select Seleção Pen Caneta Number Número Marker Rectangle Marcador Retangular Marker Ellipse Marcador Elíptico Marker Pen Caneta Marcadora Text Texto Arrow Seta Double Arrow Seta Dupla Line Linha Blur Ofuscar Rectangle Retângulo Ellipse Elipse Number Pointer Número com ponteiro Sticker Figurinha Text Pointer Texto com ponteiro Text Arrow Texto com seta Number Arrow Número com seta Pixelate Pixelizar Duplicate Duplicar kImageAnnotator::ZoomPicker Zoom In (%1) Zoom + (%1) Zoom Out (%1) Zoom - (%1) Reset Zoom (%1) Redefinir Zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_ro.ts000066400000000000000000000314471414424500400234650ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Aranjează Bring to Front Adu în față Bring Forward Adu mai în față Send Backward Trimite mai în spate Send to Back Trimite în spate Select This Alege acesta Copy Copiază Paste Lipește Edit Modifică Delete Șterge kImageAnnotator::AnnotationGeneralSettings General Settings Configurări generale kImageAnnotator::AnnotationImageSettings Image Settings Configurări imagine kImageAnnotator::AnnotationItemSettings Color Culoare Text Color Culoare text Width Lățime Number Seed Sămânță numerică Obfuscation Factor Factor de eclipsare Item Shadow Umbră element Item Settings Configurări element kImageAnnotator::AnnotationTabContextMenu Close Închide Close Other Închide celelalte Close All Închide toate Close All to the Left Închide toate la stânga Close All to the Right Închide toate la dreapta kImageAnnotator::AnnotationToolSelection Tool Selection Alegere unealtă kImageAnnotator::BoolPicker Enabled Activat Disabled Dezactivat kImageAnnotator::CropWidget Cancel Renunță X: X: Y: Y: W: L: H: Î: Apply Aplică kImageAnnotator::FillModePicker Border And Fill Visibility Vizibilitate contur și umplere Border and Fill Contur și umplere Border and No Fill Contur fără umplere No Border and No Fill Fără contur și fără umplere kImageAnnotator::FontPicker Font Size Dimensiune font Bold Aldin Italic Cursiv Underline Subliniat kImageAnnotator::ImageEffectPicker Image Effects Efecte imagine No Effect Fără efect Drop Shadow Lasă umbră Grayscale Nuanțe de gri Border Contur Invert Color Inversează culoarea kImageAnnotator::ModifyCanvasWidget Restricted Restricționat When enabled enforces the canvas to include the background image. La activare forțează canavaua să includă imaginea de fundal. X: X: Y: Y: W: L: H: Î: Apply Aplică Cancel Renunță Color: Culoare: Canvas Background Color Culoare fundal canava kImageAnnotator::RotateDialog Rotate Image Rotește imaginea 180° 180° 90° Clockwise 90° în sensul acelor de ceasornic 90° Counter Clockwise 90° în sens contrar acelor de ceasornic Arbitrary Arbitrar Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Valorile pozitive rotesc în sensul acelor de ceasornic, cele negative – în sens contrar. Rotirea cu non-multiplu de 90° poate introduce pierderi de calitate. Horizontal Orizontal Vertical Vertical OK Bine Cancel Renunță Rotate Rotește Flip Răstoarnă kImageAnnotator::ScaleDialog Scale Image Scalează imaginea Keep Aspect Ratio Păstrează raportul de aspect Width: Lățime: Height: Înălțime: OK Bine Cancel Renunță Pixel Pixel Percent Procent kImageAnnotator::StickerPicker Sticker Autocolant kImageAnnotator::ToolPicker Select Alege Pen Stilou Number Număr Marker Rectangle Dreptunghi marcator Marker Ellipse Elipsă marcatoare Marker Pen Stilou marcator Text Text Arrow Săgeată Double Arrow Săgeată dublă Line Linie Blur Estompare Rectangle Dreptunghi Ellipse Elipsă Number Pointer Indicator numeric Sticker Autocolant Pixelate Pixelează Text Pointer Indicator textual Text Arrow Săgeată textuală Number Arrow Săgeată numerică Duplicate Duplică kImageAnnotator::ZoomPicker Zoom In (%1) Apropie (%1) Zoom Out (%1) Îndepărtează (%1) Reset Zoom (%1) Reinițializează apropierea (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_ru.ts000066400000000000000000000334431414424500400234710ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Упорядочить Bring to Front На верхний слой Bring Forward На слой выше Send Backward На слой ниже Send to Back На нижний слой Select This Выбрать этот Copy Копировать Paste Вставить Edit Изменить Delete Удалить kImageAnnotator::AnnotationGeneralSettings General Settings Общие настройки kImageAnnotator::AnnotationImageSettings Image Settings Настройки изображения kImageAnnotator::AnnotationItemSettings Color Цвет Text Color Цвет текста Width Ширина Number Seed Нумератор Obfuscation Factor Уровень обфускации Item Shadow Тень элемента Item Settings Настройки элемента kImageAnnotator::AnnotationTabContextMenu Close Закрыть Close Other Закрыть остальные Close All Закрыть все Close All to the Left Закрыть все слева Close All to the Right Закрыть все справа kImageAnnotator::AnnotationToolSelection Tool Selection Выбор инструмента kImageAnnotator::BoolPicker Enabled Включено Disabled Отключено kImageAnnotator::CropWidget Cancel Отмена X: X: Y: Y: W: Ш: H: В: Apply Применить kImageAnnotator::FillModePicker Border And Fill Visibility Видимость обводки и заливки Border and Fill Обводка и заливка Border and No Fill Обводка без заливки No Border and No Fill Без обводки и заливки kImageAnnotator::FontPicker Font Size Размер шрифта Bold Жирный Italic Курсив Underline Подчёркнутый kImageAnnotator::ImageEffectPicker Image Effects Графические эффекты No Effect Без эффекта Drop Shadow Отбросить тень Grayscale Оттенки серого Border Рамка Invert Color Инвертировать цвет kImageAnnotator::ModifyCanvasWidget Restricted Ограничено When enabled enforces the canvas to include the background image. Включить принудительный захват фонового изображения. X: X: Y: Y: W: Ширина: H: Высота: Apply Применить Cancel Отменить Color: Цвет: Canvas Background Color Цвет фона kImageAnnotator::RotateDialog Rotate Image Повернуть изображение 180° 180° 90° Clockwise 90° по часовой стрелке 90° Counter Clockwise 90° против часовой стрелки Arbitrary Задать угол Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Положительные значения — по часовой стрелке, отрицательные — против. Поворот на некратный 90° угол может привести к потере качества. Horizontal Горизонально Vertical Вертикально OK Применить Cancel Отменить Rotate Повернуть Flip Отразить kImageAnnotator::ScaleDialog Scale Image Масштабировать изображение Keep Aspect Ratio Сохранять пропорции Width: Ширина: Height: Высота: OK Применить Cancel Отмена Pixel Пиксели Percent Проценты kImageAnnotator::StickerPicker Sticker Стикер kImageAnnotator::ToolPicker Select Выбор Pen Карандаш Number Число Marker Rectangle Маркер прямоугольный Marker Ellipse Маркер эллипсом Marker Pen Маркер карандаш Text Текст Arrow Стрелка Double Arrow Двойная стрелка Line Линия Blur Размытие Rectangle Прямоугольник Ellipse Эллипс Number Pointer Числовой указатель Sticker Стикер Pixelate Пикселизовать Text Pointer Текстовый указатель Text Arrow Стрелка с текстом Number Arrow Стрелка с цифрой Duplicate Дублировать kImageAnnotator::ZoomPicker Zoom In (%1) Увеличить (%1) Zoom Out (%1) Уменьшить (%1) Reset Zoom (%1) Исходный масштаб (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_si.ts000066400000000000000000000322351414424500400234540ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Bring to Front Bring Forward Send Backward Send to Back Select This Copy පිටපත් Paste අලවන්න Edit සංස්කරණය Delete kImageAnnotator::AnnotationGeneralSettings General Settings kImageAnnotator::AnnotationImageSettings Image Settings kImageAnnotator::AnnotationItemSettings Color වර්ණය Text Color Width පළල Number Seed Obfuscation Factor Item Shadow Item Settings kImageAnnotator::AnnotationTabContextMenu Close වසන්න Close Other අනෙක්වා වසන්න Close All සියල්ල වසන්න Close All to the Left Close All to the Right kImageAnnotator::AnnotationToolSelection Tool Selection මෙවලම් තේරීම kImageAnnotator::BoolPicker Enabled සබල කර ඇත Disabled අබල කර ඇත kImageAnnotator::CropWidget Cancel අවලංගු X: Y: W: H: Apply යොදන්න kImageAnnotator::FillModePicker Border And Fill Visibility Border and Fill Border and No Fill No Border and No Fill kImageAnnotator::FontPicker Font Size Bold Italic Underline kImageAnnotator::ImageEffectPicker Image Effects No Effect Drop Shadow Grayscale Border Invert Color kImageAnnotator::ModifyCanvasWidget Restricted When enabled enforces the canvas to include the background image. X: Y: W: H: Apply යොදන්න Cancel අවලංගු Color: වර්ණය: Canvas Background Color kImageAnnotator::RotateDialog Rotate Image 180° 180° 90° Clockwise 90° Counter Clockwise Arbitrary Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Horizontal Vertical OK හරි Cancel අවලංගු Rotate Flip kImageAnnotator::ScaleDialog Scale Image Keep Aspect Ratio Width: පළල: Height: උස: OK හරි Cancel අවලංගු Pixel Percent kImageAnnotator::StickerPicker Sticker kImageAnnotator::ToolPicker Select තෝරන්න Pen Number අංකය Marker Rectangle Marker Ellipse Marker Pen Text Arrow ඊතලය Double Arrow ද්විත්ව ඊතලය Line Blur Rectangle Ellipse Number Pointer Sticker Pixelate Text Pointer Text Arrow Number Arrow අංක ඊතලය Duplicate අනුපිටපත kImageAnnotator::ZoomPicker Zoom In (%1) විශාලනය (% 1) Zoom Out (%1) කුඩාලනය (% 1) Reset Zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_sv.ts000066400000000000000000000310431414424500400234650ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Ordna Bring to Front Flytta längst fram Bring Forward Flytta framåt Send Backward Flytta bakåt Send to Back Flytta längst bak Select This Markera detta Copy Kopiera Paste Klistra in Edit Redigera Delete Ta bort kImageAnnotator::AnnotationGeneralSettings General Settings Allmänna Inställningar kImageAnnotator::AnnotationImageSettings Image Settings Bildinställningar kImageAnnotator::AnnotationItemSettings Color Färg Text Color Textfärg Width Bredd Number Seed Räkneverk Obfuscation Factor Fördunklingsfaktor Item Shadow Objektskugga Item Settings Objektinställningar kImageAnnotator::AnnotationTabContextMenu Close Stäng Close Other Stäng andra Close All Stäng alla Close All to the Left Stäng alla till vänster Close All to the Right Stäng alla till höger kImageAnnotator::AnnotationToolSelection Tool Selection Verktygsval kImageAnnotator::BoolPicker Enabled Aktiverat Disabled Inaktiverat kImageAnnotator::CropWidget Cancel Avbryt X: X: Y: Y: W: B: H: H: Apply Tillämpa kImageAnnotator::FillModePicker Border And Fill Visibility Kant- och fyllnadssynlighet Border and Fill Kantlinje och fyllning Border and No Fill Kantlinje och ingen fyllning No Border and No Fill Ingen kantlinje och ingen fyllning kImageAnnotator::FontPicker Font Size Teckenstorlek Bold Fet Italic Kursiv Underline Understruken kImageAnnotator::ImageEffectPicker Image Effects Bildeffekter No Effect Ingen effekt Drop Shadow Skugga Grayscale Gråskala Border Kantlinje Invert Color Invertera färg kImageAnnotator::ModifyCanvasWidget Restricted Begränsad When enabled enforces the canvas to include the background image. Vid aktivering tvingas arbetsytan att inkludera bakgrundsbilden. X: X: Y: Y: W: B: H: H: Apply Tillämpa Cancel Avbryt Color: Färg: Canvas Background Color Arbetsytans bakgrundsfärg kImageAnnotator::RotateDialog Rotate Image Rotera bilden 180° 180° 90° Clockwise 90° medurs 90° Counter Clockwise 90° moturs Arbitrary Slumpmässig Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Positiva värden roterar medurs, negativa värden moturs. Rotation med annat än 90°-multiplikator kan leda till kvalitetsförlust. Horizontal Horisontellt Vertical Vertikalt OK OK Cancel Avbryt Rotate Rotera Flip Vänd kImageAnnotator::ScaleDialog Scale Image Skala bild Keep Aspect Ratio Bevara proportioner Width: Bredd: Height: Höjd: OK OK Cancel Avbryt Pixel Pixel Percent Procent kImageAnnotator::StickerPicker Sticker Dekal kImageAnnotator::ToolPicker Select Markera Pen Penna Number Siffra Marker Rectangle Rektangelmarkering Marker Ellipse Ellipsmarkering Marker Pen Överstrykningspenna Text Text Arrow Pil Double Arrow Dubbelpil Line Linje Blur Oskärpa Rectangle Rektangel Ellipse Ellips Number Pointer Nummerpekare Sticker Dekal Pixelate Pixelera Text Pointer Textpekare Text Arrow Textpil Number Arrow Sifferpil Duplicate Duplicera kImageAnnotator::ZoomPicker Zoom In (%1) Zooma in (%1) Zoom Out (%1) Zooma ut (%1) Reset Zoom (%1) Återställ zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_tr.ts000066400000000000000000000321471414424500400234700ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Bring to Front Öne Çıkar Bring Forward Send Backward Send to Back Select This Copy Kopyala Paste Yapıştır Edit Düzenle Delete Sil kImageAnnotator::AnnotationGeneralSettings General Settings kImageAnnotator::AnnotationImageSettings Image Settings kImageAnnotator::AnnotationItemSettings Color Renk Text Color Yazı Rengi Width En Number Seed Obfuscation Factor Item Shadow Item Settings kImageAnnotator::AnnotationTabContextMenu Close Kapat Close Other Close All Hepsini Kapat Close All to the Left Close All to the Right kImageAnnotator::AnnotationToolSelection Tool Selection kImageAnnotator::BoolPicker Enabled Disabled kImageAnnotator::CropWidget Cancel İptal X: Y: W: H: Apply kImageAnnotator::FillModePicker Border And Fill Visibility Border and Fill Border and No Fill No Border and No Fill kImageAnnotator::FontPicker Font Size Font Büyüklüğü Bold Italic Underline kImageAnnotator::ImageEffectPicker Image Effects No Effect Drop Shadow Grayscale Border Invert Color kImageAnnotator::ModifyCanvasWidget Restricted When enabled enforces the canvas to include the background image. X: Y: W: H: Apply Cancel İptal Color: Canvas Background Color kImageAnnotator::RotateDialog Rotate Image 180° 90° Clockwise 90° Counter Clockwise Arbitrary Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Horizontal Vertical OK Cancel İptal Rotate Flip kImageAnnotator::ScaleDialog Scale Image Keep Aspect Ratio Width: Height: OK Cancel İptal Pixel Percent kImageAnnotator::StickerPicker Sticker kImageAnnotator::ToolPicker Select Pen Number Marker Rectangle Marker Ellipse Marker Pen Text Arrow Double Arrow Line Blur Rectangle Ellipse Number Pointer Sticker Pixelate Text Pointer Text Arrow Number Arrow Duplicate kImageAnnotator::ZoomPicker Zoom In (%1) Zoom Out (%1) Reset Zoom (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_uk.ts000066400000000000000000000337531414424500400234660ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange Компонування Bring to Front Пересунути на передній план Bring Forward Пересунути вище Send Backward Пересунути нижче Send to Back Перемістити на задній план Select This Вибрати це Copy Копіювати Paste Вставити Edit Змінити Delete Вилучити kImageAnnotator::AnnotationGeneralSettings General Settings Загальні параметри kImageAnnotator::AnnotationImageSettings Image Settings Параметри зображень kImageAnnotator::AnnotationItemSettings Color Колір Text Color Колір тексту Width Ширина Number Seed Базове значення Obfuscation Factor Коефіцієнт заплутування Item Shadow Тінь пункту Item Settings Параметри пункту kImageAnnotator::AnnotationTabContextMenu Close Закрити Close Other Закрити інші Close All Закрити всі Close All to the Left Закрити усі ліворуч Close All to the Right Закрити усі праворуч kImageAnnotator::AnnotationToolSelection Tool Selection Вибір інструмента kImageAnnotator::BoolPicker Enabled Увімкнено Disabled Вимкнено kImageAnnotator::CropWidget Cancel Скасувати X: X: Y: Y: W: Ш: H: В: Apply Застосувати kImageAnnotator::FillModePicker Border And Fill Visibility Видимість рамки і заповнення Border and Fill Рамка і заповнення Border and No Fill Рамка без заповнення No Border and No Fill Без рамки і заповнення kImageAnnotator::FontPicker Font Size Розмір шрифту Bold Жирний Italic Курсив Underline Підкреслення kImageAnnotator::ImageEffectPicker Image Effects Ефекти зображення No Effect Без ефектів Drop Shadow Відкидання тіні Grayscale Відтінки сірого Border Рамка Invert Color Інвертувати кольори kImageAnnotator::ModifyCanvasWidget Restricted Обмеження When enabled enforces the canvas to include the background image. Якщо увімкнено, примусово включати до полотна фонове зображення. X: X: Y: Y: W: Ш: H: В: Apply Застосувати Cancel Скасувати Color: Колір: Canvas Background Color Колір тла полотна kImageAnnotator::RotateDialog Rotate Image Обертати зображення 180° 180° 90° Clockwise 90° за годинниковою стрілкою 90° Counter Clockwise 90° проти годинникової стрілки Arbitrary Довільне Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Додатні значення призводять до обертання за годинниковою стрілкою, від'ємні — проти годинникової стрілки. Обертання на кути, кратні до 90°, може призвести до втрати якості. Horizontal Горизонтально Vertical Вертикально OK Гаразд Cancel Скасувати Rotate Обертати Flip Перевернути kImageAnnotator::ScaleDialog Scale Image Масштабувати зображення Keep Aspect Ratio Зберігати пропорції Width: Ширина: Height: Висота: OK Гаразд Cancel Скасувати Pixel Піксель Percent Частка kImageAnnotator::StickerPicker Sticker Наліпка kImageAnnotator::ToolPicker Select Вибрати Pen Перо Number Номер Marker Rectangle Прямокутна позначка Marker Ellipse Еліптична позначка Marker Pen Позначка пером Text Текст Arrow Стрілка Double Arrow Подвійна стрілка Line Пряма Blur Розмивання Rectangle Прямокутник Ellipse Еліпс Number Pointer Нумерований вказівник Sticker Наліпка Pixelate Пікселізація Text Pointer Вказівник з текстом Text Arrow Стрілка з текстом Number Arrow Стрілка з номером Duplicate Дублювання kImageAnnotator::ZoomPicker Zoom In (%1) Збільшити (%1) Zoom Out (%1) Зменшити (%1) Reset Zoom (%1) Відновити масштаб (%1) kImageAnnotator-0.5.3/translations/kImageAnnotator_zh_CN.ts000066400000000000000000000305031414424500400240360ustar00rootroot00000000000000 kImageAnnotator::AnnotationContextMenu Arrange 排序 Bring to Front 置于顶层 Bring Forward 上移一层 Send Backward 下移一层 Send to Back 置于底层 Select This 选中当前 Copy 复制 Paste 粘贴 Edit 编辑 Delete 删除 kImageAnnotator::AnnotationGeneralSettings General Settings 通用设置 kImageAnnotator::AnnotationImageSettings Image Settings 图像设置 kImageAnnotator::AnnotationItemSettings Color 颜色 Text Color 文本颜色 Width 宽度 Number Seed 当前数字 Obfuscation Factor 模糊系数 Item Shadow 项影 Item Settings 元素设置 kImageAnnotator::AnnotationTabContextMenu Close 关闭 Close Other 关闭其它 Close All 关闭全部 Close All to the Left 关闭左侧 Close All to the Right 关闭右侧 kImageAnnotator::AnnotationToolSelection Tool Selection 工具选择 kImageAnnotator::BoolPicker Enabled 开启 Disabled 关闭 kImageAnnotator::CropWidget Cancel 取消 X: X: Y: Y: W: 宽度: H: 高度: Apply 应用 kImageAnnotator::FillModePicker Border And Fill Visibility 边框和填充可见性 Border and Fill 有边框且有填充 Border and No Fill 有边框且无填充 No Border and No Fill 无边框且无填充 kImageAnnotator::FontPicker Font Size 字体大小 Bold 粗体 Italic 斜体 Underline 下划线 kImageAnnotator::ImageEffectPicker Image Effects 滤镜 No Effect 无滤镜 Drop Shadow 阴影 Grayscale 灰度 Border 描边 Invert Color 反转色 kImageAnnotator::ModifyCanvasWidget Restricted When enabled enforces the canvas to include the background image. X: X: Y: Y: W: 宽度: H: 高度: Apply 应用 Cancel 取消 Color: 颜色: Canvas Background Color 画布背景色 kImageAnnotator::RotateDialog Rotate Image 旋转图片 180° 180° 90° Clockwise 顺时针旋转90° 90° Counter Clockwise 逆时针旋转90° Arbitrary Positive values rotate clockwise, negative values counter clockwise. Rotating by non 90° multipliers might introduce loss of quality. Horizontal 水平 Vertical 垂直 OK 确定 Cancel 取消 Rotate 旋转 Flip 反转 kImageAnnotator::ScaleDialog Scale Image 缩放图像 Keep Aspect Ratio 保持长宽比 Width: 宽度: Height: 高度: OK 确定 Cancel 取消 Pixel 像素 Percent 百分比 kImageAnnotator::StickerPicker Sticker 贴纸 kImageAnnotator::ToolPicker Select 选择 Pen Number 数字 Marker Rectangle 高亮矩形区域 Marker Ellipse 高亮椭圆区域 Marker Pen 高亮笔 Text 文本 Arrow 箭头 Double Arrow 双箭头 Line 线段 Blur 模糊 Rectangle 矩形 Ellipse 椭圆 Number Pointer 数字标注 Sticker 贴纸 Pixelate 像素化 Text Pointer 文字标注 Text Arrow 文字箭头标注 Number Arrow 数字箭头标注 Duplicate 复制 kImageAnnotator::ZoomPicker Zoom In (%1) 放大(%1) Zoom Out (%1) 缩小(%1) Reset Zoom (%1) 重置大小(%1)