Esempio n. 1
0
void QgsColorSwatchGrid::updateTooltip( const int colorIdx )
{
  if ( colorIdx >= 0 && colorIdx < mColors.length() )
  {
    //if color has an associated name from the color scheme, use that
    QString colorName = mColors.at( colorIdx ).second;
    if ( colorName.isEmpty() )
    {
      //otherwise, build a default string
      QColor color = mColors.at( colorIdx ).first;
      colorName = QString( tr( "rgb(%1, %2, %3)" ) ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
    }
    setToolTip( colorName );
  }
  else
  {
    //clear tooltip
    setToolTip( QString() );
  }
}
Esempio n. 2
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;
}
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;
}
Esempio n. 4
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);
    }
}
Esempio n. 5
0
void
KdeIni::setValue(const QString &key, const QVariant &value)
{
   if (localGroup == local.end()) {
      qWarning("KdeIni::setValue(): You must first set a group!");
      return;
   }
   QString val;
   switch(value.type()) {
   case QVariant::Color: {
      QColor c = value.value<QColor>();
      val = QString::number( c.red() ) + ',' + QString::number( c.green() ) + ',' + QString::number( c.blue() );
      break;
   }
   default:
      val = value.toString();
   }
   (*localGroup)[key] = val;
}
Esempio n. 6
0
void SpotLight::setSpecularColor(QColor color)
{
    specular_light = new Vec4((float)color.red()/255.0,(float)color.green()/255.0,(float)color.blue()/255.0);
}
Esempio n. 7
0
std::vector<Eigen::Vector3f> ImageReader::toVector(){
    std::vector<Eigen::Vector3f> output;
    for (int i = 0; i < getImageHeight(); i++) {
        for (int j = 0; j < getImageWidth(); j++) {
            QColor pixelColor = QColor(pixelAt(i,j));
            Eigen::Vector3f color = Eigen::Vector3f(float(pixelColor.red()), float(pixelColor.green()), float(pixelColor.blue()));
            output.push_back(color);
        }
    }
    return output;
}
void v3dViewFiberInteractor::validateSelection(const QString &name, const QColor &color)
{
    if (!d->data)
        return;

    double color_d[3] = {(double)color.red()/255.0, (double)color.green()/255.0, (double)color.blue()/255.0};

    d->manager->Validate (name.toAscii().constData(), color_d);

    d->view->renderer2d()->AddActor (d->manager->GetBundleActor(name.toAscii().constData()));

    d->data->addMetaData("BundleList", name);
    d->data->addMetaData("BundleColorList", color.name());

    // reset to initial navigation state
    d->manager->Reset();
    d->view->update();
}
Esempio n. 9
0
void fft(int squareSize, QImage *myImage, QImage *myImageMag, QImage *myImagePhase)
{
    fftw_plan planR, planG, planB;
    fftw_complex *inR, *inG, *inB, *outR, *outG, *outB;
    QColor tempColor;
    int tempCounter = 0;
    double realR, realG, realB,
            imagR, imagG, imagB,
            magR, magG, magB,
            phaseR, phaseG, phaseB,
            magRMax, magGMax, magBMax;


    //    -----------------------------------------------
    //
    //    Alokacja wektorów i egzekucja FFT.
    //
    //    -----------------------------------------------

    inR = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * squareSize * squareSize);
    inG = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * squareSize * squareSize);
    inB = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * squareSize * squareSize);

    outR = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * squareSize * squareSize);
    outG = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * squareSize * squareSize);
    outB = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * squareSize * squareSize);

    planG = fftw_plan_dft_2d(squareSize, squareSize, inG, outG, FFTW_FORWARD, FFTW_ESTIMATE);
    planB = fftw_plan_dft_2d(squareSize, squareSize, inB, outB, FFTW_FORWARD, FFTW_ESTIMATE);
    planR = fftw_plan_dft_2d(squareSize, squareSize, inR, outR, FFTW_FORWARD, FFTW_ESTIMATE);

    for(int i=0; i < squareSize; i++)
    {
        for(int j=0; j < squareSize; j++)
        {
            tempColor.setRgb(myImage->pixel(i, j));
            inR[tempCounter][0] = (double)tempColor.red();
            inG[tempCounter][0] = (double)tempColor.green();
            inB[tempCounter][0] = (double)tempColor.blue();

            tempCounter++;
        }
    }

    fftw_execute(planR);
    fftw_execute(planG);
    fftw_execute(planB);

    //    -----------------------------------------------
    //
    //    Normalizacja wartosci amplitudy FFT
    //
    //    -----------------------------------------------

    tempCounter = 0;
    for(int i=0; i < squareSize * squareSize; i++)
    {
        realR = outR[tempCounter][0] / (double)(squareSize * squareSize);
        imagR = outR[tempCounter][1] / (double)(squareSize * squareSize);

        realG = outG[tempCounter][0] / (double)(squareSize * squareSize);
        imagG = outG[tempCounter][1] / (double)(squareSize * squareSize);

        realB = outB[tempCounter][0] / (double)(squareSize * squareSize);
        imagB = outB[tempCounter][1] / (double)(squareSize * squareSize);

        magR = sqrt((realR * realR) + (imagR * imagR));
        magG = sqrt((realG * realG) + (imagG * imagG));
        magB = sqrt((realB * realB) + (imagB * imagB));

        if(i > 0)
        {
            magRMax = (magR > magRMax ? magR : magRMax);
            magGMax = (magG > magGMax ? magG : magGMax);
            magBMax = (magB > magBMax ? magB : magBMax);
        }

        tempCounter++;
    }

    //    -----------------------------------------------
    //
    //    Wyznaczenie amplitudy i fazy
    //
    //    -----------------------------------------------

    tempCounter = 0;
    for(int i=0; i < squareSize; i++)
    {
        for(int j=0; j < squareSize; j++)
        {

            realR = outR[tempCounter][0] / (double)(squareSize * squareSize);
            imagR = outR[tempCounter][1] / (double)(squareSize * squareSize);

            realG = outG[tempCounter][0] / (double)(squareSize * squareSize);
            imagG = outG[tempCounter][1] / (double)(squareSize * squareSize);

            realB = outB[tempCounter][0] / (double)(squareSize * squareSize);
            imagB = outB[tempCounter][1] / (double)(squareSize * squareSize);

            magR = sqrt((realR * realR) + (imagR * imagR));
            magG = sqrt((realG * realG) + (imagG * imagG));
            magB = sqrt((realB * realB) + (imagB * imagB));

            //log(mag)
            int param = 255;
//            magR = log(magR*param+1) / log(magRMax+1);
//            magG = log(magG*param+1) / log(magGMax+1);
//            magB = log(magB*param+1) / log(magBMax+1);
            magR = (param*log(magR+1)) / log(1 + magRMax);
            magG = (param*log(magG+1)) / log(1 + magGMax);
            magB = (param*log(magB+1)) / log(1 + magBMax);

            magR = (magR > 255 ? 255 : magR);
            magG = (magG > 255 ? 255 : magG);
            magB = (magB > 255 ? 255 : magB);

            magR = (magR < 0 ? 0 : magR);
            magG = (magG < 0 ? 0 : magG);
            magB = (magB < 0 ? 0 : magB);

            tempColor.setRed((int)magR);
            tempColor.setGreen((int)magG);
            tempColor.setBlue((int)magB);
            myImageMag->setPixel(i, j, tempColor.rgb());

//            magR = (magR / magRMax)*255.0;
//            magG = (magG / magGMax)*255.0;
//            magB = (magB / magBMax)*255.0;

//            tempColor.setRed(magR);
//            tempColor.setGreen(magG);
//            tempColor.setBlue(magB);
//            myImageMagBasic->setPixel(i, j, tempColor.rgb());


            complex<double> cR(realR, imagR);
            complex<double> cG(realG, imagG);
            complex<double> cB(realB, imagB);

            phaseR = arg(cR) + M_PI;
            phaseG = arg(cG) + M_PI;
            phaseB = arg(cB) + M_PI;


            tempColor.setRed((phaseR / (double)(2 * M_PI)) * 255);
            tempColor.setGreen((phaseG / (double)(2 * M_PI)) * 255);
            tempColor.setBlue((phaseB / (double)(2 * M_PI)) * 255);
            myImagePhase->setPixel(i, j, tempColor.rgb());

            tempCounter++;
        }
    }

    //    -----------------------------------------------
    //
    //    Wyśrodkowanie fazy i amplitudy, zwolnienie pamięci.
    //
    //    -----------------------------------------------

    swapQuadrants(squareSize, myImageMag);
    swapQuadrants(squareSize, myImagePhase);

    fftw_destroy_plan(planR);
    fftw_destroy_plan(planG);
    fftw_destroy_plan(planB);
    fftw_free(inR);
    fftw_free(inG);
    fftw_free(inB);
    fftw_free(outR);
    fftw_free(outG);
    fftw_free(outB);

}
Esempio n. 10
0
/*!
  Set the outline
  */
void QgsRubberBand::setBorderColor( const QColor & color )
{
  QColor penColor( color.red(), color.green(), color.blue(), color.alpha() );
  mPen.setColor( penColor );
}
void ossimQtVectorEditorDialogController::transferFromDialogCurrent()
{
  if((theCurrentFeatureIdx >= 0)&&
     (theCurrentFeatureIdx < (int)theFeatureInfoList.size())&&
     (theDialog))
    {
      switch(theFeatureInfoList[theCurrentFeatureIdx].theFeatureType)
	{
	case ossimQtVectorEditorFeatureInfoType_POINT:
	  {
	    stringstream radiusStream(theDialog->thePointRadiusInput->text().ascii());
	    
	    radiusStream >> theFeatureInfoList[theCurrentFeatureIdx].thePointRadius.x
			 >> theFeatureInfoList[theCurrentFeatureIdx].thePointRadius.y;
	    
             theFeatureInfoList[theCurrentFeatureIdx].theEnabledFlag = theDialog->thePointEnabledCheckBox->isChecked();
             theFeatureInfoList[theCurrentFeatureIdx].theFillFlag  = theDialog->thePointFilledCheckBox->isChecked();
             QColor qColor = theDialog->thePointColorFrame->paletteBackgroundColor();
             ossimRgbVector color(qColor.red(),
                                  qColor.green(),
                                  qColor.blue());
             theFeatureInfoList[theCurrentFeatureIdx].theColor = color;
             break;
	  }
	case ossimQtVectorEditorFeatureInfoType_LINE:
	  {
 	    theFeatureInfoList[theCurrentFeatureIdx].theEnabledFlag = theDialog->theLineEnabledCheckBox->isChecked();
	    QColor qColor = theDialog->theLineColorFrame->paletteBackgroundColor();
	    ossimRgbVector color(qColor.red(),
				 qColor.green(),
				 qColor.blue());
	    theFeatureInfoList[theCurrentFeatureIdx].theColor = color;
            theFeatureInfoList[theCurrentFeatureIdx].theThickness = theDialog->theLineThicknessInput->value();
	    break;
	  }
	case ossimQtVectorEditorFeatureInfoType_POLYGON:
	  {
             theFeatureInfoList[theCurrentFeatureIdx].theEnabledFlag = theDialog->thePolygonEnabledCheckBox->isChecked();
             theFeatureInfoList[theCurrentFeatureIdx].theFillFlag  = theDialog->thePolygonFilledCheckBox->isChecked();
             QColor qColor = theDialog->thePolygonColorFrame->paletteBackgroundColor();
             ossimRgbVector color(qColor.red(),
                                  qColor.green(),
                                  qColor.blue());
             theFeatureInfoList[theCurrentFeatureIdx].theColor = color;
             theFeatureInfoList[theCurrentFeatureIdx].theThickness = theDialog->thePolygonThicknessInput->value();
	    break;
	  }
	case ossimQtVectorEditorFeatureInfoType_TEXT:
	  {
 	    theFeatureInfoList[theCurrentFeatureIdx].theEnabledFlag = theDialog->theFontEnabledCheckBox->isChecked();
             QColor qColor = theDialog->theFontColorFrame->paletteBackgroundColor();
             ossimRgbVector color(qColor.red(),
                                  qColor.green(),
                                  qColor.blue());
             theFeatureInfoList[theCurrentFeatureIdx].theColor = color;
             theFeatureInfoList[theCurrentFeatureIdx].theFontInformation.thePointSize.x = theDialog->theFontPointSizeSpinBox->value();
             theFeatureInfoList[theCurrentFeatureIdx].theFontInformation.thePointSize.y = theDialog->theFontPointSizeSpinBox->value();
             theFeatureInfoList[theCurrentFeatureIdx].theFontInformation.theRotation    = ossimString(theDialog->theFontRotationInput->text().ascii()).toDouble();
             theFeatureInfoList[theCurrentFeatureIdx].theFontInformation.theStyleName   = ossimString(theDialog->theFontStyleNameComboBox->currentText().ascii());
             theFeatureInfoList[theCurrentFeatureIdx].theFontInformation.theFamilyName  = ossimString(theDialog->theFontFamilyNameComboBox->currentText().ascii());
             std::stringstream scaleStream(theDialog->theFontScaleInput->text().ascii());
             std::stringstream shearStream(theDialog->theFontShearInput->text().ascii());
             scaleStream >> theFeatureInfoList[theCurrentFeatureIdx].theFontInformation.theScale.x
                         >> theFeatureInfoList[theCurrentFeatureIdx].theFontInformation.theScale.y;
             shearStream >> theFeatureInfoList[theCurrentFeatureIdx].theFontInformation.theShear.x
                         >> theFeatureInfoList[theCurrentFeatureIdx].theFontInformation.theShear.y;
	    break;
	  }
	default:
	  {
	    break;
	  }
	}
    }
  if(theDialog->theAutoApplyCheckBox->isChecked())
  {
     apply();
  }
}
Esempio n. 12
0
/*!
  Set the fill color.
  */
void QgsRubberBand::setFillColor( const QColor & color )
{
  QColor fillColor( color.red(), color.green(), color.blue(), color.alpha() );
  mBrush.setColor( fillColor );
}
Esempio n. 13
0
void MarkStateRuleDialog::setColor(QColor color)
{
  m_color = color;
  m_ui.color->setAutoFillBackground(true);
  QString colorString = QString("rgb(") + QString::number(color.red()) + ", " + QString::number(color.green()) + ", " + QString::number(color.blue()) + ")";
  m_ui.color->setStyleSheet(QString("background-color: ") + colorString + "; color: " + colorString + ";");
}
Esempio n. 14
0
string RTFGenParser::parse(const QString &text)
{
    res = "";
    m_res_size = 0;
    m_codec = getContacts()->getCodec(m_contact);
    int charset = 0;
    for (const ENCODING *c = getContacts()->getEncodings(); c->language; c++) {
        if (!strcasecmp(c->codec, m_codec->name())) {
            charset = c->rtf_code;
            break;
        }
    }
#ifdef WIN32
    if ((charset == 0) && !strcasecmp(m_codec->name(), "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 = getContacts()->getEncodings(); c->language; c++) {
            if ((c->rtf_code == charset) && c->bMain) {
                send_encoding = c->codec;
                m_codec = getContacts()->getCodecByName(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;
}
Esempio n. 15
0
void QStaticTextPrivate::paintText(const QPointF &topLeftPosition, QPainter *p)
{
    bool preferRichText = textFormat == Qt::RichText
                          || (textFormat == Qt::AutoText && Qt::mightBeRichText(text));

    if (!preferRichText) {
        QTextLayout textLayout;
        textLayout.setText(text);
        textLayout.setFont(font);
        textLayout.setTextOption(textOption);

        qreal leading = QFontMetricsF(font).leading();
        qreal height = -leading;

        textLayout.beginLayout();
        while (1) {
            QTextLine line = textLayout.createLine();
            if (!line.isValid())
                break;

            if (textWidth >= 0.0)
                line.setLineWidth(textWidth);
            height += leading;
            line.setPosition(QPointF(0.0, height));
            height += line.height();
        }
        textLayout.endLayout();

        actualSize = textLayout.boundingRect().size();
        textLayout.draw(p, topLeftPosition);
    } else {
        QTextDocument document;
#ifndef QT_NO_CSSPARSER
        QColor color = p->pen().color();
        document.setDefaultStyleSheet(QString::fromLatin1("body { color: #%1%2%3 }")
                                      .arg(QString::number(color.red(), 16), 2, QLatin1Char('0'))
                                      .arg(QString::number(color.green(), 16), 2, QLatin1Char('0'))
                                      .arg(QString::number(color.blue(), 16), 2, QLatin1Char('0')));
#endif
        document.setDefaultFont(font);
        document.setDocumentMargin(0.0);        
#ifndef QT_NO_TEXTHTMLPARSER
        document.setHtml(text);
#else
        document.setPlainText(text);
#endif
        if (textWidth >= 0.0)
            document.setTextWidth(textWidth);
        else
            document.adjustSize();
        document.setDefaultTextOption(textOption);

        p->save();
        p->translate(topLeftPosition);
        QAbstractTextDocumentLayout::PaintContext ctx;
        ctx.palette.setColor(QPalette::Text, p->pen().color());
        document.documentLayout()->draw(p, ctx);
        p->restore();

        if (textWidth >= 0.0)
            document.adjustSize(); // Find optimal size

        actualSize = document.size();
    }
}
Esempio n. 16
0
osg::Drawable *ReverseTileNode::createReverseTile(void) const {
    // Get the tile
    ReverseTile* tile = static_cast<ReverseTile*>(_lego);

    // Get tile color
    QColor color = tile->getColor();

    // Get integer sizes
    int width = tile->getWidth();
    int length = tile->getLength();
    int height = 3;

    // Get real position, according to tile size
    double mw = (-width)*Lego::length_unit/2;
    double pw = (width)*Lego::length_unit/2;
    double mwp = (-width+2)*Lego::length_unit/2;
    double ml = (-length)*Lego::length_unit/2;
    double pl = (length)*Lego::length_unit/2;
    double mh = (-height)*Lego::height_unit/2;
    double ph = (height)*Lego::height_unit/2;
    double phm = (height-1)*Lego::height_unit/2;

    // Create 14 vertices
    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
    osg::Vec3 v0(mw, ml, mh);
    osg::Vec3 v1(mw, pl, mh);
    osg::Vec3 v2(mwp, pl, mh);
    osg::Vec3 v3(mwp, ml, mh);
    osg::Vec3 v4(pw, ml, phm);
    osg::Vec3 v5(pw, pl, phm);
    osg::Vec3 v6(pw, pl, ph);
    osg::Vec3 v7(pw, ml, ph);
    osg::Vec3 v8(mw, ml, ph);
    osg::Vec3 v9(mw, pl, ph);
    osg::Vec3 v10(mwp, ml, phm);
    osg::Vec3 v11(mwp, ml, ph);
    osg::Vec3 v12(mwp, pl, ph);
    osg::Vec3 v13(mwp, pl, phm);

    // Create 10 faces, 8 faces are quads splitted into two triangles
    // NB: Down face is transparent, we don't even create it

    // Front face t1
    vertices->push_back(v4);
    vertices->push_back(v5);
    vertices->push_back(v6);
    // Front face t2
    vertices->push_back(v4);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Back face t1
    vertices->push_back(v0);
    vertices->push_back(v1);
    vertices->push_back(v8);
    // Back face t2
    vertices->push_back(v1);
    vertices->push_back(v8);
    vertices->push_back(v9);

    // Top face t1
    vertices->push_back(v6);
    vertices->push_back(v7);
    vertices->push_back(v9);
    // Top face t2
    vertices->push_back(v7);
    vertices->push_back(v8);
    vertices->push_back(v9);

    // Slop face t1
    vertices->push_back(v2);
    vertices->push_back(v3);
    vertices->push_back(v5);
    // Slop face t2
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v5);

    // Right triangle face
    vertices->push_back(v2);
    vertices->push_back(v13);
    vertices->push_back(v5);

    // Right quad face t1
    vertices->push_back(v13);
    vertices->push_back(v12);
    vertices->push_back(v6);
    // Right quad face t2
    vertices->push_back(v13);
    vertices->push_back(v6);
    vertices->push_back(v5);

    // Right quad face down t1
    vertices->push_back(v1);
    vertices->push_back(v9);
    vertices->push_back(v12);
    // Right quad face down t2
    vertices->push_back(v1);
    vertices->push_back(v2);
    vertices->push_back(v12);

    // Left triangle face
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v10);

    // Left quad face t1
    vertices->push_back(v4);
    vertices->push_back(v10);
    vertices->push_back(v11);
    // Left quad face t2
    vertices->push_back(v4);
    vertices->push_back(v7);
    vertices->push_back(v11);

    // Left quad face down t1
    vertices->push_back(v0);
    vertices->push_back(v3);
    vertices->push_back(v8);
    // Left quad face down t2
    vertices->push_back(v3);
    vertices->push_back(v8);
    vertices->push_back(v11);

    // Create tile geometry
    osg::ref_ptr<osg::Geometry> tileGeometry = new osg::Geometry;

    // Match vertices
    tileGeometry->setVertexArray(vertices);

    // Add color (each rectangle has the same color except for the down one which is transparent)
    osg::Vec4 osgColor(static_cast<float>(color.red())/255.0, static_cast<float>(color.green())/255.0, static_cast<float>(color.blue())/255.0, 1.0);
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    // Every face has the same color, so there is only one color
    colors->push_back(osgColor);

    // Match color
    tileGeometry->setColorArray(colors);
    tileGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);

    // Create normals
    osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, 0, 1));
    normals->push_back(osg::Vec3(0, 0, 1));
    double w = pw - mwp;
    double h = phm - mh;
    double norm = std::sqrt(w*w + h*h);
    normals->push_back(osg::Vec3(h/norm, 0, -w/norm));
    normals->push_back(osg::Vec3(h/norm, 0, -w/norm));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));

    // Match normals
    tileGeometry->setNormalArray(normals);
    tileGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);

    // Define tile 18 GL_TRIANGLES with 20*3 vertices
    tileGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, 18*3));

    // Return the tile whithout plot
    return tileGeometry.release();
}
Esempio n. 17
0
void SpotLight::setAmbientColor(QColor color)
{
    ambient_light =new Vec4((float)color.red()/255.0,(float)color.green()/255.0,(float)color.blue()/255.0);
}
Esempio n. 18
0
void KbPerf::update(QFile& cmd, bool force, bool saveCustomDpi){
    if(!force && !_needsUpdate)
        return;
    emit settingsUpdated();
    _needsUpdate = false;
    // Save DPI stage 0 (sniper)
    cmd.write(QString("dpi 0:%1,%2").arg(dpiX[0]).arg(dpiY[0]).toLatin1());
    // If the mouse is set to a custom DPI, save it in stage 1
    int stage = dpiCurIdx;
    if(stage < 0 && saveCustomDpi){
        stage = 1;
        cmd.write(QString(" 1:%1,%2").arg(dpiCurX).arg(dpiCurY).toLatin1());
    } else {
        // Otherwise, save stage 1 normally
        if(!dpiOn[1] && stage != 1)
            cmd.write(" 1:off");
        else
            cmd.write(QString(" 1:%1,%2").arg(dpiX[1]).arg(dpiY[1]).toLatin1());
    }
    // Save stages 1 - 5
    for(int i = 2; i < DPI_COUNT; i++){
        if(!dpiOn[i] && stage != i)
            cmd.write(QString(" %1:off").arg(i).toLatin1());
        else
        cmd.write(QString(" %1:%2,%3").arg(i).arg(dpiX[i]).arg(dpiY[i]).toLatin1());
    }
    // Save stage selection, lift height, and angle snap
    cmd.write(QString(" dpisel %1 lift %2 snap %3").arg(stage).arg(_liftHeight).arg(_angleSnap ? "on" : "off").toLatin1());
    // Save DPI colors
    cmd.write(" rgb");
    for(int i = 0; i < DPI_COUNT; i++){
        QColor color = dpiColor(i);
        cmd.write(" dpi");
        char output[9];
        snprintf(output, sizeof(output), "%1d:%02x%02x%02x", i, color.red(), color.green(), color.blue());
        cmd.write(output);
    }
    // Enable indicator notifications
    cmd.write(" inotify all");
    // Set indicator state
    const char* iNames[HW_I_COUNT] = { "num", "caps", "scroll" };
    for(int i = 0; i < HW_I_COUNT; i++){
        if(hwIType[i] == ON)
            cmd.write(" ion ");
        else if(hwIType[i] == OFF)
            cmd.write(" ioff ");
        else
            cmd.write(" iauto ");
        cmd.write(iNames[i]);
    }
}
Esempio n. 19
0
void SpotLight::setDiffuseColor(QColor color)
{
    diffuse_light = new Vec4((float)color.red()/255.0,(float)color.green()/255.0,(float)color.blue()/255.0);
}
Esempio n. 20
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
QColor blend(const QColor& c1, const QColor& c2, int percentOfC1) {
	return QColor((c1.red()*percentOfC1 + c2.red()*(100-percentOfC1)) / 100,
	              (c1.green()*percentOfC1 + c2.green()*(100-percentOfC1)) / 100,
	              (c1.blue()*percentOfC1 + c2.blue()*(100-percentOfC1)) / 100);
}
Esempio n. 21
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));
}
Esempio n. 22
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
QColor blend(const QColor& c1, const QColor& c2) {
	int invertedAlpha = 255-c2.alpha();
	return QColor((c1.red()*invertedAlpha + c2.red()*c2.alpha()) / 255,
	              (c1.green()*invertedAlpha + c2.green()*c2.alpha()) / 255,
	              (c1.blue()*invertedAlpha + c2.blue()*c2.alpha()) / 255);
}
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);
        }
    }
}
Esempio n. 24
0
void Project::save_color(QString name, QColor col)
{
    //open pro file,
    QString filepath = QString ("%1/%2.3df").arg(m_path).arg(m_projectName);
    QString filepathtmp = QString ("%1/%2.tmp").arg(m_path).arg(m_projectName);
    QFile file(filepath);
    QFile tmp (filepathtmp);
    file.open(QIODevice::ReadWrite);
    tmp.open(QIODevice::ReadWrite | QIODevice::Text);
    QTextStream in(&file);
    QTextStream out(&tmp);

    while(!in.atEnd())
    {
        QString line = in.readLine();
        if(line.contains(name))
        {
            QStringList plist = line.split(" ");
            out << plist.at(0)<< " " << plist.at(1)<< " " << col.red()<< " " << col.green()<< " " << col.blue()<< "\n";

        }
        else
        {
            out<<line<<"\n";
        }
    }
    file.close();
    tmp.close();
    //smazat proj.3df a prejmenovat proj.tmp na pro.3df
    QFile::remove(filepath);
    QFile::rename(filepathtmp,filepath);
}
Esempio n. 25
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;
}
Esempio n. 26
0
void SearchLineEdit::setColors(const QColor & base, const QColor & text) {
    setStyleSheet(QString("background: rgb(%1,%2,%3); color: rgb(%4,%5,%6);")
                  .arg(base.red()).arg(base.green()).arg(base.blue())
                  .arg(text.red()).arg(text.green()).arg(text.blue()) );
}
Esempio n. 27
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();
}
Esempio n. 28
0
static QColor qt_mix_colors(QColor a, QColor b)
{
    return QColor((a.red() + b.red()) / 2, (a.green() + b.green()) / 2,
                  (a.blue() + b.blue()) / 2, (a.alpha() + b.alpha()) / 2);
}
Esempio n. 29
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;
}
Esempio n. 30
0
void enhanceImage(QImage &origin, const QString &pathToImage)
{
    QImage newImage(origin);
    int kernel[3][3] = { { 0, -3, 0 }, { -3, 50, -3 }, { 0, -3, 0 } };
    // int kernelSize = 3;
    constexpr int kernelDiv2 = 1;
    constexpr int sumKernel = 38;
    int r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4;
    QColor color;
    int N1 = (newImage.width() - kernelDiv2) / 4;
    int N2 = (newImage.height() - kernelDiv2) / 4;
    for (int x = kernelDiv2; x <= N1; ++x) {
        for (int y = kernelDiv2; y <= N2; ++y) {

            r1 = 0;
            g1 = 0;
            b1 = 0;

            for (int i = -kernelDiv2; i <= kernelDiv2; ++i) {
                for (int j = -kernelDiv2; j <= kernelDiv2; ++j) {
                    color = QColor(origin.pixel(x + i, y + j));
                    r1 += color.red() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    g1 +=
                        color.green() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    b1 += color.blue() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                }
            }
            r1 = qBound(0, r1 / sumKernel, 255);
            g1 = qBound(0, g1 / sumKernel, 255);
            b1 = qBound(0, b1 / sumKernel, 255);

            newImage.setPixel(x, y, qRgb(r1, g1, b1));

            r2 = 0;
            g2 = 0;
            b2 = 0;

            for (int i = -kernelDiv2; i <= kernelDiv2; ++i) {
                for (int j = -kernelDiv2; j <= kernelDiv2; ++j) {
                    color = QColor(origin.pixel(x + N1 + i, y + N2 + j));
                    r2 += color.red() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    g2 +=
                        color.green() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    b2 += color.blue() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                }
            }
            r2 = qBound(0, r2 / sumKernel, 255);
            g2 = qBound(0, g2 / sumKernel, 255);
            b2 = qBound(0, b2 / sumKernel, 255);

            newImage.setPixel(x + N1, y + N2, qRgb(r2, g2, b2));

            r3 = 0;
            g3 = 0;
            b3 = 0;

            for (int i = -kernelDiv2; i <= kernelDiv2; ++i) {
                for (int j = -kernelDiv2; j <= kernelDiv2; ++j) {
                    color =
                        QColor(origin.pixel(x + 2 * N1 + i, y + 2 * N2 + j));
                    r3 += color.red() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    g3 +=
                        color.green() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    b3 += color.blue() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                }
            }
            r3 = qBound(0, r3 / sumKernel, 255);
            g3 = qBound(0, g3 / sumKernel, 255);
            b3 = qBound(0, b3 / sumKernel, 255);

            newImage.setPixel(x + 2 * N1, y + 2 * N2, qRgb(r3, g3, b3));

            r4 = 0;
            g4 = 0;
            b4 = 0;

            for (int i = -kernelDiv2; i <= kernelDiv2; ++i) {
                for (int j = -kernelDiv2; j <= kernelDiv2; ++j) {
                    color = QColor(
                        origin.pixel(x + 3 * N1 + i - 1, y + 3 * N2 + j - 1));
                    r4 += color.red() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    g4 +=
                        color.green() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                    b4 += color.blue() * kernel[kernelDiv2 + i][kernelDiv2 + j];
                }
            }
            r4 = qBound(0, r4 / sumKernel, 255);
            g4 = qBound(0, g4 / sumKernel, 255);
            b4 = qBound(0, b4 / sumKernel, 255);

            newImage.setPixel(x + 3 * N1, y + 3 * N2, qRgb(r4, g4, b4));
        }
    }
    newImage.save(pathToImage);
}