int preeditText(int, int, char_type, FontInfo const &,
preedit_style) { return 0; }
- /// start monochrome painting mode, i.e. map every color into [min,max]
- void enterMonochromeMode(Color const &, Color const &) {}
+ /// start monochrome painting mode, i.e. map every color a shade of \c blend.
+ void enterMonochromeMode(Color const &) {}
/// leave monochrome painting mode
void leaveMonochromeMode() {}
/// draws a wavy line that can be used for underlining.
virtual int preeditText(int x, int y,
char_type c, FontInfo const & f, preedit_style style) = 0;
- /// start monochrome painting mode, i.e. map every color into [min,max]
- virtual void enterMonochromeMode(Color const & min,
- Color const & max) = 0;
+ /// start monochrome painting mode, i.e. map every color a shade of \c blend.
+ virtual void enterMonochromeMode(Color const & blend) = 0;
/// leave monochrome painting mode
virtual void leaveMonochromeMode() = 0;
/// draws a wavy line that can be used for underlining.
QColor GuiPainter::filterColor(QColor const & col)
{
- if (monochrome_min_.empty())
+ if (monochrome_blend_.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; // 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);
-
- QColor c;
- c.setRgbF(
- v * (minr - maxr) + maxr,
- v * (ming - maxg) + maxg,
- v * (minb - maxb) + maxb);
- return c;
+ QColor const blend = monochrome_blend_.top();
+ return QColor::fromHsv(blend.hue(), blend.saturation(), qGray(col.rgb()));
}
-void GuiPainter::enterMonochromeMode(Color const & min, Color const & max)
+void GuiPainter::enterMonochromeMode(Color const & blend)
{
- QColor qmin = filterColor(guiApp->colorCache().get(min));
- QColor qmax = filterColor(guiApp->colorCache().get(max));
- monochrome_min_.push(qmin);
- monochrome_max_.push(qmax);
+ QColor qblend = filterColor(guiApp->colorCache().get(blend));
+ monochrome_blend_.push(qblend);
}
void GuiPainter::leaveMonochromeMode()
{
- LASSERT(!monochrome_min_.empty(), return);
- monochrome_min_.pop();
- monochrome_max_.pop();
+ LASSERT(!monochrome_blend_.empty(), return);
+ monochrome_blend_.pop();
}
virtual void buttonText(int x, int baseline, docstring const & s,
FontInfo const & font, Color back, Color frame, int offset);
- /// start monochrome painting mode, i.e. map every color into [min,max]
- virtual void enterMonochromeMode(Color const & min,
- Color const & max);
+ /// start monochrome painting mode, i.e. map every color a shade of \c blend.
+ virtual void enterMonochromeMode(Color const & blend);
/// leave monochrome painting mode
virtual void leaveMonochromeMode();
Painter::line_style current_ls_;
int current_lw_;
///
- std::stack<QColor> monochrome_min_;
- ///
- std::stack<QColor> monochrome_max_;
+ std::stack<QColor> monochrome_blend_;
/// convert into Qt color, possibly applying the monochrome mode
QColor computeColor(Color col);
/// possibly apply monochrome mode
void afterDraw(PainterInfo const & pi) const
{
if (mathMacro_->editMetrics(pi.base.bv))
- pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend);
+ pi.pain.enterMonochromeMode(Color_mathmacroblend);
}
///
void metrics(MetricsInfo &, Dimension &) const {
void InsetMathMacro::beforeDraw(PainterInfo const & pi) const
{
if (d->editing_[pi.base.bv])
- pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend);
+ pi.pain.enterMonochromeMode(Color_mathmacroblend);
}
class InsetColoredCell : public InsetMathNest {
public:
///
- InsetColoredCell(Buffer * buf, ColorCode min, ColorCode max);
+ InsetColoredCell(Buffer * buf, ColorCode blend);
///
- InsetColoredCell(Buffer * buf, ColorCode min, ColorCode max, MathAtom const & atom);
+ InsetColoredCell(Buffer * buf, ColorCode blend, MathAtom const & atom);
///
void draw(PainterInfo &, int x, int y) const;
///
///
Inset * clone() const;
///
- ColorCode min_;
- ///
- ColorCode max_;
+ ColorCode blend_;
};
-InsetColoredCell::InsetColoredCell(Buffer * buf, ColorCode min, ColorCode max)
- : InsetMathNest(buf, 1), min_(min), max_(max)
+InsetColoredCell::InsetColoredCell(Buffer * buf, ColorCode blend)
+ : InsetMathNest(buf, 1), blend_(blend)
{
}
-InsetColoredCell::InsetColoredCell(Buffer * buf, ColorCode min, ColorCode max, MathAtom const & atom)
- : InsetMathNest(buf, 1), min_(min), max_(max)
+InsetColoredCell::InsetColoredCell(Buffer * buf, ColorCode blend, MathAtom const & atom)
+ : InsetMathNest(buf, 1), blend_(blend)
{
cell(0).insert(0, atom);
}
void InsetColoredCell::draw(PainterInfo & pi, int x, int y) const
{
- pi.pain.enterMonochromeMode(min_, max_);
+ pi.pain.enterMonochromeMode(blend_);
cell(0).draw(pi, x, y);
pi.pain.leaveMonochromeMode();
}
// color it light grey, if it is to be removed when the cursor leaves
if (i == argsInLook_) {
optData->push_back(MathAtom(
- new InsetColoredCell(buffer_, Color_mathbg, Color_mathmacrooldarg)));
+ new InsetColoredCell(buffer_, Color_mathmacrooldarg)));
optData = &(*optData)[optData->size() - 1].nucleus()->cell(0);
}
arg.push_back(MathAtom(new InsetMathMacroArgument(i + 1)));
if (i >= argsInLook_) {
look_.push_back(MathAtom(new InsetColoredCell(buffer_,
- Color_mathbg, Color_mathmacrooldarg,
+ Color_mathmacrooldarg,
MathAtom(new InsetMathBrace(arg)))));
} else
look_.push_back(MathAtom(new InsetMathBrace(arg)));
MathData arg;
arg.push_back(MathAtom(new InsetMathMacroArgument(i + 1)));
look_.push_back(MathAtom(new InsetColoredCell(buffer_,
- Color_mathbg, Color_mathmacronewarg,
+ Color_mathmacronewarg,
MathAtom(new InsetMathBrace(arg)))));
}