Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "angle" instead of "direction" for text #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/kicad/model/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,8 @@ void Component::reorganizeToPackageStyle()
// set position of ref and name text
_nameText->setPos(QPoint(rect.right(), rect.top() - 50));
_nameText->setTextHJustify(DrawText::TextHRight);
_nameText->setDirection(DrawText::DirectionHorizontal);
_nameText->setAngle(0.0);
_refText->setPos(QPoint(rect.left(), rect.bottom() + 50));
_refText->setTextHJustify(DrawText::TextHLeft);
_refText->setDirection(DrawText::DirectionHorizontal);
_refText->setAngle(0.0);;
}
17 changes: 12 additions & 5 deletions src/kicad/model/drawtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

DrawText::DrawText(const QString &text, const QPoint &pos)
{
_direction = DirectionHorizontal;
_angle = 0.0;
_textSize = 50;
_textStyle = TextNormal;
_visible = true;
Expand Down Expand Up @@ -50,14 +50,21 @@ void DrawText::setText(const QString &text)
_text = text;
}

DrawText::Direction DrawText::direction() const
qreal DrawText::angle(void) const
{
return _direction;
return _angle;
}

void DrawText::setDirection(Direction direction)
void DrawText::setAngle(qreal angle)
{
_direction = direction;
_angle = angle;
_transform.reset();
_transform.rotate(_angle);
}

QTransform DrawText::transform() const
{
return _transform;
}

uint DrawText::textSize() const
Expand Down
15 changes: 7 additions & 8 deletions src/kicad/model/drawtext.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define DRAWTEXT_H

#include <QString>
#include <QTransform>
#include <QtCore/qglobal.h>

#include "draw.h"
Expand All @@ -35,13 +36,10 @@ class KICAD_EXPORT DrawText : public Draw
const QString &text() const;
void setText(const QString &text);

enum Direction
{
DirectionHorizontal,
DirectionVertital
};
Direction direction() const;
void setDirection(Direction direction);
qreal angle(void) const;
void setAngle(qreal angle);

QTransform transform() const;

uint textSize() const;
void setTextSize(uint textSize);
Expand Down Expand Up @@ -79,7 +77,8 @@ class KICAD_EXPORT DrawText : public Draw

protected:
QString _text;
Direction _direction;
QTransform _transform;
qreal _angle;
uint _textSize;
TextStyles _textStyle;
bool _visible;
Expand Down
26 changes: 7 additions & 19 deletions src/kicad/parser/kicadlibparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QDateTime>
#include <QDebug>
#include <QFileInfo>
#include <QtMath>

#include "model/drawcircle.h"
#include "model/drawpoly.h"
Expand Down Expand Up @@ -275,14 +276,8 @@ void KicadLibParser::writeDraw(Draw *draw)
// T direction posx posy text_size text_type unit convert text text_italic text_bold text_hjustify text_vjustify
drawText = dynamic_cast<DrawText *>(draw);
_stream << "T ";
if (drawText->direction() == DrawText::DirectionHorizontal)
{
_stream << "0 ";
}
else
{
_stream << "900 ";
}

_stream << uint(qFloor((drawText->angle() * 10) + 0.5)) << " ";

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

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

if (draw->direction() == DrawText::DirectionHorizontal)
if (draw->angle() < 45.0)
{
_stream << "H ";
}
Expand Down Expand Up @@ -708,14 +703,7 @@ Draw *KicadLibParser::readDraw(char c)
{
DrawText *draw = new DrawText();
_stream >> n;
if (n == 0)
{
draw->setDirection(DrawText::DirectionHorizontal);
}
else
{
draw->setDirection(DrawText::DirectionVertital);
}
draw->setAngle(qreal(n) / 10);

_stream >> n;
draw->pos().setX(n);
Expand Down Expand Up @@ -881,11 +869,11 @@ DrawText *KicadLibParser::readLabel()
_stream >> nc;
if (nc == 'H')
{
draw->setDirection(DrawText::DirectionHorizontal);
draw->setAngle(0.0);
}
else
{
draw->setDirection(DrawText::DirectionVertital);
draw->setAngle(90.0);
}

_stream.skipWhiteSpace();
Expand Down
8 changes: 4 additions & 4 deletions src/kicad/pinruler/pinclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,22 +313,22 @@ DrawText *PinClass::getDrawText() const
case ClassRule::PositionTop:
height = qCeil(boundingRect().height() / 100.0) * 100 - 100;
drawClassLabel->setPos(QPoint(_pos.x() + boundingRect().width() / 2 - 50, _pos.y() + 50 + height));
drawClassLabel->setDirection(DrawText::DirectionHorizontal);
drawClassLabel->setAngle(0.0);
break;
case ClassRule::PositionBottom:
height = qCeil(boundingRect().height() / 100.0) * 100 - 100;
drawClassLabel->setPos(QPoint(_pos.x() + boundingRect().width() / 2 - 50, _pos.y() - 50 - height));
drawClassLabel->setDirection(DrawText::DirectionHorizontal);
drawClassLabel->setAngle(0.0);
break;
case ClassRule::PositionLeft:
width = qCeil(boundingRect().width() / 100.0) * 100 - 100;
drawClassLabel->setPos(QPoint(_pos.x() + width + 50, _pos.y() - 50 + boundingRect().height() / 2));
drawClassLabel->setDirection(DrawText::DirectionVertital);
drawClassLabel->setAngle(90.0);
break;
case ClassRule::PositionRight:
width = qCeil(boundingRect().width() / 100.0) * 100 - 100;
drawClassLabel->setPos(QPoint(_pos.x() - width - 50, _pos.y() - 50 + boundingRect().height() / 2));
drawClassLabel->setDirection(DrawText::DirectionVertital);
drawClassLabel->setAngle(90.0);
break;
case ClassRule::PositionASide:
break;
Expand Down
4 changes: 2 additions & 2 deletions src/kicad/pinruler/pinruler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,10 @@ void PinRuler::organize(Component *component)
component->prependDraw(rectDraw);
component->nameText()->setPos(QPoint(rect.right(), rect.bottom() + 50));
component->nameText()->setTextHJustify(DrawText::TextHRight);
component->nameText()->setDirection(DrawText::DirectionHorizontal);
component->nameText()->setAngle(0.0);
component->refText()->setPos(QPoint(rect.left(), rect.bottom() + 50));
component->refText()->setTextHJustify(DrawText::TextHLeft);
component->refText()->setDirection(DrawText::DirectionHorizontal);
component->refText()->setAngle(0.0);

for (PinClass *mpinClass : _pinClasses)
{
Expand Down
14 changes: 3 additions & 11 deletions src/kicad/viewer/drawtextitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void DrawTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
{
Q_UNUSED(option)
Q_UNUSED(widget)
Q_ASSERT(_fontText != nullptr);

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

if (_drawText->direction() == DrawText::DirectionVertital)
{
painter->rotate(-90);
}
painter->setTransform(_drawText->transform());

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

QRectF DrawTextItem::boundingRect() const
{
return _rect.adjusted(-20, -20, 20, 20);
return _drawText->transform().mapRect(_rect).adjusted(-20, -20, 20, 20);
}

void DrawTextItem::setDraw(DrawText *draw)
Expand Down Expand Up @@ -126,12 +124,6 @@ void DrawTextItem::setDraw(DrawText *draw)
}

_textRect = _rect;
if (_drawText->direction() == DrawText::DirectionVertital)
{
int swap = _rect.size().width();
_rect.setWidth(_rect.height());
_rect.setHeight(swap);
}

setPos(draw->pos() / ComponentItem::ratio);
update();
Expand Down
2 changes: 1 addition & 1 deletion src/kicad/viewer/kicadfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ double KicadFont::textWidth(const QString &text) const
return width;
}

QFont KicadFont::font()
QFont KicadFont::font() const
{
return _font;
}
Expand Down
2 changes: 1 addition & 1 deletion src/kicad/viewer/kicadfont.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class KICAD_EXPORT KicadFont
double charWidth(QChar c) const;
double textWidth(const QString &text) const;

QFont font();
QFont font() const;
static QFont font(double size);
void drawText(QPainter *painter, const QRectF &rect, int flags, const QString &text) const;

Expand Down