0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-23 16:22:58 +03:00

Grid and Settings have been added

Grid and Settings have been added
This commit is contained in:
Arin Alexander 2016-02-18 21:11:59 +03:00
parent 4cfa653ed8
commit 80be785f95
12 changed files with 399 additions and 15 deletions

View File

@ -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 \

BIN
src/images/grid.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

BIN
src/images/settings.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 B

View File

@ -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 };

View File

@ -32,6 +32,7 @@
#include "serializators/lrxmlwriter.h"
#include "lrreportengine_p.h"
#include "lrbasedesignintf.h"
#include "lrsettingdialog.h"
#include <QDebug>
#include <QObject>
@ -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;i<m_report->pageCount();++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<QFont>();
}
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;i<m_report->pageCount();++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();
}

View File

@ -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;
};
}

View File

@ -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()){

View File

@ -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;

47
src/lrsettingdialog.cpp Normal file
View File

@ -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());
}

27
src/lrsettingdialog.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef LRSETTINGDIALOG_H
#define LRSETTINGDIALOG_H
#include <QDialog>
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

182
src/lrsettingdialog.ui Normal file
View File

@ -0,0 +1,182 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SettingDialog</class>
<widget class="QDialog" name="SettingDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>298</width>
<height>184</height>
</rect>
</property>
<property name="windowTitle">
<string>Designer setting</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Default font</string>
</property>
</widget>
</item>
<item>
<widget class="QFontComboBox" name="defaultFont"/>
</item>
<item>
<widget class="QSpinBox" name="defaultFontSize">
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Grid</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Vertical grid step</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="verticalGridStep">
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Horizontal grid step</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="horizontalGridStep">
<property name="value">
<number>10</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>73</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>4</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="bbOkCancel">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>bbOkCancel</sender>
<signal>accepted()</signal>
<receiver>SettingDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>bbOkCancel</sender>
<signal>rejected()</signal>
<receiver>SettingDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -158,5 +158,7 @@
<file alias="/images/hideLeftPanel">images/hideLeftPanel.png</file>
<file alias="/images/hideRightPanel">images/hideRightPanel.png</file>
<file alias="/images/pdf">images/PDF2.png</file>
<file alias="/images/settings">images/settings.png</file>
<file alias="/images/grid">images/grid.png</file>
</qresource>
</RCC>