Merge pull request #1084 from ispyisail/fix/1082-text-rotation-dialog

Fix #1082: text angle dialog opens at 0, unclear shortcut-bar tooltip
This commit is contained in:
Laurent Trinques
2026-09-27 20:10:13 +02:00
committed by GitHub
5 changed files with 55 additions and 10 deletions
@@ -404,10 +404,16 @@ void ElementPickerPopup::setCommands(const QStringList &ids)
button->setIcon(action->icon());
}
const QKeySequence key = action->shortcut();
button->setToolTip(key.isEmpty()
? text
: QStringLiteral("%1 (%2)").arg(
text, key.toString(QKeySequence::NativeText)));
QString tip = key.isEmpty()
? text
: QStringLiteral("%1 (%2)").arg(
text, key.toString(QKeySequence::NativeText));
//The status tip says what the command does, which a short
//name such as "Orienter les textes" does not
if (!action->statusTip().isEmpty()) {
tip += QLatin1Char('\n') + action->statusTip();
}
button->setToolTip(tip);
button->setEnabled(action->isEnabled());
button->setFocusPolicy(Qt::NoFocus);
connect(button, &QToolButton::clicked, this, [this, action]() {
+6 -1
View File
@@ -23,6 +23,7 @@
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QSettings>
#include <QStringBuilder>
#include <QToolButton>
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);
+1 -1
View File
@@ -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));
}
+34 -2
View File
@@ -25,6 +25,8 @@
#include "../qetgraphicsitem/elementtextitemgroup.h"
#include "../qtextorientationspinboxwidget.h"
#include <cmath>
/**
@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<qreal> 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);
+4 -2
View File
@@ -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;