LibrePCB Developers Documentation
Loading...
Searching...
No Matches
theme.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_CORE_THEME_H
21#define LIBREPCB_CORE_THEME_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../serialization/sexpression.h"
27#include "../types/uuid.h"
28#include "themecolor.h"
29
30#include <QtCore>
31
32/*******************************************************************************
33 * Namespace / Forward Declarations
34 ******************************************************************************/
35namespace librepcb {
36
37/*******************************************************************************
38 * Class Theme
39 ******************************************************************************/
40
44class Theme final {
45 Q_DECLARE_TR_FUNCTIONS(Theme)
46
47public:
48 // Types
49 enum class GridStyle : int {
50 None,
51 Dots,
52 Lines,
53 };
54
55 struct Color {
56 // clang-format off
57 static constexpr const char* sSchematicBackground = "schematic_background";
58 static constexpr const char* sSchematicOverlays = "schematic_overlays";
59 static constexpr const char* sSchematicInfoBox = "schematic_info_box";
60 static constexpr const char* sSchematicSelection = "schematic_selection";
61 static constexpr const char* sSchematicReferences = "schematic_references";
62 static constexpr const char* sSchematicFrames = "schematic_frames";
63 static constexpr const char* sSchematicWires = "schematic_wires";
64 static constexpr const char* sSchematicNetLabels = "schematic_net_labels";
65 static constexpr const char* sSchematicNetLabelAnchors = "schematic_net_label_anchors";
66 static constexpr const char* sSchematicDocumentation = "schematic_documentation";
67 static constexpr const char* sSchematicComments = "schematic_comments";
68 static constexpr const char* sSchematicGuide = "schematic_guide";
69 static constexpr const char* sSchematicOutlines = "schematic_outlines";
70 static constexpr const char* sSchematicGrabAreas = "schematic_grab_areas";
71 static constexpr const char* sSchematicHiddenGrabAreas = "schematic_hidden_grab_areas";
72 static constexpr const char* sSchematicNames = "schematic_names";
73 static constexpr const char* sSchematicValues = "schematic_values";
74 static constexpr const char* sSchematicOptionalPins = "schematic_optional_pins";
75 static constexpr const char* sSchematicRequiredPins = "schematic_required_pins";
76 static constexpr const char* sSchematicPinLines = "schematic_pin_lines";
77 static constexpr const char* sSchematicPinNames = "schematic_pin_names";
78 static constexpr const char* sSchematicPinNumbers = "schematic_pin_numbers";
79 static constexpr const char* sBoardBackground = "board_background";
80 static constexpr const char* sBoardOverlays = "board_overlays";
81 static constexpr const char* sBoardInfoBox = "board_info_box";
82 static constexpr const char* sBoardSelection = "board_selection";
83 static constexpr const char* sBoardDrcMarker = "board_drc_marker";
84 static constexpr const char* sBoardFrames = "board_frames";
85 static constexpr const char* sBoardOutlines = "board_outlines";
86 static constexpr const char* sBoardPlatedCutouts = "board_plated_cutouts";
87 static constexpr const char* sBoardHoles = "board_holes";
88 static constexpr const char* sBoardPads = "board_pads";
89 static constexpr const char* sBoardVias = "board_vias";
90 static constexpr const char* sBoardZones = "board_zones";
91 static constexpr const char* sBoardAirWires = "board_airwires";
92 static constexpr const char* sBoardMeasures = "board_measures";
93 static constexpr const char* sBoardAlignment = "board_alignment";
94 static constexpr const char* sBoardDocumentation = "board_documentation";
95 static constexpr const char* sBoardComments = "board_comments";
96 static constexpr const char* sBoardGuide = "board_guide";
97 static constexpr const char* sBoardNamesTop = "board_names_top";
98 static constexpr const char* sBoardNamesBot = "board_names_bottom";
99 static constexpr const char* sBoardValuesTop = "board_values_top";
100 static constexpr const char* sBoardValuesBot = "board_values_bottom";
101 static constexpr const char* sBoardLegendTop = "board_legend_top";
102 static constexpr const char* sBoardLegendBot = "board_legend_bottom";
103 static constexpr const char* sBoardDocumentationTop = "board_documentation_top";
104 static constexpr const char* sBoardDocumentationBot = "board_documentation_bottom";
105 static constexpr const char* sBoardPackageOutlinesTop = "board_package_outlines_top";
106 static constexpr const char* sBoardPackageOutlinesBot = "board_package_outlines_bottom";
107 static constexpr const char* sBoardCourtyardTop = "board_courtyard_top";
108 static constexpr const char* sBoardCourtyardBot = "board_courtyard_bottom";
109 static constexpr const char* sBoardGrabAreasTop = "board_grab_areas_top";
110 static constexpr const char* sBoardGrabAreasBot = "board_grab_areas_bottom";
111 static constexpr const char* sBoardHiddenGrabAreasTop = "board_hidden_grab_areas_top";
112 static constexpr const char* sBoardHiddenGrabAreasBot = "board_hidden_grab_areas_bottom";
113 static constexpr const char* sBoardReferencesTop = "board_references_top";
114 static constexpr const char* sBoardReferencesBot = "board_references_bottom";
115 static constexpr const char* sBoardStopMaskTop = "board_stop_mask_top";
116 static constexpr const char* sBoardStopMaskBot = "board_stop_mask_bottom";
117 static constexpr const char* sBoardSolderPasteTop = "board_solder_paste_top";
118 static constexpr const char* sBoardSolderPasteBot = "board_solder_paste_bottom";
119 static constexpr const char* sBoardFinishTop = "board_finish_top";
120 static constexpr const char* sBoardFinishBot = "board_finish_bottom";
121 static constexpr const char* sBoardGlueTop = "board_glue_top";
122 static constexpr const char* sBoardGlueBot = "board_glue_bottom";
123 static constexpr const char* sBoardCopperTop = "board_copper_top";
124 static constexpr const char* sBoardCopperInner = "board_copper_inner_%1";
125 static constexpr const char* sBoardCopperBot = "board_copper_bottom";
126 // clang-format on
127 };
128
129 // Constructors / Destructor
130 explicit Theme(const Uuid& uuid = Uuid::createRandom(),
131 const QString& name = "Unnamed") noexcept;
132 Theme(const Uuid& uuid, const QString& name, const Theme& copyFrom) noexcept;
133 Theme(const Theme& other) noexcept;
134 ~Theme() noexcept;
135
136 // Getters
137 const Uuid& getUuid() const noexcept { return mUuid; }
138 const QString& getName() const noexcept { return mName; }
139 const QList<ThemeColor>& getColors() const noexcept { return mColors; }
140 const ThemeColor& getColor(const QString& identifier) const noexcept;
142 return mSchematicGridStyle;
143 }
144 GridStyle getBoardGridStyle() const noexcept { return mBoardGridStyle; }
145
146 // Setters
147 void setName(const QString& name) noexcept;
148 void setColors(const QList<ThemeColor>& colors) noexcept;
149 void setSchematicGridStyle(GridStyle style) noexcept;
150 void setBoardGridStyle(GridStyle style) noexcept;
151
152 // General Methods
153 void restoreDefaults() noexcept;
154 void load(const SExpression& root);
155 void serialize(SExpression& root) const;
156
157 // Operator Overloadings
158 bool operator==(const Theme& rhs) const noexcept;
159 bool operator!=(const Theme& rhs) const noexcept { return !(*this == rhs); }
160 Theme& operator=(const Theme& rhs) noexcept;
161
162 // Static Methods
163 static const QSet<QString>& getCopperColorNames() noexcept;
164 static QString getGrabAreaColorName(const QString& outlineColorName) noexcept;
165
166private: // Methods
167 void addColor(const QString& id, const char* category, const char* name,
168 const QColor& primary, const QColor& secondary,
169 const QString& nameSuffix = QString()) noexcept;
170 SExpression& addNode(const QString& name) noexcept;
171
172private: // Data
173 QMap<QString, SExpression> mNodes;
174
176 QString mName;
180};
181
182/*******************************************************************************
183 * End of File
184 ******************************************************************************/
185
186} // namespace librepcb
187
188Q_DECLARE_METATYPE(librepcb::Theme::GridStyle)
189
190#endif
The SExpression class.
Definition sexpression.h:69
Color settings as used by librepcb::Theme.
Definition themecolor.h:43
Theme class as used by librepcb::WorkspaceSettingsItem_Themes.
Definition theme.h:44
GridStyle mBoardGridStyle
Definition theme.h:179
const ThemeColor & getColor(const QString &identifier) const noexcept
Definition theme.cpp:214
GridStyle mSchematicGridStyle
Definition theme.h:178
GridStyle
Definition theme.h:49
static QString getGrabAreaColorName(const QString &outlineColorName) noexcept
Definition theme.cpp:357
const QList< ThemeColor > & getColors() const noexcept
Definition theme.h:139
const QString & getName() const noexcept
Definition theme.h:138
static const QSet< QString > & getCopperColorNames() noexcept
Definition theme.cpp:345
Uuid mUuid
Definition theme.h:175
QList< ThemeColor > mColors
Definition theme.h:177
QMap< QString, SExpression > mNodes
Definition theme.h:173
void load(const SExpression &root)
Definition theme.cpp:285
QString mName
Definition theme.h:176
Theme & operator=(const Theme &rhs) noexcept
Definition theme.cpp:331
void setSchematicGridStyle(GridStyle style) noexcept
Definition theme.cpp:263
GridStyle getSchematicGridStyle() const noexcept
Definition theme.h:141
SExpression & addNode(const QString &name) noexcept
Definition theme.cpp:380
void serialize(SExpression &root) const
Definition theme.cpp:307
const Uuid & getUuid() const noexcept
Definition theme.h:137
void setBoardGridStyle(GridStyle style) noexcept
Definition theme.cpp:270
void restoreDefaults() noexcept
Definition theme.cpp:281
GridStyle getBoardGridStyle() const noexcept
Definition theme.h:144
void setColors(const QList< ThemeColor > &colors) noexcept
Definition theme.cpp:234
void addColor(const QString &id, const char *category, const char *name, const QColor &primary, const QColor &secondary, const QString &nameSuffix=QString()) noexcept
Definition theme.cpp:373
void setName(const QString &name) noexcept
Definition theme.cpp:230
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition uuid.h:56
static Uuid createRandom() noexcept
Create a new random UUID.
Definition uuid.cpp:104
Definition occmodel.cpp:76
Definition theme.h:55
static constexpr const char * sSchematicOverlays
Definition theme.h:58
static constexpr const char * sBoardPlatedCutouts
Definition theme.h:86
static constexpr const char * sSchematicPinNumbers
Definition theme.h:78
static constexpr const char * sBoardCourtyardTop
Definition theme.h:107
static constexpr const char * sBoardCopperTop
Definition theme.h:123
static constexpr const char * sBoardSolderPasteBot
Definition theme.h:118
static constexpr const char * sBoardGlueBot
Definition theme.h:122
static constexpr const char * sSchematicComments
Definition theme.h:67
static constexpr const char * sBoardGrabAreasTop
Definition theme.h:109
static constexpr const char * sSchematicInfoBox
Definition theme.h:59
static constexpr const char * sBoardHiddenGrabAreasTop
Definition theme.h:111
static constexpr const char * sSchematicNetLabelAnchors
Definition theme.h:65
static constexpr const char * sSchematicOptionalPins
Definition theme.h:74
static constexpr const char * sSchematicGrabAreas
Definition theme.h:70
static constexpr const char * sBoardDocumentationBot
Definition theme.h:104
static constexpr const char * sBoardCopperInner
Definition theme.h:124
static constexpr const char * sBoardDrcMarker
Definition theme.h:83
static constexpr const char * sBoardValuesTop
Definition theme.h:99
static constexpr const char * sBoardSelection
Definition theme.h:82
static constexpr const char * sBoardFinishBot
Definition theme.h:120
static constexpr const char * sSchematicDocumentation
Definition theme.h:66
static constexpr const char * sBoardDocumentationTop
Definition theme.h:103
static constexpr const char * sBoardZones
Definition theme.h:90
static constexpr const char * sBoardBackground
Definition theme.h:79
static constexpr const char * sSchematicPinNames
Definition theme.h:77
static constexpr const char * sBoardPackageOutlinesTop
Definition theme.h:105
static constexpr const char * sSchematicPinLines
Definition theme.h:76
static constexpr const char * sBoardHiddenGrabAreasBot
Definition theme.h:112
static constexpr const char * sBoardDocumentation
Definition theme.h:94
static constexpr const char * sBoardValuesBot
Definition theme.h:100
static constexpr const char * sSchematicNames
Definition theme.h:72
static constexpr const char * sBoardNamesTop
Definition theme.h:97
static constexpr const char * sBoardPackageOutlinesBot
Definition theme.h:106
static constexpr const char * sSchematicHiddenGrabAreas
Definition theme.h:71
static constexpr const char * sBoardSolderPasteTop
Definition theme.h:117
static constexpr const char * sBoardOverlays
Definition theme.h:80
static constexpr const char * sBoardMeasures
Definition theme.h:92
static constexpr const char * sBoardCourtyardBot
Definition theme.h:108
static constexpr const char * sBoardGlueTop
Definition theme.h:121
static constexpr const char * sBoardGrabAreasBot
Definition theme.h:110
static constexpr const char * sBoardNamesBot
Definition theme.h:98
static constexpr const char * sBoardPads
Definition theme.h:88
static constexpr const char * sBoardStopMaskTop
Definition theme.h:115
static constexpr const char * sSchematicSelection
Definition theme.h:60
static constexpr const char * sBoardAirWires
Definition theme.h:91
static constexpr const char * sSchematicReferences
Definition theme.h:61
static constexpr const char * sSchematicNetLabels
Definition theme.h:64
static constexpr const char * sBoardVias
Definition theme.h:89
static constexpr const char * sBoardInfoBox
Definition theme.h:81
static constexpr const char * sSchematicGuide
Definition theme.h:68
static constexpr const char * sBoardFrames
Definition theme.h:84
static constexpr const char * sBoardReferencesBot
Definition theme.h:114
static constexpr const char * sBoardReferencesTop
Definition theme.h:113
static constexpr const char * sSchematicRequiredPins
Definition theme.h:75
static constexpr const char * sBoardComments
Definition theme.h:95
static constexpr const char * sBoardGuide
Definition theme.h:96
static constexpr const char * sBoardLegendTop
Definition theme.h:101
static constexpr const char * sBoardOutlines
Definition theme.h:85
static constexpr const char * sSchematicBackground
Definition theme.h:57
static constexpr const char * sBoardStopMaskBot
Definition theme.h:116
static constexpr const char * sBoardLegendBot
Definition theme.h:102
static constexpr const char * sSchematicOutlines
Definition theme.h:69
static constexpr const char * sSchematicFrames
Definition theme.h:62
static constexpr const char * sSchematicValues
Definition theme.h:73
static constexpr const char * sBoardFinishTop
Definition theme.h:119
static constexpr const char * sBoardAlignment
Definition theme.h:93
static constexpr const char * sBoardCopperBot
Definition theme.h:125
static constexpr const char * sBoardHoles
Definition theme.h:87
static constexpr const char * sSchematicWires
Definition theme.h:63