#include "window.h"
amplitudeP = 10.0;
ampliSliderPosP = 0;
renderGroupBox
= new QGroupBox("Wykresy",
this);
optionsGroupBox
= new QGroupBox("Opcje",
this);
oscylo = new Oscyloscop(this);
mightGraph = new SignalMight(this);
oscylo->setRenderAreaSize(400 , 400);
oscylo->resizeRenderArea();
mightGraph->setRenderAreaSize(400, 150);
mightGraph->resizeRenderArea();
renderLay->addWidget(oscylo);
renderLay->addWidget(mightGraph);
renderGroupBox->setLayout(renderLay);
ampliSilder
= new QSlider(Qt
::Horizontal,
this);
optionsLay->addWidget(ampliSilder);
optionsGroupBox->setLayout(optionsLay);
mainLay->addWidget(renderGroupBox);
mainLay->addWidget(optionsGroupBox);
setLayout(mainLay);
connect(ampliSilder, SIGNAL(valueChanged(int)), this, SLOT(changeAmplitude(int)));
connect(this, SIGNAL(amplitudeChanget(double)), oscylo, SLOT(reciveAmplitude(double)));
}
Window::~Window(){
delete mainLay;
delete renderLay;
delete optionsLay;
delete oscylo;
delete mightGraph;
}
void Window::changeAmplitude(int _pos)
{
if(_pos > ampliSliderPosP)
amplitudeP += 10.0;
else
amplitudeP -=10.0;
ampliSliderPosP = _pos;
emit amplitudeChanget(amplitudeP);
}
{
qDebug("update okna glownego");
}
#include "window.h"
Window::Window(QWidget *parent) : QWidget(parent){
amplitudeP = 10.0;
ampliSliderPosP = 0;
mainLay = new QHBoxLayout;
renderLay = new QVBoxLayout;
optionsLay = new QVBoxLayout;
renderGroupBox = new QGroupBox("Wykresy", this);
optionsGroupBox = new QGroupBox("Opcje", this);
oscylo = new Oscyloscop(this);
mightGraph = new SignalMight(this);
oscylo->setRenderAreaSize(400 , 400);
oscylo->resizeRenderArea();
mightGraph->setRenderAreaSize(400, 150);
mightGraph->resizeRenderArea();
renderLay->addWidget(oscylo);
renderLay->addWidget(mightGraph);
renderGroupBox->setLayout(renderLay);
ampliSilder = new QSlider(Qt::Horizontal, this);
optionsLay->addWidget(ampliSilder);
optionsGroupBox->setLayout(optionsLay);
mainLay->addWidget(renderGroupBox);
mainLay->addWidget(optionsGroupBox);
setLayout(mainLay);
connect(ampliSilder, SIGNAL(valueChanged(int)), this, SLOT(changeAmplitude(int)));
connect(this, SIGNAL(amplitudeChanget(double)), oscylo, SLOT(reciveAmplitude(double)));
}
Window::~Window(){
delete mainLay;
delete renderLay;
delete optionsLay;
delete oscylo;
delete mightGraph;
}
void Window::changeAmplitude(int _pos)
{
if(_pos > ampliSliderPosP)
amplitudeP += 10.0;
else
amplitudeP -=10.0;
ampliSliderPosP = _pos;
emit amplitudeChanget(amplitudeP);
}
void Window::paintEvent(QPaintEvent *)
{
qDebug("update okna glownego");
}
To copy to clipboard, switch view to plain text mode
#include "oscyloscop.h"
Oscyloscop
::Oscyloscop(QWidget* parent
) : RenderArea
(parent
){
nullCordP = new Point2D(100, 900);
xEndP = new Point2D(900, 900);
yEndP = new Point2D(100, 100);
signal = new Signal();
amplitudeP = 10.0;
}
Oscyloscop::~Oscyloscop(){
delete nullCordP;
delete xEndP;
delete yEndP;
}
void Oscyloscop::drawCoordSystem(QPen& _pen, QPainter& _painter){
_painter.drawLine(100, 900, 900, 900);
_painter.drawLine(100, 100, 100, 900);
_painter.
setFont(QFont("Tahoma",
25));
_painter.drawText(nullCordP->x-6, nullCordP->y+45, "0");
_painter.drawText(450, 980, "Czas [t]");
int xDrawPoint = 260;
int yDrawPoint = 740;
_pen.setWidth(5);
_painter.setPen(_pen);
for(int i = 0; i < 5; i++){
_painter.drawLine(xDrawPoint, nullCordP->y, xDrawPoint, nullCordP->y+10);
_painter.drawLine(nullCordP->x-10, yDrawPoint, nullCordP->x, yDrawPoint);
xDrawPoint += 160;
yDrawPoint -= 160;
}
_pen.setStyle(Qt::DotLine);
_pen.setWidth(3);
_painter.setPen(_pen);
xDrawPoint = 260;
yDrawPoint = 740;
for(int i = 0; i < 5; i++){
_painter.drawLine(xDrawPoint, nullCordP->y, xDrawPoint, nullCordP->y-800);
_painter.drawLine(nullCordP->x, yDrawPoint, nullCordP->x+800, yDrawPoint);
xDrawPoint += 160;
yDrawPoint -= 160;
}
setNumX(2);
float divX = retXscaleDigit().toFloat() / 5.0;
float divXconst = divX;
xDrawPoint = 260;
for(int i = 0; i < 5; i++){
xPrintNum.setNum(divX);
_painter.drawText(xDrawPoint-6, nullCordP->y+45, xPrintNum);
divX += divXconst;
xDrawPoint += 160;
}
nullCordP->x = 100;
}
void Oscyloscop::drawGraph(QPen& _pen, QPainter& _painter){
_pen.setStyle(Qt::SolidLine);
_pen.setColor(Qt::black);
_pen.setWidth(3);
_painter.setPen(_pen);
samples = signal->generateSignalSin(800, amplitudeP, 5.0, Signal::SIN_2PI5);
for(int i = 0 ; i < 800 ; ++i)
{
_painter.drawPoint(nullCordP->x, 500 + (samples[i] + 10));
++nullCordP->x;
}
nullCordP->x = 100;
}
pen.setWidth(10);
pen.
setColor(QColor::fromRgb(104,
104,
104,
100));
pen.setStyle(Qt::SolidLine);
painter.setPen(pen);
painter.
setRenderHint(QPainter::Antialiasing);
matrix.scale( retWidth() / 1000.0 , retHeight() / 1000.0 );
painter.setMatrix(matrix);
drawCoordSystem(pen, painter);
drawGraph(pen, painter);
qDebug("update oscyloscopu");
}
void Oscyloscop::reciveAmplitude(double _a)
{
amplitudeP = _a;
update();
}
#include "oscyloscop.h"
Oscyloscop::Oscyloscop(QWidget* parent) : RenderArea(parent)
{
nullCordP = new Point2D(100, 900);
xEndP = new Point2D(900, 900);
yEndP = new Point2D(100, 100);
signal = new Signal();
amplitudeP = 10.0;
}
Oscyloscop::~Oscyloscop(){
delete nullCordP;
delete xEndP;
delete yEndP;
}
void Oscyloscop::drawCoordSystem(QPen& _pen, QPainter& _painter){
_painter.drawLine(100, 900, 900, 900);
_painter.drawLine(100, 100, 100, 900);
_painter.setFont(QFont("Tahoma", 25));
_painter.drawText(nullCordP->x-6, nullCordP->y+45, "0");
_painter.drawText(450, 980, "Czas [t]");
int xDrawPoint = 260;
int yDrawPoint = 740;
_pen.setWidth(5);
_painter.setPen(_pen);
for(int i = 0; i < 5; i++){
_painter.drawLine(xDrawPoint, nullCordP->y, xDrawPoint, nullCordP->y+10);
_painter.drawLine(nullCordP->x-10, yDrawPoint, nullCordP->x, yDrawPoint);
xDrawPoint += 160;
yDrawPoint -= 160;
}
_pen.setStyle(Qt::DotLine);
_pen.setWidth(3);
_painter.setPen(_pen);
xDrawPoint = 260;
yDrawPoint = 740;
for(int i = 0; i < 5; i++){
_painter.drawLine(xDrawPoint, nullCordP->y, xDrawPoint, nullCordP->y-800);
_painter.drawLine(nullCordP->x, yDrawPoint, nullCordP->x+800, yDrawPoint);
xDrawPoint += 160;
yDrawPoint -= 160;
}
setNumX(2);
float divX = retXscaleDigit().toFloat() / 5.0;
float divXconst = divX;
QString xPrintNum;
xDrawPoint = 260;
for(int i = 0; i < 5; i++){
xPrintNum.setNum(divX);
_painter.drawText(xDrawPoint-6, nullCordP->y+45, xPrintNum);
divX += divXconst;
xDrawPoint += 160;
}
nullCordP->x = 100;
}
void Oscyloscop::drawGraph(QPen& _pen, QPainter& _painter){
_pen.setStyle(Qt::SolidLine);
_pen.setColor(Qt::black);
_pen.setWidth(3);
_painter.setPen(_pen);
samples = signal->generateSignalSin(800, amplitudeP, 5.0, Signal::SIN_2PI5);
for(int i = 0 ; i < 800 ; ++i)
{
_painter.drawPoint(nullCordP->x, 500 + (samples[i] + 10));
++nullCordP->x;
}
nullCordP->x = 100;
}
void Oscyloscop::paintEvent(QPaintEvent* _p){
QPainter painter(this);
QPen pen;
QMatrix matrix;
pen.setWidth(10);
pen.setColor(QColor::fromRgb(104, 104, 104, 100));
pen.setStyle(Qt::SolidLine);
painter.setPen(pen);
painter.setRenderHint(QPainter::Antialiasing);
matrix.scale( retWidth() / 1000.0 , retHeight() / 1000.0 );
painter.setMatrix(matrix);
drawCoordSystem(pen, painter);
drawGraph(pen, painter);
qDebug("update oscyloscopu");
}
void Oscyloscop::reciveAmplitude(double _a)
{
amplitudeP = _a;
update();
}
To copy to clipboard, switch view to plain text mode
and here i make y values for the graph
QVector<int> Signal::generateSignalSin(int _period, double _amplitude, double _freq, int _type)
{
double tmp;
switch(_type)
{
case SIN_2PI5:
for(int x = 0 ; x < _period ; ++x)
{
tmp = _amplitude * sin(x * 2.0 * 3.14 * _freq);
str.setNum(tmp);
strList = str.split(".");
str = strList.last();
str.resize(4);
int mod = str.toInt();
if( tmp > 0)
{
if(mod > 5000)
y = ceil(tmp);
else
y = floor(tmp);
}
else
{
if(mod > 5000)
y = floor(tmp);
else
y = ceil(tmp);
}
samples.push_back(y);
}
break;
case SIN_2PI5_2PI10:
break;
case SIN_2PI5_02_2PI25:
break;
}// end of switch
return samples;
}
QVector<int> Signal::generateSignalSin(int _period, double _amplitude, double _freq, int _type)
{
double tmp;
QString str;
QStringList strList;
switch(_type)
{
case SIN_2PI5:
for(int x = 0 ; x < _period ; ++x)
{
tmp = _amplitude * sin(x * 2.0 * 3.14 * _freq);
str.setNum(tmp);
strList = str.split(".");
str = strList.last();
str.resize(4);
int mod = str.toInt();
if( tmp > 0)
{
if(mod > 5000)
y = ceil(tmp);
else
y = floor(tmp);
}
else
{
if(mod > 5000)
y = floor(tmp);
else
y = ceil(tmp);
}
samples.push_back(y);
}
break;
case SIN_2PI5_2PI10:
break;
case SIN_2PI5_02_2PI25:
break;
}// end of switch
return samples;
}
To copy to clipboard, switch view to plain text mode
Bookmarks