page scale refactored

This commit is contained in:
Arin Alexander 2016-04-06 00:06:11 +04:00
parent aa3f9d80d3
commit 79feedd360
7 changed files with 19 additions and 9 deletions

View File

@ -70,7 +70,7 @@ void MainWindow::enableUI(bool value)
void MainWindow::slotScalePercentChanged(int percent) void MainWindow::slotScalePercentChanged(int percent)
{ {
ui->cbScalePercent->setCurrentText(QString("%1%").arg(percent)); ui->cbScalePercent->setEditText(QString("%1%").arg(percent));
} }
void MainWindow::scaleComboboxChanged(QString text) void MainWindow::scaleComboboxChanged(QString text)

View File

@ -46,6 +46,7 @@ signals:
private slots: private slots:
void slotSliderMoved(int value); void slotSliderMoved(int value);
void reportEngineDestroyed(QObject* object); void reportEngineDestroyed(QObject* object);
void slotZoomed(double);
private: private:
void initPreview(); void initPreview();
void setErrorsMesagesVisible(bool visible); void setErrorsMesagesVisible(bool visible);

View File

@ -1,7 +1,7 @@
#include "lrgraphicsviewzoom.h" #include "lrgraphicsviewzoom.h"
#include <QMouseEvent> #include <QMouseEvent>
#include <QApplication> #include <QApplication>
#include <QtMath> #include <qmath.h>
namespace LimeReport{ namespace LimeReport{
@ -11,7 +11,7 @@ GraphicsViewZoomer::GraphicsViewZoomer(QGraphicsView* view)
m_view->viewport()->installEventFilter(this); m_view->viewport()->installEventFilter(this);
m_view->setMouseTracking(true); m_view->setMouseTracking(true);
m_modifiers = Qt::ControlModifier; m_modifiers = Qt::ControlModifier;
m_zoomFactorBase = 1.0015; m_zoomFactorBase = 1.0009;
} }
void GraphicsViewZoomer::gentleZoom(double factor) { void GraphicsViewZoomer::gentleZoom(double factor) {
@ -21,7 +21,7 @@ void GraphicsViewZoomer::gentleZoom(double factor) {
m_view->viewport()->height() / 2.0); m_view->viewport()->height() / 2.0);
QPointF viewport_center = m_view->mapFromScene(m_targetScenePos) - delta_viewport_pos; QPointF viewport_center = m_view->mapFromScene(m_targetScenePos) - delta_viewport_pos;
m_view->centerOn(m_view->mapToScene(viewport_center.toPoint())); m_view->centerOn(m_view->mapToScene(viewport_center.toPoint()));
emit zoomed(); emit zoomed(factor);
} }
void GraphicsViewZoomer::setModifiers(Qt::KeyboardModifiers modifiers) { void GraphicsViewZoomer::setModifiers(Qt::KeyboardModifiers modifiers) {

View File

@ -20,7 +20,7 @@ private:
QPointF m_targetScenePos, m_targetViewportPos; QPointF m_targetScenePos, m_targetViewportPos;
bool eventFilter(QObject* object, QEvent* event); bool eventFilter(QObject* object, QEvent* event);
signals: signals:
void zoomed(); void zoomed(double factor);
}; };
} // namespace LimeReport } // namespace LimeReport

View File

@ -52,7 +52,7 @@ void PreviewReportWidgetPrivate::setPages(ReportPages pages)
PageItemDesignIntf::Ptr PreviewReportWidgetPrivate::currentPage() 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); return m_reportPages.at(m_currentPage-1);
else return PageItemDesignIntf::Ptr(0); 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(ui->graphicsView->verticalScrollBar(),SIGNAL(valueChanged(int)), this, SLOT(slotSliderMoved(int)));
connect(d_ptr->m_report, SIGNAL(destroyed(QObject*)), this, SLOT(reportEngineDestroyed(QObject*))); connect(d_ptr->m_report, SIGNAL(destroyed(QObject*)), this, SLOT(reportEngineDestroyed(QObject*)));
d_ptr->m_zoomer = new GraphicsViewZoomer(ui->graphicsView); d_ptr->m_zoomer = new GraphicsViewZoomer(ui->graphicsView);
connect(d_ptr->m_zoomer, SIGNAL(zoomed(double)), this, SLOT(slotZoomed(double)));
} }
PreviewReportWidget::~PreviewReportWidget() PreviewReportWidget::~PreviewReportWidget()
@ -97,14 +98,14 @@ void PreviewReportWidget::setErrorsMesagesVisible(bool visible)
void PreviewReportWidget::zoomIn() void PreviewReportWidget::zoomIn()
{ {
d_ptr->m_scalePercent += 10; d_ptr->m_scalePercent = (d_ptr->m_scalePercent / 10) * 10 + 10;
setScalePercent(d_ptr->m_scalePercent); setScalePercent(d_ptr->m_scalePercent);
} }
void PreviewReportWidget::zoomOut() void PreviewReportWidget::zoomOut()
{ {
if (d_ptr->m_scalePercent>0) 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); 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);
}
} }

View File

@ -46,6 +46,7 @@ signals:
private slots: private slots:
void slotSliderMoved(int value); void slotSliderMoved(int value);
void reportEngineDestroyed(QObject* object); void reportEngineDestroyed(QObject* object);
void slotZoomed(double);
private: private:
void initPreview(); void initPreview();
void setErrorsMesagesVisible(bool visible); void setErrorsMesagesVisible(bool visible);

View File

@ -64,6 +64,7 @@ PreviewReportWindow::PreviewReportWindow(ReportEnginePrivate *report,QWidget *pa
m_scalePercent = new QComboBox(this); m_scalePercent = new QComboBox(this);
m_scalePercent->setEditable(true);
ui->toolBar->insertWidget(ui->actionZoomOut, m_scalePercent); ui->toolBar->insertWidget(ui->actionZoomOut, m_scalePercent);
initPercentCombobox(); initPercentCombobox();
connect(m_previewReportWidget, SIGNAL(scalePercentChanged(int)), this, SLOT(slotScalePercentChanged(int))); connect(m_previewReportWidget, SIGNAL(scalePercentChanged(int)), this, SLOT(slotScalePercentChanged(int)));
@ -303,7 +304,7 @@ void PreviewReportWindow::scaleComboboxChanged(QString text)
void PreviewReportWindow::slotScalePercentChanged(int percent) void PreviewReportWindow::slotScalePercentChanged(int percent)
{ {
m_scalePercent->setCurrentText(QString("%1%").arg(percent)); m_scalePercent->setEditText(QString("%1%").arg(percent));
} }
}// namespace LimeReport }// namespace LimeReport