Mercurial > hg > svgui
comparison layer/ColourDatabase.cpp @ 946:36cddc3de023 alignment_view
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 20 Apr 2015 09:19:52 +0100 |
parents | e0f08e108064 |
children | a34a2a25907c |
comparison
equal
deleted
inserted
replaced
897:499b637f2a26 | 946:36cddc3de023 |
---|---|
32 } | 32 } |
33 | 33 |
34 int | 34 int |
35 ColourDatabase::getColourCount() const | 35 ColourDatabase::getColourCount() const |
36 { | 36 { |
37 return m_colours.size(); | 37 return int(m_colours.size()); |
38 } | 38 } |
39 | 39 |
40 QString | 40 QString |
41 ColourDatabase::getColourName(int c) const | 41 ColourDatabase::getColourName(int c) const |
42 { | 42 { |
43 if (c < 0 || size_t(c) >= m_colours.size()) return ""; | 43 if (!in_range_for(m_colours, c)) return ""; |
44 return m_colours[c].name; | 44 return m_colours[c].name; |
45 } | 45 } |
46 | 46 |
47 QColor | 47 QColor |
48 ColourDatabase::getColour(int c) const | 48 ColourDatabase::getColour(int c) const |
49 { | 49 { |
50 if (c < 0 || size_t(c) >= m_colours.size()) return Qt::black; | 50 if (!in_range_for(m_colours, c)) return Qt::black; |
51 return m_colours[c].colour; | 51 return m_colours[c].colour; |
52 } | 52 } |
53 | 53 |
54 QColor | 54 QColor |
55 ColourDatabase::getColour(QString name) const | 55 ColourDatabase::getColour(QString name) const |
56 { | 56 { |
57 for (ColourList::const_iterator i = m_colours.begin(); | 57 for (auto &c: m_colours) { |
58 i != m_colours.end(); ++i) { | 58 if (c.name == name) return c.colour; |
59 if (i->name == name) return i->colour; | |
60 } | 59 } |
61 | 60 |
62 return Qt::black; | 61 return Qt::black; |
63 } | 62 } |
64 | 63 |
65 int | 64 int |
66 ColourDatabase::getColourIndex(QString name) const | 65 ColourDatabase::getColourIndex(QString name) const |
67 { | 66 { |
68 int index = 0; | 67 int index = 0; |
69 for (ColourList::const_iterator i = m_colours.begin(); | 68 for (auto &c: m_colours) { |
70 i != m_colours.end(); ++i) { | 69 if (c.name == name) return index; |
71 if (i->name == name) return index; | |
72 ++index; | 70 ++index; |
73 } | 71 } |
74 | 72 |
75 return -1; | 73 return -1; |
76 } | 74 } |
77 | 75 |
78 int | 76 int |
79 ColourDatabase::getColourIndex(QColor c) const | 77 ColourDatabase::getColourIndex(QColor col) const |
80 { | 78 { |
81 int index = 0; | 79 int index = 0; |
82 for (ColourList::const_iterator i = m_colours.begin(); | 80 for (auto &c: m_colours) { |
83 i != m_colours.end(); ++i) { | 81 if (c.colour == col) return index; |
84 if (i->colour == c) return index; | |
85 ++index; | 82 ++index; |
86 } | 83 } |
87 | 84 |
88 return -1; | 85 return -1; |
89 } | 86 } |
90 | 87 |
91 bool | 88 bool |
92 ColourDatabase::useDarkBackground(int c) const | 89 ColourDatabase::useDarkBackground(int c) const |
93 { | 90 { |
94 if (c < 0 || size_t(c) >= m_colours.size()) return false; | 91 if (!in_range_for(m_colours, c)) return false; |
95 return m_colours[c].darkbg; | 92 return m_colours[c].darkbg; |
96 } | 93 } |
97 | 94 |
98 void | 95 void |
99 ColourDatabase::setUseDarkBackground(int c, bool dark) | 96 ColourDatabase::setUseDarkBackground(int c, bool dark) |
100 { | 97 { |
101 if (c < 0 || size_t(c) >= m_colours.size()) return; | 98 if (!in_range_for(m_colours, c)) return; |
102 if (m_colours[c].darkbg != dark) { | 99 if (m_colours[c].darkbg != dark) { |
103 m_colours[c].darkbg = dark; | 100 m_colours[c].darkbg = dark; |
104 emit colourDatabaseChanged(); | 101 emit colourDatabaseChanged(); |
105 } | 102 } |
106 } | 103 } |
107 | 104 |
108 int | 105 int |
109 ColourDatabase::addColour(QColor c, QString name) | 106 ColourDatabase::addColour(QColor c, QString name) |
110 { | 107 { |
111 int index = 0; | 108 int index = 0; |
109 | |
112 for (ColourList::iterator i = m_colours.begin(); | 110 for (ColourList::iterator i = m_colours.begin(); |
113 i != m_colours.end(); ++i) { | 111 i != m_colours.end(); ++i) { |
114 if (i->name == name) { | 112 if (i->name == name) { |
115 i->colour = c; | 113 i->colour = c; |
116 return index; | 114 return index; |
145 QString &colourSpec, | 143 QString &colourSpec, |
146 QString &darkbg) const | 144 QString &darkbg) const |
147 { | 145 { |
148 colourName = ""; | 146 colourName = ""; |
149 colourSpec = ""; | 147 colourSpec = ""; |
150 if (index < 0 || size_t(index) >= m_colours.size()) return; | 148 if (!in_range_for(m_colours, index)) return; |
151 | 149 |
152 colourName = getColourName(index); | 150 colourName = getColourName(index); |
153 QColor c = getColour(index); | 151 QColor c = getColour(index); |
154 colourSpec = XmlExportable::encodeColour(c.red(), c.green(), c.blue()); | 152 colourSpec = XmlExportable::encodeColour(c.red(), c.green(), c.blue()); |
155 darkbg = useDarkBackground(index) ? "true" : "false"; | 153 darkbg = useDarkBackground(index) ? "true" : "false"; |