1 /*** 2 3 Olive - Non-Linear Video Editor 4 Copyright (C) 2019 Olive Team 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 19 ***/ 20 21 #ifndef MENUHELPER_H 22 #define MENUHELPER_H 23 24 #include <QObject> 25 #include <QMenuBar> 26 27 #include "ui/menu.h" 28 29 class MenuHelper : public QObject { 30 Q_OBJECT 31 public: 32 void InitializeSharedMenus(); 33 34 /** 35 * @brief Creates a menu of new items that can be created 36 * 37 * Adds the full set of creatable items to a QMenu (e.g. new project, 38 * new sequence, new folder, etc.) 39 * 40 * @param parent 41 * 42 * The menu to add items to. 43 */ 44 void make_new_menu(QMenu* parent); 45 46 /** 47 * @brief Creates a menu of options for working with in/out points 48 * 49 * Adds a set of options for working with sequence/footage in/out points, 50 * e.g. setting in/out points, clearing in/out points, etc. 51 * 52 * @param parent 53 * 54 * The menu to add items to. 55 */ 56 void make_inout_menu(QMenu* parent); 57 58 /** 59 * @brief Creates a menu of clip functions 60 * 61 * Adds a set of clip functions including: 62 * * Add Default Transition 63 * * Link/Unlink 64 * * Enable/Disable 65 * * Nest 66 * 67 * @param parent 68 * 69 * The menu to add items to. 70 */ 71 void make_clip_functions_menu(QMenu* parent); 72 73 /** 74 * @brief Creates standard edit menu (cut, copy, paste, etc.) 75 * 76 * @param parent 77 * 78 * The menu to add items to. 79 * 80 * @param objects_are_selected 81 * 82 * Some extra functions may be hidden in the event no clip is actually selected. Set this to **FALSE** to hide those 83 * functions. 84 */ 85 void make_edit_functions_menu(QMenu* parent, bool objects_are_selected = true); 86 87 /** 88 * @brief Sets the checked state of a menu item based on a Boolean variable. 89 * 90 * Many menu items simply toggle a Boolean variable. This is a convenience function, assuming the QAction's data 91 * variable is a pointer to a Boolean variable, that sets the checked state of the QAction to the enabled state 92 * of the Boolean. Used heavily in functions like toolMenu_About_To_Be_Shown() 93 * 94 * @param a 95 * 96 * The QAction to set the checked state of. 97 */ 98 void set_bool_action_checked(QAction* a); 99 100 /** 101 * @brief Sets the checked state of a menu item based on an integer variable. 102 * 103 * Many menu items simply set a variable to a particular integer. This is a convenience function, assuming the 104 * QAction's data variable is an integer to set a variable to, that sets the checked state of the QAction to 105 * whether the QAction's integer equals the integer variable. Used heavily in functions like 106 * viewMenu_About_To_Be_Shown() 107 * 108 * @param a 109 * 110 * The QAction to set the checked state of 111 * 112 * @param i 113 * 114 * The integer variable to compare the QAction's integer to 115 */ 116 void set_int_action_checked(QAction* a, const int& i); 117 118 /** 119 * @brief Sets the checked state of a menu item based on a QPushButton. 120 * 121 * Some menu items function largely as a proxy to a QPushButton. Assuming the QAction's data variable is a 122 * pointer to a QPushButton, this sets a QAction's checked state to the checked state of the QPushButton. 123 * 124 * @param a 125 */ 126 void set_button_action_checked(QAction* a); 127 128 void Retranslate(); 129 130 static Menu *create_submenu(QMenuBar* parent, 131 const QObject *receiver = nullptr, 132 const char *member = nullptr); 133 static Menu* create_submenu(QMenu* parent); 134 static QAction* create_menu_action(QWidget *parent, 135 const char* id, 136 const QObject *receiver = nullptr, 137 const char *member = nullptr, 138 const QKeySequence &shortcut = 0); 139 140 public slots: 141 142 /** 143 * @brief Sets a QAction's Boolean reference to the opposite of its current value 144 * 145 * Many menu items simply toggle a Boolean variable. This is a convenience function, assuming the QAction's data 146 * variable is a pointer to a Boolean variable, that sets the Boolean variable to the opposite of its current value. 147 */ 148 void toggle_bool_action(); 149 150 /** 151 * @brief Set Title/Action Safe Area from QAction 152 * 153 * A receiver for several Title/Action Safe Area setting items. Assumes the sender() is a QAction with a data 154 * variable as a `double`. The `double` can be the following values: 155 * * NaN (qSNaN()) - Disable Title/Action Safe Area 156 * * 0 - Enable Title/Action Safe Area, default aspect ratio (match current active Sequence's aspect ratio). 157 * * Negative Value - Enable Title/Action Safe Area, any negative number assumes a custom aspect ratio. Will ask 158 * the user to enter an aspect ratio and will use the result. 159 * * Positive Value - Enable Title/Action Safe Area, use value as the aspect ratio. 160 */ 161 void set_titlesafe_from_menu(); 162 163 /** 164 * @brief Set Autoscroll setting from QAction 165 * 166 * Assumes the sender() is a QAction with an integer as its data variable. The data variable should be 167 * `AUTOSCROLL_NO_SCROLL`, `AUTOSCROLL_PAGE_SCROLL` (default) or `AUTOSCROLL_SMOOTH_SCROLL`. 168 */ 169 void set_autoscroll(); 170 171 /** 172 * @brief Clicks a QPushButton referenced by a QAction when triggered. 173 * 174 * Some menu items function largely as a proxy to a QPushButton. Assuming the QAction's data variable is a 175 * pointer to a QPushButton, this triggers a click() event on that QPushButton. 176 */ 177 void menu_click_button(); 178 179 /** 180 * @brief Sets the current timecode setting 181 * 182 * Assumes the sender() is a QAction with an integer as its data variable. The data variable should be 183 * `AUTOSCROLL_NO_AUTOSCROLL`, `AUTOSCROLL_PAGE_AUTOSCROLL` (default) or `AUTOSCROLL_SMOOTH_AUTOSCROLL`. 184 */ 185 void set_timecode_view(); 186 187 /** 188 * @brief Calls open_recent() in Olive::Global using the index from a QAction 189 * 190 * Assumes the sender() is a QAction with an integer as its data variable. The data variable is an index of 191 * the internal auto-recovery project list. 192 */ 193 void open_recent_from_menu(); 194 195 /** 196 * @brief Create a "Paste" action on the specified menu that's enabled only if the clipboard contains effects 197 * 198 * @param menu 199 * 200 * Menu to add action to 201 */ 202 void create_effect_paste_action(QMenu *menu); 203 204 private: 205 QAction* new_project_; 206 QAction* new_sequence_; 207 QAction* new_folder_; 208 209 QAction* set_in_point_; 210 QAction* set_out_point_; 211 QAction* reset_in_point_; 212 QAction* reset_out_point_; 213 QAction* clear_inout_point; 214 215 QAction* add_default_transition_; 216 QAction* link_unlink_; 217 QAction* enable_disable_; 218 QAction* nest_; 219 220 QAction* cut_; 221 QAction* copy_; 222 QAction* paste_; 223 QAction* paste_insert_; 224 QAction* duplicate_; 225 QAction* delete_; 226 QAction* ripple_delete_; 227 QAction* split_; 228 229 private slots: 230 231 232 }; 233 234 namespace olive { 235 /** 236 * @brief A global MenuHelper object to assist menu creation throughout Olive. 237 */ 238 extern MenuHelper MenuHelper; 239 }; 240 241 #endif // MENUHELPER_H 242