Commit 6ec8d74f authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Use proper floating point positions for the mouse

This avoids lines being snapped to pixels which creates really bad
effects.
parent b1c8dd00
......@@ -116,9 +116,7 @@ bool KisInputManager::eventFilter(QObject* object, QEvent* event)
switch (event->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick: {
QMouseEvent *mevent = static_cast<QMouseEvent*>(event);
QPointF pixel = QPointF(mevent->pos().x() + 0.5f, mevent->pos().y() + 0.5f);
d->mousePosition = d->canvas->coordinatesConverter()->widgetToDocument(pixel);
d->mousePosition = widgetToPixel(static_cast<QMouseEvent*>(event)->posF());
//If the palette is visible, then hide it.
if (canvas()->favoriteResourceManager()->isPopupPaletteVisible()) {
......@@ -157,9 +155,8 @@ bool KisInputManager::eventFilter(QObject* object, QEvent* event)
case QEvent::MouseMove:
if (!d->currentAction) {
QMouseEvent *mevent = static_cast<QMouseEvent*>(event);
QPointF pixel = QPointF(mevent->pos().x() + 0.5f, mevent->pos().y() + 0.5f);
//Update the current tool so things like the brush outline gets updated.
d->toolProxy->mouseMoveEvent(mevent, d->canvas->coordinatesConverter()->widgetToDocument(pixel));
d->toolProxy->mouseMoveEvent(mevent, widgetToPixel(mevent->posF()));
} else {
d->currentAction->inputEvent(event);
}
......@@ -255,6 +252,12 @@ void KisInputManager::setMirrorAxis()
d->canvas->resourceManager()->setResource(KisCanvasResourceProvider::MirrorAxisCenter, d->canvas->image()->documentToPixel(d->mousePosition));
}
QPointF KisInputManager::widgetToPixel(const QPointF& position)
{
QPointF pixel = QPointF(position.x() + 0.5f, position.y() + 0.5f);
return d->canvas->coordinatesConverter()->widgetToDocument(pixel);
}
void KisInputManager::Private::match(QEvent* event)
{
//Go through all possible shortcuts and update their state.
......
......@@ -87,6 +87,11 @@ public:
*/
QTabletEvent *tabletPressEvent() const;
/**
* Convert a widget position to a pixel position.
*/
QPointF widgetToPixel(const QPointF &position);
private Q_SLOTS:
void setMirrorAxis();
......
......@@ -28,8 +28,23 @@
#include "kis_input_manager.h"
class KisToolInvocationAction::Private
{
public:
Private(KisToolInvocationAction *qq) : q(qq), useTablet(false) { }
QPointF tabletToPixel(const QPointF& globalPos);
KisToolInvocationAction *q;
bool useTablet;
QTabletEvent::TabletDevice tabletDevice;
QTabletEvent::PointerType pointerType;
int tabletZ;
qint64 tabletID;
};
KisToolInvocationAction::KisToolInvocationAction(KisInputManager *manager)
: KisAbstractInputAction(manager), m_tablet(false)
: KisAbstractInputAction(manager), d(new Private(this))
{
setName(i18n("Tool Invocation"));
setDescription(i18n("Tool Invocation invokes the current tool, for example, using the brush tool, it will start painting."));
......@@ -42,24 +57,28 @@ KisToolInvocationAction::~KisToolInvocationAction()
void KisToolInvocationAction::begin(int /*shortcut*/)
{
if(inputManager()->tabletPressEvent()) {
inputManager()->tabletPressEvent()->accept();
inputManager()->toolProxy()->tabletEvent(inputManager()->tabletPressEvent(), inputManager()->canvas()->coordinatesConverter()->widgetToDocument(inputManager()->tabletPressEvent()->pos()));
m_tablet = true;
QTabletEvent *pressEvent = inputManager()->tabletPressEvent();
inputManager()->toolProxy()->tabletEvent(pressEvent, d->tabletToPixel(pressEvent->hiResGlobalPos()));
d->useTablet = true;
d->pointerType = pressEvent->pointerType();
d->tabletDevice = pressEvent->device();
d->tabletZ = pressEvent->z();
d->tabletID = pressEvent->uniqueId();
} else {
QMouseEvent *pressEvent = new QMouseEvent(QEvent::MouseButtonPress, inputManager()->mousePosition().toPoint(), Qt::LeftButton, Qt::LeftButton, 0);
inputManager()->toolProxy()->mousePressEvent(pressEvent, pressEvent->pos());
inputManager()->toolProxy()->mousePressEvent(pressEvent, inputManager()->mousePosition());
}
}
void KisToolInvocationAction::end()
{
if(m_tablet) {
QTabletEvent* pressEvent = inputManager()->tabletPressEvent();
QTabletEvent *releaseEvent = new QTabletEvent(QEvent::TabletRelease, inputManager()->mousePosition().toPoint(), inputManager()->mousePosition().toPoint(), inputManager()->mousePosition(), pressEvent->device(), pressEvent->pointerType(), 0.f, 0, 0, 0.f, 0.f, pressEvent->z(), 0, pressEvent->uniqueId());
inputManager()->toolProxy()->tabletEvent(releaseEvent, releaseEvent->pos());
if(d->useTablet) {
QTabletEvent *releaseEvent = new QTabletEvent(QEvent::TabletRelease, inputManager()->mousePosition().toPoint(), inputManager()->mousePosition().toPoint(), inputManager()->mousePosition(), d->tabletDevice, d->pointerType, 0.f, 0, 0, 0.f, 0.f, d->tabletZ, 0, d->tabletID);
inputManager()->toolProxy()->tabletEvent(releaseEvent, inputManager()->mousePosition());
} else {
QMouseEvent *releaseEvent = new QMouseEvent(QEvent::MouseButtonRelease, inputManager()->mousePosition().toPoint(), Qt::LeftButton, Qt::LeftButton, 0);
inputManager()->toolProxy()->mouseReleaseEvent(releaseEvent, releaseEvent->pos());
inputManager()->toolProxy()->mouseReleaseEvent(releaseEvent, inputManager()->mousePosition());
}
}
......@@ -67,10 +86,10 @@ void KisToolInvocationAction::inputEvent(QEvent* event)
{
if(event->type() == QEvent::MouseMove) {
QMouseEvent* mevent = static_cast<QMouseEvent*>(event);
inputManager()->toolProxy()->mouseMoveEvent(mevent, inputManager()->canvas()->coordinatesConverter()->widgetToDocument(mevent->posF()));
inputManager()->toolProxy()->mouseMoveEvent(mevent, inputManager()->widgetToPixel(mevent->posF()));
} else if(event->type() == QEvent::TabletMove) {
QTabletEvent* tevent = static_cast<QTabletEvent*>(event);
inputManager()->toolProxy()->tabletEvent(tevent, inputManager()->canvas()->coordinatesConverter()->widgetToDocument(tevent->pos()));
inputManager()->toolProxy()->tabletEvent(tevent, d->tabletToPixel(tevent->hiResGlobalPos()));
}
}
......@@ -78,3 +97,9 @@ bool KisToolInvocationAction::handleTablet() const
{
return true;
}
QPointF KisToolInvocationAction::Private::tabletToPixel(const QPointF &globalPos)
{
const QPointF pos = globalPos - q->inputManager()->canvas()->canvasWidget()->mapToGlobal(QPoint(0, 0));
return q->inputManager()->widgetToPixel(pos);
}
......@@ -40,7 +40,8 @@ public:
virtual bool handleTablet() const;
private:
bool m_tablet;
class Private;
Private * const d;
};
#endif // KISTOOLINVOCATIONACTION_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment