| 27 | } |
| 28 | |
| 29 | YACReaderSlider::YACReaderSlider(QWidget *parent) |
| 30 | : QWidget(parent) |
| 31 | { |
| 32 | const int sliderWidth = 200; |
| 33 | const int contentsMargin = 10; |
| 34 | const int elementsSpacing = 10; |
| 35 | const int percentageLabelWidth = 30; |
| 36 | |
| 37 | setFocusPolicy(Qt::StrongFocus); |
| 38 | |
| 39 | auto pLayout = new QHBoxLayout(); |
| 40 | |
| 41 | pLayout->addStretch(); |
| 42 | |
| 43 | percentageLabel = new QLabel(); |
| 44 | percentageLabel->setStyleSheet("QLabel { color : white; }"); |
| 45 | percentageLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); |
| 46 | slider = new QSlider(); |
| 47 | slider->setOrientation(Qt::Horizontal); |
| 48 | |
| 49 | slider->setMinimumWidth(sliderWidth); |
| 50 | |
| 51 | QPushButton *resetButton = new QPushButton(tr("Reset")); |
| 52 | resetButton->setStyleSheet("QPushButton {border: 1px solid #BB242424; background: #BB2E2E2E; color:white; padding: 3px 5px 5px 5px;}"); |
| 53 | connect(resetButton, &QPushButton::clicked, this, &YACReaderSlider::resetValueToDefault); |
| 54 | |
| 55 | pLayout->addWidget(percentageLabel, 1, Qt::AlignHCenter); |
| 56 | pLayout->addWidget(slider, 0, Qt::AlignHCenter | Qt::AlignBottom); |
| 57 | pLayout->addWidget(resetButton, 1, Qt::AlignHCenter | Qt::AlignBottom); |
| 58 | pLayout->setSpacing(elementsSpacing); |
| 59 | |
| 60 | pLayout->setContentsMargins(0, 0, 0, 0); |
| 61 | |
| 62 | setLayout(pLayout); |
| 63 | setAutoFillBackground(false); |
| 64 | |
| 65 | setContentsMargins(contentsMargin, contentsMargin, contentsMargin, contentsMargin); |
| 66 | setFixedSize(sliderWidth + 2 * contentsMargin + 2 * elementsSpacing + percentageLabelWidth + resetButton->sizeHint().width(), 45); |
| 67 | |
| 68 | slider->setMinimum(30); |
| 69 | slider->setMaximum(500); |
| 70 | slider->setPageStep(5); |
| 71 | |
| 72 | slider->setFocusPolicy(Qt::NoFocus); |
| 73 | resetButton->setFocusPolicy(Qt::NoFocus); |
| 74 | |
| 75 | slider->setValue(100); |
| 76 | percentageLabel->setText(QString("%1%").arg(100)); |
| 77 | connect(slider, &QSlider::valueChanged, this, &YACReaderSlider::updateText); |
| 78 | } |
| 79 | |
| 80 | void YACReaderSlider::paintEvent(QPaintEvent *) |
| 81 | { |