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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
//=========================================================
// MusE
// Linux Music Editor
// $Id: canvas.h,v 1.3.2.8 2009/02/02 21:38:01 terminator356 Exp $
// (C) Copyright 1999 Werner Schweer (ws@seh.de)
// Additions, modifications (C) Copyright 2011 Tim E. Real (terminator356 on users DOT sourceforge DOT net)
//=========================================================
#ifndef __CANVAS_H__
#define __CANVAS_H__
#include "citem.h"
#include "view.h"
#include "tools.h"
#include "undo.h"
#include <QWheelEvent>
#include <QMouseEvent>
#include <QKeyEvent>
class QMenu;
//---------------------------------------------------------
// Canvas
//---------------------------------------------------------
class Canvas : public View {
Q_OBJECT
int canvasTools;
QTimer *scrollTimer;
bool doScroll;
int scrollSpeed;
QPoint ev_pos;
bool canScrollLeft;
bool canScrollRight;
bool canScrollUp;
bool canScrollDown;
protected:
enum DragMode {
DRAG_OFF, DRAG_NEW,
DRAG_MOVE_START, DRAG_MOVE,
DRAG_COPY_START, DRAG_COPY,
DRAG_CLONE_START, DRAG_CLONE,
DRAGX_MOVE, DRAGY_MOVE,
DRAGX_COPY, DRAGY_COPY,
DRAGX_CLONE, DRAGY_CLONE,
DRAG_DELETE,
DRAG_RESIZE, DRAG_LASSO_START, DRAG_LASSO,
};
enum DragType {
MOVE_MOVE, MOVE_COPY, MOVE_CLONE
};
enum HScrollDir {
HSCROLL_NONE, HSCROLL_LEFT, HSCROLL_RIGHT
};
enum VScrollDir {
VSCROLL_NONE, VSCROLL_UP, VSCROLL_DOWN
};
CItemList items;
CItemList moving;
CItem* curItem;
Part* curPart;
int curPartId;
DragMode drag;
QRect lasso;
QPoint start;
Tool _tool;
unsigned pos[3];
HScrollDir hscrollDir;
VScrollDir vscrollDir;
int button;
Qt::KeyboardModifiers keyState;
QMenu* itemPopupMenu;
QMenu* canvasPopupMenu;
void setCursor();
virtual void viewKeyPressEvent(QKeyEvent* event);
virtual void viewMousePressEvent(QMouseEvent* event);
virtual void viewMouseMoveEvent(QMouseEvent*);
virtual void viewMouseReleaseEvent(QMouseEvent*);
virtual void draw(QPainter&, const QRect&);
virtual void wheelEvent(QWheelEvent* e);
virtual void mousePress(QMouseEvent*) {}
virtual void keyPress(QKeyEvent*);
virtual void mouseMove(QMouseEvent* event) = 0;
virtual void mouseRelease(const QPoint&) {}
virtual void drawCanvas(QPainter&, const QRect&) = 0;
virtual void drawTopItem(QPainter& p, const QRect& rect) = 0;
virtual void drawItem(QPainter&, const CItem*, const QRect&) = 0;
virtual void drawMoving(QPainter&, const CItem*, const QRect&) = 0;
virtual void updateSelection() = 0;
virtual QPoint raster(const QPoint&) const = 0;
virtual int y2pitch(int) const = 0; //CDW
virtual int pitch2y(int) const = 0; //CDW
virtual CItem* newItem(const QPoint&, int state) = 0;
virtual void resizeItem(CItem*, bool noSnap=false, bool ctrl=false) = 0;
virtual void newItem(CItem*, bool noSnap=false) = 0;
virtual bool deleteItem(CItem*) = 0;
int getCurrentDrag();
/*!
\brief Virtual member
Implementing class is responsible for creating a popup to be shown when the user rightclicks an item on the Canvas
\param item The canvas item that is rightclicked
\return A QPopupMenu*
*/
virtual QMenu* genItemPopup(CItem* /*item*/) { return 0; }
/*!
\brief Pure virtual member
Implementing class is responsible for creating a popup to be shown when the user rightclicks an empty region of the canvas
\return A QPopupMenu*
*/
QMenu* genCanvasPopup();
/*!
\brief Virtual member
This is the function called when the user has selected an option in the popupmenu generated by genItemPopup()
\param item the canvas item the whole thing is about
\param n Command type
\param pt I think this is the position of the pointer when right mouse button was pressed
*/
virtual void itemPopup(CItem* /*item */, int /*n*/, const QPoint& /*pt*/) {}
void canvasPopup(int);
virtual void startDrag(CItem*, bool) {}
// selection
virtual void deselectAll();
virtual void selectItem(CItem* e, bool);
virtual void deleteItem(const QPoint&);
// moving
void startMoving(const QPoint&, DragType);
void moveItems(const QPoint&, int dir, bool rasterize = true);
virtual void endMoveItems(const QPoint&, DragType, int dir) = 0;
virtual void selectLasso(bool toggle);
virtual void itemPressed(const CItem*) {}
virtual void itemReleased(const CItem*, const QPoint&) {}
virtual void itemMoved(const CItem*, const QPoint&) {}
virtual void curPartChanged() {}
public slots:
void setTool(int t);
void setPos(int, unsigned, bool adjustScrollbar);
void scrollTimerDone(void);
void redirectedWheelEvent(QWheelEvent*);
signals:
void followEvent(int);
void toolChanged(int);
void verticalScroll(unsigned);
void horizontalScroll(unsigned);
void horizontalScrollNoLimit(unsigned);
void horizontalZoomIn();
void horizontalZoomOut();
public:
Canvas(QWidget* parent, int sx, int sy, const char* name = 0);
bool isSingleSelection();
int selectionSize();
Tool tool() const { return _tool; }
Part* part() const { return curPart; }
void setCurrentPart(Part*);
void setCanvasTools(int n) { canvasTools = n; }
};
#endif
|