Mercurial > hg > svgui
comparison layer/SingleColourLayer.cpp @ 770:734ee80286c3 tony_integration
Merge from default branch
author | Chris Cannam |
---|---|
date | Fri, 09 May 2014 17:15:50 +0100 |
parents | 8b614632568c |
children | 1d526ba11a24 |
comparison
equal
deleted
inserted
replaced
769:336ccf8fc3f8 | 770:734ee80286c3 |
---|---|
30 SingleColourLayer::SingleColourLayer() : | 30 SingleColourLayer::SingleColourLayer() : |
31 m_colour(0), | 31 m_colour(0), |
32 m_colourExplicitlySet(false), | 32 m_colourExplicitlySet(false), |
33 m_defaultColourSet(false) | 33 m_defaultColourSet(false) |
34 { | 34 { |
35 // Reference current colour because setDefaulColourFor | |
36 // will unreference it before (possibly) changing it. | |
37 refColor(); | |
35 setDefaultColourFor(0); | 38 setDefaultColourFor(0); |
39 } | |
40 | |
41 SingleColourLayer::~SingleColourLayer() | |
42 { | |
43 unrefColor(); | |
36 } | 44 } |
37 | 45 |
38 QPixmap | 46 QPixmap |
39 SingleColourLayer::getLayerPresentationPixmap(QSize size) const | 47 SingleColourLayer::getLayerPresentationPixmap(QSize size) const |
40 { | 48 { |
150 ColourDatabase *cdb = ColourDatabase::getInstance(); | 158 ColourDatabase *cdb = ColourDatabase::getInstance(); |
151 | 159 |
152 int hint = -1; | 160 int hint = -1; |
153 bool impose = false; | 161 bool impose = false; |
154 if (v) { | 162 if (v) { |
155 if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() && | |
156 m_colourRefCount[m_colour] > 0) { | |
157 m_colourRefCount[m_colour]--; | |
158 } | |
159 // We don't want to call this if !v because that probably | 163 // We don't want to call this if !v because that probably |
160 // means we're being called from the constructor, and this is | 164 // means we're being called from the constructor, and this is |
161 // a virtual function | 165 // a virtual function |
162 hint = getDefaultColourHint(dark, impose); | 166 hint = getDefaultColourHint(dark, impose); |
163 #ifdef DEBUG_COLOUR_SELECTION | 167 #ifdef DEBUG_COLOUR_SELECTION |
172 if (hint >= 0 && impose) { | 176 if (hint >= 0 && impose) { |
173 setBaseColour(hint); | 177 setBaseColour(hint); |
174 return; | 178 return; |
175 } | 179 } |
176 | 180 |
181 unrefColor(); | |
182 | |
177 int bestCount = 0, bestColour = -1; | 183 int bestCount = 0, bestColour = -1; |
178 | 184 |
179 for (int i = 0; i < cdb->getColourCount(); ++i) { | 185 for (int i = 0; i < cdb->getColourCount(); ++i) { |
180 | 186 |
181 int index = i; | 187 int index = i; |
201 | 207 |
202 #ifdef DEBUG_COLOUR_SELECTION | 208 #ifdef DEBUG_COLOUR_SELECTION |
203 cerr << endl; | 209 cerr << endl; |
204 #endif | 210 #endif |
205 } | 211 } |
206 | 212 |
207 if (bestColour < 0) m_colour = 0; | 213 if (bestColour < 0) m_colour = 0; |
208 else m_colour = bestColour; | 214 else m_colour = bestColour; |
209 | 215 |
210 if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) { | 216 refColor(); |
211 m_colourRefCount[m_colour] = 1; | |
212 } else { | |
213 m_colourRefCount[m_colour]++; | |
214 } | |
215 } | 217 } |
216 | 218 |
217 void | 219 void |
218 SingleColourLayer::setBaseColour(int colour) | 220 SingleColourLayer::setBaseColour(int colour) |
219 { | 221 { |
220 m_colourExplicitlySet = true; | 222 m_colourExplicitlySet = true; |
221 | 223 |
222 if (m_colour == colour) return; | 224 if (m_colour == colour) return; |
223 | 225 |
224 if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() && | 226 refColor(); |
225 m_colourRefCount[m_colour] > 0) { | |
226 m_colourRefCount[m_colour]--; | |
227 } | |
228 | |
229 m_colour = colour; | 227 m_colour = colour; |
230 | 228 unrefColor(); |
231 if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) { | |
232 m_colourRefCount[m_colour] = 1; | |
233 } else { | |
234 m_colourRefCount[m_colour]++; | |
235 } | |
236 | 229 |
237 flagBaseColourChanged(); | 230 flagBaseColourChanged(); |
238 emit layerParametersChanged(); | 231 emit layerParametersChanged(); |
239 } | 232 } |
240 | 233 |
305 QString darkbg = attributes.value("darkBackground"); | 298 QString darkbg = attributes.value("darkBackground"); |
306 | 299 |
307 int colour = ColourDatabase::getInstance()->putStringValues | 300 int colour = ColourDatabase::getInstance()->putStringValues |
308 (colourName, colourSpec, darkbg); | 301 (colourName, colourSpec, darkbg); |
309 | 302 |
303 if (colour == -1) | |
304 return; | |
305 | |
310 m_colourExplicitlySet = true; | 306 m_colourExplicitlySet = true; |
311 | 307 |
312 if (m_colour != colour) { | 308 if (m_colour != colour) { |
313 | 309 |
314 #ifdef DEBUG_COLOUR_SELECTION | 310 #ifdef DEBUG_COLOUR_SELECTION |
315 SVDEBUG << "SingleColourLayer::setProperties: changing colour from " << m_colour << " to " << colour << endl; | 311 SVDEBUG << "SingleColourLayer::setProperties: changing colour from " << m_colour << " to " << colour << endl; |
316 #endif | 312 #endif |
317 | 313 |
318 if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() && | 314 unrefColor(); |
319 m_colourRefCount[m_colour] > 0) { | |
320 m_colourRefCount[m_colour]--; | |
321 } | |
322 | |
323 m_colour = colour; | 315 m_colour = colour; |
324 | 316 refColor(); |
325 if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) { | |
326 m_colourRefCount[m_colour] = 1; | |
327 } else { | |
328 m_colourRefCount[m_colour]++; | |
329 } | |
330 | 317 |
331 flagBaseColourChanged(); | 318 flagBaseColourChanged(); |
332 } | 319 } |
333 } | 320 } |
334 | 321 |
322 void SingleColourLayer::refColor() | |
323 { | |
324 if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) { | |
325 m_colourRefCount[m_colour] = 1; | |
326 } else { | |
327 m_colourRefCount[m_colour]++; | |
328 } | |
329 } | |
330 | |
331 void SingleColourLayer::unrefColor() | |
332 { | |
333 if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() && | |
334 m_colourRefCount[m_colour] > 0) { | |
335 m_colourRefCount[m_colour]--; | |
336 } | |
337 } |