mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
Use the same code for editable and non-editable buttons
This removes the use of rectText in RenderButton. The fact that this gave different spacing than buttonText was a problem. Now buttonText requires to specify * the offset, so that INSET_TO_TEXT_OFFSET is not used anymore in src/frontends/, which will be useful later. * the background and frame color, in replacement for the hover state. Remove the methods button() and buttonFrame() from GuiPainter. Remove some unused header files. Fixes bug #10704.
This commit is contained in:
parent
530fec453f
commit
62b06c64ed
@ -125,9 +125,10 @@ public:
|
|||||||
int & descent) const = 0;
|
int & descent) const = 0;
|
||||||
/**
|
/**
|
||||||
* fill in width,ascent,descent with the values for the
|
* 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,
|
virtual void buttonText(docstring const & str,
|
||||||
|
const int offset,
|
||||||
int & width,
|
int & width,
|
||||||
int & ascent,
|
int & ascent,
|
||||||
int & descent) const = 0;
|
int & descent) const = 0;
|
||||||
|
@ -123,9 +123,6 @@ public:
|
|||||||
/// draw a pixel
|
/// draw a pixel
|
||||||
virtual void point(int x, int y, Color) = 0;
|
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
|
/// draw an image from the image cache
|
||||||
virtual void image(int x, int y, int w, int h,
|
virtual void image(int x, int y, int w, int h,
|
||||||
graphics::Image const & image) = 0;
|
graphics::Image const & image) = 0;
|
||||||
@ -172,7 +169,7 @@ public:
|
|||||||
|
|
||||||
/// draw a string and enclose it inside a button frame
|
/// draw a string and enclose it inside a button frame
|
||||||
virtual void buttonText(int x, int baseline, docstring const & s,
|
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.
|
/// draw a character of a preedit string for cjk support.
|
||||||
virtual int preeditText(int x, int y,
|
virtual int preeditText(int x, int y,
|
||||||
|
@ -16,10 +16,6 @@
|
|||||||
#include "qt_helpers.h"
|
#include "qt_helpers.h"
|
||||||
|
|
||||||
#include "Dimension.h"
|
#include "Dimension.h"
|
||||||
#include "Language.h"
|
|
||||||
#include "LyXRC.h"
|
|
||||||
|
|
||||||
#include "insets/Inset.h"
|
|
||||||
|
|
||||||
#include "support/convert.h"
|
#include "support/convert.h"
|
||||||
#include "support/lassert.h"
|
#include "support/lassert.h"
|
||||||
@ -448,19 +444,20 @@ bool GuiFontMetrics::breakAt(docstring & s, int & x, bool const rtl, bool const
|
|||||||
void GuiFontMetrics::rectText(docstring const & str,
|
void GuiFontMetrics::rectText(docstring const & str,
|
||||||
int & w, int & ascent, int & descent) const
|
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;
|
w = width(str) + offset;
|
||||||
ascent = metrics_.ascent() + d;
|
ascent = metrics_.ascent() + offset / 2;
|
||||||
descent = metrics_.descent() + d;
|
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
|
int & w, int & ascent, int & descent) const
|
||||||
{
|
{
|
||||||
rectText(str, w, ascent, descent);
|
rectText(str, w, ascent, descent);
|
||||||
w += Inset::TEXT_TO_INSET_OFFSET;
|
w += offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ public:
|
|||||||
int & ascent,
|
int & ascent,
|
||||||
int & descent) const;
|
int & descent) const;
|
||||||
virtual void buttonText(docstring const & str,
|
virtual void buttonText(docstring const & str,
|
||||||
|
const int offset,
|
||||||
int & width,
|
int & width,
|
||||||
int & ascent,
|
int & ascent,
|
||||||
int & descent) const;
|
int & descent) const;
|
||||||
|
@ -21,11 +21,8 @@
|
|||||||
#include "qt_helpers.h"
|
#include "qt_helpers.h"
|
||||||
|
|
||||||
#include "Font.h"
|
#include "Font.h"
|
||||||
#include "Language.h"
|
|
||||||
#include "LyXRC.h"
|
#include "LyXRC.h"
|
||||||
|
|
||||||
#include "insets/Inset.h"
|
|
||||||
|
|
||||||
#include "support/debug.h"
|
#include "support/debug.h"
|
||||||
#include "support/lassert.h"
|
#include "support/lassert.h"
|
||||||
#include "support/lyxlib.h"
|
#include "support/lyxlib.h"
|
||||||
@ -557,31 +554,10 @@ void GuiPainter::textDecoration(FontInfo const & f, int x, int y, int width)
|
|||||||
static int max(int a, int b) { return a > b ? a : b; }
|
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,
|
void GuiPainter::rectText(int x, int y, docstring const & str,
|
||||||
FontInfo const & font, Color back, Color frame)
|
FontInfo const & font, Color back, Color frame)
|
||||||
{
|
{
|
||||||
int width;
|
int width, ascent, descent;
|
||||||
int ascent;
|
|
||||||
int descent;
|
|
||||||
|
|
||||||
FontMetrics const & fm = theFontMetrics(font);
|
FontMetrics const & fm = theFontMetrics(font);
|
||||||
fm.rectText(str, width, ascent, descent);
|
fm.rectText(str, width, ascent, descent);
|
||||||
@ -593,24 +569,25 @@ void GuiPainter::rectText(int x, int y, docstring const & str,
|
|||||||
if (frame != Color_none)
|
if (frame != Color_none)
|
||||||
rectangle(x, y - ascent, width, ascent + descent, frame);
|
rectangle(x, y - ascent, width, ascent + descent, frame);
|
||||||
|
|
||||||
|
// FIXME: let offset depend on font
|
||||||
text(x + 3, y, str, font);
|
text(x + 3, y, str, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiPainter::buttonText(int x, int y, docstring const & str,
|
void GuiPainter::buttonText(int x, int baseline, docstring const & s,
|
||||||
FontInfo const & font, bool mouseHover)
|
FontInfo const & font, Color back, Color frame, int offset)
|
||||||
{
|
{
|
||||||
int width;
|
int width, ascent, descent;
|
||||||
int ascent;
|
|
||||||
int descent;
|
|
||||||
|
|
||||||
FontMetrics const & fm = theFontMetrics(font);
|
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);
|
fillRectangle(x + d + 1, baseline - ascent + 1, width - offset - 1,
|
||||||
text(x + Inset::TEXT_TO_INSET_OFFSET, y, str, font);
|
ascent + descent - 1, back);
|
||||||
|
rectangle(x + d, baseline - ascent, width - offset, ascent + descent, frame);
|
||||||
|
text(x + offset, baseline, s, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ public:
|
|||||||
|
|
||||||
/// draw a string and enclose it inside a button frame
|
/// draw a string and enclose it inside a button frame
|
||||||
virtual void buttonText(int x, int baseline, docstring const & s,
|
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]
|
/// start monochrome painting mode, i.e. map every color into [min,max]
|
||||||
virtual void enterMonochromeMode(Color const & min,
|
virtual void enterMonochromeMode(Color const & min,
|
||||||
@ -147,9 +147,6 @@ public:
|
|||||||
virtual void rectText(int x, int baseline, docstring const & str,
|
virtual void rectText(int x, int baseline, docstring const & str,
|
||||||
FontInfo const & font, Color back, Color frame);
|
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.
|
/// draw a character of a preedit string for cjk support.
|
||||||
virtual int preeditText(int x, int y,
|
virtual int preeditText(int x, int y,
|
||||||
char_type c, FontInfo const & f, preedit_style style);
|
char_type c, FontInfo const & f, preedit_style style);
|
||||||
@ -177,9 +174,6 @@ private:
|
|||||||
void doubleUnderline(FontInfo const & f,
|
void doubleUnderline(FontInfo const & f,
|
||||||
int x, int y, int width);
|
int x, int y, int width);
|
||||||
|
|
||||||
/// draw a bevelled button border
|
|
||||||
void buttonFrame(int x, int y, int w, int h);
|
|
||||||
|
|
||||||
/// set pen parameters
|
/// set pen parameters
|
||||||
void setQPainterPen(QColor const & col,
|
void setQPainterPen(QColor const & col,
|
||||||
line_style ls = line_solid, int lw = thin_line);
|
line_style ls = line_solid, int lw = thin_line);
|
||||||
|
@ -148,7 +148,7 @@ Dimension InsetCollapsable::dimensionCollapsed(BufferView const & bv) const
|
|||||||
FontInfo labelfont(getLabelfont());
|
FontInfo labelfont(getLabelfont());
|
||||||
labelfont.realize(sane_font);
|
labelfont.realize(sane_font);
|
||||||
theFontMetrics(labelfont).buttonText(
|
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;
|
return dim;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,7 +247,8 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
|
|||||||
labelfont.setColor(labelColor());
|
labelfont.setColor(labelColor());
|
||||||
labelfont.realize(pi.base.font);
|
labelfont.realize(pi.base.font);
|
||||||
pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
|
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
|
// Draw the change tracking cue on the label, unless RowPainter already
|
||||||
// takes care of it.
|
// takes care of it.
|
||||||
if (canPaintChange(bv))
|
if (canPaintChange(bv))
|
||||||
|
@ -45,13 +45,9 @@ void RenderButton::metrics(MetricsInfo & mi, Dimension & dim) const
|
|||||||
{
|
{
|
||||||
FontInfo font = inherit_font_ ? mi.base.font : sane_font;
|
FontInfo font = inherit_font_ ? mi.base.font : sane_font;
|
||||||
font.decSize();
|
font.decSize();
|
||||||
frontend::FontMetrics const & fm =
|
frontend::FontMetrics const & fm = theFontMetrics(font);
|
||||||
theFontMetrics(font);
|
|
||||||
|
|
||||||
if (editable_)
|
fm.buttonText(text_, Inset::TEXT_TO_INSET_OFFSET, dim.wid, dim.asc, dim.des);
|
||||||
fm.buttonText(text_, dim.wid, dim.asc, dim.des);
|
|
||||||
else
|
|
||||||
fm.rectText(text_, dim.wid, dim.asc, dim.des);
|
|
||||||
|
|
||||||
dim_ = dim;
|
dim_ = dim;
|
||||||
}
|
}
|
||||||
@ -65,10 +61,13 @@ void RenderButton::draw(PainterInfo & pi, int x, int y) const
|
|||||||
font.decSize();
|
font.decSize();
|
||||||
|
|
||||||
if (editable_) {
|
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 {
|
} else {
|
||||||
pi.pain.rectText(x, y, text_, font,
|
pi.pain.buttonText(x, y, text_, font,
|
||||||
Color_commandbg, Color_commandframe);
|
Color_commandbg, Color_commandframe,
|
||||||
|
Inset::TEXT_TO_INSET_OFFSET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user