From 283e76b1b6efc5a8aa5fb32d8ec26df057e7328f Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Sun, 11 Mar 2018 11:18:24 +0800 Subject: [PATCH] Add base UI layout --- dust3d.pro | 3 ++ src/main.cpp | 30 ++++++++++++----- src/mainwindow.cpp | 75 ++++++++++++++++++++++++++++++++++++++++-- src/modelingwidget.cpp | 16 ++++----- 4 files changed, 105 insertions(+), 19 deletions(-) diff --git a/dust3d.pro b/dust3d.pro index 86223dbd..e33ce2d3 100644 --- a/dust3d.pro +++ b/dust3d.pro @@ -9,6 +9,9 @@ HEADERS += src/mainwindow.h SOURCES += src/modelingwidget.cpp HEADERS += src/modelingwidget.h +SOURCES += src/skeletoneditwidget.cpp +HEADERS += src/skeletoneditwidget.h + SOURCES += src/mesh.cpp HEADERS += src/mesh.h diff --git a/src/main.cpp b/src/main.cpp index 590996e7..a4a6d16b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,19 +1,33 @@ #include #include +#include #include "mainwindow.h" #include "meshlite.h" int main(int argc, char ** argv) { - /* - void *lite = meshlite_create_context(); - int first = meshlite_import(lite, "/Users/jeremy/cube.obj"); - int second = meshlite_import(lite, "/Users/jeremy/ball.obj"); - meshlite_scale(lite, first, 0.65); - int result = meshlite_intersect(lite, first, second); - meshlite_export(lite, result, "/Users/jeremy/testlib.obj"); - */ QApplication app(argc, argv); + + // QuantumCD/Qt 5 Dark Fusion Palette + // https://gist.github.com/QuantumCD/6245215 + qApp->setStyle(QStyleFactory::create("Fusion")); + QPalette darkPalette; + darkPalette.setColor(QPalette::Window, QColor(53,53,53)); + darkPalette.setColor(QPalette::WindowText, Qt::white); + darkPalette.setColor(QPalette::Base, QColor(25,25,25)); + darkPalette.setColor(QPalette::AlternateBase, QColor(53,53,53)); + darkPalette.setColor(QPalette::ToolTipBase, Qt::white); + darkPalette.setColor(QPalette::ToolTipText, Qt::white); + darkPalette.setColor(QPalette::Text, Qt::white); + darkPalette.setColor(QPalette::Button, QColor(53,53,53)); + darkPalette.setColor(QPalette::ButtonText, Qt::white); + darkPalette.setColor(QPalette::BrightText, Qt::red); + darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); + darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); + darkPalette.setColor(QPalette::HighlightedText, Qt::black); + qApp->setPalette(darkPalette); + qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"); + QCoreApplication::setApplicationName("Dust 3D"); MainWindow mainWindow; mainWindow.resize(mainWindow.sizeHint()); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7228d970..cfd4dc6c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,9 +1,78 @@ #include "mainwindow.h" - +#include "skeletoneditwidget.h" +#include +#include +#include +#include +#include MainWindow::MainWindow() { - modelingWidget = new ModelingWidget(this); - setCentralWidget(modelingWidget); + QPushButton *skeletonButton = new QPushButton("Skeleton"); + QPushButton *motionButton = new QPushButton("Motion"); + QPushButton *modelButton = new QPushButton("Model"); + + QButtonGroup *pageButtonGroup = new QButtonGroup; + pageButtonGroup->addButton(skeletonButton); + pageButtonGroup->addButton(motionButton); + pageButtonGroup->addButton(modelButton); + + skeletonButton->setCheckable(true); + motionButton->setCheckable(true); + modelButton->setCheckable(true); + + pageButtonGroup->setExclusive(true); + + skeletonButton->setChecked(true); + + QHBoxLayout *topLayout = new QHBoxLayout; + topLayout->addStretch(); + topLayout->addWidget(skeletonButton); + topLayout->addWidget(motionButton); + topLayout->addWidget(modelButton); + topLayout->addStretch(); + + skeletonButton->adjustSize(); + motionButton->adjustSize(); + modelButton->adjustSize(); + + SkeletonEditWidget *skeletonEditWidget = new SkeletonEditWidget; + ModelingWidget *modelViewWidget = new ModelingWidget; + modelViewWidget->setFixedSize(128, 128); + + QPushButton *changeTurnaroundButton = new QPushButton("Change turnaround.."); + + QVBoxLayout *rightLayout = new QVBoxLayout; + rightLayout->addWidget(modelViewWidget); + rightLayout->addSpacing(10); + rightLayout->addWidget(changeTurnaroundButton); + rightLayout->addStretch(); + + QToolBar *toolbar = new QToolBar; + toolbar->setOrientation(Qt::Vertical); + QAction *addAction = new QAction(tr("Add"), this); + QAction *selectAction = new QAction(tr("Select"), this); + toolbar->addAction(addAction); + toolbar->addAction(selectAction); + + QVBoxLayout *leftLayout = new QVBoxLayout; + leftLayout->addWidget(toolbar); + leftLayout->addStretch(); + + QHBoxLayout *middleLayout = new QHBoxLayout; + middleLayout->addLayout(leftLayout); + middleLayout->addWidget(skeletonEditWidget); + middleLayout->addLayout(rightLayout); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(topLayout); + mainLayout->addSpacing(20); + mainLayout->addLayout(middleLayout); + + QWidget *centralWidget = new QWidget; + centralWidget->setLayout(mainLayout); + + setCentralWidget(centralWidget); + setWindowTitle(tr("Dust 3D")); } diff --git a/src/modelingwidget.cpp b/src/modelingwidget.cpp index 8dfe2513..ee8ce472 100644 --- a/src/modelingwidget.cpp +++ b/src/modelingwidget.cpp @@ -27,12 +27,12 @@ ModelingWidget::ModelingWidget(QWidget *parent) } void *lite = meshlite_create_context(); - int first = meshlite_import(lite, "/Users/jeremy/cube.obj"); - int second = meshlite_import(lite, "/Users/jeremy/ball.obj"); + int first = meshlite_import(lite, "../assets/cube.obj"); + int second = meshlite_import(lite, "../assets/ball.obj"); meshlite_scale(lite, first, 0.65); - int intersect = meshlite_intersect(lite, first, second); - int triangulate = meshlite_triangulate(lite, intersect); - meshlite_export(lite, triangulate, "/Users/jeremy/testlib.obj"); + int merged = meshlite_union(lite, first, second); + int triangulate = meshlite_triangulate(lite, merged); + //meshlite_export(lite, triangulate, "/Users/jeremy/testlib.obj"); Mesh *mesh = new Mesh(lite, triangulate); updateMesh(mesh); } @@ -126,7 +126,7 @@ static const char *fragmentShaderSourceCore = "void main() {\n" " highp vec3 L = normalize(lightPos - vert);\n" " highp float NL = max(dot(normalize(vertNormal), L), 0.0);\n" - " highp vec3 color = vec3(0.39, 1.0, 0.0);\n" + " highp vec3 color = vec3(1.0, 1.0, 1.0);\n" " highp vec3 col = clamp(color * 0.2 + color * 0.8 * NL, 0.0, 1.0);\n" " fragColor = vec4(col, 1.0);\n" "}\n"; @@ -152,7 +152,7 @@ static const char *fragmentShaderSource = "void main() {\n" " highp vec3 L = normalize(lightPos - vert);\n" " highp float NL = max(dot(normalize(vertNormal), L), 0.0);\n" - " highp vec3 color = vec3(0.39, 1.0, 0.0);\n" + " highp vec3 color = vec3(1.0, 1.0, 1.0);\n" " highp vec3 col = clamp(color * 0.2 + color * 0.8 * NL, 0.0, 1.0);\n" " gl_FragColor = vec4(col, 1.0);\n" "}\n"; @@ -169,7 +169,7 @@ void ModelingWidget::initializeGL() connect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &ModelingWidget::cleanup); initializeOpenGLFunctions(); - glClearColor(0, 0, 0, m_transparent ? 0 : 1); + glClearColor(0.2078, 0.2078, 0.2078, m_transparent ? 0 : 1); m_program = new QOpenGLShaderProgram; m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_core ? vertexShaderSourceCore : vertexShaderSource);