1 /******************************************************************************************************* 2 DkActionManager.h 3 Created on: 28.10.2015 4 5 nomacs is a fast and small image viewer with the capability of synchronizing multiple instances 6 7 Copyright (C) 2011-2015 Markus Diem <markus@nomacs.org> 8 Copyright (C) 2011-2015 Stefan Fiel <stefan@nomacs.org> 9 Copyright (C) 2011-2015 Florian Kleber <florian@nomacs.org> 10 11 This file is part of nomacs. 12 13 nomacs is free software: you can redistribute it and/or modify 14 it under the terms of the GNU General Public License as published by 15 the Free Software Foundation, either version 3 of the License, or 16 (at your option) any later version. 17 18 nomacs is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 GNU General Public License for more details. 22 23 You should have received a copy of the GNU General Public License 24 along with this program. If not, see <http://www.gnu.org/licenses/>. 25 26 *******************************************************************************************************/ 27 28 #pragma once 29 30 #include "DkManipulators.h" 31 #include "DkBaseWidgets.h" 32 33 #pragma warning(push, 0) // no warnings from includes - begin 34 #include <QObject> 35 #include <QAction> 36 #pragma warning(pop) // no warnings from includes - end 37 38 #ifndef DllCoreExport 39 #ifdef DK_CORE_DLL_EXPORT 40 #define DllCoreExport Q_DECL_EXPORT 41 #elif DK_DLL_IMPORT 42 #define DllCoreExport Q_DECL_IMPORT 43 #else 44 #define DllCoreExport Q_DECL_IMPORT 45 #endif 46 #endif 47 48 #pragma warning(disable: 4251) // TODO: remove 49 50 // Qt defines 51 class QMenu; 52 class QMainWindow; 53 class QWinTaskbarProgress; 54 class QProgressDialog; 55 56 namespace nmc { 57 58 // nomacs defines 59 class DkTcpMenu; 60 class DkPluginActionManager; 61 62 class DllCoreExport DkAppManager : public QObject { 63 Q_OBJECT 64 65 public: 66 DkAppManager(QWidget* parent = 0); 67 ~DkAppManager(); 68 69 void setActions(QVector<QAction* > actions); 70 QVector<QAction* > getActions() const; 71 QAction* createAction(const QString& filePath); 72 QAction* findAction(const QString& appPath) const; 73 74 enum defaultAppIdx { 75 76 app_photohsop, 77 app_picasa, 78 app_picasa_viewer, 79 app_irfan_view, 80 app_explorer, 81 82 app_idx_end 83 }; 84 85 public slots: 86 void openTriggered() const; 87 88 signals: 89 void openFileSignal(QAction* action) const; 90 91 protected: 92 void saveSettings() const; 93 void loadSettings(); 94 void assignIcon(QAction* app) const; 95 bool containsApp(QVector<QAction* > apps, const QString& appName) const; 96 97 QString searchForSoftware(const QString& organization, const QString& application, const QString& pathKey = "", const QString& exeName = "") const; 98 void findDefaultSoftware(); 99 100 QVector<QString> mDefaultNames; 101 QVector<QAction* > mApps; 102 bool mFirstTime = true; 103 }; 104 105 class DllCoreExport DkActionManager { 106 107 public: 108 static DkActionManager& instance(); 109 ~DkActionManager(); 110 111 // singleton 112 DkActionManager(DkActionManager const&) = delete; 113 void operator=(DkActionManager const&) = delete; 114 115 enum FileMenuActions { 116 menu_file_open, 117 menu_file_open_dir, 118 menu_file_open_list, 119 menu_file_quick_launch, 120 menu_file_app_manager, 121 menu_file_save, 122 menu_file_save_as, 123 menu_file_save_copy, 124 menu_file_save_list, 125 menu_file_save_web, 126 menu_file_rename, 127 menu_file_goto, 128 menu_file_find, 129 menu_file_recursive, 130 menu_file_show_recent, 131 menu_file_print, 132 menu_file_reload, 133 menu_file_next, 134 menu_file_prev, 135 menu_file_new_instance, 136 menu_file_private_instance, 137 menu_file_exit, 138 139 menu_file_end, // nothing beyond this point 140 }; 141 142 enum SortMenuActions { 143 144 menu_sort_filename, 145 menu_sort_date_created, 146 menu_sort_date_modified, 147 menu_sort_random, 148 menu_sort_ascending, 149 menu_sort_descending, 150 151 menu_sort_end, 152 }; 153 154 enum EditMenuActions { 155 menu_edit_image, 156 menu_edit_rotate_cw, 157 menu_edit_rotate_ccw, 158 menu_edit_rotate_180, 159 menu_edit_undo, 160 menu_edit_redo, 161 menu_edit_copy, 162 menu_edit_copy_buffer, 163 menu_edit_copy_color, 164 menu_edit_paste, 165 menu_edit_shortcuts, 166 menu_edit_preferences, 167 menu_edit_transform, 168 menu_edit_delete, 169 menu_edit_crop, 170 171 menu_edit_end, // nothing beyond this point 172 }; 173 174 enum ToolsMenuActions { 175 menu_tools_thumbs, 176 menu_tools_filter, 177 menu_tools_export_tiff, 178 menu_tools_extract_archive, 179 menu_tools_mosaic, 180 menu_tools_batch, 181 menu_tools_wallpaper, 182 menu_tools_train_format, 183 184 menu_tools_end, 185 }; 186 187 enum PanelMenuActions { 188 menu_panel_toggle, 189 190 menu_panel_menu, 191 menu_panel_toolbar, 192 menu_panel_statusbar, 193 menu_panel_transfertoolbar, 194 195 menu_panel_player, 196 menu_panel_preview, 197 menu_panel_thumbview, 198 menu_panel_scroller, 199 menu_panel_exif, 200 menu_panel_info, 201 menu_panel_histogram, 202 menu_panel_overview, 203 menu_panel_explorer, 204 menu_panel_metadata_dock, 205 menu_panel_comment, 206 menu_panel_history, 207 menu_panel_log, 208 209 menu_panel_end, 210 }; 211 212 enum ViewMenuActions { 213 menu_view_fullscreen, 214 menu_view_reset, 215 menu_view_100, 216 menu_view_fit_frame, 217 menu_view_zoom_in, 218 menu_view_zoom_out, 219 menu_view_anti_aliasing, 220 menu_view_tp_pattern, 221 menu_view_frameless, 222 223 menu_view_new_tab, 224 menu_view_close_tab, 225 menu_view_close_all_tabs, 226 menu_view_first_tab, 227 menu_view_previous_tab, 228 menu_view_goto_tab, 229 menu_view_next_tab, 230 menu_view_last_tab, 231 232 menu_view_opacity_up, 233 menu_view_opacity_down, 234 menu_view_opacity_an, 235 menu_view_opacity_change, 236 menu_view_lock_window, 237 menu_view_gps_map, 238 menu_view_slideshow, 239 menu_view_movie_pause, 240 menu_view_movie_next, 241 menu_view_movie_prev, 242 243 menu_view_monitors, // frameless only 244 245 menu_view_end, // nothing beyond this point 246 }; 247 248 enum SyncMenuActions { 249 menu_sync_view, 250 menu_sync_pos, 251 menu_sync_arrange, 252 menu_sync_connect_all, 253 menu_sync_all_actions, 254 255 menu_sync_end, // nothing beyond this point 256 }; 257 258 enum PluginMenuActions { 259 menu_plugin_manager, 260 261 menu_plugins_end, // nothing beyond this point 262 }; 263 264 enum HelpMenuActions{ 265 menu_help_update, 266 menu_help_update_translation, 267 menu_help_bug, 268 menu_help_documentation, 269 menu_help_about, 270 271 menu_help_end, // nothing beyond this point 272 }; 273 274 enum HiddenActions { 275 sc_test_img, 276 sc_test_rec, 277 sc_test_pong, 278 279 sc_first_file, 280 sc_last_file, 281 sc_skip_prev, 282 sc_skip_next, 283 sc_skip_next_sync, 284 sc_skip_prev_sync, 285 sc_first_file_sync, 286 sc_last_file_sync, 287 sc_delete_silent, 288 289 sc_star_rating_0, 290 sc_star_rating_1, 291 sc_star_rating_2, 292 sc_star_rating_3, 293 sc_star_rating_4, 294 sc_star_rating_5, 295 296 sc_pan_up, 297 sc_pan_down, 298 sc_pan_left, 299 sc_pan_right, 300 301 sc_end, // nothing beyond this point 302 }; 303 304 enum PreviewActions { 305 preview_select_all, 306 preview_zoom_in, 307 preview_zoom_out, 308 preview_display_squares, 309 preview_show_labels, 310 preview_copy, 311 preview_paste, 312 preview_rename, 313 preview_delete, 314 preview_filter, 315 preview_batch, 316 preview_print, 317 318 actions_end 319 }; 320 321 enum FileIcons { 322 icon_file_prev, 323 icon_file_next, 324 icon_file_dir, 325 icon_file_open, 326 icon_file_open_large, 327 icon_file_dir_large, 328 icon_file_save, 329 icon_file_print, 330 icon_file_filter, 331 icon_file_find, 332 333 icon_file_end, // nothing beyond this point 334 }; 335 336 enum EditIcons { 337 icon_edit_image, 338 icon_edit_rotate_cw, 339 icon_edit_rotate_ccw, 340 icon_edit_crop, 341 icon_edit_resize, 342 icon_edit_copy, 343 icon_edit_paste, 344 icon_edit_delete, 345 346 icon_edit_end, // nothing beyond this point 347 }; 348 349 enum ViewIcons { 350 icon_view_fullscreen, 351 icon_view_reset, 352 icon_view_100, 353 icon_view_gps, 354 icon_view_movie_play, 355 icon_view_movie_prev, 356 icon_view_movie_next, 357 icon_view_zoom_in, 358 icon_view_zoom_out, 359 360 icon_view_end, // nothing beyond this point 361 }; 362 363 // default nomacs shortcuts 364 // keyboard shortcuts 365 enum Shortcuts { 366 367 // general 368 shortcut_esc = Qt::Key_Escape, 369 370 // file 371 shortcut_open_preview = Qt::Key_T, 372 shortcut_open_thumbview = Qt::SHIFT + Qt::Key_T, 373 shortcut_open_dir = Qt::CTRL + Qt::SHIFT + Qt::Key_O, 374 shortcut_app_manager = Qt::CTRL + Qt::Key_M, 375 shortcut_save_as = Qt::CTRL + Qt::SHIFT + Qt::Key_S, 376 shortcut_first_file = Qt::Key_Home, 377 shortcut_last_file = Qt::Key_End, 378 shortcut_skip_prev = Qt::Key_PageUp, 379 shortcut_skip_next = Qt::Key_PageDown, 380 shortcut_prev_file = Qt::Key_Left, 381 shortcut_next_file = Qt::Key_Right, 382 shortcut_rename = Qt::Key_F2, 383 shortcut_goto = Qt::CTRL + Qt::Key_G, 384 shortcut_extract = Qt::CTRL + Qt::Key_E, 385 shortcut_reload = Qt::Key_F5, 386 387 shortcut_first_file_sync= Qt::ALT + Qt::Key_Home, 388 shortcut_last_file_sync = Qt::ALT + Qt::Key_End, 389 shortcut_skip_prev_sync = Qt::ALT + Qt::Key_Left, 390 shortcut_skip_next_sync = Qt::ALT + Qt::Key_Right, 391 392 shortcut_star_rating_0 = Qt::Key_0, 393 shortcut_star_rating_1 = Qt::Key_1, 394 shortcut_star_rating_2 = Qt::Key_2, 395 shortcut_star_rating_3 = Qt::Key_3, 396 shortcut_star_rating_4 = Qt::Key_4, 397 shortcut_star_rating_5 = Qt::Key_5, 398 399 // view 400 shortcut_new_tab = Qt::CTRL + Qt::Key_T, 401 shortcut_close_tab = Qt::CTRL + Qt::Key_W, 402 shortcut_next_tab = Qt::CTRL + Qt::Key_Tab, 403 shortcut_previous_tab = Qt::CTRL + Qt::SHIFT + Qt::Key_Tab, 404 shortcut_show_toolbar = Qt::CTRL + Qt::Key_B, 405 shortcut_show_statusbar = Qt::CTRL + Qt::Key_I, 406 shortcut_full_screen_ad = Qt::CTRL + Qt::Key_L, 407 shortcut_show_transfer = Qt::CTRL + Qt::Key_U, 408 #ifdef Q_OS_MAC 409 shortcut_full_screen_ff = Qt::CTRL + Qt::Key_F, 410 shortcut_frameless = Qt::CTRL + Qt::Key_R, 411 #else 412 shortcut_full_screen_ff = Qt::Key_F11, 413 shortcut_frameless = Qt::Key_F10, 414 #endif 415 shortcut_reset_view = Qt::CTRL + Qt::Key_0, 416 shortcut_zoom_full = Qt::CTRL + Qt::Key_1, 417 shortcut_fit_frame = Qt::CTRL + Qt::Key_2, 418 shortcut_show_overview = Qt::Key_O, 419 shortcut_show_explorer = Qt::Key_E, 420 shortcut_show_metadata_dock = Qt::ALT + Qt::Key_M, 421 shortcut_show_history = Qt::CTRL + Qt::SHIFT + Qt::Key_H, 422 shortcut_show_log = Qt::CTRL + Qt::ALT + Qt::Key_L, 423 shortcut_view_slideshow = Qt::Key_Space, 424 shortcut_show_player = Qt::Key_P, 425 shortcut_show_exif = Qt::Key_M, 426 shortcut_show_info = Qt::Key_I, 427 shortcut_show_histogram = Qt::Key_H, 428 shortcut_show_comment = Qt::Key_N, 429 shortcut_opacity_down = Qt::CTRL + Qt::Key_J, 430 shortcut_opacity_up = Qt::CTRL + Qt::SHIFT + Qt::Key_J, 431 shortcut_opacity_change = Qt::ALT + Qt::SHIFT + Qt::Key_J, 432 shortcut_an_opacity = Qt::ALT + Qt::Key_J, 433 shortcut_new_instance = Qt::CTRL + Qt::Key_N, 434 shortcut_private_instance = Qt::CTRL + Qt::ALT + Qt::Key_N, 435 shortcut_tp_pattern = Qt::Key_B, 436 shortcut_anti_aliasing = Qt::Key_A, 437 shortcut_lock_window = Qt::CTRL + Qt::SHIFT + Qt::ALT + Qt::Key_B, 438 shortcut_recent_files = Qt::CTRL + Qt::Key_H, 439 shortcut_toggle_panels = Qt::Key_F, 440 441 // hidden viewport shortcuts 442 shortcut_pan_left = Qt::CTRL + Qt::Key_Left, 443 shortcut_pan_right = Qt::CTRL + Qt::Key_Right, 444 shortcut_pan_up = Qt::CTRL + Qt::Key_Up, 445 shortcut_pan_down = Qt::CTRL + Qt::Key_Down, 446 447 shortcut_zoom_in = Qt::Key_Plus, 448 shortcut_zoom_out = Qt::Key_Minus, 449 shortcut_zoom_in_alt = Qt::Key_Up, 450 shortcut_zoom_out_alt = Qt::Key_Down, 451 452 // edit 453 shortcut_edit_image = Qt::Key_D, 454 shortcut_rotate_cw = Qt::Key_R, 455 shortcut_rotate_ccw = Qt::SHIFT + Qt::Key_R, 456 shortcut_transform = Qt::CTRL + Qt::Key_R, 457 shortcut_manipulation = Qt::CTRL + Qt::SHIFT + Qt::Key_M, 458 shortcut_paste = Qt::Key_Insert, 459 shortcut_delete_silent = Qt::SHIFT + Qt::Key_Delete, 460 shortcut_crop = Qt::Key_C, 461 shortcut_copy_buffer = Qt::CTRL + Qt::SHIFT + Qt::Key_C, 462 shortcut_copy_color = Qt::CTRL + Qt::ALT + Qt::Key_C, 463 464 // tools 465 shortcut_batch_processing = Qt::CTRL + Qt::SHIFT + Qt::Key_B, 466 467 // tcp 468 shortcut_shortcuts = Qt::CTRL + Qt::Key_K, 469 shortcut_settings = Qt::CTRL + Qt::SHIFT + Qt::Key_P, 470 shortcut_sync = Qt::CTRL + Qt::Key_D, 471 shortcut_tab = Qt::ALT + Qt::Key_O, 472 shortcut_arrange = Qt::ALT + Qt::Key_A, 473 shortcut_send_img = Qt::ALT + Qt::Key_I, 474 shortcut_connect_all = Qt::CTRL + Qt::Key_A, 475 476 // help 477 shortcut_show_help = Qt::Key_F1, 478 479 // eggs 480 shortcut_test_pong = Qt::CTRL + Qt::SHIFT + Qt::ALT + Qt::Key_P, 481 shortcut_test_img = Qt::CTRL + Qt::SHIFT + Qt::ALT + Qt::Key_L, 482 shortcut_test_rec = Qt::CTRL + Qt::SHIFT + Qt::ALT + Qt::Key_R, 483 }; 484 485 QMenu* updateOpenWithMenu(); 486 487 QMenu* fileMenu() const; 488 QMenu* sortMenu() const; 489 QMenu* openWithMenu() const; 490 QMenu* viewMenu() const; 491 QMenu* editMenu() const; 492 QMenu* manipulatorMenu() const; 493 QMenu* toolsMenu() const; 494 QMenu* panelMenu() const; 495 QMenu* helpMenu() const; 496 QMenu* contextMenu() const; 497 QMenu* syncMenu() const; 498 DkTcpMenu* localMenu() const; 499 500 DkManipulatorManager manipulatorManager() const; 501 502 void createActions(QWidget* parent); 503 void createMenus(QWidget* parent); 504 505 QAction* action(FileMenuActions action) const; 506 QAction* action(SortMenuActions action) const; 507 QAction* action(ViewMenuActions action) const; 508 QAction* action(EditMenuActions action) const; 509 QAction* action(ToolsMenuActions action) const; 510 QAction* action(PanelMenuActions action) const; 511 QAction* action(SyncMenuActions action) const; 512 QAction* action(PluginMenuActions action) const; 513 QAction* action(HelpMenuActions action) const; 514 QAction* action(HiddenActions action) const; 515 QAction* action(PreviewActions action) const; 516 517 QIcon icon(FileIcons icon) const; 518 QIcon icon(ViewIcons icon) const; 519 QIcon icon(EditIcons icon) const; 520 521 QVector<QAction *> fileActions() const; 522 QVector<QAction *> sortActions() const; 523 QVector<QAction *> openWithActions() const; 524 QVector<QAction *> viewActions() const; 525 QVector<QAction *> editActions() const; 526 QVector<QAction *> toolsActions() const; 527 QVector<QAction *> panelActions() const; 528 QVector<QAction *> syncActions() const; 529 QVector<QAction *> pluginActions() const; 530 QVector<QAction *> helpActions() const; 531 QVector<QAction *> previewActions() const; 532 QVector<QAction *> manipulatorActions() const; 533 534 QVector<QAction *> allActions() const; 535 536 QVector<QAction*> hiddenActions() const; 537 DkAppManager* appManager() const; 538 DkPluginActionManager* pluginActionManager() const; 539 540 void assignCustomShortcuts(QVector<QAction*> actions) const; 541 542 void enableImageActions(bool enable = true) const; 543 void enableMovieActions(bool enable = true) const; 544 545 protected: 546 DkActionManager(); 547 548 void init(); 549 void createIcons(); 550 551 QMenu* createFileMenu(QWidget* parent); 552 QMenu* createSortMenu(QWidget* parent); 553 QMenu* createOpenWithMenu(QWidget* parent); 554 QMenu* createViewMenu(QWidget* parent); 555 QMenu* createEditMenu(QWidget* parent); 556 QMenu* createManipulatorMenu(QWidget* parent); 557 QMenu* createToolsMenu(QWidget* parent); 558 QMenu* createPanelMenu(QWidget* parent); 559 QMenu* createHelpMenu(QWidget* parent); 560 QMenu* createContextMenu(QWidget* parent); 561 QMenu* createSyncMenu(QWidget* parent); 562 563 // actions 564 QVector<QAction *> mFileActions; 565 QVector<QAction *> mSortActions; 566 QVector<QAction *> mEditActions; 567 QVector<QAction *> mToolsActions; 568 QVector<QAction *> mPanelActions; 569 QVector<QAction *> mViewActions; 570 QVector<QAction *> mSyncActions; 571 QVector<QAction *> mPluginActions; 572 QVector<QAction *> mHelpActions; 573 QVector<QAction *> mPreviewActions; 574 575 QVector<QAction *> mHiddenActions; 576 577 DkManipulatorManager mManipulators; 578 579 // dynamic menus 580 QMenu* mFileMenu = 0; 581 QMenu* mOpenWithMenu = 0; 582 QMenu* mSortMenu = 0; 583 QMenu* mViewMenu = 0; 584 QMenu* mEditMenu = 0; 585 QMenu* mManipulatorMenu = 0; 586 QMenu* mToolsMenu = 0; 587 QMenu* mPanelMenu = 0; 588 QMenu* mHelpMenu = 0; 589 QMenu* mContextMenu = 0; 590 591 // sync 592 QMenu* mSyncMenu = 0; 593 DkTcpMenu* mLocalMenu = 0; 594 595 // icons 596 QVector<QIcon> mFileIcons; 597 QVector<QIcon> mEditIcons; 598 QVector<QIcon> mViewIcons; 599 QVector<QIcon> mToolsIcons; 600 601 DkAppManager* mAppManager = 0; 602 DkPluginActionManager* mPluginManager = 0; 603 604 QSharedPointer<DkActionManager> inst; 605 }; 606 607 class DllCoreExport DkGlobalProgress : public DkWidget { 608 Q_OBJECT 609 610 public: 611 static DkGlobalProgress& instance(); 612 ~DkGlobalProgress(); 613 614 // singleton 615 DkGlobalProgress(DkGlobalProgress const&) = delete; 616 void operator=(DkGlobalProgress const&) = delete; 617 618 619 QObject* progressObject() const; 620 void start(); 621 void stop(); 622 623 #ifdef Q_OS_WIN 624 void setProgressBar(QWinTaskbarProgress* progressbar); 625 QWinTaskbarProgress* progressBar(); 626 #else 627 QProgressDialog* progressBar() const; 628 #endif 629 630 public slots: 631 void setProgressValue(int value); 632 633 private: 634 DkGlobalProgress(); 635 636 QSharedPointer<DkGlobalProgress> inst; 637 bool showProgress; 638 639 #ifdef Q_OS_WIN 640 QWinTaskbarProgress* mProgress = 0; 641 #else 642 QProgressDialog* mProgress = 0; 643 #endif 644 }; 645 646 647 } 648