Skip to content
qwt_event_pattern.h 5.83 KiB
Newer Older
pixhawk's avatar
pixhawk committed
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
pixhawk's avatar
pixhawk committed
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#ifndef QWT_EVENT_PATTERN
#define QWT_EVENT_PATTERN 1

Bryant's avatar
Bryant committed
#include "qwt_global.h"
pixhawk's avatar
pixhawk committed
#include <qnamespace.h>
Bryant's avatar
Bryant committed
#include <qvector.h>
pixhawk's avatar
pixhawk committed

class QMouseEvent;
class QKeyEvent;

/*!
  \brief A collection of event patterns

  QwtEventPattern introduces an level of indirection for mouse and
  keyboard inputs. Those are represented by symbolic names, so
pixhawk's avatar
pixhawk committed
  the application code can be configured by individual mappings.

  \sa QwtPicker, QwtPickerMachine, QwtPlotZoomer
*/
class QWT_EXPORT QwtEventPattern
{
public:
    /*!
      \brief Symbolic mouse input codes

Bryant's avatar
Bryant committed
      QwtEventPattern implements 3 different settings for
      mice with 1, 2, or 3 buttons that can be activated
      using initMousePattern(). The default setting is for
      3 button mice.

      Individual settings can be configured using setMousePattern().

      \sa initMousePattern(), setMousePattern(), setKeyPattern()
pixhawk's avatar
pixhawk committed
    */
Bryant's avatar
Bryant committed
    enum MousePatternCode
    {
        /*! 
          The default setting for 1, 2 and 3 button mice is:
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
          - Qt::LeftButton 
          - Qt::LeftButton 
          - Qt::LeftButton 
         */
pixhawk's avatar
pixhawk committed
        MouseSelect1,
Bryant's avatar
Bryant committed

        /*!
          The default setting for 1, 2 and 3 button mice is:

          - Qt::LeftButton + Qt::ControlModifier
          - Qt::RightButton
          - Qt::RightButton
         */
pixhawk's avatar
pixhawk committed
        MouseSelect2,
Bryant's avatar
Bryant committed

        /*!
          The default setting for 1, 2 and 3 button mice is:

          - Qt::LeftButton + Qt::AltModifier
          - Qt::LeftButton + Qt::AltModifier
          - Qt::MidButton
         */
pixhawk's avatar
pixhawk committed
        MouseSelect3,
Bryant's avatar
Bryant committed

        /*!
          The default setting for 1, 2 and 3 button mice is:

          - Qt::LeftButton + Qt::ShiftModifier
          - Qt::LeftButton + Qt::ShiftModifier
          - Qt::LeftButton + Qt::ShiftModifier
         */
pixhawk's avatar
pixhawk committed
        MouseSelect4,
Bryant's avatar
Bryant committed

        /*!
          The default setting for 1, 2 and 3 button mice is:

          - Qt::LeftButton + Qt::ControlButton | Qt::ShiftModifier
          - Qt::RightButton + Qt::ShiftModifier
          - Qt::RightButton + Qt::ShiftModifier
         */
pixhawk's avatar
pixhawk committed
        MouseSelect5,
Bryant's avatar
Bryant committed

        /*!
          The default setting for 1, 2 and 3 button mice is:

          - Qt::LeftButton + Qt::AltModifier + Qt::ShiftModifier
          - Qt::LeftButton + Qt::AltModifier | Qt::ShiftModifier
          - Qt::MidButton + Qt::ShiftModifier
         */
pixhawk's avatar
pixhawk committed
        MouseSelect6,

Bryant's avatar
Bryant committed
        //! Number of mouse patterns
pixhawk's avatar
pixhawk committed
        MousePatternCount
    };

    /*!
      \brief Symbolic keyboard input codes

Bryant's avatar
Bryant committed
      Individual settings can be configured using setKeyPattern()

      \sa setKeyPattern(), setMousePattern()
pixhawk's avatar
pixhawk committed
    */
Bryant's avatar
Bryant committed
    enum KeyPatternCode
    {
        //! Qt::Key_Return
pixhawk's avatar
pixhawk committed
        KeySelect1,
Bryant's avatar
Bryant committed

        //! Qt::Key_Space
pixhawk's avatar
pixhawk committed
        KeySelect2,
Bryant's avatar
Bryant committed

        //! Qt::Key_Escape
pixhawk's avatar
pixhawk committed
        KeyAbort,

Bryant's avatar
Bryant committed
        //! Qt::Key_Left
pixhawk's avatar
pixhawk committed
        KeyLeft,
Bryant's avatar
Bryant committed

        //! Qt::Key_Right
pixhawk's avatar
pixhawk committed
        KeyRight,
Bryant's avatar
Bryant committed

        //! Qt::Key_Up
pixhawk's avatar
pixhawk committed
        KeyUp,
Bryant's avatar
Bryant committed

        //! Qt::Key_Down
pixhawk's avatar
pixhawk committed
        KeyDown,

Bryant's avatar
Bryant committed
        //! Qt::Key_Plus
pixhawk's avatar
pixhawk committed
        KeyRedo,
Bryant's avatar
Bryant committed

        //! Qt::Key_Minus
pixhawk's avatar
pixhawk committed
        KeyUndo,
Bryant's avatar
Bryant committed

        //! Qt::Key_Escape
pixhawk's avatar
pixhawk committed
        KeyHome,

Bryant's avatar
Bryant committed
        //! Number of key patterns
pixhawk's avatar
pixhawk committed
        KeyPatternCount
    };

    //! A pattern for mouse events
    class MousePattern
    {
    public:
Bryant's avatar
Bryant committed
        //! Constructor
        MousePattern( Qt::MouseButton btn = Qt::NoButton, 
                Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):
            button( btn ),
            modifiers( modifierCodes )
        {
pixhawk's avatar
pixhawk committed
        }

Bryant's avatar
Bryant committed
        //! Button 
        Qt::MouseButton button;

        //! Keyboard modifier
        Qt::KeyboardModifiers modifiers;
pixhawk's avatar
pixhawk committed
    };

    //! A pattern for key events
    class KeyPattern
    {
    public:
Bryant's avatar
Bryant committed
        //! Constructor
        KeyPattern( int keyCode = Qt::Key_unknown, 
                Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):
            key( keyCode ),
            modifiers( modifierCodes )
        {
pixhawk's avatar
pixhawk committed
        }

Bryant's avatar
Bryant committed
        //! Key code
pixhawk's avatar
pixhawk committed
        int key;
Bryant's avatar
Bryant committed

        //! Modifiers
        Qt::KeyboardModifiers modifiers;
pixhawk's avatar
pixhawk committed
    };

    QwtEventPattern();
    virtual ~QwtEventPattern();

Bryant's avatar
Bryant committed
    void initMousePattern( int numButtons );
pixhawk's avatar
pixhawk committed
    void initKeyPattern();

Bryant's avatar
Bryant committed
    void setMousePattern( MousePatternCode, Qt::MouseButton button, 
        Qt::KeyboardModifiers = Qt::NoModifier );
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void setKeyPattern( KeyPatternCode, int keyCode, 
        Qt::KeyboardModifiers modifierCodes = Qt::NoModifier );
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void setMousePattern( const QVector<MousePattern> & );
    void setKeyPattern( const QVector<KeyPattern> & );
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    const QVector<MousePattern> &mousePattern() const;
    const QVector<KeyPattern> &keyPattern() const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    QVector<MousePattern> &mousePattern();
    QVector<KeyPattern> &keyPattern();

    bool mouseMatch( MousePatternCode, const QMouseEvent * ) const;
    bool keyMatch( KeyPatternCode, const QKeyEvent * ) const;
pixhawk's avatar
pixhawk committed

protected:
Bryant's avatar
Bryant committed
    virtual bool mouseMatch( const MousePattern &, const QMouseEvent * ) const;
    virtual bool keyMatch( const KeyPattern &, const QKeyEvent * ) const;
pixhawk's avatar
pixhawk committed
private:

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
Bryant's avatar
Bryant committed
    QVector<MousePattern> d_mousePattern;
    QVector<KeyPattern> d_keyPattern;
pixhawk's avatar
pixhawk committed
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
};

Bryant's avatar
Bryant committed
//! Compare operator
inline bool operator==( QwtEventPattern::MousePattern b1,
    QwtEventPattern::MousePattern  b2 )
Bryant's avatar
Bryant committed
    return b1.button == b2.button && b1.modifiers == b2.modifiers;
pixhawk's avatar
pixhawk committed
}

Bryant's avatar
Bryant committed
//! Compare operator
inline bool operator==( QwtEventPattern::KeyPattern b1,
   QwtEventPattern::KeyPattern  b2 )
Bryant's avatar
Bryant committed
    return b1.key == b2.key && b1.modifiers == b2.modifiers;
pixhawk's avatar
pixhawk committed
}

#endif