+QString GuiPainter::generateStringSignature(QString const & str, FontInfo const & f)
+{
+ QString sig = str;
+ sig.append(QChar(static_cast<short>(f.family())));
+ sig.append(QChar(static_cast<short>(f.series())));
+ sig.append(QChar(static_cast<short>(f.realShape())));
+ sig.append(QChar(static_cast<short>(f.size())));
+ sig.append(QChar(static_cast<short>(f.color())));
+ if (!monochrome_min_.empty()) {
+ QColor const & min = monochrome_min_.top();
+ QColor const & max = monochrome_max_.top();
+ sig.append(QChar(static_cast<short>(min.red())));
+ sig.append(QChar(static_cast<short>(min.green())));
+ sig.append(QChar(static_cast<short>(min.blue())));
+ sig.append(QChar(static_cast<short>(max.red())));
+ sig.append(QChar(static_cast<short>(max.green())));
+ sig.append(QChar(static_cast<short>(max.blue())));
+ }
+ return sig;
+}
+
+
+QColor GuiPainter::computeColor(ColorCode col)
+{
+ return filterColor(guiApp->colorCache().get(col));
+}
+
+
+QColor GuiPainter::filterColor(QColor const & col)
+{
+ if (monochrome_min_.empty())
+ return col;
+
+ // map into [min,max] interval
+ QColor const & min = monochrome_min_.top();
+ QColor const & max = monochrome_max_.top();
+
+ qreal v = col.valueF();
+ v = v * v; // make it a bit steeper (i.e. darker)
+
+ qreal minr, ming, minb;
+ qreal maxr, maxg, maxb;
+ min.getRgbF(&minr, &ming, &minb);
+ max.getRgbF(&maxr, &maxg, &maxb);
+
+ return QColor(v*minr+(1-v)*maxr, v*ming+(1-v)*maxg, v*minb+(1-v)*maxb);
+}
+
+
+void GuiPainter::enterMonochromeMode(ColorCode const & min, ColorCode const & max)
+{
+ QColor qmin = filterColor(guiApp->colorCache().get(min));
+ QColor qmax = filterColor(guiApp->colorCache().get(max));
+ monochrome_min_.push(qmin);
+ monochrome_max_.push(qmax);
+}
+
+
+void GuiPainter::leaveMonochromeMode()
+{
+ BOOST_ASSERT(!monochrome_min_.empty());
+ monochrome_min_.pop();
+ monochrome_max_.pop();
+}
+
+