mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 05:00:33 +01:00
Conductor : improve text position
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3333 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -1125,29 +1125,80 @@ ConductorSegment *Conductor::middleSegment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Positionne le texte du conducteur au milieu du segment qui contient le
|
* @brief Conductor::posForText
|
||||||
point au milieu du conducteur
|
* Calculate and return the better pos for text.
|
||||||
@see middleSegment()
|
* @param flag : flag is used to know if text pos is near of
|
||||||
*/
|
* a vertical or horizontal conductor segment.
|
||||||
|
*/
|
||||||
|
QPointF Conductor::posForText(Qt::Orientations &flag) {
|
||||||
|
|
||||||
|
ConductorSegment *segment = segments;
|
||||||
|
|
||||||
|
//Go to first segement
|
||||||
|
while (!segment->isFirstSegment()) {
|
||||||
|
segment = segment->previousSegment();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QPointF p1 = segment -> firstPoint(); //<First point of conductor
|
||||||
|
ConductorSegment *biggest_segment = segment; //<biggest segment: contain the longest segment of conductor.
|
||||||
|
|
||||||
|
while (segment -> hasNextSegment()) {
|
||||||
|
segment = segment -> nextSegment();
|
||||||
|
if (segment -> length() > biggest_segment -> length())
|
||||||
|
biggest_segment = segment;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF p2 = segment -> secondPoint();//<Last point of conductor
|
||||||
|
|
||||||
|
//If the conductor is horizontal or vertical
|
||||||
|
//Return the point at the middle of conductor
|
||||||
|
if (p1.x() == p2.x()) { //<Vertical
|
||||||
|
flag = Qt::Vertical;
|
||||||
|
if (p1.y() > p2.y()) {
|
||||||
|
p1.setY(p1.y() - (length()/2));
|
||||||
|
} else {
|
||||||
|
p1.setY(p1.y() + (length()/2));
|
||||||
|
}
|
||||||
|
} else if (p1.y() == p2.y()) { //<Horizontal
|
||||||
|
flag = Qt::Horizontal;
|
||||||
|
if (p1.x() > p2.x()) {
|
||||||
|
p1.setX(p1.x() - (length()/2));
|
||||||
|
} else {
|
||||||
|
p1.setX(p1.x() + (length()/2));
|
||||||
|
}
|
||||||
|
} else { //Return the point at the middle of biggest segment.
|
||||||
|
p1 = biggest_segment->middle();
|
||||||
|
flag = (biggest_segment->isHorizontal())? Qt::Horizontal : Qt::Vertical;
|
||||||
|
}
|
||||||
|
return p1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Conductor::calculateTextItemPosition
|
||||||
|
* Move the text at middle of conductor (if is vertical or horizontal)
|
||||||
|
* otherwise, move conductor at the middle of the longest segment of conductor.
|
||||||
|
* If text was moved by user, this function do nothing, except check if text is near conductor.
|
||||||
|
*/
|
||||||
void Conductor::calculateTextItemPosition() {
|
void Conductor::calculateTextItemPosition() {
|
||||||
if (!text_item) return;
|
if (!text_item) return;
|
||||||
|
|
||||||
//position
|
//position
|
||||||
if (text_item -> wasMovedByUser()) {
|
if (text_item -> wasMovedByUser()) {
|
||||||
// le champ de texte a ete deplace par l'utilisateur :
|
//Text field was moved by user :
|
||||||
// on verifie qu'il est encore a proximite du conducteur
|
//we check if text field is yet near the conductor
|
||||||
QPointF text_item_pos = text_item -> pos();
|
QPointF text_item_pos = text_item -> pos();
|
||||||
QPainterPath near_shape = nearShape();
|
QPainterPath near_shape = nearShape();
|
||||||
if (!near_shape.contains(text_item_pos)) {
|
if (!near_shape.contains(text_item_pos)) {
|
||||||
text_item -> setPos(movePointIntoPolygon(text_item_pos, near_shape));
|
text_item -> setPos(movePointIntoPolygon(text_item_pos, near_shape));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// positionnement automatique basique
|
//Position of text is calculated and also is rotation
|
||||||
text_item -> setPos(middleSegment() -> middle());
|
Qt::Orientations rotation;
|
||||||
//rotation
|
text_item -> setPos(posForText(rotation));
|
||||||
if (!text_item -> wasRotateByUser()) {
|
if (!text_item -> wasRotateByUser()) {
|
||||||
middleSegment() -> isVertical()? text_item -> setRotationAngle(properties_.verti_rotate_text):
|
rotation == Qt::Vertical ? text_item -> setRotationAngle(properties_.verti_rotate_text):
|
||||||
text_item -> setRotationAngle(properties_.horiz_rotate_text);
|
text_item -> setRotationAngle(properties_.horiz_rotate_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ class Conductor : public QObject, public QGraphicsPathItem {
|
|||||||
virtual bool isNearConductor(const QPointF &);
|
virtual bool isNearConductor(const QPointF &);
|
||||||
qreal length();
|
qreal length();
|
||||||
ConductorSegment *middleSegment();
|
ConductorSegment *middleSegment();
|
||||||
|
QPointF posForText(Qt::Orientations &flag);
|
||||||
bool containsPoint(const QPointF &) const;
|
bool containsPoint(const QPointF &) const;
|
||||||
QString text() const;
|
QString text() const;
|
||||||
void setText(const QString &);
|
void setText(const QString &);
|
||||||
|
|||||||
Reference in New Issue
Block a user