Example #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;
}
Example #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;
}
Example #3
0
void StrokePreview::preview(const dpcore::Point& from, const dpcore::Point& to, const dpcore::Brush& brush)
{
	Preview::preview(from, to, brush);

	setLine(from.x(), from.y(), to.x(), to.y());
	show();
}
Example #4
0
void CanvasView::updateOutline(const dpcore::Point& point) {
	if(_enableoutline && _showoutline && !_locked) {
		QList<QRectF> rect;
		rect.append(QRectF(_prevpoint.x() - _outlinesize,
					_prevpoint.y() - _outlinesize, _dia, _dia));
		rect.append(QRectF(point.x() - _outlinesize,
					point.y() - _outlinesize, _dia, _dia));
		updateScene(rect);
	}
}
Example #5
0
/**
 * Convert a dpcore::Point to network format. The
 * reverse operation for this is in statetracker.cpp
 * @param p
 * @return
 */
protocol::PenPoint pointToProtocol(const dpcore::Point &p)
{
	// The two least significant bits of the coordinate
	// are the fractional part.
	// The rest is the integer part with a bias of 128
	uint16_t x = (qMax(0, p.x() + 128) << 2) | (uint16_t(p.xFrac()*4) & 3);
	uint16_t y = (qMax(0, p.y() + 128) << 2) | (uint16_t(p.yFrac()*4) & 3);

	return protocol::PenPoint(x, y, p.pressure() * 255);
}
Example #6
0
void EditorView::updateOutline(const dpcore::Point& point) {
    if(enableoutline_ && showoutline_) {
        QList<QRectF> rect;
        rect.append(QRectF(prevpoint_.x() - outlinesize_,
                           prevpoint_.y() - outlinesize_, dia_, dia_));
        rect.append(QRectF(point.x() - outlinesize_,
                           point.y() - outlinesize_, dia_, dia_));
        updateScene(rect);
    }
}
Example #7
0
/**
 * @param point stroke coordinates to send
 */
void SessionState::sendStrokePoint(const dpcore::Point& point)
{
    host_->sendPacket(protocol::StrokePoint(
                          host_->localuser_,
                          point.x(),
                          point.y(),
                          point.xFrac(),
                          point.yFrac(),
                          qRound(point.pressure()*255)
                      )
                     );
}
Example #8
0
/**
 * @param from point from which the line begins
 * @param to point at which the line ends
 * @param brush brush to draw the line with
 */
void Preview::preview(const dpcore::Point& from, const dpcore::Point& to, const dpcore::Brush& brush)
{
	brush_ = brush;
	from_ = from;
	to_ = to;
	const int rad = brush.radius(to.pressure());
	QColor color = brush.color(to.pressure());
	QPen pen;
	if(rad==0) {
		pen.setWidth(1);
		color.setAlphaF(brush.opacity(to.pressure()));
	} else {
		pen.setWidth(rad*2);
		pen.setCapStyle(Qt::RoundCap);
		pen.setJoinStyle(Qt::RoundJoin);
		// Approximate brush transparency
		const qreal a = brush.opacity(to.pressure()) * rad * (1-brush.spacing()/100.0);
		color.setAlphaF(qMin(a, 1.0));
	}
	pen.setColor(color);
	initAppearance(pen);
}
Example #9
0
void RectanglePreview::moveTo(const dpcore::Point& to)
{
	Preview::moveTo(to);
	qreal x,w;
	if(from().x() < to.x()) {
		x = from().x();
		w = to.x() - from().x();
	} else {
		x = to.x();
		w = from().x() - to.x();
	}
	qreal y,h;
	if(from().y() < to.y()) {
		y = from().y();
		h = to.y() - from().y();
	} else {
		y = to.y();
		h = from().y() - to.y();
	}
	setRect(x,y,w,h);
}
Example #10
0
void StrokePreview::moveTo(const dpcore::Point& to)
{
	Preview::moveTo(to);
	setLine(from().x(), from().y(), to.x(), to.y());
}
Example #11
0
void RectanglePreview::preview(const dpcore::Point& from, const dpcore::Point& to, const dpcore::Brush& brush)
{
	Preview::preview(from, to, brush);

	qreal x,w;
	if(from.x() < to.x()) {
		x = from.x();
		w = to.x() - from.x();
	} else {
		x = to.x();
		w = from.x() - to.x();
	}
	qreal y,h;
	if(from.y() < to.y()) {
		y = from.y();
		h = to.y() - from.y();
	} else {
		y = to.y();
		h = from.y() - to.y();
	}
	setRect(x,y,w,h);
	show();
}