为FluentMenu提供更完善的封装类型FluentMenuButton | #24

dev-wuyize
wuyize 2023-03-21 15:15:41 +08:00
parent 291d112d11
commit 3a693de9fe
6 changed files with 61 additions and 26 deletions

View File

@ -128,6 +128,7 @@
<ClCompile Include="src\Editor\util\PaintingUtil.cpp" />
<ClCompile Include="src\Editor\util\SvgFileLoader.cpp" />
<ClCompile Include="src\FluentMenu.cpp" />
<ClCompile Include="src\FluentMenuButton.cpp" />
<ClCompile Include="src\gl.c" />
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\MainWindow.cpp" />
@ -224,6 +225,7 @@
<ClInclude Include="src\Editor\util\PaintingUtil.h" />
<ClInclude Include="src\Editor\util\SvgFileLoader.h" />
<QtMoc Include="src\FluentMenu.h" />
<ClInclude Include="src\FluentMenuButton.h" />
<ClInclude Include="src\Renderer\IblUtils.h" />
<ClInclude Include="src\Renderer\Painting\BaseStyle.h" />
<ClInclude Include="src\Renderer\Painting\CubicBezierSignedDistance.h" />

View File

@ -264,6 +264,9 @@
<ClCompile Include="src\Editor\EditorWidgetComponent\ColorPicker.cpp">
<Filter>Source Files\Editor</Filter>
</ClCompile>
<ClCompile Include="src\FluentMenuButton.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtMoc Include="src\Renderer\RendererGLWidget.h">
@ -531,6 +534,9 @@
<ClInclude Include="src\Editor\DataManager\ProjectDataManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\FluentMenuButton.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<QtRcc Include="res\MainWindow.qrc">

View File

@ -41,7 +41,7 @@
<number>5</number>
</property>
<item>
<widget class="QtMaterialFlatButton" name="openButton">
<widget class="FluentMenuButton" name="openButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -181,9 +181,9 @@
<header>RendererGLWidget.h</header>
</customwidget>
<customwidget>
<class>QtMaterialFlatButton</class>
<class>FluentMenuButton</class>
<extends>QPushButton</extends>
<header location="global">qtmaterialflatbutton.h</header>
<header>../FluentMenuButton.h</header>
</customwidget>
</customwidgets>
<resources/>

View File

@ -0,0 +1,30 @@
#include "FluentMenuButton.h"
FluentMenuButton::FluentMenuButton(QWidget* parent)
: FluentMenuButton("Menu", parent)
{
}
FluentMenuButton::FluentMenuButton(const QString& text, QWidget* parent)
: QtMaterialFlatButton(text, parent)
{
menu = new FluentMenu(this);
setHaloVisible(false);
setOverlayStyle(::Material::TintedOverlay);
setCheckable(true);
QObject::connect(menu, &QMenu::aboutToShow, [&] {
setChecked(true);
});
QObject::connect(menu, &QMenu::aboutToHide, [&] {
setChecked(false);
});
QObject::connect(this, &QPushButton::clicked, [&]() {
menu->exec(mapToGlobal(QPoint(0, height())));
});
}
void FluentMenuButton::addMenuAction(QAction* action)
{
menu->addAction(action);
}

View File

@ -0,0 +1,12 @@
#pragma once
#include <qtmaterialflatbutton.h>
#include "FluentMenu.h"
class FluentMenuButton : public QtMaterialFlatButton
{
public:
explicit FluentMenuButton(QWidget* parent = nullptr);
explicit FluentMenuButton(const QString& text, QWidget* parent = nullptr);
void addMenuAction(QAction* action);
FluentMenu* menu = nullptr;
};

View File

@ -8,29 +8,14 @@ Renderer::RendererWidget::RendererWidget(QWidget* parent)
{
ui.setupUi(this);
FluentMenu* menu = new FluentMenu(this);
auto openAction = new QAction(QStringLiteral("´ò¿ª"), menu);
auto saveAction = new QAction(QStringLiteral("±£´æ"), menu);
auto testAction = new QAction(QStringLiteral("²âÊÔ"), menu);
auto test2Action = new QAction(QStringLiteral("²âÊÔ2"), menu);
menu->addAction(openAction);
menu->addAction(saveAction);
menu->addAction(testAction);
menu->addAction(test2Action);
ui.openButton->setHaloVisible(false);
ui.openButton->setOverlayStyle(::Material::TintedOverlay);
ui.openButton->setCheckable(true);
QObject::connect(menu, &QMenu::aboutToShow, [&]() {
ui.openButton->setChecked(true);
});
QObject::connect(menu, &QMenu::aboutToHide, [&]() {
ui.openButton->setChecked(false);
});
QObject::connect(ui.openButton, &QPushButton::clicked, [&, menu]() {
menu->exec(ui.openButton->mapToGlobal(QPoint(0, ui.openButton->height())));
});
auto openAction = new QAction(QStringLiteral("´ò¿ª"), ui.openButton);
auto saveAction = new QAction(QStringLiteral("±£´æ"), ui.openButton);
auto testAction = new QAction(QStringLiteral("²âÊÔ"), ui.openButton);
auto test2Action = new QAction(QStringLiteral("²âÊÔ2"), ui.openButton);
ui.openButton->addMenuAction(openAction);
ui.openButton->addMenuAction(saveAction);
ui.openButton->addMenuAction(testAction);
ui.openButton->addMenuAction(test2Action);
QObject::connect(ui.horizontalSlider, &QSlider::valueChanged,
ui.openGLWidget, &Renderer::RendererGLWidget::setMainLightPitch);