Wed, 25 May 2022 17:25:24 +0300
remove dead code
24 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013 - 2020 Teemu Piippo | |
4 | * | |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
3 | 19 | #pragma once |
26 | 20 | #include <QColor> |
3 | 21 | #include "main.h" |
22 | ||
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
23 | namespace ldraw |
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
24 | { |
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
25 | struct Color; |
139
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
26 | struct ColorDefinition; |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
27 | class ColorTable; |
94
164f53fb5921
added a color select dialog
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
28 | Color directColor(const QColor& color); |
164f53fb5921
added a color select dialog
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
29 | bool isDirectColor(Color color); |
164f53fb5921
added a color select dialog
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
30 | QColor directColorFace(Color color); |
164f53fb5921
added a color select dialog
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
31 | QColor colorFace(Color color, const ColorTable& colorTable); |
178 | 32 | QColor colorEdge(Color color, const ColorTable& colorTable); |
33 | QString colorDisplayName(Color color, const ColorTable& colorTable); | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
34 | } |
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
35 | |
139
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
36 | /** |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
37 | * @brief Represents an LDraw color index (e.g 16, 24, ...) |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
38 | * |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
39 | * @details |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
40 | * This is essentially just an integer. It is its own structure for the sake |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
41 | * of type correctness. Commonly used color values are 16 for the main color |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
42 | * and 24 for the edge color. |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
43 | * |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
44 | * Use @c ldraw::ColorTable to obtain rgb values for color indices. |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
45 | * |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
46 | * Direct colors are colors whose index is at least 0x2000000. These colors |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
47 | * encode the rgb values directly in the index. The color table code also |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
48 | * handles these cases. |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
49 | * |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
50 | * Note that it only makes sense to construct a color index from an integer |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
51 | * value if the integer comes from an external source (e.g. user or |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
52 | * LDConfig.ldr). Since this structure only contains an integer, it should be |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
53 | * passed by value to functions instead of l-value reference. |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
54 | */ |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
55 | struct ldraw::Color |
3 | 56 | { |
89 | 57 | qint32 index = 0; |
188
64ea7282611e
more work on circle tool + cleanup
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
58 | constexpr auto operator<=>(const Color&) const = default; |
3 | 59 | }; |
60 | ||
89 | 61 | Q_DECLARE_METATYPE(ldraw::Color) |
139
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
62 | QDataStream& operator<<(QDataStream&, ldraw::Color); |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
63 | QDataStream& operator>>(QDataStream&, ldraw::Color&); |
89 | 64 | |
139
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
65 | namespace ldraw |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
66 | { |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
67 | static constexpr Color BLACK {0}; |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
68 | static constexpr Color BLUE {1}; |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
69 | static constexpr Color GREEN {2}; |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
70 | static constexpr Color RED {4}; |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
71 | static constexpr Color YELLOW {14}; |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
72 | static constexpr Color WHITE {15}; |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
73 | static constexpr Color MAIN_COLOR {16}; |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
74 | static constexpr Color EDGE_COLOR {24}; |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
75 | } |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
76 | |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
77 | /** |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
78 | * @brief Contains the information about a specific color |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
79 | */ |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
80 | struct ldraw::ColorDefinition |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
81 | { |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
82 | /** |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
83 | * @brief The face color. This is the color used for most objects. |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
84 | * This is also used for the polygons of a subfile reference. |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
85 | */ |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
86 | QColor faceColor; |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
87 | /** |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
88 | * @brief The edge color, used for the edge lines of a subfile reference. |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
89 | * Note that edges using a color actually use the face color. LDraw standards |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
90 | * require edges to use color 24, however. |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
91 | */ |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
92 | QColor edgeColor; |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
93 | /** |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
94 | * @brief Name of the color |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
95 | */ |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
96 | QString name; |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
97 | /** |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
98 | * @brief A version of the name that can be shown to the user. |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
99 | */ |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
100 | QString displayName; |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
101 | }; |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
102 | |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
103 | /** |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
104 | * @brief Reads LDConfig.ldr and contains color table information for lookup purposes. |
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
105 | */ |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
106 | class ldraw::ColorTable |
26 | 107 | { |
108 | public: | |
109 | void clear(); | |
110 | Result load(QIODevice& device, QTextStream& errors); | |
111 | const ColorDefinition& operator[](Color index) const; | |
112 | static const ColorDefinition unknownColor; | |
94
164f53fb5921
added a color select dialog
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
113 | auto begin() const { return this->definitions.begin(); } |
164f53fb5921
added a color select dialog
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
114 | auto end() const { return this->definitions.end(); } |
139
72098474d362
Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents:
132
diff
changeset
|
115 | int size() const; |
26 | 116 | private: |
117 | void loadColorFromString(const QString& string); | |
94
164f53fb5921
added a color select dialog
Teemu Piippo <teemu@hecknology.net>
parents:
89
diff
changeset
|
118 | std::map<qint32, ColorDefinition> definitions; |
26 | 119 | }; |
120 | ||
43
08dc62e03a6d
made edges white in dark backgrounds
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
121 | double luma(const QColor& color); |