Skip to content

Commit

Permalink
Merge branch 'arbasli2_master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
abreheret committed Nov 21, 2022
2 parents 4920f8e + 02a25cb commit d8203eb
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
10 changes: 10 additions & 0 deletions scripts_to_build/win_make_vc17_x64.bat
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions src/image_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/image_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public slots :
ColorMask _color ;
int _pen_size ;
bool _button_is_pressed;
QSize _act_im_size;

private slots:
void adjustScrollBars();

};

Expand Down
6 changes: 3 additions & 3 deletions src/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@
<item>
<widget class="QDoubleSpinBox" name="spinbox_scale">
<property name="minimum">
<double>0.050000000000000</double>
<double>0.500000000000000</double>
</property>
<property name="maximum">
<double>8.000000000000000</double>
</property>
<property name="singleStep">
<double>0.050000000000000</double>
<double>0.500000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
Expand All @@ -216,7 +216,7 @@
<number>0</number>
</property>
<property name="singleStep">
<number>5</number>
<number>1</number>
</property>
<property name="value">
<number>30</number>
Expand Down

0 comments on commit d8203eb

Please sign in to comment.