From f76d9c839beec7b7064f412664cdc7487f2a6abd Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Thu, 21 Sep 2017 22:02:13 +0300 Subject: [PATCH] HorizontalLayout has been updated --- common.pri | 2 +- limereport/items/lrhorizontallayout.cpp | 68 +++++++++++++++++++++---- limereport/items/lrhorizontallayout.h | 4 ++ limereport/lrbasedesignintf.cpp | 1 + limereport/lrbasedesignintf.h | 2 +- limereport/lrreportdesignwidget.cpp | 14 +++-- limereport/lrreportdesignwidget.h | 1 + limereport/lrreportengine.cpp | 9 ++++ limereport/lrreportengine_p.h | 1 + 9 files changed, 87 insertions(+), 15 deletions(-) diff --git a/common.pri b/common.pri index 3bff285..7dea220 100644 --- a/common.pri +++ b/common.pri @@ -62,7 +62,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc LIMEREPORT_VERSION_MAJOR = 1 LIMEREPORT_VERSION_MINOR = 4 -LIMEREPORT_VERSION_RELEASE = 42 +LIMEREPORT_VERSION_RELEASE = 43 LIMEREPORT_VERSION = '\\"$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}\\"' DEFINES += LIMEREPORT_VERSION_STR=\"$${LIMEREPORT_VERSION}\" diff --git a/limereport/items/lrhorizontallayout.cpp b/limereport/items/lrhorizontallayout.cpp index af91f09..d93e545 100644 --- a/limereport/items/lrhorizontallayout.cpp +++ b/limereport/items/lrhorizontallayout.cpp @@ -63,7 +63,7 @@ bool lessThen(BaseDesignIntf *c1, BaseDesignIntf* c2){ HorizontalLayout::HorizontalLayout(QObject *owner, QGraphicsItem *parent) : LayoutDesignIntf(xmlTag, owner, parent),m_isRelocating(false),m_layoutType(Layout) { - setPossibleResizeDirectionFlags(ResizeBottom); + setPossibleResizeDirectionFlags(AllDirections); m_layoutMarker = new LayoutMarker(this); m_layoutMarker->setParentItem(this); m_layoutMarker->setColor(Qt::red); @@ -86,6 +86,7 @@ BaseDesignIntf *HorizontalLayout::createSameTypeItem(QObject *owner, QGraphicsIt void HorizontalLayout::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event) + LayoutDesignIntf::hoverEnterEvent(event); // if ((itemMode() & LayoutEditMode) || isSelected()){ // setChildVisibility(false); // } @@ -94,6 +95,7 @@ void HorizontalLayout::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void HorizontalLayout::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event) + LayoutDesignIntf::hoverLeaveEvent(event); // setChildVisibility(true); } @@ -101,7 +103,7 @@ void HorizontalLayout::geometryChangedEvent(QRectF newRect, QRectF ) { m_layoutMarker->setHeight(newRect.height()); relocateChildren(); - if (m_layoutType == Table && !m_isRelocating){ + if (/*m_layoutType == Table && */!m_isRelocating){ divideSpace(); } } @@ -203,6 +205,36 @@ void HorizontalLayout::setBorderLinesFlags(BaseDesignIntf::BorderLines flags) relocateChildren(); } +QVariant HorizontalLayout::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant& value) +{ + if (change == QGraphicsItem::ItemSelectedHasChanged){ + m_isRelocating = true; + foreach(BaseDesignIntf* item, m_children){ + item->setVisible(!value.toBool()); + } + m_isRelocating = false; + } + return LayoutDesignIntf::itemChange(change, value); +} + +void HorizontalLayout::paint(QPainter* ppainter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + if (isSelected()){ + foreach( BaseDesignIntf* item, m_children){ + ppainter->save(); + ppainter->setPen(Qt::red); + ppainter->drawRect( + QRectF(item->pos().x(),item->pos().y(), + item->rect().bottomRight().rx(), + item->rect().bottomRight().ry() + ) + ); + ppainter->restore(); + } + } + LayoutDesignIntf::paint(ppainter, option, widget); +} + void HorizontalLayout::restoreChild(BaseDesignIntf* item){ if (m_children.contains(item)) return; @@ -257,9 +289,22 @@ void HorizontalLayout::addChild(BaseDesignIntf *item, bool updateSize) item->setFixedPos(true); item->setPossibleResizeDirectionFlags(ResizeRight | ResizeBottom); - connect(item,SIGNAL(destroyed(QObject*)),this,SLOT(slotOnChildDestroy(QObject*))); - connect(item,SIGNAL(geometryChanged(QObject*,QRectF,QRectF)),this,SLOT(slotOnChildGeometryChanged(QObject*,QRectF,QRectF))); - connect(item, SIGNAL(itemVisibleHasChanged(BaseDesignIntf*)),this,SLOT(slotOnChildVisibleHasChanged(BaseDesignIntf*))); + connect( + item, SIGNAL(destroyed(QObject*)), + this, SLOT(slotOnChildDestroy(QObject*)) + ); + connect( + item,SIGNAL(geometryChanged(QObject*,QRectF,QRectF)), + this,SLOT(slotOnChildGeometryChanged(QObject*,QRectF,QRectF)) + ); + connect( + item, SIGNAL(itemVisibleHasChanged(BaseDesignIntf*)), + this,SLOT(slotOnChildVisibleHasChanged(BaseDesignIntf*)) + ); + connect( + item, SIGNAL(itemSelectedHasBeenChanged(BaseDesignIntf*,bool)), + this, SLOT(slotOnChildSelectionHasChanged(BaseDesignIntf*,bool)) + ); if (updateSize){ relocateChildren(); @@ -318,7 +363,7 @@ void HorizontalLayout::relocateChildren() qreal curX = spaceBorder; m_isRelocating = true; foreach (BaseDesignIntf* item, m_children) { - if (item->isVisible()){ + if (item->isVisible() || itemMode() == DesignMode){ item->setPos(curX,spaceBorder); curX+=item->width(); item->setHeight(height()-(spaceBorder * 2)); @@ -423,7 +468,7 @@ void HorizontalLayout::divideSpace(){ int spaceBorder = (borderLines() != 0) ? borderLineSize() : 0; foreach(BaseDesignIntf* item, m_children){ - if (item->isVisible()){ + if (item->isVisible() || itemMode() == DesignMode ){ itemsSumSize += item->width(); visibleItemsCount++; } @@ -431,10 +476,10 @@ void HorizontalLayout::divideSpace(){ qreal delta = (width() - (itemsSumSize+spaceBorder*2)) / (visibleItemsCount!=0 ? visibleItemsCount : 1); for (int i=0; iisVisible()) + if (m_children[i]->isVisible() || itemMode() == DesignMode) m_children[i]->setWidth(m_children[i]->width()+delta); if ((i+1)isVisible()) + if (m_children[i+1]->isVisible() || itemMode() == DesignMode) m_children[i+1]->setPos(m_children[i+1]->pos().x()+delta*(i+1),m_children[i+1]->pos().y()); } m_isRelocating = false; @@ -473,6 +518,11 @@ void HorizontalLayout::slotOnChildVisibleHasChanged(BaseDesignIntf *) } } +void HorizontalLayout::slotOnChildSelectionHasChanged(BaseDesignIntf* item, bool value) +{ + item->setZValue(value ? item->zValue()+1 : item->zValue()-1); +} + HorizontalLayout::LayoutType HorizontalLayout::layoutType() const { return m_layoutType; diff --git a/limereport/items/lrhorizontallayout.h b/limereport/items/lrhorizontallayout.h index c2a52e3..5bfaddc 100644 --- a/limereport/items/lrhorizontallayout.h +++ b/limereport/items/lrhorizontallayout.h @@ -96,11 +96,15 @@ protected: void setItemAlign(const ItemAlign &itemAlign); void setBorderLinesFlags(BorderLines flags); + + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + void paint(QPainter* ppainter, const QStyleOptionGraphicsItem* option, QWidget* widget); private slots: void slotOnChildDestroy(QObject *child); void slotOnChildGeometryChanged(QObject*item, QRectF newGeometry, QRectF oldGeometry); void slotOnChildItemAlignChanged(BaseDesignIntf* item, const ItemAlign&, const ItemAlign&); void slotOnChildVisibleHasChanged(BaseDesignIntf*); + void slotOnChildSelectionHasChanged(BaseDesignIntf* item, bool value); //void slotOnPosChanged(QObject*, QPointF newPos, QPointF ); private: void divideSpace(); diff --git a/limereport/lrbasedesignintf.cpp b/limereport/lrbasedesignintf.cpp index bdba630..491f431 100644 --- a/limereport/lrbasedesignintf.cpp +++ b/limereport/lrbasedesignintf.cpp @@ -1008,6 +1008,7 @@ QVariant BaseDesignIntf::itemChange(QGraphicsItem::GraphicsItemChange change, co } if (change == QGraphicsItem::ItemSelectedChange) { turnOnSelectionMarker(value.toBool()); + emit itemSelectedHasBeenChanged(this, value.toBool()); } if (change == QGraphicsItem::ItemParentHasChanged) { parentChangedEvent(dynamic_cast(value.value())); diff --git a/limereport/lrbasedesignintf.h b/limereport/lrbasedesignintf.h index e722598..ecced96 100644 --- a/limereport/lrbasedesignintf.h +++ b/limereport/lrbasedesignintf.h @@ -341,7 +341,6 @@ protected: virtual void preparePopUpMenu(QMenu& menu){Q_UNUSED(menu)} virtual void processPopUpAction(QAction* action){Q_UNUSED(action)} - private: void updateSelectionMarker(); int resizeDirectionFlags(QPointF position); @@ -401,6 +400,7 @@ signals: void geometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry); void posChanged(QObject* object, QPointF newPos, QPointF oldPos); void itemSelected(LimeReport::BaseDesignIntf *item); + void itemSelectedHasBeenChanged(BaseDesignIntf *item, bool value); void loadCollectionFinished(const QString& collectionName); void objectLoaded(QObject* object); void objectChanged(QObject* object); diff --git a/limereport/lrreportdesignwidget.cpp b/limereport/lrreportdesignwidget.cpp index e6c49c9..f88a971 100644 --- a/limereport/lrreportdesignwidget.cpp +++ b/limereport/lrreportdesignwidget.cpp @@ -262,7 +262,7 @@ void ReportDesignWidget::slotItemSelected(BaseDesignIntf *item){ } void ReportDesignWidget::saveToFile(const QString &fileName){ - m_report->scriptContext()->setInitScript(m_scriptEditor->toPlainText()); + prepareReport(); if (m_report->saveToFile(fileName)) { m_report->emitSaveFinished(); } @@ -270,7 +270,7 @@ void ReportDesignWidget::saveToFile(const QString &fileName){ bool ReportDesignWidget::save() { - m_report->scriptContext()->setInitScript(m_scriptEditor->toPlainText()); + prepareReport(); if (!m_report->reportFileName().isEmpty()){ if (m_report->saveToFile()){ m_report->emitSaveFinished(); @@ -459,15 +459,21 @@ void ReportDesignWidget::setBorders(const BaseDesignIntf::BorderLines& borders) activePage()->setBorders(borders); } +void ReportDesignWidget::prepareReport() +{ + m_report->scriptContext()->setInitScript(m_scriptEditor->toPlainText()); + report()->clearSelection(); +} + void ReportDesignWidget::previewReport() { - report()->scriptContext()->setInitScript(m_scriptEditor->toPlainText()); + prepareReport(); report()->previewReport(); } void ReportDesignWidget::printReport() { - report()->scriptContext()->setInitScript(m_scriptEditor->toPlainText()); + prepareReport(); setCursor(Qt::WaitCursor); report()->printReport(); setCursor(Qt::ArrowCursor); diff --git a/limereport/lrreportdesignwidget.h b/limereport/lrreportdesignwidget.h index 0e55b78..a6dffe5 100644 --- a/limereport/lrreportdesignwidget.h +++ b/limereport/lrreportdesignwidget.h @@ -166,6 +166,7 @@ private: bool m_useGrid; bool m_useMagnet; // static ReportDesignWidget* m_instance; + void prepareReport(); }; } diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index ddb90ac..9e74c6f 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -728,6 +728,15 @@ void ReportEnginePrivate::reorderPages(const QList& reorderedP } } +void ReportEnginePrivate::clearSelection() +{ + foreach (PageDesignIntf* page, m_pages) { + foreach(QGraphicsItem* item, page->selectedItems()){ + item->setSelected(false); + } + } +} + bool ReportEnginePrivate::resultIsEditable() const { return m_resultIsEditable; diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index 76987e3..4035f6e 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -129,6 +129,7 @@ public: void setPassPhrase(const QString &passPhrase); void reorderPages(const QList &reorderedPages); + void clearSelection(); signals: void pagesLoadFinished(); void datasourceCollectionLoadFinished(const QString& collectionName);