mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-03-15 22:39:59 +01:00
Dynamic element text item : The font of the dynamic texts can be individually be setted.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5764 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -162,7 +162,21 @@ void DiagramTextItem::setFontSize(int s)
|
||||
|
||||
int DiagramTextItem::fontSize() const
|
||||
{
|
||||
return font().pointSize();
|
||||
return font().pointSize();
|
||||
}
|
||||
|
||||
void DiagramTextItem::setFont(const QFont &font)
|
||||
{
|
||||
if (this->font() == font) {
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
prepareAlignment();
|
||||
QGraphicsTextItem::setFont(font);
|
||||
finishAlignment();
|
||||
emit fontChanged(font);
|
||||
}
|
||||
}
|
||||
|
||||
void DiagramTextItem::setColor(const QColor& color)
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#define DIAGRAM_TEXT_ITEM_H
|
||||
|
||||
#include <QGraphicsTextItem>
|
||||
#include <QFont>
|
||||
|
||||
class Diagram;
|
||||
class QDomElement;
|
||||
@@ -37,6 +38,7 @@ class DiagramTextItem : public QGraphicsTextItem
|
||||
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
||||
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
|
||||
Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText)
|
||||
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
|
||||
|
||||
|
||||
signals:
|
||||
@@ -44,6 +46,7 @@ class DiagramTextItem : public QGraphicsTextItem
|
||||
void colorChanged(QColor color);
|
||||
void alignmentChanged(Qt::Alignment alignment);
|
||||
void textEdited(const QString &old_str, const QString &new_str);
|
||||
void fontChanged(QFont font);
|
||||
|
||||
public:
|
||||
DiagramTextItem(QGraphicsItem * = nullptr);
|
||||
@@ -68,6 +71,8 @@ class DiagramTextItem : public QGraphicsTextItem
|
||||
|
||||
void setFontSize(int s);
|
||||
int fontSize()const;
|
||||
|
||||
void setFont(const QFont &font);
|
||||
|
||||
void setColor(const QColor& color);
|
||||
QColor color() const;
|
||||
|
||||
@@ -92,12 +92,10 @@ QDomElement DynamicElementTextItem::toXml(QDomDocument &dom_doc) const
|
||||
root_element.setAttribute("x", QString::number(pos().x()));
|
||||
root_element.setAttribute("y", QString::number(pos().y()));
|
||||
root_element.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
|
||||
root_element.setAttribute("font_size", font().pointSize());
|
||||
root_element.setAttribute("uuid", m_uuid.toString());
|
||||
root_element.setAttribute("font_family", font().family());
|
||||
root_element.setAttribute("dynamicitemstyle", font().styleName());
|
||||
root_element.setAttribute("frame", m_frame? "true" : "false");
|
||||
root_element.setAttribute("text_width", QString::number(m_text_width));
|
||||
root_element.setAttribute("font", font().toString());
|
||||
|
||||
QMetaEnum me = textFromMetaEnum();
|
||||
root_element.setAttribute("text_from", me.valueToKey(m_text_from));
|
||||
@@ -162,10 +160,21 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
|
||||
}
|
||||
|
||||
QGraphicsTextItem::setRotation(dom_elmt.attribute("rotation", QString::number(0)).toDouble());
|
||||
QFont font_(dom_elmt.attribute("font_family", font().family()),
|
||||
dom_elmt.attribute("font_size", QString::number(9)).toInt());
|
||||
font_.setStyleName(dom_elmt.attribute("dynamicitemstyle", font().styleName()));
|
||||
setFont(font_);
|
||||
|
||||
if (dom_elmt.hasAttribute("font"))
|
||||
{
|
||||
QFont font;
|
||||
font.fromString(dom_elmt.attribute("font"));
|
||||
setFont(font);
|
||||
}
|
||||
else //Retrocompatibility during the 0.7 dev because the font property was added lately. TODO remove this part in futur
|
||||
{
|
||||
QFont font_(dom_elmt.attribute("font_family", font().family()),
|
||||
dom_elmt.attribute("font_size", QString::number(9)).toInt());
|
||||
font_.setStyleName(dom_elmt.attribute("dynamicitemstyle", font().styleName()));
|
||||
setFont(font_);
|
||||
}
|
||||
|
||||
m_uuid = QUuid(dom_elmt.attribute("uuid", QUuid::createUuid().toString()));
|
||||
setFrame(dom_elmt.attribute("frame", "false") == "true"? true : false);
|
||||
setTextWidth(dom_elmt.attribute("text_width", QString::number(-1)).toDouble());
|
||||
@@ -643,13 +652,13 @@ void DynamicElementTextItem::paint(QPainter *painter, const QStyleOptionGraphics
|
||||
if (m_frame)
|
||||
{
|
||||
painter->save();
|
||||
painter->setFont(QETApp::dynamicTextsItemFont(fontSize()));
|
||||
painter->setFont(QETApp::dynamicTextsItemFont(font().pointSize()));
|
||||
|
||||
//Adjust the thickness according to the font size,
|
||||
qreal w=0.3;
|
||||
if(fontSize() >= 5)
|
||||
if(font().pointSize() >= 5)
|
||||
{
|
||||
w = (qreal)fontSize()*0.1;
|
||||
w = font().pointSizeF()*0.1;
|
||||
if(w > 2.5)
|
||||
w = 2.5;
|
||||
}
|
||||
@@ -659,9 +668,9 @@ void DynamicElementTextItem::paint(QPainter *painter, const QStyleOptionGraphics
|
||||
pen.setWidthF(w);
|
||||
painter->setPen(pen);
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
|
||||
//Adjust the rounding of the rectangle according to the size of the font
|
||||
qreal ro = (qreal)fontSize()/3;
|
||||
qreal ro = font().pointSizeF()/3;
|
||||
painter->drawRoundedRect(frameRect(), ro, ro);
|
||||
|
||||
painter->restore();
|
||||
|
||||
Reference in New Issue
Block a user