src/colors.h

changeset 946
9cbd658b63f9
parent 945
c310073e4f22
child 968
4b93b7963456
equal deleted inserted replaced
945:c310073e4f22 946:9cbd658b63f9
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 SHARED_POINTER_DERIVATIVE(T) \ 23 class LDColor
24 public: \ 24 {
25 using Self = T; \ 25 public:
26 using DataType = T##Data; \ 26 LDColor() : m_index (0) {}
27 using Super = QSharedPointer<DataType>; \ 27 LDColor (qint32 index) : m_index (index) {}
28 \ 28 LDColor (const LDColor& other) : m_index (other.m_index) {}
29 T() : Super() {} \
30 T (DataType* data) : Super (data) {} \
31 T (Super const& other) : Super (other) {} \
32 T (QPointer<DataType> const& other) : Super (other) {} \
33 \
34 template <typename Deleter> \
35 T (DataType* data, Deleter dlt) : Super (data, dlt) {} \
36 \
37 inline bool operator== (decltype(nullptr)) { return data() == nullptr; } \
38 inline bool operator!= (decltype(nullptr)) { return data() != nullptr; } \
39 inline DataType* operator->() const = delete;
40 29
41 #define SHARED_POINTER_DATA_ACCESS(N) \ 30 bool isLDConfigColor() const;
42 public: inline decltype(DataType::m_##N) const& N() const { return data()->m_##N; } 31 bool isValid() const;
32 QString name() const;
33 QString hexcode() const;
34 QColor faceColor() const;
35 QColor edgeColor() const;
36 qint32 index() const;
37 int luma() const;
38 int edgeLuma() const;
39 bool isDirect() const;
40 QString indexString() const;
43 41
44 class LDColor; 42 static LDColor nullColor() { return LDColor (-1); }
45 43
46 struct LDColorData 44 LDColor& operator= (qint32 index) { m_index = index; return *this; }
47 { 45 LDColor& operator= (LDColor other) { m_index = other.index(); return *this; }
48 QString m_name; 46 LDColor operator++() { return ++m_index; }
49 QString m_hexcode; 47 LDColor operator++ (int) { return m_index++; }
50 QColor m_faceColor; 48 LDColor operator--() { return --m_index; }
51 QColor m_edgeColor; 49 LDColor operator-- (int) { return m_index--; }
50
51 bool operator== (LDColor other) const { return index() == other.index(); }
52 bool operator!= (LDColor other) const { return index() != other.index(); }
53 bool operator< (LDColor other) const { return index() < other.index(); }
54 bool operator<= (LDColor other) const { return index() <= other.index(); }
55 bool operator> (LDColor other) const { return index() > other.index(); }
56 bool operator>= (LDColor other) const { return index() >= other.index(); }
57
58 private:
52 qint32 m_index; 59 qint32 m_index;
53 }; 60 };
54 61
55 class LDColor : public QSharedPointer<LDColorData> 62 //
63 // Parses ldconfig.ldr
64 //
65 class LDConfigParser
56 { 66 {
57 SHARED_POINTER_DERIVATIVE (LDColor) 67 public:
58 SHARED_POINTER_DATA_ACCESS (edgeColor) 68 LDConfigParser (QString inText, char sep);
59 SHARED_POINTER_DATA_ACCESS (faceColor)
60 SHARED_POINTER_DATA_ACCESS (hexcode)
61 SHARED_POINTER_DATA_ACCESS (index)
62 SHARED_POINTER_DATA_ACCESS (name)
63 69
64 public: 70 bool getToken (QString& val, const int pos);
65 QString indexString() const; 71 bool findToken (int& result, char const* needle, int args);
66 bool isDirect() const; 72 bool compareToken (int inPos, QString text);
73 bool parseLDConfigTag (char const* tag, QString& val);
67 74
68 bool operator== (Self const& other); 75 inline QString operator[] (const int idx)
69 static void addLDConfigColor (qint32 index, LDColor color); 76 {
70 static LDColor fromIndex (qint32 index); 77 return m_tokens[idx];
78 }
79
80 private:
81 QStringList m_tokens;
82 int m_pos;
71 }; 83 };
72 84
73 void InitColors(); 85 void InitColors();
74 int Luma (const QColor& col); 86 int Luma (const QColor& col);
75 int CountLDConfigColors(); 87 int CountLDConfigColors();
76 88 void parseLDConfig();
77 // Main and edge colors
78 LDColor MainColor();
79 LDColor EdgeColor();
80 89
81 enum 90 enum
82 { 91 {
83 MainColorIndex = 16, 92 MainColor = 16,
84 EdgeColorIndex = 24, 93 EdgeColor = 24,
85 }; 94 };

mercurial