0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-25 17:14:40 +03:00

Band marker has been refactored

Selection & join markers have been returned back
This commit is contained in:
Arin Alexander 2019-03-01 02:47:19 +03:00
parent 6ce77268fd
commit 1bb6fc8f5a
4 changed files with 188 additions and 19 deletions

View File

@ -39,7 +39,9 @@ namespace LimeReport {
BandMarker::BandMarker(BandDesignIntf *band, QGraphicsItem* parent) BandMarker::BandMarker(BandDesignIntf *band, QGraphicsItem* parent)
:QGraphicsItem(parent),m_rect(0,0,30,30),m_band(band) :QGraphicsItem(parent),m_rect(0,0,30,30),m_band(band)
{} {
setAcceptHoverEvents(true);
}
QRectF BandMarker::boundingRect() const QRectF BandMarker::boundingRect() const
{ {
@ -52,6 +54,13 @@ void BandMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem* /**opt
painter->setOpacity(Const::BAND_MARKER_OPACITY); painter->setOpacity(Const::BAND_MARKER_OPACITY);
painter->fillRect(boundingRect(),m_color); painter->fillRect(boundingRect(),m_color);
painter->setOpacity(1); painter->setOpacity(1);
painter->setPen(QPen(QBrush(Qt::white),2));
painter->fillRect(QRectF(
boundingRect().bottomLeft().x(),
boundingRect().bottomLeft().y()-4,
boundingRect().width(),4), Qt::white
);
painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
qreal size = (boundingRect().width()<boundingRect().height()) ? boundingRect().width() : boundingRect().height(); qreal size = (boundingRect().width()<boundingRect().height()) ? boundingRect().width() : boundingRect().height();
QRectF r = QRectF(0,0,size,size); QRectF r = QRectF(0,0,size,size);
@ -62,6 +71,7 @@ void BandMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem* /**opt
painter->setBrush(LimeReport::Const::SELECTION_COLOR); painter->setBrush(LimeReport::Const::SELECTION_COLOR);
painter->drawEllipse(r.adjusted(7,7,-7,-7)); painter->drawEllipse(r.adjusted(7,7,-7,-7));
} }
painter->restore(); painter->restore();
} }
@ -104,6 +114,31 @@ void BandMarker::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
m_band->contextMenuEvent(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) : BandDesignIntf::BandDesignIntf(BandsType bandType, const QString &xmlTypeName, QObject* owner, QGraphicsItem *parent) :
ItemsContainerDesignInft(xmlTypeName, owner,parent), ItemsContainerDesignInft(xmlTypeName, owner,parent),
m_bandType(bandType), m_bandType(bandType),

View File

@ -62,8 +62,12 @@ public:
qreal width(){return m_rect.width();} qreal width(){return m_rect.width();}
qreal height(){return m_rect.height();} qreal height(){return m_rect.height();}
protected: protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
void hoverMoveEvent(QGraphicsSceneHoverEvent* event);
void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private: private:
QRectF m_rect; QRectF m_rect;
QColor m_color; QColor m_color;

View File

@ -81,7 +81,8 @@ BaseDesignIntf::BaseDesignIntf(const QString &storageTypeName, QObject *owner, Q
m_fillInSecondPass(false), m_fillInSecondPass(false),
m_watermark(false), m_watermark(false),
m_hovered(false), m_hovered(false),
m_joinMarkerOn(false) m_joinMarkerOn(false),
m_selectionMarker(0)
{ {
setGeometry(QRectF(0, 0, m_width, m_height)); setGeometry(QRectF(0, 0, m_width, m_height));
if (BaseDesignIntf *item = dynamic_cast<BaseDesignIntf *>(parent)) { if (BaseDesignIntf *item = dynamic_cast<BaseDesignIntf *>(parent)) {
@ -104,8 +105,7 @@ QRectF BaseDesignIntf::boundingRect() const
} }
BaseDesignIntf::~BaseDesignIntf(void) { BaseDesignIntf::~BaseDesignIntf(void) {
//delete m_selectionMarker;
//delete m_joinMarker;
} }
void BaseDesignIntf::setParentReportItem(const QString &value) void BaseDesignIntf::setParentReportItem(const QString &value)
@ -393,8 +393,8 @@ void BaseDesignIntf::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *o
ppainter->save(); ppainter->save();
setupPainter(ppainter); setupPainter(ppainter);
drawBorder(ppainter, rect()); drawBorder(ppainter, rect());
if (m_joinMarkerOn) { drawMarker(ppainter, Const::JOIN_COLOR);} // if (m_joinMarkerOn) { drawMarker(ppainter, Const::JOIN_COLOR);}
if (isSelected() && !m_joinMarkerOn) {drawMarker(ppainter, Const::SELECTION_COLOR);} // if (isSelected() && !m_joinMarkerOn) {drawMarker(ppainter, Const::SELECTION_COLOR);}
drawResizeZone(ppainter); drawResizeZone(ppainter);
ppainter->restore(); ppainter->restore();
// if (m_hovered) ppainter->drawImage( // if (m_hovered) ppainter->drawImage(
@ -677,16 +677,15 @@ QPointF BaseDesignIntf::modifyPosForAlignedItem(const QPointF& pos){
void BaseDesignIntf::turnOnJoinMarker(bool value) void BaseDesignIntf::turnOnJoinMarker(bool value)
{ {
m_joinMarkerOn = value; m_joinMarkerOn = value;
update(); if (value){
// if (value){ m_joinMarker = new Marker(this, this);
// m_joinMarker = new Marker(this); m_joinMarker->setColor(Const::JOIN_COLOR);
// m_joinMarker->setColor(Const::JOIN_COLOR); m_joinMarker->setRect(rect());
// m_joinMarker->setRect(rect()); m_joinMarker->setVisible(true);
// m_joinMarker->setVisible(true); } else {
// } else { delete m_joinMarker;
// delete m_joinMarker; m_joinMarker = 0;
// m_joinMarker = 0; }
// }
} }
void BaseDesignIntf::updateItemAlign(){ void BaseDesignIntf::updateItemAlign(){
@ -750,6 +749,31 @@ 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);
m_selectionMarker->setZValue(10000);
} else {
delete m_selectionMarker;
m_selectionMarker = 0;
}
}
QString BaseDesignIntf::patternName() const QString BaseDesignIntf::patternName() const
{ {
return (m_patternName.isEmpty()) ? objectName() : m_patternName; return (m_patternName.isEmpty()) ? objectName() : m_patternName;
@ -979,6 +1003,7 @@ void BaseDesignIntf::setGeometry(QRectF rect)
m_leftRect = QRectF(0-resizeHandleSize(), 0-resizeHandleSize(), resizeHandleSize()*2, height()+resizeHandleSize()*2); m_leftRect = QRectF(0-resizeHandleSize(), 0-resizeHandleSize(), resizeHandleSize()*2, height()+resizeHandleSize()*2);
m_rightRect = QRectF(width() - resizeHandleSize(), 0-resizeHandleSize(), resizeHandleSize()*2, height()+resizeHandleSize()*2); m_rightRect = QRectF(width() - resizeHandleSize(), 0-resizeHandleSize(), resizeHandleSize()*2, height()+resizeHandleSize()*2);
m_boundingRect = QRectF(); m_boundingRect = QRectF();
updateSelectionMarker();
if (!isLoading()){ if (!isLoading()){
geometryChangedEvent(geometry(), m_oldGeometry); geometryChangedEvent(geometry(), m_oldGeometry);
emit geometryChanged(this, geometry(), m_oldGeometry); emit geometryChanged(this, geometry(), m_oldGeometry);
@ -1064,9 +1089,11 @@ void BaseDesignIntf::initMode(ItemMode mode)
QVariant BaseDesignIntf::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) QVariant BaseDesignIntf::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{ {
if (change == QGraphicsItem::ItemPositionHasChanged) { if (change == QGraphicsItem::ItemPositionHasChanged) {
updateSelectionMarker();
} }
if (change == QGraphicsItem::ItemSelectedChange) { if (change == QGraphicsItem::ItemSelectedChange) {
turnOnSelectionMarker(value.toBool());
emit itemSelectedHasBeenChanged(this, value.toBool()); emit itemSelectedHasBeenChanged(this, value.toBool());
} }
if (change == QGraphicsItem::ItemParentHasChanged) { if (change == QGraphicsItem::ItemParentHasChanged) {
@ -1179,7 +1206,7 @@ void BaseDesignIntf::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
QRectF newGeometry = geometry(); QRectF newGeometry = geometry();
if (newGeometry != m_oldGeometry) { if (newGeometry != m_oldGeometry) {
geometryChangedEvent(newGeometry, m_oldGeometry); geometryChangedEvent(newGeometry, m_oldGeometry);
emit(posChanged(this, newGeometry.topLeft(), m_oldGeometry.topLeft())); emit posChanged(this, newGeometry.topLeft(), m_oldGeometry.topLeft());
} }
QGraphicsItem::mouseReleaseEvent(event); QGraphicsItem::mouseReleaseEvent(event);
} }
@ -1569,4 +1596,74 @@ void BookmarkContainerDesignIntf::copyBookmarks(BookmarkContainerDesignIntf* sou
} }
} }
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));
}
SelectionMarker::SelectionMarker(QGraphicsItem* parent, BaseDesignIntf* owner)
: Marker(parent, owner)
{
setAcceptHoverEvents(true);
}
void SelectionMarker::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
if (owner()) owner()->hoverMoveEvent(event);
QGraphicsItem::hoverMoveEvent(event);
}
void SelectionMarker::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
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 } //namespace LimeReport

View File

@ -47,6 +47,35 @@ enum ItemModes{ DesignMode=1, PreviewMode=2, PrintMode=4, EditMode=8, LayoutEdit
class ReportEnginePrivate; class ReportEnginePrivate;
class PageDesignIntf; class PageDesignIntf;
class BaseDesignIntf;
class Marker : public QGraphicsItem{
public:
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 {return m_rect;}
QColor color() const {return m_color;}
BaseDesignIntf* owner() const {return m_owner;}
private:
QRectF m_rect;
QColor m_color;
BaseDesignIntf* m_owner;
};
class SelectionMarker : public Marker{
public:
SelectionMarker(QGraphicsItem* parent=0, BaseDesignIntf* owner = 0);
protected:
void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
};
class DataSourceManager; class DataSourceManager;
class ReportRender; class ReportRender;
@ -151,6 +180,7 @@ public:
virtual QPainterPath shape() const; virtual QPainterPath shape() const;
void setFixedPos(bool fixedPos); void setFixedPos(bool fixedPos);
bool isFixedPos(){return m_fixedPos;}
int resizeHandleSize() const; int resizeHandleSize() const;
void setMMFactor(qreal mmFactor); void setMMFactor(qreal mmFactor);
@ -252,7 +282,8 @@ public:
void setFillInSecondPass(bool fillInSecondPass); void setFillInSecondPass(bool fillInSecondPass);
bool isWatermark() const; bool isWatermark() const;
virtual void setWatermark(bool watermark); virtual void setWatermark(bool watermark);
void updateSelectionMarker();
void turnOnSelectionMarker(bool value);
Q_INVOKABLE QString setItemWidth(qreal width); Q_INVOKABLE QString setItemWidth(qreal width);
Q_INVOKABLE QString setItemHeight(qreal height); Q_INVOKABLE QString setItemHeight(qreal height);
Q_INVOKABLE qreal getItemWidth(); Q_INVOKABLE qreal getItemWidth();
@ -385,6 +416,8 @@ private:
bool m_watermark; bool m_watermark;
bool m_hovered; bool m_hovered;
bool m_joinMarkerOn; bool m_joinMarkerOn;
SelectionMarker* m_selectionMarker;
Marker* m_joinMarker;
signals: signals:
void geometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry); void geometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry);
void posChanging(QObject* object, QPointF newPos, QPointF oldPos); void posChanging(QObject* object, QPointF newPos, QPointF oldPos);