/** * 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; }
//! 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 press events void CanvasView::mousePressEvent(QMouseEvent *event) { /** @todo why do we sometimes get mouse events for tablet strokes? */ if(_pendown != NOTDOWN) return; if(event->button() == Qt::MidButton || _dragbtndown) { ViewTransform mode; if(_dragbtndown == DRAG_NOTRANSFORM) { if((event->modifiers() & Qt::ControlModifier)) mode = DRAG_ZOOM; else if((event->modifiers() & Qt::ShiftModifier)) mode = DRAG_QUICKADJUST1; else mode = DRAG_TRANSLATE; } else mode = _dragbtndown; startDrag(event->x(), event->y(), mode); } else if((event->button() == Qt::LeftButton || event->button() == Qt::RightButton) && _isdragging==DRAG_NOTRANSFORM) { _pendown = MOUSEDOWN; _pointerdistance = 0; _pointervelocity = 0; _specialpenmode = event->modifiers() & Qt::ControlModifier; onPenDown(mapToScene(event->pos(), mapPressure(1.0, false)), event->button() == Qt::RightButton); } }
void Draw::mouseMoveEvent( QMouseEvent *e ) { // printf("called mouse Move %d %d %d\n",_time.restart(), e->x(), e->y()); // draw if ((_tool==D_DRAW || _tool==D_OVERDRAW || _tool==D_PAINT) && _mousePressed && _currDPath) { Vec2f newLoc = unproject(e->x(), e->y(), _h); //printf("%f %f\n",newLoc.x(), newLoc.y()); if (_currDPath->getNumElements()==0 || _currDPath->distToLast2(newLoc) > 0) _currDPath->addVertex(newLoc.x(),newLoc.y(), mapPressure()); QPoint curs = _parent->mapFromGlobal(QCursor::pos()); if ((e->x() - curs.x())*(e->x() - curs.x()) + (e->y() - curs.y())*(e->y() - curs.y()) < 25) _parent->updateGL(); } else if (_tool == D_SELECT && _mousePressed && _selected) { Vec2f newLoc = unproject(e->x(), e->y(), _h); Vec2f delta(newLoc, _dragLoc); _selected->translate(delta); _dragLoc = newLoc; _dragDirty = true; _parent->updateGL(); } else if (_spliceIndex>0 && _selected && _tool==D_NUDGE) { // nudge Vec2f newLoc = unproject(e->x(), e->y(), _h); _selected->nudge(_spliceIndex, newLoc); } }
void Draw::makeDrawPath(const RotoPath* rp) { DrawPath* newp = new DrawPath(); newp->setColor(_currColor); newp->initHertzStroke(); for (int i=0; i<rp->getNumElements(); ++i) newp->addVertex(rp->getElement(i).x(), rp->getElement(i).y(), mapPressure()); _dc->addPath(newp); newp->freshenAppearance(); }
void Draw::mouseReleaseEvent( QMouseEvent *e ) { // printf("mouse release event %d\n", e->button()); // draw _mousePressed = 0; if (_tool == D_DRAW && _currDPath) { // draw //_pressure = 2.*_sens; if (_currDPath->getNumElements() > 1) { _parent->setCursor(Qt::WaitCursor); Vec2f loc = unproject(e->x(), e->y(), _h); _currDPath->addVertex(loc.x(), loc.y(), mapPressure()); _dc->addPath(_currDPath); //for (int i=0; i<2; i++) //_currDPath->fair(); _currDPath->resample(NULL); _currDPath->redoStroke(); bool res=false; if (!_freeDraw) res = _currDPath->correspondRoto2(_is->getRotoCurves(_frame), _w, _h); _currDPath->calculateStrokeDisplayList(); if (res) { _corrShow = 1; propagatePathEverywhere(_currDPath); } else _currDPath = NULL; emit restoreCursor(); } else { delete _currDPath; _currDPath = NULL; } } /* else if (_tool == D_PAINT && _currDPath) { // paint Bboxf2D bbox = _currDPath->calcBbox(); DrawPatch *dch = new DrawPatch((int)floor(bbox.lower.x()),(int)floor(bbox.lower.y()), (int)ceil(bbox.width()), (int)ceil(bbox.height()), _currColor); dch->takeStroke(_currDPath->giveStroke()); _currDPath->forgetStroke(); _dc->addPatch(dch); //printf("patch corner: %f %f, window: %f %f\n",dch->x(), dch->y(), // bbox.width(), bbox.height()); delete _currDPath; _currDPath = NULL; if (_propPatch && _propMode==1) keyframeInterpolatePatch(dch); } */ else if (_tool == D_SELECT) { // select if (_selected && _dragDirty) { regeneratePath(_selected); _selected->fixLoc(); _dragDirty = false; } } else if (_tool == D_OVERDRAW && _currDPath) {// overdraw if (_currDPath->getNumElements() > 1) { _currDPath->resample(NULL); spliceDrawCurve(); } else { delete _currDPath; _currDPath=NULL; _spliceFlag=-1; } } else if (_tool==D_DROPPER) { _captureColor = true; _captureColorLoc.Set(e->x(), _h-e->y()); _parent->updateGL(); _captureColor = false; } else if (_tool==D_NUDGE) { // nudge _spliceIndex=-1; } //_minimalRenderMode = 0; _parent->updateGL(); }