[3e4acc]: libgui / CurveWidget.h Maximize Restore History

Download this file

CurveWidget.h    168 lines (126 with data), 4.7 kB

  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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/***************************************************************************
CurveWidget.h - widget for editing an interpolated curve
-------------------
begin : Sep 16 2001
copyright : (C) 2001 by Thomas Eschenbacher
email : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef _CURVE_WIDGET_H_
#define _CURVE_WIDGET_H_
#include "config.h"
#include <QMenu>
#include <QString>
#include <QWidget>
#include <kdemacros.h>
#include "libkwave/Curve.h"
#include "libkwave/Interpolation.h"
class QAction;
class QMouseEvent;
class QPaintEvent;
class QPixmap;
class KDE_EXPORT CurveWidget: public QWidget
{
Q_OBJECT
public:
/** Constructor */
CurveWidget(QWidget *parent);
/** Destructor */
virtual ~CurveWidget();
/** Returns a command string for the curve. */
QString getCommand();
/** Sets the curve parameters/points from a command string. */
void setCurve(const QString &command);
/**
* Adds a new point to the curve.
* @param x the point's x coordinate, should be [0.0...1.0]
* @param y the point's y coordinate, should be [0.0...1.0]
*/
void addPoint(double x, double y);
/**
* Tries to find a point that is nearest to the given widget coordinates
* and within a tolerance.
* @param sx screen x coordinate, left is 0
* @param sy screen y coordinate, top is 0
* @return the point of the curve or Curve::NoPoint if nothing found
*/
Curve::Point findPoint(int sx, int sy);
public slots:
/**
* Selects a new interpolation type by it's numeric index. Used from the
* mouse context menu.
*/
void selectInterpolationType(QAction *action);
/**
* Scales the size of the curve so that all interpolated points are
* between 0.0 and 1.0 in x and y direction.
*/
void scaleFit();
/** Mirrors the curve on the y axis */
void VFlip();
/** Mirrors the curve on the y axis */
void HFlip();
/** Deletes the last point of the curve. */
void deleteLast();
/** Deletes the every second (even) point of the curve. */
void deleteSecond();
/**
* Scales the x coordinates of all points to 50% so that the curve's
* points move into the first half of the curve. A new "last" point
* with the y value of the previous last point will be inserted at
* x coordinate 1.0.
*/
void firstHalf();
/** Like firstHalf(), but moves points to the right half. */
void secondHalf();
void savePreset();
/**
* Loads an existing preset.
* @param action the menu actio of the corresponding menu entry
*/
void loadPreset(QAction *action);
protected slots:
void mousePressEvent(QMouseEvent * );
void mouseReleaseEvent(QMouseEvent * );
void mouseMoveEvent(QMouseEvent * );
void paintEvent(QPaintEvent *);
protected:
/**
* (Re-)Loads the list of preset files and fills the popup
* menu with all preset files.
*/
void loadPresetList();
private:
/** Cached width of the widget */
int m_width;
/** Cached height of the widget */
int m_height;
/** The curve to be edited */
Curve m_curve;
/** Popup (context) menu for the right mouse button */
QMenu *m_menu;
/**
* Part of the popup (context) menu for the right
* mouse button with the list of preset files
*/
QMenu *m_preset_menu;
/** Currently selected point or null if none selected */
Curve::Point m_current;
/** Last selected point, remembered for deleting. */
Curve::Point m_last;
/** State of the left mouse button (when moving points) */
bool m_down;
/** pixmap for the unselected knob */
QPixmap m_knob;
/** pixmap for the selected knob */
QPixmap m_selected_knob;
};
//***********************************************************************
#endif // _CURVE_WIDGET_H_