-
Notifications
You must be signed in to change notification settings - Fork 1
/
Editor.h
146 lines (116 loc) · 3.84 KB
/
Editor.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
Copyright (C) 2010-2011 Igor Izyumin
This file is part of xpcb.
xpcb is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
xpcb is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with xpcb. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EDITOR_H
#define EDITOR_H
#include <QObject>
#include <QAction>
#include <QMouseEvent>
#include "PCBObject.h"
#include "CtrlAction.h"
class Controller;
class Document;
class CtrlAction;
class PCBDoc;
class NLPart;
class AbstractEditor : public QObject
{
Q_OBJECT
public:
explicit AbstractEditor(Controller *ctrl);
virtual void init() {}
virtual void drawOverlay(QPainter* /*painter*/) {}
virtual QList<const CtrlAction*> actions() const;
signals:
void actionsChanged();
void overlayChanged();
void editorFinished();
public slots:
protected:
virtual bool eventFilter(QObject *watched, QEvent *event);
virtual void mouseMoveEvent(QMouseEvent* event) { event->ignore(); }
virtual void mousePressEvent(QMouseEvent* event) { event->ignore(); }
virtual void mouseReleaseEvent(QMouseEvent* event) { event->ignore(); }
virtual void keyPressEvent(QKeyEvent *event) { event->ignore(); }
Controller* ctrl() { return mCtrl; }
private:
Controller *mCtrl;
};
class AbstractEditorFactory
{
public:
virtual QSharedPointer<AbstractEditor> makeEditor(Controller* ctrl, QSharedPointer<PCBObject> obj) = 0;
};
class EditorFactory
{
public:
enum ObjType {ObjArea, ObjLine, ObjPartPin, ObjPin, ObjPart, ObjFootprint, ObjText, ObjVertex, ObjSegment, ObjPadstack};
static EditorFactory& instance();
QSharedPointer<AbstractEditor> newEditor(QSharedPointer<PCBObject> obj, Controller *ctrl);
QSharedPointer<AbstractEditor> newEditor(Document* obj, Controller *ctrl);
QSharedPointer<AbstractEditor> newTextEditor(Controller *ctrl);
QSharedPointer<AbstractEditor> newPinEditor(Controller* ctrl);
QSharedPointer<AbstractEditor> newPartEditor(Controller* ctrl);
QSharedPointer<AbstractEditor> newLineEditor(Controller* ctrl);
QSharedPointer<AbstractEditor> newTraceEditor(Controller* ctrl);
QSharedPointer<AbstractEditor> newAreaEditor(Controller* ctrl);
QSharedPointer<AbstractEditor> placePartEditor(Controller* ctrl, QList<NLPart> parts);
static void registerFactory(ObjType type, QSharedPointer<AbstractEditorFactory> factory) { instance().mFactories[type] = factory; }
private:
EditorFactory();
EditorFactory(EditorFactory &other);
static EditorFactory* mInst;
QSharedPointer<AbstractEditor> mEditor;
// parameters for visit function
Controller *mCtrl;
QSharedPointer<PCBObject> mObj;
QHash<ObjType, QSharedPointer<AbstractEditorFactory> > mFactories;
};
class DefaultPCBEditor : public AbstractEditor
{
Q_OBJECT
public:
explicit DefaultPCBEditor(Controller *ctrl);
virtual void init();
virtual QList<const CtrlAction*> actions() const;
private slots:
void actionAddText();
void actionAddPart();
void actionAddTrace();
void actionAddArea();
private:
CtrlAction mAddTraceAction;
CtrlAction mAddTextAction;
CtrlAction mAddPartAction;
CtrlAction mAddAreaAction;
};
class DefaultFPEditor : public AbstractEditor
{
Q_OBJECT
public:
explicit DefaultFPEditor(Controller *ctrl);
virtual void init();
virtual QList<const CtrlAction*> actions() const;
private slots:
void actionAddPin();
void actionAddLine();
void actionAddText();
void actionEditProps();
private:
CtrlAction mAddLineAction;
CtrlAction mAddPinAction;
CtrlAction mAddTextAction;
CtrlAction mEditPropsAction;
};
#endif // EDITOR_H