Exemple #1
0
void KoChild::setClipRegion( QPainter &painter, bool combine )
{
  painter.setClipping( true );
  if ( combine && !painter.clipRegion().isEmpty() )
    painter.setClipRegion( region( painter.worldMatrix() ).intersect( painter.clipRegion() ) );
  else
    painter.setClipRegion( region( painter.worldMatrix() ) );
}
void nsRenderingContextQt::UpdateGC()
{
  QPainter *pGC;
  QColor color(NS_GET_R(mCurrentColor),
               NS_GET_G(mCurrentColor),
               NS_GET_B(mCurrentColor));
  QPen   pen(color,0,mQLineStyle);
  QBrush brush(color);

  pGC = mSurface->GetGC();
  pGC->setPen(pen);
  pGC->setBrush(brush);
  pGC->setRasterOp(mFunction);
  if (mCurrentFont)
    pGC->setFont(mCurrentFont->font);
  if (mClipRegion) {
     QRegion *rgn = nsnull;

     pGC->setClipping(TRUE);
     mClipRegion->GetNativeRegion((void*&)rgn);
     pGC->setClipRegion(*rgn);
  }
  else {
    pGC->setClipping(FALSE);
  }
}
void QQuickShapeSoftwareRenderNode::render(const RenderState *state)
{
    if (m_sp.isEmpty())
        return;

    QSGRendererInterface *rif = m_item->window()->rendererInterface();
    QPainter *p = static_cast<QPainter *>(rif->getResource(m_item->window(), QSGRendererInterface::PainterResource));
    Q_ASSERT(p);

    const QRegion *clipRegion = state->clipRegion();
    if (clipRegion && !clipRegion->isEmpty())
        p->setClipRegion(*clipRegion, Qt::ReplaceClip); // must be done before setTransform

    p->setTransform(matrix()->toTransform());
    p->setOpacity(inheritedOpacity());

    for (const ShapePathRenderData &d : qAsConst(m_sp)) {
        if (d.hidden) {
            continue;
        }

//        QTransform oldTransform = p->transform();
//        p->setTransform(d.transform, true);

//        p->setOpacity(inheritedOpacity() * d.opacity);
        p->setPen(d.strokeWidth >= 0.0f && d.pen.color() != Qt::transparent ? d.pen : Qt::NoPen);
        p->setBrush(d.brush.color() != Qt::transparent ? d.brush : Qt::NoBrush);
        p->drawPath(d.path);

//        p->setTransform(oldTransform);
    }
}
Exemple #4
0
void FreeRegionGrabber::grabRect()
{
    QPolygon pol = selection;
    if ( !pol.isEmpty() )
    {
	grabbing = true;

        int xOffset = pixmap.rect().x() - pol.boundingRect().x();
        int yOffset = pixmap.rect().y() - pol.boundingRect().y();
        QPolygon translatedPol = pol.translated(xOffset, yOffset);

        QPixmap pixmap2(pol.boundingRect().size());
        pixmap2.fill(Qt::transparent);

        QPainter pt;
        pt.begin(&pixmap2);
        if (pt.paintEngine()->hasFeature(QPaintEngine::PorterDuff)) {
            pt.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform, true);
            pt.setBrush(Qt::black);
            pt.setPen(QPen(QBrush(Qt::black), 0.5));
            pt.drawPolygon(translatedPol);
            pt.setCompositionMode(QPainter::CompositionMode_SourceIn);
        } else {
            pt.setClipRegion(QRegion(translatedPol));
            pt.setCompositionMode(QPainter::CompositionMode_Source);
        }

        pt.drawPixmap(pixmap2.rect(), pixmap, pol.boundingRect());
        pt.end();

        emit freeRegionUpdated(pol);
        emit freeRegionGrabbed(pixmap2);
    }
}
void ScopeViewBase::paintEvent( QPaintEvent * event )
{
	QRect r = event->rect();
	
	if (b_needRedraw)
	{
		//CALLGRIND_TOGGLE_COLLECT();
		
		updateOutputHeight();
		
		QPainter p;
		m_pixmap->fill( paletteBackgroundColor() );
		p.begin(m_pixmap);
		p.setClipRegion(event->region());
		
		//let the subclass draw the background (grids, etc.)
		drawBackground(p);
		
//		drawProbeMap(p, Oscilloscope::self()->m_logicProbeDataMap);	
//		drawProbeMap(p, Oscilloscope::self()->m_floatingProbeDataMap);	
		
		p.setPen(Qt::black);
		p.drawRect( frameRect() );
		
		b_needRedraw = false;
		
		//CALLGRIND_TOGGLE_COLLECT();
	}
	
	bitBlt( this, r.x(), r.y(), m_pixmap, r.x(), r.y(), r.width(), r.height() );
}
Exemple #6
0
void Plotter::drawCurves(QPainter& painter)
{
    noOfCurves = curveDataMap.count();
    QRect rect = this->printRect();
    double x=0,y=0;
    double width = rect.width() - 1;
    double height = rect.height() - 1;
    double yCount = maxY - minY;
    if(antiAliasing)
        painter.setRenderHints(QPainter::Antialiasing);
    painter.setClipRegion(rect);
    painter.translate(Margin + 1,rect.bottom()-1);
    for(int i=0; i < noOfCurves ; i++)
    {
        QPolygonF polyline;
        QList<double>* dataPtr = curveDataMap[i] ;
        for(int j = 0 ; j <= noOfPoints ; j++)
        {
            x = (width * j)/noOfPoints;
            y = (height * (dataPtr->value(j) -minY))/yCount;
            polyline << QPoint(x,-y);
            //qDebug() << y;
        }
        painter.setPen(colorMap.value(i));
        painter.drawPolyline(polyline);

    }
}
Exemple #7
0
void text_display::paint_selection(QPainter &painter, selection &selection_area, const QColor &color)
{
	if(focusPolicy() == Qt::NoFocus){
		return;  //Anything which doesn't accept focus can't be highlighted
	}
	QPoint position1 = clip_screen(nibble_to_screen(selection_area.get_start_aligned()));
	QPoint position2 = clip_screen(nibble_to_screen(selection_area.get_end_aligned()));
	QRegion area = QRect(0, position1.y(), get_line_characters() * editor_font::get_width(), 
	                 position2.y() - position1.y() + editor_font::get_height());
	if(position1.x()){
		area -= QRect(0, position1.y(), position1.x(), editor_font::get_height());
	}
	
	if(position2.x() < width()){
		area -= QRect(position2.x(), position2.y(), 
		              get_line_characters() * editor_font::get_width() - position2.x(), 
		              editor_font::get_height());
	}
	
	if(position2.y() >= get_rows() * editor_font::get_height()){
		area -= QRect(0, get_rows() * editor_font::get_height(), 
		              get_line_characters() * editor_font::get_width(), position2.y());
	}
	painter.setClipRegion(area);
	painter.fillRect(0, position1.y(), get_line_characters() * editor_font::get_width(), 
	                 position2.y() - position1.y() + editor_font::get_height(), color);
}
Exemple #8
0
void DAbstractSliderSpinBox::paintBreeze(QPainter& painter)
{
    Q_D(DAbstractSliderSpinBox);

    QStyleOptionSpinBox spinOpts         = spinBoxOptions();
    QStyleOptionProgressBar progressOpts = progressBarOptions();
    QString valueText                    = progressOpts.text;
    progressOpts.text                    = QLatin1String("");
    progressOpts.rect.adjust(0, 1, 0, -1);

    style()->drawComplexControl(QStyle::CC_SpinBox, &spinOpts, &painter, this);
    style()->drawControl(QStyle::CE_ProgressBarGroove, &progressOpts, &painter, this);

    painter.save();

    QRect leftRect;

    int progressIndicatorPos = (progressOpts.progress - double(progressOpts.minimum)) / qMax(double(1.0),
                                double(progressOpts.maximum) - progressOpts.minimum) * progressOpts.rect.width();

    if (progressIndicatorPos >= 0 && progressIndicatorPos <= progressOpts.rect.width())
    {
        leftRect = QRect(progressOpts.rect.left(), progressOpts.rect.top(), progressIndicatorPos, progressOpts.rect.height());
    }
    else if (progressIndicatorPos > progressOpts.rect.width())
    {
        painter.setPen(palette().highlightedText().color());
    }
    else
    {
        painter.setPen(palette().buttonText().color());
    }

    QRegion rightRect = progressOpts.rect;
    rightRect         = rightRect.subtracted(leftRect);
    painter.setClipRegion(rightRect);

    QTextOption textOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter);
    textOption.setWrapMode(QTextOption::NoWrap);

    if (!(d->edit && d->edit->isVisible()))
    {
        painter.drawText(progressOpts.rect, valueText, textOption);
    }

    if (!leftRect.isNull())
    {
        painter.setPen(palette().highlightedText().color());
        painter.setClipRect(leftRect);
        style()->drawControl(QStyle::CE_ProgressBarContents, &progressOpts, &painter, this);

        if (!(d->edit && d->edit->isVisible()))
        {
            painter.drawText(progressOpts.rect, valueText, textOption);
        }
    }

    painter.restore();
}
Exemple #9
0
/**
 * Set the clip region for specified painter. The clip region is the widget
 * portion in which we can draw. For a plot, is the region of the widget that
 * stay inside the padding area.
 *
 * @param[inout] painter Painter for which clip region must be specified.
 * @param[in] plot Plot.
 */
void Graph::setClipRegion(QPainter &painter, Plot2D *plot) {
	QPoint upperLeftCorner = plot->scalePoint(plot->getUpperLeftCorner()).toPoint();
	QPoint lowerRightCorner = plot->scalePoint(plot->getLowerRightCorner()).toPoint();
	upperLeftCorner.setY(plot->height() - lowerRightCorner.y());
	lowerRightCorner.setX(plot->width() - upperLeftCorner.x());
	QRegion clipRegion(QRect(upperLeftCorner, lowerRightCorner));
	painter.setClipRegion(clipRegion);
}
Exemple #10
0
void MapWidget::drawMarker(const MapMarker &marker, QPainter &painter, const QPointF &markerPosition, const QPointF &rectPosition)
{
    QRectF markerRect = getMarkerRect(marker, rectPosition);

    QColor bgColor = getMarkerTextBackgroundColor();
    painter.setBrush(QBrush(bgColor));

    // drawing the line connector
    painter.setPen(bgColor);
    painter.setClipping(true);
    painter.setClipRegion(QRegion(rect()).subtracted(markerRect.toRect()));
    painter.drawLine(markerRect.center(), markerPosition);

    // drawing the transparent background
    painter.setClipping(false);
    painter.setPen(Qt::NoPen);
    painter.drawRect(markerRect);

    // drawing the player marker
    const static qreal markerSize = 1.6;
    painter.setBrush(getMarkerColor());
    painter.drawEllipse(markerPosition, markerSize, markerSize);

    qreal hOffset = rectPosition.x() + TEXT_MARGIM; // left margin

    // draw the player name text
    QString playerName = marker.getPlayerName();
    painter.setFont(userFont);

    QFontMetrics metrics = painter.fontMetrics();
    qreal playerNameWidth = metrics.width(playerName);
    painter.setPen(getMarkerTextColor());
    qreal textY = rectPosition.y() + TEXT_MARGIM + metrics.descent()/2.0;
    painter.drawText(hOffset, textY, playerName);
    hOffset += playerNameWidth + TEXT_MARGIM * 3;

    // draw the player country name
    painter.setFont(countryFont);
    metrics = painter.fontMetrics();

    QColor countryNameColor(getMarkerTextColor());
    countryNameColor.setAlpha(180); // country name is drawed using some alpha
    painter.setPen(countryNameColor);
    QString countryName = marker.getCountryName();
    painter.drawText(hOffset, textY, countryName);

    hOffset += metrics.width(countryName);

    painter.setFont(userFont); //restore the normal font
    metrics = painter.fontMetrics();

    // draw the player country flag
    const QImage &image = marker.getFlag();
    qreal imageX = hOffset + TEXT_MARGIM;
    qreal imageY = rectPosition.y() - image.height()/2.0;
    painter.drawImage(QPointF(imageX, imageY), image);
}
void TorrentProgressWidget::paintEvent(QPaintEvent* event)
{
	QPainter painter;
	painter.begin(this);
	painter.setRenderHint(QPainter::Antialiasing);
	painter.setClipRegion(event->region());
	
	QImage bdraw = m_image.scaled(size());
	painter.drawImage(0, 0, bdraw);
	
	painter.end();
}
void CanvasRenderer::paintCameraBorder(QPainter &painter)
{

    for ( int i = 0; i < mObject->getLayerCount(); ++i )
    {
        Layer* layer = mObject->getLayer( i );

        if ( layer->type() == Layer::CAMERA && (i == mLayerIndex || mOptions.nShowAllLayers > 0) && layer->visible() ) {

            if ( i == mLayerIndex || mOptions.nShowAllLayers != 1 )
            {
                painter.setOpacity( 1.0 );
            }
            else {
                painter.setOpacity( 0.8 );
            }

            QRectF viewRect = painter.viewport();
            QRect boundingRect = mViewTransform.inverted().mapRect( viewRect ).toRect();


            LayerCamera* cameraLayer = dynamic_cast< LayerCamera* >( layer );

            QRect cameraRect = cameraLayer->getViewRect();

            painter.setWorldMatrixEnabled( true );
            painter.setPen( Qt::NoPen );
            painter.setBrush( QColor( 0, 0, 0, 160 ) );

            QRegion rg1(boundingRect);
            QRegion rg2(cameraRect);
            QRegion rg3=rg1.subtracted(rg2);

            painter.setClipRegion(rg3);

            painter.drawRect( boundingRect );

            painter.setClipping(false);

            painter.setPen( Qt::black );
            painter.setBrush( Qt::NoBrush );
            painter.drawRect( cameraRect );
        }
    }
}
Exemple #13
0
/*!
    \internal

    Paints all the dirty regions into \a pixmap.
    Returns the regions that have been repainted.
*/
void QWSManagerPrivate::paint(QPaintDevice *paintDevice, const QRegion &region)
{
    if (dirtyRegions.empty() || !paintDevice || !paintDevice->paintEngine())
        return;

    QTLWExtra *topextra = managed->d_func()->extra->topextra;
    Q_ASSERT(topextra && topextra->backingStore);
    QWidgetBackingStore *bs = topextra->backingStore;

    const QRect clipRect = managed->rect().translated(bs->topLevelOffset());
    QDecoration &dec = QApplication::qwsDecoration();

    QWSWindowSurface *surface;
    surface = static_cast<QWSWindowSurface*>(bs->windowSurface);
    const QRegion clippedRegion = region & surface->clipRegion();

    const QRegion surfaceClip = clippedRegion.translated(bs->topLevelOffset());

    paintDevice->paintEngine()->setSystemClip(surfaceClip);

    QPainter *painter = 0;

    const int numDirty = dirtyRegions.size();
    for (int i = 0; i < numDirty; ++i) {
        int r = dirtyRegions.at(i);
        QDecoration::DecorationState state = dirtyStates.at(i);

        QRegion clipRegion = dec.region(managed, clipRect, r);
        if (!clipRegion.isEmpty()) {
            if (!painter) {
                painter = new QPainter(paintDevice);
                painter->setFont(qApp->font());
                painter->translate(bs->topLevelOffset());
            }
            clipRegion.translate(-bs->topLevelOffset());
            painter->setClipRegion(clipRegion);
            dec.paint(painter, managed, r, state);
        }
    }
    dirtyRegions.clear();
    dirtyStates.clear();
    delete painter;
}
Exemple #14
0
void QvisColorGridWidget::paintEvent(QPaintEvent* e)
{
  // If the pixmap has not been created, create it and draw into it.
  if (drawPixmap == 0)
  {
    drawPixmap = new QPixmap(width(), height());
    drawColorArray();
  }

  // Blit the pixmap onto the widget.
  QPainter paint;
  paint.begin(this);
  if (!e->region().isEmpty())
  {
    paint.setClipRegion(e->region());
    paint.setClipping(true);
  }
  paint.drawPixmap(0, 0, *drawPixmap);
  paint.end();
}
Exemple #15
0
void
Panner::paintEvent(QPaintEvent *e)
{
    Profiler profiler("Panner::paintEvent");

    QPaintEvent *e2 = new QPaintEvent(e->region().boundingRect());
    QGraphicsView::paintEvent(e2);

    QPainter paint;
    paint.begin(viewport());
    paint.setClipRegion(e->region());

    QPainterPath path;
    path.addRect(rect());
    path.addPolygon(mapFromScene(m_pannedRect));

    QColor c(GUIPalette::getColour(GUIPalette::PannerOverlay));
    c.setAlpha(80);
    paint.setPen(Qt::NoPen);
    paint.setBrush(c);
    paint.drawPath(path);

    paint.setBrush(Qt::NoBrush);
    paint.setPen(QPen(GUIPalette::getColour(GUIPalette::PannerOverlay), 0));
    paint.drawConvexPolygon(mapFromScene(m_pannedRect));

    if (m_pointerVisible && scene()) {
        QPoint top = mapFromScene(m_pointerTop);
        float height = m_pointerHeight;
        if (height == 0.f) height = scene()->height();
        QPoint bottom = mapFromScene
            (QPointF(m_pointerTop.x(), m_pointerTop.y() + height));
        paint.setPen(QPen(GUIPalette::getColour(GUIPalette::Pointer), 2));
        paint.drawLine(top, bottom);
    }

    RG_DEBUG << "draw polygon: " << mapFromScene(m_pannedRect);
    paint.end();

    emit pannerChanged(m_pannedRect);
}
Exemple #16
0
void Plotter::drawGrid(QPainter &painter)
{
//    noOfCurves = curveDataMap.count();
    QRect rect = this->printRect();
////    qDebug() << rect;
////    double x=0,y=0;
    double width = rect.width() - 1;
    double height = rect.height() - 1;
    double yStep;
    int div = 50;
    if((height/100) >= 5)
    {
        yStep = height / 100;
        div = 100;
    }
    else
    {
        yStep = height/ 50;
        div = 50;
    }

    double bottom = rect.bottom();
    double right = rect.right();
    double xStep = width / 100.0;

    painter.setClipRegion(rect);
    painter.save();
    painter.setPen(QPen(gridColor));
    painter.translate(rect.left(),rect.top() + 1);
    for( int i = 1 ; i < 100 ; i++)
    {
        painter.drawLine(xStep*i , 0 , xStep*i ,bottom);
    }
    for( int i = 1 ; i < div ; i++)
    {
        painter.drawLine(1 , yStep*i , right ,yStep*i);
    }
    painter.restore();

}
Exemple #17
0
void DAbstractSliderSpinBox::paint(QPainter& painter)
{
    Q_D(DAbstractSliderSpinBox);

    // Create options to draw spin box parts
    QStyleOptionSpinBox spinOpts = spinBoxOptions();
    spinOpts.rect.adjust(0, 2, 0, -2);

    // Draw "SpinBox".Clip off the area of the lineEdit to avoid double
    // borders being drawn
    painter.save();
    painter.setClipping(true);

    QRect eraseRect(QPoint(rect().x(), rect().y()),
                    QPoint(progressRect(spinOpts).right(), rect().bottom()));

    painter.setClipRegion(QRegion(rect()).subtracted(eraseRect));
    style()->drawComplexControl(QStyle::CC_SpinBox, &spinOpts, &painter, d->dummySpinBox);
    painter.setClipping(false);
    painter.restore();


    QStyleOptionProgressBar progressOpts = progressBarOptions();
    progressOpts.rect.adjust(0, 2, 0, -2);
    style()->drawControl(QStyle::CE_ProgressBar, &progressOpts, &painter, nullptr);

    // Draw focus if necessary
    if (hasFocus() && d->edit->hasFocus())
    {
        QStyleOptionFocusRect focusOpts;
        focusOpts.initFrom(this);
        focusOpts.rect = progressOpts.rect;
        focusOpts.backgroundColor = palette().color(QPalette::Window);
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &focusOpts, &painter, this);
    }
}
Exemple #18
0
void QDial::repaintScreen( const QRect *cr )
{
    QPainter p;
    p.begin( this );

    bool resetClipping = FALSE;

    // calculate clip-region for erasing background
    if ( cr ) {
	p.setClipRect( *cr );
    } else if ( !d->onlyOutside && d->eraseAreaValid ) {
	QRegion reg = d->eraseArea;
	double a;
	reg = reg.subtract( calcArrow( a ) );
	p.setClipRegion( reg );
	resetClipping = TRUE;
    }

    QRect br( calcDial() );
    p.setPen( NoPen );
    // if ( style() == MotifStyle )
    // p.setBrush( colorGroup().brush( QColorGroup::Mid ) );
    // else {
    QBrush b;
    if ( colorGroup().brush( QColorGroup::Light ).pixmap() )
	b = QBrush( colorGroup().brush( QColorGroup::Light ) );
    else
	b = QBrush( colorGroup().light(), Dense4Pattern );
    p.setBrush( b );
    p.setBackgroundMode( OpaqueMode );
    // }

    QRect te = br;
    te.setWidth(te.width()+2);
    te.setHeight(te.height()+2);
    // erase background of dial
    if ( !d->onlyOutside ) {
	p.drawEllipse( te );
    }

    // erase remaining space around the dial
    QRegion remaining( 0, 0, width(), height() );
    remaining = remaining.subtract( QRegion( te, QRegion::Ellipse ) );
    if ( p.hasClipping() )
	remaining = remaining.intersect( p.clipRegion() );
    erase(remaining);

    if ( resetClipping ) {
	if ( cr )
	    p.setClipRect( *cr );
	else
	    p.setClipRect( QRect( 0, 0, width(), height() ) );
    }

    // draw notches
    if ( d->showNotches ) {
	calcLines();
	p.setPen( colorGroup().foreground() );
	p.drawLineSegments( d->lines );
    }

    // calculate and paint arrow
    p.setPen( QPen( colorGroup().dark() ) );
    p.drawArc( te, 60 * 16, 180 * 16 );
    p.setPen( QPen( colorGroup().light() ) );
    p.drawArc( te, 240 * 16, 180 * 16 );

    double a;
    QPointArray arrow( calcArrow( a ) );
    QRect ea( arrow.boundingRect() );
    d->eraseArea = ea;
    d->eraseAreaValid = TRUE;

    p.setPen( NoPen );
    p.setBrush( colorGroup().brush( QColorGroup::Button ) );
    if ( !d->onlyOutside )
	p.drawPolygon( arrow );

    a = angle( QPoint( width() / 2, height() / 2 ), arrow[ 0 ] );
    p.setBrush( Qt::NoBrush );

    // that's still a hack...
    if ( a <= 0 || a > 200 ) {
	p.setPen( colorGroup().light() );
	p.drawLine( arrow[ 2 ], arrow[ 0 ] );
	p.drawLine( arrow[ 1 ], arrow[ 2 ] );
	p.setPen( colorGroup().dark() );
	p.drawLine( arrow[ 0 ], arrow[ 1 ] );
    } else if ( a > 0 && a < 45 ) {
	p.setPen( colorGroup().light() );
	p.drawLine( arrow[ 2 ], arrow[ 0 ] );
	p.setPen( colorGroup().dark() );
	p.drawLine( arrow[ 1 ], arrow[ 2 ] );
	p.drawLine( arrow[ 0 ], arrow[ 1 ] );
    } else if ( a >= 45 && a < 135 ) {
	p.setPen( colorGroup().dark() );
	p.drawLine( arrow[ 2 ], arrow[ 0 ] );
	p.drawLine( arrow[ 1 ], arrow[ 2 ] );
	p.setPen( colorGroup().light() );
	p.drawLine( arrow[ 0 ], arrow[ 1 ] );
    } else if ( a >= 135 && a < 200 ) {
	p.setPen( colorGroup().dark() );
	p.drawLine( arrow[ 2 ], arrow[ 0 ] );
	p.setPen( colorGroup().light() );
	p.drawLine( arrow[ 0 ], arrow[ 1 ] );
	p.drawLine( arrow[ 1 ], arrow[ 2 ] );
    }

    // draw focus rect around the dial
    if ( hasFocus() ) {
	p.setClipping( FALSE );
	br.setWidth( br.width() + 2 );
	br.setHeight( br.height() + 2 );
	if ( d->showNotches ) {
	    int r = QMIN( width(), height() ) / 2;
	    br.moveBy( -r / 6, - r / 6 );
	    br.setWidth( br.width() + r / 3 );
	    br.setHeight( br.height() + r / 3 );
	}
	// strange, but else we get redraw errors on Windows
	p.end();
	p.begin( this );
	p.save();
	p.setPen( QPen( colorGroup().background() ) );
	p.setBrush( NoBrush );
	p.drawRect( br );
	p.restore();
	style().drawPrimitive( QStyle::PE_FocusRect, &p, br, colorGroup());
    }
    p.end();
}
void OscilloscopeView::paintEvent( QPaintEvent *e)
{
	QRect r = e->rect();
	
	if(b_needRedraw)
	{
		updateOutputHeight();
		const double pixelsPerSecond = Oscilloscope::self()->pixelsPerSecond();
		
        if (!m_pixmap) {
            qWarning() << Q_FUNC_INFO << " unexpected null m_pixmap in " << this;
            return;
        }

		QPainter p;
		//m_pixmap->fill( paletteBackgroundColor());
        m_pixmap->fill( palette().color( backgroundRole() ));
		const bool startSuccess = p.begin(m_pixmap);
        if ((!startSuccess) || (!p.isActive())) {
            qWarning() << Q_FUNC_INFO << " painter is not active";
        }

		p.setClipRegion(e->region());
		
		//BEGIN Draw vertical marker lines
		const double divisions = 5.0;
		const double min_sep = 10.0;
		
		double spacing = pixelsPerSecond/(std::pow( divisions, std::floor(std::log(pixelsPerSecond/min_sep)/std::log(divisions))));
		
		// Pixels offset is the number of pixels that the view is scrolled along
		const int64_t pixelsOffset = int64_t(Oscilloscope::self()->scrollTime()*pixelsPerSecond/LOGIC_UPDATE_RATE);
		double linesOffset = - lld_modulus( pixelsOffset, spacing);
		
		int blackness = 256 - int(184.0 * spacing / (min_sep*divisions*divisions));
		p.setPen( QColor( blackness, blackness, blackness));
		
		for( double i = linesOffset; i <= frameRect().width(); i += spacing)
			p.drawLine( int(i), 1, int(i), frameRect().height()-2);
		
		
		
		spacing *= divisions;
		linesOffset = - lld_modulus( pixelsOffset, spacing);
		
		blackness = 256 - int(184.0 * spacing / (min_sep*divisions*divisions));
		p.setPen( QColor( blackness, blackness, blackness));
		
		for( double i = linesOffset; i <= frameRect().width(); i += spacing)
			p.drawLine( int(i), 1, int(i), frameRect().height()-2);
		
		
		
		spacing *= divisions;
		linesOffset = - lld_modulus( pixelsOffset, spacing);
		
		blackness = 256 - int(184.0);
		p.setPen( QColor( blackness, blackness, blackness));
		
		for( double i = linesOffset; i <= frameRect().width(); i += spacing)
			p.drawLine( int(i), 1, int(i), frameRect().height()-2);
		//END Draw vertical marker lines
		
		drawLogicData(p);
		drawFloatingData(p);
		
		p.setPen(Qt::black);
		p.drawRect( frameRect());
		
		b_needRedraw = false;
	}
	
	//bitBlt( this, r.x(), r.y(), m_pixmap, r.x(), r.y(), r.width(), r.height()); // 2018.12.07
	QPainter p;
    const bool paintStarted = p.begin(this);
    if (!paintStarted) {
        qWarning() << Q_FUNC_INFO << " failed to start painting ";
    }
    p.drawImage(r, m_pixmap->toImage(), r);

}
Exemple #20
0
void DAbstractSliderSpinBox::paintPlastique(QPainter& painter)
{
    Q_D(DAbstractSliderSpinBox);

    QStyleOptionSpinBox spinOpts         = spinBoxOptions();
    QStyleOptionProgressBar progressOpts = progressBarOptions();

    style()->drawComplexControl(QStyle::CC_SpinBox, &spinOpts, &painter, d->dummySpinBox);

    painter.save();

    QRect rect = progressOpts.rect.adjusted(2, 0, -2, 0);
    QRect leftRect;

    int progressIndicatorPos = (progressOpts.progress - double(progressOpts.minimum)) / qMax(double(1.0),
                                double(progressOpts.maximum) - progressOpts.minimum) * rect.width();

    if (progressIndicatorPos >= 0 && progressIndicatorPos <= rect.width())
    {
        leftRect = QRect(rect.left(), rect.top(), progressIndicatorPos, rect.height());
    }
    else if (progressIndicatorPos > rect.width())
    {
        painter.setPen(palette().highlightedText().color());
    }
    else
    {
        painter.setPen(palette().buttonText().color());
    }

    QRegion rightRect = rect;
    rightRect = rightRect.subtracted(leftRect);

    QTextOption textOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter);
    textOption.setWrapMode(QTextOption::NoWrap);

    if (!(d->edit && d->edit->isVisible()))
    {
        painter.setClipRegion(rightRect);
        painter.setClipping(true);
        painter.drawText(rect.adjusted(-2, 0, 2, 0), progressOpts.text, textOption);
        painter.setClipping(false);
    }

    if (!leftRect.isNull())
    {
        painter.setPen(palette().highlight().color());
        painter.setBrush(palette().highlight());
        painter.drawRect(leftRect.adjusted(0, 0, 0, -1));

        if (!(d->edit && d->edit->isVisible()))
        {
            painter.setPen(palette().highlightedText().color());
            painter.setClipRect(leftRect.adjusted(0, 0, 1, 0));
            painter.setClipping(true);
            painter.drawText(rect.adjusted(-2, 0, 2, 0), progressOpts.text, textOption);
            painter.setClipping(false);
        }
    }

    painter.restore();
}
void CorrelationView::print(QPainter& printPainter,QPaintDeviceMetrics& metrics,bool whiteBackground){
  printState = true;
  
 //Draw the double buffer (pixmap) by copying it into the printer device throught the painter.
  QRect viewportOld = QRect(viewport.left(),viewport.top(),viewport.width(),viewport.height());

 //If the left margin is not visible (the user zoomed without taking it in his selection), the viewport and the printer
  //have the same size.
  QRect r((QRect)window);
  if(r.left() != 0) viewport = QRect(printPainter.viewport().left(),printPainter.viewport().top(),printPainter.viewport().width(),printPainter.viewport().height()-10);
  else viewport = QRect(printPainter.viewport().left() + XMARGIN,printPainter.viewport().top(),printPainter.viewport().width() - XMARGIN,printPainter.viewport().height()-10);
  
  //Set the window (part of the world I want to show)
  printPainter.setWindow(r.left(),r.top(),r.width()-1,r.height()-1);//hack because Qt QRect is used differently in this function
  
  //Set the viewport (part of the device I want to write on).
  //By default, the viewport is the same as the device's rectangle (contentsRec), taking a smaller
  //one will ensure that the legends (cluster ids) will not ovelap a correlogram.
  printPainter.setViewport(viewport);

  //Fill the background with the background color and ensure we draw the same portion of the world than on the screen
  QRect back = QRect(r.left(),r.top(),r.width(),r.height());
  float heightRatio = (static_cast<float>(back.height())/static_cast<float>(metrics.height()));
  back.setBottom(r.top() + r.height() - 1 + static_cast<long>(10 * heightRatio));
  float widthRatio = (static_cast<float>(back.width())/static_cast<float>(metrics.width()));
  if(r.left() == 0) back.setLeft(r.left() - static_cast<long>(XMARGIN * widthRatio));

  printRegion = QRegion(back);

  QColor colorLegendTmp = colorLegend;
  QColor background= backgroundColor();
  if(whiteBackground){
   colorLegend = black;
   setPaletteBackgroundColor(white);
  }
  
  printPainter.fillRect(back,backgroundColor());
  printPainter.setClipRegion(printRegion,QPainter::CoordPainter);

  //Paint all the correlograms in the pairs list (in the double buffer)
  drawCorrelograms(printPainter,pairs);

  //reset transformation due to setWindow and setViewport
  printPainter.resetXForm();

  //Draw the cluster Ids along the correlograms.
  drawClusterIds(printPainter);

  printPainter.setClipping(false);

  //Restore the colors.
  if(whiteBackground){
   colorLegend = colorLegendTmp;
   setPaletteBackgroundColor(background);
  }
  
  //Restore the previous state
  viewport = QRect(viewportOld.left(),viewportOld.top(),viewportOld.width(),viewportOld.height());

  printState = false;
}
void CorrelationView::drawCorrelograms(QPainter& painter,QValueList<Pair>& pairList){   
  
 //Clear the firing rate list
  firingRates.clear();
  
 //Sort the pair so the drawing will be simplified.
 qHeapSort(pairList); 
 
 //Loop on the pairs to be drawn.
 QValueList<Pair>::iterator pairIterator;

 ItemColors& clusterColors = doc.clusterColors();
 Data& clusteringData = doc.data();

 //The abscissa of the system coordinate center for the current correlogram.
 uint X = widthBorder;
 //The ordinate of the system coordinate center for the current correlogram.
 uint Y = heightBorder;
 //Number of verticals.
 int verticalNb = 0;
 //Clusters corresponding to the previous pair, they are initialized with the first pair.
 int previousCluster1 = pairList[0].getX();
 int previousCluster2 = pairList[0].getY();
 QColor clusterColor;
 
 //If it is an update that means that there some correlograms to redraw.
 //The position of those clusters in the drawing
 //has to been find in order to redraw them at the correct position.
 bool specificPosition = false;
 QValueList<int> shownClusters;
 if(drawContentsMode == UPDATE){
  specificPosition = true;
  QValueList<int>::const_iterator iterator;
  QValueList<int> const clusters = view.clusters();
  for(iterator = clusters.begin(); iterator != clusters.end(); ++iterator)
   shownClusters.append(*iterator);
  qHeapSort(shownClusters);
 }

 for(pairIterator = pairList.begin(); pairIterator != pairList.end(); ++pairIterator){
  int cluster1 = (*pairIterator).getX();
  int cluster2 = (*pairIterator).getY();
  
  //Get the iterator on the values of the current correlogram.
  Data::CorrelogramIterator iterator = clusteringData.correlogramIterator(*pairIterator,scaleMode,binSize,timeWindow);
      
  if(!iterator.isDataAvailable()) continue;  

  //Find the position of the next correlogram.
  if(specificPosition){
   int index1 = shownClusters.findIndex(cluster1);
   int index2 = shownClusters.findIndex(cluster2);
   X = widthBorder + index1 * shift;
   Y = heightBorder + index2 * (YsizeForMaxAmp + Yspace);
  }
  else{
   //The correlogram will be place on the current vertical. 
   if(cluster1 == previousCluster1 && cluster2 != previousCluster2){
    Y += (YsizeForMaxAmp + Yspace);
   } 
   //The correlogram will be place on a new vertical.
   if(cluster1 != previousCluster1){
    X += shift;
    verticalNb++;
    Y = verticalNb * (YsizeForMaxAmp + Yspace) + heightBorder;
   }
  }
  //Update previousCluster1 and previousCluster2 for the next loop
  previousCluster1 = cluster1;
  previousCluster2 = cluster2;                                                                                  

  if(cluster1 == cluster2){
   //Get the firing rate and ensure that there always 2 digits after the dot.
   float firingRate = iterator.getFiringRate();
   firingRate = floor((firingRate * 100) + 0.5) / 100;
   QString firingRateString = QString("%1").arg(firingRate);
   QStringList parts = QStringList::split(".", firingRateString);
   if(parts.count() == 1) firingRateString += ".00";
   else{
    QString precision = parts[1];
    if(precision.length() == 1) firingRateString += "0";
   }
   firingRates.insert(cluster1,firingRateString);
    
   //Get the color associated with the cluster and set the color to use to this color.
   clusterColor = clusterColors.color(cluster1);
   painter.setBrush(QBrush(clusterColor));
   //Do not draw the outlines of the rectangles if there is more than one pair.
   painter.setPen(NoPen);
   }
  else{
   //Use white to draw if the background is dark (the legend is then white) and grey if it is white.
   if(colorLegend == white) clusterColor = white;
   else clusterColor = gray;
   painter.setBrush(QBrush(clusterColor));
   //Do not draw the outlines of the rectangles if there is more than one pair.
   painter.setPen(NoPen);
  }
      
  uint x = 0;

  //Set the clip region to the rectangle defined by a correlogram unit.
  //If the view is been printed, a clip region has been created, take it into account
  if(printState){
   QRegion region = QRegion (X,-(Y+YsizeForMaxAmp),binWidth * nbBins + 1,YsizeForMaxAmp + 1);
   QRegion intersection = printRegion.intersect(region);
   painter.setClipRegion(intersection,QPainter::CoordPainter);
  }
  else painter.setClipRect(X,-(Y+YsizeForMaxAmp),binWidth * nbBins + 1,YsizeForMaxAmp + 1,QPainter::CoordPainter);
    
  //Iterate over the values of the current correlogram and draw them.
  for(;iterator.hasNext();){
   //The point is drawn in the QT coordinate system where the Y axis in oriented downwards
   //The value receive from the iterator is already inverted.
   float value = iterator.next();
   int y = -Y + static_cast<int>(value * Yfactor);
   painter.drawRect(x + X,y,binWidth + 1,- static_cast<int>(value * Yfactor)  + 1);
   x += binWidth;
  }
  //Draw a bottom line.
  if(printState) painter.setClipRegion(printRegion,QPainter::CoordPainter);
  else painter.setClipping(false);
  painter.setPen(clusterColor);
  painter.drawLine(X - (Xspace/5),-Y,X + (binWidth * nbBins) + (Xspace/5),-Y);
  //Draw time marks
  painter.drawLine(X + tickMarkZero,-Y,X + tickMarkZero,-Y + 5);
  for(int i = 1; i<=nbTickMarks;++i){
   int step = static_cast<int>(floor(0.5 + (i * tickMarkStep)));
   painter.drawLine(X + tickMarkZero + step,-Y,X + tickMarkZero + step,-Y + 5);
   painter.drawLine(X + tickMarkZero - step,-Y,X + tickMarkZero - step,-Y + 5);
  }
   

  //Draw the shoulder dash line if asked for.  
  if(shoulderLine){
   painter.setPen(QPen(QColor(60,60,60),0,Qt::DotLine));
   int y = -Y + static_cast<int>(iterator.getScaledShoulder() * Yfactor);
   painter.drawLine(X - (Xspace/10),y,X + (binWidth * nbBins) + (Xspace/10),y);
  }
 }
}