Add batch color paste #36

Thanks @SatishGodaPearl for the suggestion.
Closes #36
master
Jeremy Hu 2019-08-20 23:59:08 +09:30
parent 02a2b39c58
commit c4da15eb9e
5 changed files with 63 additions and 46 deletions

View File

@ -512,6 +512,14 @@ Tips:
<source>New</source> <source>New</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>Poses</source>
<translation>姿</translation>
</message>
<message>
<source>Motions</source>
<translation></translation>
</message>
</context> </context>
<context> <context>
<name>MotionListWidget</name> <name>MotionListWidget</name>
@ -676,6 +684,14 @@ Tips:
<source>Seam</source> <source>Seam</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>Copy Color</source>
<translation></translation>
</message>
<message>
<source>Paste Color</source>
<translation></translation>
</message>
</context> </context>
<context> <context>
<name>PartWidget</name> <name>PartWidget</name>

View File

@ -942,6 +942,7 @@ DocumentWindow::DocumentWindow() :
connect(partTreeWidget, &PartTreeWidget::unlockAllComponents, m_document, &Document::unlockAllComponents); connect(partTreeWidget, &PartTreeWidget::unlockAllComponents, m_document, &Document::unlockAllComponents);
connect(partTreeWidget, &PartTreeWidget::setPartLockState, m_document, &Document::setPartLockState); connect(partTreeWidget, &PartTreeWidget::setPartLockState, m_document, &Document::setPartLockState);
connect(partTreeWidget, &PartTreeWidget::setPartVisibleState, m_document, &Document::setPartVisibleState); 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::setComponentCombineMode, m_document, &Document::setComponentCombineMode);
connect(partTreeWidget, &PartTreeWidget::setPartTarget, m_document, &Document::setPartTarget); connect(partTreeWidget, &PartTreeWidget::setPartTarget, m_document, &Document::setPartTarget);
connect(partTreeWidget, &PartTreeWidget::setPartBase, m_document, &Document::setPartBase); connect(partTreeWidget, &PartTreeWidget::setPartBase, m_document, &Document::setPartBase);

View File

@ -66,8 +66,8 @@ MotionEditWidget::MotionEditWidget(const Document *document, QWidget *parent) :
}); });
std::vector<QString> tabs = { std::vector<QString> tabs = {
QString("Poses"), tr("Poses"),
QString("Motions") tr("Motions")
}; };
TabWidget *tabWidget = new TabWidget(tabs); TabWidget *tabWidget = new TabWidget(tabs);
tabWidget->setCurrentIndex(0); tabWidget->setCurrentIndex(0);

View File

@ -8,6 +8,9 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <QComboBox> #include <QComboBox>
#include <QFormLayout> #include <QFormLayout>
#include <QClipboard>
#include <QMimeData>
#include <QApplication>
#include "parttreewidget.h" #include "parttreewidget.h"
#include "partwidget.h" #include "partwidget.h"
#include "skeletongraphicswidget.h" #include "skeletongraphicswidget.h"
@ -342,6 +345,20 @@ void PartTreeWidget::showContextMenu(const QPoint &pos)
QAction unlockAction(tr("Unlock"), this); QAction unlockAction(tr("Unlock"), this);
unlockAction.setIcon(Theme::awesome()->icon(fa::unlock)); unlockAction.setIcon(Theme::awesome()->icon(fa::unlock));
QAction selectAction(tr("Select"), this); 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) { if (nullptr != component && nullptr != part) {
connect(&selectAction, &QAction::triggered, [=]() { connect(&selectAction, &QAction::triggered, [=]() {
@ -349,6 +366,19 @@ void PartTreeWidget::showContextMenu(const QPoint &pos)
}); });
contextMenu.addAction(&selectAction); contextMenu.addAction(&selectAction);
connect(&copyColorAction, &QAction::triggered, [=]() {
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(part->color.name());
});
contextMenu.addAction(&copyColorAction);
if (hasColorInClipboard) {
connect(&pasteColorAction, &QAction::triggered, [=]() {
emit setPartColorState(component->linkToPartId, true, colorInClipboard);
});
contextMenu.addAction(&pasteColorAction);
}
if (part->visible) { if (part->visible) {
connect(&hideAction, &QAction::triggered, [=]() { connect(&hideAction, &QAction::triggered, [=]() {
emit setPartVisibleState(component->linkToPartId, false); emit setPartVisibleState(component->linkToPartId, false);
@ -383,6 +413,19 @@ void PartTreeWidget::showContextMenu(const QPoint &pos)
} }
}); });
contextMenu.addAction(&selectAction); contextMenu.addAction(&selectAction);
if (hasColorInClipboard) {
connect(&pasteColorAction, &QAction::triggered, [=]() {
for (const auto &componentId: componentIds) {
std::vector<QUuid> partIds;
m_document->collectComponentDescendantParts(componentId, partIds);
for (const auto &partId: partIds) {
emit setPartColorState(partId, true, colorInClipboard);
}
}
});
contextMenu.addAction(&pasteColorAction);
}
connect(&showAction, &QAction::triggered, [=]() { connect(&showAction, &QAction::triggered, [=]() {
for (const auto &componentId: componentIds) for (const auto &componentId: componentIds)
@ -409,52 +452,8 @@ void PartTreeWidget::showContextMenu(const QPoint &pos)
contextMenu.addAction(&unlockAction); 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(); 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); QAction collapseAllAction(tr("Collapse All"), this);
connect(&collapseAllAction, &QAction::triggered, [=]() { connect(&collapseAllAction, &QAction::triggered, [=]() {
emit collapseAllComponents(); emit collapseAllComponents();

View File

@ -35,6 +35,7 @@ signals:
void unlockAllComponents(); void unlockAllComponents();
void setPartLockState(QUuid partId, bool locked); void setPartLockState(QUuid partId, bool locked);
void setPartVisibleState(QUuid partId, bool visible); void setPartVisibleState(QUuid partId, bool visible);
void setPartColorState(QUuid partId, bool hasColor, QColor color);
void setComponentCombineMode(QUuid componentId, CombineMode combineMode); void setComponentCombineMode(QUuid componentId, CombineMode combineMode);
void hideDescendantComponents(QUuid componentId); void hideDescendantComponents(QUuid componentId);
void showDescendantComponents(QUuid componentId); void showDescendantComponents(QUuid componentId);