Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/app/GUI/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
#include "widgets/uilayout.h"
#include "widgets/toolbox.h"

#ifndef Q_OS_MAC
#include "widgets/persistentmenu.h"
#endif

class VideoEncoder;
class RenderWidget;
class ActionButton;
Expand Down Expand Up @@ -280,7 +284,11 @@ class MainWindow : public QMainWindow
QMenu *mPathMenu;
QMenu *mEffectsMenu;
QMenu *mSceneMenu;
#ifndef Q_OS_MAC
Friction::Ui::PersistentMenu *mViewMenu;
#else
QMenu *mViewMenu;
#endif
QMenu *mPanelsMenu;
QMenu *mRenderMenu;

Expand Down
19 changes: 18 additions & 1 deletion src/app/GUI/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,13 @@ void MainWindow::setupMenuBar()
});
cmdAddAction(clearRecentAct);

#ifndef Q_OS_MAC
mViewMenu = new Ui::PersistentMenu(tr("View", "MenuBar"), this);
mViewMenu->setOnlyCheckable(true);
mMenuBar->addMenu(mViewMenu);
#else
mViewMenu = mMenuBar->addMenu(tr("View", "MenuBar"));
#endif

mObjectMenu = mMenuBar->addMenu(tr("Object", "MenuBar"));

Expand Down Expand Up @@ -505,7 +511,13 @@ void MainWindow::setupMenuBar()
mEffectsMenu->setEnabled(false);
setupMenuEffects();

const auto zoomMenu = mViewMenu->addMenu(QIcon::fromTheme("zoom"), tr("Zoom","MenuBar_View"));
#ifndef Q_OS_MAC
const auto zoomMenu = mViewMenu->addPersistentMenu(QIcon::fromTheme("zoom"),
tr("Zoom","MenuBar_View"));
#else
const auto zoomMenu = mViewMenu->addMenu(QIcon::fromTheme("zoom"),
tr("Zoom","MenuBar_View"));
#endif

mZoomInAction = zoomMenu->addAction(tr("Zoom In", "MenuBar_View_Zoom"));
mZoomInAction->setIcon(QIcon::fromTheme("zoom_in"));
Expand Down Expand Up @@ -566,8 +578,13 @@ void MainWindow::setupMenuBar()
});
cmdAddAction(mResetZoomAction);

#ifndef Q_OS_MAC
const auto filteringMenu = mViewMenu->addPersistentMenu(QIcon::fromTheme("user-desktop"),
tr("Filtering", "MenuBar_View"));
#else
const auto filteringMenu = mViewMenu->addMenu(QIcon::fromTheme("user-desktop"),
tr("Filtering", "MenuBar_View"));
#endif

mNoneQuality = filteringMenu->addAction(
tr("None", "MenuBar_View_Filtering"), [this]() {
Expand Down
1 change: 1 addition & 0 deletions src/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ set(
widgets/labeledslider.h
widgets/markereditor.h
widgets/performancesettingswidget.h
widgets/persistentmenu.h
widgets/presetsettingswidget.h
widgets/qdoubleslider.h
widgets/qrealanimatorvalueslider.h
Expand Down
79 changes: 79 additions & 0 deletions src/ui/widgets/persistentmenu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
#
# Friction - https://friction.graphics
#
# Copyright (c) Ole-André Rodlie and contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# See 'README.md' for more information.
#
*/

#ifndef FRICTION_PERSISTENTMENU_H
#define FRICTION_PERSISTENTMENU_H

#include "ui_global.h"

#include <QMenu>
#include <QMouseEvent>
#include <QAction>

namespace Friction
{
namespace Ui
{
class UI_EXPORT PersistentMenu : public QMenu
{
Q_OBJECT
public:
using QMenu::QMenu;

PersistentMenu* addPersistentMenu(const QIcon &icon,
const QString &title,
const bool onlyCheckable = false)
{
PersistentMenu *subMenu = new PersistentMenu(title, this);
subMenu->setOnlyCheckable(onlyCheckable);
subMenu->setIcon(icon);
this->addMenu(subMenu);
return subMenu;
}
void setOnlyCheckable(const bool checked)
{
mOnlyCheckable = checked;
}

private:
bool mOnlyCheckable = false;

protected:
void mouseReleaseEvent(QMouseEvent *event) override
{
QAction *action = actionAt(event->pos());
if (action && action->menu()) {
QMenu::mouseReleaseEvent(event);
return;
}
if ((action && !mOnlyCheckable) ||
(action && mOnlyCheckable && action->isCheckable())) {
action->activate(QAction::Trigger);
} else {
QMenu::mouseReleaseEvent(event);
}
}
};
}
}

#endif // FRICTION_PERSISTENTMENU_H
11 changes: 6 additions & 5 deletions src/ui/widgets/toolinteract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "Private/document.h"
#include "GUI/coloranimatorbutton.h"
#include "widgets/persistentmenu.h"

#include <QSpinBox>
#include <QLabel>
Expand All @@ -50,7 +51,7 @@ ToolInteract::ToolInteract(QWidget *parent)
void ToolInteract::setupGizmoButton()
{
const auto button = new QToolButton(this);
const auto menu = new QMenu(button);
const auto menu = new PersistentMenu(button);

button->setObjectName("ToolBoxGizmo");
button->setPopupMode(QToolButton::MenuButtonPopup);
Expand Down Expand Up @@ -155,7 +156,7 @@ void ToolInteract::setupSnapButton()
{
const auto grid = Document::sInstance->getGrid();
const auto button = new QToolButton(this);
const auto menu = new QMenu(button);
const auto menu = new PersistentMenu(button);

button->setObjectName("ToolBoxGizmo");
button->setPopupMode(QToolButton::MenuButtonPopup);
Expand Down Expand Up @@ -309,7 +310,7 @@ void ToolInteract::setupGridButton()
{
const auto grid = Document::sInstance->getGrid();
const auto button = new QToolButton(this);
const auto menu = new QMenu(button);
const auto menu = new PersistentMenu(button);

button->setObjectName("ToolBoxGizmo");
button->setPopupMode(QToolButton::MenuButtonPopup);
Expand Down Expand Up @@ -362,8 +363,8 @@ void ToolInteract::setupGridButton()
}

menu->addSeparator();
const auto optMenu = menu->addMenu(QIcon::fromTheme("preferences"),
tr("Settings"));
const auto optMenu = menu->addPersistentMenu(QIcon::fromTheme("preferences"),
tr("Settings"));

menu->addSeparator();
setupGridAction(button, Core::Grid::Option::SizeX);
Expand Down