ifdef QFontMetrics::horizontalAdvance to make it work with older Qt
This commit is contained in:
parent
4150e3efde
commit
5f7efee00e
|
@ -713,7 +713,11 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
|
||||||
connect(ui_->analyzer, SIGNAL(WheelEvent(int)), SLOT(VolumeWheelEvent(int)));
|
connect(ui_->analyzer, SIGNAL(WheelEvent(int)), SLOT(VolumeWheelEvent(int)));
|
||||||
|
|
||||||
// Statusbar widgets
|
// Statusbar widgets
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||||
ui_->playlist_summary->setMinimumWidth(QFontMetrics(font()).horizontalAdvance("WW selected of WW tracks - [ WW:WW ]"));
|
ui_->playlist_summary->setMinimumWidth(QFontMetrics(font()).horizontalAdvance("WW selected of WW tracks - [ WW:WW ]"));
|
||||||
|
#else
|
||||||
|
ui_->playlist_summary->setMinimumWidth(QFontMetrics(font()).width("WW selected of WW tracks - [ WW:WW ]"));
|
||||||
|
#endif
|
||||||
ui_->status_bar_stack->setCurrentWidget(ui_->playlist_summary_page);
|
ui_->status_bar_stack->setCurrentWidget(ui_->playlist_summary_page);
|
||||||
connect(ui_->multi_loading_indicator, SIGNAL(TaskCountChange(int)), SLOT(TaskCountChanged(int)));
|
connect(ui_->multi_loading_indicator, SIGNAL(TaskCountChange(int)), SLOT(TaskCountChanged(int)));
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,11 @@ void SizeOverlayDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
|
||||||
|
|
||||||
const QFontMetrics metrics(font);
|
const QFontMetrics metrics(font);
|
||||||
|
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||||
const int text_width = metrics.horizontalAdvance(text);
|
const int text_width = metrics.horizontalAdvance(text);
|
||||||
|
#else
|
||||||
|
const int text_width = metrics.width(text);
|
||||||
|
#endif
|
||||||
|
|
||||||
const QRect icon_rect(option.rect.left(), option.rect.top(), option.rect.width(), option.rect.width());
|
const QRect icon_rect(option.rect.left(), option.rect.top(), option.rect.width(), option.rect.width());
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,11 @@ EqualizerSlider::EqualizerSlider(const QString &label, QWidget *parent)
|
||||||
ui_->band->setText(label);
|
ui_->band->setText(label);
|
||||||
|
|
||||||
QFontMetrics fm = ui_->gain->fontMetrics();
|
QFontMetrics fm = ui_->gain->fontMetrics();
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||||
int longestLabelWidth = fm.horizontalAdvance(tr("%1 dB").arg(-99.99));
|
int longestLabelWidth = fm.horizontalAdvance(tr("%1 dB").arg(-99.99));
|
||||||
|
#else
|
||||||
|
int longestLabelWidth = fm.width(tr("%1 dB").arg(-99.99));
|
||||||
|
#endif
|
||||||
ui_->gain->setMinimumWidth(longestLabelWidth);
|
ui_->gain->setMinimumWidth(longestLabelWidth);
|
||||||
ui_->gain->setText(tr("%1 dB").arg(0)); // Gain [dB]
|
ui_->gain->setText(tr("%1 dB").arg(0)); // Gain [dB]
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,13 @@ void QueuedItemDelegate::DrawBox(QPainter *painter, const QRect &line_rect, cons
|
||||||
smaller.setPointSize(smaller.pointSize() - 1);
|
smaller.setPointSize(smaller.pointSize() - 1);
|
||||||
smaller.setBold(true);
|
smaller.setBold(true);
|
||||||
|
|
||||||
if (width == -1) width = QFontMetrics(font).horizontalAdvance(text + " ");
|
if (width == -1) {
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||||
|
width = QFontMetrics(font).horizontalAdvance(text + " ");
|
||||||
|
#else
|
||||||
|
width = QFontMetrics(font).width(text + " ");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
QRect rect(line_rect);
|
QRect rect(line_rect);
|
||||||
rect.setLeft(rect.right() - width - kQueueBoxBorder);
|
rect.setLeft(rect.right() - width - kQueueBoxBorder);
|
||||||
|
|
|
@ -100,7 +100,11 @@ void PlaylistProxyStyle::drawControl(ControlElement element, const QStyleOption
|
||||||
const QFontMetrics &font_metrics = header_option->fontMetrics;
|
const QFontMetrics &font_metrics = header_option->fontMetrics;
|
||||||
|
|
||||||
// Spaces added to make transition less abrupt
|
// Spaces added to make transition less abrupt
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||||
if (rect.width() < font_metrics.horizontalAdvance(text + " ")) {
|
if (rect.width() < font_metrics.horizontalAdvance(text + " ")) {
|
||||||
|
#else
|
||||||
|
if (rect.width() < font_metrics.width(text + " ")) {
|
||||||
|
#endif
|
||||||
const Playlist::Column column = static_cast<Playlist::Column>(header_option->section);
|
const Playlist::Column column = static_cast<Playlist::Column>(header_option->section);
|
||||||
QStyleOptionHeader new_option(*header_option);
|
QStyleOptionHeader new_option(*header_option);
|
||||||
new_option.text = Playlist::abbreviated_column_name(column);
|
new_option.text = Playlist::abbreviated_column_name(column);
|
||||||
|
|
|
@ -58,8 +58,13 @@ BackendSettingsPage::BackendSettingsPage(SettingsDialog *dialog) : SettingsPage(
|
||||||
ui_->setupUi(this);
|
ui_->setupUi(this);
|
||||||
setWindowIcon(IconLoader::Load("soundcard"));
|
setWindowIcon(IconLoader::Load("soundcard"));
|
||||||
|
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||||
ui_->label_bufferminfillvalue->setMinimumWidth(QFontMetrics(ui_->label_bufferminfillvalue->font()).horizontalAdvance("WW%"));
|
ui_->label_bufferminfillvalue->setMinimumWidth(QFontMetrics(ui_->label_bufferminfillvalue->font()).horizontalAdvance("WW%"));
|
||||||
ui_->label_replaygainpreamp->setMinimumWidth(QFontMetrics(ui_->label_replaygainpreamp->font()).horizontalAdvance("-WW.W dB"));
|
ui_->label_replaygainpreamp->setMinimumWidth(QFontMetrics(ui_->label_replaygainpreamp->font()).horizontalAdvance("-WW.W dB"));
|
||||||
|
#else
|
||||||
|
ui_->label_bufferminfillvalue->setMinimumWidth(QFontMetrics(ui_->label_bufferminfillvalue->font()).width("WW%"));
|
||||||
|
ui_->label_replaygainpreamp->setMinimumWidth(QFontMetrics(ui_->label_replaygainpreamp->font()).width("-WW.W dB"));
|
||||||
|
#endif
|
||||||
RgPreampChanged(ui_->stickslider_replaygainpreamp->value());
|
RgPreampChanged(ui_->stickslider_replaygainpreamp->value());
|
||||||
|
|
||||||
s_.beginGroup(BackendSettingsPage::kSettingsGroup);
|
s_.beginGroup(BackendSettingsPage::kSettingsGroup);
|
||||||
|
|
|
@ -201,7 +201,11 @@ void FreeSpaceBar::DrawText(QPainter* p, const QRect &r) {
|
||||||
|
|
||||||
int text_width = 0;
|
int text_width = 0;
|
||||||
for (const Label &label : labels) {
|
for (const Label &label : labels) {
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||||
text_width += kLabelBoxSize + kLabelBoxPadding + kLabelSpacing + small_metrics.horizontalAdvance(label.text);
|
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
|
// Draw the text
|
||||||
|
@ -216,11 +220,18 @@ void FreeSpaceBar::DrawText(QPainter* p, const QRect &r) {
|
||||||
p->setBrush(label.color);
|
p->setBrush(label.color);
|
||||||
p->drawRect(box);
|
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());
|
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->setPen(light ? label.color.darker() : label.color);
|
||||||
p->drawText(text, Qt::AlignCenter, label.text);
|
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);
|
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;
|
static const int kMargin = 5;
|
||||||
int h = 2 * kMargin + qMax(fm.height(), 14);
|
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;
|
int w = 2 * kMargin + fm.horizontalAdvance("W") * 15;
|
||||||
|
#else
|
||||||
|
int w = 2 * kMargin + fm.width("W") * 15;
|
||||||
|
#endif
|
||||||
|
|
||||||
return QSize(w, h);
|
return QSize(w, h);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,11 @@ MultiLoadingIndicator::MultiLoadingIndicator(QWidget *parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize MultiLoadingIndicator::sizeHint() const {
|
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_);
|
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());
|
const int height = kVerticalPadding * 2 + qMax(spinner_->sizeHint().height(), fontMetrics().height());
|
||||||
|
|
||||||
return QSize(width, height);
|
return QSize(width, height);
|
||||||
|
|
|
@ -87,7 +87,11 @@ void TrackSliderPopup::paintEvent(QPaintEvent*) {
|
||||||
|
|
||||||
void TrackSliderPopup::UpdatePixmap() {
|
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_));
|
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_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());
|
const QRect text_rect2(kBlurRadius + kTextMargin, text_rect1.bottom(), text_width, small_font_metrics_.height());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue