Skip to content

Commit

Permalink
Merge pull request #312 from friction2d/new-toolbar
Browse files Browse the repository at this point in the history
UI/UX: New ToolBar
  • Loading branch information
rodlie authored Nov 11, 2024
2 parents f72fc99 + 6d97218 commit 67c7c1b
Show file tree
Hide file tree
Showing 14 changed files with 466 additions and 308 deletions.
72 changes: 0 additions & 72 deletions src/app/GUI/Settings/generalsettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ GeneralSettingsWidget::GeneralSettingsWidget(QWidget *parent)
, mDefaultInterfaceScaling(nullptr)
, mInterfaceScaling(nullptr)
, mImportFileDir(nullptr)
, mToolBarActionNew(nullptr)
, mToolBarActionOpen(nullptr)
, mToolBarActionImport(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 @@ -148,8 +140,6 @@ GeneralSettingsWidget::GeneralSettingsWidget(QWidget *parent)
mProjectLayout->addSpacing(10);
mProjectLayout->addWidget(mImportFileWidget);

setupToolBarWidgets(mGeneralLayout);

mGeneralLayout->addStretch();
addWidget(mGeneralWidget);

Expand Down Expand Up @@ -177,15 +167,6 @@ void GeneralSettingsWidget::applySettings()
mSett.fInterfaceScaling = mInterfaceScaling->value() * 0.01;
mSett.fImportFileDirOpt = mImportFileDir->currentData().toInt();

mSett.fToolBarActionNew = mToolBarActionNew->isChecked();
mSett.fToolBarActionOpen = mToolBarActionOpen->isChecked();
mSett.fToolBarActionImport = mToolBarActionImport->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 @@ -208,63 +189,10 @@ void GeneralSettingsWidget::updateSettings(bool restore)
mInterfaceScaling->setEnabled(!mDefaultInterfaceScaling->isChecked());
mInterfaceScaling->setValue(mDefaultInterfaceScaling->isChecked() ? 100 : 100 * mSett.fInterfaceScaling);

mToolBarActionNew->setChecked(mSett.fToolBarActionNew);
mToolBarActionOpen->setChecked(mSett.fToolBarActionOpen);
mToolBarActionImport->setChecked(mSett.fToolBarActionImport);
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);
container->setObjectName("BlueBox");
const auto containerLayout = new QVBoxLayout(container);
const auto containerInner = new QWidget(this);
const auto containerInnerLayout = new TwoColumnLayout();
containerInner->setLayout(containerInnerLayout);

area->setWidget(containerInner);
area->setWidgetResizable(true);
area->setContentsMargins(0, 0, 0, 0);
area->setFrameShape(QFrame::NoFrame);

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);
mToolBarActionOpen = new QCheckBox(tr("Open"), this);
mToolBarActionImport = new QCheckBox(tr("Import"), this);
mToolBarActionSave = new QCheckBox(tr("Save"), this);
//mToolBarActionScene = new QCheckBox(tr("Scene"), this);
mToolBarActionRender = new QCheckBox(tr("Render"), this);
mToolBarActionPreview = new QCheckBox(tr("Preview SVG"), this);
mToolBarActionExport = new QCheckBox(tr("Export SVG"), this);

containerInnerLayout->addPair(mToolBarActionNew, mToolBarActionOpen);
containerInnerLayout->addPair(mToolBarActionImport, mToolBarActionSave);
containerInnerLayout->addPair(mToolBarActionRender, mToolBarActionPreview);
containerInnerLayout->addWidgetToFirstColumn(mToolBarActionExport);
containerLayout->addStretch();

lay->addWidget(container);
}
11 changes: 0 additions & 11 deletions src/app/GUI/Settings/generalsettingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ class GeneralSettingsWidget : public SettingsWidget
QSlider *mInterfaceScaling;

QComboBox *mImportFileDir;

QCheckBox *mToolBarActionNew;
QCheckBox *mToolBarActionOpen;
QCheckBox *mToolBarActionImport;
QCheckBox *mToolBarActionSave;
//QCheckBox *mToolBarActionScene;
QCheckBox *mToolBarActionRender;
QCheckBox *mToolBarActionPreview;
QCheckBox *mToolBarActionExport;

void setupToolBarWidgets(QVBoxLayout *lay);
};

#endif // GENERALSETTINGSWIDGET_H
86 changes: 41 additions & 45 deletions src/app/GUI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ MainWindow::MainWindow(Document& document,
, mToolBoxGroupMain(nullptr)
, mToolBoxGroupNodes(nullptr)
, mToolBoxMain(nullptr)
, mToolBoxNodes(nullptr)
, mToolBoxDraw(nullptr)
, mUI(nullptr)
, mSaveAct(nullptr)
, mSaveAsAct(nullptr)
Expand All @@ -124,11 +122,19 @@ MainWindow::MainWindow(Document& document,
, mViewFullScreenAct(nullptr)
, mLocalPivotAct(nullptr)
, mNodeVisibility(nullptr)
, mNodeVisibilityAct(nullptr)
, mFontWidget(nullptr)
, mFontWidgetAct(nullptr)
, mDrawPathAuto(nullptr)
, mDrawPathSmooth(nullptr)
, mDrawPathMaxError(nullptr)
, mToolBoxDrawActLabel1(nullptr)
, mToolBoxDrawActLabel2(nullptr)
, mToolBoxDrawActIcon1(nullptr)
, mToolBoxDrawActIcon2(nullptr)
, mToolBoxDrawActMaxError(nullptr)
, mToolBoxDrawActSmooth(nullptr)
, mToolBoxDrawActSep(nullptr)
, mDocument(document)
, mActions(actions)
, mAudioHandler(audioHandler)
Expand Down Expand Up @@ -193,6 +199,7 @@ MainWindow::MainWindow(Document& document,
this, &MainWindow::handleCurrentPixelColor);

setWindowIcon(QIcon::fromTheme(AppSupport::getAppName()));
setContextMenuPolicy(Qt::NoContextMenu);

mAutoSaveTimer = new QTimer(this);
connect (mAutoSaveTimer, &QTimer::timeout,
Expand Down Expand Up @@ -387,20 +394,22 @@ void MainWindow::setupMenuBar()

mFileMenu = mMenuBar->addMenu(tr("File", "MenuBar"));

const auto newAct = mFileMenu->addAction(QIcon::fromTheme("file_new"),
const auto newAct = mFileMenu->addAction(QIcon::fromTheme("file_blank"),
tr("New", "MenuBar_File"),
this, &MainWindow::newFile,
Qt::CTRL + Qt::Key_N);
newAct->setData(tr("New Project"));
newAct->setObjectName("NewProjectAct");

cmdAddAction(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);
openAct->setData(tr("Open Project"));
openAct->setObjectName("OpenProjectAct");

cmdAddAction(openAct);
mRecentMenu = mFileMenu->addMenu(QIcon::fromTheme("file_folder"),
tr("Open Recent", "MenuBar_File"));
Expand All @@ -411,13 +420,16 @@ void MainWindow::setupMenuBar()
Qt::CTRL + Qt::Key_L);
mLinkedAct->setEnabled(false);
mLinkedAct->setData(tr("Link File"));
mLinkedAct->setObjectName("LinkFileAct");

cmdAddAction(mLinkedAct);

mImportAct = mFileMenu->addAction(QIcon::fromTheme("file_import"),
tr("Import", "MenuBar_File"),
this, qOverload<>(&MainWindow::importFile),
Qt::CTRL + Qt::Key_I);
mImportAct->setEnabled(false);
mImportAct->setObjectName("ImportFileAct");
cmdAddAction(mImportAct);

mImportSeqAct = mFileMenu->addAction(QIcon::fromTheme("renderlayers"),
Expand All @@ -426,10 +438,6 @@ void MainWindow::setupMenuBar()
mImportSeqAct->setEnabled(false);
cmdAddAction(mImportSeqAct);

if (eSettings::instance().fToolBarActionOpen) {
mToolbar->addAction(openAct);
}

mRevertAct = mFileMenu->addAction(QIcon::fromTheme("loop_back"),
tr("Revert", "MenuBar_File"),
this, &MainWindow::revert);
Expand All @@ -445,6 +453,7 @@ void MainWindow::setupMenuBar()
Qt::CTRL + Qt::Key_S);
mSaveAct->setEnabled(false);
mSaveAct->setData(tr("Save Project"));
mSaveAct->setObjectName("SaveProjectAct");
cmdAddAction(mSaveAct);

mSaveAsAct = mFileMenu->addAction(QIcon::fromTheme("disk_drive"),
Expand All @@ -471,6 +480,7 @@ void MainWindow::setupMenuBar()
mPreviewSVGAct->setEnabled(false);
mPreviewSVGAct->setToolTip(tr("Preview SVG Animation in Web Browser"));
mPreviewSVGAct->setData(mPreviewSVGAct->toolTip());
mPreviewSVGAct->setObjectName("PreviewSVGAct");
cmdAddAction(mPreviewSVGAct);

mExportSVGAct = mFileMenu->addAction(QIcon::fromTheme("output"),
Expand All @@ -482,16 +492,9 @@ void MainWindow::setupMenuBar()
mExportSVGAct->setEnabled(false);
mExportSVGAct->setToolTip(tr("Export SVG Animation for the Web"));
mExportSVGAct->setData(mExportSVGAct->toolTip());
mExportSVGAct->setObjectName("ExportSVGAct");
cmdAddAction(mExportSVGAct);

if (eSettings::instance().fToolBarActionSave) {
mToolbar->addAction(mSaveAct);
}

if (eSettings::instance().fToolBarActionImport) {
mToolbar->addAction(mImportAct);
}

mFileMenu->addSeparator();
mCloseProjectAct = mFileMenu->addAction(QIcon::fromTheme("dialog-cancel"),
tr("Close", "MenuBar_File"),
Expand Down Expand Up @@ -1083,20 +1086,23 @@ void MainWindow::setupMenuBar()
tr("Reinstall default render profiles"),
this, &MainWindow::askInstallRenderPresets);

if (eSettings::instance().fToolBarActionRender) {
mRenderVideoAct = mToolbar->addAction(QIcon::fromTheme("render_animation"),
tr("Render"),
this, &MainWindow::openRendererWindow);
mRenderVideoAct->setEnabled(false);
}

if (eSettings::instance().fToolBarActionPreview) {
mToolbar->addAction(mPreviewSVGAct);
}
// toolbar actions
mToolbar->addAction(newAct);
mToolbar->addAction(openAct);
mToolbar->addAction(mSaveAct);
mToolbar->addAction(mImportAct);
mToolbar->addAction(mLinkedAct);

if (eSettings::instance().fToolBarActionExport) {
mToolbar->addAction(mExportSVGAct);
}
mRenderVideoAct = mToolbar->addAction(QIcon::fromTheme("render_animation"),
tr("Render"),
this, &MainWindow::openRendererWindow);
mRenderVideoAct->setEnabled(false);
mRenderVideoAct->setObjectName("RenderVideoAct");

mToolbar->addAction(mPreviewSVGAct);
mToolbar->addAction(mExportSVGAct);
mToolbar->updateActions();

setMenuBar(mMenuBar);

Expand Down Expand Up @@ -1347,17 +1353,9 @@ void MainWindow::updateSettingsForCurrentCanvas(Canvas* const scene)

void MainWindow::setupToolBar()
{
mToolbar = new QToolBar(tr("Toolbar"), this);
mToolbar->setObjectName("MainToolBar");
mToolbar->setFocusPolicy(Qt::NoFocus);
mToolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
mToolbar->setMovable(false);
#ifdef Q_OS_MAC
mToolbar->setStyleSheet(QString("font-size: %1pt;").arg(font().pointSize()));
#endif
eSizesUI::widget.add(mToolbar, [this](const int size) {
mToolbar->setIconSize({size, size});
});
mToolbar = new Ui::ToolBar(tr("Toolbar"),
"MainToolBar",
this);
addToolBar(Qt::TopToolBarArea, mToolbar);
}

Expand All @@ -1374,10 +1372,8 @@ void MainWindow::updateCanvasModeButtonsChecked()
const bool pointMode = mode == CanvasMode::pointTransform;
const bool drawMode = mode == CanvasMode::drawPath;

mToolBoxNodes->setEnabled(pointMode);
mToolBoxNodes->setVisible(pointMode);
mToolBoxDraw->setEnabled(drawMode);
mToolBoxDraw->setVisible(drawMode);
setEnableToolBoxNodes(pointMode);
setEnableToolBoxDraw(drawMode);
mLocalPivotAct->setEnabled(pointMode || boxMode);

if (mColorPickLabel) {
Expand Down
19 changes: 15 additions & 4 deletions src/app/GUI/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "window.h"
#include "widgets/aboutwidget.h"
#include "widgets/uilayout.h"
#include "widgets/toolbar.h"

class VideoEncoder;
class RenderWidget;
Expand Down Expand Up @@ -220,14 +221,12 @@ class MainWindow : public QMainWindow
TimelineDockWidget *mTimeline;
RenderWidget *mRenderWidget;

QToolBar *mToolbar;
Friction::Ui::ToolBar *mToolbar;

QActionGroup *mToolBoxGroupMain;
QActionGroup *mToolBoxGroupNodes;

QToolBar *mToolBoxMain;
QToolBar *mToolBoxNodes;
QToolBar *mToolBoxDraw;
Friction::Ui::ToolBar *mToolBoxMain;

UILayout *mUI;

Expand Down Expand Up @@ -280,6 +279,7 @@ class MainWindow : public QMainWindow
QAction *mLocalPivotAct;

QToolButton *mNodeVisibility;
QAction *mNodeVisibilityAct;

Friction::Ui::FontsWidget *mFontWidget;
QAction* mFontWidgetAct;
Expand All @@ -288,6 +288,14 @@ class MainWindow : public QMainWindow
QDoubleSlider *mDrawPathSmooth;
QDoubleSlider *mDrawPathMaxError;

QAction *mToolBoxDrawActLabel1;
QAction *mToolBoxDrawActLabel2;
QAction *mToolBoxDrawActIcon1;
QAction *mToolBoxDrawActIcon2;
QAction *mToolBoxDrawActMaxError;
QAction *mToolBoxDrawActSmooth;
QAction *mToolBoxDrawActSep;

QMenuBar *mMenuBar;
QMenu *mFileMenu;
QMenu *mRecentMenu;
Expand Down Expand Up @@ -355,6 +363,9 @@ class MainWindow : public QMainWindow
void setupToolBoxNodes();
void setupToolBoxDraw();

void setEnableToolBoxNodes(const bool &enable);
void setEnableToolBoxDraw(const bool &enable);

bool mBackupOnSave;
bool mAutoSave;
int mAutoSaveTimeout;
Expand Down
Loading

0 comments on commit 67c7c1b

Please sign in to comment.