0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 00:33:02 +03:00

Added the ability to add text elements in preview (in edit mode)

This commit is contained in:
Arin Alexander 2019-02-21 03:20:26 +03:00
parent a010f2328c
commit 83a57b5cbe
9 changed files with 101 additions and 12 deletions

View File

@ -34,6 +34,7 @@ public:
QColor previewPageBackgroundColor(); QColor previewPageBackgroundColor();
QPrinter *defaultPrinter() const; QPrinter *defaultPrinter() const;
void setDefaultPrinter(QPrinter *defaultPrinter); void setDefaultPrinter(QPrinter *defaultPrinter);
void startInsertTextItem();
public slots: public slots:
void refreshPages(); void refreshPages();
void zoomIn(); void zoomIn();

View File

@ -91,7 +91,8 @@ PageDesignIntf::PageDesignIntf(QObject *parent):
m_movedItem(0), m_movedItem(0),
m_joinItem(0), m_joinItem(0),
m_magneticMovement(false), m_magneticMovement(false),
m_reportSettings(0) m_reportSettings(0),
m_currentPage(0)
{ {
m_reportEditor = dynamic_cast<ReportEnginePrivate *>(parent); m_reportEditor = dynamic_cast<ReportEnginePrivate *>(parent);
updatePageRect(); updatePageRect();
@ -240,7 +241,9 @@ void PageDesignIntf::startInsertMode(const QString &ItemType)
m_insertItemType = ItemType; m_insertItemType = ItemType;
m_itemInsertRect = this->addRect(0, 0, 200, 50); m_itemInsertRect = this->addRect(0, 0, 200, 50);
m_itemInsertRect->setVisible(false); m_itemInsertRect->setVisible(false);
m_itemInsertRect->setParentItem(pageItem()); PageItemDesignIntf* page = pageItem() ? pageItem() : getCurrentPage();
if (page)
m_itemInsertRect->setParentItem(page);
} }
void PageDesignIntf::startEditMode() void PageDesignIntf::startEditMode()
@ -258,6 +261,7 @@ PageItemDesignIntf *PageDesignIntf::pageItem()
void PageDesignIntf::setPageItem(PageItemDesignIntf::Ptr pageItem) void PageDesignIntf::setPageItem(PageItemDesignIntf::Ptr pageItem)
{ {
if (pageItem.isNull()) return;
if (!m_pageItem.isNull()) { if (!m_pageItem.isNull()) {
removeItem(m_pageItem.data()); removeItem(m_pageItem.data());
m_pageItem->setParent(0); m_pageItem->setParent(0);
@ -334,13 +338,15 @@ void PageDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
m_selectionRect->setRect(selectionRect); m_selectionRect->setRect(selectionRect);
} }
if ((m_insertMode) && (pageItem()->rect().contains(pageItem()->mapFromScene(event->scenePos())))) { PageItemDesignIntf* page = pageItem() ? pageItem() : getCurrentPage();
if ((m_insertMode) && (page && page->rect().contains(page->mapFromScene(event->scenePos())))) {
if (!m_itemInsertRect->isVisible()) m_itemInsertRect->setVisible(true); if (!m_itemInsertRect->isVisible()) m_itemInsertRect->setVisible(true);
qreal posY = div(pageItem()->mapFromScene(event->scenePos()).y(), verticalGridStep()).quot * verticalGridStep(); qreal posY = div(page->mapFromScene(event->scenePos()).y(), verticalGridStep()).quot * verticalGridStep();
qreal posX = div(pageItem()->mapFromScene(event->scenePos()).x(), verticalGridStep()).quot * horizontalGridStep(); qreal posX = div(page->mapFromScene(event->scenePos()).x(), verticalGridStep()).quot * horizontalGridStep();
m_itemInsertRect->setPos(posX,posY); m_itemInsertRect->setPos(posX,posY);
} else {
if (m_insertMode) m_itemInsertRect->setVisible(false);
} }
else { if (m_insertMode) m_itemInsertRect->setVisible(false); }
QGraphicsScene::mouseMoveEvent(event); QGraphicsScene::mouseMoveEvent(event);
} }
@ -481,10 +487,6 @@ BaseDesignIntf *PageDesignIntf::addReportItem(const QString &itemType, QPointF p
BandDesignIntf *band = bandAt(pos); BandDesignIntf *band = bandAt(pos);
if (band) { if (band) {
BaseDesignIntf *reportItem = addReportItem(itemType, band, band); BaseDesignIntf *reportItem = addReportItem(itemType, band, band);
// QPointF insertPos = band->mapFromScene(pos);
// insertPos = QPointF(div(insertPos.x(), horizontalGridStep()).quot * horizontalGridStep(),
// div(insertPos.y(), verticalGridStep()).quot * verticalGridStep());
reportItem->setPos(placePosOnGrid(band->mapFromScene(pos))); reportItem->setPos(placePosOnGrid(band->mapFromScene(pos)));
reportItem->setSize(placeSizeOnGrid(size)); reportItem->setSize(placeSizeOnGrid(size));
return reportItem; return reportItem;
@ -1057,6 +1059,16 @@ void PageDesignIntf::changeSelectedGroupProperty(const QString &name, const QVar
} }
} }
PageItemDesignIntf* PageDesignIntf::getCurrentPage() const
{
return m_currentPage;
}
void PageDesignIntf::setCurrentPage(PageItemDesignIntf* currentPage)
{
m_currentPage = currentPage;
}
ReportSettings *PageDesignIntf::getReportSettings() const ReportSettings *PageDesignIntf::getReportSettings() const
{ {
return m_reportSettings; return m_reportSettings;

View File

@ -175,6 +175,9 @@ namespace LimeReport {
void setPropertyToSelectedItems(const char *name, const QVariant &value); void setPropertyToSelectedItems(const char *name, const QVariant &value);
PageItemDesignIntf* getCurrentPage() const;
void setCurrentPage(PageItemDesignIntf* currentPage);
protected: protected:
virtual void keyPressEvent(QKeyEvent *event); virtual void keyPressEvent(QKeyEvent *event);
@ -312,6 +315,7 @@ namespace LimeReport {
JoinType m_joinType; JoinType m_joinType;
bool m_magneticMovement; bool m_magneticMovement;
ReportSettings* m_reportSettings; ReportSettings* m_reportSettings;
PageItemDesignIntf* m_currentPage;
}; };
class AbstractPageCommand : public CommandIf{ class AbstractPageCommand : public CommandIf{

View File

@ -68,6 +68,11 @@ QList<QString> PreviewReportWidgetPrivate::aviableExporters()
return ExportersFactory::instance().map().keys(); return ExportersFactory::instance().map().keys();
} }
void PreviewReportWidgetPrivate::startInsertTextItem()
{
m_previewPage->startInsertMode("TextItem");
}
PreviewReportWidget::PreviewReportWidget(ReportEngine *report, QWidget *parent) : PreviewReportWidget::PreviewReportWidget(ReportEngine *report, QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::PreviewReportWidget), d_ptr(new PreviewReportWidgetPrivate(this)), ui(new Ui::PreviewReportWidget), d_ptr(new PreviewReportWidgetPrivate(this)),
@ -332,6 +337,11 @@ ScaleType PreviewReportWidget::scaleType() const
return m_scaleType; return m_scaleType;
} }
void PreviewReportWidget::startInsertTextItem()
{
d_ptr->startInsertTextItem();
}
int PreviewReportWidget::scalePercent() const int PreviewReportWidget::scalePercent() const
{ {
return m_scalePercent; return m_scalePercent;
@ -389,6 +399,10 @@ void PreviewReportWidget::slotSliderMoved(int value)
d_ptr->m_changingPage = true; d_ptr->m_changingPage = true;
emit pageChanged(d_ptr->m_currentPage); emit pageChanged(d_ptr->m_currentPage);
PageDesignIntf* page = dynamic_cast<PageDesignIntf*>(ui->graphicsView->scene());
if (page)
page->setCurrentPage(d_ptr->currentPage().data());
d_ptr->m_changingPage = false; d_ptr->m_changingPage = false;
d_ptr->m_priorScrolValue = value; d_ptr->m_priorScrolValue = value;
} }

View File

@ -34,6 +34,7 @@ public:
QColor previewPageBackgroundColor(); QColor previewPageBackgroundColor();
QPrinter *defaultPrinter() const; QPrinter *defaultPrinter() const;
void setDefaultPrinter(QPrinter *defaultPrinter); void setDefaultPrinter(QPrinter *defaultPrinter);
void startInsertTextItem();
public slots: public slots:
void refreshPages(); void refreshPages();
void zoomIn(); void zoomIn();

View File

@ -21,6 +21,7 @@ public:
void setPages( ReportPages pages); void setPages( ReportPages pages);
PageItemDesignIntf::Ptr currentPage(); PageItemDesignIntf::Ptr currentPage();
QList<QString> aviableExporters(); QList<QString> aviableExporters();
void startInsertTextItem();
public: public:
PageDesignIntf* m_previewPage; PageDesignIntf* m_previewPage;
ReportPages m_reportPages; ReportPages m_reportPages;

View File

@ -57,6 +57,7 @@ PreviewReportWindow::PreviewReportWindow(ReportEngine *report, QWidget *parent,
m_pagesNavigator->setPrefix(tr("Page: ")); m_pagesNavigator->setPrefix(tr("Page: "));
m_pagesNavigator->setMinimumWidth(120); m_pagesNavigator->setMinimumWidth(120);
ui->toolBar->insertWidget(ui->actionNextPage,m_pagesNavigator); ui->toolBar->insertWidget(ui->actionNextPage,m_pagesNavigator);
ui->editModeTools->hide();
ui->actionShowMessages->setVisible(false); ui->actionShowMessages->setVisible(false);
connect(m_pagesNavigator,SIGNAL(valueChanged(int)),this,SLOT(slotPageNavigatorChanged(int))); connect(m_pagesNavigator,SIGNAL(valueChanged(int)),this,SLOT(slotPageNavigatorChanged(int)));
@ -326,7 +327,9 @@ void PreviewReportWindow::on_actionEdit_Mode_triggered(bool checked)
m_previewReportWidget->d_ptr->m_previewPage->setItemMode((checked)?ItemModes(DesignMode):PreviewMode); m_previewReportWidget->d_ptr->m_previewPage->setItemMode((checked)?ItemModes(DesignMode):PreviewMode);
m_textAlignmentEditor->setVisible(checked); m_textAlignmentEditor->setVisible(checked);
m_fontEditor->setVisible(checked); m_fontEditor->setVisible(checked);
//m_reportPages.at(m_currentPage)->setItemMode((checked)?DesignMode:PreviewMode); if (checked)
ui->editModeTools->show();
else ui->editModeTools->hide();
} }
void PreviewReportWindow::slotSelectionChanged() void PreviewReportWindow::slotSelectionChanged()
@ -403,6 +406,11 @@ void PreviewReportWindow::slotPageChanged(int pageIndex)
m_pagesNavigator->setValue(pageIndex); m_pagesNavigator->setValue(pageIndex);
} }
void PreviewReportWindow::slotInsertNewTextItem()
{
m_previewReportWidget->startInsertTextItem();
}
void PreviewReportWindow::on_actionFit_page_width_triggered() void PreviewReportWindow::on_actionFit_page_width_triggered()
{ {
m_previewReportWidget->fitWidth(); m_previewReportWidget->fitWidth();
@ -439,6 +447,7 @@ void PreviewReportWindow::slotScalePercentChanged(int percent)
void PreviewReportWindow::on_actionShowMessages_toggled(bool value) void PreviewReportWindow::on_actionShowMessages_toggled(bool value)
{ {
m_previewReportWidget->setErrorsMesagesVisible(value); m_previewReportWidget->setErrorsMesagesVisible(value);
m_previewReportWidget->startInsertTextItem();
} }
void PreviewReportWindow::on_actionShow_Toolbar_triggered() void PreviewReportWindow::on_actionShow_Toolbar_triggered()

View File

@ -100,6 +100,7 @@ public slots:
void slotLastPage(); void slotLastPage();
void slotPrintToPDF(); void slotPrintToPDF();
void slotPageChanged(int pageIndex); void slotPageChanged(int pageIndex);
void slotInsertNewTextItem();
private slots: private slots:
void on_actionFit_page_width_triggered(); void on_actionFit_page_width_triggered();
void on_actionFit_page_triggered(); void on_actionFit_page_triggered();

View File

@ -35,7 +35,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>800</width> <width>800</width>
<height>20</height> <height>22</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuView"> <widget class="QMenu" name="menuView">
@ -93,6 +93,21 @@
<addaction name="actionClosePreview"/> <addaction name="actionClosePreview"/>
<addaction name="actionShowMessages"/> <addaction name="actionShowMessages"/>
</widget> </widget>
<widget class="QToolBar" name="editModeTools">
<property name="enabled">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>toolBar_2</string>
</property>
<attribute name="toolBarArea">
<enum>LeftToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionInsertTextItem"/>
</widget>
<action name="actionPrint"> <action name="actionPrint">
<property name="icon"> <property name="icon">
<iconset resource="report.qrc"> <iconset resource="report.qrc">
@ -279,11 +294,25 @@
<string>Show toolbar</string> <string>Show toolbar</string>
</property> </property>
</action> </action>
<action name="actionInsertTextItem">
<property name="icon">
<iconset resource="items/items.qrc">
<normaloff>:/items/TextItem</normaloff>:/items/TextItem</iconset>
</property>
<property name="text">
<string>InsertTextItem</string>
</property>
<property name="toolTip">
<string>Add new TextItem</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="report.qrc"/> <include location="report.qrc"/>
<include location="items/items.qrc"/>
<include location="databrowser/lrdatabrowser.qrc"/> <include location="databrowser/lrdatabrowser.qrc"/>
<include location="report.qrc"/> <include location="report.qrc"/>
<include location="items/items.qrc"/>
<include location="databrowser/lrdatabrowser.qrc"/> <include location="databrowser/lrdatabrowser.qrc"/>
</resources> </resources>
<connections> <connections>
@ -431,6 +460,22 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>actionInsertTextItem</sender>
<signal>triggered()</signal>
<receiver>LimeReport::PreviewReportWindow</receiver>
<slot>slotInsertNewTextItem()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>299</y>
</hint>
</hints>
</connection>
</connections> </connections>
<slots> <slots>
<slot>slotNextPage()</slot> <slot>slotNextPage()</slot>
@ -441,5 +486,6 @@
<slot>slotFirstPage()</slot> <slot>slotFirstPage()</slot>
<slot>slotLastPage()</slot> <slot>slotLastPage()</slot>
<slot>slotPrintToPDF()</slot> <slot>slotPrintToPDF()</slot>
<slot>slotInsertNewTextItem()</slot>
</slots> </slots>
</ui> </ui>