From 21f81140a917177b613de0e00b0c21ac45776e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= Date: Mon, 22 Jul 2024 18:39:57 +0200 Subject: [PATCH] Main Toolbar: support enable/disable actions Support enable/disable main toolbar actions like 'New', 'Open', 'Save' etc. --- .../GUI/Settings/generalsettingswidget.cpp | 77 +++++++++- src/app/GUI/Settings/generalsettingswidget.h | 13 ++ src/app/GUI/mainwindow.cpp | 141 ++++++++++-------- src/core/Private/esettings.cpp | 11 +- src/core/Private/esettings.h | 8 + 5 files changed, 185 insertions(+), 65 deletions(-) diff --git a/src/app/GUI/Settings/generalsettingswidget.cpp b/src/app/GUI/Settings/generalsettingswidget.cpp index 85ff11724..112cdb108 100644 --- a/src/app/GUI/Settings/generalsettingswidget.cpp +++ b/src/app/GUI/Settings/generalsettingswidget.cpp @@ -25,9 +25,9 @@ #include "appsupport.h" #include -#include #include #include +#include #include "Private/esettings.h" #include "GUI/global.h" @@ -42,6 +42,13 @@ GeneralSettingsWidget::GeneralSettingsWidget(QWidget *parent) , mDefaultInterfaceScaling(nullptr) , mInterfaceScaling(nullptr) , mImportFileDir(nullptr) + , mToolBarActionNew(nullptr) + , mToolBarActionOpen(nullptr) + , mToolBarActionSave(nullptr) + , mToolBarActionScene(nullptr) + , mToolBarActionRender(nullptr) + , mToolBarActionPreview(nullptr) + , mToolBarActionExport(nullptr) { const auto mGeneralWidget = new QWidget(this); mGeneralWidget->setContentsMargins(0, 0, 0, 0); @@ -139,11 +146,11 @@ GeneralSettingsWidget::GeneralSettingsWidget(QWidget *parent) mImportFileLayout->addWidget(mImportFileLabel); mImportFileLayout->addWidget(mImportFileDir); - mImportLayout->addWidget(mImportFileWidget); - mGeneralLayout->addWidget(mImportWidget); + setupToolBarWidgets(mGeneralLayout); + mGeneralLayout->addStretch(); addWidget(mGeneralWidget); @@ -173,6 +180,15 @@ void GeneralSettingsWidget::applySettings() mSett.fDefaultInterfaceScaling = mDefaultInterfaceScaling->isChecked(); mSett.fInterfaceScaling = mInterfaceScaling->value() * 0.01; mSett.fImportFileDirOpt = mImportFileDir->currentData().toInt(); + + mSett.fToolBarActionNew = mToolBarActionNew->isChecked(); + mSett.fToolBarActionOpen = mToolBarActionOpen->isChecked(); + mSett.fToolBarActionSave = mToolBarActionSave->isChecked(); + mSett.fToolBarActionScene = mToolBarActionScene->isChecked(); + mSett.fToolBarActionRender = mToolBarActionRender->isChecked(); + mSett.fToolBarActionPreview = mToolBarActionPreview->isChecked(); + mSett.fToolBarActionExport = mToolBarActionExport->isChecked(); + eSizesUI::font.updateSize(); eSizesUI::widget.updateSize(); } @@ -194,6 +210,14 @@ void GeneralSettingsWidget::updateSettings(bool restore) mDefaultInterfaceScaling->setChecked(mSett.fDefaultInterfaceScaling); mInterfaceScaling->setValue(mDefaultInterfaceScaling->isChecked() ? 100 : 100 * mSett.fInterfaceScaling); + mToolBarActionNew->setChecked(mSett.fToolBarActionNew); + mToolBarActionOpen->setChecked(mSett.fToolBarActionOpen); + mToolBarActionSave->setChecked(mSett.fToolBarActionSave); + mToolBarActionScene->setChecked(mSett.fToolBarActionScene); + mToolBarActionRender->setChecked(mSett.fToolBarActionRender); + mToolBarActionPreview->setChecked(mSett.fToolBarActionPreview); + mToolBarActionExport->setChecked(mSett.fToolBarActionExport); + for (int i = 0; i < mImportFileDir->count(); i++) { if (mImportFileDir->itemData(i).toInt() == mSett.fImportFileDirOpt) { mImportFileDir->setCurrentIndex(i); @@ -201,3 +225,50 @@ void GeneralSettingsWidget::updateSettings(bool restore) } } } + +void GeneralSettingsWidget::setupToolBarWidgets(QVBoxLayout *lay) +{ + if (!lay) { return; } + + const auto area = new QScrollArea(this); + const auto container = new QGroupBox(this); + const auto containerLayout = new QVBoxLayout(container); + const auto containerInner = new QWidget(this); + const auto containerInnerLayout = new QVBoxLayout(containerInner); + + area->setWidget(containerInner); + area->setWidgetResizable(true); + area->setContentsMargins(0, 0, 0, 0); + + container->setTitle(tr("Toolbar Actions")); + + container->setContentsMargins(0, 0, 0, 0); + + containerInnerLayout->setMargin(5); + containerLayout->setMargin(0); + + containerLayout->addWidget(area); + + mToolBarActionNew = new QCheckBox(tr("New"), this); + containerInnerLayout->addWidget(mToolBarActionNew); + + mToolBarActionOpen = new QCheckBox(tr("Open"), this); + containerInnerLayout->addWidget(mToolBarActionOpen); + + mToolBarActionSave = new QCheckBox(tr("Save"), this); + containerInnerLayout->addWidget(mToolBarActionSave); + + mToolBarActionScene = new QCheckBox(tr("Scene"), this); + containerInnerLayout->addWidget(mToolBarActionScene); + + mToolBarActionRender = new QCheckBox(tr("Render"), this); + containerInnerLayout->addWidget(mToolBarActionRender); + + mToolBarActionPreview = new QCheckBox(tr("Preview"), this); + containerInnerLayout->addWidget(mToolBarActionPreview); + + mToolBarActionExport = new QCheckBox(tr("Export"), this); + containerInnerLayout->addWidget(mToolBarActionExport); + + lay->addWidget(container); +} diff --git a/src/app/GUI/Settings/generalsettingswidget.h b/src/app/GUI/Settings/generalsettingswidget.h index ff9339aa3..c0e0288ef 100644 --- a/src/app/GUI/Settings/generalsettingswidget.h +++ b/src/app/GUI/Settings/generalsettingswidget.h @@ -30,6 +30,7 @@ #include #include #include +#include class GeneralSettingsWidget : public SettingsWidget { @@ -42,9 +43,21 @@ class GeneralSettingsWidget : public SettingsWidget QCheckBox *mAutoBackup; QCheckBox *mAutoSave; QSpinBox *mAutoSaveTimer; + QCheckBox *mDefaultInterfaceScaling; QSlider *mInterfaceScaling; + QComboBox *mImportFileDir; + + QCheckBox *mToolBarActionNew; + QCheckBox *mToolBarActionOpen; + QCheckBox *mToolBarActionSave; + QCheckBox *mToolBarActionScene; + QCheckBox *mToolBarActionRender; + QCheckBox *mToolBarActionPreview; + QCheckBox *mToolBarActionExport; + + void setupToolBarWidgets(QVBoxLayout *lay); }; #endif // GENERALSETTINGSWIDGET_H diff --git a/src/app/GUI/mainwindow.cpp b/src/app/GUI/mainwindow.cpp index 732870a8b..1525b11fa 100644 --- a/src/app/GUI/mainwindow.cpp +++ b/src/app/GUI/mainwindow.cpp @@ -446,26 +446,16 @@ void MainWindow::setupMenuBar() tr("New", "MenuBar_File"), this, &MainWindow::newFile, Qt::CTRL + Qt::Key_N); - mToolbar->addAction(newAct); + if (eSettings::instance().fToolBarActionNew) { + mToolbar->addAction(newAct); + } const auto openAct = mFileMenu->addAction(QIcon::fromTheme("file_folder"), tr("Open", "MenuBar_File"), this, qOverload<>(&MainWindow::openFile), Qt::CTRL + Qt::Key_O); - - const auto loadToolBtn = new QToolButton(this); - loadToolBtn->setPopupMode(QToolButton::MenuButtonPopup); - loadToolBtn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - loadToolBtn->setFocusPolicy(Qt::NoFocus); - const auto loadToolMenu = new QMenu(this); - loadToolBtn->setMenu(loadToolMenu); - - mToolbar->addWidget(loadToolBtn); - loadToolBtn->setDefaultAction(openAct); - mRecentMenu = mFileMenu->addMenu(QIcon::fromTheme("file_folder"), tr("Open Recent", "MenuBar_File")); - mFileMenu->addSeparator(); const auto linkedAct = mFileMenu->addAction(QIcon::fromTheme("linked"), tr("Link"), @@ -481,24 +471,29 @@ void MainWindow::setupMenuBar() tr("Import Image Sequence", "MenuBar_File"), this, &MainWindow::importImageSequence); - loadToolMenu->addAction(linkedAct); - loadToolMenu->addAction(importAct); - loadToolMenu->addAction(importSeqAct); - loadToolMenu->addMenu(mRecentMenu); + if (eSettings::instance().fToolBarActionOpen) { + const auto loadToolBtn = new QToolButton(this); + loadToolBtn->setPopupMode(QToolButton::MenuButtonPopup); + loadToolBtn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + loadToolBtn->setFocusPolicy(Qt::NoFocus); + + const auto loadToolMenu = new QMenu(this); + loadToolBtn->setMenu(loadToolMenu); + loadToolBtn->setDefaultAction(openAct); + + loadToolMenu->addAction(linkedAct); + loadToolMenu->addAction(importAct); + loadToolMenu->addAction(importSeqAct); + loadToolMenu->addMenu(mRecentMenu); + + mToolbar->addWidget(loadToolBtn); + } mFileMenu->addSeparator(); mFileMenu->addAction(QIcon::fromTheme("loop_back"), tr("Revert", "MenuBar_File"), this, &MainWindow::revert); - const auto saveToolBtn = new QToolButton(this); - saveToolBtn->setPopupMode(QToolButton::MenuButtonPopup); - saveToolBtn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - saveToolBtn->setFocusPolicy(Qt::NoFocus); - const auto saveToolMenu = new QMenu(this); - saveToolBtn->setMenu(saveToolMenu); - mToolbar->addWidget(saveToolBtn); - mFileMenu->addSeparator(); mSaveAct = mFileMenu->addAction(QIcon::fromTheme("disk_drive"), tr("Save", "MenuBar_File"), @@ -526,11 +521,24 @@ void MainWindow::setupMenuBar() QKeySequence(AppSupport::getSettings("shortcuts", "exportSVG", "Shift+F12").toString())); - saveToolBtn->setDefaultAction(mSaveAct); - saveToolMenu->addAction(saveAsAct); - saveToolMenu->addAction(saveBackAct); - //saveToolMenu->addAction(exportSvgAct); - saveToolMenu->addSeparator(); + + if (eSettings::instance().fToolBarActionSave) { + const auto saveToolBtn = new QToolButton(this); + saveToolBtn->setPopupMode(QToolButton::MenuButtonPopup); + saveToolBtn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + saveToolBtn->setFocusPolicy(Qt::NoFocus); + + const auto saveToolMenu = new QMenu(this); + saveToolBtn->setMenu(saveToolMenu); + saveToolBtn->setDefaultAction(mSaveAct); + + saveToolMenu->addAction(saveAsAct); + saveToolMenu->addAction(saveBackAct); + //saveToolMenu->addAction(exportSvgAct); + saveToolMenu->addSeparator(); + + mToolbar->addWidget(saveToolBtn); + } mFileMenu->addSeparator(); mFileMenu->addAction(QIcon::fromTheme("dialog-cancel"), @@ -817,16 +825,6 @@ void MainWindow::setupMenuBar() // mEffectsMenu->addAction("Blur"); - const auto sceneToolBtn = new QToolButton(this); - sceneToolBtn->setText(tr("Scene")); - sceneToolBtn->setIcon(QIcon::fromTheme("sequence")); - sceneToolBtn->setPopupMode(QToolButton::MenuButtonPopup); - sceneToolBtn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - sceneToolBtn->setFocusPolicy(Qt::NoFocus); - const auto sceneToolMenu = new QMenu(this); - sceneToolBtn->setMenu(sceneToolMenu); - mToolbar->addWidget(sceneToolBtn); - mSceneMenu = mMenuBar->addMenu(tr("Scene", "MenuBar")); const auto newSceneAct = mSceneMenu->addAction(QIcon::fromTheme("file_new"), @@ -834,14 +832,14 @@ void MainWindow::setupMenuBar() this, [this]() { SceneSettingsDialog::sNewSceneDialog(mDocument, this); }); - sceneToolMenu->addAction(newSceneAct); - { - const auto qAct = mSceneMenu->addAction(QIcon::fromTheme("cancel"), - tr("Delete Scene", "MenuBar_Scene")); - mActions.deleteSceneAction->connect(qAct); - sceneToolMenu->addAction(qAct); - } + + + const auto deleteSceneAct = mSceneMenu->addAction(QIcon::fromTheme("cancel"), + tr("Delete Scene", "MenuBar_Scene")); + mActions.deleteSceneAction->connect(deleteSceneAct); + + mSceneMenu->addSeparator(); @@ -851,18 +849,36 @@ void MainWindow::setupMenuBar() QKeySequence(AppSupport::getSettings("shortcuts", "addToQue", "F12").toString())); - sceneToolMenu->addAction(mAddToQueAct); + mSceneMenu->addSeparator(); - { - const auto qAct = mSceneMenu->addAction(QIcon::fromTheme("sequence"), - tr("Scene Properties", "MenuBar_Scene")); - mActions.sceneSettingsAction->connect(qAct); - sceneToolBtn->setDefaultAction(qAct); + + const auto scenePropAct = mSceneMenu->addAction(QIcon::fromTheme("sequence"), + tr("Scene Properties", "MenuBar_Scene")); + mActions.sceneSettingsAction->connect(scenePropAct); + + if (eSettings::instance().fToolBarActionScene) { + const auto sceneToolBtn = new QToolButton(this); + sceneToolBtn->setText(tr("Scene")); + sceneToolBtn->setIcon(QIcon::fromTheme("sequence")); + sceneToolBtn->setPopupMode(QToolButton::MenuButtonPopup); + sceneToolBtn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + sceneToolBtn->setFocusPolicy(Qt::NoFocus); + const auto sceneToolMenu = new QMenu(this); + sceneToolBtn->setMenu(sceneToolMenu); + + sceneToolMenu->addAction(newSceneAct); + sceneToolMenu->addAction(mAddToQueAct); + sceneToolMenu->addAction(deleteSceneAct); + + sceneToolBtn->setDefaultAction(scenePropAct); sceneToolBtn->setText(tr("Scene")); - connect(qAct, &QAction::changed, + + connect(scenePropAct, &QAction::changed, this, [sceneToolBtn]() { sceneToolBtn->setText(tr("Scene")); }); + + mToolbar->addWidget(sceneToolBtn); } const auto zoomMenu = mViewMenu->addMenu( @@ -1138,12 +1154,19 @@ void MainWindow::setupMenuBar() QMessageBox::aboutQt(this, tr("About Qt")); }); - mToolbar->addAction(QIcon::fromTheme("render_animation"), - tr("Render"), - this, &MainWindow::openRendererWindow); + if (eSettings::instance().fToolBarActionRender) { + mToolbar->addAction(QIcon::fromTheme("render_animation"), + tr("Render"), + this, &MainWindow::openRendererWindow); + } + + if (eSettings::instance().fToolBarActionPreview) { + mToolbar->addAction(previewSvgAct); + } - mToolbar->addAction(previewSvgAct); - mToolbar->addAction(exportSvgAct); + if (eSettings::instance().fToolBarActionExport) { + mToolbar->addAction(exportSvgAct); + } setMenuBar(mMenuBar); diff --git a/src/core/Private/esettings.cpp b/src/core/Private/esettings.cpp index bfb714766..47dc796fd 100644 --- a/src/core/Private/esettings.cpp +++ b/src/core/Private/esettings.cpp @@ -196,9 +196,14 @@ eSettings::eSettings(const int cpuThreads, fDefaultInterfaceScaling, "defaultInterfaceScaling", true); - gSettings << std::make_shared( - fImportFileDirOpt, - "ImportFileDirOpt", ImportFileDirRecent); + gSettings << std::make_shared(fImportFileDirOpt, "ImportFileDirOpt", ImportFileDirRecent); + gSettings << std::make_shared(fToolBarActionNew, "ToolBarActionNew", true); + gSettings << std::make_shared(fToolBarActionOpen, "ToolBarActionOpen", true); + gSettings << std::make_shared(fToolBarActionSave, "ToolBarActionSave", true); + gSettings << std::make_shared(fToolBarActionScene, "ToolBarActionScene", true); + gSettings << std::make_shared(fToolBarActionRender, "ToolBarActionRender", true); + gSettings << std::make_shared(fToolBarActionPreview, "ToolBarActionPreview", true); + gSettings << std::make_shared(fToolBarActionExport, "ToolBarActionExport", true); gSettings << std::make_shared( fCanvasRtlSupport, diff --git a/src/core/Private/esettings.h b/src/core/Private/esettings.h index 57279f82c..ddb6b3da7 100644 --- a/src/core/Private/esettings.h +++ b/src/core/Private/esettings.h @@ -96,6 +96,14 @@ class CORE_EXPORT eSettings : public QObject int fImportFileDirOpt = ImportFileDirRecent; + bool fToolBarActionNew = true; + bool fToolBarActionOpen = true; + bool fToolBarActionSave = true; + bool fToolBarActionScene = true; + bool fToolBarActionRender = true; + bool fToolBarActionPreview = true; + bool fToolBarActionExport = true; + bool fHddCache = true; QString fHddCacheFolder = ""; // "" - use system default temporary files folder intMB fHddCacheMBCap = intMB(0); // <= 0 - no cap