diff --git a/common.pri b/common.pri index fe66976..6e063c8 100644 --- a/common.pri +++ b/common.pri @@ -105,7 +105,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc LIMEREPORT_VERSION_MAJOR = 1 LIMEREPORT_VERSION_MINOR = 4 -LIMEREPORT_VERSION_RELEASE = 85 +LIMEREPORT_VERSION_RELEASE = 86 LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}' DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\" diff --git a/include/lrglobal.h b/include/lrglobal.h index b32d263..65a04d2 100644 --- a/include/lrglobal.h +++ b/include/lrglobal.h @@ -106,6 +106,7 @@ namespace Const{ enum ExpandType {EscapeSymbols, NoEscapeSymbols, ReplaceHTMLSymbols}; enum RenderPass {FirstPass = 1, SecondPass = 2}; enum ArrangeType {AsNeeded, Force}; + enum ScaleType {FitWidth, FitPage, OneToOne, Percents}; enum PreviewHint{ShowAllPreviewBars = 0, HidePreviewToolBar = 1, HidePreviewMenuBar = 2, diff --git a/include/lrpreviewreportwidget.h b/include/lrpreviewreportwidget.h index c1b571d..395af7d 100644 --- a/include/lrpreviewreportwidget.h +++ b/include/lrpreviewreportwidget.h @@ -2,6 +2,7 @@ #define LRPREVIEWREPORTWIDGET_H #include +#include #include "lrglobal.h" namespace LimeReport { @@ -25,6 +26,9 @@ public: ~PreviewReportWidget(); QList aviableExporters(); bool exportReport(QString exporterName, const QMap& params = QMap()); + ScaleType scaleType() const; + int scalePercent() const; + void setScaleType(const ScaleType &scaleType, int percent = 0); public slots: void refreshPages(); void zoomIn(); @@ -42,6 +46,8 @@ public slots: void setScalePercent(int percent); void fitWidth(); void fitPage(); +protected: + void resizeEvent(QResizeEvent *); signals: void pageChanged(int page); void scalePercentChanged(int percent); @@ -50,6 +56,7 @@ private slots: void slotSliderMoved(int value); void reportEngineDestroyed(QObject* object); void slotZoomed(double); + void resizeDone(); private: void initPreview(); void setErrorsMesagesVisible(bool visible); @@ -58,6 +65,9 @@ private: private: Ui::PreviewReportWidget *ui; PreviewReportWidgetPrivate* d_ptr; + ScaleType m_scaleType; + int m_scalePercent; + QTimer m_resizeTimer; }; } // namespace LimeReport diff --git a/include/lrreportengine.h b/include/lrreportengine.h index e3d4ec4..38f8c1b 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -116,6 +116,9 @@ public: void setPreviewLayoutDirection(const Qt::LayoutDirection& previewLayoutDirection); QList designerLanguages(); QLocale::Language currentDesignerLanguage(); + ScaleType previewScaleType(); + int previewScalePercent(); + void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0); signals: void cleared(); void renderStarted(); diff --git a/limereport/lrglobal.h b/limereport/lrglobal.h index b32d263..65a04d2 100644 --- a/limereport/lrglobal.h +++ b/limereport/lrglobal.h @@ -106,6 +106,7 @@ namespace Const{ enum ExpandType {EscapeSymbols, NoEscapeSymbols, ReplaceHTMLSymbols}; enum RenderPass {FirstPass = 1, SecondPass = 2}; enum ArrangeType {AsNeeded, Force}; + enum ScaleType {FitWidth, FitPage, OneToOne, Percents}; enum PreviewHint{ShowAllPreviewBars = 0, HidePreviewToolBar = 1, HidePreviewMenuBar = 2, diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index 756a4ac..4865973 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -70,19 +70,21 @@ QList PreviewReportWidgetPrivate::aviableExporters() PreviewReportWidget::PreviewReportWidget(ReportEngine *report, QWidget *parent) : QWidget(parent), - ui(new Ui::PreviewReportWidget), d_ptr(new PreviewReportWidgetPrivate(this)) + ui(new Ui::PreviewReportWidget), d_ptr(new PreviewReportWidgetPrivate(this)), + m_scaleType(FitWidth), m_scalePercent(0) { ui->setupUi(this); d_ptr->m_report = report->d_ptr; d_ptr->m_previewPage = d_ptr->m_report->createPreviewPage(); d_ptr->m_previewPage->setItemMode( LimeReport::PreviewMode ); - + m_resizeTimer.setSingleShot(true); ui->errorsView->setVisible(false); 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))); + connect(&m_resizeTimer, SIGNAL(timeout()), this, SLOT(resizeDone())); } PreviewReportWidget::~PreviewReportWidget() @@ -256,6 +258,11 @@ void PreviewReportWidget::setScalePercent(int percent) qreal scaleSize = percent/100.0; ui->graphicsView->scale(scaleSize, scaleSize); emit scalePercentChanged(percent); + if (percent == 100){ + m_scaleType = OneToOne; + } else { + m_scaleType = Percents; + } } void PreviewReportWidget::fitWidth() @@ -263,6 +270,7 @@ void PreviewReportWidget::fitWidth() if (d_ptr->currentPage()){ qreal scalePercent = ui->graphicsView->viewport()->width() / ui->graphicsView->scene()->width(); setScalePercent(scalePercent*100); + m_scaleType = FitWidth; } } @@ -272,9 +280,15 @@ void PreviewReportWidget::fitPage() 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; } } +void PreviewReportWidget::resizeEvent(QResizeEvent *) +{ + m_resizeTimer.start(100); +} + void PreviewReportWidget::setErrorMessages(const QStringList &value) { foreach (QString line, value) { @@ -287,6 +301,22 @@ void PreviewReportWidget::emitPageSet() emit pagesSet(d_ptr->m_reportPages.count()); } +ScaleType PreviewReportWidget::scaleType() const +{ + return m_scaleType; +} + +int PreviewReportWidget::scalePercent() const +{ + return m_scalePercent; +} + +void PreviewReportWidget::setScaleType(const ScaleType &scaleType, int percent) +{ + m_scaleType = scaleType; + m_scalePercent = percent; +} + void PreviewReportWidget::refreshPages() { if (d_ptr->m_report){ @@ -340,6 +370,23 @@ void PreviewReportWidget::slotZoomed(double ) emit scalePercentChanged(d_ptr->m_scalePercent); } +void PreviewReportWidget::resizeDone() +{ + switch (m_scaleType) { + case FitPage: + fitPage(); + break; + case FitWidth: + fitWidth(); + break; + case OneToOne: + setScalePercent(100); + break; + case Percents: + setScalePercent(m_scalePercent); + break; + } +} } diff --git a/limereport/lrpreviewreportwidget.h b/limereport/lrpreviewreportwidget.h index c1b571d..395af7d 100644 --- a/limereport/lrpreviewreportwidget.h +++ b/limereport/lrpreviewreportwidget.h @@ -2,6 +2,7 @@ #define LRPREVIEWREPORTWIDGET_H #include +#include #include "lrglobal.h" namespace LimeReport { @@ -25,6 +26,9 @@ public: ~PreviewReportWidget(); QList aviableExporters(); bool exportReport(QString exporterName, const QMap& params = QMap()); + ScaleType scaleType() const; + int scalePercent() const; + void setScaleType(const ScaleType &scaleType, int percent = 0); public slots: void refreshPages(); void zoomIn(); @@ -42,6 +46,8 @@ public slots: void setScalePercent(int percent); void fitWidth(); void fitPage(); +protected: + void resizeEvent(QResizeEvent *); signals: void pageChanged(int page); void scalePercentChanged(int percent); @@ -50,6 +56,7 @@ private slots: void slotSliderMoved(int value); void reportEngineDestroyed(QObject* object); void slotZoomed(double); + void resizeDone(); private: void initPreview(); void setErrorsMesagesVisible(bool visible); @@ -58,6 +65,9 @@ private: private: Ui::PreviewReportWidget *ui; PreviewReportWidgetPrivate* d_ptr; + ScaleType m_scaleType; + int m_scalePercent; + QTimer m_resizeTimer; }; } // namespace LimeReport diff --git a/limereport/lrpreviewreportwindow.cpp b/limereport/lrpreviewreportwindow.cpp index 02dd372..fec6d75 100644 --- a/limereport/lrpreviewreportwindow.cpp +++ b/limereport/lrpreviewreportwindow.cpp @@ -255,7 +255,22 @@ void PreviewReportWindow::showEvent(QShowEvent *) { m_fontEditor->setVisible(ui->actionEdit_Mode->isChecked()); m_textAlignmentEditor->setVisible(ui->actionEdit_Mode->isChecked()); + switch (m_previewScaleType) { + case FitWidth: + m_previewReportWidget->fitWidth(); + break; + case FitPage: + m_previewReportWidget->fitPage(); + break; + case OneToOne: + m_previewReportWidget->setScalePercent(100); + break; + case Percents: + m_previewReportWidget->setScalePercent(m_previewScalePercent); + + } } + void PreviewReportWindow::selectStateIcon() { if (ui->toolBar->isHidden()){ @@ -335,6 +350,18 @@ void PreviewReportWindow::initPercentCombobox() m_scalePercent->setCurrentIndex(4); } +ScaleType PreviewReportWindow::previewScaleType() const +{ + return m_previewScaleType; +} + +void PreviewReportWindow::setPreviewScaleType(const ScaleType &previewScaleType, int percent) +{ + m_previewScaleType = previewScaleType; + m_previewScalePercent = percent; + m_previewReportWidget->setScaleType(previewScaleType, percent); +} + void PreviewReportWindow::on_actionSaveToFile_triggered() { m_previewReportWidget->saveToFile(); diff --git a/limereport/lrpreviewreportwindow.h b/limereport/lrpreviewreportwindow.h index bfa50b5..9b29ce5 100644 --- a/limereport/lrpreviewreportwindow.h +++ b/limereport/lrpreviewreportwindow.h @@ -71,6 +71,9 @@ public: void setMenuVisible(bool value); void setHideResultEditButton(bool value); QSettings* settings(); + ScaleType previewScaleType() const; + void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0); + protected: void writeSetting(); void restoreSetting(); @@ -118,6 +121,9 @@ private: int m_priorScrolValue; PreviewReportWidget* m_previewReportWidget; QComboBox* m_scalePercent; + ScaleType m_previewScaleType; + int m_previewScalePercent; + }; } //namespace LimeReport #endif // LRPREVIEWREPORTWINDOW_H diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index c9b44b1..c89fc83 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -81,7 +81,8 @@ ReportEnginePrivate::ReportEnginePrivate(QObject *parent) : m_previewWindowIcon(":/report/images/logo32"), m_previewWindowTitle(tr("Preview")), m_reportRendering(false), m_resultIsEditable(true), m_passPhrase("HjccbzHjlbyfCkjy"), m_fileWatcher( new QFileSystemWatcher( this ) ), m_reportLanguage(QLocale::AnyLanguage), - m_previewLayoutDirection(Qt::LeftToRight), m_designerFactory(0) + m_previewLayoutDirection(Qt::LeftToRight), m_designerFactory(0), + m_previewScaleType(FitWidth), m_previewScalePercent(0) { #ifdef HAVE_STATIC_BUILD initResources(); @@ -527,6 +528,7 @@ void ReportEnginePrivate::previewReport(PreviewHints hints) w->setSettings(settings()); w->setPages(pages); w->setLayoutDirection(m_previewLayoutDirection); + if (!dataManager()->errorsList().isEmpty()){ w->setErrorMessages(dataManager()->errorsList()); } @@ -540,6 +542,9 @@ void ReportEnginePrivate::previewReport(PreviewHints hints) w->setHideResultEditButton(resultIsEditable()); w->setStyleSheet(m_styleSheet); m_activePreview = w; + + w->setPreviewScaleType(m_previewScaleType, m_previewScalePercent); + connect(w,SIGNAL(destroyed(QObject*)), this, SLOT(slotPreviewWindowDestroyed(QObject*))); w->exec(); } @@ -909,7 +914,24 @@ QString ReportEnginePrivate::renderToString() render.setDatasources(dataManager()); render.setScriptContext(scriptContext()); return render.renderPageToString(m_pages.at(0)->pageItem()); - }else return QString(); + } else return QString(); + +} + +ScaleType ReportEnginePrivate::previewScaleType() +{ + return m_previewScaleType; +} + +int ReportEnginePrivate::previewScalePercent() +{ + return m_previewScalePercent; +} + +void ReportEnginePrivate::setPreviewScaleType(const ScaleType &scaleType, int percent) +{ + m_previewScaleType = scaleType; + m_previewScalePercent = percent; } PageItemDesignIntf* ReportEnginePrivate::getPageByName(const QString& pageName) @@ -1344,6 +1366,25 @@ QLocale::Language ReportEngine::currentDesignerLanguage() return d->currentDesignerLanguage(); } +ScaleType ReportEngine::previewScaleType() +{ + Q_D(ReportEngine); + return d->previewScaleType(); +} + +int ReportEngine::previewScalePercent() +{ + Q_D(ReportEngine); + return d->previewScalePercent(); +} + +void ReportEngine::setPreviewScaleType(const ScaleType &previewScaleType, int percent) +{ + Q_D(ReportEngine); + d->setPreviewScaleType(previewScaleType, percent); +} + + void ReportEngine::setShowProgressDialog(bool value) { Q_D(ReportEngine); diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index e3d4ec4..38f8c1b 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -116,6 +116,9 @@ public: void setPreviewLayoutDirection(const Qt::LayoutDirection& previewLayoutDirection); QList designerLanguages(); QLocale::Language currentDesignerLanguage(); + ScaleType previewScaleType(); + int previewScalePercent(); + void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0); signals: void cleared(); void renderStarted(); diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index 4756b20..ef2d85e 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -193,6 +193,9 @@ public: QList designerLanguages(); QLocale::Language currentDesignerLanguage(); void setCurrentDesignerLanguage(QLocale::Language language); + ScaleType previewScaleType(); + int previewScalePercent(); + void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0); signals: void pagesLoadFinished(); void datasourceCollectionLoadFinished(const QString& collectionName); @@ -271,6 +274,8 @@ private: QString m_styleSheet; QLocale::Language m_currentDesignerLanguage; QMap exporters; + ScaleType m_previewScaleType; + int m_previewScalePercent; }; }