/** * 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; }
/** * 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; }
/** * 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; }
void Shape::update() { // Get the total number of points of the shape std::size_t count = getPointCount(); if (count < 3) { m_vertices.resize(0); m_outlineVertices.resize(0); return; } m_vertices.resize(count + 2); // + 2 for center and repeated first point // Position for (std::size_t i = 0; i < count; ++i) m_vertices[i + 1].position = getPoint(i); m_vertices[count + 1].position = m_vertices[1].position; // Update the bounding rectangle m_vertices[0] = m_vertices[1]; // so that the result of getBounds() is correct m_insideBounds = m_vertices.getBounds(); // Compute the center and make it the first vertex m_vertices[0].position.x = m_insideBounds.left + m_insideBounds.width / 2; m_vertices[0].position.y = m_insideBounds.top + m_insideBounds.height / 2; // Color updateFillColors(); // Texture coordinates updateTexCoords(); // Outline updateOutline(); }
//! Handle mouse motion events void CanvasView::mouseMoveEvent(QMouseEvent *event) { /** @todo why do we sometimes get mouse events for tablet strokes? */ if(_pendown == TABLETDOWN) return; if(_pendown && event->buttons() == Qt::NoButton) { // In case we missed a mouse release mouseReleaseEvent(event); return; } if(_isdragging) { moveDrag(event->x(), event->y()); } else { paintcore::Point point = mapToScene(event->pos(), 1); updateOutline(point); if(!_prevpoint.intSame(point)) { if(_pendown) { _pointervelocity = point.distance(_prevpoint); _pointerdistance += _pointervelocity; point.setPressure(mapPressure(1.0, false)); onPenMove(point, event->buttons() & Qt::RightButton, event->modifiers() & Qt::ShiftModifier, event->modifiers() & Qt::AltModifier); } else if(_pointertracking && _scene->hasImage()) { emit pointerMoved(point); } _prevpoint = point; } } }
//! Handle mouse motion events void EditorView::mouseMoveEvent(QMouseEvent *event) { /** @todo why do we sometimes get mouse events for tablet strokes? */ if(pendown_ == TABLETDOWN) return; if(pendown_ && event->buttons() == Qt::NoButton) { // In case we missed a mouse release mouseReleaseEvent(event); return; } if(isdragging_) { moveDrag(event->x(), event->y()); } else { ; const dpcore::Point point(mapToScene(event->pos()), 1.0); if(!prevpoint_.intSame(point)) { if(pendown_) emit penMove(point); else updateOutline(point); prevpoint_ = point; } } }
void Brush::RenderPoint(Renderer * ren, ui::Point position) { if(!outline) updateOutline(); if(!outline) return; ren->xor_bitmap(outline, position.X-radius.X, position.Y-radius.Y, size.X, size.Y); }
void CanvasView::leaveEvent(QEvent *event) { QGraphicsView::leaveEvent(event); if(_enableoutline) { _showoutline = false; updateOutline(); } }
/** * @param x initial x coordinate * @param y initial y coordinate * @param mode dragging mode */ void CanvasView::startDrag(int x,int y, ViewTransform mode) { viewport()->setCursor(Qt::ClosedHandCursor); _dragx = x; _dragy = y; _isdragging = mode; if(_enableoutline) { _showoutline = false; updateOutline(); } }
//! Handle mouse motion events void CanvasView::mouseMoveEvent(QMouseEvent *event) { /** @todo why do we sometimes get mouse events for tablet strokes? */ if(_pendown == TABLETDOWN) return; if(_pendown && event->buttons() == Qt::NoButton) { // In case we missed a mouse release mouseReleaseEvent(event); return; } if(_isdragging) { moveDrag(event->x(), event->y()); } else { const dpcore::Point point(mapToScene(event->pos()), 1.0); if(!_prevpoint.intSame(point)) { if(_pendown) onPenMove(point); updateOutline(point); _prevpoint = point; } } }