summaryrefslogtreecommitdiff
path: root/muse_qt4_evolution/muse/canvas.h
blob: 911936c290f7ce6f991b59a3cc9b26079abce048 (plain)
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
//=============================================================================
//  MusE
//  Linux Music Editor
//  $Id:$
//
//  Copyright (C) 2002-2006 by Werner Schweer and others
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License version 2.
//
//  This program 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 this program; if not, write to the Free Software
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================

#ifndef __CANVAS_H__
#define __CANVAS_H__

#include "awl/tcanvas.h"
#include "widgets/tools.h"

class CanvasWidget;
class Part;
class Track;
class ArrangerTrack;

static const int HANDLE1 = 6;
static const int HANDLE2 = 3;

//---------------------------------------------------------
//   PartCanvas
//---------------------------------------------------------

class PartCanvas : public TimeCanvas {
      Q_OBJECT

      // DRAG1    drag part head
      // DRAG2    drag part tail
      // DRAG3    drag whole part
      // DRAG4    Drag&Drop drag
      // DRAG5    draw part with pencil tool

      enum { S_NORMAL, S_START_DRAG1, S_START_DRAG2, S_START_DRAG3,
            S_DRAG1, S_DRAG2, S_DRAG3,
            S_DRAG4,
            S_START_DRAG5, S_DRAG5,                 // draw new Part
            S_SUBTRACK
            };
      int state;
      QPoint startDrag;
      int _dragOffset;
      QRect drag;
      QTime startDragTime;
      unsigned ppos, psize;

      // values set by searchPart():
      Track* track;
      Part* part;
      ArrangerTrack* at;

      Part* srcPart;    // src part of a drag/drop operation

      bool _drawBackground;
      int selected;
      int lselected;    // in local coordinates
      int starty;
      int dragy;

      virtual void paint(QPainter&, QRect);
      void drawWavePart(QPainter& p, Part* part, int, int, int, int);
      void drawMidiPart(QPainter& p, Part* mp, int, int, int, int);
      virtual void mousePress(QMouseEvent*);
      virtual void mouseMove(QPoint);
      virtual void mouseRelease(QMouseEvent*);
      virtual void mouseDoubleClick(QMouseEvent*);

      virtual void dragEnter(QDragEnterEvent*);
      virtual void drop(QDropEvent*);
      virtual void dragMove(QDragMoveEvent*);
      virtual void dragLeave(QDragLeaveEvent*);
      
      virtual void keyboardNavigate(QKeyEvent *e);


      int searchPart(const QPoint& p);

      void declonePart(Part* part);
      void renamePart(Part*);
      void splitPart(Part*, const QPoint&);
      void cutPart(Part*);
      void copyPart(Part*);

      void setCursor();
      int dragOffset() const { return _dragOffset; }
      void drawHandle(QPainter& p, int x, int y) {
            p.fillRect(x-HANDLE2, y-HANDLE2, HANDLE1, HANDLE1, x == lselected ? Qt::red : Qt::yellow);
            }
      void contextMenu(const QPoint&);
      
      QRubberBand *rubberBand;
      QPoint rubberBandStartPos;

   private slots:
      void markerChanged(int);

   signals:
      void kbdMovementUpdate(Track* t, Part* p);
      void startEditor(Part*, int);
      void createLRPart(Track*);
      void partChanged(Part*, unsigned, unsigned);
      void doubleClickPart(Part*);

   public:
      PartCanvas();
      void setDrawBackground(bool val) { _drawBackground = val; }
      };

#endif