diff --git a/sources/editor/elementscene.cpp b/sources/editor/elementscene.cpp index a9b8d85d2..2d5d035a7 100644 --- a/sources/editor/elementscene.cpp +++ b/sources/editor/elementscene.cpp @@ -23,6 +23,7 @@ #include "../NameList/ui/namelistwidget.h" #include "../QPropertyUndoCommand/qpropertyundocommand.h" #include "../QetGraphicsItemModeler/qetgraphicshandleritem.h" +#include "../QetGraphicsItemModeler/textresizehandles.h" #include "editorcommands.h" #include "elementcontent.h" #include "elementprimitivedecorator.h" @@ -1498,9 +1499,49 @@ void ElementScene::managePrimitivesGroups() m_decorator -> setPos(0, 0); m_decorator -> setItems(selected_items); } + manageTextResizeHandles(selected_items); m_decorator_lock -> unlock(); } +/** + @brief ElementScene::manageTextResizeHandles + Show the corner handles that change the width of a text field when it + is the only selected item. + Called again when the undo stack changes, including from the push of a + resize itself: the handles of the same text are then kept, not deleted + while they are still emitting. + @param selected_items +*/ +void ElementScene::manageTextResizeHandles(const QList &selected_items) +{ + QGraphicsTextItem *text = nullptr; + if (selected_items.size() == 1 && + selected_items.first()->type() == PartDynamicTextField::Type) + { + text = static_cast(selected_items.first()); + } + if (m_text_resize_handles && m_text_resize_handles->parentItem() == text) { + m_text_resize_handles->updateHandlesPos(); + return; + } + + if (m_text_resize_handles) { + m_text_resize_handles->hide(); + m_text_resize_handles->deleteLater(); + m_text_resize_handles.clear(); + } + + if (text) + { + m_text_resize_handles = new TextResizeHandles(text); + connect(m_text_resize_handles, &TextResizeHandles::resizeFinished, this, + [this, text](qreal old_width, qreal new_width, QPointF old_pos, QPointF new_pos) + { + m_undo_stack.push(new TextResizeCommand(text, old_width, new_width, old_pos, new_pos)); + }); + } +} + /** @brief ElementScene::stackAction Push the provided \a command on the undo stack. diff --git a/sources/editor/elementscene.h b/sources/editor/elementscene.h index ee275703f..5d3beb427 100644 --- a/sources/editor/elementscene.h +++ b/sources/editor/elementscene.h @@ -33,6 +33,7 @@ class QETElementEditor; class ESEventInterface; class QKeyEvent; class CustomElementGraphicPart; +class TextResizeHandles; /** @brief The ElementScene class This class is the canvas allowing the visual edition of an electrical element. @@ -90,6 +91,7 @@ class ElementScene : public QGraphicsScene m_y_grid; QPointer m_single_selected_item; + QPointer m_text_resize_handles; bool m_hotspot_visible = true; bool m_background_frame_visible = false; @@ -180,6 +182,7 @@ class ElementScene : public QGraphicsScene void slot_editAuthorInformations(); void slot_editProperties(); void managePrimitivesGroups(); + void manageTextResizeHandles(const QList &selected_items); void stackAction(ElementEditionCommand *); signals: