1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4     Rosegarden
5     A MIDI and audio sequencer and musical notation editor.
6     Copyright 2000-2021 the Rosegarden development team.
7 
8     Other copyrights also apply to some parts of this work.  Please
9     see the AUTHORS file and individual file headers for details.
10 
11     This program is free software; you can redistribute it and/or
12     modify it under the terms of the GNU General Public License as
13     published by the Free Software Foundation; either version 2 of the
14     License, or (at your option) any later version.  See the file
15     COPYING included with this distribution for more information.
16 */
17 
18 #ifndef RG_CONTROLITEM_H
19 #define RG_CONTROLITEM_H
20 
21 #include <QPolygonF>
22 #include <QColor>
23 #include <QSharedPointer>
24 
25 #include <map>
26 
27 class QPainter;
28 class QMouseEvent;
29 class QWheelEvent;
30 
31 namespace Rosegarden {
32 
33 #define MIDI_CONTROL_MAX_VALUE 0x7F // Shouldnt be here
34 
35 class ControlRuler;
36 //class ElementAdapter;
37 class Event;
38 
39 class ControlItem : public QPolygonF
40 {
41 public:
42     ControlItem(ControlRuler* controlRuler,
43 //                ElementAdapter* adapter,
44                 Event* event,
45                 QPolygonF polygon);
46 
47     virtual ~ControlItem();
48 
49     virtual void setValue(float);
y()50     float y() const { return m_y; }
getColour()51     QColor getColour() { return m_colour; }
52 
53     //void setWidth(int w)  { setSize(w, height()); }
54     //void setHeight(int h) {
55 	//setSize(width(), h);
56 	//setZ(50.0+(h/2.0));
57     //}
58     //unsigned int getHeight()       { return size().height(); }
59 
60     virtual void draw(QPainter &painter);
61 
xStart()62     virtual double xStart() { return m_xstart; }
xEnd()63     virtual double xEnd() { return m_xend; }
64 
65     virtual void handleMouseButtonPress(QMouseEvent *e);
66     virtual void handleMouseButtonRelease(QMouseEvent *e);
67     virtual void handleMouseMove(QMouseEvent *e, int deltaX, int deltaY);
68     virtual void handleMouseWheel(QWheelEvent *e);
69 
70     virtual void setSelected(bool yes);
isSelected()71     bool isSelected() { return m_selected; }
72     //    virtual void setHighlighted(bool yes) { m_highlighted=yes; update(); }
73     /// recompute height according to represented value prior to a canvas repaint
74     virtual void updateFromValue();
75 
76     /// update value according to height after a user edit
77     virtual void updateSegment();
78 
79     virtual void update();
80 
81     virtual void setX(int);
82     virtual void setWidth(int);
83 
84 //    ElementAdapter* getElementAdapter() { return m_elementAdapter; }
getEvent()85     virtual Event* getEvent() { return m_event; }
86 
setData(long data)87     void setData(long data) { m_data = data; }
getData()88     long getData() { return m_data; }
89 
90     virtual void reconfigure();
91 
92 protected:
93 
94     //--------------- Data members ---------------------------------
95 
96     QColor m_colour;
97     double m_xstart;
98     double m_xend;
99     double m_lastxstart;
100     float m_y;
101     bool m_handlingMouseMove;
102     bool m_selected;
103 
104     long m_data;  // Currently only used with velocity items
105                   // (Matrix velocity tool store initial velocity here)
106 
107     ControlRuler* m_controlRuler;
108     Event* m_event;
109 
110     static const unsigned int BorderThickness;
111     static const unsigned int DefaultWidth;
112 };
113 
114 typedef std::multimap<double /* xStart */, QSharedPointer<ControlItem>>
115         ControlItemMap;
116 
117 typedef std::list<QSharedPointer<ControlItem>> ControlItemList;
118 
119 typedef std::vector<QSharedPointer<ControlItem>> ControlItemVector;
120 
121 }
122 
123 #endif
124