mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 22:00:35 +01:00
remove the class comment item
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5277 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -1,178 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2006-2017 The QElectroTech Team
|
|
||||||
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/>.
|
|
||||||
*/
|
|
||||||
#include "commentitem.h"
|
|
||||||
#include "element.h"
|
|
||||||
#include "qetapp.h"
|
|
||||||
#include "diagram.h"
|
|
||||||
#include "qgraphicsitemutility.h"
|
|
||||||
#include <QPainter>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CommentItem::CommentItem
|
|
||||||
* @param elmt : the element to display comment,
|
|
||||||
* element is also the parent item of this item
|
|
||||||
*/
|
|
||||||
CommentItem::CommentItem(Element *elmt) :
|
|
||||||
QGraphicsObject (elmt),
|
|
||||||
m_element (elmt),
|
|
||||||
m_text_parent (false)
|
|
||||||
{
|
|
||||||
if (! setTextParent() ) {
|
|
||||||
connect(elmt, SIGNAL(yChanged()), this, SLOT (autoPos()));
|
|
||||||
connect(elmt, SIGNAL(rotationChanged()), this, SLOT (autoPos()));
|
|
||||||
}
|
|
||||||
connect(elmt, SIGNAL(elementInfoChange(DiagramContext,DiagramContext)), this, SLOT (updateLabel()));
|
|
||||||
|
|
||||||
updateLabel();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CommentItem::boundingRect
|
|
||||||
* @return the bounding rect of this item
|
|
||||||
*/
|
|
||||||
QRectF CommentItem::boundingRect() const {
|
|
||||||
return m_bounding_rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CommentItem::autoPos
|
|
||||||
* Adjust the position of this item.
|
|
||||||
*/
|
|
||||||
void CommentItem::autoPos()
|
|
||||||
{
|
|
||||||
if (m_text_parent)
|
|
||||||
centerToParentBottom(this);
|
|
||||||
else if (m_element->diagram())
|
|
||||||
{
|
|
||||||
XRefProperties xrp = m_element->diagram()->project()->defaultXRefProperties(m_element->kindInformations()["type"].toString());
|
|
||||||
centerToBottomDiagram(this, m_element, xrp.offset());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CommentItem::paint
|
|
||||||
* Paint this item
|
|
||||||
* @param painter
|
|
||||||
* @param option
|
|
||||||
* @param widget
|
|
||||||
*/
|
|
||||||
void CommentItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
|
|
||||||
Q_UNUSED(option); Q_UNUSED(widget);
|
|
||||||
m_picture.play(painter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CommentItem::mouseDoubleClickEvent
|
|
||||||
* @param event
|
|
||||||
*/
|
|
||||||
void CommentItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
|
|
||||||
event -> accept();
|
|
||||||
m_element -> editProperty();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CommentItem::setTextParent
|
|
||||||
* Set text tagged "label" of element has parent.
|
|
||||||
* @return true if text has been set has parent.
|
|
||||||
* else return false, the element is the parent of this comment item
|
|
||||||
*/
|
|
||||||
bool CommentItem::setTextParent() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CommentItem::updateLabel
|
|
||||||
* update the content of this item
|
|
||||||
* (draw this item in a QPicture)
|
|
||||||
*/
|
|
||||||
void CommentItem::updateLabel()
|
|
||||||
{
|
|
||||||
QString comment = m_element -> elementInformations()["comment"]. toString();
|
|
||||||
|
|
||||||
QString location = m_element -> elementInformations()["location"].toString();
|
|
||||||
|
|
||||||
prepareGeometryChange();
|
|
||||||
m_bounding_rect = QRectF();
|
|
||||||
|
|
||||||
QPainter painter_;
|
|
||||||
painter_.begin(&m_picture);
|
|
||||||
|
|
||||||
if (comment == m_comment && !m_text_parent && location == m_location)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (comment != m_comment)
|
|
||||||
{
|
|
||||||
m_comment = comment;
|
|
||||||
addInfo(painter_, "comment");
|
|
||||||
}
|
|
||||||
else if (comment == m_comment)
|
|
||||||
addInfo(painter_, "comment");
|
|
||||||
|
|
||||||
if (location != m_location)
|
|
||||||
{
|
|
||||||
m_location = location;
|
|
||||||
addInfo(painter_, "location");
|
|
||||||
}
|
|
||||||
else if (location == m_location){
|
|
||||||
addInfo(painter_, "location");
|
|
||||||
}
|
|
||||||
painter_.end();
|
|
||||||
|
|
||||||
autoPos();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CommentItem::addInfo
|
|
||||||
* @param painter
|
|
||||||
* @param type e.g. comment, location
|
|
||||||
* Draw Info to item text.
|
|
||||||
* (draw this item in a QPicture)
|
|
||||||
*/
|
|
||||||
void CommentItem::addInfo(QPainter &painter, QString type)
|
|
||||||
{
|
|
||||||
QString text = autonum::AssignVariables::formulaToLabel(m_element -> elementInformations()[type].toString(), m_element->rSequenceStruct(), m_element->diagram(), m_element);
|
|
||||||
bool must_show = m_element -> elementInformations().keyMustShow(type);
|
|
||||||
|
|
||||||
if (!text.isEmpty() && must_show)
|
|
||||||
{
|
|
||||||
painter.save();
|
|
||||||
painter.setFont (QETApp::diagramTextsFont(6));
|
|
||||||
|
|
||||||
QPen pen(Qt::black);
|
|
||||||
pen.setWidthF (0.5);
|
|
||||||
|
|
||||||
painter.setPen (pen);
|
|
||||||
|
|
||||||
QRectF r, text_bounding;
|
|
||||||
qreal center = boundingRect().center().x();
|
|
||||||
|
|
||||||
r = QRectF(QPointF(center - 35, boundingRect().bottom()),
|
|
||||||
QPointF(center + 35, boundingRect().bottom() + 1));
|
|
||||||
|
|
||||||
text_bounding = painter.boundingRect(r, Qt::TextWordWrap | Qt::AlignHCenter, text);
|
|
||||||
painter.drawText(text_bounding, Qt::TextWordWrap | Qt::AlignHCenter, text);
|
|
||||||
|
|
||||||
text_bounding.adjust(-1,0,1,0); //adjust only for better visual
|
|
||||||
|
|
||||||
m_shape_path.addRect(text_bounding);
|
|
||||||
prepareGeometryChange();
|
|
||||||
m_bounding_rect = m_bounding_rect.united(text_bounding);
|
|
||||||
if (type == "comment") painter.drawRoundedRect(text_bounding, 2, 2);
|
|
||||||
painter.restore();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2006-2017 The QElectroTech Team
|
|
||||||
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/>.
|
|
||||||
*/
|
|
||||||
#ifndef COMMENTITEM_H
|
|
||||||
#define COMMENTITEM_H
|
|
||||||
|
|
||||||
#include <QGraphicsObject>
|
|
||||||
#include <QPicture>
|
|
||||||
|
|
||||||
class Element;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The CommentItem class
|
|
||||||
* This item display the comment of an element
|
|
||||||
* at the bottom of element diagram in a rounded rect
|
|
||||||
*/
|
|
||||||
class CommentItem : public QGraphicsObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit CommentItem(Element *elmt);
|
|
||||||
|
|
||||||
QRectF boundingRect() const override;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void autoPos();
|
|
||||||
void updateLabel();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
|
||||||
void mouseDoubleClickEvent (QGraphicsSceneMouseEvent * event ) override;
|
|
||||||
virtual bool setTextParent ();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void addInfo(QPainter &, QString);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Element *m_element;
|
|
||||||
QPicture m_picture;
|
|
||||||
QRectF m_bounding_rect;
|
|
||||||
QString m_comment;
|
|
||||||
QString m_location;
|
|
||||||
QPainterPath m_shape_path;
|
|
||||||
bool m_text_parent;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // COMMENTITEM_H
|
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "simpleelement.h"
|
#include "simpleelement.h"
|
||||||
#include "commentitem.h"
|
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,9 +26,7 @@
|
|||||||
* @param state
|
* @param state
|
||||||
*/
|
*/
|
||||||
SimpleElement::SimpleElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
|
SimpleElement::SimpleElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
|
||||||
CustomElement(location, qgi, state),
|
CustomElement(location, qgi, state)
|
||||||
m_comment_item (nullptr),
|
|
||||||
m_location_item (nullptr)
|
|
||||||
{
|
{
|
||||||
m_link_type = Simple;
|
m_link_type = Simple;
|
||||||
}
|
}
|
||||||
@@ -37,9 +34,7 @@ SimpleElement::SimpleElement(const ElementsLocation &location, QGraphicsItem *qg
|
|||||||
/**
|
/**
|
||||||
* @brief SimpleElement::~SimpleElement
|
* @brief SimpleElement::~SimpleElement
|
||||||
*/
|
*/
|
||||||
SimpleElement::~SimpleElement() {
|
SimpleElement::~SimpleElement() {}
|
||||||
if (m_comment_item) delete m_comment_item;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SimpleElement::initLink
|
* @brief SimpleElement::initLink
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include "customelement.h"
|
#include "customelement.h"
|
||||||
|
|
||||||
class CommentItem;
|
|
||||||
class QETProject;
|
class QETProject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,10 +35,6 @@ class SimpleElement : public CustomElement {
|
|||||||
~SimpleElement() override;
|
~SimpleElement() override;
|
||||||
|
|
||||||
void initLink(QETProject *project) override;
|
void initLink(QETProject *project) override;
|
||||||
|
|
||||||
private:
|
|
||||||
CommentItem *m_comment_item;
|
|
||||||
CommentItem *m_location_item;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SIMPLEELEMENT_H
|
#endif // SIMPLEELEMENT_H
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "terminalelement.h"
|
#include "terminalelement.h"
|
||||||
#include "commentitem.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TerminalElement::TerminalElement
|
* @brief TerminalElement::TerminalElement
|
||||||
@@ -27,16 +26,10 @@
|
|||||||
* @param state int used to know if the creation of element have error
|
* @param state int used to know if the creation of element have error
|
||||||
*/
|
*/
|
||||||
TerminalElement::TerminalElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
|
TerminalElement::TerminalElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
|
||||||
CustomElement(location, qgi, state),
|
CustomElement(location, qgi, state)
|
||||||
m_comment_item (nullptr),
|
{m_link_type = Terminale;}
|
||||||
m_location_item (nullptr)
|
|
||||||
{
|
|
||||||
m_link_type = Terminale;
|
|
||||||
}
|
|
||||||
|
|
||||||
TerminalElement::~TerminalElement() {
|
TerminalElement::~TerminalElement() {}
|
||||||
if (m_comment_item) delete m_comment_item;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TerminalElement::initLink
|
* @brief TerminalElement::initLink
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include "customelement.h"
|
#include "customelement.h"
|
||||||
|
|
||||||
class CommentItem;
|
|
||||||
class QETProject;
|
class QETProject;
|
||||||
|
|
||||||
class TerminalElement : public CustomElement
|
class TerminalElement : public CustomElement
|
||||||
@@ -30,10 +29,6 @@ class TerminalElement : public CustomElement
|
|||||||
TerminalElement(const ElementsLocation &, QGraphicsItem * = nullptr, int * = nullptr);
|
TerminalElement(const ElementsLocation &, QGraphicsItem * = nullptr, int * = nullptr);
|
||||||
~TerminalElement() override;
|
~TerminalElement() override;
|
||||||
void initLink(QETProject *project) override;
|
void initLink(QETProject *project) override;
|
||||||
|
|
||||||
private:
|
|
||||||
CommentItem *m_comment_item;
|
|
||||||
CommentItem *m_location_item;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TERMINALELEMENT_H
|
#endif // TERMINALELEMENT_H
|
||||||
|
|||||||
Reference in New Issue
Block a user