Mercurial > hg > svgui
comparison layer/SingleColourLayer.cpp @ 374:64e84e5efb76 spectrogram-cache-rejig
* Merge from trunk
author | Chris Cannam |
---|---|
date | Wed, 27 Feb 2008 11:59:42 +0000 |
parents | c0b9eec70639 |
children |
comparison
equal
deleted
inserted
replaced
332:6440e280122e | 374:64e84e5efb76 |
---|---|
20 #include <iostream> | 20 #include <iostream> |
21 | 21 |
22 #include <QTextStream> | 22 #include <QTextStream> |
23 #include <QApplication> | 23 #include <QApplication> |
24 | 24 |
25 //#define DEBUG_COLOUR_SELECTION 1 | |
26 | |
25 SingleColourLayer::ColourRefCount | 27 SingleColourLayer::ColourRefCount |
26 SingleColourLayer::m_colourRefCount; | 28 SingleColourLayer::m_colourRefCount; |
27 | 29 |
28 SingleColourLayer::SingleColourLayer() : | 30 SingleColourLayer::SingleColourLayer() : |
29 m_colour(0), | 31 m_colour(0), |
30 m_colourExplicitlySet(false) | 32 m_colourExplicitlySet(false), |
33 m_defaultColourSet(false) | |
31 { | 34 { |
32 setDefaultColourFor(0); | 35 setDefaultColourFor(0); |
33 } | 36 } |
34 | 37 |
35 QPixmap | 38 QPixmap |
123 } | 126 } |
124 | 127 |
125 void | 128 void |
126 SingleColourLayer::setDefaultColourFor(View *v) | 129 SingleColourLayer::setDefaultColourFor(View *v) |
127 { | 130 { |
128 if (m_colourExplicitlySet) return; | 131 #ifdef DEBUG_COLOUR_SELECTION |
132 std::cerr << "SingleColourLayer::setDefaultColourFor: m_colourExplicitlySet = " << m_colourExplicitlySet << ", m_defaultColourSet " << m_defaultColourSet << std::endl; | |
133 #endif | |
134 | |
135 if (m_colourExplicitlySet || m_defaultColourSet) return; | |
136 | |
137 if (v) m_defaultColourSet = true; // v==0 case doesn't really count | |
129 | 138 |
130 bool dark = false; | 139 bool dark = false; |
131 if (v) { | 140 if (v) { |
132 dark = !v->hasLightBackground(); | 141 dark = !v->hasLightBackground(); |
133 } else { | 142 } else { |
146 } | 155 } |
147 // We don't want to call this if !v because that probably | 156 // We don't want to call this if !v because that probably |
148 // means we're being called from the constructor, and this is | 157 // means we're being called from the constructor, and this is |
149 // a virtual function | 158 // a virtual function |
150 hint = getDefaultColourHint(dark, impose); | 159 hint = getDefaultColourHint(dark, impose); |
151 // std::cerr << "hint = " << hint << ", impose = " << impose << std::endl; | 160 #ifdef DEBUG_COLOUR_SELECTION |
152 } else { | 161 std::cerr << "hint = " << hint << ", impose = " << impose << std::endl; |
153 // std::cerr << "(from ctor)" << std::endl; | 162 #endif |
163 } else { | |
164 #ifdef DEBUG_COLOUR_SELECTION | |
165 std::cerr << "(from ctor)" << std::endl; | |
166 #endif | |
154 } | 167 } |
155 | 168 |
156 if (hint >= 0 && impose) { | 169 if (hint >= 0 && impose) { |
157 setBaseColour(hint); | 170 setBaseColour(hint); |
158 return; | 171 return; |
169 int count = 0; | 182 int count = 0; |
170 if (m_colourRefCount.find(index) != m_colourRefCount.end()) { | 183 if (m_colourRefCount.find(index) != m_colourRefCount.end()) { |
171 count = m_colourRefCount[index]; | 184 count = m_colourRefCount[index]; |
172 } | 185 } |
173 | 186 |
174 // std::cerr << "index = " << index << ", count = " << count; | 187 #ifdef DEBUG_COLOUR_SELECTION |
188 std::cerr << "index = " << index << ", count = " << count; | |
189 #endif | |
175 | 190 |
176 if (bestColour < 0 || count < bestCount) { | 191 if (bestColour < 0 || count < bestCount) { |
177 bestColour = index; | 192 bestColour = index; |
178 bestCount = count; | 193 bestCount = count; |
179 // std::cerr << " *"; | 194 #ifdef DEBUG_COLOUR_SELECTION |
180 } | 195 std::cerr << " *"; |
181 | 196 #endif |
182 // std::cerr << std::endl; | 197 } |
198 | |
199 #ifdef DEBUG_COLOUR_SELECTION | |
200 std::cerr << std::endl; | |
201 #endif | |
183 } | 202 } |
184 | 203 |
185 if (bestColour < 0) m_colour = 0; | 204 if (bestColour < 0) m_colour = 0; |
186 else m_colour = bestColour; | 205 else m_colour = bestColour; |
187 | 206 |
287 | 306 |
288 m_colourExplicitlySet = true; | 307 m_colourExplicitlySet = true; |
289 | 308 |
290 if (m_colour != colour) { | 309 if (m_colour != colour) { |
291 | 310 |
311 #ifdef DEBUG_COLOUR_SELECTION | |
292 std::cerr << "SingleColourLayer::setProperties: changing colour from " << m_colour << " to " << colour << std::endl; | 312 std::cerr << "SingleColourLayer::setProperties: changing colour from " << m_colour << " to " << colour << std::endl; |
313 #endif | |
293 | 314 |
294 if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() && | 315 if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() && |
295 m_colourRefCount[m_colour] > 0) { | 316 m_colourRefCount[m_colour] > 0) { |
296 m_colourRefCount[m_colour]--; | 317 m_colourRefCount[m_colour]--; |
297 } | 318 } |