wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
ElementAppearance.h
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
7
8#pragma once
9
10#include <memory>
11
12#include <QColor>
13#include <QCoreApplication>
14#include <QPixmap>
15#include <QSize>
16#include <QStringList>
17
18class GraphicElement;
19class QPainter;
20class QSvgRenderer;
21class ThemeAttributes;
22
35{
36 Q_DECLARE_TR_FUNCTIONS(ElementAppearance)
37
38public:
40 explicit ElementAppearance(GraphicElement *owner);
41
44
47 void seedFromMetadata(const QStringList &defaultAppearances,
48 const QStringList &alternativeAppearances,
49 const QString &pixmapPath);
50
51 // --- Pixmap access ---
52
54 QPixmap pixmap() const { return m_pixmap; }
55
57 QPointF pixmapCenter() const;
58
60 bool hasDefaultAppearances() const { return !m_defaultAppearances.isEmpty(); }
61
63 void setPixmap(const int index);
64
66 void setPixmap(const QString &pixmapPath);
67
70 QPixmap previewPixmapAt(const int index, const QSize &size) const;
71
75 void setRenderPixmap(const QPixmap &pixmap);
76
78 void applyOrientation();
79
80 // --- Appearance list ---
81
83 void setAppearance(const bool defaultAppearance, const QString &fileName);
84
86 void setAppearanceAt(const int index, const QString &fileName);
87
89 const QStringList &defaultAppearances() const { return m_defaultAppearances; }
90
92 const QStringList &alternativeAppearances() const { return m_alternativeAppearances; }
93
95 void resetAlternativeToDefault() { m_alternativeAppearances = m_defaultAppearances; }
96
98 void setAlternativeAppearanceAt(const int index, const QString &path);
99
101 void setUsingDefaultAppearance(const bool value) { m_usingDefaultAppearance = value; }
102
104 bool usingDefaultAppearance() const { return m_usingDefaultAppearance; }
105
108
110 QStringList externalFiles() const;
111
112 // --- Painting ---
113
115 void render(QPainter *painter, const QRectF &boundingRect, const bool selected) const;
116
118 void applyTheme(const ThemeAttributes &theme);
119
121 QColor selectionBrush() const { return m_selectionBrush; }
122
124 QColor selectionPen() const { return m_selectionPen; }
125
126private:
129 void rebuildSvgRenderer();
130
131 GraphicElement *m_owner = nullptr;
132
133 QPixmap m_pixmap;
134 QPixmap m_basePixmap;
135 bool m_hasCustomRenderPixmap = false;
136 std::shared_ptr<QSvgRenderer> m_svgRenderer;
137
138 QString m_pixmapPath;
139 QString m_currentPixmapPath;
140 QString m_resolvedPixmapPath;
141
142 QStringList m_defaultAppearances;
143 QStringList m_alternativeAppearances;
144 bool m_usingDefaultAppearance = true;
145
146 QColor m_selectionBrush;
147 QColor m_selectionPen;
148};
QStringList externalFiles() const
Returns the external (non-resource) appearance file paths the element depends on.
bool hasDefaultAppearances() const
Returns true if at least one default appearance is available.
ElementAppearance(GraphicElement *owner)
Constructs the appearance bound to its owning owner element.
void recomputeUsingDefault()
Recomputes the using-default flag by comparing the alternative and default lists.
void setRenderPixmap(const QPixmap &pixmap)
QColor selectionBrush() const
Fill color of the selection highlight rectangle.
QPointF pixmapCenter() const
Returns the centre point of the displayed pixmap in local coordinates.
~ElementAppearance()
Out-of-line so the unique_ptr to the forward-declared QSvgRenderer can be destroyed.
const QStringList & alternativeAppearances() const
Returns the active (possibly user-customised) appearance paths.
void applyOrientation()
Re-derives the displayed pixmap (and SVG renderer) from the owner's current orientation.
void setUsingDefaultAppearance(const bool value)
Sets the "using built-in default appearance" flag.
void render(QPainter *painter, const QRectF &boundingRect, const bool selected) const
Draws the selection highlight (when selected) and the SVG/pixmap body onto painter.
void setAppearance(const bool defaultAppearance, const QString &fileName)
Switches the appearance: restores defaults or applies fileName at slot 0.
const QStringList & defaultAppearances() const
Returns the built-in default appearance paths.
void setAlternativeAppearanceAt(const int index, const QString &path)
Sets one alternative-appearance slot without reloading the pixmap (serializer / subclass use).
void setPixmap(const int index)
Loads and applies the appearance at position index in the active list.
void resetAlternativeToDefault()
Copies the default appearances over the alternative list (restore-to-default).
void seedFromMetadata(const QStringList &defaultAppearances, const QStringList &alternativeAppearances, const QString &pixmapPath)
bool usingDefaultAppearance() const
Returns true when the active appearance still matches the built-in default.
QPixmap previewPixmapAt(const int index, const QSize &size) const
void applyTheme(const ThemeAttributes &theme)
Applies the selection-highlight colors from theme.
QPixmap pixmap() const
Returns the pixmap currently displayed.
void setAppearanceAt(const int index, const QString &fileName)
Sets a custom appearance at index (empty fileName restores that slot's default).
QColor selectionPen() const
Border color of the selection highlight rectangle.
Abstract base class for all graphical circuit elements in wiRedPanda.
Contains all color attributes for a theme.