From 83a57b5cbe3b770d51a361b624c5bb2a19c45331 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Thu, 21 Feb 2019 03:20:26 +0300 Subject: [PATCH] Added the ability to add text elements in preview (in edit mode) --- include/lrpreviewreportwidget.h | 1 + limereport/lrpagedesignintf.cpp | 32 +++++++++++++------ limereport/lrpagedesignintf.h | 4 +++ limereport/lrpreviewreportwidget.cpp | 14 ++++++++ limereport/lrpreviewreportwidget.h | 1 + limereport/lrpreviewreportwidget_p.h | 1 + limereport/lrpreviewreportwindow.cpp | 11 ++++++- limereport/lrpreviewreportwindow.h | 1 + limereport/lrpreviewreportwindow.ui | 48 +++++++++++++++++++++++++++- 9 files changed, 101 insertions(+), 12 deletions(-) diff --git a/include/lrpreviewreportwidget.h b/include/lrpreviewreportwidget.h index 9c50adb..faa26c7 100644 --- a/include/lrpreviewreportwidget.h +++ b/include/lrpreviewreportwidget.h @@ -34,6 +34,7 @@ public: QColor previewPageBackgroundColor(); QPrinter *defaultPrinter() const; void setDefaultPrinter(QPrinter *defaultPrinter); + void startInsertTextItem(); public slots: void refreshPages(); void zoomIn(); diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index 1bb5558..b379c3a 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -91,7 +91,8 @@ PageDesignIntf::PageDesignIntf(QObject *parent): m_movedItem(0), m_joinItem(0), m_magneticMovement(false), - m_reportSettings(0) + m_reportSettings(0), + m_currentPage(0) { m_reportEditor = dynamic_cast(parent); updatePageRect(); @@ -240,7 +241,9 @@ void PageDesignIntf::startInsertMode(const QString &ItemType) m_insertItemType = ItemType; m_itemInsertRect = this->addRect(0, 0, 200, 50); m_itemInsertRect->setVisible(false); - m_itemInsertRect->setParentItem(pageItem()); + PageItemDesignIntf* page = pageItem() ? pageItem() : getCurrentPage(); + if (page) + m_itemInsertRect->setParentItem(page); } void PageDesignIntf::startEditMode() @@ -258,6 +261,7 @@ PageItemDesignIntf *PageDesignIntf::pageItem() void PageDesignIntf::setPageItem(PageItemDesignIntf::Ptr pageItem) { + if (pageItem.isNull()) return; if (!m_pageItem.isNull()) { removeItem(m_pageItem.data()); m_pageItem->setParent(0); @@ -334,13 +338,15 @@ void PageDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event) 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); - qreal posY = div(pageItem()->mapFromScene(event->scenePos()).y(), verticalGridStep()).quot * verticalGridStep(); - qreal posX = div(pageItem()->mapFromScene(event->scenePos()).x(), verticalGridStep()).quot * horizontalGridStep(); + qreal posY = div(page->mapFromScene(event->scenePos()).y(), verticalGridStep()).quot * verticalGridStep(); + qreal posX = div(page->mapFromScene(event->scenePos()).x(), verticalGridStep()).quot * horizontalGridStep(); m_itemInsertRect->setPos(posX,posY); + } else { + if (m_insertMode) m_itemInsertRect->setVisible(false); } - else { if (m_insertMode) m_itemInsertRect->setVisible(false); } QGraphicsScene::mouseMoveEvent(event); } @@ -481,10 +487,6 @@ BaseDesignIntf *PageDesignIntf::addReportItem(const QString &itemType, QPointF p BandDesignIntf *band = bandAt(pos); if (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->setSize(placeSizeOnGrid(size)); 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 { return m_reportSettings; diff --git a/limereport/lrpagedesignintf.h b/limereport/lrpagedesignintf.h index 901ddbc..c9c4aab 100644 --- a/limereport/lrpagedesignintf.h +++ b/limereport/lrpagedesignintf.h @@ -175,6 +175,9 @@ namespace LimeReport { void setPropertyToSelectedItems(const char *name, const QVariant &value); + PageItemDesignIntf* getCurrentPage() const; + void setCurrentPage(PageItemDesignIntf* currentPage); + protected: virtual void keyPressEvent(QKeyEvent *event); @@ -312,6 +315,7 @@ namespace LimeReport { JoinType m_joinType; bool m_magneticMovement; ReportSettings* m_reportSettings; + PageItemDesignIntf* m_currentPage; }; class AbstractPageCommand : public CommandIf{ diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index 7b3290d..24420fe 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -68,6 +68,11 @@ QList PreviewReportWidgetPrivate::aviableExporters() return ExportersFactory::instance().map().keys(); } +void PreviewReportWidgetPrivate::startInsertTextItem() +{ + m_previewPage->startInsertMode("TextItem"); +} + PreviewReportWidget::PreviewReportWidget(ReportEngine *report, QWidget *parent) : QWidget(parent), ui(new Ui::PreviewReportWidget), d_ptr(new PreviewReportWidgetPrivate(this)), @@ -332,6 +337,11 @@ ScaleType PreviewReportWidget::scaleType() const return m_scaleType; } +void PreviewReportWidget::startInsertTextItem() +{ + d_ptr->startInsertTextItem(); +} + int PreviewReportWidget::scalePercent() const { return m_scalePercent; @@ -389,6 +399,10 @@ void PreviewReportWidget::slotSliderMoved(int value) d_ptr->m_changingPage = true; emit pageChanged(d_ptr->m_currentPage); + PageDesignIntf* page = dynamic_cast(ui->graphicsView->scene()); + if (page) + page->setCurrentPage(d_ptr->currentPage().data()); + d_ptr->m_changingPage = false; d_ptr->m_priorScrolValue = value; } diff --git a/limereport/lrpreviewreportwidget.h b/limereport/lrpreviewreportwidget.h index 9c50adb..faa26c7 100644 --- a/limereport/lrpreviewreportwidget.h +++ b/limereport/lrpreviewreportwidget.h @@ -34,6 +34,7 @@ public: QColor previewPageBackgroundColor(); QPrinter *defaultPrinter() const; void setDefaultPrinter(QPrinter *defaultPrinter); + void startInsertTextItem(); public slots: void refreshPages(); void zoomIn(); diff --git a/limereport/lrpreviewreportwidget_p.h b/limereport/lrpreviewreportwidget_p.h index 078ce5e..dba8bd8 100644 --- a/limereport/lrpreviewreportwidget_p.h +++ b/limereport/lrpreviewreportwidget_p.h @@ -21,6 +21,7 @@ public: void setPages( ReportPages pages); PageItemDesignIntf::Ptr currentPage(); QList aviableExporters(); + void startInsertTextItem(); public: PageDesignIntf* m_previewPage; ReportPages m_reportPages; diff --git a/limereport/lrpreviewreportwindow.cpp b/limereport/lrpreviewreportwindow.cpp index 035a5e0..df61773 100644 --- a/limereport/lrpreviewreportwindow.cpp +++ b/limereport/lrpreviewreportwindow.cpp @@ -57,6 +57,7 @@ PreviewReportWindow::PreviewReportWindow(ReportEngine *report, QWidget *parent, m_pagesNavigator->setPrefix(tr("Page: ")); m_pagesNavigator->setMinimumWidth(120); ui->toolBar->insertWidget(ui->actionNextPage,m_pagesNavigator); + ui->editModeTools->hide(); ui->actionShowMessages->setVisible(false); 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_textAlignmentEditor->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() @@ -403,6 +406,11 @@ void PreviewReportWindow::slotPageChanged(int pageIndex) m_pagesNavigator->setValue(pageIndex); } +void PreviewReportWindow::slotInsertNewTextItem() +{ + m_previewReportWidget->startInsertTextItem(); +} + void PreviewReportWindow::on_actionFit_page_width_triggered() { m_previewReportWidget->fitWidth(); @@ -439,6 +447,7 @@ void PreviewReportWindow::slotScalePercentChanged(int percent) void PreviewReportWindow::on_actionShowMessages_toggled(bool value) { m_previewReportWidget->setErrorsMesagesVisible(value); + m_previewReportWidget->startInsertTextItem(); } void PreviewReportWindow::on_actionShow_Toolbar_triggered() diff --git a/limereport/lrpreviewreportwindow.h b/limereport/lrpreviewreportwindow.h index eb5b2e6..2104669 100644 --- a/limereport/lrpreviewreportwindow.h +++ b/limereport/lrpreviewreportwindow.h @@ -100,6 +100,7 @@ public slots: void slotLastPage(); void slotPrintToPDF(); void slotPageChanged(int pageIndex); + void slotInsertNewTextItem(); private slots: void on_actionFit_page_width_triggered(); void on_actionFit_page_triggered(); diff --git a/limereport/lrpreviewreportwindow.ui b/limereport/lrpreviewreportwindow.ui index 5c6cc24..23550ec 100644 --- a/limereport/lrpreviewreportwindow.ui +++ b/limereport/lrpreviewreportwindow.ui @@ -35,7 +35,7 @@ 0 0 800 - 20 + 22 @@ -93,6 +93,21 @@ + + + true + + + toolBar_2 + + + LeftToolBarArea + + + false + + + @@ -279,11 +294,25 @@ Show toolbar + + + + :/items/TextItem:/items/TextItem + + + InsertTextItem + + + Add new TextItem + + + + @@ -431,6 +460,22 @@ + + actionInsertTextItem + triggered() + LimeReport::PreviewReportWindow + slotInsertNewTextItem() + + + -1 + -1 + + + 399 + 299 + + + slotNextPage() @@ -441,5 +486,6 @@ slotFirstPage() slotLastPage() slotPrintToPDF() + slotInsertNewTextItem()