mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-05-03 12:49:59 +02:00
Diagram text item : minor change
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4091 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -22,63 +22,49 @@
|
|||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
* @brief DiagramTextItem::DiagramTextItem
|
||||||
@param parent Le QGraphicsItem parent du champ de texte
|
* @param parent : parent item
|
||||||
@param parent_diagram Le schema auquel appartient le champ de texte
|
*/
|
||||||
*/
|
|
||||||
DiagramTextItem::DiagramTextItem(QGraphicsItem *parent) :
|
DiagramTextItem::DiagramTextItem(QGraphicsItem *parent) :
|
||||||
QGraphicsTextItem(parent),
|
QGraphicsTextItem(parent),
|
||||||
m_mouse_hover(false),
|
m_mouse_hover(false),
|
||||||
previous_text_(),
|
previous_text_(),
|
||||||
rotation_angle_(0.0),
|
rotation_angle_(0.0),
|
||||||
m_first_move (true)
|
m_first_move (true)
|
||||||
{
|
{ build(); }
|
||||||
setAcceptHoverEvents(true);
|
|
||||||
build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
* @brief DiagramTextItem::DiagramTextItem
|
||||||
@param text Le texte affiche par le champ de texte
|
* @param text : text to display
|
||||||
@param parent Le QGraphicsItem parent du champ de texte
|
* @param parent : parent item
|
||||||
@param parent_diagram Le schema auquel appartient le champ de texte
|
*/
|
||||||
*/
|
|
||||||
DiagramTextItem::DiagramTextItem(const QString &text, QGraphicsItem *parent) :
|
DiagramTextItem::DiagramTextItem(const QString &text, QGraphicsItem *parent) :
|
||||||
QGraphicsTextItem(text, parent),
|
QGraphicsTextItem(text, parent),
|
||||||
m_mouse_hover(false),
|
m_mouse_hover(false),
|
||||||
previous_text_(text),
|
previous_text_(text),
|
||||||
rotation_angle_(0.0)
|
rotation_angle_(0.0)
|
||||||
{
|
{ build(); }
|
||||||
build();
|
|
||||||
setAcceptHoverEvents(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Destructeur
|
|
||||||
DiagramTextItem::~DiagramTextItem() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DiagramTextItem::build
|
* @brief DiagramTextItem::build
|
||||||
* Build this item with default value
|
* Build this item with default value
|
||||||
*/
|
*/
|
||||||
void DiagramTextItem::build() {
|
void DiagramTextItem::build()
|
||||||
//set Zvalue at 10 to be upper than the DiagramImageItem
|
{
|
||||||
|
//set Zvalue at 10 to be upper than the DiagramImageItem
|
||||||
setZValue(10);
|
setZValue(10);
|
||||||
|
setAcceptHoverEvents(true);
|
||||||
setDefaultTextColor(Qt::black);
|
setDefaultTextColor(Qt::black);
|
||||||
setFont(QETApp::diagramTextsFont());
|
setFont(QETApp::diagramTextsFont());
|
||||||
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
|
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemSendsGeometryChanges);
|
||||||
setNoEditable(false);
|
setNoEditable(false);
|
||||||
setToolTip(tr("Maintenir ctrl pour un déplacement libre"));
|
setToolTip(tr("Maintenir ctrl pour un déplacement libre"));
|
||||||
#if QT_VERSION >= 0x040600
|
|
||||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
|
||||||
#endif
|
|
||||||
connect(this, SIGNAL(lostFocus()), this, SLOT(setNonFocusable()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return le Diagram auquel ce texte appartient, ou 0 si ce texte n'est
|
* @brief DiagramTextItem::diagram
|
||||||
rattache a aucun schema
|
* @return The diagram of this item or 0 if this text isn't in a diagram
|
||||||
*/
|
*/
|
||||||
Diagram *DiagramTextItem::diagram() const {
|
Diagram *DiagramTextItem::diagram() const {
|
||||||
return(qobject_cast<Diagram *>(scene()));
|
return(qobject_cast<Diagram *>(scene()));
|
||||||
}
|
}
|
||||||
@@ -277,7 +263,7 @@ void DiagramTextItem::focusOutEvent(QFocusEvent *e) {
|
|||||||
|
|
||||||
// autorise de nouveau le deplacement du texte
|
// autorise de nouveau le deplacement du texte
|
||||||
setFlag(QGraphicsItem::ItemIsMovable, true);
|
setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||||
QTimer::singleShot(0, this, SIGNAL(lostFocus()));
|
setFlag(QGraphicsTextItem::ItemIsFocusable, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -364,35 +350,19 @@ void DiagramTextItem::applyRotation(const qreal &angle) {
|
|||||||
setRotation(QET::correctAngle(rotation()+angle));
|
setRotation(QET::correctAngle(rotation()+angle));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rend le champ de texte non focusable
|
|
||||||
void DiagramTextItem::setNonFocusable() {
|
|
||||||
setFlag(QGraphicsTextItem::ItemIsFocusable, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DiagramTextItem::setHtmlText
|
|
||||||
* @param txt
|
|
||||||
*/
|
|
||||||
void DiagramTextItem::setHtmlText(const QString &txt) {
|
|
||||||
setHtml( txt );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Edit the text with HtmlEditor
|
* @brief Edit the text with HtmlEditor
|
||||||
*/
|
*/
|
||||||
void DiagramTextItem::edit() {
|
void DiagramTextItem::edit()
|
||||||
//Open the HtmlEditor
|
{
|
||||||
QWidget *parent = nullptr;
|
QWidget *parent = nullptr;
|
||||||
if (scene() && scene()->views().size())
|
if (scene() && scene()->views().size())
|
||||||
parent = scene()->views().first();
|
parent = scene()->views().first();
|
||||||
qdesigner_internal::RichTextEditorDialog *editor = new qdesigner_internal::RichTextEditorDialog(parent);
|
|
||||||
// connect the in/out
|
qdesigner_internal::RichTextEditorDialog editor(parent);
|
||||||
connect(editor, SIGNAL(applyEditText(const QString &)), this, SLOT(setHtmlText(const QString &)));
|
connect(&editor, &qdesigner_internal::RichTextEditorDialog::applyEditText, [this](QString text) {this->setHtml(text);});
|
||||||
// load the Html txt
|
editor.setText(toHtml());
|
||||||
editor->setText( toHtml() );
|
editor.exec();
|
||||||
// show
|
|
||||||
editor->show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,77 +29,63 @@ class QDomDocument;
|
|||||||
diagram.
|
diagram.
|
||||||
@see QGraphicsItem::GraphicsItemFlags
|
@see QGraphicsItem::GraphicsItemFlags
|
||||||
*/
|
*/
|
||||||
class DiagramTextItem : public QGraphicsTextItem {
|
class DiagramTextItem : public QGraphicsTextItem
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
// constructors, destructor
|
|
||||||
public:
|
public:
|
||||||
DiagramTextItem(QGraphicsItem * = 0);
|
DiagramTextItem(QGraphicsItem * = 0);
|
||||||
DiagramTextItem(const QString &, QGraphicsItem * = 0);
|
DiagramTextItem(const QString &, QGraphicsItem * = 0);
|
||||||
virtual ~DiagramTextItem();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void build();
|
void build();
|
||||||
|
|
||||||
// attributes
|
|
||||||
public:
|
public:
|
||||||
enum { Type = UserType + 1004 };
|
enum { Type = UserType + 1004 };
|
||||||
|
virtual int type() const { return Type; }
|
||||||
// methods
|
|
||||||
public:
|
Diagram *diagram() const;
|
||||||
/**
|
virtual void fromXml(const QDomElement &) = 0;
|
||||||
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a
|
virtual QDomElement toXml(QDomDocument &) const;
|
||||||
DiagramTextItem
|
qreal rotationAngle() const;
|
||||||
@return the QGraphicsItem type
|
void setRotationAngle(const qreal &);
|
||||||
*/
|
void rotateBy(const qreal &);
|
||||||
virtual int type() const { return Type; }
|
void edit();
|
||||||
Diagram *diagram() const;
|
|
||||||
virtual void fromXml(const QDomElement &) = 0;
|
QPointF mapMovementToScene (const QPointF &) const;
|
||||||
virtual QDomElement toXml(QDomDocument &) const;
|
QPointF mapMovementFromScene (const QPointF &) const;
|
||||||
qreal rotationAngle() const;
|
QPointF mapMovementToParent (const QPointF &) const;
|
||||||
void setRotationAngle(const qreal &);
|
QPointF mapMovementFromParent (const QPointF &) const;
|
||||||
void rotateBy(const qreal &);
|
|
||||||
void edit();
|
void setFontSize(int &s);
|
||||||
QPointF mapMovementToScene(const QPointF &) const;
|
void setNoEditable(bool e = true) {no_editable = e;}
|
||||||
QPointF mapMovementFromScene(const QPointF &) const;
|
|
||||||
QPointF mapMovementToParent(const QPointF &) const;
|
|
||||||
QPointF mapMovementFromParent(const QPointF &) const;
|
|
||||||
void setFontSize(int &s);
|
|
||||||
void setNoEditable(bool e = true) {no_editable = e;}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
||||||
virtual void focusInEvent(QFocusEvent *);
|
virtual void focusInEvent(QFocusEvent *);
|
||||||
virtual void focusOutEvent(QFocusEvent *);
|
virtual void focusOutEvent(QFocusEvent *);
|
||||||
|
|
||||||
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event);
|
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event);
|
||||||
virtual void mousePressEvent (QGraphicsSceneMouseEvent *event);
|
virtual void mousePressEvent (QGraphicsSceneMouseEvent *event);
|
||||||
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event);
|
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event);
|
||||||
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
|
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
|
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
|
||||||
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
|
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
|
||||||
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *);
|
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *);
|
||||||
|
|
||||||
|
virtual void applyRotation(const qreal &);
|
||||||
|
|
||||||
virtual void applyRotation(const qreal &);
|
|
||||||
|
|
||||||
bool m_mouse_hover;
|
|
||||||
signals:
|
signals:
|
||||||
/// signal emitted when the text field loses focus
|
/// signal emitted after text was changed
|
||||||
void lostFocus();
|
void diagramTextChanged(DiagramTextItem *, const QString &, const QString &);
|
||||||
/// signal emitted after text was changed
|
|
||||||
void diagramTextChanged(DiagramTextItem *, const QString &, const QString &);
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void setNonFocusable();
|
|
||||||
void setHtmlText(const QString &);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Previous text value
|
bool m_mouse_hover;
|
||||||
QString previous_text_;
|
QString previous_text_;
|
||||||
/// angle of rotation of the text field
|
qreal rotation_angle_;
|
||||||
qreal rotation_angle_;
|
bool no_editable;
|
||||||
bool no_editable;
|
bool m_first_move;
|
||||||
bool m_first_move;
|
QPointF m_mouse_to_origin_movement;
|
||||||
QPointF m_mouse_to_origin_movement;
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user