Merge branch 'terminal_strip'

* terminal_strip:
  Terminal strip item can saved / loaded to .qet file
  See previous commit...
  Move terminal strip drawer class in is own file
  Fix wrong use of QStringLiteral and QLatin1String
  Double click a TerminalStripItem open the editor
  Minor change about checkable QAction of QetDiagramEditor
  Minor : corrects a minor aesthetic defect when unbridge terminals
  Revamp code
  Add and move terminal strip item are now managed by undo command
  TerminalStripItem : Draw terminal bridge
  Terminal strip item can be added to diagram
  Minor : add QGIUtility namespace
This commit is contained in:
joshua
2023-01-02 19:40:08 +01:00
45 changed files with 1628 additions and 276 deletions

View File

@@ -253,13 +253,13 @@ void CrossRefItem::autoPos()
{
//We calcul the position according to the snapTo of the xrefproperties
if (m_properties.snapTo() == XRefProperties::Bottom)
centerToBottomDiagram(this,
QGIUtility::centerToBottomDiagram(this,
m_element,
m_properties.offset() <= 40
? 5
: m_properties.offset());
else
centerToParentBottom(this);
QGIUtility::centerToParentBottom(this);
}
/**

View File

@@ -861,7 +861,7 @@ void ElementTextItemGroup::autoPos()
}
}
qreal r = rotation();
centerToBottomDiagram(this, m_parent_element, offset);
QGIUtility::centerToBottomDiagram(this, m_parent_element, offset);
//centerToBottomDiagram change the rotation of this group if needed,
//but setRotation is not a virtual function of QGraphicsItem, and the function centerToBottomDiagram
//work with a QGraphicsItem. So we emit the signal if rotation changed

View File

@@ -64,6 +64,10 @@ void QetGraphicsItem::setPos(qreal x, qreal y) {
setPos(QPointF(x, y));
}
bool QetGraphicsItem::isHovered() const {
return m_hovered;
}
/**
@brief QetGraphicsItem::state
@return the current state of this item
@@ -155,3 +159,15 @@ void QetGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
event->accept();
}
}
void QetGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
m_hovered = true;
QGraphicsObject::hoverEnterEvent(event);
}
void QetGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
m_hovered = false;
QGraphicsObject::hoverLeaveEvent(event);
}

View File

@@ -42,6 +42,8 @@ class QetGraphicsItem : public QGraphicsObject
{return is_movable_;}
virtual void setMovable (bool movable) { is_movable_ = movable;}
bool isHovered() const;
virtual void editProperty () {}
virtual QString name ()const
{return QString("");}
@@ -54,6 +56,8 @@ class QetGraphicsItem : public QGraphicsObject
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
protected:
bool is_movable_;
@@ -62,6 +66,9 @@ class QetGraphicsItem : public QGraphicsObject
QPointF m_mouse_to_origin_movement;
QET::GraphicsItemState m_state = QET:: GIOK;
private:
bool m_hovered{false};
};
#endif // QETGRAPHICSITEM_H

View File

@@ -23,6 +23,9 @@
#include <QDebug>
#include <QGraphicsItem>
namespace QGIUtility
{
/**
@brief centerToParentBottom
Center the item at the bottom of is parent.
@@ -51,10 +54,10 @@ bool centerToParentBottom(QGraphicsItem *item) {
@param offset
@return true if element is centered else false (element_to_follow have not diagram)
*/
#include "elementtextitemgroup.h"
#include "crossrefitem.h"
bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow, qreal offset) {
if (! element_to_follow -> diagram()) {
bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow, qreal offset)
{
if (! element_to_follow -> diagram())
{
qDebug() << "qgraphicsitemutility centerAtBottomDiagram : Element_to_follow have not diagram";
return false;
}
@@ -81,8 +84,25 @@ bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_f
rot += parent->rotation();
parent = parent->parentItem();
}
if(rot != 0)
if(rot != 0) {
item_to_center->setRotation(item_to_center->rotation() - rot);
}
return true;
}
void drawBoundingRectSelection(QGraphicsItem *item, QPainter *painter)
{
painter->save();
QPen t;
t.setColor(Qt::gray);
t.setStyle(Qt::DashDotLine);
t.setCosmetic(true);
painter->setPen(t);
painter->drawRoundedRect(item->boundingRect(),10,10);
painter->restore();
}
}

View File

@@ -17,11 +17,18 @@
*/
#ifndef QGRAPHICSITEMUTILITY_H
#define QGRAPHICSITEMUTILITY_H
#include <QtGlobal>
class QGraphicsItem;
class Element;
class QPainter;
bool centerToParentBottom (QGraphicsItem *item);
bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow, qreal offset = 0 );
namespace QGIUtility
{
bool centerToParentBottom (QGraphicsItem *item);
bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow, qreal offset = 0 );
void drawBoundingRectSelection(QGraphicsItem *item, QPainter *painter);
}
#endif // QGRAPHICSITEMUTILITY_H