Finished add new text item in preview mode

This commit is contained in:
Arin Alexander 2019-03-01 23:48:28 +03:00
parent a84d1e0f36
commit c6c5e2b206
7 changed files with 158 additions and 12 deletions

View File

@ -15,6 +15,7 @@ class PreviewReportWidget;
class PreviewReportWidgetPrivate; class PreviewReportWidgetPrivate;
class ReportEnginePrivate; class ReportEnginePrivate;
class ReportEngine; class ReportEngine;
class PageDesignIntf;
class LIMEREPORT_EXPORT PreviewReportWidget : public QWidget class LIMEREPORT_EXPORT PreviewReportWidget : public QWidget
{ {
@ -35,6 +36,10 @@ public:
QPrinter *defaultPrinter() const; QPrinter *defaultPrinter() const;
void setDefaultPrinter(QPrinter *defaultPrinter); void setDefaultPrinter(QPrinter *defaultPrinter);
void startInsertTextItem(); void startInsertTextItem();
void activateItemSelectionMode();
void deleteSelectedItems();
void activateCurrentPage();
public slots: public slots:
void refreshPages(); void refreshPages();
void zoomIn(); void zoomIn();
@ -58,6 +63,7 @@ signals:
void pageChanged(int page); void pageChanged(int page);
void scalePercentChanged(int percent); void scalePercentChanged(int percent);
void pagesSet(int pageCount); void pagesSet(int pageCount);
void itemInserted(LimeReport::PageDesignIntf* report, QPointF pos, const QString& ItemType);
private slots: private slots:
void slotSliderMoved(int value); void slotSliderMoved(int value);
void reportEngineDestroyed(QObject* object); void reportEngineDestroyed(QObject* object);

View File

@ -53,6 +53,7 @@ void PreviewReportWidgetPrivate::setPages(ReportPages pages)
m_changingPage = false; m_changingPage = false;
q_ptr->initPreview(); q_ptr->initPreview();
q_ptr->emitPageSet(); q_ptr->emitPageSet();
q_ptr->activateCurrentPage();
} }
} }
@ -73,6 +74,16 @@ void PreviewReportWidgetPrivate::startInsertTextItem()
m_previewPage->startInsertMode("TextItem"); m_previewPage->startInsertMode("TextItem");
} }
void PreviewReportWidgetPrivate::activateItemSelectionMode()
{
m_previewPage->startEditMode();
}
void PreviewReportWidgetPrivate::deleteSelectedItems()
{
m_previewPage->deleteSelected();
}
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)),
@ -135,6 +146,10 @@ void PreviewReportWidget::initPreview()
ui->graphicsView->centerOn(0, 0); ui->graphicsView->centerOn(0, 0);
ui->graphicsView->scene()->setBackgroundBrush(QColor(m_previewPageBackgroundColor)); ui->graphicsView->scene()->setBackgroundBrush(QColor(m_previewPageBackgroundColor));
setScalePercent(d_ptr->m_scalePercent); setScalePercent(d_ptr->m_scalePercent);
PageDesignIntf* page = dynamic_cast<PageDesignIntf*>(ui->graphicsView->scene());
if (page)
connect(page, SIGNAL(itemInserted(LimeReport::PageDesignIntf*, QPointF, QString)),
this, SIGNAL(itemInserted(LimeReport::PageDesignIntf*, QPointF, QString)));
} }
void PreviewReportWidget::setErrorsMesagesVisible(bool visible) void PreviewReportWidget::setErrorsMesagesVisible(bool visible)
@ -342,6 +357,16 @@ void PreviewReportWidget::startInsertTextItem()
d_ptr->startInsertTextItem(); d_ptr->startInsertTextItem();
} }
void PreviewReportWidget::activateItemSelectionMode()
{
d_ptr->activateItemSelectionMode();
}
void PreviewReportWidget::deleteSelectedItems()
{
d_ptr->deleteSelectedItems();
}
int PreviewReportWidget::scalePercent() const int PreviewReportWidget::scalePercent() const
{ {
return m_scalePercent; return m_scalePercent;
@ -380,8 +405,16 @@ void PreviewReportWidget::refreshPages()
} }
} }
void PreviewReportWidget::activateCurrentPage()
{
PageDesignIntf* page = dynamic_cast<PageDesignIntf*>(ui->graphicsView->scene());
if (page)
page->setCurrentPage(d_ptr->currentPage().data());
}
void PreviewReportWidget::slotSliderMoved(int value) void PreviewReportWidget::slotSliderMoved(int value)
{ {
int curPage = d_ptr->m_currentPage;
if (ui->graphicsView->verticalScrollBar()->minimum()==value){ if (ui->graphicsView->verticalScrollBar()->minimum()==value){
d_ptr->m_currentPage = 1; d_ptr->m_currentPage = 1;
} else if (ui->graphicsView->verticalScrollBar()->maximum()==value){ } else if (ui->graphicsView->verticalScrollBar()->maximum()==value){
@ -396,14 +429,13 @@ void PreviewReportWidget::slotSliderMoved(int value)
} }
} }
d_ptr->m_changingPage = true; if (curPage != d_ptr->m_currentPage){
emit pageChanged(d_ptr->m_currentPage); d_ptr->m_changingPage = true;
emit pageChanged(d_ptr->m_currentPage);
activateCurrentPage();
d_ptr->m_changingPage = false;
}
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; d_ptr->m_priorScrolValue = value;
} }

View File

@ -15,6 +15,7 @@ class PreviewReportWidget;
class PreviewReportWidgetPrivate; class PreviewReportWidgetPrivate;
class ReportEnginePrivate; class ReportEnginePrivate;
class ReportEngine; class ReportEngine;
class PageDesignIntf;
class LIMEREPORT_EXPORT PreviewReportWidget : public QWidget class LIMEREPORT_EXPORT PreviewReportWidget : public QWidget
{ {
@ -35,6 +36,10 @@ public:
QPrinter *defaultPrinter() const; QPrinter *defaultPrinter() const;
void setDefaultPrinter(QPrinter *defaultPrinter); void setDefaultPrinter(QPrinter *defaultPrinter);
void startInsertTextItem(); void startInsertTextItem();
void activateItemSelectionMode();
void deleteSelectedItems();
void activateCurrentPage();
public slots: public slots:
void refreshPages(); void refreshPages();
void zoomIn(); void zoomIn();
@ -58,6 +63,7 @@ signals:
void pageChanged(int page); void pageChanged(int page);
void scalePercentChanged(int percent); void scalePercentChanged(int percent);
void pagesSet(int pageCount); void pagesSet(int pageCount);
void itemInserted(LimeReport::PageDesignIntf* report, QPointF pos, const QString& ItemType);
private slots: private slots:
void slotSliderMoved(int value); void slotSliderMoved(int value);
void reportEngineDestroyed(QObject* object); void reportEngineDestroyed(QObject* object);

View File

@ -22,6 +22,8 @@ public:
PageItemDesignIntf::Ptr currentPage(); PageItemDesignIntf::Ptr currentPage();
QList<QString> aviableExporters(); QList<QString> aviableExporters();
void startInsertTextItem(); void startInsertTextItem();
void activateItemSelectionMode();
void deleteSelectedItems();
public: public:
PageDesignIntf* m_previewPage; PageDesignIntf* m_previewPage;
ReportPages m_reportPages; ReportPages m_reportPages;

View File

@ -82,10 +82,13 @@ PreviewReportWindow::PreviewReportWindow(ReportEngine *report, QWidget *parent,
ui->toolBar->insertWidget(ui->actionZoomOut, m_scalePercent); ui->toolBar->insertWidget(ui->actionZoomOut, m_scalePercent);
initPercentCombobox(); initPercentCombobox();
// connect(ui->graphicsView->verticalScrollBar(),SIGNAL(valueChanged(int)), this, SLOT(slotSliderMoved(int)));
connect(ui->actionShowMessages, SIGNAL(triggered()), this, SLOT(slotShowErrors())); connect(ui->actionShowMessages, SIGNAL(triggered()), this, SLOT(slotShowErrors()));
connect(m_previewReportWidget, SIGNAL(scalePercentChanged(int)), this, SLOT(slotScalePercentChanged(int))); connect(m_previewReportWidget, SIGNAL(scalePercentChanged(int)), this, SLOT(slotScalePercentChanged(int)));
connect(m_scalePercent, SIGNAL(currentIndexChanged(QString)), this, SLOT(scaleComboboxChanged(QString))); connect(m_scalePercent, SIGNAL(currentIndexChanged(QString)), this, SLOT(scaleComboboxChanged(QString)));
connect(m_previewReportWidget, SIGNAL(pageChanged(int)), this, SLOT(slotCurrentPageChanged(int)));
connect(m_previewReportWidget, SIGNAL(itemInserted(LimeReport::PageDesignIntf*, QPointF, QString)),
this, SLOT(slotItemInserted(LimeReport::PageDesignIntf*, QPointF, QString)));
restoreSetting(); restoreSetting();
selectStateIcon(); selectStateIcon();
} }
@ -110,10 +113,13 @@ void PreviewReportWindow::restoreSetting()
int screenWidth = desktop->screenGeometry().width(); int screenWidth = desktop->screenGeometry().width();
int screenHeight = desktop->screenGeometry().height(); int screenHeight = desktop->screenGeometry().height();
int x = screenWidth*0.1; int x = static_cast<int>(screenWidth*0.1);
int y = screenHeight*0.1; int y = static_cast<int>(screenHeight*0.1);
resize(screenWidth*0.8, screenHeight*0.8); resize(
static_cast<int>(screenWidth*0.8),
static_cast<int>(screenHeight*0.8)
);
move(x, y); move(x, y);
} }
v = settings()->value("State"); v = settings()->value("State");
@ -410,6 +416,19 @@ void PreviewReportWindow::slotPageChanged(int pageIndex)
void PreviewReportWindow::slotInsertNewTextItem() void PreviewReportWindow::slotInsertNewTextItem()
{ {
m_previewReportWidget->startInsertTextItem(); m_previewReportWidget->startInsertTextItem();
ui->actionSelection_Mode->setChecked(false);
}
void PreviewReportWindow::slotActivateItemSelectionMode()
{
m_previewReportWidget->activateItemSelectionMode();
ui->actionSelection_Mode->setChecked(true);
ui->actionInsertTextItem->setChecked(false);
}
void PreviewReportWindow::slotDeleteSelectedItems()
{
m_previewReportWidget->deleteSelectedItems();
} }
void PreviewReportWindow::on_actionFit_page_width_triggered() void PreviewReportWindow::on_actionFit_page_width_triggered()
@ -457,5 +476,15 @@ void PreviewReportWindow::on_actionShow_Toolbar_triggered()
writeSetting(); writeSetting();
} }
void PreviewReportWindow::slotCurrentPageChanged(int page)
{
slotActivateItemSelectionMode();
}
void PreviewReportWindow::slotItemInserted(PageDesignIntf *, QPointF, const QString&)
{
slotActivateItemSelectionMode();
}
}// namespace LimeReport }// namespace LimeReport

View File

@ -101,6 +101,8 @@ public slots:
void slotPrintToPDF(); void slotPrintToPDF();
void slotPageChanged(int pageIndex); void slotPageChanged(int pageIndex);
void slotInsertNewTextItem(); void slotInsertNewTextItem();
void slotActivateItemSelectionMode();
void slotDeleteSelectedItems();
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();
@ -109,6 +111,8 @@ private slots:
void slotScalePercentChanged(int percent); void slotScalePercentChanged(int percent);
void on_actionShowMessages_toggled(bool value); void on_actionShowMessages_toggled(bool value);
void on_actionShow_Toolbar_triggered(); void on_actionShow_Toolbar_triggered();
void slotCurrentPageChanged(int page);
void slotItemInserted(LimeReport::PageDesignIntf* report, QPointF pos, const QString& ItemType);
private: private:
ItemsReaderIntf* reader(); ItemsReaderIntf* reader();
void initPercentCombobox(); void initPercentCombobox();

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>22</height> <height>20</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuView"> <widget class="QMenu" name="menuView">
@ -106,7 +106,10 @@
<attribute name="toolBarBreak"> <attribute name="toolBarBreak">
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<addaction name="actionSelection_Mode"/>
<addaction name="actionInsertTextItem"/> <addaction name="actionInsertTextItem"/>
<addaction name="separator"/>
<addaction name="actionDelete_Item"/>
</widget> </widget>
<action name="actionPrint"> <action name="actionPrint">
<property name="icon"> <property name="icon">
@ -295,6 +298,9 @@
</property> </property>
</action> </action>
<action name="actionInsertTextItem"> <action name="actionInsertTextItem">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon"> <property name="icon">
<iconset resource="items/items.qrc"> <iconset resource="items/items.qrc">
<normaloff>:/items/TextItem</normaloff>:/items/TextItem</iconset> <normaloff>:/items/TextItem</normaloff>:/items/TextItem</iconset>
@ -306,6 +312,33 @@
<string>Add new TextItem</string> <string>Add new TextItem</string>
</property> </property>
</action> </action>
<action name="actionSelection_Mode">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="report.qrc">
<normaloff>:/report/images/editMode</normaloff>:/report/images/editMode</iconset>
</property>
<property name="text">
<string>Selection Mode</string>
</property>
</action>
<action name="actionDelete_Item">
<property name="icon">
<iconset resource="report.qrc">
<normaloff>:/report/images/delete</normaloff>:/report/images/delete</iconset>
</property>
<property name="text">
<string>Delete Item</string>
</property>
<property name="shortcut">
<string>Del</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="report.qrc"/> <include location="report.qrc"/>
@ -476,6 +509,38 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>actionSelection_Mode</sender>
<signal>triggered()</signal>
<receiver>LimeReport::PreviewReportWindow</receiver>
<slot>slotActivateItemSelectionMode()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>299</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionDelete_Item</sender>
<signal>triggered()</signal>
<receiver>LimeReport::PreviewReportWindow</receiver>
<slot>slotDeleteSelectedItems()</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>
@ -487,5 +552,7 @@
<slot>slotLastPage()</slot> <slot>slotLastPage()</slot>
<slot>slotPrintToPDF()</slot> <slot>slotPrintToPDF()</slot>
<slot>slotInsertNewTextItem()</slot> <slot>slotInsertNewTextItem()</slot>
<slot>slotActivateItemSelectionMode()</slot>
<slot>slotDeleteSelectedItems()</slot>
</slots> </slots>
</ui> </ui>