Classes | Public Member Functions | Protected Member Functions

QwtMagnifier Class Reference

QwtMagnifier provides zooming, by magnifying in steps. More...

#include <qwt_magnifier.h>

Inheritance diagram for QwtMagnifier:
Inheritance graph
[legend]
Collaboration diagram for QwtMagnifier:
Collaboration graph
[legend]

List of all members.

Classes

class  PrivateData

Public Member Functions

 QwtMagnifier (QWidget *)
virtual ~QwtMagnifier ()
 Destructor.
QWidget * parentWidget ()
const QWidget * parentWidget () const
void setEnabled (bool)
 En/disable the magnifier.
bool isEnabled () const
void setMouseFactor (double)
 Change the mouse factor.
double mouseFactor () const
void setMouseButton (int button, int buttonState=Qt::NoButton)
void getMouseButton (int &button, int &buttonState) const
void setWheelFactor (double)
 Change the wheel factor.
double wheelFactor () const
void setWheelButtonState (int buttonState)
int wheelButtonState () const
void setKeyFactor (double)
 Change the key factor.
double keyFactor () const
void setZoomInKey (int key, int modifiers)
void getZoomInKey (int &key, int &modifiers) const
void setZoomOutKey (int key, int modifiers)
void getZoomOutKey (int &key, int &modifiers) const
virtual bool eventFilter (QObject *, QEvent *)
 Event filter.

Protected Member Functions

virtual void rescale (double factor)=0
virtual void widgetMousePressEvent (QMouseEvent *)
virtual void widgetMouseReleaseEvent (QMouseEvent *)
virtual void widgetMouseMoveEvent (QMouseEvent *)
virtual void widgetWheelEvent (QWheelEvent *)
virtual void widgetKeyPressEvent (QKeyEvent *)
virtual void widgetKeyReleaseEvent (QKeyEvent *)

Detailed Description

QwtMagnifier provides zooming, by magnifying in steps.

Using QwtMagnifier a plot can be zoomed in/out in steps using keys, the mouse wheel or moving a mouse button in vertical direction.

Definition at line 27 of file qwt_magnifier.h.


Constructor & Destructor Documentation

QwtMagnifier::QwtMagnifier ( QWidget *  parent ) [explicit]

Constructor

Parameters:
parentWidget to be magnified

Definition at line 66 of file qwt_magnifier.cpp.

References setEnabled().

                                         :
    QObject(parent)
{
    d_data = new PrivateData();
    setEnabled(true);
}
QwtMagnifier::~QwtMagnifier (  ) [virtual]

Destructor.

Definition at line 74 of file qwt_magnifier.cpp.

{
    delete d_data;
}

Member Function Documentation

bool QwtMagnifier::eventFilter ( QObject *  o,
QEvent *  e 
) [virtual]

Event filter.

When isEnabled() the mouse events of the observed widget are filtered.

See also:
widgetMousePressEvent(), widgetMouseReleaseEvent(), widgetMouseMoveEvent(), widgetWheelEvent(), widgetKeyPressEvent() widgetKeyReleaseEvent()

Definition at line 282 of file qwt_magnifier.cpp.

References widgetKeyPressEvent(), widgetKeyReleaseEvent(), widgetMouseMoveEvent(), widgetMousePressEvent(), widgetMouseReleaseEvent(), and widgetWheelEvent().

{
    if ( o && o == parent() )
    {
        switch(e->type() )
        {
            case QEvent::MouseButtonPress:
            {
                widgetMousePressEvent((QMouseEvent *)e);
                break;
            }
            case QEvent::MouseMove:
            {
                widgetMouseMoveEvent((QMouseEvent *)e);
                break;
            }
            case QEvent::MouseButtonRelease:
            {
                widgetMouseReleaseEvent((QMouseEvent *)e);
                break;
            }
            case QEvent::Wheel:
            {
                widgetWheelEvent((QWheelEvent *)e);
                break;
            }
            case QEvent::KeyPress:
            {
                widgetKeyPressEvent((QKeyEvent *)e);
                break;
            }
            case QEvent::KeyRelease:
            {
                widgetKeyReleaseEvent((QKeyEvent *)e);
                break;
            }
            default:;
        }
    }
    return QObject::eventFilter(o, e);
}
void QwtMagnifier::getMouseButton ( int &  button,
int &  buttonState 
) const
See also:
setMouseButton()

Definition at line 199 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::mouseButton, and QwtMagnifier::PrivateData::mouseButtonState.

{
    button = d_data->mouseButton;
    buttonState = d_data->mouseButtonState;
}
void QwtMagnifier::getZoomInKey ( int &  key,
int &  modifiers 
) const
See also:
setZoomInKey()

Definition at line 246 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::zoomInKey, and QwtMagnifier::PrivateData::zoomInKeyModifiers.

{
    key = d_data->zoomInKey;
    modifiers = d_data->zoomInKeyModifiers;
}
void QwtMagnifier::getZoomOutKey ( int &  key,
int &  modifiers 
) const
See also:
setZoomOutKey()

Definition at line 267 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::zoomOutKey, and QwtMagnifier::PrivateData::zoomOutKeyModifiers.

{
    key = d_data->zoomOutKey;
    modifiers = d_data->zoomOutKeyModifiers;
}
bool QwtMagnifier::isEnabled (  ) const
Returns:
true when enabled, false otherwise
See also:
setEnabled(), eventFilter()

Definition at line 109 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::isEnabled.

{
    return d_data->isEnabled;
}
double QwtMagnifier::keyFactor (  ) const
Returns:
Key factor
See also:
setKeyFactor()

Definition at line 226 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::keyFactor.

{
    return d_data->keyFactor;
}
double QwtMagnifier::mouseFactor (  ) const
Returns:
Mouse factor
See also:
setMouseFactor()

Definition at line 179 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::mouseFactor.

{
    return d_data->mouseFactor;
}
QWidget * QwtMagnifier::parentWidget (  )
Returns:
Parent widget, where the rescaling happens

Definition at line 466 of file qwt_magnifier.cpp.

Referenced by widgetMousePressEvent(), and widgetMouseReleaseEvent().

{
    if ( parent()->inherits("QWidget") )
        return (QWidget *)parent();

    return NULL;
}
const QWidget * QwtMagnifier::parentWidget (  ) const
Returns:
Parent widget, where the rescaling happens

Definition at line 475 of file qwt_magnifier.cpp.

{
    if ( parent()->inherits("QWidget") )
        return (const QWidget *)parent();

    return NULL;
}
virtual void QwtMagnifier::rescale ( double  factor ) [protected, pure virtual]

Rescale the parent widget

Parameters:
factorScale factor

Implemented in QwtPlotMagnifier.

Referenced by widgetKeyPressEvent(), widgetMouseMoveEvent(), and widgetWheelEvent().

void QwtMagnifier::setEnabled ( bool  on )

En/disable the magnifier.

When enabled is true an event filter is installed for the observed widget, otherwise the event filter is removed.

Parameters:
ontrue or false
See also:
isEnabled(), eventFilter()

Definition at line 88 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::isEnabled.

Referenced by QwtMagnifier().

{
    if ( d_data->isEnabled != on )
    {
        d_data->isEnabled = on;

        QObject *o = parent();
        if ( o )
        {
            if ( d_data->isEnabled )
                o->installEventFilter(this);
            else
                o->removeEventFilter(this);
        }
    }
}
void QwtMagnifier::setKeyFactor ( double  factor )

Change the key factor.

The key factor defines the ratio between the current range on the parent widget and the zoomed range for each key press of the zoom in/out keys. The default value is 0.9.

Parameters:
factorKey factor
See also:
keyFactor(), setZoomInKey(), setZoomOutKey(), setWheelFactor, setMouseFactor()

Definition at line 217 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::keyFactor.

{
    d_data->keyFactor = factor;
}
void QwtMagnifier::setMouseButton ( int  button,
int  buttonState = Qt::NoButton 
)

Assign the mouse button, that is used for zooming in/out. The default value is Qt::RightButton.

Parameters:
buttonButton
buttonStateButton state
See also:
getMouseButton()

Definition at line 192 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::mouseButton, and QwtMagnifier::PrivateData::mouseButtonState.

{
    d_data->mouseButton = button;
    d_data->mouseButtonState = buttonState;
}
void QwtMagnifier::setMouseFactor ( double  factor )

Change the mouse factor.

The mouse factor defines the ratio between the current range on the parent widget and the zoomed range for each vertical mouse movement. The default value is 0.95.

Parameters:
factorWheel factor
See also:
mouseFactor(), setMouseButton(), setWheelFactor(), setKeyFactor()

Definition at line 170 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::mouseFactor.

{
    d_data->mouseFactor = factor;
}
void QwtMagnifier::setWheelButtonState ( int  buttonState )

Assign a mandatory button state for zooming in/out using the wheel. The default button state is Qt::NoButton.

Parameters:
buttonStateButton state
See also:
wheelButtonState()

Definition at line 146 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::wheelButtonState.

{
    d_data->wheelButtonState = buttonState;
}
void QwtMagnifier::setWheelFactor ( double  factor )

Change the wheel factor.

The wheel factor defines the ratio between the current range on the parent widget and the zoomed range for each step of the wheel. The default value is 0.9.

Parameters:
factorWheel factor
See also:
wheelFactor(), setWheelButtonState(), setMouseFactor(), setKeyFactor()

Definition at line 125 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::wheelFactor.

{
    d_data->wheelFactor = factor;
}
void QwtMagnifier::setZoomInKey ( int  key,
int  modifiers 
)

Assign the key, that is used for zooming in. The default combination is Qt::Key_Plus + Qt::NoModifier.

Parameters:
key
modifiers
See also:
getZoomInKey(), setZoomOutKey()

Definition at line 239 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::zoomInKey, and QwtMagnifier::PrivateData::zoomInKeyModifiers.

{
    d_data->zoomInKey = key;
    d_data->zoomInKeyModifiers = modifiers;
}
void QwtMagnifier::setZoomOutKey ( int  key,
int  modifiers 
)

Assign the key, that is used for zooming out. The default combination is Qt::Key_Minus + Qt::NoModifier.

Parameters:
key
modifiers
See also:
getZoomOutKey(), setZoomOutKey()

Definition at line 260 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::zoomOutKey, and QwtMagnifier::PrivateData::zoomOutKeyModifiers.

{
    d_data->zoomOutKey = key;
    d_data->zoomOutKeyModifiers = modifiers;
}
int QwtMagnifier::wheelButtonState (  ) const
Returns:
Wheel button state
See also:
setWheelButtonState()

Definition at line 155 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::wheelButtonState.

{
    return d_data->wheelButtonState;
}
double QwtMagnifier::wheelFactor (  ) const
Returns:
Wheel factor
See also:
setWheelFactor()

Definition at line 134 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::wheelFactor.

{
    return d_data->wheelFactor;
}
void QwtMagnifier::widgetKeyPressEvent ( QKeyEvent *  ke ) [protected, virtual]

Handle a key press event for the observed widget.

Parameters:
keKey event
See also:
eventFilter(), widgetKeyReleaseEvent()

Definition at line 434 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::keyFactor, rescale(), QwtMagnifier::PrivateData::zoomInKey, QwtMagnifier::PrivateData::zoomInKeyModifiers, QwtMagnifier::PrivateData::zoomOutKey, and QwtMagnifier::PrivateData::zoomOutKeyModifiers.

Referenced by eventFilter().

{
    const int key = ke->key();
#if QT_VERSION < 0x040000
    const int state = ke->state();
#else
    const int state = ke->modifiers();
#endif

    if ( key == d_data->zoomInKey && 
        state == d_data->zoomInKeyModifiers )
    {
        rescale(d_data->keyFactor);
    }
    else if ( key == d_data->zoomOutKey && 
        state == d_data->zoomOutKeyModifiers )
    {
        rescale(1.0 / d_data->keyFactor);
    }
}
void QwtMagnifier::widgetKeyReleaseEvent ( QKeyEvent *   ) [protected, virtual]

Handle a key release event for the observed widget.

Parameters:
keKey event
See also:
eventFilter(), widgetKeyReleaseEvent()

Definition at line 461 of file qwt_magnifier.cpp.

Referenced by eventFilter().

{
}
void QwtMagnifier::widgetMouseMoveEvent ( QMouseEvent *  me ) [protected, virtual]

Handle a mouse move event for the observed widget.

Parameters:
meMouse event
See also:
eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),

Definition at line 371 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::mouseFactor, QwtMagnifier::PrivateData::mousePos, QwtMagnifier::PrivateData::mousePressed, and rescale().

Referenced by eventFilter().

{
    if ( !d_data->mousePressed )
        return;

    const int dy = me->pos().y() - d_data->mousePos.y();
    if ( dy != 0 )
    {
        double f = d_data->mouseFactor;
        if ( dy < 0 )
            f = 1 / f;

        rescale(f);
    }

    d_data->mousePos = me->pos();
}
void QwtMagnifier::widgetMousePressEvent ( QMouseEvent *  me ) [protected, virtual]

Handle a mouse press event for the observed widget.

Parameters:
meMouse event
See also:
eventFilter(), widgetMouseReleaseEvent(), widgetMouseMoveEvent()

Definition at line 330 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::hasMouseTracking, QwtMagnifier::PrivateData::mouseButton, QwtMagnifier::PrivateData::mouseButtonState, QwtMagnifier::PrivateData::mousePos, QwtMagnifier::PrivateData::mousePressed, and parentWidget().

Referenced by eventFilter().

{
    if ( me->button() != d_data->mouseButton || parentWidget() == NULL )
        return;

#if QT_VERSION < 0x040000
    if ( (me->state() & Qt::KeyButtonMask) !=
        (d_data->mouseButtonState & Qt::KeyButtonMask) )
#else
    if ( (me->modifiers() & Qt::KeyboardModifierMask) !=
        (int)(d_data->mouseButtonState & Qt::KeyboardModifierMask) )
#endif
    {
        return;
    }

    d_data->hasMouseTracking = parentWidget()->hasMouseTracking();
    parentWidget()->setMouseTracking(true);
    d_data->mousePos = me->pos();
    d_data->mousePressed = true;
}
void QwtMagnifier::widgetMouseReleaseEvent ( QMouseEvent *   ) [protected, virtual]

Handle a mouse release event for the observed widget.

See also:
eventFilter(), widgetMousePressEvent(), widgetMouseMoveEvent(),

Definition at line 356 of file qwt_magnifier.cpp.

References QwtMagnifier::PrivateData::hasMouseTracking, QwtMagnifier::PrivateData::mousePressed, and parentWidget().

Referenced by eventFilter().

{
    if ( d_data->mousePressed && parentWidget() )
    {
        d_data->mousePressed = false;
        parentWidget()->setMouseTracking(d_data->hasMouseTracking);
    }
}
void QwtMagnifier::widgetWheelEvent ( QWheelEvent *  we ) [protected, virtual]

Handle a wheel event for the observed widget.

Parameters:
weWheel event
See also:
eventFilter()

Definition at line 395 of file qwt_magnifier.cpp.

References QuadProgPP::pow(), qwtAbs, rescale(), QwtMagnifier::PrivateData::wheelButtonState, and QwtMagnifier::PrivateData::wheelFactor.

Referenced by eventFilter().

{
#if QT_VERSION < 0x040000
    if ( (we->state() & Qt::KeyButtonMask) !=
        (d_data->wheelButtonState & Qt::KeyButtonMask) )
#else
    if ( (we->modifiers() & Qt::KeyboardModifierMask) !=
        (int)(d_data->wheelButtonState & Qt::KeyboardModifierMask) )
#endif
    {
        return;
    }

    if ( d_data->wheelFactor != 0.0 )
    {
       /*
           A positive delta indicates that the wheel was 
           rotated forwards away from the user; a negative 
           value indicates that the wheel was rotated 
           backwards toward the user.
           Most mouse types work in steps of 15 degrees, 
           in which case the delta value is a multiple 
           of 120 (== 15 * 8).
        */
        double f = ::pow(d_data->wheelFactor, 
            qwtAbs(we->delta() / 120));
        if ( we->delta() > 0 )
            f = 1 / f;

        rescale(f);
    }
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines