Skip to content

Commit 2518ab8

Browse files
committed
Use "angle" instead of "direction" for text
This replaces all instances of direction/setDirection with angle/setAngle for the DrawText type.
1 parent 2806d29 commit 2518ab8

9 files changed

Lines changed: 31 additions & 54 deletions

File tree

src/kicad/model/component.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,9 @@ void Component::reorganizeToPackageStyle()
585585
// set position of ref and name text
586586
_nameText->setPos(QPoint(rect.right(), rect.top() - 50));
587587
_nameText->setTextHJustify(DrawText::TextHRight);
588-
_nameText->setDirection(DrawText::DirectionHorizontal);
588+
_nameText->setAngle(0.0);
589589
_refText->setPos(QPoint(rect.left(), rect.bottom() + 50));
590590
_refText->setTextHJustify(DrawText::TextHLeft);
591-
_refText->setDirection(DrawText::DirectionHorizontal);
591+
_refText->setAngle(0.0);
592+
;
592593
}

src/kicad/model/drawtext.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
DrawText::DrawText(const QString &text, const QPoint &pos)
2222
{
23-
_direction = DirectionHorizontal;
23+
_angle = 0.0;
2424
_textSize = 50;
2525
_textStyle = TextNormal;
2626
_visible = true;
@@ -50,14 +50,14 @@ void DrawText::setText(const QString &text)
5050
_text = text;
5151
}
5252

53-
DrawText::Direction DrawText::direction() const
53+
qreal DrawText::angle(void) const
5454
{
55-
return _direction;
55+
return _angle;
5656
}
5757

58-
void DrawText::setDirection(Direction direction)
58+
void DrawText::setAngle(qreal angle)
5959
{
60-
_direction = direction;
60+
_angle = angle;
6161
}
6262

6363
uint DrawText::textSize() const

src/kicad/model/drawtext.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define DRAWTEXT_H
2121

2222
#include <QString>
23+
#include <QTransform>
2324
#include <QtCore/qglobal.h>
2425

2526
#include "draw.h"
@@ -35,13 +36,8 @@ class KICAD_EXPORT DrawText : public Draw
3536
const QString &text() const;
3637
void setText(const QString &text);
3738

38-
enum Direction
39-
{
40-
DirectionHorizontal,
41-
DirectionVertital
42-
};
43-
Direction direction() const;
44-
void setDirection(Direction direction);
39+
qreal angle(void) const;
40+
void setAngle(qreal angle);
4541

4642
uint textSize() const;
4743
void setTextSize(uint textSize);
@@ -79,7 +75,7 @@ class KICAD_EXPORT DrawText : public Draw
7975

8076
protected:
8177
QString _text;
82-
Direction _direction;
78+
qreal _angle;
8379
uint _textSize;
8480
TextStyles _textStyle;
8581
bool _visible;

src/kicad/parser/kicadlibparser.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <QDateTime>
2222
#include <QDebug>
2323
#include <QFileInfo>
24+
#include <QtMath>
2425

2526
#include "model/drawcircle.h"
2627
#include "model/drawpoly.h"
@@ -225,7 +226,7 @@ void KicadLibParser::writePin(Pin *pin)
225226
_stream << " " << pin->padName() << " " // pad name
226227
<< pin->pos().x() << " " << -pin->pos().y() << " " // x y position
227228
<< pin->length() << " " // lenght
228-
<< pinDirectionString(pin->angle()) << " " // pin direction (up/down/left/right)
229+
<< pinDirectionString(pin->angle()) << " " // pin direction (up/down/left/right)
229230
<< "50"
230231
<< " " // name text size
231232
<< "50"
@@ -275,14 +276,8 @@ void KicadLibParser::writeDraw(Draw *draw)
275276
// T direction posx posy text_size text_type unit convert text text_italic text_bold text_hjustify text_vjustify
276277
drawText = dynamic_cast<DrawText *>(draw);
277278
_stream << "T ";
278-
if (drawText->direction() == DrawText::DirectionHorizontal)
279-
{
280-
_stream << "0 ";
281-
}
282-
else
283-
{
284-
_stream << "900 ";
285-
}
279+
280+
_stream << uint(qFloor((drawText->angle() * 10) + 0.5)) << " ";
286281

287282
_stream << drawText->pos().x() << " " << -drawText->pos().y() << " " << drawText->textSize() << " "
288283
<< "0 " << drawText->unit() << " " << drawText->convert() << " "
@@ -345,7 +340,7 @@ void KicadLibParser::writeLabel(DrawText *draw)
345340

346341
_stream << draw->pos().x() << " " << -draw->pos().y() << " " << draw->textSize() << " ";
347342

348-
if (draw->direction() == DrawText::DirectionHorizontal)
343+
if (draw->angle() < 45.0)
349344
{
350345
_stream << "H ";
351346
}
@@ -708,14 +703,7 @@ Draw *KicadLibParser::readDraw(char c)
708703
{
709704
DrawText *draw = new DrawText();
710705
_stream >> n;
711-
if (n == 0)
712-
{
713-
draw->setDirection(DrawText::DirectionHorizontal);
714-
}
715-
else
716-
{
717-
draw->setDirection(DrawText::DirectionVertital);
718-
}
706+
draw->setAngle(qreal(n) / 10);
719707

720708
_stream >> n;
721709
draw->pos().setX(n);
@@ -881,11 +869,11 @@ DrawText *KicadLibParser::readLabel()
881869
_stream >> nc;
882870
if (nc == 'H')
883871
{
884-
draw->setDirection(DrawText::DirectionHorizontal);
872+
draw->setAngle(0.0);
885873
}
886874
else
887875
{
888-
draw->setDirection(DrawText::DirectionVertital);
876+
draw->setAngle(90.0);
889877
}
890878

891879
_stream.skipWhiteSpace();

src/kicad/pinruler/pinclass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,22 +313,22 @@ DrawText *PinClass::getDrawText() const
313313
case ClassRule::PositionTop:
314314
height = qCeil(boundingRect().height() / 100.0) * 100 - 100;
315315
drawClassLabel->setPos(QPoint(_pos.x() + boundingRect().width() / 2 - 50, _pos.y() + 50 + height));
316-
drawClassLabel->setDirection(DrawText::DirectionHorizontal);
316+
drawClassLabel->setAngle(0.0);
317317
break;
318318
case ClassRule::PositionBottom:
319319
height = qCeil(boundingRect().height() / 100.0) * 100 - 100;
320320
drawClassLabel->setPos(QPoint(_pos.x() + boundingRect().width() / 2 - 50, _pos.y() - 50 - height));
321-
drawClassLabel->setDirection(DrawText::DirectionHorizontal);
321+
drawClassLabel->setAngle(0.0);
322322
break;
323323
case ClassRule::PositionLeft:
324324
width = qCeil(boundingRect().width() / 100.0) * 100 - 100;
325325
drawClassLabel->setPos(QPoint(_pos.x() + width + 50, _pos.y() - 50 + boundingRect().height() / 2));
326-
drawClassLabel->setDirection(DrawText::DirectionVertital);
326+
drawClassLabel->setAngle(90.0);
327327
break;
328328
case ClassRule::PositionRight:
329329
width = qCeil(boundingRect().width() / 100.0) * 100 - 100;
330330
drawClassLabel->setPos(QPoint(_pos.x() - width - 50, _pos.y() - 50 + boundingRect().height() / 2));
331-
drawClassLabel->setDirection(DrawText::DirectionVertital);
331+
drawClassLabel->setAngle(90.0);
332332
break;
333333
case ClassRule::PositionASide:
334334
break;

src/kicad/pinruler/pinruler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,10 @@ void PinRuler::organize(Component *component)
332332
component->prependDraw(rectDraw);
333333
component->nameText()->setPos(QPoint(rect.right(), rect.bottom() + 50));
334334
component->nameText()->setTextHJustify(DrawText::TextHRight);
335-
component->nameText()->setDirection(DrawText::DirectionHorizontal);
335+
component->nameText()->setAngle(0.0);
336336
component->refText()->setPos(QPoint(rect.left(), rect.bottom() + 50));
337337
component->refText()->setTextHJustify(DrawText::TextHLeft);
338-
component->refText()->setDirection(DrawText::DirectionHorizontal);
338+
component->refText()->setAngle(0.0);
339339

340340
for (PinClass *mpinClass : _pinClasses)
341341
{

src/kicad/viewer/drawtextitem.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void DrawTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
4141
{
4242
Q_UNUSED(option)
4343
Q_UNUSED(widget)
44+
Q_ASSERT(_fontText != nullptr);
4445

4546
painter->setRenderHint(QPainter::Antialiasing);
4647
painter->setRenderHint(QPainter::TextAntialiasing);
@@ -64,17 +65,14 @@ void DrawTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
6465
}
6566
painter->setFont(font);
6667

67-
if (_drawText->direction() == DrawText::DirectionVertital)
68-
{
69-
painter->rotate(-90);
70-
}
68+
painter->rotate(_drawText->angle());
7169

7270
_fontText->drawText(painter, _textRect, Qt::AlignLeft, _drawText->text());
7371
}
7472

7573
QRectF DrawTextItem::boundingRect() const
7674
{
77-
return _rect.adjusted(-20, -20, 20, 20);
75+
return QTransform().rotate(_drawText->angle()).mapRect(_rect).adjusted(-20, -20, 20, 20);
7876
}
7977

8078
void DrawTextItem::setDraw(DrawText *draw)
@@ -126,12 +124,6 @@ void DrawTextItem::setDraw(DrawText *draw)
126124
}
127125

128126
_textRect = _rect;
129-
if (_drawText->direction() == DrawText::DirectionVertital)
130-
{
131-
int swap = _rect.size().width();
132-
_rect.setWidth(_rect.height());
133-
_rect.setHeight(swap);
134-
}
135127

136128
setPos(draw->pos() / ComponentItem::ratio);
137129
update();

src/kicad/viewer/kicadfont.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ double KicadFont::textWidth(const QString &text) const
5353
return width;
5454
}
5555

56-
QFont KicadFont::font()
56+
QFont KicadFont::font() const
5757
{
5858
return _font;
5959
}

src/kicad/viewer/kicadfont.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class KICAD_EXPORT KicadFont
3535
double charWidth(QChar c) const;
3636
double textWidth(const QString &text) const;
3737

38-
QFont font();
38+
QFont font() const;
3939
static QFont font(double size);
4040
void drawText(QPainter *painter, const QRectF &rect, int flags, const QString &text) const;
4141

0 commit comments

Comments
 (0)