Mercurial > hg > svgui
comparison layer/SingleColourLayer.cpp @ 293:15b8a4bfe855
* continue to pick "new" colours for coloured layers even when all colours
have been used at least once, rather than sticking on the last one
* some messing about with application palette settings
* when replacing an audio file, retain the previous playback settings for
any layers that depended on the old file
* re-check plugin program setting when a parameter changes -- so a plugin
can decide to reset the program if the parameters no longer match those
for the current program
* fix failure to update check-boxes for toggled plugin parameters when their
parameters are changed by program changes
author | Chris Cannam |
---|---|
date | Thu, 09 Aug 2007 14:40:03 +0000 |
parents | cd2492c5fe45 |
children | 919740b20cc9 |
comparison
equal
deleted
inserted
replaced
292:24fc90078754 | 293:15b8a4bfe855 |
---|---|
19 | 19 |
20 #include <iostream> | 20 #include <iostream> |
21 | 21 |
22 #include <QApplication> | 22 #include <QApplication> |
23 | 23 |
24 SingleColourLayer::ColourIndexPool | 24 SingleColourLayer::ColourRefCount |
25 SingleColourLayer::m_usedColourIndices; | 25 SingleColourLayer::m_colourRefCount; |
26 | 26 |
27 SingleColourLayer::SingleColourLayer() : | 27 SingleColourLayer::SingleColourLayer() : |
28 m_colour(0) | 28 m_colour(0) |
29 { | 29 { |
30 setDefaultColourFor(0); | 30 setDefaultColourFor(0); |
117 void | 117 void |
118 SingleColourLayer::setDefaultColourFor(View *v) | 118 SingleColourLayer::setDefaultColourFor(View *v) |
119 { | 119 { |
120 bool dark = false; | 120 bool dark = false; |
121 if (v) { | 121 if (v) { |
122 ColourIndexPool::iterator i = m_usedColourIndices.find(m_colour); | |
123 if (i != m_usedColourIndices.end()) m_usedColourIndices.erase(i); | |
124 dark = !v->hasLightBackground(); | 122 dark = !v->hasLightBackground(); |
125 } else { | 123 } else { |
126 QColor bg = QApplication::palette().color(QPalette::Window); | 124 QColor bg = QApplication::palette().color(QPalette::Window); |
127 if (bg.red() + bg.green() + bg.blue() < 384) dark = true; | 125 if (bg.red() + bg.green() + bg.blue() < 384) dark = true; |
128 } | 126 } |
129 | 127 |
130 m_colour = -1; | |
131 ColourDatabase *cdb = ColourDatabase::getInstance(); | 128 ColourDatabase *cdb = ColourDatabase::getInstance(); |
132 | 129 |
133 int hint = -1; | 130 int hint = -1; |
134 bool impose = false; | 131 bool impose = false; |
135 if (v) { | 132 if (v) { |
133 if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() && | |
134 m_colourRefCount[m_colour] > 0) { | |
135 m_colourRefCount[m_colour]--; | |
136 } | |
136 // We don't want to call this if !v because that probably | 137 // We don't want to call this if !v because that probably |
137 // means we're being called from the constructor, and this is | 138 // means we're being called from the constructor, and this is |
138 // a virtual function | 139 // a virtual function |
139 hint = getDefaultColourHint(dark, impose); | 140 hint = getDefaultColourHint(dark, impose); |
140 std::cerr << "hint = " << hint << ", impose = " << impose << std::endl; | 141 // std::cerr << "hint = " << hint << ", impose = " << impose << std::endl; |
142 } else { | |
143 // std::cerr << "(from ctor)" << std::endl; | |
141 } | 144 } |
142 | 145 |
143 if (hint >= 0 && impose) { | 146 if (hint >= 0 && impose) { |
144 m_colour = hint; | 147 setBaseColour(hint); |
145 m_usedColourIndices.insert(m_colour); | |
146 return; | 148 return; |
147 } | 149 } |
148 | 150 |
151 int bestCount = 0, bestColour = -1; | |
152 | |
149 for (int i = 0; i < cdb->getColourCount(); ++i) { | 153 for (int i = 0; i < cdb->getColourCount(); ++i) { |
154 | |
150 int index = i; | 155 int index = i; |
151 if (hint > 0) index = (index + hint) % cdb->getColourCount(); | 156 if (hint > 0) index = (index + hint) % cdb->getColourCount(); |
152 if (cdb->useDarkBackground(index) != dark) continue; | 157 if (cdb->useDarkBackground(index) != dark) continue; |
153 if (m_colour < 0) m_colour = index; | 158 |
154 if (m_usedColourIndices.find(index) == m_usedColourIndices.end()) { | 159 int count = 0; |
155 m_colour = index; | 160 if (m_colourRefCount.find(index) != m_colourRefCount.end()) { |
156 break; | 161 count = m_colourRefCount[index]; |
157 } | 162 } |
158 } | 163 |
159 | 164 // std::cerr << "index = " << index << ", count = " << count; |
160 if (m_colour < 0) m_colour = 0; | 165 |
161 m_usedColourIndices.insert(m_colour); | 166 if (bestColour < 0 || count < bestCount) { |
167 bestColour = index; | |
168 bestCount = count; | |
169 // std::cerr << " *"; | |
170 } | |
171 | |
172 // std::cerr << std::endl; | |
173 } | |
174 | |
175 if (bestColour < 0) m_colour = 0; | |
176 else m_colour = bestColour; | |
177 | |
178 if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) { | |
179 m_colourRefCount[m_colour] = 1; | |
180 } else { | |
181 m_colourRefCount[m_colour]++; | |
182 } | |
162 } | 183 } |
163 | 184 |
164 void | 185 void |
165 SingleColourLayer::setBaseColour(int colour) | 186 SingleColourLayer::setBaseColour(int colour) |
166 { | 187 { |
167 if (m_colour == colour) return; | 188 if (m_colour == colour) return; |
168 ColourIndexPool::iterator i = m_usedColourIndices.find(m_colour); | 189 |
169 if (i != m_usedColourIndices.end()) m_usedColourIndices.erase(i); | 190 if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() && |
191 m_colourRefCount[m_colour] > 0) { | |
192 m_colourRefCount[m_colour]--; | |
193 } | |
194 | |
170 m_colour = colour; | 195 m_colour = colour; |
171 m_usedColourIndices.insert(m_colour); | 196 |
197 if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) { | |
198 m_colourRefCount[m_colour] = 1; | |
199 } else { | |
200 m_colourRefCount[m_colour]++; | |
201 } | |
202 | |
172 flagBaseColourChanged(); | 203 flagBaseColourChanged(); |
173 emit layerParametersChanged(); | 204 emit layerParametersChanged(); |
174 } | 205 } |
175 | 206 |
176 int | 207 int |