diff --git a/include/lrglobal.h b/include/lrglobal.h index ba5a363..76af327 100644 --- a/include/lrglobal.h +++ b/include/lrglobal.h @@ -52,8 +52,8 @@ namespace LimeReport { namespace Const{ - int const RESIZE_HANDLE_SIZE = 10; - int const SELECTION_PEN_SIZE = 4; + int const RESIZE_HANDLE_SIZE = 5; + int const SELECTION_PEN_SIZE = 1; int const MINIMUM_ITEM_WIDTH = 2*RESIZE_HANDLE_SIZE; int const MINIMUM_ITEM_HEIGHT = 2*RESIZE_HANDLE_SIZE; double const RESIZE_ZONE_OPACITY = 0.5; diff --git a/limereport/lrbanddesignintf.cpp b/limereport/lrbanddesignintf.cpp index c77f86c..9e3323a 100644 --- a/limereport/lrbanddesignintf.cpp +++ b/limereport/lrbanddesignintf.cpp @@ -39,7 +39,9 @@ namespace LimeReport { BandMarker::BandMarker(BandDesignIntf *band, QGraphicsItem* parent) :QGraphicsItem(parent),m_rect(0,0,30,30),m_band(band) -{} +{ + setAcceptHoverEvents(true); +} QRectF BandMarker::boundingRect() const { @@ -52,6 +54,13 @@ void BandMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem* /**opt painter->setOpacity(Const::BAND_MARKER_OPACITY); painter->fillRect(boundingRect(),m_color); painter->setOpacity(1); + painter->setPen(QPen(QBrush(Qt::lightGray),2)); + painter->fillRect(QRectF( + boundingRect().bottomLeft().x(), + boundingRect().bottomLeft().y()-4, + boundingRect().width(),4), Qt::lightGray + ); + painter->setRenderHint(QPainter::Antialiasing); qreal size = (boundingRect().width()setBrush(LimeReport::Const::SELECTION_COLOR); painter->drawEllipse(r.adjusted(7,7,-7,-7)); } + painter->restore(); } @@ -104,6 +114,31 @@ void BandMarker::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) m_band->contextMenuEvent(event); } +void BandMarker::hoverMoveEvent(QGraphicsSceneHoverEvent* event) +{ + if (QRectF(0, height()-10, width(), 10).contains(event->pos())){ + setCursor(Qt::SizeVerCursor); + } else { + unsetCursor(); + } +} + +void BandMarker::mouseMoveEvent(QGraphicsSceneMouseEvent* event) +{ + qreal delta = event->pos().y() - event->lastPos().y(); + if (hasCursor()){ + m_band->setHeight(m_band->height() + delta); + } else { + if (!m_band->isFixedPos()) + m_band->setItemPos(QPointF(m_band->pos().x(),m_band->pos().y()+delta)); + } +} + +void BandMarker::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) +{ + m_band->posChanged(m_band, m_band->pos(), m_band->pos()); +} + BandDesignIntf::BandDesignIntf(BandsType bandType, const QString &xmlTypeName, QObject* owner, QGraphicsItem *parent) : ItemsContainerDesignInft(xmlTypeName, owner,parent), m_bandType(bandType), @@ -140,6 +175,8 @@ BandDesignIntf::BandDesignIntf(BandsType bandType, const QString &xmlTypeName, Q if (parentItem) setWidth(parentItem->width()); } + setBackgroundMode(BGMode::TransparentMode); + setFillTransparentInDesignMode(false); setHeight(100); setFixedPos(true); setFlag(QGraphicsItem::ItemClipsChildrenToShape); @@ -304,6 +341,12 @@ bool BandDesignIntf::isUnique() const return true; } +void BandDesignIntf::setItemMode(BaseDesignIntf::ItemMode mode) +{ + ItemsContainerDesignInft::setItemMode(mode); + updateBandMarkerGeometry(); +} + QString BandDesignIntf::datasourceName(){ return m_dataSourceName; } @@ -728,14 +771,19 @@ BandDesignIntf* BandDesignIntf::findParentBand() return 0; } +void BandDesignIntf::updateBandMarkerGeometry() +{ + if (parentItem() && m_bandMarker){ + QPointF sp = parentItem()->mapToScene(pos()); + m_bandMarker->setPos((sp.x()-m_bandMarker->boundingRect().width()),sp.y()); + m_bandMarker->setHeight(rect().height()); + } +} + void BandDesignIntf::geometryChangedEvent(QRectF, QRectF ) { if (((itemMode()&DesignMode) || (itemMode()&EditMode))&&parentItem()){ - QPointF sp = parentItem()->mapToScene(pos()); - if (m_bandMarker){ - m_bandMarker->setPos((sp.x()-m_bandMarker->boundingRect().width()),sp.y()); - m_bandMarker->setHeight(rect().height()); - } + updateBandMarkerGeometry(); } foreach (BaseDesignIntf* item, childBaseItems()) { if (item->itemAlign()!=DesignedItemAlign){ diff --git a/limereport/lrbanddesignintf.h b/limereport/lrbanddesignintf.h index 16009a5..33bca63 100644 --- a/limereport/lrbanddesignintf.h +++ b/limereport/lrbanddesignintf.h @@ -62,8 +62,12 @@ public: qreal width(){return m_rect.width();} qreal height(){return m_rect.height();} protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mousePressEvent(QGraphicsSceneMouseEvent *event); void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); + + void hoverMoveEvent(QGraphicsSceneHoverEvent* event); + void mouseMoveEvent(QGraphicsSceneMouseEvent* event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); private: QRectF m_rect; QColor m_color; @@ -142,6 +146,7 @@ public: virtual QString bandTitle() const; virtual QIcon bandIcon() const; virtual bool isUnique() const; + void setItemMode(BaseDesignIntf::ItemMode mode); void updateItemSize(DataSourceManager *dataManager, RenderPass pass=FirstPass, int maxHeight=0); void restoreItems(); void recalcItems(DataSourceManager* dataManager); @@ -250,6 +255,8 @@ public: void setBackgroundOpacity(int value); int bootomSpace() const; void setBootomSpace(int bootomSpace); + void updateBandMarkerGeometry(); + signals: void bandRendered(BandDesignIntf* band); void preparedForRender(); diff --git a/limereport/lrbasedesignintf.cpp b/limereport/lrbasedesignintf.cpp index 0cb6c09..e70199b 100644 --- a/limereport/lrbasedesignintf.cpp +++ b/limereport/lrbasedesignintf.cpp @@ -52,7 +52,7 @@ namespace LimeReport BaseDesignIntf::BaseDesignIntf(const QString &storageTypeName, QObject *owner, QGraphicsItem *parent) : QObject(owner), QGraphicsItem(parent), - m_resizeHandleSize(Const::RESIZE_HANDLE_SIZE), + m_resizeHandleSize(Const::RESIZE_HANDLE_SIZE*2), m_selectionPenSize(Const::SELECTION_PEN_SIZE), m_possibleResizeDirectionFlags(ResizeTop | ResizeBottom | ResizeLeft | ResizeRight), m_possibleMoveDirectionFlags(All), @@ -69,8 +69,6 @@ BaseDesignIntf::BaseDesignIntf(const QString &storageTypeName, QObject *owner, Q m_storageTypeName(storageTypeName), m_itemMode(DesignMode), m_objectState(ObjectCreated), - m_selectionMarker(0), - m_joinMarker(0), m_backgroundBrushStyle(SolidPattern), m_backgroundColor(Qt::white), m_margin(4), @@ -81,7 +79,11 @@ BaseDesignIntf::BaseDesignIntf(const QString &storageTypeName, QObject *owner, Q m_patternName(""), m_patternItem(0), m_fillInSecondPass(false), - m_watermark(false) + m_watermark(false), + m_hovered(false), + m_joinMarkerOn(false), + m_selectionMarker(0), + m_fillTransparentInDesignMode(true) { setGeometry(QRectF(0, 0, m_width, m_height)); if (BaseDesignIntf *item = dynamic_cast(parent)) { @@ -104,8 +106,7 @@ QRectF BaseDesignIntf::boundingRect() const } BaseDesignIntf::~BaseDesignIntf(void) { - delete m_selectionMarker; - delete m_joinMarker; + } void BaseDesignIntf::setParentReportItem(const QString &value) @@ -390,10 +391,16 @@ void BaseDesignIntf::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *o { Q_UNUSED(option); Q_UNUSED(widget); + ppainter->save(); setupPainter(ppainter); drawBorder(ppainter, rect()); - if (isSelected()) {drawSelection(ppainter, rect());} +// if (m_joinMarkerOn) { drawMarker(ppainter, Const::JOIN_COLOR);} +// if (isSelected() && !m_joinMarkerOn) {drawMarker(ppainter, Const::SELECTION_COLOR);} drawResizeZone(ppainter); + ppainter->restore(); +// if (m_hovered) ppainter->drawImage( +// QRectF(QPointF(rect().topRight().x()-24, rect().bottomLeft().y()-24), +// QSizeF(24, 24)),QImage(":/items/images/settings.png")); } QColor calcColor(QColor color){ @@ -424,7 +431,7 @@ void BaseDesignIntf::prepareRect(QPainter *painter, const QStyleOptionGraphicsIt qreal o = (itemMode() & DesignMode) ? 0.5 : qreal(m_opacity) / 100; painter->setOpacity(o); painter->fillRect(r, brush); - } else if (itemMode() & DesignMode){ + } else if ((itemMode() & DesignMode) && fillTransparentInDesignMode()){ painter->setOpacity(0.1); painter->fillRect(r, QBrush(QPixmap(":/report/images/empty"))); } @@ -480,6 +487,14 @@ void BaseDesignIntf::hoverLeaveEvent(QGraphicsSceneHoverEvent *) m_resizeDirectionFlags = 0; scene()->update(sceneBoundingRect()); m_resizeAreas.clear(); + m_hovered = false; + update(); +} + +void BaseDesignIntf::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + m_hovered = true; + update(); } @@ -561,6 +576,7 @@ void BaseDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event) moveSelectedItems(tmpPos - pos()); if (page()->selectedItems().count()==1 && (page()->magneticMovement())) page()->itemMoved(this); + } } } @@ -661,8 +677,9 @@ QPointF BaseDesignIntf::modifyPosForAlignedItem(const QPointF& pos){ void BaseDesignIntf::turnOnJoinMarker(bool value) { + m_joinMarkerOn = value; if (value){ - m_joinMarker = new Marker(this); + m_joinMarker = new Marker(this, this); m_joinMarker->setColor(Const::JOIN_COLOR); m_joinMarker->setRect(rect()); m_joinMarker->setVisible(true); @@ -705,17 +722,14 @@ void BaseDesignIntf::updatePossibleDirectionFlags(){ } } -void BaseDesignIntf::turnOnSelectionMarker(bool value) +bool BaseDesignIntf::fillTransparentInDesignMode() const { - 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; - } + return m_fillTransparentInDesignMode; +} + +void BaseDesignIntf::setFillTransparentInDesignMode(bool fillTransparentInDesignMode) +{ + m_fillTransparentInDesignMode = fillTransparentInDesignMode; } bool BaseDesignIntf::fillInSecondPass() const @@ -746,6 +760,30 @@ void BaseDesignIntf::setWatermark(bool watermark) } } +void BaseDesignIntf::updateSelectionMarker() +{ + if (m_selectionMarker && (itemMode() & DesignMode || itemMode() & EditMode)) { + if ((!m_selectionMarker->scene()) && scene()) scene()->addItem(m_selectionMarker); + if (parentItem()) { + m_selectionMarker->setRect(rect()); + m_selectionMarker->setPos(0,0); + } + } +} + +void BaseDesignIntf::turnOnSelectionMarker(bool value) +{ + if (value && !m_selectionMarker){ + m_selectionMarker = new SelectionMarker(this, this); + m_selectionMarker->setColor(selectionMarkerColor()); + updateSelectionMarker(); + m_selectionMarker->setVisible(true); + } else { + delete m_selectionMarker; + m_selectionMarker = 0; + } +} + QString BaseDesignIntf::patternName() const { return (m_patternName.isEmpty()) ? objectName() : m_patternName; @@ -1105,20 +1143,32 @@ QPainterPath BaseDesignIntf::shape() const return path; } -void BaseDesignIntf::drawSelection(QPainter *painter, QRectF /*rect*/) const +void BaseDesignIntf::drawMarker(QPainter *painter, QColor color) const { painter->save(); - // painter->setPen(QPen(Qt::red,m_selectionPenSize)); - // painter->drawLine(QPointF(m_resizeHandleSize,0),QPointF(0,0)); - // painter->drawLine(QPointF(0,m_resizeHandleSize),QPointF(0,0)); - // painter->drawLine(rect.right()-m_resizeHandleSize,0,rect.right(),0); - // painter->drawLine(rect.right(),m_resizeHandleSize,rect.right(),0); - // painter->drawLine(0,rect.bottom(),0,rect.bottom()-10); - // painter->drawLine(0,rect.bottom(),m_resizeHandleSize,rect.bottom()); - // painter->drawLine(rect.right()-m_resizeHandleSize,rect.bottom(),rect.right(),rect.bottom()); - // painter->drawLine(rect.right(),rect.bottom()-m_resizeHandleSize,rect.right(),rect.bottom()); - // painter->setOpacity(Consts::SELECTION_COLOR_OPACITY); - // painter->fillRect(rect,selectionColor()); + + QPen pen(color, m_selectionPenSize); + painter->setPen(pen); + painter->setBrush(QBrush(color)); + painter->setOpacity(1); + const int markerSize = Const::RESIZE_HANDLE_SIZE; + 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)); + + pen.setStyle(Qt::DotLine); + painter->setPen(pen); + painter->setBrush(QBrush(Qt::transparent)); + painter->drawRect(rect()); painter->restore(); } @@ -1166,8 +1216,7 @@ void BaseDesignIntf::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) QRectF newGeometry = geometry(); if (newGeometry != m_oldGeometry) { geometryChangedEvent(newGeometry, m_oldGeometry); - updateSelectionMarker(); - emit(posChanged(this, newGeometry.topLeft(), m_oldGeometry.topLeft())); + emit posChanged(this, newGeometry.topLeft(), m_oldGeometry.topLeft()); } QGraphicsItem::mouseReleaseEvent(event); } @@ -1296,17 +1345,6 @@ void BaseDesignIntf::setMarginSize(int value) } } -void BaseDesignIntf::updateSelectionMarker() -{ - if (m_selectionMarker && (itemMode() & DesignMode || itemMode() & EditMode)) { - if ((!m_selectionMarker->scene()) && scene()) scene()->addItem(m_selectionMarker); - if (parentItem()) { - m_selectionMarker->setRect(rect()); - m_selectionMarker->setPos(0,0); - } - } -} - void BaseDesignIntf::drawResizeZone(QPainter* /*painter*/) { @@ -1549,43 +1587,23 @@ void BaseDesignIntf::notify(const QVector& propertyNames) emit propertyesChanged(propertyNames); } -SelectionMarker::SelectionMarker(QGraphicsItem *parent)//, QGraphicsScene *scene) - : Marker(parent) -{ - setAcceptHoverEvents(true); + +QMap BaseDesignIntf::getStringForTranslation(){ + return QMap(); } -void SelectionMarker::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +QVariant BookmarkContainerDesignIntf::getBookMark(const QString& key) { - BaseDesignIntf* baseItem = dynamic_cast(parentItem()); - if(baseItem) baseItem->hoverMoveEvent(event); + if (m_bookmarks.contains(key)) + return m_bookmarks.value(key); + else return QVariant(); } -void SelectionMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) +void BookmarkContainerDesignIntf::copyBookmarks(BookmarkContainerDesignIntf* source) { - parentItem()->setSelected(true); - BaseDesignIntf* baseItem = dynamic_cast(parentItem()); - if(baseItem) baseItem->mousePressEvent(event); - QGraphicsItem::mousePressEvent(event); -} - -void SelectionMarker::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - BaseDesignIntf* baseItem = dynamic_cast(parentItem()); - if(baseItem) baseItem->mouseReleaseEvent(event); -} - -void SelectionMarker::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) -{ - BaseDesignIntf* baseItem = dynamic_cast(parentItem()); - if(baseItem) baseItem->mouseDoubleClickEvent(event); - QGraphicsItem::mouseDoubleClickEvent(event); -} - -void SelectionMarker::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - BaseDesignIntf* baseItem = dynamic_cast(parentItem()); - if(baseItem) baseItem->mouseMoveEvent(event); + foreach(QString key, source->bookmarks()){ + addBookmark(key,source->getBookMark(key)); + } } QRectF Marker::boundingRect() const @@ -1593,7 +1611,7 @@ QRectF Marker::boundingRect() const return m_rect.adjusted(-15,-15,15,15); } -void Marker::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +void Marker::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) { QPen pen; const int markerSize = 5; @@ -1617,40 +1635,45 @@ void Marker::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget 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)); + rect().bottom()-markerSize,markerSize*2,markerSize*2)); } -QRectF Marker::rect() const +SelectionMarker::SelectionMarker(QGraphicsItem* parent, BaseDesignIntf* owner) + : Marker(parent, owner) { - return m_rect; + setAcceptHoverEvents(true); } -QColor Marker::color() const +void SelectionMarker::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { - return m_color; + if (owner()) owner()->hoverMoveEvent(event); + QGraphicsItem::hoverMoveEvent(event); } -BaseDesignIntf *Marker::object() const +void SelectionMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) { - return m_object; -} - -QMap BaseDesignIntf::getStringForTranslation(){ - return QMap(); -} - -QVariant BookmarkContainerDesignIntf::getBookMark(const QString& key) -{ - if (m_bookmarks.contains(key)) - return m_bookmarks.value(key); - else return QVariant(); -} - -void BookmarkContainerDesignIntf::copyBookmarks(BookmarkContainerDesignIntf* source) -{ - foreach(QString key, source->bookmarks()){ - addBookmark(key,source->getBookMark(key)); + if (owner()){ + owner()->setSelected(true); + owner()->mousePressEvent(event); } + QGraphicsItem::mousePressEvent(event); +} + +void SelectionMarker::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (owner()) owner()->mouseReleaseEvent(event); +} + +void SelectionMarker::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + if (owner()) owner()->mouseDoubleClickEvent(event); + QGraphicsItem::mouseDoubleClickEvent(event); +} + +void SelectionMarker::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + qDebug() << "mouse move"; + if (owner()) owner()->mouseMoveEvent(event); } } //namespace LimeReport diff --git a/limereport/lrbasedesignintf.h b/limereport/lrbasedesignintf.h index 9bfb288..6209b97 100644 --- a/limereport/lrbasedesignintf.h +++ b/limereport/lrbasedesignintf.h @@ -51,23 +51,23 @@ class BaseDesignIntf; class Marker : public QGraphicsItem{ public: - Marker(QGraphicsItem* parent=0):QGraphicsItem(parent),m_object(NULL){} + Marker(QGraphicsItem* parent = 0, BaseDesignIntf* owner = 0): QGraphicsItem(parent), m_owner(owner){} 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; + QRectF rect() const {return m_rect;} + QColor color() const {return m_color;} + BaseDesignIntf* owner() const {return m_owner;} private: QRectF m_rect; QColor m_color; - BaseDesignIntf* m_object; + BaseDesignIntf* m_owner; }; class SelectionMarker : public Marker{ public: - SelectionMarker(QGraphicsItem* parent=0); + SelectionMarker(QGraphicsItem* parent=0, BaseDesignIntf* owner = 0); protected: void hoverMoveEvent(QGraphicsSceneHoverEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event); @@ -180,6 +180,7 @@ public: virtual QPainterPath shape() const; void setFixedPos(bool fixedPos); + bool isFixedPos(){return m_fixedPos;} int resizeHandleSize() const; void setMMFactor(qreal mmFactor); @@ -204,7 +205,7 @@ public: void setItemPos(const QPointF &newPos); void setItemPos(qreal x, qreal y); - void setItemMode(LimeReport::BaseDesignIntf::ItemMode mode); + virtual void setItemMode(LimeReport::BaseDesignIntf::ItemMode mode); ItemMode itemMode() const {return m_itemMode;} virtual void setBorderLinesFlags(LimeReport::BaseDesignIntf::BorderLines flags); @@ -281,7 +282,8 @@ public: void setFillInSecondPass(bool fillInSecondPass); bool isWatermark() const; virtual void setWatermark(bool watermark); - + void updateSelectionMarker(); + void turnOnSelectionMarker(bool value); Q_INVOKABLE QString setItemWidth(qreal width); Q_INVOKABLE QString setItemHeight(qreal height); Q_INVOKABLE qreal getItemWidth(); @@ -293,6 +295,9 @@ public: Q_INVOKABLE QString setItemPosX(qreal xValue); Q_INVOKABLE QString setItemPosY(qreal yValue); + bool fillTransparentInDesignMode() const; + void setFillTransparentInDesignMode(bool fillTransparentInDesignMode); + protected: //ICollectionContainer @@ -305,10 +310,11 @@ protected: void mousePressEvent(QGraphicsSceneMouseEvent* event); void hoverMoveEvent(QGraphicsSceneHoverEvent* event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); - //void virtual hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent* event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); virtual void geometryChangedEvent(QRectF newRect, QRectF oldRect); @@ -331,7 +337,7 @@ protected: void drawDesignModeBorder(QPainter* painter, QRectF rect) const; void drawRenderModeBorder(QPainter *painter, QRectF rect) const; void drawResizeZone(QPainter*); - void drawSelection(QPainter* painter, QRectF) const; + void drawMarker(QPainter* painter, QColor color) const; void drawPinArea(QPainter* painter) const; void initResizeZones(); @@ -358,12 +364,10 @@ protected: qreal calcAbsolutePosX(qreal currentOffset, BaseDesignIntf* item); private: - void updateSelectionMarker(); int resizeDirectionFlags(QPointF position); void moveSelectedItems(QPointF delta); Qt::CursorShape getPossibleCursor(int cursorFlags); void updatePossibleDirectionFlags(); - void turnOnSelectionMarker(bool value); private: QPointF m_startPos; int m_resizeHandleSize; @@ -398,8 +402,6 @@ private: ItemMode m_itemMode; ObjectState m_objectState; - SelectionMarker* m_selectionMarker; - Marker* m_joinMarker; BrushStyle m_backgroundBrushStyle; QColor m_backgroundColor; @@ -415,7 +417,11 @@ private: BaseDesignIntf* m_patternItem; bool m_fillInSecondPass; bool m_watermark; - + bool m_hovered; + bool m_joinMarkerOn; + SelectionMarker* m_selectionMarker; + Marker* m_joinMarker; + bool m_fillTransparentInDesignMode; signals: void geometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry); void posChanging(QObject* object, QPointF newPos, QPointF oldPos); diff --git a/limereport/lrglobal.h b/limereport/lrglobal.h index ba5a363..76af327 100644 --- a/limereport/lrglobal.h +++ b/limereport/lrglobal.h @@ -52,8 +52,8 @@ namespace LimeReport { namespace Const{ - int const RESIZE_HANDLE_SIZE = 10; - int const SELECTION_PEN_SIZE = 4; + int const RESIZE_HANDLE_SIZE = 5; + int const SELECTION_PEN_SIZE = 1; int const MINIMUM_ITEM_WIDTH = 2*RESIZE_HANDLE_SIZE; int const MINIMUM_ITEM_HEIGHT = 2*RESIZE_HANDLE_SIZE; double const RESIZE_ZONE_OPACITY = 0.5; diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index 1bb5558..0e039d8 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -339,6 +339,15 @@ void PageDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event) qreal posY = div(pageItem()->mapFromScene(event->scenePos()).y(), verticalGridStep()).quot * verticalGridStep(); qreal posX = div(pageItem()->mapFromScene(event->scenePos()).x(), verticalGridStep()).quot * horizontalGridStep(); m_itemInsertRect->setPos(posX,posY); + if (magneticMovement()){ + rectMoved( + QRectF(m_itemInsertRect->pos().x(), + m_itemInsertRect->pos().y(), + m_itemInsertRect->boundingRect().width(), + m_itemInsertRect->boundingRect().height() + ) + ); + } } else { if (m_insertMode) m_itemInsertRect->setVisible(false); } @@ -1102,9 +1111,53 @@ void PageDesignIntf::endUpdate() emit pageUpdateFinished(this); } + +void PageDesignIntf::activateItemToJoin(QRectF itemRect, QList& items){ + QRectF r1(itemRect.x(), itemRect.y()-50, itemRect.width(), itemRect.height()+100); + QRectF r2(itemRect.x()-50, itemRect.y(), itemRect.width()+100, itemRect.height()); + qreal maxSquare = 0; + + if (m_joinItem) { + m_joinItem->turnOnJoinMarker(false); + m_joinItem = 0; + } + + foreach(ItemProjections p, items){ + qreal tmpSquare = qMax(p.square(r1)/itemRect.width(),p.square(r2)/itemRect.height()); + if (tmpSquare>maxSquare) { + maxSquare = tmpSquare; + m_joinItem = p.item(); + if (p.square(r1)/itemRect.width() > p.square(r2) / itemRect.height()) + m_joinType = Width; + else + m_joinType = Height; + } + } + + if (m_joinItem) m_joinItem->turnOnJoinMarker(true); +} + +void PageDesignIntf::rectMoved(QRectF itemRect, BaseDesignIntf* container){ + if (!container){ + container = bandAt(QPointF(itemRect.topLeft())); + if (!container) container = this->pageItem(); + } + + if (container){ + m_projections.clear(); + foreach(BaseDesignIntf* bi, container->childBaseItems()){ + m_projections.append(ItemProjections(bi)); + } + } + + activateItemToJoin(itemRect, m_projections); + +} + void PageDesignIntf::itemMoved(BaseDesignIntf *item) { if (m_movedItem!=item){ + m_movedItem = item; BaseDesignIntf* curItem = dynamic_cast(item->parentItem()); ; while (curItem){ m_movedItemContainer = dynamic_cast(curItem); @@ -1122,28 +1175,29 @@ void PageDesignIntf::itemMoved(BaseDesignIntf *item) } } - 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; + activateItemToJoin(item->geometry(), m_projections); +// 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; - } +// 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; - } - } +// 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); +// if (m_joinItem) m_joinItem->turnOnJoinMarker(true); } @@ -2427,7 +2481,7 @@ CommandIf::Ptr BandMoveFromToCommand::create(PageDesignIntf* page, int from, int bool BandMoveFromToCommand::doIt() { - if (page() && from != to) { + if (page() && page()->pageItem() && from != to) { page()->pageItem()->moveBandFromTo(from, to); return true; } diff --git a/limereport/lrpagedesignintf.h b/limereport/lrpagedesignintf.h index 901ddbc..49f8031 100644 --- a/limereport/lrpagedesignintf.h +++ b/limereport/lrpagedesignintf.h @@ -166,6 +166,7 @@ namespace LimeReport { bool isUpdating(){return m_updating;} void endUpdate(); + void rectMoved(QRectF itemRect, BaseDesignIntf* container = 0); void itemMoved(BaseDesignIntf* item); bool magneticMovement() const; void setMagneticMovement(bool magneticMovement); @@ -175,6 +176,7 @@ namespace LimeReport { void setPropertyToSelectedItems(const char *name, const QVariant &value); + protected: virtual void keyPressEvent(QKeyEvent *event); @@ -272,7 +274,7 @@ namespace LimeReport { const QVariant& oldPropertyValue, const QVariant& newPropertyValue); void changeSelectedGroupProperty(const QString& name,const QVariant& value); - + void activateItemToJoin(QRectF itemRect, QList& items); private: enum JoinType{Width, Height}; LimeReport::PageItemDesignIntf::Ptr m_pageItem; @@ -312,6 +314,7 @@ namespace LimeReport { JoinType m_joinType; bool m_magneticMovement; ReportSettings* m_reportSettings; + }; class AbstractPageCommand : public CommandIf{ diff --git a/limereport/lrpageitemdesignintf.cpp b/limereport/lrpageitemdesignintf.cpp index 0f8d98a..d0f949e 100644 --- a/limereport/lrpageitemdesignintf.cpp +++ b/limereport/lrpageitemdesignintf.cpp @@ -164,6 +164,12 @@ QRectF PageItemDesignIntf::boundingRect() const } } +void PageItemDesignIntf::setItemMode(BaseDesignIntf::ItemMode mode) +{ + ItemsContainerDesignInft::setItemMode(mode); + relocateBands(); +} + void PageItemDesignIntf::clear() { foreach(QGraphicsItem* item, childItems()){ @@ -473,7 +479,7 @@ void PageItemDesignIntf::relocateBands() { if (isLoading()) return; - int bandSpace = (itemMode() & DesignMode)?4:0; + int bandSpace = (itemMode() & DesignMode)?0:0; QVector posByColumn; diff --git a/limereport/lrpageitemdesignintf.h b/limereport/lrpageitemdesignintf.h index 39c0fe3..09fa2d6 100644 --- a/limereport/lrpageitemdesignintf.h +++ b/limereport/lrpageitemdesignintf.h @@ -90,6 +90,7 @@ public: virtual QColor pageBorderColor() const; virtual QColor gridColor() const; virtual QRectF boundingRect() const; + void setItemMode(LimeReport::BaseDesignIntf::ItemMode mode); void clear(); const BandsList& childBands() const {return m_bands;} BandDesignIntf * bandByType(BandDesignIntf::BandsType bandType) const;