102 bool newAssistantAllowed =
true;
125 QPointF mousePos =
m_canvas->viewConverter()->documentToView(canvasDecoration->
snapToGuide(event, QPointF(),
false));
135 if (assistant->isLocked()) {
144 allAssistantHandles.append(assistant->handles());
145 allAssistantHandles.append(assistant->sideHandles());
150 if (dist < minDist) {
155 m_canvas->paintingAssistantsDecoration()->raiseAssistant(assistant);
169 if (dist < minDist) {
172 m_dragStart = QPointF(assistant->topRight().data()->x(),assistant->topRight().data()->y());
176 if (dist < minDist) {
180 m_dragStart = QPointF(assistant->topLeft().data()->x(),assistant->topLeft().data()->y());
183 if (dist < minDist) {
187 m_dragStart = QPointF(assistant->bottomRight().data()->x(),assistant->bottomRight().data()->y());
190 if (dist < minDist) {
194 m_dragStart = QPointF(assistant->bottomLeft().data()->x(),assistant->bottomLeft().data()->y());
197 m_dragStart = QPointF((assistant->bottomLeft().data()->x()+assistant->topLeft().data()->x())*0.5,
198 (assistant->bottomLeft().data()->y()+assistant->topLeft().data()->y())*0.5);
211 m_dragStart = QPointF((assistant->topRight().data()->x()+assistant->bottomRight().data()->x())*0.5,
212 (assistant->topRight().data()->y()+assistant->bottomRight().data()->y())*0.5);
226 m_dragStart = QPointF((assistant->topLeft().data()->x()+assistant->topRight().data()->x())*0.5,
227 (assistant->topLeft().data()->y()+assistant->topRight().data()->y())*0.5);
241 m_dragStart = QPointF((assistant->bottomLeft().data()->x()+assistant->bottomRight().data()->x())*0.5,
242 (assistant->bottomLeft().data()->y()+assistant->bottomRight().data()->y())*0.5);
258 else if (
m_handleDrag && assistant->handles().size()>1 && (assistant->id() ==
"ruler" ||
259 assistant->id() ==
"parallel ruler" ||
260 assistant->id() ==
"infinite ruler" ||
261 assistant->id() ==
"spline" ||
262 assistant->id() ==
"curvilinear-perspective")){
267 }
else if(assistant->handles().size()==4){
275 }
else if (
m_handleDrag && assistant->handles().size()>2 && (assistant->id() ==
"ellipse" ||
276 assistant->id() ==
"concentric ellipse" ||
277 assistant->id() ==
"fisheye-point")){
290 }
else if (
m_handleDrag && assistant->handles().size()>2 && assistant->id() ==
"two point") {
298 const QPointF
p1 = *assistant->handles()[0];
299 const QPointF
p2 = *assistant->handles()[1];
300 const QPointF
p3 = *assistant->handles()[2];
303 QTransform t = qSharedPointerCast<TwoPointAssistant>(
m_newAssistant)->localTransform(
p1,
p2,
p3,&size);
304 QTransform inv = t.inverted();
305 if (t.map(
p1).x() * t.map(
p2).x() > 0) {
309 const QPointF safe_start = QPointF(-1.0*t.map(
p1).x(),t.map(
p1).y());
312 const QPointF safe_start = QPointF(-1.0*t.map(
p2).x(),t.map(
p1).y());
322 }
else if (
m_handleDrag && assistant->id() ==
"vanishing point" &&
353 QPointF uiMousePosition = initialTransform.map(canvasDecoration->
snapToGuide(event, QPointF(),
false));
358 QPointF actionsPosition = initialTransform.map(assistant->viewportConstrainedEditorPosition(converter, globalEditorWidgetData.
boundingSize));
365 QPointF actionsBGRectangle(actionsPosition + QPointF(globalEditorWidgetData.
widgetOffset,globalEditorWidgetData.
widgetOffset));
366 QRectF editorWidget = QRectF(actionsBGRectangle.x(), actionsBGRectangle.y(), globalEditorWidgetData.
boundingSize.width(), globalEditorWidgetData.
boundingSize.height());
368 if (editorWidget.contains(uiMousePosition)) {
369 assistantsPressed.push_back(assistant);
375 if (!assistantsPressed.isEmpty()) {
379 m_canvas->paintingAssistantsDecoration()->raiseAssistant(assistant);
383 QPointF actionsPosition = initialTransform.map(assistant->viewportConstrainedEditorPosition(converter, globalEditorWidgetData.
boundingSize));
387 QPointF iconMovePosition(actionsPosition + globalEditorWidgetData.
moveIconPosition);
388 QRectF moveRect(iconMovePosition, QSizeF(globalEditorWidgetData.
buttonSize, globalEditorWidgetData.
buttonSize));
390 if (moveRect.contains(uiMousePosition) && !assistant->isLocked()) {
401 QPointF iconSnapPosition(actionsPosition + globalEditorWidgetData.
snapIconPosition);
402 QRectF visibleRect(iconSnapPosition, QSizeF(globalEditorWidgetData.
buttonSize, globalEditorWidgetData.
buttonSize));
403 if (visibleRect.contains(uiMousePosition)) {
404 newAssistantAllowed =
false;
405 assistant->setSnappingActive(!assistant->isSnappingActive());
406 assistant->uncache();
412 QPointF iconLockPosition(actionsPosition + globalEditorWidgetData.
lockedIconPosition);
413 QRectF lockRect(iconLockPosition, QSizeF(globalEditorWidgetData.
buttonSize, globalEditorWidgetData.
buttonSize));
414 if (lockRect.contains(uiMousePosition)) {
416 assistant->setLocked(!assistant->isLocked());
425 QRectF duplicateRect(iconDuplicatePosition,QSizeF(globalEditorWidgetData.
buttonSize,globalEditorWidgetData.
buttonSize));
427 if (duplicateRect.contains(uiMousePosition)) {
429 QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> handleMap;
437 m_canvas->viewManager()->undoAdapter()->addCommand(addAssistantCmd);
444 if(assistant->isLocked()) {
445 newAssistantAllowed =
false;
466 QPointF iconDeletePosition(actionsPosition + globalEditorWidgetData.
deleteIconPosition);
467 QRectF deleteRect(iconDeletePosition, QSizeF(globalEditorWidgetData.
buttonSize, globalEditorWidgetData.
buttonSize));
468 if (deleteRect.contains(uiMousePosition) && !assistant->isLocked()) {
470 if(
m_canvas->paintingAssistantsDecoration()->assistants().isEmpty()) {
479 if((QRectF(actionsPosition + QPointF(10, 10), globalEditorWidgetData.
boundingSize).adjusted(-2, -2, 2, 2).contains(uiMousePosition))) {
480 newAssistantAllowed =
false;
491 if (newAssistantAllowed==
true) {
492 QString key =
m_options.availableAssistantsComboBox->model()->index(
m_options.availableAssistantsComboBox->currentIndex(), 0 ).data(Qt::UserRole).toString();
493 KConfigGroup cfg = KSharedConfig::openConfig()->group(
toolId());
494 cfg.writeEntry(
"AssistantType", key);
509 m_newAssistant->setAssistantGlobalColorCache(
m_canvas->paintingAssistantsDecoration()->globalAssistantsColor());
531 if (!(event->
modifiers() & Qt::ShiftModifier)) {
532 double minDist = 49.0;
533 QPointF mousePos =
m_canvas->viewConverter()->documentToView(event->
point);
540 if (dist < minDist) {
549 if (event->
modifiers() & Qt::ShiftModifier ) {
568 QPointF currentOffset = selectedAssistant->editorWidgetOffset();
569 selectedAssistant->setEditorWidgetOffset(currentOffset + (event->
point -
m_dragEnd));
577 QPointF mousep =
m_canvas->viewConverter()->documentToView(event->
point);
578 QList <KisPaintingAssistantSP> pAssistant=
m_canvas->paintingAssistantsDecoration()->assistants();
581 if(assistant->id() ==
"perspective") {
593 if(
m_handleDrag && assistant->id() ==
"vanishing point" && assistant->sideHandles().size()==4) {
596 QLineF perspectiveline = QLineF(*assistant->handles()[0],
597 *assistant->sideHandles()[0]);
599 qreal
length = QLineF(*assistant->sideHandles()[0],
600 *assistant->sideHandles()[1]).length();
606 length += perspectiveline.length();
607 perspectiveline.setLength(
length);
608 *assistant->sideHandles()[1] = perspectiveline.p2();
611 QLineF perspectiveline = QLineF(*assistant->handles()[0], *assistant->sideHandles()[2]);
612 qreal
length = QLineF(*assistant->sideHandles()[2], *assistant->sideHandles()[3]).length();
618 length += perspectiveline.length();
619 perspectiveline.setLength(
length);
620 *assistant->sideHandles()[3] = perspectiveline.p2();
623 QPointF vanishingpoint(0,0);
624 QLineF perspectiveline = QLineF(*assistant->sideHandles()[0], *assistant->sideHandles()[1]);
625 QLineF perspectiveline2 = QLineF(*assistant->sideHandles()[2], *assistant->sideHandles()[3]);
627 if (QLineF(perspectiveline2).intersects(QLineF(perspectiveline), &vanishingpoint) != QLineF::NoIntersection){
628 *assistant->handles()[0] = vanishingpoint;
632 QLineF perspectiveline = QLineF(*assistant->handles()[0], *assistant->sideHandles()[0]);
633 QLineF perspectiveline2 = QLineF(*assistant->handles()[0], *assistant->sideHandles()[2]);
634 qreal
length = QLineF(*assistant->sideHandles()[0], *assistant->sideHandles()[1]).length();
635 qreal length2 = QLineF(*assistant->sideHandles()[2], *assistant->sideHandles()[3]).length();
645 length += perspectiveline.length();
646 length2 += perspectiveline2.length();
647 perspectiveline.setLength(
length);
648 perspectiveline2.setLength(length2);
649 *assistant->sideHandles()[1] = perspectiveline.p2();
650 *assistant->sideHandles()[3] = perspectiveline2.p2();
654 if (
m_handleDrag && assistant->id() ==
"two point" && assistant->handles().size() >= 3 &&
655 assistant->sideHandles().size() == 8) {
660 const bool far_handle_is_dragged =
664 if (far_handle_is_dragged) {
665 QLineF perspective_line_a, perspective_line_b;
666 QPointF vp_new_pos(0,0);
670 perspective_line_a = QLineF(*side_hndl[0],*side_hndl[1]);
671 perspective_line_b = QLineF(*side_hndl[4],*side_hndl[5]);
674 perspective_line_a = QLineF(*side_hndl[3],*side_hndl[2]);
675 perspective_line_b = QLineF(*side_hndl[6],*side_hndl[7]);
677 if (perspective_line_a.intersects(perspective_line_b, &vp_new_pos) != QLineF::NoIntersection) {
678 *vp_moved = vp_new_pos;
681 QLineF perspective_line_a1;
682 QLineF perspective_line_b1;
683 QLineF perspective_line_a2;
684 QLineF perspective_line_b2;
686 perspective_line_a1 = QLineF(*hndl[0], *side_hndl[0]);
687 perspective_line_a1.setLength(QLineF(*side_hndl[0],*side_hndl[1]).
length());
688 perspective_line_a1.translate(*side_hndl[0] - perspective_line_a1.p1());
689 *side_hndl[1] = perspective_line_a1.p2();
691 perspective_line_b1 = QLineF(*hndl[0], *side_hndl[4]);
692 perspective_line_b1.setLength(QLineF(*side_hndl[4],*side_hndl[5]).
length());
693 perspective_line_b1.translate(*side_hndl[4] - perspective_line_b1.p1());
694 *side_hndl[5] = perspective_line_b1.p2();
696 perspective_line_a2 = QLineF(*hndl[1], *side_hndl[2]);
697 perspective_line_a2.setLength(QLineF(*side_hndl[2],*side_hndl[3]).
length());
698 perspective_line_a2.translate(*side_hndl[2] - perspective_line_a2.p1());
699 *side_hndl[3] = perspective_line_a2.p2();
701 perspective_line_b2 = QLineF(*hndl[1], *side_hndl[6]);
702 perspective_line_b2.setLength(QLineF(*side_hndl[6],*side_hndl[7]).
length());
703 perspective_line_b2.translate(*side_hndl[6] - perspective_line_b2.p1());
704 *side_hndl[7] = perspective_line_b2.p2();
709 if (
m_handleDrag && (assistant->id() ==
"ruler" || assistant->id() ==
"infinite ruler")
710 && qSharedPointerCast<RulerAssistant>(assistant)->hasFixedLength()
711 && assistant->isAssistantComplete()) {
721 QPointF center = *ruler->handles()[0];
722 QPointF handle = *ruler->handles()[1];
724 QPointF direction = handle - center;
726 QPointF delta = direction /
distance * ruler->fixedLength();
728 *ruler->handles()[1] = center + delta;
864 int horizontalButtonCount = 0;
872 horizontalButtonCount++;
873 if(horizontalButtonCount > horizontalButtonLimit)
875 horizontalButtonCount = 1;
887 horizontalButtonCount++;
888 if(horizontalButtonCount > horizontalButtonLimit)
890 horizontalButtonCount = 1;
900 horizontalButtonCount++;
901 if(horizontalButtonCount > horizontalButtonLimit)
903 horizontalButtonCount = 1;
913 horizontalButtonCount++;
914 if(horizontalButtonCount > horizontalButtonLimit)
916 horizontalButtonCount = 0;
926 horizontalButtonCount++;
927 if(horizontalButtonCount > horizontalButtonLimit)
929 horizontalButtonCount = 1;
939 int boundingWidgetWidth = (buttonCount < horizontalButtonLimit) ? buttonCount*buttonSection:horizontalButtonLimit*buttonSection;
940 boundingWidgetWidth += 5;
943 int buttonToWidthRatio = (buttonCount/horizontalButtonLimit);
944 if(buttonCount%horizontalButtonLimit != 0) {
945 buttonToWidthRatio++;
948 int boundingWidgetHeight = buttonToWidthRatio*buttonSection;
949 boundingWidgetHeight += 5;
950 globalEditorWidgetData.
boundingSize.setHeight(boundingWidgetHeight);
953 m_canvas->updateCanvasDecorations();
980 bool hasActiveAssistant = m_selectedAssistant ? true :
false;
993 m_options.showDuplicate->setChecked(
true);
999 if (m_selectedAssistant) {
1000 bool isVanishingPointAssistant = m_selectedAssistant->id() ==
"vanishing point";
1001 bool isTwoPointAssistant = m_selectedAssistant->id() ==
"two point";
1002 bool isRulerAssistant = m_selectedAssistant->id() ==
"ruler"
1003 || m_selectedAssistant->id() ==
"infinite ruler";
1004 bool isPerspectiveAssistant = m_selectedAssistant->id() ==
"perspective";
1007 m_options.vanishingPointAngleSpinbox->setVisible(isVanishingPointAssistant);
1008 m_options.twoPointDensitySpinbox->setVisible(isTwoPointAssistant);
1009 m_options.twoPointUseVerticalCheckbox->setVisible(isTwoPointAssistant);
1010 m_options.subdivisionsSpinbox->setVisible(isRulerAssistant || isPerspectiveAssistant);
1011 m_options.brushPriorityLabel->setVisible(isPerspectiveGridAssistant);
1012 m_options.brushPrioritySpinbox->setVisible(isPerspectiveGridAssistant);
1013 m_options.brushPriorityHelpButton->setVisible(isPerspectiveGridAssistant);
1014 m_options.minorSubdivisionsSpinbox->setVisible(isRulerAssistant);
1015 m_options.fixedLengthCheckbox->setVisible(isRulerAssistant);
1020 m_options.showDuplicate->setVisible(
true);
1025 if (isVanishingPointAssistant) {
1026 QSharedPointer <VanishingPointAssistant> assis = qSharedPointerCast<VanishingPointAssistant>(m_selectedAssistant);
1027 m_options.vanishingPointAngleSpinbox->setValue(assis->referenceLineDensity());
1030 if (isTwoPointAssistant) {
1031 QSharedPointer <TwoPointAssistant> assis = qSharedPointerCast<TwoPointAssistant>(m_selectedAssistant);
1032 m_options.twoPointDensitySpinbox->setValue(assis->gridDensity());
1033 m_options.twoPointUseVerticalCheckbox->setChecked(assis->useVertical());
1036 if (isRulerAssistant) {
1037 QSharedPointer <RulerAssistant> assis = qSharedPointerCast<RulerAssistant>(m_selectedAssistant);
1038 m_options.subdivisionsSpinbox->setValue(assis->subdivisions());
1039 m_options.minorSubdivisionsSpinbox->setValue(assis->minorSubdivisions());
1040 m_options.fixedLengthCheckbox->setChecked(assis->hasFixedLength());
1042 m_options.fixedLengthSpinbox->setVisible(assis->hasFixedLength());
1043 m_options.fixedLengthUnit->setVisible(assis->hasFixedLength());
1046 QSignalBlocker b(
m_options.fixedLengthSpinbox);
1049 m_options.fixedLengthSpinbox->changeValue(assis->fixedLength());
1051 m_options.fixedLengthSpinbox->setPrefix(
"");
1053 m_options.fixedLengthSpinbox->setVisible(
false);
1054 m_options.fixedLengthUnit->setVisible(
false);
1057 if (isPerspectiveAssistant) {
1058 QSharedPointer <PerspectiveAssistant> assis = qSharedPointerCast<PerspectiveAssistant>(m_selectedAssistant);
1059 m_options.subdivisionsSpinbox->setValue(assis->subdivisions());
1062 if (isPerspectiveGridAssistant) {
1063 m_options.brushPrioritySpinbox->setValue(m_selectedAssistant->brushPriority());
1067 m_options.useCustomAssistantColor->setChecked(m_selectedAssistant->useCustomColor());
1068 m_options.customAssistantColorButton->setColor(m_selectedAssistant->assistantCustomColor());
1071 double opacity = (double)m_selectedAssistant->assistantCustomColor().alpha()/(double)255.00 * (
double)100.00 ;
1072 opacity = ceil(opacity);
1074 m_options.customColorOpacitySlider->blockSignals(
true);
1075 m_options.customColorOpacitySlider->setValue((
double)opacity);
1076 m_options.customColorOpacitySlider->blockSignals(
false);
1079 m_options.vanishingPointAngleSpinbox->setVisible(
false);
1080 m_options.twoPointDensitySpinbox->setVisible(
false);
1081 m_options.twoPointUseVerticalCheckbox->setVisible(
false);
1082 m_options.subdivisionsSpinbox->setVisible(
false);
1083 m_options.brushPriorityLabel->setVisible(
false);
1084 m_options.brushPrioritySpinbox->setVisible(
false);
1085 m_options.brushPriorityHelpButton->setVisible(
false);
1086 m_options.minorSubdivisionsSpinbox->setVisible(
false);
1087 m_options.fixedLengthCheckbox->setVisible(
false);
1088 m_options.fixedLengthSpinbox->setVisible(
false);
1089 m_options.fixedLengthUnit->setVisible(
false);
1093 m_options.useCustomAssistantColor->setVisible(hasActiveAssistant);
1096 bool showCustomColorSettings =
m_options.useCustomAssistantColor->isChecked() && hasActiveAssistant;
1097 m_options.customColorOpacitySlider->setVisible(showCustomColorSettings);
1098 m_options.customAssistantColorButton->setVisible(showCustomColorSettings);
1101 m_options.assistantsGlobalOpacitySlider->setEnabled(!showCustomColorSettings);
1102 m_options.assistantsColor->setEnabled(!showCustomColorSettings);
1103 m_options.globalColorLabel->setEnabled(!showCustomColorSettings);
1105 QString key =
m_options.availableAssistantsComboBox->model()->index(
m_options.availableAssistantsComboBox->currentIndex(), 0 ).data(Qt::UserRole).toString();
1106 m_options.localAssistantCheckbox->setVisible(key ==
"two point" || key ==
"vanishing point" || key ==
"parallel ruler");
1463 dialog.setCaption(i18n(
"Select an Assistant"));
1464 dialog.setDefaultDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
1465 dialog.setMimeTypeFilters(
QStringList() <<
"application/x-krita-assistant",
"application/x-krita-assistant");
1466 QString filename = dialog.filename();
1468 QFile file(filename);
1469 if (!file.open(QIODevice::ReadOnly)) {
return; }
1471 QByteArray data = file.readAll();
1472 QXmlStreamReader xml(data);
1473 QMap<int, KisPaintingAssistantHandleSP> handleMap;
1474 QMap<int, KisPaintingAssistantHandleSP> sideHandleMap;
1476 bool errors =
false;
1481 while (!xml.atEnd()) {
1482 switch (xml.readNext()) {
1483 case QXmlStreamReader::StartElement:
1484 if (xml.name() ==
"handle") {
1485 if (assistant && !xml.attributes().value(
"ref").isEmpty()) {
1493 QString strId = xml.attributes().value(
"id").toString(),
1494 strX = xml.attributes().value(
"x").toString(),
1495 strY = xml.attributes().value(
"y").toString();
1499 if (!strId.isEmpty() && !strX.isEmpty() && !strY.isEmpty()) {
1500 int id = strId.toInt();
1501 double x = strX.toDouble(),
1502 y = strY.toDouble();
1503 if (!handleMap.contains(
id)) {
1513 }
else if (xml.name() ==
"sidehandle"){
1516 if (!xml.attributes().value(
"id").isEmpty()) {
1517 QString strId = xml.attributes().value(
"id").toString(),
1518 strX = xml.attributes().value(
"x").toString(),
1519 strY = xml.attributes().value(
"y").toString();
1520 if (!strId.isEmpty() && !strX.isEmpty() && !strY.isEmpty()) {
1521 int id = strId.toInt();
1522 double x = strX.toDouble();
1523 double y = strY.toDouble();
1524 if (!sideHandleMap.contains(
id)) {
1529 if (!xml.attributes().value(
"ref").isEmpty() && assistant) {
1536 }
else if (xml.name() ==
"assistant") {
1551 if (xml.attributes().hasAttribute(
"useCustomColor")) {
1552 auto useCustomColor = xml.attributes().value(
"useCustomColor");
1554 bool usingColor =
false;
1555 if (useCustomColor.toString() ==
"1") {
1558 assistant->setUseCustomColor(usingColor);
1561 if ( xml.attributes().hasAttribute(
"useCustomColor")) {
1562 auto customColor = xml.attributes().value(
"customColor");
1570 assistant->loadCustomXml(&xml);
1575 case QXmlStreamReader::EndElement:
1576 if (xml.name() ==
"assistant") {
1578 if (assistant->handles().size() == assistant->numHandles()) {
1579 if (assistant->id() ==
"vanishing point" && sideHandleMap.empty()){
1581 QPointF pos = *assistant->handles()[0];
1587 m_canvas->paintingAssistantsDecoration()->addAssistant(assistant);
1605 if (xml.hasError()) {
1606 QMessageBox::warning(qApp->activeWindow(), i18nc(
"@title:window",
"Krita"), xml.errorString());
1609 QMessageBox::warning(qApp->activeWindow(), i18nc(
"@title:window",
"Krita"), i18n(
"Errors were encountered. Not all assistants were successfully loaded."));
1613 m_canvas->viewManager()->undoAdapter()->addCommand(command);
1625 QXmlStreamWriter xml(&data);
1626 xml.writeStartDocument();
1627 xml.writeStartElement(
"paintingassistant");
1628 xml.writeAttribute(
"color",
1630 m_canvas->paintingAssistantsDecoration()->globalAssistantsColor()));
1633 xml.writeStartElement(
"handles");
1634 QMap<KisPaintingAssistantHandleSP, int> handleMap;
1636 int id = handleMap.size();
1637 handleMap.insert(handle,
id);
1638 xml.writeStartElement(
"handle");
1640 xml.writeAttribute(
"id", QString::number(
id));
1641 xml.writeAttribute(
"x", QString::number(
double(handle->x()),
'f', 3));
1642 xml.writeAttribute(
"y", QString::number(
double(handle->y()),
'f', 3));
1643 xml.writeEndElement();
1645 xml.writeEndElement();
1646 xml.writeStartElement(
"sidehandles");
1647 QMap<KisPaintingAssistantHandleSP, int> sideHandleMap;
1650 int id = sideHandleMap.size();
1651 sideHandleMap.insert(handle,
id);
1652 xml.writeStartElement(
"sidehandle");
1653 xml.writeAttribute(
"id", QString::number(
id));
1654 xml.writeAttribute(
"x", QString::number(
double(handle->x()),
'f', 3));
1655 xml.writeAttribute(
"y", QString::number(
double(handle->y()),
'f', 3));
1656 xml.writeEndElement();
1659 xml.writeStartElement(
"assistants");
1663 xml.writeStartElement(
"assistant");
1664 xml.writeAttribute(
"type", assistant->id());
1665 xml.writeAttribute(
"useCustomColor", QString::number(assistant->useCustomColor()));
1671 assistant->saveCustomXml(&xml);
1674 xml.writeStartElement(
"handles");
1676 xml.writeStartElement(
"handle");
1677 xml.writeAttribute(
"ref", QString::number(handleMap.value(handle)));
1678 xml.writeEndElement();
1680 xml.writeEndElement();
1681 if (!sideHandleMap.empty()) {
1682 xml.writeStartElement(
"sidehandles");
1684 xml.writeStartElement(
"sidehandle");
1685 xml.writeAttribute(
"ref", QString::number(sideHandleMap.value(handle)));
1686 xml.writeEndElement();
1688 xml.writeEndElement();
1690 xml.writeEndElement();
1692 xml.writeEndElement();
1693 xml.writeEndElement();
1694 xml.writeEndDocument();
1697 dialog.setCaption(i18n(
"Save Assistant"));
1698 dialog.setDefaultDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
1699 dialog.setMimeTypeFilters(
QStringList() <<
"application/x-krita-assistant",
"application/x-krita-assistant");
1700 QString filename = dialog.filename();
1701 if (filename.isEmpty())
return;
1703 QFile file(filename);
1704 if (file.open(QIODevice::WriteOnly)) {
1707 qWarning() <<
"Couldn't open file" << file.fileName() <<
"for writing:" << file.errorString();
1716 const QString brushPriorityHelpText = i18n(
"When a brush is over perspective helpers, and needs to decide on the one to follow (eg for the \"Perspective\" brush sensor), this will be used. Priority is like counting, lower number comes first.");
1718 KConfigGroup cfg = KSharedConfig::openConfig()->group(
toolId());
1722 specialSpacer->setObjectName(
"SpecialSpacer");
1723 specialSpacer->setFixedSize(0, 0);
1727 m_options.loadAssistantButton->setIconSize(QSize(16, 16));
1729 m_options.saveAssistantButton->setIconSize(QSize(16, 16));
1731 m_options.deleteAllAssistantsButton->setIconSize(QSize(16, 16));
1734 m_options.showDockerOptionsButton->setIconSize(QSize(16, 16));
1739 assistants <<
KoID(key, name);
1743 QString currentAssistantType = cfg.readEntry(
"AssistantType",
"two point");
1745 int currentAssistantIndex = 0;
1746 Q_FOREACH(
const KoID &
id, assistants) {
1747 m_options.availableAssistantsComboBox->addItem(
id.name(),
id.
id());
1748 if (
id.
id() == currentAssistantType) {
1749 currentAssistantIndex = i;
1753 m_options.availableAssistantsComboBox->setCurrentIndex(currentAssistantIndex);
1783 const QColor color =
m_canvas->paintingAssistantsDecoration()->globalAssistantsColor();
1785 QColor opaqueColor = color;
1786 opaqueColor.setAlpha(255);
1788 m_options.assistantsColor->setColor(opaqueColor);
1789 m_options.customAssistantColorButton->setColor(opaqueColor);
1790 m_options.assistantsGlobalOpacitySlider->setValue(color.alphaF() * 100.0);
1793 m_options.assistantsColor->setColor(QColor(176, 176, 176, 255));
1794 m_options.assistantsGlobalOpacitySlider->setValue(100);
1797 m_options.assistantsGlobalOpacitySlider->setPrefix(i18n(
"Opacity: "));
1798 m_options.assistantsGlobalOpacitySlider->setSuffix(
" %");
1802 m_options.customColorOpacitySlider->setValue(100);
1803 m_options.customColorOpacitySlider->setPrefix(i18n(
"Opacity: "));
1804 m_options.customColorOpacitySlider->setSuffix(
" %");
1810 m_options.twoPointDensitySpinbox->setPrefix(i18n(
"Density: "));
1811 m_options.twoPointDensitySpinbox->setRange(0.1, 4.0, 2);
1812 m_options.twoPointDensitySpinbox->setSingleStep(0.1);
1814 m_options.vanishingPointAngleSpinbox->setPrefix(i18n(
"Density: "));
1815 m_options.vanishingPointAngleSpinbox->setSuffix(QStringLiteral(
"°"));
1816 m_options.vanishingPointAngleSpinbox->setRange(1.0, 180.0);
1817 m_options.vanishingPointAngleSpinbox->setSingleStep(1.0);
1819 m_options.subdivisionsSpinbox->setPrefix(i18n(
"Subdivisions: "));
1820 m_options.subdivisionsSpinbox->setRange(0, 100);
1821 m_options.subdivisionsSpinbox->setSoftRange(0, 20);
1823 m_options.brushPrioritySpinbox->setRange(-100, 100);
1824 m_options.brushPriorityLabel->setToolTip(brushPriorityHelpText);
1825 m_options.brushPrioritySpinbox->setToolTip(brushPriorityHelpText);
1827 m_options.brushPriorityHelpButton->setToolTip(brushPriorityHelpText);
1828 m_options.brushPriorityHelpButton->setWhatsThis(brushPriorityHelpText);
1830 m_options.minorSubdivisionsSpinbox->setPrefix(i18n(
"Minor Subdivisions: "));
1831 m_options.minorSubdivisionsSpinbox->setRange(1, 5);
1835 m_options.fixedLengthSpinbox->setDisplayUnit(
false);
1836 m_options.fixedLengthSpinbox->setMinimum(0);
1842 m_options.vanishingPointAngleSpinbox->setVisible(
false);
1843 m_options.twoPointDensitySpinbox->setVisible(
false);
1844 m_options.subdivisionsSpinbox->setVisible(
false);
1845 m_options.brushPriorityLabel->setVisible(
false);
1846 m_options.brushPrioritySpinbox->setVisible(
false);
1847 m_options.brushPriorityHelpButton->setVisible(
false);
1848 m_options.minorSubdivisionsSpinbox->setVisible(
false);
1849 m_options.fixedLengthCheckbox->setVisible(
false);
1850 m_options.fixedLengthSpinbox->setVisible(
false);
1851 m_options.fixedLengthUnit->setVisible(
false);
1854 m_options.localAssistantCheckbox->setChecked(cfg.readEntry(
"LimitAssistantToArea",
false));
1874 m_options.showDuplicate->setChecked(
true);
2037 if (event->
modifiers() == Qt::NoModifier) {
2046 if (selectedAssistant->id() ==
"two point" &&
m_handleDrag != handles[2] &&
2047 event->
modifiers() != Qt::ShiftModifier) {
2057 const QTransform t = assis->localTransform(prevPoint,*handleOpp,*handles[2],&size);
2058 const QTransform inv = t.inverted();
2063 const QLineF horizon(QPointF(t.map(prevPoint).x(), 0), QPointF(t.map(*handleOpp).x(), 0));
2064 const QPointF sp = QPointF(0, size);
2066 const bool preserve_distortion_snap =
event->modifiers() == Qt::ControlModifier;
2067 const bool preserve_left_right_ratio_snap =
event->modifiers() == (Qt::ControlModifier|Qt::ShiftModifier);
2068 const bool preserve_horizon_snap =
event->modifiers() == Qt::AltModifier;
2071 QPointF opp_snap_point;
2072 QLineF sp_to_opp_vp;
2074 if (preserve_distortion_snap) {
2075 const QLineF sp_to_vp = QLineF(sp, t.map(*
m_handleDrag));
2076 sp_to_opp_vp = sp_to_vp.normalVector();
2077 sp_to_vp.intersects(horizon,&snap_point);
2078 }
else if (preserve_left_right_ratio_snap) {
2079 const QLineF prev_sp_to_vp = QLineF(sp, horizon.p1());
2080 QLineF new_sp_to_vp = prev_sp_to_vp.translated(t.map(*
m_handleDrag)-sp);
2082 new_sp_to_vp.intersects(QLineF(QPoint(0,0),QPointF(0,1)),&new_sp);
2083 sp_to_opp_vp = new_sp_to_vp.normalVector().translated(new_sp-new_sp_to_vp.p1());
2084 new_sp_to_vp.intersects(horizon,&snap_point);
2085 }
else if (preserve_horizon_snap) {
2086 snap_point = QPointF(t.map(*m_handleDrag).x(), 0);
2087 sp_to_opp_vp = QLineF(sp,QPointF(t.map(prevPoint).x(), 0)).normalVector();
2093 const bool no_intersection =
2095 sp_to_opp_vp.intersects(horizon, &opp_snap_point) == QLineF::NoIntersection;
2096 const bool origin_is_between =
2097 (snap_point.x() < 0 && opp_snap_point.x() > 0) ||
2098 (snap_point.x() > 0 && opp_snap_point.x() < 0);
2099 const bool null_opp_point =
2101 const bool overlapping_snap_points =
2105 if (!origin_is_between || no_intersection || null_opp_point || overlapping_snap_points) {
2110 if (preserve_distortion_snap) {
2111 sp_to_opp_vp = QLineF(sp, t.map(
m_dragStart)).normalVector();
2112 sp_to_opp_vp.intersects(horizon, &oppStart);
2115 const qreal p2x = preserve_horizon_snap ? t.map(*handleOpp).x() : -
p1.x();
2116 const QPointF
p2 = QPointF(p2x,
p1.y());
2117 const QLineF new_horizon = QLineF(
p1,
p2);
2118 const qreal new_size = sqrt(pow(new_horizon.length()/2.0,2) -
2119 pow(abs(new_horizon.center().x()),2));
2120 const QPointF new_sp = QPointF(0, new_size);
2121 sp_to_opp_vp = QLineF(new_sp, t.map(
m_dragStart)).normalVector();
2123 sp_to_opp_vp.intersects(horizon, &oppStart);
2124 *handleOpp=inv.map(oppStart);
2129 *handleOpp = inv.map(opp_snap_point);
2134 dragRadius.setLength(
m_radius.length());
2145 if (handles.size() == 2) {
2147 *handle_snap = snap_point;
2149 bool was_snapped =
false;
2152 handles.size() == 3 ? start = handles[0] : start = handles[1];
2154 *handle_snap = snap_point;
2161 QPointF center = QLineF(*handles[0], *handles[1]).center();
2162 QLineF radius = QLineF(center,*handles[0]);
2163 QLineF dragRadius = QLineF(center, event->
point);
2164 dragRadius.setLength(radius.length());
2165 *handle_snap = dragRadius.p2();
2171 handles.size() == 3 ? start = handles[1] : start = handles[2];
2173 *handle_snap = snap_point;