1 /*************************************************************************** 2 ** ** 3 ** Polyphone, a soundfont editor ** 4 ** Copyright (C) 2013-2020 Davy Triponney ** 5 ** ** 6 ** This program is free software: you can redistribute it and/or modify ** 7 ** it under the terms of the GNU General Public License as published by ** 8 ** the Free Software Foundation, either version 3 of the License, or ** 9 ** (at your option) any later version. ** 10 ** ** 11 ** This program is distributed in the hope that it will be useful, ** 12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** 13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** 14 ** GNU General Public License for more details. ** 15 ** ** 16 ** You should have received a copy of the GNU General Public License ** 17 ** along with this program. If not, see http://www.gnu.org/licenses/. ** 18 ** ** 19 **************************************************************************** 20 ** Author: Davy Triponney ** 21 ** Website/Contact: https://www.polyphone-soundfonts.com ** 22 ** Date: 01.01.2013 ** 23 ***************************************************************************/ 24 25 #ifndef GRAPHICSVIEWRANGE_H 26 #define GRAPHICSVIEWRANGE_H 27 28 #include <QGraphicsView> 29 #include "soundfontmanager.h" 30 #include <QMap> 31 #include "basetypes.h" 32 class GraphicsSimpleTextItem; 33 class GraphicsRectangleItem; 34 class GraphicsLegendItem; 35 class GraphicsLegendItem2; 36 class GraphicsZoomLine; 37 class GraphicsKey; 38 39 class GraphicsViewRange : public QGraphicsView 40 { 41 Q_OBJECT 42 43 public: 44 explicit GraphicsViewRange(QWidget *parent = nullptr); 45 ~GraphicsViewRange(); 46 47 void display(IdList ids, bool justSelection); 48 void playKey(int key, int velocity); 49 50 signals: 51 void updateKeyboard(); 52 void divisionsSelected(IdList divisions); 53 54 protected: 55 void resizeEvent(QResizeEvent * event); 56 void mousePressEvent(QMouseEvent *event); 57 void mouseReleaseEvent(QMouseEvent *event); 58 void mouseMoveEvent(QMouseEvent *event); 59 void wheelEvent(QWheelEvent * event); mouseDoubleClickEvent(QMouseEvent *)60 void mouseDoubleClickEvent(QMouseEvent *) {} 61 void scrollContentsBy(int dx, int dy); 62 63 private: 64 void initItems(); 65 void updateLabelPosition(); 66 void updateHover(QPoint mousePos); 67 QList<QList<GraphicsRectangleItem*> > getRectanglesUnderMouse(QPoint mousePos); 68 QRectF getCurrentRect(); 69 void triggerDivisionSelected(); 70 71 SoundfontManager * _sf2; 72 EltID _defaultID; 73 74 // Graphics items 75 QGraphicsScene * _scene; 76 QList<GraphicsRectangleItem *> _rectangles; 77 QList<GraphicsSimpleTextItem *> _leftLabels, _bottomLabels; 78 GraphicsLegendItem * _legendItem; 79 GraphicsLegendItem2 * _legendItem2; 80 GraphicsZoomLine * _zoomLine; 81 QMap<int, GraphicsKey*> _mapGraphicsKeys; 82 QList<QGraphicsLineItem *> _keyLines; 83 84 // Various 85 bool _dontRememberScroll; 86 int _keyTriggered; 87 bool _keepIndexOnRelease; 88 bool _editing; 89 90 // Drag & zoom 91 Qt::MouseButton _buttonPressed; 92 bool _moveOccured; 93 double _xInit, _yInit; 94 double _zoomX, _zoomY, _posX, _posY; 95 double _zoomXinit, _zoomYinit, _posXinit, _posYinit; 96 QRectF _displayedRect; 97 QVector<GraphicsRectangleItem *> _shiftRectangles; 98 void zoom(QPoint point); 99 void drag(QPoint point); 100 void zoomDrag(); 101 void setZoomLine(double x1Norm, double y1Norm, double x2Norm, double y2Norm); 102 double normalizeX(int xPixel); 103 double normalizeY(int yPixel); 104 105 static const double WIDTH; 106 static const double MARGIN; 107 static const double OFFSET; 108 QColor _lineColor; 109 QColor _textColor; 110 }; 111 112 #endif // GRAPHICSVIEWRANGE_H 113