refactoring for making all the values related to zooming integers to avoid rounding errors, views should always use whole frame values

This commit is contained in:
Luis Ángel San Martín 2015-12-09 22:12:01 +01:00
parent 82b2153d9e
commit 84ea312b0e
6 changed files with 35 additions and 40 deletions

View File

@ -58,8 +58,8 @@ using namespace YACReader;
void setMagnifyingGlassSize(const QSize & mgs) { settings->setValue(MAG_GLASS_SIZE,mgs);}
QSize getGotoSlideSize() { return settings->value(GO_TO_FLOW_SIZE).toSize();}
void setGotoSlideSize(const QSize & gss) { settings->setValue(GO_TO_FLOW_SIZE,gss);}
float getZoomLevel() { return settings->value(ZOOM_LEVEL).toFloat();}
void setZoomLevel(float zl) { settings->setValue(ZOOM_LEVEL,zl);}
float getZoomLevel() { return settings->value(ZOOM_LEVEL).toInt();}
void setZoomLevel(int zl) { settings->setValue(ZOOM_LEVEL,zl);}
//Unified enum based fitmode
YACReader::FitMode getFitMode() { return static_cast<YACReader::FitMode>(settings->value(FITMODE, YACReader::FitMode::FullPage).toInt()); }

View File

@ -572,8 +572,8 @@ void MainWindowViewer::createToolBars()
//QAction * action = comicToolBar->addFitToWidthSlider(showZoomSliderlAction);
connect(showZoomSliderlAction,SIGNAL(triggered()),this,SLOT(toggleFitToWidthSlider()));
connect(zoomSliderAction, SIGNAL(zoomRatioChanged(float)),viewer,SLOT(updateZoomRatio(float)));
connect(viewer,SIGNAL(zoomUpdated(float)),zoomSliderAction,SLOT(updateZoomRatio(float)));
connect(zoomSliderAction, SIGNAL(zoomRatioChanged(int)),viewer,SLOT(updateZoomRatio(int)));
connect(viewer,SIGNAL(zoomUpdated(int)),zoomSliderAction,SLOT(updateZoomRatio(int)));
#endif
comicToolBar->addAction(leftRotationAction);

View File

@ -39,7 +39,7 @@ drag(false),
numScrollSteps(22),
shouldOpenNext(false),
shouldOpenPrevious(false),
zoom(1)
zoom(100)
{
translator = new YACReaderTranslator(this);
translator->hide();
@ -352,9 +352,9 @@ void Viewer::updateContentSize()
break;
}
if(zoom != 1)
if(zoom != 100)
{
pagefit.scale(pagefit.width()*zoom, 0, Qt::KeepAspectRatioByExpanding);
pagefit.scale(floor(pagefit.width()*zoom/100.0f), 0, Qt::KeepAspectRatioByExpanding);
}
//apply scaling
content->resize(pagefit);
@ -374,42 +374,38 @@ void Viewer::updateContentSize()
void Viewer::increaseZoomFactor()
{
zoom += 0.1;
if (zoom > 5)
{
zoom = 5;
}
zoom = std::min(zoom + 10, 500);
updateContentSize();
notificationsLabel->setText(QString::number(getZoomFactor()*100)+"%");
notificationsLabel->setText(QString::number(getZoomFactor())+"%");
notificationsLabel->flash();
emit zoomUpdated(zoom);
}
void Viewer::decreaseZoomFactor()
{
zoom -= 0.1;
if (zoom < 0.3)
zoom = 0.3;
zoom = std::max(zoom - 10, 30);
updateContentSize();
notificationsLabel->setText(QString::number(getZoomFactor()*100)+"%");
notificationsLabel->setText(QString::number(getZoomFactor())+"%");
notificationsLabel->flash();
emit zoomUpdated(zoom);
}
qreal Viewer::getZoomFactor()
int Viewer::getZoomFactor()
{
//this function is a placeholder for future refactoring work
return zoom;
}
void Viewer::setZoomFactor(qreal z)
void Viewer::setZoomFactor(int z)
{
//this function is mostly used to reset the zoom after a fitmode switch
if (z > 5)
zoom = 5;
else if (z < 0.1)
zoom = 0.1;
if (z > 500)
zoom = 500;
else if (z < 30)
zoom = 30;
else
zoom = z;
@ -935,7 +931,7 @@ void Viewer::mouseReleaseEvent ( QMouseEvent * event )
event->accept();
}
void Viewer::updateZoomRatio(float ratio)
void Viewer::updateZoomRatio(int ratio)
{
zoom = ratio;
updateContentSize();

View File

@ -39,8 +39,8 @@ class NotificationsLabelWidget;
public slots:
void increaseZoomFactor();
void decreaseZoomFactor();
void setZoomFactor(qreal);
qreal getZoomFactor();
void setZoomFactor(int);
int getZoomFactor();
void prepareForOpening();
void open(QString pathFile, int atPage = -1);
@ -96,14 +96,14 @@ virtual void mouseReleaseEvent ( QMouseEvent * event );
void showIsCoverMessage();
void showIsLastMessage();
int getCurrentPageNumber();
void updateZoomRatio(float ratio);
void updateZoomRatio(int ratio);
private:
bool information;
bool doublePage;
bool doubleMangaPage;
qreal zoom;
int zoom;
PageLabelWidget * informationLabel;
//QTimer * scroller;
@ -171,7 +171,7 @@ virtual void mouseReleaseEvent ( QMouseEvent * event );
void reset();
void openNextComic();
void openPreviousComic();
void zoomUpdated(float);
void zoomUpdated(int);
};
#endif

View File

@ -12,7 +12,7 @@ YACReaderSliderAction::YACReaderSliderAction (QWidget * parent)
widget = new YACReaderSlider();
setDefaultWidget(widget);
connect(widget,SIGNAL(zoomRatioChanged(float)),this,SIGNAL(zoomRatioChanged(float)));
connect(widget,SIGNAL(zoomRatioChanged(int)),this,SIGNAL(zoomRatioChanged(int)));
}
void YACReaderSliderAction::updateText(int value)
@ -20,9 +20,9 @@ void YACReaderSliderAction::updateText(int value)
widget->updateText(value);
}
void YACReaderSliderAction::updateZoomRatio(float v)
void YACReaderSliderAction::updateZoomRatio(int value)
{
widget->updateZoomRatio(v);
widget->updateZoomRatio(value);
}
YACReaderSlider::YACReaderSlider(QWidget *parent)
@ -80,13 +80,12 @@ YACReaderSlider::YACReaderSlider(QWidget *parent)
void YACReaderSlider::updateText(int value)
{
percentageLabel->setText(QString("%1 %").arg(value));
Configuration::getConfiguration().setZoomLevel(value/100.0);
emit(zoomRatioChanged(value / 100.0f));
Configuration::getConfiguration().setZoomLevel(value);
emit zoomRatioChanged(value);
}
void YACReaderSlider::updateZoomRatio(float v)
void YACReaderSlider::updateZoomRatio(int value)
{
int value = v*100;
slider->setValue(value);
percentageLabel->setText(QString("%1 %").arg(value));
}

View File

@ -19,11 +19,11 @@ public:
public slots:
void updateText(int value);
void updateZoomRatio(float v);
void updateZoomRatio(int value);
signals:
void zoomRatioChanged(float value);
void zoomRatioChanged(int value);
};
class YACReaderSliderAction : public QWidgetAction
@ -38,11 +38,11 @@ public:
public slots:
void updateText(int value);
void updateZoomRatio(float v);
void updateZoomRatio(int value);
signals:
void zoomRatioChanged(float value);
void zoomRatioChanged(int value);
};
#endif