void
SignalDisplay::DrawSignalField2d( const PaintInfo& p )
{
    int sampleBegin = 0,
        sampleEnd = mNumSamples;
    if( p.updateRgn )
    {   // We restrict drawing to the actually requested update region.
        QRect clipRect = p.updateRgn->boundingRect();
        sampleBegin = PosToSample( clipRect.left() );
        sampleBegin = max( sampleBegin - 1, 0 );
        sampleEnd = PosToSample( clipRect.right() + 1 );
        sampleEnd = min( sampleEnd + 1, mNumSamples );
    }
    for( int i = 0; i < mNumDisplayChannels; ++i )
    {
        for( int j = sampleBegin; j < sampleEnd; ++j )
        {
            bool draw = true;
            double dataValue = NormData( i + mTopGroup * mChannelGroupSize, j );
            if( dataValue < 0.0 )
                dataValue = 0.0;
            else if( dataValue > 1.0 )
                dataValue = 1.0;
            else if( IsNaN( dataValue ) )
                dataValue = 0.0;

            QRect dotRect(
                SampleLeft( j ),
                ChannelTop( i ),
                SampleRight( j ) - SampleLeft( j ),
                ChannelBottom( i ) - ChannelTop( i )
            );
            RGBColor rgb;
            if( mDisplayColors )
                rgb = RGBColor::FromHSV( dataValue - 1.0 / 3.0, 1.0, dataValue );
            else
                rgb = RGBColor::FromHSV( 0.0, 0.0, dataValue );
            p.painter->fillRect( dotRect, QColor( rgb.R(), rgb.G(), rgb.B() ) );
        }
# ifdef _WIN32
        ::Sleep( 0 );
# endif // _WIN32
    }
}
Ejemplo n.º 2
0
void
TextField::DoPaint( const GUI::DrawContext& inDC,
                    RGBColor inTextColor,
                    RGBColor inBackgroundColor )
{
#if USE_QT

  QPainter* p = inDC.handle.painter;
  QRect rect(
    static_cast<int>( inDC.rect.left ),
    static_cast<int>( inDC.rect.top ),
    static_cast<int>( inDC.rect.right - inDC.rect.left ),
    static_cast<int>( inDC.rect.bottom - inDC.rect.top )
  );
  QBrush brush;
  brush.setStyle( Qt::SolidPattern );
  if( mColor != RGBColor( RGBColor::NullColor ) )
  {
    QColor backColor( mColor.R(), mColor.G(), mColor.B() );
    brush.setColor( backColor );
    p->fillRect( rect, brush );
  }

  QFont font;
  font.fromString( QString( "Arial" ) );
  font.setPixelSize( static_cast<int>( mTextHeight * ( inDC.rect.bottom - inDC.rect.top ) ) );
  font.setBold( true );
  QColor textColor( inTextColor.R(), inTextColor.G(), inTextColor.B() );
  QPen pen;
  brush.setColor( textColor );
  pen.setColor( textColor );
  p->setPen( pen );
  p->setBrush( brush );
  p->setFont( font );

  QString text = QString::fromLocal8Bit( mText.c_str() );
  text.append( " " ).prepend( " " );
  p->drawText( rect, Qt::AlignCenter, text );

#endif // USE_QT
}
void
SignalDisplay::DrawChannelLabels( const PaintInfo& p )
{
    p.painter->setFont( p.labelFont );
    if( mShowChannelLabels && mChannelGroupSize > 1 )
    {   // Draw channel labels when channels don't coincide with groups.
        p.painter->setBackground( p.backgroundColor );
        p.painter->setBackgroundMode( Qt::OpaqueMode );
        QRect legendRect;
        for( size_t i = 0; i < mChannelLabels.size(); ++i )
        {
            RGBColor textColor = ChannelColor( mChannelLabels[ i ].Address() );
            if( mInverted && textColor == RGBColor::White )
                textColor = RGBColor::Black;
            p.painter->setPen( QColor( textColor.R(), textColor.G(), textColor.B() ) );
            p.painter->drawText( legendRect,
                                 Qt::TextSingleLine | Qt::AlignLeft | Qt::TextDontClip,
                                 mChannelLabels[ i ].Text().c_str() );
            legendRect.setTop( legendRect.top() + p.painter->fontMetrics().height() );
        }
    }
}
void
SignalDisplay::SetupPainting( PaintInfo& p, const void* inUpdateRgn )
{
    SyncGraphics();

    p.updateRgn = reinterpret_cast<const QRegion*>( inUpdateRgn );
    p.painter = new QPainter( mTargetDC );
    p.painter->setRenderHint( QPainter::Antialiasing, false );
    p.painter->setRenderHint( QPainter::TextAntialiasing, false );
    p.signalPens.resize( mData.Channels() );
    p.signalBrushes.resize( mData.Channels() );

    // Background properties
    RGBColor c = mInverted ? RGBColor::White : RGBColor::Black;
    p.backgroundColor = QColor( c.R(), c.G(), c.B() );
    p.backgroundBrush = QBrush( p.backgroundColor );

    // Cursor properties
    p.cursorWidth = 3;
    c = RGBColor::Yellow;
    p.cursorColor = QColor( c.R(), c.G(), c.B() );
    p.cursorBrush = QBrush( p.cursorColor );

    // Axis properties
    RGBColor axisColor = mAxisColor;
    if( mInverted && ( axisColor == RGBColor::White ) )
        axisColor = RGBColor::Black;
    QColor qAxisColor( axisColor.R(), axisColor.G(), axisColor.B() );
    p.axisBrush = QBrush( qAxisColor );
    p.axisY = GroupBottom( mNumDisplayGroups - 1 );

    p.markerWidth = 1;
    p.baselinePen = QPen( qAxisColor );
    c = RGBColor( mInverted ? RGBColor::Black : RGBColor::White );
    p.markerColor = QColor( c.R(), c.G(), c.B() );
    p.markerBrush = QBrush( p.markerColor );
    p.labelColor = qAxisColor;
    p.labelFont = AxisFont();
    p.monoFont = MonoFont();


    // Signal properties
    if( mDisplayColors )
        for( int i = 0; i < mData.Channels(); ++i )
        {
            RGBColor channelColor = ChannelColor( i );
            if( mInverted && channelColor == RGBColor::White )
                channelColor = RGBColor::Black;
            QColor c( channelColor.R(), channelColor.G(), channelColor.B() );
            p.signalPens[ i ] = QPen( c );
            p.signalBrushes[ i ] = QBrush( c );
        }
    else
    {
        RGBColor channelColor = mInverted? RGBColor::Black : RGBColor::White;
        QColor c( channelColor.R(), channelColor.G(), channelColor.B() );
        QPen pen( c );
        for( int i = 0; i < mData.Channels(); ++i )
            p.signalPens[ i ] = pen;
    }
}