mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-23 20:22:58 +03:00
Added the ability to add text elements in preview (in edit mode)
This commit is contained in:
parent
a010f2328c
commit
83a57b5cbe
@ -34,6 +34,7 @@ public:
|
||||
QColor previewPageBackgroundColor();
|
||||
QPrinter *defaultPrinter() const;
|
||||
void setDefaultPrinter(QPrinter *defaultPrinter);
|
||||
void startInsertTextItem();
|
||||
public slots:
|
||||
void refreshPages();
|
||||
void zoomIn();
|
||||
|
@ -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<ReportEnginePrivate *>(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;
|
||||
|
@ -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{
|
||||
|
@ -68,6 +68,11 @@ QList<QString> 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<PageDesignIntf*>(ui->graphicsView->scene());
|
||||
if (page)
|
||||
page->setCurrentPage(d_ptr->currentPage().data());
|
||||
|
||||
d_ptr->m_changingPage = false;
|
||||
d_ptr->m_priorScrolValue = value;
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
QColor previewPageBackgroundColor();
|
||||
QPrinter *defaultPrinter() const;
|
||||
void setDefaultPrinter(QPrinter *defaultPrinter);
|
||||
void startInsertTextItem();
|
||||
public slots:
|
||||
void refreshPages();
|
||||
void zoomIn();
|
||||
|
@ -21,6 +21,7 @@ public:
|
||||
void setPages( ReportPages pages);
|
||||
PageItemDesignIntf::Ptr currentPage();
|
||||
QList<QString> aviableExporters();
|
||||
void startInsertTextItem();
|
||||
public:
|
||||
PageDesignIntf* m_previewPage;
|
||||
ReportPages m_reportPages;
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
|
@ -35,7 +35,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>20</height>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuView">
|
||||
@ -93,6 +93,21 @@
|
||||
<addaction name="actionClosePreview"/>
|
||||
<addaction name="actionShowMessages"/>
|
||||
</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">
|
||||
<property name="icon">
|
||||
<iconset resource="report.qrc">
|
||||
@ -279,11 +294,25 @@
|
||||
<string>Show toolbar</string>
|
||||
</property>
|
||||
</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>
|
||||
<resources>
|
||||
<include location="report.qrc"/>
|
||||
<include location="items/items.qrc"/>
|
||||
<include location="databrowser/lrdatabrowser.qrc"/>
|
||||
<include location="report.qrc"/>
|
||||
<include location="items/items.qrc"/>
|
||||
<include location="databrowser/lrdatabrowser.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
@ -431,6 +460,22 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</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>
|
||||
<slots>
|
||||
<slot>slotNextPage()</slot>
|
||||
@ -441,5 +486,6 @@
|
||||
<slot>slotFirstPage()</slot>
|
||||
<slot>slotLastPage()</slot>
|
||||
<slot>slotPrintToPDF()</slot>
|
||||
<slot>slotInsertNewTextItem()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
Loading…
Reference in New Issue
Block a user