Fixed font height for custom text displaying
This commit is contained in:
parent
eacf588546
commit
d68deebf87
1 changed files with 9 additions and 2 deletions
11
ui/painter.h
11
ui/painter.h
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue