2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2014-01-27 03:00:37 +00:00
|
|
|
Copyright 2006-2013 The QElectroTech Team
|
2007-12-01 10:47:15 +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/>.
|
|
|
|
*/
|
2007-02-24 00:26:04 +00:00
|
|
|
#ifndef ELEMENT_TEXT_ITEM_H
|
2007-04-09 02:56:47 +00:00
|
|
|
#define ELEMENT_TEXT_ITEM_H
|
2007-09-26 22:57:53 +00:00
|
|
|
#include "diagramtextitem.h"
|
2007-04-09 02:56:47 +00:00
|
|
|
#include <QtXml>
|
2007-09-25 23:24:36 +00:00
|
|
|
class Diagram;
|
2010-04-18 17:59:54 +00:00
|
|
|
class Element;
|
2007-04-09 02:56:47 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This class represents a text item attached to an element. Users can change its
|
|
|
|
value, adjust its position (defined relatively to its parent element), and
|
|
|
|
direct it to any angle.
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
2007-09-26 22:57:53 +00:00
|
|
|
class ElementTextItem : public DiagramTextItem {
|
2009-04-04 21:47:07 +00:00
|
|
|
Q_OBJECT
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-04-09 02:56:47 +00:00
|
|
|
public:
|
2010-04-18 17:59:54 +00:00
|
|
|
ElementTextItem(Element * = 0, Diagram * = 0);
|
|
|
|
ElementTextItem(const QString &, Element * = 0, Diagram * = 0);
|
2007-04-12 03:13:13 +00:00
|
|
|
virtual ~ElementTextItem();
|
2007-04-09 02:56:47 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
|
|
|
enum { Type = UserType + 1003 };
|
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
private:
|
2010-04-18 17:59:54 +00:00
|
|
|
Element *parent_element_;
|
2007-04-09 02:56:47 +00:00
|
|
|
bool follow_parent_rotations;
|
2008-01-11 20:01:27 +00:00
|
|
|
QPointF original_position;
|
2009-12-13 22:12:52 +00:00
|
|
|
qreal original_rotation_angle_;
|
2010-04-25 12:12:59 +00:00
|
|
|
bool first_move_;
|
2007-04-09 02:56:47 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-04-09 02:56:47 +00:00
|
|
|
public:
|
|
|
|
virtual int type() const { return Type; }
|
2010-04-18 17:59:54 +00:00
|
|
|
Element *parentElement() const;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// @return the rectangle defining the bounds of this text item
|
2007-12-01 21:19:01 +00:00
|
|
|
virtual QRectF boundingRect() const { return(QGraphicsTextItem::boundingRect().adjusted(0.0, -1.1, 0.0, 0.0)); }
|
2007-04-09 02:56:47 +00:00
|
|
|
bool followParentRotations() const;
|
|
|
|
void setFollowParentRotations(bool);
|
2007-04-12 03:13:13 +00:00
|
|
|
void fromXml(const QDomElement &);
|
|
|
|
QDomElement toXml(QDomDocument &) const;
|
2007-04-09 02:56:47 +00:00
|
|
|
void setPos(const QPointF &);
|
|
|
|
void setPos(qreal, qreal);
|
2010-04-18 17:59:54 +00:00
|
|
|
virtual QPointF pos() const;
|
2008-01-11 20:01:27 +00:00
|
|
|
void setOriginalPos(const QPointF &);
|
|
|
|
QPointF originalPos() const;
|
2009-12-13 22:12:52 +00:00
|
|
|
void setOriginalRotationAngle(const qreal &);
|
|
|
|
qreal originalRotationAngle() const;
|
2012-05-27 15:18:22 +00:00
|
|
|
virtual void setFont(const QFont &);
|
2009-12-13 22:12:52 +00:00
|
|
|
|
|
|
|
public slots:
|
2010-07-18 15:16:51 +00:00
|
|
|
void adjustItemPosition(int = 0);
|
2009-12-13 22:12:52 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void applyRotation(const qreal &);
|
2010-05-08 21:24:43 +00:00
|
|
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
2010-04-24 20:42:20 +00:00
|
|
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
2014-01-11 18:09:04 +00:00
|
|
|
virtual void focusOutEvent(QFocusEvent *e) {DiagramTextItem::focusOutEvent(e); setFlag(QGraphicsItem::ItemIsMovable, false);}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void build();
|
2007-04-09 02:56:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Element text items can optionally be applied a counter-rotation when their
|
|
|
|
parent element is rotated, thus preserving their readability.
|
|
|
|
@return whether this text item follows the rotations of its parent element.
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
|
|
|
inline bool ElementTextItem::followParentRotations() const {
|
|
|
|
return(follow_parent_rotations);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Element text items can optionally be applied a counter-rotation when their
|
|
|
|
parent element is rotated, thus preserving their readability.
|
|
|
|
@param frp whether this text item should follow the rotations of its parent
|
|
|
|
element.
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
|
|
|
inline void ElementTextItem::setFollowParentRotations(bool frp) {
|
|
|
|
follow_parent_rotations = frp;
|
|
|
|
}
|
|
|
|
|
2007-02-24 00:26:04 +00:00
|
|
|
#endif
|