2 * Copyright (C) 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "PressedOutsideNotifier.h"
21PressedOutsideNotifier::PressedOutsideNotifier(QQuickItem *parent)
24 connect(this, &QQuickItem::enabledChanged,
25 this, &PressedOutsideNotifier::setupOrTearDownEventFiltering);
27 m_signalEmissionTimer.setSingleShot(true);
28 m_signalEmissionTimer.setInterval(0); // times out on the next iteration of the event loop
29 connect(&m_signalEmissionTimer, &QTimer::timeout,
30 this, &PressedOutsideNotifier::pressedOutside);
33bool PressedOutsideNotifier::eventFilter(QObject *watched, QEvent *event)
36 Q_ASSERT(watched == m_filteredWindow);
38 // We are already going to emit pressedOutside() anyway, thus no need
40 // This case takes place when a QTouchEvent comes in and isn't handled by any item,
41 // causing QQuickWindow to synthesize a QMouseEvent out of it, which would
42 // be filtered by us as well and count as a second press, which is wrong.
43 if (m_signalEmissionTimer.isActive()) {
47 switch (event->type()) {
48 case QEvent::MouseButtonPress: {
49 QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
50 QPointF p = mapFromScene(mouseEvent->windowPos());
52 m_signalEmissionTimer.start();
56 case QEvent::TouchBegin:
57 processFilteredTouchBegin(static_cast<QTouchEvent*>(event));
62 // let the event be handled further
66void PressedOutsideNotifier::itemChange(ItemChange change, const ItemChangeData &value)
68 if (change == QQuickItem::ItemSceneChange) {
69 setupOrTearDownEventFiltering();
72 QQuickItem::itemChange(change, value);
75void PressedOutsideNotifier::setupOrTearDownEventFiltering()
77 if (isEnabled() && window()) {
78 setupEventFiltering();
79 } else if (m_filteredWindow) {
80 tearDownEventFiltering();
84void PressedOutsideNotifier::setupEventFiltering()
86 QQuickWindow *currentWindow = window();
87 Q_ASSERT(currentWindow != nullptr);
89 if (currentWindow == m_filteredWindow)
92 if (m_filteredWindow) {
93 m_filteredWindow->removeEventFilter(this);
96 currentWindow->installEventFilter(this);
97 m_filteredWindow = currentWindow;
100void PressedOutsideNotifier::tearDownEventFiltering()
102 m_filteredWindow->removeEventFilter(this);
103 m_filteredWindow.clear();
106void PressedOutsideNotifier::processFilteredTouchBegin(QTouchEvent *event)
108 const QList<QTouchEvent::TouchPoint> &touchPoints = event->touchPoints();
109 for (int i = 0; i < touchPoints.count(); ++i) {
110 const QTouchEvent::TouchPoint &touchPoint = touchPoints.at(i);
111 if (touchPoint.state() == Qt::TouchPointPressed) {
112 QPointF p = mapFromScene(touchPoint.pos());
114 m_signalEmissionTimer.start();
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list