Fixed font height for custom text displaying

This commit is contained in:
Eric Kotato 2020-02-26 00:15:50 +03:00
parent eacf588546
commit d68deebf87

View file

@ -18,13 +18,15 @@ public:
void drawTextLeft(int x, int y, int outerw, const QString &text, int textWidth = -1) {
QFontMetrics m(fontMetrics());
auto ascent = (_ascent == 0 ? m.ascent() : _ascent);
if (style::RightToLeft() && textWidth < 0) textWidth = m.width(text);
drawText(style::RightToLeft() ? (outerw - x - textWidth) : x, y + m.ascent(), text);
drawText(style::RightToLeft() ? (outerw - x - textWidth) : x, y + ascent, text);
}
void drawTextRight(int x, int y, int outerw, const QString &text, int textWidth = -1) {
QFontMetrics m(fontMetrics());
auto ascent = (_ascent == 0 ? m.ascent() : _ascent);
if (!style::RightToLeft() && textWidth < 0) textWidth = m.width(text);
drawText(style::RightToLeft() ? x : (outerw - x - textWidth), y + m.ascent(), text);
drawText(style::RightToLeft() ? x : (outerw - x - textWidth), y + ascent, text);
}
void drawPixmapLeft(int x, int y, int outerw, const QPixmap &pix, const QRect &from) {
drawPixmap(QPoint(style::RightToLeft() ? (outerw - x - (from.width() / pix.devicePixelRatio())) : x, y), pix, from);
@ -72,9 +74,14 @@ public:
const style::TextPalette &textPalette() const {
return _textPalette ? *_textPalette : st::defaultTextPalette;
}
void setFont(const style::font &font) {
_ascent = font->ascent;
QPainter::setFont(font);
}
private:
const style::TextPalette *_textPalette = nullptr;
int _ascent = 0;
};