Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

# qwt_event_pattern.cpp

    00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
    00002  * Qwt Widget Library
    00003  * Copyright (C) 1997   Josef Wilgen
    00004  * Copyright (C) 2002   Uwe Rathmann
    00005  *
    00006  * This library is free software; you can redistribute it and/or
    00007  * modify it under the terms of the Qwt License, Version 1.0
    00008  *****************************************************************************/
    00009
    00010 #include <qevent.h>
    00011 #include "qwt_event_pattern.h"
    00012
    00019 QwtEventPattern::QwtEventPattern():
    00020     d_mousePattern(MousePatternCount),
    00021     d_keyPattern(KeyPatternCount)
    00022 {
    00023     initKeyPattern();
    00024     initMousePattern(3);
    00025 }
    00026
    00028 QwtEventPattern::~QwtEventPattern()
    00029 {
    00030 }
    00031
    00038 void QwtEventPattern::initMousePattern(int numButtons)
    00039 {
    00040     d_mousePattern.resize(MousePatternCount);
    00041
    00042     switch(numButtons)
    00043     {
    00044         case 1:
    00045         {
    00046             setMousePattern(MouseSelect1, Qt::LeftButton);
    00047             setMousePattern(MouseSelect2, Qt::LeftButton, Qt::ControlButton);
    00048             setMousePattern(MouseSelect3, Qt::LeftButton, Qt::AltButton);
    00049             break;
    00050         }
    00051         case 2:
    00052         {
    00053             setMousePattern(MouseSelect1, Qt::LeftButton);
    00054             setMousePattern(MouseSelect2, Qt::RightButton);
    00055             setMousePattern(MouseSelect3, Qt::LeftButton, Qt::AltButton);
    00056             break;
    00057         }
    00058         default:
    00059         {
    00060             setMousePattern(MouseSelect1, Qt::LeftButton);
    00061             setMousePattern(MouseSelect2, Qt::RightButton);
    00062             setMousePattern(MouseSelect3, Qt::MidButton);
    00063         }
    00064     }
    00065     for ( int i = 0; i < 3; i++ )
    00066     {
    00067         setMousePattern(MouseSelect4 + i,
    00068             d_mousePattern[MouseSelect1 + i].button,
    00069             d_mousePattern[MouseSelect1 + i].state | Qt::ShiftButton);
    00070     }
    00071 }
    00072
    00078 void QwtEventPattern::initKeyPattern()
    00079 {
    00080     d_keyPattern.resize(KeyPatternCount);
    00081
    00082     setKeyPattern(KeySelect1, Qt::Key_Return);
    00083     setKeyPattern(KeySelect2, Qt::Key_Space);
    00084     setKeyPattern(KeyAbort, Qt::Key_Escape);
    00085
    00086     setKeyPattern(KeyLeft, Qt::Key_Left);
    00087     setKeyPattern(KeyRight, Qt::Key_Right);
    00088     setKeyPattern(KeyUp, Qt::Key_Up);
    00089     setKeyPattern(KeyDown, Qt::Key_Down);
    00090
    00091     setKeyPattern(KeyRedo, Qt::Key_Plus);
    00092     setKeyPattern(KeyUndo, Qt::Key_Minus);
    00093     setKeyPattern(KeyHome, Qt::Key_Escape);
    00094 }
    00095
    00105 void QwtEventPattern::setMousePattern(uint pattern, int button, int state)
    00106 {
    00107     if ( pattern < d_mousePattern.count() )
    00108     {
    00109         d_mousePattern[int(pattern)].button = button;
    00110         d_mousePattern[int(pattern)].state = state;
    00111     }
    00112 }
    00113
    00123 void QwtEventPattern::setKeyPattern(uint pattern, int key, int state)
    00124 {
    00125     if ( pattern < d_keyPattern.count() )
    00126     {
    00127         d_keyPattern[int(pattern)].key = key;
    00128         d_keyPattern[int(pattern)].state = state;
    00129     }
    00130 }
    00131
    00133 void QwtEventPattern::setMousePattern(const QwtArray<MousePattern> &pattern)
    00134 {
    00135     d_mousePattern = pattern;
    00136 }
    00137
    00139 void QwtEventPattern::setKeyPattern(const QwtArray<KeyPattern> &pattern)
    00140 {
    00141     d_keyPattern = pattern;
    00142 }
    00143
    00145 const QwtArray<QwtEventPattern::MousePattern> &
    00146 QwtEventPattern::mousePattern() const
    00147 {
    00148     return d_mousePattern;
    00149 }
    00150
    00152 const QwtArray<QwtEventPattern::KeyPattern> &
    00153 QwtEventPattern::keyPattern() const
    00154 {
    00155     return d_keyPattern;
    00156 }
    00157
    00159 QwtArray<QwtEventPattern::MousePattern> &QwtEventPattern::mousePattern()
    00160 {
    00161     return d_mousePattern;
    00162 }
    00163
    00165 QwtArray<QwtEventPattern::KeyPattern> &QwtEventPattern::keyPattern()
    00166 {
    00167     return d_keyPattern;
    00168 }
    00169
    00183 bool QwtEventPattern::mouseMatch(uint pattern, const QMouseEvent *e) const
    00184 {
    00185     bool ok = FALSE;
    00186
    00187     if ( e && pattern < d_mousePattern.count() )
    00188         ok = mouseMatch(d_mousePattern[int(pattern)], e);
    00189
    00190     return ok;
    00191 }
    00192
    00207 bool QwtEventPattern::mouseMatch(const MousePattern &pattern,
    00208     const QMouseEvent *e) const
    00209 {
    00210     return (e->button() == pattern.button) &&
    00211         ((e->state() & Qt::KeyButtonMask) == (pattern.state & Qt::KeyButtonMask));
    00212 }
    00213
    00227 bool QwtEventPattern::keyMatch(uint pattern, const QKeyEvent *e) const
    00228 {
    00229     bool ok = FALSE;
    00230
    00231     if ( e && pattern < d_keyPattern.count() )
    00232         ok = keyMatch(d_keyPattern[int(pattern)], e);
    00233
    00234     return ok;
    00235 }
    00236
    00251 bool QwtEventPattern::keyMatch(
    00252     const KeyPattern &pattern, const QKeyEvent *e) const
    00253 {
    00254     return (e->key() == pattern.key) &&
    00255         ((e->state() & Qt::KeyButtonMask) == (pattern.state & Qt::KeyButtonMask));
    00256 }