Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

[xmlgui] Remove KGesture implementation

Dmitry Kazakov67aa8b932f7e
diff --git a/libs/widgetutils/CMakeLists.txt b/libs/widgetutils/CMakeLists.txt
index 71f5d611ab..3f27e42316 100644
--- a/libs/widgetutils/CMakeLists.txt
+++ b/libs/widgetutils/CMakeLists.txt
@@ -74,8 +74,6 @@ set(kritawidgetutils_LIB_SRCS
xmlgui/kbugreport.cpp
xmlgui/kcheckaccelerators.cpp
xmlgui/kedittoolbar.cpp
- xmlgui/kgesture.cpp
- xmlgui/kgesturemap.cpp
xmlgui/khelpmenu.cpp
xmlgui/kkeysequencewidget.cpp
xmlgui/kmainwindow.cpp
diff --git a/libs/widgetutils/xmlgui/kgesture.cpp b/libs/widgetutils/xmlgui/kgesture.cpp
deleted file mode 100644
index e9208b9d9b..0000000000
--- a/libs/widgetutils/xmlgui/kgesture.cpp
+++ /dev/null
@@ -1,578 +0,0 @@
-/* This file is part of the KDE libraries
- SPDX-FileCopyrightText: 2006, 2007 Andreas Hartmetz ([email protected])
-
- SPDX-License-Identifier: LGPL-2.0-or-later
-*/
-
-#include "kgesture_p.h"
-#include <klocalizedstring.h>
-#include <math.h>
-#include <QStringList>
-
-inline float metric(float dx, float dy)
-{
- //square root of that or not? - not square root has possible advantages
- return (dx * dx + dy * dy);
-}
-
-class KisKShapeGesturePrivate
-{
-public:
- KisKShapeGesturePrivate()
- {
- }
- KisKShapeGesturePrivate(const KisKShapeGesturePrivate &other)
- : m_shape(other.m_shape),
- m_lengthTo(other.m_lengthTo),
- m_curveLength(other.m_curveLength)
- {
- }
- QPolygon m_shape;
- QVector<float> m_lengthTo;
- float m_curveLength {0.0};
- QString m_friendlyName;
-};
-
-KisKShapeGesture::KisKShapeGesture()
- : d(new KisKShapeGesturePrivate)
-{
-}
-
-KisKShapeGesture::KisKShapeGesture(const QPolygon &shape)
- : d(new KisKShapeGesturePrivate)
-{
- setShape(shape);
-}
-
-KisKShapeGesture::KisKShapeGesture(const QString &description)
- : d(new KisKShapeGesturePrivate)
-{
- QStringList sl = description.split(QLatin1Char(','));
- d->m_friendlyName = sl.takeFirst();
-
- bool ok = true;
- QPolygon poly;
- int x, y;
- QStringList::const_iterator it = sl.constBegin();
- while (it != sl.constEnd()) {
- x = (*it).toInt(&ok);
- ++it;
- if (!ok || it == sl.constEnd()) {
- break;
- }
- y = (*it).toInt(&ok);
- if (!ok) {
- break;
- }
- ++it;
- poly.append(QPoint(x, y));
- }
- if (!ok) {
- d->m_friendlyName.clear();
- return;
- }
-
- setShape(poly);
-}
-
-KisKShapeGesture::KisKShapeGesture(const KisKShapeGesture &other)
- : d(new KisKShapeGesturePrivate(*(other.d)))
-{
-}
-
-KisKShapeGesture::~KisKShapeGesture()
-{
- delete d;
-}
-
-void KisKShapeGesture::setShape(const QPolygon &shape)
-{
- //Scale and translate into a 100x100 square with its
- //upper left corner at origin.
- d->m_shape = shape;
- QRect bounding = shape.boundingRect();
- //TODO: don't change aspect ratio "too much" to avoid problems with straight lines
- //TODO: catch all bad input, like null height/width
-
- //compensate for QRect weirdness
- bounding.setWidth(bounding.width() - 1);
- bounding.setHeight(bounding.height() - 1);
-
- float xScale = bounding.width() ? 100.0 / bounding.width() : 1.0;
- float yScale = bounding.height() ? 100.0 / bounding.height() : 1.0;
- d->m_shape.translate(-bounding.left(), -bounding.top());
- for (int i = 0; i < d->m_shape.size(); i++) {
- d->m_shape[i].setX((int)(xScale * (float)d->m_shape[i].x()));
- d->m_shape[i].setY((int)(yScale * (float)d->m_shape[i].y()));
- }
-
- //calculate accumulated lengths of lines making up the polygon
- Q_ASSERT(d->m_shape.size() > 1);
- d->m_curveLength = 0.0;
- d->m_lengthTo.clear();
- d->m_lengthTo.reserve(d->m_shape.size());
- d->m_lengthTo.append(d->m_curveLength);
-
- int prevX = d->m_shape[0].x();
- int prevY = d->m_shape[0].y();
- for (int i = 1; i < d->m_shape.size(); i++) {
- int curX = d->m_shape[i].x();
- int curY = d->m_shape[i].y();
- d->m_curveLength += metric(curX - prevX, curY - prevY);
- d->m_lengthTo.append(d->m_curveLength);
- prevX = curX;
- prevY = curY;
- }
-}
-
-void KisKShapeGesture::setShapeName(const QString &friendlyName)
-{
- d->m_friendlyName = friendlyName;
-}
-
-QString KisKShapeGesture::shapeName() const
-{
- return d->m_friendlyName;
-}
-
-bool KisKShapeGesture::isValid() const
-{
- return !d->m_shape.isEmpty();
-}
-
-QString KisKShapeGesture::toString() const
-{
- if (!isValid()) {
- return QString();
- }
-
- //TODO: what if the name contains a "," or ";"? Limit the name to letters?
- QString ret = d->m_friendlyName;
-
- int i;
- for (i = 0; i < d->m_shape.size(); i++) {
- ret.append(QLatin1Char(','));
- ret.append(QString::number(d->m_shape[i].x()));
- ret.append(QLatin1Char(','));
- ret.append(QString::number(d->m_shape[i].y()));
- }
-
- return ret;
-}
-
-QByteArray KisKShapeGesture::toSvg(const QString &attributes) const
-{
- if (!isValid()) {
- return QByteArray();
- //TODO: KDE standard debug output
- }
- const char *prolog = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
- "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" "
- "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">"
- "<svg width=\"100\" height=\"100\" version=\"1.1\" "
- "xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M";
- const char *epilog1 = "\" fill=\"none\" ";
- const char *epilog2 = " /></svg>";
- QByteArray ret(prolog);
-
- ret.append(QString::number(d->m_shape[0].x()).toUtf8());
- ret.append(",");
- ret.append(QString::number(d->m_shape[0].y()).toUtf8());
-
- for (int i = 1; i < d->m_shape.size(); i++) {
- ret.append("L");
- ret.append(QString::number(d->m_shape[i].x()).toUtf8());
- ret.append(",");
- ret.append(QString::number(d->m_shape[i].y()).toUtf8());
- }
-
- ret.append(epilog1);
- ret.append(attributes.toUtf8());
- ret.append(epilog2);
- return ret;
-}
-
-/*
- algorithm: iterate in order over 30 points on our shape and measure the
- minimum distance to any point on the other shape. never go backwards on
- the other shape to also check direction of movement.
- This algorithm is best applied like a->distance(b) + b->distance(a).
- fabs(a->distance(b) - b->distance(a)) might turn out to be very interesting,
- too. in fact, i think it's the most interesting value.
- */
-float KisKShapeGesture::distance(const KisKShapeGesture &other, float abortThreshold) const
-{
- Q_UNUSED(abortThreshold); //for optimizations, later
- const QPolygon &o_shape = other.d->m_shape;
- const QVector<float> &o_lengthTo = other.d->m_lengthTo;
- float x = 0;
- float y = 0;
- float mx = 0;
- float my = 0;
- float position = 0;
- float ox = 0;
- float oy = 0;
- float opposition = 0;
- float omx = 0;
- float omy = 0;
- float oxB = 0;
- float oyB = 0;
- float oppositionB = 0;
- float omxB = 0;
- float omyB = 0;
- float dist = 0;
- float distB = 0;
- float desiredPosition = 0;
- float strokeLength = 0;
- float retval = 0.0;
- int pointIndex = 0, opointIndex = 0, opointIndexB = 0;
-
- //set up starting point on our shape
- x = d->m_shape[0].x();
- y = d->m_shape[0].y();
- strokeLength = d->m_lengthTo[1];
- mx = (d->m_shape[1].x() - x) / strokeLength;
- my = (d->m_shape[1].y() - y) / strokeLength;
- position = 0.0;
-
- //set up lower bound of search interval on other shape
- ox = o_shape[0].x();
- oy = o_shape[0].y();
- strokeLength = o_lengthTo[1];
- omx = (o_shape[1].x() - ox) / strokeLength;
- omy = (o_shape[1].y() - oy) / strokeLength;
- opposition = 0.0;
- dist = metric(ox - x, oy - y);
-
- for (int i = 0; i <= 30; i++) {
- //go to comparison point on our own polygon
- //30.0001 to prevent getting out-of-bounds pointIndex
- desiredPosition = d->m_curveLength / 30.0001 * (float)i;
- if (desiredPosition > d->m_lengthTo[pointIndex + 1]) {
-
- while (desiredPosition > d->m_lengthTo[pointIndex + 1]) {
- pointIndex++;
- }
-
- x = d->m_shape[pointIndex].x();
- y = d->m_shape[pointIndex].y();
- position = d->m_lengthTo[pointIndex];
- strokeLength = d->m_lengthTo[pointIndex + 1] - position;
- mx = (d->m_shape[pointIndex + 1].x() - x) / strokeLength;
- my = (d->m_shape[pointIndex + 1].y() - y) / strokeLength;
- }
- x += mx * (desiredPosition - position);
- y += my * (desiredPosition - position);
- position = desiredPosition;
-
- //set up upper bound of search interval on other shape
- desiredPosition = qMin(opposition + other.d->m_curveLength / 15.00005,
- other.d->m_curveLength - 0.0001);
- if (i == 0 || desiredPosition > o_lengthTo[opointIndexB + 1]) {
-
- while (desiredPosition > o_lengthTo[opointIndexB + 1]) {
- opointIndexB++;
- }
-
- oxB = o_shape[opointIndexB].x();
- oyB = o_shape[opointIndexB].y();
- oppositionB = o_lengthTo[opointIndexB];
- strokeLength = o_lengthTo[opointIndexB + 1] - oppositionB;
- omxB = (o_shape[opointIndexB + 1].x() - oxB) / strokeLength;
- omyB = (o_shape[opointIndexB + 1].y() - oyB) / strokeLength;
- }
- oxB += omxB * (desiredPosition - oppositionB);
- oyB += omyB * (desiredPosition - oppositionB);
- oppositionB = desiredPosition;
- distB = metric(oxB - x, oyB - y);
-
- //binary search for nearest point on other shape
- for (int j = 0; j < 6; j++) {
- desiredPosition = (opposition + oppositionB) * 0.5;
- if (dist < distB) {
- //retract upper bound to desiredPosition
- //copy state of lower bound to upper bound, advance it from there
- oxB = ox; oyB = oy;
- omxB = omx; omyB = omy;
- opointIndexB = opointIndex; oppositionB = opposition;
-
- if (desiredPosition > o_lengthTo[opointIndexB + 1]) {
-
- while (desiredPosition > o_lengthTo[opointIndexB + 1]) {
- opointIndexB++;
- }
-
- oxB = o_shape[opointIndexB].x();
- oyB = o_shape[opointIndexB].y();
- oppositionB = o_lengthTo[opointIndexB];
- strokeLength = o_lengthTo[opointIndexB + 1] - oppositionB;
- omxB = (o_shape[opointIndexB + 1].x() - oxB) / strokeLength;
- omyB = (o_shape[opointIndexB + 1].y() - oyB) / strokeLength;
- }
- oxB += omxB * (desiredPosition - oppositionB);
- oyB += omyB * (desiredPosition - oppositionB);
- oppositionB = desiredPosition;
- distB = metric(oxB - x, oyB - y);
- } else {
- //advance lower bound to desiredPosition
- if (desiredPosition > o_lengthTo[opointIndex + 1]) {
-
- while (desiredPosition > o_lengthTo[opointIndex + 1]) {
- opointIndex++;
- }
-
- ox = o_shape[opointIndex].x();
- oy = o_shape[opointIndex].y();
- opposition = o_lengthTo[opointIndex];
- strokeLength = o_lengthTo[opointIndex + 1] - opposition;
- omx = (o_shape[opointIndex + 1].x() - ox) / strokeLength;
- omy = (o_shape[opointIndex + 1].y() - oy) / strokeLength;
- }
- ox += omx * (desiredPosition - opposition);
- oy += omy * (desiredPosition - opposition);
- opposition = desiredPosition;
- dist = metric(ox - x, oy - y);
- }
- }
- retval += qMin(dist, distB);
- }
- //scale value to make it roughly invariant against step width
- return retval / 30.0;
-}
-
-KisKShapeGesture &KisKShapeGesture::operator=(const KisKShapeGesture &other)
-{
- d->m_lengthTo = other.d->m_lengthTo;
- d->m_shape = other.d->m_shape;
- d->m_curveLength = other.d->m_curveLength;
- return *this;
-}
-
-bool KisKShapeGesture::operator==(const KisKShapeGesture &other) const
-{
- //a really fast and workable shortcut
- if (fabs(d->m_curveLength - other.d->m_curveLength) > 0.1) {
- return false;
- }
- return d->m_shape == other.d->m_shape;
-}
-
-bool KisKShapeGesture::operator!=(const KisKShapeGesture &other) const
-{
- return !operator==(other);
-}
-
-uint KisKShapeGesture::hashable() const
-{
- uint hash = 0;
-
- foreach (const QPoint &point, d->m_shape) {
- hash += qHash(point.x()) + qHash(point.y());
- }
-
- return hash;
-}
-
-/********************************************************
- * KisKRockerGesture *
- *******************************************************/
-
-class KisKRockerGesturePrivate
-{
-public:
- KisKRockerGesturePrivate()
- : m_hold(Qt::NoButton),
- m_thenPush(Qt::NoButton)
- {
- }
- KisKRockerGesturePrivate(const KisKRockerGesturePrivate &other)
- : m_hold(other.m_hold),
- m_thenPush(other.m_thenPush)
- {
- }
- Qt::MouseButton m_hold;
- Qt::MouseButton m_thenPush;
-};
-
-KisKRockerGesture::KisKRockerGesture()
- : d(new KisKRockerGesturePrivate)
-{
-}
-
-KisKRockerGesture::KisKRockerGesture(Qt::MouseButton hold, Qt::MouseButton thenPush)
- : d(new KisKRockerGesturePrivate)
-{
- setButtons(hold, thenPush);
-}
-
-KisKRockerGesture::KisKRockerGesture(const QString &description)
- : d(new KisKRockerGesturePrivate)
-{
- if (description.length() != 2) {
- return;
- }
-
- Qt::MouseButton hold, thenPush;
- Qt::MouseButton *current = &hold;
- for (int i = 0; i < 2; i++) {
- switch (description[i].toLatin1()) {
- case 'L':
- *current = Qt::LeftButton;
- break;
- case 'R':
- *current = Qt::RightButton;
- break;
- case 'M':
- *current = Qt::MiddleButton;
- break;
- case '1':
- *current = Qt::XButton1;
- break;
- case '2':
- *current = Qt::XButton2;
- break;
- default:
- return;
- }
- current = &thenPush;
- }
- d->m_hold = hold;
- d->m_thenPush = thenPush;
-}
-
-KisKRockerGesture::KisKRockerGesture(const KisKRockerGesture &other)
- : d(new KisKRockerGesturePrivate(*(other.d)))
-{
-}
-
-KisKRockerGesture::~KisKRockerGesture()
-{
- delete d;
-}
-
-void KisKRockerGesture::setButtons(Qt::MouseButton hold, Qt::MouseButton thenPush)
-{
- if (hold == thenPush) {
- d->m_hold = Qt::NoButton;
- d->m_thenPush = Qt::NoButton;
- return;
- }
-
- int button = hold;
- for (int i = 0; i < 2; i++) {
- switch (button) {
- case Qt::LeftButton:
- case Qt::RightButton:
- case Qt::MiddleButton:
- case Qt::XButton1:
- case Qt::XButton2:
- break;
- default:
- d->m_hold = Qt::NoButton;
- d->m_thenPush = Qt::NoButton;
- return;
- }
- button = thenPush;
- }
-
- d->m_hold = hold;
- d->m_thenPush = thenPush;
-}
-
-void KisKRockerGesture::getButtons(Qt::MouseButton *hold, Qt::MouseButton *thenPush) const
-{
- *hold = d->m_hold;
- *thenPush = d->m_thenPush;
-}
-
-QString KisKRockerGesture::mouseButtonName(Qt::MouseButton button)
-{
- switch (button) {
- case Qt::LeftButton:
- return i18nc("left mouse button", "left button");
- break;
- case Qt::MiddleButton:
- return i18nc("middle mouse button", "middle button");
- break;
- case Qt::RightButton:
- return i18nc("right mouse button", "right button");
- break;
- default:
- return i18nc("a nonexistent value of mouse button", "invalid button");
- break;
- }
-}
-
-QString KisKRockerGesture::rockerName() const
-{
- if (!isValid()) {
- return QString();
- }
- //return i18nc("an invalid mouse gesture of type \"hold down one button, then press another button\"",
- // "invalid rocker gesture");
- else
- return i18nc("a kind of mouse gesture: hold down one mouse button, then press another button",
- "Hold %1, then push %2", mouseButtonName(d->m_hold), mouseButtonName(d->m_thenPush));
-}
-
-bool KisKRockerGesture::isValid() const
-{
- return (d->m_hold != Qt::NoButton);
-}
-
-QString KisKRockerGesture::toString() const
-{
- if (!isValid()) {
- return QString();
- }
- QString ret;
- int button = d->m_hold;
- char desc;
- for (int i = 0; i < 2; i++) {
- switch (button) {
- case Qt::LeftButton:
- desc = 'L';
- break;
- case Qt::RightButton:
- desc = 'R';
- break;
- case Qt::MiddleButton:
- desc = 'M';
- break;
- case Qt::XButton1:
- desc = '1';
- break;
- case Qt::XButton2:
- desc = '2';
- break;
- default:
- return QString();
- }
- ret.append(QLatin1Char(desc));
- button = d->m_thenPush;
- }
- return ret;
-}
-
-KisKRockerGesture &KisKRockerGesture::operator=(const KisKRockerGesture &other)
-{
- d->m_hold = other.d->m_hold;
- d->m_thenPush = other.d->m_thenPush;
- return *this;
-}
-
-bool KisKRockerGesture::operator==(const KisKRockerGesture &other) const
-{
- return d->m_hold == other.d->m_hold && d->m_thenPush == other.d->m_thenPush;
-}
-
-bool KisKRockerGesture::operator!=(const KisKRockerGesture &other) const
-{
- return !operator==(other);
-}
-
-uint KisKRockerGesture::hashable() const
-{
- //make it asymmetric
- return qHash(d->m_hold) + d->m_thenPush;
-}
diff --git a/libs/widgetutils/xmlgui/kgesture_p.h b/libs/widgetutils/xmlgui/kgesture_p.h
deleted file mode 100644
index fd6a686b0a..0000000000
--- a/libs/widgetutils/xmlgui/kgesture_p.h
+++ /dev/null
@@ -1,234 +0,0 @@
-/* This file is part of the KDE libraries
- SPDX-FileCopyrightText: 2006, 2007 Andreas Hartmetz ([email protected])
-
- SPDX-License-Identifier: LGPL-2.0-or-later
-*/
-
-#ifndef KGESTURE_H
-#define KGESTURE_H
-
-#include <kritawidgetutils_export.h>
-
-#include <QString>
-#include <QHash>
-#include <QPolygon>
-
-/*
- kinds of gestures:
- -shapes like triangle, right angle, line
- -"rocker" (i.e. two mouse button) gestures
- */
-
-class KisKShapeGesturePrivate;
-//TODO: implement operator== for special situations like in KKeyChooser.
-class KRITAWIDGETUTILS_EXPORT KisKShapeGesture
-{
-public:
- /**
- * Create a new invalid shape gesture.
- */
- KisKShapeGesture();
-
- /**
- * Creates a new gesture consisting of given shape.
- * If the gesture belongs to a KAction, and the user draws approximately the same shape
- * on the screen while holding down the right mouse button, the action will trigger.
- * @p shape must be a "reasonable" polygon. It must contain at least two points
- * and it should contain at most 50 for performance reasons. No two consecutive points
- * are allowed to be at the same position.
- * @param shape to draw to trigger this gesture
- */
- KisKShapeGesture(const QPolygon &shape);
-
- /**
- * Creates a new gesture from a string description.
- * @param description create gesture according to this
- */
- KisKShapeGesture(const QString &description);
-
- /**
- * Copies the given gesture.
- * @param other gesture to copy
- */
- KisKShapeGesture(const KisKShapeGesture &other);
-
- /**
- * Destructor.
- */
- ~KisKShapeGesture();
-
- /**
- * Set the shape to draw to trigger this gesture.
- */
- void setShape(const QPolygon &shape);
-
- /**
- * set a user-visible name for this gesture's shape, like "triangle" or "line".
- */
- void setShapeName(const QString &friendlyName);
-
- /**
- * Return the user-visible name for this gesture's shape, like "triangle" or "line".
- */
- QString shapeName() const;
-
- /**
- * Return true if this gesture is valid.
- *
- */
- bool isValid() const;
-
- /**
- * Return a string representation of this gesture.
- * Return empty string if invalid.
- * This function is mainly for use with config files.
- *
- * @see shapeName()
- */
- QString toString() const;
-
- /**
- * Return an idealized SVG image of this gesture.
- * Return an empty image if invalid.
- * @param attributes SVG attributes to apply to the SVG "path" element that
- * makes up the drawing of the gesture. By default, only a 'fill="none"'
- * attribute will be set.
- */
- QByteArray toSvg(const QString &attributes = QString()) const;
-
- /**
- * Return a difference measurement between this gesture and the @p other
- * gesture. Abort comparison if difference is larger than @p abortThreshold
- * and return a very large difference in that case.
- * Usual return values range from x to y //TODO: fill in x and y
- */
- float distance(const KisKShapeGesture &other, float abortThreshold) const;
-
- /**
- * Set this gesture to the other gesture.
- */
- KisKShapeGesture &operator=(const KisKShapeGesture &other);
-
- /**
- * Return whether this gesture is equal to the other gesture.
- */
- bool operator==(const KisKShapeGesture &other) const;
-
- /**
- * Return the opposite of operator==()
- */
- bool operator!=(const KisKShapeGesture &other) const;
-
- /**
- * Return an opaque value for use in hash tables
- */
- uint hashable() const;
-
-private:
- KisKShapeGesturePrivate *const d;
-};
-
-inline uint qHash(const KisKShapeGesture &key)
-{
- return qHash(key.hashable());
-}
-
-class KisKRockerGesturePrivate;
-
-class KRITAWIDGETUTILS_EXPORT KisKRockerGesture
-{
-public:
- /**
- * Create a new invalid rocker gesture.
- */
- KisKRockerGesture();
-
- /**
- * Creates a new gesture consisting of given buttons.
- * @param hold create gesture according to this hold
- * @param thenPush create gesture according to this push
- */
- KisKRockerGesture(enum Qt::MouseButton hold, enum Qt::MouseButton thenPush);
-
- /**
- * Creates a new gesture from a string description.
- * @param description create gesture according to this
- */
- KisKRockerGesture(const QString &description);
-
- /**
- * Copies the given gesture.
- * @param other gesture to copy
- */
- KisKRockerGesture(const KisKRockerGesture &other);
-
- /**
- * Destructor.
- */
- ~KisKRockerGesture();
-
- /**
- * set button combination to trigger
- */
- void setButtons(Qt::MouseButton hold, Qt::MouseButton thenPush);
-
- /**
- * Write the button combination to hold and thenPush
- */
- void getButtons(Qt::MouseButton *hold, Qt::MouseButton *thenPush) const;
-
- /**
- * Return a user-friendly name of the button combination.
- */
- QString rockerName() const;
-
- /**
- * Return a user-friendly name for the mouse button button
- */
- static QString mouseButtonName(Qt::MouseButton button);
-
- /**
- * Return true if this gesture is valid.
- */
- bool isValid() const;
-
- /**
- * Return a string representation of this gesture.
- * Return an empty string if invalid.
- * This function is mainly for use with config files.
- *
- * @see rockerName()
- */
- QString toString() const;
-
- /**
- * Set this gesture to the other gesture.
- */
- KisKRockerGesture &operator=(const KisKRockerGesture &other);
-
- /**
- * Return whether this gesture is equal to the other gesture.
- */
- bool operator==(const KisKRockerGesture &other) const;
-
- /**
- * Return the opposite of operator==()
- */
- bool operator!=(const KisKRockerGesture &other) const;
-
- /**
- * Return an opaque value for use in hash tables
- */
- uint hashable() const;
-
-private:
- KisKRockerGesturePrivate *const d;
-};
-
-inline uint qHash(const KisKRockerGesture &key)
-{
- return qHash(key.hashable());
-}
-
-//KGESTURE_H
-#endif
diff --git a/libs/widgetutils/xmlgui/kgesturemap.cpp b/libs/widgetutils/xmlgui/kgesturemap.cpp
deleted file mode 100644
index 79bd8f9fa2..0000000000
--- a/libs/widgetutils/xmlgui/kgesturemap.cpp
+++ /dev/null
@@ -1,350 +0,0 @@
-/* This file is part of the KDE libraries
- SPDX-FileCopyrightText: 2006, 2007 Andreas Hartmetz ([email protected])
-
- SPDX-License-Identifier: LGPL-2.0-or-later
-*/
-
-#include "kgesturemap_p.h"
-
-#include <qapplication.h>
-#include <QAction>
-#include <QActionEvent>
-#include <QDebug>
-
-/*
- This is a class for internal use by the KDE libraries only. This class
- may change or go away without notice so don't try to use it in non-kdelibs
- code.
- */
-
-class KisKGestureMapContainer
-{
-public:
- KisKGestureMap gestureMap;
-};
-
-Q_GLOBAL_STATIC(KisKGestureMapContainer, g_instance)
-
-KisKGestureMap::~KisKGestureMap()
-{
-}
-
-KisKGestureMap *KisKGestureMap::self()
-{
- return &g_instance()->gestureMap;
-}
-
-KisKGestureMap::KisKGestureMap()
-{
- m_gestureTimeout.setSingleShot(true);
- connect(&m_gestureTimeout, SIGNAL(timeout()), this, SLOT(stopAcquisition()));
- //It would be nice to install the filter on demand. Unfortunately,
- //undesired behavior might result due to changing invocation
- //orders of different event filters.
- if (qApp) {
- qApp->installEventFilter(this);
- }
-}
-
-void KisKGestureMap::setShapeGesture(QAction *act, const KisKShapeGesture &gesture)
-{
- if (!gesture.isValid() || !act) {
- return;
- }
- qDebug() << "KisKGestureMap::addGesture(KisKShapeGesture ...)";
- if (m_shapeGestures.contains(gesture)) {
- qWarning() << "Replacing an action for a gesture already taken";
- }
- m_shapeGestures.insert(gesture, act);
-}
-
-void KisKGestureMap::setRockerGesture(QAction *act, const KisKRockerGesture &gesture)
-{
- if (!gesture.isValid() || !act) {
- return;
- }
- qDebug() << "KisKGestureMap::addGesture(KisKRockerGesture ...)";
- if (m_rockerGestures.contains(gesture)) {
- qWarning() << "Replacing an action for a gesture already taken";
- }
- m_rockerGestures.insert(gesture, act);
-}
-
-void KisKGestureMap::setDefaultShapeGesture(QAction *act, const KisKShapeGesture &gesture)
-{
- if (!gesture.isValid() || !act) {
- return;
- }
- qDebug() << "KisKGestureMap::addGesture(KisKShapeGesture ...)";
- if (m_defaultShapeGestures.contains(gesture)) {
- qWarning() << "Replacing an action for a gesture already taken";
- }
- m_defaultShapeGestures.insert(gesture, act);
-}
-
-void KisKGestureMap::setDefaultRockerGesture(QAction *act, const KisKRockerGesture &gesture)
-{
- if (!gesture.isValid() || !act) {
- return;
- }
- qDebug() << "KisKGestureMap::addGesture(KisKRockerGesture ...)";
- if (m_defaultRockerGestures.contains(gesture)) {
- qWarning() << "Replacing an action for a gesture already taken";
- }
- m_defaultRockerGestures.insert(gesture, act);
-}
-
-void KisKGestureMap::removeAllGestures(QAction *kact)
-{
- KisKShapeGesture activeGesture;
- ShapeGestureHash::iterator si = m_shapeGestures.begin();
- ShapeGestureHash::iterator send = m_shapeGestures.end();
- for (; si != send; ++si) {
- if (si.value() == kact) {
- m_shapeGestures.remove(si.key());
- break;
- }
- }
-
- si = m_defaultShapeGestures.begin();
- send = m_defaultShapeGestures.end();
- for (; si != send; ++si) {
- if (si.value() == kact) {
- m_defaultShapeGestures.remove(si.key());
- break;
- }
- }
-
- RockerGestureHash::iterator ri = m_rockerGestures.begin();
- RockerGestureHash::iterator rend = m_rockerGestures.end();
- for (; ri != rend; ++ri) {
- if (ri.value() == kact) {
- m_rockerGestures.remove(ri.key());
- break;
- }
- }
-
- ri = m_defaultRockerGestures.begin();
- rend = m_defaultRockerGestures.end();
- for (; ri != rend; ++ri) {
- if (ri.value() == kact) {
- m_defaultRockerGestures.remove(ri.key());
- break;
- }
- }
-}
-
-QAction *KisKGestureMap::findAction(const KisKShapeGesture &gesture) const
-{
- return m_shapeGestures.value(gesture);
-}
-
-QAction *KisKGestureMap::findAction(const KisKRockerGesture &gesture) const
-{
- return m_rockerGestures.value(gesture);
-}
-
-void KisKGestureMap::installEventFilterOnMe(QApplication *app)
-{
- app->installEventFilter(this);
-}
-
-KisKShapeGesture KisKGestureMap::shapeGesture(const QAction *kact) const
-{
- KisKShapeGesture activeGesture;
- ShapeGestureHash::const_iterator it = m_shapeGestures.constBegin();
- ShapeGestureHash::const_iterator end = m_shapeGestures.constEnd();
- for (; it != end; ++it) {
- if (it.value() == kact) {
- activeGesture = it.key();
- break;
- }
- }
- return activeGesture;
-}
-
-KisKShapeGesture KisKGestureMap::defaultShapeGesture(const QAction *kact) const
-{
- KisKShapeGesture defaultGesture;
- ShapeGestureHash::const_iterator it = m_defaultShapeGestures.constBegin();
- ShapeGestureHash::const_iterator end = m_defaultShapeGestures.constEnd();
- for (; it != end; ++it) {
- if (it.value() == kact) {
- defaultGesture = it.key();
- break;
- }
- }
- return defaultGesture;
-}
-
-KisKRockerGesture KisKGestureMap::rockerGesture(const QAction *kact) const
-{
- KisKRockerGesture activeGesture;
- RockerGestureHash::const_iterator it = m_rockerGestures.constBegin();
- RockerGestureHash::const_iterator end = m_rockerGestures.constEnd();
- for (; it != end; ++it) {
- if (it.value() == kact) {
- activeGesture = it.key();
- break;
- }
- }
- return activeGesture;
-}
-
-KisKRockerGesture KisKGestureMap::defaultRockerGesture(const QAction *kact) const
-{
- KisKRockerGesture defaultGesture;
- RockerGestureHash::const_iterator it = m_defaultRockerGestures.constBegin();
- RockerGestureHash::const_iterator end = m_defaultRockerGestures.constEnd();
- for (; it != end; ++it) {
- if (it.value() == kact) {
- defaultGesture = it.key();
- break;
- }
- }
- return defaultGesture;
-}
-
-inline int KisKGestureMap::bitCount(int n)
-{
- int count = 0;
- while (n) {
- n &= (n - 1);
- count++;
- }
- return count;
-}
-
-void KisKGestureMap::handleAction(QAction *kact)
-{
- if (!kact) {
- return;
- }
- qDebug() << "handleAction";
- //TODO: only activate in the action's context, just like keyboard shortcuts
- kact->trigger();
- return;
-}
-
-void KisKGestureMap::matchShapeGesture()
-{
- //TODO: tune and tweak until satisfied with result :)
- m_shapeGesture.setShape(m_points);
- float dist, minDist = 20.0;
- QAction *bestMatch = 0;
-
- for (QHash<KisKShapeGesture, QAction *>::const_iterator it = m_shapeGestures.constBegin();
- it != m_shapeGestures.constEnd(); ++it) {
- dist = m_shapeGesture.distance(it.key(), 1000.0);
- if (dist < minDist) {
- minDist = dist;
- bestMatch = it.value();
- }
- }
- handleAction(bestMatch);
-}
-
-//slot
-void KisKGestureMap::stopAcquisition()
-{
- m_gestureTimeout.stop();
- m_acquiring = false;
-}
-
-//TODO: Probably kwin, kded and others should not have a gesture map.
-//Maybe making them friends and providing a private "die()" function would work.
-/*
- * Act on rocker gestures immediately and collect movement data for evaluation.
- * The decision when to consume and when to relay an event is quite tricky.
- * I decided to only consume clicks that belong to completed rocker gestures.
- * A user might e.g. go back in a browser several times using rocker gestures,
- * thus changing what's under the cursor every time. This might lead to
- * unintended clicks on links where there was free space before.
- */
-
-bool KisKGestureMap::eventFilter(QObject *obj, QEvent *e)
-{
- //disable until it does not interfere with other input any more
- return false;
- Q_UNUSED(obj);
- int type = e->type();
-
- //catch right-clicks disguised as context menu events. if we ignore a
- //context menu event caused by a right-click, it should get resent
- //as a right-click event, according to documentation.
- //### this is preliminary
- if (type == QEvent::ContextMenu) {
- QContextMenuEvent *cme = static_cast<QContextMenuEvent *>(e);
- if (cme->reason() == QContextMenuEvent::Mouse) {
- cme->ignore();
- return true;
- }
- return false;
- }
-
- if (type < QEvent::MouseButtonPress || type > QEvent::MouseMove) {
- return false;
- }
-
- QMouseEvent *me = static_cast<QMouseEvent *>(e);
- if (type == QEvent::MouseButtonPress) {
- int nButtonsDown = bitCount(me->buttons());
- qDebug() << "number of buttons down:" << nButtonsDown;
-
- //right button down starts gesture acquisition
- if (nButtonsDown == 1 && me->button() == Qt::RightButton) {
- //"startAcquisition()"
- m_acquiring = true;
- m_gestureTimeout.start(4000);
- qDebug() << "========================";
- m_points.clear();
- m_points.append(me->pos());
- return true;
- } else if (nButtonsDown != 2) {
- return false;
- }
-
- //rocker gestures. do not trigger any movement gestures from now on.
- stopAcquisition();
- int buttonHeld = me->buttons() ^ me->button();
- m_rockerGesture.setButtons(static_cast<Qt::MouseButton>(buttonHeld), me->button());
- QAction *match = m_rockerGestures.value(m_rockerGesture);
- if (!match) {
- return false;
- }
- handleAction(match);
- return true;
- }
-
- if (m_acquiring) {
- if (type == QEvent::MouseMove) {
- m_points.append(me->pos());
- //abort to avoid using too much memory. 1010 points should be enough
- //for everyone! :)
- //next reallocation of m_points would happen at 1012 items
- if (m_points.size() > 1010) {
- stopAcquisition();
- }
- return true;
- } else if (type == QEvent::MouseButtonRelease && me->button() == Qt::RightButton) {
- stopAcquisition();
-
- //TODO: pre-selection of gestures by length (optimization), if necessary
- //possibly apply other heuristics
- //then try all remaining gestures for sufficiently small distance
- int dist = 0;
- for (int i = 1; i < m_points.size(); i++) {
- dist += (m_points[i] - m_points[i - 1]).manhattanLength();
- if (dist > 40) {
- matchShapeGesture();
- return true;
- }
- //this was probably a small glitch while right-clicking if we get here.
- //TODO: open the context menu or do whatever happens on right-click (how?)
- }
- return false;
- }
- }
- return false;
-}
-
diff --git a/libs/widgetutils/xmlgui/kgesturemap_p.h b/libs/widgetutils/xmlgui/kgesturemap_p.h
deleted file mode 100644
index 7fa4eb8146..0000000000
--- a/libs/widgetutils/xmlgui/kgesturemap_p.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/* This file is part of the KDE libraries
- SPDX-FileCopyrightText: 2006, 2007 Andreas Hartmetz ([email protected])
-
- SPDX-License-Identifier: LGPL-2.0-or-later
-*/
-
-#ifndef KGESTUREMAP_H
-#define KGESTUREMAP_H
-
-#include <QObject>
-#include <QHash>
-#include <QTimer>
-#include <QPolygon>
-
-#include "kgesture_p.h"
-
-class QApplication;
-class QAction;
-class QEvent;
-
-class KRITAWIDGETUTILS_EXPORT KisKGestureMap : public QObject
-{
- Q_OBJECT
-public:
- static KisKGestureMap *self();
-
- bool eventFilter(QObject *obj, QEvent *e) override;
- void setShapeGesture(QAction *kact, const KisKShapeGesture &gesture);
- void setRockerGesture(QAction *kact, const KisKRockerGesture &gesture);
- void setDefaultShapeGesture(QAction *kact, const KisKShapeGesture &gesture);
- void setDefaultRockerGesture(QAction *kact, const KisKRockerGesture &gesture);
- /**
- * This method will remove all gestures defined for a given action
- */
- void removeAllGestures(QAction *kact);
- QAction *findAction(const KisKShapeGesture &gesture) const;
- QAction *findAction(const KisKRockerGesture &gesture) const;
- KisKShapeGesture shapeGesture(const QAction *kact) const;
- KisKShapeGesture defaultShapeGesture(const QAction *kact) const;
- KisKRockerGesture rockerGesture(const QAction *kact) const;
- KisKRockerGesture defaultRockerGesture(const QAction *kact) const;
-
-private Q_SLOTS:
- void stopAcquisition();
-
-private:
- friend class KisKGestureMapContainer;
- KisKGestureMap();
- ~KisKGestureMap() override;
-
- friend class KApplicationPrivate;
- //intended to be used at application initialization
- void installEventFilterOnMe(QApplication *app);
-
- inline int bitCount(int n);
- void handleAction(QAction *kact);
- void matchShapeGesture();
-
- //this is an internal class so don't bother with a d-pointer
- typedef QHash< KisKShapeGesture, QAction * > ShapeGestureHash;
- typedef QHash< KisKRockerGesture, QAction * > RockerGestureHash;
- ShapeGestureHash m_shapeGestures;
- ShapeGestureHash m_defaultShapeGestures;
- RockerGestureHash m_rockerGestures;
- RockerGestureHash m_defaultRockerGestures;
- QPolygon m_points;
- QTimer m_gestureTimeout;
- bool m_acquiring {false};
-
- KisKShapeGesture m_shapeGesture;
- KisKRockerGesture m_rockerGesture;
-};
-
-#endif //KGESTUREMAP_H
diff --git a/libs/widgetutils/xmlgui/kkeysequencewidget.cpp b/libs/widgetutils/xmlgui/kkeysequencewidget.cpp
index 7fabd7734d..cb5579957b 100644
--- a/libs/widgetutils/xmlgui/kkeysequencewidget.cpp
+++ b/libs/widgetutils/xmlgui/kkeysequencewidget.cpp
@@ -20,7 +20,6 @@
#include <klocalizedstring.h>
#include <kmessagebox.h>
-#include <kkeyserver.h>
#include "kactioncollection.h"
#include <kis_icon_utils.h>
@@ -631,6 +630,203 @@ bool KKeySequenceButton::event(QEvent *e)
return QPushButton::event(e);
}
+namespace {
+
+// Copied here from KKeyServer
+static bool isShiftAsModifierAllowed(int keyQt)
+{
+ // remove any modifiers
+ keyQt &= ~Qt::KeyboardModifierMask;
+
+ // Shift only works as a modifier with certain keys. It's not possible
+ // to enter the SHIFT+5 key sequence for me because this is handled as
+ // '%' by qt on my keyboard.
+ // The working keys are all hardcoded here :-(
+ if (keyQt >= Qt::Key_F1 && keyQt <= Qt::Key_F35) {
+ return true;
+ }
+
+ if (QChar::isLetter(keyQt)) {
+ return true;
+ }
+
+ switch (keyQt) {
+ case Qt::Key_Return:
+ case Qt::Key_Space:
+ case Qt::Key_Backspace:
+ case Qt::Key_Tab:
+ case Qt::Key_Backtab:
+ case Qt::Key_Escape:
+ case Qt::Key_Print:
+ case Qt::Key_ScrollLock:
+ case Qt::Key_Pause:
+ case Qt::Key_PageUp:
+ case Qt::Key_PageDown:
+ case Qt::Key_Insert:
+ case Qt::Key_Delete:
+ case Qt::Key_Home:
+ case Qt::Key_End:
+ case Qt::Key_Up:
+ case Qt::Key_Down:
+ case Qt::Key_Left:
+ case Qt::Key_Right:
+ case Qt::Key_Enter:
+ case Qt::Key_SysReq:
+ case Qt::Key_CapsLock:
+ case Qt::Key_NumLock:
+ case Qt::Key_Help:
+ case Qt::Key_Back:
+ case Qt::Key_Forward:
+ case Qt::Key_Stop:
+ case Qt::Key_Refresh:
+ case Qt::Key_Favorites:
+ case Qt::Key_LaunchMedia:
+ case Qt::Key_OpenUrl:
+ case Qt::Key_HomePage:
+ case Qt::Key_Search:
+ case Qt::Key_VolumeDown:
+ case Qt::Key_VolumeMute:
+ case Qt::Key_VolumeUp:
+ case Qt::Key_BassBoost:
+ case Qt::Key_BassUp:
+ case Qt::Key_BassDown:
+ case Qt::Key_TrebleUp:
+ case Qt::Key_TrebleDown:
+ case Qt::Key_MediaPlay:
+ case Qt::Key_MediaStop:
+ case Qt::Key_MediaPrevious:
+ case Qt::Key_MediaNext:
+ case Qt::Key_MediaRecord:
+ case Qt::Key_MediaPause:
+ case Qt::Key_MediaTogglePlayPause:
+ case Qt::Key_LaunchMail:
+ case Qt::Key_Calculator:
+ case Qt::Key_Memo:
+ case Qt::Key_ToDoList:
+ case Qt::Key_Calendar:
+ case Qt::Key_PowerDown:
+ case Qt::Key_ContrastAdjust:
+ case Qt::Key_Standby:
+ case Qt::Key_MonBrightnessUp:
+ case Qt::Key_MonBrightnessDown:
+ case Qt::Key_KeyboardLightOnOff:
+ case Qt::Key_KeyboardBrightnessUp:
+ case Qt::Key_KeyboardBrightnessDown:
+ case Qt::Key_PowerOff:
+ case Qt::Key_WakeUp:
+ case Qt::Key_Eject:
+ case Qt::Key_ScreenSaver:
+ case Qt::Key_WWW:
+ case Qt::Key_Sleep:
+ case Qt::Key_LightBulb:
+ case Qt::Key_Shop:
+ case Qt::Key_History:
+ case Qt::Key_AddFavorite:
+ case Qt::Key_HotLinks:
+ case Qt::Key_BrightnessAdjust:
+ case Qt::Key_Finance:
+ case Qt::Key_Community:
+ case Qt::Key_AudioRewind:
+ case Qt::Key_BackForward:
+ case Qt::Key_ApplicationLeft:
+ case Qt::Key_ApplicationRight:
+ case Qt::Key_Book:
+ case Qt::Key_CD:
+ case Qt::Key_Clear:
+ case Qt::Key_ClearGrab:
+ case Qt::Key_Close:
+ case Qt::Key_Copy:
+ case Qt::Key_Cut:
+ case Qt::Key_Display:
+ case Qt::Key_DOS:
+ case Qt::Key_Documents:
+ case Qt::Key_Excel:
+ case Qt::Key_Explorer:
+ case Qt::Key_Game:
+ case Qt::Key_Go:
+ case Qt::Key_iTouch:
+ case Qt::Key_LogOff:
+ case Qt::Key_Market:
+ case Qt::Key_Meeting:
+ case Qt::Key_MenuKB:
+ case Qt::Key_MenuPB:
+ case Qt::Key_MySites:
+ case Qt::Key_News:
+ case Qt::Key_OfficeHome:
+ case Qt::Key_Option:
+ case Qt::Key_Paste:
+ case Qt::Key_Phone:
+ case Qt::Key_Reply:
+ case Qt::Key_Reload:
+ case Qt::Key_RotateWindows:
+ case Qt::Key_RotationPB:
+ case Qt::Key_RotationKB:
+ case Qt::Key_Save:
+ case Qt::Key_Send:
+ case Qt::Key_Spell:
+ case Qt::Key_SplitScreen:
+ case Qt::Key_Support:
+ case Qt::Key_TaskPane:
+ case Qt::Key_Terminal:
+ case Qt::Key_Tools:
+ case Qt::Key_Travel:
+ case Qt::Key_Video:
+ case Qt::Key_Word:
+ case Qt::Key_Xfer:
+ case Qt::Key_ZoomIn:
+ case Qt::Key_ZoomOut:
+ case Qt::Key_Away:
+ case Qt::Key_Messenger:
+ case Qt::Key_WebCam:
+ case Qt::Key_MailForward:
+ case Qt::Key_Pictures:
+ case Qt::Key_Music:
+ case Qt::Key_Battery:
+ case Qt::Key_Bluetooth:
+ case Qt::Key_WLAN:
+ case Qt::Key_UWB:
+ case Qt::Key_AudioForward:
+ case Qt::Key_AudioRepeat:
+ case Qt::Key_AudioRandomPlay:
+ case Qt::Key_Subtitle:
+ case Qt::Key_AudioCycleTrack:
+ case Qt::Key_Time:
+ case Qt::Key_Select:
+ case Qt::Key_View:
+ case Qt::Key_TopMenu:
+ case Qt::Key_Suspend:
+ case Qt::Key_Hibernate:
+ case Qt::Key_Launch0:
+ case Qt::Key_Launch1:
+ case Qt::Key_Launch2:
+ case Qt::Key_Launch3:
+ case Qt::Key_Launch4:
+ case Qt::Key_Launch5:
+ case Qt::Key_Launch6:
+ case Qt::Key_Launch7:
+ case Qt::Key_Launch8:
+ case Qt::Key_Launch9:
+ case Qt::Key_LaunchA:
+ case Qt::Key_LaunchB:
+ case Qt::Key_LaunchC:
+ case Qt::Key_LaunchD:
+ case Qt::Key_LaunchE:
+ case Qt::Key_LaunchF:
+ case Qt::Key_Shift:
+ case Qt::Key_Control:
+ case Qt::Key_Meta:
+ case Qt::Key_Alt:
+ case Qt::Key_Super_L:
+ case Qt::Key_Super_R:
+ return true;
+
+ default:
+ return false;
+ }
+}
+
+} // namespace
+
void KKeySequenceButton::keyPressEvent(QKeyEvent *e)
{
int keyQt = e->key();
@@ -715,7 +911,7 @@ void KKeySequenceButton::keyPressEvent(QKeyEvent *e)
keyQt = vec.first();
} else if ((keyQt == Qt::Key_Backtab) && (d->modifierKeys & Qt::SHIFT)) {
keyQt = Qt::Key_Tab | d->modifierKeys;
- } else if (KKeyServer::isShiftAsModifierAllowed(keyQt)) {
+ } else if (isShiftAsModifierAllowed(keyQt)) {
keyQt |= d->modifierKeys;
} else {
keyQt |= (d->modifierKeys & ~Qt::SHIFT);