Skip to content

Commit

Permalink
qtui: Try to make the time label constant width. Closes: #957.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlindgren90 committed Apr 11, 2020
1 parent fda439a commit 3ead981
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/qtui/time_slider.cc
Expand Up @@ -28,10 +28,7 @@
#include <QProxyStyle>
#include <QStyle>

TimeSliderLabel::TimeSliderLabel(QWidget * parent) : QLabel(parent)
{
setStyleSheet("font-weight: bold");
}
TimeSliderLabel::TimeSliderLabel(QWidget * parent) : QLabel(parent) {}
TimeSliderLabel::~TimeSliderLabel() {}

void TimeSliderLabel::mouseDoubleClickEvent(QMouseEvent * event)
Expand Down Expand Up @@ -88,14 +85,28 @@ void TimeSlider::set_label(int time, int length)
QString text;

if (length >= 0)
{
auto length_str = str_format_time(length);
auto time_pad = length_str.len();

QString time_str;
if (aud_get_bool("qtui", "show_remaining_time"))
text = str_concat({str_format_time(time - length), " / ",
str_format_time(length)});
{
time = aud::max(0, length - time);
time_str = QString('-') + str_format_time(time);
time_pad++;
}
else
text = str_concat(
{str_format_time(time), " / ", str_format_time(length)});
time_str = str_format_time(time);

// To avoid the label changing width as time progresses, use
// monospaced digits and pad the time to the width of the song
// length (which should be the widest time we'll display).
text = "<b><tt>" + time_str.rightJustified(time_pad, QChar::Nbsp) +
"</tt> / <tt>" + length_str + "</tt></b>";
}
else
text = str_format_time(time);
text = "<b><tt>" + QString(str_format_time(time)) + "</tt></b>";

m_label->setText(text);
}
Expand Down

0 comments on commit 3ead981

Please sign in to comment.