Skip to content

Commit

Permalink
src:update view windows code
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoming <[email protected]>
  • Loading branch information
QQxiaoming committed Jun 9, 2023
1 parent f2ec8e4 commit b1c6426
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/ImgViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ void ImgViewer::mouseDoubleClickEvent(QMouseEvent *event) {
}

void ImgViewer::wheelEvent(QWheelEvent *event) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
double event_x=event->position().x();
double event_y=event->position().y();
#else
double event_x=event->x();
double event_y=event->y();
#endif
if (!this->img_list.empty()) {
if( event->angleDelta().y() > 0) {
// 放大图片
Expand All @@ -289,10 +296,10 @@ void ImgViewer::wheelEvent(QWheelEvent *event) {
if(this->flipRGB) {
this->scaled_img = this->scaled_img.rgbSwapped();
}
float new_w = event->position().x() -
(this->scaled_img.width() * (event->position().x() - this->point.x())) / (this->scaled_img.width() - setpsize_x);
float new_h = event->position().y() -
(this->scaled_img.height() * (event->position().y() - this->point.y())) / (this->scaled_img.height() - setpsize_y);
float new_w = event_x -
(this->scaled_img.width() * (event_x - this->point.x())) / (this->scaled_img.width() - setpsize_x);
float new_h = event_y -
(this->scaled_img.height() * (event_y - this->point.y())) / (this->scaled_img.height() - setpsize_y);
this->point = QPoint(new_w, new_h);
this->repaint();
}
Expand All @@ -308,10 +315,10 @@ void ImgViewer::wheelEvent(QWheelEvent *event) {
if(this->flipRGB) {
this->scaled_img = this->scaled_img.rgbSwapped();
}
float new_w = event->position().x() -
(this->scaled_img.width() * (event->position().x() - this->point.x())) / (this->scaled_img.width() + setpsize_x);
float new_h = event->position().y() -
(this->scaled_img.height() * (event->position().y() - this->point.y())) / (this->scaled_img.height() + setpsize_y);
float new_w = event_x -
(this->scaled_img.width() * (event_x - this->point.x())) / (this->scaled_img.width() + setpsize_x);
float new_h = event_y -
(this->scaled_img.height() * (event_y - this->point.y())) / (this->scaled_img.height() + setpsize_y);
this->point = QPoint(new_w, new_h);
this->repaint();
}
Expand Down

0 comments on commit b1c6426

Please sign in to comment.