18 |
18 |
19 #pragma once |
19 #pragma once |
20 #include <QColor> |
20 #include <QColor> |
21 #include "main.h" |
21 #include "main.h" |
22 |
22 |
23 #define MAX_COLORS 512 |
23 class LDColor; |
24 |
24 |
25 class LDColor |
25 class LDColorData |
|
26 { |
|
27 protected: |
|
28 QString _name; |
|
29 QString _hexcode; |
|
30 QColor _faceColor; |
|
31 QColor _edgeColor; |
|
32 qint32 _index; |
|
33 friend class LDConfigParser; |
|
34 friend class LDColor; |
|
35 friend void initColors(); |
|
36 |
|
37 public: |
|
38 LDColorData(){} |
|
39 |
|
40 readAccess (edgeColor) |
|
41 readAccess (faceColor) |
|
42 readAccess (hexcode) |
|
43 readAccess (index) |
|
44 QString indexString() const; |
|
45 bool isDirect() const; |
|
46 readAccess (name) |
|
47 }; |
|
48 |
|
49 |
|
50 class LDColor : public QSharedPointer<LDColorData> |
26 { |
51 { |
27 public: |
52 public: |
28 QString name, hexcode; |
53 using Super = QSharedPointer<LDColorData>; |
29 QColor faceColor, edgeColor; |
54 using Self = LDColor; |
30 int index; |
55 |
|
56 LDColor() : Super() {} |
|
57 LDColor (LDColorData* data) : Super (data) {} |
|
58 LDColor (Super const& other) : Super (other) {} |
|
59 LDColor (QWeakPointer<LDColorData> const& other) : Super (other) {} |
|
60 |
|
61 template <typename Deleter> |
|
62 LDColor (LDColorData* data, Deleter dlt) : Super (data, dlt) {} |
|
63 |
|
64 inline bool operator== (Self const& other); |
|
65 inline bool operator== (decltype(nullptr)) { return data() == nullptr; } |
|
66 inline bool operator!= (decltype(nullptr)) { return data() != nullptr; } |
|
67 inline LDColorData* operator->() const { return data(); } |
|
68 |
|
69 static void addLDConfigColor (qint32 index, LDColor color); |
|
70 static LDColor fromIndex (qint32 index); |
31 }; |
71 }; |
32 |
72 |
33 void initColors(); |
73 void initColors(); |
34 int luma (const QColor& col); |
74 int luma (const QColor& col); |
|
75 int numLDConfigColors(); |
35 |
76 |
36 // Safely gets a color with the given number or null if no such color. |
77 // Main and edge colors |
37 LDColor* getColor (int colnum); |
78 LDColor maincolor(); |
38 void setColor (int colnum, LDColor* col); |
79 LDColor edgecolor(); |
|
80 static constexpr int mainColorIndex = 16; |
|
81 static constexpr int edgeColorIndex = 24; |
39 |
82 |
40 // Main and edge color identifiers |
83 bool LDColor::operator== (LDColor const& other) |
41 static const int maincolor = 16; |
84 { |
42 static const int edgecolor = 24; |
85 if ((data() == nullptr) ^ (other == nullptr)) |
|
86 return false; |
|
87 |
|
88 if (data() != nullptr) |
|
89 return data()->index() == other->index(); |
|
90 |
|
91 // both are null |
|
92 return true; |
|
93 } |