Example #1
0
void EyedropperTool::mouseReleaseEvent(QMouseEvent *event)
{
    Layer* layer = mEditor->layers()->currentLayer();
    if (layer == NULL) { return; }

    if (event->button() == Qt::LeftButton)
    {
        if (layer->type() == Layer::BITMAP)
        {
            BitmapImage* targetImage = ((LayerBitmap *)layer)->getLastBitmapImageAtFrame( mEditor->currentFrame(), 0);
            //QColor pickedColour = targetImage->pixel(getLastPoint().x(), getLastPoint().y());
            QColor pickedColour;
            pickedColour.setRgba( targetImage->pixel( getLastPoint().x(), getLastPoint().y() ) );
            int transp = 255 - pickedColour.alpha();
            pickedColour.setRed( pickedColour.red() + transp );
            pickedColour.setGreen( pickedColour.green() + transp );
            pickedColour.setBlue( pickedColour.blue() + transp );
            if (pickedColour.alpha() != 0)
            {
                mEditor->color()->setColor(pickedColour);
            }
        }
        else if (layer->type() == Layer::VECTOR)
        {
            VectorImage *vectorImage = ((LayerVector *)layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
            int colourNumber = vectorImage->getColourNumber(getLastPoint());
            if (colourNumber != -1)
            {
                mEditor->color()->setColorNumber(colourNumber);
            }
        }
    }
}
Example #2
0
void BrushShape::fromBitMap(const char* fileName){
    QImage image(fileName,0);
    if ( image.isNull() ){
        return;
    }

    m_radius = -1;
    m_sigma = -1;

    m_width = image.width();
    m_height = image.height();

    int x_radius = m_width/2;
    int y_radius = m_height/2;

    QColor pixelColor;
    for (int x=-x_radius;x<x_radius;x++){
        for (int y=-y_radius;y<y_radius;y++)
        {
            pixelColor.setRgba( image.pixel(x+x_radius,y+y_radius) );
            Bristle b(x,y , (float)pixelColor.value()/255.0f); // using value from image as length of bristle
            m_bristles.append(b);
        }
    }

}
QImage DwarfClipboardPng::getTileFromScreen(DFHack::t_screen screen)
{
    QColor foregroundColor = getForegroundColorFromScreen(screen);
    QColor backgroundColor = getBackgroundColorFromScreen(screen);
    QImage tile = tileSet->copy((screen.symbol % 16)*tileWidth,int(screen.symbol/16)*tileHeight,tileWidth,tileHeight);
    QImage resultImage(tileWidth,tileHeight,QImage::Format_ARGB32);
    for(int x = 0;x< tile.width();x++){
        for(int y =0;y<tile.height();y++){
            QColor color;
            color.setRgba(tile.pixel(x,y));
            if(color == QColor("#FF00FF")){ // FF00FF is magenta
                resultImage.setPixel(x,y,backgroundColor.rgb());
            }
            else{
                QColor newColor;
                qreal alpha = color.alphaF();
                qreal alpha_diff = 1-alpha;
                newColor.setRedF((alpha * (color.redF() * foregroundColor.redF() )) + (alpha_diff * backgroundColor.redF()));
                newColor.setGreenF((alpha * (color.greenF() * foregroundColor.greenF() )) + (alpha_diff * backgroundColor.greenF()));
                newColor.setBlueF((alpha * (color.blueF() * foregroundColor.blueF() )) + (alpha_diff * backgroundColor.blueF()));
                resultImage.setPixel(x,y,newColor.rgb());
            }
        }
    }
    return(resultImage);
}
Example #4
0
void tst_QColor::setNamedColor()
{
    for (int i = 0; i < rgbTblSize; ++i) {
        QColor color;
        color.setNamedColor(QLatin1String(rgbTbl[i].name));
        QColor expected;
        expected.setRgba(rgbTbl[i].value);
        QCOMPARE(color, expected);
    }
}
Example #5
0
void tst_QColor::setRgba()
{
    for (int a = 0; a < 255; ++a) {
        const QRgb rgba1 = qRgba(a, a, a, a);
        QColor color;
        color.setRgba(rgba1);
        QCOMPARE(color.alpha(), a);
        const QRgb rgba2 = color.rgba();
        QCOMPARE(rgba2, rgba1);
        QCOMPARE(qAlpha(rgba2), a);
    }
}
void ColorButton::chooseColor() {

  bool ok;
  if (_color == Qt::transparent) {
    _color = Qt::black;
  }
  QRgb rgba = QColorDialog::getRgba(_color.rgba(), &ok, parentWidget());
  if (ok) {
    QColor color;
    color.setRgba(rgba);
    setColor(color);
  }
}
Example #7
0
void mW::on_btnSelectBgColor_clicked()
{
  int r,g,b;
  QColor myColor;
  myColor.setRgba(QColorDialog::getRgba(0x00));
  myColor.getRgb(&r,&g,&b);
  
  QString bgColorStyleSheet;
  char sh[64];
  sprintf(sh, "background-color: rgb(%i, %i, %i);", r,g,b);
  bgColorStyleSheet=sh;
  btnSelectBgColor->setStyleSheet(bgColorStyleSheet);
  sprintf(sh, "%02x%02x%02x",r,g,b);
  osggBackgroundColor=sh;
}
Example #8
0
void EyedropperTool::mouseMoveEvent(QMouseEvent *event)
{
    Q_UNUSED(event);

    Layer* layer = mEditor->layers()->currentLayer();
    if (layer == NULL) { return; }

    if (layer->type() == Layer::BITMAP)
    {
        BitmapImage *targetImage = ((LayerBitmap *)layer)->getLastBitmapImageAtFrame(mEditor->currentFrame(), 0);
        if (targetImage->contains(getCurrentPoint()))
        {
            QColor pickedColour;
            //pickedColour.setRgba(targetImage->pixel(getCurrentPoint().x(), getCurrentPoint().y()));
            pickedColour.setRgba( targetImage->pixel( getCurrentPoint().x(), getCurrentPoint().y() ) );
            int transp = 255 - pickedColour.alpha();
            pickedColour.setRed( pickedColour.red() + transp );
            pickedColour.setGreen( pickedColour.green() + transp );
            pickedColour.setBlue( pickedColour.blue() + transp );
            if (pickedColour.alpha() != 0)
            {
                mScribbleArea->setCursor(cursor(pickedColour));
            }
            else
            {
                mScribbleArea->setCursor(cursor());
            }
        }
        else
        {
            mScribbleArea->setCursor(cursor());
        }
    }
    if (layer->type() == Layer::VECTOR)
    {
        VectorImage *vectorImage = ((LayerVector *)layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0);
        int colourNumber = vectorImage->getColourNumber(getCurrentPoint());
        if (colourNumber != -1)
        {
            mScribbleArea->setCursor(cursor(mEditor->object()->getColour(colourNumber).colour));
        }
        else
        {
            mScribbleArea->setCursor(cursor());
        }
    }
}
Example #9
0
void StyleSheetEditorDialog::slotAddColor(const QString &property)
{
    bool ok;
    QRgb rgba = QColorDialog::getRgba(0xffffffff, &ok, this);
    if (!ok)
        return;

    QColor color;
    color.setRgba(rgba);
    QString colorStr;

    if (color.alpha() == 255) {
        colorStr = QString("rgb(%1, %2, %3)").arg(
                color.red()).arg(color.green()).arg(color.blue());
    } else {
        colorStr = QString("rgba(%1, %2, %3, %4)").arg(
                color.red()).arg(color.green()).arg(color.blue()).arg(color.alpha());
    }

    insertCssProperty(property, colorStr);
}
/*!
  Draw a color bar into a rectangle

  \param painter Painter
  \param colorMap Color map
  \param interval Value range
  \param scaleMap Scale map
  \param orientation Orientation
  \param rect Traget rectangle
*/
void QwtPainter::drawColorBar( QPainter *painter,
        const QwtColorMap &colorMap, const QwtInterval &interval,
        const QwtScaleMap &scaleMap, Qt::Orientation orientation,
        const QRectF &rect )
{
    QVector<QRgb> colorTable;
    if ( colorMap.format() == QwtColorMap::Indexed )
        colorTable = colorMap.colorTable( interval );

    QColor c;

    const QRect devRect = rect.toAlignedRect();

    /*
      We paint to a pixmap first to have something scalable for printing
      ( f.e. in a Pdf document )
     */

    QPixmap pixmap( devRect.size() );
    QPainter pmPainter( &pixmap );
    pmPainter.translate( -devRect.x(), -devRect.y() );

    if ( orientation == Qt::Horizontal )
    {
        QwtScaleMap sMap = scaleMap;
        sMap.setPaintInterval( rect.left(), rect.right() );

        for ( int x = devRect.left(); x <= devRect.right(); x++ )
        {
            const double value = sMap.invTransform( x );

            if ( colorMap.format() == QwtColorMap::RGB )
                c.setRgba( colorMap.rgb( interval, value ) );
            else
                c = colorTable[colorMap.colorIndex( interval, value )];

            pmPainter.setPen( c );
            pmPainter.drawLine( x, devRect.top(), x, devRect.bottom() );
        }
    }
    else // Vertical
    {
        QwtScaleMap sMap = scaleMap;
        sMap.setPaintInterval( rect.bottom(), rect.top() );

        for ( int y = devRect.top(); y <= devRect.bottom(); y++ )
        {
            const double value = sMap.invTransform( y );

            if ( colorMap.format() == QwtColorMap::RGB )
                c.setRgb( colorMap.rgb( interval, value ) );
            else
                c = colorTable[colorMap.colorIndex( interval, value )];

            pmPainter.setPen( c );
            pmPainter.drawLine( devRect.left(), y, devRect.right(), y );
        }
    }
    pmPainter.end();

    drawPixmap( painter, rect, pixmap );
}