Example #1
0
void GLEDrawingObject::setSimplePenProperties(QPen& pen) {
	QColor col;
	GLEDrawObject* obj = getGLEObject();
	GLEColor* color = obj->getProperties()->getColorProperty(GLEDOPropertyColor);
	col.setRgbF(color->getRed(), color->getGreen(), color->getBlue());
	pen.setColor(col);
	double lwidth = obj->getProperties()->getRealProperty(GLEDOPropertyLineWidth);
	pen.setWidthF(QGLE::relGLEToQt(lwidth, dpi));
	GLEString* lstyle = obj->getProperties()->getStringProperty(GLEDOPropertyLineStyle);
	if (lstyle->length() == 1 && lstyle->get(0) > (unsigned int)'1') {
		QVector<qreal> dashes;
		const char *defline[] = {"","","12","41","14","92","1282","9229","4114","54","73","7337","6261","2514"};
		const char *myline = defline[lstyle->get(0)-'0'];
		int len = strlen(myline);
		for (int i = 0; i < len; i++) {
			double value = (myline[i]-'0');
			dashes.append((qreal)QGLE::relGLEToQt(value*0.04, dpi));
		}
		pen.setDashPattern(dashes);
	} else if (lstyle->length() > 1) {
		QVector<qreal> dashes;
		for (unsigned int i = 0; i < lstyle->length(); i++) {
			double value = (lstyle->get(i)-'0');
			dashes.append((qreal)QGLE::relGLEToQt(value*0.04, dpi));
		}
		pen.setDashPattern(dashes);
	}
}
Example #2
0
QPen* getPen(const CLGraphicalPrimitive1D *item, const CLGroup *group, const CLRenderResolver* resolver, const CLBoundingBox * /*pBB*/)
{
  QColor color; double width;

  if (item != NULL && item->isSetStroke())
    {
      color = getColor(item->getStroke(), resolver);
    }
  else if (group != NULL && group->isSetStroke())
    {
      color = getColor(group->getStroke(), resolver);
    }
  else return new QPen(Qt::transparent);

  if (item != NULL && item->isSetStrokeWidth())
    {
      width = item->getStrokeWidth();
    }
  else if (group != NULL && group->isSetStrokeWidth())
    {
      width = group->getStrokeWidth();
    }
  else return new QPen(Qt::transparent);

  QPen *result = new QPen(color, width);
  result->setCapStyle(Qt::RoundCap);
  result->setJoinStyle(Qt::RoundJoin);

  if (item != NULL && item->isSetDashArray())
    {
      const std::vector<unsigned int>& raw = item->getDashArray();
      std::vector<unsigned int>::const_iterator start = raw.begin();
      QVector<qreal> pattern;

      while (start != raw.end())
        {
          pattern << *start;
          ++start;
        }

      result->setDashPattern(pattern);
    }
  else if (group != NULL && group->isSetDashArray())
    {
      const std::vector<unsigned int>& raw = group->getDashArray();
      std::vector<unsigned int>::const_iterator start = raw.begin();
      QVector<qreal> pattern;

      while (start != raw.end())
        {
          pattern << *start;
          ++start;
        }

      result->setDashPattern(pattern);
    }

  return result;
}
Example #3
0
void StitcherView::drawConstraintFit(geometrically_constrained_system *gc){
  for(int i = 0;i<gc->n_constraints;i++){
    GeometryConstraintType type = gc->constraints[i].type;
    double fit = gc->constraints[i].best_fit;    
    if(type == RadialLineConstraint){
      qreal x1,x2,y1,y2;
      qreal scale = 10000;
      x1 = cos(fit)*scale;

      y1 = sin(fit)*scale;
      x2 = -x1;
      y2 = -y1;
      QGraphicsLineItem * item = new QGraphicsLineItem(x1,y1,x2,y2);
      QPen p = item->pen();
      p.setStyle(Qt::DashLine);
      QVector<qreal> dashes;
      dashes << 25 << 15;
      p.setDashPattern(dashes);
      p.setColor(Qt::white);
      item->setPen(p);
      item->setZValue(10000);
      scene()->addItem(item);
      constraintFit.append(item);
    }else if(type == CircleConstraint){
      double radius = fit;
      QGraphicsEllipseItem * item = new QGraphicsEllipseItem(-radius,-radius,2*radius,2*radius);
      QPen p = item->pen();
      p.setStyle(Qt::DashLine);
      QVector<qreal> dashes;
      dashes << 25 << 15;
      p.setDashPattern(dashes);
      p.setColor(Qt::white);
      item->setPen(p);
      item->setZValue(10000);
      scene()->addItem(item);
      constraintFit.append(item);
    }
    sp_vector ** cp_g = control_point_list_to_global(gc->constraints[i].points,gc->constraints[i].n_points);
    QColor color = QColor::fromHsvF(1.0/3+(double)i/gc->n_constraints,1,1,1);
    for(int j = 0;j<gc->constraints[i].n_points;j++){
      QGraphicsEllipseItem * point = new QGraphicsEllipseItem(-4,-4,8,8);
      point->setZValue(10001);
      point->setPos(sp_vector_get(cp_g[j],0),sp_vector_get(cp_g[j],1));
      point->setPen(QPen(color, 2));
      point->setFlags(point->flags() | QGraphicsItem::ItemIgnoresTransformations);
      scene()->addItem(point);
      constraintFit.append(point);
    }
  }
}
Example #4
0
void SVGPaintServer::setPenProperties(const RenderObject* object, const RenderStyle* style, QPen& pen) const
{
    pen.setWidthF(SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeWidth(), 1.0));

    if (style->svgStyle()->capStyle() == ButtCap)
        pen.setCapStyle(Qt::FlatCap);
    else if (style->svgStyle()->capStyle() == RoundCap)
        pen.setCapStyle(Qt::RoundCap);

    if (style->svgStyle()->joinStyle() == MiterJoin) {
        pen.setJoinStyle(Qt::MiterJoin);
        pen.setMiterLimit((qreal) style->svgStyle()->strokeMiterLimit());
    } else if(style->svgStyle()->joinStyle() == RoundJoin)
        pen.setJoinStyle(Qt::RoundJoin);

    const DashArray& dashes = WebCore::dashArrayFromRenderingStyle(style);
    double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0);

    unsigned int dashLength = !dashes.isEmpty() ? dashes.size() : 0;
    if(dashLength) {
        QVector<qreal> pattern;
        unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2;

        for(unsigned int i = 0; i < count; i++)
            pattern.append(dashes[i % dashLength] / (float)pen.widthF());

        pen.setDashPattern(pattern);

        Q_UNUSED(dashOffset);
        // TODO: dash-offset, does/will qt4 API allow it? (Rob)
    }
}
void ImageCanvasWidget::paintEvent(QPaintEvent *) {
  QPainter painter(this);

  if (image_.isNull())
    return;
  painter.drawImage(image_.rect(), image_);

  if (active_) {
    QRect selection = options_cache_->tile_selection().adjusted(0, 0, -1, -1);

    if (underMouse()) {
      painter.setPen(Qt::yellow);
      painter.setBrush(Qt::NoBrush);
      painter.drawRect(selection);

      QVector<qreal> dashes = {2, 2};

      QPen pen;
      pen.setColor(Qt::red);
      pen.setDashPattern(dashes);
      painter.setPen(pen);
      painter.drawRect(selection);
    }
  }
}
Example #6
0
void graph2_1::paintEvent(QPaintEvent *)
{
    /***********�����α߿���������**************/
    QPainter *painter=new QPainter(this);
    painter->setRenderHint(QPainter::Antialiasing,true);
    painter->drawRect(10,10,380,230);
    QPoint beginPoint(50,200);
    QPoint xEndPoint(xEndX,xEndY);
    QPoint yEndPoint(yEndX,yEndY);
    painter->drawLine(beginPoint,xEndPoint);
    painter->drawLine(beginPoint,yEndPoint);

    //*****************����������ͷ*********/
    int xOffset=13;
    brush.setColor(Qt::black);
    brush.setStyle(Qt::SolidPattern);
    painter->setBrush(brush);

    QPoint xarrowRightPoint(xEndX+xOffset,xEndY);
    QPoint xarrowTopPoint(xEndX,-xOffset*tan(PI/6)+xEndY);
    QPoint xarrowBotPoint(xEndX,xOffset*tan(PI/6)+xEndY);
    static const QPoint xarrowPoints[3] = {
    xarrowRightPoint,xarrowTopPoint,xarrowBotPoint,
    };
    painter->drawPolygon(xarrowPoints,3);

    QPoint yarrowTopPoint(yEndX,yEndY-xOffset);
    QPoint yarrowRightPoint(xOffset*tan(PI/6)+yEndX,yEndY);
    QPoint yarrowLeftPoint(-xOffset*tan(PI/6)+yEndX,yEndY);
    static const QPoint yarrowPoints[3] = {
    yarrowTopPoint,yarrowLeftPoint,yarrowRightPoint,
    };
    painter->drawPolygon(yarrowPoints,3);
    painter->setBrush(Qt::NoBrush);

    /************��ע������**********/
    painter->drawText(xEndX,xEndY+20,tr("HZ"));
    //painter->rotate(270);
    painter->drawText(yEndY,yEndX+20,tr("dB"));
    //painter->rotate(90);


    /*************************/
    QVector<qreal> dashes;
    qreal space = 3;
    dashes << 5 << space << 5 << space;
    pen.setDashPattern(dashes);
    pen.setWidth(2);
    pen.setColor(Qt::blue);
    painter->setPen(pen);

    QPoint point5(90,200);
    QPoint point6(100,155);
    QPoint point7(250,110);
    QPoint point8(300,80);

    painter->drawPath(drawBezierCurve(point5,point6));
    painter->drawPath(drawBezierCurve(point6,point7));
    painter->drawPath(drawBezierCurve(point7,point8));
}
Example #7
0
void koregui::BindPathItem::paint(QPainter* painter,
                                  const QStyleOptionGraphicsItem* option,
                                  QWidget* widget) {
  // TODO(dospelt) use QPainterPathStroker
  QPointF start = mapFromItem(_start,6,6);
  QPointF dest = (_end)?mapFromItem(_end,6,6):_dragend;
  QPointF dist = QPointF((dest.x()- start.x())/2, 0);
  QPainterPath path(start);
  path.cubicTo(start + dist, dest - dist, dest);
  setPath(path);

  QPen p;
  p.setWidth(2);

  if (isSelected()) {
    p.setColor(QColor(100, 255, 255));
  } else {
    p.setColor(QColor(200, 200, 200));
  }
  if(_animated) {
    QVector<qreal> dashes;
    dashes << 4 << 3;
    p.setDashPattern(dashes);
    p.setDashOffset(_animOffset);
  }
  painter->setPen(p);
  painter->drawPath(path);
}
void MyPainterWidget::paintEvent(QPaintEvent *event)
{
    QPen pen;
    QVector<qreal> dashes;
    qreal space = 3;

    QWidget::paintEvent(event);
    if (m_image.isNull())
        return;
    ImageAction ia;
    QImage img = ia.GetImageZoom(m_image,action_type==Zoom?zoom:0,this->width(),this->height(),o_x,o_y);
    main_window->status_value->setText(QString("%1%").arg(ia.nowZoom));
    QPainter painter(this);
    img_rect = ia.rect;
    main_window->status_size_now->setText(QString("Now:%1x%2").arg(ia.rect.width()).arg(ia.rect.height()));
    painter.drawImage(ia.rect,img);
    percentage = (float)m_image.width()/img_rect.width();
    switch(action_type){
    case Cut:
    case Copy:
    case Delete:
        if(rect.isEmpty())break;
        pen.setBrush(QBrush(qRgb(100,100,100)));
        dashes << 5 << space << 5 <<space;
        pen.setDashPattern(dashes);
        pen.setWidth(1);
        painter.setPen(pen);
        painter.drawRect(rect);
        break;
    default:

        break;
    }
    main_window->status_size->setText(QString("%1x%2").arg(m_image.width()).arg(m_image.height()));
}
Example #9
0
void initDashPen(){
    dashPen = QPen(Qt::DashLine);
    dashPen.setWidth(1);
    QVector<qreal> dashes;
    dashes << 10 << 10;
    dashPen.setDashPattern(dashes);
}
void CurveCursor::counterSceneScale(QPointF sceneScale){
    inverseScale = QPointF(1.0/sceneScale.x(), 1.0/sceneScale.y());
    vertCoordText->resetTransform();
    vertCoordText->scale(inverseScale.x(), inverseScale.y());
    horCoordText->resetTransform();
    horCoordText->scale(inverseScale.x(), inverseScale.y());

    //de-scale the line pattern
    QPen linePen = vertLine->pen();
    linePen.setDashPattern( scaleDashPattern(inverseScale.y()) );
    vertLine->setPen(linePen);

    linePen = horLine->pen();
    linePen.setDashPattern( scaleDashPattern(inverseScale.x()) );
    horLine->setPen(linePen);
}
Example #11
0
QIcon ConfigTabAppearance::createThemeIcon(const QString &fileName)
{
    QSettings settings(fileName, QSettings::IniFormat);
    Theme theme(settings);

    QPixmap pix(16, 16);
    pix.fill(Qt::black);

    QPainter p(&pix);

    QRect rect(1, 1, 14, 5);
    p.setPen(Qt::NoPen);
    p.setBrush( theme.color("sel_bg") );
    p.drawRect(rect);

    rect.translate(0, 5);
    p.setBrush( theme.color("bg") );
    p.drawRect(rect);

    rect.translate(0, 5);
    p.setBrush( theme.color("alt_bg") );
    p.drawRect(rect);

    QLine line;

    line = QLine(2, 3, 14, 3);
    QPen pen;
    p.setOpacity(0.6);

    pen.setColor( theme.color("sel_fg") );
    pen.setDashPattern(QVector<qreal>() << 2 << 1 << 1 << 1 << 3 << 1 << 2 << 10);
    p.setPen(pen);
    p.drawLine(line);

    line.translate(0, 5);
    pen.setColor( theme.color("fg") );
    pen.setDashPattern(QVector<qreal>() << 2 << 1 << 4 << 10);
    p.setPen(pen);
    p.drawLine(line);

    line.translate(0, 5);
    pen.setDashPattern(QVector<qreal>() << 3 << 1 << 2 << 1);
    p.setPen(pen);
    p.drawLine(line);

    return pix;
}
void GeoLineStringGraphicsItem::paint( GeoPainter* painter, const ViewportParams* viewport )
{
    if ( !style() )
    {
        painter->save();
        painter->setPen( QPen() );
        painter->drawPolyline( *m_lineString );
        painter->restore();
        return;
    }
    
    if(style()->lineStyle().paintedColor() == Qt::transparent)
        return;

    painter->save();
    QPen currentPen = painter->pen();

    if ( currentPen.color() != style()->lineStyle().paintedColor() )
        currentPen.setColor( style()->lineStyle().paintedColor() );

    if ( currentPen.widthF() != style()->lineStyle().width() ||
            style()->lineStyle().physicalWidth() != 0.0 )
    {
        if ( float( viewport->radius() ) / EARTH_RADIUS * style()->lineStyle().physicalWidth() < style()->lineStyle().width() )
            currentPen.setWidthF( style()->lineStyle().width() );
        else
            currentPen.setWidthF( float( viewport->radius() ) / EARTH_RADIUS * style()->lineStyle().physicalWidth() );
    }

    if ( currentPen.capStyle() != style()->lineStyle().capStyle() )
        currentPen.setCapStyle( style()->lineStyle().capStyle() );

    if ( currentPen.style() != style()->lineStyle().penStyle() )
        currentPen.setStyle( style()->lineStyle().penStyle() );
    
    if ( style()->lineStyle().penStyle() == Qt::CustomDashLine )
        currentPen.setDashPattern( style()->lineStyle().dashPattern() );

    if ( painter->mapQuality() != Marble::HighQuality
            && painter->mapQuality() != Marble::PrintQuality )
    {
        QColor penColor = currentPen.color();
        penColor.setAlpha( 255 );
        currentPen.setColor( penColor );
    }

    if ( painter->pen() != currentPen ) painter->setPen( currentPen );
    if ( style()->lineStyle().background() )
    {
        QBrush brush = painter->background();
        brush.setColor( style()->polyStyle().paintedColor() );
        painter->setBackground( brush );

        painter->setBackgroundMode( Qt::OpaqueMode );
    }
    painter->drawPolyline( *m_lineString );
    painter->restore();
}
void QgsSimpleLineSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset )
{
  //data defined properties
  double scaledWidth = 0;
  if ( mStrokeWidthExpression )
  {
    scaledWidth = mStrokeWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble()
                  * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit );
    pen.setWidthF( scaledWidth );
    selPen.setWidthF( scaledWidth );
  }
  else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale )
  {
    scaledWidth = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit );
    pen.setWidthF( scaledWidth );
    selPen.setWidthF( scaledWidth );
  }

  //color
  if ( mStrokeColorExpression )
  {
    pen.setColor( QgsSymbolLayerV2Utils::decodeColor( mStrokeColorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
  }

  //offset
  offset = mOffset;
  if ( mLineOffsetExpression )
  {
    offset = mLineOffsetExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
  }

  //dash dot vector
  if ( mDashPatternExpression )
  {
    QVector<qreal> dashVector;
    QStringList dashList = mDashPatternExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString().split( ";" );
    QStringList::const_iterator dashIt = dashList.constBegin();
    for ( ; dashIt != dashList.constEnd(); ++dashIt )
    {
      dashVector.push_back( dashIt->toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mCustomDashPatternUnit ) / mPen.widthF() );
    }
    pen.setDashPattern( dashVector );
  }

  //join style
  if ( mJoinStyleExpression )
  {
    QString joinStyleString = mJoinStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
    pen.setJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle( joinStyleString ) );
  }

  //cap style
  if ( mCapStyleExpression )
  {
    QString capStyleString = mCapStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
    pen.setCapStyle( QgsSymbolLayerV2Utils::decodePenCapStyle( capStyleString ) );
  }
}
Example #14
0
void REPainter::SetLineDash(const REReal* lengths, int count, float phase)
{
    if(!_painter) return;
    QPen pen = _painter->pen();

    QVector<qreal> pattern;
    for(int i=0; i<count; ++i) pattern << lengths[i];

    pen.setDashPattern(pattern);
    _painter->setPen(pen);
}
Example #15
0
void TestbedImageWidget::childRepaint(QPaintEvent *event, QWidget *who)
{
    AdvancedImageWidget::childRepaint(event, who);

    if (mCurrentToolClass == POINT_SELECTION_TOOLS &&
        (mCurrentPointButton == 4 ||
        mCurrentPointButton == 5 ))
    {
        QPainter painter(who);
        QPen pen;
        QVector<qreal> dashesEven;
        QVector<qreal> dashesOdd;
        dashesEven << 2 << 1 << 2 << 1;
        dashesOdd  << 1 << 2 << 1 << 2;
        pen.setDashPattern(dashesEven);
        pen.setColor(Qt::black);
        painter.setPen(pen);
        painter.drawEllipse(mousePoint, decorationSize / 2, decorationSize / 2);
        pen.setDashPattern(dashesOdd);
        pen.setColor(Qt::white);
        painter.setPen(pen);
        painter.drawEllipse(mousePoint, decorationSize / 2, decorationSize / 2);
    }
}
Example #16
0
void Stroke::paint(QPainter &painter, qreal zoom, bool last)
{
  if (points.length() == 1)
  {
    QRectF pointRect(zoom * points[0], QSizeF(0, 0));
    qreal pad = penWidth * zoom / 2;
    painter.setPen(Qt::NoPen);
    painter.setBrush(QBrush(color));
    painter.drawEllipse(pointRect.adjusted(-pad, -pad, pad, pad));
  }
  else
  {
    QPen pen;
    pen.setColor(color);
    if (pattern != solidLinePattern)
    {
      pen.setDashPattern(pattern);
    }
    pen.setCapStyle(Qt::RoundCap);
    painter.setPen(pen);
    qreal dashOffset = 0.0;
    for (int j = 1; j < points.length(); ++j)
    {
      qreal tmpPenWidth = zoom * penWidth * (pressures.at(j - 1) + pressures.at(j)) / 2.0;
      if (pattern != solidLinePattern)
      {
        pen.setDashOffset(dashOffset);
      }
      pen.setWidthF(tmpPenWidth);
      painter.setPen(pen);
      //                painter.drawLine(zoom * points.at(j-1), zoom * points.at(j));
      if (last == false)
      {
        painter.drawLine(zoom * points.at(j - 1), zoom * points.at(j));
      }
      else if (last == true && j == points.length() - 1)
      {
        painter.drawLine(zoom * points.at(j - 1), zoom * points.at(j));
      }

      if (tmpPenWidth != 0)
        dashOffset += 1.0 / tmpPenWidth * (QLineF(zoom * points.at(j - 1), zoom * points.at(j))).length();
    }
  }
}
void GraphicsContext::setLineDash(const DashArray& dashes, float dashOffset)
{
    QPainter* p = m_data->p();
    QPen pen = p->pen();
    unsigned dashLength = dashes.size();
    if (dashLength) {
        QVector<qreal> pattern;
        unsigned count = dashLength;
        if (dashLength % 2)
            count *= 2;

        float penWidth = narrowPrecisionToFloat(double(pen.widthF()));
        for (unsigned i = 0; i < count; i++)
            pattern.append(dashes[i % dashLength] / penWidth);

        pen.setDashPattern(pattern);
        pen.setDashOffset(dashOffset);
    }
    p->setPen(pen);
}
static QPen readSimplePen (QDataStream &instream) {
	QColor col = readColor (instream);
	double lwd;
	qint32 lty;
	instream >> lwd >> lty;
	if (!col.isValid () || (lty == -1L)) return QPen (Qt::NoPen);

	lwd = qMax (1.0001, lwd);	// minimum 1 px (+rounding margin!) as in X11 device
	QPen ret;
	if (lty != 0) {	// solid
		QVector<qreal> dashes;
		quint32 nlty = lty;
		for (int i = 0; i < 8; ++i) {
			if (!nlty) break;
			quint8 j = nlty & 0xF;
			dashes.append (j * lwd * 96/72 + .5);	// 96/72: value taken from X11 device
			nlty >>= 4;
		}
		if (!dashes.isEmpty ()) ret.setDashPattern (dashes);
	}
Example #19
0
void ZCircle::displayHelper(ZPainter *painter, int stackFocus, EDisplayStyle style) const
{
  UNUSED_PARAMETER(style);
#if defined(_QT_GUI_USED_)
  double adjustedRadius = getAdjustedRadius(m_r);

  double dataFocus = stackFocus - painter->getZOffset();
  bool visible = false;

  const QBrush &oldBrush = painter->getBrush();
  const QPen &oldPen = painter->getPen();

  double alpha = oldPen.color().alphaF();

  if (stackFocus == -1) {
    visible = true;
  } else {
    if (isCuttingPlane(m_center.z(), m_r, dataFocus, m_zScale)) {
      double h = fabs(m_center.z() - dataFocus) / m_zScale;
      double r = 0.0;
      if (m_r > h) {
        r = sqrt(m_r * m_r - h * h);
        adjustedRadius = getAdjustedRadius(r);
        //adjustedRadius = r + getPenWidth() * 0.5;
        visible = true;
      } else { //too small, show at least one plane
        //adjustedRadius = getPenWidth() * 0.5;
        r = 0.1;
        adjustedRadius = getAdjustedRadius(r);
        visible = true;
      }
      if (hasVisualEffect(VE_OUT_FOCUS_DIM)) {
        alpha *= r * r / m_r / m_r;
        //alpha *= alpha;
      }
    }
  }

  if (visible) {
    if (!hasVisualEffect(VE_NO_CIRCLE)) {
      //qDebug() << painter->brush().color();
      QColor color = painter->getPenColor();
      color.setAlphaF(alpha);
      painter->setPen(color);
      painter->drawEllipse(QPointF(m_center.x(), m_center.y()),
                           adjustedRadius, adjustedRadius);
    }
  }

  if (hasVisualEffect(VE_BOUND_BOX)) {
    QRectF rect;
    double halfSize = adjustedRadius;
    if (m_usingCosmeticPen) {
      halfSize += 0.5;
    }
    rect.setLeft(m_center.x() - halfSize);
    rect.setTop(m_center.y() - halfSize);
    rect.setWidth(halfSize * 2);
    rect.setHeight(halfSize * 2);

    painter->setBrush(Qt::NoBrush);

    QPen pen = oldPen;
    if (visible) {
      pen.setStyle(Qt::SolidLine);
    } else {
      pen.setStyle(Qt::DotLine);
    }
    pen.setCosmetic(m_usingCosmeticPen);
    painter->setPen(pen);

#if 0 //for future versions
    QPen pen = oldPen;
    QVector<qreal> pattern;
    pattern << 1 << 2;
    pen.setDashPattern(pattern);
    painter->setPen(pen);
    painter->drawRect(rect);

    pen.setColor(Qt::black);
    pen.setDashOffset(1.5);
    painter->setPen(pen);
#endif

    //QPainter::CompositionMode oldMode = painter->compositionMode();
    //painter->setCompositionMode(QPainter::RasterOp_SourceXorDestination);
    painter->drawRect(rect);

    //painter->setCompositionMode(oldMode);
  }

  painter->setBrush(oldBrush);
  painter->setPen(oldPen);
#endif
}
Example #20
0
void QSvgStrokeStyle::apply(QPainter *p, const QSvgNode *, QSvgExtraStates &states)
{
    m_oldStroke = p->pen();
    m_oldStrokeOpacity = states.strokeOpacity;
    m_oldStrokeDashOffset = states.strokeDashOffset;
    m_oldVectorEffect = states.vectorEffect;

    QPen pen = p->pen();

    qreal oldWidth = pen.widthF();
    qreal width = m_stroke.widthF();
    if (oldWidth == 0)
        oldWidth = 1;
    if (width == 0)
        width = 1;
    qreal scale = oldWidth / width;

    if (m_strokeOpacitySet)
        states.strokeOpacity = m_strokeOpacity;

    if (m_vectorEffectSet)
        states.vectorEffect = m_vectorEffect;

    if (m_strokeSet) {
        if (m_style)
            pen.setBrush(m_style->brush(p, states));
        else
            pen.setBrush(m_stroke.brush());
    }

    if (m_strokeWidthSet)
        pen.setWidthF(m_stroke.widthF());

    bool setDashOffsetNeeded = false;

    if (m_strokeDashOffsetSet) {
        states.strokeDashOffset = m_strokeDashOffset;
        setDashOffsetNeeded = true;
    }

    if (m_strokeDashArraySet) {
        if (m_stroke.style() == Qt::SolidLine) {
            pen.setStyle(Qt::SolidLine);
        } else if (m_strokeWidthSet || oldWidth == 1) {
            // If both width and dash array was set, the dash array is already scaled correctly.
            pen.setDashPattern(m_stroke.dashPattern());
            setDashOffsetNeeded = true;
        } else {
            // If dash array was set, but not the width, the dash array has to be scaled with respect to the old width.
            QVector<qreal> dashes = m_stroke.dashPattern();
            for (int i = 0; i < dashes.size(); ++i)
                dashes[i] /= oldWidth;
            pen.setDashPattern(dashes);
            setDashOffsetNeeded = true;
        }
    } else if (m_strokeWidthSet && pen.style() != Qt::SolidLine && scale != 1) {
        // If the width was set, but not the dash array, the old dash array must be scaled with respect to the new width.
        QVector<qreal> dashes = pen.dashPattern();
        for (int i = 0; i < dashes.size(); ++i)
            dashes[i] *= scale;
        pen.setDashPattern(dashes);
        setDashOffsetNeeded = true;
    }

    if (m_strokeLineCapSet)
        pen.setCapStyle(m_stroke.capStyle());
    if (m_strokeLineJoinSet)
        pen.setJoinStyle(m_stroke.joinStyle());
    if (m_strokeMiterLimitSet)
        pen.setMiterLimit(m_stroke.miterLimit());

    // You can have dash offset on solid strokes in SVG files, but not in Qt.
    // QPen::setDashOffset() will set the pen style to Qt::CustomDashLine,
    // so don't call the method if the pen is solid.
    if (setDashOffsetNeeded && pen.style() != Qt::SolidLine) {
        qreal currentWidth = pen.widthF();
        if (currentWidth == 0)
            currentWidth = 1;
        pen.setDashOffset(states.strokeDashOffset / currentWidth);
    }

    pen.setCosmetic(states.vectorEffect);

    p->setPen(pen);
}
Example #21
0
void MapWidget::draw(QPainter &painter) {
	_canvas.setPreviewMode(_isDragging || _isMeasureDragging);
	_canvas.setGrayScale(!isEnabled() || _forceGrayScale);
	_canvas.draw(painter);

	if ( _isMeasuring ) {
		painter.save();
		painter.setRenderHint(QPainter::Antialiasing, true);
		painter.setPen(QPen(Qt::red, 2));

		// draw geo line
		QPoint p;
		double dist = 0.0;
		_canvas.projection()->project(p, _measurePoints[0]);
#if QT_VERSION >= 0x040400
		painter.drawEllipse(QPointF(p), 1.3f, 1.3f);
#else
		painter.drawEllipse(QRectF(p.x()-1.3f, p.y()-1.3f, 2.6f, 2.6f));
#endif
		for ( int i = 1; i < _measurePoints.size(); ++i ) {
			_canvas.projection()->project(p, _measurePoints[i]);
#if QT_VERSION >= 0x040400
			painter.drawEllipse(QPointF(p), 1.3f, 1.3f);
#else
			painter.drawEllipse(QRectF(p.x()-1.3f, p.y()-1.3f, 2.6f, 2.6f));
#endif
			dist += _canvas.drawGeoLine(painter, _measurePoints[i-1], _measurePoints[i]);
		}

		QString aziArea;
		if ( _measurePoints.size() > 2 ) {
			painter.save();
			QPen pen = QPen(Qt::red, 1, Qt::DashLine);
			QVector<qreal> dashes;
			dashes << 3 << 7;
			pen.setDashPattern(dashes);
			painter.setPen(pen);
			_canvas.drawGeoLine(painter, _measurePoints.last(), _measurePoints.first());
			painter.restore();
			aziArea = QString("Area    : %1 km²").arg(polyArea(_measurePoints));
		}
		else {
			double tmp, azi1, azi2;
			Math::Geo::delazi(_measurePoints.first().y(), _measurePoints.first().x(),
			                  _measurePoints.last().y(), _measurePoints.last().x(),
			                  &tmp, &azi1, &azi2);
			aziArea = QString("AZ / BAZ: %1 ° / %2 °")
			                  .arg(azi1, 0, 'f', 1)
			                  .arg(azi2, 0, 'f', 1);
		}

		int precision = 0;
		if ( _canvas.projection()->zoom() > 0 ) {
			precision = (int) log10(_canvas.projection()->zoom());
		}
		++precision;

		QString distStr = QString("Distance: %1 km / %2 °")
		                  .arg(Math::Geo::deg2km(dist), 0, 'f', precision)
		                  .arg(dist, 0, 'f', precision + 2);

		QFont f = painter.font();
		QFont mf = f;
		mf.setFamily("Monospace");
		mf.setStyleHint(QFont::TypeWriter);

		QFontMetrics mfm(mf);
		QFontMetrics fm(f);
		int h = mfm.height() * 4 + fm.height();
		int padding = fm.width(" ");
		QRect r = QRect(0, rect().height() - h, mfm.width(distStr) + 2*padding, h);
		painter.setPen(QPen(Qt::black));
		painter.fillRect(r, QBrush(QColor(255, 255, 255, 140)));

		r.setLeft(padding);
		painter.setFont(mf);
		_measureText = QString("Start   : %1 / %2\n"
		                       "End     : %3 / %4\n"
		                       "%5\n"
		                       "%6")
		               .arg(lat2String(_measurePoints.first().y(), precision))
		               .arg(lon2String(_measurePoints.first().x(), precision))
		               .arg(lat2String(_measurePoints.last().y(), precision))
		               .arg(lon2String(_measurePoints.last().x(), precision))
		               .arg(distStr)
		               .arg(aziArea);

		painter.drawText(r, Qt::AlignLeft, _measureText);

		r.setTop(rect().height() - fm.height());
		r.setRight(r.width()-padding);
		painter.setFont(f);
		painter.drawText(r, Qt::AlignRight, "(right click to copy/save)");
		painter.restore();
	}
}
Example #22
0
/*!
 * draw a (line) graph from screen coord pairs
 */
void Graph::drawLines(int x0, int y0, QPainter *p) const
{
  float DX_, DY_;
  float x1, y1;
  auto Scale = 1; /// \todo p->Scale;
  auto Painter = p;
  QVector<qreal> dashes;

  double Stroke=10., Space=0.;
  switch(Style) {
    case GRAPHSTYLE_DASH:
      Stroke = 10.; Space =  6.;
      break;
    case GRAPHSTYLE_DOT:
      Stroke =  2.; Space =  4.;
      break;
    case GRAPHSTYLE_LONGDASH:
      Stroke = 24.; Space =  8.;
      break;
    default:
      break;
  }

  QPen pen = Painter->pen();
  switch(Style) {
    case GRAPHSTYLE_DASH:
    case GRAPHSTYLE_DOT:
    case GRAPHSTYLE_LONGDASH:
      dashes << Stroke << Space;
      pen.setDashPattern(dashes);
      Painter->setPen(pen);
      break;
    default:
      pen.setStyle(Qt::SolidLine);
      break;
  }
  Painter->setPen(pen);

  auto pp = begin();
  if(!pp->isPt())
    pp++;

  /// \todo DX DY
  DX_ = /*p->DX*/ + float(x0)*Scale;
  DY_ = /*p->DY*/ + float(y0)*Scale;

  while(!pp->isGraphEnd()) {
    if(pp->isStrokeEnd()) ++pp; // ??
    QPainterPath path;
    if(pp->isPt()) {
      x1 = DX_ + pp->getScrX()*Scale;
      y1 = DY_ - pp->getScrY()*Scale;
      path.moveTo(x1,y1);
      ++pp;
    }else{
      break;
    }

    while(!pp->isStrokeEnd()) {
      x1 = DX_ + pp->getScrX()*Scale;
      y1 = DY_ - pp->getScrY()*Scale;
      path.lineTo(x1,y1);
      ++pp;
    }

    Painter->drawPath(path);
  }
}
Example #23
0
void SCgAlphabet::paintPair(QPainter *painter, SCgPair *pair)
{
    Q_ASSERT(pair != 0);

    QVector<QPointF> points = pair->points();

    Q_ASSERT(points.size() > 1);

    static float arrowLength = 10.f;
    static float arrowWidth = LINE_FAT_WIDTH;

    if (pair->isOrient())
    {

        static const QPointF arrowPoints[3] = {QPointF(-arrowWidth / 2.f, 0.f),
                                               QPointF(arrowWidth / 2.f, 0.f),
                                               QPointF(0.f, arrowLength)};

        // draw arrow for orient pairs
        QLineF line(points[points.size() - 2], points.last());
        double angle = ::atan2(line.dx(), line.dy());

        painter->save();
        painter->translate(line.p2());
        painter->rotate(-angle * 180.f / M_PI);
        painter->translate(0.f, -arrowLength);

        painter->setBrush(QBrush(pair->color(), Qt::SolidPattern));
        painter->setPen(Qt::NoPen);
        painter->drawConvexPolygon(arrowPoints, 3);

        painter->restore();

        // correct last point
        points.last() -= QPointF((arrowLength) * ::sin(angle), (arrowLength) * ::cos(angle));
    }

    // get type data
    SCgPosType posType = pair->posType();
    SCgConstType constType = pair->constType();
    SCgPermType permType = pair->permType();

    painter->setBrush(Qt::NoBrush);

    QPen pen(pair->color());
    pen.setCapStyle(Qt::FlatCap);
    pen.setJoinStyle(Qt::RoundJoin);

    // draw all cases
    if (pair->isAccessory())
    {       
        pen.setWidthF(LINE_THIN_WIDTH);
        QPen markPen = pen;

        if (constType == ConstUnknown && posType == PosUnknown)
        {
            painter->setPen(pen);
            painter->drawPolyline(&(points[0]), points.size());

            markPen.setWidthF(LINE_COM_ACCESS_MARK_WIDTH);
            markPen.setDashPattern(msCommonAccessoryDashPattern);

            painter->setPen(markPen);
            painter->drawPolyline(&(points[0]), points.size());
        }else
        {

            if (permType == Permanent && constType == Var)
                pen.setDashPattern(msPermVarAccesDashPattern);

            if (permType == Temporary)
            {
                if (constType == Const)
                    pen.setDashPattern(msTempConstAccesDashPattern);
                else
                    pen.setDashPattern(msTempVarAccesDashPattern);
            }

            painter->setPen(pen);
            painter->drawPolyline(&(points[0]), points.size());

            // draw negative lines
            if (posType == Negative)
            {
                painter->setPen(markPen);

                QPainterPath path = pair->shapeNormal();
                float length = path.length() - arrowLength - 3;
                int i = 0;

                qreal mult = 28.f;
                qreal offset = 22.f;
                qreal l = offset;

                while (l < length)
                {
                    qreal perc = path.percentAtLength(l);

                    painter->save();
                    painter->translate(path.pointAtPercent(perc));
                    painter->rotate(-path.angleAtPercent(perc));
                    painter->drawLine(0.f, -LINE_MARK_NEG_LENGTH, 0.f, LINE_MARK_NEG_LENGTH);
                    painter->restore();

                    l = (++i) * mult + offset;
                }

            }else   // draw fuzzy lines
                if (posType == Fuzzy)
                {
                    painter->setPen(markPen);

                    QPainterPath path = pair->shapeNormal();
                    float length = path.length() - arrowLength - 3;
                    int i = 0;

                    qreal mult = 28.f;
                    qreal offset = 22.f;
                    qreal l = offset;

                    while (l < length)
                    {
                        qreal perc = path.percentAtLength(l);

                        painter->save();
                        painter->translate(path.pointAtPercent(perc));
                        painter->rotate(-path.angleAtPercent(perc));

                        if (i % 2 == 0)
                            painter->drawLine(0.f, -LINE_MARK_FUZ_LENGTH, 0.f, 0.f);
                        else
                            painter->drawLine(0.f, LINE_MARK_FUZ_LENGTH, 0.f, 0.f);
                        painter->restore();

                        l = (++i) * mult + offset;
                    }
                }
        }
    }else // draw binary pairs
    {
        pen.setWidthF(LINE_FAT_WIDTH);
        painter->setPen(pen);
        painter->drawPolyline(&(points[0]), points.size());

        if (constType == Var)
        {
            pen.setWidthF(LINE_FATIN_WIDTH);
            pen.setDashPattern(msPermVarNoAccesDashPattern);
            pen.setDashOffset(20);
            pen.setColor(QColor(255, 255, 255));
            painter->setPen(pen);
            painter->drawPolyline(&(points[0]), points.size());
        }else
        {
            pen.setWidthF(LINE_FATIN_WIDTH);
            pen.setColor(Qt::white);
            painter->setPen(pen);
            painter->drawPolyline(&(points[0]), points.size());

            if (constType == ConstUnknown)
            {
                pen.setWidthF(LINE_THIN_WIDTH);
                pen.setDashPattern(msPermVarAccesDashPattern);
                pen.setColor(pair->color());

                painter->setPen(pen);
                painter->drawPolyline(&(points[0]), points.size());
            }
        }
    }
}
Example #24
0
void
ScaleSliderQWidget::paintEvent(QPaintEvent* /*e*/)
{
    if (_imp->mustInitializeSliderPosition) {
        if (_imp->minimum < _imp->maximum) {
            centerOn(_imp->minimum, _imp->maximum);
        }
        _imp->mustInitializeSliderPosition = false;
        seekScalePosition(_imp->value);
        _imp->initialized = true;
    }

    ///fill the background with the appropriate style color
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    p.setOpacity(1);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);

    double txtR, txtG, txtB;
    if (_imp->altered) {
        appPTR->getCurrentSettings()->getAltTextColor(&txtR, &txtG, &txtB);
    } else {
        appPTR->getCurrentSettings()->getTextColor(&txtR, &txtG, &txtB);
    }

    QColor textColor;
    textColor.setRgbF( Image::clamp<qreal>(txtR, 0., 1.),
                       Image::clamp<qreal>(txtG, 0., 1.),
                       Image::clamp<qreal>(txtB, 0., 1.) );

    QColor scaleColor;
    scaleColor.setRgbF(textColor.redF() / 2., textColor.greenF() / 2., textColor.blueF() / 2.);

    QFontMetrics fontM(_imp->font, 0);

    if (!_imp->useLineColor) {
        p.setPen(scaleColor);
    } else {
        p.setPen(_imp->lineColor);
    }

    QPointF btmLeft = _imp->zoomCtx.toZoomCoordinates(0, height() - 1);
    QPointF topRight = _imp->zoomCtx.toZoomCoordinates(width() - 1, 0);

    if ( btmLeft.x() == topRight.x() ) {
        return;
    }

    /*drawing X axis*/
    double lineYpos = height() - 1 - fontM.height()  - TO_DPIY(TICK_HEIGHT) / 2;
    p.drawLine(0, lineYpos, width() - 1, lineYpos);

    double tickBottom = _imp->zoomCtx.toZoomCoordinates( 0, height() - 1 - fontM.height() ).y();
    double tickTop = _imp->zoomCtx.toZoomCoordinates( 0, height() - 1 - fontM.height()  - TO_DPIY(TICK_HEIGHT) ).y();
    const double smallestTickSizePixel = 10.; // tick size (in pixels) for alpha = 0.
    const double largestTickSizePixel = 1000.; // tick size (in pixels) for alpha = 1.
    const double rangePixel =  width();
    const double range_min = btmLeft.x();
    const double range_max =  topRight.x();
    const double range = range_max - range_min;
    double smallTickSize;
    bool half_tick;
    ticks_size(range_min, range_max, rangePixel, smallestTickSizePixel, &smallTickSize, &half_tick);
    if ( (_imp->dataType == eDataTypeInt) && (smallTickSize < 1.) ) {
        smallTickSize = 1.;
        half_tick = false;
    }
    int m1, m2;
    const int ticks_max = 1000;
    double offset;
    ticks_bounds(range_min, range_max, smallTickSize, half_tick, ticks_max, &offset, &m1, &m2);
    std::vector<int> ticks;
    ticks_fill(half_tick, ticks_max, m1, m2, &ticks);
    const double smallestTickSize = range * smallestTickSizePixel / rangePixel;
    const double largestTickSize = range * largestTickSizePixel / rangePixel;
    const double minTickSizeTextPixel = fontM.width( QLatin1String("00") ); // AXIS-SPECIFIC
    const double minTickSizeText = range * minTickSizeTextPixel / rangePixel;
    for (int i = m1; i <= m2; ++i) {
        double value = i * smallTickSize + offset;
        const double tickSize = ticks[i - m1] * smallTickSize;
        const double alpha = ticks_alpha(smallestTickSize, largestTickSize, tickSize);
        QColor color(textColor);
        color.setAlphaF(alpha);
        QPen pen(color);
        pen.setWidthF(1.9);
        p.setPen(pen);

        // for Int slider, because smallTickSize is at least 1, isFloating can never be true
        bool isFloating = std::abs(std::floor(0.5 + value) - value) != 0.;
        assert( !(_imp->dataType == eDataTypeInt && isFloating) );
        bool renderFloating = _imp->dataType == eDataTypeDouble || !isFloating;

        if (renderFloating) {
            QPointF tickBottomPos = _imp->zoomCtx.toWidgetCoordinates(value, tickBottom);
            QPointF tickTopPos = _imp->zoomCtx.toWidgetCoordinates(value, tickTop);

            p.drawLine(tickBottomPos, tickTopPos);
        }

        if ( renderFloating && (tickSize > minTickSizeText) ) {
            const int tickSizePixel = rangePixel * tickSize / range;
            const QString s = QString::number(value);
            const int sSizePixel =  fontM.width(s);
            if (tickSizePixel > sSizePixel) {
                const int sSizeFullPixel = sSizePixel + minTickSizeTextPixel;
                double alphaText = 1.0; //alpha;
                if (tickSizePixel < sSizeFullPixel) {
                    // when the text size is between sSizePixel and sSizeFullPixel,
                    // draw it with a lower alpha
                    alphaText *= (tickSizePixel - sSizePixel) / (double)minTickSizeTextPixel;
                }
                QColor c = _imp->readOnly || !isEnabled() ? Qt::black : textColor;
                c.setAlphaF(alphaText);
                p.setFont(_imp->font);
                p.setPen(c);

                QPointF textPos = _imp->zoomCtx.toWidgetCoordinates( value, btmLeft.y() );

                p.drawText(textPos, s);
            }
        }
    }
    double positionValue = _imp->zoomCtx.toWidgetCoordinates(_imp->value, 0).x();
    QPointF sliderBottomLeft(positionValue - TO_DPIX(SLIDER_WIDTH) / 2, height() - 1 - fontM.height() / 2);
    QPointF sliderTopRight( positionValue + TO_DPIX(SLIDER_WIDTH) / 2, height() - 1 - fontM.height() / 2 - TO_DPIY(SLIDER_HEIGHT) );

    /*draw the slider*/
    p.setPen(_imp->sliderColor);
    p.fillRect(sliderBottomLeft.x(), sliderBottomLeft.y(), sliderTopRight.x() - sliderBottomLeft.x(), sliderTopRight.y() - sliderBottomLeft.y(), _imp->sliderColor);

    /*draw a black rect around the slider for contrast or orange when focused*/
    if ( !hasFocus() ) {
        p.setPen(Qt::black);
    } else {
        QPen pen = p.pen();
        pen.setColor( QColor(243, 137, 0) );
        QVector<qreal> dashStyle;
        qreal space = 2;
        dashStyle << 1 << space;
        pen.setDashPattern(dashStyle);
        p.setOpacity(0.8);
        p.setPen(pen);
    }

    p.drawLine( sliderBottomLeft.x(), sliderBottomLeft.y(), sliderBottomLeft.x(), sliderTopRight.y() );
    p.drawLine( sliderBottomLeft.x(), sliderTopRight.y(), sliderTopRight.x(), sliderTopRight.y() );
    p.drawLine( sliderTopRight.x(), sliderTopRight.y(), sliderTopRight.x(), sliderBottomLeft.y() );
    p.drawLine( sliderTopRight.x(), sliderBottomLeft.y(), sliderBottomLeft.x(), sliderBottomLeft.y() );
} // paintEvent
Example #25
0
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), pixmapCache_(3) {
	ready_ = false;
	updateDisplayTimer_ = NULL;
	loopPixmapItem_ = NULL;
	hideLoopItemTimer_ = NULL;
	loopPixmap_ = NULL;
	pixmap_ = NULL;
	rotation_ = 0;
	invalidated_ = true;
	selectionInvalidated_ = true;
	autoFit_ = true;
	loopAnimationPlaying_ = false;
	progressBarCancelButton_ = NULL;
	progressBar_ = NULL;
	selectionP1_ = QPoint(0,0);
	selectionP2_ = QPoint(0,0);

	mv::messageBoxes::setParent(this);

	possibleZoomValues_.push_back(1.0/128.0);
	possibleZoomValues_.push_back(1.0/64.0);
	possibleZoomValues_.push_back(1.0/32.0);
	possibleZoomValues_.push_back(1.0/16.0);
	possibleZoomValues_.push_back(1.0/8.0);
	possibleZoomValues_.push_back(1.0/4.0);
	possibleZoomValues_.push_back(1.0/2.0);
	possibleZoomValues_.push_back(1.0/1.5);
	possibleZoomValues_.push_back(1.0);
	possibleZoomValues_.push_back(1.5);
	possibleZoomValues_.push_back(2.0);
	possibleZoomValues_.push_back(4.0);
	possibleZoomValues_.push_back(8.0);
	possibleZoomValues_.push_back(16.0);
	possibleZoomValues_.push_back(32.0);
	possibleZoomValues_.push_back(64.0);
	possibleZoomValues_.push_back(128.0);
	zoomIndex_ = possibleZoomValues_.size() / 2;
	noZoomIndex_ = zoomIndex_;

	ui->setupUi(this);

	statusBar()->layout()->setSpacing(0);

	scene_ = new QGraphicsScene(this);
	scene_->setBackgroundBrush(QBrush(Qt::black));

	view_ = new XGraphicsView(scene_, this);
	view_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	view_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

	pixmapItem_ = new QGraphicsPixmapItem();
	scene_->addItem(pixmapItem_);

	selectionRectItem_ = new QGraphicsRectItem();
	selectionRectItem_->setBrush(QBrush(QColor(255,255,255,25)));
	selectionRectItem_->setPen(QPen(Qt::black));
	selectionRectItem_->setZValue(1000);
	selectionRectItem_->setVisible(false);
	selectionRectItem_->setRect(0,0,0,0);
	scene_->addItem(selectionRectItem_);

	selectionRectItem2_ = new QGraphicsRectItem();
	selectionRectItem2_->setBrush(QBrush(QColor(255,255,255,0)));
	QPen pen;
	QVector<qreal> dashes;
	dashes << 4 << 4;
	pen.setDashPattern(dashes);
	pen.setColor(Qt::white);
	selectionRectItem2_->setPen(pen);
	selectionRectItem2_->setZValue(1001);
	selectionRectItem2_->setVisible(false);
	selectionRectItem2_->setRect(0,0,0,0);
	scene_->addItem(selectionRectItem2_);

	splitter_ = new QSplitter(this);
	splitter_->setOrientation(Qt::Vertical);
	console_ = new mv::ConsoleWidget(this);
	splitter_->addWidget(view_);
	splitter_->addWidget(console_);
	console_->hide();
	connect(splitter_, SIGNAL(splitterMoved(int, int)), this, SLOT(splitter_splitterMoved(int, int)));

	toolbar()->setStyleSheet("QToolButton:hover { background-color: rgba(0, 0, 0, 10%); } QToolButton:!hover { color: rgba(0, 0, 0, 0%); }");

	ui->centralwidget->layout()->addWidget(splitter_);

	connect(view_, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(view_mousePress(QMouseEvent*)));
	connect(view_, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(view_mouseRelease(QMouseEvent*)));
	connect(view_, SIGNAL(mouseDrag(QMouseEvent*)), this, SLOT(view_mouseDrag(QMouseEvent*)));

	view_->show();

	ready_ = true;
	invalidate();
}
void GeoLineStringGraphicsItem::paint( GeoPainter* painter, const ViewportParams* viewport )
{
    LabelPositionFlags labelPositionFlags = NoLabel;

    painter->save();

    QPen currentPen = painter->pen();
    if ( !style() ) {
        painter->setPen( QPen() );
    }
    else {

        if ( currentPen.color() != style()->lineStyle().paintedColor() )
            currentPen.setColor( style()->lineStyle().paintedColor() );

        if ( currentPen.widthF() != style()->lineStyle().width() ||
                style()->lineStyle().physicalWidth() != 0.0 ) {
            if ( float( viewport->radius() ) / EARTH_RADIUS * style()->lineStyle().physicalWidth() < style()->lineStyle().width() )
                currentPen.setWidthF( style()->lineStyle().width() );
            else
                currentPen.setWidthF( float( viewport->radius() ) / EARTH_RADIUS * style()->lineStyle().physicalWidth() );
        }
        else if ( style()->lineStyle().width() != 0.0 ) {
            currentPen.setWidthF( style()->lineStyle().width() );
        }

        if ( currentPen.capStyle() != style()->lineStyle().capStyle() )
            currentPen.setCapStyle( style()->lineStyle().capStyle() );

        if ( currentPen.style() != style()->lineStyle().penStyle() )
            currentPen.setStyle( style()->lineStyle().penStyle() );

        if ( style()->lineStyle().penStyle() == Qt::CustomDashLine )
            currentPen.setDashPattern( style()->lineStyle().dashPattern() );

        if ( painter->mapQuality() != Marble::HighQuality
                && painter->mapQuality() != Marble::PrintQuality ) {
            QColor penColor = currentPen.color();
            penColor.setAlpha( 255 );
            currentPen.setColor( penColor );
        }

        if ( painter->pen() != currentPen )
            painter->setPen( currentPen );

        if ( style()->lineStyle().background() ) {
            QBrush brush = painter->background();
            brush.setColor( style()->polyStyle().paintedColor() );
            painter->setBackground( brush );

            painter->setBackgroundMode( Qt::OpaqueMode );
        }

        // label styles
        painter->setFont( style()->labelStyle().font() );
        switch ( style()->labelStyle().alignment() ) {
        case GeoDataLabelStyle::Corner:
        case GeoDataLabelStyle::Right:
            labelPositionFlags |= LineStart;
            break;
        case GeoDataLabelStyle::Center:
            labelPositionFlags |= LineCenter;
            break;
        }
    }

    if ( ! ( isDecoration() && currentPen.widthF() < 2.5f ) )
    {
        if( style()->lineStyle().cosmeticOutline() &&
            style()->lineStyle().penStyle() == Qt::SolidLine ) {
            if ( isDecoration() ) {
                painter->drawPolyline( *m_lineString, "", NoLabel );
            } else {
                if ( currentPen.widthF() > 2.5f ) {
                    currentPen.setWidthF( currentPen.widthF() - 2.0f );
                }
                currentPen.setColor( style()->polyStyle().paintedColor() );
                painter->setPen( currentPen );
                painter->drawPolyline( *m_lineString, feature()->name(), FollowLine,
                                        style()->labelStyle().paintedColor(),
                                        style()->labelStyle().font());
            }
        } else {
            painter->drawPolyline( *m_lineString, feature()->name(), labelPositionFlags );
        }
    }

    painter->restore();
}
Example #27
0
void DisplayTile::drawOutline(QPainter &painter) const
{
    QPen tilePen;
    QVector<qreal> dashPattern;

    tilePen.setWidth(this->size / 100);
    dashPattern << 2 << 7;

    for(int i = 0; i < 8; i++)
    {

        if(labels[i].empty())
            continue;

        Qt::PenStyle lineType;

        int startX = x;
        int startY = y;
        int xInc = 0;
        int yInc = 0;

        switch(i)
        {
        case 0:
        case 4:
            startX = x + size;
            yInc = (float)size / labels[i].size();
            break;
        case 1:
        case 5:
            startY = y + size;
            xInc = (float)size / labels[i].size();
            break;
        case 2:
        case 6:
            startX = x;
            yInc = (float)size / labels[i].size();
            break;
        case 3:
        case 7:
            startY = y;
            xInc = (float)size / labels[i].size();
            break;
        }

        if(i < 4)
            lineType = Qt::SolidLine;
        else
        {
            lineType = Qt::CustomDashLine;
            tilePen.setDashPattern(dashPattern);
            if(startX > x)
                startX -= size * .02;
            else
                startX += size * .02;
            if(startY > y)
                startY -= size * .02;
            else
                startY += size * .02;
            yInc *= .96;
            xInc *= .96;
        }

        for(QList<DisplayLabel>::ConstIterator next = labels[i].begin();
            next != labels[i].end();
            next++)
        {

            tilePen.setColor((*next).color);
            tilePen.setStyle(lineType);
            painter.setPen(tilePen);

            painter.drawLine(startX, startY, startX + xInc, startY + yInc);

            startX += xInc;
            startY += yInc;
        }
    }
}
Example #28
0
void QgsSimpleLineSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset )
{
  if ( mDataDefinedProperties.isEmpty() )
    return; // shortcut

  //data defined properties
  double scaledWidth = 0;
  QgsExpression* strokeWidthExpression = expression( "width" );
  if ( strokeWidthExpression )
  {
    scaledWidth = strokeWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble()
                  * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit, mWidthMapUnitScale );
    pen.setWidthF( scaledWidth );
    selPen.setWidthF( scaledWidth );
  }
  else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale )
  {
    scaledWidth = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit, mWidthMapUnitScale );
    pen.setWidthF( scaledWidth );
    selPen.setWidthF( scaledWidth );
  }

  //color
  QgsExpression* strokeColorExpression = expression( "color" );
  if ( strokeColorExpression )
  {
    pen.setColor( QgsSymbolLayerV2Utils::decodeColor( strokeColorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
  }

  //offset
  QgsExpression* lineOffsetExpression = expression( "offset" );
  if ( lineOffsetExpression )
  {
    offset = lineOffsetExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
  }

  //dash dot vector
  QgsExpression* dashPatternExpression = expression( "customdash" );
  if ( dashPatternExpression )
  {
    double scaledWidth = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit, mWidthMapUnitScale );
    double dashWidthDiv = mPen.widthF();

    if ( strokeWidthExpression )
    {
      dashWidthDiv = pen.widthF();
      scaledWidth = pen.widthF();
    }

    //fix dash pattern width in Qt 4.8
    QStringList versionSplit = QString( qVersion() ).split( "." );
    if ( versionSplit.size() > 1
         && versionSplit.at( 1 ).toInt() >= 8
         && ( scaledWidth * context.renderContext().rasterScaleFactor() ) < 1.0 )
    {
      dashWidthDiv = 1.0;
    }

    QVector<qreal> dashVector;
    QStringList dashList = dashPatternExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString().split( ";" );
    QStringList::const_iterator dashIt = dashList.constBegin();
    for ( ; dashIt != dashList.constEnd(); ++dashIt )
    {
      dashVector.push_back( dashIt->toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mCustomDashPatternUnit, mCustomDashPatternMapUnitScale ) / dashWidthDiv );
    }
    pen.setDashPattern( dashVector );
  }

  //join style
  QgsExpression* joinStyleExpression = expression( "joinstyle" );
  if ( joinStyleExpression )
  {
    QString joinStyleString = joinStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
    pen.setJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle( joinStyleString ) );
  }

  //cap style
  QgsExpression* capStyleExpression = expression( "capstyle" );
  if ( capStyleExpression )
  {
    QString capStyleString = capStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
    pen.setCapStyle( QgsSymbolLayerV2Utils::decodePenCapStyle( capStyleString ) );
  }
}
Example #29
0
void QgsSimpleLineSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset )
{
  if ( !hasDataDefinedProperties() )
    return; // shortcut

  //data defined properties
  bool hasStrokeWidthExpression = false;
  if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH ) )
  {
    context.setOriginalValueVariable( mWidth );
    double scaledWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(),
                         evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, context, mWidth ).toDouble(),
                         mWidthUnit, mWidthMapUnitScale );
    pen.setWidthF( scaledWidth );
    selPen.setWidthF( scaledWidth );
    hasStrokeWidthExpression = true;
  }

  //color
  bool ok;
  if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR ) )
  {
    context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( pen.color() ) );
    QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR, context, QVariant(), &ok ).toString();
    if ( ok )
      pen.setColor( QgsSymbolLayerV2Utils::decodeColor( colorString ) );
  }

  //offset
  if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OFFSET ) )
  {
    context.setOriginalValueVariable( mOffset );
    offset = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OFFSET, context, offset ).toDouble();
  }

  //dash dot vector
  if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_CUSTOMDASH ) )
  {
    double scaledWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), mWidth, mWidthUnit, mWidthMapUnitScale );
    double dashWidthDiv = mPen.widthF();

    if ( hasStrokeWidthExpression )
    {
      dashWidthDiv = pen.widthF();
      scaledWidth = pen.widthF();
    }

    //fix dash pattern width in Qt 4.8
    QStringList versionSplit = QString( qVersion() ).split( '.' );
    if ( versionSplit.size() > 1
         && versionSplit.at( 1 ).toInt() >= 8
         && ( scaledWidth * context.renderContext().rasterScaleFactor() ) < 1.0 )
    {
      dashWidthDiv = 1.0;
    }

    QVector<qreal> dashVector;
    QStringList dashList = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_CUSTOMDASH, context, QVariant(), &ok ).toString().split( ';' );
    if ( ok )
    {
      QStringList::const_iterator dashIt = dashList.constBegin();
      for ( ; dashIt != dashList.constEnd(); ++dashIt )
      {
        dashVector.push_back( QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), dashIt->toDouble(), mCustomDashPatternUnit, mCustomDashPatternMapUnitScale ) / dashWidthDiv );
      }
      pen.setDashPattern( dashVector );
    }
  }

  //line style
  if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_LINE_STYLE ) )
  {
    context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodePenStyle( pen.style() ) );
    QString lineStyleString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_LINE_STYLE, context, QVariant(), &ok ).toString();
    if ( ok )
      pen.setStyle( QgsSymbolLayerV2Utils::decodePenStyle( lineStyleString ) );
  }

  //join style
  if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_JOINSTYLE ) )
  {
    context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodePenJoinStyle( pen.joinStyle() ) );
    QString joinStyleString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_JOINSTYLE, context, QVariant(), &ok ).toString();
    if ( ok )
      pen.setJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle( joinStyleString ) );
  }

  //cap style
  if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_CAPSTYLE ) )
  {
    context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodePenCapStyle( pen.capStyle() ) );
    QString capStyleString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_CAPSTYLE, context, QVariant(), &ok ).toString();
    if ( ok )
      pen.setCapStyle( QgsSymbolLayerV2Utils::decodePenCapStyle( capStyleString ) );
  }
}