Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[99b84b]: libgui / FaderWidget.cpp Maximize Restore History

Download this file

FaderWidget.cpp    106 lines (90 with data), 2.4 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
#include <stdio.h>
#include <stdlib.h>
#include <qkeycode.h>
#include <qpainter.h>
#include <math.h>
#include <limits.h>
#include <libkwave/String.h>
#include "FaderWidget.h"
//****************************************************************************
FaderWidget::FaderWidget(QWidget *parent, int dir)
:QWidget(parent)
{
comstr = 0;
curve = 0;
this->dir = dir;
height = -1;
width = 0;
setBackgroundColor(QColor(black));
}
//****************************************************************************
FaderWidget::~FaderWidget()
{
if (comstr) delete comstr;
}
//****************************************************************************
void FaderWidget::setCurve(int c)
{
curve = c * c * c;
repaint ();
}
//****************************************************************************
const char *FaderWidget::getDegree()
{
char buf[128];
deleteString (comstr);
snprintf(buf, sizeof(buf), "%f", ((float) (curve)) / 10);
comstr = duplicateString(buf);
return comstr;
}
//****************************************************************************
void FaderWidget::paintEvent (QPaintEvent *)
{
QPainter p;
height = rect().height();
width = rect().width();
ASSERT(width);
if (!width) return;
p.begin (this);
p.setPen (white);
int lx = (dir == 1) ? 0 : width;
int ly = height;
if (curve == 0) {
for (int i = 1; i < width; i++) {
if (dir == 1) {
p.drawLine (lx, ly, i, (width - i)*height / width);
lx = i;
} else {
p.drawLine (lx, ly, width - i, (width - i)*height / width);
lx = width - i;
}
ly = (width - i) * height / width;
}
} else
if (curve < 0)
for (int i = 1; i < width; i++) {
int y = height - (int)(log10(1 + ( -curve * ((double)i) / width)) * height / log10(1 - curve));
if (dir == 1) {
p.drawLine (lx, ly, i, y);
lx = i;
} else {
p.drawLine (lx, ly, width - i, y);
lx = width - i;
}
ly = y;
}
else
for (int i = 1; i < width; i++) {
int y = (int)(log10(1 + (curve * ((double)(width - i)) / width)) * height / log10(1 + curve));
if (dir == 1) {
p.drawLine (lx, ly, i, y);
lx = i;
} else {
p.drawLine (lx, ly, width - i, y);
lx = width - i;
}
ly = y;
}
p.end();
}
//****************************************************************************