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

0001 /*
0002     SPDX-FileCopyrightText: 2021 Derek Christ <christ.derek@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <KActionCollection>
0010 #include <QAction>
0011 #include <QPointer>
0012 
0013 /**
0014  * A QAction that manages the delete based on the current state of
0015  * the Shift key or the parameter passed to update.
0016  *
0017  * This class expects the presence of both the "del" and
0018  * "trash" actions in @ref collection.
0019  */
0020 class RemoveAction : public QAction
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     explicit RemoveAction(KActionCollection *collection, QObject *parent = nullptr);
0026 
0027     enum class ShiftState { Unknown, Pressed, Released };
0028 
0029     /**
0030      * Updates this action key based on @p shiftState.
0031      * Default value is Unknown, meaning it will query QGuiApplication::modifiers().
0032      */
0033     void update(ShiftState shiftState = ShiftState::Unknown);
0034 
0035     /**
0036      * Returns the current action that RemoveAction performs.
0037      */
0038     const QAction *proxyAction() const;
0039 
0040 protected:
0041     bool eventFilter(QObject *watched, QEvent *event) override;
0042 
0043 private:
0044     QPointer<KActionCollection> m_collection;
0045     QPointer<QAction> m_action;
0046 };