Esempio n. 1
0
/**
 * Tablet events are handled here
 * @param event event info
 */
bool CanvasView::viewportEvent(QEvent *event)
{
	if(event->type() == QEvent::TabletMove) {
		// Stylus moved
		QTabletEvent *tabev = static_cast<QTabletEvent*>(event);
		tabev->accept();
		const dpcore::Point point(mapToScene(tabev->pos()), tabev->pressure());

		if(!_prevpoint.intSame(point)) {
			if(_isdragging)
				moveDrag(tabev->x(), tabev->y());
			else {
				if(_pendown) {
					if(point.pressure()==0) {
						// Missed a release event
						_pendown = NOTDOWN;
						onPenUp();
					} else {
						onPenMove(point);
					}
				}
				updateOutline(point);
			}
			_prevpoint = point;
		}
	} else if(event->type() == QEvent::TabletPress) {
		// Stylus touches the tablet surface
		QTabletEvent *tabev = static_cast<QTabletEvent*>(event);
		tabev->accept();
		if(_dragbtndown) {
			startDrag(tabev->x(), tabev->y(), _dragbtndown);
		} else {
			if(_pendown == NOTDOWN) {
				const dpcore::Point point(mapToScene(tabev->pos()), tabev->pressure());

				_pendown = TABLETDOWN;
				onPenDown(point, false);
				updateOutline(point);
				_prevpoint = point;
			}
		}
	} else if(event->type() == QEvent::TabletRelease) {
		// Stylus lifted
		QTabletEvent *tabev = static_cast<QTabletEvent*>(event);
		tabev->accept();
		if(_isdragging) {
			stopDrag();
		} else if(_pendown == TABLETDOWN) {
			dpcore::Point point(mapToScene(tabev->pos()), 0);
			updateOutline(point);
			_prevpoint = point;
			_pendown = NOTDOWN;
			onPenUp();
		}
	} else {
		return QGraphicsView::viewportEvent(event);
	}
	
	return true;
}
Esempio n. 2
0
/**
 * Tablet events are handled here
 * @param event event info
 */
bool EditorView::viewportEvent(QEvent *event)
{
    if(event->type() == QEvent::TabletMove) {
        // Stylus moved
        QTabletEvent *tabev = static_cast<QTabletEvent*>(event);
        tabev->accept();
        const dpcore::Point point(mapToScene(tabev->pos()), tabev->pressure());

        if(!prevpoint_.intSame(point)) {
            if(isdragging_)
                moveDrag(tabev->x(), tabev->y());
            else {
                if(pendown_) {
                    if(point.pressure()==0) {
                        // Missed a release event
                        pendown_ = NOTDOWN;
                        emit penUp();
                    } else {
                        emit penMove(point);
                    }
                }
                updateOutline(point);
            }
            prevpoint_ = point;
        }
    } else if(event->type() == QEvent::TabletPress) {
        // Stylus touches the tablet surface
        QTabletEvent *tabev = static_cast<QTabletEvent*>(event);
        tabev->accept();
        if(dragbtndown_) {
            startDrag(tabev->x(), tabev->y(), dragbtndown_);
        } else {
            if(pendown_ == NOTDOWN) {
                const dpcore::Point point(mapToScene(tabev->pos()), tabev->pressure());

                pendown_ = TABLETDOWN;
                emit penDown(point);
                updateOutline(point);
                prevpoint_ = point;
            }
        }
    } else if(event->type() == QEvent::TabletRelease) {
        // Stylus lifted
        QTabletEvent *tabev = static_cast<QTabletEvent*>(event);
        tabev->accept();
        if(isdragging_) {
            stopDrag();
        } else if(pendown_ == TABLETDOWN) {
            dpcore::Point point(mapToScene(tabev->pos()), 0);
            updateOutline(point);
            prevpoint_ = point;
            pendown_ = NOTDOWN;
            emit penUp();
        }
    } else {
        return QGraphicsView::viewportEvent(event);
    }

    return true;
}
Esempio n. 3
0
/**
 * Tablet events are handled here
 * @param event event info
 */
bool CanvasView::viewportEvent(QEvent *event)
{
	if(event->type() == QEvent::Gesture) {
		gestureEvent(static_cast<QGestureEvent*>(event));

	} else if(event->type() == QEvent::TabletMove && _enableTabletEvents) {
		// Stylus moved
		QTabletEvent *tabev = static_cast<QTabletEvent*>(event);
		tabev->accept();

		paintcore::Point point = mapToScene(tabev->posF(), tabev->pressure());
		updateOutline(point);

		if(!_prevpoint.intSame(point)) {
			if(_isdragging)
				moveDrag(tabev->x(), tabev->y());
			else {
				if(_pendown) {
					_pointervelocity = point.distance(_prevpoint);
					_pointerdistance += _pointervelocity;
					point.setPressure(mapPressure(point.pressure(), true));
					onPenMove(point, false, tabev->modifiers() & Qt::ShiftModifier, tabev->modifiers() & Qt::AltModifier);
				}
			}
			_prevpoint = point;
		}
	} else if(event->type() == QEvent::TabletPress && _enableTabletEvents) {
		// Stylus touches the tablet surface
		QTabletEvent *tabev = static_cast<QTabletEvent*>(event);
		tabev->accept();

		if(_dragbtndown) {
			startDrag(tabev->x(), tabev->y(), _dragbtndown);
		} else {
			if(_pendown == NOTDOWN) {
				_pointerdistance = 0;
				_pointervelocity = 0;

				const paintcore::Point point = mapToScene(tabev->posF(), mapPressure(tabev->pressure(), true));

				_specialpenmode = tabev->modifiers() & Qt::ControlModifier; /* note: modifiers doesn't seem to work, at least on Qt 5.2.0 */
				_pendown = TABLETDOWN;
				onPenDown(point, false);
				updateOutline(point);
				_prevpoint = point;

			}
		}
	} else if(event->type() == QEvent::TabletRelease && _enableTabletEvents) {
		// Stylus lifted
		// Ignore this event: a mouseRelease event is also generated, so we let
		// the mouseRleaseEvent function handle this.
	} else {
		return QGraphicsView::viewportEvent(event);
	}
	
	return true;
}
Esempio n. 4
0
bool KisToolProxy::forwardEvent(ActionState state, KisTool::ToolAction action, QEvent *event, QEvent *originalEvent, QTabletEvent *lastTabletEvent, const QPoint &canvasOriginWorkaround)
{
    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 = tabletToDocument(tabletEvent->hiResGlobalPos(), canvasOriginWorkaround);
        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->deviceType(), touchEvent->modifiers(), touchEvent->touchPointStates(), touchEvent->touchPoints());
            this->touchEvent(&fakeEvent);
        } else {
            this->touchEvent(touchEvent);
        }
    } else if (mouseEvent) {
        if (lastTabletEvent) {
            QPointF docPoint = tabletToDocument(lastTabletEvent->hiResGlobalPos(), canvasOriginWorkaround);
            lastTabletEvent->accept();
            this->tabletEvent(lastTabletEvent, docPoint);
            forwardToTool(state, action, lastTabletEvent, docPoint);
            retval = lastTabletEvent->isAccepted();
        } else {
            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;
}