Files
QsLog
YACReader
YACReader.icns
YACReader.pri
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_decorationbar.cpp
goto_flow_decorationbar.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_es.qm
yacreader_es.ts
yacreader_files.qrc
yacreader_fr.ts
yacreader_images.qrc
yacreader_images_osx.qrc
yacreader_images_win.qrc
yacreader_local_client.cpp
yacreader_local_client.h
yacreader_nl.ts
yacreader_pt.ts
yacreader_ru.ts
yacreader_source.ts
yacreader_tr.ts
YACReaderLibrary
common
compressed_archive
custom_widgets
dependencies
files
images
release
shortcuts_management
CHANGELOG.txt
COPYING.txt
INSTALL.txt
README.txt
YACReader.desktop
YACReader.pro
YACReaderLibrary.desktop
background.png
cleanOSX.sh
compileOSX.sh
compileX11.sh
create-dmg
generateVS2010Projects.bat
icon.icns
releaseOSX.sh
yacreader/YACReader/width_slider.cpp

78 lines
2.4 KiB
C++

#include "width_slider.h"
#include <QWidget>
#include <QHBoxLayout>
#include <QLabel>
#include <QSlider>
#include "configuration.h"
YACReaderSliderAction::YACReaderSliderAction (QWidget * parent)
:QWidgetAction (parent) {
QWidget* pWidget = new QWidget (NULL);
QHBoxLayout* pLayout = new QHBoxLayout();
pLayout->addStretch();
percentageLabel = new QLabel ("100%");
percentageLabel->setStyleSheet("QLabel { color : white; }");
percentageLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
pLayout->addWidget (percentageLabel);
slider = new QSlider(NULL);
slider->setOrientation(Qt::Horizontal);
pLayout->addWidget (slider);
QString sliderCSS =
"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);
QLabel* imgLabel = new QLabel(pWidget);
QPixmap p(":/images/sliderBackground.png");
imgLabel->resize(p.size());
imgLabel->setPixmap(p);
pLayout->setMargin(0);
pLayout->setSpacing(0);
pLayout->setStretchFactor(percentageLabel,1);
pLayout->setStretchFactor(slider,0);
pWidget->setLayout (pLayout);
pWidget->setAutoFillBackground(false);
pWidget->setMinimumSize(276,45);
setDefaultWidget(pWidget);
slider->setMinimum(50);
slider->setMaximum(100);
slider->setPageStep(5);
int value = Configuration::getConfiguration().getFitToWidthRatio()*100;
slider->setValue(value);
percentageLabel->setText(QString("%1 %").arg(value));
connect(slider,SIGNAL(valueChanged(int)),this,SLOT(updateText(int)));
}
void YACReaderSliderAction::updateText(int value)
{
percentageLabel->setText(QString("%1 %").arg(value));
Configuration::getConfiguration().setFitToWidthRatio(value/100.0);
emit(fitToWidthRatioChanged(value / 100.0f));
}
void YACReaderSliderAction::updateFitToWidthRatio(float v)
{
int value = v*100;
slider->setValue(value);
percentageLabel->setText(QString("%1 %").arg(value));
}