From 81a4432a108bf2166db108a3de63ce936ff797d0 Mon Sep 17 00:00:00 2001 From: Amirreza Baghbanpourasl Date: Fri, 18 Nov 2022 17:02:28 +0100 Subject: [PATCH 1/3] script to build for vc17 --- scripts_to_build/win_make_vc17_x64.bat | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 scripts_to_build/win_make_vc17_x64.bat diff --git a/scripts_to_build/win_make_vc17_x64.bat b/scripts_to_build/win_make_vc17_x64.bat new file mode 100644 index 0000000..527f663 --- /dev/null +++ b/scripts_to_build/win_make_vc17_x64.bat @@ -0,0 +1,10 @@ +mkdir build +cd build +mkdir x64 +cd x64 + +cmake -DQT5_DIR=C:/Qt/5.15.2/msvc2019_64/lib/cmake -DCMAKE_PREFIX_PATH=../opencv/build/install -G "Visual Studio 17 2022" ../../.. + +cmake --build . --config Release + +PAUSE \ No newline at end of file From 501ac7f5435d878a5e75fba2af5693a38cbe503c Mon Sep 17 00:00:00 2001 From: Amirreza Baghbanpourasl Date: Fri, 18 Nov 2022 17:08:23 +0100 Subject: [PATCH 2/3] values for spin bars adjusted: scale and pen size --- src/main_window.ui | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main_window.ui b/src/main_window.ui index 662e7f0..bb38089 100644 --- a/src/main_window.ui +++ b/src/main_window.ui @@ -186,13 +186,13 @@ - 0.050000000000000 + 0.500000000000000 8.000000000000000 - 0.050000000000000 + 0.500000000000000 1.000000000000000 @@ -216,7 +216,7 @@ 0 - 5 + 1 30 From 02a25cb26206f8b9119fa1fa383c59a88b4aa61f Mon Sep 17 00:00:00 2001 From: Amirreza Baghbanpourasl Date: Fri, 18 Nov 2022 17:10:24 +0100 Subject: [PATCH 3/3] zoom in and out centers around the mouse pointer --- src/image_canvas.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ src/image_canvas.h | 4 ++++ 2 files changed, 47 insertions(+) diff --git a/src/image_canvas.cpp b/src/image_canvas.cpp index 43f94bd..6bfec3f 100644 --- a/src/image_canvas.cpp +++ b/src/image_canvas.cpp @@ -99,9 +99,47 @@ void ImageCanvas::saveMask() { void ImageCanvas::scaleChanged(double scale) { _scale = scale ; resize(_scale * _image.size()); + + adjustScrollBars(); repaint(); } +void ImageCanvas::adjustScrollBars() +{ // from : https://github.com/BestVanRome + // x ------> + // _________ + // y |.........| + // | |.........| + // | |.........| + // | |.........| + // v |.........| + // --------- + QPointF mPos = _mouse_pos; + QSize imSize = _act_im_size; + + + if (_scroll_parent->verticalScrollBar()) + { + auto posHeightRel = (mPos.y() / imSize.height()); //Relation Mauspos to Height of Image + + //set vertical scrollbar to mouse position + QScrollBar* verticalScroll = _scroll_parent->verticalScrollBar(); + double vertScrollSpace = verticalScroll->maximum() - verticalScroll->minimum(); // general calculating of moving-space + verticalScroll->setValue(vertScrollSpace * posHeightRel); + //alternative: QWheelEvent::angleDelta().y() -> see example!!! : https://doc.qt.io/qt-5/qwheelevent.html#angleDelta + } + + if (_scroll_parent->horizontalScrollBar()) + { + auto posWidthRel = (mPos.x() / imSize.width()); ////Relation Mauspos to Width of Image + + //set horizontal scrollbar to mouse position + QScrollBar* horizontalScroll = _scroll_parent->horizontalScrollBar(); + double horizScrollSpace = horizontalScroll->maximum() - horizontalScroll->minimum(); // general calculating of moving-space + horizontalScroll->setValue(horizScrollSpace * posWidthRel); + } +} + void ImageCanvas::alphaChanged(double alpha) { _alpha = alpha; repaint(); @@ -144,8 +182,13 @@ void ImageCanvas::mouseMoveEvent(QMouseEvent * e) { if (_button_is_pressed) _drawFillCircle(e); + _act_im_size = _image.size() * _scale; //important for adjusting the scrollBars + //using statusbar to show actual _mouse_pos + _ui->statusbar->showMessage("X: " + QString::number(_mouse_pos.x()) + " " + + "Y: " + QString::number(_mouse_pos.y())); update(); + } void ImageCanvas::setSizePen(int pen_size) { diff --git a/src/image_canvas.h b/src/image_canvas.h index 6b5e1d7..6cfeb39 100644 --- a/src/image_canvas.h +++ b/src/image_canvas.h @@ -71,6 +71,10 @@ public slots : ColorMask _color ; int _pen_size ; bool _button_is_pressed; + QSize _act_im_size; + +private slots: + void adjustScrollBars(); };