From 239065af7d16e1816c117e7a697f9b11e8abef12 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Mon, 28 Sep 2026 06:16:17 +1300 Subject: [PATCH] Open the text orientation dialog at the texts' current angle The "Orienter les textes" dialog always opened at 0, so turning a text at 90 degrees by a little meant typing the angle in again. It now opens at the angle every selected text and text group shares, and at 0 as before when they differ. The shortcut bar showed only a command's short name as its tooltip, which for this one ("Choose texts orientation") does not say what it does. It now adds the command's status tip on a second line: "Rotate selected texts to a specific angle". Checked in the GUI on a folio holding one text at 90 degrees: master opens the dialog at 0.00, this at 90.00. Fixes #1082 Co-Authored-By: Claude Opus 5.5 --- sources/diagramcontexttoolbar.cpp | 7 ++++- sources/qetdiagrameditor.cpp | 2 +- sources/undocommand/rotatetextscommand.cpp | 36 ++++++++++++++++++++-- sources/undocommand/rotatetextscommand.h | 6 ++-- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/sources/diagramcontexttoolbar.cpp b/sources/diagramcontexttoolbar.cpp index c8e8ab3be..610b2eec7 100644 --- a/sources/diagramcontexttoolbar.cpp +++ b/sources/diagramcontexttoolbar.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include namespace { @@ -92,7 +93,11 @@ void DiagramContextToolbar::showAt(const QPoint &viewport_pos, } else { button->setIcon(action->icon()); } - button->setToolTip(text); + //The status tip says what the command does, which a short + //name such as "Orienter les textes" does not + button->setToolTip(action->statusTip().isEmpty() + ? text + : text % QLatin1Char('\n') % action->statusTip()); button->setEnabled(action->isEnabled()); connect(button, &QToolButton::clicked, action, &QAction::trigger); m_layout->addWidget(button); diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 1845df15f..7407c892e 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -2059,7 +2059,7 @@ void QETDiagramEditor::selectionGroupTriggered(QAction *action) //nothing to rotate. if (RotateTextsCommand::hasSelectedTexts(diagram)) { - qreal rotation = 0; + qreal rotation = RotateTextsCommand::currentRotation(diagram); if (RotateTextsCommand::askRotation(rotation)) diagram->undoStack().push(new RotateTextsCommand(diagram, rotation)); } diff --git a/sources/undocommand/rotatetextscommand.cpp b/sources/undocommand/rotatetextscommand.cpp index 704b7bcd8..9936721f1 100644 --- a/sources/undocommand/rotatetextscommand.cpp +++ b/sources/undocommand/rotatetextscommand.cpp @@ -25,6 +25,8 @@ #include "../qetgraphicsitem/elementtextitemgroup.h" #include "../qtextorientationspinboxwidget.h" +#include + /** @brief RotateTextsCommand::hasSelectedTexts @param diagram @@ -41,6 +43,35 @@ bool RotateTextsCommand::hasSelectedTexts(Diagram *diagram) return (!dc.selectedTexts().isEmpty() || !dc.selectedTextsGroup().isEmpty()); } +/** + @brief RotateTextsCommand::currentRotation + @param diagram + @return the rotation shared by every selected text and text group of + @p diagram, so the dialog can open at the angle they already have. + 0 when nothing is selected or when their angles differ. +*/ +qreal RotateTextsCommand::currentRotation(Diagram *diagram) +{ + if(!diagram) + return 0; + + DiagramContent dc(diagram); + QList angles; + for(DiagramTextItem *dti : dc.selectedTexts()) + angles << dti->rotation(); + for(ElementTextItemGroup *etig : dc.selectedTextsGroup()) + angles << etig->rotation(); + + if(angles.isEmpty()) + return 0; + for(qreal angle : angles) + if(qAbs(angle - angles.first()) > 0.01) + return 0; + + //The dialog's spin box accepts -360 to 360 + return std::fmod(angles.first(), 360); +} + /** @brief RotateTextsCommand::RotateTextsCommand @param diagram : Apply the rotation to the selected texts and group of texts @@ -124,8 +155,8 @@ void RotateTextsCommand::redo() /** @brief RotateTextsCommand::askRotation Ask the user for an orientation. - @param rotation : set to the chosen angle when the dialog is accepted, - left untouched otherwise. + @param rotation : the angle the dialog opens at; set to the chosen + angle when the dialog is accepted, left untouched otherwise. @return true if the user accepted, false if they cancelled. Deliberately static and separate from the command: a QUndoCommand that @@ -145,6 +176,7 @@ bool RotateTextsCommand::askRotation(qreal &rotation) QTextOrientationSpinBoxWidget *ori_widget = QETApp::createTextOrientationSpinBoxWidget(); ori_widget->setParent(&ori_text_dialog); + ori_widget->setOrientation(rotation); ori_widget->spinBox()->selectAll(); QDialogButtonBox buttons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); diff --git a/sources/undocommand/rotatetextscommand.h b/sources/undocommand/rotatetextscommand.h index 0ddf58830..ebe7f3bf6 100644 --- a/sources/undocommand/rotatetextscommand.h +++ b/sources/undocommand/rotatetextscommand.h @@ -40,7 +40,7 @@ class QParallelAnimationGroup; Typical interactive use: @code if (RotateTextsCommand::hasSelectedTexts(diagram)) { - qreal rotation = 0; + qreal rotation = RotateTextsCommand::currentRotation(diagram); if (RotateTextsCommand::askRotation(rotation)) diagram->undoStack().push(new RotateTextsCommand(diagram, rotation)); } @@ -53,7 +53,9 @@ class RotateTextsCommand : public QUndoCommand /// @return true if @p diagram has at least one selected text or text group to rotate. static bool hasSelectedTexts(Diagram *diagram); - /// Open the orientation dialog. @return true and set @p rotation if accepted, false if cancelled. + /// @return the angle the selected texts share, or 0 if they differ. + static qreal currentRotation(Diagram *diagram); + /// Open the orientation dialog at @p rotation. @return true and set @p rotation if accepted, false if cancelled. static bool askRotation(qreal &rotation); void undo() override;