diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj index d7932a1..4f07662 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj @@ -128,6 +128,7 @@ + @@ -224,6 +225,7 @@ + diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters index ec634e5..164cd2e 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters @@ -264,6 +264,9 @@ Source Files\Editor + + Source Files + @@ -531,6 +534,9 @@ Header Files + + Header Files + diff --git a/ArchitectureColoredPainting/RendererWidget.ui b/ArchitectureColoredPainting/RendererWidget.ui index e0d5a12..41cba11 100644 --- a/ArchitectureColoredPainting/RendererWidget.ui +++ b/ArchitectureColoredPainting/RendererWidget.ui @@ -41,7 +41,7 @@ 5 - + 0 @@ -181,9 +181,9 @@
RendererGLWidget.h
- QtMaterialFlatButton + FluentMenuButton QPushButton -
qtmaterialflatbutton.h
+
../FluentMenuButton.h
diff --git a/ArchitectureColoredPainting/src/FluentMenuButton.cpp b/ArchitectureColoredPainting/src/FluentMenuButton.cpp new file mode 100644 index 0000000..2ab7935 --- /dev/null +++ b/ArchitectureColoredPainting/src/FluentMenuButton.cpp @@ -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); +} diff --git a/ArchitectureColoredPainting/src/FluentMenuButton.h b/ArchitectureColoredPainting/src/FluentMenuButton.h new file mode 100644 index 0000000..97554a7 --- /dev/null +++ b/ArchitectureColoredPainting/src/FluentMenuButton.h @@ -0,0 +1,12 @@ +#pragma once +#include +#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; +}; diff --git a/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp b/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp index 7e1e03a..01ff2c2 100644 --- a/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp +++ b/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp @@ -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);