File indexing completed on 2024-12-22 04:40:00
0001 /* 0002 SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar> 0003 SPDX-FileCopyrightText: 2010-2022 Mladen Milinkovic <max@smoothware.net> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef USERACTION_H 0009 #define USERACTION_H 0010 0011 #include <QList> 0012 0013 #include <QAction> 0014 #include <QExplicitlySharedDataPointer> 0015 0016 namespace SubtitleComposer { 0017 class Subtitle; 0018 class LinesWidget; 0019 class CurrentLineWidget; 0020 0021 class UserAction : public QObject 0022 { 0023 Q_OBJECT 0024 0025 public: 0026 typedef enum { 0027 SubClosed = 0x1, // Subtitle is not opened 0028 SubOpened = 0x2, // Subtitle is opened 0029 SubTrClosed = 0x4, // Subtitle is not opened 0030 SubTrOpened = 0x8, // Subtitle is opened 0031 SubHasLine = 0x10, // Subtitle opened with, at least, one line 0032 SubHasLines = 0x20, // Subtitle opened with, at least, two lines 0033 SubPDirty = 0x40, // Subtitle opened and has unsaved changes 0034 SubPClean = 0x80, // Subtitle opened or closed without unsaved changes 0035 SubSDirty = 0x100, // Subtitle opened and has unsaved changes 0036 SubSClean = 0x200, // Subtitle opened or closed without unsaved changes 0037 HasSelection = 0x400, // Subtitle opened with, at least, one line selected 0038 VideoClosed = 0x800, 0039 VideoOpened = 0x1000, 0040 VideoStopped = 0x2000, 0041 VideoPlaying = 0x4000, 0042 FullScreenOn = 0x8000, 0043 FullScreenOff = 0x10000, 0044 AnchorsNone = 0x20000, // None of the subtitles is anchored 0045 AnchorsSome = 0x40000, // At least one subtitle is anchored 0046 EditableShowTime = 0x80000, // Selected line's show time is editable 0047 0048 AnchorsMask = AnchorsNone | AnchorsSome | EditableShowTime, 0049 SubtitleMask = SubClosed | SubOpened | SubTrClosed | SubTrOpened | SubPDirty | SubPClean | SubSDirty | SubSClean | SubHasLine | SubHasLines | AnchorsMask, 0050 SelectionMask = HasSelection, 0051 VideoMask = VideoClosed | VideoOpened | VideoStopped | VideoPlaying, 0052 FullScreenMask = FullScreenOn | FullScreenOff, 0053 AllMask = AnchorsMask | SubtitleMask | SelectionMask | VideoMask | FullScreenMask 0054 } EnableFlag; 0055 0056 explicit UserAction(QAction *action, int enableFlags = SubOpened); 0057 0058 QAction * action(); 0059 int enableFlags(); 0060 0061 bool isEnabled(); 0062 void setActionEnabled(bool enabled); 0063 void setContextFlags(int contextFlags); 0064 0065 private: 0066 void updateEnabledState(); 0067 0068 private slots: 0069 void onActionChanged(); 0070 0071 private: 0072 QAction *m_action; 0073 int m_enableFlags; 0074 0075 bool m_actionEnabled; 0076 bool m_contextEnabled; 0077 0078 bool m_ignoreActionEnabledSignal; 0079 }; 0080 0081 class UserActionManager : public QObject 0082 { 0083 Q_OBJECT 0084 0085 public: 0086 static UserActionManager * instance(); 0087 0088 void addAction(QAction *action, int enableFlags = UserAction::SubOpened); 0089 void addAction(UserAction *actionSpec); 0090 void removeAction(UserAction *actionSpec); 0091 0092 public slots: 0093 void setSubtitle(const Subtitle *subtitle = nullptr); 0094 void setLinesWidget(LinesWidget *linesWidget = nullptr); 0095 void setTranslationMode(bool translationMode); 0096 void setFullScreenMode(bool fullScreenMode); 0097 0098 private: 0099 UserActionManager(); 0100 0101 void updateActionsContext(int contextFlags); 0102 0103 private slots: 0104 void onSubtitleLinesChanged(); 0105 void onPrimaryDirtyStateChanged(bool dirty); 0106 void onSecondaryDirtyStateChanged(bool dirty); 0107 void onLinesWidgetSelectionChanged(); 0108 void onPlayerStateChanged(); 0109 void onSubtitleAnchorsChanged(); 0110 0111 private: 0112 QList<UserAction *> m_actionSpecs; 0113 0114 QExplicitlySharedDataPointer<const Subtitle> m_subtitle; 0115 const LinesWidget *m_linesWidget; 0116 bool m_translationMode; 0117 0118 int m_contextFlags; 0119 }; 0120 } 0121 #endif