From 33cfd7e949b1e97fc91b04120a0bdc8481295c5b Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Tue, 21 Apr 2020 15:14:26 +0200 Subject: [PATCH 01/12] Convert to CMake --- .clang-format | 126 ++++++++++++++++++++++++++ .gitignore | 86 +++++++++++++++++- .idea/.gitignore | 6 ++ .idea/.name | 1 + .idea/caesium-image-compressor.iml | 2 + .idea/codeStyles/Project.xml | 13 +++ .idea/codeStyles/codeStyleConfig.xml | 5 + .idea/misc.xml | 4 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 ++ CMakeLists.txt | 68 ++++++++++++++ caesium-image-compressor.pro | 87 ------------------ qt.conf | 2 +- src/MainWindow.cpp | 16 +--- src/MainWindow.h | 11 +-- src/main.cpp | 1 - src/models/CImage.cpp | 5 - src/models/CImage.h | 4 +- src/models/CImageTreeItem.cpp | 5 - src/models/CImageTreeItem.h | 3 +- src/models/CImageTreeModel.cpp | 1 - src/utils/Utils.cpp | 7 +- src/utils/Utils.h | 3 +- src/widgets/QDropTreeView.cpp | 2 - src/widgets/QDropTreeView.h | 4 +- src/widgets/QTreeViewItemDelegate.cpp | 32 ------- src/widgets/QTreeViewItemDelegate.h | 21 ----- src/widgets/QZoomGraphicsView.h | 3 +- views/MainWindow.ui | 14 ++- 29 files changed, 356 insertions(+), 190 deletions(-) create mode 100644 .clang-format create mode 100644 .idea/.gitignore create mode 100644 .idea/.name create mode 100644 .idea/caesium-image-compressor.iml create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 CMakeLists.txt delete mode 100644 caesium-image-compressor.pro delete mode 100644 src/widgets/QTreeViewItemDelegate.cpp delete mode 100644 src/widgets/QTreeViewItemDelegate.h diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..2bda4072 --- /dev/null +++ b/.clang-format @@ -0,0 +1,126 @@ +--- +Language: Cpp +# BasedOnStyle: WebKit +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: false +AlignTrailingComments: false +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: All +BreakBeforeBraces: WebKit +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseTab: Never +... + diff --git a/.gitignore b/.gitignore index fab7372d..6f3351b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # This file is used to ignore files which are generated # ---------------------------------------------------------------------------- - +.DS_STORE *~ *.autosave *.a @@ -71,3 +71,87 @@ Thumbs.db *.dll *.exe +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..8bf4d45d --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,6 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 00000000..564fef85 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +caesium_image_compressor \ No newline at end of file diff --git a/.idea/caesium-image-compressor.iml b/.idea/caesium-image-compressor.iml new file mode 100644 index 00000000..f08604bb --- /dev/null +++ b/.idea/caesium-image-compressor.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..0226d7e9 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..79ee123c --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..79b3c948 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..5dcd2c9e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..64221587 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,68 @@ +cmake_minimum_required(VERSION 3.5) + +project(caesium_image_compressor LANGUAGES CXX) + +if(CMAKE_VERSION VERSION_LESS "3.7.0") + set(CMAKE_INCLUDE_CURRENT_DIR ON) +endif() + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_AUTOUIC_SEARCH_PATHS views) + +if (APPLE) + SET(MACOSX_DEPLOYMENT_TARGET 10.14) +endif() + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nullability-completeness") + +if (NOT (DEFINED ENV{Qt5_DIR} OR DEFINED Qt5_DIR)) + message(FATAL_ERROR "Qt5_DIR is not defined. Cannot find Qt5 dir." ) +endif() + +message(${PROJECT_SOURCE_DIR}) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/include) + +if (APPLE) + link_directories(/usr/local/lib) +elseif (WIN32) + link_directories("C:\\libcaesium\\lib") +endif () + +find_package(Qt5 COMPONENTS Widgets Core Gui Concurrent Svg REQUIRED) + +set(SOURCES + src/main.cpp + src/MainWindow.cpp + src/models/CImage.cpp + src/models/CImageTreeItem.cpp + src/models/CImageTreeModel.cpp + src/utils/Utils.cpp + src/dialogs/AboutDialog.cpp + src/widgets/QDropTreeView.cpp + src/widgets/QZoomGraphicsView.cpp) + +set(HEADERS + src/vendor/caesium.h + src/MainWindow.h + src/models/CImage.h + src/models/CImageTreeItem.h + src/models/CImageTreeModel.h + src/utils/Utils.h + src/dialogs/AboutDialog.h + src/widgets/QDropTreeView.h + src/widgets/QZoomGraphicsView.h) + +set(UI + views/MainWindow.ui + views/AboutDialog.ui) + +add_executable(caesium_image_compressor ${SOURCES} ${HEADERS} ${UI}) + +target_link_libraries(caesium_image_compressor PRIVATE Qt5::Widgets Qt5::Core Qt5::Gui Qt5::Concurrent Qt5::Svg caesium) diff --git a/caesium-image-compressor.pro b/caesium-image-compressor.pro deleted file mode 100644 index cb7361d3..00000000 --- a/caesium-image-compressor.pro +++ /dev/null @@ -1,87 +0,0 @@ -QT += core gui concurrent svg - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -CONFIG += c++11 -unix: { - QMAKE_CFLAGS += -Wno-nullability-completeness - QMAKE_CXXFLAGS += -Wno-nullability-completeness -} - -# The following define makes your compiler emit warnings if you use -# any Qt feature that has been marked deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -TARGET = "Caesium Image Compressor" -macx: { - ICON = resources/icons/icon.icns - QMAKE_INFO_PLIST = Info.plist - QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.14 - QMAKE_RPATHDIR += @executable_path/../Frameworks - -} -win32: { - RC_ICONS = resources/icons/icon.ico -} - -SOURCES += \ - src/main.cpp \ - src/MainWindow.cpp \ - src/models/CImage.cpp \ - src/models/CImageTreeItem.cpp \ - src/models/CImageTreeModel.cpp \ - src/utils/Utils.cpp \ - src/dialogs/AboutDialog.cpp \ - src/widgets/QDropTreeView.cpp \ - src/widgets/QTreeViewItemDelegate.cpp \ - src/widgets/QZoomGraphicsView.cpp - -HEADERS += \ - src/vendor/caesium.h \ - src/MainWindow.h \ - src/models/CImage.h \ - src/models/CImageTreeItem.h \ - src/models/CImageTreeModel.h \ - src/utils/Utils.h \ - src/dialogs/AboutDialog.h \ - src/widgets/QDropTreeView.h \ - src/widgets/QTreeViewItemDelegate.h \ - src/widgets/QZoomGraphicsView.h - -FORMS += \ - views/MainWindow.ui \ - views/AboutDialog.ui - -TRANSLATIONS += \ - locale/en_US.ts - -RESOURCES += \ - resources/resources.qrc - -unix: { - LIBS += -L"/usr/local/lib/caesium" -lcaesium -} - -win32: { - LIBS += -L"C:\\libcaesium\\lib" -lcaesium \ - -L"C:\\zopfli\\lib" -lzopflipng \ - -L"C:\\mozjpeg\\lib" -ljpeg \ - -L"C:\\mozjpeg\\lib" -lturbojpeg \ -} - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target - -DISTFILES += \ - Info.plist \ - README.md \ - CHANGELOG.md diff --git a/qt.conf b/qt.conf index dd3d6ec6..8bd4ac8e 100644 --- a/qt.conf +++ b/qt.conf @@ -1,3 +1,3 @@ [Paths] Prefix = . -Translations = :/translations +Translations = :/locale diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 32833b83..16dab4db 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1,22 +1,14 @@ #include "MainWindow.h" -#include "src/dialogs/AboutDialog.h" -#include "src/utils/Utils.h" +#include "./dialogs/AboutDialog.h" #include "ui_MainWindow.h" +#include -#include -#include #include -#include -#include #include #include #include -#include -#include #include -#include - MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) , ui(new Ui::MainWindow) @@ -26,11 +18,9 @@ MainWindow::MainWindow(QWidget* parent) this->cImageModel = new CImageTreeModel(); this->previewScene = new QGraphicsScene(); ui->preview_graphicsView->setScene(this->previewScene); - // this->listViewDelegate = new QTreeViewItemDelegate(ui->imageList_TreeView, this); ui->imageList_TreeView->setModel(this->cImageModel); ui->imageList_TreeView->setIconSize(QSize(10, 10)); ui->imageList_TreeView->header()->setSectionResizeMode(0, QHeaderView::Stretch); - // ui->imageList_TreeView->setItemDelegate(listViewDelegate); ui->main_Splitter->setSizes(QList({ 500, 1 })); @@ -281,7 +271,7 @@ void MainWindow::closeEvent(QCloseEvent* event) event->accept(); } -void MainWindow::resizeEvent(QResizeEvent* event) +void MainWindow::resizeEvent(__unused QResizeEvent* event) { ui->preview_graphicsView->fitInView(this->previewScene->itemsBoundingRect(), Qt::KeepAspectRatio); } diff --git a/src/MainWindow.h b/src/MainWindow.h index f806df48..5c03fd54 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -1,3 +1,4 @@ +#include #ifndef MAINWINDOW_H #define MAINWINDOW_H @@ -6,11 +7,8 @@ #include #include -#include - -#include - -#include "src/models/CImage.h" +#include "models/CImageTreeModel.h" +#include "models/CImage.h" QT_BEGIN_NAMESPACE namespace Ui { @@ -28,7 +26,7 @@ class MainWindow : public QMainWindow { protected: void closeEvent(QCloseEvent* event) override; - void resizeEvent(QResizeEvent* event) override; + void resizeEvent(__unused QResizeEvent* event) override; private slots: @@ -57,7 +55,6 @@ private slots: Ui::MainWindow* ui; CImageTreeModel* cImageModel; - QTreeViewItemDelegate* listViewDelegate; QFutureWatcher compressionWatcher; QGraphicsScene* previewScene; QMap folderMap; diff --git a/src/main.cpp b/src/main.cpp index 5301833c..854c3ba8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,6 @@ #include "MainWindow.h" #include -#include int main(int argc, char* argv[]) { diff --git a/src/models/CImage.cpp b/src/models/CImage.cpp index 9db254be..d83874e6 100644 --- a/src/models/CImage.cpp +++ b/src/models/CImage.cpp @@ -1,11 +1,6 @@ #include "CImage.h" -#include "src/utils/Utils.h" -#include - -#include #include -#include #include #include diff --git a/src/models/CImage.h b/src/models/CImage.h index f51263d2..a0b9cadf 100644 --- a/src/models/CImage.h +++ b/src/models/CImage.h @@ -4,7 +4,7 @@ #include #include -#include +#include "../utils/Utils.h" class CImage { @@ -43,8 +43,6 @@ class CImage size_t size; size_t compressedSize; - QString formattedSize; - QString compressedFormattedSize; int width; int height; diff --git a/src/models/CImageTreeItem.cpp b/src/models/CImageTreeItem.cpp index 251ee139..2e44ece7 100644 --- a/src/models/CImageTreeItem.cpp +++ b/src/models/CImageTreeItem.cpp @@ -105,11 +105,6 @@ QFuture CImageTreeItem::compress(CompressionOptions compressionOptions) }); } -void CImageTreeItem::setData(int column, QString data) -{ - this->m_itemData.replace(column, QVariant(data)); -} - void CImageTreeItem::setData(QStringList data) { QVector columnData; diff --git a/src/models/CImageTreeItem.h b/src/models/CImageTreeItem.h index 32bb71fd..56676272 100644 --- a/src/models/CImageTreeItem.h +++ b/src/models/CImageTreeItem.h @@ -5,7 +5,7 @@ #include #include -#include "src/models/CImage.h" +#include "CImage.h" class CImageTreeItem { public: @@ -29,7 +29,6 @@ class CImageTreeItem { CImage *getCImage() const; QFuture compress(CompressionOptions compressionOptions); - void setData(int column, QString data); void setData(QStringList data); private: diff --git a/src/models/CImageTreeModel.cpp b/src/models/CImageTreeModel.cpp index ac2982da..4ddb67ef 100644 --- a/src/models/CImageTreeModel.cpp +++ b/src/models/CImageTreeModel.cpp @@ -1,6 +1,5 @@ #include "CImageTreeModel.h" -#include #include CImageTreeModel::CImageTreeModel() diff --git a/src/utils/Utils.cpp b/src/utils/Utils.cpp index f4d253f0..8fd71f92 100644 --- a/src/utils/Utils.cpp +++ b/src/utils/Utils.cpp @@ -3,8 +3,6 @@ #include #include #include -#include -#include QString toHumanSize(size_t size) { @@ -36,7 +34,7 @@ QSize getScaledSizeWithRatio(QSize size, int square) int w = size.width(); int h = size.height(); - double ratio = 0.0; + double ratio; //Check the biggest between the two and scale on that dimension if (w >= h) { @@ -134,8 +132,9 @@ QString getRootFolder(QMap folderMap) if (QString::compare(splittedNewFolder.at(i), splittedRootFolder.at(i)) != 0) { if (i == 0) { rootFolderPath = QDir::rootPath(); + } else { + rootFolderPath = QDir(QDir::rootPath() + splittedCommonPath.join(QDir::separator())).absolutePath(); } - rootFolderPath = QDir(QDir::rootPath() + splittedCommonPath.join(QDir::separator())).absolutePath(); break; } splittedCommonPath.append(splittedNewFolder.at(i)); diff --git a/src/utils/Utils.h b/src/utils/Utils.h index ccbec8d5..c4465fd2 100644 --- a/src/utils/Utils.h +++ b/src/utils/Utils.h @@ -4,8 +4,9 @@ #include #include #include +#include -#include +#include "../vendor/caesium.h" enum class CImageStatus { UNCOMPRESSED, diff --git a/src/widgets/QDropTreeView.cpp b/src/widgets/QDropTreeView.cpp index 3878d794..758df61e 100755 --- a/src/widgets/QDropTreeView.cpp +++ b/src/widgets/QDropTreeView.cpp @@ -1,9 +1,7 @@ #include "QDropTreeView.h" -#include #include #include -#include #include diff --git a/src/widgets/QDropTreeView.h b/src/widgets/QDropTreeView.h index 5cc2c313..6e06e68c 100755 --- a/src/widgets/QDropTreeView.h +++ b/src/widgets/QDropTreeView.h @@ -1,10 +1,10 @@ +#include #ifndef QDROPTREEWIDGET_H #define QDROPTREEWIDGET_H #include class QMimeData; -class Caesium; class QDropTreeView : public QTreeView { @@ -21,6 +21,6 @@ class QDropTreeView : public QTreeView void dragMoveEvent(QDragMoveEvent *event) override; void dropEvent(QDropEvent *event) override; -}; +} __unused; #endif // QDROPTREEWIDGET_H diff --git a/src/widgets/QTreeViewItemDelegate.cpp b/src/widgets/QTreeViewItemDelegate.cpp deleted file mode 100644 index 13a473e8..00000000 --- a/src/widgets/QTreeViewItemDelegate.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "QTreeViewItemDelegate.h" - -/* Here for future use */ - -QTreeViewItemDelegate::QTreeViewItemDelegate(QTreeView* view, QObject* parent) - : QStyledItemDelegate(parent) - , m_view(view) -{ - svgRenderer = new QSvgRenderer(m_view); - connect(svgRenderer, &QSvgRenderer::repaintNeeded, [this] { - m_view->viewport()->update(); - }); -} - -void QTreeViewItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const -{ - QStyleOptionViewItem opt { option }; - initStyleOption(&opt, index); - - if (index.column() == 0) { - this->svgRenderer->load(QString(":/icons/compression_statuses/compressing.svg")); - if (false) { - auto bounds = opt.rect; - bounds.setWidth(16); - bounds.moveTo(2, opt.rect.center().y() - bounds.height() / 2); - - this->svgRenderer->render(painter, bounds); - } - } - - QStyledItemDelegate::paint(painter, opt, index); -} diff --git a/src/widgets/QTreeViewItemDelegate.h b/src/widgets/QTreeViewItemDelegate.h deleted file mode 100644 index 2d57a434..00000000 --- a/src/widgets/QTreeViewItemDelegate.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef QTREEVIEWITEMDELEGATE_H -#define QTREEVIEWITEMDELEGATE_H - -#include -#include -#include - -class QTreeViewItemDelegate : public QStyledItemDelegate -{ - Q_OBJECT -public: - QTreeViewItemDelegate(QTreeView* view, QObject* parent); - - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; - -private: - QSvgRenderer* svgRenderer; - QTreeView* m_view; -}; - -#endif // QTREEVIEWITEMDELEGATE_H diff --git a/src/widgets/QZoomGraphicsView.h b/src/widgets/QZoomGraphicsView.h index 22c427a2..64c1eb85 100644 --- a/src/widgets/QZoomGraphicsView.h +++ b/src/widgets/QZoomGraphicsView.h @@ -1,3 +1,4 @@ +#include #ifndef QZOOMGRAPHICSVIEW_H #define QZOOMGRAPHICSVIEW_H @@ -11,6 +12,6 @@ class QZoomGraphicsView : public QGraphicsView public: explicit QZoomGraphicsView(QWidget *parent = 0); void wheelEvent(QWheelEvent* event); -}; +} __unused; #endif // QZOOMGRAPHICSVIEW_H diff --git a/views/MainWindow.ui b/views/MainWindow.ui index 7c6f6c8f..39545da8 100644 --- a/views/MainWindow.ui +++ b/views/MainWindow.ui @@ -254,6 +254,18 @@ + + + + Resize + + + + + + + + @@ -452,7 +464,7 @@ QZoomGraphicsView QGraphicsView -
src/widgets/QZoomGraphicsView.h
+
./widgets/QZoomGraphicsView.h
From bdc1ddaedd04fac1d899ee5e549e641e49ea57f7 Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Tue, 28 Apr 2020 09:22:20 +0200 Subject: [PATCH 02/12] Resize UI options --- CMakeLists.txt | 5 +- src/MainWindow.cpp | 4 +- src/MainWindow.h | 12 +- src/utils/Utils.cpp | 17 --- src/utils/Utils.h | 1 - views/MainWindow.ui | 310 +++++++++++++++++++++++++++++--------------- 6 files changed, 218 insertions(+), 131 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64221587..a0aa8096 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,9 @@ set(UI views/MainWindow.ui views/AboutDialog.ui) -add_executable(caesium_image_compressor ${SOURCES} ${HEADERS} ${UI}) +set(RESOURCES resources/resources.qrc) + +add_executable(caesium_image_compressor ${SOURCES} ${HEADERS} ${UI} ${RESOURCES}) +set_target_properties(caesium_image_compressor PROPERTIES OUTPUT_NAME "Caesium Image Compressor") target_link_libraries(caesium_image_compressor PRIVATE Qt5::Widgets Qt5::Core Qt5::Gui Qt5::Concurrent Qt5::Svg caesium) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 16dab4db..e70218ef 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1,7 +1,6 @@ #include "MainWindow.h" #include "./dialogs/AboutDialog.h" #include "ui_MainWindow.h" -#include #include #include @@ -22,7 +21,8 @@ MainWindow::MainWindow(QWidget* parent) ui->imageList_TreeView->setIconSize(QSize(10, 10)); ui->imageList_TreeView->header()->setSectionResizeMode(0, QHeaderView::Stretch); - ui->main_Splitter->setSizes(QList({ 500, 1 })); + ui->main_Splitter->setSizes(QList({ 600, 1 })); + ui->left_Splitter->setSizes(QList({ 100, 1 })); connect(ui->imageList_TreeView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(imageList_selectionChanged(const QModelIndex&, const QModelIndex&))); this->readSettings(); diff --git a/src/MainWindow.h b/src/MainWindow.h index 5c03fd54..ce0474bc 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -7,8 +7,8 @@ #include #include -#include "models/CImageTreeModel.h" #include "models/CImage.h" +#include "models/CImageTreeModel.h" QT_BEGIN_NAMESPACE namespace Ui { @@ -41,16 +41,12 @@ private slots: void on_lossless_Checkbox_stateChanged(int arg1); void on_keepMetadata_Checkbox_stateChanged(int arg1); void on_compression_Slider_valueChanged(int value); - - void imageList_selectionChanged(const QModelIndex ¤t, const QModelIndex &previous); - void compressionFinished(); - void on_keepStructure_Checkbox_stateChanged(int arg1); - void on_actionRemove_triggered(); - void on_actionClear_triggered(); + void imageList_selectionChanged(const QModelIndex& current, const QModelIndex& previous); + void compressionFinished(); private: Ui::MainWindow* ui; @@ -66,7 +62,7 @@ private slots: void writeSettings(); void writeSetting(const QString& key, const QVariant& value); void readSettings(); - void previewImage(const QModelIndex &imageIndex); + void previewImage(const QModelIndex& imageIndex); void updateFolderMap(QString baseFolder, int count); QVariant readSetting(const QString& key); }; diff --git a/src/utils/Utils.cpp b/src/utils/Utils.cpp index 8fd71f92..3f4a7e79 100644 --- a/src/utils/Utils.cpp +++ b/src/utils/Utils.cpp @@ -29,23 +29,6 @@ QString toHumanSize(size_t size) return QString::number(size / (pow(1024, order)), 'f', 2) + ' ' + unit[(int)order]; } -QSize getScaledSizeWithRatio(QSize size, int square) -{ - int w = size.width(); - int h = size.height(); - - double ratio; - - //Check the biggest between the two and scale on that dimension - if (w >= h) { - ratio = w / (double)square; - } else { - ratio = h / (double)square; - } - - return QSize((int)round(w / ratio), (int)h / ratio); -} - //TODO Another thread? QStringList scanDirectory(QString directory) { diff --git a/src/utils/Utils.h b/src/utils/Utils.h index c4465fd2..3c4ed0ec 100644 --- a/src/utils/Utils.h +++ b/src/utils/Utils.h @@ -37,7 +37,6 @@ typedef struct CompressionOptions //Utilities QString toHumanSize(size_t size); -QSize getScaledSizeWithRatio(QSize size, int square); QStringList scanDirectory(QString directory); cs_image_pars getCompressionParametersFromLevel(int level, bool lossless, bool keepMetadata); QString getRootFolder(QMap folderMap); diff --git a/views/MainWindow.ui b/views/MainWindow.ui index 39545da8..1c85480f 100644 --- a/views/MainWindow.ui +++ b/views/MainWindow.ui @@ -6,8 +6,8 @@ 0 0 - 880 - 636 + 943 + 641
@@ -17,102 +17,100 @@ - + - - 3 - - - 3 - Qt::Horizontal - - true - - - 6 - - - - - - - QAbstractItemView::DropOnly - - - Qt::MoveAction - - - true - - - QAbstractItemView::ExtendedSelection - - - 0 - - - false - - - false - - - true - - - false - - - false - - - false - - - - - - - - - Add - - - - - - - Remove - - - - - - - Qt::Horizontal - - - - 256 - 20 - - - - - - - - Compress - - - - - - + + + Qt::Vertical + + + + + + + QAbstractItemView::DropOnly + + + Qt::MoveAction + + + true + + + QAbstractItemView::ExtendedSelection + + + 0 + + + false + + + false + + + true + + + false + + + false + + + false + + + + + + + + + Add + + + + + + + Remove + + + + + + + Qt::Horizontal + + + + 247 + 17 + + + + + + + + Compress + + + + + + + + + + QGraphicsView::ScrollHandDrag + + @@ -259,9 +257,124 @@ Resize + + true + - + + + + + + + + 0 + 0 + + + + Resize to fit + + + + + + + + Dimensions + + + + + Percentage + + + + + Short edge + + + + + Long edge + + + + + + + + + + + + Width + + + + + + + px + + + 1 + + + 99999 + + + 1000 + + + + + + + Height + + + + + + + px + + + 1 + + + 99999 + + + 1000 + + + + + + + + + Keep aspect ratio + + + true + + + + + + + Do not enlarge + + + true + + + + @@ -364,13 +477,6 @@ - - - - QGraphicsView::ScrollHandDrag - - -
@@ -383,7 +489,7 @@ 0 0 - 880 + 943 22 From 7eb1f4e3ad947a499d2c496f1ed7c4c58887730b Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Wed, 6 May 2020 15:19:48 +0200 Subject: [PATCH 03/12] Accept drops in list --- src/MainWindow.cpp | 6 ++++++ src/MainWindow.h | 1 + src/widgets/QDropTreeView.cpp | 8 ++++++-- views/MainWindow.ui | 9 +++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index e70218ef..605fde3b 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -25,6 +25,7 @@ MainWindow::MainWindow(QWidget* parent) ui->left_Splitter->setSizes(QList({ 100, 1 })); connect(ui->imageList_TreeView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(imageList_selectionChanged(const QModelIndex&, const QModelIndex&))); + connect(ui->imageList_TreeView, SIGNAL(dropFinished(QStringList)), this, SLOT(dropFinished(QStringList))); this->readSettings(); } @@ -339,3 +340,8 @@ void MainWindow::on_actionClear_triggered() { this->removeFiles(true); } +void MainWindow::dropFinished(QStringList filePaths) +{ + QString baseFolder = QFileInfo(filePaths.at(0)).absolutePath(); + MainWindow::importFiles(filePaths, baseFolder); +} diff --git a/src/MainWindow.h b/src/MainWindow.h index ce0474bc..c818928d 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -47,6 +47,7 @@ private slots: void imageList_selectionChanged(const QModelIndex& current, const QModelIndex& previous); void compressionFinished(); + void dropFinished(QStringList filePaths); private: Ui::MainWindow* ui; diff --git a/src/widgets/QDropTreeView.cpp b/src/widgets/QDropTreeView.cpp index 758df61e..bd78e31c 100755 --- a/src/widgets/QDropTreeView.cpp +++ b/src/widgets/QDropTreeView.cpp @@ -4,6 +4,7 @@ #include #include +#include QDropTreeView::QDropTreeView(QWidget *parent) : QTreeView(parent) @@ -23,10 +24,13 @@ void QDropTreeView::dropEvent(QDropEvent *event) { QStringList fileList; if (mimeData->hasFormat("text/uri-list")) { foreach (QUrl url, urlList) { - fileList << url.toLocalFile(); + QString absolutePath = url.toLocalFile(); + //TODO This is limitation by now. We only accept drops for files. May be changed in the future. + if (QFileInfo(absolutePath).isFile()) { + fileList << url.toLocalFile(); + } } } event->acceptProposedAction(); - qDebug() << fileList; emit dropFinished(fileList); } diff --git a/views/MainWindow.ui b/views/MainWindow.ui index 1c85480f..f7116718 100644 --- a/views/MainWindow.ui +++ b/views/MainWindow.ui @@ -27,10 +27,10 @@ Qt::Vertical - + - + QAbstractItemView::DropOnly @@ -572,6 +572,11 @@ QGraphicsView
./widgets/QZoomGraphicsView.h
+ + QDropTreeView + QTreeView +
widgets/QDropTreeView.h
+
From b701da103cc25ff04acb8ea5dac9ca151704c434 Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Sun, 10 May 2020 18:06:18 +0200 Subject: [PATCH 04/12] Resize --- CMakeLists.txt | 63 ++++++++------ src/MainWindow.cpp | 139 ++++++++++++++++++++++++++++-- src/MainWindow.h | 14 +++ src/main.cpp | 28 ++++++ src/models/CImage.cpp | 43 ++++++--- src/utils/Utils.cpp | 35 +++++++- src/utils/Utils.h | 21 ++++- src/widgets/QZoomGraphicsView.cpp | 5 ++ src/widgets/QZoomGraphicsView.h | 1 + views/MainWindow.ui | 69 ++++++++++++++- 10 files changed, 365 insertions(+), 53 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a0aa8096..cf0a2a8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.5) project(caesium_image_compressor LANGUAGES CXX) -if(CMAKE_VERSION VERSION_LESS "3.7.0") +if (CMAKE_VERSION VERSION_LESS "3.7.0") set(CMAKE_INCLUDE_CURRENT_DIR ON) -endif() +endif () set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) @@ -16,16 +16,18 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_AUTOUIC_SEARCH_PATHS views) if (APPLE) - SET(MACOSX_DEPLOYMENT_TARGET 10.14) -endif() + set(MACOSX_DEPLOYMENT_TARGET 10.14) + set(MACOSX_BUNDLE_ICON_FILE icon.icns) + set(CAESIUM_ICON ${CMAKE_CURRENT_SOURCE_DIR}/resources/icons/icon.icns) + set_source_files_properties(${CAESIUM_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION "resources/icons") +endif () set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nullability-completeness") if (NOT (DEFINED ENV{Qt5_DIR} OR DEFINED Qt5_DIR)) - message(FATAL_ERROR "Qt5_DIR is not defined. Cannot find Qt5 dir." ) -endif() + message(FATAL_ERROR "Qt5_DIR is not defined. Cannot find Qt5 dir.") +endif () -message(${PROJECT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/include) @@ -38,34 +40,39 @@ endif () find_package(Qt5 COMPONENTS Widgets Core Gui Concurrent Svg REQUIRED) set(SOURCES - src/main.cpp - src/MainWindow.cpp - src/models/CImage.cpp - src/models/CImageTreeItem.cpp - src/models/CImageTreeModel.cpp - src/utils/Utils.cpp - src/dialogs/AboutDialog.cpp - src/widgets/QDropTreeView.cpp + src/main.cpp + src/MainWindow.cpp + src/models/CImage.cpp + src/models/CImageTreeItem.cpp + src/models/CImageTreeModel.cpp + src/utils/Utils.cpp + src/dialogs/AboutDialog.cpp + src/widgets/QDropTreeView.cpp src/widgets/QZoomGraphicsView.cpp) set(HEADERS - src/vendor/caesium.h - src/MainWindow.h - src/models/CImage.h - src/models/CImageTreeItem.h - src/models/CImageTreeModel.h - src/utils/Utils.h - src/dialogs/AboutDialog.h - src/widgets/QDropTreeView.h + src/vendor/caesium.h + src/MainWindow.h + src/models/CImage.h + src/models/CImageTreeItem.h + src/models/CImageTreeModel.h + src/utils/Utils.h + src/dialogs/AboutDialog.h + src/widgets/QDropTreeView.h src/widgets/QZoomGraphicsView.h) set(UI - views/MainWindow.ui - views/AboutDialog.ui) + views/MainWindow.ui + views/AboutDialog.ui) set(RESOURCES resources/resources.qrc) -add_executable(caesium_image_compressor ${SOURCES} ${HEADERS} ${UI} ${RESOURCES}) -set_target_properties(caesium_image_compressor PROPERTIES OUTPUT_NAME "Caesium Image Compressor") +if (APPLE) + add_executable(caesium_image_compressor MACOSX_BUNDLE ${CAESIUM_ICON} ${SOURCES} ${HEADERS} ${UI} ${RESOURCES}) + set_target_properties(caesium_image_compressor PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/Info.plist") +else () + add_executable(caesium_image_compressor ${SOURCES} ${HEADERS} ${UI} ${RESOURCES}) +endif () -target_link_libraries(caesium_image_compressor PRIVATE Qt5::Widgets Qt5::Core Qt5::Gui Qt5::Concurrent Qt5::Svg caesium) +set_target_properties(caesium_image_compressor PROPERTIES OUTPUT_NAME "Caesium Image Compressor") +target_link_libraries(caesium_image_compressor PRIVATE Qt5::Widgets Qt5::Core Qt5::Gui Qt5::Concurrent Qt5::Svg caesium) \ No newline at end of file diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 605fde3b..c2152a2e 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1,6 +1,7 @@ #include "MainWindow.h" #include "./dialogs/AboutDialog.h" #include "ui_MainWindow.h" +#include "./utils/Utils.h" #include #include @@ -13,6 +14,7 @@ MainWindow::MainWindow(QWidget* parent) , ui(new Ui::MainWindow) { ui->setupUi(this); + qDebug() << "Starting application"; this->cImageModel = new CImageTreeModel(); this->previewScene = new QGraphicsScene(); @@ -21,12 +23,15 @@ MainWindow::MainWindow(QWidget* parent) ui->imageList_TreeView->setIconSize(QSize(10, 10)); ui->imageList_TreeView->header()->setSectionResizeMode(0, QHeaderView::Stretch); - ui->main_Splitter->setSizes(QList({ 600, 1 })); - ui->left_Splitter->setSizes(QList({ 100, 1 })); - connect(ui->imageList_TreeView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(imageList_selectionChanged(const QModelIndex&, const QModelIndex&))); connect(ui->imageList_TreeView, SIGNAL(dropFinished(QStringList)), this, SLOT(dropFinished(QStringList))); this->readSettings(); + + this->on_fitTo_ComboBox_currentIndexChanged(ui->fitTo_ComboBox->currentIndex()); + this->on_keepAspectRatio_CheckBox_toggled(ui->keepAspectRatio_CheckBox->isChecked()); + this->on_doNotEnlarge_CheckBox_toggled(ui->doNotEnlarge_CheckBox->isChecked()); + ui->main_Splitter->setSizes(QList({ 700, 1 })); + ui->left_Splitter->setSizes(QList({ 100, 1 })); } MainWindow::~MainWindow() @@ -99,6 +104,14 @@ void MainWindow::writeSettings() settings.setValue("compression_options/compression/keep_metadata", this->ui->keepMetadata_Checkbox->isChecked()); settings.setValue("compression_options/compression/keep_structure", this->ui->keepStructure_Checkbox->isChecked()); + settings.setValue("compression_options/resize/resize", this->ui->resize_groupBox->isChecked()); + settings.setValue("compression_options/resize/fit_to", this->ui->fitTo_ComboBox->currentIndex()); + settings.setValue("compression_options/resize/width", this->ui->width_SpinBox->value()); + settings.setValue("compression_options/resize/height", this->ui->height_SpinBox->value()); + settings.setValue("compression_options/resize/size", this->ui->edge_SpinBox->value()); + settings.setValue("compression_options/resize/keep_aspect_ratio", this->ui->keepAspectRatio_CheckBox->isChecked()); + settings.setValue("compression_options/resize/do_not_enlarge", this->ui->doNotEnlarge_CheckBox->isChecked()); + settings.setValue("compression_options/output/output_folder", this->ui->outputFolder_LineEdit->text()); settings.setValue("compression_options/output/output_suffix", this->ui->outputSuffix_LineEdit->text()); } @@ -120,6 +133,14 @@ void MainWindow::readSettings() this->ui->keepMetadata_Checkbox->setChecked(settings.value("compression_options/compression/keep_metadata").toBool()); this->ui->keepStructure_Checkbox->setChecked(settings.value("compression_options/compression/keep_structure").toBool()); + this->ui->resize_groupBox->setChecked(settings.value("compression_options/resize/resize", false).toBool()); + this->ui->fitTo_ComboBox->setCurrentIndex(settings.value("compression_options/resize/fit_to", 0).toInt()); + this->ui->width_SpinBox->setValue(settings.value("compression_options/resize/width", 1000).toInt()); + this->ui->height_SpinBox->setValue(settings.value("compression_options/resize/height", 1000).toInt()); + this->ui->edge_SpinBox->setValue(settings.value("compression_options/resize/size", 1000).toInt()); + this->ui->keepAspectRatio_CheckBox->setChecked(settings.value("compression_options/resize/keep_aspect_ratio", false).toBool()); + this->ui->doNotEnlarge_CheckBox->setChecked(settings.value("compression_options/resize/do_not_enlarge", false).toBool()); + this->ui->outputFolder_LineEdit->setText(settings.value("compression_options/output/output_folder").toString()); this->ui->outputSuffix_LineEdit->setText(settings.value("compression_options/output/output_suffix").toString()); } @@ -243,13 +264,19 @@ void MainWindow::on_compress_Button_clicked() progressDialog->show(); CompressionOptions compressionOptions = { - settings.value("compression_options/output/output_folder").toString(), + this->ui->outputFolder_LineEdit->text(), getRootFolder(this->folderMap), - settings.value("compression_options/output/output_suffix").toString(), - settings.value("compression_options/compression/level", 4).toBool(), - settings.value("compression_options/compression/lossless", false).toBool(), - settings.value("compression_options/compression/keep_metadata", false).toBool(), - settings.value("compression_options/compression/keep_structure", false).toBool(), + this->ui->outputSuffix_LineEdit->text(), + this->ui->compression_Slider->value(), + this->ui->lossless_Checkbox->isChecked(), + this->ui->keepMetadata_Checkbox->isChecked(), + this->ui->keepStructure_Checkbox->isChecked(), + this->ui->resize_groupBox->isChecked(), + this->ui->fitTo_ComboBox->currentIndex(), + this->ui->width_SpinBox->value(), + this->ui->height_SpinBox->value(), + this->ui->edge_SpinBox->value(), + this->ui->doNotEnlarge_CheckBox->isChecked(), }; QFuture future = this->cImageModel->getRootItem()->compress(compressionOptions); @@ -269,6 +296,7 @@ void MainWindow::on_removeFiles_Button_clicked() void MainWindow::closeEvent(QCloseEvent* event) { this->writeSettings(); + qInfo() << "---- Closing application ----"; event->accept(); } @@ -345,3 +373,96 @@ void MainWindow::dropFinished(QStringList filePaths) QString baseFolder = QFileInfo(filePaths.at(0)).absolutePath(); MainWindow::importFiles(filePaths, baseFolder); } + +void MainWindow::on_fitTo_ComboBox_currentIndexChanged(int index) +{ + QSettings settings; + switch (index) { + default: + case ResizeMode::DIMENSIONS: + ui->edge_Label->hide(); + ui->edge_SpinBox->hide(); + ui->width_Label->show(); + ui->width_SpinBox->show(); + ui->width_SpinBox->setSuffix(tr("px")); + ui->width_SpinBox->setMaximum(99999); + ui->height_Label->show(); + ui->height_SpinBox->show(); + ui->height_SpinBox->setSuffix(tr("px")); + ui->height_SpinBox->setMaximum(99999); + ui->keepAspectRatio_CheckBox->setDisabled(true); + break; + case ResizeMode::PERCENTAGE: + ui->edge_Label->hide(); + ui->edge_SpinBox->hide(); + ui->width_Label->show(); + ui->width_SpinBox->show(); + ui->width_SpinBox->setSuffix(tr("%")); + ui->width_SpinBox->setMaximum(999); + ui->height_Label->show(); + ui->height_SpinBox->show(); + ui->height_SpinBox->setSuffix(tr("%")); + ui->height_SpinBox->setMaximum(999); + ui->keepAspectRatio_CheckBox->setEnabled(true); + break; + case ResizeMode::SHORT_EDGE: + case ResizeMode::LONG_EDGE: + ui->edge_Label->show(); + ui->edge_SpinBox->show(); + ui->width_Label->hide(); + ui->width_SpinBox->hide(); + ui->height_Label->hide(); + ui->height_SpinBox->hide(); + ui->keepAspectRatio_CheckBox->setDisabled(true); + break; + } + + this->writeSetting("compression_options/resize/fit_to", index); +} + +void MainWindow::on_resize_groupBox_toggled(bool checked) +{ + this->writeSetting("compression_options/resize/resize", checked); +} + +void MainWindow::on_width_SpinBox_valueChanged(int value) +{ + if (this->ui->fitTo_ComboBox->currentIndex() == ResizeMode::PERCENTAGE && this->ui->keepAspectRatio_CheckBox->isChecked()) { + this->ui->height_SpinBox->setValue(value); + } + this->writeSetting("compression_options/resize/width", value); +} + +void MainWindow::on_height_SpinBox_valueChanged(int value) +{ + if (this->ui->fitTo_ComboBox->currentIndex() == ResizeMode::PERCENTAGE && this->ui->keepAspectRatio_CheckBox->isChecked()) { + this->ui->width_SpinBox->setValue(value); + } + this->writeSetting("compression_options/resize/height", value); +} + +void MainWindow::on_edge_SpinBox_valueChanged(int value) +{ + this->writeSetting("compression_options/resize/size", value); +} + +void MainWindow::on_keepAspectRatio_CheckBox_toggled(bool checked) +{ + if (this->ui->fitTo_ComboBox->currentIndex() == ResizeMode::PERCENTAGE && checked) { + this->ui->height_SpinBox->setValue(this->ui->width_SpinBox->value()); + } + this->writeSetting("compression_options/resize/keep_aspect_ratio", checked); +} + +void MainWindow::on_doNotEnlarge_CheckBox_toggled(bool checked) +{ + if (this->ui->fitTo_ComboBox->currentIndex() == ResizeMode::PERCENTAGE && checked) { + this->ui->width_SpinBox->setMaximum(100); + this->ui->height_SpinBox->setMaximum(100); + } else { + int maximum = this->ui->fitTo_ComboBox->currentIndex() == ResizeMode::PERCENTAGE ? 999 : 99999; + this->ui->width_SpinBox->setMaximum(maximum); + this->ui->height_SpinBox->setMaximum(maximum); + } + this->writeSetting("compression_options/resize/do_not_enlarge", checked); +} diff --git a/src/MainWindow.h b/src/MainWindow.h index c818928d..14694bc5 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -48,6 +48,20 @@ private slots: void imageList_selectionChanged(const QModelIndex& current, const QModelIndex& previous); void compressionFinished(); void dropFinished(QStringList filePaths); + void on_fitTo_ComboBox_currentIndexChanged(int index); + + void on_resize_groupBox_toggled(bool arg1); + + void on_width_SpinBox_valueChanged(int arg1); + + void on_height_SpinBox_valueChanged(int arg1); + + void on_edge_SpinBox_valueChanged(int arg1); + + void on_keepAspectRatio_CheckBox_toggled(bool checked); + + void on_doNotEnlarge_CheckBox_toggled(bool checked); + private: Ui::MainWindow* ui; diff --git a/src/main.cpp b/src/main.cpp index 854c3ba8..822e333d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,14 +1,42 @@ #include "MainWindow.h" #include +#include +#include + +void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg) +{ + QDateTime currentTime = QDateTime::currentDateTime(); + QString formattedTime = currentTime.toString("yyyy-MM-dd hh:mm:ss.zzz"); + QByteArray localMsg = msg.toLocal8Bit(); + switch (type) { + case QtDebugMsg: + fprintf(stderr, "[%s][D] %s (%s:%u, %s)\n", formattedTime.toLocal8Bit().constData(), localMsg.constData(), context.file, context.line, context.function); + break; + case QtInfoMsg: + fprintf(stderr, "[%s][I] %s\n", formattedTime.toLocal8Bit().constData(), localMsg.constData()); + break; + case QtWarningMsg: + fprintf(stderr, "[%s][W] %s\n", formattedTime.toLocal8Bit().constData(), localMsg.constData()); + break; + case QtCriticalMsg: + fprintf(stderr, "[%s][C] %s (%s:%u, %s)\n", formattedTime.toLocal8Bit().constData(), localMsg.constData(), context.file, context.line, context.function); + break; + case QtFatalMsg: + fprintf(stderr, "[%s][F] %s (%s:%u, %s)\n", formattedTime.toLocal8Bit().constData(), localMsg.constData(), context.file, context.line, context.function); + abort(); + } +} int main(int argc, char* argv[]) { QCoreApplication::setOrganizationName("SaeraSoft"); QCoreApplication::setOrganizationDomain("com.saerasoft.caesium"); QCoreApplication::setApplicationName("Caesium Image Compressor"); + qInstallMessageHandler(messageHandler); QApplication a(argc, argv); + qInfo() << "---- Starting application ----"; QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); MainWindow w; w.show(); diff --git a/src/models/CImage.cpp b/src/models/CImage.cpp index d83874e6..eeabf443 100644 --- a/src/models/CImage.cpp +++ b/src/models/CImage.cpp @@ -4,14 +4,14 @@ #include #include +#include #include #include - CImage::CImage(const QString& path) { QFileInfo fileInfo = QFileInfo(path); - auto *imageReader = new QImageReader(path); + auto* imageReader = new QImageReader(path); QSize imageSize = imageReader->size(); this->fullPath = fileInfo.absoluteFilePath(); @@ -29,12 +29,12 @@ CImage::CImage(const QString& path) delete imageReader; } -bool operator== (const CImage &c1, const CImage &c2) +bool operator==(const CImage& c1, const CImage& c2) { return (c1.fullPath == c2.fullPath); } -bool operator!= (const CImage &c1, const CImage &c2) +bool operator!=(const CImage& c1, const CImage& c2) { return !(c1 == c2); } @@ -64,7 +64,6 @@ QString CImage::getFullPath() const return this->fullPath; } - bool CImage::compress(CompressionOptions compressionOptions) { QSettings settings; @@ -81,7 +80,7 @@ bool CImage::compress(CompressionOptions compressionOptions) QDir outputDir(outputPath); if (!outputDir.exists()) { - if(!outputDir.mkpath(outputPath)) { + if (!outputDir.mkpath(outputPath)) { return false; } } @@ -91,8 +90,8 @@ bool CImage::compress(CompressionOptions compressionOptions) QString tempFileFullPath = ""; bool outputAlreadyExists = QFile(outputFullPath).exists(); - if (outputAlreadyExists) { - QTemporaryFile tempFile; + QTemporaryFile tempFile; + if (outputAlreadyExists || compressionOptions.resize) { if (tempFile.open()) { tempFileFullPath = tempFile.fileName(); } @@ -100,6 +99,7 @@ bool CImage::compress(CompressionOptions compressionOptions) if (tempFileFullPath.isEmpty()) { return false; } + tempFile.close(); } @@ -113,7 +113,26 @@ bool CImage::compress(CompressionOptions compressionOptions) int res = 0; cs_image_pars compress_pars = getCompressionParametersFromLevel(compressionLevel, lossless, keepMetadata); - bool result = cs_compress(this->getFullPath().toUtf8().constData(), tempFileFullPath.toUtf8().constData(), &compress_pars, &res); + //Resize + if (compressionOptions.resize) { + QImage image(this->getFullPath()); + + image = cResize(image, + compressionOptions.fitTo, + compressionOptions.width, + compressionOptions.height, + compressionOptions.size, + compressionOptions.doNotEnlarge); + + bool saveResult = image.save(tempFileFullPath, inputFileInfo.completeSuffix().toLocal8Bit(), 100); + if (!saveResult) { + return false; + } + inputFullPath = tempFileFullPath; + } + + + bool result = cs_compress(inputFullPath.toUtf8().constData(), tempFileFullPath.toUtf8().constData(), &compress_pars, &res); if (result) { QFileInfo outputInfo(tempFileFullPath); if (outputAlreadyExists && outputInfo.size() < inputFileInfo.size()) { @@ -130,8 +149,12 @@ bool CImage::compress(CompressionOptions compressionOptions) void CImage::setCompressedInfo(QFileInfo fileInfo) { + QImage compressedImage(fileInfo.absoluteFilePath()); this->compressedSize = fileInfo.size(); this->compressedFullPath = fileInfo.absoluteFilePath(); + this->compressedWidth = compressedImage.width(); + this->compressedHeight = compressedImage.height(); + } QString CImage::getCompressedFullPath() const @@ -154,7 +177,7 @@ CImageStatus CImage::getStatus() const return status; } -void CImage::setStatus(const CImageStatus &value) +void CImage::setStatus(const CImageStatus& value) { status = value; } diff --git a/src/utils/Utils.cpp b/src/utils/Utils.cpp index 3f4a7e79..f027f631 100644 --- a/src/utils/Utils.cpp +++ b/src/utils/Utils.cpp @@ -36,7 +36,6 @@ QStringList scanDirectory(QString directory) QStringList fileList = {}; //Collecting all files in folder if (QDir(directory).exists()) { - qInfo() << "Collecting files in" << directory; QDirIterator it(directory, inputFilterList, QDir::AllEntries, @@ -92,7 +91,6 @@ cs_image_pars getCompressionParametersFromLevel(int level, bool lossless, bool k pars.png.lossy_8 = false; pars.png.transparent = false; break; - } if (lossless) { @@ -126,5 +124,38 @@ QString getRootFolder(QMap folderMap) } return rootFolderPath; +} + +QImage cResize(QImage image, int fitTo, int width, int height, int size, bool doNotEnlarge) +{ + int originalWidth = image.width(); + int originalHeight = image.height(); + + if (fitTo == ResizeMode::DIMENSIONS) { + int outputWidth = width; + int outputHeight = height; + if (doNotEnlarge && (outputWidth >= originalWidth || outputHeight >= originalHeight)) { + return image; + } + image = image.scaled(outputWidth, outputHeight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + } else if (fitTo == ResizeMode::PERCENTAGE) { + int outputWidthPerc = width; + int outputHeightPerc = height; + + if (doNotEnlarge && (outputWidthPerc >= 100 || outputHeightPerc >= 100)) { + return image; + } + + int outputWidth = (int)round((float)originalWidth * (float)outputWidthPerc / 100); + int outputHeight = (int)round((float)originalHeight * (float)outputHeightPerc / 100); + image = image.scaled(outputWidth, outputHeight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + } else if (fitTo == ResizeMode::LONG_EDGE || fitTo == ResizeMode::SHORT_EDGE) { + if ((fitTo == ResizeMode::LONG_EDGE && originalWidth >= originalHeight) || (fitTo == ResizeMode::SHORT_EDGE && originalWidth <= originalHeight)) { + image = image.scaledToWidth(size, Qt::SmoothTransformation); + } else if ((fitTo == ResizeMode::LONG_EDGE && originalHeight >= originalWidth) || (fitTo == ResizeMode::SHORT_EDGE && originalHeight <= originalWidth)) { + image = image.scaledToHeight(size, Qt::SmoothTransformation); + } + } + return image; } diff --git a/src/utils/Utils.h b/src/utils/Utils.h index 3c4ed0ec..48518c8e 100644 --- a/src/utils/Utils.h +++ b/src/utils/Utils.h @@ -1,10 +1,11 @@ #ifndef UTILS_H #define UTILS_H -#include +#include +#include #include +#include #include -#include #include "../vendor/caesium.h" @@ -23,6 +24,14 @@ enum CImageColumns RATIO = 3 }; +enum ResizeMode +{ + DIMENSIONS = 0, + PERCENTAGE = 1, + SHORT_EDGE = 2, + LONG_EDGE = 3 +}; + typedef struct CompressionOptions { QString outputPath; @@ -32,6 +41,12 @@ typedef struct CompressionOptions bool lossless; bool keepMetadata; bool keepStructure; + bool resize; + int fitTo; + int width; + int height; + int size; + bool doNotEnlarge; } CompressionOptions; @@ -40,5 +55,5 @@ QString toHumanSize(size_t size); QStringList scanDirectory(QString directory); cs_image_pars getCompressionParametersFromLevel(int level, bool lossless, bool keepMetadata); QString getRootFolder(QMap folderMap); - +QImage cResize(QImage image, int fitTo, int width, int height, int size, bool doNotEnlarge); #endif // UTILS_H diff --git a/src/widgets/QZoomGraphicsView.cpp b/src/widgets/QZoomGraphicsView.cpp index 18c38d61..056dd804 100644 --- a/src/widgets/QZoomGraphicsView.cpp +++ b/src/widgets/QZoomGraphicsView.cpp @@ -24,3 +24,8 @@ void QZoomGraphicsView::wheelEvent(QWheelEvent* event) QGraphicsView::wheelEvent(event); } } + +void QZoomGraphicsView::resizeEvent(QResizeEvent *event) +{ + this->fitInView(this->scene()->itemsBoundingRect(), Qt::KeepAspectRatio); +} diff --git a/src/widgets/QZoomGraphicsView.h b/src/widgets/QZoomGraphicsView.h index 64c1eb85..b7d2dd21 100644 --- a/src/widgets/QZoomGraphicsView.h +++ b/src/widgets/QZoomGraphicsView.h @@ -12,6 +12,7 @@ class QZoomGraphicsView : public QGraphicsView public: explicit QZoomGraphicsView(QWidget *parent = 0); void wheelEvent(QWheelEvent* event); + void resizeEvent(QResizeEvent* event); } __unused; #endif // QZOOMGRAPHICSVIEW_H diff --git a/views/MainWindow.ui b/views/MainWindow.ui index f7116718..0d40de06 100644 --- a/views/MainWindow.ui +++ b/views/MainWindow.ui @@ -278,6 +278,19 @@
+ + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -315,6 +328,12 @@ + + + 0 + 0 + + px @@ -330,7 +349,49 @@ - + + + Size + + + + + + + + 0 + 0 + + + + px + + + 1 + + + 99999 + + + 1000 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + Height @@ -338,6 +399,12 @@ + + + 0 + 0 + + px From 1c96fadf02a4dd42d1c0ee4fb1f97b409d30dee8 Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Mon, 11 May 2020 09:23:06 +0200 Subject: [PATCH 05/12] Windows cleanup --- src/MainWindow.cpp | 2 +- src/MainWindow.h | 2 +- src/models/CImage.cpp | 1 + src/utils/Utils.cpp | 1 + src/widgets/QDropTreeView.h | 2 +- src/widgets/QZoomGraphicsView.h | 2 +- 6 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index c2152a2e..2abaf905 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -300,7 +300,7 @@ void MainWindow::closeEvent(QCloseEvent* event) event->accept(); } -void MainWindow::resizeEvent(__unused QResizeEvent* event) +void MainWindow::resizeEvent(QResizeEvent* event) { ui->preview_graphicsView->fitInView(this->previewScene->itemsBoundingRect(), Qt::KeepAspectRatio); } diff --git a/src/MainWindow.h b/src/MainWindow.h index 14694bc5..dd9f8671 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -26,7 +26,7 @@ class MainWindow : public QMainWindow { protected: void closeEvent(QCloseEvent* event) override; - void resizeEvent(__unused QResizeEvent* event) override; + void resizeEvent(QResizeEvent* event) override; private slots: diff --git a/src/models/CImage.cpp b/src/models/CImage.cpp index eeabf443..94b764d9 100644 --- a/src/models/CImage.cpp +++ b/src/models/CImage.cpp @@ -7,6 +7,7 @@ #include #include #include +#include CImage::CImage(const QString& path) { diff --git a/src/utils/Utils.cpp b/src/utils/Utils.cpp index f027f631..fbae3d6f 100644 --- a/src/utils/Utils.cpp +++ b/src/utils/Utils.cpp @@ -3,6 +3,7 @@ #include #include #include +#include QString toHumanSize(size_t size) { diff --git a/src/widgets/QDropTreeView.h b/src/widgets/QDropTreeView.h index 6e06e68c..101096ef 100755 --- a/src/widgets/QDropTreeView.h +++ b/src/widgets/QDropTreeView.h @@ -21,6 +21,6 @@ class QDropTreeView : public QTreeView void dragMoveEvent(QDragMoveEvent *event) override; void dropEvent(QDropEvent *event) override; -} __unused; +}; #endif // QDROPTREEWIDGET_H diff --git a/src/widgets/QZoomGraphicsView.h b/src/widgets/QZoomGraphicsView.h index b7d2dd21..fd71395d 100644 --- a/src/widgets/QZoomGraphicsView.h +++ b/src/widgets/QZoomGraphicsView.h @@ -13,6 +13,6 @@ class QZoomGraphicsView : public QGraphicsView explicit QZoomGraphicsView(QWidget *parent = 0); void wheelEvent(QWheelEvent* event); void resizeEvent(QResizeEvent* event); -} __unused; +}; #endif // QZOOMGRAPHICSVIEW_H From 9052bf4d07194a676e4fa4e01f5cebb151b7cbba Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Mon, 11 May 2020 12:22:48 +0200 Subject: [PATCH 06/12] Restored .pro file --- caesium-image-compressor.pro | 85 ++++++++++++++++++++++++++++++++++++ views/MainWindow.ui | 6 +-- 2 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 caesium-image-compressor.pro diff --git a/caesium-image-compressor.pro b/caesium-image-compressor.pro new file mode 100644 index 00000000..a2f2f43c --- /dev/null +++ b/caesium-image-compressor.pro @@ -0,0 +1,85 @@ +QT += core gui concurrent svg + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 +unix: { + QMAKE_CFLAGS += -Wno-nullability-completeness + QMAKE_CXXFLAGS += -Wno-nullability-completeness +} + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +TARGET = "Caesium Image Compressor" +macx: { + ICON = resources/icons/icon.icns + QMAKE_INFO_PLIST = Info.plist + QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.14 + QMAKE_RPATHDIR += @executable_path/../Frameworks + +} +win32: { + RC_ICONS = resources/icons/icon.ico +} + +SOURCES += \ + src/main.cpp \ + src/MainWindow.cpp \ + src/models/CImage.cpp \ + src/models/CImageTreeItem.cpp \ + src/models/CImageTreeModel.cpp \ + src/utils/Utils.cpp \ + src/dialogs/AboutDialog.cpp \ + src/widgets/QDropTreeView.cpp \ + src/widgets/QZoomGraphicsView.cpp + +HEADERS += \ + src/vendor/caesium.h \ + src/MainWindow.h \ + src/models/CImage.h \ + src/models/CImageTreeItem.h \ + src/models/CImageTreeModel.h \ + src/utils/Utils.h \ + src/dialogs/AboutDialog.h \ + src/widgets/QDropTreeView.h \ + src/widgets/QZoomGraphicsView.h + +FORMS += \ + views/MainWindow.ui \ + views/AboutDialog.ui + +TRANSLATIONS += \ + locale/en_US.ts + +RESOURCES += \ + resources/resources.qrc + +unix: { + LIBS += -L"/usr/local/lib/caesium" -lcaesium +} + +win32: { + LIBS += -L"C:\\libcaesium\\lib" -lcaesium \ + -L"C:\\zopfli\\lib" -lzopflipng \ + -L"C:\\mozjpeg\\lib" -ljpeg \ + -L"C:\\mozjpeg\\lib" -lturbojpeg \ +} + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +DISTFILES += \ + Info.plist \ + README.md \ + CHANGELOG.md diff --git a/views/MainWindow.ui b/views/MainWindow.ui index 0d40de06..3783d0f9 100644 --- a/views/MainWindow.ui +++ b/views/MainWindow.ui @@ -187,7 +187,7 @@ - 11 + 8 @@ -212,7 +212,7 @@ - 11 + 8 @@ -557,7 +557,7 @@ 0 0 943 - 22 + 21 From 96907d3a6af2e0e8580da675a87c0aa4b4de49b2 Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Wed, 13 May 2020 09:45:37 +0200 Subject: [PATCH 07/12] Fix to resize copy --- src/models/CImage.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/models/CImage.cpp b/src/models/CImage.cpp index 94b764d9..8844e21d 100644 --- a/src/models/CImage.cpp +++ b/src/models/CImage.cpp @@ -117,6 +117,7 @@ bool CImage::compress(CompressionOptions compressionOptions) //Resize if (compressionOptions.resize) { QImage image(this->getFullPath()); + QSize originalSize = image.size(); image = cResize(image, compressionOptions.fitTo, @@ -125,18 +126,21 @@ bool CImage::compress(CompressionOptions compressionOptions) compressionOptions.size, compressionOptions.doNotEnlarge); - bool saveResult = image.save(tempFileFullPath, inputFileInfo.completeSuffix().toLocal8Bit(), 100); - if (!saveResult) { - return false; + if (image.size() != originalSize) { + bool saveResult = image.save(tempFileFullPath, inputFileInfo.completeSuffix().toLocal8Bit(), 100); + if (!saveResult) { + return false; + } + inputFullPath = tempFileFullPath; } - inputFullPath = tempFileFullPath; + } bool result = cs_compress(inputFullPath.toUtf8().constData(), tempFileFullPath.toUtf8().constData(), &compress_pars, &res); if (result) { QFileInfo outputInfo(tempFileFullPath); - if (outputAlreadyExists && outputInfo.size() < inputFileInfo.size()) { + if ((outputAlreadyExists || compressionOptions.resize) && outputInfo.size() < inputFileInfo.size()) { QFile::remove(outputFullPath); bool copyResult = QFile::copy(tempFileFullPath, outputFullPath); if (!copyResult) { From bb5a8a1d98f1384fbf63655c2068eae103d49f55 Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Wed, 13 May 2020 13:52:16 +0200 Subject: [PATCH 08/12] Win fix for #19 --- src/MainWindow.cpp | 5 ++++- src/models/CImage.cpp | 1 - src/utils/Utils.cpp | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 2abaf905..e9c0ce0f 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -32,12 +32,15 @@ MainWindow::MainWindow(QWidget* parent) this->on_doNotEnlarge_CheckBox_toggled(ui->doNotEnlarge_CheckBox->isChecked()); ui->main_Splitter->setSizes(QList({ 700, 1 })); ui->left_Splitter->setSizes(QList({ 100, 1 })); + +#ifdef Q_OS_WIN + QThreadPool::globalInstance()->setMaxThreadCount(QThread::idealThreadCount() / 2); +#endif } MainWindow::~MainWindow() { delete cImageModel; - // delete listViewDelegate; delete previewScene; delete ui; } diff --git a/src/models/CImage.cpp b/src/models/CImage.cpp index 8844e21d..ea545d3d 100644 --- a/src/models/CImage.cpp +++ b/src/models/CImage.cpp @@ -136,7 +136,6 @@ bool CImage::compress(CompressionOptions compressionOptions) } - bool result = cs_compress(inputFullPath.toUtf8().constData(), tempFileFullPath.toUtf8().constData(), &compress_pars, &res); if (result) { QFileInfo outputInfo(tempFileFullPath); diff --git a/src/utils/Utils.cpp b/src/utils/Utils.cpp index fbae3d6f..c4ca1b5f 100644 --- a/src/utils/Utils.cpp +++ b/src/utils/Utils.cpp @@ -115,13 +115,13 @@ QString getRootFolder(QMap folderMap) if (i == 0) { rootFolderPath = QDir::rootPath(); } else { - rootFolderPath = QDir(QDir::rootPath() + splittedCommonPath.join(QDir::separator())).absolutePath(); + rootFolderPath = QDir(splittedCommonPath.join(QDir::separator())).absolutePath(); } break; } splittedCommonPath.append(splittedNewFolder.at(i)); } - rootFolderPath = QDir(QDir::rootPath() + splittedCommonPath.join(QDir::separator())).absolutePath(); + rootFolderPath = QDir(splittedCommonPath.join(QDir::separator())).absolutePath(); } return rootFolderPath; From 20aebac747f424fc1453ef49e39a79b24a0ec9b9 Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Wed, 13 May 2020 15:34:21 +0200 Subject: [PATCH 09/12] Update README.md --- README.md | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index ac19d05e..8e4d515b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ -## Caesium Image Compressor (Cs-133) -##### v2.0.0-alpha1 (build 20200318) - Copyright © Matteo Paonessa, 2020. All Rights Reserved. -##### WARNING This version is a very early stage version! Don't use on important files without a backup and expect some major changes. +## Caesium - Image Compressor (Cs-133) +##### v2.0.0-alpha2 (build 20200513) - Copyright © Matteo Paonessa, 2020. All Rights Reserved. +##### ⚠️ WARNING This version is a very early stage version! Don't use on important files without a backup and expect some major changes. ⚠️ + +![caesium_screenshot](https://user-images.githubusercontent.com/12133996/81818327-2e893680-952e-11ea-927f-8d11b285e72e.png) ---------- @@ -14,14 +16,14 @@ ##### TESTED PLATFORMS * Windows 10 64bit -* MacOS X Catalina (v. 10.15) +* MacOS X Catalina (v10.15) ---------- ##### INSTALLATION -Binaries for Windows and OS X will be available soon. +You can find binaries for Windows and OS X in the [releases page](https://github.com/Lymphatus/caesium-image-compressor/releases) -Linux source code must be compiled using Qt5. +For linux you must compile the source by yourself. ---------- @@ -29,13 +31,7 @@ Linux source code must be compiled using Qt5. 1. You need the [Qt5 SDK](https://www.qt.io/download/) installed on your platform. 2. Compile [libcaesium](https://github.com/Lymphatus/libcaesium). Please refer to its own documentation for detailed instructions for your platform. 3. Clone the repository using ``` git clone https://github.com/Lymphatus/caesium-image-compressor.git ```. If it doesn't work somehow, you can download the latest snapshot [here](https://github.com/Lymphatus/caesium-image-compressor/archive/master.zip). -4. Open *caesium-image-compressor.pro* on Qt Creator and compile it. It should compile both Caesium and its Updater. -5. Should be done! - ----------- - -##### KNOWN ISSUES -* A lot right now +4. Open *caesium-image-compressor.pro* on Qt Creator and compile it. ---------- From 2e517364e0c94fbdbe2cb35186092ff3eaa0e419 Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Wed, 13 May 2020 16:47:10 +0200 Subject: [PATCH 10/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e4d515b..acad38d4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## Caesium - Image Compressor (Cs-133) ##### v2.0.0-alpha2 (build 20200513) - Copyright © Matteo Paonessa, 2020. All Rights Reserved. -##### ⚠️ WARNING This version is a very early stage version! Don't use on important files without a backup and expect some major changes. ⚠️ +##### ⚠️ WARNING This is a very early stage version! Don't use on important files without a backup and expect some major changes. ⚠️ ![caesium_screenshot](https://user-images.githubusercontent.com/12133996/81818327-2e893680-952e-11ea-927f-8d11b285e72e.png) From 5260b757959aa33b3dbd4ed354e22798dff5278a Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Sun, 17 May 2020 13:22:56 +0200 Subject: [PATCH 11/12] Select all --- CHANGELOG.md | 16 +++++++++++++++- README.md | 2 +- src/MainWindow.cpp | 23 +++++++++++++++++------ src/MainWindow.h | 2 ++ views/AboutDialog.ui | 2 +- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 231c3f2d..a96fa298 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,20 @@ ### CHANGELOG -###### 2.0.0-alpha1 (18/03/2020) +#### 2.0.0-alpha2 (17/05/2020) +###### ADDED + +- Resize +- New layout +- Select all + +###### FIXED + +- "Keep folder structure" directory names +- Tentative fix for random crash while compressing large number of files (~5k) +- Minor fixes from previous release + +---------- +#### 2.0.0-alpha1 (18/03/2020) Initial release ---------- diff --git a/README.md b/README.md index acad38d4..4df24414 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ## Caesium - Image Compressor (Cs-133) -##### v2.0.0-alpha2 (build 20200513) - Copyright © Matteo Paonessa, 2020. All Rights Reserved. +##### v2.0.0-alpha2 - Copyright © Matteo Paonessa, 2020. All Rights Reserved. ##### ⚠️ WARNING This is a very early stage version! Don't use on important files without a backup and expect some major changes. ⚠️ ![caesium_screenshot](https://user-images.githubusercontent.com/12133996/81818327-2e893680-952e-11ea-927f-8d11b285e72e.png) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index e9c0ce0f..7c69651d 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -16,6 +16,8 @@ MainWindow::MainWindow(QWidget* parent) ui->setupUi(this); qDebug() << "Starting application"; + qRegisterMetaTypeStreamOperators>(); + this->cImageModel = new CImageTreeModel(); this->previewScene = new QGraphicsScene(); ui->preview_graphicsView->setScene(this->previewScene); @@ -30,9 +32,6 @@ MainWindow::MainWindow(QWidget* parent) this->on_fitTo_ComboBox_currentIndexChanged(ui->fitTo_ComboBox->currentIndex()); this->on_keepAspectRatio_CheckBox_toggled(ui->keepAspectRatio_CheckBox->isChecked()); this->on_doNotEnlarge_CheckBox_toggled(ui->doNotEnlarge_CheckBox->isChecked()); - ui->main_Splitter->setSizes(QList({ 700, 1 })); - ui->left_Splitter->setSizes(QList({ 100, 1 })); - #ifdef Q_OS_WIN QThreadPool::globalInstance()->setMaxThreadCount(QThread::idealThreadCount() / 2); #endif @@ -101,6 +100,8 @@ void MainWindow::writeSettings() QSettings settings; settings.setValue("mainwindow/size", this->size()); settings.setValue("mainwindow/pos", this->pos()); + settings.setValue("mainwindow/left_splitter_sizes", QVariant::fromValue>(this->ui->left_Splitter->sizes())); + settings.setValue("mainwindow/main_splitter_sizes", QVariant::fromValue>(this->ui->main_Splitter->sizes())); settings.setValue("compression_options/compression/level", this->ui->compression_Slider->value()); settings.setValue("compression_options/compression/lossless", this->ui->lossless_Checkbox->isChecked()); @@ -131,6 +132,9 @@ void MainWindow::readSettings() this->resize(settings.value("mainwindow/size").toSize()); this->move(settings.value("mainwindow/pos").toPoint()); + this->ui->left_Splitter->setSizes(settings.value("mainwindow/left_splitter_sizes", QVariant::fromValue>({ 100, 1 })).value>()); + this->ui->main_Splitter->setSizes(settings.value("mainwindow/main_splitter_sizes", QVariant::fromValue>({ 700, 1 })).value>()); + this->ui->compression_Slider->setValue(settings.value("compression_options/compression/level", 4).toInt()); this->ui->lossless_Checkbox->setChecked(settings.value("compression_options/compression/lossless").toBool()); this->ui->keepMetadata_Checkbox->setChecked(settings.value("compression_options/compression/keep_metadata").toBool()); @@ -196,7 +200,7 @@ void MainWindow::importFiles(const QStringList& fileList, QString baseFolder) progressDialog.setWindowModality(Qt::WindowModal); QList list; - //TODO use an interator + //TODO use an iterator for (int i = 0; i < listLength; i++) { if (progressDialog.wasCanceled()) { break; @@ -401,11 +405,11 @@ void MainWindow::on_fitTo_ComboBox_currentIndexChanged(int index) ui->width_Label->show(); ui->width_SpinBox->show(); ui->width_SpinBox->setSuffix(tr("%")); - ui->width_SpinBox->setMaximum(999); + ui->width_SpinBox->setMaximum(ui->keepAspectRatio_CheckBox->isChecked() ? 100 : 999); ui->height_Label->show(); ui->height_SpinBox->show(); ui->height_SpinBox->setSuffix(tr("%")); - ui->height_SpinBox->setMaximum(999); + ui->height_SpinBox->setMaximum(ui->keepAspectRatio_CheckBox->isChecked() ? 100 : 999); ui->keepAspectRatio_CheckBox->setEnabled(true); break; case ResizeMode::SHORT_EDGE: @@ -434,6 +438,7 @@ void MainWindow::on_width_SpinBox_valueChanged(int value) this->ui->height_SpinBox->setValue(value); } this->writeSetting("compression_options/resize/width", value); + this->writeSetting("compression_options/resize/height", this->ui->height_SpinBox->value()); } void MainWindow::on_height_SpinBox_valueChanged(int value) @@ -442,6 +447,7 @@ void MainWindow::on_height_SpinBox_valueChanged(int value) this->ui->width_SpinBox->setValue(value); } this->writeSetting("compression_options/resize/height", value); + this->writeSetting("compression_options/resize/width", this->ui->width_SpinBox->value()); } void MainWindow::on_edge_SpinBox_valueChanged(int value) @@ -469,3 +475,8 @@ void MainWindow::on_doNotEnlarge_CheckBox_toggled(bool checked) } this->writeSetting("compression_options/resize/do_not_enlarge", checked); } + +void MainWindow::on_actionSelect_All_triggered() +{ + this->ui->imageList_TreeView->selectAll(); +} diff --git a/src/MainWindow.h b/src/MainWindow.h index dd9f8671..19f4be83 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -62,6 +62,8 @@ private slots: void on_doNotEnlarge_CheckBox_toggled(bool checked); + void on_actionSelect_All_triggered(); + private: Ui::MainWindow* ui; diff --git a/views/AboutDialog.ui b/views/AboutDialog.ui index 938802e6..173821e2 100644 --- a/views/AboutDialog.ui +++ b/views/AboutDialog.ui @@ -131,7 +131,7 @@ - v2.0.0-beta3 + v2.0.0-alpha.2 Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter From cca844bddc0b5ba6ba381f7c66c79b3b0ac740bc Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Sun, 17 May 2020 13:35:43 +0200 Subject: [PATCH 12/12] Fix to promoted import paths --- views/MainWindow.ui | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/views/MainWindow.ui b/views/MainWindow.ui index 3783d0f9..b3da0c08 100644 --- a/views/MainWindow.ui +++ b/views/MainWindow.ui @@ -557,7 +557,7 @@ 0 0 943 - 21 + 22 @@ -637,12 +637,12 @@ QZoomGraphicsView QGraphicsView -
./widgets/QZoomGraphicsView.h
+
src/widgets/QZoomGraphicsView.h
QDropTreeView QTreeView -
widgets/QDropTreeView.h
+
src/widgets/QDropTreeView.h