Replace QFontMetrics::width with horizontalAdvance, dark with darker, background() with window() and QString::null with QString()

This commit is contained in:
Jonas Kvinge 2019-07-08 22:19:14 +02:00
parent 51462dee1e
commit 870dc0d36f
11 changed files with 18 additions and 18 deletions

View File

@ -345,12 +345,12 @@ void BlockAnalyzer::paletteChange(const QPalette&) {
p.fillRect(0, y * (kHeight + 1), kWidth, kHeight, QColor(r + static_cast<int>(dr * y), g + static_cast<int>(dg * y), b + static_cast<int>(db * y)));
{
const QColor bg = palette().color(QPalette::Background).dark(112);
const QColor bg = palette().color(QPalette::Background).darker(112);
// make a complimentary fadebar colour
// TODO dark is not always correct, dumbo!
int h, s, v;
palette().color(QPalette::Background).dark(150).getHsv(&h, &s, &v);
palette().color(QPalette::Background).darker(150).getHsv(&h, &s, &v);
const QColor fg(QColor::fromHsv(h + 120, s, v));
const double dr = fg.red() - bg.red();
@ -380,7 +380,7 @@ void BlockAnalyzer::drawBackground() {
}
const QColor bg = palette().color(QPalette::Background);
const QColor bgdark = bg.dark(112);
const QColor bgdark = bg.darker(112);
background_.fill(bg);

View File

@ -610,7 +610,7 @@ void ContextView::SetImage(const QImage &image) {
// Cache the current pixmap so we can fade between them
pixmap_previous_ = QPixmap(size());
pixmap_previous_.fill(palette().background().color());
pixmap_previous_.fill(palette().window().color());
pixmap_previous_opacity_ = 1.0;
QPainter p(&pixmap_previous_);

View File

@ -86,7 +86,7 @@ void SizeOverlayDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
const QFontMetrics metrics(font);
const int text_width = metrics.width(text);
const int text_width = metrics.horizontalAdvance(text);
const QRect icon_rect(option.rect.left(), option.rect.top(), option.rect.width(), option.rect.width());

View File

@ -36,7 +36,7 @@ EqualizerSlider::EqualizerSlider(const QString &label, QWidget *parent)
ui_->band->setText(label);
QFontMetrics fm = ui_->gain->fontMetrics();
int longestLabelWidth = fm.width(tr("%1 dB").arg(-99.99));
int longestLabelWidth = fm.horizontalAdvance(tr("%1 dB").arg(-99.99));
ui_->gain->setMinimumWidth(longestLabelWidth);
ui_->gain->setText(tr("%1 dB").arg(0)); // Gain [dB]

View File

@ -117,7 +117,7 @@ void QueuedItemDelegate::DrawBox(QPainter *painter, const QRect &line_rect, cons
smaller.setPointSize(smaller.pointSize() - 1);
smaller.setBold(true);
if (width == -1) width = QFontMetrics(font).width(text + " ");
if (width == -1) width = QFontMetrics(font).horizontalAdvance(text + " ");
QRect rect(line_rect);
rect.setLeft(rect.right() - width - kQueueBoxBorder);
@ -295,7 +295,7 @@ QString LengthItemDelegate::displayText(const QVariant &value, const QLocale&) c
qint64 nanoseconds = value.toLongLong(&ok);
if (ok && nanoseconds > 0) return Utilities::PrettyTimeNanosec(nanoseconds);
return QString::null;
return QString();
}
@ -316,7 +316,7 @@ QString DateItemDelegate::displayText(const QVariant &value, const QLocale &loca
int time = value.toInt(&ok);
if (!ok || time == -1)
return QString::null;
return QString();
return QDateTime::fromTime_t(time).toString(QLocale::system().dateTimeFormat(QLocale::ShortFormat));

View File

@ -100,7 +100,7 @@ void PlaylistProxyStyle::drawControl(ControlElement element, const QStyleOption
const QFontMetrics &font_metrics = header_option->fontMetrics;
// Spaces added to make transition less abrupt
if (rect.width() < font_metrics.width(text + " ")) {
if (rect.width() < font_metrics.horizontalAdvance(text + " ")) {
const Playlist::Column column = static_cast<Playlist::Column>(header_option->section);
QStyleOptionHeader new_option(*header_option);
new_option.text = Playlist::abbreviated_column_name(column);

View File

@ -58,8 +58,8 @@ BackendSettingsPage::BackendSettingsPage(SettingsDialog *dialog) : SettingsPage(
ui_->setupUi(this);
setWindowIcon(IconLoader::Load("soundcard"));
ui_->label_bufferminfillvalue->setMinimumWidth(QFontMetrics(ui_->label_bufferminfillvalue->font()).width("WW%"));
ui_->label_replaygainpreamp->setMinimumWidth(QFontMetrics(ui_->label_replaygainpreamp->font()).width("-WW.W dB"));
ui_->label_bufferminfillvalue->setMinimumWidth(QFontMetrics(ui_->label_bufferminfillvalue->font()).horizontalAdvance("WW%"));
ui_->label_replaygainpreamp->setMinimumWidth(QFontMetrics(ui_->label_replaygainpreamp->font()).horizontalAdvance("-WW.W dB"));
RgPreampChanged(ui_->stickslider_replaygainpreamp->value());
s_.beginGroup(BackendSettingsPage::kSettingsGroup);

View File

@ -201,7 +201,7 @@ void FreeSpaceBar::DrawText(QPainter* p, const QRect &r) {
int text_width = 0;
for (const Label &label : labels) {
text_width += kLabelBoxSize + kLabelBoxPadding + kLabelSpacing + small_metrics.width(label.text);
text_width += kLabelBoxSize + kLabelBoxPadding + kLabelSpacing + small_metrics.horizontalAdvance(label.text);
}
// Draw the text
@ -216,11 +216,11 @@ void FreeSpaceBar::DrawText(QPainter* p, const QRect &r) {
p->setBrush(label.color);
p->drawRect(box);
QRect text(x + kLabelBoxSize + kLabelBoxPadding, r.top(), small_metrics.width(label.text), r.height());
QRect text(x + kLabelBoxSize + kLabelBoxPadding, r.top(), small_metrics.horizontalAdvance(label.text), r.height());
p->setPen(light ? label.color.darker() : label.color);
p->drawText(text, Qt::AlignCenter, label.text);
x += kLabelBoxSize + kLabelBoxPadding + kLabelSpacing + small_metrics.width(label.text);
x += kLabelBoxSize + kLabelBoxPadding + kLabelSpacing + small_metrics.horizontalAdvance(label.text);
}
}

View File

@ -48,7 +48,7 @@ QSize LineTextEdit::sizeHint() const {
static const int kMargin = 5;
int h = 2 * kMargin + qMax(fm.height(), 14);
int w = 2 * kMargin + fm.width("W") * 15;
int w = 2 * kMargin + fm.horizontalAdvance("W") * 15;
return QSize(w, h);
}

View File

@ -53,7 +53,7 @@ MultiLoadingIndicator::MultiLoadingIndicator(QWidget *parent)
}
QSize MultiLoadingIndicator::sizeHint() const {
const int width = kHorizontalPadding * 2 + spinner_->sizeHint().width() + kSpacing + fontMetrics().width(text_);
const int width = kHorizontalPadding * 2 + spinner_->sizeHint().width() + kSpacing + fontMetrics().horizontalAdvance(text_);
const int height = kVerticalPadding * 2 + qMax(spinner_->sizeHint().height(), fontMetrics().height());
return QSize(width, height);

View File

@ -87,7 +87,7 @@ void TrackSliderPopup::paintEvent(QPaintEvent*) {
void TrackSliderPopup::UpdatePixmap() {
const int text_width = qMax(font_metrics_.width(text_), small_font_metrics_.width(small_text_));
const int text_width = qMax(font_metrics_.horizontalAdvance(text_), small_font_metrics_.horizontalAdvance(small_text_));
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());