From c4da15eb9e7bf79e23ca5ae8764cd04676e493f5 Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Tue, 20 Aug 2019 23:59:08 +0930 Subject: [PATCH] Add batch color paste #36 Thanks @SatishGodaPearl for the suggestion. Closes #36 --- languages/dust3d_zh_CN.ts | 16 +++++++ src/documentwindow.cpp | 1 + src/motioneditwidget.cpp | 4 +- src/parttreewidget.cpp | 87 +++++++++++++++++++-------------------- src/parttreewidget.h | 1 + 5 files changed, 63 insertions(+), 46 deletions(-) diff --git a/languages/dust3d_zh_CN.ts b/languages/dust3d_zh_CN.ts index f9dca8b7..b8312fd6 100644 --- a/languages/dust3d_zh_CN.ts +++ b/languages/dust3d_zh_CN.ts @@ -512,6 +512,14 @@ Tips: New 新建 + + Poses + 姿势 + + + Motions + 动作 + MotionListWidget @@ -676,6 +684,14 @@ Tips: Seam + + Copy Color + 复制颜色 + + + Paste Color + 粘贴颜色 + PartWidget diff --git a/src/documentwindow.cpp b/src/documentwindow.cpp index 171a39f9..4de6d23c 100644 --- a/src/documentwindow.cpp +++ b/src/documentwindow.cpp @@ -942,6 +942,7 @@ DocumentWindow::DocumentWindow() : connect(partTreeWidget, &PartTreeWidget::unlockAllComponents, m_document, &Document::unlockAllComponents); connect(partTreeWidget, &PartTreeWidget::setPartLockState, m_document, &Document::setPartLockState); connect(partTreeWidget, &PartTreeWidget::setPartVisibleState, m_document, &Document::setPartVisibleState); + connect(partTreeWidget, &PartTreeWidget::setPartColorState, m_document, &Document::setPartColorState); connect(partTreeWidget, &PartTreeWidget::setComponentCombineMode, m_document, &Document::setComponentCombineMode); connect(partTreeWidget, &PartTreeWidget::setPartTarget, m_document, &Document::setPartTarget); connect(partTreeWidget, &PartTreeWidget::setPartBase, m_document, &Document::setPartBase); diff --git a/src/motioneditwidget.cpp b/src/motioneditwidget.cpp index b89f9777..16987aa4 100644 --- a/src/motioneditwidget.cpp +++ b/src/motioneditwidget.cpp @@ -66,8 +66,8 @@ MotionEditWidget::MotionEditWidget(const Document *document, QWidget *parent) : }); std::vector tabs = { - QString("Poses"), - QString("Motions") + tr("Poses"), + tr("Motions") }; TabWidget *tabWidget = new TabWidget(tabs); tabWidget->setCurrentIndex(0); diff --git a/src/parttreewidget.cpp b/src/parttreewidget.cpp index f6f62a7f..05a2c0a5 100644 --- a/src/parttreewidget.cpp +++ b/src/parttreewidget.cpp @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include #include "parttreewidget.h" #include "partwidget.h" #include "skeletongraphicswidget.h" @@ -342,6 +345,20 @@ void PartTreeWidget::showContextMenu(const QPoint &pos) QAction unlockAction(tr("Unlock"), this); unlockAction.setIcon(Theme::awesome()->icon(fa::unlock)); QAction selectAction(tr("Select"), this); + QAction copyColorAction(tr("Copy Color"), this); + QAction pasteColorAction(tr("Paste Color"), this); + + QColor colorInClipboard; + bool hasColorInClipboard = false; + const QClipboard *clipboard = QApplication::clipboard(); + const QMimeData *mimeData = clipboard->mimeData(); + if (mimeData->hasText()) { + auto text = mimeData->text(); + if (text.startsWith("#")) { + colorInClipboard.setNamedColor(text); + hasColorInClipboard = colorInClipboard.isValid(); + } + } if (nullptr != component && nullptr != part) { connect(&selectAction, &QAction::triggered, [=]() { @@ -349,6 +366,19 @@ void PartTreeWidget::showContextMenu(const QPoint &pos) }); contextMenu.addAction(&selectAction); + connect(©ColorAction, &QAction::triggered, [=]() { + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(part->color.name()); + }); + contextMenu.addAction(©ColorAction); + + if (hasColorInClipboard) { + connect(&pasteColorAction, &QAction::triggered, [=]() { + emit setPartColorState(component->linkToPartId, true, colorInClipboard); + }); + contextMenu.addAction(&pasteColorAction); + } + if (part->visible) { connect(&hideAction, &QAction::triggered, [=]() { emit setPartVisibleState(component->linkToPartId, false); @@ -383,6 +413,19 @@ void PartTreeWidget::showContextMenu(const QPoint &pos) } }); contextMenu.addAction(&selectAction); + + if (hasColorInClipboard) { + connect(&pasteColorAction, &QAction::triggered, [=]() { + for (const auto &componentId: componentIds) { + std::vector partIds; + m_document->collectComponentDescendantParts(componentId, partIds); + for (const auto &partId: partIds) { + emit setPartColorState(partId, true, colorInClipboard); + } + } + }); + contextMenu.addAction(&pasteColorAction); + } connect(&showAction, &QAction::triggered, [=]() { for (const auto &componentId: componentIds) @@ -409,52 +452,8 @@ void PartTreeWidget::showContextMenu(const QPoint &pos) contextMenu.addAction(&unlockAction); } - /* - if (component && !component->inverse) { - connect(&invertAction, &QAction::triggered, [=]() { - emit setComponentInverseState(component->id, true); - }); - contextMenu.addAction(&invertAction); - } - - if (component && component->inverse) { - connect(&cancelInverseAction, &QAction::triggered, [=]() { - emit setComponentInverseState(component->id, false); - }); - contextMenu.addAction(&cancelInverseAction); - } - */ - contextMenu.addSeparator(); - /* - QWidgetAction smoothAction(this); - QAction hideOthersAction(tr("Hide Others"), this); - QAction lockOthersAction(tr("Lock Others"), this); - if (nullptr != component) { - QMenu *smoothMenu = contextMenu.addMenu(tr("Smooth")); - - smoothAction.setDefaultWidget(createSmoothMenuWidget(component->id)); - smoothMenu->addAction(&smoothAction); - - contextMenu.addSeparator(); - - hideOthersAction.setIcon(Theme::awesome()->icon(fa::eyeslash)); - connect(&hideOthersAction, &QAction::triggered, [=]() { - emit hideOtherComponents(component->id); - }); - contextMenu.addAction(&hideOthersAction); - - lockOthersAction.setIcon(Theme::awesome()->icon(fa::lock)); - connect(&lockOthersAction, &QAction::triggered, [=]() { - emit lockOtherComponents(component->id); - }); - contextMenu.addAction(&lockOthersAction); - - contextMenu.addSeparator(); - } - */ - QAction collapseAllAction(tr("Collapse All"), this); connect(&collapseAllAction, &QAction::triggered, [=]() { emit collapseAllComponents(); diff --git a/src/parttreewidget.h b/src/parttreewidget.h index 2feebb40..8ace952b 100644 --- a/src/parttreewidget.h +++ b/src/parttreewidget.h @@ -35,6 +35,7 @@ signals: void unlockAllComponents(); void setPartLockState(QUuid partId, bool locked); void setPartVisibleState(QUuid partId, bool visible); + void setPartColorState(QUuid partId, bool hasColor, QColor color); void setComponentCombineMode(QUuid componentId, CombineMode combineMode); void hideDescendantComponents(QUuid componentId); void showDescendantComponents(QUuid componentId);