From 59635e3216883aed7cecb7e50d1983ca3b2d7fa9 Mon Sep 17 00:00:00 2001 From: Arin Alex Date: Sun, 21 Feb 2016 01:08:54 +0300 Subject: [PATCH] Magnet feature has been added --- include/lrglobal.h | 1 + src/images/magnet.png | Bin 0 -> 782 bytes src/lrbanddesignintf.h | 1 + src/lrbasedesignintf.cpp | 157 ++++++++++++++++++++------------- src/lrbasedesignintf.h | 30 +++++-- src/lrglobal.h | 1 + src/lrpagedesignintf.cpp | 164 ++++++++++++++++++++++++++++++++--- src/lrpagedesignintf.h | 42 +++++++++ src/lrpageitemdesignintf.cpp | 1 - src/lrpageitemdesignintf.h | 1 + src/lrreportdesignwidget.cpp | 13 +++ src/lrreportdesignwidget.h | 3 + src/lrreportdesignwindow.cpp | 15 ++++ src/lrreportdesignwindow.h | 2 + src/report.qrc | 5 +- 15 files changed, 349 insertions(+), 87 deletions(-) create mode 100644 src/images/magnet.png diff --git a/include/lrglobal.h b/include/lrglobal.h index c652ad7..baf2bd8 100644 --- a/include/lrglobal.h +++ b/include/lrglobal.h @@ -52,6 +52,7 @@ namespace Const{ double const SELECTED_RESIZE_ZONE_OPACITY = 0.6; Qt::GlobalColor const RESIZE_ZONE_COLOR = Qt::green; Qt::GlobalColor const SELECTION_COLOR = Qt::red; + Qt::GlobalColor const JOIN_COLOR = Qt::blue; double const SELECTION_COLOR_OPACITY = 0.6; const qreal fontFACTOR = 3.5; const int mmFACTOR = 10; diff --git a/src/images/magnet.png b/src/images/magnet.png new file mode 100644 index 0000000000000000000000000000000000000000..5b98576b09a550d3540c2bc79d7bdaf7acba2be8 GIT binary patch literal 782 zcmV+p1M&QcP)&)D_ZSF+a=-GbX?|wP zuH~WF7=U!40OIkwFIXytcq*I@C?VBHC@hXT^Cex=H#U~GM~V(vuJR6UG5RyP#Qwuw z?psWtedY?GjgzR;*Fn2WL`a=~=5wY>v$&KR6q#=a=5Cy`hEh%9n(9+8g-1>Rb0ub^7}g^U7mu zmFS61C&xLFm8HVzFaX#NNF}Tgp6v;a09XbP01zuXX4eTLrZwOClvu(iBR@93i=}*0 zjb#?ena(5iyq#Ovg@XWo1Be6AJYM%(=&1kpVDavzKeYlNogX8mJh=z}N=O}^?Fo(n z2>pXIt=;YyjHhjcBh^xw-~^x;Ju-k0ha8FlAia@I0N6B&2?M{R9KDv)bY;FzZeJT; zj~H9HWo#m7W=op^0Q*7dw6#VQ@&(UR_p3af>yta=Pw`&>R*g%t0CE6w1c1%c<(^;y zZOp1#B)hHoc!%jYWyF=!bY-qrz8@Nm&jIiokD3qAVf-*~W;$u95?f3Xb8!-DAe7j% zsur1lEk6v6CicXCcOHNRKy~f8(pFAj<+`p@|NHPPfTS@_xex|`KlU>+le}Gr4gdfE M07*qoM6N<$f|avaYXATM literal 0 HcmV?d00001 diff --git a/src/lrbanddesignintf.h b/src/lrbanddesignintf.h index 0b09e92..e02a22f 100644 --- a/src/lrbanddesignintf.h +++ b/src/lrbanddesignintf.h @@ -163,6 +163,7 @@ public: virtual bool isHeader() const {return false;} virtual bool isGroupHeader() const {return false;} virtual bool isData() const {return false;} + bool isBand(){return true;} void setTryToKeepTogether(bool value); bool tryToKeepTogether(); diff --git a/src/lrbasedesignintf.cpp b/src/lrbasedesignintf.cpp index 130e0ec..dc64ae8 100644 --- a/src/lrbasedesignintf.cpp +++ b/src/lrbasedesignintf.cpp @@ -69,6 +69,7 @@ BaseDesignIntf::BaseDesignIntf(const QString &storageTypeName, QObject *owner, Q m_itemMode(DesignMode), m_objectState(ObjectCreated), m_selectionMarker(0), + m_joinMarker(0), m_backgroundBrush(Solid), m_backgroundBrushcolor(Qt::white), m_margin(4), @@ -82,9 +83,8 @@ BaseDesignIntf::BaseDesignIntf(const QString &storageTypeName, QObject *owner, Q m_font = QFont("Arial",10); } initFlags(); - m_selectionMarker = new SelectionMarker(this); - m_selectionMarker->setColor(Const::SELECTION_COLOR); - m_selectionMarker->setVisible(false); + + //connect(this,SIGNAL(objectNameChanged(QString)),this,SLOT(slotObjectNameChanged(QString))); } @@ -99,7 +99,10 @@ QRectF BaseDesignIntf::boundingRect() const return m_boundingRect; } -BaseDesignIntf::~BaseDesignIntf(void) {delete m_selectionMarker;} +BaseDesignIntf::~BaseDesignIntf(void) { + delete m_selectionMarker; + delete m_joinMarker; +} void BaseDesignIntf::setParentReportItem(const QString &value) { @@ -112,7 +115,7 @@ void BaseDesignIntf::setParentReportItem(const QString &value) } } -QString BaseDesignIntf::parentReportItem() +QString BaseDesignIntf::parentReportItemName() { BaseDesignIntf *parent = dynamic_cast(parentItem()); if (parent) return parent->objectName(); @@ -292,7 +295,7 @@ void BaseDesignIntf::mousePressEvent(QGraphicsSceneMouseEvent *event) m_startPos = pos(); m_oldGeometry = geometry(); QGraphicsItem::mousePressEvent(event); - QApplication::processEvents(); + //QApplication::processEvents(); emit(itemSelected(this)); } else QGraphicsItem::mousePressEvent(event); @@ -392,22 +395,10 @@ void BaseDesignIntf::hoverLeaveEvent(QGraphicsSceneHoverEvent *) void BaseDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - -// if (!scene()->items(event->scenePos()).contains(parentItem())){ -// BandDesignIntf* band = 0; -// PageItemDesignIntf* pageItem = 0; -// foreach (QGraphicsItem* item, scene()->items(event->scenePos())) { -// band = dynamic_cast(item); -// if (band){ -// break; -// } -// pageItem = dynamic_cast(item); -// } -// if (band) -// qDebug()<<"band found"<objectName(); -// if (pageItem) -// qDebug()<<"page found"<objectName(); -// } + if (!isSelected()){ + QGraphicsItem::mouseMoveEvent(event); + return; + } int hStep = dynamic_cast(scene())->horizontalGridStep(); int vStep = dynamic_cast(scene())->verticalGridStep(); @@ -469,7 +460,11 @@ void BaseDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event) }; setItemPos(m_startPos - delta); - moveSelectedItems(tmpPos - pos()); + + if (!isBand() && scene()->selectedItems().count()>1) + moveSelectedItems(tmpPos - pos()); + if (scene()->selectedItems().count()==1 && (page()->magneticMovement())) + page()->itemMoved(this); } } @@ -571,6 +566,19 @@ QPointF BaseDesignIntf::modifyPosForAlignedItem(const QPointF& pos){ return result; } +void BaseDesignIntf::turnOnJoinMarker(bool value) +{ + if (value){ + m_joinMarker = new Marker(this); + m_joinMarker->setColor(Const::JOIN_COLOR); + m_joinMarker->setRect(rect()); + m_joinMarker->setVisible(true); + } else { + delete m_joinMarker; + m_joinMarker = 0; + } +} + void BaseDesignIntf::updateItemAlign(){ BaseDesignIntf* parent = dynamic_cast(parentItem()); PageItemDesignIntf* parentPage = dynamic_cast(parentItem()); @@ -604,6 +612,19 @@ void BaseDesignIntf::updatePosibleDirectionFlags(){ } } +void BaseDesignIntf::turnOnSelectionMarker(bool value) +{ + if (value && !m_selectionMarker){ + m_selectionMarker = new SelectionMarker(this); + m_selectionMarker->setColor(selectionMarkerColor()); + updateSelectionMarker(); + m_selectionMarker->setVisible(true); + } else { + delete m_selectionMarker; + m_selectionMarker = 0; + } +} + void BaseDesignIntf::setItemAlign(const ItemAlign &itemAlign) { if (m_itemAlign != itemAlign){ @@ -864,8 +885,7 @@ QVariant BaseDesignIntf::itemChange(QGraphicsItem::GraphicsItemChange change, co updateSelectionMarker(); } if (change == QGraphicsItem::ItemSelectedChange) { - updateSelectionMarker(); - m_selectionMarker->setVisible(value.toBool()); + turnOnSelectionMarker(value.toBool()); } if (change == QGraphicsItem::ItemParentHasChanged) { parentChangedEvent(dynamic_cast(value.value())); @@ -916,7 +936,7 @@ void BaseDesignIntf::moveSelectedItems(QPointF delta) foreach(QGraphicsItem * item, selectedItems) { if (item != this) { selectedItem = dynamic_cast(item); - if (selectedItem) { + if (selectedItem && !selectedItem->isBand()) { if (!selectedItem->m_fixedPos) selectedItem->setItemPos(selectedItem->pos() - delta); } @@ -1023,7 +1043,7 @@ void BaseDesignIntf::updateSelectionMarker() if ((!m_selectionMarker->scene()) && scene()) scene()->addItem(m_selectionMarker); if (parentItem()) { m_selectionMarker->setRect(rect()); - m_selectionMarker->setPos(0,0/*parentItem()->mapToScene(pos())*/); + m_selectionMarker->setPos(0,0); } } } @@ -1235,45 +1255,11 @@ void BaseDesignIntf::notify(const QVector& propertyNames) } SelectionMarker::SelectionMarker(QGraphicsItem *parent)//, QGraphicsScene *scene) - : QGraphicsItem(parent)//, scene) + : Marker(parent) { setAcceptHoverEvents(true); } -QRectF SelectionMarker::boundingRect() const -{ - return m_rect.adjusted(-15,-15,15,15); -} - -void SelectionMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) -{ - QPen pen; - const int markerSize = 5; - pen.setColor(m_color); - pen.setWidth(2); - pen.setStyle(Qt::DotLine); - painter->setPen(pen); - painter->setOpacity(Const::SELECTION_COLOR_OPACITY); - painter->drawRect(m_rect); - painter->setBrush(m_color); - painter->setPen(Qt::transparent); - painter->setOpacity(1); - painter->drawRect(QRectF(-markerSize,-markerSize,markerSize*2,markerSize*2)); - painter->drawRect(QRectF(m_rect.right()-markerSize,m_rect.bottom()-markerSize,markerSize*2,markerSize*2)); - painter->drawRect(QRectF(m_rect.right()-markerSize,m_rect.top()-markerSize,markerSize*2,markerSize*2)); - painter->drawRect(QRectF(m_rect.left()-markerSize,m_rect.bottom()-markerSize,markerSize*2,markerSize*2)); - painter->drawRect(QRectF(m_rect.left()-markerSize, - m_rect.bottom()-m_rect.height()/2-markerSize,markerSize*2,markerSize*2)); - painter->drawRect(QRectF(m_rect.right()-markerSize, - m_rect.bottom()-m_rect.height()/2-markerSize,markerSize*2,markerSize*2)); - painter->drawRect(QRectF(m_rect.left()+m_rect.width()/2-markerSize, - m_rect.top()-markerSize,markerSize*2,markerSize*2)); - painter->drawRect(QRectF(m_rect.left()+m_rect.width()/2-markerSize, - m_rect.bottom()-markerSize,markerSize*2,markerSize*2)); - - //painter->drawRect(); -} - void SelectionMarker::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { BaseDesignIntf* baseItem = dynamic_cast(parentItem()); @@ -1307,6 +1293,53 @@ void SelectionMarker::mouseMoveEvent(QGraphicsSceneMouseEvent *event) if(baseItem) baseItem->mouseMoveEvent(event); } +QRectF Marker::boundingRect() const +{ + return m_rect.adjusted(-15,-15,15,15); +} + +void Marker::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + QPen pen; + const int markerSize = 5; + pen.setColor(color()); + pen.setWidth(2); + pen.setStyle(Qt::DotLine); + painter->setPen(pen); + painter->setOpacity(Const::SELECTION_COLOR_OPACITY); + painter->drawRect(rect()); + painter->setBrush(color()); + painter->setPen(Qt::transparent); + painter->setOpacity(1); + painter->drawRect(QRectF(-markerSize,-markerSize,markerSize*2,markerSize*2)); + painter->drawRect(QRectF(rect().right()-markerSize,rect().bottom()-markerSize,markerSize*2,markerSize*2)); + painter->drawRect(QRectF(rect().right()-markerSize,rect().top()-markerSize,markerSize*2,markerSize*2)); + painter->drawRect(QRectF(rect().left()-markerSize,rect().bottom()-markerSize,markerSize*2,markerSize*2)); + painter->drawRect(QRectF(rect().left()-markerSize, + rect().bottom()-rect().height()/2-markerSize,markerSize*2,markerSize*2)); + painter->drawRect(QRectF(rect().right()-markerSize, + rect().bottom()-rect().height()/2-markerSize,markerSize*2,markerSize*2)); + painter->drawRect(QRectF(rect().left()+rect().width()/2-markerSize, + rect().top()-markerSize,markerSize*2,markerSize*2)); + painter->drawRect(QRectF(rect().left()+rect().width()/2-markerSize, + rect().bottom()-markerSize,markerSize*2,markerSize*2)); +} + +QRectF Marker::rect() const +{ + return m_rect; +} + +QColor Marker::color() const +{ + return m_color; +} + +BaseDesignIntf *Marker::object() const +{ + return m_object; +} + } diff --git a/src/lrbasedesignintf.h b/src/lrbasedesignintf.h index ffbb05d..e1e07d7 100644 --- a/src/lrbasedesignintf.h +++ b/src/lrbasedesignintf.h @@ -48,23 +48,31 @@ class ReportEnginePrivate; class PageDesignIntf; class BaseDesignIntf; -class SelectionMarker : public QGraphicsItem{ +class Marker : public QGraphicsItem{ public: - SelectionMarker(QGraphicsItem* parent=0);//, QGraphicsScene* scene=0); + Marker(QGraphicsItem* parent=0):QGraphicsItem(parent){} QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *); void setRect(QRectF rect){prepareGeometryChange();m_rect=rect;} void setColor(QColor color){m_color=color;} + QRectF rect() const; + QColor color() const; + BaseDesignIntf *object() const; +private: + QRectF m_rect; + QColor m_color; + BaseDesignIntf* m_object; +}; + +class SelectionMarker : public Marker{ +public: + SelectionMarker(QGraphicsItem* parent=0); protected: void hoverMoveEvent(QGraphicsSceneHoverEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event); -private: - QRectF m_rect; - QColor m_color; - BaseDesignIntf* m_object; }; class DataSourceManager; @@ -82,7 +90,7 @@ class BaseDesignIntf : Q_PROPERTY(ACollectionProperty children READ fakeCollectionReader DESIGNABLE false) Q_PROPERTY(qreal zOrder READ zValue WRITE setZValueProperty DESIGNABLE false) Q_PROPERTY(BorderLines borders READ borderLines WRITE setBorderLinesFlags) - Q_PROPERTY(QString parentName READ parentReportItem WRITE setParentReportItem DESIGNABLE false) + Q_PROPERTY(QString parentName READ parentReportItemName WRITE setParentReportItem DESIGNABLE false) Q_PROPERTY(int borderLineSize READ borderLineSize WRITE setBorderLineSize) Q_PROPERTY(bool isVisible READ isVisible WRITE setVisible DESIGNABLE false) @@ -115,7 +123,7 @@ public: virtual ~BaseDesignIntf(); void setParentReportItem(const QString& value); - QString parentReportItem(); + QString parentReportItemName(); BrushMode backgroundBrushMode(){return m_backgroundBrush;} void setBackgroundBrushMode(BrushMode value); @@ -231,6 +239,8 @@ public: virtual void setItemAlign(const ItemAlign &itemAlign); void updateItemAlign(); QPointF modifyPosForAlignedItem(const QPointF &pos); + void turnOnJoinMarker(bool value); + virtual bool isBand(){return false;} protected: //ICollectionContainer @@ -277,7 +287,7 @@ protected: RenderPass currentRenderPass(){return m_currentPass;} virtual bool drawDesignBorders() const {return true;} - SelectionMarker* selectionMarker() {return m_selectionMarker;} + virtual QColor selectionMarkerColor(){ return Const::SELECTION_COLOR;} private: void updateSelectionMarker(); int resizeDirectionFlags(QPointF position); @@ -285,6 +295,7 @@ private: Qt::CursorShape getPosibleCursor(int cursorFlags); void setZValueProperty(qreal value); void updatePosibleDirectionFlags(); + void turnOnSelectionMarker(bool value); private: QPointF m_startPos; //QPointF m_startScenePos; @@ -321,6 +332,7 @@ private: ObjectState m_objectState; SelectionMarker* m_selectionMarker; + Marker* m_joinMarker; BrushMode m_backgroundBrush; QColor m_backgroundBrushcolor; diff --git a/src/lrglobal.h b/src/lrglobal.h index c652ad7..baf2bd8 100644 --- a/src/lrglobal.h +++ b/src/lrglobal.h @@ -52,6 +52,7 @@ namespace Const{ double const SELECTED_RESIZE_ZONE_OPACITY = 0.6; Qt::GlobalColor const RESIZE_ZONE_COLOR = Qt::green; Qt::GlobalColor const SELECTION_COLOR = Qt::red; + Qt::GlobalColor const JOIN_COLOR = Qt::blue; double const SELECTION_COLOR_OPACITY = 0.6; const qreal fontFACTOR = 3.5; const int mmFACTOR = 10; diff --git a/src/lrpagedesignintf.cpp b/src/lrpagedesignintf.cpp index 4a099bb..103e68e 100644 --- a/src/lrpagedesignintf.cpp +++ b/src/lrpagedesignintf.cpp @@ -89,7 +89,10 @@ PageDesignIntf::PageDesignIntf(QObject *parent): m_horizontalGridStep(2), m_updating(false), m_currentObjectIndex(1), - m_multiSelectStarted(false) + m_multiSelectStarted(false), + m_movedItem(0), + m_joinItem(0), + m_magneticMovement(false) { m_reportEditor = dynamic_cast(parent); updatePageRect(); @@ -315,11 +318,7 @@ void PageDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } } - if (event->button() & Qt::LeftButton && event->modifiers()==0){ - - } - - if (event->buttons() & Qt::LeftButton && m_multiSelectStarted/*event->modifiers()==Qt::ShiftModifier*/){ + if (event->buttons() & Qt::LeftButton && m_multiSelectStarted){ if (!m_selectionRect){ m_selectionRect = new QGraphicsRectItem(); QBrush brush(QColor(140,190,30,50)); @@ -350,6 +349,35 @@ void PageDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void PageDesignIntf::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if ( (event->button() == Qt::LeftButton)) { + if (m_joinItem && selectedItems().count()==1){ + BaseDesignIntf* selectedItem = dynamic_cast(selectedItems().at(0)); + if (m_magneticMovement){ + if (m_joinType == Width){ + + QPointF tmpPos; + if (selectedItem->pos().y()>m_joinItem->pos().y()) + tmpPos = QPointF(m_joinItem->x(),m_joinItem->pos().y()+m_joinItem->height()); + else + tmpPos = QPointF(m_joinItem->x(),m_joinItem->pos().y()-selectedItem->height()); + + selectedItem->setPos(tmpPos); + selectedItem->setWidth(m_joinItem->width()); + + } else { + + QPointF tmpPos; + if (selectedItem->pos().x()>m_joinItem->pos().x()) + tmpPos = QPointF(m_joinItem->x()+m_joinItem->width(),m_joinItem->pos().y()); + else + tmpPos = QPointF(m_joinItem->x()-selectedItem->width(),m_joinItem->pos().y()); + + selectedItem->setPos(tmpPos); + selectedItem->setHeight(m_joinItem->height()); + } + } + m_joinItem->turnOnJoinMarker(false); + m_joinItem = 0; + } checkSizeOrPosChanges(); } if (m_selectionRect) { @@ -1016,6 +1044,16 @@ void PageDesignIntf::changeSelectedGroupProperty(const QString &name, const QVar } } +bool PageDesignIntf::magneticMovement() const +{ + return m_magneticMovement; +} + +void PageDesignIntf::setMagneticMovement(bool magneticMovement) +{ + m_magneticMovement = magneticMovement; +} + int PageDesignIntf::horizontalGridStep() const { return m_horizontalGridStep; @@ -1032,6 +1070,51 @@ void PageDesignIntf::endUpdate() emit pageUpdateFinished(this); } +void PageDesignIntf::itemMoved(BaseDesignIntf *item) +{ + if (m_movedItem!=item){ + BaseDesignIntf* curItem = dynamic_cast(item->parentItem()); ; + while (curItem){ + m_movedItemContainer = dynamic_cast(curItem); + if (!m_movedItemContainer) + m_movedItemContainer = dynamic_cast(curItem); + if (m_movedItemContainer) break; + else curItem = dynamic_cast(curItem->parentItem()); + } + if (m_movedItemContainer){ + m_projections.clear(); + foreach(BaseDesignIntf* bi, m_movedItemContainer->childBaseItems()){ + if (bi != item) + m_projections.append(ItemProjections(bi)); + } + } + } + + QRectF r1(item->pos().x(),item->pos().y()-50,item->width(),item->height()+100); + QRectF r2(item->pos().x()-50,item->pos().y(),item->width()+100,item->height()); + qreal maxSquare = 0; + + if (m_joinItem) { + m_joinItem->turnOnJoinMarker(false); + m_joinItem = 0; + } + + foreach(ItemProjections p, m_projections){ + qreal tmpSquare = qMax(p.square(r1)/item->width(),p.square(r2)/item->height()); + if (tmpSquare>maxSquare) { + maxSquare = tmpSquare; + m_joinItem = p.item(); + if (p.square(r1)/item->width()>p.square(r2)/item->height()) + m_joinType = Width; + else + m_joinType = Height; + } + } + + if (m_joinItem) m_joinItem->turnOnJoinMarker(true); + +} + int PageDesignIntf::verticalGridStep() const { return m_verticalGridStep; @@ -1907,12 +1990,12 @@ void CommandGroup::undoIt() void CommandGroup::addCommand(CommandIf::Ptr command, bool execute) { - if (execute) + if (execute){ if (command->doIt()) m_commands.append(command); - - else + }else{ m_commands.append(command); + } } PrintRange::PrintRange(QAbstractPrintDialog::PrintRange rangeType, int fromPage, int toPage) @@ -2023,10 +2106,6 @@ bool PropertyItemAlignChangedCommand::doIt() { BaseDesignIntf *reportItem = page()->reportItemByName(m_objectName); - //if (m_oldValue == BaseDesignIntf::DesignedItemAlign){ - // m_savedPos = reportItem->pos(); - //} - if (reportItem && (reportItem->property(m_propertyName.toLatin1()) != m_newValue)) { reportItem->setProperty(m_propertyName.toLatin1(), m_newValue); } @@ -2046,5 +2125,64 @@ void PropertyItemAlignChangedCommand::undoIt() } } +bool Projection::intersect(Projection projection) +{ + if ( + (projection.start()>=start() && projection.start()<=end()) || + (projection.end()>=start() && projection.end()<=end()) || + (projection.start()<=start() && projection.end()>=end()) + ) return true; + return false; +} + +qreal Projection::start() const +{ + return m_start; +} + +qreal Projection::end() const +{ + return m_end; +} + +bool ItemProjections::intersect(QRectF rect) +{ + Projection xProjection(rect.x(),rect.x()+rect.width()); + Projection yProjection(rect.y(),rect.y()+rect.height()); + if (m_xProjection.intersect(xProjection) && m_yProjection.intersect(yProjection)) + return true; + return false; +} + +bool ItemProjections::intersect(BaseDesignIntf *item) +{ + return intersect(QRectF(item->pos().x(), item->pos().y(), item->width(), item->height())); +} + +qreal lineLength(qreal start, qreal end, Projection p){ + qreal result = 0; + if (start>=p.start() && end<=p.end()) + result = end - start; + if (start>=p.start() && start<=p.end()) + result = p.end() - start; + else if (end>=p.start() && end<=p.end()) + result = end-p.start(); + else if (start<=p.start() && end>=p.end()) + result = p.end() - p.start(); + return result; +} + +qreal ItemProjections::square(QRectF rect) +{ + qreal a = lineLength(rect.left(),rect.right(),m_xProjection); + qreal b = lineLength(rect.top(),rect.bottom(),m_yProjection); + return a*b; +} + +qreal ItemProjections::square(BaseDesignIntf *item) +{ + return square(QRectF(item->pos().x(),item->pos().y(),item->width(),item->height())); +} + } diff --git a/src/lrpagedesignintf.h b/src/lrpagedesignintf.h index 516da01..1463944 100644 --- a/src/lrpagedesignintf.h +++ b/src/lrpagedesignintf.h @@ -66,6 +66,36 @@ namespace LimeReport { QSizeF size; }; + class Projection{ + public: + Projection(qreal start, qreal end) + :m_start(start),m_end(end){} + bool intersect(Projection projection); + qreal start() const; + qreal end() const; + private: + qreal m_start; + qreal m_end; + }; + + class ItemProjections{ + public: + ItemProjections(BaseDesignIntf* item) + :m_xProjection(item->pos().x(), item->pos().x()+item->width()), + m_yProjection(item->pos().y(), item->pos().y()+item->height()), + m_item(item) + {} + bool intersect(QRectF rect); + bool intersect(BaseDesignIntf* item); + qreal square(QRectF rect); + qreal square(BaseDesignIntf* item); + BaseDesignIntf* item(){return m_item;} + private: + Projection m_xProjection; + Projection m_yProjection; + BaseDesignIntf* m_item; + }; + class PageDesignIntf : public QGraphicsScene, public ObjectLoadingStateIntf{ Q_OBJECT Q_PROPERTY(QObject* pageItem READ pageItem()) @@ -143,6 +173,11 @@ namespace LimeReport { void beginUpdate(){m_updating = true;} bool isUpdating(){return m_updating;} void endUpdate(); + + void itemMoved(BaseDesignIntf* item); + bool magneticMovement() const; + void setMagneticMovement(bool magneticMovement); + protected: virtual void keyPressEvent(QKeyEvent *event); @@ -233,6 +268,7 @@ namespace LimeReport { void changeSelectedGroupProperty(const QString& name,const QVariant& value); private: + enum JoinType{Width, Height}; PageSize m_pageSize; QSizeF m_pageSizeValue; Orientation m_orientation; @@ -267,6 +303,12 @@ namespace LimeReport { bool m_updating; int m_currentObjectIndex; bool m_multiSelectStarted; + QList m_projections; + BaseDesignIntf* m_movedItem; + BaseDesignIntf* m_movedItemContainer; + BaseDesignIntf* m_joinItem; + JoinType m_joinType; + bool m_magneticMovement; }; class AbstractPageCommand : public CommandIf{ diff --git a/src/lrpageitemdesignintf.cpp b/src/lrpageitemdesignintf.cpp index f55b54e..e15c953 100644 --- a/src/lrpageitemdesignintf.cpp +++ b/src/lrpageitemdesignintf.cpp @@ -52,7 +52,6 @@ PageItemDesignIntf::PageItemDesignIntf(QObject *owner, QGraphicsItem *parent) : setFixedPos(true); setPosibleResizeDirectionFlags(Fixed); initPageSize(m_pageSize); - selectionMarker()->setColor(Qt::transparent); } PageItemDesignIntf::PageItemDesignIntf(const PageSize pageSize, const QRectF &rect, QObject *owner, QGraphicsItem *parent) : diff --git a/src/lrpageitemdesignintf.h b/src/lrpageitemdesignintf.h index 8b0f741..56d90c5 100644 --- a/src/lrpageitemdesignintf.h +++ b/src/lrpageitemdesignintf.h @@ -113,6 +113,7 @@ protected: QSizeF getRectByPageSize(const PageSize &size); void initPageSize(const PageSize &size); void initPageSize(const QSizeF &size); + QColor selectionMarkerColor(){return Qt::transparent;} private: void paintGrid(QPainter *ppainter); void initColumnsPos(QVector&posByColumns, qreal pos, int columnCount); diff --git a/src/lrreportdesignwidget.cpp b/src/lrreportdesignwidget.cpp index 91fef52..e41fcaa 100644 --- a/src/lrreportdesignwidget.cpp +++ b/src/lrreportdesignwidget.cpp @@ -134,6 +134,19 @@ ReportDesignWidget::ReportDesignWidget(ReportEnginePrivate *report, QMainWindow #endif } +bool ReportDesignWidget::useMagnet() const +{ + return m_useMagnet; +} + +void ReportDesignWidget::setUseMagnet(bool useMagnet) +{ + m_useMagnet = useMagnet; + for (int i=0;ipageCount();++i){ + m_report->pageAt(i)->setMagneticMovement(useMagnet); + } +} + void ReportDesignWidget::saveState(QSettings* settings) { settings->beginGroup("DesignerWidget"); diff --git a/src/lrreportdesignwidget.h b/src/lrreportdesignwidget.h index 4e9aa14..5829d30 100644 --- a/src/lrreportdesignwidget.h +++ b/src/lrreportdesignwidget.h @@ -99,6 +99,8 @@ public: void applySettings(); void applyUseGrid(); bool useGrid(){ return m_useGrid;} + bool useMagnet() const; + void setUseMagnet(bool useMagnet); public slots: void saveToFile(const QString&); @@ -161,6 +163,7 @@ private: int m_verticalGridStep; int m_horizontalGridStep; bool m_useGrid; + bool m_useMagnet; // static ReportDesignWidget* m_instance; }; diff --git a/src/lrreportdesignwindow.cpp b/src/lrreportdesignwindow.cpp index b201245..d35ba86 100644 --- a/src/lrreportdesignwindow.cpp +++ b/src/lrreportdesignwindow.cpp @@ -136,7 +136,15 @@ void ReportDesignWindow::createActions() m_useGridAction = new QAction(tr("Use grid"),this); m_useGridAction->setIcon(QIcon(":/report/images/grid")); m_useGridAction->setCheckable(true); + m_useGridAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_G)); connect(m_useGridAction,SIGNAL(toggled(bool)),this,SLOT(slotUseGrid(bool))); + + m_useMagnetAction = new QAction(tr("Use magnet"),this); + m_useMagnetAction->setIcon(QIcon(":/report/images/magnet")); + m_useMagnetAction->setCheckable(true); + m_useMagnetAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); + connect(m_useMagnetAction,SIGNAL(toggled(bool)),this,SLOT(slotUseMagnet(bool))); + m_newTextItemAction = new QAction(tr("Text Item"),this); m_newTextItemAction->setIcon(QIcon(":/items/TextItem")); @@ -281,6 +289,8 @@ void ReportDesignWindow::createToolBars() m_itemsAlignmentEditorBar->setIconSize(m_mainToolBar->iconSize()); m_itemsAlignmentEditorBar->setObjectName("itemsAlignmentTools"); m_itemsAlignmentEditorBar->insertAction(m_itemsAlignmentEditorBar->actions().at(0),m_useGridAction); + m_itemsAlignmentEditorBar->insertAction(m_itemsAlignmentEditorBar->actions().at(1),m_useMagnetAction); + m_itemsAlignmentEditorBar->insertSeparator(m_itemsAlignmentEditorBar->actions().at(2)); addToolBar(m_itemsAlignmentEditorBar); m_itemsBordersEditorBar = new ItemsBordersEditorWidget(m_reportDesignWidget,tr("Borders"),this); m_itemsBordersEditorBar->setIconSize(m_mainToolBar->iconSize()); @@ -1035,6 +1045,11 @@ void ReportDesignWindow::slotUseGrid(bool value) m_reportDesignWidget->setUseGrid(value); } +void ReportDesignWindow::slotUseMagnet(bool value) +{ + m_reportDesignWidget->setUseMagnet(value); +} + void ReportDesignWindow::slotLoadRecentFile(const QString fileName) { if (checkNeedToSave()){ diff --git a/src/lrreportdesignwindow.h b/src/lrreportdesignwindow.h index 0fcd8d3..b04ba90 100644 --- a/src/lrreportdesignwindow.h +++ b/src/lrreportdesignwindow.h @@ -111,6 +111,7 @@ private slots: void slotHideRightPanel(bool value); void slotEditSettings(); void slotUseGrid(bool value); + void slotUseMagnet(bool value); void slotLoadRecentFile(const QString fileName); protected: void closeEvent(QCloseEvent *event); @@ -170,6 +171,7 @@ private: QAction* m_cutAction; QAction* m_settingsAction; QAction* m_useGridAction; + QAction* m_useMagnetAction; QAction* m_newPageHeader; QAction* m_newPageFooter; diff --git a/src/report.qrc b/src/report.qrc index b47d795..75b1d3b 100644 --- a/src/report.qrc +++ b/src/report.qrc @@ -19,7 +19,7 @@ images/Hourglass_80.png images/closebox.png images/design.png - images/barcode.png + images/barcode.png images/barcode2.png images/edit_pecil2.png images/undo1.png @@ -154,11 +154,12 @@ images/logo.png images/cpyright_logo.png images/logo_100.png - images/empty.png + images/empty.png images/hideLeftPanel.png images/hideRightPanel.png images/PDF2.png images/settings.png images/grid.png + images/magnet.png