Files
YACReader
Info.plist
YACReader.icns
YACReader.pro
bookmarks_dialog.cpp
bookmarks_dialog.h
configuration.cpp
configuration.h
goto_dialog.cpp
goto_dialog.h
goto_flow.cpp
goto_flow.h
goto_flow_gl.cpp
goto_flow_gl.h
goto_flow_toolbar.cpp
goto_flow_toolbar.h
goto_flow_widget.cpp
goto_flow_widget.h
icon.ico
icon.rc
magnifying_glass.cpp
magnifying_glass.h
main.cpp
main_window_viewer.cpp
main_window_viewer.h
notifications_label_widget.cpp
notifications_label_widget.h
options_dialog.cpp
options_dialog.h
page_label_widget.cpp
page_label_widget.h
render.cpp
render.h
shortcuts_dialog.cpp
shortcuts_dialog.h
translator.cpp
translator.h
viewer.cpp
viewer.h
width_slider.cpp
width_slider.h
yacreader_de.ts
yacreader_es.ts
yacreader_files.qrc
yacreader_fr.ts
yacreader_images.qrc
yacreader_images_osx.qrc
yacreader_images_win.qrc
yacreader_it.ts
yacreader_local_client.cpp
yacreader_local_client.h
yacreader_nl.ts
yacreader_pt.ts
yacreader_ru.ts
yacreader_source.ts
yacreader_tr.ts
yacreader_zh_CN.ts
yacreader_zh_HK.ts
yacreader_zh_TW.ts
YACReaderLibrary
YACReaderLibraryServer
ci
common
compressed_archive
custom_widgets
dependencies
files
images
release
shortcuts_management
tests
third_party
.clang-format
.editorconfig
.gitattributes
.gitignore
CHANGELOG.md
COPYING.txt
INSTALL.md
README.md
YACReader.1
YACReader.desktop
YACReader.pro
YACReader.svg
YACReaderLibrary.1
YACReaderLibrary.desktop
YACReaderLibrary.svg
azure-pipelines-build-number.yml
azure-pipelines-windows-template-qt6.yml
azure-pipelines-windows-template.yml
azure-pipelines.yml
background.png
background@2x.png
cleanOSX.sh
com.yacreader.YACReader.appdata.xml
com.yacreader.YACReader.yml
compileOSX.sh
config.pri
dmg.json
icon.icns
mktarball.sh
signapps.sh
yacreader/YACReader/width_slider.cpp
2021-10-19 00:00:08 +02:00

113 lines
3.0 KiB
C++

#include "width_slider.h"
#include <QtWidgets>
#include "configuration.h"
YACReaderSliderAction::YACReaderSliderAction(QWidget *parent)
: QWidgetAction(parent)
{
widget = new YACReaderSlider();
setDefaultWidget(widget);
connect(widget, &YACReaderSlider::zoomRatioChanged, this, &YACReaderSliderAction::zoomRatioChanged);
}
void YACReaderSliderAction::updateText(int value)
{
widget->updateText(value);
}
void YACReaderSliderAction::updateZoomRatio(int value)
{
widget->updateZoomRatio(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);
auto pLayout = new QHBoxLayout();
pLayout->addStretch();
percentageLabel = new QLabel();
percentageLabel->setStyleSheet("QLabel { color : white; }");
percentageLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
slider = new QSlider();
slider->setOrientation(Qt::Horizontal);
slider->setMinimumWidth(sliderWidth);
QPushButton *resetButton = new QPushButton(tr("Reset"));
resetButton->setStyleSheet("QPushButton {border: 1px solid #BB242424; background: #BB2E2E2E; color:white; padding: 3px 5px 5px 5px;}");
connect(resetButton, &QPushButton::clicked, this, &YACReaderSlider::resetValueToDefault);
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->setContentsMargins(0, 0, 0, 0);
setLayout(pLayout);
setAutoFillBackground(false);
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, &QSlider::valueChanged, this, &YACReaderSlider::updateText);
}
void YACReaderSlider::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.fillRect(0, 0, width(), height(), QColor(0xBB000000));
}
void YACReaderSlider::show()
{
QWidget::show();
setFocus();
}
void YACReaderSlider::focusOutEvent(QFocusEvent *event)
{
QWidget::focusOutEvent(event);
hide();
}
void YACReaderSlider::updateText(int value)
{
percentageLabel->setText(QString("%1%").arg(value));
emit zoomRatioChanged(value);
}
void YACReaderSlider::updateZoomRatio(int value)
{
slider->setValue(value);
percentageLabel->setText(QString("%1%").arg(value));
}
void YACReaderSlider::resetValueToDefault()
{
slider->setValue(100);
}