From 79feedd360a2bcff84cc9601a6094cf3c20aa835 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Wed, 6 Apr 2016 00:06:11 +0400 Subject: [PATCH] page scale refactored --- demo_r2/mainwindow.cpp | 2 +- include/lrpreviewreportwidget.h | 1 + limereport/lrgraphicsviewzoom.cpp | 6 +++--- limereport/lrgraphicsviewzoom.h | 2 +- limereport/lrpreviewreportwidget.cpp | 13 ++++++++++--- limereport/lrpreviewreportwidget.h | 1 + limereport/lrpreviewreportwindow.cpp | 3 ++- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/demo_r2/mainwindow.cpp b/demo_r2/mainwindow.cpp index 45e4b84..6245274 100644 --- a/demo_r2/mainwindow.cpp +++ b/demo_r2/mainwindow.cpp @@ -70,7 +70,7 @@ void MainWindow::enableUI(bool value) void MainWindow::slotScalePercentChanged(int percent) { - ui->cbScalePercent->setCurrentText(QString("%1%").arg(percent)); + ui->cbScalePercent->setEditText(QString("%1%").arg(percent)); } void MainWindow::scaleComboboxChanged(QString text) diff --git a/include/lrpreviewreportwidget.h b/include/lrpreviewreportwidget.h index d9cde20..4e35ea6 100644 --- a/include/lrpreviewreportwidget.h +++ b/include/lrpreviewreportwidget.h @@ -46,6 +46,7 @@ signals: private slots: void slotSliderMoved(int value); void reportEngineDestroyed(QObject* object); + void slotZoomed(double); private: void initPreview(); void setErrorsMesagesVisible(bool visible); diff --git a/limereport/lrgraphicsviewzoom.cpp b/limereport/lrgraphicsviewzoom.cpp index 58fc752..8676f22 100644 --- a/limereport/lrgraphicsviewzoom.cpp +++ b/limereport/lrgraphicsviewzoom.cpp @@ -1,7 +1,7 @@ #include "lrgraphicsviewzoom.h" #include #include -#include +#include namespace LimeReport{ @@ -11,7 +11,7 @@ GraphicsViewZoomer::GraphicsViewZoomer(QGraphicsView* view) m_view->viewport()->installEventFilter(this); m_view->setMouseTracking(true); m_modifiers = Qt::ControlModifier; - m_zoomFactorBase = 1.0015; + m_zoomFactorBase = 1.0009; } void GraphicsViewZoomer::gentleZoom(double factor) { @@ -21,7 +21,7 @@ void GraphicsViewZoomer::gentleZoom(double factor) { m_view->viewport()->height() / 2.0); QPointF viewport_center = m_view->mapFromScene(m_targetScenePos) - delta_viewport_pos; m_view->centerOn(m_view->mapToScene(viewport_center.toPoint())); - emit zoomed(); + emit zoomed(factor); } void GraphicsViewZoomer::setModifiers(Qt::KeyboardModifiers modifiers) { diff --git a/limereport/lrgraphicsviewzoom.h b/limereport/lrgraphicsviewzoom.h index 9d0a714..d9f1720 100644 --- a/limereport/lrgraphicsviewzoom.h +++ b/limereport/lrgraphicsviewzoom.h @@ -20,7 +20,7 @@ private: QPointF m_targetScenePos, m_targetViewportPos; bool eventFilter(QObject* object, QEvent* event); signals: - void zoomed(); + void zoomed(double factor); }; } // namespace LimeReport diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index 47b3fb9..b405710 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -52,7 +52,7 @@ void PreviewReportWidgetPrivate::setPages(ReportPages pages) PageItemDesignIntf::Ptr PreviewReportWidgetPrivate::currentPage() { - if (m_reportPages.count()>m_currentPage) + if (m_reportPages.count()>0 && m_reportPages.count()>=m_currentPage) return m_reportPages.at(m_currentPage-1); else return PageItemDesignIntf::Ptr(0); } @@ -70,6 +70,7 @@ PreviewReportWidget::PreviewReportWidget(ReportEnginePrivate *report, QWidget *p connect(ui->graphicsView->verticalScrollBar(),SIGNAL(valueChanged(int)), this, SLOT(slotSliderMoved(int))); connect(d_ptr->m_report, SIGNAL(destroyed(QObject*)), this, SLOT(reportEngineDestroyed(QObject*))); d_ptr->m_zoomer = new GraphicsViewZoomer(ui->graphicsView); + connect(d_ptr->m_zoomer, SIGNAL(zoomed(double)), this, SLOT(slotZoomed(double))); } PreviewReportWidget::~PreviewReportWidget() @@ -97,14 +98,14 @@ void PreviewReportWidget::setErrorsMesagesVisible(bool visible) void PreviewReportWidget::zoomIn() { - d_ptr->m_scalePercent += 10; + d_ptr->m_scalePercent = (d_ptr->m_scalePercent / 10) * 10 + 10; setScalePercent(d_ptr->m_scalePercent); } void PreviewReportWidget::zoomOut() { if (d_ptr->m_scalePercent>0) - d_ptr->m_scalePercent -= 10; + d_ptr->m_scalePercent = (d_ptr->m_scalePercent / 10) * 10 - 10; setScalePercent(d_ptr->m_scalePercent); } @@ -293,6 +294,12 @@ void PreviewReportWidget::reportEngineDestroyed(QObject *object) } } +void PreviewReportWidget::slotZoomed(double ) +{ + d_ptr->m_scalePercent = ui->graphicsView->matrix().m11()*100; + emit scalePercentChanged(d_ptr->m_scalePercent); +} + } diff --git a/limereport/lrpreviewreportwidget.h b/limereport/lrpreviewreportwidget.h index d9cde20..4e35ea6 100644 --- a/limereport/lrpreviewreportwidget.h +++ b/limereport/lrpreviewreportwidget.h @@ -46,6 +46,7 @@ signals: private slots: void slotSliderMoved(int value); void reportEngineDestroyed(QObject* object); + void slotZoomed(double); private: void initPreview(); void setErrorsMesagesVisible(bool visible); diff --git a/limereport/lrpreviewreportwindow.cpp b/limereport/lrpreviewreportwindow.cpp index c0b33fc..7552b45 100644 --- a/limereport/lrpreviewreportwindow.cpp +++ b/limereport/lrpreviewreportwindow.cpp @@ -64,6 +64,7 @@ PreviewReportWindow::PreviewReportWindow(ReportEnginePrivate *report,QWidget *pa m_scalePercent = new QComboBox(this); + m_scalePercent->setEditable(true); ui->toolBar->insertWidget(ui->actionZoomOut, m_scalePercent); initPercentCombobox(); connect(m_previewReportWidget, SIGNAL(scalePercentChanged(int)), this, SLOT(slotScalePercentChanged(int))); @@ -303,7 +304,7 @@ void PreviewReportWindow::scaleComboboxChanged(QString text) void PreviewReportWindow::slotScalePercentChanged(int percent) { - m_scalePercent->setCurrentText(QString("%1%").arg(percent)); + m_scalePercent->setEditText(QString("%1%").arg(percent)); } }// namespace LimeReport