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);} void setMagnifyingGlassSize(const QSize & mgs) { settings->setValue(MAG_GLASS_SIZE,mgs);}
QSize getGotoSlideSize() { return settings->value(GO_TO_FLOW_SIZE).toSize();} QSize getGotoSlideSize() { return settings->value(GO_TO_FLOW_SIZE).toSize();}
void setGotoSlideSize(const QSize & gss) { settings->setValue(GO_TO_FLOW_SIZE,gss);} void setGotoSlideSize(const QSize & gss) { settings->setValue(GO_TO_FLOW_SIZE,gss);}
float getZoomLevel() { return settings->value(ZOOM_LEVEL).toFloat();} float getZoomLevel() { return settings->value(ZOOM_LEVEL).toInt();}
void setZoomLevel(float zl) { settings->setValue(ZOOM_LEVEL,zl);} void setZoomLevel(int zl) { settings->setValue(ZOOM_LEVEL,zl);}
//Unified enum based fitmode //Unified enum based fitmode
YACReader::FitMode getFitMode() { return static_cast<YACReader::FitMode>(settings->value(FITMODE, YACReader::FitMode::FullPage).toInt()); } 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); //QAction * action = comicToolBar->addFitToWidthSlider(showZoomSliderlAction);
connect(showZoomSliderlAction,SIGNAL(triggered()),this,SLOT(toggleFitToWidthSlider())); connect(showZoomSliderlAction,SIGNAL(triggered()),this,SLOT(toggleFitToWidthSlider()));
connect(zoomSliderAction, SIGNAL(zoomRatioChanged(float)),viewer,SLOT(updateZoomRatio(float))); connect(zoomSliderAction, SIGNAL(zoomRatioChanged(int)),viewer,SLOT(updateZoomRatio(int)));
connect(viewer,SIGNAL(zoomUpdated(float)),zoomSliderAction,SLOT(updateZoomRatio(float))); connect(viewer,SIGNAL(zoomUpdated(int)),zoomSliderAction,SLOT(updateZoomRatio(int)));
#endif #endif
comicToolBar->addAction(leftRotationAction); comicToolBar->addAction(leftRotationAction);

View File

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

View File

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

View File

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

View File

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