2014-03-13 14:59:40 +00:00
|
|
|
/*
|
2025-01-04 13:37:40 +01:00
|
|
|
Copyright 2006-2025 The QElectroTech Team
|
2014-03-13 14:59:40 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2014-03-03 17:31:45 +00:00
|
|
|
#ifndef CROSSREFITEM_H
|
|
|
|
#define CROSSREFITEM_H
|
|
|
|
|
2020-12-09 15:28:43 +01:00
|
|
|
#include "../properties/xrefproperties.h"
|
|
|
|
|
2014-07-21 20:44:32 +00:00
|
|
|
#include <QGraphicsObject>
|
2020-06-10 20:46:35 +02:00
|
|
|
#include <QMultiMap>
|
2020-12-09 15:28:43 +01:00
|
|
|
#include <QPicture>
|
2014-07-21 20:44:32 +00:00
|
|
|
|
|
|
|
class Element;
|
2018-01-19 12:17:20 +00:00
|
|
|
class DynamicElementTextItem;
|
|
|
|
class ElementTextItemGroup;
|
2014-03-03 17:31:45 +00:00
|
|
|
|
2014-03-13 14:59:40 +00:00
|
|
|
/**
|
2020-08-12 21:53:02 +02:00
|
|
|
@brief The CrossRefItem class
|
|
|
|
This clas provide an item, for show the cross reference,
|
|
|
|
like the contacts linked to a coil.
|
2022-12-04 08:21:12 -05:00
|
|
|
The item setpos automatically when parent move.
|
2020-08-12 21:53:02 +02:00
|
|
|
All slave displayed in cross ref will be updated
|
|
|
|
when folio position change in the project.
|
2022-12-04 08:21:12 -05:00
|
|
|
It's the responsibility of the master element
|
|
|
|
to inform displayed slave are moved,
|
2020-08-12 21:53:02 +02:00
|
|
|
by calling the slot updateLabel
|
|
|
|
By default master element is the parent graphics item of this Xref,
|
|
|
|
but if the Xref must be snap to the label of master,
|
|
|
|
the label become the parent of this Xref.
|
|
|
|
This behavior can be changed at anytime by calling setProperties.
|
|
|
|
*/
|
2014-04-12 01:26:19 +00:00
|
|
|
class CrossRefItem : public QGraphicsObject
|
2014-03-03 17:31:45 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2016-11-16 16:01:53 +00:00
|
|
|
//Methods
|
2014-03-03 17:31:45 +00:00
|
|
|
public:
|
2016-11-16 16:01:53 +00:00
|
|
|
explicit CrossRefItem(Element *elmt);
|
2020-09-07 22:03:40 +02:00
|
|
|
explicit CrossRefItem(
|
|
|
|
Element *elmt, DynamicElementTextItem *text);
|
|
|
|
explicit CrossRefItem(
|
|
|
|
Element *elmt, ElementTextItemGroup *group);
|
2017-08-05 02:10:01 +00:00
|
|
|
~CrossRefItem() override;
|
2018-01-19 12:17:20 +00:00
|
|
|
private:
|
|
|
|
void init();
|
|
|
|
void setUpConnection();
|
|
|
|
|
|
|
|
public:
|
2016-11-16 16:01:53 +00:00
|
|
|
enum { Type = UserType + 1009 };
|
2017-08-05 02:10:01 +00:00
|
|
|
int type() const override { return Type; }
|
2016-11-16 16:01:53 +00:00
|
|
|
|
2020-08-12 21:53:02 +02:00
|
|
|
/**
|
|
|
|
@brief The CONTACTS enum
|
|
|
|
*/
|
2016-11-16 16:01:53 +00:00
|
|
|
enum CONTACTS {
|
2020-08-12 21:53:02 +02:00
|
|
|
NO = 1,
|
|
|
|
NC = 2,
|
|
|
|
NOC = 3,
|
|
|
|
SW = 4,
|
|
|
|
Power = 8,
|
|
|
|
DelayOn = 16,
|
|
|
|
DelayOff = 32,
|
|
|
|
DelayOnOff = 64,
|
2022-06-22 18:02:13 +02:00
|
|
|
Delay = 112,
|
|
|
|
Other = 128
|
2016-11-16 16:01:53 +00:00
|
|
|
};
|
|
|
|
|
2020-08-12 21:53:02 +02:00
|
|
|
QRectF boundingRect() const override;
|
|
|
|
QPainterPath shape() const override;
|
|
|
|
QString elementPositionText(
|
|
|
|
const Element *elmt,
|
|
|
|
const bool &add_prefix = false) const;
|
2014-03-03 17:31:45 +00:00
|
|
|
|
|
|
|
public slots:
|
2020-08-12 21:53:02 +02:00
|
|
|
void updateProperties();
|
|
|
|
void updateLabel();
|
|
|
|
void autoPos();
|
2014-03-03 17:31:45 +00:00
|
|
|
|
|
|
|
protected:
|
2018-01-19 12:17:20 +00:00
|
|
|
bool sceneEvent(QEvent *event) override;
|
2020-08-12 21:53:02 +02:00
|
|
|
void paint(QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *option,
|
|
|
|
QWidget *widget) override;
|
|
|
|
void mouseDoubleClickEvent (
|
|
|
|
QGraphicsSceneMouseEvent * event ) override;
|
2017-08-05 02:10:01 +00:00
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
|
|
|
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
|
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
2014-03-03 17:31:45 +00:00
|
|
|
|
|
|
|
private:
|
2018-01-19 12:17:20 +00:00
|
|
|
void linkedChanged();
|
2020-08-12 21:53:02 +02:00
|
|
|
void buildHeaderContact();
|
|
|
|
void setUpCrossBoundingRect(QPainter &painter);
|
|
|
|
void drawAsCross(QPainter &painter);
|
|
|
|
void drawAsContacts(QPainter &painter);
|
|
|
|
QRectF drawContact(QPainter &painter, int flags, Element *elmt);
|
|
|
|
void fillCrossRef(QPainter &painter);
|
|
|
|
void AddExtraInfo(QPainter &painter, const QString&);
|
2016-11-17 14:42:07 +00:00
|
|
|
QList<Element *> NOElements() const;
|
|
|
|
QList<Element *> NCElements() const;
|
2016-11-16 16:01:53 +00:00
|
|
|
|
|
|
|
//Attributes
|
2014-03-03 17:31:45 +00:00
|
|
|
private:
|
2020-08-12 21:53:02 +02:00
|
|
|
Element *m_element; //element to display the cross reference
|
|
|
|
QRectF m_bounding_rect;
|
|
|
|
QPicture m_drawing, m_hdr_no_ctc, m_hdr_nc_ctc;
|
|
|
|
QPainterPath m_shape_path;
|
2016-11-16 16:01:53 +00:00
|
|
|
XRefProperties m_properties;
|
2020-08-12 21:53:02 +02:00
|
|
|
int m_drawed_contacts;
|
2020-06-10 20:46:35 +02:00
|
|
|
QMultiMap <Element *, QRectF> m_hovered_contacts_map;
|
2016-11-16 18:37:31 +00:00
|
|
|
Element *m_hovered_contact = nullptr;
|
2018-01-19 12:17:20 +00:00
|
|
|
DynamicElementTextItem *m_text = nullptr;
|
|
|
|
ElementTextItemGroup *m_group = nullptr;
|
|
|
|
QList <QMetaObject::Connection> m_slave_connection;
|
|
|
|
QList <QMetaObject::Connection> m_update_connection;
|
2014-03-03 17:31:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CROSSREFITEM_H
|
2014-05-13 19:28:11 +00:00
|
|
|
|