mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01: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;
|
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
|
* @brief DiagramTextItem::paint
|
||||||
* Draw this text field. This method draw the text by calling QGraphicsTextItem::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);
|
void setAlignment(const Qt::Alignment &alignment);
|
||||||
Qt::Alignment alignment() const;
|
Qt::Alignment alignment() const;
|
||||||
bool m_block_alignment = false;
|
bool m_block_alignment = false;
|
||||||
|
|
||||||
|
QRectF frameRect() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
|
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
|
||||||
|
|||||||
@@ -635,7 +635,6 @@ void DynamicElementTextItem::paint(QPainter *painter, const QStyleOptionGraphics
|
|||||||
if (m_frame)
|
if (m_frame)
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
painter->setFont(QETApp::diagramTextsFont(fontSize()));
|
painter->setFont(QETApp::diagramTextsFont(fontSize()));
|
||||||
|
|
||||||
//Adjust the thickness according to the font size,
|
//Adjust the thickness according to the font size,
|
||||||
@@ -653,24 +652,9 @@ void DynamicElementTextItem::paint(QPainter *painter, const QStyleOptionGraphics
|
|||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
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
|
//Adjust the rounding of the rectangle according to the size of the font
|
||||||
qreal ro = (qreal)fontSize()/3;
|
qreal ro = (qreal)fontSize()/3;
|
||||||
painter->drawRoundedRect(QRectF(pos, size), ro, ro);
|
painter->drawRoundedRect(frameRect(), ro, ro);
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -298,6 +298,17 @@ void ElementTextItemGroup::setHoldToBottomPage(bool hold)
|
|||||||
emit holdToBottomPageChanged(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
|
* @brief ElementTextItemGroup::texts
|
||||||
* @return Every texts in this group
|
* @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("rotation", this->rotation());
|
||||||
dom_element.setAttribute("vertical_adjustment", m_vertical_adjustment);
|
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");
|
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());
|
setRotation(dom_element.attribute("rotation", QString::number(0)).toDouble());
|
||||||
setVerticalAdjustment(dom_element.attribute("vertical_adjustment").toInt());
|
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");
|
QString hold = dom_element.attribute("hold_to_bottom_page", "false");
|
||||||
setHoldToBottomPage(hold == "true" ? true : false);
|
setHoldToBottomPage(hold == "true" ? true : false);
|
||||||
@@ -437,6 +450,36 @@ void ElementTextItemGroup::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
|||||||
|
|
||||||
painter->restore();
|
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(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
|
||||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||||
Q_PROPERTY(bool holdToBottomPage READ holdToBottomPage WRITE setHoldToBottomPage NOTIFY holdToBottomPageChanged)
|
Q_PROPERTY(bool holdToBottomPage READ holdToBottomPage WRITE setHoldToBottomPage NOTIFY holdToBottomPageChanged)
|
||||||
|
Q_PROPERTY(bool frame READ frame WRITE setFrame NOTIFY frameChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
signals:
|
signals:
|
||||||
@@ -52,6 +53,7 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
|
|||||||
void holdToBottomPageChanged(bool);
|
void holdToBottomPageChanged(bool);
|
||||||
void xChanged();
|
void xChanged();
|
||||||
void yChanged();
|
void yChanged();
|
||||||
|
void frameChanged(bool frame);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ElementTextItemGroup(const QString &name, Element *parent);
|
ElementTextItemGroup(const QString &name, Element *parent);
|
||||||
@@ -69,6 +71,8 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
|
|||||||
QString name() const {return m_name;}
|
QString name() const {return m_name;}
|
||||||
void setHoldToBottomPage(bool hold);
|
void setHoldToBottomPage(bool hold);
|
||||||
bool holdToBottomPage() const {return m_hold_to_bottom_of_page;}
|
bool holdToBottomPage() const {return m_hold_to_bottom_of_page;}
|
||||||
|
void setFrame(const bool frame);
|
||||||
|
bool frame() const;
|
||||||
QList<DynamicElementTextItem *> texts() const;
|
QList<DynamicElementTextItem *> texts() const;
|
||||||
Diagram *diagram() const;
|
Diagram *diagram() const;
|
||||||
Element *parentElement() const;
|
Element *parentElement() const;
|
||||||
@@ -102,7 +106,8 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
|
|||||||
QString m_name;
|
QString m_name;
|
||||||
bool m_first_move = true,
|
bool m_first_move = true,
|
||||||
m_hold_to_bottom_of_page = false,
|
m_hold_to_bottom_of_page = false,
|
||||||
m_block_alignment_update = false;
|
m_block_alignment_update = false,
|
||||||
|
m_frame = false;
|
||||||
QPointF m_initial_position;
|
QPointF m_initial_position;
|
||||||
int m_vertical_adjustment = 0;
|
int m_vertical_adjustment = 0;
|
||||||
CrossRefItem *m_Xref_item = nullptr;
|
CrossRefItem *m_Xref_item = nullptr;
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ int x_grp_row = 1;
|
|||||||
int y_grp_row = 2;
|
int y_grp_row = 2;
|
||||||
int rot_grp_row = 3;
|
int rot_grp_row = 3;
|
||||||
int adjust_grp_row = 4;
|
int adjust_grp_row = 4;
|
||||||
int hold_to_bottom_grp_row = 5;
|
int frame_grp_row = 5;
|
||||||
|
int hold_to_bottom_grp_row = 6;
|
||||||
|
|
||||||
DynamicElementTextModel::DynamicElementTextModel(Element *element, QObject *parent) :
|
DynamicElementTextModel::DynamicElementTextModel(Element *element, QObject *parent) :
|
||||||
QStandardItemModel(parent),
|
QStandardItemModel(parent),
|
||||||
@@ -566,19 +567,23 @@ QUndoCommand *DynamicElementTextModel::undoForEditedGroup(ElementTextItemGroup *
|
|||||||
else if((alignment == tr("Centre")) && (group->alignment() != Qt::AlignVCenter))
|
else if((alignment == tr("Centre")) && (group->alignment() != Qt::AlignVCenter))
|
||||||
new QPropertyUndoCommand(group, "alignment", QVariant(group->alignment()), QVariant(Qt::AlignVCenter), undo);
|
new QPropertyUndoCommand(group, "alignment", QVariant(group->alignment()), QVariant(Qt::AlignVCenter), undo);
|
||||||
|
|
||||||
QPointF pos(group_qsi->child(x_grp_row,1)->data(Qt::EditRole).toDouble(),
|
|
||||||
group_qsi->child(y_grp_row,1)->data(Qt::EditRole).toDouble());
|
|
||||||
if(group->pos() != pos)
|
|
||||||
{
|
|
||||||
QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(group, "pos", QVariant(group->pos()), QVariant(pos), undo);
|
|
||||||
qpuc->setAnimated(true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
qreal rotation = group_qsi->child(rot_grp_row,1)->data(Qt::EditRole).toDouble();
|
if (group_qsi->child(hold_to_bottom_grp_row, 1)->checkState() == Qt::Unchecked)
|
||||||
if(group->rotation() != rotation)
|
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(group, "rotation", QVariant(group->rotation()), QVariant(rotation), undo);
|
QPointF pos(group_qsi->child(x_grp_row,1)->data(Qt::EditRole).toDouble(),
|
||||||
qpuc->setAnimated(true, false);
|
group_qsi->child(y_grp_row,1)->data(Qt::EditRole).toDouble());
|
||||||
|
if(group->pos() != pos)
|
||||||
|
{
|
||||||
|
QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(group, "pos", QVariant(group->pos()), QVariant(pos), undo);
|
||||||
|
qpuc->setAnimated(true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal rotation = group_qsi->child(rot_grp_row,1)->data(Qt::EditRole).toDouble();
|
||||||
|
if(group->rotation() != rotation)
|
||||||
|
{
|
||||||
|
QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(group, "rotation", QVariant(group->rotation()), QVariant(rotation), undo);
|
||||||
|
qpuc->setAnimated(true, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int v_adjustment = group_qsi->child(adjust_grp_row,1)->data(Qt::EditRole).toInt();
|
int v_adjustment = group_qsi->child(adjust_grp_row,1)->data(Qt::EditRole).toInt();
|
||||||
@@ -592,8 +597,11 @@ QUndoCommand *DynamicElementTextModel::undoForEditedGroup(ElementTextItemGroup *
|
|||||||
bool hold_to_bottom = group_qsi->child(hold_to_bottom_grp_row, 1)->checkState() == Qt::Checked? true : false;
|
bool hold_to_bottom = group_qsi->child(hold_to_bottom_grp_row, 1)->checkState() == Qt::Checked? true : false;
|
||||||
if(group->holdToBottomPage() != hold_to_bottom)
|
if(group->holdToBottomPage() != hold_to_bottom)
|
||||||
new QPropertyUndoCommand(group, "holdToBottomPage", QVariant(group->holdToBottomPage()), QVariant(hold_to_bottom), undo);
|
new QPropertyUndoCommand(group, "holdToBottomPage", QVariant(group->holdToBottomPage()), QVariant(hold_to_bottom), undo);
|
||||||
|
|
||||||
|
|
||||||
|
bool frame_ = group_qsi->child(frame_grp_row, 1)->checkState() == Qt::Checked? true : false;
|
||||||
|
if(group->frame() != frame_)
|
||||||
|
new QPropertyUndoCommand(group, "frame", QVariant(group->frame()), QVariant(frame_), undo);
|
||||||
|
|
||||||
return undo;
|
return undo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -689,6 +697,20 @@ void DynamicElementTextModel::addGroup(ElementTextItemGroup *group)
|
|||||||
qsi_list << v_adj << v_adj_a;
|
qsi_list << v_adj << v_adj_a;
|
||||||
grp->appendRow(qsi_list);
|
grp->appendRow(qsi_list);
|
||||||
|
|
||||||
|
//Frame
|
||||||
|
QStandardItem *frame_ = new QStandardItem(tr("Cadre"));
|
||||||
|
frame_->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||||
|
|
||||||
|
QStandardItem *frame_a = new QStandardItem;
|
||||||
|
frame_a->setCheckable(true);
|
||||||
|
frame_a->setCheckState(group->frame()? Qt::Checked : Qt::Unchecked);
|
||||||
|
frame_a->setData(DynamicElementTextModel::grpFrame, Qt::UserRole+1);
|
||||||
|
frame_a->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
|
||||||
|
qsi_list.clear();
|
||||||
|
qsi_list << frame_ << frame_a;
|
||||||
|
grp->appendRow(qsi_list);
|
||||||
|
|
||||||
|
|
||||||
//Hold to the bottom of the page
|
//Hold to the bottom of the page
|
||||||
QStandardItem *hold_bottom = new QStandardItem(tr("Maintenir en bas de page"));
|
QStandardItem *hold_bottom = new QStandardItem(tr("Maintenir en bas de page"));
|
||||||
hold_bottom->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
hold_bottom->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||||
@@ -1233,6 +1255,7 @@ void DynamicElementTextModel::setConnection(ElementTextItemGroup *group, bool se
|
|||||||
connection_list << connect(group, &ElementTextItemGroup::holdToBottomPageChanged, [group, this]() {this->updateDataFromGroup(group, grpHoldBottom);});
|
connection_list << connect(group, &ElementTextItemGroup::holdToBottomPageChanged, [group, this]() {this->updateDataFromGroup(group, grpHoldBottom);});
|
||||||
connection_list << connect(group, &ElementTextItemGroup::xChanged, [group, this]() {this->updateDataFromGroup(group, grpPos);});
|
connection_list << connect(group, &ElementTextItemGroup::xChanged, [group, this]() {this->updateDataFromGroup(group, grpPos);});
|
||||||
connection_list << connect(group, &ElementTextItemGroup::yChanged, [group, this]() {this->updateDataFromGroup(group, grpPos);});
|
connection_list << connect(group, &ElementTextItemGroup::yChanged, [group, this]() {this->updateDataFromGroup(group, grpPos);});
|
||||||
|
connection_list << connect(group, &ElementTextItemGroup::frameChanged, [group, this]() {this->updateDataFromGroup(group, grpFrame);});
|
||||||
|
|
||||||
m_hash_group_connect.insert(group, connection_list);
|
m_hash_group_connect.insert(group, connection_list);
|
||||||
}
|
}
|
||||||
@@ -1373,6 +1396,9 @@ void DynamicElementTextModel::updateDataFromGroup(ElementTextItemGroup *group, D
|
|||||||
enableGroupRotationAndPos(group);
|
enableGroupRotationAndPos(group);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case grpFrame:
|
||||||
|
qsi->child(frame_grp_row, 1)->setCheckState(group->frame()? Qt::Checked : Qt::Unchecked);
|
||||||
|
break;
|
||||||
default:break;
|
default:break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ class DynamicElementTextModel : public QStandardItemModel
|
|||||||
grpRotation,
|
grpRotation,
|
||||||
grpVAdjust,
|
grpVAdjust,
|
||||||
grpName,
|
grpName,
|
||||||
grpHoldBottom
|
grpHoldBottom,
|
||||||
|
grpFrame
|
||||||
};
|
};
|
||||||
|
|
||||||
DynamicElementTextModel(Element *element, QObject *parent = nullptr);
|
DynamicElementTextModel(Element *element, QObject *parent = nullptr);
|
||||||
|
|||||||
Reference in New Issue
Block a user