int & descent) const = 0;
/**
* fill in width,ascent,descent with the values for the
- * given string in the font for a button.
+ * given string in the font for a button with given offset.
*/
virtual void buttonText(docstring const & str,
+ const int offset,
int & width,
int & ascent,
int & descent) const = 0;
/// draw a pixel
virtual void point(int x, int y, Color) = 0;
- /// draw a filled rectangle with the shape of a 3D button
- virtual void button(int x, int y, int w, int h, bool mouseHover) = 0;
-
/// draw an image from the image cache
virtual void image(int x, int y, int w, int h,
graphics::Image const & image) = 0;
/// draw a string and enclose it inside a button frame
virtual void buttonText(int x, int baseline, docstring const & s,
- FontInfo const & font, bool mouseHover) = 0;
+ FontInfo const & font, Color back, Color frame, int offset) = 0;
/// draw a character of a preedit string for cjk support.
virtual int preeditText(int x, int y,
#include "qt_helpers.h"
#include "Dimension.h"
-#include "Language.h"
-#include "LyXRC.h"
-
-#include "insets/Inset.h"
#include "support/convert.h"
#include "support/lassert.h"
void GuiFontMetrics::rectText(docstring const & str,
int & w, int & ascent, int & descent) const
{
- static int const d = Inset::TEXT_TO_INSET_OFFSET / 2;
+ // FIXME: let offset depend on font (this is Inset::TEXT_TO_OFFSET)
+ int const offset = 4;
- w = width(str) + Inset::TEXT_TO_INSET_OFFSET;
- ascent = metrics_.ascent() + d;
- descent = metrics_.descent() + d;
+ w = width(str) + offset;
+ ascent = metrics_.ascent() + offset / 2;
+ descent = metrics_.descent() + offset / 2;
}
-void GuiFontMetrics::buttonText(docstring const & str,
+void GuiFontMetrics::buttonText(docstring const & str, const int offset,
int & w, int & ascent, int & descent) const
{
rectText(str, w, ascent, descent);
- w += Inset::TEXT_TO_INSET_OFFSET;
+ w += offset;
}
int & ascent,
int & descent) const;
virtual void buttonText(docstring const & str,
+ const int offset,
int & width,
int & ascent,
int & descent) const;
#include "qt_helpers.h"
#include "Font.h"
-#include "Language.h"
#include "LyXRC.h"
-#include "insets/Inset.h"
-
#include "support/debug.h"
#include "support/lassert.h"
#include "support/lyxlib.h"
static int max(int a, int b) { return a > b ? a : b; }
-void GuiPainter::button(int x, int y, int w, int h, bool mouseHover)
-{
- if (mouseHover)
- fillRectangle(x, y, w, h, Color_buttonhoverbg);
- else
- fillRectangle(x, y, w, h, Color_buttonbg);
- buttonFrame(x, y, w, h);
-}
-
-
-void GuiPainter::buttonFrame(int x, int y, int w, int h)
-{
- line(x, y, x, y + h - 1, Color_buttonframe);
- line(x - 1 + w, y, x - 1 + w, y + h - 1, Color_buttonframe);
- line(x, y - 1, x - 1 + w, y - 1, Color_buttonframe);
- line(x, y + h - 1, x - 1 + w, y + h - 1, Color_buttonframe);
-}
-
-
void GuiPainter::rectText(int x, int y, docstring const & str,
FontInfo const & font, Color back, Color frame)
{
- int width;
- int ascent;
- int descent;
+ int width, ascent, descent;
FontMetrics const & fm = theFontMetrics(font);
fm.rectText(str, width, ascent, descent);
if (frame != Color_none)
rectangle(x, y - ascent, width, ascent + descent, frame);
+ // FIXME: let offset depend on font
text(x + 3, y, str, font);
}
-void GuiPainter::buttonText(int x, int y, docstring const & str,
- FontInfo const & font, bool mouseHover)
+void GuiPainter::buttonText(int x, int baseline, docstring const & s,
+ FontInfo const & font, Color back, Color frame, int offset)
{
- int width;
- int ascent;
- int descent;
+ int width, ascent, descent;
FontMetrics const & fm = theFontMetrics(font);
- fm.buttonText(str, width, ascent, descent);
+ fm.buttonText(s, offset, width, ascent, descent);
- static int const d = Inset::TEXT_TO_INSET_OFFSET / 2;
+ static int const d = offset / 2;
- button(x + d, y - ascent, width - Inset::TEXT_TO_INSET_OFFSET, descent + ascent, mouseHover);
- text(x + Inset::TEXT_TO_INSET_OFFSET, y, str, font);
+ fillRectangle(x + d + 1, baseline - ascent + 1, width - offset - 1,
+ ascent + descent - 1, back);
+ rectangle(x + d, baseline - ascent, width - offset, ascent + descent, frame);
+ text(x + offset, baseline, s, font);
}
/// draw a string and enclose it inside a button frame
virtual void buttonText(int x, int baseline, docstring const & s,
- FontInfo const & font, bool mouseHover);
+ 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,
virtual void rectText(int x, int baseline, docstring const & str,
FontInfo const & font, Color back, Color frame);
- /// draw a filled rectangle with the shape of a 3D button
- virtual void button(int x, int y, int w, int h, bool mouseHover);
-
/// draw a character of a preedit string for cjk support.
virtual int preeditText(int x, int y,
char_type c, FontInfo const & f, preedit_style style);
void doubleUnderline(FontInfo const & f,
int x, int y, int width);
- /// draw a bevelled button border
- void buttonFrame(int x, int y, int w, int h);
-
/// set pen parameters
void setQPainterPen(QColor const & col,
line_style ls = line_solid, int lw = thin_line);
FontInfo labelfont(getLabelfont());
labelfont.realize(sane_font);
theFontMetrics(labelfont).buttonText(
- buttonLabel(bv), dim.wid, dim.asc, dim.des);
+ buttonLabel(bv), TEXT_TO_INSET_OFFSET, dim.wid, dim.asc, dim.des);
return dim;
}
labelfont.setColor(labelColor());
labelfont.realize(pi.base.font);
pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
- view_[&bv].mouse_hover_);
+ view_[&bv].mouse_hover_ ? Color_buttonhoverbg : Color_buttonbg,
+ Color_buttonframe, TEXT_TO_INSET_OFFSET);
// Draw the change tracking cue on the label, unless RowPainter already
// takes care of it.
if (canPaintChange(bv))
{
FontInfo font = inherit_font_ ? mi.base.font : sane_font;
font.decSize();
- frontend::FontMetrics const & fm =
- theFontMetrics(font);
+ frontend::FontMetrics const & fm = theFontMetrics(font);
- if (editable_)
- fm.buttonText(text_, dim.wid, dim.asc, dim.des);
- else
- fm.rectText(text_, dim.wid, dim.asc, dim.des);
+ fm.buttonText(text_, Inset::TEXT_TO_INSET_OFFSET, dim.wid, dim.asc, dim.des);
dim_ = dim;
}
font.decSize();
if (editable_) {
- pi.pain.buttonText(x, y, text_, font, renderState());
+ pi.pain.buttonText(x, y, text_, font,
+ renderState() ? Color_buttonhoverbg : Color_buttonbg,
+ Color_buttonframe, Inset::TEXT_TO_INSET_OFFSET);
} else {
- pi.pain.rectText(x, y, text_, font,
- Color_commandbg, Color_commandframe);
+ pi.pain.buttonText(x, y, text_, font,
+ Color_commandbg, Color_commandframe,
+ Inset::TEXT_TO_INSET_OFFSET);
}
}