Exemplo n.º 1
0
void CPlotter::draw(float swide[], int i0)             //draw()
{
  int j,y2;
  float y;

  m_i0=i0;
  double gain = pow(10.0,0.05*(m_plotGain+7));

//move current data down one line (must do this before attaching a QPainter object)
  m_WaterfallPixmap.scroll(0,1,0,0,m_w,m_h1);
  QPainter painter1(&m_WaterfallPixmap);
  m_2DPixmap = m_OverlayPixmap.copy(0,0,m_w,m_h2);
  QPainter painter2D(&m_2DPixmap);

  painter2D.setPen(Qt::green);

  QPoint LineBuf[MAX_SCREENSIZE];
  j=0;

//  int iz=XfromFreq(2000.0);
  int iz=XfromFreq(5000.0);
  m_fMax=FreqfromX(iz);
  for(int i=0; i<iz; i++) {
    if(i>iz) swide[i]=0;
    y=0.0;
    if(swide[i]>0.0) y = 10.0*log10(swide[i]);
    int y1 = 5.0*gain*y + 10*(m_plotZero-4);
    if (y1<0) y1=0;
    if (y1>254) y1=254;
    if (swide[i]>1.e29) y1=255;
    painter1.setPen(m_ColorTbl[y1]);
    painter1.drawPoint(i,0);
    y2=0;
    if(m_bCurrent) y2 = 0.4*gain*y - 15;
    if(m_bCumulative) {
      float sum=0.0;
      int j=m_binsPerPixel*i;
      for(int k=0; k<m_binsPerPixel; k++) {
        sum+=jt9com_.savg[j++];
      }
      y2=gain*6.0*log10(sum/m_binsPerPixel) - 10.0;
    }
    y2 += m_plotZero;
    if(i==iz-1) painter2D.drawPolyline(LineBuf,j);
    LineBuf[j].setX(i);
    LineBuf[j].setY(m_h-(y2+0.8*m_h));
    j++;
  }

  if(swide[0]>1.0e29) m_line=0;
  m_line++;
  if(m_line == 13) {
    UTCstr();
    painter1.setPen(Qt::white);
    painter1.drawText(5,10,m_sutc);
  }
  update();                              //trigger a new paintEvent
}
Exemplo n.º 2
0
/**
 * Handles paint events by redrawing the graphic in this view.
 * usually that's very fast since we only paint the buffer we
 * have from the last call..
 */
void QG_GraphicView::paintEvent(QPaintEvent *) {
    RS_DEBUG->print("QG_GraphicView::paintEvent begin");

        RS_SETTINGS->beginGroup("/Appearance");
    bool draftMode = (bool)RS_SETTINGS->readNumEntry("/DraftMode", 0);
    RS_SETTINGS->endGroup();


        // Re-Create or get the layering pixmaps
        PixmapLayer1=getPixmapForView(PixmapLayer1);
        PixmapLayer2=getPixmapForView(PixmapLayer2);
        PixmapLayer3=getPixmapForView(PixmapLayer3);

    // Draw Layer 1
        if (redrawMethod & RS2::RedrawGrid) {
                PixmapLayer1->fill(background);
                RS_PainterQt painter1(PixmapLayer1);
                //painter1->setBackgroundMode(Qt::OpaqueMode);
                //painter1->setBackgroundColor(background);
                //painter1->eraseRect(0,0,getWidth(), getHeight());
                drawLayer1((RS_Painter*)&painter1);
                painter1.end();
        }


        if (redrawMethod & RS2::RedrawDrawing) {
                // DRaw layer 2
                PixmapLayer2->fill(Qt::transparent);
                RS_PainterQt painter2(PixmapLayer2);
                painter2.setDrawingMode(drawingMode);
                setDraftMode(draftMode);
        painter2.setDrawSelectedOnly(false);
        drawLayer2((RS_Painter*)&painter2);
        painter2.setDrawSelectedOnly(true);
        drawLayer2((RS_Painter*)&painter2);
        //removed to solve bug #3470573
//        setDraftMode(false);
                painter2.end();
        }

    if (redrawMethod & RS2::RedrawOverlay) {
        PixmapLayer3->fill(Qt::transparent);
        RS_PainterQt painter3(PixmapLayer3);
        drawLayer3((RS_Painter*)&painter3);
        painter3.end();
    }

        // Finally paint the layers back on the screen, bitblk to the rescue!
        RS_PainterQt wPainter(this);
        //wPainter.setCompositionMode(QPainter::CompositionMode_Screen);
        wPainter.drawPixmap(0,0,*PixmapLayer1);
        wPainter.drawPixmap(0,0,*PixmapLayer2);
        wPainter.drawPixmap(0,0,*PixmapLayer3);
        wPainter.end();

        redrawMethod=RS2::RedrawNone;
    RS_DEBUG->print("QG_GraphicView::paintEvent end");
}
Exemplo n.º 3
0
/**
 * Handles paint events by redrawing the graphic in this view.
 * usually that's very fast since we only paint the buffer we
 * have from the last call..
 */
void QG_GraphicView::paintEvent(QPaintEvent *)
{

    // Re-Create or get the layering pixmaps
    getPixmapForView(PixmapLayer1);
    getPixmapForView(PixmapLayer2);
    getPixmapForView(PixmapLayer3);

    // Draw Layer 1
    if (redrawMethod & RS2::RedrawGrid)
    {
        PixmapLayer1->fill(background);
        RS_PainterQt painter1(PixmapLayer1.get());
        drawLayer1((RS_Painter*)&painter1);
        painter1.end();
    }

    if (redrawMethod & RS2::RedrawDrawing)
    {
        view_rect = LC_Rect(toGraph(0, 0),
                            toGraph(getWidth(), getHeight()));
        // DRaw layer 2
        PixmapLayer2->fill(Qt::transparent);
        RS_PainterQt painter2(PixmapLayer2.get());
        if (antialiasing)
        {
            painter2.setRenderHint(QPainter::Antialiasing);
        }
        painter2.setDrawingMode(drawingMode);
        painter2.setDrawSelectedOnly(false);
        drawLayer2((RS_Painter*)&painter2);
        painter2.setDrawSelectedOnly(true);
        drawLayer2((RS_Painter*)&painter2);
        painter2.end();
    }

    if (redrawMethod & RS2::RedrawOverlay)
    {
        PixmapLayer3->fill(Qt::transparent);
        RS_PainterQt painter3(PixmapLayer3.get());
        if (antialiasing)
        {
            painter3.setRenderHint(QPainter::Antialiasing);
        }
        drawLayer3((RS_Painter*)&painter3);
        painter3.end();
    }

    // Finally paint the layers back on the screen, bitblk to the rescue!
    RS_PainterQt wPainter(this);
    wPainter.drawPixmap(0,0,*PixmapLayer1);
    wPainter.drawPixmap(0,0,*PixmapLayer2);
    wPainter.drawPixmap(0,0,*PixmapLayer3);
    wPainter.end();

    redrawMethod=RS2::RedrawNone;
}
Exemplo n.º 4
0
void Worker::run()
{
    // Note: this is never called directly. It is called by Qt once the 
    // thread environment has been set up        
    // random.seed();
    int n = stars;
    int m_width = m_size.width();
    int m_height= m_size.height();
        
    do {
        QImage image = QImage(outerRadius * 2, outerRadius * 2, QImage::Format_ARGB32);
        image.fill(qRgba(255, 255, 256, 0));
            
        int x = GetRNDValue(0, m_width);
        int y = GetRNDValue(0, m_height);
        
        int angle = GetRNDValue(0, 360);
        int red = GetRNDValue(0, 256);
        
        int green = GetRNDValue(0, 256);
        int blue = GetRNDValue(0, 256);
        int alpha = GetRNDValue(0, 256);
        /*
        QPainter *painter = new QPainter();
        painter->begin(&image);
        painter->setRenderHint(QPainter::Antialiasing);
        painter->setPen(Qt::NoPen);
        painter->setBrush(QColor(red, green, blue, alpha));
        painter->translate(outerRadius, outerRadius);
        painter->rotate(angle);
        painter->drawPath(path);
        painter->end();
        */       

        //-----------
       QImage myQImage(60, 60, QImage::Format_RGB32);
       QPainter painter1(&myQImage);
        for (int i=0; i<60; i++)
        {
            for (int j=0; j<60; j++)
            {
                double hue = (double)(i + j + i*j)/361200.0;
                QColor myColor;
                myColor.setHsvF(hue, 1.0, 1.0, 1.0);
                painter1.setPen(myColor);
                painter1.drawPoint(i, j);
            }
        }
        //-----------

        emit output (QRect(x - outerRadius, y - outerRadius, outerRadius * 2, outerRadius * 2), myQImage);
        
        sleep(0.01);
        n --;
        qDebug("Iteration number %d\n", n);
    } while ((!exiting) && (n > 0));
}
Exemplo n.º 5
0
//////////////////////////////////////////////////////////////////////
// Called to update spectrum data for displaying on the screen
//////////////////////////////////////////////////////////////////////
void CPlotter::draw()
{
    int i;
    int w;
    int h;

    QPoint LineBuf[MAX_SCREENSIZE];

    if (!m_Running)
        return;

    //get/draw the waterfall
    w = m_WaterfallPixmap.width();
    h = m_WaterfallPixmap.height();

    //move current data down one line(must do before attaching a QPainter object)
    m_WaterfallPixmap.scroll(0,1,0,0, w, h);

    QPainter painter1(&m_WaterfallPixmap);
    //get scaled FFT data
    GetScreenIntegerFFTData(255, w, m_MaxdB, m_MindB, -m_Span/2, m_Span/2, m_fftbuf);

    //draw new line of fft data at top of waterfall bitmap
    for(i=0; i<w; i++)
    {
        painter1.setPen(m_ColorTbl[ 255-m_fftbuf[i] ]);
        painter1.drawPoint(i,0);
    }

    //get/draw the 2D spectrum
    w = m_2DPixmap.width();
    h = m_2DPixmap.height();
    //first copy into 2Dbitmap the overlay bitmap.
    m_2DPixmap = m_OverlayPixmap.copy(0,0,w,h);

    QPainter painter2(&m_2DPixmap);

    //get new scaled fft data
    GetScreenIntegerFFTData(h, w, m_MaxdB, m_MindB, -m_Span/2, m_Span/2, m_fftbuf);

    //draw the 2D spectrum
    painter2.setPen(QColor(0x97,0xD0,0x97,0xFF));
    for(i=0; i<w; i++)
    {
        LineBuf[i].setX(i);
        LineBuf[i].setY(m_fftbuf[i]);
    }
    painter2.drawPolyline(LineBuf,w);

    //trigger a new paintEvent
    update();

}
Exemplo n.º 6
0
void Trashdialog::paintEvent(QPaintEvent *)
{
    QPixmap pixmap(size());
    QPainter painter(&pixmap);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.fillRect(pixmap.rect(), Qt::white);
    painter.setBrush(Qt::black);
    painter.drawRoundRect(pixmap.rect(), 5, 5);
    setMask(pixmap.createMaskFromColor(Qt::white));

    QPainter painter1(this);
    painter1.setRenderHint(QPainter::Antialiasing);
    painter1.setPen(QPen(Qt::darkGray, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
    painter1.drawRoundedRect(0, 0, width(), height(), 5, 5, Qt::RelativeSize);
}
Exemplo n.º 7
0
 void ScribbleArea::drawLineTo(const QPoint &endPoint)
 {
     QPainter painter(&image);
     painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap,
                         Qt::RoundJoin));
     painter.drawLine(lastPoint, endPoint);

     QPainter painter1(&paintImage);
     painter1.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap,
                         Qt::RoundJoin));
     painter1.drawLine(lastPoint, endPoint);

     modified = true;

     int rad = (myPenWidth / 2) + 2;
     update(QRect(lastPoint, endPoint).normalized()
                                      .adjusted(-rad, -rad, +rad, +rad));

     lastPoint = endPoint;
 }
Exemplo n.º 8
0
//////////////////////////////////////////////////////////////////////
// Called to update spectrum data for displaying on the screen
//////////////////////////////////////////////////////////////////////
void CPlotter::draw()
{
    int i;
    int w;
    int h;
    int xmin, xmax;

    if (m_DrawOverlay)
    {
        DrawOverlay();
        m_DrawOverlay = false;
    }

    QPoint LineBuf[MAX_SCREENSIZE];

    if (!m_Running)
        return;

    // get/draw the waterfall
    w = m_WaterfallPixmap.width();
    h = m_WaterfallPixmap.height();

    // no need to draw if pixmap is invisible
    if ((w != 0) || (h != 0))
    {
        // move current data down one line(must do before attaching a QPainter object)
        m_WaterfallPixmap.scroll(0,1,0,0, w, h);

        QPainter painter1(&m_WaterfallPixmap);
        // get scaled FFT data
        GetScreenIntegerFFTData(255, w, m_MaxdB, m_MindB,
                                m_FftCenter-m_Span/2, m_FftCenter+m_Span/2,
                                m_fftbuf, &xmin, &xmax);

        // draw new line of fft data at top of waterfall bitmap
        painter1.setPen(QColor(0, 0, 0));
        for (i = 0; i < xmin; i++)
            painter1.drawPoint(i,0);
        for (i = xmax; i < w; i++)
            painter1.drawPoint(i,0);
        for (i = xmin; i < xmax; i++)
        {
            painter1.setPen(m_ColorTbl[ 255-m_fftbuf[i] ]);
            painter1.drawPoint(i,0);
        }
    }

    // get/draw the 2D spectrum
    w = m_2DPixmap.width();
    h = m_2DPixmap.height();

    if ((w != 0) || (h != 0))
    {
        // first copy into 2Dbitmap the overlay bitmap.
        m_2DPixmap = m_OverlayPixmap.copy(0,0,w,h);

        QPainter painter2(&m_2DPixmap);

        // get new scaled fft data
        GetScreenIntegerFFTData(h, w, m_MaxdB, m_MindB,
                                m_FftCenter-m_Span/2, m_FftCenter+m_Span/2,
                                m_fftbuf, &xmin, &xmax);

        // draw the 2D spectrum
        painter2.setPen(QColor(0x97,0xD0,0x97,0xFF));
        for (i = 0; i < xmax - xmin; i++)
        {
            LineBuf[i].setX(i + xmin);
            LineBuf[i].setY(m_fftbuf[i + xmin]);
        }
        painter2.drawPolyline(LineBuf, xmax - xmin);
    }

    // trigger a new paintEvent
    update();

}
Exemplo n.º 9
0
void QBalloonTip::balloon(const QPoint& pos, int msecs, bool showArrow)
{
    QRect scr = QApplication::desktop()->screenGeometry(pos);
    QSize sh = sizeHint();
    const int border = 1;
    const int ah = 18, ao = 18, aw = 18, rc = 7;
    bool arrowAtTop = (pos.y() + sh.height() + ah < scr.height());
    bool arrowAtLeft = (pos.x() + sh.width() - ao < scr.width());
    setContentsMargins(border + 3,  border + (arrowAtTop ? ah : 0) + 2, border + 3, border + (arrowAtTop ? 0 : ah) + 2);
    updateGeometry();
    sh  = sizeHint();

    int ml, mr, mt, mb;
    QSize sz = sizeHint();
    if (!arrowAtTop) {
        ml = mt = 0;
        mr = sz.width() - 1;
        mb = sz.height() - ah - 1;
    } else {
        ml = 0;
        mt = ah;
        mr = sz.width() - 1;
        mb = sz.height() - 1;
    }

    QPainterPath path;
#if defined(QT_NO_XSHAPE) && defined(Q_WS_X11)
    // XShape is required for setting the mask, so we just
    // draw an ugly square when its not available
    path.moveTo(0, 0);
    path.lineTo(sz.width() - 1, 0);
    path.lineTo(sz.width() - 1, sz.height() - 1);
    path.lineTo(0, sz.height() - 1);
    path.lineTo(0, 0);
    move(qMax(pos.x() - sz.width(), scr.left()), pos.y());
#else
    path.moveTo(ml + rc, mt);
    if (arrowAtTop && arrowAtLeft) {
        if (showArrow) {
            path.lineTo(ml + ao, mt);
            path.lineTo(ml + ao, mt - ah);
            path.lineTo(ml + ao + aw, mt);
        }
        move(qMax(pos.x() - ao, scr.left() + 2), pos.y());
    } else if (arrowAtTop && !arrowAtLeft) {
        if (showArrow) {
            path.lineTo(mr - ao - aw, mt);
            path.lineTo(mr - ao, mt - ah);
            path.lineTo(mr - ao, mt);
        }
        move(qMin(pos.x() - sh.width() + ao, scr.right() - sh.width() - 2), pos.y());
    }
    path.lineTo(mr - rc, mt);
    path.arcTo(QRect(mr - rc*2, mt, rc*2, rc*2), 90, -90);
    path.lineTo(mr, mb - rc);
    path.arcTo(QRect(mr - rc*2, mb - rc*2, rc*2, rc*2), 0, -90);
    if (!arrowAtTop && !arrowAtLeft) {
        if (showArrow) {
            path.lineTo(mr - ao, mb);
            path.lineTo(mr - ao, mb + ah);
            path.lineTo(mr - ao - aw, mb);
        }
        move(qMin(pos.x() - sh.width() + ao, scr.right() - sh.width() - 2),
             pos.y() - sh.height());
    } else if (!arrowAtTop && arrowAtLeft) {
        if (showArrow) {
            path.lineTo(ao + aw, mb);
            path.lineTo(ao, mb + ah);
            path.lineTo(ao, mb);
        }
        move(qMax(pos.x() - ao, scr.x() + 2), pos.y() - sh.height());
    }
    path.lineTo(ml + rc, mb);
    path.arcTo(QRect(ml, mb - rc*2, rc*2, rc*2), -90, -90);
    path.lineTo(ml, mt + rc);
    path.arcTo(QRect(ml, mt, rc*2, rc*2), 180, -90);

    // Set the mask
    QBitmap bitmap = QBitmap(sizeHint());
    bitmap.fill(Qt::color0);
    QPainter painter1(&bitmap);
    painter1.setPen(QPen(Qt::color1, border));
    painter1.setBrush(QBrush(Qt::color1));
    painter1.drawPath(path);
    setMask(bitmap);
#endif

    // Draw the border
    pixmap = QPixmap(sz);
    QPainter painter2(&pixmap);
    painter2.setPen(QPen(palette().color(QPalette::Window).darker(160), border));
    painter2.setBrush(palette().color(QPalette::Window));
    painter2.drawPath(path);

    if (msecs > 0)
        timerId = startTimer(msecs);
    show();
}
Exemplo n.º 10
0
//////////////////////////////////////////////////////////////////////
// Called to update spectrum data for displaying on the screen
//////////////////////////////////////////////////////////////////////
void CPlotter::draw()
{
    int i,n;
    int w;
    int h;
    int xmin, xmax;

    if (m_DrawOverlay)
    {
        drawOverlay();
        m_DrawOverlay = false;
    }

    QPoint LineBuf[MAX_SCREENSIZE];

    if (!m_Running)
        return;

    // get/draw the waterfall
    w = m_WaterfallPixmap.width();
    h = m_WaterfallPixmap.height();

    // no need to draw if pixmap is invisible
    if ((w != 0) || (h != 0))
    {
        // move current data down one line(must do before attaching a QPainter object)
        m_WaterfallPixmap.scroll(0,1,0,0, w, h);

        QPainter painter1(&m_WaterfallPixmap);
        // get scaled FFT data
        getScreenIntegerFFTData(255, qMin(w, MAX_SCREENSIZE),
                                m_MaxdB, m_MindB,
                                m_FftCenter - (qint64)m_Span/2,
                                m_FftCenter + (qint64)m_Span/2,
                                m_wfData, m_fftbuf,
                                &xmin, &xmax);

        // draw new line of fft data at top of waterfall bitmap
        painter1.setPen(QColor(0, 0, 0));
        for (i = 0; i < xmin; i++)
            painter1.drawPoint(i,0);
        for (i = xmax; i < w; i++)
            painter1.drawPoint(i,0);
        for (i = xmin; i < xmax; i++)
        {
            painter1.setPen(m_ColorTbl[ 255-m_fftbuf[i] ]);
            painter1.drawPoint(i,0);
        }
    }

    // get/draw the 2D spectrum
    w = m_2DPixmap.width();
    h = m_2DPixmap.height();

    if ((w != 0) || (h != 0))
    {
        // first copy into 2Dbitmap the overlay bitmap.
        m_2DPixmap = m_OverlayPixmap.copy(0,0,w,h);

        QPainter painter2(&m_2DPixmap);

// workaround for "fixed" line drawing since Qt 5
// see http://stackoverflow.com/questions/16990326 
#if QT_VERSION >= 0x050000
        painter2.translate(0.5, 0.5);
#endif

        // get new scaled fft data
        getScreenIntegerFFTData(h, qMin(w, MAX_SCREENSIZE),
                                m_MaxdB, m_MindB,
                                m_FftCenter - (qint64)m_Span/2,
                                m_FftCenter + (qint64)m_Span/2,
                                m_fftData, m_fftbuf,
                                &xmin, &xmax);

        // draw the pandapter
        painter2.setPen(m_FftColor);
        n = xmax - xmin;
        for (i = 0; i < n; i++)
        {
            LineBuf[i].setX(i + xmin);
            LineBuf[i].setY(m_fftbuf[i + xmin]);
        }

        if (m_FftFill)
        {
            QLinearGradient linGrad(QPointF(xmin, h), QPointF(xmin, 0));
            linGrad.setColorAt(0.0, m_FftCol0);
            linGrad.setColorAt(1.0, m_FftCol1);
            painter2.setBrush(QBrush(QGradient(linGrad)));
            if (n < MAX_SCREENSIZE-2)
            {
                LineBuf[n].setX(xmax-1);
                LineBuf[n].setY(h);
                LineBuf[n+1].setX(xmin);
                LineBuf[n+1].setY(h);
                painter2.drawPolygon(LineBuf, n+2);
            }
            else
            {
                LineBuf[MAX_SCREENSIZE-2].setX(xmax-1);
                LineBuf[MAX_SCREENSIZE-2].setY(h);
                LineBuf[MAX_SCREENSIZE-1].setX(xmin);
                LineBuf[MAX_SCREENSIZE-1].setY(h);
                painter2.drawPolygon(LineBuf, n);
            }
        }
        else
        {
            painter2.drawPolyline(LineBuf, n);
        }
    }

    // trigger a new paintEvent
    update();
}
Exemplo n.º 11
0
void CPlotter::draw(float swide[])                                //draw()
{
  int j,y2;
  float y;

  double gain = pow(10.0,0.05*(m_plotGain+7));

//move current data down one line (must do this before attaching a QPainter object)
  m_WaterfallPixmap.scroll(0,1,0,0,m_w,m_h1);
  QPainter painter1(&m_WaterfallPixmap);
  m_2DPixmap = m_OverlayPixmap.copy(0,0,m_w,m_h2);
  QPainter painter2D(&m_2DPixmap);

  painter2D.setPen(Qt::green);

  QPoint LineBuf[MAX_SCREENSIZE];
  j=0;
  bool strong0=false;
  bool strong=false;
  int i0=(m_StartFreq-1000)/m_fftBinWidth;
  if(m_nsps==65536) i0=(m_StartFreq-1550)/m_fftBinWidth;

  for(int i=0; i<m_w; i++) {
    strong=false;
    if(swide[i0+i]<0) {
      strong=true;
      swide[i0+i]=-swide[i0+i];
    }
    y = 10.0*log10(swide[i0+i]);
    int y1 = 5.0*gain*y + 10*m_plotZero;
    if (y1<0) y1=0;
    if (y1>254) y1=254;
    if (swide[i0+i]>1.e29) y1=255;
    if(y1==255 and m_transmitted) {
      painter1.setPen(Qt::red);
    } else {
      painter1.setPen(m_ColorTbl[y1]);
    }
    painter1.drawPoint(i,0);
    y2=0;
    if(m_bCumulative) {
      y2=1.5*gain*10.0*log10(datcom_.savg[i0+i]) - 20;
    } else {
      y2 = 0.4*gain*y - 15;
    }
    y2=y2*float(m_h)/540.0;
    if(strong != strong0 or i==m_w-1) {
      painter2D.drawPolyline(LineBuf,j);
      j=0;
      strong0=strong;
      if(strong0) painter2D.setPen(Qt::red);
      if(!strong0) painter2D.setPen(Qt::green);
    }
    LineBuf[j].setX(i);
    LineBuf[j].setY(m_h-(y2+0.8*m_h));
    j++;
  }
  m_transmitted=false;

  if(swide[0]>1.0e29) m_line=0;
  m_line++;
  if(m_line == 13) {
    UTCstr();
    painter1.setPen(Qt::white);
    painter1.drawText(5,10,m_sutc);
  }
  update();                              //trigger a new paintEvent
}
Exemplo n.º 12
0
//////////////////////////////////////////////////////////////////////
// Called to update spectrum data for displaying on the screen
//////////////////////////////////////////////////////////////////////
void CPlotter::draw()
{
    int i,n;
    int w;
    int h;
    int xmin, xmax;

    if (m_DrawOverlay)
    {
        drawOverlay();
        m_DrawOverlay = false;
    }

    QPoint LineBuf[MAX_SCREENSIZE];

    if (!m_Running)
        return;

    // get/draw the waterfall
    w = m_WaterfallPixmap.width();
    h = m_WaterfallPixmap.height();

    // no need to draw if pixmap is invisible
    if ((w != 0) || (h != 0))
    {
        // move current data down one line(must do before attaching a QPainter object)
        m_WaterfallPixmap.scroll(0,1,0,0, w, h);

        QPainter painter1(&m_WaterfallPixmap);
        // get scaled FFT data
        getScreenIntegerFFTData(255, qMin(w, MAX_SCREENSIZE),
                                m_MaxdB, m_MindB,
                                m_FftCenter - (qint64)m_Span/2,
                                m_FftCenter + (qint64)m_Span/2,
                                m_wfData, m_fftbuf,
                                &xmin, &xmax);

        // draw new line of fft data at top of waterfall bitmap
        painter1.setPen(QColor(0, 0, 0));
        for (i = 0; i < xmin; i++)
            painter1.drawPoint(i,0);
        for (i = xmax; i < w; i++)
            painter1.drawPoint(i,0);
        for (i = xmin; i < xmax; i++)
        {
            painter1.setPen(m_ColorTbl[ 255-m_fftbuf[i] ]);
            painter1.drawPoint(i,0);
        }
    }

    // get/draw the 2D spectrum
    w = m_2DPixmap.width();
    h = m_2DPixmap.height();

    if ((w != 0) || (h != 0))
    {
        // first copy into 2Dbitmap the overlay bitmap.
        m_2DPixmap = m_OverlayPixmap.copy(0,0,w,h);

        QPainter painter2(&m_2DPixmap);

// workaround for "fixed" line drawing since Qt 5
// see http://stackoverflow.com/questions/16990326 
#if QT_VERSION >= 0x050000
        painter2.translate(0.5, 0.5);
#endif

        // get new scaled fft data
        getScreenIntegerFFTData(h, qMin(w, MAX_SCREENSIZE),
                                m_MaxdB, m_MindB,
                                m_FftCenter - (qint64)m_Span/2,
                                m_FftCenter + (qint64)m_Span/2,
                                m_fftData, m_fftbuf,
                                &xmin, &xmax);

        // draw the pandapter
        painter2.setPen(m_FftColor);
        n = xmax - xmin;
        for (i = 0; i < n; i++)
        {
            LineBuf[i].setX(i + xmin);
            LineBuf[i].setY(m_fftbuf[i + xmin]);
        }

        if (m_FftFill)
        {
            QLinearGradient linGrad(QPointF(xmin, h), QPointF(xmin, 0));
            linGrad.setColorAt(0.0, m_FftCol0);
            linGrad.setColorAt(1.0, m_FftCol1);
            painter2.setBrush(QBrush(QGradient(linGrad)));
            if (n < MAX_SCREENSIZE-2)
            {
                LineBuf[n].setX(xmax-1);
                LineBuf[n].setY(h);
                LineBuf[n+1].setX(xmin);
                LineBuf[n+1].setY(h);
                painter2.drawPolygon(LineBuf, n+2);
            }
            else
            {
                LineBuf[MAX_SCREENSIZE-2].setX(xmax-1);
                LineBuf[MAX_SCREENSIZE-2].setY(h);
                LineBuf[MAX_SCREENSIZE-1].setX(xmin);
                LineBuf[MAX_SCREENSIZE-1].setY(h);
                painter2.drawPolygon(LineBuf, n);
            }
        }
        else
        {
            painter2.drawPolyline(LineBuf, n);
        }

        //Peak detection
        if (m_PeakDetection > 0)
        {
            m_Peaks.clear();

            float   mean = 0;
            float   sum_of_sq = 0;
            for (i = 0; i < n; i++)
            {
                mean += m_fftbuf[i + xmin];
                sum_of_sq += m_fftbuf[i + xmin] * m_fftbuf[i + xmin];
            }
            mean /= n;
            float stdev= sqrt( sum_of_sq/n-mean*mean );

            int lastPeak=-1;
            for (i = 0; i < n; i++)
            {
                //m_PeakDetection times the std over the mean or better than current peak
                float d = (lastPeak==-1) ? (mean - m_PeakDetection * stdev) :
                                           m_fftbuf[lastPeak+xmin];

                if (m_fftbuf[i + xmin] < d)
                    lastPeak=i;

                if (lastPeak != -1 && (i - lastPeak > PEAK_H_TOLERANCE || i == n-1))
                {
                    m_Peaks.insert(lastPeak+xmin, m_fftbuf[lastPeak + xmin]);
                    painter2.drawEllipse(lastPeak+xmin-5, m_fftbuf[lastPeak + xmin]-5, 10, 10);
                    lastPeak=-1;
                }
            }
        }

        //Peak hold
        if (m_PeakHoldActive)
        {
            for (i = 0; i < n; i++)
            {
                if(!m_PeakHoldValid || m_fftbuf[i] < m_fftPeakHoldBuf[i])
                    m_fftPeakHoldBuf[i] = m_fftbuf[i];

                LineBuf[i].setX(i + xmin);
                LineBuf[i].setY(m_fftPeakHoldBuf[i + xmin]);
            }
            painter2.setPen(m_PeakHoldColor);
            painter2.drawPolyline(LineBuf, n);

            m_PeakHoldValid=true;
        }

		painter2.end();

    }

    // trigger a new paintEvent
    update();
}