Example #1
0
void KstViewLegend::paintSelf(KstPainter& p, const QRegion& bounds) {
  if (p.type() == KstPainter::P_PRINT || p.type() == KstPainter::P_EXPORT) {
    p.save();
    QRect cr(contentsRectForPainter(p));
    cr.setSize(sizeForText(_parent->geometry()));
    setContentsRectForPainter(p, cr);    
    KstBorderedViewObject::paintSelf(p, bounds);
    
    p.translate(cr.left(), cr.top());
    if (!_transparent) {
      p.fillRect(0, 0, cr.width(), cr.height(), _backgroundColor);
    }
    drawToPainter(p);
    
    p.restore();
  } else {
    const QRect cr(contentsRect());
    if (p.makingMask()) {
      p.setCompositionMode(QPainter::CompositionMode_Source);
    } else {
      const QRegion clip(clipRegion());
      KstBorderedViewObject::paintSelf(p, bounds - _myClipMask);
      p.setClipRegion(bounds & clip);
    }

    _backBuffer.paintInto(p, cr);
  }
}
void KstViewLabel::paintSelf(KstPainter& p, const QRegion& bounds) {
  p.save();
  if (p.type() == KstPainter::P_PRINT || p.type() == KstPainter::P_EXPORT) {
    int absFontSizeOld = _absFontSize;

    QRect cr(contentsRectForPainter(p));
    cr.setSize(sizeForText(_parent->geometry()));
    setContentsRectForPainter(p, cr);
    KstBorderedViewObject::paintSelf(p, bounds);

    p.translate(cr.left(), cr.top());
    if (!_transparent) {
      p.fillRect(0, 0, cr.width(), cr.height(), backgroundColor());
    }
    drawToPainter(_parsed, p);

    _absFontSize = absFontSizeOld;
  } else {
    if (p.makingMask()) {
      KstBorderedViewObject::paintSelf(p, bounds);
      p.setRasterOp(Qt::SetROP);
      const QRect cr(contentsRect());
      // slow but preserves antialiasing...
      QBitmap bm = _backBuffer.buffer().createHeuristicMask(false);
      bm.setMask(bm);
      p.drawPixmap(cr.left(), cr.top(), bm, 0, 0, cr.width(), cr.height());
    } else {
      const QRegion clip(clipRegion());
      KstBorderedViewObject::paintSelf(p, bounds);
      p.setClipRegion(bounds & clip);
      _backBuffer.paintInto(p, contentsRect());
    }
  }
  p.restore();
}
Example #3
0
void KstViewArrow::paintSelf(KstPainter& p, const QRegion& bounds) {
  p.save();
  if (p.type() != KstPainter::P_PRINT && p.type() != KstPainter::P_EXPORT) {
    if (p.makingMask()) {
      p.setCompositionMode(QPainter::CompositionMode_Source);
    } else {
      const QRegion clip(clipRegion());
      KstViewLine::paintSelf(p, bounds - _myClipMask);
      p.setClipRegion(bounds & clip);
    }
  } else {
      KstViewLine::paintSelf(p, bounds);
  }
  
  if (hasArrow()) {
    QPoint to = KstViewLine::to();
    QPoint from = KstViewLine::from();    
    const int w = width() * p.lineWidthAdjustmentFactor();
    QPen pen(_foregroundColor, w);
    
    pen.setCapStyle(capStyle());
    p.setPen(pen);
    p.setBrush(_foregroundColor);
    
    if (_hasToArrow) {      
      paintArrow(p, to, from, w, _toArrowScaling);
    }
    if (_hasFromArrow) {      
      paintArrow(p, from, to, w, _fromArrowScaling);
    }
  }
  p.restore();
}
Example #4
0
void KstBorderedViewObject::paintSelf(KstPainter& p, const QRegion& bounds) {
  p.save();
  if (p.type() != KstPainter::P_PRINT && p.type() != KstPainter::P_EXPORT) {
    if (p.makingMask()) {
      p.setRasterOp(Qt::SetROP);
      KstViewObject::paintSelf(p, bounds);
    } else {
      const QRegion clip(clipRegion());
      KstViewObject::paintSelf(p, bounds - clip);
      p.setClipRegion(bounds & clip);
    }
  }
  if (_borderWidth > 0) {
    QRect r;
    const int bw(_borderWidth * p.lineWidthAdjustmentFactor());
    QPen pen(_borderColor, bw);
    p.setBrush(Qt::NoBrush);
    p.setPen(pen);
    r.setX(_geom.left() + _margin + bw / 2);
    r.setY(_geom.top() + _margin + bw / 2);
    r.setWidth(_geom.width() - 2 * _margin - bw + 1);
    r.setHeight(_geom.height() - 2 * _margin - bw + 1);
    p.drawRect(r);
  }
  p.restore();
}
Example #5
0
void KstViewLine::paintSelf(KstPainter& p, const QRegion& bounds) {
  p.save();
  if (p.type() != KstPainter::P_PRINT && p.type() != KstPainter::P_EXPORT) {
    if (p.makingMask()) {
      p.setRasterOp(Qt::SetROP);
      KstViewObject::paintSelf(p, geometry());
    } else {
      const QRegion clip(clipRegion());
      KstViewObject::paintSelf(p, bounds - clip);
      p.setClipRegion(bounds & clip);
    }
  }

  // figure out which direction to draw the line
  const int w(_width * p.lineWidthAdjustmentFactor());
  QPen pen(_foregroundColor, w);
  pen.setCapStyle(_capStyle);
  pen.setStyle(_penStyle);
  p.setPen(pen);

  const QRect geom(geometry());
  int u = 0, v = 0;
  
  // Adjust for large widths.  We don't want the line clipped because it goes
  // out of the bounding box.
  if (w > 1 && geom.height() > 0) {
    double theta = atan(geom.width()/geom.height());
    if (theta >= 0 && theta <= M_PI/4) {
      u = int(fabs((w / 2.0) * (sin(theta) + cos(theta))));
      v = int(fabs((w / 2.0) * (1.5*sin(theta) + 0.5*cos(theta))));
    } else {
      u = int(fabs((w / 2.0) * (1.5*sin(theta) + 0.5*cos(theta))));
      v = int(fabs((w / 2.0) * (sin(theta) + cos(theta))));
    }
  }

  switch (_orientation) {
    case UpLeft:
    case DownRight:
      p.drawLine(geom.bottomRight() + QPoint(-u, -v), geom.topLeft() + QPoint(u, v));
      break;
    case UpRight:
    case DownLeft:
      p.drawLine(geom.bottomLeft() + QPoint(u, -v), geom.topRight() + QPoint(-u, v));
      break;
  }
  p.restore();
}
Example #6
0
void KstViewPicture::paintSelf(KstPainter& p, const QRegion& bounds) {
  p.save();
  if (p.type() != KstPainter::P_PRINT && p.type() != KstPainter::P_EXPORT) {
    if (p.makingMask()) {
      p.setRasterOp(Qt::OrROP);
    } else {
      const QRegion clip(clipRegion());
      KstBorderedViewObject::paintSelf(p, bounds - _myClipMask);
      p.setClipRegion(bounds & clip);
    }
  } else {
    KstBorderedViewObject::paintSelf(p, bounds);
  }

  const QRect cr(contentsRectForDevice(p));
  if (_image.isNull()) {
    // fill with X
    p.setBrush(QBrush(Qt::gray, Qt::SolidPattern));
    p.setPen(QPen(Qt::black, 0, Qt::SolidLine));
    p.drawRect(cr);
    p.drawLine(cr.topLeft(), cr.bottomRight());
    p.drawLine(cr.topRight(), cr.bottomLeft());
  } else {
    assert(!cr.isNull()); // Null view objects are not allowed.  I want to see
                          // how this happens so it can be fixed.

    if (_iCache.isNull() || _iCache.size() != cr.size()) {
      _iCache = _image.copy();
      if (!_iCache.isNull()) {
        _iCache = _iCache.smoothScale(cr.size());
      }
    }
    if (!_iCache.isNull()) {
      if (p.makingMask()) {
        // which indicates clipping / BW mode
        if (_iCache.hasAlphaBuffer()) {
          p.drawImage(cr.topLeft(), _iCache.createAlphaMask());
        } else {
          p.setBrush(Qt::color1);
          p.drawRect(cr);
        }
      } else {
        p.drawImage(cr.topLeft(), _iCache);
      }
    }
  }
  p.restore();
}
void KstPlotGroup::paintSelf(KstPainter& p, const QRegion& bounds) {
  if (!transparent()) {
    p.save();
    // fill non-children areas with color
    QRegion clipRegion(contentsRect());
    QBrush brush(_backgroundColor);
    for (KstViewObjectList::Iterator i = _children.begin(); i != _children.end(); ++i) {
      clipRegion -= (*i)->clipRegion();
    }
    p.setClipRegion(clipRegion);
    p.fillRect(contentsRect(), brush);
    p.restore();
  }

  KstMetaPlot::paintSelf(p, bounds);
}
Example #8
0
void KstViewBox::paintSelf(KstPainter& p, const QRegion& bounds) {
  p.save();
  if (p.type() != KstPainter::P_PRINT && p.type() != KstPainter::P_EXPORT) {
    if (p.makingMask()) {
      p.setRasterOp(Qt::SetROP);
    } else {
      const QRegion clip(clipRegion());
      KstViewObject::paintSelf(p, bounds - clip);
      p.setClipRegion(bounds & clip);
    }
  }

  // restrict the border width so we do not draw outside of the rectangle itself
  int bw(borderWidth() * p.lineWidthAdjustmentFactor());
  if (bw > _geom.width() / 2) {
    bw = _geom.width() / 2;
  }
  if (bw > _geom.height()) {
    bw = _geom.height() / 2;
  }
  
  QPen pen(borderColor(), bw);
  pen.setJoinStyle(_cornerStyle);
  if (bw == 0) {
    pen.setStyle(Qt::NoPen);
  }
  p.setPen(pen);
  if (_transparentFill) {
    p.setBrush(Qt::NoBrush);  
  } else {
    p.setBrush(_foregroundColor);
  }
  QRect r;
  r.setX(_geom.left() + bw / 2);
  r.setY(_geom.top() + bw / 2);
  r.setWidth(_geom.width() - bw);
  r.setHeight(_geom.height() - bw);

  p.drawRoundRect(r, _xRound, _yRound);
  p.restore();
}