From 7fe2a1f4be6edfccc22a4dc2ddd23da954d6dd1f Mon Sep 17 00:00:00 2001 From: frakod Date: Wed, 27 Mar 2024 17:36:43 +0530 Subject: [PATCH] v1.2 - Added Percentage based Cropping --- CMakeLists.txt | 5 +-- main.cpp | 37 ++++++++++++++-- main.ui | 112 +++++++++++++++++++++++++++---------------------- 3 files changed, 97 insertions(+), 57 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b9f742..40035bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,8 @@ cmake_minimum_required(VERSION 3.5) -project(smol_img VERSION 1.1 LANGUAGES CXX) +project(smol_img VERSION 1.2 LANGUAGES CXX) set(CMAKE_AUTOUIC ON) -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) - set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/main.cpp b/main.cpp index 344a488..ea32027 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,3 @@ -#include #include using namespace std::literals; @@ -50,15 +49,45 @@ int main(int argc, char* argv[]) img_view.scale2fit(state == Qt::Unchecked); }); + QObject::connect(ui.crop_in_percent, &QCheckBox::stateChanged, [&](int state) + { + if (input_img.isNull()) return; + + if (state == Qt::Checked) + { + // absolute to percentage + ui.crop_top->setValue(ui.crop_top->value()*100.f / input_img.height()); + ui.crop_left->setValue(ui.crop_left->value()*100.f / input_img.width()); + ui.crop_right->setValue(ui.crop_right->value()*100.f / input_img.width()); + ui.crop_bottom->setValue(ui.crop_bottom->value()*100.f / input_img.height()); + } + else + { + // percentage to absolute + ui.crop_top->setValue(ui.crop_top->value()/100.f * input_img.height()); + ui.crop_left->setValue(ui.crop_left->value()/100.f * input_img.width()); + ui.crop_right->setValue(ui.crop_right->value()/100.f * input_img.width()); + ui.crop_bottom->setValue(ui.crop_bottom->value()/100.f * input_img.height()); + } + }); + bool png_mode = false; auto compute_output = [&] { + QImage img = input_img; int quality = png_mode ? 0 : ui.img_quality->sliderPosition(); // max compression for png - // crop - auto img = input_img.copy(QRect{QPoint{ui.crop_left->value(), ui.crop_top->value()}, - QPoint{input_img.width() - ui.crop_right->value(), input_img.height() - ui.crop_bottom->value()}}); + if (ui.crop_in_percent->isChecked()) + { + img = img.copy(QRect{QPoint( ui.crop_left->value()/100.f * img.width(), ui.crop_top->value() /100.f * img.height()), + QPoint((1-ui.crop_right->value()/100.f) * img.width(), (1-ui.crop_bottom->value()/100.f) * img.height())}); + } + else // crop values in pixels + { + img = img.copy(QRect{QPoint{ui.crop_left->value(), ui.crop_top->value()}, + QPoint{img.width() - ui.crop_right->value(), img.height() - ui.crop_bottom->value()}}); + } // rotate img = img.transformed(QTransform{}.rotate(rotation)); diff --git a/main.ui b/main.ui index 246062b..6a39144 100644 --- a/main.ui +++ b/main.ui @@ -7,11 +7,11 @@ 0 0 1000 - 650 + 685 - smol_img tool v1.1 by frakod + smol_img tool v1.2 by frakod @@ -28,8 +28,8 @@ 0 0 - 666 - 630 + 648 + 661 @@ -133,27 +133,8 @@ - - - - - 0 - 0 - - - - Rotate Clockwise - - - - - - - - - - - + + 0 @@ -161,7 +142,7 @@ - Crop Left + Crop Bottom true @@ -190,8 +171,8 @@ - - + + 0 @@ -199,7 +180,7 @@ - Crop Bottom + Crop Top true @@ -209,8 +190,37 @@ - - + + + + + 0 + 0 + + + + Rotate Clockwise + + + + + + + + + + + + + Crop Values in Percentage + + + true + + + + + 0 @@ -218,7 +228,7 @@ - Crop Top + Crop Left true @@ -548,7 +558,7 @@ - Preview in Original Size + Preview in Actual Size false @@ -581,6 +591,9 @@ + rotl_btn + rotr_btn + crop_in_percent crop_top crop_left crop_right @@ -596,25 +609,10 @@ copy_btn save_btn image_frame + phony_btn - - crop_left - valueChanged(int) - phony_btn - click() - - - 779 - 113 - - - 834 - 123 - - - crop_top valueChanged(int) @@ -759,5 +757,21 @@ + + crop_left + valueChanged(int) + phony_btn + click() + + + 779 + 113 + + + 834 + 123 + + +