comparison base/ColourDatabase.cpp @ 278:9a13687c078b

* Add SingleColourLayer to manage colours for layers that have a single predominant colour (i.e. most of them).
author Chris Cannam
date Thu, 12 Jul 2007 16:14:59 +0000
parents 3b8008d09541
children
comparison
equal deleted inserted replaced
277:3b8008d09541 278:9a13687c078b
14 */ 14 */
15 15
16 #include "ColourDatabase.h" 16 #include "ColourDatabase.h"
17 #include "XmlExportable.h" 17 #include "XmlExportable.h"
18 18
19 #include <QPainter>
20
19 ColourDatabase 21 ColourDatabase
20 ColourDatabase::m_instance; 22 ColourDatabase::m_instance;
21 23
22 ColourDatabase * 24 ColourDatabase *
23 ColourDatabase::getInstance() 25 ColourDatabase::getInstance()
95 97
96 void 98 void
97 ColourDatabase::setUseDarkBackground(int c, bool dark) 99 ColourDatabase::setUseDarkBackground(int c, bool dark)
98 { 100 {
99 if (c < 0 || size_t(c) >= m_colours.size()) return; 101 if (c < 0 || size_t(c) >= m_colours.size()) return;
100 m_colours[c].darkbg = dark; 102 if (m_colours[c].darkbg != dark) {
103 m_colours[c].darkbg = dark;
104 emit colourDatabaseChanged();
105 }
101 } 106 }
102 107
103 int 108 int
104 ColourDatabase::addColour(QColor c, QString name) 109 ColourDatabase::addColour(QColor c, QString name)
105 { 110 {
180 *max = 0; 185 *max = 0;
181 if (db->getColourCount() > 0) *max = db->getColourCount()-1; 186 if (db->getColourCount() > 0) *max = db->getColourCount()-1;
182 } 187 }
183 } 188 }
184 189
190 QPixmap
191 ColourDatabase::getExamplePixmap(int index, QSize size) const
192 {
193 QPixmap pmap(size);
194 pmap.fill(useDarkBackground(index) ? Qt::black : Qt::white);
195 QPainter paint(&pmap);
196 QColor colour(getColour(index));
197 paint.setPen(colour);
198 paint.setBrush(colour);
199 int margin = 2;
200 if (size.width() < 4 || size.height() < 4) margin = 0;
201 else if (size.width() < 8 || size.height() < 8) margin = 1;
202 paint.drawRect(margin, margin,
203 size.width() - margin*2 - 1, size.height() - margin*2 - 1);
204 return pmap;
205 }
206