|
| 1 | +/******************************************************************************\ |
| 2 | + * Copyright (c) 2023 |
| 3 | + * |
| 4 | + * Author(s): |
| 5 | + * Peter L Jones |
| 6 | + * |
| 7 | + ****************************************************************************** |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or modify it under |
| 10 | + * the terms of the GNU General Public License as published by the Free Software |
| 11 | + * Foundation; either version 2 of the License, or (at your option) any later |
| 12 | + * version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 16 | + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 17 | + * details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License along with |
| 20 | + * this program; if not, write to the Free Software Foundation, Inc., |
| 21 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 22 | + * |
| 23 | +\******************************************************************************/ |
| 24 | +#pragma once |
| 25 | + |
| 26 | +#include <QGesture> |
| 27 | +#include <QPanGesture> |
| 28 | +#include <QPinchGesture> |
| 29 | +#include <QSwipeGesture> |
| 30 | +#include <QTapAndHoldGesture> |
| 31 | +#include <QTapGesture> |
| 32 | + |
| 33 | +#include <QWidget> |
| 34 | +#include <QGroupBox> |
| 35 | +#include <QMessageBox> |
| 36 | + |
| 37 | +class CGGroupBox : public QGroupBox |
| 38 | +{ |
| 39 | + |
| 40 | + Q_OBJECT |
| 41 | + |
| 42 | +public: |
| 43 | + CGGroupBox ( QWidget* parent = nullptr ) : QGroupBox ( parent ) |
| 44 | + { |
| 45 | + grabGesture ( Qt::PanGesture ); |
| 46 | + grabGesture ( Qt::PinchGesture ); |
| 47 | + grabGesture ( Qt::SwipeGesture ); |
| 48 | + grabGesture ( Qt::TapAndHoldGesture ); |
| 49 | + grabGesture ( Qt::TapGesture ); |
| 50 | + grabGesture ( Qt::CustomGesture ); |
| 51 | + } |
| 52 | + |
| 53 | + bool event ( QEvent* event ) |
| 54 | + { |
| 55 | + if ( event->type() != QEvent::Gesture ) |
| 56 | + { |
| 57 | + return QGroupBox::event ( event ); |
| 58 | + } |
| 59 | + |
| 60 | +QMessageBox::information(this, "Jamulus", "CGGroupBox gesture detected"); |
| 61 | + |
| 62 | + QGestureEvent* gestureEvent = static_cast<QGestureEvent*> ( event ); |
| 63 | + QGesture* gesture = nullptr; |
| 64 | + |
| 65 | + if ( !event->isAccepted() && ( gesture = gestureEvent->gesture ( Qt::PanGesture ) ) != nullptr ) |
| 66 | + { |
| 67 | + emit panGestureSignal ( gestureEvent, static_cast<QPanGesture*> ( gesture ) ); |
| 68 | + } |
| 69 | + if ( !event->isAccepted() && ( gesture = gestureEvent->gesture ( Qt::PinchGesture ) ) != nullptr ) |
| 70 | + { |
| 71 | + emit pinchGestureSignal ( gestureEvent, static_cast<QPinchGesture*> ( gesture ) ); |
| 72 | + } |
| 73 | + if ( !event->isAccepted() && ( gesture = gestureEvent->gesture ( Qt::SwipeGesture ) ) != nullptr ) |
| 74 | + { |
| 75 | + emit swipeGestureSignal ( gestureEvent, static_cast<QSwipeGesture*> ( gesture ) ); |
| 76 | + } |
| 77 | + if ( !event->isAccepted() && ( gesture = gestureEvent->gesture ( Qt::TapAndHoldGesture ) ) != nullptr ) |
| 78 | + { |
| 79 | + emit tapAndHoldGestureSignal ( gestureEvent, static_cast<QTapAndHoldGesture*> ( gesture ) ); |
| 80 | + } |
| 81 | + if ( !event->isAccepted() && ( gesture = gestureEvent->gesture ( Qt::TapGesture ) ) != nullptr ) |
| 82 | + { |
| 83 | + emit tapGestureSignal ( gestureEvent, static_cast<QTapGesture*> ( gesture ) ); |
| 84 | + } |
| 85 | + if ( !event->isAccepted() && ( gesture = gestureEvent->gesture ( Qt::CustomGesture ) ) != nullptr ) |
| 86 | + { |
| 87 | + emit customGestureSignal ( gestureEvent, gesture ); |
| 88 | + } |
| 89 | + |
| 90 | + return event->isAccepted() ? true : QGroupBox::event ( event ); |
| 91 | + } |
| 92 | + |
| 93 | +signals: |
| 94 | + void panGestureSignal ( QGestureEvent* gestureEvent, QPanGesture* gesture ); |
| 95 | + void pinchGestureSignal ( QGestureEvent* gestureEvent, QPinchGesture* gesture ); |
| 96 | + void swipeGestureSignal ( QGestureEvent* gestureEvent, QSwipeGesture* gesture ); |
| 97 | + void tapAndHoldGestureSignal ( QGestureEvent* gestureEvent, QTapAndHoldGesture* gesture ); |
| 98 | + void tapGestureSignal ( QGestureEvent* gestureEvent, QTapGesture* gesture ); |
| 99 | + void customGestureSignal ( QGestureEvent* gestureEvent, QGesture* gesture ); |
| 100 | +}; |
0 commit comments