From 5dbff8b9e3e2c98005245324ba8fa178f6fee6ea Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Wed, 14 Mar 2018 14:43:16 +0800 Subject: [PATCH] Add styled tab header --- dust3d.pro | 3 + src/mainwindow.cpp | 229 +++++++---------------------------------- src/mainwindow.h | 21 +--- src/skeletonwidget.cpp | 194 ++++++++++++++++++++++++++++++++++ src/skeletonwidget.h | 35 +++++++ src/theme.cpp | 7 +- src/theme.h | 3 + 7 files changed, 280 insertions(+), 212 deletions(-) create mode 100644 src/skeletonwidget.cpp create mode 100644 src/skeletonwidget.h diff --git a/dust3d.pro b/dust3d.pro index 9b073500..5a853cd4 100644 --- a/dust3d.pro +++ b/dust3d.pro @@ -28,6 +28,9 @@ HEADERS += src/skeletontomesh.h SOURCES += src/turnaroundloader.cpp HEADERS += src/turnaroundloader.h +SOURCES += src/skeletonwidget.cpp +HEADERS += src/skeletonwidget.h + SOURCES += src/theme.cpp HEADERS += src/theme.h diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3c907d19..993171a8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -9,98 +9,51 @@ #include #include #include "mainwindow.h" -#include "skeletoneditwidget.h" -#include "meshlite.h" -#include "skeletontomesh.h" -#include "turnaroundloader.h" +#include "skeletonwidget.h" +#include "theme.h" -MainWindow::MainWindow() : - m_skeletonToMesh(NULL), - m_skeletonDirty(false), - m_turnaroundLoader(NULL), - m_turnaroundDirty(false) +MainWindow::MainWindow() { - //QPushButton *skeletonButton = new QPushButton("Skeleton"); - //QPushButton *motionButton = new QPushButton("Motion"); - //QPushButton *modelButton = new QPushButton("Model"); + m_partsPageButton = new QPushButton("Parts"); + m_combinePageButton = new QPushButton("Combine"); - //QButtonGroup *pageButtonGroup = new QButtonGroup; - //pageButtonGroup->addButton(skeletonButton); - //pageButtonGroup->addButton(motionButton); - //pageButtonGroup->addButton(modelButton); + QWidget *hrWidget = new QWidget; + hrWidget->setFixedHeight(2); + hrWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + hrWidget->setStyleSheet(QString("background-color: #fc6621;")); + hrWidget->setContentsMargins(0, 0, 0, 0); - //skeletonButton->setCheckable(true); - //motionButton->setCheckable(true); - //modelButton->setCheckable(true); + QButtonGroup *pageButtonGroup = new QButtonGroup; + pageButtonGroup->addButton(m_partsPageButton); + pageButtonGroup->addButton(m_combinePageButton); - //pageButtonGroup->setExclusive(true); + m_partsPageButton->setCheckable(true); + m_combinePageButton->setCheckable(true); - //skeletonButton->setChecked(true); + pageButtonGroup->setExclusive(true); - QHBoxLayout *topLayout = new QHBoxLayout; - topLayout->addStretch(); - //topLayout->addWidget(skeletonButton); - //topLayout->addWidget(motionButton); - //topLayout->addWidget(modelButton); - topLayout->addStretch(); + m_partsPageButton->setChecked(true); + updatePageButtons(); - //skeletonButton->adjustSize(); - //motionButton->adjustSize(); - //modelButton->adjustSize(); + QHBoxLayout *topButtonsLayout = new QHBoxLayout; + topButtonsLayout->setContentsMargins(0, 0, 0, 0); + topButtonsLayout->setSpacing(0); + topButtonsLayout->addStretch(); + topButtonsLayout->addWidget(m_partsPageButton); + topButtonsLayout->addWidget(m_combinePageButton); + topButtonsLayout->addStretch(); - m_skeletonEditWidget = new SkeletonEditWidget; + QVBoxLayout *topLayout = new QVBoxLayout; + topLayout->setContentsMargins(0, 0, 0, 0); + topLayout->setSpacing(0); + topLayout->addLayout(topButtonsLayout); + topLayout->addWidget(hrWidget); - m_modelingWidget = new ModelingWidget(this); - m_modelingWidget->setMinimumSize(128, 128); - m_modelingWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - m_modelingWidget->setWindowFlags(Qt::Tool | Qt::Window); - m_modelingWidget->setWindowTitle("3D Model"); - - QVBoxLayout *rightLayout = new QVBoxLayout; - rightLayout->addSpacing(10); - - //QPushButton *changeTurnaroundButton = new QPushButton(""); - //changeTurnaroundButton->setIcon(QIcon(":/resources/picture.png")); - //changeTurnaroundButton->setToolTip(tr("Change turnaround reference image")); - //rightLayout->addWidget(changeTurnaroundButton); - - rightLayout->addStretch(); - - QToolBar *toolbar = new QToolBar; - toolbar->setIconSize(QSize(16, 16)); - toolbar->setOrientation(Qt::Vertical); - - QAction *addAction = new QAction(tr("Add"), this); - addAction->setIcon(QIcon(":/resources/add.png")); - toolbar->addAction(addAction); - - QAction *selectAction = new QAction(tr("Select"), this); - selectAction->setIcon(QIcon(":/resources/select.png")); - toolbar->addAction(selectAction); - - QAction *rangeSelectAction = new QAction(tr("Range Select"), this); - rangeSelectAction->setIcon(QIcon(":/resources/rangeselect.png")); - toolbar->addAction(rangeSelectAction); - - //m_clipTableWidget = new QTableWidget; - //m_clipTableWidget->setFixedWidth(32); - //m_clipTableWidget->verticalHeader()->setVisible(false); - - QVBoxLayout *leftLayout = new QVBoxLayout; - leftLayout->addWidget(toolbar); - leftLayout->addStretch(); - //leftLayout->addWidget(m_clipTableWidget); - leftLayout->addSpacing(10); - - QHBoxLayout *middleLayout = new QHBoxLayout; - middleLayout->addLayout(leftLayout); - middleLayout->addWidget(m_skeletonEditWidget); - middleLayout->addLayout(rightLayout); + SkeletonWidget *skeletonWidget = new SkeletonWidget(this); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addLayout(topLayout); - mainLayout->addSpacing(20); - mainLayout->addLayout(middleLayout); + mainLayout->addWidget(skeletonWidget); QWidget *centralWidget = new QWidget; centralWidget->setLayout(mainLayout); @@ -108,124 +61,18 @@ MainWindow::MainWindow() : setCentralWidget(centralWidget); setWindowTitle(tr("Dust 3D")); - bool connectResult; + bool connectResult = false; - connectResult = connect(addAction, SIGNAL(triggered(bool)), m_skeletonEditWidget->graphicsView(), SLOT(turnOnAddNodeMode())); + connectResult = connect(m_partsPageButton, SIGNAL(clicked()), this, SLOT(updatePageButtons())); assert(connectResult); - connectResult = connectResult = connect(selectAction, SIGNAL(triggered(bool)), m_skeletonEditWidget->graphicsView(), SLOT(turnOffAddNodeMode())); + connectResult = connect(m_combinePageButton, SIGNAL(clicked()), this, SLOT(updatePageButtons())); assert(connectResult); - - connectResult = connect(m_skeletonEditWidget->graphicsView(), SIGNAL(nodesChanged()), this, SLOT(skeletonChanged())); - assert(connectResult); - - connectResult = connect(m_skeletonEditWidget, SIGNAL(sizeChanged()), this, SLOT(turnaroundChanged())); - assert(connectResult); - - connectResult = connect(m_skeletonEditWidget->graphicsView(), SIGNAL(changeTurnaroundTriggered()), this, SLOT(changeTurnaround())); - assert(connectResult); - - //connectResult = connect(clipButton, SIGNAL(clicked()), this, SLOT(saveClip())); - //assert(connectResult); } -void MainWindow::showModelingWidgetAtCorner() +void MainWindow::updatePageButtons() { - if (!m_modelingWidget->isVisible()) { - QPoint pos = QPoint(QApplication::desktop()->width(), - QApplication::desktop()->height()); - m_modelingWidget->move(pos.x() - m_modelingWidget->width(), - pos.y() - m_modelingWidget->height()); - m_modelingWidget->show(); - } + m_partsPageButton->setStyleSheet(m_partsPageButton->isChecked() ? Theme::tabButtonSelectedStylesheet : Theme::tabButtonStylesheet); + m_combinePageButton->setStyleSheet(m_combinePageButton->isChecked() ? Theme::tabButtonSelectedStylesheet : Theme::tabButtonStylesheet); } -void MainWindow::meshReady() -{ - Mesh *resultMesh = m_skeletonToMesh->takeResultMesh(); - showModelingWidgetAtCorner(); - m_modelingWidget->updateMesh(resultMesh); - delete m_skeletonToMesh; - m_skeletonToMesh = NULL; - if (m_skeletonDirty) { - skeletonChanged(); - } -} - -void MainWindow::skeletonChanged() -{ - if (m_skeletonToMesh) { - m_skeletonDirty = true; - return; - } - - m_skeletonDirty = false; - - QThread *thread = new QThread; - m_skeletonToMesh = new SkeletonToMesh(m_skeletonEditWidget->graphicsView()); - m_skeletonToMesh->moveToThread(thread); - connect(thread, SIGNAL(started()), m_skeletonToMesh, SLOT(process())); - connect(m_skeletonToMesh, SIGNAL(finished()), this, SLOT(meshReady())); - connect(m_skeletonToMesh, SIGNAL(finished()), thread, SLOT(quit())); - connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); - thread->start(); -} - -void MainWindow::turnaroundChanged() -{ - if (m_turnaroundFilename.isEmpty()) - return; - - if (m_turnaroundLoader) { - m_turnaroundDirty = true; - return; - } - - m_turnaroundDirty = false; - - QThread *thread = new QThread; - m_turnaroundLoader = new TurnaroundLoader(m_turnaroundFilename, - m_skeletonEditWidget->rect().size()); - m_turnaroundLoader->moveToThread(thread); - connect(thread, SIGNAL(started()), m_turnaroundLoader, SLOT(process())); - connect(m_turnaroundLoader, SIGNAL(finished()), this, SLOT(turnaroundImageReady())); - connect(m_turnaroundLoader, SIGNAL(finished()), thread, SLOT(quit())); - connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); - thread->start(); -} - -void MainWindow::turnaroundImageReady() -{ - QImage *backgroundImage = m_turnaroundLoader->takeResultImage(); - if (backgroundImage && backgroundImage->width() > 0 && backgroundImage->height() > 0) { - m_skeletonEditWidget->graphicsView()->updateBackgroundImage(*backgroundImage); - } - delete backgroundImage; - delete m_turnaroundLoader; - m_turnaroundLoader = NULL; - if (m_turnaroundDirty) { - turnaroundChanged(); - } -} - -void MainWindow::changeTurnaround() -{ - QString fileName = QFileDialog::getOpenFileName(this, tr("Open Turnaround Reference Image"), - QString(), - tr("Image Files (*.png *.jpg *.bmp)")).trimmed(); - if (fileName.isEmpty()) - return; - m_turnaroundFilename = fileName; - turnaroundChanged(); -} - -void MainWindow::saveClip() -{ - QImage image = m_modelingWidget->grabFramebuffer(); - //QTableWidgetItem *item = new QTableWidgetItem; - //item->setSizeHint(QSize(32, 32)); - //item->setIcon(QPixmap::fromImage(image.scaled(32, 32))); - //m_clipTableWidget->insertRow(m_clipTableWidget->rowCount()); - //m_clipTableWidget->setItem(m_clipTableWidget->rowCount() - 1, 0, item); - //image.save("/Users/jeremy/Repositories/dust3d/gl.png"); -} diff --git a/src/mainwindow.h b/src/mainwindow.h index bba763dd..ef0637d0 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -4,10 +4,6 @@ #include #include #include -#include "modelingwidget.h" -#include "skeletoneditwidget.h" -#include "skeletontomesh.h" -#include "turnaroundloader.h" class MainWindow : public QMainWindow { @@ -15,21 +11,10 @@ class MainWindow : public QMainWindow public: MainWindow(); public slots: - void skeletonChanged(); - void meshReady(); - void turnaroundChanged(); - void turnaroundImageReady(); - void changeTurnaround(); - void saveClip(); - void showModelingWidgetAtCorner(); + void updatePageButtons(); private: - ModelingWidget *m_modelingWidget; - SkeletonEditWidget *m_skeletonEditWidget; - SkeletonToMesh *m_skeletonToMesh; - bool m_skeletonDirty; - TurnaroundLoader *m_turnaroundLoader; - bool m_turnaroundDirty; - QString m_turnaroundFilename; + QPushButton *m_partsPageButton; + QPushButton *m_combinePageButton; }; #endif diff --git a/src/skeletonwidget.cpp b/src/skeletonwidget.cpp new file mode 100644 index 00000000..ea566a98 --- /dev/null +++ b/src/skeletonwidget.cpp @@ -0,0 +1,194 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "skeletonwidget.h" +#include "skeletoneditwidget.h" +#include "meshlite.h" +#include "skeletontomesh.h" +#include "turnaroundloader.h" + +SkeletonWidget::SkeletonWidget(QWidget *parent) : + QWidget(parent), + m_skeletonToMesh(NULL), + m_skeletonDirty(false), + m_turnaroundLoader(NULL), + m_turnaroundDirty(false) +{ + QHBoxLayout *topLayout = new QHBoxLayout; + topLayout->addStretch(); + + m_skeletonEditWidget = new SkeletonEditWidget; + + m_modelingWidget = new ModelingWidget(this); + m_modelingWidget->setMinimumSize(128, 128); + m_modelingWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + m_modelingWidget->setWindowFlags(Qt::Tool | Qt::Window); + m_modelingWidget->setWindowTitle("3D Model"); + + QVBoxLayout *rightLayout = new QVBoxLayout; + rightLayout->addSpacing(10); + rightLayout->addStretch(); + + QToolBar *toolbar = new QToolBar; + toolbar->setIconSize(QSize(16, 16)); + toolbar->setOrientation(Qt::Vertical); + + QAction *addAction = new QAction(tr("Add"), this); + addAction->setIcon(QIcon(":/resources/add.png")); + toolbar->addAction(addAction); + + QAction *selectAction = new QAction(tr("Select"), this); + selectAction->setIcon(QIcon(":/resources/select.png")); + toolbar->addAction(selectAction); + + QAction *rangeSelectAction = new QAction(tr("Range Select"), this); + rangeSelectAction->setIcon(QIcon(":/resources/rangeselect.png")); + toolbar->addAction(rangeSelectAction); + + QVBoxLayout *leftLayout = new QVBoxLayout; + leftLayout->addWidget(toolbar); + leftLayout->addStretch(); + leftLayout->addSpacing(10); + + QHBoxLayout *middleLayout = new QHBoxLayout; + middleLayout->addLayout(leftLayout); + middleLayout->addWidget(m_skeletonEditWidget); + middleLayout->addLayout(rightLayout); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(topLayout); + //mainLayout->addSpacing(10); + mainLayout->addLayout(middleLayout); + + setLayout(mainLayout); + + setWindowTitle(tr("Dust 3D")); + + bool connectResult; + + connectResult = connect(addAction, SIGNAL(triggered(bool)), m_skeletonEditWidget->graphicsView(), SLOT(turnOnAddNodeMode())); + assert(connectResult); + + connectResult = connectResult = connect(selectAction, SIGNAL(triggered(bool)), m_skeletonEditWidget->graphicsView(), SLOT(turnOffAddNodeMode())); + assert(connectResult); + + connectResult = connect(m_skeletonEditWidget->graphicsView(), SIGNAL(nodesChanged()), this, SLOT(skeletonChanged())); + assert(connectResult); + + connectResult = connect(m_skeletonEditWidget, SIGNAL(sizeChanged()), this, SLOT(turnaroundChanged())); + assert(connectResult); + + connectResult = connect(m_skeletonEditWidget->graphicsView(), SIGNAL(changeTurnaroundTriggered()), this, SLOT(changeTurnaround())); + assert(connectResult); + + //connectResult = connect(clipButton, SIGNAL(clicked()), this, SLOT(saveClip())); + //assert(connectResult); +} + +void SkeletonWidget::showModelingWidgetAtCorner() +{ + if (!m_modelingWidget->isVisible()) { + QPoint pos = QPoint(QApplication::desktop()->width(), + QApplication::desktop()->height()); + m_modelingWidget->move(pos.x() - m_modelingWidget->width(), + pos.y() - m_modelingWidget->height()); + m_modelingWidget->show(); + } +} + +void SkeletonWidget::meshReady() +{ + Mesh *resultMesh = m_skeletonToMesh->takeResultMesh(); + showModelingWidgetAtCorner(); + m_modelingWidget->updateMesh(resultMesh); + delete m_skeletonToMesh; + m_skeletonToMesh = NULL; + if (m_skeletonDirty) { + skeletonChanged(); + } +} + +void SkeletonWidget::skeletonChanged() +{ + if (m_skeletonToMesh) { + m_skeletonDirty = true; + return; + } + + m_skeletonDirty = false; + + QThread *thread = new QThread; + m_skeletonToMesh = new SkeletonToMesh(m_skeletonEditWidget->graphicsView()); + m_skeletonToMesh->moveToThread(thread); + connect(thread, SIGNAL(started()), m_skeletonToMesh, SLOT(process())); + connect(m_skeletonToMesh, SIGNAL(finished()), this, SLOT(meshReady())); + connect(m_skeletonToMesh, SIGNAL(finished()), thread, SLOT(quit())); + connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + thread->start(); +} + +void SkeletonWidget::turnaroundChanged() +{ + if (m_turnaroundFilename.isEmpty()) + return; + + if (m_turnaroundLoader) { + m_turnaroundDirty = true; + return; + } + + m_turnaroundDirty = false; + + QThread *thread = new QThread; + m_turnaroundLoader = new TurnaroundLoader(m_turnaroundFilename, + m_skeletonEditWidget->rect().size()); + m_turnaroundLoader->moveToThread(thread); + connect(thread, SIGNAL(started()), m_turnaroundLoader, SLOT(process())); + connect(m_turnaroundLoader, SIGNAL(finished()), this, SLOT(turnaroundImageReady())); + connect(m_turnaroundLoader, SIGNAL(finished()), thread, SLOT(quit())); + connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + thread->start(); +} + +void SkeletonWidget::turnaroundImageReady() +{ + QImage *backgroundImage = m_turnaroundLoader->takeResultImage(); + if (backgroundImage && backgroundImage->width() > 0 && backgroundImage->height() > 0) { + m_skeletonEditWidget->graphicsView()->updateBackgroundImage(*backgroundImage); + } + delete backgroundImage; + delete m_turnaroundLoader; + m_turnaroundLoader = NULL; + if (m_turnaroundDirty) { + turnaroundChanged(); + } +} + +void SkeletonWidget::changeTurnaround() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Open Turnaround Reference Image"), + QString(), + tr("Image Files (*.png *.jpg *.bmp)")).trimmed(); + if (fileName.isEmpty()) + return; + m_turnaroundFilename = fileName; + turnaroundChanged(); +} + +void SkeletonWidget::saveClip() +{ + QImage image = m_modelingWidget->grabFramebuffer(); + //QTableWidgetItem *item = new QTableWidgetItem; + //item->setSizeHint(QSize(32, 32)); + //item->setIcon(QPixmap::fromImage(image.scaled(32, 32))); + //m_clipTableWidget->insertRow(m_clipTableWidget->rowCount()); + //m_clipTableWidget->setItem(m_clipTableWidget->rowCount() - 1, 0, item); + //image.save("/Users/jeremy/Repositories/dust3d/gl.png"); +} diff --git a/src/skeletonwidget.h b/src/skeletonwidget.h new file mode 100644 index 00000000..d2290327 --- /dev/null +++ b/src/skeletonwidget.h @@ -0,0 +1,35 @@ +#ifndef SKELETON_WIDGET_H +#define SKELETON_WIDGET_H +#include +#include +#include +#include +#include "modelingwidget.h" +#include "skeletoneditwidget.h" +#include "skeletontomesh.h" +#include "turnaroundloader.h" + +class SkeletonWidget : public QWidget +{ + Q_OBJECT +public: + SkeletonWidget(QWidget *parent=0); +public slots: + void skeletonChanged(); + void meshReady(); + void turnaroundChanged(); + void turnaroundImageReady(); + void changeTurnaround(); + void saveClip(); + void showModelingWidgetAtCorner(); +private: + ModelingWidget *m_modelingWidget; + SkeletonEditWidget *m_skeletonEditWidget; + SkeletonToMesh *m_skeletonToMesh; + bool m_skeletonDirty; + TurnaroundLoader *m_turnaroundLoader; + bool m_turnaroundDirty; + QString m_turnaroundFilename; +}; + +#endif diff --git a/src/theme.cpp b/src/theme.cpp index 27f6d422..0cc09a38 100644 --- a/src/theme.cpp +++ b/src/theme.cpp @@ -5,12 +5,13 @@ // 0.99, 0.4, 0.13 QColor Theme::skeletonMasterNodeBorderColor = QColor(0xfc, 0x66, 0x21, 128); -QColor Theme::skeletonMasterNodeBorderHighlightColor = QColor(0xfc, 0x66, 0x21, 200); +QColor Theme::skeletonMasterNodeBorderHighlightColor = QColor(0xfc, 0x66, 0x21); QColor Theme::skeletonMasterNodeFillColor = QColor(0xfc, 0x66, 0x21, 50); int Theme::skeletonMasterNodeBorderSize = 2; QColor Theme::skeletonSlaveNodeBorderColor = QColor(0xcc, 0xcc, 0xcc, 64); -QColor Theme::skeletonSlaveNodeBorderHighlightColor = QColor(0xfc, 0x66, 0x21, 100); +QColor Theme::skeletonSlaveNodeBorderHighlightColor = QColor(0xcc, 0xcc, 0xcc); QColor Theme::skeletonSlaveNodeFillColor = QColor(0xcc, 0xcc, 0xcc, 25); int Theme::skeletonSlaveNodeBorderSize = 2; - +QString Theme::tabButtonSelectedStylesheet = "QPushButton { color: #efefef; background-color: #fc6621; border: 0px; padding-top: 2px; padding-bottom: 2px; padding-left: 25px; padding-right: 25px;}"; +QString Theme::tabButtonStylesheet = "QPushButton { color: #efefef; background-color: #353535; border: 0px; padding-top: 2px; padding-bottom: 2px; padding-left: 25px; padding-right: 25px;}"; diff --git a/src/theme.h b/src/theme.h index babf768a..7fd74249 100644 --- a/src/theme.h +++ b/src/theme.h @@ -1,6 +1,7 @@ #ifndef THEME_H #define THEME_H #include +#include class Theme { @@ -13,6 +14,8 @@ public: static QColor skeletonSlaveNodeBorderHighlightColor; static QColor skeletonSlaveNodeFillColor; static int skeletonSlaveNodeBorderSize; + static QString tabButtonSelectedStylesheet; + static QString tabButtonStylesheet; }; #endif