10#include "qwt_magnifier.h"
16class QwtMagnifier::PrivateData
22 , wheelModifiers( Qt::NoModifier )
24 , mouseButton( Qt::RightButton )
25 , mouseButtonModifiers( Qt::NoModifier )
27 , zoomInKey( Qt::Key_Plus )
28 , zoomInKeyModifiers( Qt::NoModifier )
29 , zoomOutKey( Qt::Key_Minus )
30 , zoomOutKeyModifiers( Qt::NoModifier )
31 , mousePressed( false )
32 , hasMouseTracking( false )
39 Qt::KeyboardModifiers wheelModifiers;
43 Qt::MouseButton mouseButton;
44 Qt::KeyboardModifiers mouseButtonModifiers;
49 Qt::KeyboardModifiers zoomInKeyModifiers;
52 Qt::KeyboardModifiers zoomOutKeyModifiers;
55 bool hasMouseTracking;
66 m_data =
new PrivateData();
70 if ( parent->focusPolicy() == Qt::NoFocus )
71 parent->setFocusPolicy( Qt::WheelFocus );
94 if ( m_data->isEnabled != on )
96 m_data->isEnabled = on;
98 QObject* o = parent();
101 if ( m_data->isEnabled )
102 o->installEventFilter(
this );
104 o->removeEventFilter(
this );
115 return m_data->isEnabled;
136 m_data->wheelFactor = factor;
145 return m_data->wheelFactor;
157 m_data->wheelModifiers = modifiers;
166 return m_data->wheelModifiers;
181 m_data->mouseFactor = factor;
190 return m_data->mouseFactor;
203 Qt::MouseButton button, Qt::KeyboardModifiers modifiers )
205 m_data->mouseButton = button;
206 m_data->mouseButtonModifiers = modifiers;
211 Qt::MouseButton& button, Qt::KeyboardModifiers& modifiers )
const
213 button = m_data->mouseButton;
214 modifiers = m_data->mouseButtonModifiers;
230 m_data->keyFactor = factor;
239 return m_data->keyFactor;
251 Qt::KeyboardModifiers modifiers )
253 m_data->zoomInKey = key;
254 m_data->zoomInKeyModifiers = modifiers;
266 Qt::KeyboardModifiers& modifiers )
const
268 key = m_data->zoomInKey;
269 modifiers = m_data->zoomInKeyModifiers;
281 Qt::KeyboardModifiers modifiers )
283 m_data->zoomOutKey = key;
284 m_data->zoomOutKeyModifiers = modifiers;
296 Qt::KeyboardModifiers& modifiers )
const
298 key = m_data->zoomOutKey;
299 modifiers = m_data->zoomOutKeyModifiers;
319 if (
object &&
object == parent() )
321 switch ( event->type() )
323 case QEvent::MouseButtonPress:
328 case QEvent::MouseMove:
333 case QEvent::MouseButtonRelease:
343 case QEvent::KeyPress:
348 case QEvent::KeyRelease:
356 return QObject::eventFilter(
object, event );
370 if ( ( mouseEvent->button() != m_data->mouseButton ) ||
371 ( mouseEvent->modifiers() != m_data->mouseButtonModifiers ) )
376 m_data->hasMouseTracking =
parentWidget()->hasMouseTracking();
379 m_data->mousePos = mouseEvent->pos();
380 m_data->mousePressed =
true;
392 Q_UNUSED( mouseEvent );
396 m_data->mousePressed =
false;
397 parentWidget()->setMouseTracking( m_data->hasMouseTracking );
409 if ( !m_data->mousePressed )
412 const int dy = mouseEvent->pos().y() - m_data->mousePos.y();
415 double f = m_data->mouseFactor;
422 m_data->mousePos = mouseEvent->pos();
433 if ( wheelEvent->modifiers() != m_data->wheelModifiers )
438 if ( m_data->wheelFactor != 0.0 )
440#if QT_VERSION < 0x050000
441 const int wheelDelta = wheelEvent->delta();
443 const QPoint delta = wheelEvent->angleDelta();
444 const int wheelDelta = ( qAbs( delta.x() ) > qAbs( delta.y() ) )
445 ? delta.x() : delta.y();
457 double f = std::pow( m_data->wheelFactor,
458 qAbs( wheelDelta / 120.0 ) );
460 if ( wheelDelta > 0 )
475 if ( keyEvent->key() == m_data->zoomInKey &&
476 keyEvent->modifiers() == m_data->zoomInKeyModifiers )
480 else if ( keyEvent->key() == m_data->zoomOutKey &&
481 keyEvent->modifiers() == m_data->zoomOutKeyModifiers )
483 rescale( 1.0 / m_data->keyFactor );
495 Q_UNUSED( keyEvent );
501 return qobject_cast< QWidget* >( parent() );
507 return qobject_cast< const QWidget* >( parent() );
510#include "moc_qwt_magnifier.cpp"
void setZoomInKey(int key, Qt::KeyboardModifiers=Qt::NoModifier)
void setEnabled(bool)
En/disable the magnifier.
void setZoomOutKey(int key, Qt::KeyboardModifiers=Qt::NoModifier)
void getZoomInKey(int &key, Qt::KeyboardModifiers &) const
Retrieve the settings of the zoom in key.
virtual void widgetWheelEvent(QWheelEvent *)
double mouseFactor() const
virtual void widgetKeyPressEvent(QKeyEvent *)
Qt::KeyboardModifiers wheelModifiers() const
virtual void widgetMouseMoveEvent(QMouseEvent *)
virtual void widgetMousePressEvent(QMouseEvent *)
virtual void rescale(double factor)=0
void getMouseButton(Qt::MouseButton &, Qt::KeyboardModifiers &) const
double wheelFactor() const
virtual void widgetMouseReleaseEvent(QMouseEvent *)
void setWheelModifiers(Qt::KeyboardModifiers)
void setKeyFactor(double)
Change the key factor.
virtual ~QwtMagnifier()
Destructor.
void getZoomOutKey(int &key, Qt::KeyboardModifiers &) const
Retrieve the settings of the zoom out key.
void setMouseButton(Qt::MouseButton, Qt::KeyboardModifiers=Qt::NoModifier)
void setMouseFactor(double)
Change the mouse factor.
void setWheelFactor(double)
Change the wheel factor.
virtual void widgetKeyReleaseEvent(QKeyEvent *)
virtual bool eventFilter(QObject *, QEvent *) override
Event filter.