File indexing completed on 2025-01-05 04:35:06

0001 /*
0002  * This file is part of the mouse gesture package.
0003  * Copyright (C) 2006 Johan Thelin <e8johan@gmail.com>
0004  * All rights reserved.
0005  *
0006  * Redistribution and use in source and binary forms, with or
0007  * without modification, are permitted provided that the
0008  * following conditions are met:
0009  *
0010  *   - Redistributions of source code must retain the above
0011  *     copyright notice, this list of conditions and the
0012  *     following disclaimer.
0013  *   - Redistributions in binary form must reproduce the
0014  *     above copyright notice, this list of conditions and
0015  *     the following disclaimer in the documentation and/or
0016  *     other materials provided with the distribution.
0017  *   - The names of its contributors may be used to endorse
0018  *     or promote products derived from this software without
0019  *     specific prior written permission.
0020  *
0021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
0022  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
0023  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
0024  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0025  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0026  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
0027  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
0028  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
0029  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
0030  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0031  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0032  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
0033  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  *
0036  */
0037 
0038 #ifndef QJTMOUSEGESTURE_H
0039 #define QJTMOUSEGESTURE_H
0040 
0041 #include <QObject>
0042 #include <QList>
0043 
0044 #include "mousegesturerecognizer.h"
0045 
0046 class GestureCallbackToSignal;
0047 
0048 /*
0049  *  A Direction can be any of the following:
0050  *
0051  *    Up
0052  *    Down
0053  *    Left
0054  *    Right
0055  *    AnyHorizontal (Left or Right)
0056  *    AnyVertical (Up or Down)
0057  *    UpLeft (diagnonal)
0058  *    UpRight (diagnonal)
0059  *    DownLeft (diagnonal)
0060  *    DownRight (diagnonal)
0061  *
0062  *  In addition to these, the NoMatch enum is
0063  *  available. A gesture holding only the NoMatch
0064  *  enum is gestured when no other gesture can be
0065  *  matched to the mouse gesture performed.
0066  */
0067 typedef Gesture::Direction Direction;
0068 
0069 using Gesture::Up;
0070 using Gesture::Down;
0071 using Gesture::Left;
0072 using Gesture::Right;
0073 using Gesture::AnyHorizontal;
0074 using Gesture::AnyVertical;
0075 using Gesture::UpLeft;
0076 using Gesture::UpRight;
0077 using Gesture::DownLeft;
0078 using Gesture::DownRight;
0079 using Gesture::NoMatch;
0080 
0081 /*
0082  *  A list of Directions
0083  */
0084 typedef QList<Direction> DirectionList;
0085 
0086 /*
0087  *  A mouse gesture is a list of Directions that
0088  *  trigger the gestured signal. Create instances
0089  *  and add to a QjtMouseGestureFilter object.
0090  */
0091 class QjtMouseGesture : public QObject
0092 {
0093     Q_OBJECT
0094 public:
0095     QjtMouseGesture(const DirectionList &directions, QObject* parent = nullptr);
0096     ~QjtMouseGesture();
0097 
0098     const DirectionList directions() const;
0099 
0100 Q_SIGNALS:
0101     void gestured();
0102 
0103 private:
0104     friend class GestureCallbackToSignal;
0105 
0106     /*
0107      *  Emits the gestured signal.
0108      *
0109      *  Required to connect this to the toolkit
0110      *  independent recognizer in a tidy way.
0111      */
0112     void emitGestured();
0113 
0114     DirectionList m_directions;
0115 };
0116 
0117 #endif // QJTMOUSEGESTURE_H