30 #include <QGraphicsSceneMouseEvent> 33 bool sorting(QGraphicsItem *qgia, QGraphicsItem *qgib)
35 return qgia->pos().y() < qgib->pos().y();
43 QGraphicsItemGroup(parent),
45 m_parent_element(parent)
47 setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
66 QGraphicsItemGroup::addToGroup(item);
91 QGraphicsItemGroup::removeFromGroup(item);
94 item->resetTransform();
96 item->setFlag(QGraphicsItem::ItemIsSelectable,
true);
155 prepareGeometryChange();
157 QList <DynamicElementTextItem *>
texts = this->
texts();
163 QGraphicsItem *parent = parentItem();
165 rot += parent->rotation();
166 parent = parent->parentItem();
172 if(
texts.size() == 1)
174 prepareGeometryChange();
176 QGraphicsItem *first =
texts.first();
177 setPos(mapFromScene(first->mapToScene(
pos())));
180 else if (
texts.size() > 1)
183 for(QGraphicsItem *item :
texts)
184 if(item->boundingRect().width() > width)
185 width = item->boundingRect().width();
187 prepareGeometryChange();
194 QPointF ref =
texts.first()->pos();
196 for(QGraphicsItem *item :
texts)
198 item->setPos(0, ref.y()+y_offset);
204 QPointF ref(width/2,0);
206 for(QGraphicsItem *item :
texts)
208 item->setPos(ref.x() - item->boundingRect().width()/2,
215 QPointF ref(width,0);
217 for(QGraphicsItem *item :
texts)
219 item->setPos(ref.x() - item->boundingRect().width(),
245 prepareGeometryChange();
269 setFlag(QGraphicsItem::ItemIsSelectable,
false);
270 setFlag(QGraphicsItem::ItemIsMovable,
false);
287 setFlag(QGraphicsItem::ItemIsSelectable,
true);
288 setFlag(QGraphicsItem::ItemIsMovable,
true);
319 QList<DynamicElementTextItem *> list;
320 for(QGraphicsItem *qgi : childItems())
323 list << static_cast<DynamicElementTextItem *>(qgi);
335 return static_cast<Diagram *
>(scene());
347 return static_cast<Element *
>(parentItem());
360 QDomElement dom_element = dom_document.createElement(this->
xmlTaggName());
361 dom_element.setAttribute(
"name",
m_name);
363 dom_element.setAttribute(
"x", QString::number(
pos().x()));
364 dom_element.setAttribute(
"y", QString::number(
pos().y()));
366 QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>();
367 dom_element.setAttribute(
"alignment", me.valueToKey(
m_alignment));
369 dom_element.setAttribute(
"rotation", this->
rotation());
371 dom_element.setAttribute(
"frame",
m_frame?
"true" :
"false");
375 QDomElement dom_texts = dom_document.createElement(
"texts");
378 QDomElement text = dom_document.createElement(
"text");
379 text.setAttribute(
"uuid", deti->uuid().toString());
380 dom_texts.appendChild(text);
383 dom_element.appendChild(dom_texts);
395 qDebug() <<
"ElementTextItemGroup::fromXml : Wrong tagg name";
399 setName(dom_element.attribute(
"name",
"no name"));
400 QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>();
401 setAlignment(Qt::Alignment(me.keyToValue(dom_element.attribute(
"alignment").toStdString().data())));
403 setPos(dom_element.attribute(
"x", QString::number(0)).toDouble(),
404 dom_element.attribute(
"y", QString::number(0)).toDouble());
406 setRotation(dom_element.attribute(
"rotation", QString::number(0)).toDouble());
408 setFrame(dom_element.attribute(
"frame",
"false") ==
"true"? true :
false);
410 QString hold = dom_element.attribute(
"hold_to_bottom_page",
"false");
419 QUuid uuid(text.attribute(
"uuid"));
422 if(txt->uuid() == uuid)
446 t.setColor(Qt::gray);
447 t.setStyle(Qt::DashDotLine);
450 painter->drawRoundRect(
boundingRect().adjusted(1, 1, -1, -1), 10, 10);
460 font_size = std::max(font_size, deti->font().pointSizeF());
461 rect = rect.united(mapFromItem(deti, deti->frameRect()).
boundingRect());
476 painter->setPen(pen);
477 painter->setRenderHint(QPainter::Antialiasing);
480 qreal
ro = font_size/3;
481 painter->drawRoundedRect(rect,
ro,
ro);
498 for(QGraphicsItem *qgi :
texts())
500 QRectF r(qgi->pos(), QSize(qgi->boundingRect().width(), qgi->boundingRect().height()));
501 rect = rect.united(r);
508 QGraphicsItemGroup::setRotation(angle);
514 QPointF old_pos = this->
pos();
515 QGraphicsItemGroup::setPos(
pos);
516 if (old_pos.x() != this->
pos().x())
518 if (old_pos.y() != this->
pos().y())
524 QPointF old_pos = this->
pos();
525 QGraphicsItemGroup::setPos(x,y);
526 if (old_pos.x() != this->
pos().x())
528 if (old_pos.y() != this->
pos().y())
538 if(event->button() == Qt::LeftButton)
541 if(event->modifiers() & Qt::ControlModifier)
542 setSelected(!isSelected());
545 QGraphicsItemGroup::mousePressEvent(event);
554 if((event->buttons() & Qt::LeftButton) && (flags() & ItemIsMovable))
566 QPointF current_parent_pos;
567 QPointF button_down_parent_pos;
568 current_parent_pos = mapToParent(mapFromScene(event->scenePos()));
569 button_down_parent_pos = mapToParent(mapFromScene(event->buttonDownScenePos(Qt::LeftButton)));
597 if(!(event->modifiers() & Qt::ControlModifier))
598 QGraphicsItemGroup::mouseReleaseEvent(event);
617 if(scene() != elmt->scene())
619 elmt->setSelected(
true);
622 for(QGraphicsView *view : elmt->scene()->views())
624 QRectF fit = elmt->sceneBoundingRect();
625 fit.adjust(-200, -200, 200, 200);
626 view->fitInView(fit, Qt::KeepAspectRatioByExpanding);
639 if(event->modifiers() == Qt::ControlModifier)
641 if(event->key() == Qt::Key_Left &&
m_alignment != Qt::AlignLeft)
648 else if (event->key() == Qt::Key_Up &&
m_alignment != Qt::AlignVCenter)
655 else if (event->key() == Qt::Key_Right &&
m_alignment != Qt::AlignRight)
674 QGraphicsItemGroup::hoverEnterEvent(event);
682 QGraphicsItemGroup::hoverLeaveEvent(event);
705 deti->infoName() ==
"label")
790 offset += (int)rectXref.height();
void holdToBottomPageChanged(bool)
The CrossRefItem class This clas provide an item, for show the cross reference, like the contacts lin...
void fontChanged(QFont font)
QRectF boundingRect() const override
ElementTextItemGroup::boundingRect.
virtual kind linkType() const
void frameChanged(bool frame)
QList< Element * > linkedElements()
Element::linkedElements.
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
static QString formulaToLabel(QString formula, sequentialNumbers &seqStruct, Diagram *diagram, const Element *elmt=nullptr)
AssignVariables::formulaToLabel Return the with variable assigned (ready to be displayed) ...
The DynamicElementTextItem class This class provide a simple text field of element who can be added o...
The MasterElement class This class is a custom element, with extended behavior to be a master element...
void textFromChanged(DynamicElementTextItem::TextFrom text_from)
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
ElementTextItemGroup::mouseReleaseEvent.
The XRefProperties class this class store properties used by XrefItem.
QGraphicsTextItem * m_slave_Xref_item
QList< QMetaObject::Connection > m_update_slave_Xref_connection
void setAlignment(Qt::Alignment alignement)
ElementTextItemGroup::setAlignement Set the alignement of this group.
Diagram * diagram() const
QetGraphicsItem::diagram return the diagram of this item.
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
ElementTextItemGroup::mousePressEvent.
autonum::sequentialNumbers & rSequenceStruct()
QString slaveLabel() const
virtual void setHighlighted(bool)
void fromXml(QDomElement &dom_element)
ElementTextItemGroup::fromXml Import data of this group from xml.
void removeFromGroup(QGraphicsItem *item)
ElementTextItemGroup::removeFromGroup.
void addToGroup(QGraphicsItem *item)
ElementTextItemGroup::addToGroup.
void linkedElementChanged()
int beginMovement(Diagram *diagram, QGraphicsItem *driver_item=nullptr)
ElementTextsMover::beginMovement Begin a movement.
bool centerToBottomDiagram(QGraphicsItem *item_to_center, Element *element_to_follow, qreal offset)
centerToBottomDiagram Set item pos to the bottom of diagram and centered vertically to element_to_fol...
~ElementTextItemGroup() override
void verticalAdjustmentChanged(int)
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
ElementTextItemGroup::mouseMoveEvent.
ElementTextsMover & elementTextsMover()
void setVerticalAdjustment(int v)
ElementTextItemGroup::setVerticalAdjustment Set the value of the vertical adjustment to ...
void setRotation(qreal angle)
bool m_block_alignment_update
ElementTextItemGroup(const QString &name, Element *parent)
ElementTextItemGroup::ElementTextItemGroup.
void updateAlignment()
ElementTextItemGroup::setAlignment Update the alignement of the items in this group, according to the current alignement.
void setFrame(const bool frame)
QPointF m_initial_position
QList< DynamicElementTextItem * > texts() const
ElementTextItemGroup::texts.
CrossRefItem * m_Xref_item
QList< QDomElement > findInDomElement(const QDomElement &, const QString &)
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
Qt::Alignment m_alignment
void continueMovement(QGraphicsSceneMouseEvent *event)
bool sorting(QGraphicsItem *qgia, QGraphicsItem *qgib)
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
ElementTextItemGroup::paint.
void rotationChanged(qreal)
int m_vertical_adjustment
QDomElement toXml(QDomDocument &dom_document) const
ElementTextItemGroup::toXml Export data of this group to xml.
void textWidthChanged(qreal width)
Element * parentElement() const
ElementTextItemGroup::parentElement.
void setName(QString name)
ElementTextItemGroup::setName.
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
void projectDiagramsOrderChanged(QETProject *, int, int)
QMetaObject::Connection m_XrefChanged_timer
void elementInfoChange(DiagramContext old_info, DiagramContext new_info)
void textChanged(QString text)
void infoNameChanged(QString info)
void blockAlignmentUpdate(bool block)
ElementTextItemGroup::blockAlignmentUpdate If true, the texts in this group are never aligned...
void setPos(const QPointF &pos)
static QPointF snapToGrid(const QPointF &p)
Diagram::snapToGrid Return a nearest snap point of p.
void adjustSlaveXrefPos()
void alignmentChanged(Qt::Alignment)
static QString xmlTaggName()
static QFont diagramTextsFont(qreal=-1.0)
QETApp::diagramTextsFont The font to use By default the font is "sans Serif" and size 9...
void compositeTextChanged(QString text)
void nameChanged(QString)
void setHoldToBottomPage(bool hold)
XRefProperties defaultXRefProperties(const QString &type) const
bool m_hold_to_bottom_of_page
DiagramContext kindInformations() const
QRectF XrefBoundingRect() const
MasterElement::XrefBoundingRect.
Qt::Alignment alignment() const
void keyPressEvent(QKeyEvent *event) override
ElementTextItemGroup::keyPressEvent.
void XRefPropertiesChanged()
QMetaObject::Connection m_linked_changed_timer
QETProject * project() const
bool addTextToGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
Element::addTextToGroup Add the text to the group ; If isn't owned by this element return false...
void autoPos()
CrossRefItem::autoPos Calculate and set position automaticaly.
QList< DynamicElementTextItem * > dynamicTextItems() const
Element::dynamicTextItems.
void endMovement()
ElementTextsMover::endMovement Finish the movement by pushing an undo command to the parent diagram o...
Element * m_parent_element
Diagram * diagram() const
ElementTextItemGroup::diagram.
void diagramRemoved(QETProject *, Diagram *)