forked from aizenbit/Scribbler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
symboldataeditor.h
113 lines (99 loc) · 3.62 KB
/
symboldataeditor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*!
SymbolDataEditor - class representing an editor of the symbol data.
It is included into the Font Editor window.
The handwritten font is a folder with SVG images and INI file that
contains information about the associations of characters and images,
as well as some additional data. This data includes the limits,
inPoint and outPoint. Limits show part of the symbol, which part of
the symbol must be within the line. It's a rectangle with a height
equal to the height of the line and the width equal to the width of
the character. InPoint and outPoint are the points of entry and exit
of connecting lines for the letter.
Data is not stored in absolute coordinates, it's stored as a relative
position to the image side
This class allows to set additional data by moving markers of points
or changing rectangle of limits. It also changes the cursor to make
editing easier for user and converts data from absolute to relative
coordinates.
*/
#ifndef SVGDATAEDITOR_H
#define SVGDATAEDITOR_H
#include <QtCore/QtMath>
#include <QtWidgets/QGraphicsView>
#include <QtWidgets/QGraphicsItem>
#include <QtSvg/QGraphicsSvgItem>
#include <QtSvg/QSvgRenderer>
#include <QtGui/QWheelEvent>
#include "svgview.h"
class SymbolDataEditor : public QGraphicsView
{
Q_OBJECT
public:
explicit SymbolDataEditor(QWidget *parent = 0);
~SymbolDataEditor();
void load(const QString & fileName); //!< loads specified item
void setSymbolData(const QPointF _inPoint, const QPointF _outPoint, const QRectF _limits);
void clear();
void disableChanges();
void disablePoints();
QPointF getInPoint() const {return toStored(inPoint);}
QPointF getOutPoint() const {return toStored(outPoint);}
QRectF getLimits() const {return QRectF(toStored(limits.topLeft()),
toStored(limits.bottomRight()));}
public slots:
void enableInPointChanges();
void enableOutPointChanges();
void enableLimitsChanges();
protected:
void wheelEvent(QWheelEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent * event);
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
private:
enum Item : int {
SymbolItem,
InPoint,
OutPoint,
LimitsRect,
NoItem
};
enum Side : int {
NoSide = 0x00,
Top = 0x01,
Bottom = 0x02,
Left = 0x04,
Right = 0x08,
AllSides = 0x10
};
const qreal maxScaleFactor = 40, minScaleFactor = 0.1, sceneScale = 5;
QGraphicsScene *scene;
qreal currentScaleFactor;
Item itemToChange;
Side sideToChange; //for Item::LimitsRect
qreal pointWidth;
bool setupPoints, pointsEnabled;
QPointF inPoint, outPoint, dLimitsCenter;
QRectF limits;
QDomDocument doc;
void limitScale(qreal factor); //!< limited view zoom
void loadSettings();
QPointF toStored(const QPointF &point) const;
QPointF fromStored(const QPointF &point) const;
QPointF fromViewBox(const QPointF &point) const; //!< used to get points by automatic setup
void moveItem(const QPoint pos);
void calculateSideToChange(QPoint pos);
void changeCursor();
void rememberChanges();
void correctLimits();
void addDataItems();
QPointF getBeginPoint();
QPointF getEndPoint();
QPointF getTranslatePoint();
QPointF getMovePoint(const QString &path);
QPointF getLastCurvePoint(const QString &path);
QPointF getLinePoint(const QString &path);
QStringList getPathList();
};
#endif // SVGDATAEDITOR_H