void GraphicsContext::clip(const FloatRect& rect)
{
    if (paintingDisabled())
        return;

    QPainter *p = m_data->p();
    if (p->clipRegion().isEmpty())
        p->setClipRect(rect);
    else p->setClipRect(rect, Qt::IntersectClip);
}
示例#2
0
void COverlayText::draw(QPainter& p, const QRect& viewport)
{
    if(highlight)
    {
        p.setBrush(Qt::white);
        p.setPen(QPen(Qt::blue,3));
    }
    else
    {
        p.setBrush(Qt::white);
        p.setPen(QPen(Qt::darkGray,2));
    }
    PAINT_ROUNDED_RECT(p,rect);

    if(selected == this)
    {
        p.setBrush(Qt::white);
        p.setPen(QPen(Qt::red, 3));
        PAINT_ROUNDED_RECT(p,rect);

        p.drawPixmap(rectMove, QPixmap(":/icons/iconMoveMap16x16.png"));
        p.drawPixmap(rectSize, QPixmap(":/icons/iconSize16x16.png"));
        p.drawPixmap(rectDel, QPixmap(":/icons/iconClear16x16.png"));
        p.drawPixmap(rectEdit, QPixmap(":/icons/iconEdit16x16.png"));
    }
    p.save();
    p.setClipRect(rectDoc);
    p.translate(rectDoc.topLeft());
    doc->drawContents(&p);
    p.restore();
}
示例#3
0
  void Paint( QPainter& painter, int x, int y ) const {
    painter.save();

    QRect rect( x, y, Width(), Height() );
    painter.setClipRect( rect );

    // BG
    QPen pen = QPen( QColor( 160, 160, 160 ) );
    pen.setWidth( 3 );
    painter.setPen( pen );
    painter.setBrush( QBrush( QColor( 70, 70, 70, 175 ) ) );
    painter.drawRoundedRect( rect, 10, 10 );

    // Title
    y += Padding();
    painter.setPen( QPen( Qt::white) );
    painter.setFont( mTitleFont );
    painter.drawText( x, y, Width(), TitleHeight(), Qt::AlignCenter | Qt::AlignVCenter | Qt::TextDontClip, mTitle );
    y += TitleHeight() + RowSpacing();

    // Lines
    painter.setPen( QPen( Qt::white) );
    painter.setFont( mRowFont );
    for( const QVariantMap& it : mHistory ) {
      int mx = x + Padding();
      DrawMana( painter, mx, y, RowHeight(), RowHeight(), it["mana"].toInt() );
      int cx = mx + RowHeight() + 5;
      DrawCardLine( painter, cx, y, RowWidth() - cx, RowHeight(), it["name"].toString(), it["count"].toInt() );
      y += RowHeight();
      y += RowSpacing();
    }

    painter.restore();
  }
示例#4
0
void ClipboardProxyShape::paint(QPainter &painter, const KViewConverter &converter)
{
    painter.setClipRect(converter.documentToView(QRectF(QPointF(), size())));
    QSizeF nestedSize = m_child->size();
    QSizeF ourSize = size();
    const qreal scale = qMin(ourSize.width() / nestedSize.width(), ourSize.height() / nestedSize.height());
    if (scale != 1.0) {
        ZoomHandler zh;
        qreal x1;
        converter.zoom(&x1, &x1);
        zh.setAbsoluteZoom(x1 * scale);
        painter.save();
        m_child->paint(painter, zh);
        painter.restore();
        if (m_child->border())
            m_child->border()->paint(m_child, painter, zh);
    }
    else {
        painter.save();
        m_child->paint(painter, converter);
        painter.restore();
        if (m_child->border())
            m_child->border()->paint(m_child, painter, converter);
    }
}
示例#5
0
void SurfaceImpl::SetClip(PRectangle rc)
{
    Q_ASSERT(painter);

    painter->setClipRect(
            QRectF(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top));
}
示例#6
0
void AFCWidget::drawAmplitude(QPainter & painter, QRectF rect)
{
	if(m_dB_points.size()<2) return;

	painter.setClipping(true);
	painter.setClipRect(rect);
	painter.setRenderHint(QPainter::Antialiasing, true);
	

	//amplitude
	painter.setPen( QPen(QColor(0, 0, 0, 255)) );

	float prev_x=m_dB_points.first().x();
	float prev_y=m_dB_points.first().y();

	float dB_range = m_dB2-m_dB1;

	foreach(QPointF p, m_dB_points){
//		QPointF p1( rect.left()+log_coef*log10(prev_x-m_freq1)/freq_range*rect.width(), rect.bottom()-(prev_y-m_dB1)/dB_range*rect.height() );
//		QPointF p2( rect.left()+log_coef*log10(p.rx()-m_freq1)/freq_range*rect.width(), rect.bottom()-(p.ry()-m_dB1)/dB_range*rect.height() );

		//linear scale
//		QPointF p1( rect.left()+(prev_x-m_freq1)/(m_freq2-m_freq1)*rect.width(), rect.bottom()-(prev_y-m_dB1)/dB_range*rect.height() );
//		QPointF p2( rect.left()+(p.rx()-m_freq1)/(m_freq2-m_freq1)*rect.width(), rect.bottom()-(p.ry()-m_dB1)/dB_range*rect.height() );

		//log scale
		QPointF p1( rect.left()+logFreq(prev_x)*rect.width(), rect.bottom()-(prev_y-m_dB1)/dB_range*rect.height() );
		QPointF p2( rect.left()+logFreq(p.rx())*rect.width(), rect.bottom()-(p.ry()-m_dB1)/dB_range*rect.height() );


		if(p.x() <= m_freq2) painter.drawLine(p1, p2);
		prev_x = p.rx();
		prev_y = p.ry();
	}
示例#7
0
void QWebFramePrivate::renderFromTiledBackingStore(GraphicsContext* context, const QRegion& clip)
{
    ASSERT(frame->tiledBackingStore());

    if (!frame->view() || !frame->contentRenderer())
        return;

    QVector<QRect> vector = clip.rects();
    if (vector.isEmpty())
        return;

    QPainter* painter = context->platformContext();

    WebCore::FrameView* view = frame->view();
    
    int scrollX = view->scrollX();
    int scrollY = view->scrollY();
    context->translate(-scrollX, -scrollY);

    for (int i = 0; i < vector.size(); ++i) {
        const QRect& clipRect = vector.at(i);

        painter->save();
        
        QRect rect = clipRect.translated(scrollX, scrollY);
        painter->setClipRect(rect, Qt::IntersectClip);

        frame->tiledBackingStore()->paint(context, rect);

        painter->restore();
    }
}
示例#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();
}
示例#9
0
void
PlayField::paintPainterClip(QPainter &paint, int x, int y, int w, int h) {
  QRect rect(x, y, w, h);

  paint.setClipRect(rect);
  paint.setClipping(true);
  paintPainter(paint, rect);
}
示例#10
0
void KisCanvasWidgetBase::drawDecorations(QPainter & gc, const QRect &updateWidgetRect) const
{
    gc.save();
    if (!m_d->canvas) {
        dbgFile<<"canvas doesn't exist, in canvas widget base!";
    }
    // Setup the painter to take care of the offset; all that the
    // classes that do painting need to keep track of is resolution
    gc.setRenderHint(QPainter::Antialiasing);
    gc.setRenderHint(QPainter::TextAntialiasing);

    // This option does not do anything anymore with Qt4.6, so don't reenable it since it seems to break display
    // http://www.archivum.info/[email protected]/2010-01/00481/Re:-(Qt-interest)-Is-QPainter::HighQualityAntialiasing-render-hint-broken-in-Qt-4.6.html
    // gc.setRenderHint(QPainter::HighQualityAntialiasing);

    gc.setRenderHint(QPainter::SmoothPixmapTransform);


    gc.save();
    gc.setClipRect(updateWidgetRect);

    QTransform transform = m_d->coordinatesConverter->flakeToWidgetTransform();
    gc.setTransform(transform);

    // Paint the shapes (other than the layers)
    m_d->canvas->globalShapeManager()->paint(gc, *m_d->viewConverter, false);

    // draw green selection outlines around text shapes that are edited, so the user sees where they end
    gc.save();
    QTransform worldTransform = gc.worldTransform();
    gc.setPen( Qt::green );

    Q_FOREACH (KoShape *shape, canvas()->shapeManager()->selection()->selectedShapes()) {
        if (shape->shapeId() == "ArtisticText" || shape->shapeId() == "TextShapeID") {
            gc.setWorldTransform(shape->absoluteTransformation(m_d->viewConverter) * worldTransform);
            KoShape::applyConversion(gc, *m_d->viewConverter);
            gc.drawRect(QRectF(QPointF(), shape->size()));
        }
    }
    gc.restore();

    // Draw text shape over canvas while editing it, that's needs to show the text selection correctly
    QString toolId = KoToolManager::instance()->activeToolId();
    if (toolId == "ArtisticTextTool" || toolId == "TextTool") {
        gc.save();
        gc.setPen(Qt::NoPen);
        gc.setBrush(Qt::NoBrush);
        Q_FOREACH (KoShape *shape, canvas()->shapeManager()->selection()->selectedShapes()) {
            if (shape->shapeId() == "ArtisticText" || shape->shapeId() == "TextShapeID") {
                KoShapePaintingContext  paintContext(canvas(), false);
                gc.save();
                gc.setTransform(shape->absoluteTransformation(m_d->viewConverter) * gc.transform());
                canvas()->shapeManager()->paintShape(shape, gc, *m_d->viewConverter, paintContext);
                gc.restore();
            }
        }
        gc.restore();
    }
void QSGPainterNode::paint()
{
    QRect dirtyRect = m_dirtyRect.isNull() ? QRect(0, 0, m_size.width(), m_size.height()) : m_dirtyRect;

    QPainter painter;
    if (m_actualRenderTarget == QQuickPaintedItem::Image) {
        if (m_image.isNull())
            return;
        painter.begin(&m_image);
    } else {
        if (!m_gl_device) {
            m_gl_device = new QOpenGLPaintDevice(m_fboSize);
            m_gl_device->setPaintFlipped(true);
        }

        if (m_multisampledFbo)
            m_multisampledFbo->bind();
        else
            m_fbo->bind();

        painter.begin(m_gl_device);
    }

    if (m_smoothPainting) {
        painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
    }

    painter.scale(m_contentsScale, m_contentsScale);

    QRect sclip(qFloor(dirtyRect.x()/m_contentsScale),
                qFloor(dirtyRect.y()/m_contentsScale),
                qCeil(dirtyRect.width()/m_contentsScale+dirtyRect.x()/m_contentsScale-qFloor(dirtyRect.x()/m_contentsScale)),
                qCeil(dirtyRect.height()/m_contentsScale+dirtyRect.y()/m_contentsScale-qFloor(dirtyRect.y()/m_contentsScale)));

    if (!m_dirtyRect.isNull())
        painter.setClipRect(sclip);

    painter.setCompositionMode(QPainter::CompositionMode_Source);
    painter.fillRect(sclip, m_fillColor);
    painter.setCompositionMode(QPainter::CompositionMode_SourceOver);

    m_item->paint(&painter);
    painter.end();

    if (m_actualRenderTarget == QQuickPaintedItem::Image) {
        m_texture->setImage(m_image);
        m_texture->setDirtyRect(dirtyRect);
    } else if (m_multisampledFbo) {
        QOpenGLFramebufferObject::blitFramebuffer(m_fbo, dirtyRect, m_multisampledFbo, dirtyRect);
    }

    if (m_multisampledFbo)
        m_multisampledFbo->release();
    else if (m_fbo)
        m_fbo->release();

    m_dirtyRect = QRect();
}
示例#12
0
void PreviewWidget::drawShadow(QPainter &painter, QRectF rect)
{
    // Shadow width
    int width = qBound(4, int(qMax(rect.height(), rect.width())) / 100, 7);

    painter.save();
    painter.setClipRect(rect.adjusted(0, 0, width, width));

    QColor lightColor = this->palette().color(QPalette::Background);
    QColor darkColor  = lightColor.darker(160);

    QRectF shadowRect = rect.adjusted(0, 0, width, width);
    QLinearGradient lg;
    lg.setColorAt(0.0, darkColor);
    lg.setColorAt(1.0, lightColor);


    QRadialGradient rg;
    rg.setColorAt(0, darkColor);
    rg.setColorAt(1, lightColor);
    rg.setRadius(width);


    // Right
    lg.setStart(QPointF(rect.right(), rect.center().y()));
    lg.setFinalStop(QPointF(shadowRect.right(), rect.center().y()));
    painter.fillRect(rect.right(), rect.top() + width, width, rect.height() - width, lg);

    // Bottom
    lg.setStart(rect.center().x(),  rect.bottom());
    lg.setFinalStop(rect.center().x(), rect.bottom() + width);
    painter.fillRect(rect.left() + width, rect.bottom(), rect.width() - width, width, lg);

    //TopRight
    QPointF p;
    p = rect.bottomRight();
    rg.setCenter(p);
    rg.setFocalPoint(p);
    painter.fillRect(rect.right(), rect.bottom(), width, width, rg);

    // BottomRight
    p = rect.topRight();
    p.ry() += width;
    rg.setCenter(p);
    rg.setFocalPoint(p);
    painter.fillRect(rect.right(), rect.top(), width, width, rg);

    //BottomLeft
    p = rect.bottomLeft();
    p.rx() += width;
    rg.setCenter(p);
    rg.setFocalPoint(p);
    painter.fillRect(rect.left(), rect.bottom(), width, width, rg);


    painter.restore();
}
示例#13
0
void MusicShape::constPaint( QPainter& painter, const KoViewConverter& converter ) const
{
    applyConversion( painter, converter );

    painter.setClipping(true);
    painter.setClipRect(QRectF(0, 0, size().width(), size().height()));

    m_renderer->renderSheet( painter, m_sheet, m_firstSystem, m_lastSystem );
}
示例#14
0
void TextureMapperQt::beginClip(const TransformationMatrix& matrix, const FloatRect& rect)
{
    QPainter* painter = currentPainter();
    painter->save();
    QTransform prevTransform = painter->transform();
    painter->setTransform(matrix, false);
    painter->setClipRect(rect);
    painter->setTransform(prevTransform, false);
}
示例#15
0
void SignalPlot::paintEvent(QPaintEvent *event)
{
    QPainter painter;
    painter.begin(this);
    painter.setClipRect(event->rect());
    //painter.setRenderHint(QPainter::Antialiasing);
    painter.drawImage(QPoint(0,0), mBackground);
    drawSignal(painter);
    painter.end();
}
示例#16
0
void ItemDocument::print() {
	static KPrinter *printer = new KPrinter;

	if (! printer->setup(KTechlab::self()))
		return;

	// setup the printer.  with Qt, you always "print" to a
	// QPainter.. whether the output medium is a pixmap, a screen,
	// or paper
	QPainter p;
	p.begin(printer);

	// we let our view do the actual printing
	QPaintDeviceMetrics metrics(printer);

	// Round to 16 so that we cut in the middle of squares
	int w = metrics.width();
	w = (w & 0xFFFFFFF0) + ((w << 1) & 0x10);

	int h = metrics.height();
	h = (h & 0xFFFFFFF0) + ((h << 1) & 0x10);

	p.setClipping(true);
	p.setClipRect(0, 0, w, h, QPainter::CoordPainter);

	// Send off the painter for drawing
	m_canvas->setBackgroundPixmap(0);
	QRect bounding = canvasBoundingRect();

	unsigned int rows = (unsigned) std::ceil(double(bounding.height()) / double(h));
	unsigned int cols = (unsigned) std::ceil(double(bounding.width()) / double(w));

	int offset_x = bounding.x();
	int offset_y = bounding.y();

	for (unsigned row = 0; row < rows; ++row) {
		for (unsigned col = 0; col < cols; ++col) {
			if (row != 0 || col != 0)
				printer->newPage();

			QRect drawArea(offset_x + (col * w), offset_y + (row * h), w, h);

			m_canvas->drawArea(drawArea, & p);

			p.translate(-w, 0);
		}

		p.translate(w * cols, -h);
	}

	updateBackground();

	// and send the result to the printer
	p.end();
}
示例#17
0
void PlatformScrollbar::paint(GraphicsContext* graphicsContext, const IntRect& damageRect)
{
    if (controlSize() != RegularScrollbar) {
        m_opt.state |= QStyle::State_Mini;
    } else {
        m_opt.state &= ~QStyle::State_Mini;
    }
    m_opt.orientation = (orientation() == VerticalScrollbar) ? Qt::Vertical : Qt::Horizontal;
    QStyle *s = QApplication::style();
    if (orientation() == HorizontalScrollbar) {
        m_opt.rect.setHeight(horizontalScrollbarHeight(controlSize()));
        m_opt.state |= QStyle::State_Horizontal;
    } else {
        m_opt.rect.setWidth(verticalScrollbarWidth(controlSize()));
        m_opt.state &= ~QStyle::State_Horizontal;
    }

    if (graphicsContext->paintingDisabled() || !m_opt.rect.isValid())
        return;

    QRect clip = m_opt.rect.intersected(damageRect);
    // Don't paint anything if the scrollbar doesn't intersect the damage rect.
    if (clip.isEmpty())
        return;

    QPainter *p = graphicsContext->platformContext();
    p->save();
    p->setClipRect(clip);
    m_opt.sliderValue = value();
    m_opt.sliderPosition = value();
    m_opt.pageStep = m_visibleSize;
    m_opt.singleStep = m_lineStep;
    m_opt.minimum = 0;
    m_opt.maximum = qMax(0, m_totalSize - m_visibleSize);
    if (m_pressedPart != QStyle::SC_None) {
        m_opt.activeSubControls = m_pressedPart;
    } else {
        m_opt.activeSubControls = m_hoveredPart;
    }

    const QPoint topLeft = m_opt.rect.topLeft();
#ifdef Q_WS_MAC
    QApplication::style()->drawComplexControl(QStyle::CC_ScrollBar, &m_opt, p, 0);
#else
    p->translate(topLeft);
    m_opt.rect.moveTo(QPoint(0, 0));

    // The QStyle expects the background to be already filled
    p->fillRect(m_opt.rect, m_opt.palette.background());

    QApplication::style()->drawComplexControl(QStyle::CC_ScrollBar, &m_opt, p, 0);
    m_opt.rect.moveTo(topLeft);
#endif
    p->restore();
}
示例#18
0
void KWCopyShape::paint(QPainter &painter, const KoViewConverter &converter)
{
    painter.setClipRect(QRectF(QPointF(0, 0), converter.documentToView(size()))
                        .adjusted(-2, -2, 2, 2), // adjust for anti aliassing.
                        Qt::IntersectClip);
    painter.save();
    m_original->paint(painter, converter);
    painter.restore();
    if (m_original->border())
        m_original->border()->paintBorder(m_original, painter, converter);
}
示例#19
0
void QImageWidget::paintEvent( QPaintEvent *e )
{
  if( !image.isNull() )
  {
    QPainter p;
    p.begin(this);
    p.setClipRect(e->rect());
    p.drawImage(QPoint(0,0), image);
    p.end();
  }
}
void ThumbSlider::paintEvent(QPaintEvent *event)
{
	QPainter painter;

	painter.begin(this);
	painter.setClipRect(event->rect());
	painter.setPen(Qt::NoPen);

	drawBackground(&painter);
	drawLines(&painter);
	drawBorders(&painter);
	drawEdges(&painter);
}
示例#21
0
void SCAnimationDirector::paint(QPainter &painter, const QRectF &paintRect)
{
    if (m_pageEffectRunner)
    {
        bool finished = m_pageEffectRunner->isFinished();
        if (!m_pageEffectRunner->paint(painter))
        {
            delete m_pageEffectRunner;
            m_pageEffectRunner = 0;

            // check if there where a animation to start
            if (hasAnimation()) {
                if (finished) {
                    QRect clipRect = m_pageRect.intersected(paintRect.toRect());
                    painter.setClipRect(clipRect);
                    painter.setRenderHint(QPainter::Antialiasing);
                    paintStep(painter);
                }
                else {
                    // start the animations
                    startTimeLine(m_animations.at(m_stepIndex)->totalDuration());
                }
            }
        }
    }
    else {
        QRect clipRect = m_pageRect.intersected(paintRect.toRect());
        painter.setClipRect(clipRect);
        painter.setRenderHint(QPainter::Antialiasing);
        paintStep(painter);
    }
    // This is needed as otherwise on some ATI graphic cards it leads to
    // 100% CPU load of the x server and no more key events are received
    // until the page effect is finished. With it is made sure that key
    // events still get through so that it is possible to cancel the
    // events. It looks like this is not a problem with nvidia graphic
    // cards.
    KApplication::kApplication()->syncX();
}
示例#22
0
void KWCanvasBase::paint(QPainter &painter, const QRectF &paintRect)
{
    painter.translate(-m_documentOffset);

    static int iteration = 0;
    iteration++;

    if (m_viewMode->hasPages()) {

        int pageContentArea = 0;
        if (!m_cacheEnabled || !m_pageCacheManager) { // no caching, simple case

            QList<KWViewMode::ViewMap> map =
                    m_viewMode->mapExposedRects(paintRect.translated(m_documentOffset),
                                                viewConverter());
            foreach (KWViewMode::ViewMap vm, map) {
                painter.save();

                // Set up the painter to clip the part of the canvas that contains the rect.
                painter.translate(vm.distance.x(), vm.distance.y());
                vm.clipRect = vm.clipRect.adjusted(-1, -1, 1, 1);
                painter.setClipRect(vm.clipRect);

                // Paint the background of the page.
                QColor color = Qt::white;
#ifdef DEBUG_REPAINT
                color = QColor(random() % 255, random() % 255, random() % 255);
#endif
                painter.fillRect(vm.clipRect, QBrush(color));

                // Paint the contents of the page.
                painter.setRenderHint(QPainter::Antialiasing);
                m_shapeManager->paint(painter, *(viewConverter()), false); // Paint all shapes
                paintBorder(painter, vm);

                // Paint the page decorations: shadow, etc.
                paintPageDecorations(painter, vm);

                // Paint the grid
                paintGrid(painter, vm);

                // paint whatever the tool wants to paint
                m_toolProxy->paint(painter, *(viewConverter()));
                painter.restore();

                int contentArea = vm.clipRect.width() * vm.clipRect.height();
                if (contentArea > pageContentArea) {
                    pageContentArea = contentArea;
                }
            }
示例#23
0
void Legend::paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintContext)
{
    //painter.save();

    // First of all, scale the painter's coordinate system to fit the current zoom level
    applyConversion(painter, converter);

    // Calculate the clipping rect
    QRectF paintRect = QRectF(QPointF(0, 0), size());
    //clipRect.intersect(paintRect);
    painter.setClipRect(paintRect, Qt::IntersectClip);

    // Get the current zoom level
    QPointF zoomLevel;
    converter.zoom(&zoomLevel.rx(), &zoomLevel.ry());

    // Only repaint the pixmap if it is scheduled, the zoom level changed or the shape was resized
    /*if (   d->pixmapRepaintRequested
         || d->lastZoomLevel != zoomLevel
         || d->lastSize      != size()) {
        // TODO: What if two zoom levels are constantly being requested?
        // At the moment, this *is* the case, due to the fact
        // that the shape is also rendered in the page overview
        // in Stage
        // Every time the window is hidden and shown again, a repaint is
        // requested --> laggy performance, especially when quickly
        // switching through windows
        d->pixmapRepaintRequested = false;
        d->lastZoomLevel = zoomLevel;
        d->lastSize      = size();

        paintPixmap(painter, converter);
    }*/

    // Paint the background
    if (background()) {
        QPainterPath p;
        p.addRect(paintRect);
        background()->paint(painter, converter, paintContext, p);
    }

    // KChart thinks in pixels, Calligra in pt
    ScreenConversions::scaleFromPtToPx(painter);

    d->kdLegend->paint(&painter);

    //painter.restore();
    // Paint the cached pixmap
    //painter.drawImage(0, 0, d->image);
}
示例#24
0
//! [paint function]
void DisplayWidget::paint(QPainter &painter)
{
//![paint picture]
    painter.setClipRect(QRect(0, 0, 200, 200));
    painter.setPen(Qt::NoPen);

    switch (background) {
    case Sky:
    default:
        painter.fillRect(QRect(0, 0, 200, 200), Qt::darkBlue);
        painter.translate(145, 10);
        painter.setBrush(Qt::white);
        painter.drawPath(moon);
        painter.translate(-145, -10);
        break;
    case Trees:
    {
        painter.fillRect(QRect(0, 0, 200, 200), Qt::darkGreen);
        painter.setBrush(Qt::green);
        painter.setPen(Qt::black);
        for (int y = -55, row = 0; y < 200; y += 50, ++row) {
            int xs;
            if (row == 2 || row == 3)
                xs = 150;
            else
                xs = 50;
            for (int x = 0; x < 200; x += xs) {
                painter.save();
                painter.translate(x, y);
                painter.drawPath(tree);
                painter.restore();
            }
        }
        break;
    }
    case Road:
        painter.fillRect(QRect(0, 0, 200, 200), Qt::gray);
        painter.setPen(QPen(Qt::white, 4, Qt::DashLine));
        painter.drawLine(QLine(0, 35, 200, 35));
        painter.drawLine(QLine(0, 165, 200, 165));
        break;
    }

    painter.setBrush(shapeColor);
    painter.setPen(Qt::black);
    painter.translate(100, 100);
    painter.drawPath(shapeMap[shape]);
//![paint picture]
}
/*!
  draw an outline

  \warning Outlining functionality is obsolete: use QwtPlotPicker or
  QwtPlotZoomer.
*/
void QwtPlotCanvas::drawOutline(QPainter &p)
{
    const QRect &r = contentsRect();

    QColor bg = ((QwtPlot *)parent())->canvasBackground();

    QPen pn = d_pen;
    pn.setColor(QColor(bg.rgb() ^ d_pen.color().rgb()));

    p.setPen(pn);
    p.setRasterOp(XorROP);
    p.setClipRect(r);
    p.setClipping(TRUE);

    switch(d_outline)
    {
        case Qwt::VLine:
            QwtPainter::drawLine(&p, d_lastPoint.x(), 
                r.top(), d_lastPoint.x(), r.bottom());
            break;
        
        case Qwt::HLine:
            QwtPainter::drawLine(&p, r.left(), 
                d_lastPoint.y(), r.right(), d_lastPoint.y());
            break;
        
        case Qwt::Cross:
            QwtPainter::drawLine(&p, r.left(), 
                d_lastPoint.y(), r.right(), d_lastPoint.y());
            QwtPainter::drawLine(&p, d_lastPoint.x(), 
                r.top(), d_lastPoint.x(), r.bottom());
            break;

        case Qwt::Rect:
            QwtPainter::drawRect(&p, d_entryPoint.x(), d_entryPoint.y(),
               d_lastPoint.x() - d_entryPoint.x() + 1,
               d_lastPoint.y() - d_entryPoint.y() + 1);
            break;
        
        case Qwt::Ellipse:
            p.drawEllipse(d_entryPoint.x(), d_entryPoint.y(),
               d_lastPoint.x() - d_entryPoint.x() + 1,
               d_lastPoint.y() - d_entryPoint.y() + 1);
            break;

        default:
            break;
    }
}
示例#26
0
void ActiveLabel::paintEvent(QPaintEvent *event)
{
    if (m_iconPath.isEmpty()){
        QLabel::paintEvent(event);
        return;
    }
    QPainter painter;
    painter.begin(this);

    painter.setClipRect(rect());
    painter.setOpacity(m_opacity);
    painter.drawPixmap(0, 0, QPixmap(m_iconPath).scaled(size()));

    painter.end();
}
示例#27
0
void TicketPopup::paintEvent(QPaintEvent *e)
{
  QPainter painter;
  painter.begin(this);
  painter.setClipRect(e->rect());
  painter.setRenderHint(QPainter::Antialiasing);

  paint(&painter);
  painter.restore();
  painter.save();
  int level = 180;
  painter.setPen(QPen(QColor(level, level, level), 6));
  painter.setBrush(Qt::NoBrush);
  painter.drawRect(rect());
}
示例#28
0
void KviThemedComboBox::paintEvent(QPaintEvent * event)
{
#ifdef COMPILE_PSEUDO_TRANSPARENCY
	QPainter * p = new QPainter(this);
	QLineEdit * le = lineEdit();
	if(le)
	{
		QRect r = rect();
		QPalette pal = palette();

		QStyleOptionFrame option;

		option.initFrom(this);
		option.rect = contentsRect();
		option.lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, le);
		option.midLineWidth = 0;
		option.state |= QStyle::State_Sunken;
		if(le->isReadOnly())
			option.state |= QStyle::State_ReadOnly;
		option.features = QStyleOptionFrame::None;
		style()->drawPrimitive(QStyle::PE_FrameLineEdit, &option, p, this);

		r = style()->subElementRect(QStyle::SE_LineEditContents, &option, le);
		int left, right, top, bottom;
		le->getTextMargins(&left, &top, &right, &bottom);
		r.setX(r.x() + left);
		r.setY(r.y() + top);
		r.setRight(r.right() - right);
		r.setBottom(r.bottom() - bottom);
		p->setClipRect(r);
	} // else not editable

	if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing())
	{
		p->setCompositionMode(QPainter::CompositionMode_Source);
		QColor col = KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade);
		col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100));
		p->fillRect(contentsRect(), col);
	}
	else if(g_pShadedChildGlobalDesktopBackground)
	{
		QPoint pnt = m_pKviWindow->isDocked() ? mapTo(g_pMainWindow, contentsRect().topLeft()) : mapTo(m_pKviWindow, contentsRect().topLeft());
		p->drawTiledPixmap(contentsRect(), *(g_pShadedChildGlobalDesktopBackground), pnt);
	}
	delete p;
#endif
	QComboBox::paintEvent(event);
}
示例#29
0
// Sven Wiegand <*****@*****.**> -- eps output filter (from KSnapshot)
KDE_EXPORT void kimgio_eps_write(QImageIO *imageio)
{
    QPrinter psOut(QPrinter::PrinterResolution);
    QPainter p;

    // making some definitions (papersize, output to file, filename):
    psOut.setCreator("KDE " KDE_VERSION_STRING);
    psOut.setOutputToFile(true);

    // Extension must be .eps so that Qt generates EPS file
    KTempFile tmpFile(QString::null, ".eps");
    tmpFile.setAutoDelete(true);
    if(tmpFile.status() != 0)
        return;
    tmpFile.close(); // Close the file, we just want the filename

    psOut.setOutputFileName(tmpFile.name());
    psOut.setFullPage(true);

    // painting the pixmap to the "printer" which is a file
    p.begin(&psOut);
    // Qt uses the clip rect for the bounding box
    p.setClipRect(0, 0, imageio->image().width(), imageio->image().height(), QPainter::CoordPainter);
    p.drawImage(QPoint(0, 0), imageio->image());
    p.end();

    // Copy file to imageio struct
    QFile inFile(tmpFile.name());
    inFile.open(IO_ReadOnly);

    QTextStream in(&inFile);
    in.setEncoding(QTextStream::Latin1);
    QTextStream out(imageio->ioDevice());
    out.setEncoding(QTextStream::Latin1);

    QString szInLine = in.readLine();
    out << szInLine << '\n';

    while(!in.atEnd())
    {
        szInLine = in.readLine();
        out << szInLine << '\n';
    }

    inFile.close();

    imageio->setStatus(0);
}
示例#30
0
void NativeRenderDialog::render(QPainter& P, QRect theR, RendererOptions opt)
{
    P.setClipRect(theR);
    P.setClipping(true);
    P.setRenderHint(QPainter::Antialiasing);

    mapview->setGeometry(theR);
    mapview->setViewport(boundingBox(), theR);
    mapview->setRenderOptions(opt);
    mapview->invalidate(true, true, false);
    mapview->drawFeaturesSync(P);
    if (opt.options & RendererOptions::ScaleVisible)
        mapview->drawScale(P);
    if (opt.options & RendererOptions::LatLonGridVisible)
        mapview->drawLatLonGrid(P);
}