1 //============================================================================= 2 // Awl 3 // Audio Widget Library 4 // $Id:$ 5 // 6 // Copyright (C) 1999-2011 by Werner Schweer and others 7 // 8 // This program is free software; you can redistribute it and/or modify 9 // it under the terms of the GNU General Public License 10 // as published by the Free Software Foundation; version 2 of 11 // the License, or (at your option) any later version. 12 // 13 // This program is distributed in the hope that it will be useful, 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 // GNU General Public License for more details. 17 // 18 // You should have received a copy of the GNU General Public License 19 // along with this program; if not, write to the Free Software 20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 //============================================================================= 22 23 #ifndef __TCANVAS_H__ 24 #define __TCANVAS_H__ 25 26 #include "al/pos.h" 27 #include "al/marker.h" 28 29 #define MAP_OFFSET 20 30 31 enum TimeCanvasType { 32 TIME_CANVAS, TIME_CANVAS_PIANOROLL, TIME_CANVAS_DRUMEDIT, 33 TIME_CANVAS_WAVEEDIT 34 }; 35 36 enum Tool { 37 PointerTool=1, PencilTool=2, RubberTool=4, CutTool=8, 38 GlueTool=16, QuantTool=32, DrawTool=64, MuteTool=128 39 }; 40 41 enum FollowMode { 42 FOLLOW_NO, FOLLOW_JUMP, FOLLOW_CONTINUOUS 43 }; 44 45 static const int rulerHeight = 28; 46 static const int pianoWidth = 40; 47 static const int waveWidth = 40; 48 static const int drumWidth = 120; 49 static const int drumHeight = 18; 50 static const int keyHeight = 13; 51 52 //--------------------------------------------------------- 53 // TimeCanvas 54 // 55 // Layout: 56 // Button Ruler 57 // panelA canvasA 58 // panelB canvasB 59 // 60 // Pianoroll: 61 // panelA -> keyboard 62 // 63 // Drumeditor: 64 // panelA -> instrument list 65 // 66 //--------------------------------------------------------- 67 68 class TimeCanvas : public QFrame { 69 Q_OBJECT 70 71 Q_PROPERTY(QFont font1 READ font1 WRITE setFont1) 72 Q_PROPERTY(QFont font2 READ font2 WRITE setFont2) 73 Q_PROPERTY(QFont font3 READ font3 WRITE setFont3) 74 75 // I could not find out how to set the size of a font property with 76 // style sheets. As a workaround here are special "size" properties 77 // which could be set with style sheet command 78 // TimeCanvas { qproperty-fontSize1: 6 } 79 80 Q_PROPERTY(int fontSize1 READ fontSize1 WRITE setFontSize1 STORED false) 81 Q_PROPERTY(int fontSize2 READ fontSize2 WRITE setFontSize2 STORED false) 82 Q_PROPERTY(int fontSize3 READ fontSize3 WRITE setFontSize3 STORED false) 83 84 QFont _font1; 85 QFont _font2; 86 QFont _font3; 87 88 int yRange; 89 bool _yFit; 90 AL::Pos pos1; // time scroll range 91 AL::Pos pos2; 92 93 int metronomeRulerMag; 94 95 double _xmagMin, _xmagMax; 96 double _ymagMin, _ymagMax; 97 98 AL::TType _timeType; 99 AL::MarkerList* marker; 100 QScrollBar* hbar; 101 QScrollBar* vbar; 102 QSlider* vmag; 103 QSlider* hmag; 104 QToolButton* timeTypeButton; 105 QGridLayout* grid; 106 QColor canvasBackgroundColor; 107 QPixmap canvasBackgroundPixmap; 108 int dragType; 109 bool followPos; 110 111 // 112 // pianoroll variables 113 // 114 static QPixmap* octave; 115 static QPixmap* mk1; 116 static QPixmap* mk2; 117 static QPixmap* mk3; 118 static QPixmap* mk4; 119 QPushButton* addCtrlButton; 120 121 bool mouseInB; 122 123 void updateScrollBars(); 124 void canvasPaintEvent(const QRect&, QPainter&); 125 void paintCanvas(QPainter&, const QRect&); 126 void paintMetronomRuler(QPainter&, const QRect&); 127 void paintClockRuler(QPainter&, const QRect&); 128 void initPianoroll(); 129 void paintPiano(QPainter&, QRect); 130 void paintPianorollHorizontalGrid(QPainter&, QRect); 131 void paintDrumeditHorizontalGrid(QPainter&, QRect); 132 void updateGeometry(); 133 double s2xmag(int val); 134 int xmag2s(double m); 135 void updateRulerMag(); 136 137 protected: 138 TimeCanvasType type; 139 Tool _tool; 140 QRect rButton, rPanelA, rPanelB, rRuler, rCanvasA, rCanvasB; 141 AL::Pos pos[3]; 142 bool showCursor; 143 AL::Pos cursor; 144 145 QWidget* _widget; 146 147 AL::Pos partPos1; // active time range for midi editors 148 AL::Pos partPos2; 149 150 QPoint wpos; // "widget" position 151 double _xmag, _ymag; 152 153 int ctrlHeight; 154 int curPitch; 155 156 int _raster; 157 int button; 158 Qt::KeyboardModifiers keyState; 159 160 bool eventFilter(QObject*, QEvent*); 161 162 virtual void paint(QPainter&, QRect) = 0; mousePress(QMouseEvent *)163 virtual void mousePress(QMouseEvent*) {} mouseMove(QPoint)164 virtual void mouseMove(QPoint) {} mouseRelease(QMouseEvent *)165 virtual void mouseRelease(QMouseEvent*) {} mouseDoubleClick(QMouseEvent *)166 virtual void mouseDoubleClick(QMouseEvent*) {} paintDrumList(QPainter &,QRect)167 virtual void paintDrumList(QPainter&, QRect) {} layout()168 virtual void layout() {} enterB()169 virtual void enterB() {} leaveB()170 virtual void leaveB() {} 171 172 virtual void setCursor(); 173 timeTypeChanged()174 virtual void timeTypeChanged() {} magChanged()175 virtual void magChanged() {} 176 paintControllerCanvas(QPainter &,QRect)177 virtual void paintControllerCanvas(QPainter&, QRect) {} paintControllerPanel(QPainter &,QRect)178 virtual void paintControllerPanel(QPainter&, QRect) {} 179 dragEnter(QDragEnterEvent *)180 virtual void dragEnter(QDragEnterEvent*) {} drop(QDropEvent *)181 virtual void drop(QDropEvent*) {} dragMove(QDragMoveEvent *)182 virtual void dragMove(QDragMoveEvent*) {} dragLeave(QDragLeaveEvent *)183 virtual void dragLeave(QDragLeaveEvent*) {} 184 addController()185 virtual void addController() {} 186 187 virtual void keyPressEvent(QKeyEvent *e); keyboardNavigate(QKeyEvent *)188 virtual void keyboardNavigate(QKeyEvent *) {} 189 190 // map logical coordinates to physical coordinates (pixel) 191 int mapx(int x) const; mapy(int y)192 int mapy(int y) const { return lrint(y * _ymag) - wpos.y(); } rmapx(int x)193 int rmapx(int x) const { return lrint(x * _xmag); } rmapy(int y)194 int rmapy(int y) const { return lrint(y * _ymag); } map(const QPoint & p)195 QPoint map(const QPoint& p) const { 196 return QPoint(mapx(p.x()), mapy(p.y())); 197 } rmap(const QPoint & p)198 QPoint rmap(const QPoint& p) const { 199 return QPoint(rmapx(p.x()), rmapy(p.y())); 200 } 201 202 // map physical coordinates (pixel) to logical coordinates 203 int mapxDev(int x) const; rmapxDev(int x)204 int rmapxDev(int x) const { return lrint(x / _xmag); } mapyDev(int y)205 int mapyDev(int y) const { 206 int val = lrint((y + wpos.y()) / _ymag); 207 return val < 0 ? 0 : val; 208 } mapDev(const QPoint & p)209 QPoint mapDev(const QPoint& p) const { 210 return QPoint(mapxDev(p.x()), mapyDev(p.y())); 211 } 212 213 virtual int y2pitch(int y) const; 214 virtual int pitch2y(int pitch) const; 215 void setTimeType1(AL::TType t); 216 void setPart(const AL::Pos& p1, const AL::Pos& p2); 217 218 private slots: 219 void moveX(int); 220 void scaleX(int); 221 void scaleY(int); 222 void toggleTimeType(); 223 void addCtrlClicked(); 224 225 signals: 226 void posChanged(int, const AL::Pos&); // emitted from ruler 227 void cursorPos(const AL::Pos&, bool); 228 void contentsMoving(int, int); 229 void addMarker(const AL::Pos&); 230 void removeMarker(const AL::Pos&); 231 void pitchChanged(int); 232 void toolChanged(int); 233 234 public slots: 235 void setLocatorPos(int idx, const AL::Pos&, bool follow); 236 void setVSize(int); 237 virtual void setRaster(int); 238 void setYPos(int); 239 void moveY(int); 240 void setEndPos(const AL::Pos&); 241 void tempoChanged(); 242 void setTool(int); setFollow(bool val)243 void setFollow(bool val) { followPos = val; } 244 245 public: 246 TimeCanvas(TimeCanvasType = TIME_CANVAS); 247 void setTimeRange(const AL::Pos&, const AL::Pos&); 248 void setMag(double, double); xmag()249 double xmag() const { return _xmag; } ymag()250 double ymag() const { return _ymag; } 251 252 void setYMagRange(double, double); setYFit(bool val)253 void setYFit(bool val) { _yFit = val; } 254 getWPos()255 QPoint getWPos() const { return wpos; } widget()256 QWidget* widget() const { return _widget; } 257 void setWPos(const QPoint& p); 258 void setTimeType(AL::TType t); timeType()259 AL::TType timeType() const { return _timeType; } 260 void setMarkerList(AL::MarkerList*); 261 void setCornerWidget(QWidget* w); 262 void resizeController(int); raster()263 int raster() const { return _raster; } 264 265 AL::Pos pix2pos(int x) const; 266 int pos2pix(const AL::Pos&) const; verticalScrollBar()267 QScrollBar* verticalScrollBar() const { return vbar; } tool()268 Tool tool() const { return _tool; } 269 void setCanvasBackground(const QColor& color); 270 void setCanvasBackground(const QPixmap& pm); 271 updateCanvasB()272 void updateCanvasB() { _widget->update(rCanvasB); } updateRuler()273 void updateRuler() { _widget->update(rRuler); } 274 font1()275 QFont font1() const { return _font1; } font2()276 QFont font2() const { return _font2; } font3()277 QFont font3() const { return _font3; } 278 279 void setFont1(const QFont& f); 280 void setFont2(const QFont& f); 281 void setFont3(const QFont& f); 282 fontSize1()283 int fontSize1() const { return _font1.pointSize(); } fontSize2()284 int fontSize2() const { return _font2.pointSize(); } fontSize3()285 int fontSize3() const { return _font3.pointSize(); } setFontSize1(int val)286 void setFontSize1(int val) { _font1.setPointSize(val); } setFontSize2(int val)287 void setFontSize2(int val) { _font2.setPointSize(val); } setFontSize3(int val)288 void setFontSize3(int val) { _font3.setPointSize(val); } 289 290 static FollowMode followMode; 291 friend class CtrlEdit; 292 }; 293 294 #endif 295 296