Skip to content

Commit

Permalink
#61 prevent qscrollarea in imagewidget from scrolling on zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrussmill committed Nov 30, 2019
1 parent 617bd68 commit 93717b4
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 6 deletions.
7 changes: 5 additions & 2 deletions imagewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include <QScrollBar>
#include <QPixmap>
#include <algorithm>
#include "mousewheelctrleatereventfilter.h"

#include <QDebug>

Expand All @@ -81,6 +82,8 @@ ImageWidget::ImageWidget(QWidget *parent) : QWidget(parent),
imageLabel_m->setScaledContents(true);
imageLabel_m->setVisible(false);

MouseWheelCtrlEaterEventFilter *wheelFilter = new MouseWheelCtrlEaterEventFilter(scrollArea_m);
scrollArea_m->viewport()->installEventFilter(wheelFilter);
scrollArea_m->setObjectName("imageWidgetBackground");
scrollArea_m->setAlignment(Qt::AlignCenter);
scrollArea_m->setWidget(imageLabel_m);
Expand Down Expand Up @@ -228,7 +231,7 @@ void ImageWidget::clearImage()
void ImageWidget::zoomIn()
{
if(!imageAttached()) return;
float tmpScalar = scalar_m * 1.125;
float tmpScalar = scalar_m * 1.125f;
if (tmpScalar * imageLabel_m->width() > 32768 ||
tmpScalar * imageLabel_m->height() > 32768)
{
Expand All @@ -249,7 +252,7 @@ void ImageWidget::zoomIn()
void ImageWidget::zoomOut()
{
if(!imageAttached()) return;
scalar_m *= 0.889;
scalar_m *= 0.889f;
imageLabel_m->resize(scalar_m * attachedImage_m->size());
if (fillScrollArea_m == true)
{
Expand Down
2 changes: 2 additions & 0 deletions imagewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class QImage;
class QMenu;
class QMutex;
class QPixmap;
class MouseWheelCtrlEaterEventFilter;

class ImageWidget : public QWidget
{
Expand Down Expand Up @@ -114,6 +115,7 @@ public slots:
QAction *zoomActualAction_m;
QScrollArea *scrollArea_m;
const QImage *attachedImage_m = nullptr;
MouseWheelCtrlEaterEventFilter *wheelFilter;
float scalar_m;
bool fillScrollArea_m = true;
};
Expand Down
55 changes: 55 additions & 0 deletions mousewheelctrleatereventfilter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,61 @@
/***********************************************************************
* FILENAME : mousewheeleatereventfilter.h
*
* LICENSE:
* qcvTouchUp provides an image processing toolset for editing
* photographs, purposed and packaged for use in a desktop application
* user environment. Copyright (C) 2018, Matthew R. Miller
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation (version 3 of the License).
*
* The framework and libraries used to create this software are licenced
* under the GNU Lesser General Public License (LGPL) version 3 and the
* 3-clause BSD License as agreed upon through the use of the Qt toolkit
* and OpenCV libraries respectively. Copies of the appropriate licenses
* for qcvTouchup, and its source code, can be found in LICENSE.txt,
* LICENSE.Qt.txt, and LICENSE.CV.txt. If not, please see
* <http://www.gnu.org/licenses/> and <https://opencv.org/license.html>
* for further information on licensing.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* If you wish to contact the developer about this project, please do so
* through their account at <https://github.com/mattrussmill>
*
* DESCRIPTION :
* This object is an event filter to disable mouse scroll wheel interactions
* when the ctrl key is held down.
*
* NOTES :
* Some QWidgets have scroll wheel interactions which cannot be disabled.
*
* AUTHOR : Matthew R. Miller START DATE : March 6, 2018
*
* CHANGES : N/A - N/A
*
* VERSION DATE WHO DETAIL
* 0.1 November 30, 2019 Matthew R. Miller Initial Rev
*
************************************************************************/
#include "mousewheelctrleatereventfilter.h"
#include <QEvent>
#include <QApplication>

MouseWheelCtrlEaterEventFilter::MouseWheelCtrlEaterEventFilter(QObject *parent) : QObject(parent)
{

}

//If the event is a mouse scroll wheel event with the ctrl modifier, eventFilter returns true to disable further processing
bool MouseWheelCtrlEaterEventFilter::eventFilter(QObject *watched, QEvent *event)
{
if(QApplication::queryKeyboardModifiers() & Qt::ControlModifier)
if(event->type() == QEvent::Wheel)
return true;
return false;
}
49 changes: 46 additions & 3 deletions mousewheelctrleatereventfilter.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
/***********************************************************************
* FILENAME : mousewheeleatereventfilter.h
*
* LICENSE:
* qcvTouchUp provides an image processing toolset for editing
* photographs, purposed and packaged for use in a desktop application
* user environment. Copyright (C) 2018, Matthew R. Miller
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation (version 3 of the License).
*
* The framework and libraries used to create this software are licenced
* under the GNU Lesser General Public License (LGPL) version 3 and the
* 3-clause BSD License as agreed upon through the use of the Qt toolkit
* and OpenCV libraries respectively. Copies of the appropriate licenses
* for qcvTouchup, and its source code, can be found in LICENSE.txt,
* LICENSE.Qt.txt, and LICENSE.CV.txt. If not, please see
* <http://www.gnu.org/licenses/> and <https://opencv.org/license.html>
* for further information on licensing.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* If you wish to contact the developer about this project, please do so
* through their account at <https://github.com/mattrussmill>
*
* DESCRIPTION :
* This object is an event filter to disable mouse scroll wheel interactions
* when the ctrl key is held down.
*
* NOTES :
* Some QWidgets have scroll wheel interactions which cannot be disabled.
*
* AUTHOR : Matthew R. Miller START DATE : March 6, 2018
*
* CHANGES : N/A - N/A
*
* VERSION DATE WHO DETAIL
* 0.1 November 30, 2019 Matthew R. Miller Initial Rev
*
************************************************************************/
#ifndef MOUSEWHEELCTRLEATEREVENTFILTER_H
#define MOUSEWHEELCTRLEATEREVENTFILTER_H

Expand All @@ -9,9 +53,8 @@ class MouseWheelCtrlEaterEventFilter : public QObject
public:
explicit MouseWheelCtrlEaterEventFilter(QObject *parent = nullptr);

signals:

public slots:
protected:
bool eventFilter(QObject *watched, QEvent *event);
};

#endif // MOUSEWHEELCTRLEATEREVENTFILTER_H
1 change: 0 additions & 1 deletion mousewheeleatereventfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
*
************************************************************************/
#include "mousewheeleatereventfilter.h"
#include <QObject>
#include <QEvent>

//Autogenerated constructor
Expand Down
2 changes: 2 additions & 0 deletions qcvTouchUp.pro
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SOURCES += \
main.cpp \
mainwindow.cpp \
imagewidget.cpp \
mousewheelctrleatereventfilter.cpp \
quickmenu.cpp \
adjustmenu.cpp \
mousewheeleatereventfilter.cpp \
Expand All @@ -58,6 +59,7 @@ HEADERS += \
imagesavewebpmenu.h \
mainwindow.h \
imagewidget.h \
mousewheelctrleatereventfilter.h \
quickmenu.h \
adjustmenu.h \
mousewheeleatereventfilter.h \
Expand Down

0 comments on commit 93717b4

Please sign in to comment.