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 "width_slider.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QtWidgets>
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QSlider>
|
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
|
|
||||||
YACReaderSliderAction::YACReaderSliderAction (QWidget * parent)
|
YACReaderSliderAction::YACReaderSliderAction (QWidget * parent)
|
||||||
@ -28,56 +26,59 @@ void YACReaderSliderAction::updateZoomRatio(int value)
|
|||||||
YACReaderSlider::YACReaderSlider(QWidget *parent)
|
YACReaderSlider::YACReaderSlider(QWidget *parent)
|
||||||
:QWidget(parent)
|
:QWidget(parent)
|
||||||
{
|
{
|
||||||
|
const int sliderWidth = 200;
|
||||||
|
const int contentsMargin = 10;
|
||||||
|
const int elementsSpacing = 10;
|
||||||
|
const int percentageLabelWidth = 30;
|
||||||
|
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
|
|
||||||
QHBoxLayout* pLayout = new QHBoxLayout();
|
QHBoxLayout* pLayout = new QHBoxLayout();
|
||||||
|
|
||||||
pLayout->addStretch();
|
pLayout->addStretch();
|
||||||
|
|
||||||
percentageLabel = new QLabel ("100%");
|
percentageLabel = new QLabel();
|
||||||
percentageLabel->setStyleSheet("QLabel { color : white; }");
|
percentageLabel->setStyleSheet("QLabel { color : white; }");
|
||||||
percentageLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
percentageLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||||
pLayout->addWidget (percentageLabel);
|
slider = new QSlider();
|
||||||
slider = new QSlider(NULL);
|
|
||||||
slider->setOrientation(Qt::Horizontal);
|
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;}"
|
QPushButton *resetButton = new QPushButton(tr("Reset"));
|
||||||
"QSlider::add-page:horizontal {background-image: url(:/images/sliderAddPage.png); border: 0px; margin-right: 25px;}"
|
resetButton->setStyleSheet("QPushButton {border: 1px solid #BB242424; background: #BB2E2E2E; color:white; padding: 3px 5px 5px 5px; font-color: white}");
|
||||||
"QSlider::handle:horizontal {image: url(:/images/sliderHandle.png); width: 31px;height:45px; }"
|
connect(resetButton, &QPushButton::clicked, this, &YACReaderSlider::resetValueToDefault);
|
||||||
"QSlider::groove:horizontal {border-image:url(:/images/sliderGround.png); border-left:-2px; border-right:0;}"
|
|
||||||
;
|
|
||||||
slider->setStyleSheet(sliderCSS);
|
|
||||||
slider->setFixedSize(218,45);
|
|
||||||
|
|
||||||
QLabel* imgLabel = new QLabel(this);
|
pLayout->addWidget(percentageLabel, 1, Qt::AlignHCenter);
|
||||||
QPixmap p(":/images/sliderBackground.png");
|
pLayout->addWidget(slider, 0, Qt::AlignHCenter | Qt::AlignBottom);
|
||||||
imgLabel->resize(p.size());
|
pLayout->addWidget(resetButton, 1, Qt::AlignHCenter | Qt::AlignBottom);
|
||||||
imgLabel->setPixmap(p);
|
pLayout->setSpacing(elementsSpacing);
|
||||||
|
|
||||||
pLayout->setMargin(0);
|
pLayout->setMargin(0);
|
||||||
pLayout->setSpacing(0);
|
|
||||||
|
|
||||||
pLayout->setStretchFactor(percentageLabel,1);
|
|
||||||
pLayout->setStretchFactor(slider,0);
|
|
||||||
|
|
||||||
|
|
||||||
setLayout (pLayout);
|
setLayout (pLayout);
|
||||||
setAutoFillBackground(false);
|
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->setMinimum(30);
|
||||||
slider->setMaximum(500);
|
slider->setMaximum(500);
|
||||||
slider->setPageStep(5);
|
slider->setPageStep(5);
|
||||||
|
|
||||||
slider->setFocusPolicy(Qt::NoFocus);
|
slider->setFocusPolicy(Qt::NoFocus);
|
||||||
|
resetButton->setFocusPolicy(Qt::NoFocus);
|
||||||
|
|
||||||
slider->setValue(100);
|
slider->setValue(100);
|
||||||
percentageLabel->setText(QString("%1%").arg(100));
|
percentageLabel->setText(QString("%1%").arg(100));
|
||||||
connect(slider,SIGNAL(valueChanged(int)),this,SLOT(updateText(int)));
|
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()
|
void YACReaderSlider::show()
|
||||||
@ -103,3 +104,8 @@ void YACReaderSlider::updateZoomRatio(int value)
|
|||||||
slider->setValue(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:
|
protected:
|
||||||
virtual void focusOutEvent(QFocusEvent * event);
|
virtual void focusOutEvent(QFocusEvent * event);
|
||||||
|
virtual void paintEvent(QPaintEvent *);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateText(int value);
|
void updateText(int value);
|
||||||
void updateZoomRatio(int value);
|
void updateZoomRatio(int value);
|
||||||
|
void resetValueToDefault();
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user