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 0000000..b29f9a9 Binary files /dev/null and b/src/images/grid.png differ diff --git a/src/images/settings.png b/src/images/settings.png new file mode 100644 index 0000000..64dae39 Binary files /dev/null and b/src/images/settings.png differ 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