Exemplo n.º 1
0
void QgsPalLabeling::drawLabeling( QgsRenderContext& context )
{
  Q_ASSERT( mMapRenderer != NULL );
  QPainter* painter = context.painter();
  QgsRectangle extent = context.extent();

  if ( mLabelSearchTree )
  {
    mLabelSearchTree->clear();
  }

  QTime t;
  t.start();

  // do the labeling itself
  double scale = mMapRenderer->scale(); // scale denominator
  QgsRectangle r = extent;
  double bbox[] = { r.xMinimum(), r.yMinimum(), r.xMaximum(), r.yMaximum() };

  std::list<LabelPosition*>* labels;
  pal::Problem* problem;
  try
  {
    problem = mPal->extractProblem( scale, bbox );
  }
  catch ( std::exception& e )
  {
    Q_UNUSED( e );
    QgsDebugMsg( "PAL EXCEPTION :-( " + QString::fromLatin1( e.what() ) );
    //mActiveLayers.clear(); // clean up
    return;
  }

  const QgsMapToPixel* xform = mMapRenderer->coordinateTransform();

  // draw rectangles with all candidates
  // this is done before actual solution of the problem
  // before number of candidates gets reduced
  mCandidates.clear();
  if ( mShowingCandidates && problem )
  {
    painter->setPen( QColor( 0, 0, 0, 64 ) );
    painter->setBrush( Qt::NoBrush );
    for ( int i = 0; i < problem->getNumFeatures(); i++ )
    {
      for ( int j = 0; j < problem->getFeatureCandidateCount( i ); j++ )
      {
        pal::LabelPosition* lp = problem->getFeatureCandidate( i, j );

        drawLabelCandidateRect( lp, painter, xform );
      }
    }
  }

  // find the solution
  labels = mPal->solveProblem( problem, mShowingAllLabels );

  QgsDebugMsg( QString( "LABELING work:  %1 ms ... labels# %2" ).arg( t.elapsed() ).arg( labels->size() ) );
  t.restart();

  painter->setRenderHint( QPainter::Antialiasing );

  // draw the labels
  std::list<LabelPosition*>::iterator it = labels->begin();
  for ( ; it != labels->end(); ++it )
  {
    QgsPalGeometry* palGeometry = dynamic_cast< QgsPalGeometry* >(( *it )->getFeaturePart()->getUserGeometry() );
    if ( !palGeometry )
    {
      continue;
    }

    //layer names
    QString layerNameUtf8 = QString::fromUtf8(( *it )->getLayerName() );
    if ( palGeometry->isDiagram() )
    {
      //render diagram
      QHash<QgsVectorLayer*, QgsDiagramLayerSettings>::iterator dit = mActiveDiagramLayers.begin();
      for ( dit = mActiveDiagramLayers.begin(); dit != mActiveDiagramLayers.end(); ++dit )
      {
        if ( dit.key() && dit.key()->id().append( "d" ) == layerNameUtf8 )
        {
          QgsPoint outPt = xform->transform(( *it )->getX(), ( *it )->getY() );
          dit.value().renderer->renderDiagram( palGeometry->diagramAttributes(), context, QPointF( outPt.x(), outPt.y() ) );
        }
      }

      //insert into label search tree to manipulate position interactively
      if ( mLabelSearchTree )
      {
        //for diagrams, remove the additional 'd' at the end of the layer id
        QString layerId = layerNameUtf8;
        layerId.chop( 1 );
        mLabelSearchTree->insertLabel( *it,  QString( palGeometry->strId() ).toInt(), layerId, true );
      }
      continue;
    }

    const QgsPalLayerSettings& lyr = layer( layerNameUtf8 );
    QFont fontForLabel = lyr.textFont;
    QColor fontColor = lyr.textColor;
    double bufferSize = lyr.bufferSize;
    QColor bufferColor = lyr.bufferColor;

    //apply data defined settings for the label
    //font size
    QVariant dataDefinedSize = palGeometry->dataDefinedValues().value( QgsPalLayerSettings::Size );
    if ( dataDefinedSize.isValid() )
    {
      fontForLabel.setPixelSize( lyr.sizeToPixel( dataDefinedSize.toDouble(), context ) );
    }
    //font color
    QVariant dataDefinedColor = palGeometry->dataDefinedValues().value( QgsPalLayerSettings::Color );
    if ( dataDefinedColor.isValid() )
    {
      fontColor.setNamedColor( dataDefinedColor.toString() );
      if ( !fontColor.isValid() )
      {
        fontColor = lyr.textColor;
      }
    }
    //font bold
    QVariant dataDefinedBold = palGeometry->dataDefinedValues().value( QgsPalLayerSettings::Bold );
    if ( dataDefinedBold.isValid() )
    {
      fontForLabel.setBold(( bool )dataDefinedBold.toInt() );
    }
    //font italic
    QVariant dataDefinedItalic = palGeometry->dataDefinedValues().value( QgsPalLayerSettings::Italic );
    if ( dataDefinedItalic.isValid() )
    {
      fontForLabel.setItalic(( bool ) dataDefinedItalic.toInt() );
    }
    //font underline
    QVariant dataDefinedUnderline = palGeometry->dataDefinedValues().value( QgsPalLayerSettings::Underline );
    if ( dataDefinedUnderline.isValid() )
    {
      fontForLabel.setUnderline(( bool ) dataDefinedUnderline.toInt() );
    }
    //font strikeout
    QVariant dataDefinedStrikeout = palGeometry->dataDefinedValues().value( QgsPalLayerSettings::Strikeout );
    if ( dataDefinedStrikeout.isValid() )
    {
      fontForLabel.setStrikeOut(( bool ) dataDefinedStrikeout.toInt() );
    }
    //font family
    QVariant dataDefinedFontFamily = palGeometry->dataDefinedValues().value( QgsPalLayerSettings::Family );
    if ( dataDefinedFontFamily.isValid() )
    {
      fontForLabel.setFamily( dataDefinedFontFamily.toString() );
    }
    //buffer size
    QVariant dataDefinedBufferSize = palGeometry->dataDefinedValues().value( QgsPalLayerSettings::BufferSize );
    if ( dataDefinedBufferSize.isValid() )
    {
      bufferSize = dataDefinedBufferSize.toDouble();
    }

    //buffer color
    QVariant dataDefinedBufferColor = palGeometry->dataDefinedValues().value( QgsPalLayerSettings::BufferColor );
    if ( dataDefinedBufferColor.isValid() )
    {
      bufferColor.setNamedColor( dataDefinedBufferColor.toString() );
      if ( !bufferColor.isValid() )
      {
        bufferColor = lyr.bufferColor;
      }
    }

    if ( lyr.bufferSize != 0 )
      drawLabel( *it, painter, fontForLabel, fontColor, xform, bufferSize, bufferColor, true );

    drawLabel( *it, painter, fontForLabel, fontColor, xform );

    if ( mLabelSearchTree )
    {
      mLabelSearchTree->insertLabel( *it,  QString( palGeometry->strId() ).toInt(), ( *it )->getLayerName() );
    }
  }

  QgsDebugMsg( QString( "LABELING draw:  %1 ms" ).arg( t.elapsed() ) );

  delete problem;
  delete labels;

  // delete all allocated geometries for features
  QHash<QgsVectorLayer*, QgsPalLayerSettings>::iterator lit;
  for ( lit = mActiveLayers.begin(); lit != mActiveLayers.end(); ++lit )
  {
    QgsPalLayerSettings& lyr = lit.value();
    for ( QList<QgsPalGeometry*>::iterator git = lyr.geometries.begin(); git != lyr.geometries.end(); ++git )
      delete *git;
    lyr.geometries.clear();
  }

  //delete all allocated geometries for diagrams
  QHash<QgsVectorLayer*, QgsDiagramLayerSettings>::iterator dIt = mActiveDiagramLayers.begin();
  for ( ; dIt != mActiveDiagramLayers.end(); ++dIt )
  {
    QgsDiagramLayerSettings& dls = dIt.value();
    for ( QList<QgsPalGeometry*>::iterator git = dls.geometries.begin(); git != dls.geometries.end(); ++git )
    {
      delete *git;
    }
    dls.geometries.clear();
  }
}
Exemplo n.º 2
0
void MyRenderWidget::paintEvent(QPaintEvent * /*event*/ )
{
    QPainter painter;
    painter.begin(this);
    
    QColor color(0,0,0,255);
    QMatrix m,n;

    QString secstr = QString::number(sec);
    QString minstr = QString::number(min);
    QString hourstr = QString::number(hour);

    QFont font("Arial",12);
    painter.setFont(font);
    painter.drawText(200,75,hourstr);
    painter.drawText(250,75,minstr);
    painter.drawText(300,75,secstr);
	
    //Shadow
    m.reset();
    m.translate(90,420);
    m.rotate(-35);
    m.shear(1,0.2);
    m.scale(0.5,0.5);

    painter.setMatrix(m);
    painter.setPen(Qt::gray);
    painter.setBrush(QColor(138, 121, 93,255));
    painter.drawEllipse(100,100,300,300);

    //Background
    m.reset();
    painter.setMatrix(m);
    painter.setPen(QColor(0,0,0,255));
    painter.setBrush(QColor(16,23,33,255));
    painter.drawEllipse(100,100,300,300);

    m.scale(0.8,0.8);
    painter.setMatrix(m);
    painter.setBrush(QColor(188,237,241,255));
    painter.drawEllipse(165,163,300,300);    

    //Number
    QPoint rotatedPoint;
    painter.setMatrix(m);
    for(int deg = 1; deg < 13; deg++){
        m.reset();
        m.translate(146,155);
        m.rotate(deg*30-135);

        rotatedPoint = QPoint(97,97)* m;
        n.reset();
        n.translate(rotatedPoint.x(), rotatedPoint.y());

        painter.setMatrix(n);
        painter.setPen(QColor(245,146,55,255));

        QString hour = QString::number(deg);
        QFont font("Arial",12);
        painter.setFont(font);
        painter.drawText(100,100,hour);
    }

    //Second Hand
    m.reset();
    m.translate(250,250);
    m.rotate(180+6*sec);
    m.translate(-100,-100);

    painter.setMatrix(m);
    painter.setPen(QColor(245,146,55,255));
    painter.drawLine(99,100,99,220);

    //Minute Hand
    m.reset();
    m.translate(250,250);
    m.rotate(-90+6*min);
    m.translate(-100,-100);

    painter.setMatrix(m);
    painter.setPen(QColor(245,146,55,255));
    painter.setBrush(QColor(245,146,55,255));
    painter.drawRect(100,100,130,5);

    //Hour Hand
    m.reset();
    m.translate(250,250);
    m.rotate(-90+30*hour+0.5*min);
    m.translate(-100,-100);

    painter.setMatrix(m);
    painter.setPen(QColor(245,146,55,255));
    painter.setBrush(QColor(245,146,55,255));
    painter.drawRect(100,100,100,10);
	
    //Center dot
    m.reset();
    painter.setMatrix(m);
    painter.setPen(QColor(0,0,0,255));
    painter.setBrush(QColor(16,23,33,255));
    painter.drawEllipse(245,245,20,20);

	painter.end();		
}
Exemplo n.º 3
0
void PointSetStyles::drawShape(QPainter &p, int xScreen, int yScreen, PointSetStyle pointSetStyle)
{
  p.setPen(pointSetPen(pointSetStyle.pointLineColor, pointSetStyle.pointLineSize));
  p.setBrush(pointSetBrush(pointSetStyle.pointInColor));

  Q3PointArray arr;  
  int hPS = pointSizeToHalfwidth(pointSetStyle.pointSize); // half point size, excluding point line size
  
  switch (pointSetStyle.pointShape)
  {
  case Cross:
    arr.resize(9);
    arr.setPoint(0, QPoint(-hPS + xScreen,    0 + yScreen));
    arr.setPoint(1, QPoint(   0 + xScreen,    0 + yScreen));
    arr.setPoint(2, QPoint(   0 + xScreen, -hPS + yScreen));
    arr.setPoint(3, QPoint(   0 + xScreen,    0 + yScreen));
    arr.setPoint(4, QPoint( hPS + xScreen,    0 + yScreen));
    arr.setPoint(5, QPoint(   0 + xScreen,    0 + yScreen));
    arr.setPoint(6, QPoint(   0 + xScreen,  hPS + yScreen));
    arr.setPoint(7, QPoint(   0 + xScreen,    0 + yScreen));
    arr.setPoint(8, QPoint(-hPS + xScreen,    0 + yScreen));
    break;
  case Diamond:
    arr.resize(5);
    arr.setPoint(0, QPoint(-hPS + xScreen,    0 + yScreen));
    arr.setPoint(1, QPoint(   0 + xScreen, -hPS + yScreen));
    arr.setPoint(2, QPoint( hPS + xScreen,    0 + yScreen));
    arr.setPoint(3, QPoint(   0 + xScreen,  hPS + yScreen));
    arr.setPoint(4, QPoint(-hPS + xScreen,    0 + yScreen));
    break;
  case Square:
    arr.resize(5);
    arr.setPoint(0, QPoint(-hPS + xScreen, -hPS + yScreen));
    arr.setPoint(1, QPoint( hPS + xScreen, -hPS + yScreen));
    arr.setPoint(2, QPoint( hPS + xScreen,  hPS + yScreen));
    arr.setPoint(3, QPoint(-hPS + xScreen,  hPS + yScreen));
    arr.setPoint(4, QPoint(-hPS + xScreen, -hPS + yScreen));
    break;
  case Triangle:
    arr.resize(4);
    arr.setPoint(0, QPoint(-hPS + xScreen,  hPS + yScreen));
    arr.setPoint(1, QPoint( hPS + xScreen,  hPS + yScreen));
    arr.setPoint(2, QPoint(   0 + xScreen, -hPS + yScreen));
    arr.setPoint(3, QPoint(-hPS + xScreen,  hPS + yScreen));
    break;
  case X:
  default:
    arr.resize(9);
    arr.setPoint(0, QPoint(-hPS + xScreen, -hPS + yScreen));
    arr.setPoint(1, QPoint(   0 + xScreen,    0 + yScreen));
    arr.setPoint(2, QPoint(-hPS + xScreen,  hPS + yScreen));
    arr.setPoint(3, QPoint(   0 + xScreen,    0 + yScreen));
    arr.setPoint(4, QPoint( hPS + xScreen,  hPS + yScreen));
    arr.setPoint(5, QPoint(   0 + xScreen,    0 + yScreen));
    arr.setPoint(6, QPoint( hPS + xScreen, -hPS + yScreen));
    arr.setPoint(7, QPoint(   0 + xScreen,    0 + yScreen));
    arr.setPoint(8, QPoint(-hPS + xScreen, -hPS + yScreen));
    break;
  }

  p.drawPolygon(arr);
}
Exemplo n.º 4
0
void QgsHistogramDiagram::renderDiagram( const QgsFeature& feature, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position )
{
  QPainter* p = c.painter();
  if ( !p )
  {
    return;
  }

  QList<double> values;
  double maxValue = 0;

  QgsExpressionContext expressionContext = c.expressionContext();
  expressionContext.setFeature( feature );
  if ( feature.fields() )
    expressionContext.setFields( *feature.fields() );

  Q_FOREACH ( const QString& cat, s.categoryAttributes )
  {
    QgsExpression* expression = getExpression( cat, expressionContext );
    double currentVal = expression->evaluate( &expressionContext ).toDouble();
    values.push_back( currentVal );
    maxValue = qMax( currentVal, maxValue );
  }

  double scaledMaxVal = sizePainterUnits( maxValue * mScaleFactor, s, c );

  double currentOffset = 0;
  double scaledWidth = sizePainterUnits( s.barWidth, s, c );

  double baseX = position.x();
  double baseY = position.y();

  mPen.setColor( s.penColor );
  setPenWidth( mPen, s, c );
  p->setPen( mPen );

  QList<double>::const_iterator valIt = values.constBegin();
  QList< QColor >::const_iterator colIt = s.categoryColors.constBegin();
  for ( ; valIt != values.constEnd(); ++valIt, ++colIt )
  {
    double length = sizePainterUnits( *valIt * mScaleFactor, s, c );

    mCategoryBrush.setColor( *colIt );
    p->setBrush( mCategoryBrush );

    switch ( s.diagramOrientation )
    {
      case QgsDiagramSettings::Up:
        p->drawRect( baseX + currentOffset, baseY, scaledWidth, length * -1 );
        break;

      case QgsDiagramSettings::Down:
        p->drawRect( baseX + currentOffset, baseY - scaledMaxVal, scaledWidth, length );
        break;

      case QgsDiagramSettings::Right:
        p->drawRect( baseX, baseY - currentOffset, length, scaledWidth * -1 );
        break;

      case QgsDiagramSettings::Left:
        p->drawRect( baseX + scaledMaxVal, baseY - currentOffset, 0 - length, scaledWidth * -1 );
        break;
    }

    currentOffset += scaledWidth;
  }
}
Exemplo n.º 5
0
void ossimGui::ImageScrollWidget::paintMultiLayer(QPainter& painter)
{
   if(m_multiLayerAlgorithm != ANIMATION_ALGORITHM)
   {
      ossimRefPtr<Layer> topLayer    = m_layers->layer((ossim_uint32)0);
      ossimRefPtr<Layer> bottomLayer    = m_layers->layer((ossim_uint32)1);
      if(topLayer.valid()&&bottomLayer.valid())
      {
         ossimRefPtr<StaticTileImageCache> topTileCache = topLayer->tileCache();
         ossimRefPtr<StaticTileImageCache> bottomTileCache = bottomLayer->tileCache();
         
         if(topTileCache.valid()&&bottomTileCache.valid())
         {
            ossimIrect rect = topTileCache->getRect();
            QRectF rectF    = m_scrollToLocal.mapRect(QRectF(rect.ul().x, rect.ul().y, rect.width(), rect.height()));
            ossimIpt topOriginOffset = ossimDpt(rectF.x(), rectF.y());
            // for scrolling we need to offset from the tile location to the actual rect indicated by the viewport.
            // 
            ossim_uint32 w = rect.width();
            ossim_uint32 h = rect.height();
            switch(m_multiLayerAlgorithm)
            {
               case HORIZONTAL_SWIPE_ALGORITHM:
               {
                  ossim_int64 topLayerx     = topOriginOffset.x;
                  ossim_int64 bottomLayerx  = m_activePointEnd.x();
                  ossim_int64 topLayerWidth = bottomLayerx - topLayerx;
                  painter.drawImage(topLayerx, topOriginOffset.y, topTileCache->getCache(), 0,0,topLayerWidth,h);
                  painter.drawImage(topLayerx+topLayerWidth, topOriginOffset.y, bottomTileCache->getCache(), topLayerWidth, 0);
                  break;
               }
               case VERTICAL_SWIPE_ALGORITHM:
               {
                  ossim_int64 topLayery    = topOriginOffset.y;
                  ossim_int64 bottomLayery = m_activePointEnd.y();
                  ossim_int64 topLayerHeight = bottomLayery - topLayery;
                  painter.drawImage(topOriginOffset.x, topLayery, topTileCache->getCache(), 0, 0, w, topLayerHeight);
                  painter.drawImage(topOriginOffset.x, topLayery+topLayerHeight, bottomTileCache->getCache(), 0, topLayerHeight);
                  break;
               }
               case BOX_SWIPE_ALGORITHM:
               {
                  painter.drawImage(topOriginOffset.x, topOriginOffset.y, topTileCache->getCache());
                  ossim_int64 minx = ossim::min(m_activePointStart.x(), m_activePointEnd.x());
                  ossim_int64 maxx = ossim::max(m_activePointStart.x(), m_activePointEnd.x());
                  ossim_int64 miny = ossim::min(m_activePointStart.y(), m_activePointEnd.y());
                  ossim_int64 maxy = ossim::max(m_activePointStart.y(), m_activePointEnd.y());
                  ossim_int64 w = maxx-minx;
                  ossim_int64 h = maxy-miny;
                  ossim_int64 x = minx;
                  ossim_int64 y = miny;
                  QPointF scrollPoint = m_localToScroll.map(QPointF(x,y));
                  ossimDrect cacheRect = bottomTileCache->getRect();
                  ossimDpt delta = ossimDpt(scrollPoint.x(), scrollPoint.y()) - cacheRect.ul();
                  
                  painter.drawImage(x, y, bottomTileCache->getCache(), delta.x, delta.y, w, h);
                  break;
               }
               case CIRCLE_SWIPE_ALGORITHM:
               {
                  // QImage& cahceImage = topTileCache->getCache();
                  // draw top and then overlay the bottom
                  ossim_int64 minx = ossim::min(m_activePointStart.x(), m_activePointEnd.x());
                  ossim_int64 maxx = ossim::max(m_activePointStart.x(), m_activePointEnd.x());
                  ossim_int64 miny = ossim::min(m_activePointStart.y(), m_activePointEnd.y());
                  ossim_int64 maxy = ossim::max(m_activePointStart.y(), m_activePointEnd.y());
                  ossim_int64 w = maxx-minx;
                  ossim_int64 h = maxy-miny;
                  ossim_int64 x = minx;
                  ossim_int64 y = miny;

                  // QPointF scrollPoint = m_localToScroll.map(QPointF(x,y));
                  // ossimDpt cachePt = ossimDpt(scrollPoint.x(), scrollPoint.y()) - topTileCache->getRect().ul();
                  painter.save();
                  painter.drawImage(topOriginOffset.x, topOriginOffset.y, topTileCache->getCache());
                  painter.setBrush(QBrush(bottomTileCache->getCache()));
                  painter.setPen(Qt::NoPen);
                  
                  // this part is a little tricky but for the texturing to be placed in the ellipse properly
                  // I had to add a translation for the painter because the cache might extend past the current scroll region because it
                  // is on tile boundaries
                  //
                  // Because we shift for texturing with the QBrush we must undo the shift when drawing the ellipse so it lines up with
                  // the mouse draws.  The topOriginOffset holds the shift.
                  //
                  painter.translate(topOriginOffset.x, topOriginOffset.y);
                  painter.drawEllipse(x-topOriginOffset.x,y-topOriginOffset.y,w,h);
                  painter.restore();
                  break;
               }
               default:
               {
                  break;
               }
            }
         }
      }
   }
   else
   {
   }
   
}
Exemplo n.º 6
0
void KoColorBackground::paint(QPainter &painter, const QPainterPath &fillPath) const
{
    painter.setBrush(QBrush(d->color, d->style));
    painter.drawPath(fillPath);
}
Exemplo n.º 7
0
void MapIcons::paintIcon(MapParameters& param, 
			 QPainter& p, 
			 const MapIcon& mapIcon,
			 const Point3D<int16_t>& item, 
			 const QString& itemName,
			 const QPoint& point)
{
  // Draw Line
  if (mapIcon.showLine0())
  {
    p.setPen(mapIcon.line0Pen());
    p.drawLine(param.playerXOffset(), 
	       param.playerYOffset(),
	       point.x(), point.y());
  }

  // Calculate distance and draw distance related lines
  uint32_t distance = UINT32_MAX;
  if (mapIcon.line1Distance() || mapIcon.line2Distance())
  {
    if (!showeq_params->fast_machine)
      distance = item.calcDist2DInt(param.player());
    else
      distance = (int)item.calcDist(param.player());

    if (mapIcon.line1Distance() > distance)
    {
      p.setPen(mapIcon.line1Pen());
      p.drawLine(param.playerXOffset(), 
		 param.playerYOffset(),
		 point.x(), point.y());
    }

    if (mapIcon.line2Distance() > distance)
    {
      p.setPen(mapIcon.line2Pen());
      p.drawLine(param.playerXOffset(), 
		 param.playerYOffset(),
		 point.x(), point.y());
    }
  }

  // Draw Item Name
  if (mapIcon.showName())
  {
    QFontMetrics fm(param.font());
    int width = fm.width(itemName);
    p.setPen(gray);
    p.drawText(point.x() - (width / 2),
	       point.y() + fm.height() + 1, itemName);
  }

  // Draw Icon Image
  if (mapIcon.image() && 
      (!mapIcon.imageFlash() || m_flash) &&
      (mapIcon.imageStyle() != tIconStyleNone))
  {
    p.setPen(mapIcon.imagePen());
    p.setBrush(mapIcon.imageBrush());

    mapIcon.paintIconImage(mapIcon.imageStyle(), p, point, 
			   *m_mapIconSizes[mapIcon.imageSize()],
			   *m_mapIconSizesWH[mapIcon.imageSize()]);
  }

  // Draw Highlight
  if (mapIcon.highlight() && 
      (!mapIcon.highlightFlash() || m_flash) &&
      (mapIcon.highlightStyle() != tIconStyleNone))
  {
    p.setPen(mapIcon.highlightPen());
    p.setBrush(mapIcon.highlightBrush());

    mapIcon.paintIconImage(mapIcon.highlightStyle(), p, point, 
			   *m_mapIconSizes[mapIcon.highlightSize()],
			   *m_mapIconSizesWH[mapIcon.highlightSize()]);
  }
}
Exemplo n.º 8
0
	void FrameView::paintEvent(QPaintEvent *)
	{
		const int px_unit = font.pixelSize();
		const int px_hspace = px_unit * horizontal_factor;
		const int px_vspace = px_unit * vertical_factor;
		const int y_offset = viewport()->height()/2 - px_vspace/2;

		const DocInfo *dinfo = gui::activeDocInfo();

		m_currentFrame = dinfo->currentFrame();
		m_currentChannel = dinfo->currentChannel();
		int currentFrame = m_currentFrame;
		int currentChannel = m_currentChannel;

		const int frame_y_offset = y_offset - currentFrame*px_vspace;

		const QColor bg = stylecolor(styles::PATTERN_BG);

		QPainter p;
		p.begin(viewport());
		p.setPen(Qt::NoPen);
		p.setBrush(bg);
		p.drawRect(rect());

		{
			QLinearGradient lg(0, 0, 0, 1);
			lg.setColorAt(0, QColor(96, 96, 96));
			lg.setColorAt(1, QColor(64, 64, 64));
			lg.setCoordinateMode(QGradient::ObjectBoundingMode);

			p.setBrush(lg);
			p.drawRect(0, y_offset, viewport()->width(), px_vspace);
		}

		{
			p.setBrush(QColor(255,255,255,64));
			p.drawRect(px_hspace*(currentChannel+1), y_offset, px_hspace, px_vspace);
		}

		p.setFont(font);

		QTextOption opt;
		opt.setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);

		const QColor framenumcol = stylecolor(styles::PATTERN_HIGHLIGHT2_FG, true);

		p.setPen(framenumcol);
		p.setBrush(Qt::NoBrush);

		FtmDocument *d = activeDocument();

		int chans = 0;
		if (d != NULL)
		{
			 chans = d->GetAvailableChannels();
		}

		int num_frames = d->GetFrameCount();

		int viewport_height = viewport()->height();

		for (int i = 0; i < num_frames; i++)
		{
			int y = px_vspace*i+frame_y_offset;
			if (y+px_vspace < 0)
				continue;
			if (y > viewport_height)
				break;

			char buf[6];
			sprintf(buf, "%02X", i);

			p.drawText(QRect(0,y,px_hspace,px_vspace), buf, opt);
		}

		unsigned int active_patterns[MAX_CHANNELS];

		for (int i = 0; i < chans; i++)
		{
			active_patterns[i] = d->GetPatternAtFrame(currentFrame, i);
		}

		const QColor selectedpat = stylecolor(styles::PATTERN_FG, true);
		const QColor unselectedpat = stylecolor(styles::PATTERN_FG, false);


		for (int i = 0; i < num_frames; i++)
		{
			int y = px_vspace*i+frame_y_offset;
			if (y+px_vspace < 0)
				continue;
			if (y > viewport_height)
				break;
			for (int x = 0; x < chans; x++)
			{
				char buf[6];
				int pattern = d->GetPatternAtFrame(i, x);

				if (pattern == active_patterns[x])
				{
					p.setPen(selectedpat);
				}
				else
				{
					p.setPen(unselectedpat);
				}

				sprintf(buf, "%02X", pattern);
				p.drawText(QRect(px_hspace*(x+1),y,px_hspace,px_vspace), buf, opt);
			}
		}

		p.setPen(Qt::gray);
		p.drawLine(px_hspace,0,px_hspace,viewport()->height());

		p.end();
	}
Exemplo n.º 9
0
void NWaveformSlider::checkForUpdate()
{
    if (!m_waveBuilder)
        return;

    float builderPos;
    int builderIndex;
    m_waveBuilder->positionAndIndex(builderPos, builderIndex);

    if (m_oldSize != size() || m_oldBuilderIndex != builderIndex)
        m_needsUpdate = true;

    if ((builderPos != 0.0 && builderPos != 1.0) && m_timer->interval() != FAST_INTERVAL)
        m_timer->setInterval(FAST_INTERVAL);
    else
    if ((builderPos == 0.0 || builderPos == 1.0) && m_timer->interval() != IDLE_INTERVAL)
        m_timer->setInterval(IDLE_INTERVAL);

    if (m_needsUpdate) {
        QPainter painter;
        QImage waveImage;
        QImage backgroundImage;
        waveImage = backgroundImage = m_progressPlayingImage = m_progressPausedImage = m_remainingPlayingImage = m_remainingPausedImage = QImage(size(), QImage::Format_ARGB32_Premultiplied);

        m_oldBuilderPos = builderPos;
        m_oldBuilderIndex = builderIndex;
        m_oldSize = size();


        // waveform >>
        waveImage.fill(0);
        painter.begin(&waveImage);
        painter.setBrush(m_waveBackground);
        QPen wavePen;
        wavePen.setWidth(0);
        wavePen.setColor(m_waveBorderColor);
        painter.setPen(wavePen);

        painter.translate(1, 1);
        painter.scale((qreal)(width() - 1) / m_oldBuilderIndex * m_oldBuilderPos, (height() - 2) / 2);
        painter.translate(0, 1);

        QPainterPath pathPos;
        QPainterPath pathNeg;
        NWaveformPeaks *peaks = m_waveBuilder->peaks();
        for (int i = 0; i < m_oldBuilderIndex; ++i) {
            pathPos.lineTo(i, peaks->positive(i));
            pathNeg.lineTo(i, peaks->negative(i));
        }
        QPainterPath fullPath(pathNeg);
        fullPath.connectPath(pathPos.toReversed());
        fullPath.closeSubpath();
        painter.setRenderHint(QPainter::Antialiasing);
        painter.drawPath(fullPath);
        painter.end();
        // << waveform


        // main background >>
        painter.begin(&backgroundImage);
        backgroundImage.fill(0);
        painter.setPen(Qt::NoPen);
        painter.setBrush(m_background);
        painter.setRenderHint(QPainter::Antialiasing);
        painter.drawRoundedRect(rect(), m_radius, m_radius);
        painter.end();
        // << main background


        QList<QImage *> images; images << &m_progressPlayingImage << &m_progressPausedImage << &m_remainingPlayingImage << &m_remainingPausedImage;
        QList<QPainter::CompositionMode> modes; modes << m_playingComposition << m_pausedComposition << m_playingComposition << m_pausedComposition;
        QList<QBrush> brushes; brushes << m_progressPlayingBackground << m_progressPausedBackground << m_remainingPlayingBackground << m_remainingPausedBackground;
        for (int i = 0; i < images.size(); ++i) {
            painter.begin(images[i]);
            // background
            images[i]->fill(0);
            // + overlay
            painter.setPen(Qt::NoPen);
            painter.setBrush(brushes[i]);
            painter.setRenderHint(QPainter::Antialiasing);
            painter.drawRoundedRect(rect(), m_radius, m_radius);
            // + waveform
            painter.setCompositionMode(modes[i]);
            painter.drawImage(0, 0, waveImage);
            painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
            painter.drawImage(0, 0, backgroundImage);
            painter.end();
        }

        update();
        m_needsUpdate = false;
    }
}
Exemplo n.º 10
0
QPixmap QgsFontButton::createDragIcon( QSize size, const QgsTextFormat *tempFormat, const QFont *tempFont ) const
{
  if ( !tempFormat )
    tempFormat = &mFormat;
  if ( !tempFont )
    tempFont = &mFont;

  //create an icon pixmap
  QPixmap pixmap( size.width(), size.height() );
  pixmap.fill( Qt::transparent );
  QPainter p;
  p.begin( &pixmap );
  p.setRenderHint( QPainter::Antialiasing );
  QRect rect( 0, 0, size.width(), size.height() );

  if ( mMode == ModeQFont || tempFormat->color().lightnessF() < 0.7 )
  {
    p.setBrush( QBrush( QColor( 255, 255, 255 ) ) );
    p.setPen( QPen( QColor( 150, 150, 150 ), 0 ) );
  }
  else
  {
    p.setBrush( QBrush( QColor( 0, 0, 0 ) ) );
    p.setPen( QPen( QColor( 100, 100, 100 ), 0 ) );
  }
  p.drawRect( rect );
  p.setBrush( Qt::NoBrush );
  p.setPen( Qt::NoPen );

  switch ( mMode )
  {
    case ModeTextRenderer:
    {
      QgsRenderContext context;
      QgsMapToPixel newCoordXForm;
      newCoordXForm.setParameters( 1, 0, 0, 0, 0, 0 );
      context.setMapToPixel( newCoordXForm );

      context.setScaleFactor( QgsApplication::desktop()->logicalDpiX() / 25.4 );
      context.setUseAdvancedEffects( true );
      context.setPainter( &p );

      // slightly inset text to account for buffer/background
      double xtrans = 0;
      if ( tempFormat->buffer().enabled() )
        xtrans = context.convertToPainterUnits( tempFormat->buffer().size(), tempFormat->buffer().sizeUnit(), tempFormat->buffer().sizeMapUnitScale() );
      if ( tempFormat->background().enabled() && tempFormat->background().sizeType() != QgsTextBackgroundSettings::SizeFixed )
        xtrans = std::max( xtrans, context.convertToPainterUnits( tempFormat->background().size().width(), tempFormat->background().sizeUnit(), tempFormat->background().sizeMapUnitScale() ) );

      double ytrans = 0.0;
      if ( tempFormat->buffer().enabled() )
        ytrans = std::max( ytrans, context.convertToPainterUnits( tempFormat->buffer().size(), tempFormat->buffer().sizeUnit(), tempFormat->buffer().sizeMapUnitScale() ) );
      if ( tempFormat->background().enabled() )
        ytrans = std::max( ytrans, context.convertToPainterUnits( tempFormat->background().size().height(), tempFormat->background().sizeUnit(), tempFormat->background().sizeMapUnitScale() ) );

      QRectF textRect = rect;
      textRect.setLeft( xtrans );
      textRect.setWidth( textRect.width() - xtrans );
      textRect.setTop( ytrans );
      if ( textRect.height() > 300 )
        textRect.setHeight( 300 );
      if ( textRect.width() > 2000 )
        textRect.setWidth( 2000 );

      QgsTextRenderer::drawText( textRect, 0, QgsTextRenderer::AlignCenter, QStringList() << tr( "Aa" ),
                                 context, *tempFormat );
      break;
    }
    case ModeQFont:
    {
      p.setBrush( Qt::NoBrush );
      p.setPen( QColor( 0, 0, 0 ) );
      p.setFont( *tempFont );
      QRectF textRect = rect;
      textRect.setLeft( 2 );
      p.drawText( textRect, Qt::AlignVCenter, tr( "Aa" ) );
      break;
    }
  }

  p.end();
  return pixmap;
}
Exemplo n.º 11
0
//drawing:
void G_arcSector::draw(QPainter &p, const G_drawstyle &d, bool selected)
{ //FIXME!
  double r = arc.getRadius();
  QRect re = p.window();

  if(!inRect(re)) return;

  if(r > DRAW_MAX / 2) {
    //draw big arc...

    return;
  }

  p.setBrush(d.getBrush());
  p.setPen(QPen(Qt::NoPen));

  const double angle_scale = -16 * 180. / M_PI;
  
  if(/*p.device()->isExtDev() ||*/ p.hasViewXForm()) { //draw at higher accuracy to a printer or image
    p.scale(0.125, .125);

    p.drawPie(ROUND((arc.getCenter().getX() - r) * 8),
	      ROUND((arc.getCenter().getY() - r) * 8),
	      ROUND(r * 16), ROUND(r * 16),
	      ROUND(((arc.getP2() - arc.getCenter()).angle() -
		     acos(arc.getCosangle())) * angle_scale),
	      ROUND(angle_scale * acos(arc.getCosangle()) * 2));

    p.scale(8, 8);
    return;
  }

  p.drawPie(ROUND(arc.getCenter().getX() - r),
	    ROUND(arc.getCenter().getY() - r),
	    ROUND(r * 2), ROUND(r * 2),
	    ROUND(((arc.getP2() - arc.getCenter()).angle() -
		   acos(arc.getCosangle())) * angle_scale),
	    ROUND(angle_scale * acos(arc.getCosangle()) * 2));
  
  if(selected) {
    if(KSegView::getSelectType() == KSegView::BORDER_SELECT) {
      p.setBrush(QBrush(G_drawstyle::getBorderColor(d.getBrush().color()), Qt::BDiagPattern));
    }
    if(selected && KSegView::getSelectType() == KSegView::BLINKING_SELECT) {
      QColor c(QTime::currentTime().msec() * 17, 255, 255, QColor::Hsv);
      
      p.setBrush(QBrush(c, Qt::BDiagPattern));
    }
    
    p.drawPie(ROUND(arc.getCenter().getX() - r),
	      ROUND(arc.getCenter().getY() - r),
	      ROUND(r * 2), ROUND(r * 2),
	      ROUND(((arc.getP2() - arc.getCenter()).angle() -
		     acos(arc.getCosangle())) * angle_scale),
	      ROUND(angle_scale * acos(arc.getCosangle()) * 2));    

  }

  p.setBrush(QBrush());

  return;

}
Exemplo n.º 12
0
void QLCDNumber::drawSegment( const QPoint &pos, char segmentNo, QPainter &p,
			      int segLen, bool erase )
{
    QPoint pt = pos;
    int width = segLen/5;

    const QColorGroup & g = colorGroup();
    QColor lightColor,darkColor,fgColor;
    if ( erase ){
	lightColor = backgroundColor();
	darkColor  = lightColor;
	fgColor    = lightColor;
    } else {
	lightColor = g.light();
	darkColor  = g.dark();
	fgColor    = g.foreground();
    }

#define LINETO(X,Y) addPoint( a, QPoint(pt.x() + (X),pt.y() + (Y)))
#define LIGHT
#define DARK

    if ( fill ) {
	QPointArray a(0);

	//The following is an exact copy of the switch below.
	//don't make any changes here
	switch ( segmentNo ) {
	case 0 :
	    p.moveTo(pt);
	    LIGHT;
	    LINETO(segLen - 1,0);
	    DARK;
	    LINETO(segLen - width - 1,width);
	    LINETO(width,width);
	    LINETO(0,0);
	    break;
	case 1 :
	    pt += QPoint(0 , 1);
	    p.moveTo(pt);
	    LIGHT;
	    LINETO(width,width);
	    DARK;
	    LINETO(width,segLen - width/2 - 2);
	    LINETO(0,segLen - 2);
	    LIGHT;
	    LINETO(0,0);
	    break;
	case 2 :
	    pt += QPoint(segLen - 1 , 1);
	    p.moveTo(pt);
	    DARK;
	    LINETO(0,segLen - 2);
	    LINETO(-width,segLen - width/2 - 2);
	    LIGHT;
	    LINETO(-width,width);
	    LINETO(0,0);
	    break;
	case 3 :
	    pt += QPoint(0 , segLen);
	    p.moveTo(pt);
	    LIGHT;
	    LINETO(width,-width/2);
	    LINETO(segLen - width - 1,-width/2);
	    LINETO(segLen - 1,0);
	    DARK;
	    if (width & 1) {		// adjust for integer division error
		LINETO(segLen - width - 3,width/2 + 1);
		LINETO(width + 2,width/2 + 1);
	    } else {
		LINETO(segLen - width - 1,width/2);
		LINETO(width,width/2);
	    }
	    LINETO(0,0);
	    break;
	case 4 :
	    pt += QPoint(0 , segLen + 1);
	    p.moveTo(pt);
	    LIGHT;
	    LINETO(width,width/2);
	    DARK;
	    LINETO(width,segLen - width - 2);
	    LINETO(0,segLen - 2);
	    LIGHT;
	    LINETO(0,0);
	    break;
	case 5 :
	    pt += QPoint(segLen - 1 , segLen + 1);
	    p.moveTo(pt);
	    DARK;
	    LINETO(0,segLen - 2);
	    LINETO(-width,segLen - width - 2);
	    LIGHT;
	    LINETO(-width,width/2);
	    LINETO(0,0);
	    break;
	case 6 :
	    pt += QPoint(0 , segLen*2);
	    p.moveTo(pt);
	    LIGHT;
	    LINETO(width,-width);
	    LINETO(segLen - width - 1,-width);
	    LINETO(segLen - 1,0);
	    DARK;
	    LINETO(0,0);
	    break;
	case 7 :
	    if ( smallPoint )	// if smallpoint place'.' between other digits
		pt += QPoint(segLen + width/2 , segLen*2);
	    else
		pt += QPoint(segLen/2 , segLen*2);
	    p.moveTo(pt);
	    DARK;
	    LINETO(width,0);
	    LINETO(width,-width);
	    LIGHT;
	    LINETO(0,-width);
	    LINETO(0,0);
	    break;
	case 8 :
	    pt += QPoint(segLen/2 - width/2 + 1 , segLen/2 + width);
	    p.moveTo(pt);
	    DARK;
	    LINETO(width,0);
	    LINETO(width,-width);
	    LIGHT;
	    LINETO(0,-width);
	    LINETO(0,0);
	    break;
	case 9 :
	    pt += QPoint(segLen/2 - width/2 + 1 , 3*segLen/2 + width);
	    p.moveTo(pt);
	    DARK;
	    LINETO(width,0);
	    LINETO(width,-width);
	    LIGHT;
	    LINETO(0,-width);
	    LINETO(0,0);
	    break;
#if defined(CHECK_RANGE)
	default :
	    qWarning( "QLCDNumber::drawSegment: (%s) Internal error."
		     "  Illegal segment id: %d\n",
		     name( "unnamed" ), segmentNo );
#endif
	}
	// End exact copy
	p.setPen( fgColor );
	p.setBrush( fgColor );
	p.drawPolygon( a );
	p.setBrush( NoBrush );

	pt = pos;
    }
#undef LINETO
#undef LIGHT
#undef DARK

#define LINETO(X,Y) p.lineTo(QPoint(pt.x() + (X),pt.y() + (Y)))
#define LIGHT p.setPen(lightColor)
#define DARK  p.setPen(darkColor)
    if ( shadow )
	switch ( segmentNo ) {
	case 0 :
	    p.moveTo(pt);
	    LIGHT;
	    LINETO(segLen - 1,0);
	    DARK;
	    LINETO(segLen - width - 1,width);
	    LINETO(width,width);
	    LINETO(0,0);
	    break;
	case 1 :
	    pt += QPoint(0,1);
	    p.moveTo(pt);
	    LIGHT;
	    LINETO(width,width);
	    DARK;
	    LINETO(width,segLen - width/2 - 2);
	    LINETO(0,segLen - 2);
	    LIGHT;
	    LINETO(0,0);
	    break;
	case 2 :
	    pt += QPoint(segLen - 1 , 1);
	    p.moveTo(pt);
	    DARK;
	    LINETO(0,segLen - 2);
	    LINETO(-width,segLen - width/2 - 2);
	    LIGHT;
	    LINETO(-width,width);
	    LINETO(0,0);
	    break;
	case 3 :
	    pt += QPoint(0 , segLen);
	    p.moveTo(pt);
	    LIGHT;
	    LINETO(width,-width/2);
	    LINETO(segLen - width - 1,-width/2);
	    LINETO(segLen - 1,0);
	    DARK;
	    if (width & 1) {		// adjust for integer division error
		LINETO(segLen - width - 3,width/2 + 1);
		LINETO(width + 2,width/2 + 1);
	    } else {
		LINETO(segLen - width - 1,width/2);
		LINETO(width,width/2);
	    }
	    LINETO(0,0);
	    break;
	case 4 :
	    pt += QPoint(0 , segLen + 1);
	    p.moveTo(pt);
	    LIGHT;
	    LINETO(width,width/2);
	    DARK;
	    LINETO(width,segLen - width - 2);
	    LINETO(0,segLen - 2);
	    LIGHT;
	    LINETO(0,0);
	    break;
	case 5 :
	    pt += QPoint(segLen - 1 , segLen + 1);
	    p.moveTo(pt);
	    DARK;
	    LINETO(0,segLen - 2);
	    LINETO(-width,segLen - width - 2);
	    LIGHT;
	    LINETO(-width,width/2);
	    LINETO(0,0);
	    break;
	case 6 :
	    pt += QPoint(0 , segLen*2);
	    p.moveTo(pt);
	    LIGHT;
	    LINETO(width,-width);
	    LINETO(segLen - width - 1,-width);
	    LINETO(segLen - 1,0);
	    DARK;
	    LINETO(0,0);
	    break;
	case 7 :
	    if ( smallPoint )	// if smallpoint place'.' between other digits
		pt += QPoint(segLen + width/2 , segLen*2);
	    else
		pt += QPoint(segLen/2 , segLen*2);
	    p.moveTo(pt);
	    DARK;
	    LINETO(width,0);
	    LINETO(width,-width);
	    LIGHT;
	    LINETO(0,-width);
	    LINETO(0,0);
	    break;
	case 8 :
	    pt += QPoint(segLen/2 - width/2 + 1 , segLen/2 + width);
	    p.moveTo(pt);
	    DARK;
	    LINETO(width,0);
	    LINETO(width,-width);
	    LIGHT;
	    LINETO(0,-width);
	    LINETO(0,0);
	    break;
	case 9 :
	    pt += QPoint(segLen/2 - width/2 + 1 , 3*segLen/2 + width);
	    p.moveTo(pt);
	    DARK;
	    LINETO(width,0);
	    LINETO(width,-width);
	    LIGHT;
	    LINETO(0,-width);
	    LINETO(0,0);
	    break;
#if defined(CHECK_RANGE)
	default :
	    qWarning( "QLCDNumber::drawSegment: (%s) Internal error."
		     "  Illegal segment id: %d\n",
		     name( "unnamed" ), segmentNo );
#endif
	}

#undef LINETO
#undef LIGHT
#undef DARK
}
void QRoundProgressBar::drawInnerBackground(QPainter &p, const QRectF &innerRect) {
    if (m_barStyle == StyleDonut) {
        p.setBrush(palette().alternateBase());
        p.drawEllipse(innerRect);
    }
}
Exemplo n.º 14
0
bool m_node::eventFilter(QObject *object, QEvent *event){

    //std::cout << "THE EVENT IS : "<< event->type() << "\n";



    if(QLabel* label = static_cast<QLabel*>(object)){


        if(event->type() == QEvent::MouseButtonDblClick){

            std::cout << "declanche double clic \n";

            this->edit_label->setReadOnly(false);
            this->edit_label->setFocus();

            return true;
        }

        if (event->type()==QEvent::KeyPress) {

                std::cout <<"declanche key press \n";
                QKeyEvent* key = static_cast<QKeyEvent*>(event);
                if ( (key->key()==Qt::Key_Enter) || (key->key()==Qt::Key_Return) ) {

                    this->edit_label->setReadOnly(true);
                    this->setName(edit_label->text());
                    this->edit_label->clearFocus();
                    this->edit_label->setStyleSheet("border:nonde;background-color:#4c5053;");

                }

                return true;
        }

        if(event->type() == QEvent::MouseButtonPress){

            if(QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event)){

                if(mouseEvent->button() == Qt::RightButton){

                    std::cout <<"declanche right button \n";
                    QSize iconSize = QSize (30,30);
                    QPixmap iconPmap (iconSize);
                    iconPmap.fill (Qt::transparent);

                    QPainter painter (&iconPmap);
                    painter.setBrush (QBrush (*m_colors::colorNonParcouru));
                    painter.setPen(QPen(Qt::NoPen));
                    painter.drawRect (0,0,30,30);
                    painter.drawPixmap (0, 0, iconPmap);

                    QIcon retIconNonParoucru;
                    retIconNonParoucru.addPixmap(iconPmap, QIcon::Normal, QIcon::Off);
                    retIconNonParoucru.addPixmap(iconPmap, QIcon::Normal, QIcon::On);

                    painter.setBrush (QBrush (*m_colors::colorActif));
                    painter.drawRect (0,0,30,30);
                    painter.drawPixmap (0, 0, iconPmap);

                    QIcon retIconActif;
                    retIconActif.addPixmap(iconPmap, QIcon::Normal, QIcon::Off);
                    retIconActif.addPixmap(iconPmap, QIcon::Normal, QIcon::On);

                    painter.setBrush (QBrush (*m_colors::colorParcouru));
                    painter.drawRect (0,0,30,30);
                    painter.drawPixmap (0, 0, iconPmap);

                    QIcon retIconParcouru;
                    retIconParcouru.addPixmap(iconPmap, QIcon::Normal, QIcon::Off);
                    retIconParcouru.addPixmap(iconPmap, QIcon::Normal, QIcon::On);

                    painter.setBrush (QBrush (*m_colors::colorSolution));
                    painter.drawRect (0,0,30,30);
                    painter.drawPixmap (0, 0, iconPmap);

                    QIcon retIconSolution;
                    retIconSolution.addPixmap(iconPmap, QIcon::Normal, QIcon::Off);
                    retIconSolution.addPixmap(iconPmap, QIcon::Normal, QIcon::On);

                    menu = new QMenu(this);
                    menu->setStyleSheet("background-color:#8e8e8e;padding:0;");


                    action_non_parcouru = new QAction(retIconNonParoucru,"Non parcouru", this);
                    action_actif = new QAction(retIconActif,"Actif", this);
                    action_parcouru = new QAction(retIconParcouru, "Parcouru", this);
                    action_solution = new QAction(retIconSolution,"Solution",this);

                    if(this->isInitial && !this->isFinal){
                        action_setInitial = new QAction("☑ Noeud initial",this);
                        action_setFinal = new QAction("☐ Noeud final",this);
                        action_setSimpleNode = new QAction("☐ Noeud simple",this);
                    }
                    else if(!this->isInitial && this->isFinal){
                        action_setInitial = new QAction("☐ Noeud initial",this);
                        action_setFinal = new QAction("☑ Noeud final",this);
                        action_setSimpleNode = new QAction("☐ Noeud simple",this);
                    }
                    else{
                        action_setInitial = new QAction("☐ Noeud initial",this);
                        action_setFinal = new QAction("☐ Noeud final",this);
                        action_setSimpleNode = new QAction("☑ Noeud simple",this);
                    }


                    QObject::connect(action_solution,SIGNAL(triggered()),this, SLOT(setSolutionColor()));
                    QObject::connect(action_non_parcouru,SIGNAL(triggered()),this, SLOT(setNonParcouruColor()));
                    QObject::connect(action_parcouru,SIGNAL(triggered()),this, SLOT(setParcouruColor()));
                    QObject::connect(action_actif,SIGNAL(triggered()),this, SLOT(setActifColor()));
                    QObject::connect(action_setInitial,SIGNAL(triggered()),this, SLOT(setInitialStyle()));
                    QObject::connect(action_setFinal,SIGNAL(triggered()),this, SLOT(setFinalStyle()));
                    QObject::connect(action_setSimpleNode,SIGNAL(triggered()),this, SLOT(setSimpleStyle()));

                    menu->addAction(action_non_parcouru);
                    menu->addAction(action_actif);
                    menu->addAction(action_parcouru);
                    menu->addAction(action_solution);
                    menu->addAction(action_setInitial);
                    menu->addAction(action_setFinal);
                    menu->addAction(action_setSimpleNode);

                    //menu->installEventFilter(this);
                    //menu->grabMouse();
                    menu->exec(mouseEvent->globalPos());


                }

            }
            return true;

        }



            //fonction hover node
            if(event->type() == QEvent::Enter){
                if(static_cast<QWidget*>(object) && object == this){

                  std::cout << "mouseEnter \n";
                  this->drawBorder = true;
                  this->repaint();
                }

                return true;

            }
            else if(event->type() == QEvent::Leave && !imSelected){
                if(static_cast<QWidget*>(object) && object == this){

                   this->drawBorder = false;
                   this->repaint();
                }

                return true;

            }




     }

    return false;
}
Exemplo n.º 15
0
void MyImageWidget::painterDrawCar(QPainter &paint)
{
    paint.setPen(QPen(Qt::black, 1));
    paint.setBrush(Qt::black);
    paint.drawEllipse(QPoint(nCarX,nCarY),7,7);


    QPoint points[3];
    double rdx,rdy,dx0,dy0,dx1,dy1,dx2,dy2;
    double pi = 3.141592653;

    dx0 = 21*sin((dCarSita/180)*pi);
    dy0 = 21*cos((dCarSita/180)*pi);
    dx2 = 14*sin((dCarSita/180)*pi);
    dy2 = 14*cos((dCarSita/180)*pi);
    rdx = 11*sin((dCarSita/180)*pi);
    rdy = 11*cos((dCarSita/180)*pi);
    dx1 = 7*cos((dCarSita/180)*pi);
    dy1 = 7*sin((dCarSita/180)*pi);

    points[0]=QPoint(nCarX+rdx-dx1,nCarY-rdy-dy1);
    points[1]=QPoint(nCarX+dx0,nCarY-dy0);
    points[2]=QPoint(nCarX+rdx+dx1,nCarY-rdy+dy1);
    points[3]=QPoint(nCarX+dx2,nCarY-dy2);

    paint.drawPolygon(points,4);

//    //绘制小车图标
//    QImage *myImage = new QImage;
//    QString strPath = QApplication::applicationDirPath()+"/car.png";
//    myImage->load(strPath);
//    QPixmap myPixmap = QPixmap::fromImage(*myImage).scaled(myImage->width()/5,myImage->height()/5);
//    QMatrix myMatrix;
//    myMatrix.rotate(dCarSita);
//    myPixmap=myPixmap.transformed(myMatrix);
//    switch((int)dCarSita)
//    {
//    case 0:
//        paint.drawPixmap(nCarX-myImage->width()/10,nCarY-myImage->height()/10,myPixmap);
//        break;
//    case 45:
//        paint.drawPixmap(nCarX-myImage->width()/7,nCarY-myImage->height()/7,myPixmap);
//        break;
//    case 90:
//        paint.drawPixmap(nCarX-myImage->height()/10,nCarY-myImage->width()/10,myPixmap);
//        break;
//    case 135:
//        paint.drawPixmap(nCarX-myImage->width()/7,nCarY-myImage->width()/7,myPixmap);
//        break;
//    case 180:
//        paint.drawPixmap(nCarX-myImage->width()/10,nCarY-myImage->height()/10,myPixmap);
//        break;
//    case 225:
//        paint.drawPixmap(nCarX-myImage->width()/7,nCarY-myImage->height()/7,myPixmap);
//        break;
//    case 270:
//        paint.drawPixmap(nCarX-myImage->height()/10,nCarY-myImage->width()/10,myPixmap);
//        break;
//    case 315:
//        paint.drawPixmap(nCarX-myImage->height()/7,nCarY-myImage->height()/7,myPixmap);
//        break;
//    default:
//        paint.drawPixmap(nCarX,nCarY,myPixmap);
//        break;
//    }
}
void GridDisplay::paintEvent(QPaintEvent* /* event */) 
{

	QPainter painter;
	painter.begin(this);
	_cellSize = grid_->getCellSize(_winSize);

	//Find density
	int maxDensity = 0;
	int minDensity = 100;
	for (int i=0; i < grid_->getFiles().size(); i++) {
		if(grid_->getFilesAt(i).size() > maxDensity)
		{
			maxDensity = grid_->getFilesAt(i).size();
		}
		else if (grid_->getFilesAt(i).size() < minDensity) 
		{
			minDensity = grid_->getFilesAt(i).size();
		}
	}
	Colormap *map = Colormap::factory(Colormap::GreyScale);
	for (int i=0; i < grid_->getHeight(); i++) {
		for (int j=0; j < grid_->getWidth(); j++) {

			int k = j * grid_->getHeight() + i;

			QRect	 myr(i*_cellSize,j*_cellSize,_cellSize,_cellSize);
			QLine	 myl1(i*_cellSize,j*_cellSize, i*_cellSize, j*_cellSize + _cellSize);
			QLine	 myl2(i*_cellSize,j*_cellSize, i*_cellSize+_cellSize, j*_cellSize );

			if ( grid_->getFilesAt(k).size() == 0 ) 
			{
				QColor color;
				if(colourMapMode_)
				{
					color.setRgb(map->getRed(0), map->getGreen(0), map->getBlue(0));
				}
				else
				{
					color.setRgb(map->getRed(128), map->getGreen(0), map->getBlue(0));
				}
				painter.setBrush(color);
			}
			else 
			{
				if(colourMapMode_)
				{
					/*
					* index - genre - color
					* 0 - blues - Qt::blue
					* 1 - classical - Qt::darkRed
					* 2 - country - Qt::green
					* 3 - disco - PURPLE
					* 4 - hiphop - Qt::yellow
					* 5 - jazz - Qt::darkGreen
					* 6 - metal - BROWN
					* 7 - reggae - PINK
					* 8 - rock - ORANGE
					* 9 - pop - Qt::grey
					*/
					int * genreDensity = grid_->getDensity(k);
					double *squarePaintSize = new double[10];
					int startHeight = j*_cellSize;

					for(int m = 0; m < 10; m++)
					{
						squarePaintSize[m] = genreDensity[m] /  (1.0 * grid_->getFilesAt(k).size() );
					}

					// 10 is the number of genres
					for(int l = 0; l < 10; l++)
					{
						QColor * color;
						switch(l)
						{
						case 0:
							color = new QColor(Qt::blue);
							break;
						case 1:
							color = new QColor(Qt::darkRed);
							break;
						case 2:
							color = new QColor(Qt::green);
							break;
						case 3:
							color = new QColor(PURPLE);
							break;
						case 4:
							color = new QColor(Qt::yellow);
							break;
						case 5:
							color = new QColor(Qt::darkGreen);
							break;
						case 6:
							color = new QColor(BROWN);
							break;
						case 7:
							color = new QColor(PINK);
							break;
						case 8:
							color = new QColor(ORANGE);
							break;
						case 9:
							color = new QColor(Qt::gray);
							break;
						}
						if(grid_->getFilesAt(k).size() > 0)
						{
							painter.setBrush(*color);
							painter.setPen(Qt::NoPen);
							QRect rect(i*_cellSize, startHeight, _cellSize, squarePaintSize[l] * _cellSize);
							painter.drawRect(rect);
							startHeight += squarePaintSize[l] *  _cellSize;
						}
					}

				}
				else
				{
					int c = int(grid_->getFilesAt(k).size() / float(maxDensity) * (map->getDepth()-1));
					QColor color(map->getRed(c), map->getGreen(c), map->getBlue(c));
					painter.setBrush(color);
				}
			}

			if(colourMapMode_)
			{
				painter.setPen(Qt::white);
				if(grid_->getFilesAt(k).size() == 0)
				painter.drawRect(myr);
			}
			else
			{
				painter.setPen(Qt::NoPen);
				painter.drawRect(myr);
				painter.setPen(Qt::black);
			}
			painter.drawLine(myl1);
			painter.drawLine(myl2);

			painter.setBrush(Qt::red);
			QRect newr( grid_->getXPos() * _cellSize + _cellSize / 4,
				grid_->getYPos() * _cellSize + _cellSize / 4,
				_cellSize - _cellSize / 2,
				_cellSize-_cellSize / 2);
			painter.drawRect(newr);

			painter.setBrush(Qt::white);
			QRect newr1( grid_->getX1Pos() * _cellSize + _cellSize / 4,
				grid_->getY1Pos() * _cellSize + _cellSize / 4,
				_cellSize - _cellSize / 2,
				_cellSize-_cellSize / 2);
			painter.drawRect(newr1);
		}
	}

	// Draw an 'i' in all initilized squares
	for(int i = 0; i < squareHasInitialized.size(); i++)
	{
		if(squareHasInitialized[i])
		{
			int y = i / grid_->getHeight();
			int x = i % grid_->getHeight();
			painter.setBrush(Qt::green);
			QFont *font = new QFont();
			font->setPointSize(16);
			font->setStyleHint(QFont::OldEnglish);
			painter.setFont(*font);
			painter.drawText(x * _cellSize, y * _cellSize, _cellSize, _cellSize, Qt::AlignCenter, "i");
		}
	}

	delete map;
	painter.end();
}
Exemplo n.º 17
0
void MyImageWidget::painterDrawNaveRoute(QPainter &paint)
{
    paint.setPen(QPen(Qt::green, 3));
    paint.setBrush(Qt::green);
    paint.drawPolyline(naviRoutePoints,nNaviRoutePointsNumber);
}
Exemplo n.º 18
0
void DemoGLWidget::paintGL()
{
    // Render scene to FBO
    //render_fbo->bind();
    //glBindFramebuffer(GL_FRAMEBUFFER, fbo->frame);


    QPainter painter;
    painter.begin(this);
    Utils::setPainter(&painter);

    painter.beginNativePainting();

    float r = 0.05f;
    float g = 0.05f;
    float b = 0.2f;

    // Flash screen on snare hit
    float snareEnv = synth_get_current_envelope_for_instrument(4);

    if (snareEnv > 0.001f)
    {
        r += snareEnv * 0.2f;
        g += snareEnv * 0.2f;
        b += snareEnv * 0.2f;
    }

    glClearColor(r, g, b, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

    glFrontFace(GL_CW);
    glCullFace(GL_FRONT);

    painter.endNativePainting();


    // Create entities when an instrument is first played
    if (synth_get_current_note_for_instrument(0) != 0 &&
        critter == 0)
    {
        critter = new Critter(QPointF(500,200), 10, CRITTER_SPEED);
    }

    if (synth_get_current_note_for_instrument(1) != 0 &&
        entity1 == 0)
    {
        entity1 = new Entity(QPointF(300,200), 6, 3, 1);
        entities.append(entity1);
        entities.append(new Entity(QPointF(200,300), 10, 3, 1));
    }

    if (synth_get_current_note_for_instrument(2) != 0 &&
        entity2 == 0)
    {
        entity2 = new Entity(QPointF(300,200), 8, 3, 2);
        entities.append(entity2);
        entities.append(new Entity(QPointF(200,400), 10, 3, 2));
    }

    if (synth_get_current_note_for_instrument(3) != 0 &&
        entity3 == 0)
    {
        entity3 = new Entity(QPointF(300,200), 8, 3, 3);
        entities.append(entity3);
        entities.append(new Entity(QPointF(400,300), 12, 3, 3));
        entities.append(new Entity(QPointF(100,100), 7, 3, 3));
    }

    if (synth_get_current_note_for_instrument(4) != 0 &&
        entity4 == 0)
    {
        entity4 = new Entity(QPointF(300,200), 8, 3, 4);
        entities.append(entity4);
        entities.append(new Entity(QPointF(200,400), 12, 3, 4));
    }


    // Draw Entities and Critter    
    painter.setBrush(QBrush());

    // Move entities
    qreal minDistToCritter = 8000;
    static Entity* closestToCritter = 0;
    static int critterEnemyDetectionDelayer = 0;
    for(int i = 0; i < entities.size(); i++)
    {
        Entity *entity = entities[i];
        qreal distToCritter = 10000;

        // Use all entities as local flock for now
        QMutableListIterator<Entity*> localFlock(entities);

        entity->clearSteering();
        if (critter != 0)
        {
            entity->steerToTarget(critter->pos(), STEER_TO_TARGET_STRENGTH);
            distToCritter = entity->steerToAvoindWithinDistance(critter->pos(), STEER_AVOID_WITHIN_DISTANCE_STRENGTH);
        }
        entity->steerWithFlock(localFlock, STEER_SEPARATION_STRENGTH, STEER_COHESION_STRENGTH);
        entity->move();

        if(critterEnemyDetectionDelayer == 0 && distToCritter < minDistToCritter)
        {
            closestToCritter = entity;
            minDistToCritter = distToCritter;
        }
    }

    foreach (Entity *entity, entities)
    {
        entity->drawEntity(&painter);
    }
Exemplo n.º 19
0
void MapIcons::paintSpawnPointIcon(MapParameters& param, 
				   QPainter& p, 
				   const MapIcon& mapIcon,
				   const SpawnPoint* sp, 
				   const QPoint& point)
{
  // Draw Line
  if (mapIcon.showLine0())
  {
    p.setPen(mapIcon.line0Pen());
    p.drawLine(param.playerXOffset(), 
	       param.playerYOffset(),
	       point.x(), point.y());
  }

  // calculate distance and draw distance related lines
  uint32_t distance = UINT32_MAX;
  if (mapIcon.line1Distance() || mapIcon.line2Distance())
  {
    if (!showeq_params->fast_machine)
      distance = sp->calcDist2DInt(param.player());
    else
      distance = (int)sp->calcDist(param.player());
    
    if (mapIcon.line1Distance() > distance)
    {
      p.setPen(mapIcon.line1Pen());
      p.drawLine(param.playerXOffset(), 
		 param.playerYOffset(),
		 point.x(), point.y());
    }

    if (mapIcon.line2Distance() > distance)
    {
      p.setPen(mapIcon.line2Pen());
      p.drawLine(param.playerXOffset(), 
		 param.playerYOffset(),
		 point.x(), point.y());
    }
  }

  // Draw Spawn Names
  if (mapIcon.showName())
  {
    QString spawnNameText;
    
    spawnNameText.sprintf("sp:%s %s (%d)",
			  (const char*)sp->name(),
			  (const char*)sp->last(),
			  sp->count());
    
    QFontMetrics fm(param.font());
    int width = fm.width(spawnNameText);
    p.setPen(gray);
    p.drawText(point.x() - (width / 2),
	       point.y() + fm.height() + 1, spawnNameText);
  }
  
  // Draw the Icon
  if (mapIcon.image() && 
      (!mapIcon.imageFlash() || m_flash) &&
      (mapIcon.imageStyle() != tIconStyleNone))
  {
    if (mapIcon.imageUseSpawnColorPen())
    {
      QPen pen = mapIcon.imagePen();
      pen.setColor(pickSpawnPointColor(sp, pen.color()));
      p.setPen(pen);
    }
    else
      p.setPen(mapIcon.imagePen());

    if (mapIcon.imageUseSpawnColorBrush())
    {
      QBrush brush = mapIcon.imageBrush();
      brush.setColor(pickSpawnPointColor(sp, brush.color()));
      p.setBrush(brush);
    }
    else
      p.setBrush(mapIcon.imageBrush());

    mapIcon.paintIconImage(mapIcon.imageStyle(), p, point, 
			   *m_mapIconSizes[mapIcon.imageSize()],
			   *m_mapIconSizesWH[mapIcon.imageSize()]);
  }

  // Draw the highlight
  if (mapIcon.highlight() && 
      (!mapIcon.highlightFlash() || m_flash) &&
      (mapIcon.highlightStyle() != tIconStyleNone))
  {
    if (mapIcon.highlightUseSpawnColorPen())
    {
      QPen pen = mapIcon.highlightPen();
      pen.setColor(pickSpawnPointColor(sp, pen.color()));
      p.setPen(pen);
    }
    else
      p.setPen(mapIcon.highlightPen());

    if (mapIcon.highlightUseSpawnColorBrush())
    {
      QBrush brush = mapIcon.highlightBrush();
      brush.setColor(pickSpawnPointColor(sp, brush.color()));
      p.setBrush(brush);
    }
    else
      p.setBrush(mapIcon.highlightBrush());

    mapIcon.paintIconImage(mapIcon.highlightStyle(), p, point, 
			   *m_mapIconSizes[mapIcon.highlightSize()],
			   *m_mapIconSizesWH[mapIcon.highlightSize()]);
  }
}
Exemplo n.º 20
0
void TurnAndBank::createGlass(void){
    QImage _glassImage = QImage(QSize(500,500), QImage::Format_ARGB32);
    _glassImage.fill(0x00ffffff);
    
    QPainter p;
    p.setRenderHint(QPainter::Antialiasing, true);
    p.begin(&_glassImage);
    //p.scale(1./2.5, 1./2.5);
    
    
    
    // Cosmetics on glass: yellow arrows:
    p.setPen(QPen(QColor(79, 106, 25), 0, Qt::SolidLine,
                  Qt::FlatCap, Qt::MiterJoin));
    p.setBrush(Qt::SolidPattern);
    p.setBrush(Qt::yellow);
    
    static const QPointF bigArrow[] = {
        QPointF(250, 250),
        QPointF(362.5, 287.5),
        QPointF(137.5, 287.5)
    };
    int bigArrowNPts = sizeof(bigArrow)/sizeof(bigArrow[0]);
    
    p.drawConvexPolygon(bigArrow, bigArrowNPts);
    
    static const QPointF leftArrow[] = {
        QPointF(125, 375-10),
        QPointF(237.5, 320-10),
        QPointF(240, 322.5-10),
        QPointF(137.5, 387.5-10),
        QPointF(125,387.5-10)
    };
    int leftArrowNPts = sizeof(leftArrow)/sizeof(leftArrow[0]);
    p.drawConvexPolygon(leftArrow, leftArrowNPts);
    
    static const QPointF rightArrow[] = {
        QPointF(375, 375-10),
        QPointF(262.5, 320-10),
        QPointF(260, 322.5-10),
        QPointF(362.5,387.5-10),
        QPointF(375,387.5-10)
    };
    p.drawConvexPolygon(rightArrow, leftArrowNPts);
    
    // Upwards facing orange arrow at vertical up:
    
    static const QPointF orangeArrow[] = {
        QPointF(250, 50),
        QPointF(233, 88),
        QPointF(267, 88)
    };
    p.setBrush(QColor(255,116,0));
    p.drawConvexPolygon(orangeArrow, 3);
    
    // Little black pyramid and chord at bottom:
    p.setBrush(QColor(25,25,25));
    static const QPointF pyramid[] = {
        QPointF(250-19-60, 417+20),
        QPointF(250+19+60, 417+20),
        QPointF(250+25, 250+63+20),
        QPointF(250-25, 250+63+20)
    };
    
    p.drawConvexPolygon(pyramid, 4);
    p.setPen(QPen(Qt::black, 0, Qt::SolidLine,
                  Qt::FlatCap, Qt::MiterJoin));
    
    p.setBrush(QColor(76,76,76));
    p.drawChord(_glassImage.rect(), -40*16, -100*16);
    
    p.setBrush(QColor(25,25,25));
    p.drawChord(_glassImage.rect(), -42*16, -96*16);
    
    
    // Little vacuum text line
    p.setPen(QColor(200,200,200));
    p.setFont(QFont(QString("Helvetica"), 24, QFont::Bold, false));
    int width = p.fontMetrics().width(QString("VACUUM"));
    int height =p.fontMetrics().height();
    p.drawText(250-width/2,385,width, height, Qt::AlignCenter,  "VACUUM");
    
    
    
    p.end();    
    
    _glass = QPixmap::fromImage(_glassImage, Qt::AutoColor);
    
}    
Exemplo n.º 21
0
void MapIcons::paintSpawnIcon(MapParameters& param, 
			      QPainter& p, 
			      const MapIcon& mapIcon,
			      const Spawn* spawn, 
			      const EQPoint& location,
			      const QPoint& point)
{
  // ------------------------
  // Draw Walk Path
  if (mapIcon.showWalkPath() ||
      (m_showNPCWalkPaths && spawn->isNPC()))
  {
    SpawnTrackListIterator trackIt(spawn->trackList());
    
    const SpawnTrackPoint* trackPoint = trackIt.current();
    if (trackPoint)
    {
      if (!mapIcon.useWalkPathPen())
	p.setPen(blue);
      else
	p.setPen(mapIcon.walkPathPen());

      p.moveTo (param.calcXOffsetI(trackPoint->x()), 
		param.calcYOffsetI(trackPoint->y()));
      
      while ((trackPoint = ++trackIt) != NULL)
	p.lineTo (param.calcXOffsetI (trackPoint->x()), 
		  param.calcYOffsetI (trackPoint->y()));
      
      p.lineTo (point.x(), point.y());
    }
  }

  // Draw Line
  if (mapIcon.showLine0())
  {
    p.setPen(mapIcon.line0Pen());
    p.drawLine(param.playerXOffset(), 
	       param.playerYOffset(),
	       point.x(), point.y());
  }

  // calculate distance and draw distance related lines
  uint32_t distance = UINT32_MAX;
  if (mapIcon.line1Distance() || mapIcon.line2Distance() || 
      m_showSpawnNames)
  {
    if (!showeq_params->fast_machine)
      distance = location.calcDist2DInt(param.player());
    else
      distance = (int)location.calcDist(param.player());
    
    if (mapIcon.line1Distance() > distance)
    {
      p.setPen(mapIcon.line1Pen());
      p.drawLine(param.playerXOffset(), 
		 param.playerYOffset(),
		 point.x(), point.y());
    }

    if (mapIcon.line2Distance() > distance)
    {
      p.setPen(mapIcon.line2Pen());
      p.drawLine(param.playerXOffset(), 
		 param.playerYOffset(),
		 point.x(), point.y());
    }
  }

  // Draw Spawn Names
  if (mapIcon.showName() || 
      (m_showSpawnNames && (distance < m_fovDistance)))
  {
    QString spawnNameText;
    
    spawnNameText.sprintf("%2d: %s",
			  spawn->level(),
			  (const char*)spawn->name());
    
    QFontMetrics fm(param.font());
    int width = fm.width(spawnNameText);
    p.setPen(gray);
    p.drawText(point.x() - (width / 2),
	       point.y() + fm.height() + 1, spawnNameText);
  }
  
  // Draw the Icon
  if (mapIcon.image() && 
      (!mapIcon.imageFlash() || m_flash) &&
      (mapIcon.imageStyle() != tIconStyleNone))
  {
    if (mapIcon.imageUseSpawnColorPen())
    {
      QPen pen = mapIcon.imagePen();
      pen.setColor(pickSpawnColor(spawn));
      p.setPen(pen);
    }
    else
      p.setPen(mapIcon.imagePen());

    if (mapIcon.imageUseSpawnColorBrush())
    {
      QBrush brush = mapIcon.imageBrush();
      brush.setColor(pickSpawnColor(spawn));
      p.setBrush(brush);
    }
    else
      p.setBrush(mapIcon.imageBrush());

    mapIcon.paintIconImage(mapIcon.imageStyle(), p, point, 
			   *m_mapIconSizes[mapIcon.imageSize()],
			   *m_mapIconSizesWH[mapIcon.imageSize()]);
  }

  // Draw the highlight
  if (mapIcon.highlight() && 
      (!mapIcon.highlightFlash() || m_flash) &&
      (mapIcon.highlightStyle() != tIconStyleNone))
  {
    if (mapIcon.highlightUseSpawnColorPen())
    {
      QPen pen = mapIcon.highlightPen();
      pen.setColor(pickSpawnColor(spawn));
      p.setPen(pen);
    }
    else
      p.setPen(mapIcon.highlightPen());

    if (mapIcon.highlightUseSpawnColorBrush())
    {
      QBrush brush = mapIcon.highlightBrush();
      brush.setColor(pickSpawnColor(spawn));
      p.setBrush(brush);
    }
    else
      p.setBrush(mapIcon.highlightBrush());

    mapIcon.paintIconImage(mapIcon.highlightStyle(), p, point, 
			   *m_mapIconSizes[mapIcon.highlightSize()],
			   *m_mapIconSizesWH[mapIcon.highlightSize()]);
  }
}
Exemplo n.º 22
0
void TurnAndBank::createFrame(void){
    
    QImage _frameImage = QImage(QSize(600,600), QImage::Format_ARGB32);
    _frameImage.fill(0x00ff0000);
    
    
    int outerR = _frameImage.width()/2;
    const int innerR = _frameImage.width()/2-60;
    
    QPainter p;
    p.setRenderHint(QPainter::Antialiasing, true);
    p.begin(&_frameImage);
    p.translate(300, 300);

    p.setPen(Qt::NoPen);
    p.setBrush(Qt::SolidPattern);
    p.setBrush(QColor(225,225,225));

    QRadialGradient gradient(0, 0, outerR, 0, 0);
    gradient.setSpread(QGradient::ReflectSpread);
    gradient.setColorAt(0, Qt::white);
    gradient.setColorAt(1, Qt::black);
    QBrush gbrush(gradient); 
    p.setBrush(gbrush);           
    p.drawChord(-outerR, -outerR, 2*outerR, 2*outerR, 0, 360*16);

    //Ring outside of intstrument with white line:
    if (0){
        p.setPen(QPen(QColor(225,225,225), 2, Qt::SolidLine,
                      Qt::FlatCap, Qt::MiterJoin));
        p.setBrush(Qt::NoBrush);
        p.drawChord(-outerR, -outerR, 2*outerR, 2*outerR, 0, 360*16);
    }
    
    // Create black inner core:
    p.setBrush(Qt::black);
    p.setPen(Qt::NoPen);
    p.drawChord(-innerR, -innerR, 2*innerR, 2*innerR, 0, 360*16);

    
    // Put horizontal and 2minute lines on outside:
    p.setPen(QPen(Qt::white, 7, Qt::SolidLine,
                  Qt::FlatCap, Qt::MiterJoin));
    
    const float angle = 15.;
    
    outerR = outerR-20;
    p.drawLine(innerR*cos(angle/180*3.1415926), innerR*sin(angle/180*3.1415926), 
               outerR*cos(angle/180*3.1415926), outerR*sin(angle/180*3.1415926));
    p.drawLine(-innerR*cos(angle/180*3.1415926), innerR*sin(angle/180*3.1415926), 
               -outerR*cos(angle/180*3.1415926), outerR*sin(angle/180*3.1415926));
               
    p.drawLine(innerR, 0, outerR, 0);
    p.drawLine(-innerR, 0, -outerR, 0);
    
    // Little vacuum text line
    p.setPen(QColor(200,200,200));
    
    QString legend = QString("NO PITCH");
    p.setFont(QFont(QString("Helvetica"), 20, QFont::Bold, false));
    int width = p.fontMetrics().width(legend);
    int height =p.fontMetrics().height();
    p.drawText(0-width/2,245,width, height, Qt::AlignCenter, legend);
    legend = QString("INFORMATION");
    width = p.fontMetrics().width(legend);
    p.drawText(0-width/2,267,width, height, Qt::AlignCenter, legend);

    p.setFont(QFont(QString("Helvetica"), 32, QFont::Bold, false));
    legend = QString("D. C. ELEC.");
    width = p.fontMetrics().width(legend);
    height =p.fontMetrics().height();
    p.drawText(0-width/2,-275,width, height, Qt::AlignCenter, legend);
    
    legend = QString("2 MIN");
    width = p.fontMetrics().width(legend);
    height =p.fontMetrics().height();
    p.drawText(0-width/2,205,width, height, Qt::AlignCenter, legend);
    
    p.setFont(QFont(QString("Helvetica"), 24, QFont::Bold, false));
    legend = QString("TURN COORDINATOR");
    width = p.fontMetrics().width(legend);
    height =p.fontMetrics().height();
    p.drawText(0-width/2,-150,width, height, Qt::AlignCenter, legend);
    
    p.setFont(QFont(QString("Helvetica"), 48, QFont::Bold, false));
    legend = QString("L");
    width = p.fontMetrics().width(legend);
    height =p.fontMetrics().height();
    p.drawText(-265*cos(18./180.*3.1415926)-width/2+5, 265*sin(18./180.*3.1415926),
               width, height, Qt::AlignCenter, legend);
    
    legend = QString("R");
    width = p.fontMetrics().width(legend);
    height =p.fontMetrics().height();
    p.drawText(265*cos(18./180.*3.1415926)-width/2-5, 265*sin(18./180.*3.1415926),
               width, height, Qt::AlignCenter, legend);
    
    p.end();    
    
    _frame = QPixmap::fromImage(_frameImage, Qt::AutoColor);
    
}
Exemplo n.º 23
0
void HeatmapDisplay::drawVarNames(){
    //qDebug()<<"drawVarNames";
    double height = floor(CANVAS_BORD/(2*CANVAS_BORD+1)*this->height());
    double width =  this->width();

    RddtClust* currentClust = NULL;
    if(this->m_dimClust==NULL)
        return;
    currentClust = this->m_dimClust->m_currentSelection;
    if(currentClust == NULL)
        return;
    int r = 0;
    r= currentClust->m_selected.size();
    if(r!= currentClust->m_order.size())
        return;
    if(r<=0)
        return;
    int start_x = 10+(CANVAS_BORD/(1+2*CANVAS_BORD)*width)/sqrt(2.0); //CANVAS_BORD*width;//move right
    int start_y = 10-(CANVAS_BORD/(1+2*CANVAS_BORD)*width)/sqrt(2.0); //CANVAS_BORD*width;//move up
    double offset = (double)width*(((double)1)/(1+2*CANVAS_BORD))/((double)r*sqrt(2.0));

    QImage img(width,height,QImage::Format_ARGB32);
    QPainter p;
    p.begin(&img);
    p.setRenderHint(QPainter::Antialiasing);
    p.fillRect(rect(),Qt::white);
    //p.setBrush(Qt::red);
    //p.drawRect(rect());
    p.setBrush(Qt::black);
    p.save();
    p.translate(0,0);
    p.rotate(45);
    QFont f;
    f.setFamily("Arial");
    f.setPointSize(8);
    //QFont font("Times",5,QFont::Normal);
    //font.setPixelSize();
    //p.setFont(font);
    f.setStyleStrategy(QFont::PreferAntialias);
    p.setFont(f);
    for(int i = 0; i<r; i++){
        int x = (int)(start_x+offset*(double)i);
        int y = (int)(start_y-offset*(double)i);
        int locIdx = currentClust->m_order[i];
        int globIdx = currentClust->m_selected[locIdx];
        bool selected = currentClust->m_colSelected[i];
        std::string name = this->m_dimClust->m_dimName[globIdx];
        QString qname = QString::fromAscii(name.c_str());

        if(selected){
            p.setPen(Qt::red);
            p.drawText(x,y,qname);
        }else{
            p.setPen(Qt::black);
            p.drawText(x,y,qname);
        }
    }

    p.restore();
    p.end();

    QImage gldata = QGLWidget::convertToGLFormat(img);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glTranslated(CANVAS_BORD,0,0);
    glDepthMask(0); //before glDrawPixels().
    glDrawPixels(img.width(), img.height(), GL_RGBA, GL_UNSIGNED_BYTE, gldata.bits());
    glDepthMask(1); //Restore
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
}
Exemplo n.º 24
0
void FormulaCursor::paint( QPainter& painter ) const
{
    kDebug() << "Drawing cursor with selecting: "<< isSelecting() << " from "
    << mark()<<" to " << position() << " in "<<ElementFactory::elementName(m_currentElement->elementType());
    if( !m_currentElement )
        return;
    painter.save();
    QPointF origin=m_currentElement->absoluteBoundingRect().topLeft();
    qreal baseline=m_currentElement->baseLine();
    QPen pen;
    pen.setWidthF( 0.5 );
    pen.setColor(Qt::black);
    painter.setPen( pen );
    painter.drawLine(m_currentElement->cursorLine( m_position ));
    pen.setWidth( 0.1);
    pen.setColor(Qt::blue);
    pen.setStyle(Qt::DashLine);
    painter.setPen( pen );
    painter.drawLine( origin+QPointF(0.0,baseline),origin+QPointF(m_currentElement->width(), baseline) );
    pen.setStyle(Qt::DotLine);
    //Only here for debug purpose for now
    switch(m_currentElement->elementType()) {
    case Number:
        pen.setColor(Qt::red);
        break;
    case Identifier:
        pen.setColor(Qt::darkRed);
        break;
    case Row:
        pen.setColor(Qt::yellow);
        break;
    case Fraction:
        pen.setColor(Qt::blue);
        break;
    case Table:
        pen.setColor(Qt::darkGreen);
        break;
    case TableRow:
        pen.setColor(Qt::green);
        break;
    default:
        pen.setColor(Qt::darkGray);
        break;
    }
    painter.setPen(pen);
    painter.drawRect( m_currentElement->absoluteBoundingRect() );
    //draw the selection rectangle
    if ( m_selecting ) {
        QBrush brush;
        QColor color(Qt::blue);
        color.setAlpha(128);
        brush.setColor(color);
        brush.setStyle(Qt::SolidPattern);
        painter.setBrush(brush);
        painter.setPen(Qt::NoPen);
        int p1=position()<mark()? position() : mark();
        int p2=position()<mark()? mark() : position() ;
        painter.drawPath(m_currentElement->selectionRegion(p1,p2));
    }
    painter.restore();
}
void  TernaryPointDiagram::paint (PaintContext *paintContext)
{
    d->reverseMapper.clear();

    d->paint( paintContext );

    // sanity checks:
    if ( model() == 0 ) return;

    QPainter* p = paintContext->painter();
    PainterSaver s( p );

    TernaryCoordinatePlane* plane =
        static_cast< TernaryCoordinatePlane* >( paintContext->coordinatePlane() );
    Q_ASSERT( plane );

    qreal x, y, z;


    // for some reason(?) TernaryPointDiagram is using per-diagram DVAs only:
    const DataValueAttributes attrs( dataValueAttributes() );

    d->forgetAlreadyPaintedDataValues();

    int columnCount = model()->columnCount( rootIndex() );
    for (int column=0; column<columnCount; column+=datasetDimension() )
    {
        int numrows = model()->rowCount( rootIndex() );
        for ( int row = 0; row < numrows; row++ )
        {
            QModelIndex base = model()->index( row, column, rootIndex() ); // checked
            // see if there is data otherwise skip
            if ( ! model()->data( base ).isNull() )
            {
                p->setPen( PrintingParameters::scalePen( pen( base ) ) );
                p->setBrush( brush( base ) );

                // retrieve data
                x = qMax( model()->data( model()->index( row, column+0, rootIndex() ) ).toReal(), // checked
                          0.0 );
                y = qMax( model()->data( model()->index( row, column+1, rootIndex() ) ).toReal(), // checked
                          0.0 );
                z = qMax( model()->data( model()->index( row, column+2, rootIndex() ) ).toReal(), // checked
                          0.0 );

                // fix messed up data values (paint as much as possible)
                qreal total = x + y + z;
                if ( fabs( total ) > 3 * std::numeric_limits<qreal>::epsilon() ) {
                    TernaryPoint tPunkt( x / total, y / total );
                    QPointF diagramLocation = translate( tPunkt );
                    QPointF widgetLocation = plane->translate( diagramLocation );

                    paintMarker( p, model()->index( row, column, rootIndex() ), widgetLocation ); // checked
                    QString text = tr( "(%1, %2, %3)" )
                                   .arg( x * 100, 0, 'f', 0 )
                                   .arg( y * 100, 0, 'f', 0 )
                                   .arg( z * 100, 0, 'f', 0 );
                    d->paintDataValueText( p, attrs, widgetLocation, true, text, true );
                } else {
                    // ignore and do not paint this point, garbage data
                    qDebug() << "TernaryPointDiagram::paint: data point x/y/z:"
                             << x << "/" << y << "/" << z << "ignored, unusable.";
                }
            }
        }
    }
}
Exemplo n.º 26
0
void ContactListEdit::addContactEntry(const QString& contactText, const bts::addressbook::contact& c)
  {
  QFont        default_font;
  default_font.setPointSize( default_font.pointSize() - 1 );
  QFontMetrics font_metrics(default_font);
  QRect        bounding = font_metrics.boundingRect(contactText);
  int          completion_width = font_metrics.width(contactText);
  int          completion_height = bounding.height();

  completion_width += 20;

  QImage   completion_image(completion_width, completion_height + 4, QImage::Format_ARGB32);
  completion_image.fill(QColor(0, 0, 0, 0) );
  QPainter painter;
  painter.begin(&completion_image);
  painter.setFont(default_font);
  painter.setRenderHint(QPainter::Antialiasing);

  QBrush brush(Qt::SolidPattern);
  brush.setColor( QColor( 205, 220, 241 ) );
  QPen  pen;

  bool isKeyhoteeFounder = Contact::isKeyhoteeFounder(c);

  if (isKeyhoteeFounder)
    {
    QLinearGradient grad(QPointF(0, 0), QPointF(0, 1));
    grad.setCoordinateMode(QGradient::ObjectBoundingMode);
    grad.setColorAt(0, QColor(35, 40, 3));
    grad.setColorAt(0.102273, QColor(136, 106, 22));
    grad.setColorAt(0.225, QColor(166, 140, 41));
    grad.setColorAt(0.285, QColor(204, 181, 74));
    grad.setColorAt(0.345, QColor(235, 219, 102));
    grad.setColorAt(0.415, QColor(245, 236, 112));
    grad.setColorAt(0.52, QColor(209, 190, 76));
    grad.setColorAt(0.57, QColor(187, 156, 51));
    grad.setColorAt(0.635, QColor(168, 142, 42));
    grad.setColorAt(0.695, QColor(202, 174, 68));
    grad.setColorAt(0.75, QColor(218, 202, 86));
    grad.setColorAt(0.815, QColor(208, 187, 73));
    grad.setColorAt(0.88, QColor(187, 156, 51));
    grad.setColorAt(0.935, QColor(137, 108, 26));
    grad.setColorAt(1, QColor(35, 40, 3));

    brush = QBrush(grad);
    pen.setColor( QColor( 103, 51, 1 ) );
    }
  else
    {
    brush.setColor( QColor( 205, 220, 241 ) );
    pen.setColor( QColor( 105,110,180 ) );
    }

  painter.setBrush(brush);
  painter.setPen(pen);
  painter.drawRoundedRect(0, 0, completion_width - 1, completion_image.height() - 1, 8, 8,
    Qt::AbsoluteSize);
  painter.setPen(QPen());
  painter.drawText(QPoint(10, completion_height - 2), contactText);

  QTextDocument* doc = document();
  doc->addResource(QTextDocument::ImageResource, QUrl(contactText), completion_image);
  QTextImageFormat format;
  format.setName(contactText);

  encodePublicKey(c.public_key, &format);

  QTextCursor txtCursor = textCursor();
  txtCursor.insertImage(format);

  txtCursor.insertText(" ");
  setTextCursor(txtCursor);
  }
Exemplo n.º 27
0
void Plot2D::drawFrame(QPainter &dc)
{
  LocalPainter p(dc);

  dc.setBrush(QColor(0xFFFFFF));

  dc.drawRect(dm_offset.x(), dm_offset.y(), dm_area.width(), dm_area.height());

  int x, y, i, ticknum;
  int last_font;
  double axis_min, axis_max, tick_spacing;

  // draw x axis
  last_font = -1;
  ticknum = calcTickMarks(dm_view_xmin, dm_view_xmax, axis_min, axis_max, tick_spacing);
  for (i=0; i<=ticknum; ++i) {
    x = xToPixel(axis_min + i*tick_spacing);
    if (x == -1)
      continue;
    y = dm_offset.y()+dm_area.height();
    dc.drawLine(x, y, x, y+6);

    QString label;
    QTextStream s(&label);
    s << handleXLabel(axis_min + i*tick_spacing);
    QSize ext = QFontMetrics(dc.font()).size(Qt::TextSingleLine, label);

    if (last_font == -1 || x-ext.width()/2 > last_font) {
      dc.drawLine(x, y, x, y+12);   // draw a longer line
      dc.drawText(x-ext.width()/2, y+12+ext.height(), label);
      last_font = x+ext.width()/2;
      last_font += 10;  // add some buffer space
    }
  }

  // draw y axis
  last_font = -1;
  ticknum = calcTickMarks(dm_view_ymin, dm_view_ymax, axis_min, axis_max, tick_spacing);
  for (i=0; i<=ticknum; ++i) {
    y = yToPixel(axis_min + i*tick_spacing);
    if (y == -1)
      continue;
    x = dm_offset.x();
    dc.drawLine(x, y, x-4, y);

    QString label;
    QTextStream s(&label);
    s << handleYLabel(axis_min + i*tick_spacing);
    QSize ext = QFontMetrics(dc.font()).size(Qt::TextSingleLine, label);

    if (last_font == -1 || y+ext.height()/2 < last_font) {
      dc.drawLine(x, y, x-10, y);   //draw a longer line
      dc.drawText(x-10-4-ext.width(), y+ext.height()/2-4, label);
      last_font = y+ext.height()/2;
      last_font -= 20;  // add some buffer space
    }
  }

  if (!dm_title.isEmpty()) {
    QSize ext = QFontMetrics(dc.font()).size(Qt::TextSingleLine, dm_title);
    dc.drawText((dc.device()->width()-ext.width())/2, 10, dm_title);
  }
  if (!dm_xlabel.isEmpty()) {
    QSize ext = QFontMetrics(dc.font()).size(Qt::TextSingleLine, dm_xlabel);
    //dc.DrawRotatedText(dm_xlabel, (dm_area.width()-ext.width())/2+dm_offset.x(), dc.device()->height()-20, 0);
    dc.drawText((dm_area.width()-ext.width())/2+dm_offset.x(), dc.device()->height(), dm_xlabel);
  }
  if (!dm_ylabel.isEmpty()) {
    QSize ext = QFontMetrics(dc.font()).size(Qt::TextSingleLine, dm_ylabel);

    LocalPainter rotatedcontext(dc);    // cuz we'redoing a rotate

    dc.translate(4+ext.height(), dm_offset.y()+dm_area.height()-(dm_area.height()-ext.width())/2);
    dc.rotate(-90);

    //dc.DrawRotatedText(dm_ylabel, 4, dm_offset.y()+dm_area.height()-(dm_area.height()-ext.width())/2, 90);
    //dc.drawText(4, dm_offset.y()+dm_area.height()-(dm_area.height()-ext.width())/2, dm_ylabel);
    dc.drawText(0, 0, dm_ylabel);
  }
}
Exemplo n.º 28
0
void ArthurFrame::paintEvent(QPaintEvent *e)
{
    static QImage *static_image = 0;
    QPainter painter;
    if (preferImage()
#ifdef QT_OPENGL_SUPPORT
        && !m_use_opengl
#endif
        ) {
        if (!static_image || static_image->size() != size()) {
            delete static_image;
            static_image = new QImage(size(), QImage::Format_RGB32);
        }
        painter.begin(static_image);

        int o = 10;

        QBrush bg = palette().brush(QPalette::Background);
        painter.fillRect(0, 0, o, o, bg);
        painter.fillRect(width() - o, 0, o, o, bg);
        painter.fillRect(0, height() - o, o, o, bg);
        painter.fillRect(width() - o, height() - o, o, o, bg);
    } else {
#ifdef QT_OPENGL_SUPPORT
        if (m_use_opengl) {
            painter.begin(glw);
            painter.fillRect(QRectF(0, 0, glw->width(), glw->height()), palette().color(backgroundRole()));
        } else {
            painter.begin(this);
        }
#else
        painter.begin(this);
#endif
    }

    painter.setClipRect(e->rect());

    painter.setRenderHint(QPainter::Antialiasing);

    QPainterPath clipPath;

    QRect r = rect();
    qreal left = r.x() + 1;
    qreal top = r.y() + 1;
    qreal right = r.right();
    qreal bottom = r.bottom();
    qreal radius2 = 8 * 2;

    clipPath.moveTo(right - radius2, top);
    clipPath.arcTo(right - radius2, top, radius2, radius2, 90, -90);
    clipPath.arcTo(right - radius2, bottom - radius2, radius2, radius2, 0, -90);
    clipPath.arcTo(left, bottom - radius2, radius2, radius2, 270, -90);
    clipPath.arcTo(left, top, radius2, radius2, 180, -90);
    clipPath.closeSubpath();

    painter.save();
    painter.setClipPath(clipPath, Qt::IntersectClip);

    painter.drawTiledPixmap(rect(), m_tile);

    // client painting

    paint(&painter);

    painter.restore();

    painter.save();
    if (m_show_doc)
        paintDescription(&painter);
    painter.restore();

    int level = 180;
    painter.setPen(QPen(QColor(level, level, level), 2));
    painter.setBrush(Qt::NoBrush);
    painter.drawPath(clipPath);

    if (preferImage()
#ifdef QT_OPENGL_SUPPORT
        && !m_use_opengl
#endif
        ) {
        painter.end();
        painter.begin(this);
        painter.drawImage(e->rect(), *static_image, e->rect());
    }

#ifdef QT_OPENGL_SUPPORT
    if (m_use_opengl && (inherits("PathDeformRenderer") || inherits("PathStrokeRenderer") || inherits("CompositionRenderer") || m_show_doc))
        glw->swapBuffers();
#endif
}
Exemplo n.º 29
0
void QgsColorButton::setButtonBackground( const QColor &color )
{
  QColor backgroundColor = color;
  bool isProjectColor = false;
  if ( !backgroundColor.isValid() && !mLinkedColorName.isEmpty() )
  {
    backgroundColor = linkedProjectColor();
    isProjectColor = backgroundColor.isValid();
    if ( !isProjectColor )
    {
      mLinkedColorName.clear(); //color has been deleted, renamed, etc...
      emit unlinked();
    }
  }
  if ( !backgroundColor.isValid() )
  {
    backgroundColor = mColor;
  }

  QSize currentIconSize;
  //icon size is button size with a small margin
  if ( menu() )
  {
    if ( !mIconSize.isValid() )
    {
      //calculate size of push button part of widget (ie, without the menu drop-down button part)
      QStyleOptionToolButton opt;
      initStyleOption( &opt );
      QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
                         this );
      //make sure height of icon looks good under different platforms
#ifdef Q_OS_WIN
      mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
#else
      mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
#endif
    }
    currentIconSize = mIconSize;
  }
  else
  {
    //no menu
#ifdef Q_OS_WIN
    currentIconSize = QSize( width() - 10, height() - 6 );
#else
    currentIconSize = QSize( width() - 10, height() - 12 );
#endif
  }

  if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
  {
    return;
  }

  //create an icon pixmap
  QPixmap pixmap( currentIconSize );
  pixmap.fill( Qt::transparent );

  if ( backgroundColor.isValid() )
  {
    QRect rect( 0, 0, currentIconSize.width(), currentIconSize.height() );
    QPainter p;
    p.begin( &pixmap );
    p.setRenderHint( QPainter::Antialiasing );
    p.setPen( Qt::NoPen );
    if ( mAllowOpacity && backgroundColor.alpha() < 255 )
    {
      //start with checkboard pattern
      QBrush checkBrush = QBrush( transparentBackground() );
      p.setBrush( checkBrush );
      p.drawRoundedRect( rect, 3, 3 );
    }

    //draw semi-transparent color on top
    p.setBrush( backgroundColor );
    p.drawRoundedRect( rect, 3, 3 );
    p.end();
  }

  setIconSize( currentIconSize );
  setIcon( pixmap );
}
Exemplo n.º 30
0
void PinItem::drawShape( QPainter& p )
{
	if (!m_pinSettings)
		return;
	
	if ( m_pinSettings->state() == PinSettings::ps_on )
	{
		if ( m_pinSettings->type() == PinSettings::pt_output )
			setBrush( QColor( 255, 127, 127 ) );
		else
			setBrush( QColor( 255, 191, 191 ) );
	}
	else
		setBrush( Qt::white );
	
	p.drawRect(rect());
	
	p.setFont(m_font);
	p.setBrush( Qt::NoBrush );
	QRect r = m_textRect;
	if ( onLeft )
		p.drawText( r, Qt::AlignLeft, m_pinSettings->id() );
	else
		p.drawText( r, Qt::AlignRight, m_pinSettings->id() );
	QRect br = p.boundingRect( r, Qt::AlignLeft, m_pinSettings->id() );
	
	int left;
	int right;
	if ( onLeft )
	{
		right = (int)x();
		left = right - 8;
	}
	else
	{
		left = (int)x() + PinLength;
		right = left + 8;
	}
	
	int midY = (int)y() + PinWidth/2;
	Q3PointArray pa(3);
	int midLeft = left + (8-PinDirArrow)/2;
	int midRight = left + (8+PinDirArrow)/2;
	
	if ( onLeft )
	{
		midLeft--;
		midRight--;
	}
	else
	{
		midLeft++;
		midRight++;
	}
	
	p.setBrush( Qt::black );
	
	// Right facing arrow
	if ( (m_pinSettings->type() == PinSettings::pt_input && onLeft) ||
			 (m_pinSettings->type() == PinSettings::pt_output && !onLeft) )
	{
		pa[0] = QPoint( midRight, midY );
		pa[1] = QPoint( midLeft, midY - PinDirArrow );
		pa[2] = QPoint( midLeft, midY + PinDirArrow );
		p.drawPolygon(pa);
		p.drawLine ( left, midY, right, midY );
	}
	else // Left facing arrow
	{
		pa[0] = QPoint( midLeft, midY );
		pa[1] = QPoint( midRight, midY - PinDirArrow );
		pa[2] = QPoint( midRight, midY + PinDirArrow );
		p.drawPolygon(pa);
		p.drawLine ( left, midY, right, midY );
	}
}