mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
new visual style for zoom slider + reset button
This commit is contained in:
parent
d737f86734
commit
05b77b0461
@ -1,9 +1,7 @@
|
||||
#include "width_slider.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QSlider>
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "configuration.h"
|
||||
|
||||
YACReaderSliderAction::YACReaderSliderAction (QWidget * parent)
|
||||
@ -28,56 +26,59 @@ void YACReaderSliderAction::updateZoomRatio(int value)
|
||||
YACReaderSlider::YACReaderSlider(QWidget *parent)
|
||||
:QWidget(parent)
|
||||
{
|
||||
const int sliderWidth = 200;
|
||||
const int contentsMargin = 10;
|
||||
const int elementsSpacing = 10;
|
||||
const int percentageLabelWidth = 30;
|
||||
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
QHBoxLayout* pLayout = new QHBoxLayout();
|
||||
|
||||
pLayout->addStretch();
|
||||
|
||||
percentageLabel = new QLabel ("100%");
|
||||
percentageLabel = new QLabel();
|
||||
percentageLabel->setStyleSheet("QLabel { color : white; }");
|
||||
percentageLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
|
||||
pLayout->addWidget (percentageLabel);
|
||||
slider = new QSlider(NULL);
|
||||
percentageLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
slider = new QSlider();
|
||||
slider->setOrientation(Qt::Horizontal);
|
||||
pLayout->addWidget (slider);
|
||||
|
||||
QString sliderCSS =
|
||||
slider->setMinimumWidth(sliderWidth);
|
||||
|
||||
"QSlider::sub-page:horizontal {background-image: url(:/images/sliderSubPage.png); border: 0px; margin-left: 18px;}"
|
||||
"QSlider::add-page:horizontal {background-image: url(:/images/sliderAddPage.png); border: 0px; margin-right: 25px;}"
|
||||
"QSlider::handle:horizontal {image: url(:/images/sliderHandle.png); width: 31px;height:45px; }"
|
||||
"QSlider::groove:horizontal {border-image:url(:/images/sliderGround.png); border-left:-2px; border-right:0;}"
|
||||
;
|
||||
slider->setStyleSheet(sliderCSS);
|
||||
slider->setFixedSize(218,45);
|
||||
QPushButton *resetButton = new QPushButton(tr("Reset"));
|
||||
resetButton->setStyleSheet("QPushButton {border: 1px solid #BB242424; background: #BB2E2E2E; color:white; padding: 3px 5px 5px 5px; font-color: white}");
|
||||
connect(resetButton, &QPushButton::clicked, this, &YACReaderSlider::resetValueToDefault);
|
||||
|
||||
QLabel* imgLabel = new QLabel(this);
|
||||
QPixmap p(":/images/sliderBackground.png");
|
||||
imgLabel->resize(p.size());
|
||||
imgLabel->setPixmap(p);
|
||||
pLayout->addWidget(percentageLabel, 1, Qt::AlignHCenter);
|
||||
pLayout->addWidget(slider, 0, Qt::AlignHCenter | Qt::AlignBottom);
|
||||
pLayout->addWidget(resetButton, 1, Qt::AlignHCenter | Qt::AlignBottom);
|
||||
pLayout->setSpacing(elementsSpacing);
|
||||
|
||||
pLayout->setMargin(0);
|
||||
pLayout->setSpacing(0);
|
||||
|
||||
pLayout->setStretchFactor(percentageLabel,1);
|
||||
pLayout->setStretchFactor(slider,0);
|
||||
|
||||
|
||||
setLayout (pLayout);
|
||||
setAutoFillBackground(false);
|
||||
|
||||
setMinimumSize(276,45);
|
||||
setContentsMargins(contentsMargin,contentsMargin,contentsMargin,contentsMargin);
|
||||
setFixedSize(sliderWidth + 2 * contentsMargin + 2 * elementsSpacing + percentageLabelWidth + resetButton->sizeHint().width(), 45);
|
||||
|
||||
slider->setMinimum(30);
|
||||
slider->setMaximum(500);
|
||||
slider->setPageStep(5);
|
||||
|
||||
slider->setFocusPolicy(Qt::NoFocus);
|
||||
resetButton->setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
slider->setValue(100);
|
||||
percentageLabel->setText(QString("%1 %").arg(100));
|
||||
connect(slider,SIGNAL(valueChanged(int)),this,SLOT(updateText(int)));
|
||||
percentageLabel->setText(QString("%1%").arg(100));
|
||||
connect(slider, &QSlider::valueChanged, this, &YACReaderSlider::updateText);
|
||||
}
|
||||
|
||||
void YACReaderSlider::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
painter.fillRect(0,0,width(),height(),QColor("#BB000000"));
|
||||
}
|
||||
|
||||
void YACReaderSlider::show()
|
||||
@ -94,12 +95,17 @@ void YACReaderSlider::focusOutEvent(QFocusEvent * event)
|
||||
|
||||
void YACReaderSlider::updateText(int value)
|
||||
{
|
||||
percentageLabel->setText(QString("%1 %").arg(value));
|
||||
percentageLabel->setText(QString("%1%").arg(value));
|
||||
emit zoomRatioChanged(value);
|
||||
}
|
||||
|
||||
void YACReaderSlider::updateZoomRatio(int value)
|
||||
{
|
||||
slider->setValue(value);
|
||||
percentageLabel->setText(QString("%1 %").arg(value));
|
||||
percentageLabel->setText(QString("%1%").arg(value));
|
||||
}
|
||||
|
||||
void YACReaderSlider::resetValueToDefault()
|
||||
{
|
||||
slider->setValue(100);
|
||||
}
|
||||
|
@ -19,10 +19,12 @@ public:
|
||||
|
||||
protected:
|
||||
virtual void focusOutEvent(QFocusEvent * event);
|
||||
virtual void paintEvent(QPaintEvent *);
|
||||
|
||||
public slots:
|
||||
void updateText(int value);
|
||||
void updateZoomRatio(int value);
|
||||
void resetValueToDefault();
|
||||
|
||||
|
||||
signals:
|
||||
|
Loading…
x
Reference in New Issue
Block a user