diff --git a/include/lrpreviewreportwidget.h b/include/lrpreviewreportwidget.h index 797acdb..9a9eab7 100644 --- a/include/lrpreviewreportwidget.h +++ b/include/lrpreviewreportwidget.h @@ -40,6 +40,7 @@ public: void activateItemSelectionMode(); void deleteSelectedItems(); void activateCurrentPage(); + void resize(ScaleType scaleType, int percent=0); public slots: void refreshPages(); diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index 43ea2cc..71b4d35 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -320,19 +320,14 @@ void PreviewReportWidget::setScalePercent(int percent) void PreviewReportWidget::fitWidth() { if (d_ptr->currentPage()){ - qreal scalePercent = ui->graphicsView->viewport()->width() / ui->graphicsView->scene()->width(); - setScalePercent(scalePercent*100); - m_scaleType = FitWidth; + resize(m_scaleType = FitWidth); } } void PreviewReportWidget::fitPage() { if (d_ptr->currentPage()){ - qreal vScale = ui->graphicsView->viewport()->width() / ui->graphicsView->scene()->width(); - qreal hScale = ui->graphicsView->viewport()->height() / d_ptr->currentPage()->height(); - setScalePercent(qMin(vScale,hScale)*100); - m_scaleType = FitPage; + resize(m_scaleType = FitPage); } } @@ -428,6 +423,28 @@ void PreviewReportWidget::activateCurrentPage() page->setCurrentPage(d_ptr->currentPage().data()); } +void PreviewReportWidget::resize(ScaleType scaleType, int percent) +{ + switch (scaleType) { + case FitWidth: + setScalePercent(ui->graphicsView->viewport()->width() / ui->graphicsView->scene()->width()*100); + break; + case FitPage: + setScalePercent(qMin( + ui->graphicsView->viewport()->width() / ui->graphicsView->scene()->width(), + ui->graphicsView->viewport()->height() / d_ptr->currentPage()->height() + ) * 100); + break; + case OneToOne: + setScalePercent(100); + break; + case Percents: + setScalePercent(percent); + break; + } + +} + void PreviewReportWidget::slotSliderMoved(int value) { if (m_scaleChanging) return; diff --git a/limereport/lrpreviewreportwidget.h b/limereport/lrpreviewreportwidget.h index 797acdb..9a9eab7 100644 --- a/limereport/lrpreviewreportwidget.h +++ b/limereport/lrpreviewreportwidget.h @@ -40,6 +40,7 @@ public: void activateItemSelectionMode(); void deleteSelectedItems(); void activateCurrentPage(); + void resize(ScaleType scaleType, int percent=0); public slots: void refreshPages();