Skip to content

Commit d8203eb

Browse files
committed
Merge branch 'arbasli2_master' into dev
2 parents 4920f8e + 02a25cb commit d8203eb

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mkdir build
2+
cd build
3+
mkdir x64
4+
cd x64
5+
6+
cmake -DQT5_DIR=C:/Qt/5.15.2/msvc2019_64/lib/cmake -DCMAKE_PREFIX_PATH=../opencv/build/install -G "Visual Studio 17 2022" ../../..
7+
8+
cmake --build . --config Release
9+
10+
PAUSE

src/image_canvas.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,47 @@ void ImageCanvas::saveMask() {
9999
void 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+
105143
void 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

151194
void ImageCanvas::setSizePen(int pen_size) {

src/image_canvas.h

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public slots :
7171
ColorMask _color ;
7272
int _pen_size ;
7373
bool _button_is_pressed;
74+
QSize _act_im_size;
75+
76+
private slots:
77+
void adjustScrollBars();
7478

7579
};
7680

src/main_window.ui

+3-3
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@
186186
<item>
187187
<widget class="QDoubleSpinBox" name="spinbox_scale">
188188
<property name="minimum">
189-
<double>0.050000000000000</double>
189+
<double>0.500000000000000</double>
190190
</property>
191191
<property name="maximum">
192192
<double>8.000000000000000</double>
193193
</property>
194194
<property name="singleStep">
195-
<double>0.050000000000000</double>
195+
<double>0.500000000000000</double>
196196
</property>
197197
<property name="value">
198198
<double>1.000000000000000</double>
@@ -216,7 +216,7 @@
216216
<number>0</number>
217217
</property>
218218
<property name="singleStep">
219-
<number>5</number>
219+
<number>1</number>
220220
</property>
221221
<property name="value">
222222
<number>30</number>

0 commit comments

Comments
 (0)