From 65b14200a5b0a97d509e6e407908149619705e1e Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Sat, 7 Apr 2018 19:51:33 +0800 Subject: [PATCH] Make part list more tidy --- src/meshgenerator.cpp | 6 +++-- src/modelmeshbinder.cpp | 23 +++++++++++++---- src/modelmeshbinder.h | 3 +++ src/modelofflinerender.cpp | 13 ++++++++-- src/modelwidget.cpp | 2 +- src/skeletondocumentwindow.cpp | 47 +++++++++++++++++++--------------- src/skeletonpartlistwidget.cpp | 27 ++++++++++++------- src/theme.cpp | 4 ++- src/theme.h | 2 ++ 9 files changed, 86 insertions(+), 41 deletions(-) diff --git a/src/meshgenerator.cpp b/src/meshgenerator.cpp index 07b337b9..52179dae 100644 --- a/src/meshgenerator.cpp +++ b/src/meshgenerator.cpp @@ -189,7 +189,8 @@ void MeshGenerator::process() qDebug() << "m_requirePartPreviewMap.find:" << partIdIt; if (m_requirePartPreviewMap.find(partIdIt) != m_requirePartPreviewMap.end()) { ModelOfflineRender *render = m_partPreviewRenderMap[partIdIt]; - render->updateMesh(new Mesh(meshliteContext, meshId)); + int trimedMeshId = meshlite_trim(meshliteContext, meshId, 1); + render->updateMesh(new Mesh(meshliteContext, trimedMeshId)); QImage *image = new QImage(render->toImage(QSize(Theme::previewImageSize, Theme::previewImageSize))); m_partPreviewMap[partIdIt] = image; } @@ -211,7 +212,8 @@ void MeshGenerator::process() QImage *image = new QImage(m_previewRender->toImage(QSize(Theme::previewImageSize, Theme::previewImageSize))); m_preview = image; } - m_mesh = new Mesh(meshliteContext, mergedMeshId); + int trimedMeshId = meshlite_trim(meshliteContext, mergedMeshId, 1); + m_mesh = new Mesh(meshliteContext, trimedMeshId); } if (m_previewRender) { diff --git a/src/modelmeshbinder.cpp b/src/modelmeshbinder.cpp index f414336c..1f123497 100644 --- a/src/modelmeshbinder.cpp +++ b/src/modelmeshbinder.cpp @@ -8,7 +8,8 @@ ModelMeshBinder::ModelMeshBinder() : m_renderTriangleVertexCount(0), m_renderEdgeVertexCount(0), m_mesh(NULL), - m_meshUpdated(false) + m_meshUpdated(false), + m_showFrames(true) { } @@ -102,10 +103,12 @@ void ModelMeshBinder::paint() m_meshUpdated = false; } } - - if (m_renderEdgeVertexCount > 0) { - QOpenGLVertexArrayObject::Binder vaoBinder(&m_vaoEdge); - glDrawArrays(GL_LINES, 0, m_renderEdgeVertexCount); + + if (m_showFrames) { + if (m_renderEdgeVertexCount > 0) { + QOpenGLVertexArrayObject::Binder vaoBinder(&m_vaoEdge); + glDrawArrays(GL_LINES, 0, m_renderEdgeVertexCount); + } } if (m_renderTriangleVertexCount > 0) { QOpenGLVertexArrayObject::Binder vaoBinder(&m_vaoTriangle); @@ -120,3 +123,13 @@ void ModelMeshBinder::cleanup() if (m_vboEdge.isCreated()) m_vboEdge.destroy(); } + +void ModelMeshBinder::showFrames() +{ + m_showFrames = true; +} + +void ModelMeshBinder::hideFrames() +{ + m_showFrames = false; +} diff --git a/src/modelmeshbinder.h b/src/modelmeshbinder.h index 3cf036d3..c2d11d25 100644 --- a/src/modelmeshbinder.h +++ b/src/modelmeshbinder.h @@ -16,6 +16,8 @@ public: void initialize(); void paint(); void cleanup(); + void showFrames(); + void hideFrames(); private: QOpenGLVertexArrayObject m_vaoTriangle; QOpenGLBuffer m_vboTriangle; @@ -26,6 +28,7 @@ private: int m_renderTriangleVertexCount; int m_renderEdgeVertexCount; bool m_meshUpdated; + bool m_showFrames; }; #endif diff --git a/src/modelofflinerender.cpp b/src/modelofflinerender.cpp index b1b74e15..af689c7d 100644 --- a/src/modelofflinerender.cpp +++ b/src/modelofflinerender.cpp @@ -10,7 +10,14 @@ ModelOfflineRender::ModelOfflineRender(QScreen *targetScreen) : { create(); m_context = new QOpenGLContext(); - m_context->setFormat(format()); + + QSurfaceFormat fmt = format(); + fmt.setAlphaBufferSize(8); + fmt.setSamples(4); + + setFormat(fmt); + + m_context->setFormat(fmt); m_context->create(); } @@ -41,6 +48,7 @@ QImage ModelOfflineRender::toImage(const QSize &size) QOpenGLFramebufferObjectFormat format; format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); + format.setSamples(16); QOpenGLFramebufferObject *renderFbo = new QOpenGLFramebufferObject(size, format); renderFbo->bind(); m_context->functions()->glViewport(0, 0, size.width(), size.height()); @@ -56,6 +64,7 @@ QImage ModelOfflineRender::toImage(const QSize &size) ModelShaderProgram *program = new ModelShaderProgram; ModelMeshBinder meshBinder; meshBinder.initialize(); + meshBinder.hideFrames(); program->setUniformValue(program->lightPosLoc(), QVector3D(0, 0, 70)); @@ -65,7 +74,7 @@ QImage ModelOfflineRender::toImage(const QSize &size) glEnable(GL_LINE_SMOOTH); camera.setToIdentity(); - camera.translate(0, 0, -2.5); + camera.translate(0, 0, -2.1); world.setToIdentity(); world.rotate(180.0f - (xRot / 16.0f), 1, 0, 0); diff --git a/src/modelwidget.cpp b/src/modelwidget.cpp index d46f6feb..77b9e523 100644 --- a/src/modelwidget.cpp +++ b/src/modelwidget.cpp @@ -125,7 +125,7 @@ void ModelWidget::initializeGL() // Our camera never changes in this example. m_camera.setToIdentity(); - m_camera.translate(0, 0, -3.5); + m_camera.translate(0, 0, -2.1); // Light position is fixed. m_program->setUniformValue(m_program->lightPosLoc(), QVector3D(0, 0, 70)); diff --git a/src/skeletondocumentwindow.cpp b/src/skeletondocumentwindow.cpp index e7b8610f..bd3dffee 100644 --- a/src/skeletondocumentwindow.cpp +++ b/src/skeletondocumentwindow.cpp @@ -103,35 +103,38 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() : m_modelWidget->setGraphicsFunctions(graphicsWidget); SkeletonPartListWidget *partListWidget = new SkeletonPartListWidget(m_document); + partListWidget->setMaximumWidth(Theme::previewImageSize); - QTabWidget *firstTabWidget = new QTabWidget; - firstTabWidget->setFont(Theme::awesome()->font(Theme::toolIconFontSize * 3 / 4)); - firstTabWidget->setMaximumWidth(200); - firstTabWidget->addTab(partListWidget, QChar(fa::puzzlepiece)); - firstTabWidget->addTab(new QWidget, QChar(fa::history)); - firstTabWidget->addTab(new QWidget, QChar(fa::wrench)); + //QTabWidget *firstTabWidget = new QTabWidget; + //firstTabWidget->setFont(Theme::awesome()->font(Theme::toolIconFontSize * 3 / 4)); + //firstTabWidget->setMaximumWidth(200); + //firstTabWidget->addTab(partListWidget, QChar(fa::puzzlepiece)); + //firstTabWidget->addTab(new QWidget, QChar(fa::history)); + //firstTabWidget->addTab(new QWidget, QChar(fa::wrench)); - SkeletonEdgePropertyWidget *edgePropertyWidget = new SkeletonEdgePropertyWidget(m_document); - SkeletonNodePropertyWidget *nodePropertyWidget = new SkeletonNodePropertyWidget(m_document); + //SkeletonEdgePropertyWidget *edgePropertyWidget = new SkeletonEdgePropertyWidget(m_document); + //SkeletonNodePropertyWidget *nodePropertyWidget = new SkeletonNodePropertyWidget(m_document); - QVBoxLayout *propertyLayout = new QVBoxLayout; - propertyLayout->addWidget(edgePropertyWidget); - propertyLayout->addWidget(nodePropertyWidget); + //QVBoxLayout *propertyLayout = new QVBoxLayout; + //propertyLayout->addWidget(edgePropertyWidget); + //propertyLayout->addWidget(nodePropertyWidget); - QWidget *propertyWidget = new QWidget; - propertyWidget->setLayout(propertyLayout); + //QWidget *propertyWidget = new QWidget; + //propertyWidget->setLayout(propertyLayout); - QTabWidget *secondTabWidget = new QTabWidget; - secondTabWidget->setFont(Theme::awesome()->font(Theme::toolIconFontSize * 3 / 4)); - secondTabWidget->setMaximumWidth(200); - secondTabWidget->setMaximumHeight(90); - secondTabWidget->addTab(propertyWidget, QChar(fa::adjust)); + //QTabWidget *secondTabWidget = new QTabWidget; + //secondTabWidget->setFont(Theme::awesome()->font(Theme::toolIconFontSize * 3 / 4)); + //secondTabWidget->setMaximumWidth(200); + //secondTabWidget->setMaximumHeight(90); + //secondTabWidget->addTab(propertyWidget, QChar(fa::adjust)); QVBoxLayout *mainRightLayout = new QVBoxLayout; mainRightLayout->setSpacing(0); - mainRightLayout->setContentsMargins(5, 5, 5, 5); - mainRightLayout->addWidget(firstTabWidget); - mainRightLayout->addWidget(secondTabWidget); + //mainRightLayout->setContentsMargins(5, 5, 5, 5); + mainRightLayout->setContentsMargins(0, 0, 0, 0); + mainRightLayout->addWidget(partListWidget); + //mainRightLayout->addWidget(firstTabWidget); + //mainRightLayout->addWidget(secondTabWidget); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->setSpacing(0); @@ -194,6 +197,7 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() : connect(m_document, &SkeletonDocument::partListChanged, partListWidget, &SkeletonPartListWidget::partListChanged); connect(m_document, &SkeletonDocument::partPreviewChanged, partListWidget, &SkeletonPartListWidget::partPreviewChanged); + /* connect(graphicsWidget, &SkeletonGraphicsWidget::checkEdge, edgePropertyWidget, &SkeletonEdgePropertyWidget::showProperties); connect(graphicsWidget, &SkeletonGraphicsWidget::uncheckEdge, [=](QUuid edgeId) { edgePropertyWidget->hide(); @@ -215,6 +219,7 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() : } }); connect(nodePropertyWidget, &SkeletonNodePropertyWidget::setNodeRootMarkMode, m_document, &SkeletonDocument::setNodeRootMarkMode); + */ connect(m_document, &SkeletonDocument::skeletonChanged, m_document, &SkeletonDocument::generateMesh); diff --git a/src/skeletonpartlistwidget.cpp b/src/skeletonpartlistwidget.cpp index f6c5a82f..c46c78fa 100644 --- a/src/skeletonpartlistwidget.cpp +++ b/src/skeletonpartlistwidget.cpp @@ -1,4 +1,5 @@ -#include +#include +#include #include #include "skeletonpartlistwidget.h" #include "theme.h" @@ -8,18 +9,24 @@ SkeletonPartWidget::SkeletonPartWidget(const SkeletonDocument *document, QUuid p m_partId(partId) { m_visibleButton = new QPushButton(QChar(fa::eye)); - //m_visibleButton->setStyleSheet("QPushButton {border: none; background: none;}"); - m_visibleButton->setFont(Theme::awesome()->font(Theme::toolIconFontSize * 2 / 3)); - m_visibleButton->setFixedSize(Theme::toolIconSize * 2 / 3, Theme::toolIconSize * 2 / 3); + m_visibleButton->setStyleSheet("QPushButton {border: none; background: none; color: #cccccc;}"); + m_visibleButton->setFont(Theme::awesome()->font(Theme::miniIconFontSize)); + m_visibleButton->setFixedSize(Theme::miniIconSize, Theme::miniIconSize); m_previewLabel = new QLabel; - //m_nameLabel = new QLabel; + QHBoxLayout *miniToolLayout = new QHBoxLayout; + miniToolLayout->setSpacing(0); + miniToolLayout->setContentsMargins(0, 0, 0, 0); + miniToolLayout->addSpacing(3); + miniToolLayout->addWidget(m_visibleButton); + miniToolLayout->addStretch(); - QGridLayout *mainLayout = new QGridLayout; - mainLayout->addWidget(m_visibleButton, 0, 0); - mainLayout->addWidget(m_previewLabel, 0, 1); - //mainLayout->addWidget(m_nameLabel, 0, 2); + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->setSpacing(0); + mainLayout->setContentsMargins(0, 0, 0, 0); + mainLayout->addLayout(miniToolLayout); + mainLayout->addWidget(m_previewLabel); setLayout(mainLayout); } @@ -45,6 +52,8 @@ SkeletonPartListWidget::SkeletonPartListWidget(const SkeletonDocument *document) { setSelectionMode(QAbstractItemView::NoSelection); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setSpacing(1); + setContentsMargins(0, 0, 0, 0); } void SkeletonPartListWidget::partChanged(QUuid partId) diff --git a/src/theme.cpp b/src/theme.cpp index 99eee21e..c46f6b7e 100644 --- a/src/theme.cpp +++ b/src/theme.cpp @@ -27,7 +27,9 @@ int Theme::skeletonNodeBorderSize = 0; int Theme::skeletonEdgeWidth = 0; int Theme::toolIconFontSize = 16; int Theme::toolIconSize = 24; -int Theme::previewImageSize = 64; +int Theme::previewImageSize = 48; +int Theme::miniIconFontSize = 8; +int Theme::miniIconSize = 12; QtAwesome *Theme::awesome() { diff --git a/src/theme.h b/src/theme.h index 594ee0c0..35dc9092 100644 --- a/src/theme.h +++ b/src/theme.h @@ -27,6 +27,8 @@ public: static int toolIconFontSize; static int toolIconSize; static int previewImageSize; + static int miniIconFontSize; + static int miniIconSize; }; #endif