Merge remote-tracking branch 'weblate/master'
[GPXSee.git] / src / GUI / percentslider.cpp
blobdd8a8cd6875b5cee96806507cf32db29f8a52e8d
1 #include <QSlider>
2 #include <QLabel>
3 #include <QHBoxLayout>
4 #include <QLocale>
5 #include "units.h"
6 #include "percentslider.h"
9 static QString format(int value)
11 return QLocale::system().toString(value) + UNIT_SPACE + QString("%");
14 PercentSlider::PercentSlider(QWidget *parent) : QWidget(parent)
16 _slider = new QSlider(Qt::Horizontal);
17 _label = new QLabel();
19 _slider->setMinimum(0);
20 _slider->setMaximum(100);
22 QFontMetrics fm(_label->font());
23 _label->setFixedWidth(fm.boundingRect(format(_slider->maximum())).width());
24 _label->setAlignment(Qt::AlignRight);
25 _label->setText(format(_slider->value()));
27 connect(_slider, &QSlider::valueChanged, this, &PercentSlider::updateLabel);
29 QHBoxLayout *layout = new QHBoxLayout();
30 layout->addWidget(_slider);
31 layout->addWidget(_label);
33 setLayout(layout);
36 void PercentSlider::updateLabel(int value)
38 _label->setText(format(value));
41 int PercentSlider::value() const
43 return _slider->value();
46 void PercentSlider::setValue(int value)
48 _slider->setValue(value);
49 _label->setText(format(value));