ifdef QFontMetrics::horizontalAdvance to make it work with older Qt
This commit is contained in:
@@ -201,7 +201,11 @@ void FreeSpaceBar::DrawText(QPainter* p, const QRect &r) {
|
||||
|
||||
int text_width = 0;
|
||||
for (const Label &label : labels) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||
text_width += kLabelBoxSize + kLabelBoxPadding + kLabelSpacing + small_metrics.horizontalAdvance(label.text);
|
||||
#else
|
||||
text_width += kLabelBoxSize + kLabelBoxPadding + kLabelSpacing + small_metrics.width(label.text);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Draw the text
|
||||
@@ -216,11 +220,18 @@ void FreeSpaceBar::DrawText(QPainter* p, const QRect &r) {
|
||||
p->setBrush(label.color);
|
||||
p->drawRect(box);
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||
QRect text(x + kLabelBoxSize + kLabelBoxPadding, r.top(), small_metrics.horizontalAdvance(label.text), r.height());
|
||||
#else
|
||||
QRect text(x + kLabelBoxSize + kLabelBoxPadding, r.top(), small_metrics.width(label.text), r.height());
|
||||
#endif
|
||||
p->setPen(light ? label.color.darker() : label.color);
|
||||
p->drawText(text, Qt::AlignCenter, label.text);
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||
x += kLabelBoxSize + kLabelBoxPadding + kLabelSpacing + small_metrics.horizontalAdvance(label.text);
|
||||
#else
|
||||
x += kLabelBoxSize + kLabelBoxPadding + kLabelSpacing + small_metrics.width(label.text);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,7 +48,11 @@ QSize LineTextEdit::sizeHint() const {
|
||||
|
||||
static const int kMargin = 5;
|
||||
int h = 2 * kMargin + qMax(fm.height(), 14);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||
int w = 2 * kMargin + fm.horizontalAdvance("W") * 15;
|
||||
#else
|
||||
int w = 2 * kMargin + fm.width("W") * 15;
|
||||
#endif
|
||||
|
||||
return QSize(w, h);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,11 @@ MultiLoadingIndicator::MultiLoadingIndicator(QWidget *parent)
|
||||
}
|
||||
|
||||
QSize MultiLoadingIndicator::sizeHint() const {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||
const int width = kHorizontalPadding * 2 + spinner_->sizeHint().width() + kSpacing + fontMetrics().horizontalAdvance(text_);
|
||||
#else
|
||||
const int width = kHorizontalPadding * 2 + spinner_->sizeHint().width() + kSpacing + fontMetrics().width(text_);
|
||||
#endif
|
||||
const int height = kVerticalPadding * 2 + qMax(spinner_->sizeHint().height(), fontMetrics().height());
|
||||
|
||||
return QSize(width, height);
|
||||
|
||||
@@ -87,7 +87,11 @@ void TrackSliderPopup::paintEvent(QPaintEvent*) {
|
||||
|
||||
void TrackSliderPopup::UpdatePixmap() {
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||
const int text_width = qMax(font_metrics_.horizontalAdvance(text_), small_font_metrics_.horizontalAdvance(small_text_));
|
||||
#else
|
||||
const int text_width = qMax(font_metrics_.width(text_), small_font_metrics_.width(small_text_));
|
||||
#endif
|
||||
const QRect text_rect1(kBlurRadius + kTextMargin, kBlurRadius + kTextMargin, text_width + 2, font_metrics_.height());
|
||||
const QRect text_rect2(kBlurRadius + kTextMargin, text_rect1.bottom(), text_width, small_font_metrics_.height());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user