Fix turnaround resize

master
Jeremy Hu 2018-03-14 10:55:59 +08:00
parent 20f4b669bb
commit d3dfffcc59
20 changed files with 140 additions and 23 deletions

View File

@ -1,3 +1,13 @@
convert thirdparty/capicon/png/white/059.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/add.png convert thirdparty/capicon/png/white/059.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/add.png
convert thirdparty/capicon/png/white/262.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/select.png convert thirdparty/capicon/png/white/262.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/select.png
convert thirdparty/capicon/png/white/078.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/picture.png convert thirdparty/capicon/png/white/078.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/picture.png
convert thirdparty/capicon/png/white/226.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/save.png
convert thirdparty/capicon/png/white/341.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/info.png
convert thirdparty/capicon/png/white/279.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/up.png
convert thirdparty/capicon/png/white/278.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/down.png
convert thirdparty/capicon/png/white/274.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/clip.png
convert thirdparty/capicon/png/white/254.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/rangeselect.png
convert thirdparty/capicon/png/white/057.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/delete.png
convert thirdparty/capicon/png/white/047.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/new.png
convert thirdparty/capicon/png/white/039.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/palette.png
convert thirdparty/capicon/png/white/030.png -fuzz 90% -fill 'rgb(252,102,33)' -opaque 'rgb(255,255,255)' resources/trashbin.png

View File

@ -1,7 +1,17 @@
<!DOCTYPE RCC><RCC version="1.0"> <!DOCTYPE RCC><RCC version="1.0">
<qresource> <qresource>
<file>resources/add.png</file> <file>resources/add.png</file>
<file>resources/select.png</file> <file>resources/select.png</file>
<file>resources/picture.png</file> <file>resources/picture.png</file>
<file>resources/save.png</file>
<file>resources/info.png</file>
<file>resources/up.png</file>
<file>resources/down.png</file>
<file>resources/clip.png</file>
<file>resources/rangeselect.png</file>
<file>resources/delete.png</file>
<file>resources/new.png</file>
<file>resources/palette.png</file>
<file>resources/trashbin.png</file>
</qresource> </qresource>
</RCC> </RCC>

BIN
resources/clip.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
resources/delete.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
resources/down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
resources/info.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
resources/new.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
resources/palette.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
resources/rangeselect.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
resources/save.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
resources/trashbin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
resources/up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -26,7 +26,7 @@ int main(int argc, char ** argv)
darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218));
darkPalette.setColor(QPalette::HighlightedText, Qt::black); darkPalette.setColor(QPalette::HighlightedText, Qt::black);
qApp->setPalette(darkPalette); qApp->setPalette(darkPalette);
qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"); qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #fc6621; border: 1px solid white; }");
QCoreApplication::setApplicationName("Dust 3D"); QCoreApplication::setApplicationName("Dust 3D");

View File

@ -5,6 +5,8 @@
#include <QToolBar> #include <QToolBar>
#include <QThread> #include <QThread>
#include <QFileDialog> #include <QFileDialog>
#include <QApplication>
#include <QDesktopWidget>
#include <assert.h> #include <assert.h>
#include "mainwindow.h" #include "mainwindow.h"
#include "skeletoneditwidget.h" #include "skeletoneditwidget.h"
@ -53,28 +55,42 @@ MainWindow::MainWindow() :
m_modelingWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); m_modelingWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
m_modelingWidget->setWindowFlags(Qt::Tool | Qt::Window); m_modelingWidget->setWindowFlags(Qt::Tool | Qt::Window);
m_modelingWidget->setWindowTitle("3D Model"); m_modelingWidget->setWindowTitle("3D Model");
QPushButton *changeTurnaroundButton = new QPushButton("");
changeTurnaroundButton->setIcon(QIcon(":/resources/picture.png"));
QVBoxLayout *rightLayout = new QVBoxLayout; QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout->addSpacing(10); rightLayout->addSpacing(10);
rightLayout->addWidget(changeTurnaroundButton);
//QPushButton *changeTurnaroundButton = new QPushButton("");
//changeTurnaroundButton->setIcon(QIcon(":/resources/picture.png"));
//changeTurnaroundButton->setToolTip(tr("Change turnaround reference image"));
//rightLayout->addWidget(changeTurnaroundButton);
rightLayout->addStretch(); rightLayout->addStretch();
QToolBar *toolbar = new QToolBar; QToolBar *toolbar = new QToolBar;
toolbar->setIconSize(QSize(16, 16)); toolbar->setIconSize(QSize(16, 16));
toolbar->setOrientation(Qt::Vertical); toolbar->setOrientation(Qt::Vertical);
QAction *addAction = new QAction(tr("Add"), this); QAction *addAction = new QAction(tr("Add"), this);
addAction->setIcon(QIcon(":/resources/add.png")); addAction->setIcon(QIcon(":/resources/add.png"));
toolbar->addAction(addAction);
QAction *selectAction = new QAction(tr("Select"), this); QAction *selectAction = new QAction(tr("Select"), this);
selectAction->setIcon(QIcon(":/resources/select.png")); selectAction->setIcon(QIcon(":/resources/select.png"));
toolbar->addAction(addAction);
toolbar->addAction(selectAction); 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; QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addWidget(toolbar); leftLayout->addWidget(toolbar);
leftLayout->addStretch(); leftLayout->addStretch();
//leftLayout->addWidget(m_clipTableWidget);
leftLayout->addSpacing(10);
QHBoxLayout *middleLayout = new QHBoxLayout; QHBoxLayout *middleLayout = new QHBoxLayout;
middleLayout->addLayout(leftLayout); middleLayout->addLayout(leftLayout);
@ -106,22 +122,28 @@ MainWindow::MainWindow() :
connectResult = connect(m_skeletonEditWidget, SIGNAL(sizeChanged()), this, SLOT(turnaroundChanged())); connectResult = connect(m_skeletonEditWidget, SIGNAL(sizeChanged()), this, SLOT(turnaroundChanged()));
assert(connectResult); assert(connectResult);
connectResult = connect(changeTurnaroundButton, SIGNAL(released()), this, SLOT(changeTurnaround())); connectResult = connect(m_skeletonEditWidget->graphicsView(), SIGNAL(changeTurnaroundTriggered()), this, SLOT(changeTurnaround()));
assert(connectResult); assert(connectResult);
//connectResult = connect(clipButton, SIGNAL(clicked()), this, SLOT(saveClip()));
//assert(connectResult);
}
void MainWindow::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 MainWindow::meshReady() void MainWindow::meshReady()
{ {
Mesh *resultMesh = m_skeletonToMesh->takeResultMesh(); Mesh *resultMesh = m_skeletonToMesh->takeResultMesh();
if (resultMesh) { showModelingWidgetAtCorner();
if (!m_modelingWidget->isVisible()) {
QRect referenceRect = m_skeletonEditWidget->geometry();
QPoint pos = QPoint(referenceRect.right() - m_modelingWidget->width(),
referenceRect.bottom() - m_modelingWidget->height());
m_modelingWidget->move(pos.x(), pos.y());
m_modelingWidget->show();
}
}
m_modelingWidget->updateMesh(resultMesh); m_modelingWidget->updateMesh(resultMesh);
delete m_skeletonToMesh; delete m_skeletonToMesh;
m_skeletonToMesh = NULL; m_skeletonToMesh = NULL;
@ -196,3 +218,14 @@ void MainWindow::changeTurnaround()
m_turnaroundFilename = fileName; m_turnaroundFilename = fileName;
turnaroundChanged(); 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");
}

View File

@ -2,6 +2,8 @@
#define MAIN_WINDOW_H #define MAIN_WINDOW_H
#include <QMainWindow> #include <QMainWindow>
#include <QString> #include <QString>
#include <QVBoxLayout>
#include <QPushButton>
#include "modelingwidget.h" #include "modelingwidget.h"
#include "skeletoneditwidget.h" #include "skeletoneditwidget.h"
#include "skeletontomesh.h" #include "skeletontomesh.h"
@ -18,6 +20,8 @@ public slots:
void turnaroundChanged(); void turnaroundChanged();
void turnaroundImageReady(); void turnaroundImageReady();
void changeTurnaround(); void changeTurnaround();
void saveClip();
void showModelingWidgetAtCorner();
private: private:
ModelingWidget *m_modelingWidget; ModelingWidget *m_modelingWidget;
SkeletonEditWidget *m_skeletonEditWidget; SkeletonEditWidget *m_skeletonEditWidget;

View File

@ -35,6 +35,8 @@ SkeletonEditGraphicsView::SkeletonEditGraphicsView(QWidget *parent) :
void SkeletonEditGraphicsView::toggleAddNodeMode() void SkeletonEditGraphicsView::toggleAddNodeMode()
{ {
if (!m_backgroundLoaded)
return;
m_inAddNodeMode = !m_inAddNodeMode; m_inAddNodeMode = !m_inAddNodeMode;
applyAddNodeMode(); applyAddNodeMode();
} }
@ -48,12 +50,16 @@ void SkeletonEditGraphicsView::applyAddNodeMode()
void SkeletonEditGraphicsView::turnOffAddNodeMode() void SkeletonEditGraphicsView::turnOffAddNodeMode()
{ {
if (!m_backgroundLoaded)
return;
m_inAddNodeMode = false; m_inAddNodeMode = false;
applyAddNodeMode(); applyAddNodeMode();
} }
void SkeletonEditGraphicsView::turnOnAddNodeMode() void SkeletonEditGraphicsView::turnOnAddNodeMode()
{ {
if (!m_backgroundLoaded)
return;
m_inAddNodeMode = true; m_inAddNodeMode = true;
applyAddNodeMode(); applyAddNodeMode();
} }
@ -89,6 +95,12 @@ void SkeletonEditGraphicsView::mousePressEvent(QMouseEvent *event)
m_lastMousePos = mapToScene(event->pos()); m_lastMousePos = mapToScene(event->pos());
} }
void SkeletonEditGraphicsView::mouseDoubleClickEvent(QMouseEvent *event)
{
QWidget::mouseDoubleClickEvent(event);
emit changeTurnaroundTriggered();
}
float SkeletonEditGraphicsView::findXForSlave(float x) float SkeletonEditGraphicsView::findXForSlave(float x)
{ {
return x - m_backgroundItem->boundingRect().width() / 4; return x - m_backgroundItem->boundingRect().width() / 4;
@ -286,11 +298,38 @@ void SkeletonEditGraphicsView::setNextStartNodeItem(SkeletonEditNodeItem *item)
void SkeletonEditGraphicsView::updateBackgroundImage(const QImage &image) void SkeletonEditGraphicsView::updateBackgroundImage(const QImage &image)
{ {
QSizeF oldSceneSize = scene()->sceneRect().size();
QPixmap pixmap = QPixmap::fromImage(image); QPixmap pixmap = QPixmap::fromImage(image);
m_backgroundItem->setPixmap(pixmap); m_backgroundItem->setPixmap(pixmap);
scene()->setSceneRect(pixmap.rect()); scene()->setSceneRect(pixmap.rect());
adjustItems(oldSceneSize, scene()->sceneRect().size());
if (!m_backgroundLoaded) { if (!m_backgroundLoaded) {
m_backgroundLoaded = true; m_backgroundLoaded = true;
applyAddNodeMode(); applyAddNodeMode();
} }
} }
void SkeletonEditGraphicsView::adjustItems(QSizeF oldSceneSize, QSizeF newSceneSize)
{
if (oldSceneSize == newSceneSize)
return;
float radiusMul = (float)newSceneSize.height() / oldSceneSize.height();
float xMul = (float)newSceneSize.width() / oldSceneSize.width();
float yMul = radiusMul;
QList<QGraphicsItem *>::iterator it;
QList<QGraphicsItem *> list = scene()->items();
for (it = list.begin(); it != list.end(); ++it) {
if ((*it)->data(0).toString() == "node") {
SkeletonEditNodeItem *nodeItem = static_cast<SkeletonEditNodeItem *>(*it);
nodeItem->setRadius(nodeItem->radius() * radiusMul);
QPointF oldOrigin = nodeItem->origin();
nodeItem->setOrigin(QPointF(oldOrigin.x() * xMul, oldOrigin.y() * yMul));
}
}
for (it = list.begin(); it != list.end(); ++it) {
if ((*it)->data(0).toString() == "edge") {
SkeletonEditEdgeItem *edgeItem = static_cast<SkeletonEditEdgeItem *>(*it);
edgeItem->updatePosition();
}
}
}

View File

@ -10,6 +10,7 @@ class SkeletonEditGraphicsView : public QGraphicsView
Q_OBJECT Q_OBJECT
signals: signals:
void nodesChanged(); void nodesChanged();
void changeTurnaroundTriggered();
public slots: public slots:
void turnOffAddNodeMode(); void turnOffAddNodeMode();
void turnOnAddNodeMode(); void turnOnAddNodeMode();
@ -21,6 +22,7 @@ protected:
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);
void mouseReleaseEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
void mouseDoubleClickEvent(QMouseEvent *event);
private: private:
QGraphicsPixmapItem *m_backgroundItem; QGraphicsPixmapItem *m_backgroundItem;
QGraphicsEllipseItem *m_pendingNodeItem; QGraphicsEllipseItem *m_pendingNodeItem;
@ -33,6 +35,7 @@ private:
QPointF m_lastMousePos; QPointF m_lastMousePos;
bool m_isMovingNodeItem; bool m_isMovingNodeItem;
bool m_backgroundLoaded; bool m_backgroundLoaded;
private:
void toggleAddNodeMode(); void toggleAddNodeMode();
void applyAddNodeMode(); void applyAddNodeMode();
SkeletonEditNodeItem *findNodeItemByPos(QPointF pos); SkeletonEditNodeItem *findNodeItemByPos(QPointF pos);
@ -41,6 +44,7 @@ private:
bool canNodeItemMoveTo(SkeletonEditNodeItem *item, QPointF moveTo); bool canNodeItemMoveTo(SkeletonEditNodeItem *item, QPointF moveTo);
void AddItemRadius(QGraphicsEllipseItem *item, float delta); void AddItemRadius(QGraphicsEllipseItem *item, float delta);
bool canAddItemRadius(QGraphicsEllipseItem *item, float delta); bool canAddItemRadius(QGraphicsEllipseItem *item, float delta);
void adjustItems(QSizeF oldSceneSize, QSizeF newSceneSize);
}; };
#endif #endif

View File

@ -61,6 +61,21 @@ float SkeletonEditNodeItem::radius()
return rect().width() / 2; return rect().width() / 2;
} }
void SkeletonEditNodeItem::setRadius(float radius)
{
QPointF oldOrigin = origin();
setRect(oldOrigin.x() - radius, oldOrigin.y() - radius,
radius * 2, radius * 2);
}
void SkeletonEditNodeItem::setOrigin(QPointF point)
{
QPointF moveBy = point - origin();
QRectF newRect = rect();
newRect.adjust(moveBy.x(), moveBy.y(), moveBy.x(), moveBy.y());
setRect(newRect);
}
void SkeletonEditNodeItem::setHighlighted(bool highlighted) void SkeletonEditNodeItem::setHighlighted(bool highlighted)
{ {
m_highlighted = highlighted; m_highlighted = highlighted;

View File

@ -19,6 +19,8 @@ public:
SkeletonEditNodeItem *master(); SkeletonEditNodeItem *master();
SkeletonEditNodeItem *slave(); SkeletonEditNodeItem *slave();
SkeletonEditNodeItem *pair(); SkeletonEditNodeItem *pair();
void setRadius(float radius);
void setOrigin(QPointF point);
private: private:
bool m_highlighted; bool m_highlighted;
bool m_isNextStartNode; bool m_isNextStartNode;

View File

@ -7,10 +7,10 @@
QColor Theme::skeletonMasterNodeBorderColor = QColor(0xfc, 0x66, 0x21, 128); QColor Theme::skeletonMasterNodeBorderColor = QColor(0xfc, 0x66, 0x21, 128);
QColor Theme::skeletonMasterNodeBorderHighlightColor = QColor(0xfc, 0x66, 0x21, 200); QColor Theme::skeletonMasterNodeBorderHighlightColor = QColor(0xfc, 0x66, 0x21, 200);
QColor Theme::skeletonMasterNodeFillColor = QColor(0xfc, 0x66, 0x21, 50); QColor Theme::skeletonMasterNodeFillColor = QColor(0xfc, 0x66, 0x21, 50);
int Theme::skeletonMasterNodeBorderSize = 15; int Theme::skeletonMasterNodeBorderSize = 2;
QColor Theme::skeletonSlaveNodeBorderColor = QColor(0xcc, 0xcc, 0xcc, 64); QColor Theme::skeletonSlaveNodeBorderColor = QColor(0xcc, 0xcc, 0xcc, 64);
QColor Theme::skeletonSlaveNodeBorderHighlightColor = QColor(0xfc, 0x66, 0x21, 100); QColor Theme::skeletonSlaveNodeBorderHighlightColor = QColor(0xfc, 0x66, 0x21, 100);
QColor Theme::skeletonSlaveNodeFillColor = QColor(0xcc, 0xcc, 0xcc, 25); QColor Theme::skeletonSlaveNodeFillColor = QColor(0xcc, 0xcc, 0xcc, 25);
int Theme::skeletonSlaveNodeBorderSize = 15; int Theme::skeletonSlaveNodeBorderSize = 2;