Пример #1
0
void KviTalWizard::setCurrentPage(KviTalWizardPageData * pData)
{
    m_p->pCurrentPage = pData;

    bool bCancelEnabled = true;
    bool bNextEnabled = false;
    bool bBackEnabled = false;
    bool bHelpEnabled = false;
    bool bFinishEnabled = false;

    QString szTitle;
    QString szSteps;

    bool bHaveNextPage = false;
    bool bHavePrevPage = false;

    if(pData)
    {
        bHavePrevPage = m_p->findPrevEnabledPage(pData->pWidget);
        bHaveNextPage = m_p->findNextEnabledPage(pData->pWidget);

        bNextEnabled = (pData->iEnableFlags & KviTalWizardPageData::EnableNext) && bHaveNextPage;
        bBackEnabled = (pData->iEnableFlags & KviTalWizardPageData::EnableBack) && bHavePrevPage;

        bCancelEnabled = (pData->iEnableFlags & KviTalWizardPageData::EnableCancel);
        bFinishEnabled = (pData->iEnableFlags & KviTalWizardPageData::EnableFinish);

        bHelpEnabled = (pData->iEnableFlags & KviTalWizardPageData::EnableHelp);

        m_p->pWidgetStack->setCurrentWidget(pData->pWidget);

        szTitle = "<b>";
        szTitle += pData->szTitle;
        szTitle += "</b>";
        QPalette pal = m_p->pStepsLabel->palette();
        QColor clrWin = pal.color(QPalette::Normal, QPalette::Window);
        QColor clrTxt = pal.color(QPalette::Normal, QPalette::WindowText);
        QColor clrMid = qRgb(
                            (clrWin.red() + clrTxt.red()) / 2,
                            (clrWin.green() + clrTxt.green()) / 2,
                            (clrWin.blue() + clrTxt.blue()) / 2);

        szSteps = "<font color=\"";
        szSteps += clrMid.name();
        szSteps += "\"><b>[";
        szSteps += QString("Step %1 of %2").arg(pData->iVisibleIndex).arg(m_p->iEnabledPageCount);
        szSteps += "]</b></font>";
    }

    m_p->pTitleLabel->setText(szTitle);
    m_p->pStepsLabel->setText(szSteps);

    m_p->pNextButton->setEnabled(bNextEnabled);
    if(bHaveNextPage)
    {
        m_p->pNextButton->show();
        m_p->pNextSpacer->show();
        m_p->pNextButton->setDefault(true);
    }
    else
    {
        m_p->pNextButton->hide();
        m_p->pNextSpacer->hide();
        m_p->pNextButton->setDefault(false);
    }

    m_p->pBackButton->setEnabled(bBackEnabled);
    if(bHavePrevPage)
        m_p->pBackButton->show();
    else
        m_p->pBackButton->hide();

    m_p->pHelpButton->setEnabled(bHelpEnabled);
    if(bHelpEnabled)
        m_p->pHelpButton->show();
    else
        m_p->pHelpButton->hide();

    m_p->pCancelButton->setEnabled(bCancelEnabled);
    m_p->pFinishButton->setEnabled(bFinishEnabled);

    if(bFinishEnabled)
    {
        m_p->pFinishButton->show();
        m_p->pFinishSpacer->show();
        m_p->pFinishButton->setDefault(true);
    }
    else
    {
        m_p->pFinishButton->hide();
        m_p->pFinishSpacer->hide();
        m_p->pFinishButton->setDefault(false);
    }
}
bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) const
{
  if ( itemElem.isNull() )
  {
    return false;
  }

  QDomElement composerItemElem = doc.createElement( "ComposerItem" );

  //frame
  if ( mFrame )
  {
    composerItemElem.setAttribute( "frame", "true" );
  }
  else
  {
    composerItemElem.setAttribute( "frame", "false" );
  }

  //frame
  if ( mBackground )
  {
    composerItemElem.setAttribute( "background", "true" );
  }
  else
  {
    composerItemElem.setAttribute( "background", "false" );
  }

  //scene rect
  composerItemElem.setAttribute( "x", QString::number( transform().dx() ) );
  composerItemElem.setAttribute( "y", QString::number( transform().dy() ) );
  composerItemElem.setAttribute( "width", QString::number( rect().width() ) );
  composerItemElem.setAttribute( "height", QString::number( rect().height() ) );
  composerItemElem.setAttribute( "positionMode", QString::number(( int ) mLastUsedPositionMode ) );
  composerItemElem.setAttribute( "zValue", QString::number( zValue() ) );
  composerItemElem.setAttribute( "outlineWidth", QString::number( pen().widthF() ) );
  composerItemElem.setAttribute( "rotation",  QString::number( mRotation ) );
  composerItemElem.setAttribute( "uuid", mUuid );
  composerItemElem.setAttribute( "id", mId );
  //position lock for mouse moves/resizes
  if ( mItemPositionLocked )
  {
    composerItemElem.setAttribute( "positionLock", "true" );
  }
  else
  {
    composerItemElem.setAttribute( "positionLock", "false" );
  }

  composerItemElem.setAttribute( "lastValidViewScaleFactor", QString::number( mLastValidViewScaleFactor ) );


  //frame color
  QDomElement frameColorElem = doc.createElement( "FrameColor" );
  QColor frameColor = pen().color();
  frameColorElem.setAttribute( "red", QString::number( frameColor.red() ) );
  frameColorElem.setAttribute( "green", QString::number( frameColor.green() ) );
  frameColorElem.setAttribute( "blue", QString::number( frameColor.blue() ) );
  frameColorElem.setAttribute( "alpha", QString::number( frameColor.alpha() ) );
  composerItemElem.appendChild( frameColorElem );

  //background color
  QDomElement bgColorElem = doc.createElement( "BackgroundColor" );
  QColor bgColor = brush().color();
  bgColorElem.setAttribute( "red", QString::number( bgColor.red() ) );
  bgColorElem.setAttribute( "green", QString::number( bgColor.green() ) );
  bgColorElem.setAttribute( "blue", QString::number( bgColor.blue() ) );
  bgColorElem.setAttribute( "alpha", QString::number( bgColor.alpha() ) );
  composerItemElem.appendChild( bgColorElem );

  //blend mode
  composerItemElem.setAttribute( "blendMode", QgsMapRenderer::getBlendModeEnum( mBlendMode ) );

  //transparency
  composerItemElem.setAttribute( "transparency", QString::number( mTransparency ) );

  itemElem.appendChild( composerItemElem );

  return true;
}
Пример #3
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));


}
Пример #4
0
void CodeAtlas::RandomWalkClusterer::writeToGephi( char* fileName )
{
	ofstream file(fileName);
	file << 
		"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
		"<gexf xmlns=\"http://www.gexf.net/1.2draft\" version=\"1.2\" xmlns:viz=\"http://www.gexf.net/1.2draft/viz\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd\">\n"
		"<meta lastmodifieddate=\"2015-07-06\">\n"
		"<creator>Gephi 0.8.1</creator>\n"
		"<description></description>\n"
		"</meta>\n"
		"<graph defaultedgetype=\"directed\" mode=\"static\">\n";

	// write nodes
	file << "    <nodes>\n";
	for (int ithNode = 0; ithNode < m_vtx.size(); ++ithNode)
	{
		char buf[200];
		QColor c = QColor::fromHsv((m_vtx[ithNode].m_clusterID * 43)%359, 255, 255);
		sprintf(buf,       
			"<node id=\"%d\" label=\"%d\">\n"
			"<attvalues></attvalues>\n"
			"<viz:size value=\"1.0\"></viz:size>\n"
			"<viz:color r=\"%d\" g=\"%d\" b=\"%d\"></viz:color>\n"
			"</node>\n",
			ithNode, ithNode,
			c.red(), c.green(), c.blue());
		file << buf;
	}
	file << "    </nodes>\n";

	// write edges
	file << "    <edges>\n";
	int e = 0;
	for (int ithNode = 0; ithNode < m_vtx.size(); ++ithNode)
	{
		char buf[200];
		Vertex& v = m_vtx[ithNode];
		typedef QHash<int, float> EdgeMap;
		/*
		for (EdgeMap::Iterator pE = v.m_inEdge.begin(); pE != v.m_inEdge.end(); ++pE, ++e)
		{
			sprintf(buf, 
				"<edge source=\"%d\" target=\"%d\" label=\"%d\">\n"
				"<attvalues></attvalues>\n"
				"</edge>\n", pE.key(), ithNode, e);
			file << buf;
		}*/
		for (EdgeMap::Iterator pE = v.m_outEdge.begin(); pE != v.m_outEdge.end(); ++pE, ++e)
		{
			sprintf(buf, 
				"<edge source=\"%d\" target=\"%d\" label=\"%d\">\n"
				"<attvalues></attvalues>\n"
				"</edge>\n", ithNode, pE.key(), e);
			file << buf;
		}
	}
	file << "    </edges>\n";

	file << "  </graph>\n"
		"</gexf>";

	file.close();
}
void ScalarColourRangeMapper::setMaxColour( const QColor& c) { _cols[2] = cv::Vec3b( c.red(), c.green(), c.blue());}
Пример #6
0
//when user clicks apply button
void QgsProjectProperties::apply()
{
  // Set the map units
  // Note. Qt 3.2.3 and greater have a function selectedId() that
  // can be used instead of the two part technique here
  QGis::UnitType mapUnit;
  if ( radMeters->isChecked() )
  {
    mapUnit = QGis::Meters;
  }
  else if ( radFeet->isChecked() )
  {
    mapUnit = QGis::Feet;
  }
  else if ( radDMS->isChecked() )
  {
    mapUnit = QGis::DegreesMinutesSeconds;
  }
  else
  {
    mapUnit = QGis::Degrees;
  }

  QgsMapRenderer* myRender = mMapCanvas->mapRenderer();

  myRender->setMapUnits( mapUnit );

  myRender->setProjectionsEnabled( cbxProjectionEnabled->isChecked() );

  // Only change the projection if there is a node in the tree
  // selected that has an srid. This prevents error if the user
  // selects a top-level node rather than an actual coordinate
  // system
  long myCRSID = projectionSelector->selectedCrsId();
  if ( myCRSID )
  {
    QgsCoordinateReferenceSystem srs( myCRSID, QgsCoordinateReferenceSystem::InternalCrsId );
    myRender->setDestinationSrs( srs );
    QgsDebugMsg( QString( "Selected CRS " ) + srs.description() );
    // write the currently selected projections _proj string_ to project settings
    QgsDebugMsg( QString( "SpatialRefSys/ProjectCRSProj4String: %1" ).arg( projectionSelector->selectedProj4String() ) );
    QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", projectionSelector->selectedProj4String() );

    // Set the map units to the projected coordinates if we are projecting
    if ( isProjected() )
    {
      // If we couldn't get the map units, default to the value in the
      // projectproperties dialog box (set above)
      if ( srs.mapUnits() != QGis::UnknownUnit )
        myRender->setMapUnits( srs.mapUnits() );
    }
  }

  // Set the project title
  QgsProject::instance()->title( title() );

  // set the mouse display precision method and the
  // number of decimal places for the manual option
  // Note. Qt 3.2.3 and greater have a function selectedId() that
  // can be used instead of the two part technique here
  QgsProject::instance()->writeEntry( "PositionPrecision", "/Automatic", radAutomatic->isChecked() );
  QgsProject::instance()->writeEntry( "PositionPrecision", "/DecimalPlaces", spinBoxDP->value() );
  // Announce that we may have a new display precision setting
  emit displayPrecisionChanged();

  QgsProject::instance()->writeEntry( "Paths", "/Absolute", cbxAbsolutePath->currentIndex() == 0 );

  //set the color for selections
  QColor myColor = pbnSelectionColor->color();
  QgsProject::instance()->writeEntry( "Gui", "/SelectionColorRedPart", myColor.red() );
  QgsProject::instance()->writeEntry( "Gui", "/SelectionColorGreenPart", myColor.green() );
  QgsProject::instance()->writeEntry( "Gui", "/SelectionColorBluePart", myColor.blue() );
  QgsProject::instance()->writeEntry( "Gui", "/SelectionColorAlphaPart", myColor.alpha() );
  QgsRenderer::setSelectionColor( myColor );

  //set the color for canvas
  myColor = pbnCanvasColor->color();
  QgsProject::instance()->writeEntry( "Gui", "/CanvasColorRedPart", myColor.red() );
  QgsProject::instance()->writeEntry( "Gui", "/CanvasColorGreenPart", myColor.green() );
  QgsProject::instance()->writeEntry( "Gui", "/CanvasColorBluePart", myColor.blue() );

  QStringList noIdentifyLayerList;
  for ( int i = 0; i < twIdentifyLayers->rowCount(); i++ )
  {
    QCheckBox *cb = qobject_cast<QCheckBox *>( twIdentifyLayers->cellWidget( i, 2 ) );
    if ( cb && !cb->isChecked() )
    {
      QString id = twIdentifyLayers->item( i, 0 )->data( Qt::UserRole ).toString();
      noIdentifyLayerList << id;
    }
  }

  QgsProject::instance()->writeEntry( "Identify", "/disabledLayers", noIdentifyLayerList );

  //todo XXX set canvas color
  emit refresh();
}
Пример #7
0
	Color::Color(const QColor &c) : owner(false) {
		init(c.red(), c.green(), c.blue(), c.alpha());
	}
QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle  const & extent, int width, int height )
{
  QgsRasterBlock *outputBlock = new QgsRasterBlock();
  if ( !mInput || mNColors == 0 )
  {
    return outputBlock;
  }

  QgsRasterBlock *inputBlock = mInput->block( bandNo, extent, width, height );

  if ( !inputBlock || inputBlock->isEmpty() )
  {
    QgsDebugMsg( "No raster data!" );
    delete inputBlock;
    return outputBlock;
  }

  double currentOpacity = mOpacity;

  //rendering is faster without considering user-defined transparency
  bool hasTransparency = usesTransparency();
  QgsRasterBlock *alphaBlock = nullptr;

  if ( mAlphaBand > 0 && mAlphaBand != mBand )
  {
    alphaBlock = mInput->block( mAlphaBand, extent, width, height );
    if ( !alphaBlock || alphaBlock->isEmpty() )
    {
      delete inputBlock;
      delete alphaBlock;
      return outputBlock;
    }
  }
  else if ( mAlphaBand == mBand )
  {
    alphaBlock = inputBlock;
  }

  if ( !outputBlock->reset( QGis::ARGB32_Premultiplied, width, height ) )
  {
    delete inputBlock;
    delete alphaBlock;
    return outputBlock;
  }

  QRgb myDefaultColor = NODATA_COLOR;

  //use direct data access instead of QgsRasterBlock::setValue
  //because of performance
  unsigned int* outputData = ( unsigned int* )( outputBlock->bits() );

  qgssize rasterSize = ( qgssize )width * height;
  for ( qgssize i = 0; i < rasterSize; ++i )
  {
    if ( inputBlock->isNoData( i ) )
    {
      outputData[i] = myDefaultColor;
      continue;
    }
    int val = ( int ) inputBlock->value( i );
    if ( !hasTransparency )
    {
      outputData[i] = mColors[val];
    }
    else
    {
      currentOpacity = mOpacity;
      if ( mRasterTransparency )
      {
        currentOpacity = mRasterTransparency->alphaValue( val, mOpacity * 255 ) / 255.0;
      }
      if ( mAlphaBand > 0 )
      {
        currentOpacity *=  alphaBlock->value( i ) / 255.0;
      }
      QColor currentColor = QColor( mColors[val] );
      outputData[i] = qRgba( currentOpacity * currentColor.red(), currentOpacity * currentColor.green(), currentOpacity * currentColor.blue(), currentOpacity * 255 );
    }
  }

  delete inputBlock;
  if ( mAlphaBand > 0 && mBand != mAlphaBand )
  {
    delete alphaBlock;
  }

  return outputBlock;
}
Пример #9
0
bool DomConvenience::variantToElement(const QVariant& v, QDomElement& e)
{
  bool ok = true;

  clearAttributes(e);

  switch (v.type())
  {
  case QVariant::String:
    e.setTagName("string");
    e.setAttribute("value", v.toString().utf8());
    break;
  case QVariant::CString:
    e.setTagName("string");
    e.setAttribute("value", v.toCString());
    break;
  case QVariant::Int:
    e.setTagName("int");
    e.setAttribute("value", v.toInt());
    break;
  case QVariant::UInt:
    e.setTagName("uint");
    e.setAttribute("value", v.toUInt());
    break;
  case QVariant::Double:
    e.setTagName("double");
    e.setAttribute("value", v.toDouble());
    break;
  case QVariant::Bool:
    e.setTagName("bool");
    e.setAttribute("value", boolString(v.toBool()));
    break;
  case QVariant::Color:
    {
      e.setTagName("color");
      QColor color = v.toColor();
      e.setAttribute("red", color.red());
      e.setAttribute("green", color.green());
      e.setAttribute("blue", color.blue());
    }
    break;
  case QVariant::Point:
    {
      e.setTagName("point");
      QPoint point = v.toPoint();
      e.setAttribute("x", point.x());
      e.setAttribute("y", point.y());
    }
    break;
  case QVariant::Rect:
    {
      e.setTagName("rect");
      QRect rect = v.toRect();
      e.setAttribute("x", rect.x());
      e.setAttribute("y", rect.y());
      e.setAttribute("width", rect.width());
      e.setAttribute("height", rect.height());
    }
    break;
  case QVariant::Size:
    {
      e.setTagName("size");
      QSize qsize = v.toSize();
      e.setAttribute("width", qsize.width());
      e.setAttribute("height", qsize.height());
    }
    break;
  case QVariant::Font:
    {
      e.setTagName("font");
      QFont f(v.toFont());
      e.setAttribute("family", f.family());
      e.setAttribute("pointsize", f.pointSize());
      e.setAttribute("bold", boolString(f.bold()));
      e.setAttribute("italic", boolString(f.italic()));
      e.setAttribute("underline", boolString(f.underline()));
      e.setAttribute("strikeout", boolString(f.strikeOut()));
    }
    break;
  case QVariant::SizePolicy:
    {
      e.setTagName("sizepolicy");
      QSizePolicy sp(v.toSizePolicy());
      e.setAttribute("hsizetype", sp.horData());
      e.setAttribute("vsizetype", sp.verData());
#if (QT_VERSION >= 300)
      e.setAttribute("horstretch", sp.horStretch());
      e.setAttribute("verstretch", sp.verStretch());
#endif
    }
    break;
  case QVariant::Cursor:
    e.setTagName("cursor");
    e.setAttribute("shape", v.toCursor().shape());
    break;

  case QVariant::StringList:
    {
      e.setTagName("stringlist");
      uint j;
      
      QDomNode n;
      QDomNodeList stringNodeList = e.elementsByTagName("string");
      QDomElement stringElem;
      QStringList stringList = v.toStringList();
      QStringList::Iterator it = stringList.begin();

      for (j = 0; 
	   ((j < stringNodeList.length()) && (it != stringList.end()));
	   j++)
      {
	// get the current string element
	stringElem = stringNodeList.item(j).toElement();

	// set it to the current string
	variantToElement(QVariant(*it), stringElem);

	// iterate to the next string
	++it;
      }
      
      // more nodes in previous stringlist then current, remove excess nodes
      if (stringNodeList.count() > stringList.count())
      {
	while (j < stringNodeList.count())
	  e.removeChild(stringNodeList.item(j).toElement());
      }
      else if (j <stringList.count())
      {
	while (it != stringList.end())
	{
	  // create a new element
	  stringElem = m_doc.createElement("string");
	
	  // set it to the currentstring
	  variantToElement(QVariant(*it), stringElem);

	  // append it to the current element
	  e.appendChild(stringElem);

	  // iterate to the next string
	  ++it;
	}
      }
    }
    break;

#if QT_VERSION >= 300
  case QVariant::KeySequence:
    e.setTagName("key");
    e.setAttribute("sequence", (QString)v.toKeySequence());
    break;
#endif

#if 0
  case QVariant::List:
  case QVaraint::Map:
#endif
  default:
    qWarning("Don't know how to persist variant of type: %s (%d)!",
	     v.typeName(), v.type());
    ok = false;
    break;
  }

  return ok;
}
Пример #10
0
std::vector<EnvObject *> Servant::buildEnvironment(std::pair<int, int> mapSize)
{
    std::vector<EnvObject *> *environment = new std::vector<EnvObject *>();

    // Scan /robots/ directory for configuration files
    QStringList filters;
    filters << QString("????.env");
    QDir directory("robots/");
    QStringList files = directory.entryList(filters);

    // Choose only first file
    QString configFilename = "";
    for (int i = 0; i < files.size(); i++) {
        if (files.at(i).contains(QRegExp(QString("^(\\d){4}.env$")))) {
            configFilename = files.at(i);
            break;
        }
    }

    if (configFilename.isEmpty()) {
        qDebug() << "Cannot find configuration file for the environment";
        return *environment;
    }

    // Load file contents (without commented strings) to configStringList
    QFile config(QString("robots/") + configFilename);
    QStringList configStringList = QStringList();
    if (!config.open(QFile::ReadOnly)) {
        qDebug() << "Cannot open configuration file for the environment";
        return *environment;
    }
    QTextStream stream (&config);
    QString line;
    while(!stream.atEnd()) {
        line = stream.readLine();
        if (!line.contains(QRegExp("^(//)")) && !line.isEmpty())
            configStringList.append(line);
    }
    config.close();

    // check launch command
    if (configStringList.at(0).isEmpty()) {
        qDebug() << "Launch command is empty!";
        return *environment;
    }

    // check port
    int portFilename = configFilename.left(4).toInt();
    if (portFilename == 0 || portFilename != configStringList.at(1).toInt()) {
        qDebug() << "Ports in filename and file body aren't equal!";
        return *environment;
    }
    EnvObject::setPortNumber(portFilename);

    // start parsing each object
    const int parametersQuantityPerObject = 8;      // See AI-simulator wiki
    QVector<int> indexes = QVector<int>();
    for (int obj = 0; obj < ENV_OBJECTS; obj++) {
        EnvObject *envObject = new EnvObject();

        if (configStringList.size() < 2 + (obj+1) * parametersQuantityPerObject)
            break;
        QStringList objectParams = QStringList();
        for (int i = 0; i < parametersQuantityPerObject; i++)
            objectParams.push_back(configStringList.at(2 + obj * parametersQuantityPerObject + i));
        bool ok = true;

        // Check object id
        int index = objectParams.at(0).toInt(&ok);
        if (!ok || index < 0) {
            qDebug() << "Id must be non-negative integer number (object" << obj << ")";
            return * environment;
        }
        if (indexes.contains(index)) {
            qDebug() << "Object with same id already exists (object" << obj << ")";
            return *environment;
        }

        // Check object start position
        QString pos = objectParams.at(1);
        if (!pos.contains(QRegExp("^(\\d)+;(\\d)+$")) && pos != QString("-1;-1")) {
            qDebug() << "Invalid start position (object" << obj << ")";
            return *environment;
        }
        int x, y;
        if (pos != QString("-1;-1"))
        {
            x = pos.split(";").at(0).toInt(&ok);
            if (!ok) {
                qDebug() << "Invalid start position (object" << obj << ")";
                return *environment;
            }
            y = pos.split(";").at(1).toInt(&ok);
            if (!ok) {
                qDebug() << "Invalid start position (object" << obj << ")";
                return *environment;
            }
            if (x < 0 || y < 0
                    || x >= mapSize.first * REAL_PIXEL_SIZE
                    || y >= mapSize.second * REAL_PIXEL_SIZE) {
                qDebug() << "Start position is out of the map (object" << obj << ")";
                return *environment;
            }
        } else {
            /*
            srand(static_cast<unsigned int>(time(0)));
            x = rand() % (mapSize.first * REAL_PIXEL_SIZE);
            y = rand() % (mapSize.second * REAL_PIXEL_SIZE);
            qDebug() << "Object" << obj << "receives random coordinates (" << x << "," << y << ")";
            */
            // coordinates must be generated in the environment app
            x = 0;
            y = 0;
        }

        // Check if size is a number and is over than zero
        int size = objectParams.at(2).toInt();
        if (size <= 0) {
            qDebug() << "Invalid size (object" << obj << ")";
            return *environment;
        }

        // Check intersection type
        QString intersection = objectParams.at(3);
        if (intersection != "0" && intersection != "1" && intersection != "2") {
            qDebug() << "Invalid intersection type (object" << obj << ")";
            return *environment;
        }

        bool movable;
        if (objectParams.at(4) == QString("0"))
            movable = false;
        else if (objectParams.at(4) == QString("1"))
            movable = true;
        else {
            qDebug() << "Movable parameter can receive only 0 or 1 (object" << obj << ")";
            return *environment;
        }

        // Check orientation
        int orientation = objectParams.at(5).toDouble(&ok);
        if (!ok || orientation < 0) {
            qDebug() << "Invalid orientation (object" << obj << ")";
            return *environment;
        }

        int velocity = objectParams.at(6).toInt();
        if (velocity <= 0) {
            qDebug() << "Invalid velocity (object" << obj << ")";
            return *environment;
        }

        // Check color
        QColor color = QColor(objectParams.at(7));
        if (!color.isValid()) {
            qDebug() << "Invalid color (object" << obj << ")";
            return *environment;
        }

        indexes.push_back(index);
        envObject->setObjectId(index);
        envObject->setCoords(x, y);
        envObject->setSize(size);
        envObject->setIntersection(static_cast<Intersection>(intersection.toInt()));
        envObject->setMovable(movable);
        envObject->setOrientation(orientation);
        envObject->setVelocity(velocity);
        envObject->setColor(Color(color.red(), color.green(), color.blue()));
        environment->push_back(envObject);
    }

    QString command = configStringList.at(0) + QString(" ") + configFilename + QString(" ")
            + QString("%1").arg(mapSize.first) + QString(" ") + QString("%1").arg(mapSize.second);
    qDebug() << "Environment will be called by command" << command;
    //ProcessContainer::getInstance().addApplication(command);

    return *environment;
}
Пример #11
0
void
AnimatingTextEdit::refreshStylesheet()
{

    double bgColor[3];
    bool bgColorSet = false;

    if (multipleSelection) {
        bgColor[0] = bgColor[1] = bgColor[2] = 0;
        bgColorSet = true;
    }

    if (!bgColorSet) {
        // draw the background with
        // a color reflecting the animation level
        switch ((AnimationLevelEnum)animation) {
            case eAnimationLevelExpression:
                appPTR->getCurrentSettings()->getExprColor(&bgColor[0], &bgColor[1], &bgColor[2]);
                bgColorSet = true;
                break;
            case eAnimationLevelInterpolatedValue:
                appPTR->getCurrentSettings()->getInterpolatedColor(&bgColor[0], &bgColor[1], &bgColor[2]);
                bgColorSet = true;
                break;
            case eAnimationLevelOnKeyframe:
                appPTR->getCurrentSettings()->getKeyframeColor(&bgColor[0], &bgColor[1], &bgColor[2]);
                bgColorSet = true;
                break;
            case eAnimationLevelNone:
                break;
        }
    }

    double fgColor[3];
    bool fgColorSet = false;
    if (!isEnabled() || isReadOnly() || (AnimationLevelEnum)animation == eAnimationLevelExpression) {
        fgColor[0] = fgColor[1] = fgColor[2] = 0.;
        fgColorSet = true;
    }

    QString bgColorStyleSheetStr;
    if (bgColorSet) {
        QColor bgCol;
        bgCol.setRgbF(Image::clamp(bgColor[0], 0., 1.), Image::clamp(bgColor[1], 0., 1.), Image::clamp(bgColor[2], 0., 1.));
        bgColorStyleSheetStr = QString::fromUtf8("background-color: rgb(%1, %2, %3);").arg(bgCol.red()).arg(bgCol.green()).arg(bgCol.blue())
        ;

    }


    if (fgColorSet) {
        QColor fgCol;
        fgCol.setRgbF(Image::clamp(fgColor[0], 0., 1.), Image::clamp(fgColor[1], 0., 1.), Image::clamp(fgColor[2], 0., 1.));

        setStyleSheet(QString::fromUtf8("QTextEdit {\n"
                                        "color: rgb(%1, %2, %3);\n"
                                        "%4\n"
                                        "}\n").arg(fgCol.red()).arg(fgCol.green()).arg(fgCol.blue()).arg(bgColorStyleSheetStr));

    }


    style()->unpolish(this);
    style()->polish(this);
    update();
}
Пример #12
0
Robot * Servant::buildRobot(unsigned int number)
{
    Robot *robot = new Robot();

    // Scan /robots/ directory for configuration files
    QStringList filters;
    filters << QString("????.%1.ini").arg(number);
    QDir directory("robots/");
    QStringList files = directory.entryList(filters);

    // Choose only first file
    QString configFilename = "";
    for (int i = 0; i < files.size(); i++) {
        if (files.at(i).contains(QRegExp(QString("^(\\d){4}.%1.ini$").arg(number)))) {
            configFilename = files.at(i);
            break;
        }
    }

    if (configFilename.isEmpty()) {
        qDebug() << "Cannot find configuration file for robot" << number;
        return robot;
    }

    QSettings settings("robots/" + configFilename, QSettings::IniFormat);

    /* Robot main parameters */
    settings.beginGroup("robot");
    int x = settings.value("startX").toInt();
    int y = settings.value("startY").toInt();
    int size = settings.value("size").toInt();
    int portNumber = settings.value("port").toInt();
    int type = settings.value("type").toInt();
    int visibilityRadius = settings.value("visibilityRadius").toInt();
    int visibilityAngle = settings.value("visibilityAngle").toInt();
    int orientation = settings.value("orientation").toInt();
    QColor color = QColor(settings.value("color").toString());
    int intersection = settings.value("intersection").toInt();
    int scaling = settings.value("localMapScaling").toInt();
    settings.endGroup();

    /* Custom parameters */
    settings.beginGroup("robot_custom_params");
    std::pair<std::string, double> parameters[CUSTOM_PARAMETERS_QUANTITY];

    const QStringList childKeys = settings.childKeys();
    for (int i = 0; i < CUSTOM_PARAMETERS_QUANTITY; i++) {
        parameters[i].first = childKeys.at(i).toStdString();
        parameters[i].second = settings.value(childKeys.at(i)).toInt();
    }
    settings.endGroup();

    robot->setCoords(x, y);
    robot->setSize(size);
    robot->setPortNumber(portNumber);
    robot->setType(static_cast<RobotType>(type));
    robot->setVisibilityRadius(visibilityRadius);
    robot->setVisibilityAngle(visibilityAngle);
    robot->setOrientation(orientation);
    robot->setColor(Color(color.red(), color.green(), color.blue()));
    robot->setIntersection(static_cast<Intersection>(intersection));
    robot->setParameters(parameters);

    this->scaling[number] = scaling;

    // TODO: fix this shit - configFilename.left(6)
    QString command = settings.value("robot/launch").toString() + QString(" ") + configFilename.left(6);
    qDebug() << "Robot" << number << "will be called by command" << command;
    ProcessContainer::getInstance().addApplication(command);

    return robot;
}
void tst_QColor::setRgb()
{
    QColor color;

    for (int A = 0; A <= USHRT_MAX; ++A) {
        {
            // 0-255
            int a = A >> 8;
            QRgb rgb = qRgba(0, 0, 0, a);

            color.setRgb(0, 0, 0, a);
            QCOMPARE(color.alpha(), a);
            QCOMPARE(color.rgb(),  qRgb(0, 0, 0));

            color.setRgb(rgb);
            QCOMPARE(color.alpha(), 255);
            QCOMPARE(color.rgb(),   qRgb(0, 0, 0));

            int r, g, b, a2;
            color.setRgb(0, 0, 0, a);
            color.getRgb(&r, &g, &b, &a2);
            QCOMPARE(a2, a);

            QColor c(0, 0, 0);
            c.setAlpha(a);
            QCOMPARE(c.alpha(), a);
        }

        {
            // 0.0-1.0
            qreal a = A / qreal(USHRT_MAX);
            color.setRgbF(0.0, 0.0, 0.0, a);
            QCOMPARE(color.alphaF(), a);

            qreal r, g, b, a2;
            color.getRgbF(&r, &g, &b, &a2);
            QCOMPARE(a2, a);

            QColor c(0, 0, 0);
            c.setAlphaF(a);

            QCOMPARE(c.alphaF(), a);
        }
    }

    for (int R = 0; R <= USHRT_MAX; ++R) {
        {
            // 0-255
            int r = R >> 8;
            QRgb rgb = qRgb(r, 0, 0);

            color.setRgb(r, 0, 0);
            QCOMPARE(color.red(), r);
            QCOMPARE(color.rgb(), rgb);

            color.setRgb(rgb);
            QCOMPARE(color.red(), r);
            QCOMPARE(color.rgb(), rgb);

            int r2, g, b, a;
            color.getRgb(&r2, &g, &b, &a);
            QCOMPARE(r2, r);
        }

        {
            // 0.0-1.0
            qreal r = R / qreal(USHRT_MAX);
            color.setRgbF(r, 0.0, 0.0);
            QCOMPARE(color.redF(), r);

            qreal r2, g, b, a;
            color.getRgbF(&r2, &g, &b, &a);
            QCOMPARE(r2, r);
        }
    }

    for (int G = 0; G <= USHRT_MAX; ++G) {
        {
            // 0-255
            int g = G >> 8;
            QRgb rgb = qRgb(0, g, 0);

            color.setRgb(0, g, 0);
            QCOMPARE(color.green(), g);
            QCOMPARE(color.rgb(),   rgb);

            color.setRgb(rgb);
            QCOMPARE(color.green(), g);
            QCOMPARE(color.rgb(),   rgb);

            int r, g2, b, a;
            color.getRgb(&r, &g2, &b, &a);
            QCOMPARE(g2, g);
        }

        {
            // 0.0-1.0
            qreal g = G / qreal(USHRT_MAX);
            color.setRgbF(0.0, g, 0.0);
            QCOMPARE(color.greenF(), g);

            qreal r, g2, b, a;
            color.getRgbF(&r, &g2, &b, &a);
            QCOMPARE(g2, g);
        }
    }

    for (int B = 0; B <= USHRT_MAX; ++B) {
        {
            // 0-255
            int b = B >> 8;
            QRgb rgb = qRgb(0, 0, b);

            color.setRgb(0, 0, b);
            QCOMPARE(color.blue(),  b);
            QCOMPARE(color.rgb(),   rgb);

            color.setRgb(rgb);
            QCOMPARE(color.blue(),  b);
            QCOMPARE(color.rgb(),   rgb);

            int r, g, b2, a;
            color.getRgb(&r, &g, &b2, &a);
            QCOMPARE(b2, b);
        }

        {
            // 0.0-1.0
            qreal b = B / qreal(USHRT_MAX);
            color.setRgbF(0.0, 0.0, b);
            QCOMPARE(color.blueF(), b);

            qreal r, g, b2, a;
            color.getRgbF(&r, &g, &b2, &a);
            QCOMPARE(b2, b);
        }
    }
}
Пример #14
0
void BBTCOView::paintEvent( QPaintEvent * )
{
	QPainter p( this );

	QColor col;
	if( m_bbTCO->getTrack()->isMuted() || m_bbTCO->isMuted() )
	{
		col = QColor( 160, 160, 160 );
	}
	else if ( m_bbTCO->m_useStyleColor )
	{
		col =  p.pen().brush().color();
	}
	else
	{
		col = m_bbTCO->colorObj();
	}

	if( isSelected() == true )
	{
		col.setRgb( qMax( col.red() - 128, 0 ), qMax( col.green() - 128, 0 ), 255 );
	}

	QLinearGradient lingrad( 0, 0, 0, height() );
	lingrad.setColorAt( 0, col.light( 130 ) );
	lingrad.setColorAt( 1, col.light( 70 ) );
	p.fillRect( rect(), lingrad );

	tact_t t = Engine::getBBTrackContainer()->lengthOfBB( m_bbTCO->bbTrackIndex() );
	if( m_bbTCO->length() > MidiTime::ticksPerTact() && t > 0 )
	{
		for( int x = static_cast<int>( t * pixelsPerTact() );
								x < width()-2;
			x += static_cast<int>( t * pixelsPerTact() ) )
		{
			p.setPen( col.light( 80 ) );
			p.drawLine( x, 1, x, 5 );
			p.setPen( col.light( 120 ) );
			p.drawLine( x, height() - 6, x, height() - 2 );
		}
	}

	p.setPen( col.lighter( 130 ) );
	p.drawRect( 1, 1, rect().right()-2, rect().bottom()-2 );

	p.setPen( col.darker( 300 ) );
	p.drawRect( 0, 0, rect().right(), rect().bottom() );

	p.setFont( pointSize<8>( p.font() ) );
	
	p.setPen( QColor( 0, 0, 0 ) );
	p.drawText( 4, p.fontMetrics().height()+1, m_bbTCO->name() );
	p.setPen( textColor() );
	p.drawText( 3, p.fontMetrics().height(), m_bbTCO->name() );
	
	if( m_bbTCO->isMuted() )
	{
		p.drawPixmap( 3, p.fontMetrics().height() + 1,
				embed::getIconPixmap( "muted", 16, 16 ) );
	}
}
Пример #15
0
void MainWindow::colorStripes()
{
	QColor color;
	int x, y;

	int number = 0;
	bool onOff = false;

	int width = 100;
	int height = 100;

	int stepSize = 16;


	std::default_random_engine generator;
	std::normal_distribution<double> onDistribution(30.0,10.0);
	std::normal_distribution<double> offDistribution(40.0,20.0);
	QVector<QColor*> *colorVector;
	colorVector = computeGoldenRatioColors(0.01,0.7,1,100);

	motorControl.openShutter();
	for (y=0;y!=height;++y) {
		for(x=0;x!=width; x++) {
			motorControl.setLedColor(color);
			if (number<=0) {
				if(onOff) {
					color.setRed(0);
					color.setGreen(0);
					color.setBlue(0);
					motorControl.setLedColor(color);
					onOff = false;
					number = int(offDistribution(generator));
				} else {
					QColor *pColor = colorVector->at(rand() % 100);
					color.setRed(pColor->red());
					color.setGreen(pColor->green());
					color.setBlue(pColor->blue());

					motorControl.setLedColor(color);
					onOff = true;
					number = int(onDistribution(generator));
				}
			}

			motorControl.commandMotor1(3, -stepSize);


			number--;

		}
		motorControl.setLedColor(QColor(0,0,0));
		motorControl.commandMotor1(3, stepSize * width);		

		motorControl.commandMotor2(6, -stepSize);
	}
	motorControl.closeShutter();


	// Reset x axis to initial position if the width is uneven
	if( width%2 != 0) {
		motorControl.commandMotor1(6, stepSize * width);
	}

	// Reset y axis to initial position
	motorControl.commandMotor2(6, stepSize * height);

	motorControl.releaseMotor1();
	motorControl.releaseMotor2();
}
Пример #16
0
void ThumbnailRunnable::run()
{
    emit started(this->item);

    QColor c;

    argv0Array = this->item->getFilePath().toString().toLocal8Bit();
    parameters.gb_argv0 = argv0Array.data();

    parameters.gb_a_ratio = GB_A_RATIO;
    parameters.gb_C_cut = GB_C_CUT;
    parameters.gb_h_height = 0;
    parameters.gb_I_individual = GB_I_INDIVIDUAL;
    parameters.gb_z_seek    = GB_Z_SEEK;
    parameters.gb_Z_nonseek = GB_Z_NONSEEK;
    parameters.gb_s_step    = GB_S_STEP;
    parameters.gb_O_format = main_window->mpDockConf->getFormatFileCode();
    parameters.gb_r_row     = main_window->mpDockConf->getRows();
    parameters.gb_c_column  = main_window->mpDockConf->getColumns();
    parameters.gb_w_width   = main_window->mpDockConf->getWidth();
    parameters.gb_g_gap     = main_window->mpDockConf->getGap();
    parameters.gb_j_quality = main_window->mpDockConf->getQuality();
    parameters.gb_b_blank   = main_window->mpDockConf->getBlankSkip();
    parameters.gb_D_edge    = GB_D_EDGE;
    parameters.gb_L_info_location = main_window->mpDockStyles->getInfoTextLocation();
    parameters.gb_L_time_location = main_window->mpDockStyles->getTimeStampLocation();
    c = main_window->mpDockStyles->getColorBackground();
    parameters.gb_k_bcolor   = (rgb_color) {c.red(), c.green(), c.blue()};

    f_fontnameArray = main_window->mpDockStyles->getFontInfoText(0).toLocal8Bit();
    parameters.gb_f_fontname = f_fontnameArray.data();

    c = main_window->mpDockStyles->getColorInfoText();
    parameters.gb_F_info_color = (rgb_color) {c.red(), c.green(), c.blue()};
    parameters.gb_F_info_font_size = main_window->mpDockStyles->getSizeInfoText();

    if(main_window->mpDockStyles->isTimeStampChecked())
    {
         parameters.gb_t_timestamp = 1;
         F_ts_fontnameArray = main_window->mpDockStyles->getFontTimeStamp(2).toLocal8Bit();
         parameters.gb_F_ts_fontname  = F_ts_fontnameArray.data();
         c = main_window->mpDockStyles->getColorTimeStamp();
         parameters.gb_F_ts_color     = (rgb_color) {c.red(), c.green(), c.blue()};
         c = main_window->mpDockStyles->getColorShadow();
         parameters.gb_F_ts_shadow    = (rgb_color) {c.red(), c.green(), c.blue()};
         parameters.gb_F_ts_font_size = main_window->mpDockStyles->getSizeTimeStamp();
    }
    else parameters.gb_t_timestamp = 0;

    if(this->modeConversion == ThumbnailEngine::SIMPLEMOD && !main_window->mpDockInputOutput->isSameSourceChecked())
    {
        O_outdir = main_window->mpDockInputOutput->getPathOutput().toLocal8Bit();
        parameters.gb_O_outdir = O_outdir.data();

        if(!this->suffix.isEmpty())
        {
           o_suffixArray = QString(this->suffix + "." + this->main_window->mpDockConf->getFormatFile()).toLocal8Bit();
           parameters.gb_o_suffix = o_suffixArray.data();
        }
        else
        {
            o_suffixArray = QString("." + this->main_window->mpDockConf->getFormatFile()).toLocal8Bit();
            parameters.gb_o_suffix = o_suffixArray.data();
        }
    }
    else if (this->modeConversion == ThumbnailEngine::SIMPLEMOD && main_window->mpDockInputOutput->isSameSourceChecked())
    {
        O_outdir = QDir::toNativeSeparators(QFileInfo(item->getFilePath().toString()).canonicalPath()).toLocal8Bit();
        parameters.gb_O_outdir = O_outdir.data();

        if(!this->suffix.isEmpty())
        {
           o_suffixArray = QString(this->suffix + "." + this->main_window->mpDockConf->getFormatFile()).toLocal8Bit();
           parameters.gb_o_suffix = o_suffixArray.data();
        }
        else
        {
            o_suffixArray = QString("." + this->main_window->mpDockConf->getFormatFile()).toLocal8Bit();
            parameters.gb_o_suffix = o_suffixArray.data();
        }
    }
    else
    {
        O_outdir = QDir::tempPath().toLocal8Bit();
        parameters.gb_O_outdir = O_outdir.data();

        o_suffixArray = DEFAULT_TMP_EXTENSION.toLocal8Bit();
        parameters.gb_o_suffix = o_suffixArray.data();
    }

    if(main_window->mpDockStyles->isInfoTextChecked())
         parameters.gb_i_info = 1;
    else parameters.gb_i_info = 0;

    if(!main_window->mpDockStyles->getTitleEdit().isEmpty())
    {
        T_textArray = main_window->mpDockStyles->getTitleEdit().toLocal8Bit();
        parameters.gb_T_text = T_textArray.data();
    }

    if(!this->item->isReadable() && !!this->item->getLowerTime().isNull() && !this->item->getUpperTime().isNull())
    {
        parameters.gb_B_begin = this->item->getBeginOmmitSecs();
        parameters.gb_E_end = this->item->getEndOmmitSecs();
    }

    process_file();

    this->item->logs = QString::fromUtf8(logs);

    emit finished(this->item);
}
void CreateMarkedObjectBagDlg::setMarkedObjectBagColor(const QColor &color)
{
    mMarkedObjectBagColor = color;
    buttonSelectColor->setStyleSheet(QString("background-color: rgb(%1, %2, %3);").arg(color.red()).arg(color.green()).arg(color.blue()));
}
Пример #18
0
static void _writeColor( QgsVectorLayer* layer, QString property, QColor color )
{
  layer->setCustomProperty( property + "R", color.red() );
  layer->setCustomProperty( property + "G", color.green() );
  layer->setCustomProperty( property + "B", color.blue() );
}
Пример #19
0
void Vizkit3DWidget::setBackgroundColor(QColor color)
{
    osgViewer::View *view = getView(0);
    assert(view);
    view->getCamera()->setClearColor(::osg::Vec4(color.red()/255.0,color.green()/255.0,color.blue()/255.0,1.0));
}
Пример #20
0
static QString color( const QColor& col )
{
    return QString( "{ %1, %2, %3 }" ).arg( item( col.red() ) ).arg( item( col.green() ) ).arg( item( col.blue() ) );
}
Пример #21
0
string RTFGenParser::parse(const QString &text)
{
    res = "";
    m_codec = m_client->getCodec(m_encoding);
    m_encoding = m_codec->name();
    int charset = 0;
    for (const ENCODING *c = ICQPlugin::core->encodings; c->language; c++){
        if (!strcasecmp(c->codec, m_encoding)){
            charset = c->rtf_code;
            break;
        }
    }
#ifdef WIN32
    if ((charset == 0) && !strcasecmp(m_encoding, "system")){
        char buff[256];
        int res = GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE, (char*)&buff, sizeof(buff));
        if (res){
            unsigned codepage = atol(buff);
            if (codepage){
                for (const rtf_cp *c = rtf_cps; c->cp; c++){
                    if (c->cp == codepage)
                        charset = c->charset;
                }
            }
        }
    }
#endif
    unsigned ansicpg = 0;
    const char *send_encoding = 0;
    m_codec = NULL;
    if (charset){
        for (const ENCODING *c = ICQPlugin::core->encodings; c->language; c++){
            if ((c->rtf_code == charset) && c->bMain){
                send_encoding = c->codec;
                m_codec = m_client->getCodec(send_encoding);
                ansicpg = c->cp_code;
                break;
            }
        }
    }

    // Add defaults to the tables
    m_fontFaces.push_back("MS Sans Serif");
    m_colors.push_back(m_foreColor);
    // Create a "fake" tag which'll serve as the default style
    CharStyle style;
    style.faceIdx = 0;
    style.colorIdx = 1; // colors are 1-based (0 = default)
    style.sizePt = 12; // default according to Microsoft
    Tag& tag = *(m_tags.pushNew());
    tag.setCharStyle(style);

    // Assume we go immediately after a tag.
    m_bSpace = true;
    HTMLParser::parse(text);

    string s;
    s = "{\\rtf1\\ansi";
    if (ansicpg){
        s += "\\ansicpg";
        s += number(ansicpg);
    }
    s += "\\deff0\r\n";
    s += "{\\fonttbl";
    unsigned n = 0;
    for (list<QString>::iterator it_face = m_fontFaces.begin(); it_face != m_fontFaces.end(); it_face++, n++){
        s += "{\\f";
        s += number(n);
        QString face = (*it_face);
        if (face.find("Times") >= 0){
            s += "\\froman";
        }else if (face.find("Courier") >= 0){
            s += "\\fmodern";
        }else{
            s += "\\fswiss";
        }
        if (charset){
            s += "\\fcharset";
            s += number(charset);
        }
        s += " ";
        int pos = face.find(QRegExp(" +["));
        if (pos > 0)
            face = face.left(pos);
        s += face.latin1();
        s += ";}";
    }
    s += "}\r\n";
    s += "{\\colortbl ;";
    for (list<QColor>::iterator it_colors = m_colors.begin(); it_colors != m_colors.end(); ++it_colors){
        QColor c = *it_colors;
        s += "\\red";
        s += number(c.red());
        s += "\\green";
        s += number(c.green());
        s += "\\blue";
        s += number(c.blue());
        s += ";";
    }
    s += "}\r\n";
    s += "\\viewkind4\\pard";
    s += style.getDiffRTF(CharStyle()).utf8();
    s += res;
    s += "\r\n}\r\n";

    log(L_DEBUG, "Resulting RTF: %s", s.c_str());

    return s;
}
Пример #22
0
static
QString
qcolor_to_qstring(const QColor& col)
{
    return QString::fromUtf8("rgb(%1,%2,%3)").arg( col.red() ).arg( col.green() ).arg( col.blue() );
}
Пример #23
0
bool SessionManager::save()
{
    if (debug)
        qDebug() << "SessionManager - saving session" << d->m_sessionName;

    emit m_instance->aboutToSaveSession();

    if (!d->m_writer || d->m_writer->fileName() != sessionNameToFileName(d->m_sessionName)) {
        delete d->m_writer;
        d->m_writer = new PersistentSettingsWriter(sessionNameToFileName(d->m_sessionName),
                                                       QLatin1String("QtCreatorSession"));
    }

    QVariantMap data;
    // save the startup project
    if (d->m_startupProject)
        data.insert(QLatin1String("StartupProject"), d->m_startupProject->projectFilePath());

    QColor c = StyleHelper::requestedBaseColor();
    if (c.isValid()) {
        QString tmp = QString::fromLatin1("#%1%2%3")
                .arg(c.red(), 2, 16, QLatin1Char('0'))
                .arg(c.green(), 2, 16, QLatin1Char('0'))
                .arg(c.blue(), 2, 16, QLatin1Char('0'));
        data.insert(QLatin1String("Color"), tmp);
    }

    QStringList projectFiles;
    foreach (Project *pro, d->m_projects)
        projectFiles << pro->projectFilePath();

    // Restore infromation on projects that failed to load:
    // don't readd projects to the list, which the user loaded
    foreach (const QString &failed, d->m_failedProjects)
        if (!projectFiles.contains(failed))
            projectFiles << failed;

    data.insert(QLatin1String("ProjectList"), projectFiles);

    QMap<QString, QVariant> depMap;
    QMap<QString, QStringList>::const_iterator i = d->m_depMap.constBegin();
    while (i != d->m_depMap.constEnd()) {
        QString key = i.key();
        QStringList values;
        foreach (const QString &value, i.value()) {
            values << value;
        }
        depMap.insert(key, values);
        ++i;
    }
    data.insert(QLatin1String("ProjectDependencies"), QVariant(depMap));
    data.insert(QLatin1String("EditorSettings"), EditorManager::saveState().toBase64());

    QMap<QString, QVariant>::const_iterator it, end = d->m_values.constEnd();
    QStringList keys;
    for (it = d->m_values.constBegin(); it != end; ++it) {
        data.insert(QLatin1String("value-") + it.key(), it.value());
        keys << it.key();
    }

    data.insert(QLatin1String("valueKeys"), keys);

    bool result = d->m_writer->save(data, Core::ICore::mainWindow());
    if (!result) {
        QMessageBox::warning(0, tr("Error while saving session"),
            tr("Could not save session to file %1").arg(d->m_writer->fileName().toUserOutput()));
    }

    if (debug)
        qDebug() << "SessionManager - saving session returned " << result;

    return result;
}
Пример #24
0
// Overloaded message send.
long QsciScintillaBase::SendScintilla(unsigned int msg, const QColor &col) const
{
    uptr_t wParam = (col.blue() << 16) | (col.green() << 8) | col.red();

    return sci->WndProc(msg, wParam, static_cast<sptr_t>(0));
}
Пример #25
0
//! Conversion of the QColor \p c to a Quantity_Color
Quantity_Color toOccColor(const QColor& c)
{
  return Quantity_Color(c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB);
}
Пример #26
0
void Widget::optimizeColors(int polyIndex, QImage& predrawn)
{
    /*
    // Find the poly's bounding box
    int minx,miny,maxx,maxy;
    minx = maxx = poly.points[0].x();
    miny = maxy = poly.points[0].y();
    for (QPoint point : poly.points)
    {
        minx = min(minx, point.x());
        maxx = max(maxx, point.x());
        miny = min(miny, point.y());
        maxy = max(maxy, point.y());
    }
    QRect box(minx, miny, maxx-minx, maxy-miny);
    */

    int polysSize = polys.size();
    Poly& poly = polys[polyIndex];
    static QBrush brush(Qt::SolidPattern);
    int processEventsRatelimit = 0;

    // Check if the pic is better, commit and return if it is
    auto validate = [&]()
    {
        QImage newGen = predrawn;
        QPainter painter(&newGen);
        painter.setPen(QPen(Qt::NoPen));
        for (int i=polyIndex; i<polysSize; ++i)
        {
            brush.setColor(polys[i].color);
            painter.setBrush(brush);
            painter.drawPolygon(polys[i].points.data(), polys[i].points.size());
        }
        quint64 newFit = computeFitness(newGen);
        generation++;
        ui->generationLabel->setNum(generation);
        if (newFit < fitness)
        {
            // Update data
            generated = newGen;
            fitness = newFit;

            // Update GUI
            if (processEventsRatelimit==0)
            {
                ui->imgBest->setPixmap(QPixmap::fromImage(generated));
                updateGuiFitness();
            }
            return true;
        }
        else
            return false;
    };

    app->processEvents();
    int targetColor;
    for (targetColor=0; targetColor <= 8; targetColor++)
    {
        do
        {
            if (processEventsRatelimit == GUI_REFRESH_RATE) // processEvents is a massive slowdown
            {
                processEventsRatelimit=0;
                app->processEvents();
            }
            else
                processEventsRatelimit++;
            QColor color = poly.color;
            if (targetColor == 0)
                color = color.lighter(110); // Lighter
            else if (targetColor == 1)
                color = color.darker(110); // Darker
            else if (targetColor == 2)
                color.setRed(min(color.red()+N_COLOR_VAR,255)); // More red
            else if (targetColor == 3)
                color.setBlue(max(color.blue()-N_COLOR_VAR,0)); // Less blue
            else if (targetColor == 4)
                color.setGreen(min(color.green()+N_COLOR_VAR,255)); // More green
            else if (targetColor == 5)
                color.setRed(max(color.red()-N_COLOR_VAR,0)); // Less red
            else if (targetColor == 6)
                color.setBlue(min(color.blue()+N_COLOR_VAR,255)); // More blue
            else if (targetColor == 7)
                color.setGreen(max(color.green()-N_COLOR_VAR,0)); // Less green
            else if (targetColor == 8)
                color.setAlpha(max(color.alpha()-N_COLOR_VAR,0)); // Less alpha
            else if (targetColor == 9 && OPT_INCREASE_ALPHA)
                color.setAlpha(min(color.alpha()+N_COLOR_VAR,255)); // More alpha
            poly.color = color;
        } while (validate());
    }
    app->processEvents();
}
Пример #27
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;
}
Пример #28
0
void MainWindow::colorLinesFull()
{
	QColor color;
	QColor *pColor;
	Mat image;
	std::default_random_engine generator;
	std::normal_distribution<double> onDistribution(30.0,10.0);

	QVector<QColor*> *colorVector;
	colorVector = computeGoldenRatioColors(0.01,0.99,1,100);

	int x, y;

	int number = 0;

	int width, height;

	int stepSizeX = 11;
	int stepSizeY = 12;

	QFileDialog *dialog = new QFileDialog();
	dialog->setNameFilter("PNG Files (*.png)");
	dialog->setOption(QFileDialog::ReadOnly);
	//dialog->setOption(QFileDialog::DontUseNativeDialog);
	dialog->setDirectory(".");
	QStringList fileNames;
	if (dialog->exec()) {
		fileNames = dialog->selectedFiles();
		QString fileName = fileNames.at(0);
		image = imread(fileName.toStdString(), CV_LOAD_IMAGE_COLOR);
		height = image.rows;
		width = image.cols;


			motorControl.openShutter();
			motorControl.commandMotor1(3, 5);  // Go a few steps back
			for (y=0;y!=height;++y) {
				motorControl.commandMotor1(3, -5);  // Go a few steps forth
				for(x=0;x!=width; x++) {
					motorControl.setLedColor(color);
					if (number<=0) {
						number = int(onDistribution(generator));
						pColor = colorVector->at(rand() % 100);
					}

					
					color.setBlue((image.data[((y*image.cols)+x)*3] / 6 * 5) + ( pColor->blue() / 6 ));
					color.setGreen((image.data[((y*image.cols)+x)*3+1] / 6 * 5)  + ( pColor->green() / 6));
					color.setRed((image.data[((y*image.cols)+x)*3+2] / 6 * 5) + ( pColor->red() / 6));
					motorControl.setLedColor(color);
					

					motorControl.commandMotor1(3, -stepSizeX);


					number--;

				}
				motorControl.setLedColor(QColor(0,0,0));
				motorControl.commandMotor1(3, stepSizeX * width);
				motorControl.commandMotor1(3, 5);  // Go a few steps back

				motorControl.commandMotor2(6, -stepSizeY);
			}
			motorControl.closeShutter();


			// Reset x axis to initial position if the width is uneven
			if( width%2 != 0) {
				motorControl.commandMotor1(6, stepSizeX * width);
			}

			// Reset y axis to initial position
			motorControl.commandMotor2(6, stepSizeY * height);

			motorControl.releaseMotor1();
			motorControl.releaseMotor2();


	}
}
Пример #29
0
void LEDPart::setColor(const QColor &color) {
	r = color.red()   / (double)0x100;
	g = color.green() / (double)0x100;
	b = color.blue()  / (double)0x100;
}
Пример #30
0
QColor GrepOutputDelegate::blendColor(QColor color1, QColor color2, double blend) const
{
    return QColor(color1.red() * blend + color2.red() * (1-blend),
                  color1.green() * blend + color2.green() * (1-blend),
                  color1.blue() * blend + color2.blue() * (1-blend));
}