@@ -99,9 +99,47 @@ void ImageCanvas::saveMask() {
99
99
void ImageCanvas::scaleChanged (double scale) {
100
100
_scale = scale ;
101
101
resize (_scale * _image.size ());
102
+
103
+ adjustScrollBars ();
102
104
repaint ();
103
105
}
104
106
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
+
105
143
void ImageCanvas::alphaChanged (double alpha) {
106
144
_alpha = alpha;
107
145
repaint ();
@@ -144,8 +182,13 @@ void ImageCanvas::mouseMoveEvent(QMouseEvent * e) {
144
182
145
183
if (_button_is_pressed)
146
184
_drawFillCircle (e);
185
+ _act_im_size = _image.size () * _scale; // important for adjusting the scrollBars
147
186
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 ()));
148
190
update ();
191
+
149
192
}
150
193
151
194
void ImageCanvas::setSizePen (int pen_size) {
0 commit comments