Files
qelectrotech-source-mirror/sources/lastusedstyle.h
T
ispyisail 1ec4f56a50 Remember the F2 conductor color for the rest of the session (#879)
The F2 color editor recolors one conductor, but the next one drawn
falls straight back to defaultConductorProperties -- the choice made
via F2 is lost the moment you place another wire, and lost again on
restart. LastUsedStyle already solves the same problem for shapes
(pen/brush) and free text (font), session-scoped and deliberately not
QSettings-backed; this extends it with a conductor color, following
the identical has/get/set shape.

F2's handler records the color after pushing its undo command.
Conductor's constructor -- the one place a new conductor's properties
are set from defaultConductorProperties -- overrides just the color
field when a session color has been recorded, leaving every other
default (style, thickness, text) alone.

Verified: build clean, ctest 6/6. Could not get a reliable headless
GUI trace of "F2 one wire, draw a new one, see it inherit the color"
-- drag-and-drop element placement under Xvfb was unreliable in this
environment (one attempt did nothing, another drew an unintended long
conductor undo didn't fully clear). The code path is otherwise
identical to the already-shipped shape/text mechanism this mirrors.

Refs #461.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-16 15:40:41 +12:00

73 lines
2.2 KiB
C++

/*
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 <http://www.gnu.org/licenses/>.
*/
#ifndef LAST_USED_STYLE_H
#define LAST_USED_STYLE_H
#include <QBrush>
#include <QColor>
#include <QFont>
#include <QPen>
/**
@brief The LastUsedStyle class
Session-scoped "last used" style for new shapes, free text and
conductors created on the diagram canvas: whatever pen/brush/font/color
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, and
by the project's default conductor color, read the same way).
*/
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);
static bool hasConductorColor();
static QColor conductorColor();
static void setConductorColor(const QColor &color);
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;
static QColor m_conductor_color;
static bool m_has_conductor_color;
};
#endif // LAST_USED_STYLE_H