From a2c93601d0fd6df43272ae3ab5cacac79a6c2d5f Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Fri, 24 Feb 2017 07:13:43 +0300 Subject: [PATCH] Items context menu has been added Fields drag & drop init band datasource if it empty --- limereport/items/lrtextitem.cpp | 46 +++++++++++++++++++++++ limereport/items/lrtextitem.h | 2 + limereport/lrbanddesignintf.cpp | 37 +++++++++++++++++++ limereport/lrbanddesignintf.h | 4 +- limereport/lrbasedesignintf.cpp | 51 ++++++++++++++++++++++++++ limereport/lrbasedesignintf.h | 15 ++++++-- limereport/lrpagedesignintf.cpp | 19 +++++++++- limereport/lrpageitemdesignintf.cpp | 9 +++++ limereport/lrpageitemdesignintf.h | 1 + limereport/serializators/lrxmlreader.h | 5 --- 10 files changed, 177 insertions(+), 12 deletions(-) diff --git a/limereport/items/lrtextitem.cpp b/limereport/items/lrtextitem.cpp index cddcfee..664bd20 100644 --- a/limereport/items/lrtextitem.cpp +++ b/limereport/items/lrtextitem.cpp @@ -42,6 +42,7 @@ #include "lrsimpletagparser.h" #include "lrtextitemeditor.h" #include "lrreportengine_p.h" +#include namespace{ @@ -80,6 +81,51 @@ int TextItem::fakeMarginSize() const{ return marginSize()+5; } +void TextItem::preparePopUpMenu(QMenu &menu) +{ + QAction* editAction = menu.addAction(QIcon(":/report/images/edit_pecil2.png"),tr("Edit")); + menu.insertAction(menu.actions().at(0),editAction); + menu.insertSeparator(menu.actions().at(1)); + + menu.addSeparator(); + + QAction* action = menu.addAction(tr("Auto height")); + action->setCheckable(true); + action->setChecked(autoHeight()); + + action = menu.addAction(tr("Allow HTML")); + action->setCheckable(true); + action->setChecked(allowHTML()); + + action = menu.addAction(tr("Allow HTML in fields")); + action->setCheckable(true); + action->setChecked(allowHTMLInFields()); + + action = menu.addAction(tr("Strethc to max height")); + action->setCheckable(true); + action->setChecked(stretchToMaxHeight()); + +} + +void TextItem::processPopUpAction(QAction *action) +{ + if (action->text().compare(tr("Edit")) == 0){ + this->showEditorDialog(); + } + if (action->text().compare(tr("Auto height")) == 0){ + setProperty("autoHeight",action->isChecked()); + } + if (action->text().compare(tr("Allow HTML")) == 0){ + setProperty("allowHTML",action->isChecked()); + } + if (action->text().compare(tr("Allow HTML in fields")) == 0){ + setProperty("allowHTMLInFields",action->isChecked()); + } + if (action->text().compare(tr("Strethc to max height")) == 0){ + setProperty("stretchToMaxHeight",action->isChecked()); + } +} + void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, QWidget* widget) { Q_UNUSED(widget); Q_UNUSED(style); diff --git a/limereport/items/lrtextitem.h b/limereport/items/lrtextitem.h index ac9b5b6..6dc735b 100644 --- a/limereport/items/lrtextitem.h +++ b/limereport/items/lrtextitem.h @@ -172,6 +172,8 @@ protected: int fakeMarginSize() const; QString getTextPart(int height, int skipHeight); void restoreLinksEvent(); + void preparePopUpMenu(QMenu &menu); + void processPopUpAction(QAction *action); private: void initTextSizes() const; void setTextFont(TextPtr text, const QFont &value) const; diff --git a/limereport/lrbanddesignintf.cpp b/limereport/lrbanddesignintf.cpp index c6993ad..9a704f2 100644 --- a/limereport/lrbanddesignintf.cpp +++ b/limereport/lrbanddesignintf.cpp @@ -33,6 +33,7 @@ #include #include #include +#include namespace LimeReport { @@ -431,6 +432,34 @@ void BandDesignIntf::moveItemsDown(qreal startPos, qreal offset){ } } +void BandDesignIntf::preparePopUpMenu(QMenu &menu) +{ + foreach (QAction* action, menu.actions()) { + if (action->text().compare(tr("Bring to top")) == 0 || + action->text().compare(tr("Send to back")) == 0 ) + action->setEnabled(false); + } + + menu.addSeparator(); + QAction* autoHeightAction = menu.addAction(tr("Auto height")); + autoHeightAction->setCheckable(true); + autoHeightAction->setChecked(autoHeight()); + + QAction* autoSplittableAction = menu.addAction(tr("Splittable")); + autoSplittableAction->setCheckable(true); + autoSplittableAction->setChecked(isSplittable()); +} + +void BandDesignIntf::processPopUpAction(QAction *action) +{ + if (action->text().compare(tr("Auto height")) == 0){ + setProperty("autoHeight",action->isChecked()); + } + if (action->text().compare(tr("Splittable")) == 0){ + setProperty("splittable",action->isChecked()); + } +} + BaseDesignIntf* BandDesignIntf::cloneUpperPart(int height, QObject *owner, QGraphicsItem *parent) { int maxBottom = 0; @@ -804,6 +833,14 @@ void BandDesignIntf::setStartNewPage(bool startNewPage) m_startNewPage = startNewPage; } +void BandDesignIntf::setAutoHeight(bool value){ + if (m_autoHeight != value){ + m_autoHeight=value; + if (!isLoading()) + notify("autoHeight",!value,value); + } +} + bool BandDesignIntf::reprintOnEachPage() const { return m_reprintOnEachPage; diff --git a/limereport/lrbanddesignintf.h b/limereport/lrbanddesignintf.h index fea245a..0d92f5e 100644 --- a/limereport/lrbanddesignintf.h +++ b/limereport/lrbanddesignintf.h @@ -207,7 +207,7 @@ public: bool startNewPage() const; void setStartNewPage(bool startNewPage); - void setAutoHeight(bool value){m_autoHeight=value;} + void setAutoHeight(bool value); bool autoHeight(){return m_autoHeight;} bool startFromNewPage() const; @@ -244,6 +244,8 @@ protected: void setColumnsCount(int value); void setColumnsFillDirection(BandColumnsLayoutType value); void moveItemsDown(qreal startPos, qreal offset); + void preparePopUpMenu(QMenu &menu); + void processPopUpAction(QAction *action); private slots: void childBandDeleted(QObject* band); private: diff --git a/limereport/lrbasedesignintf.cpp b/limereport/lrbasedesignintf.cpp index f0f7e2b..2f5f4db 100644 --- a/limereport/lrbasedesignintf.cpp +++ b/limereport/lrbasedesignintf.cpp @@ -35,6 +35,8 @@ #include "qgraphicsitem.h" #include "lrdesignelementsfactory.h" #include "lrhorizontallayout.h" +#include "serializators/lrstorageintf.h" +#include "serializators/lrxmlreader.h" #include @@ -43,6 +45,8 @@ #include #include #include +#include +#include namespace LimeReport { @@ -1147,6 +1151,53 @@ void BaseDesignIntf::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) QGraphicsItem::mouseDoubleClickEvent(event); } +void BaseDesignIntf::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + PageDesignIntf* page = dynamic_cast(scene()); + if (!page->selectedItems().contains(this)){ + page->clearSelection(); + this->setSelected(true); + } + QMenu menu; + QAction* copyAction = menu.addAction(QIcon(":/report/images/copy.png"), tr("Copy")); + copyAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C)); + QAction* cutAction = menu.addAction(QIcon(":/report//images/cut"), tr("Cut")); + cutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X)); + QAction* pasteAction = menu.addAction(QIcon(":/report/images/paste.png"), tr("Paste")); + pasteAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_V)); + pasteAction->setEnabled(false); + QClipboard *clipboard = QApplication::clipboard(); + ItemsReaderIntf::Ptr reader = StringXMLreader::create(clipboard->text()); + if (reader->first() && reader->itemType() == "Object"){ + pasteAction->setEnabled(true); + } + menu.addSeparator(); + QAction* brinToTopAction = menu.addAction(QIcon(":/report//images/bringToTop"), tr("Bring to top")); + QAction* sendToBackAction = menu.addAction(QIcon(":/report//images/sendToBack"), tr("Send to back")); + menu.addSeparator(); + QAction* noBordersAction = menu.addAction(QIcon(":/report//images/noLines"), tr("No borders")); + QAction* allBordersAction = menu.addAction(QIcon(":/report//images/allLines"), tr("All borders")); + preparePopUpMenu(menu); + QAction* a = menu.exec(event->screenPos()); + if (a){ + if (a == cutAction) + page->cut(); + if (a == copyAction) + page->copy(); + if (a == pasteAction) + page->paste(); + if (a == brinToTopAction) + page->bringToFront(); + if (a == sendToBackAction) + page->sendToBack(); + if (a == noBordersAction) + page->setBorders(BaseDesignIntf::NoLine); + if (a == allBordersAction) + page->setBorders(BaseDesignIntf::AllLines); + processPopUpAction(a); + } +} + int BaseDesignIntf::possibleMoveDirectionFlags() const { return m_possibleMoveDirectionFlags; diff --git a/limereport/lrbasedesignintf.h b/limereport/lrbasedesignintf.h index 253da8d..4f615ed 100644 --- a/limereport/lrbasedesignintf.h +++ b/limereport/lrbasedesignintf.h @@ -124,10 +124,13 @@ public: TopBotom=2, All=3 }; - enum BorderSide { TopLine = 1, - BottomLine = 2, - LeftLine = 4, - RightLine = 8 + enum BorderSide { + NoLine = 0, + TopLine = 1, + BottomLine = 2, + LeftLine = 4, + RightLine = 8, + AllLines = 15 }; enum ObjectState {ObjectLoading, ObjectLoaded, ObjectCreated}; enum ItemAlign {LeftItemAlign,RightItemAlign,CenterItemAlign,ParentWidthItemAlign,DesignedItemAlign}; @@ -293,6 +296,7 @@ protected: void mouseMoveEvent(QGraphicsSceneMouseEvent* event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); virtual void geometryChangedEvent(QRectF newRect, QRectF oldRect); virtual QPen borderPen(BorderSide side) const; @@ -333,6 +337,9 @@ protected: QVariant m_varValue; + virtual void preparePopUpMenu(QMenu& menu){Q_UNUSED(menu)} + virtual void processPopUpAction(QAction* action){Q_UNUSED(action)} + private: void updateSelectionMarker(); int resizeDirectionFlags(QPointF position); diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index e0a5ec2..2178d43 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -56,6 +56,7 @@ #include #include + namespace LimeReport { @@ -744,6 +745,15 @@ void PageDesignIntf::dropEvent(QGraphicsSceneDragDropEvent* event) QString data = event->mimeData()->text().remove(0,event->mimeData()->text().indexOf(":")+1); if (isVar) data = data.remove(QRegExp(" \\[.*\\]")); ti->setContent(data); + if (!isVar){ + BandDesignIntf* parentBand = dynamic_cast(ti->parentItem()); + if (parentBand && parentBand->datasourceName().isEmpty()){ + QRegExp dataSource("(?:\\$D\\{\\s*(.*)\\..*\\})"); + if (dataSource.indexIn(data) != -1){ + parentBand->setProperty("datasource",dataSource.cap(1)); + } + } + } } } @@ -1231,8 +1241,13 @@ BaseDesignIntf* PageDesignIntf::findDestObject(BaseDesignIntf* item){ void PageDesignIntf::paste() { QClipboard *clipboard = QApplication::clipboard(); - if (!selectedItems().isEmpty()) { - BaseDesignIntf* destItem = findDestObject(dynamic_cast(selectedItems().at(0))); + BaseDesignIntf* destItem = 0; + ItemsReaderIntf::Ptr reader = StringXMLreader::create(clipboard->text()); + if (reader->first() && reader->itemType() == "Object"){ + if (!selectedItems().isEmpty()) + destItem = findDestObject(dynamic_cast(selectedItems().at(0))); + else + destItem = this->pageItem(); if (destItem){ CommandIf::Ptr command = PasteCommand::create(this, clipboard->text(), destItem); saveCommand(command); diff --git a/limereport/lrpageitemdesignintf.cpp b/limereport/lrpageitemdesignintf.cpp index 41d89aa..d943a13 100644 --- a/limereport/lrpageitemdesignintf.cpp +++ b/limereport/lrpageitemdesignintf.cpp @@ -33,6 +33,7 @@ #include #include +#include namespace LimeReport { @@ -519,6 +520,14 @@ void PageItemDesignIntf::initPageSize(const QSizeF& size) setHeight(size.height()); m_sizeChainging=false; } + +void PageItemDesignIntf::preparePopUpMenu(QMenu &menu) +{ + foreach (QAction* action, menu.actions()) { + if (action->text().compare(tr("Paste")) != 0) + action->setVisible(false); + } +} void PageItemDesignIntf::initPageSize(const PageItemDesignIntf::PageSize &size) { m_sizeChainging = true; diff --git a/limereport/lrpageitemdesignintf.h b/limereport/lrpageitemdesignintf.h index 635655f..2c1fb84 100644 --- a/limereport/lrpageitemdesignintf.h +++ b/limereport/lrpageitemdesignintf.h @@ -127,6 +127,7 @@ protected: void initPageSize(const PageSize &size); void initPageSize(const QSizeF &size); QColor selectionMarkerColor(){return Qt::transparent;} + void preparePopUpMenu(QMenu &menu); private: void paintGrid(QPainter *ppainter); void initColumnsPos(QVector&posByColumns, qreal pos, int columnCount); diff --git a/limereport/serializators/lrxmlreader.h b/limereport/serializators/lrxmlreader.h index 0bc17ee..c0f3508 100644 --- a/limereport/serializators/lrxmlreader.h +++ b/limereport/serializators/lrxmlreader.h @@ -63,7 +63,6 @@ protected: void readCollection(QObject *item, QDomElement *node); QVariant getValue(QDomElement *node); - protected: bool extractFirstNode(); QString m_error; @@ -72,10 +71,6 @@ private: QDomElement m_curNode; QDomElement m_firstNode; QString m_passPhrase; - - - - }; class FileXMLReader : public XMLReader{