File indexing completed on 2025-01-26 05:06:23

0001 /*
0002     SPDX-FileCopyrightText: Ken <https://stackoverflow.com/users/1568857/ken>
0003     SPDX-FileCopyrightText: 2016 Leslie Zhai <xiangzhai83@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include <QObject>
0011 
0012 /**
0013  * TODO: ShortCut is a stopgap solution and should be dropped when Qt's StandardKey
0014  * gains support for these actions. QTBUG-54926 https://bugreports.qt.io/browse/QTBUG-54926
0015  * And it is *NOT* encouraged registering C++ types with the QML by using EventFilter
0016  * but for special case QTBUG-40327 https://bugreports.qt.io/browse/QTBUG-40327
0017  *
0018  * ShortCut was copied from Ken's answer.
0019  * https://stackoverflow.com/questions/12192780/assigning-keyboard-shortcuts-to-qml-components
0020  * it uses cc by-sa 3.0 license by default compatible with GPL.
0021  * https://www.gnu.org/licenses/license-list.en.html#ccbysa
0022  */
0023 class ShortCut : public QObject
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     explicit ShortCut(QObject *parent = nullptr);
0029 
0030     Q_INVOKABLE void installAsEventFilterFor(QObject *target = nullptr);
0031 
0032 Q_SIGNALS:
0033     void deleteFile();
0034     void renameFile();
0035     void moveToTrash();
0036     void createFolder();
0037 
0038 protected:
0039     bool eventFilter(QObject *obj, QEvent *e) override;
0040 };