コード例 #1
0
ファイル: PhotoKitView.cpp プロジェクト: BIbiLion/PhotoKit
bool PhotoKitView::viewportEvent(QEvent *event)
{
	switch (event->type()) {
	case QEvent::TouchBegin:
	case QEvent::TouchUpdate:
	case QEvent::TouchEnd:
	{
		//only do these in picture wall mode
		QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
		QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
		if (touchPoints.count() == 2) {//TODO: next/pre in PlayPage
			// determine scale factor
			const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
			const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
			qreal currentScaleFactor =
					QLineF(touchPoint0.pos(), touchPoint1.pos()).length()
					/ QLineF(touchPoint0.startPos(), touchPoint1.startPos()).length();
			if (touchEvent->touchPointStates() & Qt::TouchPointMoved
					|| touchEvent->touchPointStates() & Qt::TouchPointReleased) {
				BaseItem* item = UiManager::instance()->currentPageRootItem();
				if (UiManager::page == UiManager::ThumbPage
						|| UiManager::page == UiManager::SearchPage) {
					qreal scale0 = item->mScale;
                    if (currentScaleFactor > 1) {
						item->mScale += 0.12;
						item->mScale = qMin(kScaleMax, item->mScale);
                    } else {
						item->mScale -= 0.12;
						item->mScale = qMax(kScaleMin, item->mScale);
                    }
					setAnimationDuration(kAniDuration);
					smartTransform(item->mX, item->mY, scale0, item->mScale, 0, 0, 0, 0, 0); //both thumbpage and playpage works
                } else if (UiManager::page == UiManager::PlayPage) {
					//qreal s0 = item->transform().m11();
					qreal s = currentScaleFactor > 1 ? 1.1:0.9; //TODO: smooth and slow
                    QRectF r = item->boundingRect();
					//TODO: why translate?
                    item->setTransform(QTransform().translate(r.width()/2, r.height()/2)
                                       .scale(s, s).translate(-r.width()/2, -r.height()/2), true);
                }
            }
		}
		return true;
	}
	default:
		break;
    }
	return QGraphicsView::viewportEvent(event);
}
コード例 #2
0
ファイル: graphicsview.cpp プロジェクト: Andreas665/qt
bool GraphicsView::viewportEvent(QEvent *event)
{
    switch (event->type()) {
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
    {
        QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
        QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
        if (touchPoints.count() == 2) {
            // determine scale factor
            const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
            const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
            qreal currentScaleFactor =
                    QLineF(touchPoint0.pos(), touchPoint1.pos()).length()
                    / QLineF(touchPoint0.startPos(), touchPoint1.startPos()).length();
            if (touchEvent->touchPointStates() & Qt::TouchPointReleased) {
                // if one of the fingers is released, remember the current scale
                // factor so that adding another finger later will continue zooming
                // by adding new scale factor to the existing remembered value.
                totalScaleFactor *= currentScaleFactor;
                currentScaleFactor = 1;
            }
            setTransform(QTransform().scale(totalScaleFactor * currentScaleFactor,
                                            totalScaleFactor * currentScaleFactor));
        }
        return true;
    }
    default:
        break;
    }
    return QGraphicsView::viewportEvent(event);
}
コード例 #3
0
bool LipstickCompositorWindow::eventFilter(QObject *obj, QEvent *event)
{
#if QT_VERSION >= 0x050202
    if (obj == window() && m_interceptingTouch) {
        switch (event->type()) {
        case QEvent::TouchUpdate: {
            QTouchEvent *te = static_cast<QTouchEvent *>(event);
            // If we get press/release, don't intercept the event, but send it through QQuickWindow.
            // These are sent through to QQuickWindow so that the integrity of the touch
            // handling is maintained.
            if (te->touchPointStates() & (Qt::TouchPointPressed | Qt::TouchPointReleased))
                return false;
            handleTouchEvent(static_cast<QTouchEvent *>(event));
            return true;
        }
        case QEvent::TouchEnd: // Intentional fall through...
        case QEvent::TouchCancel:
            obj->removeEventFilter(this);
            m_interceptingTouch = false;
        default:
            break;
        }
        return false;
    }
#else
    Q_UNUSED(obj);
#endif
    if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
        QKeyEvent *ke = static_cast<QKeyEvent *>(event);
        QWaylandSurface *m_surface = surface();
        if (m_surface && (m_grabbedKeys.contains(ke->key()) || m_pressedGrabbedKeys.keys.contains(ke->key())) && !ke->isAutoRepeat()) {
            QWaylandInputDevice *inputDevice = m_surface->compositor()->defaultInputDevice();
            if (event->type() == QEvent::KeyPress) {
                if (m_pressedGrabbedKeys.keys.isEmpty()) {
                    QWaylandSurface *old = inputDevice->keyboardFocus();
                    m_pressedGrabbedKeys.oldFocus = old;
                    inputDevice->setKeyboardFocus(m_surface);
                }
                m_pressedGrabbedKeys.keys << ke->key();
            }
            inputDevice->sendFullKeyEvent(ke);
            if (event->type() == QEvent::KeyRelease) {
                m_pressedGrabbedKeys.keys.removeOne(ke->key());
                if (m_pressedGrabbedKeys.keys.isEmpty()) {
                    inputDevice->setKeyboardFocus(m_pressedGrabbedKeys.oldFocus);
                    if (m_grabbedKeys.isEmpty())
                        qApp->removeEventFilter(this);
                }
            }
            return true;
        }
    }
    return false;
}
コード例 #4
0
ファイル: kis_tool_proxy.cpp プロジェクト: ChrisJong/krita
bool KisToolProxy::forwardEvent(ActionState state, KisTool::ToolAction action, QEvent *event, QEvent *originalEvent)
{
    bool retval = true;

    QTabletEvent *tabletEvent = dynamic_cast<QTabletEvent*>(event);
    QTouchEvent *touchEvent = dynamic_cast<QTouchEvent*>(event);
    QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);

    if (tabletEvent) {
        QPointF docPoint = widgetToDocument(tabletEvent->posF());
        tabletEvent->accept();
        this->tabletEvent(tabletEvent, docPoint);
        forwardToTool(state, action, tabletEvent, docPoint);
        retval = tabletEvent->isAccepted();
    } else if (touchEvent) {
        if (state == END && touchEvent->type() != QEvent::TouchEnd) {
            //Fake a touch end if we are "upgrading" a single-touch gesture to a multi-touch gesture.
            QTouchEvent fakeEvent(QEvent::TouchEnd, touchEvent->device(),
                                  touchEvent->modifiers(), touchEvent->touchPointStates(),
                                  touchEvent->touchPoints());
            this->touchEvent(&fakeEvent);
        } else {
            this->touchEvent(touchEvent);
        }
    } else if (mouseEvent) {
        QPointF docPoint = widgetToDocument(mouseEvent->posF());
        mouseEvent->accept();
        if (mouseEvent->type() == QEvent::MouseButtonPress) {
            mousePressEvent(mouseEvent, docPoint);
        } else if (mouseEvent->type() == QEvent::MouseButtonDblClick) {
            mouseDoubleClickEvent(mouseEvent, docPoint);
        } else if (mouseEvent->type() == QEvent::MouseButtonRelease) {
            mouseReleaseEvent(mouseEvent, docPoint);
        } else if (mouseEvent->type() == QEvent::MouseMove) {
            mouseMoveEvent(mouseEvent, docPoint);
        }
        forwardToTool(state, action, originalEvent, docPoint);
        retval = mouseEvent->isAccepted();
    } else if(event->type() == QEvent::KeyPress) {
        QKeyEvent* kevent = static_cast<QKeyEvent*>(event);
        keyPressEvent(kevent);
    } else if(event->type() == QEvent::KeyRelease) {
        QKeyEvent* kevent = static_cast<QKeyEvent*>(event);
        keyReleaseEvent(kevent);
    }

    return retval;
}