annotate widgets/Panner.h @ 1534:bfd8b22fd67c

Fix #1904 Scrolling colour 3d plot does not always work when in View normalisation mode. We shouldn't imagine we've just invalidated the cache if the truth is that we've only just created the renderer
author Chris Cannam
date Wed, 09 Oct 2019 13:45:17 +0100
parents a18e78b9c78b
children
rev   line source
Chris@172 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@172 2
Chris@172 3 /*
Chris@172 4 Sonic Visualiser
Chris@172 5 An audio file viewer and annotation editor.
Chris@172 6 Centre for Digital Music, Queen Mary, University of London.
Chris@182 7 This file copyright 2006 QMUL.
Chris@172 8
Chris@172 9 This program is free software; you can redistribute it and/or
Chris@172 10 modify it under the terms of the GNU General Public License as
Chris@172 11 published by the Free Software Foundation; either version 2 of the
Chris@172 12 License, or (at your option) any later version. See the file
Chris@172 13 COPYING included with this distribution for more information.
Chris@172 14 */
Chris@172 15
Chris@1303 16 #ifndef SV_PANNER_H
Chris@1303 17 #define SV_PANNER_H
Chris@172 18
Chris@172 19 #include <QWidget>
Chris@172 20
Chris@1303 21 #include "WheelCounter.h"
Chris@1303 22
Chris@172 23 class Panner : public QWidget
Chris@172 24 {
Chris@172 25 Q_OBJECT
Chris@172 26
Chris@172 27 public:
Chris@172 28 Panner(QWidget *parent = 0);
Chris@172 29 virtual ~Panner();
Chris@172 30
Chris@173 31 void setDefaultRectCentre(float, float);
Chris@173 32
Chris@174 33 void setThumbColour(QColor colour);
Chris@174 34 void setAlpha(int backgroundAlpha, int thumbAlpha);
Chris@174 35
Chris@256 36 /**
Chris@256 37 * Set the amount the scroll() function or mouse wheel movement
Chris@256 38 * makes the panner rectangle move by. The default value of 0
Chris@256 39 * means to select a value automatically based on the dimensions
Chris@256 40 * of the panner rectangle.
Chris@256 41 */
Chris@256 42 void setScrollUnit(float unit);
Chris@256 43
Chris@188 44 void getRectExtents(float &x0, float &y0, float &width, float &height);
Chris@188 45
Chris@1406 46 QSize sizeHint() const override;
Chris@172 47
Chris@172 48 signals:
Chris@172 49 /**
Chris@172 50 * Emitted when the panned rectangle is dragged or otherwise
Chris@172 51 * moved. Arguments are x0, y0, width and height of the rectangle
Chris@172 52 * in the range 0 -> 1 as proportions of the width and height of
Chris@172 53 * the whole widget.
Chris@172 54 */
Chris@172 55 void rectExtentsChanged(float, float, float, float);
Chris@172 56
Chris@172 57 /**
Chris@172 58 * Emitted when the rectangle is dragged or otherwise moved (as
Chris@172 59 * well as extentsChanged). Arguments are the centre coordinates
Chris@172 60 * of the rectangle in the range 0 -> 1 as proportions of the
Chris@172 61 * width and height of the whole widget.
Chris@172 62 */
Chris@172 63 void rectCentreMoved(float, float);
Chris@172 64
Chris@188 65 /**
Chris@188 66 * Emitted when the panner is double-clicked (for the "customer"
Chris@188 67 * code to pop up a value editing dialog, for example).
Chris@188 68 */
Chris@188 69 void doubleClicked();
Chris@188 70
Chris@189 71 void mouseEntered();
Chris@189 72 void mouseLeft();
Chris@189 73
Chris@172 74 public slots:
Chris@172 75 /**
Chris@172 76 * Set the extents of the panned rectangle within the overall
Chris@172 77 * panner widget. Coordinates are in the range 0 -> 1 in both axes,
Chris@172 78 * with 0 at the top in the y axis.
Chris@172 79 */
Chris@172 80 void setRectExtents(float x0, float y0, float width, float height);
Chris@172 81
Chris@172 82 /**
Chris@172 83 * Set the width of the panned rectangle as a fraction (0 -> 1) of
Chris@172 84 * that of the whole panner widget.
Chris@172 85 */
Chris@172 86 void setRectWidth(float width);
Chris@172 87
Chris@172 88 /**
Chris@172 89 * Set the height of the panned rectangle as a fraction (0 -> 1)
Chris@172 90 * of that of the whole panner widget.
Chris@172 91 */
Chris@172 92 void setRectHeight(float height);
Chris@172 93
Chris@172 94 /**
Chris@172 95 * Set the location of the centre of the panned rectangle on the x
Chris@172 96 * axis, as a proportion (0 -> 1) of the width of the whole panner
Chris@172 97 * widget.
Chris@172 98 */
Chris@172 99 void setRectCentreX(float x);
Chris@172 100
Chris@172 101 /**
Chris@172 102 * Set the location of the centre of the panned rectangle on the y
Chris@172 103 * axis, as a proportion (0 -> 1) of the height of the whole panner
Chris@172 104 * widget.
Chris@172 105 */
Chris@172 106 void setRectCentreY(float y);
Chris@172 107
Chris@256 108 /**
Chris@256 109 * Move up (if up is true) or down a bit. This is basically the
Chris@256 110 * same action as rolling the mouse wheel one notch.
Chris@256 111 */
Chris@256 112 void scroll(bool up);
Chris@256 113
Chris@1303 114 /**
Chris@1303 115 * Move up (if up is true) or down a bit. This is basically the
Chris@1303 116 * same action as rolling the mouse wheel n notches.
Chris@1303 117 */
Chris@1303 118 void scroll(bool up, int n);
Chris@1303 119
Chris@188 120 void resetToDefault();
Chris@188 121
Chris@172 122 protected:
Chris@1406 123 void mousePressEvent(QMouseEvent *e) override;
Chris@1406 124 void mouseDoubleClickEvent(QMouseEvent *e) override;
Chris@1406 125 void mouseMoveEvent(QMouseEvent *e) override;
Chris@1406 126 void mouseReleaseEvent(QMouseEvent *e) override;
Chris@1406 127 void wheelEvent(QWheelEvent *e) override;
Chris@1406 128 void paintEvent(QPaintEvent *e) override;
Chris@1406 129 void enterEvent(QEvent *) override;
Chris@1406 130 void leaveEvent(QEvent *) override;
Chris@189 131
Chris@172 132 void normalise();
Chris@172 133 void emitAndUpdate();
Chris@172 134
Chris@172 135 float m_rectX;
Chris@172 136 float m_rectY;
Chris@172 137 float m_rectWidth;
Chris@172 138 float m_rectHeight;
Chris@256 139 float m_scrollUnit;
Chris@173 140
Chris@173 141 float m_defaultCentreX;
Chris@173 142 float m_defaultCentreY;
Chris@173 143 bool m_defaultsSet;
Chris@173 144
Chris@174 145 QColor m_thumbColour;
Chris@174 146 int m_backgroundAlpha;
Chris@174 147 int m_thumbAlpha;
Chris@174 148
Chris@173 149 float centreX() const { return m_rectX + m_rectWidth/2; }
Chris@173 150 float centreY() const { return m_rectY + m_rectHeight/2; }
Chris@173 151
Chris@173 152 bool m_clicked;
Chris@173 153 QPoint m_clickPos;
Chris@173 154 float m_dragStartX;
Chris@173 155 float m_dragStartY;
Chris@1303 156
Chris@1303 157 WheelCounter m_wheelCounter;
Chris@172 158 };
Chris@172 159
Chris@172 160 #endif
Chris@172 161