diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.rc b/ArchitectureColoredPainting/ArchitectureColoredPainting.rc deleted file mode 100644 index ae1f3fe..0000000 Binary files a/ArchitectureColoredPainting/ArchitectureColoredPainting.rc and /dev/null differ diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj index a60f373..8bb0b0a 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj @@ -105,7 +105,6 @@ - @@ -122,8 +121,8 @@ + - @@ -151,7 +150,6 @@ - @@ -189,7 +187,6 @@ - @@ -205,6 +202,7 @@ + @@ -217,9 +215,6 @@ - - - @@ -247,9 +242,6 @@ {8f360763-a045-3808-87a9-3fae38e69819} - - - diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters index df8eb42..750b755 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters @@ -111,15 +111,6 @@ Source Files - - Source Files - - - Source Files - - - Source Files - Source Files\Renderer\Painting @@ -216,6 +207,9 @@ Source Files\Editor + + Source Files + Source Files\Editor\util @@ -233,15 +227,6 @@ Header Files - - Header Files - - - Header Files - - - Header Files - Header Files @@ -260,6 +245,9 @@ Header Files\Editor + + Header Files + @@ -465,7 +453,4 @@ Resource Files - - - \ No newline at end of file diff --git a/ArchitectureColoredPainting/Models/Sponza/Sponza.txt b/ArchitectureColoredPainting/Models/Sponza/Sponza.txt new file mode 100644 index 0000000..abc7a1d --- /dev/null +++ b/ArchitectureColoredPainting/Models/Sponza/Sponza.txt @@ -0,0 +1,2 @@ +17876391417123941155.jpg 0.json 0 0 1 1 +11474523244911310074.jpg 1.json 0 0 1 1 \ No newline at end of file diff --git a/ArchitectureColoredPainting/RendererWidget.ui b/ArchitectureColoredPainting/RendererWidget.ui index 6986ddc..e116c32 100644 --- a/ArchitectureColoredPainting/RendererWidget.ui +++ b/ArchitectureColoredPainting/RendererWidget.ui @@ -13,7 +13,7 @@ RendererWidget - + 0 @@ -31,8 +31,14 @@ - - QLayout::SetDefaultConstraint + + 6 + + + 5 + + + 5 @@ -44,12 +50,18 @@ - 80 - 40 + 50 + 30 + + + + + 50 + 30 - 打开 + 文件 false @@ -71,34 +83,6 @@ - - - - - 0 - 0 - - - - - 0 - 0 - - - - - - 0 - 40 - - - - 打开 - - - - - diff --git a/ArchitectureColoredPainting/resource.h b/ArchitectureColoredPainting/resource.h deleted file mode 100644 index 9375764..0000000 --- a/ArchitectureColoredPainting/resource.h +++ /dev/null @@ -1,14 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by ArchitectureColoredPainting.rc - -// жÔÏóµÄÏÂÒ»×éĬÈÏÖµ -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 101 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1001 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/ArchitectureColoredPainting/src/CaptionButton.cpp b/ArchitectureColoredPainting/src/CaptionButton.cpp deleted file mode 100644 index 833bb82..0000000 --- a/ArchitectureColoredPainting/src/CaptionButton.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/* -The MIT License (MIT) - -Copyright © 2018-2022 Antonio Dias - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#include "CaptionButton.h" - -CaptionButton::CaptionButton(QWidget *parent) : QWidget(parent) -{ - m_is_active = false; - m_is_under_mouse = false; - m_is_pressed = false; - m_icon_dark = false; - - setAttribute(Qt::WA_Hover); -} - -CaptionButton::~CaptionButton() -{ - -} - -QPixmap CaptionButton::drawIcon(const QPixmap &icon, bool active, bool force_light) -{ - QImage tmp = icon.toImage(); - - if (!active) - { - for (int i = 0; i < tmp.height(); i++) - { - for (int j = 0; j < tmp.width(); j++) - { - QColor pixel = QColor::fromRgba(tmp.pixel(j, i)); - - pixel.setRedF(pixel.redF() * 0.5f); - pixel.setGreenF(pixel.greenF() * 0.5f); - pixel.setBlueF(pixel.blueF() * 0.5f); - - tmp.setPixel(j, i, pixel.rgba()); - } - } - } - - if (m_icon_dark && !force_light) - tmp.invertPixels(); - - return QPixmap::fromImage(tmp); -} - -void CaptionButton::init(IconType type) -{ - m_type = type; - - setColors(); - drawIcons(); -} - -void CaptionButton::drawIcons() -{ - switch (m_type) - { - case IconType::Minimize: - { - QPixmap icon = QPixmap(":/images/icon_window_minimize.png"); - - m_active_icon = drawIcon(icon, true); - m_inactive_icon = drawIcon(icon, false); - - break; - } - case IconType::Restore: - { - QPixmap icon = QPixmap(":/images/icon_window_restore.png"); - - m_active_icon = drawIcon(icon, true); - m_inactive_icon = drawIcon(icon, false); - - break; - } - case IconType::Maximize: - { - QPixmap icon = QPixmap(":/images/icon_window_maximize.png"); - - m_active_icon = drawIcon(icon, true); - m_inactive_icon = drawIcon(icon, false); - - break; - } - case IconType::Close: - { - QPixmap icon = QPixmap(":/images/icon_window_close.png"); - - m_active_icon = drawIcon(icon, true); - m_inactive_icon = drawIcon(icon, false); - m_close_icon_hover = drawIcon(icon, true, true); - - break; - } - } -} - -void CaptionButton::setColors() -{ - if (m_icon_dark) - { - if (m_type == IconType::Close) - { - m_normal = QColor("transparent"); - m_hover = QColor("#F00000"); - m_pressed = QColor("#F1707A"); - } - else - { - m_normal = QColor("transparent"); - m_hover = QColor("#E5E5E5"); - m_pressed = QColor("#CACACB"); - } - } - else - { - if (m_type == IconType::Close) - { - m_normal = QColor("transparent"); - m_hover = QColor("#F00000"); - m_pressed = QColor("#F1707A"); - } - else - { - m_normal = QColor("transparent"); - m_hover = QColor("#505050"); - m_pressed = QColor("#3F3F3F"); - } - } - - repaint(); -} - -void CaptionButton::setIconMode(bool icon_dark) -{ - m_icon_dark = icon_dark; - - drawIcons(); - setColors(); - - repaint(); -} - -void CaptionButton::setActive(bool is_active) -{ - m_is_active = is_active; - - repaint(); -} - -void CaptionButton::setState(int state) -{ - switch (state) - { - case QEvent::HoverEnter: - { - m_is_under_mouse = true; - - repaint(); - - break; - } - case QEvent::HoverLeave: - { - m_is_under_mouse = false; - - repaint(); - - break; - } - case QEvent::MouseButtonPress: - { - m_is_pressed = true; - - m_is_under_mouse = true; - - repaint(); - - break; - } - case QEvent::MouseButtonRelease: - { - m_is_pressed = false; - - m_is_under_mouse = false; - - repaint(); - - break; - } - default: - break; - } -} - -void CaptionButton::paintEvent(QPaintEvent *event) -{ - Q_UNUSED(event) - - QPixmap current_icon = m_active_icon; - QColor current_color = m_normal; - - //Change icon if needed - if (m_is_under_mouse) - { - if (m_type == IconType::Close) - current_icon = m_close_icon_hover; - } - else - { - if (!m_is_active) - current_icon = m_inactive_icon; - } - - //Change background color if needed - if (m_is_pressed) - { - if (m_is_under_mouse) - current_color = m_pressed; - } - else - { - if (m_is_under_mouse) - current_color = m_hover; - } - - QPainter painter(this); - painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - painter.setCompositionMode(QPainter::CompositionMode_SourceOver); - - painter.fillRect(rect(), current_color); - - QRect target_rect; - target_rect = current_icon.rect(); - target_rect.setSize(QSize(16, 16)); - target_rect = QRect(rect().center() - target_rect.center(), target_rect.size()); - painter.drawPixmap(target_rect, current_icon); -} diff --git a/ArchitectureColoredPainting/src/CaptionButton.h b/ArchitectureColoredPainting/src/CaptionButton.h deleted file mode 100644 index e2a3f2b..0000000 --- a/ArchitectureColoredPainting/src/CaptionButton.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -The MIT License (MIT) - -Copyright © 2018-2022 Antonio Dias - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#ifndef CAPTIONBUTTON_H -#define CAPTIONBUTTON_H - -#include -#include -#include - -class CaptionButton : public QWidget -{ - Q_OBJECT -public: - explicit CaptionButton(QWidget *parent = nullptr); - ~CaptionButton(); - - enum class IconType - { - Minimize, - Restore, - Maximize, - Close - }; - - void init(IconType type); - -signals: - void clicked(); - -public slots: - void setIconMode(bool icon_dark); - void setActive(bool is_active); - void setState(int state); - -private: - //Functions - QPixmap drawIcon(const QPixmap &icon, bool active, bool force_light = false); - void setColors(); - void drawIcons(); - void paintEvent(QPaintEvent *event); - - //Variables - QPixmap m_inactive_icon; - QPixmap m_active_icon; - - QPixmap m_close_icon_hover; - - QColor m_normal; - QColor m_hover; - QColor m_pressed; - - IconType m_type; - bool m_is_active; - bool m_is_under_mouse; - bool m_is_pressed; - bool m_icon_dark; -}; - -#endif // CAPTIONBUTTON_H diff --git a/ArchitectureColoredPainting/src/FluentMenu.cpp b/ArchitectureColoredPainting/src/FluentMenu.cpp new file mode 100644 index 0000000..42b0f7d --- /dev/null +++ b/ArchitectureColoredPainting/src/FluentMenu.cpp @@ -0,0 +1,24 @@ +#include "FluentMenu.h" +#include +#include + +::FluentMenu::FluentMenu(QWidget* parent) : QMenu(parent) +{ + setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint); + setAttribute(Qt::WA_TranslucentBackground); + setStyleSheet(QString::fromStdString(std::format("QMenu {{margin:{}px;border-radius:{}px;padding:4px;border: 1px solid #c1c1c1;}}" + "QMenu::item {{height:30px;width:100px;padding-left:20px;border-radius:{}px;}}" + "QMenu::item:selected {{background-color:#dedede;}}", shadowRadius, borderRadius, itemBorderRadius))); +} + +void ::FluentMenu::paintEvent(QPaintEvent* event) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing, true); + for (qreal i = 0; i < shadowRadius; i += 1 / devicePixelRatioF()) + { + painter.setPen(QColor(0, 0, 0, glm::mix(0.22 * 255, 0., glm::pow(i / shadowRadius, 0.2)))); + painter.drawRoundedRect(QRectF(shadowRadius - i, shadowRadius - i, width() - (shadowRadius - i) * 2, height() - (shadowRadius - i) * 2), borderRadius + i, borderRadius + i); + } + QMenu::paintEvent(event); +} \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/FluentMenu.h b/ArchitectureColoredPainting/src/FluentMenu.h new file mode 100644 index 0000000..480f6e2 --- /dev/null +++ b/ArchitectureColoredPainting/src/FluentMenu.h @@ -0,0 +1,14 @@ +#pragma once +#include + +class FluentMenu : public QMenu +{ + Q_OBJECT +public: + explicit FluentMenu(QWidget* parent = nullptr); + void paintEvent(QPaintEvent* event) override; + int shadowRadius = 16; + int borderRadius = 6; + int itemBorderRadius = 4; +}; + diff --git a/ArchitectureColoredPainting/src/IconWidget.cpp b/ArchitectureColoredPainting/src/IconWidget.cpp deleted file mode 100644 index 65412b2..0000000 --- a/ArchitectureColoredPainting/src/IconWidget.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* -The MIT License (MIT) - -Copyright © 2018-2022 Antonio Dias - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#include "iconwidget.h" - -#define ICONWIDTH 16 -#define ICONHEIGHT 16 - -IconWidget::IconWidget(QWidget *parent) : QWidget(parent) -{ - m_active = true; -} - -void IconWidget::setPixmap(const QPixmap &pixmap) -{ - m_pixmap = pixmap; - - QImage tmp = m_pixmap.toImage(); - - for (int i = 0; i < m_pixmap.width(); i++) - { - for (int j = 0; j < m_pixmap.height(); j++) - { - int gray = qGray(tmp.pixel(i, j)); - - int alpha = qAlpha(tmp.pixel(i, j)); - - tmp.setPixel(i, j, qRgba(gray, gray, gray, alpha)); - } - } - - m_grayed_pixmap = QPixmap::fromImage(tmp); - - repaint(); -} - -void IconWidget::setActive(bool active) -{ - m_active = active; - repaint(); -} - -void IconWidget::paintEvent(QPaintEvent *event) -{ - Q_UNUSED(event) - - QPainter painter(this); - painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - - painter.drawPixmap((width() - ICONWIDTH)/ 2, - (height() - ICONHEIGHT) / 2, - ICONWIDTH, ICONHEIGHT, - m_active ? m_pixmap : m_grayed_pixmap); -} diff --git a/ArchitectureColoredPainting/src/IconWidget.h b/ArchitectureColoredPainting/src/IconWidget.h deleted file mode 100644 index 94f489d..0000000 --- a/ArchitectureColoredPainting/src/IconWidget.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -The MIT License (MIT) - -Copyright © 2018-2022 Antonio Dias - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#ifndef ICONWIDGET_H -#define ICONWIDGET_H - -#include -#include -#include - -class IconWidget : public QWidget -{ - Q_OBJECT -public: - explicit IconWidget(QWidget *parent = nullptr); - -public slots: - void setPixmap(const QPixmap &pixmap); - void setActive(bool active); - -private: - //Functions - void paintEvent(QPaintEvent *event); - - //Variables - QPixmap m_pixmap; - QPixmap m_grayed_pixmap; - bool m_active; -}; - -#endif // ICONWIDGET_H diff --git a/ArchitectureColoredPainting/src/MainWindow.cpp b/ArchitectureColoredPainting/src/MainWindow.cpp index 12b8bad..485a39f 100644 --- a/ArchitectureColoredPainting/src/MainWindow.cpp +++ b/ArchitectureColoredPainting/src/MainWindow.cpp @@ -15,7 +15,7 @@ FRAMELESSHELPER_USE_NAMESPACE CentralWidget::CentralWidget(QWidget* parent) : QMainWindow(parent) { ui.setupUi(this); - NavigationBarWidget* navigationBarWidget = new NavigationBarWidget(); + NavigationBarWidget* navigationBarWidget = new NavigationBarWidget(this); ui.gridLayout->addWidget(navigationBarWidget, 0, 0, 1, 1, Qt::AlignTop | Qt::AlignHCenter); QObject::connect(navigationBarWidget->tabs, &QtMaterialTabs::currentChanged, ui.stackedWidget, &QStackedWidget::setCurrentIndex); QObject::connect(ui.stackedWidget, &QStackedWidget::currentChanged, diff --git a/ArchitectureColoredPainting/src/Renderer/Model.cpp b/ArchitectureColoredPainting/src/Renderer/Model.cpp index 6182387..0cd402c 100644 --- a/ArchitectureColoredPainting/src/Renderer/Model.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Model.cpp @@ -45,19 +45,41 @@ void Model::drawShadow() { void Renderer::Model::loadModel(QString path) { - directory = path; + QFileInfo modelFile(path); + name = modelFile.baseName(); + directory = modelFile.dir(); + Assimp::Importer importer; - const aiScene* scene = importer.ReadFile(directory.absolutePath().toUtf8(), aiProcess_Triangulate | aiProcess_FlipUVs); + const aiScene* scene = importer.ReadFile(modelFile.absoluteFilePath().toUtf8(), aiProcess_Triangulate | aiProcess_FlipUVs); if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) { - qDebug() << "ERROR::ASSIMP::" << importer.GetErrorString() << endl; + qCritical() << "ERROR::ASSIMP::" << importer.GetErrorString() << endl; return; } - qDebug() << directory.absolutePath() << "Loaded Successfully"; + qDebug() << modelFile.absoluteFilePath() << "Loaded Successfully"; qDebug() << "NumMeshes: " << scene->mNumMeshes; qDebug() << "NumMaterials: " << scene->mNumMaterials; qDebug() << "NumTextures: " << scene->mNumTextures; - directory.cdUp(); + + if (QFile paintingConfigFile(directory.filePath(name + ".txt")); paintingConfigFile.open(QFile::ReadOnly | QIODevice::Text)) + { + paintingMap.clear(); + QTextStream stream(&paintingConfigFile); + while (!stream.atEnd()) + { + QString source, target; + glm::vec2 leftBottom, rightTop; + stream >> source >> target >> leftBottom.x >> leftBottom.y >> rightTop.x >> rightTop.y; + qDebug() << source << target << leftBottom.x << leftBottom.y << rightTop.x << rightTop.y; + paintingMap.emplace(source.toStdString(), std::forward_as_tuple(target.toStdString(), leftBottom, rightTop)); + } + paintingConfigFile.close(); + } + else + { + qWarning() << "Painting Config Not Found!"; + } + minX = std::numeric_limits::max(); maxX = std::numeric_limits::min(); minY = std::numeric_limits::max(); @@ -99,8 +121,9 @@ std::unique_ptr Model::processMesh(aiMesh* mesh, const aiScene* scene, aiString str; material->GetTexture(aiTextureType_BASE_COLOR, 0, &str); - if (paintingProgram != nullptr && (std::strcmp(str.C_Str(), "17876391417123941155.jpg") == 0 || std::strcmp(str.C_Str(), "11474523244911310074.jpg") == 0)) + if (auto iter = paintingMap.find(std::string(str.C_Str())); paintingProgram != nullptr && iter != paintingMap.end()) { + auto& [paintingPath, leftBottom, rightTop] = iter->second; qDebug() << str.C_Str() << "Replaced"; // ³õʼ»¯Íø¸ñ auto m_mesh = std::make_unique(glFunc, paintingProgram, shadowProgram, modelQ); @@ -129,7 +152,7 @@ std::unique_ptr Model::processMesh(aiMesh* mesh, const aiScene* scene, } } - m_mesh->paintingId = loadPainting(std::string(str.C_Str())); + m_mesh->paintingId = loadPainting(paintingPath); auto& handle = vtManager->getPaintingHandle(m_mesh->paintingId); m_mesh->textureBasecolor = handle.baseColor; m_mesh->textureMetallicRoughness = handle.metallicRoughness; @@ -250,7 +273,7 @@ GLuint Renderer::Model::loadPainting(std::string path) }; Painting painting; - if (path == "17876391417123941155.jpg") + if (path == "0.json") { painting.addElement(*element[0], ElementTransform{ glm::vec2(-0.45,-0.45), glm::vec2(0.5,0.5) / 2.f, 0, glm::bvec2(false), 0 }); painting.addElement(*element[1], ElementTransform{ glm::vec2(-0.45, 0.45), glm::vec2(0.5,0.5) / 2.f, 0, glm::bvec2(false), 0 }); @@ -266,7 +289,6 @@ GLuint Renderer::Model::loadPainting(std::string path) } } - painting.generateBuffers(glFunc); auto index = vtManager->createVirtualTexture(painting); diff --git a/ArchitectureColoredPainting/src/Renderer/Model.h b/ArchitectureColoredPainting/src/Renderer/Model.h index 0c0dca0..c19fdf3 100644 --- a/ArchitectureColoredPainting/src/Renderer/Model.h +++ b/ArchitectureColoredPainting/src/Renderer/Model.h @@ -17,20 +17,20 @@ namespace Renderer void loadModel(QString path); Model(QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* paintingProgram, QOpenGLShaderProgram* shadowProgram, VirtualTextureManager* vtManager); private: - QOpenGLContext* context; + QOpenGLContext* context = nullptr; QOpenGLFunctions_4_5_Core* glFunc = nullptr; QOpenGLShaderProgram* shaderProgram = nullptr; QOpenGLShaderProgram* paintingProgram = nullptr; QOpenGLShaderProgram* shadowProgram = nullptr; VirtualTextureManager* vtManager = nullptr; - /* Ä£ÐÍÊý¾Ý */ + std::unordered_map> paintingMap; std::unordered_map paintingLoaded; std::unordered_map texturesLoaded; std::vector> meshes; - - /// Ä£ÐÍËùÔÚ·¾¶ - QDir directory; + + QDir directory; /// Ä£ÐÍËùÔÚ·¾¶ + QString name; /// Ä£ÐÍÎļþÃû float minX, maxX, minY, maxY, minZ, maxZ; diff --git a/ArchitectureColoredPainting/src/Renderer/Preview/ElementRenderer.cpp b/ArchitectureColoredPainting/src/Renderer/Preview/ElementRenderer.cpp index d7744a7..46bbb40 100644 --- a/ArchitectureColoredPainting/src/Renderer/Preview/ElementRenderer.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Preview/ElementRenderer.cpp @@ -118,9 +118,7 @@ Renderer::ElementRenderer::ElementRenderer(QOpenGLWidget* glWidget) : glWidget(glWidget) { surface.create(); - thread = std::jthread([&] { - std::cout << thread.get_id(); QOpenGLContext context; context.create(); context.makeCurrent(&surface); diff --git a/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp b/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp index 244f3c9..27bc6c8 100644 --- a/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp +++ b/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp @@ -1,25 +1,44 @@ #include "RendererWidget.h" #include "RendererGLWidget.h" +#include "../FluentMenu.h" -Renderer::RendererWidget::RendererWidget(QWidget *parent) +Renderer::RendererWidget::RendererWidget(QWidget* parent) : QWidget(parent) { ui.setupUi(this); + + FluentMenu* menu = new FluentMenu(this); + auto openAction = new QAction(QStringLiteral("´ò¿ª"), menu); + auto saveAction = new QAction(QStringLiteral("±£´æ"), menu); + menu->addAction(openAction); + menu->addAction(saveAction); + 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(-menu->shadowRadius, ui.openButton->height() - menu->shadowRadius))); + }); + QObject::connect(ui.horizontalSlider, &QSlider::valueChanged, ui.openGLWidget, &Renderer::RendererGLWidget::setMainLightPitch); QObject::connect(ui.horizontalSlider_2, &QSlider::valueChanged, ui.openGLWidget, &Renderer::RendererGLWidget::setMainLightYaw); QObject::connect(ui.exposureSlider, &QSlider::valueChanged, [&](int value) { - ui.openGLWidget->setExposure(value/100.f); + ui.openGLWidget->setExposure(value / 100.f); }); + QObject::connect(openAction, &QAction::triggered, ui.openGLWidget, &Renderer::RendererGLWidget::setModel); ui.horizontalSlider->setValue(105); ui.horizontalSlider_2->setValue(80); ui.exposureSlider->setValue(60); - QObject::connect(ui.openButton, &QPushButton::clicked, - ui.openGLWidget, &Renderer::RendererGLWidget::setModel); } Renderer::RendererWidget::~RendererWidget() @@ -35,4 +54,5 @@ void Renderer::RendererWidget::currentTabChanged(int index) { ui.openGLWidget->stopTimer(); } -} \ No newline at end of file +} + diff --git a/ArchitectureColoredPainting/src/Renderer/RendererWidget.h b/ArchitectureColoredPainting/src/Renderer/RendererWidget.h index 8d3f1e2..258a173 100644 --- a/ArchitectureColoredPainting/src/Renderer/RendererWidget.h +++ b/ArchitectureColoredPainting/src/Renderer/RendererWidget.h @@ -1,15 +1,14 @@ #pragma once #include +#include #include "ui_RendererWidget.h" namespace Renderer { class RendererWidget : public QWidget { Q_OBJECT - public: - RendererWidget(QWidget* parent = nullptr); ~RendererWidget(); public slots: diff --git a/ArchitectureColoredPainting/src/TitleWidget.cpp b/ArchitectureColoredPainting/src/TitleWidget.cpp deleted file mode 100644 index cd4d5b6..0000000 --- a/ArchitectureColoredPainting/src/TitleWidget.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* -The MIT License (MIT) - -Copyright © 2018-2022 Antonio Dias - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#include "titlewidget.h" - -TitleWidget::TitleWidget(QWidget *parent) : QWidget(parent) -{ - m_active = false; -} - -void TitleWidget::setText(const QString &text) -{ - m_title = text; - repaint(); -} - -void TitleWidget::setActive(bool active) -{ - m_active = active; - repaint(); -} - -void TitleWidget::setTitleColor(const QColor &active_color, const QColor &inactive_color) -{ - m_active_color = active_color; - m_inactive_color = inactive_color; - - repaint(); -} - -void TitleWidget::paintEvent(QPaintEvent *event) -{ - Q_UNUSED(event) - - QPainter painter(this); - painter.setRenderHints(QPainter::Antialiasing); - - QFont font; - font.setPointSize(10); -#ifdef Q_OS_WIN - font.setFamily("Segoe UI, Microsoft YaHei UI"); -#else - font.setFamily(qApp->font().family()); -#endif - - painter.setFont(font); - - QPen pen; - pen.setColor(m_active ? m_active_color : m_inactive_color); - - painter.setPen(pen); - - QFontMetrics metrics(painter.font()); - QSize title_size = metrics.size(0, m_title); - - QString title = metrics.elidedText(m_title, Qt::ElideRight, width()); - - painter.drawText(0, (height() - title_size.height()) / 2, title_size.width(), title_size.height(), 0, title); -} diff --git a/ArchitectureColoredPainting/src/TitleWidget.h b/ArchitectureColoredPainting/src/TitleWidget.h deleted file mode 100644 index ea297b7..0000000 --- a/ArchitectureColoredPainting/src/TitleWidget.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -The MIT License (MIT) - -Copyright © 2018-2022 Antonio Dias - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#ifndef TITLEWIDGET_H -#define TITLEWIDGET_H - -#include -#include -#include - -class TitleWidget : public QWidget -{ - Q_OBJECT -public: - explicit TitleWidget(QWidget *parent = nullptr); - -public slots: - void setText(const QString &text); - void setActive(bool active); - void setTitleColor(const QColor &active_color, const QColor &inactive_color); - -private: - //Functions - void paintEvent(QPaintEvent *event); - - //Variables - QString m_title; - bool m_active; - QColor m_active_color; - QColor m_inactive_color; -}; - -#endif // TITLEWIDGET_H diff --git a/UnitTest/ElementRendererTest.h b/UnitTest/ElementRendererTest.h index c6d1651..5c1e12c 100644 --- a/UnitTest/ElementRendererTest.h +++ b/UnitTest/ElementRendererTest.h @@ -22,7 +22,6 @@ namespace UnitTest void initializeGL() override { initializeOpenGLFunctions(); - renderer.initialize(); }; void paintGL() override { @@ -35,7 +34,7 @@ namespace UnitTest transform.scale(10, 10); path = transform.map(path); float pixelRatio = devicePixelRatioF(); - auto [img, pos] = renderer.drawElement(path, style, pixelRatio, false); + auto [img, pos] = renderer.drawElement(path, style, pixelRatio); QPainter painter(this); painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::HighQualityAntialiasing);