src/colors.h

Mon, 02 Apr 2018 10:59:38 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 02 Apr 2018 10:59:38 +0300
changeset 1370
c6d5ba08c62c
parent 1326
69a90bd2dba2
child 1397
5d5c11af0268
permissions
-rw-r--r--

reworked bounding box

655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1308
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #pragma once
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QColor>
974
b2fa5f89798a Added a GuiUtilities class to contain useful non-MainWindow-related GUI functions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
21 #include "basics.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22
1044
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
23 /*
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
24 * ColorData
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
25 *
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
26 * This class contains the model data for LDConfig-defined colors.
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
27 */
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
28 class ColorData
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
29 {
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
30 public:
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
31 struct Entry
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
32 {
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
33 QString name;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
34 QColor faceColor;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
35 QColor edgeColor;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
36 };
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
37
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
38 ColorData();
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
39 void loadFromLdconfig();
1308
dcc8c02530c2 Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents: 1269
diff changeset
40 void loadFromFile(QIODevice& device);
1044
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
41 bool contains(int code) const;
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
42 const Entry& get(int code) const;
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
43
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
44 private:
1044
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
45 Entry m_data[512];
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
46 };
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
47
1044
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
48 /*
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
49 * LDColor
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
50 *
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
51 * This class represents an LDraw color. For a color index, this class provides information for that color.
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
52 * It only contains the index of the color. Therefore it is a wrapper around an integer and should be passed by value.
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
53 */
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
54 class LDColor
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
55 {
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
56 public:
1044
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
57 LDColor();
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
58 LDColor(qint32 index);
1174
91696a2e022c Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents: 1114
diff changeset
59 LDColor(QColor color, bool transparent = false);
1044
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
60 LDColor(const LDColor& other) = default;
806
4240f47aa2d4 - moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
61
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
62 bool isLDConfigColor() const;
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
63 bool isValid() const;
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
64 QString name() const;
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
65 QString hexcode() const;
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
66 QColor faceColor() const;
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
67 QColor edgeColor() const;
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
68 qint32 index() const;
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
69 bool isDirect() const;
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
70 QString indexString() const;
806
4240f47aa2d4 - moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
71
1114
ffd49a28f49e Moved some global constants into appropriate namespaces.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
72 static const LDColor nullColor;
1174
91696a2e022c Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents: 1114
diff changeset
73 static qint32 directColorIndex(QColor color, bool transparent = false);
1114
ffd49a28f49e Moved some global constants into appropriate namespaces.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
74 static void initColors();
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
75
1044
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
76 LDColor& operator=(qint32 index) { m_index = index; return *this; }
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
77 LDColor& operator=(const LDColor &other) = default;
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
78 LDColor operator++() { return ++m_index; }
1044
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
79 LDColor operator++(int) { return m_index++; }
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
80 LDColor operator--() { return --m_index; }
1044
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
81 LDColor operator--(int) { return m_index--; }
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
82 bool operator==(LDColor other) const { return index() == other.index(); }
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
83 bool operator!=(LDColor other) const { return index() != other.index(); }
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
84 bool operator<(LDColor other) const { return index() < other.index(); }
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
85 bool operator<=(LDColor other) const { return index() <= other.index(); }
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
86 bool operator>(LDColor other) const { return index() > other.index(); }
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
87 bool operator>=(LDColor other) const { return index() >= other.index(); }
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
88
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
89 private:
1114
ffd49a28f49e Moved some global constants into appropriate namespaces.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
90 static ColorData* colorData;
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
91 const ColorData::Entry& data() const;
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
92
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
93 qint32 m_index;
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
94 };
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
95
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1174
diff changeset
96 Q_DECLARE_METATYPE(LDColor)
1031
55c0d3beea0d removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
97 uint qHash(LDColor color);
55c0d3beea0d removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
98
1044
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
99 /*
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
100 * LDConfigParser
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
101 *
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
102 * Parses LDConfig.ldr.
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
103 */
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
104 class LDConfigParser
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 {
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
106 public:
1044
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
107 LDConfigParser(QString inputText);
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
108
1044
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
109 bool getToken(QString& tokenText, int position);
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
110 bool findToken(int& tokenPosition, QString needle, int args);
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
111 bool compareToken(int inPos, QString text);
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
112 bool parseTag(QString key, QString& value);
795
195fa1fff9c3 - changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
113
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
114 private:
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
115 QStringList m_tokens;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 };
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
1044
b5106ca8705e Cleanup colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 1031
diff changeset
118 int luma(const QColor& col);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
119
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
120 enum
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
121 {
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
122 MainColor = 16,
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
123 EdgeColor = 24,
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
124 };

mercurial