File indexing completed on 2024-05-05 04:50:48

0001 /*
0002  * SPDX-FileCopyrightText: 2022 George Florea Bănuș <georgefb899@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #ifndef ACTIONSMODEL_H
0008 #define ACTIONSMODEL_H
0009 
0010 #include <KLocalizedString>
0011 #include <KSharedConfig>
0012 
0013 #include <QAbstractListModel>
0014 #include <QKeySequence>
0015 #include <QQmlPropertyMap>
0016 #include <QSortFilterProxyModel>
0017 #include <QtQml/qqmlregistration.h>
0018 
0019 struct Action {
0020     QString name;
0021     QString text;
0022     QString iconName;
0023     QString shortcut;
0024     QKeySequence defaultShortcut;
0025     QString description;
0026     QString type = QStringLiteral("NormalAction");
0027 };
0028 
0029 class ProxyActionsModel : public QSortFilterProxyModel
0030 {
0031     Q_OBJECT
0032     QML_NAMED_ELEMENT(ProxyActionsModel)
0033 
0034 public:
0035     explicit ProxyActionsModel(QObject *parent = nullptr);
0036     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
0037 
0038 public Q_SLOTS:
0039     void setNameFilter(const QString &regExp);
0040     void setTypeFilter(const QString &regExp);
0041     bool saveShortcut(int row, const QVariant &shortcut);
0042 
0043 private:
0044     QRegularExpression nameRegExp;
0045     QRegularExpression typeRegExp;
0046 };
0047 
0048 class ActionsModel : public QAbstractListModel
0049 {
0050     Q_OBJECT
0051     QML_NAMED_ELEMENT(ActionsModel)
0052 
0053 public:
0054     explicit ActionsModel(QObject *parent = nullptr);
0055 
0056     enum Roles {
0057         NameRole = Qt::UserRole + 1,
0058         TextRole,
0059         IconRole,
0060         ShortcutRole,
0061         DefaultShortcutRole,
0062         DescriptionRole,
0063         TypeRole,
0064     };
0065 
0066     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0067     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0068     QHash<int, QByteArray> roleNames() const override;
0069     void appendCustomAction(const Action &action);
0070     void editCustomAction(const QString &name, const QString &text, const QString &description);
0071     Q_INVOKABLE bool saveShortcut(const QString &name, const QVariant &shortcut);
0072     Q_INVOKABLE bool saveShortcut(int row, const QVariant &shortcut);
0073     Q_INVOKABLE QString getShortcut(const QString &key, const QKeySequence &defaultValue) const;
0074     Q_INVOKABLE void signalEmitter(const QString &actionName);
0075 
0076     QQmlPropertyMap propertyMap;
0077 
0078     QList<Action> &actions();
0079 
0080 Q_SIGNALS:
0081     void shortcutChanged(const QString &actionName, const QString &actionShortcut);
0082     void openActionsDialogAction();
0083     void aboutHarunaAction();
0084     void audioCycleUpAction();
0085     void audioCycleDownAction();
0086     void configureAction();
0087     void configureShortcutsAction();
0088     void exitFullscreenAction();
0089     void frameStepForwardAction();
0090     void frameStepBackwardAction();
0091     void loadLastPlayedFileAction();
0092     void muteAction();
0093     void openContextMenuAction();
0094     void openFileAction();
0095     void openSubtitlesFileAction();
0096     void openUrlAction();
0097     void playbackSpeedIncreaseAction();
0098     void playbackSpeedDecreaseAction();
0099     void playbackSpeedResetAction();
0100     void playPauseAction();
0101     void playNextAction();
0102     void playPreviousAction();
0103     void quitApplicationAction();
0104     void restartPlaybackAction();
0105     void seekForwardSmallAction();
0106     void seekBackwardSmallAction();
0107     void seekForwardMediumAction();
0108     void seekBackwardMediumAction();
0109     void seekForwardBigAction();
0110     void seekBackwardBigAction();
0111     void seekNextChapterAction();
0112     void seekPreviousChapterAction();
0113     void seekNextSubtitleAction();
0114     void seekPreviousSubtitleAction();
0115     void seekToWatchLaterPositionAction();
0116     void setLoopAction();
0117     void screenshotAction();
0118     void subtitleToggleAction();
0119     void subtitleIncreaseFontSizeAction();
0120     void subtitleDecreaseFontSizeAction();
0121     void subtitleMoveUpAction();
0122     void subtitleMoveDownAction();
0123     void subtitleQuickenAction();
0124     void subtitleDelayAction();
0125     void subtitleCycleUpAction();
0126     void subtitleCycleDownAction();
0127     void toggleDeinterlacingAction();
0128     void toggleFullscreenAction();
0129     void toggleMenuBarAction();
0130     void toggleHeaderAction();
0131     void togglePlaylistAction();
0132     void videoPanXLeftAction();
0133     void videoPanXRightAction();
0134     void videoPanYUpAction();
0135     void videoPanYDownAction();
0136     void volumeUpAction();
0137     void volumeDownAction();
0138     void zoomInAction();
0139     void zoomOutAction();
0140     void zoomResetAction();
0141 
0142     void contrastUpAction();
0143     void contrastDownAction();
0144     void contrastResetAction();
0145     void brightnessUpAction();
0146     void brightnessDownAction();
0147     void brightnessResetAction();
0148     void gammaUpAction();
0149     void gammaDownAction();
0150     void gammaResetAction();
0151     void saturationUpAction();
0152     void saturationDownAction();
0153     void saturationResetAction();
0154 
0155 private:
0156     bool keyConflictMessageBox(const QString &actionText);
0157     KSharedConfig::Ptr m_config;
0158     QList<Action> m_actions;
0159 };
0160 
0161 #endif // ACTIONSMODEL_H