static void write(QTextStream &ts, RenderLayer &l,
                  const QRect& layerBounds, const QRect& backgroundClipRect, const QRect& clipRect,
                  int layerType = 0, int indent = 0)
{
    writeIndent(ts, indent);
    
    ts << "layer";
    ts << " " << layerBounds;

    if (layerBounds != layerBounds.intersect(backgroundClipRect))
        ts << " backgroundClip " << backgroundClipRect;
    if (layerBounds != layerBounds.intersect(clipRect))
        ts << " clip " << clipRect;

    if (l.renderer()->hasOverflowClip()) {
        if (l.scrollXOffset())
            ts << " scrollX " << l.scrollXOffset();
        if (l.scrollYOffset())
            ts << " scrollY " << l.scrollYOffset();
        if (l.renderer()->clientWidth() != l.scrollWidth())
            ts << " scrollWidth " << l.scrollWidth();
        if (l.renderer()->clientHeight() != l.scrollHeight())
            ts << " scrollHeight " << l.scrollHeight();
    }

    if (layerType == -1)
        ts << " layerType: background only";
    else if (layerType == 1)
        ts << " layerType: foreground only";
    
    ts << "\n";

    if (layerType != -1)
        write(ts, *l.renderer(), indent + 1);
}
QRect KstGfxMouseHandlerUtils::resizeRectFromEdgeCentered(const QRect& originalRect, const QPoint& anchorPoint, const QPoint& movePoint, const QPoint& pos, const QRect& bounds, bool maintainAspect) {
  QRect newRect;
  bool vertical;
  int newHalfWidth = abs((pos - anchorPoint).x());
  int newHalfHeight = abs((pos - anchorPoint).y());

  if (movePoint.x() == anchorPoint.x()) {
    vertical = true;
  } else {
    vertical = false;
  }

  if (maintainAspect) {
    QSize newSize(originalRect.size());

    if (vertical) {
      newHalfHeight = kMin(newHalfHeight, anchorPoint.y() - bounds.top());
      newHalfHeight = kMin(newHalfHeight, bounds.bottom() - anchorPoint.y());
      if (newHalfHeight > originalRect.height()/2) {
        newSize.scale(originalRect.width(), 2*newHalfHeight, QSize::ScaleMax);
      } else {
        newSize.scale(originalRect.width(), 2*newHalfHeight, QSize::ScaleMin);
      }
    } else {
      newHalfWidth = kMin(newHalfWidth, anchorPoint.x() - bounds.left());
      newHalfWidth = kMin(newHalfWidth, bounds.right() - anchorPoint.x());
      if (newHalfWidth > originalRect.width()/2) {
        newSize.scale(2*newHalfWidth, originalRect.height(), QSize::ScaleMax);
      } else {
        newSize.scale(2*newHalfWidth, originalRect.height(), QSize::ScaleMin);
      }
    }

    newRect.setSize(newSize);
    newRect.moveCenter(anchorPoint);
    newRect = newRect.intersect(bounds);
  } else {
    if (vertical) {
      newRect = QRect(0, 0, originalRect.width(), 2*newHalfHeight);
    } else {
      newRect = QRect(0, 0, 2*newHalfWidth, originalRect.height());
    }
    newRect.moveCenter(anchorPoint);
    newRect = newRect.intersect(bounds);
  }

  return newRect;
}
Example #3
0
/*!
    Wrapper for QPainter::fillRect()
*/
void QwtPainter::fillRect(QPainter *painter,
    const QRect &rect, const QBrush &brush)
{
    if ( !rect.isValid() )
        return;

    QRect clipRect;
    const bool deviceClipping = isClippingNeeded(painter, clipRect);

#if QT_VERSION >= 0x040000
    /*
      Performance of Qt4 is horrible for non trivial brushs. Without
      clipping expect minutes or hours for repainting large rects
      (might result from zooming)
    */

    if ( deviceClipping )
        clipRect &= painter->window();
    else
        clipRect = painter->window();

    if ( painter->hasClipping() )
        clipRect &= painter->clipRegion().boundingRect();
#endif

    QRect r = d_metricsMap.layoutToDevice(rect, painter);
    if ( deviceClipping )
        r = r.intersect(clipRect);

    if ( r.isValid() )
        painter->fillRect(r, brush);
}
Example #4
0
QImage KisPixelSelection::maskImage(const QRect & rc) const
{
    // If part of a KisAdjustmentLayer, there may be no parent device.
    QImage img;
    QRect bounds;
    if (m_d->parentPaintDevice) {
        bounds = m_d->parentPaintDevice->exactBounds();
        bounds = bounds.intersect(rc);
        img = QImage(bounds.width(), bounds.height(), QImage::Format_RGB32);
    } else {
        bounds = rc;
        img = QImage(bounds.width(), bounds.height(), QImage::Format_RGB32);
    }

    KisHLineConstIteratorPixel it = createHLineConstIterator(bounds.x(), bounds.y(), bounds.width());
    for (int y2 = bounds.y(); y2 < bounds.height() - bounds.y(); ++y2) {
        int x2 = 0;
        while (!it.isDone()) {
            quint8 s = MAX_SELECTED - *(it.rawData());
            qint32 c = qRgb(s, s, s);
            img.setPixel(x2, y2, c);
            ++x2;
            ++it;
        }
        it.nextRow(); // XXX: Why wasn't this line here? Used to be
        // present in 1.6.
    }
    return img;
}
Example #5
0
void PanelKMenu::paintEvent(QPaintEvent * e)
{
    if (sidePixmap.isNull()) {
        PanelServiceMenu::paintEvent(e);
        return;
    }

    QPainter p(this);
    p.setClipRegion(e->region());

    style().drawPrimitive( QStyle::PE_PanelPopup, &p,
                           QRect( 0, 0, width(), height() ),
                           colorGroup(), QStyle::Style_Default,
                           QStyleOption( frameWidth(), 0 ) );

    QRect r = sideImageRect();
    r.setBottom( r.bottom() - sidePixmap.height() );
    if ( r.intersects( e->rect() ) )
    {
        p.drawTiledPixmap( r, sideTilePixmap );
    }

    r = sideImageRect();
    r.setTop( r.bottom() - sidePixmap.height() );
    if ( r.intersects( e->rect() ) )
    {
        QRect drawRect = r.intersect( e->rect() );
        QRect pixRect = drawRect;
        pixRect.moveBy( -r.left(), -r.top() );
        p.drawPixmap( drawRect.topLeft(), sidePixmap, pixRect );
    }

    drawContents( &p );
}
Example #6
0
void CGMainWindow::applyFilter(BaseFilter* filter)
{
    QMdiSubWindow *active = ui->mdiArea->activeSubWindow();
    if (active != NULL)
    {
        MdiElement* activeElement =
            dynamic_cast<MdiElement*> (active->widget());

        QImage image =  activeElement->pixmap().toImage();
        QImage result;
        if (!activeElement->isRubberBandVisible()) {
            result = filter->process(image);
        } else {
            QRectF selection = activeElement->getSelectionRect();
            QRect boundingRect = QRect(selection.left(), selection.top(), selection.width(), selection.height());
            boundingRect = boundingRect.intersect(image.rect());
            QImage toProcess = image.copy(boundingRect);
            QImage areaResult = filter->process(toProcess);
            result = image;
            for (int i = boundingRect.left(); i < boundingRect.right(); ++i) {
                for (int j = boundingRect.top(); j < boundingRect.bottom(); ++j) {
                    result.setPixel(i, j, areaResult.pixel(i - boundingRect.left(), j - boundingRect.top()));
                }
            }
            activeElement->hideRubberBand();

        }
        QPixmap pixmap = QPixmap::fromImage(result);
        activeElement->setPixmap(pixmap);

    }
}
Example #7
0
void HTMLCell::select( KHTMLWidget *_htmlw, HTMLChain *_chain, QRect & _rect, int _tx, int _ty )
{
    HTMLObject *obj;

    QRect r( x + _tx, y - ascent + _ty, width, ascent + descent );

    _tx += x;
    _ty += y - ascent;

    bool sel = false;

    if ( _rect.contains( r ) )
    {
	sel = true;
    }
    else if ( !_rect.intersects( r ) )
    {
	sel = false;
    }
    else
    {
	QRect isect = _rect.intersect( r );
	if ( isect.width() > r.width()/2 && isect.height() > r.height()/2 )
	    sel = true;
    }

    _chain->push( this );

    for ( obj = head; obj != 0; obj = obj->next() )
	obj->select( _htmlw, _chain, sel, _tx, _ty );

    _chain->pop();
}
Example #8
0
void
PrettyPopupMenu::paintEvent( QPaintEvent* e )
{
    generateSidePixmap();

    QPainter p( this );

    QRect r = sideImageRect();
    r.setTop( r.bottom() - s_sidePixmap.height() );
    if ( r.intersects( e->rect() ) )
    {
        QRect drawRect = r.intersect( e->rect() ).intersect( sideImageRect() );
        QRect pixRect = drawRect;
        pixRect.moveBy( -r.left(), -r.top() );
        p.drawImage( drawRect.topLeft(), s_sidePixmap, pixRect );
    }

    p.setClipRegion( e->region() );


    //NOTE The order is important here. drawContents() must be called before drawPrimitive(),
    //     otherwise we get rendering glitches.

    drawContents( &p );

    style().drawPrimitive( QStyle::PE_PanelPopup, &p,
                           QRect( 0, 0, width(), height() ),
                           colorGroup(), QStyle::Style_Default,
                           QStyleOption( frameWidth(), 0 ) );
}
Example #9
0
void ColourBrush::endCapture()
{
    if (mBrushBehavior != Capture)
        return;

    mBrushBehavior = Free;

    ColourLayer *colourLayer = currentColourLayer();
    Q_ASSERT(colourLayer);

    // Intersect with the layer and translate to layer coordinates
    QRect captured = capturedArea();
    captured.intersect(QRect(colourLayer->x(), colourLayer->y(),
                             colourLayer->width(), colourLayer->height()));

    if (captured.isValid()) {
        captured.translate(-colourLayer->x(), -colourLayer->y());
        ColourLayer *capture = colourLayer->copy(captured);
        emit currentTilesChanged(capture);
        // A copy will have been created, so delete this version
        delete capture;
    } else {
        updatePosition();
    }
}
QRect KstGfxMouseHandlerUtils::resizeRectFromCornerCentered(const QRect& originalRect, const QPoint& pos, const QRect& bounds, bool maintainAspect) {
  QRect newRect;
  QPoint anchorPoint = originalRect.center();

  int newHalfWidth, newHalfHeight;

  newHalfWidth = abs((pos - anchorPoint).x());
  newHalfHeight = abs((pos - anchorPoint).y());

  if (maintainAspect) {
    newHalfWidth = kMin(newHalfWidth,anchorPoint.x() - bounds.left());
    newHalfWidth = kMin(newHalfWidth,bounds.right() - anchorPoint.x());

    newHalfHeight = kMin(newHalfHeight,anchorPoint.y() - bounds.top());
    newHalfHeight = kMin(newHalfHeight,bounds.bottom() - anchorPoint.y());

    QSize newSize(originalRect.size());
    newSize.scale(2*newHalfWidth, 2*newHalfHeight, QSize::ScaleMin);

    newRect.setSize(newSize);
    newRect.moveCenter(anchorPoint);
  } else {
    newRect = QRect(0, 0, 2*newHalfWidth, 2*newHalfHeight);
    newRect.moveCenter(anchorPoint);
    newRect = newRect.intersect(bounds);
  }

  return newRect;
}
QRect MyGraphicsView::getViewableRect() const
{
    if (mScene->items().size() == 0)
        return QRect();

    QRect r =
            mapToScene( viewport()->geometry() ).boundingRect().toRect();

    //qDebug() << "Rect " << r;

    if ( r.top() < 0 )
        r.setTop(0);

    if ( r.left() < 0 )
        r.setLeft(0);

    // get only intersection between pixmap and region
    #ifdef QT4
    r = r.intersect( mScene->sceneRect().toRect() );
    #else
    r = r.intersected( mScene->sceneRect().toRect() );
    #endif

    //qDebug() << "Rect2 " << r;

    return r;
}
Example #12
0
void PanelKMenu::paintEvent(QPaintEvent * e)
{
    if (sidePixmap.isNull()) {
        PanelServiceMenu::paintEvent(e);
        return;
    }

    QPainter p(this);
    p.setClipRegion(e->region());

    QStyleOptionFrame frOpt;
    frOpt.init(this);
    frOpt.lineWidth    = frameWidth();
    frOpt.midLineWidth = 0;
    style()->drawPrimitive( QStyle::PE_FrameMenu, &frOpt, &p, this);

    QRect r = sideImageRect();
    r.setBottom( r.bottom() - sidePixmap.height() );
    if ( r.intersects( e->rect() ) )
    {
        p.drawTiledPixmap( r, sideTilePixmap );
    }

    r = sideImageRect();
    r.setTop( r.bottom() - sidePixmap.height() );
    if ( r.intersects( e->rect() ) )
    {
        QRect drawRect = r.intersect( e->rect() );
        QRect pixRect = drawRect;
        pixRect.translate( -r.left(), -r.top() );
        p.drawPixmap( drawRect.topLeft(), sidePixmap, pixRect );
    }

    PanelServiceMenu::paintEvent( e );
}
Example #13
0
/*!\reimp
*/
void QSlider::paintEvent( QPaintEvent * )
{

    QPainter p( this );
    const QRect & sliderR = sliderRect();
    const QColorGroup & g = colorGroup();
    int mid = thickness()/2;
    if ( ticks & Above )
	mid += style().sliderLength() / 8;
    if ( ticks & Below )
	mid -= style().sliderLength() / 8;
    if ( orient == Horizontal ) {
	style().drawSliderGroove(&p, 0, tickOffset, width(), thickness(),
				     g, mid, Horizontal );
// 	    p.fillRect( 0, 0, width(), tickOffset, g.background() );
// 	    p.fillRect( 0, tickOffset + thickness(),
// 			width(), height()/*###*/, g.background() );
	erase( 0, 0, width(), tickOffset );
	erase( 0, tickOffset + thickness(), width(), height() );
    }
    else {
	style().drawSliderGroove( &p, tickOffset, 0, thickness(), height(),
				      g, mid, Vertical );
// 	    p.fillRect( 0, 0,  tickOffset, height(), g.background() );
// 	    p.fillRect( tickOffset + thickness(), 0,
// 			width()/*###*/, height(), g.background() );
	erase( 0, 0,  tickOffset, height() );
	erase( tickOffset + thickness(), 0, width()/*###*/, height() );
    }

    int interval = tickInt;
    if ( interval <= 0 ) {
	interval = lineStep();
	if ( positionFromValue( interval ) - positionFromValue( 0 ) < 3 )
	    interval = pageStep();
    }
    if ( ticks & Above )
	drawTicks( &p, g, 0, tickOffset - 2, interval );

    if ( ticks & Below ) {
	int avail = (orient == Horizontal) ? height() : width();
	avail -= tickOffset + thickness();
	drawTicks( &p, g, tickOffset + thickness() + 1, avail - 2, interval );
    }
    if ( hasFocus() ) {
	QRect r;
	if ( orient == Horizontal )
	    r.setRect( 0, tickOffset-1, width(), thickness()+2 );
	else
	    r.setRect( tickOffset-1, 0, thickness()+2, height() );
	r = r.intersect( rect() );
	if (style() == MotifStyle)
	    style().drawFocusRect(&p, QRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2), g);
	else
	    style().drawFocusRect(&p, r, g);
    }
    paintSlider( &p, g, sliderR );

}
Example #14
0
void
SegmentTip::moveTo(QPoint p, QWidget &canvas, bool placeAbove)
{
    //**** this function is very slow and seems to be visibly influenced by operations like mapFromGlobal() (who knows why!)
    //  ** so any improvements are much desired

    //TODO uints could improve the class
    p.rx() -= rect().center().x();
    p.ry() -= (placeAbove ? 8 + height() : m_cursorHeight - 8);

    const QRect screen = KGlobalSettings::desktopGeometry(parentWidget());

    const int x  = p.x();
    const int y  = p.y();
    const int x2 = x + width();
    const int y2 = y + height(); //how's it ever gunna get below screen height?! (well you never know I spose)
    const int sw = screen.width();
    const int sh = screen.height();

    if (x  < 0 ) p.setX(0);
    if (y  < 0 ) p.setY(0);
    if (x2 > sw) p.rx() -= x2 - sw;
    if (y2 > sh) p.ry() -= y2 - sh;


    //I'm using this QPoint to determine where to offset the bitBlt in m_pixmap
    QPoint offset = canvas.mapToGlobal(QPoint()) - p;
    if (offset.x() < 0) offset.setX(0);
    if (offset.y() < 0) offset.setY(0);


    const QRect alphaMaskRect(canvas.mapFromGlobal(p), size());
    const QRect intersection(alphaMaskRect.intersect(canvas.rect()));

    m_pixmap = QPixmap(size()); //move to updateTip once you are sure it can never be null

    const QColor c = QToolTip::palette().color(QPalette::Active, QPalette::Background);
    if (!m_backing_store)
        m_pixmap.fill(c);

    QPainter paint(&m_pixmap);
    paint.setPen(Qt::black);
    paint.setBrush(Qt::NoBrush);
    paint.drawRect(rect());
    paint.end();

    /* if (m_backing_store)
        m_pixmap = QPixmap::fromImage(Blitz::fade(m_pixmap.toImage() , 0.6f, c)); */ // TODO: reimplement this

    paint.begin(&m_pixmap);
    paint.drawText(rect(), Qt::AlignCenter, m_text);
    paint.end();

    p += screen.topLeft(); //for Xinerama users

    move(x, y);
    show();
    update();
}
Example #15
0
/*!\reimp
 */
void QRadioButton::updateMask()
{
    QBitmap bm(width(),height());
    {
	bm.fill(color0);
	QPainter p( &bm, this );
	int x, y, w, h;
	GUIStyle gs = style();
	QFontMetrics fm = fontMetrics();
	QSize lsz = fm.size(ShowPrefix, text());
	QSize sz = style().exclusiveIndicatorSize();
	if ( gs == WindowsStyle )
	    sz.setWidth(sz.width()+1);
	y = 0;
	x = sz.width() + gutter;
	w = width() - x;
	h = height();

	QColorGroup cg(color1,color1, color1,color1,color1,color1,color1,color1, color0);

	style().drawItem( &p, x, y, w, h,
			  AlignLeft|AlignVCenter|ShowPrefix,
			  cg, TRUE,
			  pixmap(), text() );
	x = 0;
	y = (height() - lsz.height() + fm.height() - sz.height())/2;

	style().drawExclusiveIndicatorMask(&p, x, y, sz.width(), sz.height(), isOn() );

	if ( hasFocus() ) {
 	    y = 0;
 	    x = sz.width() + gutter;
 	    w = width() - x;
 	    h = height();
	    QRect br = style().itemRect( &p, x, y, w, h,
					 AlignLeft|AlignVCenter|ShowPrefix,
					 isEnabled(),
					 pixmap(), text() );
	    br.setLeft( br.left()-3 );
	    br.setRight( br.right()+2 );
	    br.setTop( br.top()-2 );
	    br.setBottom( br.bottom()+2);
	    br = br.intersect( QRect(0,0,width(),height()) );

	    if ( !text().isEmpty() )
		style().drawFocusRect( &p, br, cg );
	    else {
		br.setRight( br.left()-1 );
		br.setLeft( br.left()-16 );
		br.setTop( br.top() );
		br.setBottom( br.bottom() );
		style().drawFocusRect( &p, br, cg );
	    }

	}
    }
    setMask(bm);
}
Example #16
0
// Display the video.
void MHVideo::Display(MHEngine *engine)
{
    if (! m_fRunning) return;
    if (m_nBoxWidth == 0 || m_nBoxHeight == 0) return; // Can't draw zero sized boxes.
    // The bounding box is assumed always to be True.
    // The full screen video is displayed in this rectangle.  It is therefore scaled to
    // m_nDecodeWidth/720 by m_nDecodeHeight/576.
    QRect videoRect = QRect(m_nPosX+m_nXDecodeOffset, m_nPosY+m_nYDecodeOffset,
                                m_nDecodeWidth, m_nDecodeHeight);        
    QRect displayRect = videoRect.intersect(QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight));
    engine->GetContext()->DrawVideo(videoRect, displayRect);
}
QRect KstGfxMouseHandlerUtils::resizeRectFromCorner(const QPoint& anchorPoint, const QPoint& movePoint, const QPoint& pos, const QRect& bounds, bool maintainAspect) {
  QRect newSize;
  QPoint npos = pos;

  if (maintainAspect) {
    QPoint fakeMovePoint = anchorPoint + QPoint(quadrantSign(pos,anchorPoint)*abs((movePoint - anchorPoint).x()),abs((movePoint - anchorPoint).y())); // allow the rectangle to flip.
    npos = findNearestPtOnLine(anchorPoint, fakeMovePoint, pos, bounds);
  }

  newSize.setTopLeft(anchorPoint);
  newSize.setBottomRight(npos);

  return bounds.intersect(newSize.normalize());
}
Example #18
0
void FLReportViewer::showEvent(QShowEvent *e)
{
  QWidget::showEvent(e);

  if (!embedInParent_) {
    QRect geo(aqApp->geometryForm(QObject::name()));
    if (geo.isValid()) {
      QRect desk = QApplication::desktop() ->availableGeometry(this);
      QRect inter = desk.intersect(geo);
      resize(geo.size());
      if (inter.width() * inter.height() > (geo.width() * geo.height() / 20))
        move(geo.topLeft());
    }
  }
}
Example #19
0
void
QSFieldView::paintEvent(QPaintEvent *pEvent)
{
    if(_pEditor && _pEditor->getActive())
        return;

    QPainter painter;
    QRect    rectSelf = rect();

    painter.begin(this);

    painter.setClipRect(rectSelf.intersect(pEvent->rect()));

    _pLabel->paint(&painter, palette().active(), rectSelf);

    painter.end();
}
Example #20
0
///public:
QUuid	PixmapJUPOCObject::addPart(QPixmap& srcPixmap,const QRect& srcRect)
{
	if (srcPixmap.isNull())
	{
		return QUuid();
	}
	//proper clipped rect, please
	QRect csrcRect = (srcRect.isEmpty() ? srcPixmap.rect() : srcRect.intersect(srcPixmap.rect()));
	QRect targetRect = findSpace(csrcRect.size());
	if (targetRect.isEmpty())
	{
		//couldn't find space
		return QUuid();
	}
	//copy in
	QPainter localPainter(pm);
	localPainter.drawPixmap(targetRect,srcPixmap,csrcRect);
	QUuid nUid = QUuid::createUuid();
	m_parts[nUid] = targetRect;
	return nUid;
}
QSObject QSRectClass::intersection(QSEnv *env)
{
  QSObject t = env->thisValue();
  QSRectClass *cl = (QSRectClass *)t.objectType();
  QRect *r = cl->rect(&t);

  if (env->numArgs() != 1) {
    env->throwError(QString::fromLatin1("Rect.intersection() called with %1 arguments. 1 argument expected.").
                    arg(env->numArgs()));
    return env->createUndefined();
  }

  QSObject a0 = env->arg(0);
  if (!a0.isA(cl)) {
    env->throwError(QString::fromLatin1("Rect.intersection() called with an argument of type %1. "
                                        "Type Rect is expeced").
                    arg(a0.typeName()));
    return env->createUndefined();
  }

  return cl->construct(r->intersect(*cl->rect(&a0)));
}
Example #22
0
/*!\reimp
*/
void QRadioButton::drawButtonLabel( QPainter *p )
{
    int x, y, w, h;
    GUIStyle gs = style();
    QSize sz = style().exclusiveIndicatorSize();
    if ( gs == WindowsStyle )
	sz.setWidth(sz.width()+1);
    y = 0;
    x = sz.width() + gutter;
    w = width() - x;
    h = height();

    style().drawItem( p, x, y, w, h,
		      AlignLeft|AlignVCenter|ShowPrefix,
		      colorGroup(), isEnabled(),
		      pixmap(), text() );

    if ( hasFocus() ) {
	QRect br = style().itemRect( p, x, y, w, h,
				     AlignLeft|AlignVCenter|ShowPrefix,
				     isEnabled(),
				     pixmap(), text() );
	br.setLeft( br.left()-3 );
	br.setRight( br.right()+2 );
	br.setTop( br.top()-2 );
	br.setBottom( br.bottom()+2);
	br = br.intersect( QRect(0,0,width(),height()) );

	if ( !text().isEmpty() )
	    style().drawFocusRect( p, br, colorGroup() );
	else {
	    br.setRight( br.left()-1 );
	    br.setLeft( br.left()-16 );
	    br.setTop( br.top() );
	    br.setBottom( br.bottom() );
	    style().drawFocusRect( p, br, colorGroup() );
	}
    }
}
Example #23
0
void PageView::viewportPaintEvent(QPaintEvent* e)
{
  // Region from which rectangles occupied by child widgets will by substracted.
  QRegion backgroundArea(e->rect());

  if (widgetList != 0)
  {
    for (unsigned int i = 0; i < widgetList->count(); i++)
    {
      DocumentWidget* item = widgetList->at(i);

      // Check if the Widget needs to be updated.
      if (!item->geometry().intersects(e->rect()))
        continue;

      QRect widgetGeometry = item->geometry();

      // Draw the widget.
      if (e->rect().intersects(widgetGeometry))
      {
        QRect widgetRect = e->rect().intersect(widgetGeometry);
        widgetRect.moveBy(-widgetGeometry.left(), -widgetGeometry.top());

        item->update(widgetRect);
      }

      // Substract the painted area.
      backgroundArea -= widgetGeometry.intersect(e->rect());
    }
  }

  // Paint the background.
  QPainter p(viewport());

  QMemArray<QRect> backgroundRects = backgroundArea.rects();

  for (unsigned int i = 0; i < backgroundRects.count(); i++)
    p.fillRect(backgroundRects[i], colorGroup().mid());
}
Example #24
0
QRect GameBoard::shipRect(int snum, bool margin) const
{
	QRect r;
	GameShip *ship = ships_.at(snum);
	int pos = ship->position();
	r.setTopLeft(QPoint(pos % 10, pos / 10));
	if (ship->direction() == GameShip::ShipHorizontal)
	{
		r.setWidth(ship->length());
		r.setHeight(1);
	}
	else
	{
		r.setWidth(1);
		r.setHeight(ship->length());
	}
	if (margin)
	{
		r.adjust(-1, -1, 1, 1);
		r = r.intersect(QRect(0, 0, 10, 10));
	}
	return r;
}
Example #25
0
void PagePainter::paintPageOnPainter( const KPDFPage * page, int id, int flags,
    QPainter * destPainter, const QRect & limits, int width, int height )
{
    QPixmap * pixmap = 0;

    // if a pixmap is present for given id, use it
    if ( page->m_pixmaps.contains( id ) )
        pixmap = page->m_pixmaps[ id ];

    // else find the closest match using pixmaps of other IDs (great optim!)
    else if ( !page->m_pixmaps.isEmpty() && width != -1 )
    {
        int minDistance = -1;
        QMap< int,QPixmap * >::const_iterator it = page->m_pixmaps.begin(), end = page->m_pixmaps.end();
        for ( ; it != end; ++it )
        {
            int pixWidth = (*it)->width(),
                distance = pixWidth > width ? pixWidth - width : width - pixWidth;
            if ( minDistance == -1 || distance < minDistance )
            {
                pixmap = *it;
                minDistance = distance;
            }
        }
    }

    // if have no pixmap, draw blank page with gray cross and exit
    if ( !pixmap )
    {
        QColor color = Qt::white;
        if ( KpdfSettings::changeColors() )
        {
            switch ( KpdfSettings::renderMode() )
            {
                case KpdfSettings::EnumRenderMode::Inverted:
                    color = Qt::black;
                    break;
                case KpdfSettings::EnumRenderMode::Paper:
                    color = KpdfSettings::paperColor();
                    break;
                case KpdfSettings::EnumRenderMode::Recolor:
                    color = KpdfSettings::recolorBackground();
                    break;
                default: ;
            }
        }
        destPainter->fillRect( limits, color );

        // draw a cross (to  that the pixmap as not yet been loaded)
        // helps a lot on pages that take much to render
        destPainter->setPen( Qt::gray );
        destPainter->drawLine( 0, 0, width-1, height-1 );
        destPainter->drawLine( 0, height-1, width-1, 0 );
        // idea here: draw a hourglass (or kpdf icon :-) on top-left corner
        return;
    }

    // find out what to paint over the pixmap (manipulations / overlays)
    bool paintAccessibility = (flags & Accessibility) && KpdfSettings::changeColors() && (KpdfSettings::renderMode() != KpdfSettings::EnumRenderMode::Paper);
    bool paintHighlights = (flags & Highlights) && !page->m_highlights.isEmpty();
    bool enhanceLinks = (flags & EnhanceLinks) && KpdfSettings::highlightLinks();
    bool enhanceImages = (flags & EnhanceImages) && KpdfSettings::highlightImages();
    // check if there are really some highlightRects to paint
    if ( paintHighlights )
    {
        // precalc normalized 'limits rect' for intersection
        double nXMin = (double)limits.left() / (double)width,
               nXMax = (double)limits.right() / (double)width,
               nYMin = (double)limits.top() / (double)height,
               nYMax = (double)limits.bottom() / (double)height;
        // if no rect intersects limits, disable paintHighlights
        paintHighlights = false;
        QValueList< HighlightRect * >::const_iterator hIt = page->m_highlights.begin(), hEnd = page->m_highlights.end();
        for ( ; hIt != hEnd; ++hIt )
        {
            if ( (*hIt)->intersects( nXMin, nYMin, nXMax, nYMax ) )
            {
                paintHighlights = true;
                break;
            }
        }
    }

    // use backBuffer if 'pixmap direct manipulation' is needed
    bool backBuffer = paintAccessibility || paintHighlights;
    QPixmap * backPixmap = 0;
    QPainter * p = destPainter;
    if ( backBuffer )
    {
        // let's paint using a buffered painter
        backPixmap = new QPixmap( limits.width(), limits.height() );
        p = new QPainter( backPixmap );
        p->translate( -limits.left(), -limits.top() );
    }

    // 1. fast blit the pixmap if it has the right size..
    if ( pixmap->width() == width && pixmap->height() == height )
        p->drawPixmap( limits.topLeft(), *pixmap, limits );
    // ..else set a scale matrix to the painter and paint a quick 'zoomed' pixmap
    else
    {
        p->save();
        // TODO paint only the needed part (note: hope that Qt4 transforms are faster)
        p->scale( width / (double)pixmap->width(), height / (double)pixmap->height() );
        p->drawPixmap( 0,0, *pixmap, 0,0, pixmap->width(), pixmap->height() );
        p->restore();
    }

    // 2. mangle pixmap: convert it to 32-bit qimage and perform pixel-level manipulations
    if ( backBuffer )
    {
        QImage backImage = backPixmap->convertToImage();
        // 2.1. modify pixmap following accessibility settings
        if ( paintAccessibility )
        {
            switch ( KpdfSettings::renderMode() )
            {
                case KpdfSettings::EnumRenderMode::Inverted:
                    // Invert image pixels using QImage internal function
                    backImage.invertPixels(false);
                    break;
                case KpdfSettings::EnumRenderMode::Recolor:
                    // Recolor image using KImageEffect::flatten with dither:0
                    KImageEffect::flatten( backImage, KpdfSettings::recolorForeground(), KpdfSettings::recolorBackground() );
                    break;
                case KpdfSettings::EnumRenderMode::BlackWhite:
                    // Manual Gray and Contrast
                    unsigned int * data = (unsigned int *)backImage.bits();
                    int val, pixels = backImage.width() * backImage.height(),
                        con = KpdfSettings::bWContrast(), thr = 255 - KpdfSettings::bWThreshold();
                    for( int i = 0; i < pixels; ++i )
                    {
                        val = qGray( data[i] );
                        if ( val > thr )
                            val = 128 + (127 * (val - thr)) / (255 - thr);
                        else if ( val < thr )
                            val = (128 * val) / thr;
                        if ( con > 2 )
                        {
                            val = con * ( val - thr ) / 2 + thr;
                            if ( val > 255 )
                                val = 255;
                            else if ( val < 0 )
                                val = 0;
                        }
                        data[i] = qRgba( val, val, val, 255 );
                    }
                    break;
            }
        }
        // 2.2. highlight rects in page
        if ( paintHighlights )
        {
            // draw highlights that are inside the 'limits' paint region
            QValueList< HighlightRect * >::const_iterator hIt = page->m_highlights.begin(), hEnd = page->m_highlights.end();
            for ( ; hIt != hEnd; ++hIt )
            {
                HighlightRect * r = *hIt;
                QRect highlightRect = r->geometry( width, height );
                if ( highlightRect.isValid() && highlightRect.intersects( limits ) )
                {
                    // find out the rect to highlight on pixmap
                    highlightRect = highlightRect.intersect( limits );
                    highlightRect.moveBy( -limits.left(), -limits.top() );

                    // highlight composition (product: highlight color * destcolor)
                    unsigned int * data = (unsigned int *)backImage.bits();
                    int val, newR, newG, newB,
                        rh = r->color.red(),
                        gh = r->color.green(),
                        bh = r->color.blue(),
                        offset = highlightRect.top() * backImage.width();
                    for( int y = highlightRect.top(); y <= highlightRect.bottom(); ++y )
                    {
                        for( int x = highlightRect.left(); x <= highlightRect.right(); ++x )
                        {
                            val = data[ x + offset ];
                            newR = (qRed(val) * rh) / 255;
                            newG = (qGreen(val) * gh) / 255;
                            newB = (qBlue(val) * bh) / 255;
                            data[ x + offset ] = qRgba( newR, newG, newB, 255 );
                        }
                        offset += backImage.width();
                    }
                }
            }
        }
        backPixmap->convertFromImage( backImage );
    }

    // 3. visually enchance links and images if requested
    if ( enhanceLinks || enhanceImages )
    {
        QColor normalColor = QApplication::palette().active().highlight();
        QColor lightColor = normalColor.light( 140 );
        // enlarging limits for intersection is like growing the 'rectGeometry' below
        QRect limitsEnlarged = limits;
        limitsEnlarged.addCoords( -2, -2, 2, 2 );
        // draw rects that are inside the 'limits' paint region as opaque rects
        QValueList< ObjectRect * >::const_iterator lIt = page->m_rects.begin(), lEnd = page->m_rects.end();
        for ( ; lIt != lEnd; ++lIt )
        {
            ObjectRect * rect = *lIt;
            if ( (enhanceLinks && rect->objectType() == ObjectRect::Link) ||
                 (enhanceImages && rect->objectType() == ObjectRect::Image) )
            {
                QRect rectGeometry = rect->geometry( width, height );
                if ( rectGeometry.intersects( limitsEnlarged ) )
                {
                    // expand rect and draw inner border
                    rectGeometry.addCoords( -1,-1,1,1 );
                    p->setPen( lightColor );
                    p->drawRect( rectGeometry );
                    // expand rect to draw outer border
                    rectGeometry.addCoords( -1,-1,1,1 );
                    p->setPen( normalColor );
                    p->drawRect( rectGeometry );
                }
            }
        }
    }

    // 4. if was backbuffering, copy the backPixmap to destination
    if ( backBuffer )
    {
        delete p;
        destPainter->drawPixmap( limits.left(), limits.top(), *backPixmap );
        delete backPixmap;
    }
}
Example #26
0
STDMETHODIMP UIFrameBufferQuartz2D::SetVisibleRegion(BYTE *aRectangles, ULONG aCount)
{
    PRTRECT rects = (PRTRECT)aRectangles;

    if (!rects)
        return E_POINTER;

    /** @todo r=bird: Is this thread safe? If I remember the code flow correctly, the
     * GUI thread could be happily jogging along paintEvent now on another cpu core.
     * This function is called on the EMT (emulation thread). Which means, blocking
     * execution waiting for a lock is out of the question. A quick solution using
     * ASMAtomic(Cmp)XchgPtr and a struct { cAllocated; cRects; aRects[1]; }
     * *mRegion, *mUnusedRegion; should suffice (and permit you to reuse allocations). */
    RegionRects *rgnRcts = ASMAtomicXchgPtrT(&mRegionUnused, NULL, RegionRects *);
    if (rgnRcts && rgnRcts->allocated < aCount)
    {
        RTMemFree (rgnRcts);
        rgnRcts = NULL;
    }
    if (!rgnRcts)
    {
        ULONG allocated = RT_ALIGN_32(aCount + 1, 32);
        allocated = RT_MAX (128, allocated);
        rgnRcts = (RegionRects *)RTMemAlloc(RT_OFFSETOF(RegionRects, rcts[allocated]));
        if (!rgnRcts)
            return E_OUTOFMEMORY;
        rgnRcts->allocated = allocated;
    }
    rgnRcts->used = 0;

    QRegion reg;
//    printf ("Region rects follow...\n");
    QRect vmScreenRect (0, 0, width(), height());
    for (ULONG ind = 0; ind < aCount; ++ ind)
    {
        QRect rect;
        rect.setLeft(rects->xLeft);
        rect.setTop(rects->yTop);
        /* QRect are inclusive */
        rect.setRight(rects->xRight - 1);
        rect.setBottom(rects->yBottom - 1);

        /* The rect should intersect with the vm screen. */
        rect = vmScreenRect.intersect(rect);
        ++ rects;
        /* Make sure only valid rects are distributed */
        /* todo: Test if the other framebuffer implementation have the same
         * problem with invalid rects (In Linux/Windows) */
        if (rect.isValid() &&
           rect.width() > 0 && rect.height() > 0)
            reg += rect;
        else
            continue;

        CGRect *cgRct = &rgnRcts->rcts[rgnRcts->used];
        cgRct->origin.x = rect.x();
        cgRct->origin.y = height() - rect.y() - rect.height();
        cgRct->size.width = rect.width();
        cgRct->size.height = rect.height();
//        printf ("Region rect[%d - %d]: %d %d %d %d\n", rgnRcts->used, aCount, rect.x(), rect.y(), rect.height(), rect.width());
        rgnRcts->used++;
    }
//    printf ("..................................\n");

    RegionRects *pOld = ASMAtomicXchgPtrT(&mRegion, rgnRcts, RegionRects *);
    if (    pOld
        &&  !ASMAtomicCmpXchgPtr(&mRegionUnused, pOld, NULL))
        RTMemFree(pOld);

    QApplication::postEvent(m_pMachineView, new UISetRegionEvent (reg));

    return S_OK;
}
Example #27
0
void MTScale::pdraw(QPainter& p, const QRect& r)
{
	QColor colTimeLine = QColor(172,181,176);
	int x = r.x();
	int w = r.width();

	//printf("MTScale::pdraw x:%d w:%d\n", x, w);

	x -= 20;
	w += 40; // wg. Text

	//---------------------------------------------------
	//    draw Marker
	//---------------------------------------------------

	int y = 12;
	p.setPen(colTimeLine);
	p.setFont(QFont("fixed-width", 9, QFont::Bold));
	p.drawLine(r.x(), y + 1, r.x() + r.width(), y + 1);
	QRect tr(r);
	tr.setHeight(12);
	MarkerList* marker = song->marker();
	for (iMarker m = marker->begin(); m != marker->end(); ++m)
	{

		int xp;
		if (waveMode)
			xp = mapx(m->second.frame());
		else
			xp = mapx(m->second.tick());
		if (xp > x + w)
			break;
		int xe = r.x() + r.width();
		iMarker mm = m;
		++mm;
		if (mm != marker->end())
		{

			if (waveMode)
				xe = mapx(tempomap.tick2frame(mm->first));
			else
				xe = mapx(mm->first);
		}

		QRect tr(xp, 0, xe - xp, 13);

		QRect wr = r.intersect(tr);
		if (!wr.isEmpty())
		{
			if (m->second.current())
			{
				p.fillRect(wr, QColor(89, 89, 102));
			}

			int x2;
			if (mm != marker->end())
			{
				if (waveMode)
					x2 = mapx(tempomap.tick2frame(mm->first));
				else
					x2 = mapx(mm->first);
			}
			else
				x2 = xp + 200;

			//printf("MTScale::pdraw marker %s xp:%d y:%d h:%d r.x:%d r.w:%d\n", m->second.name().toLatin1(), xp, height(), y, r.x(), r.width());

			// Must be reasonable about very low negative x values! With long songs > 15min
			//  and with high horizontal magnification, 'ghost' drawings appeared,
			//  apparently the result of truncation later (xp = -65006 caused ghosting
			//  at bar 245 with magnification at max.), even with correct clipping region
			//  applied to painter in View::paint(). Tim.  Apr 5 2009
			// Quote: "Warning: Note that QPainter does not attempt to work around
			//  coordinate limitations in the underlying window system. Some platforms may
			//  behave incorrectly with coordinates as small as +/-4000."
			if (xp >= -32)
				p.drawPixmap(xp, 0, *flagIconS);

			if (xp >= -1023)
			{
				QRect r = QRect(xp + 10, 0, x2 - xp, 12);
				p.setPen(colTimeLine);
				p.drawText(r, Qt::AlignLeft | Qt::AlignVCenter, m->second.name());
			}

			if (xp >= 0)
			{
				p.setPen(colTimeLine);
				p.drawLine(xp, y, xp, height());
			}
		}
	}
	unsigned ctick;
	int bar1, bar2, beat;
	unsigned tick;

	if (waveMode)
	{
		ctick = tempomap.frame2tick(mapxDev(x));
		AL::sigmap.tickValues(ctick, &bar1, &beat, &tick);
		AL::sigmap.tickValues(tempomap.frame2tick(mapxDev(x + w)),
				&bar2, &beat, &tick);
	}
	else
	{
		ctick = mapxDev(x);
		AL::sigmap.tickValues(ctick, &bar1, &beat, &tick);
		AL::sigmap.tickValues(mapxDev(x + w), &bar2, &beat, &tick);
	}

	//printf("bar %d  %d-%d=%d\n", bar, ntick, stick, ntick-stick);
	int h = height() - 12;

	int stick = AL::sigmap.bar2tick(bar1, 0, 0);
	int ntick;
	for (int bar = bar1; bar <= bar2; bar++, stick = ntick)
	{
		ntick = AL::sigmap.bar2tick(bar + 1, 0, 0);
		int tpix, a, b = 0;
		if (waveMode)
		{
			a = tempomap.tick2frame(ntick);
			b = tempomap.tick2frame(stick);
			tpix = rmapx(a - b);
		}
		else
		{
			tpix = rmapx(ntick - stick);
		}
		if (tpix < 64)
		{
			// don�t show beats if measure is this small
			int n = 1;
			if (tpix < 32)
				n = 2;
			if (tpix <= 16)
				n = 4;
			if (tpix < 8)
				n = 8;
			if (tpix <= 4)
				n = 16;
			if (tpix <= 2)
				n = 32;
			if (bar % n)
				continue;
			int x = mapx(waveMode ? b : stick);
			QString s;
			s.setNum(bar + 1);
			p.drawLine(x, y + 1, x, y + 1 + h);
			QRect r = QRect(x + 2, y, 1000, h);
			p.setFont(QFont("fixed-width", 9, QFont::Bold));
			p.drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextDontClip, s);
		}
		else
		{
			int z, n;
			AL::sigmap.timesig(stick, z, n);
			for (int beat = 0; beat < z; beat++)
			{
				int xx = AL::sigmap.bar2tick(bar, beat, 0);
				if (waveMode)
					xx = tempomap.tick2frame(xx);
				int xp = mapx(xx);
				QString s;
				QRect r(xp + 2, y, 1000, h);
				int y1;
				int num;
				if (beat == 0)
				{
					num = bar + 1;
					y1 = y + 1;
					p.setFont(QFont("fixed-width", 9, QFont::Bold));
				}
				else
				{
					num = beat + 1;
					y1 = y + 7;
					p.setFont(QFont("fixed-width", 7, QFont::Normal));
					r.setY(y + 3);
				}
				s.setNum(num);
				p.drawLine(xp, y1, xp, y + 1 + h);
				p.drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextDontClip, s);
			}
		}
	}

	//---------------------------------------------------
	//    draw location marker
	//---------------------------------------------------

	//Christopher here is your color
	p.setPen(QColor(156,75,219));

	if (pos[3] != MAXINT)
	{
		int xp = mapx(pos[3]);
		if (xp >= x && xp < x + w)
			p.drawLine(xp, 0, xp, height());
	}

	p.setPen(colTimeLine);
	if (barLocator)
	{
		p.setPen(QColor(0, 186, 255));
		int xp = mapx(pos[0]);
		if (xp >= x && xp < x + w)
			p.drawLine(xp, 0, xp, height());
		p.setPen(QColor(139, 225, 69));
		xp = mapx(pos[1]);
		if (xp >= x && xp < x + w)
			p.drawLine(xp, 0, xp, height());
		xp = mapx(pos[2]);
		if (xp >= x && xp < x + w)
			p.drawLine(xp, 0, xp, height());
	}
	else
	{
		for (int i = 0; i < 3; ++i)
		{
			int xp = mapx(pos[i]);
			if (xp >= x && xp < x + w)
			{
				QPixmap* pm = markIcon[i];
				p.drawPixmap(xp - pm->width() / 2, y - 1, *pm);
			}
		}
	}
}
void ThumbnailWidget::paintEvent( QPaintEvent * e )
{
    int width = m_pixmapWidth + m_margin;
    int height = m_pixmapHeight + m_margin + m_labelHeight;
    QRect clipRect = e->rect();
    if ( !clipRect.isValid() )
        return;
    QPainter p( this );

    // draw the bottom label + highlight mark
    QColor fillColor = m_selected ? palette().active().highlight() : palette().active().base();
    p.fillRect( 0, 0, width, height, fillColor );
    p.setPen( m_selected ? palette().active().highlightedText() : palette().active().text() );
    p.drawText( 0, m_pixmapHeight + m_margin, width, m_labelHeight, Qt::AlignCenter, QString::number( m_labelNumber ) );

    // draw page outline and pixmap
    if ( clipRect.top() < m_pixmapHeight + m_margin )
    {
        // if page is bookmarked draw a colored border
        bool isBookmarked = m_page->hasBookmark();
        // draw the inner rect
        p.setPen( isBookmarked ? QColor( 0xFF8000 ) : Qt::black );
        p.drawRect( m_margin/2 - 1, m_margin/2 - 1, m_pixmapWidth + 2, m_pixmapHeight + 2 );
        // draw the clear rect
        p.setPen( isBookmarked ? QColor( 0x804000 ) : palette().active().base() );
        // draw the bottom and right shadow edges
        if ( !isBookmarked )
        {
            int left, right, bottom, top;
            left = m_margin/2 + 1;
            right = m_margin/2 + m_pixmapWidth + 1;
            bottom = m_pixmapHeight + m_margin/2 + 1;
            top = m_margin/2 + 1;
            p.setPen( Qt::gray );
            p.drawLine( left, bottom, right, bottom );
            p.drawLine( right, top, right, bottom );
        }

        // draw the page using the shared PagePainter class
        p.translate( m_margin/2, m_margin/2 );
        clipRect.moveBy( -m_margin/2, -m_margin/2 );
        clipRect = clipRect.intersect( QRect( 0, 0, m_pixmapWidth, m_pixmapHeight ) );
        if ( clipRect.isValid() )
        {
            int flags = PagePainter::Accessibility | PagePainter::Highlights;
            PagePainter::paintPageOnPainter( m_page, THUMBNAILS_ID, flags, &p,
                                             clipRect, m_pixmapWidth, m_pixmapHeight );
        }

        // draw the bookmark overlay on the top-right corner
        const QPixmap * bookmarkPixmap = m_tl->getBookmarkOverlay();
        if ( isBookmarked && bookmarkPixmap )
        {
            int pixW = bookmarkPixmap->width(),
                pixH = bookmarkPixmap->height();
            clipRect = clipRect.intersect( QRect( m_pixmapWidth - pixW, 0, pixW, pixH ) );
            if ( clipRect.isValid() )
                p.drawPixmap( m_pixmapWidth - pixW, -pixH/8, *bookmarkPixmap );
        }
    }
}
Example #29
0
void
QMFieldView::redrawChanged(QPaintEvent *pEvent, QPainter *pPainter)
{
    SNOTICE << "QMFieldView::redrawChanged()" << endLog;

    UInt32                currIndex;
    Int32                 drawTop;

    QRect                 drawRect;
    QSize                 drawSize;

    bool                  doneDraw = false;

    QFieldValueLabelBase *pLabel;

    _uiBeginIndex = _pScrollbar->value()/2;
    _uiEndIndex   = _uiBeginIndex;
    currIndex     = _uiBeginIndex;

    if(_uiBeginIndex >= getFieldPtr()->getSize())
    {
        releaseAllLabels();
        return;
    }

    pLabel   = acquireLabel   (_uiEndIndex++);
    drawSize = pLabel->sizeHint(             );
    drawTop  = ((_pScrollbar->value() % 2) == 0) ? 0 : -drawSize.height()/2;

    drawRect = QRect(0, drawTop,
                     width()-_pScrollbar->width(), 
                     osgMin(drawSize.height(), height()            ) );

    while(!doneDraw)
    {
        pPainter->setClipRect(drawRect.intersect(pEvent->rect()));

        pLabel->paint(pPainter, palette().active(), drawRect);
        
        _usedLabels[currIndex].setLabel(pLabel  );
        _usedLabels[currIndex].setRect (drawRect);
              
        drawTop += drawRect.height();
        
        if((_uiEndIndex >= getFieldPtr()->getSize()) ||
           (drawTop     >= height()                )   )
        {
            doneDraw = true;
        }
        else
        {
            currIndex = _uiEndIndex++;
            pLabel    = acquireLabel    (currIndex);
            drawSize  = pLabel->sizeHint(         );

            drawRect  = QRect(0, drawTop,
                              width()-_pScrollbar->width(),
                              osgMin(drawSize.height(), height()));
        }
    }

    IndexLabelMapIt   begin = _usedLabels.begin();
    IndexLabelMapIt   end   = _usedLabels.end();

    for(; begin != end; ++begin)
    {
        pLabel = begin->second.getLabel();

        if( (pLabel->getIndex() <  _uiBeginIndex) ||
            (pLabel->getIndex() >= _uiEndIndex  )   )
        {
            releaseLabel(pLabel);
//            _usedLabels.erase(begin);
//            _poolLabels.push_back(pLabel);
        }
    }

    _bContentsChanged = false;
}
Example #30
0
void
PixmapRenderer::drawPixmap(
	QPainter& painter, QPixmap const& pixmap)
{
#if !defined(Q_WS_X11)
	drawPixmapNoXRender(painter, pixmap);
#else
	QPaintDevice* const dev = painter.device();
	
	QPoint offset; // Both x and y will be either zero or negative.
	QPaintDevice* const redir_dev = QPainter::redirected(painter.device(), &offset);
	QPaintDevice* const paint_dev = redir_dev ? redir_dev : dev;

#if defined(ENABLE_OPENGL)
	if (dynamic_cast<QGLWidget*>(paint_dev)) {
		drawPixmapNoXRender(painter, pixmap);
		return;
	}
#endif

	QRect const device_rect(
		QRect(0, 0, dev->width(), dev->height()).translated(-offset)
	);
	
	QRectF const src_rect(pixmap.rect());
	
	Display* const dpy = QX11Info::display();
	Picture const src_pict = pixmap.x11PictureHandle();
	Picture dst_pict = 0;
	if (QWidget* widget = dynamic_cast<QWidget*>(paint_dev)) {
		dst_pict = widget->x11PictureHandle();
	} else if (QPixmap* pixmap = dynamic_cast<QPixmap*>(paint_dev)) {
		dst_pict = pixmap->x11PictureHandle();
	}
	
	if (!dst_pict) {
		drawPixmapNoXRender(painter, pixmap);
		return;
	}
	
	// Note that device transform already accounts for offset
	// within a destination surface.
	QTransform const src_to_dst(painter.deviceTransform());
	QTransform const dst_to_src(src_to_dst.inverted());
	QPolygonF const dst_poly(src_to_dst.map(src_rect));
	
	XTransform xform = {{
		{
			XDoubleToFixed(dst_to_src.m11()),
			XDoubleToFixed(dst_to_src.m21()),
			XDoubleToFixed(dst_to_src.m31())
		},
		{
			XDoubleToFixed(dst_to_src.m12()),
			XDoubleToFixed(dst_to_src.m22()),
			XDoubleToFixed(dst_to_src.m32())
		},
		{
			XDoubleToFixed(dst_to_src.m13()),
			XDoubleToFixed(dst_to_src.m23()),
			XDoubleToFixed(dst_to_src.m33())
		}
	}};
	
	XRenderSetPictureTransform(dpy, src_pict, &xform);

	char const* filter = "fast";
	if (painter.testRenderHint(QPainter::SmoothPixmapTransform)) {
		filter = "good";
	}
	
	XRenderSetPictureFilter(dpy, src_pict, filter, 0, 0);
	
	QRectF const dst_rect_precise(dst_poly.boundingRect());
	QRect const dst_rect_fitting(
		QPoint(
			int(ceil(dst_rect_precise.left())),
			int(ceil(dst_rect_precise.top()))
		),
		QPoint(
			int(floor(dst_rect_precise.right())) - 1,
			int(floor(dst_rect_precise.bottom())) - 1
		)
	);
	QRect dst_bounding_rect(device_rect);
	if (painter.hasClipping()) {
		QRect const clip_rect(
			src_to_dst.map(painter.clipPath()).boundingRect().toRect()
		);
		dst_bounding_rect = dst_bounding_rect.intersected(clip_rect);
	}
	QRect const dst_rect(dst_rect_fitting.intersect(dst_bounding_rect));
	
	// Note that XRenderComposite() expects destination coordinates
	// everywhere, even for source picture origin.
	XRenderComposite(
		dpy, PictOpSrc,
		src_pict, 0, dst_pict, dst_rect.left(), dst_rect.top(), 0, 0,
		dst_rect.left(), dst_rect.top(), dst_rect.width(), dst_rect.height()
	);
#endif
}