Ejemplo n.º 1
0
QGradientStops
GradientEditor::gradientStops()
{
  QGradientStops gradStops;

  for(int i=0; i<m_points.size(); i++)
    {
      float pos, r,g,b,a;
      QPointF pt;
      pt = m_points[i];
      
      pos = pt.x();
      
      a = 255*(1-pt.y());
      r = m_colors[i].red();
      g = m_colors[i].green();
      b = m_colors[i].blue();

      gradStops << QGradientStop(pos, QColor(r,g,b,a));
    }

  return gradStops;
}
Ejemplo n.º 2
0
//! [1]
void LayoutItem::paint(QPainter *painter,
    const QStyleOptionGraphicsItem *option, QWidget *widget /*= 0*/)
{
    Q_UNUSED(widget);
    Q_UNUSED(option);

    QRectF frame(QPointF(0,0), geometry().size());
    qreal w = m_pix->width();
    qreal h = m_pix->height();
    QGradientStops stops;
//! [1]

//! [2]
    // paint a background rect (with gradient)
    QLinearGradient gradient(frame.topLeft(), frame.topLeft() + QPointF(200,200));
    stops << QGradientStop(0.0, QColor(60, 60,  60));
    stops << QGradientStop(frame.height()/2/frame.height(), QColor(102, 176, 54));

    //stops << QGradientStop(((frame.height() + h)/2 )/frame.height(), QColor(157, 195,  55));
    stops << QGradientStop(1.0, QColor(215, 215, 215));
    gradient.setStops(stops);
    painter->setBrush(QBrush(gradient));
    painter->drawRoundedRect(frame, 10.0, 10.0);

    // paint a rect around the pixmap (with gradient)
    QPointF pixpos = frame.center() - (QPointF(w, h)/2);
    QRectF innerFrame(pixpos, QSizeF(w, h));
    innerFrame.adjust(-4, -4, +4, +4);
    gradient.setStart(innerFrame.topLeft());
    gradient.setFinalStop(innerFrame.bottomRight());
    stops.clear();
    stops << QGradientStop(0.0, QColor(215, 255, 200));
    stops << QGradientStop(0.5, QColor(102, 176, 54));
    stops << QGradientStop(1.0, QColor(0, 0,  0));
    gradient.setStops(stops);
    painter->setBrush(QBrush(gradient));
    painter->drawRoundedRect(innerFrame, 10.0, 10.0);
    painter->drawPixmap(pixpos, *m_pix);
}
Ejemplo n.º 3
0
void GradientWidget::setDefault(int config)
{
    QGradientStops stops;
    QPolygonF points;
    switch (config) {
    case 1:
        stops << QGradientStop(0.00, QColor::fromRgba(0));
        stops << QGradientStop(0.04, QColor::fromRgba(0xff131360));
        stops << QGradientStop(0.08, QColor::fromRgba(0xff202ccc));
        stops << QGradientStop(0.42, QColor::fromRgba(0xff93d3f9));
        stops << QGradientStop(0.51, QColor::fromRgba(0xffb3e6ff));
        stops << QGradientStop(0.73, QColor::fromRgba(0xffffffec));
        stops << QGradientStop(0.92, QColor::fromRgba(0xff5353d9));
        stops << QGradientStop(0.96, QColor::fromRgba(0xff262666));
        stops << QGradientStop(1.00, QColor::fromRgba(0));
        m_linearButton->animateClick();
        m_repeatSpreadButton->animateClick();
        break;

    case 2:
        stops << QGradientStop(0.00, QColor::fromRgba(0xffffffff));
        stops << QGradientStop(0.11, QColor::fromRgba(0xfff9ffa0));
        stops << QGradientStop(0.13, QColor::fromRgba(0xfff9ff99));
        stops << QGradientStop(0.14, QColor::fromRgba(0xfff3ff86));
        stops << QGradientStop(0.49, QColor::fromRgba(0xff93b353));
        stops << QGradientStop(0.87, QColor::fromRgba(0xff264619));
        stops << QGradientStop(0.96, QColor::fromRgba(0xff0c1306));
        stops << QGradientStop(1.00, QColor::fromRgba(0));
        m_radialButton->animateClick();
        m_padSpreadButton->animateClick();
        break;

    case 3:
        stops << QGradientStop(0.00, QColor::fromRgba(0));
        stops << QGradientStop(0.10, QColor::fromRgba(0xffe0cc73));
        stops << QGradientStop(0.17, QColor::fromRgba(0xffc6a006));
        stops << QGradientStop(0.46, QColor::fromRgba(0xff600659));
        stops << QGradientStop(0.72, QColor::fromRgba(0xff0680ac));
        stops << QGradientStop(0.92, QColor::fromRgba(0xffb9d9e6));
        stops << QGradientStop(1.00, QColor::fromRgba(0));
        m_conicalButton->animateClick();
        m_padSpreadButton->animateClick();
        break;

    case 4:
        stops << QGradientStop(0.00, QColor::fromRgba(0xff000000));
        stops << QGradientStop(1.00, QColor::fromRgba(0xffffffff));
        break;

    default:
        qWarning("bad default: %d\n", config);
        break;
    }

    QPolygonF pts;
    int h_off = m_renderer->width() / 10;
    int v_off = m_renderer->height() / 8;
    pts << QPointF(m_renderer->width() / 2, m_renderer->height() / 2)
        << QPointF(m_renderer->width() / 2 - h_off, m_renderer->height() / 2 - v_off);

    m_editor->setGradientStops(stops);
    m_renderer->hoverPoints()->setPoints(pts);
    m_renderer->setGradientStops(stops);
}
Ejemplo n.º 4
0
void
TagColorEditor::askGradientChoice()
{
  QString homePath = QDir::homePath();
  QFileInfo sfi(homePath, ".drishtigradients.xml");
  QString stopsflnm = sfi.absoluteFilePath();
  if (!sfi.exists())
    copyGradientFile(stopsflnm);

  QDomDocument document;
  QFile f(stopsflnm);
  if (f.open(QIODevice::ReadOnly))
    {
      document.setContent(&f);
      f.close();
    }

  QStringList glist;

  QDomElement main = document.documentElement();
  QDomNodeList dlist = main.childNodes();
  for(int i=0; i<dlist.count(); i++)
    {
      if (dlist.at(i).nodeName() == "gradient")
	{
	  QDomNodeList cnode = dlist.at(i).childNodes();
	  for(int j=0; j<cnode.count(); j++)
	    {
	      QDomElement dnode = cnode.at(j).toElement();
	      if (dnode.nodeName() == "name")
		glist << dnode.text();
	    }
	}
    }

  bool ok;
  QString gstr = QInputDialog::getItem(0,
				       "Color Gradient",
				       "Color Gradient",
				       glist, 0, false,
				       &ok);
  if (!ok)
    return;

  int cno = -1;
  for(int i=0; i<dlist.count(); i++)
    {
      if (dlist.at(i).nodeName() == "gradient")
	{
	  QDomNodeList cnode = dlist.at(i).childNodes();
	  for(int j=0; j<cnode.count(); j++)
	    {
	      QDomElement dnode = cnode.at(j).toElement();
	      if (dnode.tagName() == "name" && dnode.text() == gstr)
		{
		  cno = i;
		  break;
		}
	    }
	}
    }
	
  if (cno < 0)
    return;

  QGradientStops stops;
  QDomNodeList cnode = dlist.at(cno).childNodes();
  for(int j=0; j<cnode.count(); j++)
    {
      QDomElement de = cnode.at(j).toElement();
      if (de.tagName() == "gradientstops")
	{
	  QString str = de.text();
	  QStringList strlist = str.split(" ", QString::SkipEmptyParts);
	  for(int j=0; j<strlist.count()/5; j++)
	    {
	      float pos, r,g,b,a;
	      pos = strlist[5*j].toFloat();
	      r = strlist[5*j+1].toInt();
	      g = strlist[5*j+2].toInt();
	      b = strlist[5*j+3].toInt();
	      a = strlist[5*j+4].toInt();
	      stops << QGradientStop(pos, QColor(r,g,b,a));
	    }
	}
    }

  int mapSize = QInputDialog::getInt(0,
				     "Number of Colors",
				     "Number of Colors",
				     50, 2, 255, 1, &ok);
  if (!ok)
    mapSize = 50;

  QGradientStops gstops;
  gstops = StaticFunctions::resampleGradientStops(stops, mapSize);

  uchar *colors = Global::tagColors();  
  for(int i=0; i<gstops.size(); i++)
    {
      float pos = gstops[i].first;
      QColor color = gstops[i].second;
      int r = color.red();
      int g = color.green();
      int b = color.blue();
      colors[4*i+0] = r;
      colors[4*i+1] = g;
      colors[4*i+2] = b;
    }
  
  setColors();
}
void VesselConnectionView::paint(QPainter *painter,
                                 const QStyleOptionGraphicsItem *option,
                                 QWidget *widget)
{
	Q_UNUSED(widget);

	double lod = option->levelOfDetailFromTransform(painter->transform());
	if (lod < minLOD())
		return;

	QColor fill_color = baseColor(option);
	QColor dark_fill_color = fill_color.dark();

	QGradientStops stops;
	stops << QGradientStop(0.038, dark_fill_color)
	      << QGradientStop(0.128, fill_color)
	      << QGradientStop(0.174, fill_color)
	      << QGradientStop(0.174+0.125-0.03, dark_fill_color)
	      << QGradientStop(0.45, fill_color)
	      << QGradientStop(0.55, fill_color)

	      << QGradientStop(1-(0.174+0.125-0.03), dark_fill_color)
	      << QGradientStop(1-0.174, fill_color)
	      << QGradientStop(1-0.128, fill_color)
	      << QGradientStop(1-0.038, dark_fill_color);
	const QRectF &br = boundingRect();
	QLinearGradient gradient(QLineF(br.topLeft(), br.topRight()).pointAt(0.5),
	                         QLineF(br.bottomRight(), br.bottomLeft()).pointAt(0.5));
	gradient.setStops(stops);

	QLinearGradient gradient2(QLineF(br.topLeft(), br.bottomLeft()).pointAt(0.5),
	                          QLineF(br.topRight(), br.bottomRight()).pointAt(0.5));
	QColor transparent_color(fill_color), semi_transparent_color(fill_color);
	transparent_color.setAlpha(0);
	semi_transparent_color.setAlpha(200);

	gradient2.setStops(QGradientStops()
	                   << QGradientStop(0, transparent_color)
	                   << QGradientStop(0.45, semi_transparent_color)
	                   << QGradientStop(0.55, semi_transparent_color)
	                   << QGradientStop(1, transparent_color));

	painter->setPen(QPen(penColor(option), 32/2, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin));
	painter->drawPath(path);

	if (isClearBg()) {
		painter->fillPath(fill, Qt::white);
	}
	else {
		painter->fillPath(fill, gradient);
		painter->fillPath(fill, gradient2);
	}
}
Ejemplo n.º 6
0
QGradientStops
SplineInformation::interpolateGradientStops(QGradientStops stops1,
					    QGradientStops stops2,
					    float frc)
{
  QVector<float> pos; 

  for(int i=0; i<stops1.size(); i++)
    pos.append(stops1[i].first);

  for(int i=0; i<stops2.size(); i++)
    {
      float pos2 = stops2[i].first;
      bool flag = true;
      for(int j=0; j<stops1.size(); j++)
	{
	  if (fabs(pos[j] - pos2) < 0.0001)
	    {
	      flag = false;
	      break;
	    }
	}
      if (flag)
	pos.append(pos2);
    }

  qSort(pos.begin(), pos.end());

  QGradientStops gradStops1 = StaticFunctions::resampleGradientStops(stops1);
  QGradientStops gradStops2 = StaticFunctions::resampleGradientStops(stops2);

  QGradientStops gradStops;
  int gsize = gradStops1.size()-1;
  for(int i=0; i<pos.size(); i++)
    {
      int idx = pos[i]*gsize;
      QColor color1 = gradStops1[idx].second;
      QColor color2 = gradStops2[idx].second;

      // linear interpolation of colors
      float rb,gb,bb,ab, re,ge,be,ae;
      rb = color1.red();
      gb = color1.green();
      bb = color1.blue();
      ab = color1.alpha();
      re = color2.red();
      ge = color2.green();
      be = color2.blue();
      ae = color2.alpha();
      
      float r,g,b,a;
      r = rb + frc*(re-rb);
      g = gb + frc*(ge-gb);
      b = bb + frc*(be-bb);
      a = ab + frc*(ae-ab);


      QColor color = QColor(r,g,b,a);
      gradStops << QGradientStop(pos[i], color);
    }

  return gradStops;
}
Ejemplo n.º 7
0
RoundProgressBarTest::RoundProgressBarTest(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::RoundProgressBarTest)
{
    ui->setupUi(this);

    //圆环
    ui->roundBar1->setFormat("%v");
    ui->roundBar1->setDecimals(0);
    connectToSlider(ui->roundBar1);
    connectToBaseCircleCheckBox(ui->roundBar1);
    connectToDataCircleCheckBox(ui->roundBar1);
    connectToCenterCircleCheckBox(ui->roundBar1);
    connectToTextCheckBox(ui->roundBar1);

    QGradientStops grandientPoints;
    grandientPoints << QGradientStop(0, Qt::red) << QGradientStop(1, Qt::yellow);
    ui->roundBar4->setStartAngle(RoundProgressBar::PositionLeft);
    ui->roundBar4->setDecimals(0);
    ui->roundBar4->setDataColors(grandientPoints);
    connectToSlider(ui->roundBar4);
    connectToBaseCircleCheckBox(ui->roundBar4);
    connectToDataCircleCheckBox(ui->roundBar4);
    connectToCenterCircleCheckBox(ui->roundBar4);
    connectToTextCheckBox(ui->roundBar4);

    //饼状
    ui->roundBar2->setStartAngle(RoundProgressBar::PositionRight);
    ui->roundBar2->setBarStyle(RoundProgressBar::StylePie);
    ui->roundBar2->setDecimals(0);
    connectToSlider(ui->roundBar2);
    connectToBaseCircleCheckBox(ui->roundBar2);
    connectToDataCircleCheckBox(ui->roundBar2);
    connectToCenterCircleCheckBox(ui->roundBar2);
    connectToTextCheckBox(ui->roundBar2);

    ui->roundBar5->setStartAngle(RoundProgressBar::PositionLeft);
    ui->roundBar5->setBarStyle(RoundProgressBar::StylePie);
    ui->roundBar5->setDecimals(0);
    connectToSlider(ui->roundBar5);
    connectToBaseCircleCheckBox(ui->roundBar5);
    connectToDataCircleCheckBox(ui->roundBar5);
    connectToCenterCircleCheckBox(ui->roundBar5);
    connectToTextCheckBox(ui->roundBar5);

    //线条
    ui->roundBar3->setStartAngle(RoundProgressBar::PositionTop);
    ui->roundBar3->setBarStyle(RoundProgressBar::StyleLine);
    ui->roundBar3->setOutlinePenWidth(4);
    ui->roundBar3->setDataPenWidth(4);
    ui->roundBar3->setDecimals(0);
    connectToSlider(ui->roundBar3);
    connectToBaseCircleCheckBox(ui->roundBar3);
    connectToDataCircleCheckBox(ui->roundBar3);
    connectToCenterCircleCheckBox(ui->roundBar3);
    connectToTextCheckBox(ui->roundBar3);

    ui->roundBar6->setStartAngle(RoundProgressBar::PositionTop);
    ui->roundBar6->setBarStyle(RoundProgressBar::StyleLine);
    ui->roundBar6->setDecimals(2);
    ui->roundBar6->setClockwise(false);
    ui->roundBar6->setOutlinePenWidth(18);
    ui->roundBar6->setDataPenWidth(10);
    connectToSlider(ui->roundBar6);
    connectToBaseCircleCheckBox(ui->roundBar6);
    connectToDataCircleCheckBox(ui->roundBar6);
    connectToCenterCircleCheckBox(ui->roundBar6);
    connectToTextCheckBox(ui->roundBar6);
}
Ejemplo n.º 8
0
//------------------------------------------------------------------------------
// Values referenced from "MFD_contextual_panel_key_colors_FINAL_v1.ai".
//------------------------------------------------------------------------------
const QGradientStops MercuryPalette::GetLinearGradient( eGradientRole role )
{
    QGradientStops stops;

    switch( role )
    {
        case eGradient_PositiveFill:    
            stops   << QGradientStop( 0.2977, QColor( 57, 181, 74 ) )
                    << QGradientStop( 0.7296, QColor( 140, 232, 63 ) );            
        break;
        case eGradient_WarningFill:
            stops   << QGradientStop( 0.25, QColor( 204, 0, 0 ) )
                    << QGradientStop( 0.75, QColor( 255, 102, 51 ) );
        break;
        case eGradient_FuelFill:
            stops   << QGradientStop( 0.25, QColor( 0, 146, 69 ) )
                    << QGradientStop( 0.75, QColor( 97, 199, 120 ) );
        break;
        case eGradient_OilFill:
            stops   << QGradientStop( 0.0189, QColor( 149, 103, 70 ) )
                    << QGradientStop( 0.35, QColor( 217, 161, 116 ) )
                    << QGradientStop( 0.75, QColor( 255, 229, 151 ) );
        break;
        case eGradient_WaterFill:
            stops   << QGradientStop( 0.25, QColor( 52, 109, 174 ) )
                    << QGradientStop( 0.75, QColor( 0, 159, 221 ) );
        break;
        case eGradient_WasteFill:
            stops   << QGradientStop( 0.25, QColor( 135, 79, 110 ) )
                    << QGradientStop( 0.75, QColor( 190, 95, 131 ) );
        break;
        case eGradient_GreyWaterFill:
            stops   << QGradientStop( 0.1887, QColor( 87, 87, 87 ) )
                    << QGradientStop( 0.7421, QColor( 174, 174, 175 ) );
        break;
        case eGradient_LiveWellFill:
            stops   << QGradientStop( 0.1887, QColor( 102, 52, 152 ) )
                    << QGradientStop( 0.7421, QColor( 170, 120, 220 ) );
        break;
        case eGradient_SystemTrayPositiveFill:
            stops   << QGradientStop( 0.0, QColor( 81, 159, 38 ) )
                    << QGradientStop( 1.0, QColor( 0, 112, 48 ) );
        break;
        case eGradient_SystemTrayWarningFill:
            stops   << QGradientStop( 0.0, QColor( 237, 46, 54 ) )
                    << QGradientStop( 1.0, QColor( 100, 14, 15 ) );
        break;
        case eGradient_SystemTrayInactiveFill:
            stops   << QGradientStop( 0.0, QColor( 255, 255, 255 ) )
                    << QGradientStop( 1.0, QColor( 67, 68, 71 ) );
        break;
        default:    
        break;
    }

    return stops;
}
Ejemplo n.º 9
0
void
RemapWidget::on_colorList_activated(int index)
{
  QGradientStops stops;
  if (index == 0) // black-white
    {
      stops << QGradientStop(0, Qt::black)
	    << QGradientStop(1, Qt::white);
    }
  else if (index == 1) // white-black
    {
      stops << QGradientStop(0, Qt::white)
	    << QGradientStop(1, Qt::black);
    
    }
  else if (index == 2) // white-sepia
    {
      stops << QGradientStop(0, Qt::white)
	    << QGradientStop(1, QColor(112, 66, 20));
    
    }
  else if (index == 3) // sepia-white
    {
      stops << QGradientStop(0, QColor(112, 66, 20))
	    << QGradientStop(1, Qt::white);
    
    }
  else if (index == 4) // white-green
    {
      stops << QGradientStop(0, Qt::white)
	    << QGradientStop(1, QColor(20, 112, 66));
    
    }
  else if (index == 5) // white-blue
    {
      stops << QGradientStop(0, Qt::white)
	    << QGradientStop(1, QColor(66, 20, 112));
    
    }
  else if (index == 6) // yellow-red
    {
      stops << QGradientStop(0, QColor(250, 250, 200))
	    << QGradientStop(0.5, QColor(250, 100, 0))
	    << QGradientStop(1, Qt::darkRed);
    
    }
  else if (index == 7) // cyan-blue
    {
      stops << QGradientStop(0, QColor(200, 250, 250))
	    << QGradientStop(0.5, QColor(0, 100, 250))
	    << QGradientStop(1, Qt::darkBlue);
    
    }
  else // default black-white
    {
      stops << QGradientStop(0, Qt::black)
	    << QGradientStop(1, Qt::white);
    }

  m_gradientWidget->setColorGradient(stops);
  m_imageWidget->setGradientStops(stops);
  m_histogramWidget->setGradientStops(stops);
}
Ejemplo n.º 10
0
bool
RemapWidget::setFile(QList<QString> flnm,
		     int voltype)
{  
  m_timeseriesFiles.clear();
  Global::statusBar()->clearMessage();

  hideWidgets();

  if (m_histogramWidget)
    delete m_histogramWidget;

  if (m_imageWidget)
    delete m_imageWidget;

  if (m_remapVolume)
    delete m_remapVolume;
  
  if (m_gradientWidget)
    delete m_gradientWidget;

  if (m_slider)
    delete m_slider;

  m_histogramWidget = 0;
  m_imageWidget = 0;
  m_gradientWidget = 0;
  m_remapVolume = 0;
  m_slider = 0;

  m_volumeType = voltype;
  m_volumeFile = flnm;

  if (m_volumeType == RAWVolume)
    m_remapVolume = new RemapRawVolume();
  else if (m_volumeType == TOMVolume)
    m_remapVolume = new RemapTomVolume();
  else if (m_volumeType == AnalyzeVolume)
    m_remapVolume = new RemapAnalyze();
  else if (m_volumeType == HDF4Volume)
    m_remapVolume = new RemapHDF4();
  else if (m_volumeType == RawSlices)
    m_remapVolume = new RemapRawSlices();
  else if (m_volumeType == RawSlabs)
    m_remapVolume = new RemapRawSlabs();
  else if (m_volumeType == NCVolume)
    m_remapVolume = new RemapNcVolume();
  else if (m_volumeType == ImageVolume)
    m_remapVolume = new RemapImageVolume();
  else if (m_volumeType == ImageMagickVolume)
    m_remapVolume = new RemapDicomVolume();

  if (! m_remapVolume->setFile(m_volumeFile))
    return false;

  m_histogramWidget = new RemapHistogramWidget();
  m_histogramWidget->setMinimumSize(100, 300);
  m_histogramWidget->setSizePolicy(QSizePolicy::Expanding,
				   QSizePolicy::Fixed);

  m_gradientWidget = new GradientEditorWidget();
  m_gradientWidget->setDrawBox(false);
  m_gradientWidget->setMinimumSize(200, 20);
  m_gradientWidget->setGeneralLock(GradientEditor::LockToTop);
  
  int d, w, h;
  m_remapVolume->gridSize(d, w, h);

  m_slider = new MySlider();
  m_slider->set(0, d-1, 0, d-1, 0);
  
  ui.histogramFrame->layout()->addWidget(m_histogramWidget);
  ui.colorFrame->layout()->addWidget(m_gradientWidget);
  ui.sliderFrame->layout()->addWidget(m_slider);

  m_imageWidget = new RemapImage();
  m_imageWidget->setGridSize(d, w, h);
  m_scrollArea->setWidget(m_imageWidget);

  m_currSlice = 0;

  connect(m_histogramWidget, SIGNAL(getHistogram()),
	  this, SLOT(getHistogram()));  

  connect(m_histogramWidget, SIGNAL(newMapping()),
	  this, SLOT(newMapping()));  

  connect(m_histogramWidget, SIGNAL(newMinMax(float, float)),
	  this, SLOT(newMinMax(float, float)));

  connect(m_imageWidget, SIGNAL(getSlice(int)),
	  this, SLOT(getSlice(int)));  

  connect(m_imageWidget, SIGNAL(getRawValue(int, int, int)),
	  this, SLOT(getRawValue(int, int, int)));

  connect(m_imageWidget, SIGNAL(newMinMax(float, float)),
	  this, SLOT(newMinMax(float, float)));

  connect(m_imageWidget, SIGNAL(saveTrimmed(int, int, int,
					    int, int, int)),
	  this, SLOT(saveTrimmed(int, int, int,
				 int, int, int)));
  
  connect(m_imageWidget, SIGNAL(saveTrimmedImages(int, int, int,
						  int, int, int)),
	  this, SLOT(saveTrimmedImages(int, int, int,
				       int, int, int)));
  
  connect(m_imageWidget, SIGNAL(extractRawVolume()),
	  this, SLOT(extractRawVolume()));
  
  connect(m_gradientWidget, SIGNAL(gradientChanged(QGradientStops)),
	  m_imageWidget, SLOT(setGradientStops(QGradientStops)));

  connect(m_gradientWidget, SIGNAL(gradientChanged(QGradientStops)),
	  m_histogramWidget, SLOT(setGradientStops(QGradientStops)));


  connect(m_slider, SIGNAL(valueChanged(int)),
	  m_imageWidget, SLOT(sliceChanged(int)));

  connect(m_slider, SIGNAL(userRangeChanged(int, int)),
	  m_imageWidget, SLOT(userRangeChanged(int, int)));


  QGradientStops stops;
  stops << QGradientStop(0, Qt::black)
	<< QGradientStop(1, Qt::white);
  m_gradientWidget->setColorGradient(stops);
  m_imageWidget->setGradientStops(stops);
  m_histogramWidget->setGradientStops(stops);

  setRawMinMax();
  
  showWidgets();

  return true;
}
Ejemplo n.º 11
0
void TransferFunctionEditor::_setDefault()
{
    QGradientStops stops;

    stops << QGradientStop( 0.0, QColor::fromRgba( 0x000000ff ));
    stops << QGradientStop( 0.1, QColor::fromRgba( 0x330000ff ));
    stops << QGradientStop( 0.2, QColor::fromRgba( 0x53007dff ));
    stops << QGradientStop( 0.3, QColor::fromRgba( 0x7300ffff ));
    stops << QGradientStop( 0.4, QColor::fromRgba( 0x7f00ff7d ));
    stops << QGradientStop( 0.5, QColor::fromRgba( 0x8500ff00 ));
    stops << QGradientStop( 0.6, QColor::fromRgba( 0x86ffff00 ));
    stops << QGradientStop( 0.7, QColor::fromRgba( 0x8cff7d00 ));
    stops << QGradientStop( 0.8, QColor::fromRgba( 0x99ff0000 ));
    stops << QGradientStop( 0.925, QColor::fromRgba( 0xb3ff007d ));
    stops << QGradientStop( 1.00, QColor::fromRgba( 0xffff7dff ));

    setColorMapStops( stops );
    _gradientRenderer->setGradientStops( stops );
    _pointsUpdated();
}
Ejemplo n.º 12
0
void
MeshGenerator::generateMesh(int nSlabs,
			    QStringList volumeFiles,
			    QString flnm,
			    int depth,
			    QGradientStops vstops,
			    int fillValue,
			    bool checkForMore,
			    bool lookInside,
			    Vec voxelScaling,
			    QList<Vec> clipPos,
			    QList<Vec> clipNormal,
			    QList<CropObject> crops,
			    QList<PathObject> paths,
			    uchar *lut,
			    int chan,
			    bool avgColor)
{
  bool saveIntermediate = false;

  int bpv = 1;
  if (m_voxelType > 0) bpv = 2;
  int nbytes = bpv*m_nY*m_nZ;

//  if (nSlabs > 1)
//    {
//      QStringList sl;
//      sl << "No";
//      sl << "Yes";
//      bool ok;
//      QString okstr = QInputDialog::getItem(0, "Save slab files",
//		      "Save slab files in .ply format.\nFiles will not be collated together to create a unified mesh for the whole sample.",
//					    sl, 0, false, &ok);
//      if (ok && okstr == "Yes")
//	saveIntermediate = true;
//    }

  QGradientStops lutstops;
  for(int i=0; i<255; i++)
    {
      QColor col(lut[4*i+0], lut[4*i+1], lut[4*i+2], lut[4*i+3]);
      lutstops << QGradientStop((float)i/(float)255.0f, col);
    }
  
  bool trim = (qRound(m_dataSize.x) < m_height ||
	       qRound(m_dataSize.y) < m_width ||
	       qRound(m_dataSize.z) < m_depth);
  bool clipPresent = (clipPos.count() > 0);

  m_cropPresent = false;
  m_tearPresent = false;
  m_blendPresent = false;
  for(int ci=0; ci<m_crops.count(); ci++)
    {
      if (crops[ci].cropType() < CropObject::Tear_Tear)
	m_cropPresent = true;
      else if (crops[ci].cropType() < CropObject::View_Tear)
	m_tearPresent = true;
      else if (m_crops[ci].cropType() > CropObject::Displace_Displace &&
	       m_crops[ci].cropType() < CropObject::Glow_Ball)
	m_blendPresent = true;
    }

  m_pathCropPresent = false;
  m_pathBlendPresent = false;
  for (int i=0; i<m_paths.count(); i++)
    {
      if (m_paths[i].blend()) m_pathBlendPresent = true;
      if (m_paths[i].crop()) m_pathCropPresent = true;
    }

  int nextra = depth;
  int blockStep = m_nX/nSlabs;


  //-----------------------------
  int nvols = volumeFiles.count();      
  //-----------------------------

  for (int volnum=0; volnum < nvols; volnum++)
    {
      //if (nvols > 1)
	{
	  m_vfm->setBaseFilename(volumeFiles[volnum]);
	  uchar *vslice = m_vfm->getSlice(0);
	}

      m_meshLog->moveCursor(QTextCursor::End);
      m_meshLog->insertPlainText(QString("\nProcessing file %1 of %2 : %3\n").\
				 arg(volnum+1).arg(nvols).arg(m_vfm->fileName()));

      for (int nb=0; nb<nSlabs; nb++)
	{
	  m_meshLog->moveCursor(QTextCursor::End);
	  m_meshLog->insertPlainText(QString("  Processing slab %1 of %2\n").arg(nb+1).arg(nSlabs));
	  int d0 = nb*blockStep;
	  int d1 = qMin(m_nX-1, (nb+1)*blockStep);
	  int dlen = d1-d0+1;
	  
	  int d0z = d0 + qRound(m_dataMin.z);
	  int d1z = d1 + qRound(m_dataMin.z);
	  
	  uchar *extData;
	  if (m_voxelType == 0)
	    extData = new uchar[(dlen+2*nextra)*m_nY*m_nZ];
	  else
	    extData = new uchar[2*(dlen+2*nextra)*m_nY*m_nZ]; // ushort
	  
	  uchar *cropped = new uchar[nbytes];
	  uchar *tmp = new uchar[nbytes];
	  
	  int i0 = 0;
	  for(int i=d0z-nextra; i<=d1z+nextra; i++)
	    {
	      m_meshProgress->setValue((int)(100.0*(float)(i0/(float)(dlen+2*nextra))));
	      qApp->processEvents();
	      
	      int iv = qBound(0, i, m_depth-1);
	      uchar *vslice = m_vfm->getSlice(iv);
	      
	      memset(cropped, 0, nbytes);
	      
	      if (!trim)
		memcpy(tmp, vslice, nbytes);
	      else
		{
		  int wmin = qRound(m_dataMin.y);
		  int hmin = qRound(m_dataMin.x);
		  if (m_voxelType == 0)
		    {
		      for(int w=0; w<m_nY; w++)
			for(int h=0; h<m_nZ; h++)
			  tmp[w*m_nZ + h] = vslice[(wmin+w)*m_height + (hmin+h)];
		    }
		  else
		    {
		      for(int w=0; w<m_nY; w++)
			for(int h=0; h<m_nZ; h++)
			  ((ushort*)tmp)[w*m_nZ + h] = ((ushort*)vslice)[(wmin+w)*m_height + (hmin+h)];
		    }
		}
	      
	      
	      int jk = 0;
	      for(int j=0; j<m_nY; j++)
		for(int k=0; k<m_nZ; k++)
		  {
		    Vec po = Vec(m_dataMin.x+k, m_dataMin.y+j, iv);
		    bool ok = true;
		    
		    // we don't want to scale before pruning
		    // no mop pruning

		    po *= m_samplingLevel;
		    
		    if (ok && clipPresent)
		      ok = StaticFunctions::getClip(po, clipPos, clipNormal);
		    
		    if (ok && m_cropPresent)
		      ok = checkCrop(po);
		    
		    if (ok && m_pathCropPresent)
		      ok = checkPathCrop(po);
		    
		    if (ok && m_blendPresent)
		      {
			ushort v;
			if (m_voxelType == 0)
			  v = tmp[j*m_nZ + k];
			else
			  v = ((ushort*)tmp)[j*m_nZ + k];
			ok = checkBlend(po, v, lut);
		      }
		    
		    if (ok && m_pathBlendPresent)
		      {
			ushort v;
			if (m_voxelType == 0)
			  v = tmp[j*m_nZ + k];
			else
			  v = ((ushort*)tmp)[j*m_nZ + k];
			ok = checkPathBlend(po, v, lut);
		      }
		    
		    if (ok)
		      //cropped[jk] = mop; // nop mop pruning
		      cropped[jk] = 255;
		    else
		      cropped[jk] = 0;
		    
		    jk ++;
		  }
	      
	      if (m_voxelType == 0)
		{
		  for(int j=0; j<m_nY*m_nZ; j++)
		    {
		      if (cropped[j] == 0)
			tmp[j] = 0;
		    }
		}
	      else
		{
		  for(int j=0; j<m_nY*m_nZ; j++)
		    {
		      if (cropped[j] == 0)
			((ushort*)tmp)[j] = 0;
		    }
		}
	      
	      // tmp now clipped and contains raw data
	      memcpy(extData + bpv*i0*m_nY*m_nZ, tmp, nbytes);
	      
	      i0++;
	    }
	  delete [] tmp;
	  delete [] cropped;
	  m_meshProgress->setValue(100);
	  qApp->processEvents();
	  
	  //------------
	  if (m_tearPresent)
	    {
	      uchar *data0 = new uchar[(dlen+2*nextra)*m_nY*m_nZ];
	      
	      uchar *data1 = extData;
	      memcpy(data0, data1, (dlen+2*nextra)*m_nY*m_nZ);
	      applyTear(d0, d1, nextra,
			data0, data1, true);
	      
	      delete [] data0;
	    }
	  //------------
	  
	  
	  //--------------------------------
	  // ---- set border voxels to fillValue
	  if (fillValue >= 0)
	    {
	      uchar *v = extData;
	      
	      i0 = 0;
	      for(int i=d0z-nextra; i<=d1z+nextra; i++)
		{
		  int iv = qBound(0, i, m_depth-1);
		  int i0dx = i0*m_nY*m_nZ;
		  if (iv <= qRound(m_dataMin.z) || iv >= qRound(m_dataMax.z))
		    {
		      if (m_voxelType == 0)
			memset(v + i0dx, fillValue, m_nY*m_nZ);
		      else
			{
			  for(int fi=0; fi<m_nY*m_nZ; fi++)
			    ((ushort*)v)[i0*m_nY*m_nZ + fi] = fillValue;
			}
		    }
		  else
		    {
		      if (m_voxelType == 0)
			{
			  for(int j=0; j<m_nY; j++)
			    v[i0dx + j*m_nZ] = fillValue;
			  for(int j=0; j<m_nY; j++)
			    v[i0dx + j*m_nZ + m_nZ-1] = fillValue;
			  for(int k=0; k<m_nZ; k++)
			    v[i0dx + k] = fillValue;
			  for(int k=0; k<m_nZ; k++)
			    v[i0dx + (m_nY-1)*m_nZ + k] = fillValue;
			}
		      else
			{
			  for(int j=0; j<m_nY; j++)
			    ((ushort*)v)[i0dx + j*m_nZ] = fillValue;
			  for(int j=0; j<m_nY; j++)
			    ((ushort*)v)[i0dx + j*m_nZ + m_nZ-1] = fillValue;
			  for(int k=0; k<m_nZ; k++)
			    ((ushort*)v)[i0dx + k] = fillValue;
			  for(int k=0; k<m_nZ; k++)
			    ((ushort*)v)[i0dx + (m_nY-1)*m_nZ + k] = fillValue;
			}
		    }
		  i0++;
		}
	    }
	  //--------------------------------
	  
	  m_meshLog->moveCursor(QTextCursor::End);
	  m_meshLog->insertPlainText("  Generating Color ...\n");
	  
	  for(int ni=0; ni<m_nverts; ni++)
	    {
	      m_meshProgress->setValue((int)(100.0*(float)ni/(float)m_nverts));
	      qApp->processEvents();
	      
	      float v[3];
	      v[0] = m_vlist[ni]->x/voxelScaling.x/m_scaleModel;
	      v[1] = m_vlist[ni]->y/voxelScaling.y/m_scaleModel;
	      v[2] = m_vlist[ni]->z/voxelScaling.z/m_scaleModel;

	      if (v[2] > d0 && v[2] <= d1)
		{
//		  QMessageBox::information(0, "", QString("%1 %2 %3\n%4 %5 %6\n%7 %8"). \
//					   arg(v[0]).arg(v[1]).arg(v[2]). \
//					   arg(m_vlist[ni]->x).arg(m_vlist[ni]->y).arg(m_vlist[ni]->z). \
//					   arg(d0).arg(d1));
		  		  
		  uchar *volData = extData;
		  QColor col;
		  QVector3D pos, normal;
		  pos = QVector3D(v[0], v[1], v[2]-d0 + nextra);
		  normal = QVector3D(-m_vlist[ni]->nx,
				     -m_vlist[ni]->ny,
				     -m_vlist[ni]->nz);
		  col = getVRLutColor(volData,
				      dlen,
				      depth, nextra,
				      pos, normal,
				      lut,
				      lookInside,
				      QVector3D(v[0], v[1], v[2]));
		      
		  if (col.alphaF() > 0)
		    {
		      float r = col.red()/255.0f;
		      float g = col.green()/255.0f;
		      float b = col.blue()/255.0f;
		      float a = col.alphaF();

		      // tinge with lutcolor
		      QColor col0 = vstops[255*(float)(volnum+1)/(float)nvols].second;
		      float aa = col0.alphaF();
		      float tr = col0.red()/255.0f;
		      float tg = col0.green()/255.0f;
		      float tb = col0.blue()/255.0f;
		      
		      r = (1.0-aa)*r + aa*a*tr;
		      g = (1.0-aa)*g + aa*a*tg;
		      b = (1.0-aa)*b + aa*a*tb;

		      vcolor[3*ni+0] = (1-a)*vcolor[3*ni+0] + r;
		      vcolor[3*ni+1] = (1-a)*vcolor[3*ni+1] + g;
		      vcolor[3*ni+2] = (1-a)*vcolor[3*ni+2] + b;
		    }
		}
	    }
	  m_meshProgress->setValue(100);
	  
	  delete [] extData;
	} // loop over slabs

//      if (nvols > 1) // save intermediate files
//	{
//	  QString plyflnm = flnm;
//	  plyflnm.chop(3);
//	  plyflnm += QString("%1.ply").arg((int)volnum, (int)nvols/10+2, 10, QChar('0'));
//
//	  for(int ni=0; ni<m_nverts; ni++)
//	    {
//	      m_vlist[ni]->r = 255*vcolor[3*ni+0];
//	      m_vlist[ni]->g = 255*vcolor[3*ni+1];
//	      m_vlist[ni]->b = 255*vcolor[3*ni+2];
//	    }
//	  savePLY(plyflnm);
//	}

    }// loop over files

  for(int ni=0; ni<m_nverts; ni++)
    {
      m_vlist[ni]->r = 255*vcolor[3*ni+0];
      m_vlist[ni]->g = 255*vcolor[3*ni+1];
      m_vlist[ni]->b = 255*vcolor[3*ni+2];
    }

  savePLY(flnm);

  m_meshLog->moveCursor(QTextCursor::End);
  m_meshLog->insertPlainText("Mesh saved in "+flnm);

  QMessageBox::information(0, "", QString("Mesh saved in "+flnm));


}
Ejemplo n.º 13
0
bool
MeshGenerator::getValues(int &depth,
			 int &fillValue,
			 bool &checkForMore,
			 bool &lookInside,
			 QGradientStops &stops,
			 bool doBorder,
			 int &chan,
			 bool &avgColor)
{
  chan = 0;
  depth = 1;
  fillValue = -1;
  checkForMore = true;
  lookInside = false;
  avgColor = false;
  m_useTagColors = false;
  m_scaleModel = 1.0;
  QGradientStops vstops;
  vstops << QGradientStop(0.0, QColor(50 ,50 ,50 ,255))
	 << QGradientStop(0.5, QColor(200,150,100,255))
	 << QGradientStop(1.0, QColor(255,255,255,255));

  if (doBorder) fillValue = 0;
  
  PropertyEditor propertyEditor;
  QMap<QString, QVariantList> plist;
  
  QVariantList vlist;

  vlist.clear();
  vlist << QVariant("checkbox");
  vlist << QVariant(avgColor);
  plist["average color"] = vlist;

  vlist.clear();
  vlist << QVariant("checkbox");
  vlist << QVariant(m_useTagColors);
  plist["apply tag colors"] = vlist;

  vlist.clear();
  vlist << QVariant("int");
  vlist << QVariant(chan);
  vlist << QVariant(0);
  vlist << QVariant(2);
  plist["mop channel"] = vlist;

  vlist.clear();
  vlist << QVariant("int");
  vlist << QVariant(depth);
  vlist << QVariant(0);
  vlist << QVariant(200);
  plist["depth"] = vlist;

  vlist.clear();
  vlist << QVariant("int");
  vlist << QVariant(fillValue);
  vlist << QVariant(-1);
  vlist << QVariant(255);
  plist["fillvalue"] = vlist;

  vlist.clear();
  vlist << QVariant("checkbox");
  vlist << QVariant(checkForMore);
  plist["greater"] = vlist;

  vlist.clear();
  vlist << QVariant("checkbox");
  vlist << QVariant(lookInside);
  plist["look inside"] = vlist;

  vlist.clear();
  vlist << QVariant("float");
  vlist << QVariant(m_scaleModel);
  vlist << QVariant(0.001);
  vlist << QVariant(1.0);
  vlist << QVariant(0.005); // singlestep
  vlist << QVariant(3); // decimals
  plist["scale"] = vlist;

  vlist.clear();
  vlist << QVariant("colorgradient");
  for(int s=0; s<vstops.size(); s++)
    {
      float pos = vstops[s].first;
      QColor color = vstops[s].second;
      int r = color.red();
      int g = color.green();
      int b = color.blue();
      int a = color.alpha();
      vlist << QVariant(pos);
      vlist << QVariant(r);
      vlist << QVariant(g);
      vlist << QVariant(b);
      vlist << QVariant(a);
    }
  plist["color gradient"] = vlist;


  vlist.clear();
  QFile helpFile(":/mesh.help");
  if (helpFile.open(QFile::ReadOnly))
    {
      QTextStream in(&helpFile);
      QString line = in.readLine();
      while (!line.isNull())
	{
	  if (line == "#begin")
	    {
	      QString keyword = in.readLine();
	      QString helptext;
	      line = in.readLine();
	      while (!line.isNull())
		{
		  helptext += line;
		  helptext += "\n";
		  line = in.readLine();
		  if (line == "#end") break;
		}
	      vlist << keyword << helptext;
	    }
	  line = in.readLine();
	}
    }	      
  plist["commandhelp"] = vlist;

  vlist.clear();
  QString mesg;
  mesg += "File : "+m_vfm->fileName()+"\n";
  int d = m_vfm->depth();
  int w = m_vfm->width();
  int h = m_vfm->height();
  mesg += QString("Volume Size : %1 %2 %3\n").arg(h).arg(w).arg(d);
  mesg += QString("Data Min : %1 %2 %3\n").arg(m_dataMin.x).arg(m_dataMin.y).arg(m_dataMin.z);
  mesg += QString("Data Max : %1 %2 %3\n").arg(m_dataMax.x).arg(m_dataMax.y).arg(m_dataMax.z);

  if (m_voxelType > 0)
    mesg += "\n ** Only opacity based surface generation available for unsigned short data **\n";

  mesg += "\n* You can keep on working while this process is running.\n";
  vlist << mesg;
  plist["message"] = vlist;


  QStringList keys;
  keys << "average color";
  keys << "apply tag colors";
  keys << "mop channel";
  keys << "isosurface value";
  keys << "depth";
  keys << "fillvalue";
  keys << "scale";
  keys << "greater";
  keys << "look inside";
  keys << "color gradient";
  keys << "commandhelp";
  keys << "message";

  propertyEditor.set("Mesh Repainting Parameters", plist, keys);
  QMap<QString, QPair<QVariant, bool> > vmap;
  
  if (propertyEditor.exec() == QDialog::Accepted)
    vmap = propertyEditor.get();
  else
    return false;
  
  for(int ik=0; ik<keys.count(); ik++)
    {
      QPair<QVariant, bool> pair = vmap.value(keys[ik]);

      if (pair.second)
	{
	  if (keys[ik] == "average color")
	    avgColor = pair.first.toBool();
	  else if (keys[ik] == "apply tag colors")
	    m_useTagColors = pair.first.toBool();
	  else if (keys[ik] == "mop channel")
	    chan = pair.first.toInt();
	  else if (keys[ik] == "color gradient")
	    vstops = propertyEditor.getGradientStops(keys[ik]);
	  else if (keys[ik] == "scale")
	    m_scaleModel = pair.first.toFloat();
	  else if (keys[ik] == "depth")
	    depth = pair.first.toInt();
	  else if (keys[ik] == "fillvalue")
	    fillValue = pair.first.toInt();
	  else if (keys[ik] == "greater")
	    checkForMore = pair.first.toBool();
	  else if (keys[ik] == "look inside")
	    lookInside = pair.first.toBool();
	}
    }

  stops = resampleGradientStops(vstops);

  return true;
}
Ejemplo n.º 14
0
void
SplineTransferFunction::fromDomElement(QDomElement de)
{
  m_on.clear();
  m_name.clear();
  m_points.clear();
  m_normals.clear();
  m_rightNormals.clear();
  m_leftNormals.clear();
  m_normalWidths.clear();
  m_normalRotations.clear();
  m_gradientStops.clear();

  QDomNodeList dlist = de.childNodes();
  for(int i=0; i<dlist.count(); i++)
    {
      QDomElement dnode = dlist.at(i).toElement();
      if (dnode.tagName() == "name")
	{
	  m_name = dnode.toElement().text();
	}
      else if (dnode.tagName() == "points")
	{
	  QString str = dnode.toElement().text();
	  QStringList strlist = str.split(" ", QString::SkipEmptyParts);
	  for(int j=0; j<strlist.count()/2; j++)
	    {
	      float x,y;
	      x = strlist[2*j].toFloat();
	      y = strlist[2*j+1].toFloat();
	      m_points << QPointF(x,y);
	    }
	}
      else if (dnode.tagName() == "normalwidths")
	{
	  QString str = dnode.toElement().text();
	  QStringList strlist = str.split(" ", QString::SkipEmptyParts);
	  for(int j=0; j<strlist.count()/2; j++)
	    {
	      float x,y;
	      x = strlist[2*j].toFloat();
	      y = strlist[2*j+1].toFloat();
	      m_normalWidths << QPointF(x,y);
	    }
	}
      else if (dnode.tagName() == "normalrotations")
	{
	  QString str = dnode.toElement().text();
	  QStringList strlist = str.split(" ", QString::SkipEmptyParts);
	  for(int j=0; j<strlist.count(); j++)
	    m_normalRotations << strlist[j].toFloat();
	}
      else if (dnode.tagName() == "gradientstops")
	{
	  QString str = dnode.toElement().text();
	  QStringList strlist = str.split(" ", QString::SkipEmptyParts);
	  for(int j=0; j<strlist.count()/5; j++)
	    {
	      float pos, r,g,b,a;
	      pos = strlist[5*j].toFloat();
	      r = strlist[5*j+1].toInt();
	      g = strlist[5*j+2].toInt();
	      b = strlist[5*j+3].toInt();
	      a = strlist[5*j+4].toInt();
	      m_gradientStops << QGradientStop(pos, QColor(r,g,b,a));
	    }
	}
      else if (dnode.tagName() == "sets")
	{
	  QString str = dnode.toElement().text();
	  QStringList strlist = str.split(" ", QString::SkipEmptyParts);
	  for(int j=0; j<strlist.count(); j++)
	    m_on.append(strlist[j].toInt() > 0);
	}
    }

  updateNormals();
  updateColorMapImage();
}
Ejemplo n.º 15
0
QList<SplineInformation>
SplineInformation::interpolate(QList<SplineInformation> splineInfo1,
			       QList<SplineInformation> splineInfo2,
			       float frc)
{

  QList<SplineInformation> splineInfo;

  for(int i=0; i<qMin(splineInfo1.size(),
		      splineInfo2.size()); i++)
    {
      splineInfo.append(interpolate(splineInfo1[i],
				    splineInfo2[i],
				    frc));
    }

  int st = splineInfo.size();
  for(int i=st; i<splineInfo1.size(); i++)
    {
      QGradientStops stops = splineInfo1[i].gradientStops();
      QGradientStops newStops;
      for(int j=0; j<stops.size(); j++)
	{
	  float pos = stops[j].first;
	  QColor col = stops[j].second;
	  float r,g,b,a;
	  r = col.red();
	  g = col.green();
	  b = col.blue();
	  a = (1-frc)*col.alpha();
	  col = QColor(r,g,b,a);

	  newStops << QGradientStop(pos, col);
	}

      SplineInformation sinfo;
      sinfo.setName(splineInfo1[i].name());
      sinfo.setOn(splineInfo1[i].on());
      sinfo.setPoints(splineInfo1[i].points());
      sinfo.setNormalWidths(splineInfo1[i].normalWidths());
      sinfo.setNormalRotations(splineInfo1[i].normalRotations());
      sinfo.setGradientStops(newStops);

      splineInfo.append(sinfo);
    }

  st = splineInfo.size();
  for(int i=st; i<splineInfo2.size(); i++)
    {
      QGradientStops stops = splineInfo2[i].gradientStops();
      QGradientStops newStops;
      for(int j=0; j<stops.size(); j++)
	{
	  float pos = stops[j].first;
	  QColor col = stops[j].second;
	  float r,g,b,a;
	  r = col.red();
	  g = col.green();
	  b = col.blue();
	  a = frc*col.alpha();
	  col = QColor(r,g,b,a);

	  newStops << QGradientStop(pos, col);
	}

      SplineInformation sinfo;
      sinfo.setName(splineInfo2[i].name());
      sinfo.setOn(splineInfo2[i].on());
      sinfo.setPoints(splineInfo2[i].points());
      sinfo.setNormalWidths(splineInfo2[i].normalWidths());
      sinfo.setNormalRotations(splineInfo2[i].normalRotations());
      sinfo.setGradientStops(newStops);

      splineInfo.append(sinfo);
    }

  
  return splineInfo;
}
Ejemplo n.º 16
0
void QgsQuickPrint::renderPrintScaleBar( QPainter * thepPainter,
    QgsMapRenderer * thepMapRenderer,
    int theMaximumWidth )
{
  //hard coding some options for now
  bool mySnappingFlag = true;
  QColor mColor = Qt::black;
  // Hard coded sizes
  int myTextOffsetX = 0;
  int myTextOffsetY = 5;
  int myXMargin = 20;
  int myYMargin = 20;
  int myPreferredSize = theMaximumWidth - ( myXMargin * 2 );
  double myActualSize = 0;
  int myBufferSize = 1; //softcode this later
  QColor myBackColor = Qt::white; //used for text
  QColor myForeColor = Qt::black; //used for text

  //Get canvas dimensions
  //int myCanvasHeight = thepMapCanvas->height();

  //Get map units per pixel. This can be negative at times (to do with
  //projections) and that just confuses the rest of the code in this
  //function, so force to a positive number.
  double myMapUnitsPerPixelDouble = qAbs( thepMapRenderer->mapUnitsPerPixel() );
  //
  // Exit if the canvas width is 0 or layercount is 0 or QGIS will freeze
  int myLayerCount = thepMapRenderer->layerSet().count();
  if ( !myLayerCount || !myMapUnitsPerPixelDouble ) return;

  //Calculate size of scale bar for preferred number of map units
  double myScaleBarWidth = myPreferredSize;
  myActualSize = myScaleBarWidth * myMapUnitsPerPixelDouble;


  // Work out the exponent for the number - e.g, 1234 will give 3,
  // and .001234 will give -3
  double myPowerOf10 = floor( log10( myActualSize ) );

  // snap to integer < 10 times power of 10
  if ( mySnappingFlag )
  {
    double scaler = pow( 10.0, myPowerOf10 );
    myActualSize = round( myActualSize / scaler ) * scaler;
    myScaleBarWidth = myActualSize / myMapUnitsPerPixelDouble;
  }

  //Get type of map units and set scale bar unit label text
  QGis::UnitType myMapUnits = thepMapRenderer->mapUnits();
  QString myScaleBarUnitLabel;
  switch ( myMapUnits )
  {
    case QGis::Meters:
      if ( myActualSize > 1000.0 )
      {
        myScaleBarUnitLabel = tr( " km" );
        myActualSize = myActualSize / 1000;
      }
      else if ( myActualSize < 0.01 )
      {
        myScaleBarUnitLabel = tr( " mm" );
        myActualSize = myActualSize * 1000;
      }
      else if ( myActualSize < 0.1 )
      {
        myScaleBarUnitLabel = tr( " cm" );
        myActualSize = myActualSize * 100;
      }
      else
        myScaleBarUnitLabel = tr( " m" );
      break;
    case QGis::Feet:
      if ( myActualSize > 5280.0 ) //5280 feet to the mile
      {
        myScaleBarUnitLabel = tr( " miles" );
        myActualSize = myActualSize / 5280;
      }
      else if ( myActualSize == 5280.0 ) //5280 feet to the mile
      {
        myScaleBarUnitLabel = tr( " mile" );
        myActualSize = myActualSize / 5280;
      }
      else if ( myActualSize < 1 )
      {
        myScaleBarUnitLabel = tr( " inches" );
        myActualSize = myActualSize * 12;
      }
      else if ( myActualSize == 1.0 )
      {
        myScaleBarUnitLabel = tr( " foot" );
      }
      else
      {
        myScaleBarUnitLabel = tr( " feet" );
      }
      break;
    case QGis::Degrees:
      if ( myActualSize == 1.0 )
        myScaleBarUnitLabel = tr( " degree" );
      else
        myScaleBarUnitLabel = tr( " degrees" );
      break;
    case QGis::UnknownUnit:
      myScaleBarUnitLabel = tr( " unknown" );
    default:
      QgsDebugMsg( "Error: not picked up map units - actual value = "
                   + QString::number( myMapUnits ) );
  };

  //Set font and calculate width of unit label
  int myFontSize = 10; //we use this later for buffering
  QFont myFont( "helvetica", myFontSize );
  thepPainter->setFont( myFont );
  QFontMetrics myFontMetrics( myFont );
  double myFontWidth = myFontMetrics.width( myScaleBarUnitLabel );
  double myFontHeight = myFontMetrics.height();

  //Set the maximum label
  QString myScaleBarMaxLabel = QString::number( myActualSize );

  //Calculate total width of scale bar and label
  //we divide by 2 because the max scale label
  //will be centered over the endpoint of the scale bar
  double myTotalScaleBarWidth = myScaleBarWidth + ( myFontWidth / 2 );

  //determine the origin of scale bar (bottom right)
  //for x origin set things up so the scalebar is centered
  int myOriginX = ( theMaximumWidth - myTotalScaleBarWidth ) / 2;
  int myOriginY = myYMargin;

  //Set pen to draw with
  QPen myForegroundPen( mColor, 2 );
  QPen myBackgroundPen( Qt::white, 3 );

  //Cast myScaleBarWidth to int for drawing
  int myScaleBarWidthInt = ( int ) myScaleBarWidth;

  //now draw the bar itself in user selected color
  thepPainter->setPen( myForegroundPen );
  //make a glossygradient for the background
  QGradientStops myStops;
  myStops << QGradientStop( 0.0, QColor( "#616161" ) );
  myStops << QGradientStop( 0.5, QColor( "#505050" ) );
  myStops << QGradientStop( 0.6, QColor( "#434343" ) );
  myStops << QGradientStop( 1.0, QColor( "#656565" ) );
  //draw again with the brush in the revers direction to complete teh glossiness
  QLinearGradient myReverseGlossyBrush(
    QPointF( myOriginX, myOriginY +  myFontHeight*3 ),
    QPointF( myOriginX, myOriginY ) );
  thepPainter->setBrush( myReverseGlossyBrush );
  thepPainter->drawRect(
    myOriginX,
    myOriginY,
    myOriginX + myScaleBarWidthInt,
    myOriginY + myFontHeight
  );

  //
  //Do drawing of scale bar text
  //


  //Draw the minimum label buffer
  thepPainter->setPen( myBackColor );
  myFontWidth = myFontMetrics.width( "0" );

  for ( int i = 0 - myBufferSize; i <= myBufferSize; i++ )
  {
    for ( int j = 0 - myBufferSize; j <= myBufferSize; j++ )
    {
      thepPainter->drawText( int( i + ( myOriginX - ( myFontWidth / 2 ) ) ),
                             int( j + ( myOriginY - ( myFontHeight / 4 ) ) ) - myTextOffsetY,
                             "0" );
    }
  }

  //Draw minimum label
  thepPainter->setPen( myForeColor );

  thepPainter->drawText(
    int( myOriginX - ( myFontWidth / 2 ) ),
    int( myOriginY - ( myFontHeight / 4 ) ) - myTextOffsetY,
    "0"
  );

  //
  //Draw maximum label
  //
  thepPainter->setPen( myBackColor );
  myFontWidth = myFontMetrics.width( myScaleBarMaxLabel );
  myFontHeight = myFontMetrics.height();
  //first the buffer
  for ( int i = 0 - myBufferSize; i <= myBufferSize; i++ )
  {
    for ( int j = 0 - myBufferSize; j <= myBufferSize; j++ )
    {
      thepPainter->drawText( int( i + ( myOriginX + myScaleBarWidthInt - ( myFontWidth / 2 ) ) ),
                             int( j + ( myOriginY - ( myFontHeight / 4 ) ) ) - myTextOffsetY,
                             myScaleBarMaxLabel );
    }
  }
  //then the text itself
  thepPainter->setPen( myForeColor );
  thepPainter->drawText(
    int( myOriginX + myScaleBarWidthInt - ( myFontWidth / 2 ) ),
    int( myOriginY - ( myFontHeight / 4 ) ) - myTextOffsetY,
    myScaleBarMaxLabel
  );

  //
  //Draw unit label
  //
  thepPainter->setPen( myBackColor );
  myFontWidth = myFontMetrics.width( myScaleBarUnitLabel );
  //first the buffer
  for ( int i = 0 - myBufferSize; i <= myBufferSize; i++ )
  {
    for ( int j = 0 - myBufferSize; j <= myBufferSize; j++ )
    {
      thepPainter->drawText( i + ( myOriginX + myScaleBarWidthInt + myTextOffsetX ),
                             j + myOriginY + myFontHeight + ( myFontHeight*2.5 ) + myTextOffsetY,
                             myScaleBarUnitLabel );
    }
  }
  //then the text itself
  thepPainter->setPen( myForeColor );
  thepPainter->drawText(
    myOriginX + myScaleBarWidthInt + myTextOffsetX,
    myOriginY + myFontHeight + ( myFontHeight*2.5 ) +  myTextOffsetY,
    myScaleBarUnitLabel
  );
}
int main(int argc, char** argv)
{
    QApplication app(argc, argv);
    QMainWindow* mw{new QMainWindow()};
    mw->setWindowTitle("scroll event compression test case");
    QToolBar* toolbar{mw->addToolBar("toolbar")};
    QAction* sleep_a_lot_action{new QAction("Sleep A Lot", mw)};
    sleep_a_lot_action->setCheckable(true);
    sleep_a_lot_action->setChecked(false);
    sleep_a_lot_action->setToolTip("When activated, the main thread will attempt to sleep for 999ms intervals with 1ms gaps between naps.\n"
                                   "Shortcut: spacebar");
    sleep_a_lot_action->setShortcut(QKeySequence(Qt::Key_Space));
    sleep_a_lot_action->setShortcutContext(Qt::WindowShortcut);
    QTimer* sleep_a_lot_timer{new QTimer(mw)};
    QObject::connect(sleep_a_lot_action, &QAction::toggled, [&](const bool& is_on){
        if(is_on) sleep_a_lot_timer->start();
        else sleep_a_lot_timer->stop();});
    sleep_a_lot_timer->setSingleShot(false);
    sleep_a_lot_timer->setInterval(1);
    QObject::connect(sleep_a_lot_timer, &QTimer::timeout, [&](){
        std::this_thread::sleep_for(std::chrono::milliseconds(999));
        if(sleep_a_lot_action->isChecked()) sleep_a_lot_timer->start();
    });
    toolbar->addAction(sleep_a_lot_action);
    toolbar->addSeparator();
    QGraphicsScene* gs{new QGraphicsScene(mw)};
    QGraphicsSimpleTextItem* sti{gs->addSimpleText("Move the mouse wheel a few clicks up or down with various combinations of:\n"
                                                   "* \"Sleep A Lot\" enabled/disabled (shortcut to toggle: spacebar).\n"
                                                   "* Mouse held still/mouse moved about.\n\n"
                                                   "Questions whose answers differ for the same version of Qt on various\n"
                                                   "platforms (eg, Win32, X11, Aqua):\n"
                                                   "* With \"Sleep A Lot\" active, are mouse wheel events compressed?\n"
                                                   "* With \"Sleep A Lot\" active, does moving the mouse and the mouse wheel\n"
                                                   "  cause scroll wheel events to be thrown away by compression that are not\n"
                                                   "  thrown away when just the mouse wheel is manipulated?\n"
                                                   "* With \"Sleep A Lot\" active, is it necessary to move the mouse in order\n"
                                                   "  to provoke processing of buffered mouse wheel events?")};
    sti->setBrush(QBrush(Qt::black));
    sti->setPen(QPen(Qt::white));
    {
        QFont f(sti->font());
        f.setBold(true);
        f.setPointSize(36);
        sti->setFont(f);
    }
    gs->setSceneRect(sti->boundingRect());
    QGraphicsEllipseItem* mc{gs->addEllipse(0, 0, 25, 25, QPen(QColor(0, 255, 0, 200)), QBrush(QColor(0, 0, 0, 100)))};
    mc->setFlag(QGraphicsItem::ItemIgnoresTransformations);
    QGraphicsSimpleTextItem* mcsti{gs->addSimpleText("0\n0")};
    mcsti->setBrush(QBrush(Qt::white));
    mcsti->setParentItem(mc);
    mcsti->moveBy(23, 22);
    QGraphicsDropShadowEffect* mcstige{new QGraphicsDropShadowEffect(gs)};
    mcstige->setBlurRadius(10);
    mcstige->setOffset(0, 0);
    mcstige->setColor(Qt::black);
    mcsti->setGraphicsEffect(mcstige);
    TestView* gv{new TestView(gs, mw)};
    QOpenGLWidget* gl_widget = new QOpenGLWidget;
    {
        QSurfaceFormat fmt;
        fmt.setRenderableType(QSurfaceFormat::OpenGL);
        fmt.setProfile(QSurfaceFormat::CompatibilityProfile);
        fmt.setVersion(2, 1);
        fmt.setSamples(4);
        gl_widget->setFormat(fmt);
    }
    gv->setViewport(gl_widget);
    QObject::connect(gv, &TestView::mouse_moved, [&](const QPointF& scene_pos){
        mcsti->setText(QString("%1\n%2").arg(scene_pos.x()).arg(scene_pos.y()));
        qreal zoom{gv->transform().m22()};
        qreal delta{12.5 / zoom};
        mc->setPos(scene_pos.x() - delta, scene_pos.y() - delta);
    });
    gv->setDragMode(QGraphicsView::ScrollHandDrag);
    {
        QLinearGradient g;
        g.setSpread(QGradient::ReflectSpread);
        QGradientStops grad_stops;
        grad_stops.push_back(QGradientStop(0, QColor(Qt::red)));
        grad_stops.push_back(QGradientStop(0.5, QColor(Qt::green)));
        grad_stops.push_back(QGradientStop(1, QColor(Qt::blue)));
        g.setStops(grad_stops);
        QBrush b(g);
        gs->setBackgroundBrush(b);
    }
    mw->setCentralWidget(gv);
    mw->resize(2045, 838);
    mw->show();
    return app.exec();
}