148 #include <QMouseEvent>
151 #include <KCharSelect>
155 #include "SymbolEditor.h"
176 setMouseTracking(
true);
177 setFocusPolicy(Qt::StrongFocus);
184 m_angles << 0 << 45 << 90 << 135 << 180 << 225 << 270 << 315;
277 QPainterPath
Editor::cubicTo(
const QPointF &control1,
const QPointF &control2,
const QPointF &to)
359 for (
int i = 0 ; i <
m_points.count() ; ++i) {
361 m_points[i] = QPointF(p.y(), 1.0 - p.x());
379 for (
int i = 0 ; i <
m_points.count() ; ++i) {
381 m_points[i] = QPointF(1.0 - p.y(), p.x());
399 for (
int i = 0 ; i <
m_points.count() ; ++i) {
421 for (
int i = 0 ; i <
m_points.count() ; ++i) {
495 width = round(width * 100) / 100;
586 path.addText(0.0, 0.0, font, QString(character));
590 QRectF boundingRect = path.boundingRect();
593 QTransform transform = QTransform::fromTranslate(-boundingRect.center().x(), -boundingRect.center().y()) * QTransform::fromScale(scale, scale) * QTransform::fromTranslate(0.5, 0.5);
594 path = transform.map(path);
630 Qt::FillRule fillRule =
static_cast<Qt::FillRule
>(action->data().toInt());
643 Qt::PenCapStyle capStyle =
static_cast<Qt::PenCapStyle
>(action->data().toInt());
656 Qt::PenJoinStyle joinStyle =
static_cast<Qt::PenJoinStyle
>(action->data().toInt());
742 setMinimumSize(size());
757 if (event->buttons() & Qt::LeftButton) {
798 if (event->buttons() & Qt::LeftButton) {
817 setCursor(Qt::SizeAllCursor);
819 setCursor(Qt::ArrowCursor);
923 p.setRenderHint(QPainter::Antialiasing,
true);
924 p.fillRect(event->rect(), Qt::white);
929 p.setPen(Qt::lightGray);
931 p.setPen(Qt::darkGray);
938 for (
int y = 0 ; y < m_gridElements + 1 ; ++y) {
940 p.setPen(Qt::lightGray);
942 p.setPen(Qt::darkGray);
952 QPen dashedPen(Qt::DashLine);
955 p.setBrush(Qt::SolidPattern);
957 for (
int i = 0 ; i <
m_points.count() ; ++i) {
970 for (
int i = 0, j = 0 ; i <
m_elements.count() ; ++i) {
971 QPainterPath::ElementType element =
m_elements[i];
978 case QPainterPath::MoveToElement:
983 case QPainterPath::LineToElement:
988 case QPainterPath::CurveToElement:
1003 p.setBrush(Qt::NoBrush);
1011 p.setPen(dashedPen);
1027 QRect preferredSizeRect = QRect(0, 0,
m_size,
m_size).adjusted(border, border, -border, -border);
1029 preferredSizeColor.setAlpha(128);
1030 p.setPen(preferredSizeColor);
1031 p.setBrush(Qt::NoBrush);
1032 p.drawRect(preferredSizeRect);
1036 QColor c(Qt::black);
1043 QBrush pathFill(
m_symbol.
filled() ? Qt::SolidPattern : Qt::NoBrush);
1044 pathFill.setColor(c);
1045 p.setBrush(pathFill);
1050 guideLineColor.setAlpha(128);
1051 QPen guideLinePen(guideLineColor);
1052 p.setPen(guideLinePen);
1053 p.setBrush(Qt::NoBrush);
1054 QRectF snapRect(0, 0, 0.03, 0.03);
1057 snapRect.moveCenter(snapPoint);
1058 p.drawRect(snapRect);
1062 p.drawLine(guideLine);
1066 p.drawEllipse(QPointF(0.5, 0.5), guideCircle, guideCircle);
1078 switch (event->key()) {
1079 case Qt::Key_Escape:
1085 QWidget::keyPressEvent(event);
1103 double sx =
static_cast<double>(point.x()) /
m_size;
1104 double sy =
static_cast<double>(point.y()) /
m_size;
1105 return QPointF(sx, sy);
1145 QPair<bool, QPointF> snap(
false,
toSymbol(point));
1151 snap.second = QPointF(sx, sy);
1170 QPair<bool, QPointF> snap(
false, point);
1197 int sx = floor(point.x() *
m_size);
1198 int sy = floor(point.y() *
m_size);
1199 return QPoint(sx, sy);
1215 for (
int i = 0 ; i <
m_points.count() ; ++i) {
1216 QPointF distance = point -
m_points[i];
1246 for (
int i = 0 ; i <
m_points.count() ; ++i) {
1247 QPointF distance = point -
m_points[i];
1250 return QPair<bool, int>(
true, i);
1258 return QPair<bool, int>(
false, i);
1262 return QPair<bool, int>(
false, -1);
1281 case QPainterPath::MoveToElement:
1286 case QPainterPath::LineToElement:
1291 case QPainterPath::CurveToElement:
1296 case QPainterPath::CurveToDataElement:
1313 for (
int i = 0, j = 0 ; i <
m_elements.count() ; ++i) {
1317 case QPainterPath::MoveToElement:
1321 case QPainterPath::LineToElement:
1325 case QPainterPath::CurveToElement:
1349 foreach (
const QPointF & from,
m_points) {
1375 QLineF line(from, to);
1377 if (
m_angles.contains(line.angle())) {
1397 QVector<QPointF> intersections;
1398 intersections << QPointF(1.0 - from.x(), from.y()) << QPointF(from.x(), 1.0 - from.y()) << QPointF(1.0 - from.x(), 1.0 - from.y());
1399 bool circles =
false;
1401 foreach (
const QPointF & i, intersections) {
1413 m_guideCircles.append(sqrt(pow(0.5 - to.x(), 2) + pow(0.5 - to.y(), 2)));
1432 QPointF intersectTop;
1433 QPointF intersectBottom;
1434 QPointF intersectLeft;
1435 QPointF intersectRight;
1437 QLineF::IntersectType t;
1438 QLineF::IntersectType b;
1439 QLineF::IntersectType l;
1440 QLineF::IntersectType r;
1442 t = line.intersect(
m_topEdge, &intersectTop);
1444 l = line.intersect(
m_leftEdge, &intersectLeft);
1448 return QLineF(intersectLeft, intersectRight);
1452 return QLineF(intersectTop, intersectBottom);
1455 if (intersectTop == QPointF(0.0, 0.0) || intersectTop == QPointF(1.0, 0.0)) {
1456 return QLineF(intersectTop, intersectBottom);
1459 if (intersectTop.x() > 0.0 && intersectTop.x() < 1.0) {
1460 if (intersectLeft.y() > 0.0 && intersectLeft.y() < 1.0) {
1461 return QLineF(intersectTop, intersectLeft);
1463 return QLineF(intersectTop, intersectRight);
1466 if (intersectLeft.y() > 0.0 && intersectLeft.y() < 1.0) {
1467 return QLineF(intersectBottom, intersectLeft);
1469 return QLineF(intersectBottom, intersectRight);