1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 /***************************************************************************
8     begin                : Jan 2005
9     copyright            : (C) 2005 by Craig Bradney
10     email                : cbradney@zip.com.au
11  ***************************************************************************/
12 
13 /***************************************************************************
14  *                                                                         *
15  *   This program is free software; you can redistribute it and/or modify  *
16  *   it under the terms of the GNU General Public License as published by  *
17  *   the Free Software Foundation; either version 2 of the License, or     *
18  *   (at your option) any later version.                                   *
19  *                                                                         *
20  ***************************************************************************/
21 #ifndef ACTIONMANAGER_H
22 #define ACTIONMANAGER_H
23 
24 #include <QKeySequence>
25 #include <QObject>
26 #include <QString>
27 #include <QStringList>
28 #include <QMap>
29 #include <QPair>
30 #include <QVector>
31 #include <QPointer>
32 #include <QMultiHash>
33 #include <QPixmap>
34 #include <QActionGroup>
35 
36 class QEvent;
37 
38 #include "scribusapi.h"
39 #include "scraction.h"
40 
41 class IconManager;
42 class ScribusDoc;
43 class ScribusMainWindow;
44 class ScribusQApp;
45 class ScribusView;
46 class UndoManager;
47 /**
48 @author Craig Bradney
49 */
50 class SCRIBUS_API ActionManager : public QObject
51 {
52 	Q_OBJECT
53 
54 	friend class StoryEditor;
55 	public:
56 		ActionManager ( QObject * parent );
57 		~ActionManager() override;
58 
59 		virtual void changeEvent(QEvent *e);
60 
61 		void init(ScribusMainWindow *);
62 		bool compareKeySeqToShortcut(const QKeySequence& ks, const QString& actionName);
63 		bool compareKeySeqToShortcut(int k, Qt::KeyboardModifiers km, const QString& actionName);
64 		static void createDefaultShortcuts();
defaultShortcuts()65 		static QMap<QString, QKeySequence>* defaultShortcuts() {return &defKeys;}
66 		static void createDefaultMenus();
67 		static void createDefaultMenuNames();
68 		static void createDefaultNonMenuActions();
69 		static void createDefaultNonMenuNames();
defaultMenuNames()70 		static QVector< QPair<QString, QStringList> >* defaultMenuNames() {return &defMenuNames;}
defaultNonMenuNames()71 		static QVector< QPair<QString, QStringList> >* defaultNonMenuNames() {return &defNonMenuNames;}
72 		static QString defaultMenuNameEntryTranslated(const QString& index);
defaultMenus()73 		static QVector< QPair<QString, QStringList> >* defaultMenus() {return &defMenus;}
defaultNonMenuActions()74 		static QVector< QPair<QString, QStringList> >* defaultNonMenuActions() {return &defNonMenuActions;}
75 		void createActions();
76 		void disconnectModeActions();
77 		void connectModeActions();
78 		void disconnectNewViewActions();
79 		void connectNewViewActions(ScribusView *);
80 		void disconnectNewDocActions();
81 		void connectNewDocActions(ScribusDoc *);
82 		void disconnectNewSelectionActions();
83 		void connectNewSelectionActions(ScribusView *,ScribusDoc *);
84 		void saveActionShortcutsPreEditMode();
85 		void restoreActionShortcutsPostEditMode();
86 		void enableActionStringList(QMap<QString, QPointer<ScrAction> > *actionMap, QStringList *list, bool enabled, bool checkingUnicode=false, const QString& fontName=QString());
87 		void enableUnicodeActions(QMap<QString, QPointer<ScrAction> > *actionMap, bool enabled, const QString& fontName=QString());
88 		void setPDFActions(ScribusView *);
89 
90 	public slots:
91 		void languageChange();
92 		void handleMultipleSelections();
93 
94 	private:
95 		void initFileMenuActions();
96 		void initEditMenuActions();
97 		void initStyleMenuActions();
98 		void initItemMenuActions();
99 		void initInsertMenuActions();
100 		void initPageMenuActions();
101 		void initTableMenuActions();
102 		void initViewMenuActions();
103 		void initToolsMenuActions();
104 		void initExtrasMenuActions();
105 		void initWindowsMenuActions();
106 		void initScriptMenuActions();
107 		void initHelpMenuActions();
108 		static void initUnicodeActions(QMap<QString, QPointer<ScrAction> > *actionMap, QWidget *actionParent, QStringList *actionNamesList);
109 		void initSpecialActions();
110 		static void setActionTooltips(QMap<QString, QPointer<ScrAction> > *actionMap);
111 		static void languageChangeUnicodeActions(QMap<QString, QPointer<ScrAction> > *actionMap);
112 		void languageChangeActions();
113 		static QKeySequence defaultKey(const QString &actionName);
114 
115 		QPixmap noIcon;
116 		ScribusMainWindow *mainWindow {nullptr};
117 		UndoManager *undoManager {nullptr};
118 		IconManager& im;
119 		QMap<QString, QPointer<ScrAction> > *scrActions {nullptr};
120 		QMultiHash<QString, QActionGroup*> *scrActionGroups {nullptr};
121 		QStringList *modeActionNames {nullptr};
122 		QStringList *nonEditActionNames {nullptr};
123 		QStringList *unicodeCharActionNames {nullptr};
124 		static QMap<QString, QKeySequence> defKeys;
125 		static QVector< QPair<QString, QStringList> > defMenuNames;
126 		static QVector< QPair<QString, QStringList> > defMenus;
127 		static QVector< QPair<QString, QStringList> > defNonMenuNames;
128 		static QVector< QPair<QString, QStringList> > defNonMenuActions;
129 };
130 
131 #endif
132