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>
<translation></translation>
</message>
<message>
<source>Poses</source>
<translation>姿</translation>
</message>
<message>
<source>Motions</source>
<translation></translation>
</message>
</context>
<context>
<name>MotionListWidget</name>
@ -676,6 +684,14 @@ Tips:
<source>Seam</source>
<translation></translation>
</message>
<message>
<source>Copy Color</source>
<translation></translation>
</message>
<message>
<source>Paste Color</source>
<translation></translation>
</message>
</context>
<context>
<name>PartWidget</name>

View File

@ -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);

View File

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

View File

@ -8,6 +8,9 @@
#include <QGuiApplication>
#include <QComboBox>
#include <QFormLayout>
#include <QClipboard>
#include <QMimeData>
#include <QApplication>
#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(&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) {
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<QUuid> 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();

View File

@ -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);