WColor transform(const QColor& color)
{
	return WColor(color.red(), color.green(), color.blue(), color.alpha());
}
void QtWebPageEventHandler::handleInputMethodEvent(QInputMethodEvent* ev)
{
    QString commit = ev->commitString();
    QString composition = ev->preeditString();

    int replacementStart = ev->replacementStart();
    int replacementLength = ev->replacementLength();

    // NOTE: We might want to handle events of one char as special
    // and resend them as key events to make web site completion work.

    int cursorPositionWithinComposition = 0;

    Vector<CompositionUnderline> underlines;

    for (int i = 0; i < ev->attributes().size(); ++i) {
        const QInputMethodEvent::Attribute& attr = ev->attributes().at(i);
        switch (attr.type) {
        case QInputMethodEvent::TextFormat: {
            if (composition.isEmpty())
                break;

            QTextCharFormat textCharFormat = attr.value.value<QTextFormat>().toCharFormat();
            QColor qcolor = textCharFormat.underlineColor();
            Color color = makeRGBA(qcolor.red(), qcolor.green(), qcolor.blue(), qcolor.alpha());
            int start = qMin(attr.start, (attr.start + attr.length));
            int end = qMax(attr.start, (attr.start + attr.length));
            underlines.append(CompositionUnderline(start, end, color, false));
            break;
        }
        case QInputMethodEvent::Cursor:
            if (attr.length)
                cursorPositionWithinComposition = attr.start;
            break;
        // Selection is handled further down.
        default:
            break;
        }
    }

    if (composition.isEmpty()) {
        int selectionStart = -1;
        int selectionLength = 0;
        for (int i = 0; i < ev->attributes().size(); ++i) {
            const QInputMethodEvent::Attribute& attr = ev->attributes().at(i);
            if (attr.type == QInputMethodEvent::Selection) {
                selectionStart = attr.start;
                selectionLength = attr.length;

                ASSERT(selectionStart >= 0);
                ASSERT(selectionLength >= 0);
                break;
            }
        }

        m_webPageProxy->confirmComposition(commit, selectionStart, selectionLength);
    } else {
        ASSERT(cursorPositionWithinComposition >= 0);
        ASSERT(replacementStart >= 0);

        m_webPageProxy->setComposition(composition, underlines,
                                       cursorPositionWithinComposition, cursorPositionWithinComposition,
                                       replacementStart, replacementLength);
    }

    ev->accept();
}
Esempio n. 3
0
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. 4
0
void QgsSingleBandPseudoColorRendererWidget::on_mExportToFileButton_clicked()
{
  QSettings settings;
  QString lastDir = settings.value( "lastColorMapDir", QDir::homePath() ).toString();
  QString fileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), lastDir, tr( "Textfile (*.txt)" ) );
  if ( !fileName.isEmpty() )
  {
    if ( !fileName.endsWith( ".txt", Qt::CaseInsensitive ) )
    {
      fileName = fileName + ".txt";
    }

    QFile outputFile( fileName );
    if ( outputFile.open( QFile::WriteOnly ) )
    {
      QTextStream outputStream( &outputFile );
      outputStream << "# " << tr( "QGIS Generated Color Map Export File" ) << '\n';
      outputStream << "INTERPOLATION:";
      QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast< QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox->itemData( mColorInterpolationComboBox->currentIndex() ).toInt() );
      switch ( interpolation )
      {
        case QgsColorRampShader::INTERPOLATED:
          outputStream << "INTERPOLATED\n";
          break;
        case QgsColorRampShader::DISCRETE:
          outputStream << "DISCRETE\n";
          break;
        case QgsColorRampShader::EXACT:
          outputStream << "EXACT\n";
          break;
      }

      int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
      QTreeWidgetItem* currentItem;
      QColor color;
      for ( int i = 0; i < topLevelItemCount; ++i )
      {
        currentItem = mColormapTreeWidget->topLevelItem( i );
        if ( !currentItem )
        {
          continue;
        }
        color = currentItem->background( ColorColumn ).color();
        outputStream << currentItem->text( ValueColumn ).toDouble() << ',';
        outputStream << color.red() << ',' << color.green() << ',' << color.blue() << ',' << color.alpha() << ',';
        if ( currentItem->text( LabelColumn ).isEmpty() )
        {
          outputStream << "Color entry " << i + 1 << '\n';
        }
        else
        {
          outputStream << currentItem->text( LabelColumn ) << '\n';
        }
      }
      outputStream.flush();
      outputFile.close();

      QFileInfo fileInfo( fileName );
      settings.setValue( "lastColorMapDir", fileInfo.absoluteDir().absolutePath() );
    }
    else
    {
      QMessageBox::warning( this, tr( "Write access denied" ), tr( "Write access denied. Adjust the file permissions and try again.\n\n" ) );
    }
  }
}
Esempio n. 5
0
/*!
  Set the outline
  */
void QgsRubberBand::setBorderColor( const QColor & color )
{
  QColor penColor( color.red(), color.green(), color.blue(), color.alpha() );
  mPen.setColor( penColor );
}
Esempio n. 6
0
const QString NxDocument::serialize() const {
    QString retour;
    QString prefix = "\trun(\"", postfix = "\");\n";

    if(NxObjectDispatchProperty::source == ExecuteSourceGui) {
        //Textures
        QMapIterator<QString, UiRenderTexture*> textureIterator(*Render::textures);
        while (textureIterator.hasNext()) {
            textureIterator.next();
            UiRenderTexture *texture = textureIterator.value();
            if(texture->filename.exists()) {
                QString filename = getScriptFile().absoluteDir().relativeFilePath(texture->filename.absoluteFilePath());
                retour += prefix + QString("%1 %2 %3  %4 %5 %6 %7").arg(COMMAND_TEXTURE).arg(textureIterator.key()).arg(texture->mapping.topLeft().x()).arg(texture->mapping.topLeft().y()).arg(texture->mapping.bottomRight().x()).arg(texture->mapping.bottomRight().y()).arg(filename) + postfix;
            }
        }

        //Colors
        QMapIterator<QString, QColor> colorIterator(*Render::colors);
        while (colorIterator.hasNext()) {
            colorIterator.next();
            if(!((Render::defaultColors.contains(colorIterator.key())) && (Render::defaultColors.value(colorIterator.key()) == colorIterator.value()))) {
                QColor color = colorIterator.value();
                retour += prefix + QString("%1 %2  %3 %4 %5 %6").arg(COMMAND_GLOBAL_COLOR).arg(colorIterator.key()).arg(color.red()).arg(color.green()).arg(color.blue()).arg(color.alpha()) + postfix;
            }
        }

        retour += COMMAND_END;
    }

    //Browse groups
    foreach(NxGroup *group, groups)
        retour += group->serialize();

    return retour;
}
Esempio n. 7
0
void MythRenderD3D9::DrawRect(const QRect &rect, const QColor &color)
{
    if (!m_rect_vertexbuffer)
    {
        HRESULT hr = m_d3dDevice->CreateVertexBuffer(
                sizeof(VERTEX)*4,     D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
                D3DFVF_VERTEX,        D3DPOOL_DEFAULT,
                &m_rect_vertexbuffer, NULL);

        if (FAILED(hr))
        {
            VERBOSE(VB_IMPORTANT, D3DERR + "Failed to create vertex buffer");
            return;
        }
    }

    EnableBlending(false);
    SetTextureVertices(false);
    MultiTexturing(false);
    SetTexture(NULL, 0);

    QMutexLocker locker(&m_lock);
    D3DCOLOR clr = D3DCOLOR_ARGB(color.alpha(), color.red(),
                                 color.green(), color.blue());
    VERTEX *p_vertices;
    HRESULT hr = m_rect_vertexbuffer->Lock(0, 0, (VOID **)(&p_vertices),
                                           D3DLOCK_DISCARD);
    if (FAILED(hr))
    {
        VERBOSE(VB_IMPORTANT, D3DERR + "Failed to lock vertex buffer.");
        return;
    }

    p_vertices[0].x       = (float)rect.left();
    p_vertices[0].y       = (float)rect.top();
    p_vertices[0].z       = 0.0f;
    p_vertices[0].diffuse = clr;
    p_vertices[0].rhw     = 1.0f;
    p_vertices[1].x       = (float)(rect.left() + rect.width());
    p_vertices[1].y       = (float)rect.top();
    p_vertices[1].z       = 0.0f;
    p_vertices[1].diffuse = clr;
    p_vertices[1].rhw     = 1.0f;
    p_vertices[2].x       = (float)(rect.left() + rect.width());
    p_vertices[2].y       = (float)(rect.top() + rect.height());
    p_vertices[2].z       = 0.0f;
    p_vertices[2].diffuse = clr;
    p_vertices[2].rhw     = 1.0f;
    p_vertices[3].x       = (float)rect.left();
    p_vertices[3].y       = (float)(rect.top() + rect.height());
    p_vertices[3].z       = 0.0f;
    p_vertices[3].diffuse = clr;
    p_vertices[3].rhw     = 1.0f;

    hr = m_rect_vertexbuffer->Unlock();
    if (FAILED(hr))
    {
        VERBOSE(VB_IMPORTANT, D3DERR + "Failed to unlock vertex buffer");
        return;
    }

    hr = m_d3dDevice->SetStreamSource(0, m_rect_vertexbuffer,
                                      0, sizeof(VERTEX));
    if (FAILED(hr))
    {
        VERBOSE(VB_IMPORTANT, D3DERR + "SetStreamSource() failed");
        return;
    }

    hr = m_d3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
    if (FAILED(hr))
    {
        VERBOSE(VB_IMPORTANT, D3DERR + "DrawPrimitive() failed");
        return;
    }
}
Esempio n. 8
0
Color::Color(const QColor &c) : owner(false) {
	init(c.red(), c.green(), c.blue(), c.alpha());
}
Esempio n. 9
0
/*!
  Draw dots

  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param canvasRect Contents rectangle of the canvas
  \param from index of the first point to be painted
  \param to index of the last point to be painted

  \sa draw(), drawCurve(), drawSticks(), drawLines(), drawSteps()
*/
void QwtPlotCurve::drawDots( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect, int from, int to ) const
{
    const QColor color = painter->pen().color();

    if ( painter->pen().style() == Qt::NoPen || color.alpha() == 0 )
    {
        return;
    }

    const bool doFill = ( d_data->brush.style() != Qt::NoBrush )
            && ( d_data->brush.color().alpha() > 0 );
    const bool doAlign = QwtPainter::roundingAlignment( painter );

    QwtPointMapper mapper;
    mapper.setBoundingRect( canvasRect );
    mapper.setFlag( QwtPointMapper::RoundPoints, doAlign );

    if ( d_data->paintAttributes & FilterPoints )
    {
        if ( ( color.alpha() == 255 )
            && !( painter->renderHints() & QPainter::Antialiasing ) )
        {
            mapper.setFlag( QwtPointMapper::WeedOutPoints, true );
        }
    }

    if ( doFill )
    {
        mapper.setFlag( QwtPointMapper::WeedOutPoints, false );

        QPolygonF points = mapper.toPointsF( 
            xMap, yMap, data(), from, to );

        QwtPainter::drawPoints( painter, points );
        fillCurve( painter, xMap, yMap, canvasRect, points );
    }
    else if ( d_data->paintAttributes & ImageBuffer )
    {
        const QImage image = mapper.toImage( xMap, yMap,
            data(), from, to, d_data->pen, 
            painter->testRenderHint( QPainter::Antialiasing ),
            renderThreadCount() );

        painter->drawImage( canvasRect.toAlignedRect(), image );
    }
    else if ( d_data->paintAttributes & MinimizeMemory )
    {
        const QwtSeriesData<QPointF> *series = data();

        for ( int i = from; i <= to; i++ )
        {
            const QPointF sample = series->sample( i );

            double xi = xMap.transform( sample.x() );
            double yi = yMap.transform( sample.y() );

            if ( doAlign )
            {
                xi = qRound( xi );
                yi = qRound( yi );
            }

            QwtPainter::drawPoint( painter, QPointF( xi, yi ) );
        }
    }
    else
    {
        if ( doAlign )
        {
            const QPolygon points = mapper.toPoints(
                xMap, yMap, data(), from, to ); 

            QwtPainter::drawPoints( painter, points );
        }
        else
        {
            const QPolygonF points = mapper.toPointsF( 
                xMap, yMap, data(), from, to );

            QwtPainter::drawPoints( painter, points );
        }
    }
}
Esempio n. 10
0
QString DetailSection::ColorString(QColor c)
{
    return QString("%1,%2,%3,%4").arg(c.red()).arg(c.green()).arg(c.blue()).arg(c.alpha());
}
static inline QColor normalizeColor(const QColor &color)
{
    QColor newColor = QColor(color.name());
    newColor.setAlpha(color.alpha());
    return newColor;
}
Esempio n. 12
0
void locWmGlDisplay::drawRobot(QColor colour, float x, float y, float theta)
{
    const float robotHeight = 58.0f;
    const float robotWidth = 30.0f;
    glPushMatrix();
    glEnable(GL_BLEND);		// Turn Blending On
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_TEXTURE_2D);       // Disable Texture Mapping
    glTranslatef(x,y,0);    // Move to centre of robot.
    glRotatef(mathGeneral::rad2deg(theta),0.0f, 0.0f, 1.0f);

    glDisable(GL_DEPTH_TEST);		// Turn Z Buffer testing Off
    glDisable(GL_LIGHTING);      // Disable Global Lighting
    // Draw Aura
    glColor4ub(0,0,255,255);
    glBindTexture(GL_TEXTURE_2D, robotAuraTexture);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);    // Turn off filtering of textures
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);    // Turn off filtering of textures
    glBegin(GL_QUADS);
        glNormal3f(0.0f,0.0f,1.0f);	// Set The Normal
        glTexCoord2f(0.0f, 0.0f); glVertex3f(-robotWidth/2.0f,  -robotWidth/2.0f*1.2,  1.5);      // Bottom Left Of The Texture and Quad
        glTexCoord2f(1.0f, 0.0f); glVertex3f(-robotWidth/2.0f, robotWidth/2.0f*1.2,  1.5);    // Bottom Right Of The Texture and Quad
        glTexCoord2f(1.0f, 1.0f); glVertex3f(+robotWidth/2.0f, robotWidth/2.0f*1.2,  1.5);     // Top Right Of The Texture and Quad
        glTexCoord2f(0.0f, 1.0f); glVertex3f(+robotWidth/2.0f, -robotWidth/2.0f*1.2,  1.5);       // Top Left Of The Texture and Quad
    glEnd();
    glEnable(GL_DEPTH_TEST);		// Turn Z Buffer testing On
    glEnable(GL_LIGHTING);      // Enable Global Lighting

    glColor4ub(255,255,255,colour.alpha());
    if(drawRobotModel)
    {
        glTranslatef(0,0,robotHeight/2.0);    // Move to centre of robot.

        // Draw Front
        glBindTexture(GL_TEXTURE_2D, robotTexture);
            glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);    // Turn off filtering of textures
            glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);    // Turn off filtering of textures
            glBegin(GL_QUADS);
                glNormal3f(0.0f,0.0f,1.0f);	// Set The Normal
                glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f,  -robotWidth/2.0f,  -robotHeight/2.0);      // Bottom Left Of The Texture and Quad
                glTexCoord2f(1.0f, 0.0f); glVertex3f(0.0f, robotWidth/2.0f,  -robotHeight/2.0);    // Bottom Right Of The Texture and Quad
                glTexCoord2f(1.0f, 1.0f); glVertex3f(0.0f, robotWidth/2.0f,  robotHeight/2.0);     // Top Right Of The Texture and Quad
                glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, -robotWidth/2.0f,  robotHeight/2.0);       // Top Left Of The Texture and Quad
            glEnd();

        // Draw back
        glBindTexture(GL_TEXTURE_2D, robotBackTexture);
            glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);    // Turn off filtering of textures
            glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);    // Turn off filtering of textures
            glBegin(GL_QUADS);
                glNormal3f(0.0f,0.0f,1.0f);	// Set The Normal
                glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f,  robotWidth/2.0f,  -robotHeight/2.0);      // Bottom Left Of The Texture and Quad
                glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f, -robotWidth/2.0f,  -robotHeight/2.0);    // Bottom Right Of The Texture and Quad
                glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, -robotWidth/2.0f,  robotHeight/2.0);     // Top Right Of The Texture and Quad
                glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, robotWidth/2.0f,  robotHeight/2.0);       // Top Left Of The Texture and Quad
            glEnd();
    }

    glDisable(GL_TEXTURE_2D);       // Disable Texture Mapping
    glDisable(GL_BLEND);		// Turn Blending Off
    glPopMatrix();
}
Esempio n. 13
0
QImage AudioSpectrum::renderAudioScope(uint, const QVector<int16_t> audioFrame, const int freq, const int num_channels,
                                       const int num_samples, const int)
{
    if (
            audioFrame.size() > 63
            && m_innerScopeRect.width() > 0 && m_innerScopeRect.height() > 0    // <= 0 if widget is too small (resized by user)
    ) {
        if (!m_customFreq) {
            m_freqMax = freq / 2;
        }

        QTime start = QTime::currentTime();


#ifdef DETECT_OVERMODULATION
        bool overmodulated = false;
        int overmodulateCount = 0;

        for (int i = 0; i < audioFrame.size(); i++) {
            if (
                    audioFrame[i] == std::numeric_limits<int16_t>::max()
                    || audioFrame[i] == std::numeric_limits<int16_t>::min()) {
                overmodulateCount++;
                if (overmodulateCount > 3) {
                    overmodulated = true;
                    break;
                }
            }
        }
        if (overmodulated) {
            colorizeFactor = 1;
        } else {
            if (colorizeFactor > 0) {
                colorizeFactor -= .08;
                if (colorizeFactor < 0) {
                    colorizeFactor = 0;
                }
            }
        }
#endif


        // Determine the window size to use. It should be
        // * not bigger than the number of samples actually available
        // * divisible by 2
        int fftWindow = ui->windowSize->itemData(ui->windowSize->currentIndex()).toInt();
        if (fftWindow > num_samples) {
            fftWindow = num_samples;
        }
        if ((fftWindow & 1) == 1) {
            fftWindow--;
        }

        // Show the window size used, for information
        ui->labelFFTSizeNumber->setText(QVariant(fftWindow).toString());


        // Get the spectral power distribution of the input samples,
        // using the given window size and function
        float freqSpectrum[fftWindow/2];
        FFTTools::WindowType windowType = (FFTTools::WindowType) ui->windowFunction->itemData(ui->windowFunction->currentIndex()).toInt();
        m_fftTools.fftNormalized(audioFrame, 0, num_channels, freqSpectrum, windowType, fftWindow, 0);


        // Store the current FFT window (for the HUD) and run the interpolation
        // for easy pixel-based dB value access
        QVector<float> dbMap;
        m_lastFFTLock.acquire();
        m_lastFFT = QVector<float>(fftWindow/2);
        memcpy(m_lastFFT.data(), &(freqSpectrum[0]), fftWindow/2 * sizeof(float));

        uint right = ((float) m_freqMax)/(m_freq/2) * (m_lastFFT.size() - 1);
        dbMap = FFTTools::interpolatePeakPreserving(m_lastFFT, m_innerScopeRect.width(), 0, right, -180);
        m_lastFFTLock.release();


#ifdef DEBUG_AUDIOSPEC
        QTime drawTime = QTime::currentTime();
#endif

        // Draw the spectrum
        QImage spectrum(m_scopeRect.size(), QImage::Format_ARGB32);
        spectrum.fill(qRgba(0,0,0,0));
        const uint w = m_innerScopeRect.width();
        const uint h = m_innerScopeRect.height();
        const uint leftDist = m_innerScopeRect.left() - m_scopeRect.left();
        const uint topDist = m_innerScopeRect.top() - m_scopeRect.top();
        QColor spectrumColor(AbstractScopeWidget::colDarkWhite);
        int yMax;

#ifdef DETECT_OVERMODULATION
        if (colorizeFactor > 0) {
            QColor col = AbstractScopeWidget::colHighlightDark;
            QColor spec = spectrumColor;
            float f = std::sin(M_PI_2 * colorizeFactor);
            spectrumColor = QColor(
                        (int) (f * col.red() + (1-f) * spec.red()),
                        (int) (f * col.green() + (1-f) * spec.green()),
                        (int) (f * col.blue() + (1-f) * spec.blue()),
                        spec.alpha()
                        );
            // Limit the maximum colorization for non-overmodulated frames to better
            // recognize consecutively overmodulated frames
            if (colorizeFactor > MAX_OVM_COLOR) {
                colorizeFactor = MAX_OVM_COLOR;
            }
        }
#endif

#ifdef AUDIOSPEC_LINES
        QPainter davinci(&spectrum);
        davinci.setPen(QPen(QBrush(spectrumColor.rgba()), 1, Qt::SolidLine));
#endif

        for (uint i = 0; i < w; i++) {
            yMax = (dbMap[i] - m_dBmin) / (m_dBmax-m_dBmin) * (h-1);
            if (yMax < 0) {
                yMax = 0;
            } else if (yMax >= (int)h) {
                yMax = h-1;
            }
#ifdef AUDIOSPEC_LINES
            davinci.drawLine(leftDist + i, topDist + h-1, leftDist + i, topDist + h-1 - yMax);
#else
            for (int y = 0; y < yMax && y < (int)h; y++) {
                spectrum.setPixel(leftDist + i, topDist + h-y-1, spectrumColor.rgba());
            }
#endif
        }

        // Calculate the peak values. Use the new value if it is bigger, otherwise adapt to lower
        // values using the Moving Average formula
        if (m_aShowMax->isChecked()) {
            davinci.setPen(QPen(QBrush(AbstractScopeWidget::colHighlightLight), 2));
            if (m_peaks.size() != fftWindow/2) {
                m_peaks = QVector<float>(m_lastFFT);
            } else {
                for (int i = 0; i < fftWindow/2; i++) {
                    if (m_lastFFT[i] > m_peaks[i]) {
                        m_peaks[i] = m_lastFFT[i];
                    } else {
                        m_peaks[i] = ALPHA_MOVING_AVG * m_lastFFT[i] + (1-ALPHA_MOVING_AVG) * m_peaks[i];
                    }
                }
            }
            int prev = 0;
            m_peakMap = FFTTools::interpolatePeakPreserving(m_peaks, m_innerScopeRect.width(), 0, right, -180);
            for (uint i = 0; i < w; i++) {
                yMax = (m_peakMap[i] - m_dBmin) / (m_dBmax-m_dBmin) * (h-1);
                if (yMax < 0) {
                    yMax = 0;
                } else if (yMax >= (int)h) {
                    yMax = h-1;
                }

                davinci.drawLine(leftDist + i-1, topDist + h-prev-1, leftDist + i, topDist + h-yMax-1);
                spectrum.setPixel(leftDist + i, topDist + h-yMax-1, AbstractScopeWidget::colHighlightLight.rgba());
                prev = yMax;
            }
        }

#ifdef DEBUG_AUDIOSPEC
        m_showTotal++;
        m_timeTotal += drawTime.elapsed();
        qDebug() << widgetName() << " took " << drawTime.elapsed() << " ms for drawing. Average: " << ((float)m_timeTotal/m_showTotal) ;
#endif

        emit signalScopeRenderingFinished(start.elapsed(), 1);


        return spectrum;
    } else {
        emit signalScopeRenderingFinished(0, 1);
        return QImage();
    }
}
Esempio n. 14
0
Color::Color(const QColor& c)
    : m_color(makeRGBA(c.red(), c.green(), c.blue(), c.alpha()))
{
    m_valid = c.isValid();
}
Esempio n. 15
0
static QString colorToString(const QColor &color)
{
    if (color.alpha() != 255)
        return color.name(QColor::HexArgb);
    return color.name();
}
Esempio n. 16
0
void Document::loadTheme(const Theme& theme)
{
    m_text->document()->blockSignals(true);

    // Update colors
    QString contrast = (qGray(theme.textColor().rgb()) > 127) ? "black" : "white";
    QColor color = theme.foregroundColor();
    color.setAlpha(theme.foregroundOpacity() * 2.55f);
    m_text->setStyleSheet(
        QString("QTextEdit { background: rgba(%1, %2, %3, %4); color: %5; selection-background-color: %6; selection-color: %7; padding: %8px; border-radius: %9px; }")
        .arg(color.red())
        .arg(color.green())
        .arg(color.blue())
        .arg(color.alpha())
        .arg(theme.textColor().name())
        .arg(theme.textColor().name())
        .arg(contrast)
        .arg(theme.foregroundPadding())
        .arg(theme.foregroundRounding())
    );
    m_highlighter->setMisspelledColor(theme.misspelledColor());
    m_focusmode->setBlurredTextColor(theme.blurredTextColor());

    // Update text
    QFont font = theme.textFont();
    font.setStyleStrategy(m_text->font().styleStrategy());
    if (m_text->font() != font) {
        m_text->setFont(font);
    }
    m_text->setCursorWidth(!m_block_cursor ? 1 : m_text->fontMetrics().averageCharWidth());

    int margin = theme.foregroundMargin();
    m_layout->setColumnMinimumWidth(0, margin);
    m_layout->setColumnMinimumWidth(2, margin);
    if (theme.foregroundPosition() < 3) {
        m_text->setFixedWidth(theme.foregroundWidth());

        switch (theme.foregroundPosition()) {
        case 0:
            m_layout->setColumnStretch(0, 0);
            m_layout->setColumnStretch(2, 1);
            break;

        case 2:
            m_layout->setColumnStretch(0, 1);
            m_layout->setColumnStretch(2, 0);
            break;

        case 1:
        default:
            m_layout->setColumnStretch(0, 1);
            m_layout->setColumnStretch(2, 1);
            break;
        };
    } else {
        m_text->setMinimumWidth(theme.foregroundWidth());
        m_text->setMaximumWidth(maximumSize().height());

        m_layout->setColumnStretch(0, 0);
        m_layout->setColumnStretch(2, 0);
    }

    centerCursor(true);
    m_text->document()->blockSignals(false);
}
Esempio n. 17
0
void MainWindow::keyPressEvent(QKeyEvent* event)
{
    const bool altDown = event->modifiers() & Qt::AltModifier;
    const bool ctrlDown = event->modifiers() & Qt::ControlModifier;
    //const bool shiftDown = event->modifiers() & Qt::ShiftModifier;

    if (altDown && event->key() == Qt::Key_X)
    {
      m_actAxisX->setChecked(true);
    }
    else if (altDown && event->key() == Qt::Key_Y)
    {
      m_actAxisY->setChecked(true);
    }
    else if (altDown && event->key() == Qt::Key_Z)
    {
      m_actAxisZ->setChecked(true);
    }
    else if (ctrlDown && event->key() == Qt::Key_C)
    {
        QColor color = QColorDialog::getColor(Qt::white, this);
        m_paletteWidget->setActiveColor(Imath::Color4f((float)color.red()/255.0f,
                                                       (float)color.green()/255.0f,
                                                       (float)color.blue()/255.0f,
                                                       (float)color.alpha()/255.0f),
                                                       -1);
    }
    else if (ctrlDown && event->key() == Qt::Key_F)
    {
        // Frame the full extents no matter what
        m_glModelWidget->frame(true);
    }
    else if (event->key() == Qt::Key_F)
    {
        // Frame the data if it exists
        m_glModelWidget->frame(false);
    }
    else if (event->key() == Qt::Key_X)
    {
        m_paletteWidget->swapColors();
    }
    //else if (event->key() == Qt::Key_D)
    //{
    //    m_paletteWidget->setDefaultColors();
    //}

    else if (event->key() == Qt::Key_Q) m_actToolSplat->setChecked(true);
    else if (event->key() == Qt::Key_W) m_actToolReplace->setChecked(true);
    else if (event->key() == Qt::Key_E) m_actToolFlood->setChecked(true);
    else if (event->key() == Qt::Key_R) m_actToolDropper->setChecked(true);
    else if (event->key() == Qt::Key_T) m_actToolEraser->setChecked(true);
    else if (event->key() == Qt::Key_Y) m_actToolSlab->setChecked(true);
    else if (event->key() == Qt::Key_U) m_actToolLine->setChecked(true);
    else if (event->key() == Qt::Key_I) m_actToolBox->setChecked(true);
    else if (event->key() == Qt::Key_O) m_actToolExtrude->setChecked(true);

    else if (event->key() >= Qt::Key_Left && event->key() <= Qt::Key_PageDown)
    {
        m_glModelWidget->handleArrows(event);
    }
    else if (event->key() == Qt::Key_Space)
    {
        // It's okay to call setVoxelColor once on the model widget, but any more requires an internal wrapper
        m_glModelWidget->setVoxelColor(m_glModelWidget->activeVoxel(),
                                       m_glModelWidget->activeColor(),
                                       m_glModelWidget->activeIndex());
        m_glModelWidget->updateGL();
    }
    else if (event->key() == Qt::Key_Delete)
    {
        // It's okay to call setVoxelColor once on the model widget, but any more requires an internal wrapper
        m_glModelWidget->setVoxelColor(m_glModelWidget->activeVoxel(),
                                       Imath::Color4f(0.0f, 0.0f, 0.0f, 0.0f),
                                       0);
        m_glModelWidget->updateGL();
    }
}
Esempio n. 18
0
Color pWindow::backgroundColor() {
  if(window.state.backgroundColorOverride) return window.state.backgroundColor;
  QColor color = qtWindow->palette().color(QPalette::ColorRole::Window);
  return { (uint8_t)color.red(), (uint8_t)color.green(), (uint8_t)color.blue(), (uint8_t)color.alpha() };
}
Esempio n. 19
0
QString XlsxColor::toARGBString(const QColor &c)
{
    QString color;
    color.sprintf("%02X%02X%02X%02X", c.alpha(), c.red(), c.green(), c.blue());
    return color;
}
Esempio n. 20
0
QString ColorToRgba(const QColor& c) {
  return QString("rgba(%1, %2, %3, %4)")
      .arg(c.red()).arg(c.green()).arg(c.blue()).arg(c.alpha());
}
void QSGPropertyAnimator::updateProperty(QObject *target, const QString& p)
{
    QSGAnimatedProperty *ap = m_controller->registeredProperty(p, target);
    if (ap && m_duration > 0) {
        if (m_elapsed > m_startTime && ((m_elapsed < m_startTime + m_loops * m_duration) || (m_loops < 0))) {

            QVariant value = ap->value();
            qreal tx = int(m_elapsed - m_startTime) % int(m_duration);

            switch (value.type()) {
            case QMetaType::Double:
                value = QVariant(m_from.toReal() + (m_to.toReal() - m_from.toReal()) * m_easing.valueForProgress(tx / m_duration));
                break;
            case QMetaType::QColor:
                {
                QColor from = qvariant_cast<QColor>(m_from);
                QColor to = qvariant_cast<QColor>(m_to);
                QColor result = qvariant_cast<QColor>(value);
                result.setRed(from.red() + (to.red() - from.red()) * m_easing.valueForProgress(tx / m_duration));
                result.setGreen(from.green() + (to.green() - from.green()) * m_easing.valueForProgress(tx / m_duration));
                result.setBlue(from.blue() + (to.blue() - from.blue()) * m_easing.valueForProgress(tx / m_duration));
                result.setAlpha(from.alpha() + (to.alpha() - from.alpha()) * m_easing.valueForProgress(tx / m_duration));
                value = result;
                break;
                }
            case QMetaType::Int:
                value = QVariant(m_from.toInt() + (m_to.toInt() - m_from.toInt()) * m_easing.valueForProgress(tx / m_duration));
                break;
            case QMetaType::QSize:
                {
                QSize from = m_from.toSize();
                QSize to = m_to.toSize();
                QSize result = value.toSize();
                result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration));
                result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration));
                value = result;
                break;
                }
            case QMetaType::QSizeF:
                {
                QSizeF from = m_from.toSize();
                QSizeF to = m_to.toSize();
                QSizeF result = value.toSize();
                result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration));
                result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration));
                value = result;
                break;
                }
            case QMetaType::QPoint:
                {
                QPoint from = m_from.toPoint();
                QPoint to = m_to.toPoint();
                QPoint result = value.toPoint();
                result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration));
                result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration));
                value = result;
                break;
                }
            case QMetaType::QPointF:
                {
                QPointF from = m_from.toPointF();
                QPointF to = m_to.toPointF();
                QPointF result = value.toPointF();
                result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration));
                result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration));
                value = result;
                break;
                }
            case QMetaType::QRect:
                {
                QRect from = m_from.toRect();
                QRect to = m_to.toRect();
                QRect result = value.toRect();
                result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration));
                result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration));
                result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration));
                result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration));
                value = result;
                break;
                }
            case QMetaType::QRectF:
                {
                QRectF from = m_from.toRectF();
                QRectF to = m_to.toRectF();
                QRectF result = value.toRectF();
                result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration));
                result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration));
                result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration));
                result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration));
                value = result;
                break;
                }
            case QMetaType::QVector3D:
                {
                QVector3D from = qvariant_cast<QVector3D>(m_from);
                QVector3D to = qvariant_cast<QVector3D>(m_to);
                QVector3D result = qvariant_cast<QVector3D>(value);
                result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration));
                result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration));
                result.setZ(from.z() + (to.z() - from.z()) * m_easing.valueForProgress(tx / m_duration));
                value = result;
                break;
                }
            default:
                break;
            }
            ap->setValue(value);
        }
    }
}
Esempio n. 22
0
void PropertyEditorView::changeValue(const QString &name)
{
    PropertyName propertyName = name.toUtf8();

    if (propertyName.isNull())
        return;

    if (m_locked)
        return;

    if (propertyName == "type")
        return;

    if (!m_selectedNode.isValid())
        return;

    if (propertyName == "id") {
        PropertyEditorValue *value = m_qmlBackEndForCurrentType->propertyValueForName(propertyName);
        const QString newId = value->value().toString();

        if (newId == m_selectedNode.id())
            return;

        if (m_selectedNode.isValidId(newId)  && !hasId(newId)) {
            m_selectedNode.setIdWithRefactoring(newId);
        } else {
            m_locked = true;
            value->setValue(m_selectedNode.id());
            m_locked = false;
            if (!m_selectedNode.isValidId(newId))
                Core::AsynchronousMessageBox::warning(tr("Invalid Id"),  tr("%1 is an invalid id.").arg(newId));
            else
                Core::AsynchronousMessageBox::warning(tr("Invalid Id"),  tr("%1 already exists.").arg(newId));
        }
        return;
    }

    PropertyName underscoreName(propertyName);
    underscoreName.replace('.', '_');
    PropertyEditorValue *value = m_qmlBackEndForCurrentType->propertyValueForName(underscoreName);

    if (value ==0)
        return;

    QmlObjectNode qmlObjectNode(m_selectedNode);

    QVariant castedValue;

    if (qmlObjectNode.modelNode().metaInfo().isValid() && qmlObjectNode.modelNode().metaInfo().hasProperty(propertyName)) {
        castedValue = qmlObjectNode.modelNode().metaInfo().propertyCastedValue(propertyName, value->value());
    } else if (propertyIsAttachedLayoutProperty(propertyName)) {
        castedValue = value->value();
    } else {
        qWarning() << "PropertyEditor:" <<propertyName << "cannot be casted (metainfo)";
        return ;
    }

    if (value->value().isValid() && !castedValue.isValid()) {
        qWarning() << "PropertyEditor:" << propertyName << "not properly casted (metainfo)";
        return ;
    }

    if (qmlObjectNode.modelNode().metaInfo().isValid() && qmlObjectNode.modelNode().metaInfo().hasProperty(propertyName))
        if (qmlObjectNode.modelNode().metaInfo().propertyTypeName(propertyName) == "QUrl"
                || qmlObjectNode.modelNode().metaInfo().propertyTypeName(propertyName) == "url") { //turn absolute local file paths into relative paths
            QString filePath = castedValue.toUrl().toString();
        if (QFileInfo(filePath).exists() && QFileInfo(filePath).isAbsolute()) {
            QDir fileDir(QFileInfo(model()->fileUrl().toLocalFile()).absolutePath());
            castedValue = QUrl(fileDir.relativeFilePath(filePath));
        }
    }

        if (castedValue.type() == QVariant::Color) {
            QColor color = castedValue.value<QColor>();
            QColor newColor = QColor(color.name());
            newColor.setAlpha(color.alpha());
            castedValue = QVariant(newColor);
        }

        try {
            if (!value->value().isValid()) { //reset
                qmlObjectNode.removeProperty(propertyName);
            } else {
                if (castedValue.isValid() && !castedValue.isNull()) {
                    m_locked = true;
                    qmlObjectNode.setVariantProperty(propertyName, castedValue);
                    m_locked = false;
                }
            }
        }
        catch (const RewritingException &e) {
            e.showException();
        }
}
Esempio n. 23
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. 24
0
bool QDirectFbBlitter::drawCachedGlyphs(const QPaintEngineState *state, QFontEngine::GlyphFormat glyphFormat, int numGlyphs, const glyph_t *glyphs, const QFixedPoint *positions, QFontEngine *fontEngine)
{
    void *cacheKey = QDirectFbConvenience::dfbInterface();

    QDirectFbTextureGlyphCache *cache =
            static_cast<QDirectFbTextureGlyphCache *>(fontEngine->glyphCache(cacheKey, glyphFormat, state->transform()));
    if (!cache) {
        cache = new QDirectFbTextureGlyphCache(glyphFormat, state->transform());
        fontEngine->setGlyphCache(cacheKey, cache);
    }

    cache->populate(fontEngine, numGlyphs, glyphs, positions);
    cache->fillInPendingGlyphs();

    if (cache->image().width() == 0 || cache->image().height() == 0)
        return false;

    const int margin = fontEngine->glyphMargin(glyphFormat);

    QVarLengthArray<DFBRectangle, 64> sourceRects(numGlyphs);
    QVarLengthArray<DFBPoint, 64> destPoints(numGlyphs);
    int nGlyphs = 0;

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

        QFixed subPixelPosition = fontEngine->subPixelPositionForX(positions[i].x);
        QTextureGlyphCache::GlyphAndSubPixelPosition glyph(glyphs[i], subPixelPosition);
        const QTextureGlyphCache::Coord &c = cache->coords[glyph];
        if (c.isNull())
            continue;

        int x = qFloor(positions[i].x) + c.baseLineX - margin;
        int y = qRound(positions[i].y) - c.baseLineY - margin;

        // printf("drawing [%d %d %d %d] baseline [%d %d], glyph: %d, to: %d %d, pos: %d %d\n",
        //        c.x, c.y,
        //        c.w, c.h,
        //        c.baseLineX, c.baseLineY,
        //        glyphs[i],
        //        x, y,
        //        positions[i].x.toInt(), positions[i].y.toInt());

        sourceRects[nGlyphs].x = c.x;
        sourceRects[nGlyphs].y = c.y;
        sourceRects[nGlyphs].w = c.w;
        sourceRects[nGlyphs].h = c.h;
        destPoints[nGlyphs].x = x;
        destPoints[nGlyphs].y = y;
        ++nGlyphs;
    }

    const QColor color = state->pen().color();
    m_surface->SetColor(m_surface.data(), color.red(), color.green(), color.blue(), color.alpha());

    m_surface->SetSrcBlendFunction(m_surface.data(), DSBF_SRCALPHA);
    m_surface->SetDstBlendFunction(m_surface.data(), DSBF_INVSRCALPHA);

    int flags = DSBLIT_BLEND_ALPHACHANNEL | DSBLIT_COLORIZE;
    if (color.alpha() != 0xff)
        flags |= DSBLIT_BLEND_COLORALPHA;
    m_surface->SetBlittingFlags(m_surface.data(), DFBSurfaceBlittingFlags(flags));

    const QRasterPaintEngineState *rs = static_cast<const QRasterPaintEngineState*>(state);
    if (rs->clip && rs->clip->enabled) {
        Q_ASSERT(rs->clip->hasRectClip);
        DFBRegion dfbClip;
        dfbClip.x1 = rs->clip->clipRect.x();
        dfbClip.y1 = rs->clip->clipRect.y();
        dfbClip.x2 = rs->clip->clipRect.right();
        dfbClip.y2 = rs->clip->clipRect.bottom();
        m_surface->SetClip(m_surface.data(), &dfbClip);
    }

    m_surface->BatchBlit(m_surface.data(), cache->sourceSurface(), sourceRects.constData(), destPoints.constData(), nGlyphs);

    if (m_debugPaint) {
        for (int i = 0; i < nGlyphs; ++i) {
            drawDebugRect(QRect(destPoints[i].x, destPoints[i].y, sourceRects[i].w, sourceRects[i].h), QColor(Qt::yellow));
        }
    }

    if (rs->clip && rs->clip->enabled)
        m_surface->SetClip(m_surface.data(), 0);
    return true;
}
Esempio n. 25
0
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
  QPointF pagepos = pagePos();
  composerItemElem.setAttribute( "x", QString::number( pos().x() ) );
  composerItemElem.setAttribute( "y", QString::number( pos().y() ) );
  composerItemElem.setAttribute( "page", page() );
  composerItemElem.setAttribute( "pagex", QString::number( pagepos.x() ) );
  composerItemElem.setAttribute( "pagey", QString::number( pagepos.y() ) );
  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( "frameJoinStyle", QgsSymbolLayerV2Utils::encodePenJoinStyle( mFrameJoinStyle ) );
  composerItemElem.setAttribute( "itemRotation",  QString::number( mItemRotation ) );
  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;
}
QImage SpecularmapGenerator::calculateSpecmap(QImage input, double scale, double contrast) {
    QImage result(input.width(), input.height(), QImage::Format_ARGB32);

    //generate contrast lookup table
    unsigned short contrastLookup[256];
    double newValue = 0;

    for(int i = 0; i < 256; i++) {
        newValue = (double)i;
        newValue /= 255.0;
        newValue -= 0.5;
        newValue *= contrast;
        newValue += 0.5;
        newValue *= 255;

        if(newValue < 0)
            newValue = 0;
        if(newValue > 255)
            newValue = 255;

        contrastLookup[i] = (unsigned short)newValue;
    }

    #pragma omp parallel for  // OpenMP
    //for every row of the image
    for(int y = 0; y < result.height(); y++) {
        QRgb *scanline = (QRgb*) result.scanLine(y);

        //for every column of the image
        for(int x = 0; x < result.width(); x++) {
            double r, g, b, a;
            double intensity = 0.0;

            QColor pxColor = QColor(input.pixel(x, y));

            r = pxColor.redF() * redMultiplier;
            g = pxColor.greenF() * greenMultiplier;
            b = pxColor.blueF() * blueMultiplier;
            a = pxColor.alphaF() * alphaMultiplier;

            if(mode == IntensityMap::AVERAGE) {
                //take the average out of all selected channels
                double multiplierSum = (redMultiplier + greenMultiplier + blueMultiplier + alphaMultiplier);

                if(multiplierSum == 0.0)
                    multiplierSum = 1.0;

                intensity = (r + g + b + a) / multiplierSum;
            }
            else if(mode == IntensityMap::MAX) {
                //take the maximum out of all selected channels
                double tempMaxRG = std::max(r, g);
                double tempMaxBA = std::max(b, a);
                intensity = std::max(tempMaxRG, tempMaxBA);
            }

            //apply scale (brightness)
            intensity *= scale;

            if(intensity > 1.0)
                intensity = 1.0;

            //convert intensity to the 0-255 range
            int c = (int)(255.0 * intensity);

            //apply contrast
            c = (int)contrastLookup[c];

            //write color into image pixel
            scanline[x] = qRgba(c, c, c, pxColor.alpha());
        }
    }

    return result;
}
Esempio n. 27
0
void tst_QColor::setHsl()
{
    QColor color;

    for (int A = 0; A <= USHRT_MAX; ++A) {
        {
            // 0-255
            int a = A >> 8;
            color.setHsl(0, 0, 0, a);
            QCOMPARE(color.alpha(), a);

            int h, s, l, a2;
            color.getHsv(&h, &s, &l, &a2);
            QCOMPARE(a2, a);
        }

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

            qreal h, s, l, a2;
            color.getHslF(&h, &s, &l, &a2);
            QCOMPARE(a2, a);
        }
    }

    for (int H = 0; H < 36000; ++H) {
        {
            // 0-255
            int h = H / 100;

            color.setHsl(h, 0, 0, 0);
            QCOMPARE(color.hslHue(), h);

            int h2, s, l, a;
            color.getHsl(&h2, &s, &l, &a);
            QCOMPARE(h2, h);
        }

        {
            // 0.0-1.0
            qreal h = H / 36000.0;
            color.setHslF(h, 0.0, 0.0, 0.0);
            QCOMPARE(color.hslHueF(), h);

            qreal h2, s, l, a;
            color.getHslF(&h2, &s, &l, &a);
            QCOMPARE(h2, h);
        }
    }

    for (int S = 0; S <= USHRT_MAX; ++S) {
        {
            // 0-255
            int s = S >> 8;
            color.setHsl(0, s, 0, 0);
            QCOMPARE(color.hslSaturation(), s);

            int h, s2, l, a;
            color.getHsl(&h, &s2, &l, &a);
            QCOMPARE(s2, s);
        }

        {
            // 0.0-1.0
            qreal s = S / qreal(USHRT_MAX);
            color.setHslF(0.0, s, 0.0, 0.0);
            QCOMPARE(color.hslSaturationF(), s);

            qreal h, s2, l, a;
            color.getHslF(&h, &s2, &l, &a);
            QCOMPARE(s2, s);
        }
    }

    for (int L = 0; L <= USHRT_MAX; ++L) {
        {
            // 0-255
            int l = L >> 8;
            color.setHsl(0, 0, l, 0);
            QCOMPARE(color.lightness(),  l);

            int h, s, l2, a;
            color.getHsl(&h, &s, &l2, &a);
            QCOMPARE(l2, l);
        }

        {
            // 0.0-1.0
            qreal l = L / qreal(USHRT_MAX);
            color.setHslF(0.0, 0.0, l, 0.0);
            QCOMPARE(color.lightnessF(), l);

            qreal h, s, l2, a;
            color.getHslF(&h, &s, &l2, &a);
            QCOMPARE(l2, l);
        }
    }
}
Esempio n. 28
0
void ShapeEntityItem::setColor(const QColor& value) {
    setColor(rgbColor { (uint8_t)value.red(), (uint8_t)value.green(), (uint8_t)value.blue() });
    setAlpha(value.alpha());
}
Esempio n. 29
0
void tst_QColor::setHsv()
{
    QColor color;

    for (int A = 0; A <= USHRT_MAX; ++A) {
        {
            // 0-255
            int a = A >> 8;
            color.setHsv(0, 0, 0, a);
            QCOMPARE(color.alpha(), a);

            int h, s, v, a2;
            color.getHsv(&h, &s, &v, &a2);
            QCOMPARE(a2, a);
        }

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

            qreal h, s, v, a2;
            color.getHsvF(&h, &s, &v, &a2);
            QCOMPARE(a2, a);
        }
    }

    for (int H = 0; H < 36000; ++H) {
        {
            // 0-255
            int h = H / 100;

            color.setHsv(h, 0, 0, 0);
            QCOMPARE(color.hue(), h);

            int h2, s, v, a;
            color.getHsv(&h2, &s, &v, &a);
            QCOMPARE(h2, h);
        }

        {
            // 0.0-1.0
            qreal h = H / 36000.0;
            color.setHsvF(h, 0.0, 0.0, 0.0);
            QCOMPARE(color.hueF(), h);

            qreal h2, s, v, a;
            color.getHsvF(&h2, &s, &v, &a);
            QCOMPARE(h2, h);
        }
    }

    for (int S = 0; S <= USHRT_MAX; ++S) {
        {
            // 0-255
            int s = S >> 8;
            color.setHsv(0, s, 0, 0);
            QCOMPARE(color.saturation(), s);

            int h, s2, v, a;
            color.getHsv(&h, &s2, &v, &a);
            QCOMPARE(s2, s);
        }

        {
            // 0.0-1.0
            qreal s = S / qreal(USHRT_MAX);
            color.setHsvF(0.0, s, 0.0, 0.0);
            QCOMPARE(color.saturationF(), s);

            qreal h, s2, v, a;
            color.getHsvF(&h, &s2, &v, &a);
            QCOMPARE(s2, s);
        }
    }

    for (int V = 0; V <= USHRT_MAX; ++V) {
        {
            // 0-255
            int v = V >> 8;
            color.setHsv(0, 0, v, 0);
            QCOMPARE(color.value(),  v);

            int h, s, v2, a;
            color.getHsv(&h, &s, &v2, &a);
            QCOMPARE(v2, v);
        }

        {
            // 0.0-1.0
            qreal v = V / qreal(USHRT_MAX);
            color.setHsvF(0.0, 0.0, v, 0.0);
            QCOMPARE(color.valueF(), v);

            qreal h, s, v2, a;
            color.getHsvF(&h, &s, &v2, &a);
            QCOMPARE(v2, v);
        }
    }
}
Esempio n. 30
0
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" );
    }

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

    composerItemElem.setAttribute( "lastValidViewScaleFactor", 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 );

    itemElem.appendChild( composerItemElem );

    return true;
}