Commit 26e76078 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Compress mouse events as well

It really needs testing!
parent 44306bff
......@@ -210,6 +210,49 @@ bool KisInputManager::eventFilter(QObject* object, QEvent* event)
return eventFilterImpl(event);
}
template <class Event>
bool KisInputManager::compressMoveEventCommon(Event *event)
{
/**
* We construct a copy of this event object, so we must ensure it
* has a correct type.
*/
static_assert(std::is_same<Event, QMouseEvent>::value ||
std::is_same<Event, QTabletEvent>::value,
"event should a mouse or a tablet event");
bool retval = false;
/**
* Compress the events if the tool doesn't need high resolution input
*/
if ((event->type() == QEvent::MouseMove ||
event->type() == QEvent::TabletMove) &&
(!d->matcher.supportsHiResInputEvents() ||
d->testingCompressBrushEvents)) {
d->compressedMoveEvent.reset(new Event(*event));
d->moveEventCompressor.start();
/**
* On Linux Qt eats the rest of unneeded events if we
* ignore the first of the chunk of tablet events. So
* generally we should never activate this feature. Only
* for testing purposes!
*/
if (d->testingAcceptCompressedTabletEvents) {
event->setAccepted(true);
}
retval = true;
} else {
slotCompressedMoveEvent();
retval = d->handleCompressedTabletEvent(event);
}
return retval;
}
bool KisInputManager::eventFilterImpl(QEvent * event)
{
// TODO: Handle touch events correctly.
......@@ -281,12 +324,9 @@ bool KisInputManager::eventFilterImpl(QEvent * event)
d->debugEvent<QMouseEvent, true>(event);
break_if_should_ignore_cursor_events();
if (!d->matcher.pointerMoved(event)) {
//Update the current tool so things like the brush outline gets updated.
d->toolProxy->forwardHoverEvent(event);
}
retval = true;
event->setAccepted(retval);
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
retval = compressMoveEventCommon(mouseEvent);
break;
}
case QEvent::Wheel: {
......@@ -376,33 +416,9 @@ bool KisInputManager::eventFilterImpl(QEvent * event)
case QEvent::TabletMove: {
d->debugEvent<QTabletEvent, false>(event);
QTabletEvent *tabletEvent = static_cast<QTabletEvent*>(event);
/**
* Compress the events if the tool doesn't need high resolution input
*/
if (tabletEvent->type() == QEvent::TabletMove &&
(!d->matcher.supportsHiResInputEvents() ||
d->testingCompressBrushEvents)) {
d->compressedMoveEvent.reset(new QTabletEvent(*tabletEvent));
d->moveEventCompressor.start();
/**
* On Linux Qt eats the rest of unneeded events if we
* ignore the first of the chunk of tablet events. So
* generally we should never activate this feature. Only
* for testing purposes!
*/
if (d->testingAcceptCompressedTabletEvents) {
tabletEvent->setAccepted(true);
}
retval = true;
} else {
slotCompressedMoveEvent();
retval = d->handleCompressedTabletEvent(tabletEvent);
}
QTabletEvent *tabletEvent = static_cast<QTabletEvent*>(event);
retval = compressMoveEventCommon(tabletEvent);
/**
* The flow of tablet events means the tablet is in the
......
......@@ -115,6 +115,10 @@ private Q_SLOTS:
void profileChanged();
void slotCompressedMoveEvent();
private:
template <class Event>
bool compressMoveEventCommon(Event *event);
private:
class Private;
Private* const d;
......
......@@ -426,15 +426,15 @@ void KisInputManager::Private::eatOneMousePress()
eventEater.eatOneMousePress();
}
bool KisInputManager::Private::handleCompressedTabletEvent(QTabletEvent *tevent)
bool KisInputManager::Private::handleCompressedTabletEvent(QEvent *event)
{
bool retval = false;
if (!matcher.pointerMoved(tevent)) {
toolProxy->forwardHoverEvent(tevent);
if (!matcher.pointerMoved(event)) {
toolProxy->forwardHoverEvent(event);
}
retval = true;
tevent->setAccepted(true);
event->setAccepted(true);
return retval;
}
......@@ -47,7 +47,7 @@ public:
bool processUnhandledEvent(QEvent *event);
void setupActions();
void saveTouchEvent( QTouchEvent* event );
bool handleCompressedTabletEvent(QTabletEvent *tevent);
bool handleCompressedTabletEvent(QEvent *event);
KisInputManager *q;
......@@ -67,7 +67,7 @@ public:
QObject *eventsReceiver = 0;
KisSignalCompressor moveEventCompressor;
QScopedPointer<QTabletEvent> compressedMoveEvent;
QScopedPointer<QEvent> compressedMoveEvent;
bool testingAcceptCompressedTabletEvents = false;
bool testingCompressBrushEvents = false;
......
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