@@ -99,9 +99,47 @@ void ImageCanvas::saveMask() {
9999void ImageCanvas::scaleChanged (double scale) {
100100 _scale = scale ;
101101 resize (_scale * _image.size ());
102+
103+ adjustScrollBars ();
102104 repaint ();
103105}
104106
107+ void ImageCanvas::adjustScrollBars ()
108+ { // from : https://github.com/BestVanRome
109+ // x ------>
110+ // _________
111+ // y |.........|
112+ // | |.........|
113+ // | |.........|
114+ // | |.........|
115+ // v |.........|
116+ // ---------
117+ QPointF mPos = _mouse_pos;
118+ QSize imSize = _act_im_size;
119+
120+
121+ if (_scroll_parent->verticalScrollBar ())
122+ {
123+ auto posHeightRel = (mPos .y () / imSize.height ()); // Relation Mauspos to Height of Image
124+
125+ // set vertical scrollbar to mouse position
126+ QScrollBar* verticalScroll = _scroll_parent->verticalScrollBar ();
127+ double vertScrollSpace = verticalScroll->maximum () - verticalScroll->minimum (); // general calculating of moving-space
128+ verticalScroll->setValue (vertScrollSpace * posHeightRel);
129+ // alternative: QWheelEvent::angleDelta().y() -> see example!!! : https://doc.qt.io/qt-5/qwheelevent.html#angleDelta
130+ }
131+
132+ if (_scroll_parent->horizontalScrollBar ())
133+ {
134+ auto posWidthRel = (mPos .x () / imSize.width ()); // //Relation Mauspos to Width of Image
135+
136+ // set horizontal scrollbar to mouse position
137+ QScrollBar* horizontalScroll = _scroll_parent->horizontalScrollBar ();
138+ double horizScrollSpace = horizontalScroll->maximum () - horizontalScroll->minimum (); // general calculating of moving-space
139+ horizontalScroll->setValue (horizScrollSpace * posWidthRel);
140+ }
141+ }
142+
105143void ImageCanvas::alphaChanged (double alpha) {
106144 _alpha = alpha;
107145 repaint ();
@@ -144,8 +182,13 @@ void ImageCanvas::mouseMoveEvent(QMouseEvent * e) {
144182
145183 if (_button_is_pressed)
146184 _drawFillCircle (e);
185+ _act_im_size = _image.size () * _scale; // important for adjusting the scrollBars
147186
187+ // using statusbar to show actual _mouse_pos
188+ _ui->statusbar ->showMessage (" X: " + QString::number (_mouse_pos.x ()) + " " +
189+ " Y: " + QString::number (_mouse_pos.y ()));
148190 update ();
191+
149192}
150193
151194void ImageCanvas::setSizePen (int pen_size) {
0 commit comments