mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-04-30 18:09:59 +02:00
Element text item group can now be framed.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5410 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -184,6 +184,30 @@ Qt::Alignment DiagramTextItem::alignment() const
|
||||
return m_alignment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DiagramTextItem::frameRect
|
||||
* @return the rect used to draw a frame around this text
|
||||
*/
|
||||
QRectF DiagramTextItem::frameRect() const
|
||||
{
|
||||
//Get the bounding rectangle of the text
|
||||
QSizeF size = document()->size();
|
||||
size.setWidth(document()->idealWidth());
|
||||
//Remove the margin. Size is exactly the bounding rect of the text
|
||||
size.rheight() -= document()->documentMargin()*2;
|
||||
size.rwidth() -= document()->documentMargin()*2;
|
||||
//Add a little margin only for a better visual;
|
||||
size.rheight() += 2;
|
||||
size.rwidth() += 2;
|
||||
|
||||
//The pos of the rect
|
||||
QPointF pos = boundingRect().center();
|
||||
pos.rx() -= size.width()/2;
|
||||
pos.ry() -= size.height()/2;
|
||||
|
||||
return QRectF(pos, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DiagramTextItem::paint
|
||||
* Draw this text field. This method draw the text by calling QGraphicsTextItem::paint.
|
||||
|
||||
@@ -76,6 +76,8 @@ class DiagramTextItem : public QGraphicsTextItem
|
||||
void setAlignment(const Qt::Alignment &alignment);
|
||||
Qt::Alignment alignment() const;
|
||||
bool m_block_alignment = false;
|
||||
|
||||
QRectF frameRect() const;
|
||||
|
||||
protected:
|
||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
|
||||
|
||||
@@ -635,7 +635,6 @@ void DynamicElementTextItem::paint(QPainter *painter, const QStyleOptionGraphics
|
||||
if (m_frame)
|
||||
{
|
||||
painter->save();
|
||||
|
||||
painter->setFont(QETApp::diagramTextsFont(fontSize()));
|
||||
|
||||
//Adjust the thickness according to the font size,
|
||||
@@ -653,24 +652,9 @@ void DynamicElementTextItem::paint(QPainter *painter, const QStyleOptionGraphics
|
||||
painter->setPen(pen);
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
//Get the bounding rectangle of the text
|
||||
QSizeF size = document()->size();
|
||||
size.setWidth(document()->idealWidth());
|
||||
//Remove the margin. Size is exactly the bounding rect of the text
|
||||
size.rheight() -= document()->documentMargin()*2;
|
||||
size.rwidth() -= document()->documentMargin()*2;
|
||||
//Add a little margin only for a better visual;
|
||||
size.rheight() += 2;
|
||||
size.rwidth() += 2;
|
||||
|
||||
//The pos of the rect
|
||||
QPointF pos = boundingRect().center();
|
||||
pos.rx() -= size.width()/2;
|
||||
pos.ry() -= size.height()/2;
|
||||
|
||||
//Adjust the rounding of the rectangle according to the size of the font
|
||||
qreal ro = (qreal)fontSize()/3;
|
||||
painter->drawRoundedRect(QRectF(pos, size), ro, ro);
|
||||
painter->drawRoundedRect(frameRect(), ro, ro);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
@@ -298,6 +298,17 @@ void ElementTextItemGroup::setHoldToBottomPage(bool hold)
|
||||
emit holdToBottomPageChanged(hold);
|
||||
}
|
||||
|
||||
void ElementTextItemGroup::setFrame(const bool frame)
|
||||
{
|
||||
m_frame = frame;
|
||||
update();
|
||||
emit frameChanged(m_frame);
|
||||
}
|
||||
|
||||
bool ElementTextItemGroup::frame() const {
|
||||
return m_frame;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementTextItemGroup::texts
|
||||
* @return Every texts in this group
|
||||
@@ -356,6 +367,7 @@ QDomElement ElementTextItemGroup::toXml(QDomDocument &dom_document) const
|
||||
|
||||
dom_element.setAttribute("rotation", this->rotation());
|
||||
dom_element.setAttribute("vertical_adjustment", m_vertical_adjustment);
|
||||
dom_element.setAttribute("frame", m_frame? "true" : "false");
|
||||
|
||||
dom_element.setAttribute("hold_to_bottom_page", m_hold_to_bottom_of_page == true ? "true" : "false");
|
||||
|
||||
@@ -392,6 +404,7 @@ void ElementTextItemGroup::fromXml(QDomElement &dom_element)
|
||||
|
||||
setRotation(dom_element.attribute("rotation", QString::number(0)).toDouble());
|
||||
setVerticalAdjustment(dom_element.attribute("vertical_adjustment").toInt());
|
||||
setFrame(dom_element.attribute("frame", "false") == "true"? true : false);
|
||||
|
||||
QString hold = dom_element.attribute("hold_to_bottom_page", "false");
|
||||
setHoldToBottomPage(hold == "true" ? true : false);
|
||||
@@ -437,6 +450,36 @@ void ElementTextItemGroup::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
if(m_frame)
|
||||
{
|
||||
int font_size = 1;
|
||||
QRectF rect;
|
||||
for(DynamicElementTextItem *deti : this->texts())
|
||||
{
|
||||
font_size = std::max(font_size, deti->fontSize());
|
||||
rect = rect.united(mapFromItem(deti, deti->frameRect()).boundingRect());
|
||||
}
|
||||
|
||||
//Adjust the thickness according to the font size
|
||||
qreal w=0.3;
|
||||
if (font_size >= 5)
|
||||
{
|
||||
w = (qreal)font_size*0.1;
|
||||
if(w > 2.5)
|
||||
w = 2.5;
|
||||
}
|
||||
|
||||
painter->save();
|
||||
QPen pen;
|
||||
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)font_size/3;
|
||||
painter->drawRoundedRect(rect, ro, ro);
|
||||
painter->restore();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,6 +42,7 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
|
||||
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
|
||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||
Q_PROPERTY(bool holdToBottomPage READ holdToBottomPage WRITE setHoldToBottomPage NOTIFY holdToBottomPageChanged)
|
||||
Q_PROPERTY(bool frame READ frame WRITE setFrame NOTIFY frameChanged)
|
||||
|
||||
public:
|
||||
signals:
|
||||
@@ -52,6 +53,7 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
|
||||
void holdToBottomPageChanged(bool);
|
||||
void xChanged();
|
||||
void yChanged();
|
||||
void frameChanged(bool frame);
|
||||
|
||||
public:
|
||||
ElementTextItemGroup(const QString &name, Element *parent);
|
||||
@@ -69,6 +71,8 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
|
||||
QString name() const {return m_name;}
|
||||
void setHoldToBottomPage(bool hold);
|
||||
bool holdToBottomPage() const {return m_hold_to_bottom_of_page;}
|
||||
void setFrame(const bool frame);
|
||||
bool frame() const;
|
||||
QList<DynamicElementTextItem *> texts() const;
|
||||
Diagram *diagram() const;
|
||||
Element *parentElement() const;
|
||||
@@ -102,7 +106,8 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
|
||||
QString m_name;
|
||||
bool m_first_move = true,
|
||||
m_hold_to_bottom_of_page = false,
|
||||
m_block_alignment_update = false;
|
||||
m_block_alignment_update = false,
|
||||
m_frame = false;
|
||||
QPointF m_initial_position;
|
||||
int m_vertical_adjustment = 0;
|
||||
CrossRefItem *m_Xref_item = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user