#ifndef INCLUDED_AUDIOCHART_H
#define INCLUDED_AUDIOCHART_H
#include <qcanvas.h>
class AudioChart : protected QCanvasView {
Q_OBJECT
public:
AudioChart
( QWidget *parent,
const char *name
);
void drawContents
( QPainter * p,
int cx,
int cy,
int cw,
int ch
);
private:
QCanvas* myCanvas;
int border;
};
#endif
#ifndef INCLUDED_AUDIOCHART_H
#define INCLUDED_AUDIOCHART_H
#include <qcanvas.h>
class AudioChart : protected QCanvasView {
Q_OBJECT
public:
AudioChart( QWidget *parent, const char *name );
void drawContents ( QPainter * p, int cx, int cy, int cw, int ch );
private:
QCanvas* myCanvas;
int border;
};
#endif
To copy to clipboard, switch view to plain text mode
#include "audiochart.h"
#include <qpainter.h>
#include "guicommonhelper.h"
#include <iostream>
AudioChart
::AudioChart( QWidget *parent
=0,
const char *name
=0 ) : QCanvasView
::QCanvasView( parent, name
) { //QLabel* tmp = new QLabel( "implement me", parent );
this->myCanvas = new QCanvas( this, "" );
this->setCanvas( this->myCanvas );
this
->myCanvas
->setBackgroundColor
( QColor( 255,
255,
255 ) );
this->border = 10;
this->setVScrollBarMode( QScrollView::AlwaysOff );
this->setHScrollBarMode( QScrollView::AlwaysOff );
//this->myCanvas->setDoubleBuffering( false );
}
void AudioChart
::drawContents( QPainter * p,
int cx,
int cy,
int cw,
int ch
) { this->myCanvas->resize(this->visibleWidth(), this->visibleHeight());
p->setClipping( false );
p->setPen( pen );
p->fillRect( 0, 0, this->myCanvas->width(), this->myCanvas->height(), brush );
char tmpString[255];
p->setPen( pen );
p->drawLine( 20, 50, 50, 20 );
p->setFont( font );
int w, h, x, y;
int max = 10;
int offsetXAxis = 10;
int totalWidth = this->myCanvas->width() - 2*this->border - 10 - offsetXAxis;
int totalHeight = this->myCanvas->height() - 2*this->border;
std::cout<<"w "<<totalWidth<<" h "<<totalHeight<<std::endl;
std::cout<<"-"<<std::endl;
for (int i = 0; i <= max; i++) {
w = fm->width(string);
h = fm->height();
x = totalWidth*i/max + this->border + offsetXAxis;
y = totalHeight + this->border;
std::cout<<i<<": x "<<x<<" y "<<y<<std::endl;
p->drawText( x, y, string );
//p->drawRect( x, y-h, w, h );
p->drawLine( x+w/2-1, y-h, x+w/2-1, y-h-2 );
}
std::cout<<"-"<<std::endl;
p->flush();
this->myCanvas->setAllChanged();
this->update();
}
#include "audiochart.h"
#include <qpainter.h>
#include "guicommonhelper.h"
#include <iostream>
AudioChart::AudioChart( QWidget *parent=0, const char *name=0 ) : QCanvasView::QCanvasView( parent, name ) {
//QLabel* tmp = new QLabel( "implement me", parent );
this->myCanvas = new QCanvas( this, "" );
this->setCanvas( this->myCanvas );
this->myCanvas->setBackgroundColor( QColor( 255, 255, 255 ) );
this->border = 10;
this->setVScrollBarMode( QScrollView::AlwaysOff );
this->setHScrollBarMode( QScrollView::AlwaysOff );
//this->myCanvas->setDoubleBuffering( false );
}
void AudioChart::drawContents( QPainter * p, int cx, int cy, int cw, int ch ) {
this->myCanvas->resize(this->visibleWidth(), this->visibleHeight());
QPen pen = QPen( white, 0 );
QBrush brush = QBrush( white );
p->setClipping( false );
p->setPen( pen );
p->fillRect( 0, 0, this->myCanvas->width(), this->myCanvas->height(), brush );
pen = QPen( black, 1 );
QFont font = QFont( "Helvetica [Cronyx]", 8 );
QFontMetrics* fm = new QFontMetrics( font );
char tmpString[255];
p->setPen( pen );
p->drawLine( 20, 50, 50, 20 );
p->setFont( font );
int w, h, x, y;
int max = 10;
int offsetXAxis = 10;
int totalWidth = this->myCanvas->width() - 2*this->border - 10 - offsetXAxis;
int totalHeight = this->myCanvas->height() - 2*this->border;
std::cout<<"w "<<totalWidth<<" h "<<totalHeight<<std::endl;
std::cout<<"-"<<std::endl;
for (int i = 0; i <= max; i++) {
QString string = QString(intToChar(tmpString, i*3823/max));
w = fm->width(string);
h = fm->height();
x = totalWidth*i/max + this->border + offsetXAxis;
y = totalHeight + this->border;
std::cout<<i<<": x "<<x<<" y "<<y<<std::endl;
p->drawText( x, y, string );
//p->drawRect( x, y-h, w, h );
p->drawLine( x+w/2-1, y-h, x+w/2-1, y-h-2 );
}
std::cout<<"-"<<std::endl;
p->flush();
this->myCanvas->setAllChanged();
this->update();
}
To copy to clipboard, switch view to plain text mode
Bookmarks