diff options
Diffstat (limited to 'src/kitemviews')
| -rw-r--r-- | src/kitemviews/kfileitemlisttostring.cpp | 82 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemlisttostring.h | 56 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemmodel.cpp | 9 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemmodel.h | 5 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemmodelrolesupdater.cpp | 5 | ||||
| -rw-r--r-- | src/kitemviews/kitemlistcontroller.cpp | 10 | ||||
| -rw-r--r-- | src/kitemviews/kstandarditemlistwidget.cpp | 4 | ||||
| -rw-r--r-- | src/kitemviews/private/kbaloorolesprovider.cpp | 1 | ||||
| -rw-r--r-- | src/kitemviews/private/ktwofingerswipe.cpp | 139 | ||||
| -rw-r--r-- | src/kitemviews/private/ktwofingerswipe.h | 54 | ||||
| -rw-r--r-- | src/kitemviews/private/ktwofingertap.cpp | 122 | ||||
| -rw-r--r-- | src/kitemviews/private/ktwofingertap.h | 48 |
12 files changed, 165 insertions, 370 deletions
diff --git a/src/kitemviews/kfileitemlisttostring.cpp b/src/kitemviews/kfileitemlisttostring.cpp new file mode 100644 index 000000000..8e8f880e9 --- /dev/null +++ b/src/kitemviews/kfileitemlisttostring.cpp @@ -0,0 +1,82 @@ +/* + This file is part of the KDE project + SPDX-FileCopyrightText: 2022 Felix Ernst <[email protected]> + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "kfileitemlisttostring.h" + +#include <KFileItem> +#include <KFileItemListProperties> +#include <KLocalizedString> + +#include <QFontMetrics> +#include <QString> + +QString fileItemListToString(KFileItemList items, int maximumTextWidth, QFontMetrics fontMetrics, ItemsState itemsState) +{ + QString text; + switch (items.count()) { + case 1: + text = i18nc("Textual representation of a file. %1 is the name of the file/folder.", + "\"%1\"", items.first().name()); + break; + case 2: + text = i18nc("Textual representation of two files. %1 and %2 are names of files/folders.", + "\"%1\" and \"%2\"", items.first().name(), items.last().name()); + break; + case 3: + text = i18nc("Textual representation of three files. %1, %2 and %3 are names of files/folders.", + "\"%1\", \"%2\" and \"%3\"", + items.first().name(), items.at(1).name(), items.last().name()); + break; + case 4: + text = i18nc("Textual representation of four files. %1, %2, %3 and %4 are names of files/folders.", + "\"%1\", \"%2\", \"%3\" and \"%4\"", + items.first().name(), items.at(1).name(), items.at(2).name(), items.last().name()); + break; + case 5: + text = i18nc("Textual representation of five files. %1, %2, %3, %4 and %5 are names of files/folders.", + "\"%1\", \"%2\", \"%3\", \"%4\" and \"%5\"", + items.first().name(), items.at(1).name(), items.at(2).name(), items.at(3).name(), items.last().name()); + break; + default: + text = QString(); + break; + } + + // At some point the added clarity from the text starts being less important than the text width. + if (!text.isEmpty() && fontMetrics.horizontalAdvance(text) <= maximumTextWidth) { + return text; + } + + const KFileItemListProperties properties(items); + if (itemsState == Selected) { + if (properties.isFile()) { + text = i18ncp("Textual representation of selected files. %1 is the number of files.", + "One Selected File", "%1 Selected Files", items.count()); + } else if (properties.isDirectory()) { + text = i18ncp("Textual representation of selected folders. %1 is the number of folders.", + "One Selected Folder", "%1 Selected Folders", items.count()); + } else { + text = i18ncp("Textual representation of selected fileitems. %1 is the number of files/folders.", + "One Selected Item", "%1 Selected Items", items.count()); + } + + if (fontMetrics.horizontalAdvance(text) <= maximumTextWidth) { + return text; + } + } + + if (properties.isFile()) { + return i18ncp("Textual representation of files. %1 is the number of files.", + "One File", "%1 Files", items.count()); + } else if (properties.isDirectory()) { + return i18ncp("Textual representation of folders. %1 is the number of folders.", + "One Folder", "%1 Folders", items.count()); + } else { + return i18ncp("Textual representation of fileitems. %1 is the number of files/folders.", + "One Item", "%1 Items", items.count()); + } +} diff --git a/src/kitemviews/kfileitemlisttostring.h b/src/kitemviews/kfileitemlisttostring.h new file mode 100644 index 000000000..7eee0aec9 --- /dev/null +++ b/src/kitemviews/kfileitemlisttostring.h @@ -0,0 +1,56 @@ +/* + This file is part of the KDE project + SPDX-FileCopyrightText: 2022 Felix Ernst <[email protected]> + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef KFILEITEMLISTTOSTRING_H +#define KFILEITEMLISTTOSTRING_H + +class KFileItemList; +class QFontMetrics; +class QString; + +enum ItemsState { + None, + Selected +}; + +/** + * @brief Generates a textual representation of the given list of KFileItems. + * + * This method is especially useful to be very explicit about which items will be affected by an action. + * For example can a label for a delete button be enriched to say "Permanantly Delete `picture1` and `picture2`" + * but also "Permanently Delete 7 Selected Folders" without requiring a huge amount of new translations for this. + * + * Unfortunately this doesn't always work. + * + * For some texts and some languages this wide range of words cannot be inserted into a text while staying + * grammatically correct. Because of this you will probably need to write a fallback for these languages. + * Something like this: + * \code + * // i18n: @action:inmenu menu with actions like copy, paste, rename. + * // %2 is a textual representation of the currently selected files or folders. This can be the name of + * // the file/files like "file1" or "file1, file2 and file3" or an aggregate like "8 Selected Folders". + * // If this sort of word puzzle can not be correctly translated in your language, translate it as "NULL" (without the quotes) + * // and a fallback will be used. + * auto buttonText = i18ncp("@action A more elaborate and clearly worded version of the Delete action", "Permanently Delete %2", "Permanently Delete %2", items.count(), fileItemListToString(items, fontMetrics.averageCharWidth() * 20, fontMetrics)); + * if (buttonText == QStringLiteral("NULL")) { + * buttonText = i18ncp("@action Delete button label. %1 is the number of items to be deleted.", + * "Permanently Delete %1 Item", "Permanently Delete %1 Items", items.count()) + * } + * \endcode + * (The i18n call should be completely in the line following the i18n: comment without any line breaks within the i18n call or the comment might not be correctly extracted. See: https://commits.kde.org/kxmlgui/a31135046e1b3335b5d7bbbe6aa9a883ce3284c1 ) + * + * @param items The KFileItemList for which a QString should be generated. + * @param maximumTextWidth The maximum width/horizontalAdvance the QString should have. Keep scaling in mind. + * @param fontMetrics the fontMetrics for the font that is used to calculate the maximumTextWidth. + * @param itemsState A state of the @p items that should be spelled out in the returned QString. + * @returns the names of the @p items separated by commas if that is below the @p maximumCharacterWidth. + * Otherwise returns something like "5 Files", "8 Selected Folders" or "60 Items" + * while being as specific as possible. + */ +QString fileItemListToString(KFileItemList items, int maximumTextWidth, QFontMetrics fontMetrics, ItemsState itemsState = ItemsState::None); + +#endif // KFILEITEMLISTTOSTRING_H diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 6391d7d3f..641091674 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -15,7 +15,7 @@ #include <KDirLister> #include <KIO/Job> -#include <KIO/kio_version.h> +#include <kio_version.h> #include <KLocalizedString> #include <KLazyLocalizedString> #include <KUrlMimeData> @@ -1580,6 +1580,7 @@ QList<KFileItemModel::ItemData*> KFileItemModel::createItemDataList(const QUrl& void KFileItemModel::prepareItemsForSorting(QList<ItemData*>& itemDataList) { switch (m_sortRole) { + case ExtensionRole: case PermissionsRole: case OwnerRole: case GroupRole: @@ -1801,6 +1802,10 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item, data.insert(sharedValue("text"), item.text()); } + if (m_requestRole[ExtensionRole]) { + data.insert(sharedValue("extension"), QFileInfo(item.name()).suffix()); + } + if (m_requestRole[SizeRole] && !isDir) { data.insert(sharedValue("size"), item.size()); } @@ -2613,6 +2618,7 @@ const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count) { "tags", TagsRole, kli18nc("@label", "Tags"), KLazyLocalizedString(), true, false }, { "comment", CommentRole, kli18nc("@label", "Comment"), KLazyLocalizedString(), true, false }, { "title", TitleRole, kli18nc("@label", "Title"), kli18nc("@label", "Document"), true, true }, + { "author", AuthorRole, kli18nc("@label", "Author"), kli18nc("@label", "Document"), true, true }, { "wordCount", WordCountRole, kli18nc("@label", "Word Count"), kli18nc("@label", "Document"), true, true }, { "lineCount", LineCountRole, kli18nc("@label", "Line Count"), kli18nc("@label", "Document"), true, true }, { "imageDateTime", ImageDateTimeRole, kli18nc("@label", "Date Photographed"), kli18nc("@label", "Image"), true, true }, @@ -2630,6 +2636,7 @@ const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count) { "aspectRatio", AspectRatioRole, kli18nc("@label", "Aspect Ratio"), kli18nc("@label", "Video"), true, true }, { "frameRate", FrameRateRole, kli18nc("@label", "Frame Rate"), kli18nc("@label", "Video"), true, true }, { "path", PathRole, kli18nc("@label", "Path"), kli18nc("@label", "Other"), false, false }, + { "extension", ExtensionRole, kli18nc("@label", "File Extension"), kli18nc("@label", "Other"), false, false }, { "deletiontime", DeletionTimeRole, kli18nc("@label", "Deletion Time"), kli18nc("@label", "Other"), false, false }, { "destination", DestinationRole, kli18nc("@label", "Link Destination"), kli18nc("@label", "Other"), false, false }, { "originUrl", OriginUrlRole, kli18nc("@label", "Downloaded From"), kli18nc("@label", "Other"), true, false }, diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h index cc39a0084..f4c09b6c5 100644 --- a/src/kitemviews/kfileitemmodel.h +++ b/src/kitemviews/kfileitemmodel.h @@ -290,10 +290,10 @@ private: enum RoleType { // User visible roles: NoRole, NameRole, SizeRole, ModificationTimeRole, CreationTimeRole, AccessTimeRole, PermissionsRole, OwnerRole, - GroupRole, TypeRole, DestinationRole, PathRole, DeletionTimeRole, + GroupRole, TypeRole, ExtensionRole, DestinationRole, PathRole, DeletionTimeRole, // User visible roles available with Baloo: CommentRole, TagsRole, RatingRole, DimensionsRole, WidthRole, HeightRole, ImageDateTimeRole, OrientationRole, - WordCountRole, TitleRole, LineCountRole, ArtistRole, GenreRole, AlbumRole, DurationRole, TrackRole, ReleaseYearRole, + WordCountRole, TitleRole, AuthorRole, LineCountRole, ArtistRole, GenreRole, AlbumRole, DurationRole, TrackRole, ReleaseYearRole, BitrateRole, OriginUrlRole, AspectRatioRole, FrameRateRole, // Non-visible roles: IsDirRole, IsLinkRole, IsHiddenRole, IsExpandedRole, IsExpandableRole, ExpandedParentsCountRole, @@ -527,6 +527,7 @@ private: inline bool KFileItemModel::isRoleValueNatural(RoleType roleType) { return (roleType == TypeRole || + roleType == ExtensionRole || roleType == TagsRole || roleType == CommentRole || roleType == TitleRole || diff --git a/src/kitemviews/kfileitemmodelrolesupdater.cpp b/src/kitemviews/kfileitemmodelrolesupdater.cpp index e13b3dedf..d9594de41 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.cpp +++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp @@ -28,6 +28,7 @@ #endif #include <QApplication> +#include <QFileInfo> #include <QIcon> #include <QPainter> #include <QPluginLoader> @@ -1337,6 +1338,10 @@ QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileIte } } + if (m_roles.contains("extension")) { + data.insert("extension", QFileInfo(item.name()).suffix()); + } + if (m_roles.contains("type")) { data.insert("type", item.mimeComment()); } diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 7ef37481d..994812b1f 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -13,10 +13,11 @@ #include "kitemlistview.h" #include "private/kitemlistkeyboardsearchmanager.h" #include "private/kitemlistrubberband.h" -#include "private/ktwofingerswipe.h" -#include "private/ktwofingertap.h" #include "views/draganddrophelper.h" +#include <KTwoFingerSwipe> +#include <KTwoFingerTap> + #include <QAccessible> #include <QApplication> #include <QDrag> @@ -1496,6 +1497,7 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c const bool shiftPressed = modifiers & Qt::ShiftModifier; const bool controlPressed = modifiers & Qt::ControlModifier; + const bool leftClick = buttons & Qt::LeftButton; const bool rightClick = buttons & Qt::RightButton; // The previous selection is cleared if either @@ -1599,8 +1601,8 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c break; case MultiSelection: - if (controlPressed && !shiftPressed) { - // A mouse button press is happening on an item while control is pressed. This either means a user wants to: + if (controlPressed && !shiftPressed && leftClick) { + // A left mouse button press is happening on an item while control is pressed. This either means a user wants to: // - toggle the selection of item(s) or // - they want to begin a drag on the item(s) to copy them. // We rule out the latter, if the item is not clicked directly and was unselected previously. diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp index b531b8641..247581a4e 100644 --- a/src/kitemviews/kstandarditemlistwidget.cpp +++ b/src/kitemviews/kstandarditemlistwidget.cpp @@ -1196,7 +1196,11 @@ QString KStandardItemListWidget::elideRightKeepExtension(const QString &text, in QString ret = m_customizedFontMetrics.elidedText(text.chopped(extensionLength), Qt::ElideRight, elidingWidth - extensionWidth); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) ret.append(text.rightRef(extensionLength)); +#else + ret.append(QStringView(text).right(extensionLength)); +#endif return ret; } } diff --git a/src/kitemviews/private/kbaloorolesprovider.cpp b/src/kitemviews/private/kbaloorolesprovider.cpp index 4c231e2ff..e183a0f9a 100644 --- a/src/kitemviews/private/kbaloorolesprovider.cpp +++ b/src/kitemviews/private/kbaloorolesprovider.cpp @@ -37,6 +37,7 @@ namespace { { Property::Rating, QByteArrayLiteral("rating") }, { Property::Comment, QByteArrayLiteral("comment") }, { Property::Title, QByteArrayLiteral("title") }, + { Property::Author, QByteArrayLiteral("author") }, { Property::WordCount, QByteArrayLiteral("wordCount") }, { Property::LineCount, QByteArrayLiteral("lineCount") }, { Property::Width, QByteArrayLiteral("width") }, diff --git a/src/kitemviews/private/ktwofingerswipe.cpp b/src/kitemviews/private/ktwofingerswipe.cpp deleted file mode 100644 index 6d0e18e65..000000000 --- a/src/kitemviews/private/ktwofingerswipe.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2020 Steffen Hartleib <[email protected]> - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -// Self -#include "ktwofingerswipe.h" - -// Qt -#include <QTouchEvent> -#include <QLineF> - -KTwoFingerSwipeRecognizer::KTwoFingerSwipeRecognizer() : - QGestureRecognizer(), - m_touchBeginnTimestamp(0), - m_gestureAlreadyTriggered(false) -{ -} - -KTwoFingerSwipeRecognizer::~KTwoFingerSwipeRecognizer() -{ -} - -QGesture* KTwoFingerSwipeRecognizer::create(QObject*) -{ - return static_cast<QGesture*>(new KTwoFingerSwipe()); -} - -QGestureRecognizer::Result KTwoFingerSwipeRecognizer::recognize(QGesture* gesture, QObject* watched, QEvent* event) -{ - Q_UNUSED(watched) - - KTwoFingerSwipe* const kTwoFingerSwipe = static_cast<KTwoFingerSwipe*>(gesture); - const QTouchEvent* touchEvent = static_cast<const QTouchEvent*>(event); - - const int maxTimeFrameForSwipe = 90; - const int minDistanceForSwipe = 30; - - switch (event->type()) { - case QEvent::TouchBegin: { - m_touchBeginnTimestamp = touchEvent->timestamp(); - m_gestureAlreadyTriggered = false; - kTwoFingerSwipe->setHotSpot(touchEvent->touchPoints().first().startScreenPos()); - kTwoFingerSwipe->setPos(touchEvent->touchPoints().first().startPos()); - kTwoFingerSwipe->setScreenPos(touchEvent->touchPoints().first().startScreenPos()); - kTwoFingerSwipe->setScenePos(touchEvent->touchPoints().first().startScenePos()); - return MayBeGesture; - } - - case QEvent::TouchUpdate: { - const qint64 now = touchEvent->timestamp(); - const qint64 elapsedTime = now - m_touchBeginnTimestamp; - const QPointF distance = touchEvent->touchPoints().first().startPos() - touchEvent->touchPoints().first().pos(); - kTwoFingerSwipe->setHotSpot(touchEvent->touchPoints().first().startScreenPos()); - kTwoFingerSwipe->setPos(touchEvent->touchPoints().first().startPos()); - kTwoFingerSwipe->setScreenPos(touchEvent->touchPoints().first().startScreenPos()); - kTwoFingerSwipe->setScenePos(touchEvent->touchPoints().first().startScenePos()); - const QLineF ql = QLineF(touchEvent->touchPoints().first().startPos(), touchEvent->touchPoints().first().pos()); - kTwoFingerSwipe->setSwipeAngle(ql.angle()); - - if (touchEvent->touchPoints().size() > 2) { - return CancelGesture; - } - - if (touchEvent->touchPoints().size() == 2) { - if ((elapsedTime) > maxTimeFrameForSwipe) { - return CancelGesture; - } - - if (distance.manhattanLength() >= minDistanceForSwipe && - (elapsedTime) <= maxTimeFrameForSwipe && !m_gestureAlreadyTriggered) { - m_gestureAlreadyTriggered = true; - return FinishGesture; - } else if ((elapsedTime) <= maxTimeFrameForSwipe && !m_gestureAlreadyTriggered) { - return TriggerGesture; - } - } - break; - } - - default: - return Ignore; - } - return Ignore; -} - -KTwoFingerSwipe::KTwoFingerSwipe(QObject* parent) : - QGesture(parent), - m_pos(QPointF(-1, -1)), - m_screenPos(QPointF(-1, -1)), - m_scenePos(QPointF(-1, -1)), - m_swipeAngle(0.0) -{ -} - -KTwoFingerSwipe::~KTwoFingerSwipe() -{ -} - -QPointF KTwoFingerSwipe::pos() const -{ - return m_pos; -} - -void KTwoFingerSwipe::setPos(QPointF _pos) -{ - m_pos = _pos; -} - -QPointF KTwoFingerSwipe::screenPos() const -{ - return m_screenPos; -} - -void KTwoFingerSwipe::setScreenPos(QPointF _screenPos) -{ - m_screenPos = _screenPos; -} - -QPointF KTwoFingerSwipe::scenePos() const -{ - return m_scenePos; -} - -void KTwoFingerSwipe::setScenePos(QPointF _scenePos) -{ - m_scenePos = _scenePos; -} - -qreal KTwoFingerSwipe::swipeAngle() const -{ - return m_swipeAngle; -} - void KTwoFingerSwipe::setSwipeAngle(qreal _swipeAngle) -{ - m_swipeAngle = _swipeAngle; -} - diff --git a/src/kitemviews/private/ktwofingerswipe.h b/src/kitemviews/private/ktwofingerswipe.h deleted file mode 100644 index 6d64d8ff7..000000000 --- a/src/kitemviews/private/ktwofingerswipe.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2020 Steffen Hartleib <[email protected]> - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -#ifndef KTWOFINGERSWIPE_H -#define KTWOFINGERSWIPE_H - -#include "dolphin_export.h" -// Qt -#include <QGesture> -#include <QGestureRecognizer> - -class DOLPHIN_EXPORT KTwoFingerSwipe : public QGesture -{ - Q_OBJECT - Q_PROPERTY(QPointF pos READ pos WRITE setPos) - Q_PROPERTY(QPointF screenPos READ screenPos WRITE setScreenPos) - Q_PROPERTY(QPointF scenePos READ scenePos WRITE setScenePos) - Q_PROPERTY(qreal swipeAngle READ swipeAngle WRITE setSwipeAngle) -public: - explicit KTwoFingerSwipe(QObject* parent = nullptr); - ~KTwoFingerSwipe() override; - QPointF pos() const; - void setPos(QPointF pos); - QPointF screenPos() const; - void setScreenPos(QPointF screenPos); - QPointF scenePos() const; - void setScenePos(QPointF scenePos); - qreal swipeAngle() const; - void setSwipeAngle(qreal swipeAngle); -private: - QPointF m_pos; - QPointF m_screenPos; - QPointF m_scenePos; - qreal m_swipeAngle; -}; - -class DOLPHIN_EXPORT KTwoFingerSwipeRecognizer : public QGestureRecognizer -{ -public: - explicit KTwoFingerSwipeRecognizer(); - ~KTwoFingerSwipeRecognizer() override; - QGesture* create(QObject*) override; - Result recognize(QGesture*, QObject*, QEvent*) override; -private: - Q_DISABLE_COPY( KTwoFingerSwipeRecognizer ) - qint64 m_touchBeginnTimestamp; - bool m_gestureAlreadyTriggered; -}; - -#endif /* KTWOFINGERSWIPE_H */ - diff --git a/src/kitemviews/private/ktwofingertap.cpp b/src/kitemviews/private/ktwofingertap.cpp deleted file mode 100644 index edd9d1d35..000000000 --- a/src/kitemviews/private/ktwofingertap.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2020 Steffen Hartleib <[email protected]> - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -// Self -#include "ktwofingertap.h" - -// Qt -#include <QTouchEvent> -#include <QApplication> -#include <QGraphicsWidget> - -KTwoFingerTapRecognizer::KTwoFingerTapRecognizer() : - QGestureRecognizer(), - m_gestureTriggered(false) -{ -} - -KTwoFingerTapRecognizer::~KTwoFingerTapRecognizer() -{ -} - -QGesture* KTwoFingerTapRecognizer::create(QObject*) -{ - return static_cast<QGesture*>(new KTwoFingerTap()); -} - -QGestureRecognizer::Result KTwoFingerTapRecognizer::recognize(QGesture* gesture, QObject* watched, QEvent* event) -{ - if (qobject_cast<QGraphicsWidget*>(watched)) { - return Ignore; - } - - KTwoFingerTap* const kTwoFingerTap = static_cast<KTwoFingerTap*>(gesture); - const QTouchEvent* touchEvent = static_cast<const QTouchEvent*>(event); - - switch (event->type()) { - case QEvent::TouchBegin: { - kTwoFingerTap->setHotSpot(touchEvent->touchPoints().first().startScreenPos()); - kTwoFingerTap->setPos(touchEvent->touchPoints().first().startPos()); - kTwoFingerTap->setScreenPos(touchEvent->touchPoints().first().startScreenPos()); - kTwoFingerTap->setScenePos(touchEvent->touchPoints().first().startScenePos()); - m_gestureTriggered = false; - return MayBeGesture; - } - - case QEvent::TouchUpdate: { - - if (touchEvent->touchPoints().size() > 2) { - m_gestureTriggered = false; - return CancelGesture; - } - - if (touchEvent->touchPoints().size() == 2) { - if ((touchEvent->touchPoints().first().startPos() - touchEvent->touchPoints().first().pos()).manhattanLength() >= QApplication::startDragDistance()) { - m_gestureTriggered = false; - return CancelGesture; - } - if ((touchEvent->touchPoints().at(1).startPos() - touchEvent->touchPoints().at(1).pos()).manhattanLength() >= QApplication::startDragDistance()) { - m_gestureTriggered = false; - return CancelGesture; - } - if (touchEvent->touchPointStates() & Qt::TouchPointPressed) { - m_gestureTriggered = true; - } - if (touchEvent->touchPointStates() & Qt::TouchPointReleased && m_gestureTriggered) { - m_gestureTriggered = false; - return FinishGesture; - } - } - break; - } - - default: - return Ignore; - } - return Ignore; -} - -KTwoFingerTap::KTwoFingerTap(QObject* parent) : - QGesture(parent), - m_pos(QPointF(-1, -1)), - m_screenPos(QPointF(-1, -1)), - m_scenePos(QPointF(-1, -1)) -{ -} - -KTwoFingerTap::~KTwoFingerTap() -{ -} - -QPointF KTwoFingerTap::pos() const -{ - return m_pos; -} - -void KTwoFingerTap::setPos(QPointF _pos) -{ - m_pos = _pos; -} - -QPointF KTwoFingerTap::screenPos() const -{ - return m_screenPos; -} - -void KTwoFingerTap::setScreenPos(QPointF _screenPos) -{ - m_screenPos = _screenPos; -} - -QPointF KTwoFingerTap::scenePos() const -{ - return m_scenePos; -} - -void KTwoFingerTap::setScenePos(QPointF _scenePos) -{ - m_scenePos = _scenePos; -} diff --git a/src/kitemviews/private/ktwofingertap.h b/src/kitemviews/private/ktwofingertap.h deleted file mode 100644 index 6d409900b..000000000 --- a/src/kitemviews/private/ktwofingertap.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2020 Steffen Hartleib <[email protected]> - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -#ifndef KTWOFINGERTAP_H -#define KTWOFINGERTAP_H - -#include <dolphin_export.h> -// Qt -#include <QGesture> -#include <QGestureRecognizer> - -class DOLPHIN_EXPORT KTwoFingerTap : public QGesture -{ - Q_OBJECT - Q_PROPERTY(QPointF pos READ pos WRITE setPos) - Q_PROPERTY(QPointF screenPos READ screenPos WRITE setScreenPos) - Q_PROPERTY(QPointF scenePos READ scenePos WRITE setScenePos) -public: - explicit KTwoFingerTap(QObject* parent = nullptr); - ~KTwoFingerTap() override; - QPointF pos() const; - void setPos(QPointF pos); - QPointF screenPos() const; - void setScreenPos(QPointF screenPos); - QPointF scenePos() const; - void setScenePos(QPointF scenePos); -private: - QPointF m_pos; - QPointF m_screenPos; - QPointF m_scenePos; -}; - -class DOLPHIN_EXPORT KTwoFingerTapRecognizer : public QGestureRecognizer -{ -public: - explicit KTwoFingerTapRecognizer(); - ~KTwoFingerTapRecognizer() override; - QGesture* create(QObject*) override; - Result recognize(QGesture*, QObject*, QEvent*) override; -private: - Q_DISABLE_COPY(KTwoFingerTapRecognizer) - bool m_gestureTriggered; -}; - -#endif /* KTWOFINGERTAP_H */ |
