From 8c75893c8b0e6793f8fff7194123baad024f8639 Mon Sep 17 00:00:00 2001 From: Pablo Gil Date: Thu, 5 Dec 2024 16:52:44 +0100 Subject: [PATCH 1/5] first tests --- src/app/GUI/extraactions.cpp | 10 +++++++++- src/core/Boxes/boundingbox.cpp | 6 ++++++ src/core/Boxes/boundingbox.h | 1 + src/core/canvas.h | 4 ++-- src/core/canvasselectedboxesactions.cpp | 11 +++++++++++ src/ui/widgets/alignwidget.cpp | 2 ++ 6 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/app/GUI/extraactions.cpp b/src/app/GUI/extraactions.cpp index 4c1304b1c..8ca04d155 100644 --- a/src/app/GUI/extraactions.cpp +++ b/src/app/GUI/extraactions.cpp @@ -242,11 +242,19 @@ void MainWindow::setupMenuExtras() align = Qt::AlignHCenter; break; case 4: // Align Left - Geometry Relative to Scene ----------------------------------------------------------------------------------- + // alignString = alignLeft; + // pivotString = alignGeometry; + // relString = alignScene; + // pivot = AlignPivot::geometry; + // rel = AlignRelativeTo::scene; + // iconString = alignLeftIcon; + // alignBoth = false; + // align = Qt::AlignLeft; alignString = alignLeft; pivotString = alignGeometry; relString = alignScene; pivot = AlignPivot::geometry; - rel = AlignRelativeTo::scene; + rel = AlignRelativeTo::itself; iconString = alignLeftIcon; alignBoth = false; align = Qt::AlignLeft; diff --git a/src/core/Boxes/boundingbox.cpp b/src/core/Boxes/boundingbox.cpp index 010c1fed0..43e95a7d0 100644 --- a/src/core/Boxes/boundingbox.cpp +++ b/src/core/Boxes/boundingbox.cpp @@ -865,6 +865,12 @@ void BoundingBox::alignPivot(const Qt::Alignment align, const QRectF& to) { alignGeometry(QRectF(pivot, pivot), align, to); } +void BoundingBox::alignPivot2(const Qt::Alignment align, const QRectF& to) { + const auto center = getRelCenterPosition(); + mTransformAnimator->setPivotFixedTransform(center); + requestGlobalPivotUpdateIfSelected(); +} + void BoundingBox::moveByAbs(const QPointF &trans) { mTransformAnimator->moveByAbs(trans); } diff --git a/src/core/Boxes/boundingbox.h b/src/core/Boxes/boundingbox.h index ced978d1f..d145e2500 100644 --- a/src/core/Boxes/boundingbox.h +++ b/src/core/Boxes/boundingbox.h @@ -298,6 +298,7 @@ class CORE_EXPORT BoundingBox : public eBoxOrSound { void alignGeometry(const Qt::Alignment align, const QRectF& to); void alignPivot(const Qt::Alignment align, const QRectF& to); + void alignPivot2(const Qt::Alignment align, const QRectF& to); QMatrix getTotalTransform() const; diff --git a/src/core/canvas.h b/src/core/canvas.h index dfad87691..1412b9d2f 100644 --- a/src/core/canvas.h +++ b/src/core/canvas.h @@ -69,11 +69,11 @@ class eKeyEvent; enum class CtrlsMode : short; enum class AlignPivot { - geometry, pivot + geometry, pivot, pivot2 }; enum class AlignRelativeTo { - scene, lastSelected + scene, lastSelected, itself }; class CORE_EXPORT Canvas : public CanvasBase diff --git a/src/core/canvasselectedboxesactions.cpp b/src/core/canvasselectedboxesactions.cpp index efa3099a8..619f83189 100644 --- a/src/core/canvasselectedboxesactions.cpp +++ b/src/core/canvasselectedboxesactions.cpp @@ -864,6 +864,14 @@ void Canvas::alignSelectedBoxes(const Qt::Alignment align, skip = mLastSelectedBox; geometry = mLastSelectedBox->getAbsBoundingRect(); break; + case AlignRelativeTo::itself: + // Usar el rectángulo del propio objeto como referencia + if (pivot == AlignPivot::pivot2) { + geometry = QRectF(0., 0., mWidth, mHeight); + } else { + geometry = QRectF(0., 0., mWidth, mHeight); + } + break; } pushUndoRedoName("align"); @@ -876,6 +884,9 @@ void Canvas::alignSelectedBoxes(const Qt::Alignment align, case AlignPivot::geometry: box->alignGeometry(align, geometry); break; + case AlignPivot::pivot2: + box->alignPivot2(align, geometry); + break; } } } diff --git a/src/ui/widgets/alignwidget.cpp b/src/ui/widgets/alignwidget.cpp index 8c00fc64a..d7c46ae08 100644 --- a/src/ui/widgets/alignwidget.cpp +++ b/src/ui/widgets/alignwidget.cpp @@ -51,6 +51,7 @@ AlignWidget::AlignWidget(QWidget* const parent) mAlignPivot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); mAlignPivot->setFocusPolicy(Qt::NoFocus); mAlignPivot->addItem(tr("Align Geometry")); + mAlignPivot->addItem(tr("Align Geometry (Pivot)")); mAlignPivot->addItem(tr("Align Pivot")); combosLay->addWidget(mAlignPivot); @@ -61,6 +62,7 @@ AlignWidget::AlignWidget(QWidget* const parent) mRelativeTo->setFocusPolicy(Qt::NoFocus); mRelativeTo->addItem(tr("Relative to Scene")); mRelativeTo->addItem(tr("Relative to Last Selected")); + mRelativeTo->addItem(tr("Itself")); combosLay->addWidget(mRelativeTo); const auto buttonsLay = new QHBoxLayout; From 4e5a7d7b12461d0dbe92d1cd07bc07fee90d8268 Mon Sep 17 00:00:00 2001 From: Pablo Gil Date: Tue, 10 Dec 2024 10:02:31 +0100 Subject: [PATCH 2/5] all pivot alignment features working --- src/app/GUI/extraactions.cpp | 132 ++++++++++++++++++++++-- src/core/Boxes/boundingbox.cpp | 93 ++++++++++++++++- src/core/Boxes/boundingbox.h | 10 +- src/core/canvas.h | 2 +- src/core/canvasselectedboxesactions.cpp | 16 +-- src/ui/widgets/alignwidget.cpp | 101 ++++++++++++++++-- src/ui/widgets/alignwidget.h | 1 + 7 files changed, 327 insertions(+), 28 deletions(-) diff --git a/src/app/GUI/extraactions.cpp b/src/app/GUI/extraactions.cpp index 8ca04d155..bcd51f461 100644 --- a/src/app/GUI/extraactions.cpp +++ b/src/app/GUI/extraactions.cpp @@ -161,7 +161,7 @@ void MainWindow::setupMenuExtras() } // align { - const int alignTotal = 28; + const int alignTotal = 40; const QString alignTextDefault = tr("Align %1 %2 Relative to %3"); const QString alignGeometry = tr("Geometry"); @@ -242,19 +242,11 @@ void MainWindow::setupMenuExtras() align = Qt::AlignHCenter; break; case 4: // Align Left - Geometry Relative to Scene ----------------------------------------------------------------------------------- - // alignString = alignLeft; - // pivotString = alignGeometry; - // relString = alignScene; - // pivot = AlignPivot::geometry; - // rel = AlignRelativeTo::scene; - // iconString = alignLeftIcon; - // alignBoth = false; - // align = Qt::AlignLeft; alignString = alignLeft; pivotString = alignGeometry; relString = alignScene; pivot = AlignPivot::geometry; - rel = AlignRelativeTo::itself; + rel = AlignRelativeTo::scene; iconString = alignLeftIcon; alignBoth = false; align = Qt::AlignLeft; @@ -489,6 +481,126 @@ void MainWindow::setupMenuExtras() alignBoth = false; align = Qt::AlignVCenter; break; + case 28: // Pivot alignment to Bounding Box - VCenter ----------------------------------------------------------------------------------- + alignString = alignVCenter; + pivotString = alignPivot; + relString = alignLast; + pivot = AlignPivot::pivot2; + rel = AlignRelativeTo::boundingBox; + iconString = alignVCenterIcon; + alignBoth = false; + align = Qt::AlignVCenter; + break; + case 29: // Pivot alignment to Bounding Box - HCenter + alignString = alignVCenter; + pivotString = alignPivot; + relString = alignLast; + pivot = AlignPivot::pivot2; + rel = AlignRelativeTo::boundingBox; + iconString = alignVCenterIcon; + alignBoth = false; + align = Qt::AlignHCenter; + break; + case 30: // Pivot alignment to Bounding Box - Left + alignString = alignVCenter; + pivotString = alignPivot; + relString = alignLast; + pivot = AlignPivot::pivot2; + rel = AlignRelativeTo::boundingBox; + iconString = alignVCenterIcon; + alignBoth = false; + align = Qt::AlignLeft; + break; + case 31: // Pivot alignment to Bounding Box - Right + alignString = alignVCenter; + pivotString = alignPivot; + relString = alignLast; + pivot = AlignPivot::pivot2; + rel = AlignRelativeTo::boundingBox; + iconString = alignVCenterIcon; + alignBoth = false; + align = Qt::AlignRight; + break; + case 32: // Pivot alignment to Bounding Box - Top + alignString = alignVCenter; + pivotString = alignPivot; + relString = alignLast; + pivot = AlignPivot::pivot2; + rel = AlignRelativeTo::boundingBox; + iconString = alignVCenterIcon; + alignBoth = false; + align = Qt::AlignTop; + break; + case 33: // Pivot alignment to Bounding Box - Bottom + alignString = alignVCenter; + pivotString = alignPivot; + relString = alignLast; + pivot = AlignPivot::pivot2; + rel = AlignRelativeTo::boundingBox; + iconString = alignVCenterIcon; + alignBoth = false; + align = Qt::AlignBottom; + break; + case 34: // Pivot alignment to Scene - VCenter ----------------------------------------------------------------------------------- + alignString = alignVCenter; + pivotString = alignPivot; + relString = alignLast; + pivot = AlignPivot::pivot2; + rel = AlignRelativeTo::scene; + iconString = alignVCenterIcon; + alignBoth = false; + align = Qt::AlignVCenter; + break; + case 35: // Pivot alignment to Scene - HCenter + alignString = alignVCenter; + pivotString = alignPivot; + relString = alignLast; + pivot = AlignPivot::pivot2; + rel = AlignRelativeTo::scene; + iconString = alignVCenterIcon; + alignBoth = false; + align = Qt::AlignHCenter; + break; + case 36: // Pivot alignment to Scene - Left + alignString = alignVCenter; + pivotString = alignPivot; + relString = alignLast; + pivot = AlignPivot::pivot2; + rel = AlignRelativeTo::scene; + iconString = alignVCenterIcon; + alignBoth = false; + align = Qt::AlignLeft; + break; + case 37: // Pivot alignment to Scene - Right + alignString = alignVCenter; + pivotString = alignPivot; + relString = alignLast; + pivot = AlignPivot::pivot2; + rel = AlignRelativeTo::scene; + iconString = alignVCenterIcon; + alignBoth = false; + align = Qt::AlignRight; + break; + case 38: // Pivot alignment to Scene - Top + alignString = alignVCenter; + pivotString = alignPivot; + relString = alignLast; + pivot = AlignPivot::pivot2; + rel = AlignRelativeTo::scene; + iconString = alignVCenterIcon; + alignBoth = false; + align = Qt::AlignTop; + break; + case 39: // Pivot alignment to Scene - Bottom + alignString = alignVCenter; + pivotString = alignPivot; + relString = alignLast; + pivot = AlignPivot::pivot2; + rel = AlignRelativeTo::scene; + iconString = alignVCenterIcon; + alignBoth = false; + align = Qt::AlignBottom; + break; default: return; } diff --git a/src/core/Boxes/boundingbox.cpp b/src/core/Boxes/boundingbox.cpp index 43e95a7d0..a8ef2c9ed 100644 --- a/src/core/Boxes/boundingbox.cpp +++ b/src/core/Boxes/boundingbox.cpp @@ -865,8 +865,97 @@ void BoundingBox::alignPivot(const Qt::Alignment align, const QRectF& to) { alignGeometry(QRectF(pivot, pivot), align, to); } -void BoundingBox::alignPivot2(const Qt::Alignment align, const QRectF& to) { - const auto center = getRelCenterPosition(); +void BoundingBox::alignPivot2(const Qt::Alignment align, + const QRectF& to, + const AlignRelativeTo relativeTo, + const QPointF lastPivotAbsPos) { + auto settings = getStrokeSettings(); + auto strokeWidth = settings->getCurrentStrokeWidth(); + + auto boundingBox2 = getAbsBoundingRect(); + auto toAbsBoundingRect = getTotalTransform().mapRect(to); + QPointF currentPivot = mTransformAnimator->getPivot(); + QPointF currentPivotAbsPos = getPivotAbsPos(); + + QPointF lastSelectedPivotAbsPos = lastPivotAbsPos; + + QPointF center = getRelCenterPosition(); + + // Obtener el último objeto seleccionado + // const BoundingBox* lastSelected = mSelectedBoxes.last(); + // QPointF lastPivot = lastSelected->getPivotAbsPos(); + + if (relativeTo == AlignRelativeTo::scene) { + if (align & Qt::AlignVCenter) { + center.setX(currentPivot.x()); + center.setY(currentPivot.y() - currentPivotAbsPos.y() + to.bottomRight().y()/2); + } else if (align & Qt::AlignHCenter) { + center.setX(currentPivot.x() - currentPivotAbsPos.x() + to.bottomRight().x()/2); + center.setY(currentPivot.y()); + } else if (align & Qt::AlignLeft) { + center.setX(currentPivot.x() - currentPivotAbsPos.x()); + center.setY(currentPivot.y()); + } else if (align & Qt::AlignRight) { + center.setX(currentPivot.x() + (to.topRight().x() - currentPivotAbsPos.x())); + center.setY(currentPivot.y()); + } else if (align & Qt::AlignTop) { + center.setX(currentPivot.x()); + center.setY(currentPivot.y() - currentPivotAbsPos.y()); + } else if (align & Qt::AlignBottom) { + center.setX(currentPivot.x()); + center.setY(currentPivot.y() + (to.bottomRight().y() - currentPivotAbsPos.y())); + } + } else if (relativeTo == AlignRelativeTo::lastSelected) { + if (align & Qt::AlignVCenter) { + center.setX(currentPivot.x()); + center.setY(currentPivot.y() - currentPivotAbsPos.y() + to.center().y()); + } else if (align & Qt::AlignHCenter) { + center.setX(currentPivot.x() - currentPivotAbsPos.x() + to.center().x()); + center.setY(currentPivot.y()); + } else if (align & Qt::AlignLeft) { // OK + center.setX(currentPivot.x() - currentPivotAbsPos.x() + to.topLeft().x()); + center.setY(currentPivot.y()); + } else if (align & Qt::AlignRight) { // OK + center.setX(currentPivot.x() + (to.topRight().x() - currentPivotAbsPos.x())); + center.setY(currentPivot.y()); + } else if (align & Qt::AlignTop) { // OK + center.setX(currentPivot.x()); + center.setY(currentPivot.y() - currentPivotAbsPos.y() + to.topLeft().y()); + } else if (align & Qt::AlignBottom) { // OK + center.setX(currentPivot.x()); + center.setY(currentPivot.y() + (to.bottomRight().y() - currentPivotAbsPos.y())); + } + } else if (relativeTo == AlignRelativeTo::lastSelectedPivot) { + if (align & Qt::AlignVCenter) { + center.setX(currentPivot.x()); + center.setY(currentPivot.y() - currentPivotAbsPos.y() + lastSelectedPivotAbsPos.y()); + } else if (align & Qt::AlignHCenter) { + center.setX(currentPivot.x() - currentPivotAbsPos.x() + lastSelectedPivotAbsPos.x()); + center.setY(currentPivot.y()); + } else { + center.setX(currentPivot.x()); + center.setY(currentPivot.y()); + } + } else if (relativeTo == AlignRelativeTo::boundingBox) { + if (align & Qt::AlignVCenter) { + center.setX(currentPivot.x()); + } else if (align & Qt::AlignHCenter) { + center.setY(currentPivot.y()); + } else if (align & Qt::AlignLeft) { + center.setX(mRelRect.topLeft().x()); + center.setY(currentPivot.y()); + } else if (align & Qt::AlignRight) { + center.setX(mRelRect.topRight().x()); + center.setY(currentPivot.y()); + } else if (align & Qt::AlignTop) { + center.setX(currentPivot.x()); + center.setY(mRelRect.topLeft().y()); + } else if (align & Qt::AlignBottom) { + center.setX(currentPivot.x()); + center.setY(mRelRect.bottomLeft().y()); + } + } + mTransformAnimator->setPivotFixedTransform(center); requestGlobalPivotUpdateIfSelected(); } diff --git a/src/core/Boxes/boundingbox.h b/src/core/Boxes/boundingbox.h index d145e2500..79c5509a1 100644 --- a/src/core/Boxes/boundingbox.h +++ b/src/core/Boxes/boundingbox.h @@ -40,6 +40,8 @@ class Canvas; +enum class AlignRelativeTo; + class QrealAction; class MovablePoint; @@ -298,7 +300,10 @@ class CORE_EXPORT BoundingBox : public eBoxOrSound { void alignGeometry(const Qt::Alignment align, const QRectF& to); void alignPivot(const Qt::Alignment align, const QRectF& to); - void alignPivot2(const Qt::Alignment align, const QRectF& to); + void alignPivot2(const Qt::Alignment align, + const QRectF& to, + const AlignRelativeTo relativeTo, + const QPointF lastPivotAbsPos); QMatrix getTotalTransform() const; @@ -457,6 +462,9 @@ class CORE_EXPORT BoundingBox : public eBoxOrSound { uint mStateId = 0; + int mWidth; + int mHeight; + int mNReasonsNotToApplyUglyTransform = 0; protected: bool getUpdatePlanned() const diff --git a/src/core/canvas.h b/src/core/canvas.h index 1412b9d2f..bb39aaedc 100644 --- a/src/core/canvas.h +++ b/src/core/canvas.h @@ -73,7 +73,7 @@ enum class AlignPivot { }; enum class AlignRelativeTo { - scene, lastSelected, itself + scene, lastSelected, lastSelectedPivot, boundingBox }; class CORE_EXPORT Canvas : public CanvasBase diff --git a/src/core/canvasselectedboxesactions.cpp b/src/core/canvasselectedboxesactions.cpp index 619f83189..b2c694edb 100644 --- a/src/core/canvasselectedboxesactions.cpp +++ b/src/core/canvasselectedboxesactions.cpp @@ -864,13 +864,13 @@ void Canvas::alignSelectedBoxes(const Qt::Alignment align, skip = mLastSelectedBox; geometry = mLastSelectedBox->getAbsBoundingRect(); break; - case AlignRelativeTo::itself: - // Usar el rectángulo del propio objeto como referencia - if (pivot == AlignPivot::pivot2) { - geometry = QRectF(0., 0., mWidth, mHeight); - } else { - geometry = QRectF(0., 0., mWidth, mHeight); - } + case AlignRelativeTo::lastSelectedPivot: + if(!mLastSelectedBox) return; + skip = mLastSelectedBox; + geometry = QRectF(mLastSelectedBox->getPivotAbsPos(),mLastSelectedBox->getPivotAbsPos()); + break; + case AlignRelativeTo::boundingBox: + geometry = QRectF(0., 0., mWidth, mHeight); // TODO: not using it? break; } @@ -885,7 +885,7 @@ void Canvas::alignSelectedBoxes(const Qt::Alignment align, box->alignGeometry(align, geometry); break; case AlignPivot::pivot2: - box->alignPivot2(align, geometry); + box->alignPivot2(align, geometry, relativeTo, mLastSelectedBox->getPivotAbsPos()); break; } } diff --git a/src/ui/widgets/alignwidget.cpp b/src/ui/widgets/alignwidget.cpp index d7c46ae08..826970a17 100644 --- a/src/ui/widgets/alignwidget.cpp +++ b/src/ui/widgets/alignwidget.cpp @@ -42,6 +42,21 @@ AlignWidget::AlignWidget(QWidget* const parent) mainLayout->setContentsMargins(5, 5, 5, 5); setLayout(mainLayout); + // Crear un layout para las etiquetas encima de los combos + const auto labelsLay = new QHBoxLayout; + mainLayout->insertLayout(0, labelsLay); // Insertar en la posición 0, encima de combosLay + + // Crear las etiquetas + const auto labelAlignPivot = new QLabel(tr("Align:"), this); + labelAlignPivot->setAlignment(Qt::AlignLeft); // Alineación izquierda + labelsLay->addWidget(labelAlignPivot, 1); // Ocupa mitad del espacio + + const auto labelRelativeTo = new QLabel(tr("Relative to:"), this); + labelRelativeTo->setAlignment(Qt::AlignLeft); // Alineación izquierda + labelsLay->addWidget(labelRelativeTo, 1); // Ocupa mitad del espacio + + labelsLay->addStretch(); // Añadir un estiramiento opcional para asegurar el alineamiento + const auto combosLay = new QHBoxLayout; mainLayout->addLayout(combosLay); @@ -50,9 +65,9 @@ AlignWidget::AlignWidget(QWidget* const parent) mAlignPivot->setMinimumWidth(20); mAlignPivot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); mAlignPivot->setFocusPolicy(Qt::NoFocus); - mAlignPivot->addItem(tr("Align Geometry")); - mAlignPivot->addItem(tr("Align Geometry (Pivot)")); - mAlignPivot->addItem(tr("Align Pivot")); + mAlignPivot->addItem(tr("Geometry")); + mAlignPivot->addItem(tr("Geometry (Pivot)")); + mAlignPivot->addItem(tr("Pivot")); combosLay->addWidget(mAlignPivot); //combosLay->addWidget(new QLabel(tr("Relative to"))); @@ -60,11 +75,62 @@ AlignWidget::AlignWidget(QWidget* const parent) mRelativeTo->setMinimumWidth(20); mRelativeTo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); mRelativeTo->setFocusPolicy(Qt::NoFocus); - mRelativeTo->addItem(tr("Relative to Scene")); - mRelativeTo->addItem(tr("Relative to Last Selected")); - mRelativeTo->addItem(tr("Itself")); + mRelativeTo->addItem(tr("Scene")); + mRelativeTo->addItem(tr("Last Selected")); combosLay->addWidget(mRelativeTo); + // Conectar la señal de cambio de índice + connect(mAlignPivot, QOverload::of(&QComboBox::currentIndexChanged), this, [this](int index) { + static bool isItem2Removed = true; + + if (index == 2) { // Si el índice seleccionado en mAlignPivot es 2 + if (isItem2Removed) { + // Volvemos a insertar el índice 2 si no está presente + mRelativeTo->insertItem(2, tr("Last Selected Pivot")); + mRelativeTo->insertItem(3, tr("Bounding Box")); + isItem2Removed = false; + } + mRelativeTo->setCurrentIndex(3); // Seleccionar el índice 2 en mRelativeTo + } else { + if (!isItem2Removed) { + // Eliminamos el índice 2 si está presente + mRelativeTo->removeItem(2); + mRelativeTo->removeItem(2); + isItem2Removed = true; + mRelativeTo->setCurrentIndex(0); // Seleccionar el índice 0 en mRelativeTo + } + } + }); + + + // // Crear mRelativeToPivot + // mRelativeToPivot = new QComboBox(this); + // mRelativeToPivot->setMinimumWidth(20); + // mRelativeToPivot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + // mRelativeToPivot->setFocusPolicy(Qt::NoFocus); + // // Añadir opciones a mRelativeToPivot + // mRelativeToPivot->addItem(tr("Bounding Box")); // Index 0 + // mRelativeToPivot->addItem(tr("Scene")); // Index 1 + // combosLay->addWidget(mRelativeToPivot); + + // // Inicialmente, ocultamos mRelativeToPivot + // mRelativeToPivot->hide(); + + // // Conectar el cambio de mAlignPivot + // connect(mAlignPivot, QOverload::of(&QComboBox::currentIndexChanged), this, [this](int index) { + // if (index == 2) { + // // Mostrar mRelativeToPivot y ocultar mRelativeTo + // mRelativeTo->hide(); + // mRelativeToPivot->show(); + // mRelativeToPivot->setCurrentIndex(0); // Seleccionar siempre el índice 0 + // } else { + // // Mostrar mRelativeTo y ocultar mRelativeToPivot + // mRelativeToPivot->hide(); + // mRelativeTo->show(); + // mRelativeTo->setCurrentIndex(0); // Seleccionar siempre el índice 0 + // } + // }); + const auto buttonsLay = new QHBoxLayout; mainLayout->addLayout(buttonsLay); mainLayout->addStretch(); @@ -123,6 +189,29 @@ AlignWidget::AlignWidget(QWidget* const parent) }); buttonsLay->addWidget(bottomButton); + connect(mRelativeTo, QOverload::of(&QComboBox::currentIndexChanged), this, [this, leftButton, rightButton, topButton, bottomButton]() { + if (mRelativeTo->currentIndex() == 2) { + leftButton->setEnabled(false); + leftButton->setIcon(QIcon()); + rightButton->setEnabled(false); + rightButton->setIcon(QIcon()); + topButton->setEnabled(false); + topButton->setIcon(QIcon()); + bottomButton->setEnabled(false); + bottomButton->setIcon(QIcon()); + } else { + leftButton->setEnabled(true); + leftButton->setIcon(QIcon::fromTheme("pivot-align-left")); + rightButton->setEnabled(true); + rightButton->setIcon(QIcon::fromTheme("pivot-align-right")); + topButton->setEnabled(true); + topButton->setIcon(QIcon::fromTheme("pivot-align-top")); + bottomButton->setEnabled(true); + bottomButton->setIcon(QIcon::fromTheme("pivot-align-bottom")); + } + }); + + eSizesUI::widget.add(leftButton, [leftButton, hCenterButton, rightButton, diff --git a/src/ui/widgets/alignwidget.h b/src/ui/widgets/alignwidget.h index 2b74199ad..a274fa9ba 100644 --- a/src/ui/widgets/alignwidget.h +++ b/src/ui/widgets/alignwidget.h @@ -50,6 +50,7 @@ class UI_EXPORT AlignWidget : public QWidget QComboBox *mAlignPivot; QComboBox *mRelativeTo; + QComboBox *mRelativeToPivot; }; #endif // ALIGNWIDGET_H From 5ba3a564d2b2c7eb6db7d4d753527db399b16087 Mon Sep 17 00:00:00 2001 From: Pablo Gil Date: Tue, 10 Dec 2024 16:47:36 +0100 Subject: [PATCH 3/5] rename function --- src/app/GUI/extraactions.cpp | 24 ++++++++++++------------ src/core/Boxes/boundingbox.h | 2 +- src/core/canvas.h | 2 +- src/core/canvasselectedboxesactions.cpp | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/app/GUI/extraactions.cpp b/src/app/GUI/extraactions.cpp index bcd51f461..eb7fc15dc 100644 --- a/src/app/GUI/extraactions.cpp +++ b/src/app/GUI/extraactions.cpp @@ -485,7 +485,7 @@ void MainWindow::setupMenuExtras() alignString = alignVCenter; pivotString = alignPivot; relString = alignLast; - pivot = AlignPivot::pivot2; + pivot = AlignPivot::pivotItself; rel = AlignRelativeTo::boundingBox; iconString = alignVCenterIcon; alignBoth = false; @@ -495,7 +495,7 @@ void MainWindow::setupMenuExtras() alignString = alignVCenter; pivotString = alignPivot; relString = alignLast; - pivot = AlignPivot::pivot2; + pivot = AlignPivot::pivotItself; rel = AlignRelativeTo::boundingBox; iconString = alignVCenterIcon; alignBoth = false; @@ -505,7 +505,7 @@ void MainWindow::setupMenuExtras() alignString = alignVCenter; pivotString = alignPivot; relString = alignLast; - pivot = AlignPivot::pivot2; + pivot = AlignPivot::pivotItself; rel = AlignRelativeTo::boundingBox; iconString = alignVCenterIcon; alignBoth = false; @@ -515,7 +515,7 @@ void MainWindow::setupMenuExtras() alignString = alignVCenter; pivotString = alignPivot; relString = alignLast; - pivot = AlignPivot::pivot2; + pivot = AlignPivot::pivotItself; rel = AlignRelativeTo::boundingBox; iconString = alignVCenterIcon; alignBoth = false; @@ -525,7 +525,7 @@ void MainWindow::setupMenuExtras() alignString = alignVCenter; pivotString = alignPivot; relString = alignLast; - pivot = AlignPivot::pivot2; + pivot = AlignPivot::pivotItself; rel = AlignRelativeTo::boundingBox; iconString = alignVCenterIcon; alignBoth = false; @@ -535,7 +535,7 @@ void MainWindow::setupMenuExtras() alignString = alignVCenter; pivotString = alignPivot; relString = alignLast; - pivot = AlignPivot::pivot2; + pivot = AlignPivot::pivotItself; rel = AlignRelativeTo::boundingBox; iconString = alignVCenterIcon; alignBoth = false; @@ -545,7 +545,7 @@ void MainWindow::setupMenuExtras() alignString = alignVCenter; pivotString = alignPivot; relString = alignLast; - pivot = AlignPivot::pivot2; + pivot = AlignPivot::pivotItself; rel = AlignRelativeTo::scene; iconString = alignVCenterIcon; alignBoth = false; @@ -555,7 +555,7 @@ void MainWindow::setupMenuExtras() alignString = alignVCenter; pivotString = alignPivot; relString = alignLast; - pivot = AlignPivot::pivot2; + pivot = AlignPivot::pivotItself; rel = AlignRelativeTo::scene; iconString = alignVCenterIcon; alignBoth = false; @@ -565,7 +565,7 @@ void MainWindow::setupMenuExtras() alignString = alignVCenter; pivotString = alignPivot; relString = alignLast; - pivot = AlignPivot::pivot2; + pivot = AlignPivot::pivotItself; rel = AlignRelativeTo::scene; iconString = alignVCenterIcon; alignBoth = false; @@ -575,7 +575,7 @@ void MainWindow::setupMenuExtras() alignString = alignVCenter; pivotString = alignPivot; relString = alignLast; - pivot = AlignPivot::pivot2; + pivot = AlignPivot::pivotItself; rel = AlignRelativeTo::scene; iconString = alignVCenterIcon; alignBoth = false; @@ -585,7 +585,7 @@ void MainWindow::setupMenuExtras() alignString = alignVCenter; pivotString = alignPivot; relString = alignLast; - pivot = AlignPivot::pivot2; + pivot = AlignPivot::pivotItself; rel = AlignRelativeTo::scene; iconString = alignVCenterIcon; alignBoth = false; @@ -595,7 +595,7 @@ void MainWindow::setupMenuExtras() alignString = alignVCenter; pivotString = alignPivot; relString = alignLast; - pivot = AlignPivot::pivot2; + pivot = AlignPivot::pivotItself; rel = AlignRelativeTo::scene; iconString = alignVCenterIcon; alignBoth = false; diff --git a/src/core/Boxes/boundingbox.h b/src/core/Boxes/boundingbox.h index 79c5509a1..f4e436f9e 100644 --- a/src/core/Boxes/boundingbox.h +++ b/src/core/Boxes/boundingbox.h @@ -300,7 +300,7 @@ class CORE_EXPORT BoundingBox : public eBoxOrSound { void alignGeometry(const Qt::Alignment align, const QRectF& to); void alignPivot(const Qt::Alignment align, const QRectF& to); - void alignPivot2(const Qt::Alignment align, + void alignPivotItself(const Qt::Alignment align, const QRectF& to, const AlignRelativeTo relativeTo, const QPointF lastPivotAbsPos); diff --git a/src/core/canvas.h b/src/core/canvas.h index bb39aaedc..4724686b5 100644 --- a/src/core/canvas.h +++ b/src/core/canvas.h @@ -69,7 +69,7 @@ class eKeyEvent; enum class CtrlsMode : short; enum class AlignPivot { - geometry, pivot, pivot2 + geometry, pivot, pivotItself }; enum class AlignRelativeTo { diff --git a/src/core/canvasselectedboxesactions.cpp b/src/core/canvasselectedboxesactions.cpp index b2c694edb..e8229e468 100644 --- a/src/core/canvasselectedboxesactions.cpp +++ b/src/core/canvasselectedboxesactions.cpp @@ -884,8 +884,8 @@ void Canvas::alignSelectedBoxes(const Qt::Alignment align, case AlignPivot::geometry: box->alignGeometry(align, geometry); break; - case AlignPivot::pivot2: - box->alignPivot2(align, geometry, relativeTo, mLastSelectedBox->getPivotAbsPos()); + case AlignPivot::pivotItself: + box->alignPivotItself(align, geometry, relativeTo, mLastSelectedBox->getPivotAbsPos()); break; } } From b008231119b3dd58ec3a3731d29938827db1edca Mon Sep 17 00:00:00 2001 From: Pablo Gil Date: Tue, 10 Dec 2024 16:49:03 +0100 Subject: [PATCH 4/5] add missing rename function --- src/core/Boxes/boundingbox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Boxes/boundingbox.cpp b/src/core/Boxes/boundingbox.cpp index a8ef2c9ed..1c8651b15 100644 --- a/src/core/Boxes/boundingbox.cpp +++ b/src/core/Boxes/boundingbox.cpp @@ -865,7 +865,7 @@ void BoundingBox::alignPivot(const Qt::Alignment align, const QRectF& to) { alignGeometry(QRectF(pivot, pivot), align, to); } -void BoundingBox::alignPivot2(const Qt::Alignment align, +void BoundingBox::alignPivotItself(const Qt::Alignment align, const QRectF& to, const AlignRelativeTo relativeTo, const QPointF lastPivotAbsPos) { From 5eef5ec53a25e9d7c14167f7fe68c3fed1c4e441 Mon Sep 17 00:00:00 2001 From: Pablo Gil Date: Tue, 10 Dec 2024 16:49:58 +0100 Subject: [PATCH 5/5] cleaning up and delete comments --- src/core/Boxes/boundingbox.cpp | 15 +++++---- src/ui/widgets/alignwidget.cpp | 56 ++++++---------------------------- 2 files changed, 17 insertions(+), 54 deletions(-) diff --git a/src/core/Boxes/boundingbox.cpp b/src/core/Boxes/boundingbox.cpp index 1c8651b15..b53e9e4e2 100644 --- a/src/core/Boxes/boundingbox.cpp +++ b/src/core/Boxes/boundingbox.cpp @@ -881,10 +881,6 @@ void BoundingBox::alignPivotItself(const Qt::Alignment align, QPointF center = getRelCenterPosition(); - // Obtener el último objeto seleccionado - // const BoundingBox* lastSelected = mSelectedBoxes.last(); - // QPointF lastPivot = lastSelected->getPivotAbsPos(); - if (relativeTo == AlignRelativeTo::scene) { if (align & Qt::AlignVCenter) { center.setX(currentPivot.x()); @@ -912,16 +908,16 @@ void BoundingBox::alignPivotItself(const Qt::Alignment align, } else if (align & Qt::AlignHCenter) { center.setX(currentPivot.x() - currentPivotAbsPos.x() + to.center().x()); center.setY(currentPivot.y()); - } else if (align & Qt::AlignLeft) { // OK + } else if (align & Qt::AlignLeft) { center.setX(currentPivot.x() - currentPivotAbsPos.x() + to.topLeft().x()); center.setY(currentPivot.y()); - } else if (align & Qt::AlignRight) { // OK + } else if (align & Qt::AlignRight) { center.setX(currentPivot.x() + (to.topRight().x() - currentPivotAbsPos.x())); center.setY(currentPivot.y()); - } else if (align & Qt::AlignTop) { // OK + } else if (align & Qt::AlignTop) { center.setX(currentPivot.x()); center.setY(currentPivot.y() - currentPivotAbsPos.y() + to.topLeft().y()); - } else if (align & Qt::AlignBottom) { // OK + } else if (align & Qt::AlignBottom) { center.setX(currentPivot.x()); center.setY(currentPivot.y() + (to.bottomRight().y() - currentPivotAbsPos.y())); } @@ -956,8 +952,11 @@ void BoundingBox::alignPivotItself(const Qt::Alignment align, } } + startPosTransform(); + // TODO: get undo/redo to save last previous state mTransformAnimator->setPivotFixedTransform(center); requestGlobalPivotUpdateIfSelected(); + finishTransform(); } void BoundingBox::moveByAbs(const QPointF &trans) { diff --git a/src/ui/widgets/alignwidget.cpp b/src/ui/widgets/alignwidget.cpp index 826970a17..5a8ebcad0 100644 --- a/src/ui/widgets/alignwidget.cpp +++ b/src/ui/widgets/alignwidget.cpp @@ -42,35 +42,31 @@ AlignWidget::AlignWidget(QWidget* const parent) mainLayout->setContentsMargins(5, 5, 5, 5); setLayout(mainLayout); - // Crear un layout para las etiquetas encima de los combos const auto labelsLay = new QHBoxLayout; - mainLayout->insertLayout(0, labelsLay); // Insertar en la posición 0, encima de combosLay + mainLayout->insertLayout(0, labelsLay); - // Crear las etiquetas const auto labelAlignPivot = new QLabel(tr("Align:"), this); - labelAlignPivot->setAlignment(Qt::AlignLeft); // Alineación izquierda - labelsLay->addWidget(labelAlignPivot, 1); // Ocupa mitad del espacio + labelAlignPivot->setAlignment(Qt::AlignLeft); + labelsLay->addWidget(labelAlignPivot, 1); const auto labelRelativeTo = new QLabel(tr("Relative to:"), this); - labelRelativeTo->setAlignment(Qt::AlignLeft); // Alineación izquierda - labelsLay->addWidget(labelRelativeTo, 1); // Ocupa mitad del espacio + labelRelativeTo->setAlignment(Qt::AlignLeft); + labelsLay->addWidget(labelRelativeTo, 1); - labelsLay->addStretch(); // Añadir un estiramiento opcional para asegurar el alineamiento + labelsLay->addStretch(); const auto combosLay = new QHBoxLayout; mainLayout->addLayout(combosLay); - //combosLay->addWidget(new QLabel(tr("Align"))); mAlignPivot = new QComboBox(this); mAlignPivot->setMinimumWidth(20); mAlignPivot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); mAlignPivot->setFocusPolicy(Qt::NoFocus); mAlignPivot->addItem(tr("Geometry")); - mAlignPivot->addItem(tr("Geometry (Pivot)")); + mAlignPivot->addItem(tr("Geometry by Pivot")); mAlignPivot->addItem(tr("Pivot")); combosLay->addWidget(mAlignPivot); - //combosLay->addWidget(new QLabel(tr("Relative to"))); mRelativeTo = new QComboBox(this); mRelativeTo->setMinimumWidth(20); mRelativeTo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -79,58 +75,26 @@ AlignWidget::AlignWidget(QWidget* const parent) mRelativeTo->addItem(tr("Last Selected")); combosLay->addWidget(mRelativeTo); - // Conectar la señal de cambio de índice connect(mAlignPivot, QOverload::of(&QComboBox::currentIndexChanged), this, [this](int index) { static bool isItem2Removed = true; - if (index == 2) { // Si el índice seleccionado en mAlignPivot es 2 + if (index == 2) { if (isItem2Removed) { - // Volvemos a insertar el índice 2 si no está presente mRelativeTo->insertItem(2, tr("Last Selected Pivot")); mRelativeTo->insertItem(3, tr("Bounding Box")); isItem2Removed = false; } - mRelativeTo->setCurrentIndex(3); // Seleccionar el índice 2 en mRelativeTo + mRelativeTo->setCurrentIndex(3); } else { if (!isItem2Removed) { - // Eliminamos el índice 2 si está presente mRelativeTo->removeItem(2); mRelativeTo->removeItem(2); isItem2Removed = true; - mRelativeTo->setCurrentIndex(0); // Seleccionar el índice 0 en mRelativeTo + mRelativeTo->setCurrentIndex(0); } } }); - - // // Crear mRelativeToPivot - // mRelativeToPivot = new QComboBox(this); - // mRelativeToPivot->setMinimumWidth(20); - // mRelativeToPivot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - // mRelativeToPivot->setFocusPolicy(Qt::NoFocus); - // // Añadir opciones a mRelativeToPivot - // mRelativeToPivot->addItem(tr("Bounding Box")); // Index 0 - // mRelativeToPivot->addItem(tr("Scene")); // Index 1 - // combosLay->addWidget(mRelativeToPivot); - - // // Inicialmente, ocultamos mRelativeToPivot - // mRelativeToPivot->hide(); - - // // Conectar el cambio de mAlignPivot - // connect(mAlignPivot, QOverload::of(&QComboBox::currentIndexChanged), this, [this](int index) { - // if (index == 2) { - // // Mostrar mRelativeToPivot y ocultar mRelativeTo - // mRelativeTo->hide(); - // mRelativeToPivot->show(); - // mRelativeToPivot->setCurrentIndex(0); // Seleccionar siempre el índice 0 - // } else { - // // Mostrar mRelativeTo y ocultar mRelativeToPivot - // mRelativeToPivot->hide(); - // mRelativeTo->show(); - // mRelativeTo->setCurrentIndex(0); // Seleccionar siempre el índice 0 - // } - // }); - const auto buttonsLay = new QHBoxLayout; mainLayout->addLayout(buttonsLay); mainLayout->addStretch();