mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-13 10:04:13 +02:00
29ba7c9636
Drawing tools on the diagram canvas always started new shapes and free text from a fixed hardcoded default (Qt's plain QPen()/QBrush(), and the static Preferences font) -- changing a shape's color or a text's font had zero effect on what the next new item of that type got, even within the same editing session. Add LastUsedStyle: a small in-memory, session-scoped static helper (no QSettings, no persistence across restarts -- this is a live "what did I just use" value, not a new app-wide default). Write side hooks capture the value right where the properties editors already apply a change (ShapeGraphicsItemPropertiesWidget::associatedUndo(), both the live-edit dock path and the modal editProperty() dialog path; and IndiTextPropertiesWidget::on_m_font_pb_clicked() right after the font dialog returns). Read side hooks apply the stored value, if any, to a newly created item: DiagramEventAddShape::mousePressEvent for shapes, IndependentTextItem's constructor for free text (falling back to the existing QETApp::indiTextsItemFont() Preferences default otherwise). Doesn't touch the element/symbol editor's own drawing tools (a separate subsystem) or add last-used text color (no color control exists in the text properties UI to originate it from yet).
107 lines
2.3 KiB
C++
107 lines
2.3 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/>.
|
|
*/
|
|
#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;
|
|
}
|