From b8900b1e96ac0de3e81810ff76d972fa5614c2f2 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Mon, 18 Feb 2019 15:16:55 +0300 Subject: [PATCH] Added the ability to change the background color of the preview page --- include/lrpreviewreportwidget.h | 5 ++++- include/lrreportengine.h | 1 + limereport/lrpreviewreportwidget.cpp | 13 ++++++++++++- limereport/lrpreviewreportwidget.h | 5 ++++- limereport/lrpreviewreportwidget_p.h | 4 ++-- limereport/lrpreviewreportwindow.cpp | 13 ++++++++++++- limereport/lrpreviewreportwindow.h | 4 ++-- limereport/lrreportengine.cpp | 20 +++++++++++++++++++- limereport/lrreportengine.h | 1 + limereport/lrreportengine_p.h | 3 +++ 10 files changed, 60 insertions(+), 9 deletions(-) diff --git a/include/lrpreviewreportwidget.h b/include/lrpreviewreportwidget.h index 395af7d..306af9c 100644 --- a/include/lrpreviewreportwidget.h +++ b/include/lrpreviewreportwidget.h @@ -29,6 +29,8 @@ public: ScaleType scaleType() const; int scalePercent() const; void setScaleType(const ScaleType &scaleType, int percent = 0); + void setPreviewPageBackgroundColor(QColor color); + QColor previewPageBackgroundColor(); public slots: void refreshPages(); void zoomIn(); @@ -67,7 +69,8 @@ private: PreviewReportWidgetPrivate* d_ptr; ScaleType m_scaleType; int m_scalePercent; - QTimer m_resizeTimer; + QTimer m_resizeTimer; + QColor m_previewPageBackgroundColor; }; } // namespace LimeReport diff --git a/include/lrreportengine.h b/include/lrreportengine.h index 178dcc2..a36d1b0 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -107,6 +107,7 @@ public: PreviewReportWidget *createPreviewWidget(QWidget *parent = 0); void setPreviewWindowTitle(const QString& title); void setPreviewWindowIcon(const QIcon& icon); + void setPreviewPageBackgroundColor(QColor color); void setResultEditable(bool value); bool resultIsEditable(); bool isBusy(); diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index fb24404..6799a62 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -71,7 +71,7 @@ QList PreviewReportWidgetPrivate::aviableExporters() PreviewReportWidget::PreviewReportWidget(ReportEngine *report, QWidget *parent) : QWidget(parent), ui(new Ui::PreviewReportWidget), d_ptr(new PreviewReportWidgetPrivate(this)), - m_scaleType(FitWidth), m_scalePercent(0) + m_scaleType(FitWidth), m_scalePercent(0), m_previewPageBackgroundColor(Qt::white) { ui->setupUi(this); d_ptr->m_report = report->d_ptr; @@ -127,6 +127,7 @@ void PreviewReportWidget::initPreview() ui->graphicsView->setScene(d_ptr->m_previewPage); ui->graphicsView->resetMatrix(); ui->graphicsView->centerOn(0, 0); + ui->graphicsView->scene()->setBackgroundBrush(QColor(m_previewPageBackgroundColor)); setScalePercent(d_ptr->m_scalePercent); } @@ -322,6 +323,16 @@ void PreviewReportWidget::setScaleType(const ScaleType &scaleType, int percent) m_scalePercent = percent; } +void PreviewReportWidget::setPreviewPageBackgroundColor(QColor color) +{ + m_previewPageBackgroundColor = color; +} + +QColor PreviewReportWidget::previewPageBackgroundColor() +{ + return m_previewPageBackgroundColor; +} + void PreviewReportWidget::refreshPages() { if (d_ptr->m_report){ diff --git a/limereport/lrpreviewreportwidget.h b/limereport/lrpreviewreportwidget.h index 395af7d..306af9c 100644 --- a/limereport/lrpreviewreportwidget.h +++ b/limereport/lrpreviewreportwidget.h @@ -29,6 +29,8 @@ public: ScaleType scaleType() const; int scalePercent() const; void setScaleType(const ScaleType &scaleType, int percent = 0); + void setPreviewPageBackgroundColor(QColor color); + QColor previewPageBackgroundColor(); public slots: void refreshPages(); void zoomIn(); @@ -67,7 +69,8 @@ private: PreviewReportWidgetPrivate* d_ptr; ScaleType m_scaleType; int m_scalePercent; - QTimer m_resizeTimer; + QTimer m_resizeTimer; + QColor m_previewPageBackgroundColor; }; } // namespace LimeReport diff --git a/limereport/lrpreviewreportwidget_p.h b/limereport/lrpreviewreportwidget_p.h index c7c2ce1..078ce5e 100644 --- a/limereport/lrpreviewreportwidget_p.h +++ b/limereport/lrpreviewreportwidget_p.h @@ -15,7 +15,7 @@ public: PreviewReportWidgetPrivate(PreviewReportWidget* previewReportWidget): m_previewPage(NULL), m_report(NULL), m_zoomer(NULL), m_currentPage(1), m_changingPage(false), m_priorScrolValue(0), m_scalePercent(50), - q_ptr(previewReportWidget) {} + q_ptr(previewReportWidget), m_previePageColor(Qt::white) {} bool pageIsVisible(); QRectF calcPageShift(); void setPages( ReportPages pages); @@ -31,7 +31,7 @@ public: int m_priorScrolValue; int m_scalePercent; PreviewReportWidget* q_ptr; - + QColor m_previePageColor; }; } diff --git a/limereport/lrpreviewreportwindow.cpp b/limereport/lrpreviewreportwindow.cpp index c81591e..71fed64 100644 --- a/limereport/lrpreviewreportwindow.cpp +++ b/limereport/lrpreviewreportwindow.cpp @@ -47,7 +47,8 @@ namespace LimeReport{ PreviewReportWindow::PreviewReportWindow(ReportEngine *report, QWidget *parent, QSettings *settings, Qt::WindowFlags flags) : QMainWindow(parent,flags), - ui(new Ui::PreviewReportWindow), m_settings(settings), m_ownedSettings(false), m_scalePercentChanging(false) + ui(new Ui::PreviewReportWindow), m_settings(settings), m_ownedSettings(false), + m_scalePercentChanging(false) { ui->setupUi(this); setWindowTitle("Lime Report Preview"); @@ -362,6 +363,16 @@ void PreviewReportWindow::setPreviewScaleType(const ScaleType &previewScaleType, m_previewReportWidget->setScaleType(previewScaleType, percent); } +QColor PreviewReportWindow::previewPageBackgroundColor() +{ + return m_previewReportWidget->previewPageBackgroundColor(); +} + +void PreviewReportWindow::setPreviewPageBackgroundColor(QColor color) +{ + m_previewReportWidget->setPreviewPageBackgroundColor(color); +} + void PreviewReportWindow::on_actionSaveToFile_triggered() { m_previewReportWidget->saveToFile(); diff --git a/limereport/lrpreviewreportwindow.h b/limereport/lrpreviewreportwindow.h index a42ccde..dc210ce 100644 --- a/limereport/lrpreviewreportwindow.h +++ b/limereport/lrpreviewreportwindow.h @@ -73,7 +73,8 @@ public: QSettings* settings(); ScaleType previewScaleType() const; void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0); - + QColor previewPageBackgroundColor(); + void setPreviewPageBackgroundColor(QColor color); protected: void writeSetting(); void restoreSetting(); @@ -124,7 +125,6 @@ private: ScaleType m_previewScaleType; int m_previewScalePercent; bool m_scalePercentChanging; - }; } //namespace LimeReport #endif // LRPREVIEWREPORTWINDOW_H diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 2c3890c..9591c13 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -82,7 +82,8 @@ ReportEnginePrivate::ReportEnginePrivate(QObject *parent) : m_reportRendering(false), m_resultIsEditable(true), m_passPhrase("HjccbzHjlbyfCkjy"), m_fileWatcher( new QFileSystemWatcher( this ) ), m_reportLanguage(QLocale::AnyLanguage), m_previewLayoutDirection(Qt::LayoutDirectionAuto), m_designerFactory(0), - m_previewScaleType(FitWidth), m_previewScalePercent(0), m_startTOCPage(0) + m_previewScaleType(FitWidth), m_previewScalePercent(0), m_startTOCPage(0), + m_previewPageBackgroundColor(Qt::white) { #ifdef HAVE_STATIC_BUILD initResources(); @@ -503,6 +504,7 @@ void ReportEnginePrivate::previewReport(PreviewHints hints) if (pages.count()>0){ Q_Q(ReportEngine); PreviewReportWindow* w = new PreviewReportWindow(q,0,settings()); + w->setPreviewPageBackgroundColor(m_previewPageBackgroundColor); w->setWindowFlags(Qt::Dialog|Qt::WindowMaximizeButtonHint|Qt::WindowCloseButtonHint| Qt::WindowMinMaxButtonsHint); w->setAttribute(Qt::WA_DeleteOnClose,true); w->setWindowModality(Qt::ApplicationModal); @@ -1094,6 +1096,16 @@ void ReportEnginePrivate::setPreviewWindowTitle(const QString &previewWindowTitl m_previewWindowTitle = previewWindowTitle; } +QColor ReportEnginePrivate::previewWindowPageBackground() +{ + return m_previewPageBackgroundColor; +} + +void ReportEnginePrivate::setPreviewWindowPageBackground(QColor color) +{ + m_previewPageBackgroundColor = color; +} + QIcon ReportEnginePrivate::previewWindowIcon() const { return m_previewWindowIcon; @@ -1338,6 +1350,12 @@ void ReportEngine::setPreviewWindowIcon(const QIcon &icon) d->setPreviewWindowIcon(icon); } +void ReportEngine::setPreviewPageBackgroundColor(QColor color) +{ + Q_D(ReportEngine); + d->setPreviewWindowPageBackground(color); +} + void ReportEngine::setResultEditable(bool value) { Q_D(ReportEngine); diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index 178dcc2..a36d1b0 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -107,6 +107,7 @@ public: PreviewReportWidget *createPreviewWidget(QWidget *parent = 0); void setPreviewWindowTitle(const QString& title); void setPreviewWindowIcon(const QIcon& icon); + void setPreviewPageBackgroundColor(QColor color); void setResultEditable(bool value); bool resultIsEditable(); bool isBusy(); diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index 27aa8ff..1813f81 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -189,6 +189,8 @@ public: void setPreviewWindowIcon(const QIcon &previewWindowIcon); QString previewWindowTitle() const; void setPreviewWindowTitle(const QString &previewWindowTitle); + QColor previewWindowPageBackground(); + void setPreviewWindowPageBackground(QColor color); bool suppressFieldAndVarError() const; void setSuppressFieldAndVarError(bool suppressFieldAndVarError); @@ -299,6 +301,7 @@ private: ScaleType m_previewScaleType; int m_previewScalePercent; int m_startTOCPage; + QColor m_previewPageBackgroundColor; }; }