diff --git a/cmake/qet_compilation_vars.cmake b/cmake/qet_compilation_vars.cmake
index 5aa0433ba..9670794e3 100644
--- a/cmake/qet_compilation_vars.cmake
+++ b/cmake/qet_compilation_vars.cmake
@@ -215,6 +215,8 @@ set(QET_SRC_FILES
${QET_DIR}/sources/exportpropertieswidget.h
${QET_DIR}/sources/genericpanel.cpp
${QET_DIR}/sources/genericpanel.h
+ ${QET_DIR}/sources/lastusedstyle.cpp
+ ${QET_DIR}/sources/lastusedstyle.h
${QET_DIR}/sources/machine_info.cpp
${QET_DIR}/sources/machine_info.h
${QET_DIR}/sources/main.cpp
diff --git a/sources/diagramevent/diagrameventaddshape.cpp b/sources/diagramevent/diagrameventaddshape.cpp
index 8a5f0967c..0ab945266 100644
--- a/sources/diagramevent/diagrameventaddshape.cpp
+++ b/sources/diagramevent/diagrameventaddshape.cpp
@@ -18,6 +18,7 @@
#include "diagrameventaddshape.h"
#include "../diagram.h"
+#include "../lastusedstyle.h"
#include "../undocommand/addgraphicsobjectcommand.h"
/**
@@ -77,6 +78,14 @@ void DiagramEventAddShape::mousePressEvent(QGraphicsSceneMouseEvent *event)
if (!m_shape_item)
{
m_shape_item = new QetShapeItem(pos, pos, m_shape_type);
+ //Start from whatever pen/brush was last applied this
+ //session, rather than always the hardcoded default.
+ if (LastUsedStyle::hasShapePen()) {
+ m_shape_item->setPen(LastUsedStyle::shapePen());
+ }
+ if (LastUsedStyle::hasShapeBrush()) {
+ m_shape_item->setBrush(LastUsedStyle::shapeBrush());
+ }
m_diagram->addItem (m_shape_item);
event->setAccepted(true);
return;
diff --git a/sources/lastusedstyle.cpp b/sources/lastusedstyle.cpp
new file mode 100644
index 000000000..0dad351a8
--- /dev/null
+++ b/sources/lastusedstyle.cpp
@@ -0,0 +1,106 @@
+/*
+ Copyright 2006-2026 The QElectroTech Team
+ This file is part of QElectroTech.
+
+ QElectroTech is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ QElectroTech is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with QElectroTech. If not, see .
+*/
+#include "lastusedstyle.h"
+
+QPen LastUsedStyle::m_shape_pen;
+bool LastUsedStyle::m_has_shape_pen = false;
+QBrush LastUsedStyle::m_shape_brush;
+bool LastUsedStyle::m_has_shape_brush = false;
+QFont LastUsedStyle::m_text_font;
+bool LastUsedStyle::m_has_text_font = false;
+
+/**
+ @return true if a shape pen was set this session
+*/
+bool LastUsedStyle::hasShapePen()
+{
+ return m_has_shape_pen;
+}
+
+/**
+ @return the last pen applied to a shape this session
+*/
+QPen LastUsedStyle::shapePen()
+{
+ return m_shape_pen;
+}
+
+/**
+ @brief LastUsedStyle::setShapePen
+ Record @a pen as the last-used shape pen for this session
+ @param pen
+*/
+void LastUsedStyle::setShapePen(const QPen &pen)
+{
+ m_shape_pen = pen;
+ m_has_shape_pen = true;
+}
+
+/**
+ @return true if a shape brush was set this session
+*/
+bool LastUsedStyle::hasShapeBrush()
+{
+ return m_has_shape_brush;
+}
+
+/**
+ @return the last brush applied to a shape this session
+*/
+QBrush LastUsedStyle::shapeBrush()
+{
+ return m_shape_brush;
+}
+
+/**
+ @brief LastUsedStyle::setShapeBrush
+ Record @a brush as the last-used shape brush for this session
+ @param brush
+*/
+void LastUsedStyle::setShapeBrush(const QBrush &brush)
+{
+ m_shape_brush = brush;
+ m_has_shape_brush = true;
+}
+
+/**
+ @return true if a text font was set this session
+*/
+bool LastUsedStyle::hasTextFont()
+{
+ return m_has_text_font;
+}
+
+/**
+ @return the last font applied to a free text item this session
+*/
+QFont LastUsedStyle::textFont()
+{
+ return m_text_font;
+}
+
+/**
+ @brief LastUsedStyle::setTextFont
+ Record @a font as the last-used free text font for this session
+ @param font
+*/
+void LastUsedStyle::setTextFont(const QFont &font)
+{
+ m_text_font = font;
+ m_has_text_font = true;
+}
diff --git a/sources/lastusedstyle.h b/sources/lastusedstyle.h
new file mode 100644
index 000000000..17c1f50b3
--- /dev/null
+++ b/sources/lastusedstyle.h
@@ -0,0 +1,63 @@
+/*
+ Copyright 2006-2026 The QElectroTech Team
+ This file is part of QElectroTech.
+
+ QElectroTech is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ QElectroTech is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with QElectroTech. If not, see .
+*/
+#ifndef LAST_USED_STYLE_H
+#define LAST_USED_STYLE_H
+
+#include
+#include
+#include
+
+/**
+ @brief The LastUsedStyle class
+ Session-scoped "last used" style for new shapes and free text created
+ on the diagram canvas: whatever pen/brush/font was last applied through
+ the properties editors becomes the starting point for the next new
+ item of that type, the way most drawing tools behave.
+
+ Deliberately in-memory only, not QSettings-backed: this is a live
+ "what did I just use" value for the current editing session, not an
+ app-wide default (that's already covered by the Preferences dialog's
+ font setting, read as the fallback when nothing has been set yet).
+*/
+class LastUsedStyle
+{
+ public:
+ static bool hasShapePen();
+ static QPen shapePen();
+ static void setShapePen(const QPen &pen);
+
+ static bool hasShapeBrush();
+ static QBrush shapeBrush();
+ static void setShapeBrush(const QBrush &brush);
+
+ static bool hasTextFont();
+ static QFont textFont();
+ static void setTextFont(const QFont &font);
+
+ private:
+ LastUsedStyle() = delete;
+
+ static QPen m_shape_pen;
+ static bool m_has_shape_pen;
+ static QBrush m_shape_brush;
+ static bool m_has_shape_brush;
+ static QFont m_text_font;
+ static bool m_has_text_font;
+};
+
+#endif // LAST_USED_STYLE_H
diff --git a/sources/qetgraphicsitem/independenttextitem.cpp b/sources/qetgraphicsitem/independenttextitem.cpp
index ba92533b8..36c5eb5d8 100644
--- a/sources/qetgraphicsitem/independenttextitem.cpp
+++ b/sources/qetgraphicsitem/independenttextitem.cpp
@@ -19,6 +19,7 @@
#include "../diagram.h"
#include "../diagramcommands.h"
+#include "../lastusedstyle.h"
#include "../qet.h"
#include "../qetapp.h"
#include "../utils/qetutils.h"
@@ -33,7 +34,10 @@
IndependentTextItem::IndependentTextItem() :
DiagramTextItem(nullptr)
{
- setFont(QETApp::indiTextsItemFont());
+ //Start from the font last applied to a text item this session,
+ //falling back to the app-wide Preferences default otherwise.
+ setFont(LastUsedStyle::hasTextFont() ? LastUsedStyle::textFont()
+ : QETApp::indiTextsItemFont());
QSettings settings;
setRotation(settings.value("diagrameditor/independent_text_rotation", 0).toInt());
}
diff --git a/sources/ui/inditextpropertieswidget.cpp b/sources/ui/inditextpropertieswidget.cpp
index 45884a1cb..0ebe9ba15 100644
--- a/sources/ui/inditextpropertieswidget.cpp
+++ b/sources/ui/inditextpropertieswidget.cpp
@@ -20,6 +20,7 @@
#include "../QPropertyUndoCommand/qpropertyundocommand.h"
#include "../diagram.h"
#include "../diagramcommands.h"
+#include "../lastusedstyle.h"
#include "../qetgraphicsitem/independenttextitem.h"
#include "../ui_inditextpropertieswidget.h"
@@ -455,6 +456,7 @@ void IndiTextPropertiesWidget::on_m_font_pb_clicked()
m_font_is_selected = true;
ui->m_font_pb->setText(font.family());
ui->m_size_sb->setValue(font.pointSize());
+ LastUsedStyle::setTextFont(m_selected_font);
apply();
} else {
ui->m_font_pb->setText(tr("Police"));
diff --git a/sources/ui/shapegraphicsitempropertieswidget.cpp b/sources/ui/shapegraphicsitempropertieswidget.cpp
index 242f1dd2f..5d4580321 100644
--- a/sources/ui/shapegraphicsitempropertieswidget.cpp
+++ b/sources/ui/shapegraphicsitempropertieswidget.cpp
@@ -20,6 +20,7 @@
#include "../QPropertyUndoCommand/qpropertyundocommand.h"
#include "../diagram.h"
+#include "../lastusedstyle.h"
#include "../qetgraphicsitem/qetshapeitem.h"
#include "../ui_shapegraphicsitempropertieswidget.h"
@@ -180,6 +181,7 @@ QUndoCommand* ShapeGraphicsItemPropertiesWidget::associatedUndo() const
{
undo = new QPropertyUndoCommand(m_shape, "pen", old_pen, new_pen);
undo->setText(tr("Modifier le trait d'une forme"));
+ LastUsedStyle::setShapePen(new_pen);
}
QBrush old_brush = m_shape->brush();
@@ -196,6 +198,7 @@ QUndoCommand* ShapeGraphicsItemPropertiesWidget::associatedUndo() const
undo = new QPropertyUndoCommand(m_shape, "brush", old_brush, new_brush);
undo->setText(tr("Modifier le remplissage d'une forme"));
}
+ LastUsedStyle::setShapeBrush(new_brush);
}
if (ui->m_close_polygon->isChecked() != m_shape->isClosed())
@@ -321,6 +324,7 @@ QUndoCommand* ShapeGraphicsItemPropertiesWidget::associatedUndo() const
if (new_pen != old_pen) {
new QPropertyUndoCommand(m_shape, "pen", old_pen, new_pen, undo);
+ LastUsedStyle::setShapePen(new_pen);
}
QBrush old_brush = m_shape->brush();
@@ -330,6 +334,7 @@ QUndoCommand* ShapeGraphicsItemPropertiesWidget::associatedUndo() const
if (new_brush != old_brush) {
new QPropertyUndoCommand(m_shape, "brush", old_brush, new_brush, undo);
+ LastUsedStyle::setShapeBrush(new_brush);
}
if (ui->m_close_polygon->isChecked() != m_shape->isClosed()) {