#include "fluxocaixawidget.h"
#include <QDebug>
fluxoCaixaWidget
::fluxoCaixaWidget(QWidget *parent
) :{
linhaTempo.setRect(20, 100, 700, 30);
this->setMouseTracking(true);
dentro = false;
fluxo = NULL;
}
{
//linhaTempo.setRect(20, this->parentWidget()->height() / 2 - 20, this->parentWidget()->width()-65, 30);
//linhaTempo.setRect(20, this->parentWidget()->rect().height() / 2 - 20, this->parentWidget()->rect().width()-65, 30);
painter.setBrush(pincel);
//painter.drawRect(parentWidget()->rect());
painter.drawRect(0,0,800,600);
if(this->dentro == true)
{
caneta.setWidth(3);
}
else
{
caneta.setWidth(2);
}
painter.setPen(caneta);
painter.drawRect(linhaTempo);
if(fluxo != NULL)
{
for(int i = 0; i < fluxo->count(); i++)
{
if(fluxo->at(i) < 0)
{
caneta.setColor(Qt::red);
}
else
{
if(fluxo->at(i) == 0)
{
caneta.setColor(Qt::black);
}
else
{
if(fluxo->at(i) > 0)
{
caneta.setColor(Qt::blue);
}
}
}
if(fluxoDentro.at(i) == true)
{
caneta.setWidth(3);
}
else
{
caneta.setWidth(2);
}
painter.setPen(caneta);
painter.drawRect(fluxoRect.at(i));
}
}
}
{
if(linhaTempo.
contains(this
->mapFromGlobal
(QCursor::pos()))) {
dentro = true;
}
else
{
dentro = false;
}
for(int i = 0; i < fluxoRect.count(); i++)
{
if(fluxoRect.
at(i
).
contains(this
->mapFromGlobal
(QCursor::pos()))) {
fluxoDentro.insert(i, true);
dentro = false;
}
else
{
fluxoDentro.insert(i, false);
}
}
this->update();
}
void fluxoCaixaWidget::setFluxo(QList<double> *f)
{
fluxo = f;
fluxoRect.clear();
fluxoDentro.clear();
int espacamento = 0;
if(fluxo->count() > 1)
{
espacamento = linhaTempo.width() / (fluxo->count() - 1);
}
for(int i = 0; i < fluxo->count(); i++)
{
if(i == 0)
{
//fluxoRect.append(QRect(20, this->parentWidget()->height() / 2 - 20, 10, 50));
fluxoRect.
append(QRect(20, linhaTempo.
y(),
10,
50));
fluxoDentro.append(false);
}
else
{
//fluxoRect.append(QRect(20 + espacamento * i, this->parentWidget()->height() / 2 - 20, 10, 50));
fluxoRect.
append(QRect(20 + espacamento
* i, linhaTempo.
y(),
10,
50));
fluxoDentro.append(false);
}
}
this->update();
}
#include "fluxocaixawidget.h"
#include <QDebug>
fluxoCaixaWidget::fluxoCaixaWidget(QWidget *parent) :
QWidget(parent)
{
linhaTempo.setRect(20, 100, 700, 30);
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
this->setMouseTracking(true);
dentro = false;
fluxo = NULL;
}
void fluxoCaixaWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
//linhaTempo.setRect(20, this->parentWidget()->height() / 2 - 20, this->parentWidget()->width()-65, 30);
//linhaTempo.setRect(20, this->parentWidget()->rect().height() / 2 - 20, this->parentWidget()->rect().width()-65, 30);
QPen caneta;
QBrush pincel(Qt::white);
painter.setBrush(pincel);
//painter.drawRect(parentWidget()->rect());
painter.drawRect(0,0,800,600);
if(this->dentro == true)
{
painter.drawText(QRect(20, 15, linhaTempo.width(), 25), "Linha do tempo", QTextOption::QTextOption(Qt::AlignCenter));
caneta.setWidth(3);
}
else
{
caneta.setWidth(2);
}
painter.setPen(caneta);
painter.drawRect(linhaTempo);
if(fluxo != NULL)
{
for(int i = 0; i < fluxo->count(); i++)
{
if(fluxo->at(i) < 0)
{
caneta.setColor(Qt::red);
}
else
{
if(fluxo->at(i) == 0)
{
caneta.setColor(Qt::black);
}
else
{
if(fluxo->at(i) > 0)
{
caneta.setColor(Qt::blue);
}
}
}
if(fluxoDentro.at(i) == true)
{
QString valor = QString::number(fluxo->at(i));
painter.drawText(QRect(20, 15, linhaTempo.width(), 25), valor, QTextOption::QTextOption(Qt::AlignCenter));
caneta.setWidth(3);
}
else
{
caneta.setWidth(2);
}
painter.setPen(caneta);
painter.drawRect(fluxoRect.at(i));
}
}
}
void fluxoCaixaWidget::mouseMoveEvent(QMouseEvent *)
{
if(linhaTempo.contains(this->mapFromGlobal(QCursor::pos())))
{
dentro = true;
}
else
{
dentro = false;
}
for(int i = 0; i < fluxoRect.count(); i++)
{
if(fluxoRect.at(i).contains(this->mapFromGlobal(QCursor::pos())))
{
fluxoDentro.insert(i, true);
dentro = false;
}
else
{
fluxoDentro.insert(i, false);
}
}
this->update();
}
void fluxoCaixaWidget::setFluxo(QList<double> *f)
{
fluxo = f;
fluxoRect.clear();
fluxoDentro.clear();
int espacamento = 0;
if(fluxo->count() > 1)
{
espacamento = linhaTempo.width() / (fluxo->count() - 1);
}
for(int i = 0; i < fluxo->count(); i++)
{
if(i == 0)
{
//fluxoRect.append(QRect(20, this->parentWidget()->height() / 2 - 20, 10, 50));
fluxoRect.append(QRect(20, linhaTempo.y(), 10, 50));
fluxoDentro.append(false);
}
else
{
//fluxoRect.append(QRect(20 + espacamento * i, this->parentWidget()->height() / 2 - 20, 10, 50));
fluxoRect.append(QRect(20 + espacamento * i, linhaTempo.y(), 10, 50));
fluxoDentro.append(false);
}
}
this->update();
}
To copy to clipboard, switch view to plain text mode
Bookmarks