Skip to content

Commit

Permalink
Main Toolbar: support enable/disable actions
Browse files Browse the repository at this point in the history
Support enable/disable main toolbar actions like 'New', 'Open', 'Save' etc.
  • Loading branch information
rodlie committed Jul 22, 2024
1 parent 32fd0fe commit 21f8114
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 65 deletions.
77 changes: 74 additions & 3 deletions src/app/GUI/Settings/generalsettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include "appsupport.h"

#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QGroupBox>
#include <QScrollArea>

#include "Private/esettings.h"
#include "GUI/global.h"
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}
Expand All @@ -194,10 +210,65 @@ 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);
return;
}
}
}

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);
}
13 changes: 13 additions & 0 deletions src/app/GUI/Settings/generalsettingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QSpinBox>
#include <QSlider>
#include <QComboBox>
#include <QVBoxLayout>

class GeneralSettingsWidget : public SettingsWidget
{
Expand All @@ -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
141 changes: 82 additions & 59 deletions src/app/GUI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -817,31 +825,21 @@ 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"),
tr("New Scene", "MenuBar_Scene"),
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();

Expand All @@ -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(
Expand Down Expand Up @@ -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);

Expand Down
11 changes: 8 additions & 3 deletions src/core/Private/esettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,14 @@ eSettings::eSettings(const int cpuThreads,
fDefaultInterfaceScaling,
"defaultInterfaceScaling", true);

gSettings << std::make_shared<eIntSetting>(
fImportFileDirOpt,
"ImportFileDirOpt", ImportFileDirRecent);
gSettings << std::make_shared<eIntSetting>(fImportFileDirOpt, "ImportFileDirOpt", ImportFileDirRecent);
gSettings << std::make_shared<eBoolSetting>(fToolBarActionNew, "ToolBarActionNew", true);
gSettings << std::make_shared<eBoolSetting>(fToolBarActionOpen, "ToolBarActionOpen", true);
gSettings << std::make_shared<eBoolSetting>(fToolBarActionSave, "ToolBarActionSave", true);
gSettings << std::make_shared<eBoolSetting>(fToolBarActionScene, "ToolBarActionScene", true);
gSettings << std::make_shared<eBoolSetting>(fToolBarActionRender, "ToolBarActionRender", true);
gSettings << std::make_shared<eBoolSetting>(fToolBarActionPreview, "ToolBarActionPreview", true);
gSettings << std::make_shared<eBoolSetting>(fToolBarActionExport, "ToolBarActionExport", true);

gSettings << std::make_shared<eBoolSetting>(
fCanvasRtlSupport,
Expand Down
8 changes: 8 additions & 0 deletions src/core/Private/esettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 21f8114

Please sign in to comment.