Commit 0498dfe5 authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Add support for auto-repeating key shortcuts.

parent 3f8c4e77
......@@ -80,3 +80,8 @@ void KisAbstractInputAction::setShortcutIndexes(const QHash< QString, int >& ind
{
d->indexes = indexes;
}
bool KisAbstractInputAction::isBlockingAutoRepeat() const
{
return false;
}
......@@ -85,6 +85,11 @@ public:
*/
virtual QString description() const;
/**
* Does this action block auto repeat events?
*/
virtual bool isBlockingAutoRepeat() const;
protected:
/**
* The input manager this action belongs to.
......
......@@ -57,3 +57,8 @@ void KisAlternateInvocationAction::inputEvent(QEvent* event)
inputManager()->toolProxy()->mouseMoveEvent(mevent, mevent->posF());
}
}
bool KisAlternateInvocationAction::isBlockingAutoRepeat() const
{
return true;
}
......@@ -37,6 +37,8 @@ public:
virtual void begin(int /*shortcut*/);
virtual void end();
virtual void inputEvent(QEvent* event);
virtual bool isBlockingAutoRepeat() const;
};
#endif // KIS_ALTERNATE_INVOCATION_ACTION_H
......@@ -54,3 +54,8 @@ void KisChangePrimarySettingAction::inputEvent(QEvent* event)
inputManager()->toolProxy()->mouseMoveEvent(mevent, mevent->posF());
}
}
bool KisChangePrimarySettingAction::isBlockingAutoRepeat() const
{
return true;
}
......@@ -36,6 +36,8 @@ public:
virtual void begin(int shortcut);
virtual void end();
virtual void inputEvent(QEvent* event);
virtual bool isBlockingAutoRepeat() const;
};
#endif // KISCHANGEPRIMARYSETTINGACTION_H
......@@ -33,10 +33,12 @@
class KisPanAction::Private
{
public:
Private() : panDistance(10) { }
Private() : active(false), panDistance(10) { }
QPointF lastMousePosition;
const int panDistance;
bool active;
};
KisPanAction::KisPanAction(KisInputManager *manager)
......@@ -63,6 +65,7 @@ void KisPanAction::begin(int shortcut)
case PanToggleShortcut:
d->lastMousePosition = inputManager()->canvas()->coordinatesConverter()->documentToWidget(inputManager()->mousePosition());
QApplication::setOverrideCursor(Qt::OpenHandCursor);
d->active = true;
break;
case PanLeftShortcut:
inputManager()->canvas()->canvasController()->pan(QPoint(d->panDistance, 0));
......@@ -81,6 +84,7 @@ void KisPanAction::begin(int shortcut)
void KisPanAction::end()
{
d->active = false;
QApplication::restoreOverrideCursor();
}
......@@ -93,7 +97,7 @@ void KisPanAction::inputEvent(QEvent *event)
}
case QEvent::MouseMove: {
QMouseEvent *mevent = static_cast<QMouseEvent*>(event);
if(mevent->buttons()) {
if (mevent->buttons()) {
QPointF relMovement = -(mevent->posF() - d->lastMousePosition);
inputManager()->canvas()->canvasController()->pan(relMovement.toPoint());
d->lastMousePosition = mevent->posF();
......@@ -107,3 +111,8 @@ void KisPanAction::inputEvent(QEvent *event)
break;
}
}
bool KisPanAction::isBlockingAutoRepeat() const
{
return d->active;
}
......@@ -47,6 +47,8 @@ public:
virtual void end();
virtual void inputEvent(QEvent* event);
virtual bool isBlockingAutoRepeat() const;
private:
class Private;
Private * const d;
......
......@@ -32,7 +32,10 @@ using namespace Eigen;
class KisRotateCanvasAction::Private
{
public:
Private() : active(false) { }
QPointF lastMousePosition;
bool active;
};
KisRotateCanvasAction::KisRotateCanvasAction(KisInputManager* manager)
......@@ -58,6 +61,7 @@ void KisRotateCanvasAction::begin(int shortcut)
case RotateToggleShortcut:
d->lastMousePosition = inputManager()->canvas()->coordinatesConverter()->documentToWidget(inputManager()->mousePosition());
QApplication::setOverrideCursor(Qt::OpenHandCursor);
d->active = true;
break;
case RotateLeftShortcut:
inputManager()->canvas()->rotateCanvasLeft15();
......@@ -73,6 +77,7 @@ void KisRotateCanvasAction::begin(int shortcut)
void KisRotateCanvasAction::end()
{
d->active = false;
QApplication::restoreOverrideCursor();
}
......@@ -108,3 +113,8 @@ void KisRotateCanvasAction::inputEvent(QEvent* event)
break;
}
}
bool KisRotateCanvasAction::isBlockingAutoRepeat() const
{
return d->active;
}
......@@ -47,6 +47,8 @@ public:
virtual void end();
virtual void inputEvent(QEvent* event);
virtual bool isBlockingAutoRepeat() const;
private:
class Private;
Private * const d;
......
......@@ -105,21 +105,23 @@ void KisShortcut::match(QEvent* event)
switch (event->type()) {
case QEvent::KeyPress: {
QKeyEvent *kevent = static_cast<QKeyEvent*>(event);
if (!kevent->isAutoRepeat()) {
Qt::Key key = static_cast<Qt::Key>(kevent->key());
if (d->keys.contains(key) && !d->keyState.contains(key)) {
d->keyState.append(key);
}
if (kevent->isAutoRepeat() && d->action->isBlockingAutoRepeat()) {
break;
}
Qt::Key key = static_cast<Qt::Key>(kevent->key());
if (d->keys.contains(key) && !d->keyState.contains(key)) {
d->keyState.append(key);
}
break;
}
case QEvent::KeyRelease: {
QKeyEvent *kevent = static_cast<QKeyEvent*>(event);
if (!kevent->isAutoRepeat()) {
Qt::Key key = static_cast<Qt::Key>(kevent->key());
if (d->keyState.contains(key)) {
d->keyState.removeOne(key);
}
if (kevent->isAutoRepeat() && d->action->isBlockingAutoRepeat()) {
break;
}
Qt::Key key = static_cast<Qt::Key>(kevent->key());
if (d->keyState.contains(key)) {
d->keyState.removeOne(key);
}
break;
}
......
......@@ -31,6 +31,9 @@
class KisZoomAction::Private
{
public:
Private() : active(false) { }
bool active;
QPointF mouseStart;
QPointF lastMousePosition;
};
......@@ -61,6 +64,7 @@ void KisZoomAction::begin(int shortcut)
case ZoomToggleShortcut:
d->lastMousePosition = d->mouseStart = inputManager()->canvas()->coordinatesConverter()->documentToWidget(inputManager()->mousePosition());
QApplication::setOverrideCursor(Qt::OpenHandCursor);
d->active = true;
break;
case ZoomInShortcut: {
float zoom = inputManager()->canvas()->view()->zoomController()->zoomAction()->effectiveZoom();
......@@ -101,6 +105,7 @@ void KisZoomAction::begin(int shortcut)
void KisZoomAction::end()
{
d->active = false;
QApplication::restoreOverrideCursor();
}
......@@ -128,3 +133,8 @@ void KisZoomAction::inputEvent(QEvent* event)
break;
}
}
bool KisZoomAction::isBlockingAutoRepeat() const
{
return d->active;
}
......@@ -46,6 +46,8 @@ public:
virtual void end();
virtual void inputEvent(QEvent* event);
virtual bool isBlockingAutoRepeat() const;
private:
class Private;
Private * const d;
......
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