From 92d75c496373bd830778f68eab5780f9e21c6216 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 11 Jul 2020 12:22:01 -0700 Subject: [PATCH] Support assigning shortcuts to toolbars. Fixes #463. --- common/lc_commands.cpp | 49 ++++++++++++++++++++++++ common/lc_commands.h | 9 +++++ common/lc_mainwindow.cpp | 81 +++++++++++++++++++++++++++++++++------- common/lc_mainwindow.h | 2 + 4 files changed, 127 insertions(+), 14 deletions(-) diff --git a/common/lc_commands.cpp b/common/lc_commands.cpp index bb6e46b2..21f79ff9 100644 --- a/common/lc_commands.cpp +++ b/common/lc_commands.cpp @@ -1018,6 +1018,55 @@ lcCommand gCommands[LC_NUM_COMMANDS] = QT_TRANSLATE_NOOP("Status", "Reset all views"), "" }, + // LC_VIEW_TOOLBAR_STANDARD + { + QT_TRANSLATE_NOOP("Action", "View.Toolbars.Standard"), + QT_TRANSLATE_NOOP("Menu", "Standard"), + QT_TRANSLATE_NOOP("Status", "Toggle the Standard Toolbar"), + "" + }, + // LC_VIEW_TOOLBAR_TOOLS + { + QT_TRANSLATE_NOOP("Action", "View.Toolbars.Tools"), + QT_TRANSLATE_NOOP("Menu", "Tools"), + QT_TRANSLATE_NOOP("Status", "Toggle the Tools Toolbar"), + "" + }, + // LC_VIEW_TOOLBAR_TIME + { + QT_TRANSLATE_NOOP("Action", "View.Toolbars.Time"), + QT_TRANSLATE_NOOP("Menu", "Time"), + QT_TRANSLATE_NOOP("Status", "Toggle the Time Toolbar"), + "" + }, + // LC_VIEW_TOOLBAR_PARTS + { + QT_TRANSLATE_NOOP("Action", "View.Toolbars.Parts"), + QT_TRANSLATE_NOOP("Menu", "Parts"), + QT_TRANSLATE_NOOP("Status", "Toggle the Parts Toolbar"), + "" + }, + // LC_VIEW_TOOLBAR_COLORS + { + QT_TRANSLATE_NOOP("Action", "View.Toolbars.Colors"), + QT_TRANSLATE_NOOP("Menu", "Colors"), + QT_TRANSLATE_NOOP("Status", "Toggle the Colors Toolbar"), + "" + }, + // LC_VIEW_TOOLBAR_PROPERTIES + { + QT_TRANSLATE_NOOP("Action", "View.Toolbars.Properties"), + QT_TRANSLATE_NOOP("Menu", "Properties"), + QT_TRANSLATE_NOOP("Status", "Toggle the Properties Toolbar"), + "" + }, + // LC_VIEW_TOOLBAR_TIMELINE + { + QT_TRANSLATE_NOOP("Action", "View.Toolbars.Timeline"), + QT_TRANSLATE_NOOP("Menu", "Timeline"), + QT_TRANSLATE_NOOP("Status", "Toggle the Timeline Toolbar"), + "" + }, // LC_VIEW_FULLSCREEN { QT_TRANSLATE_NOOP("Action", "View.FullScreen"), diff --git a/common/lc_commands.h b/common/lc_commands.h index 6182b15b..7601f236 100644 --- a/common/lc_commands.h +++ b/common/lc_commands.h @@ -155,6 +155,15 @@ enum lcCommandId LC_VIEW_SPLIT_VERTICAL, LC_VIEW_REMOVE_VIEW, LC_VIEW_RESET_VIEWS, + LC_VIEW_TOOLBAR_STANDARD, + LC_VIEW_TOOLBAR_FIRST = LC_VIEW_TOOLBAR_STANDARD, + LC_VIEW_TOOLBAR_TOOLS, + LC_VIEW_TOOLBAR_TIME, + LC_VIEW_TOOLBAR_PARTS, + LC_VIEW_TOOLBAR_COLORS, + LC_VIEW_TOOLBAR_PROPERTIES, + LC_VIEW_TOOLBAR_TIMELINE, + LC_VIEW_TOOLBAR_LAST = LC_VIEW_TOOLBAR_TIMELINE, LC_VIEW_FULLSCREEN, LC_VIEW_CLOSE_CURRENT_TAB, LC_VIEW_SHADING_FIRST, diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 94cc7a95..46a13ddc 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -329,6 +329,9 @@ void lcMainWindow::CreateActions() mActions[LC_VIEW_CAMERA_NONE]->setCheckable(true); mActions[LC_VIEW_TIME_ADD_KEYS]->setCheckable(true); + for (int ActionIndex = LC_VIEW_TOOLBAR_FIRST; ActionIndex <= LC_VIEW_TOOLBAR_LAST; ActionIndex++) + mActions[ActionIndex]->setCheckable(true); + QActionGroup* ActionSnapXYGroup = new QActionGroup(this); for (int ActionIdx = LC_EDIT_SNAP_MOVE_XY0; ActionIdx <= LC_EDIT_SNAP_MOVE_XY9; ActionIdx++) { @@ -540,14 +543,15 @@ void lcMainWindow::CreateMenus() ViewMenu->addAction(mActions[LC_VIEW_RESET_VIEWS]); ViewMenu->addSeparator(); QMenu* ToolBarsMenu = ViewMenu->addMenu(tr("T&oolbars")); - ToolBarsMenu->addAction(mPartsToolBar->toggleViewAction()); - ToolBarsMenu->addAction(mColorsToolBar->toggleViewAction()); - ToolBarsMenu->addAction(mPropertiesToolBar->toggleViewAction()); - ToolBarsMenu->addAction(mTimelineToolBar->toggleViewAction()); + connect(ToolBarsMenu, SIGNAL(aboutToShow()), this, SLOT(UpdateDockWidgetActions())); + ToolBarsMenu->addAction(mActions[LC_VIEW_TOOLBAR_PARTS]); + ToolBarsMenu->addAction(mActions[LC_VIEW_TOOLBAR_COLORS]); + ToolBarsMenu->addAction(mActions[LC_VIEW_TOOLBAR_PROPERTIES]); + ToolBarsMenu->addAction(mActions[LC_VIEW_TOOLBAR_TIMELINE]); ToolBarsMenu->addSeparator(); - ToolBarsMenu->addAction(mStandardToolBar->toggleViewAction()); - ToolBarsMenu->addAction(mToolsToolBar->toggleViewAction()); - ToolBarsMenu->addAction(mTimeToolBar->toggleViewAction()); + ToolBarsMenu->addAction(mActions[LC_VIEW_TOOLBAR_STANDARD]); + ToolBarsMenu->addAction(mActions[LC_VIEW_TOOLBAR_TOOLS]); + ToolBarsMenu->addAction(mActions[LC_VIEW_TOOLBAR_TIME]); ViewMenu->addAction(mActions[LC_VIEW_FULLSCREEN]); QMenu* PieceMenu = menuBar()->addMenu(tr("&Piece")); @@ -873,18 +877,31 @@ QMenu* lcMainWindow::createPopupMenu() { QMenu* Menu = new QMenu(this); - Menu->addAction(mPartsToolBar->toggleViewAction()); - Menu->addAction(mColorsToolBar->toggleViewAction()); - Menu->addAction(mPropertiesToolBar->toggleViewAction()); - Menu->addAction(mTimelineToolBar->toggleViewAction()); + UpdateDockWidgetActions(); + + Menu->addAction(mActions[LC_VIEW_TOOLBAR_PARTS]); + Menu->addAction(mActions[LC_VIEW_TOOLBAR_COLORS]); + Menu->addAction(mActions[LC_VIEW_TOOLBAR_PROPERTIES]); + Menu->addAction(mActions[LC_VIEW_TOOLBAR_TIMELINE]); Menu->addSeparator(); - Menu->addAction(mStandardToolBar->toggleViewAction()); - Menu->addAction(mToolsToolBar->toggleViewAction()); - Menu->addAction(mTimeToolBar->toggleViewAction()); + Menu->addAction(mActions[LC_VIEW_TOOLBAR_STANDARD]); + Menu->addAction(mActions[LC_VIEW_TOOLBAR_TOOLS]); + Menu->addAction(mActions[LC_VIEW_TOOLBAR_TIME]); return Menu; } +void lcMainWindow::UpdateDockWidgetActions() +{ + mActions[LC_VIEW_TOOLBAR_PARTS]->setChecked(mPartsToolBar->isVisible()); + mActions[LC_VIEW_TOOLBAR_COLORS]->setChecked(mColorsToolBar->isVisible()); + mActions[LC_VIEW_TOOLBAR_PROPERTIES]->setChecked(mPropertiesToolBar->isVisible()); + mActions[LC_VIEW_TOOLBAR_TIMELINE]->setChecked(mTimelineToolBar->isVisible()); + mActions[LC_VIEW_TOOLBAR_STANDARD]->setChecked(mStandardToolBar->isVisible()); + mActions[LC_VIEW_TOOLBAR_TOOLS]->setChecked(mToolsToolBar->isVisible()); + mActions[LC_VIEW_TOOLBAR_TIME]->setChecked(mTimeToolBar->isVisible()); +} + void lcMainWindow::UpdateGamepads() { #if LC_ENABLE_GAMEPAD @@ -1829,6 +1846,14 @@ void lcMainWindow::ResetViews() TabWidget->GetActiveView()->SetViewpoint(LC_VIEWPOINT_HOME); } +void lcMainWindow::ToggleDockWidget(QWidget* DockWidget) +{ + if (DockWidget->isHidden()) + DockWidget->show(); + else + DockWidget->hide(); +} + void lcMainWindow::TogglePrintPreview() { #ifndef QT_NO_PRINTER @@ -2655,6 +2680,34 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) ResetViews(); break; + case LC_VIEW_TOOLBAR_STANDARD: + ToggleDockWidget(mStandardToolBar); + break; + + case LC_VIEW_TOOLBAR_TOOLS: + ToggleDockWidget(mToolsToolBar); + break; + + case LC_VIEW_TOOLBAR_TIME: + ToggleDockWidget(mTimeToolBar); + break; + + case LC_VIEW_TOOLBAR_PARTS: + ToggleDockWidget(mPartsToolBar); + break; + + case LC_VIEW_TOOLBAR_COLORS: + ToggleDockWidget(mColorsToolBar); + break; + + case LC_VIEW_TOOLBAR_PROPERTIES: + ToggleDockWidget(mPropertiesToolBar); + break; + + case LC_VIEW_TOOLBAR_TIMELINE: + ToggleDockWidget(mTimelineToolBar); + break; + case LC_VIEW_FULLSCREEN: ToggleFullScreen(); break; diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index 3ce7355b..6312ccd1 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -353,6 +353,7 @@ public slots: void ProjectFileChanged(const QString& Path); protected slots: + void UpdateDockWidgetActions(); void UpdateGamepads(); void ModelTabContextMenuRequested(const QPoint& Point); void ModelTabCloseOtherTabs(); @@ -373,6 +374,7 @@ protected: void CreateMenus(); void CreateToolBars(); void CreateStatusBar(); + void ToggleDockWidget(QWidget* DockWidget); void SplitView(Qt::Orientation Orientation); void ShowSearchDialog(); void ShowUpdatesDialog();