From 80be785f9596d1918c2b6544f1a3e0bcc57f5ef3 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Thu, 18 Feb 2016 21:11:59 +0300 Subject: [PATCH] Grid and Settings have been added Grid and Settings have been added --- report-lib.pri | 9 +- src/images/grid.png | Bin 0 -> 305 bytes src/images/settings.png | Bin 0 -> 583 bytes src/lrpageitemdesignintf.h | 3 +- src/lrreportdesignwidget.cpp | 91 ++++++++++++++++-- src/lrreportdesignwidget.h | 16 ++- src/lrreportdesignwindow.cpp | 32 +++++- src/lrreportdesignwindow.h | 5 +- src/lrsettingdialog.cpp | 47 +++++++++ src/lrsettingdialog.h | 27 ++++++ src/lrsettingdialog.ui | 182 +++++++++++++++++++++++++++++++++++ src/report.qrc | 2 + 12 files changed, 399 insertions(+), 15 deletions(-) create mode 100644 src/images/grid.png create mode 100644 src/images/settings.png create mode 100644 src/lrsettingdialog.cpp create mode 100644 src/lrsettingdialog.h create mode 100644 src/lrsettingdialog.ui diff --git a/report-lib.pri b/report-lib.pri index 61a7b84..a89f99d 100644 --- a/report-lib.pri +++ b/report-lib.pri @@ -112,7 +112,8 @@ SOURCES += \ $$REPORT_PATH/lrvariablesholder.cpp \ $$REPORT_PATH/lrgroupfunctions.cpp \ $$REPORT_PATH/lrsimplecrypt.cpp \ - $$REPORT_PATH/lraboutdialog.cpp + $$REPORT_PATH/lraboutdialog.cpp \ + $$REPORT_PATH/lrsettingdialog.cpp contains(CONFIG, zint){ SOURCES += $$REPORT_PATH/items/lrbarcodeitem.cpp @@ -204,7 +205,8 @@ HEADERS += \ $$REPORT_PATH/lrscriptenginemanagerintf.h \ $$REPORT_PATH/lrsimplecrypt.h \ $$REPORT_PATH/lraboutdialog.h \ - $$REPORT_PATH/lrcallbackdatasourceintf.h + $$REPORT_PATH/lrcallbackdatasourceintf.h \ + $$REPORT_PATH/lrsettingdialog.h contains(CONFIG,zint){ HEADERS += $$REPORT_PATH/items/lrbarcodeitem.h @@ -218,7 +220,8 @@ FORMS += \ $$REPORT_PATH/objectinspector/editors/ltextitempropertyeditor.ui \ $$REPORT_PATH/lrpreviewreportwindow.ui \ $$REPORT_PATH/items/lrtextitemeditor.ui \ - $$REPORT_PATH/lraboutdialog.ui + $$REPORT_PATH/lraboutdialog.ui \ + $$REPORT_PATH/lrsettingdialog.ui RESOURCES += \ $$REPORT_PATH/objectinspector/lobjectinspector.qrc \ diff --git a/src/images/grid.png b/src/images/grid.png new file mode 100644 index 0000000000000000000000000000000000000000..b29f9a939b45ae4f7df2d4bf1d701587d9e29636 GIT binary patch literal 305 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPN6SugDm9X5e&p@Glo-U3d7N_4{Hq1NZAkg|SUzWYA zMJ3dNQC2l|3UdK#RG;f?>8ElMJsM&ymwQy56S-AW-J~+>&c1m2X7aOxr79xjA4-e2 z&W!)iBG|>~7u(ok^hz_%K<cl@eZt`B>gTe~DWM4fv66TX literal 0 HcmV?d00001 diff --git a/src/images/settings.png b/src/images/settings.png new file mode 100644 index 0000000000000000000000000000000000000000..64dae390e91ae5cd5cb1039904cd62716bd0a8ff GIT binary patch literal 583 zcmV-N0=WH&P)YwNJyuE>~ep z32Xo<-G_h)U}E$*w#1PfyImkktx;t$O6|iawPOI@=_OTm0=o_#GqV7}Jk2n%k8-S` z)KS93E&->2Enp4UJ)ri72n|(+fd{>gI}KE7!R)j2L?QN|LSdTPK+!7i1165 zH>NyF0Aoe}IrD*>2x5927XWqjdKo~KGeGw*{BE8@z0PK_+mXfY$bXyor$8`Iv(~U5 zfw~9^-0@Bq0mR6(2>{{yeO2JgGoh){(&7ZCfJSlUiTBazqYhhwntCp!U!o;pbseM+3`3>96 VxU@P(euMx3002ovPDHLkV1g$&^%(#F literal 0 HcmV?d00001 diff --git a/src/lrpageitemdesignintf.h b/src/lrpageitemdesignintf.h index 7a1f776..8b0f741 100644 --- a/src/lrpageitemdesignintf.h +++ b/src/lrpageitemdesignintf.h @@ -47,7 +47,8 @@ class PageItemDesignIntf : public LimeReport::BaseDesignIntf Q_PROPERTY(int rightMargin READ rightMargin WRITE setRightMargin) Q_PROPERTY(int leftMargin READ leftMargin WRITE setLeftMargin) Q_PROPERTY(Orientation pageOrientation READ pageOrientation WRITE setPageOrientation) - Q_PROPERTY(PageSize pageSize READ pageSize WRITE setPageSize) + Q_PROPERTY(PageSize pageSize READ pageSize WRITE setPageSize ) + Q_PROPERTY(int gridStep READ gridStep WRITE setGridStep) friend class ReportRender; public: enum Orientation { Portrait, Landscape }; diff --git a/src/lrreportdesignwidget.cpp b/src/lrreportdesignwidget.cpp index c204a9c..2296f42 100644 --- a/src/lrreportdesignwidget.cpp +++ b/src/lrreportdesignwidget.cpp @@ -32,6 +32,7 @@ #include "serializators/lrxmlwriter.h" #include "lrreportengine_p.h" #include "lrbasedesignintf.h" +#include "lrsettingdialog.h" #include #include @@ -96,10 +97,10 @@ bool GraphicsViewZoom::eventFilter(QObject *object, QEvent *event) { } // ReportDesignIntf -ReportDesignWidget* ReportDesignWidget::m_instance=0; +//ReportDesignWidget* ReportDesignWidget::m_instance=0; ReportDesignWidget::ReportDesignWidget(ReportEnginePrivate *report, QMainWindow *mainWindow, QWidget *parent) : - QWidget(parent), m_mainWindow(mainWindow) + QWidget(parent), m_mainWindow(mainWindow), m_verticalGridStep(10), m_horizontalGridStep(10), m_useGrid(false) { QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setContentsMargins(1,1,1,1); @@ -125,13 +126,61 @@ ReportDesignWidget::ReportDesignWidget(ReportEnginePrivate *report, QMainWindow connect(m_report,SIGNAL(pagesLoadFinished()),this,SLOT(slotPagesLoadFinished())); connect(m_report,SIGNAL(cleared()),this,SIGNAL(cleared())); m_view->scale(0.5,0.5); - m_instance=this; + //m_instance=this; //m_view->viewport()->installEventFilter(this); m_zoomer = new GraphicsViewZoom(m_view); +#ifdef Q_OS_WIN + m_defaultFont = QFont("Arial",10); +#endif +} + +void ReportDesignWidget::saveState(QSettings* settings) +{ + settings->beginGroup("DesignerWidget"); + settings->setValue("hGridStep",m_horizontalGridStep); + settings->setValue("vGridStep",m_verticalGridStep); + settings->setValue("defaultFont",m_defaultFont); + settings->setValue("useGrid",m_useGrid); + settings->endGroup(); +} + +void ReportDesignWidget::applySettings() +{ + for (int i=0;ipageCount();++i){ + m_report->pageAt(i)->pageItem()->setFont(m_defaultFont); + } + applyUseGrid(); +} + +void ReportDesignWidget::loadState(QSettings* settings) +{ + settings->beginGroup("DesignerWidget"); + QVariant v = settings->value("hGridStep"); + if (v.isValid()){ + m_horizontalGridStep = v.toInt(); + } + + v = settings->value("vGridStep"); + if (v.isValid()){ + m_verticalGridStep = v.toInt(); + } + v = settings->value("defaultFont"); + if (v.isValid()){ + m_defaultFont = v.value(); + } + + v = settings->value("useGrid"); + if (v.isValid()){ + m_useGrid = v.toBool(); + } + + settings->endGroup(); + + applySettings(); } ReportDesignWidget::~ReportDesignWidget() -{ m_instance=0;} +{ /*m_instance=0;*/} void ReportDesignWidget::setActivePage(PageDesignIntf *page) { @@ -153,8 +202,6 @@ void ReportDesignWidget::setActivePage(PageDesignIntf *page) connect(page, SIGNAL(bandRemoved(LimeReport::PageDesignIntf*,LimeReport::BandDesignIntf*)), this, SIGNAL(bandDeleted(LimeReport::PageDesignIntf*,LimeReport::BandDesignIntf*))); - - m_view->centerOn(0, 0); emit activePageChanged(); } @@ -367,6 +414,37 @@ void ReportDesignWidget::setBorders(const BaseDesignIntf::BorderLines& borders) activePage()->setBorders(borders); } +void ReportDesignWidget::editSetting() +{ + SettingDialog setting(this); + setting.setVerticalGridStep(m_verticalGridStep); + setting.setHorizontalGridStep(m_horizontalGridStep); + setting.setDefaultFont(m_defaultFont); + + if (setting.exec()){ + m_horizontalGridStep = setting.horizontalGridStep(); + m_verticalGridStep = setting.verticalGridStep(); + m_defaultFont = setting.defaultFont(); + applySettings(); + } +} + +void ReportDesignWidget::applyUseGrid() +{ + int hGridStep = m_useGrid?m_horizontalGridStep:2; + int vGridStep = m_useGrid?m_verticalGridStep:2; + for(int i=0;ipageCount();++i){ + m_report->pageAt(i)->setVerticalGridStep(hGridStep); + m_report->pageAt(i)->setHorizontalGridStep(vGridStep); + } +} + +void ReportDesignWidget::setUseGrid(bool value) +{ + m_useGrid = value; + applyUseGrid(); +} + bool ReportDesignWidget::isCanUndo() { return activePage()->isCanUndo(); @@ -399,6 +477,7 @@ DataSourceManager* ReportDesignWidget::dataManager() void ReportDesignWidget::slotPagesLoadFinished() { + applySettings(); setActivePage(m_report->pageAt(0)); emit loaded(); } diff --git a/src/lrreportdesignwidget.h b/src/lrreportdesignwidget.h index f38f5d5..4e9aa14 100644 --- a/src/lrreportdesignwidget.h +++ b/src/lrreportdesignwidget.h @@ -72,7 +72,7 @@ class ReportDesignWidget : public QWidget friend class ReportDesignWindow; public: ~ReportDesignWidget(); - static ReportDesignWidget* instance(){return m_instance;} +// static ReportDesignWidget* instance(){return m_instance;} void createStartPage(); void clear(); DataSourceManager* dataManager(); @@ -94,6 +94,12 @@ public: QString reportFileName(); bool isNeedToSave(); bool emitLoadReport(); + void saveState(QSettings *settings); + void loadState(QSettings *settings); + void applySettings(); + void applyUseGrid(); + bool useGrid(){ return m_useGrid;} + public slots: void saveToFile(const QString&); bool save(); @@ -120,6 +126,8 @@ public slots: void setFont(const QFont &font); void setTextAlign(const bool &horizontalAlign, const Qt::AlignmentFlag &alignment); void setBorders(const BaseDesignIntf::BorderLines& borders); + void editSetting(); + void setUseGrid(bool value); private slots: void slotItemSelected(LimeReport::BaseDesignIntf *item); void slotSelectionChanged(); @@ -149,7 +157,11 @@ private: QGraphicsView *m_view; QMainWindow *m_mainWindow; GraphicsViewZoom* m_zoomer; - static ReportDesignWidget* m_instance; + QFont m_defaultFont; + int m_verticalGridStep; + int m_horizontalGridStep; + bool m_useGrid; +// static ReportDesignWidget* m_instance; }; } diff --git a/src/lrreportdesignwindow.cpp b/src/lrreportdesignwindow.cpp index 4841a6d..0c5663a 100644 --- a/src/lrreportdesignwindow.cpp +++ b/src/lrreportdesignwindow.cpp @@ -129,6 +129,15 @@ void ReportDesignWindow::createActions() m_cutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X)); connect(m_cutAction,SIGNAL(triggered()),this,SLOT(slotCut())); + m_settingsAction = new QAction(tr("Settings"),this); + m_settingsAction->setIcon(QIcon(":/report/images/settings")); + connect(m_settingsAction,SIGNAL(triggered()),this,SLOT(slotEditSettings())); + + m_useGridAction = new QAction(tr("Use grid"),this); + m_useGridAction->setIcon(QIcon(":/report/images/grid")); + m_useGridAction->setCheckable(true); + connect(m_useGridAction,SIGNAL(toggled(bool)),this,SLOT(slotUseGrid(bool))); + m_newTextItemAction = new QAction(tr("Text Item"),this); m_newTextItemAction->setIcon(QIcon(":/items/TextItem")); m_actionMap.insert("TextItem",m_newTextItemAction); @@ -241,6 +250,8 @@ void ReportDesignWindow::createToolBars() m_mainToolBar->addAction(m_loadReportAction); m_mainToolBar->addAction(m_saveReportAction); m_mainToolBar->addSeparator(); + m_mainToolBar->addAction(m_settingsAction); + m_mainToolBar->addSeparator(); m_mainToolBar->addAction(m_copyAction); m_mainToolBar->addAction(m_pasteAction); @@ -252,8 +263,10 @@ void ReportDesignWindow::createToolBars() m_mainToolBar->addAction(m_zoomInReportAction); m_mainToolBar->addAction(m_zoomOutReportAction); m_mainToolBar->addSeparator(); - m_mainToolBar->addAction(m_previewReportAction); + //m_mainToolBar->addSeparator(); + //m_mainToolBar->addAction(m_useGridAction); + //m_mainToolBar->addAction(m_printReportAction); m_fontEditorBar = new FontEditorWidget(m_reportDesignWidget,tr("Font"),this); @@ -267,10 +280,11 @@ void ReportDesignWindow::createToolBars() m_itemsAlignmentEditorBar = new ItemsAlignmentEditorWidget(m_reportDesignWidget,tr("Items alignment"),this); m_itemsAlignmentEditorBar->setIconSize(m_mainToolBar->iconSize()); m_itemsAlignmentEditorBar->setObjectName("itemsAlignmentTools"); + m_itemsAlignmentEditorBar->insertAction(m_itemsAlignmentEditorBar->actions().at(0),m_useGridAction); addToolBar(m_itemsAlignmentEditorBar); m_itemsBordersEditorBar = new ItemsBordersEditorWidget(m_reportDesignWidget,tr("Borders"),this); m_itemsBordersEditorBar->setIconSize(m_mainToolBar->iconSize()); - m_itemsBordersEditorBar->setObjectName("itemsBorederTools"); + m_itemsBordersEditorBar->setObjectName("itemsBorderTools"); addToolBar(m_itemsBordersEditorBar); createReportToolBar(); @@ -384,6 +398,7 @@ void ReportDesignWindow::createMainMenu() m_editMenu->addAction(m_copyAction); m_editMenu->addAction(m_pasteAction); m_editMenu->addAction(m_cutAction); + m_editMenu->addAction(m_settingsAction); m_infoMenu = menuBar()->addMenu(tr("Info")); m_infoMenu->addAction(m_aboutAction); @@ -495,6 +510,7 @@ void ReportDesignWindow::writeState() settings()->setValue("State",saveState()); settings()->setValue("InspectorFirsColumnWidth",m_objectInspector->columnWidth(0)); settings()->endGroup(); + m_reportDesignWidget->saveState(settings()); } void ReportDesignWindow::restoreSetting() @@ -524,6 +540,8 @@ void ReportDesignWindow::restoreSetting() m_objectInspector->setColumnWidth(0,v.toInt()); } settings()->endGroup(); + m_reportDesignWidget->loadState(settings()); + m_useGridAction->setChecked(m_reportDesignWidget->useGrid()); } bool ReportDesignWindow::checkNeedToSave() @@ -948,6 +966,16 @@ void ReportDesignWindow::slotHideRightPanel(bool value) hideDockWidgets(Qt::RightDockWidgetArea,value); } +void ReportDesignWindow::slotEditSettings() +{ + m_reportDesignWidget->editSetting(); +} + +void ReportDesignWindow::slotUseGrid(bool value) +{ + m_reportDesignWidget->setUseGrid(value); +} + void ReportDesignWindow::closeEvent(QCloseEvent * event) { if (checkNeedToSave()){ diff --git a/src/lrreportdesignwindow.h b/src/lrreportdesignwindow.h index 6be217f..5e46bc1 100644 --- a/src/lrreportdesignwindow.h +++ b/src/lrreportdesignwindow.h @@ -109,6 +109,8 @@ private slots: void slotShowAbout(); void slotHideLeftPanel(bool value); void slotHideRightPanel(bool value); + void slotEditSettings(); + void slotUseGrid(bool value); protected: void closeEvent(QCloseEvent *event); void resizeEvent(QResizeEvent *); @@ -133,7 +135,6 @@ private: private: static ReportDesignWindow* m_instance; - QStatusBar* m_statusBar; QToolBar* m_mainToolBar; QToolBar* m_fontToolBar; @@ -165,6 +166,8 @@ private: QAction* m_copyAction; QAction* m_pasteAction; QAction* m_cutAction; + QAction* m_settingsAction; + QAction* m_useGridAction; QAction* m_newPageHeader; QAction* m_newPageFooter; diff --git a/src/lrsettingdialog.cpp b/src/lrsettingdialog.cpp new file mode 100644 index 0000000..b02b2f0 --- /dev/null +++ b/src/lrsettingdialog.cpp @@ -0,0 +1,47 @@ +#include "lrsettingdialog.h" +#include "ui_lrsettingdialog.h" + +SettingDialog::SettingDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SettingDialog) +{ + ui->setupUi(this); +} + +SettingDialog::~SettingDialog() +{ + delete ui; +} + +int SettingDialog::verticalGridStep() +{ + return ui->verticalGridStep->value(); +} + +int SettingDialog::horizontalGridStep() +{ + return ui->horizontalGridStep->value(); +} + +QFont SettingDialog::defaultFont() +{ + QFont result = ui->defaultFont->currentFont(); + result.setPointSize(ui->defaultFontSize->value()); + return result; +} + +void SettingDialog::setHorizontalGridStep(int value) +{ + ui->horizontalGridStep->setValue(value); +} + +void SettingDialog::setVerticalGridStep(int value) +{ + ui->verticalGridStep->setValue(value); +} + +void SettingDialog::setDefaultFont(const QFont &value) +{ + ui->defaultFont->setCurrentFont(value); + ui->defaultFontSize->setValue(value.pointSize()); +} diff --git a/src/lrsettingdialog.h b/src/lrsettingdialog.h new file mode 100644 index 0000000..053c1c9 --- /dev/null +++ b/src/lrsettingdialog.h @@ -0,0 +1,27 @@ +#ifndef LRSETTINGDIALOG_H +#define LRSETTINGDIALOG_H + +#include + +namespace Ui { +class SettingDialog; +} + +class SettingDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SettingDialog(QWidget *parent = 0); + ~SettingDialog(); + int verticalGridStep(); + int horizontalGridStep(); + QFont defaultFont(); + void setHorizontalGridStep(int value); + void setVerticalGridStep(int value); + void setDefaultFont(const QFont& value); +private: + Ui::SettingDialog *ui; +}; + +#endif // LRSETTINGDIALOG_H diff --git a/src/lrsettingdialog.ui b/src/lrsettingdialog.ui new file mode 100644 index 0000000..f8c5120 --- /dev/null +++ b/src/lrsettingdialog.ui @@ -0,0 +1,182 @@ + + + SettingDialog + + + + 0 + 0 + 298 + 184 + + + + Designer setting + + + + + + + + Default font + + + + + + + + + + 10 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Grid + + + + + + + + Vertical grid step + + + + + + + 10 + + + + + + + Horizontal grid step + + + + + + + 10 + + + + + + + + + Qt::Horizontal + + + + 73 + 20 + + + + + + + + + + + Qt::Vertical + + + + 20 + 4 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + bbOkCancel + accepted() + SettingDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + bbOkCancel + rejected() + SettingDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/report.qrc b/src/report.qrc index 5d48873..b47d795 100644 --- a/src/report.qrc +++ b/src/report.qrc @@ -158,5 +158,7 @@ images/hideLeftPanel.png images/hideRightPanel.png images/PDF2.png + images/settings.png + images/grid.png