Example #1
0
ColorSchema::ColorSchema(KConfig& c)
:m_fileRead(false)
,fRelPath(QString::null)
,lastRead(0L)
{
  clearSchema();

  c.setGroup("SchemaGeneral");

  m_title = c.readEntry("Title",i18n("[no title]"));
  m_imagePath = c.readEntry("ImagePath");
  m_alignment = c.readNumEntry("ImageAlignment",1);
  m_useTransparency = c.readBoolEntry("UseTransparency",false);

  m_tr_r = c.readNumEntry("TransparentR",0);
  m_tr_g = c.readNumEntry("TransparentG",0);
  m_tr_b = c.readNumEntry("TransparentB",0);
  m_tr_x = c.readDoubleNumEntry("TransparentX",0.0);

  for (int i=0; i < TABLE_COLORS; i++)
  {
    readConfigColor(c,colorName(i),m_table[i]);
  }

  m_numb = serial++;
}
Example #2
0
File: graph.c Project: crcox/lens
char *nextColor(void) {
  static int last = 0;
  char *color = (char *) safeMalloc(8, "color");
  colorName(color, (real) last / 16, 1.0, 0.75);
  last = (last + 3) % 16;
  return color;
}
Example #3
0
QStringList PointSetStyles::colorNames(void)
{
  QStringList list;
  for (int color = 0; color < (int) DigitMaxColor; color++)
    list.append(colorName((Color) color));
  
  return list;
}
Example #4
0
Color PointSetStyles::color(QString text)
{
  for (int color = 0; color < (int) DigitMaxColor; color++)
    if (text == colorName((Color) color))
      return (Color) color;

  return (Color) 0;
}
Example #5
0
bool ColorIsPantone(const AIColor color)
{
    //If the swatch name includes "PANTONE" return true
    string s = GetColorName(color);
    ai::UnicodeString colorName(s);
    if (colorName.caseFind(ai::UnicodeString("PANTONE"), 0) != string::npos)
    {
        return TRUE;
    }
    return FALSE;
}
Example #6
0
AIColor GetColorDefinitionFromBook(string name, bool& found)
{
    found = FALSE;
    AIColor resultColor;
    AICustomColor tColor;
    ai::UnicodeString colorName(name);
    if (colorName.caseFind(ai::UnicodeString("PANTONE"), 0) != string::npos)
    {
        //Get the definition from the swatch book and replace the current definition
        //If the name matches one in the book, store the attributes in customColor
        if ( sAISwatchLibrary->FindStandardBookColor(colorName, &tColor) )
        {
            found = TRUE;
        }
        else //If the color says "PANTONE" but can't be found, turn it to PANTONE ### U and look it up
        {
            string s = colorName.as_Platform();

            string formattedResult = GetInnerPantoneColorNumber(s);

            formattedResult = "PANTONE " + formattedResult + " U";

            if ( sAISwatchLibrary->FindStandardBookColor(ai::UnicodeString(formattedResult), &tColor) )
            {
                colorName = ai::UnicodeString(formattedResult);
                found = TRUE;
            }
        }
    }

    AICustomColorHandle tColorHandle;
    ASErr err = sAICustomColor->NewCustomColor(&tColor, colorName, &tColorHandle);
    string error = GetIllustratorErrorCode(err);

    if (found == TRUE)
    {
        if (err == kNameInUseErr)
        {
            sAICustomColor->NewCustomColor(&tColor, ai::UnicodeString("DUMMY NAME"), &tColorHandle);
            sAICustomColor->GetCustomColorByName(ai::UnicodeString(colorName), &tColorHandle);
        }

        sAICustomColor->SetCustomColor(tColorHandle, &tColor);
        resultColor = {.kind = kCustomColor, .c.c.color = tColorHandle, .c.c.tint = 0};

        return resultColor;
    }
    else
    {
        return resultColor;
    }
}
Example #7
0
WidgetColor::WidgetColor (QWidget *parent, const QString &name)
    : WidgetBase (parent, name)
{
    const int w = (width () - 2 /*margin*/ - 2 /*spacing*/) / 3;
    const int h = (height () - 2 /*margin*/ - 3 /*spacing*/) / 3;

    for (unsigned int color = 0; color < sizeof(ColorTable) / sizeof(int); color++)
    {
        QImage previewPixmap (w, h, QImage::Format_ARGB32);
        previewPixmap.fill(Qt::transparent);
        QPainter painter(&previewPixmap);
        painter.fillRect(2,2,previewPixmap.width() - 4,previewPixmap.height() - 4,ColorTable1[color]);

        addOption (QPixmap::fromImage(previewPixmap), colorName (color) /*tooltip*/);

        if (color % 3 == 2)
            startNewOptionRow ();
    }

    finishConstruction (0, 0);
}
Example #8
0
void ColorSchema::writeConfig(const QString& path) const
{
//  KONSOLEDEBUG << "Writing schema " << relPath << " to file " << path << endl;

  KConfig c(path,false,false);

  c.setGroup("SchemaGeneral");
  c.writeEntry("Title",m_title);
  c.writeEntry("ImagePath",m_imagePath);
  c.writeEntry("ImageAlignment",m_alignment);
  c.writeEntry("UseTransparency",m_useTransparency);

  c.writeEntry("TransparentR",m_tr_r);
  c.writeEntry("TransparentG",m_tr_g);
  c.writeEntry("TransparentB",m_tr_b);
  c.writeEntry("TransparentX",m_tr_x);

  for (int i=0; i < TABLE_COLORS; i++)
  {
    writeConfigColor(c,colorName(i),m_table[i]);
  }
}
Example #9
0
int RazdsParser::ParseCOLS( FILE *fp )
{
    int ret;
    colTable *ct = new colTable;

    // get color table name
    ChopS52Line( pBuf, '\0' );

    ct->tableName = new wxString( pBuf + 19, wxConvUTF8 );

    ColorTableArray->Add( (void *) ct );

    // read color
    ret = ReadS52Line( pBuf, NEWLN, 0, fp );
    while( 0 != strncmp( pBuf, "****", 4 ) ) {
        double x, y, L;

        S52color c;

        ChopS52Line( pBuf, ' ' );
        strncpy( c.colName, pBuf + 9, 5 );
        c.colName[5] = 0;

        sscanf( pBuf + 14, "%lf %lf %lf", &x, &y, &L );

        _CIE2RGB( &c, x, y, L );

        wxString colorName( c.colName, wxConvUTF8 );
        ct->colors[colorName] = c;
        wxColour wxcolor( c.R, c.G, c.B );
        ct->wxColors[colorName] = wxcolor;

        ret = ReadS52Line( pBuf, NEWLN, 0, fp );
    }
    return ret;
}
Example #10
0
void BpDocument::composeLineGraph( int yid, EqVar *xVar, EqVar *yVar,
    EqVar *zVar, GraphAxleParms *xParms, GraphAxleParms *yParms )
{
    //--------------------------------------------------------------------------
    // 1: Set up fonts, pens, and colors used by this graph
    //--------------------------------------------------------------------------

    // Graph fonts
    QFont  textFont( property()->string( "graphTextFontFamily" ),
                    property()->integer( "graphTextFontSize" ) );
    QColor textColor( property()->color( "graphTextFontColor" ) );
    QPen   textPen( textColor );
    // How many colors are requested?
    QString colorName( property()->color( "graphLineColor" ) );
    int colors = 1;
    if ( colorName == "rainbow" )
    {
        colors = property()->integer( "graphRainbowColors" );
    }
    // Allocate number of requested colors.
    QColor *color = new QColor [colors];
    checkmem( __FILE__, __LINE__, color, "QColor color", colors );
    int colorId = 0;
    // If only 1 color...
    if ( colors == 1 )
    {
        color[0].setNamedColor( colorName );
    }
    // else if rainbow colors are requested...
    else
    {
        // todo - add some code to check conflicts with graphBackgroundColor
        // and graphGridColor (if graphGridWidth > 0 ).
        int hue = 0;
        for ( colorId = 0;
              colorId < colors;
              colorId++ )
        {
            color[colorId].setHsv( hue, 255, 255);
            hue += 360 / colors;
        }
        colorId = 0;
    }
    // Set up line width and color
    int lineWidth = property()->integer( "graphLineWidth" );
    QPen pen( color[0], lineWidth, SolidLine );

    //--------------------------------------------------------------------------
    // 2: Create the graph and add its curves.
    //--------------------------------------------------------------------------

    // Initialize graph and variables
    Graph      g;
    GraphLine *line[graphMaxLines];
    double     l_x[graphMaxSteps];
    double     l_y[graphMaxSteps];
    int        curves = ( tableCols() < graphMaxLines )
                  ? ( tableCols() )
                  : ( graphMaxLines );
    int        points = tableRows();
    int        vStep  = tableCols() * tableVars();

    // Loop for each zVar family curve value in this graph (or at least once!).
    // Note that zVar count is in tableCols(), e.g. each column stores a curve,
    // and zVar values are in tableCol( col ).
    int col, vid;
    for ( col = 0;
          col < curves;
          col++ )
    {
        // tableVal[] offset of first y-value for this curve.
        vid = yid + col * tableVars();
        // Set up the y[point] array for this curve.
        // Note number of points is in tableRows() and
        // point x values are in tableRow( point ).
        for ( int point = 0;
              point < points;
              point++ )
        {
            l_x[point] = tableRow( point );
            l_y[point] = tableVal( vid );
            vid += vStep;
        }
        // If we're out of colors, start over.
        if ( colorId >= colors )
        {
            colorId = 0;
        }
        // Create a graph line (with its own copy of the data).
        pen.setColor( color[colorId++] );
        line[col] = g.addGraphLine( points, l_x, l_y, pen );
    } // Next z-variable curve.

    //--------------------------------------------------------------------------
    // 3: Add curve labels if there is more than 1 curve.
    //--------------------------------------------------------------------------

    QString label;
    if ( curves > 1 )
    {
        colorId = 0;

#define GRAPH_LABEL_METHOD_1

#ifdef GRAPH_LABEL_METHOD_1
        // Label x array index step size between labels
        int j1 = points / curves;
        if ( j1 < 1 )
        {
            j1 = 1;
        }
        // Label x array index offset
        int j0 = j1 / 2;
#endif
        double xLabel, yLabel;
        int idx;
        // Loop for each z-variable curve.
        for ( col = 0;
              col < curves;
              col++ )
        {
            // Get a new color for the curve.
            if ( colorId >= colors )
            {
                colorId = 0;
            }
            // Set the curve label.
            if ( zVar->isDiscrete() )
            {
                int iid = (int) tableCol( col );
                label = zVar->m_itemList->itemName( iid );
            }
            else if ( zVar->isContinuous() )
            {
				int decimals = zVar->m_displayDecimals;
                label.sprintf( "%1.*f",
                    zVar->m_displayDecimals, tableCol( col ) );
				// Remove all trailing zeros
				while ( decimals && label.endsWith( "0" ) )
				{
					label = label.left( label.length()-1 );
					decimals--;
				}
            }

#ifdef GRAPH_LABEL_METHOD_1
            // Determine an x-axis index for the label position.
            idx = ( j0 + col * j1 ) % points;
            xLabel = line[col]->m_x[idx];
            yLabel = line[col]->m_y[idx];
#endif

#ifdef GRAPH_LABEL_METHOD_2
            // NEW LABEL POSITIONING METHOD STARTS HERE
            // Find the x position where this variable has the maximum y
            // clearance
            // Loop for each x value for this curve
            idx = 0;
            double dMax = 0;
            double dir  = 1.;
            double yMin = yParms->m_axleMin;
            double yMax = yParms->m_axleMax;
            for ( int row=1; row<tableRows()-1; row++ )
            {
                // Find vertical clearance above and below this x point
                double y0 = m_eqTree->getResult( row, col, yid );
                // Don't consider locations outside the viewport
                if ( y0 < yMin || y0 > yMax )
                {
                    continue;
                }
                double below = y0 - yMin;
                double above = yMax - y0;
                double dist, y1;
                // Loop for each family member curve
                for ( int c=0; c<curves; c++ )
                {
                    // Skip self
                    if ( c == col )
                    {
                        continue;
                    }
                    y1 = m_eqTree->getResult( row, c, yid );
                    y1 = ( y1 < yMax ) ? y1 : yMax;
                    y1 = ( y1 > yMin ) ? y1 : yMin;
                    // Shrink vertical clearance above and below this x point?
                    if ( y0 <= y1 )
                    {
                        dist = y1 - y0;
                        above = ( dist < above ) ? dist : above;
                    }
                    else
                    {
                        dist = y0 - y1;
                        below = ( dist < below ) ? dist : below;
                    }
                }
                // Is this the maximum vertical clearance so far?
                if ( above + below > dMax )
                {
                    dMax = above + below;
                    idx  = row;
                    dir  = ( above > below ) ? 1. : -1;
                }
            }
            xLabel = line[col]->m_x[idx];
            double offset = dir * 0.02 * ( yMax - yMin );
            yLabel = line[col]->m_y[idx] + offset;
#endif
            // Set the label text, font, color, and position.
            line[col]->setGraphLineLabel( label, xLabel, yLabel, textFont,
                QColor( color[colorId++] ) );
        } // Next curve.

        // Add a z-variable label to the graph.
        label = *(zVar->m_label);
        if ( zVar->isContinuous() )
        {
            label = *(zVar->m_label) + "\n" + zVar->displayUnits(true);
        }
        g.setMultipleCurveLabel( label );
    }

    //--------------------------------------------------------------------------
    // 4: Compose the graph and add an output page to draw it onto
    //--------------------------------------------------------------------------

    composeGraphBasics( &g, true, xVar, yVar, zVar, curves, xParms, yParms );

    // Create a separate output page for this graph.
    QString text("");
    translate( text, "BpDocument:Graphs:By" );
    label = *(yVar->m_label) + " " + text + " " + *(xVar->m_label);
    if ( curves > 1 )
    {
        translate( text, "BpDocument:Graphs:And" );
        label += " " + text + " " + *(zVar->m_label);
    }
    startNewPage( label, TocLineGraph );

    // This is how we save the graph and its composer.
    m_composer->graph( g,
        m_pageSize->m_marginLeft
            + m_pageSize->m_bodyWd * property()->real( "graphXOffset" ),
        m_pageSize->m_marginTop
            + m_pageSize->m_bodyHt * property()->real( "graphYOffset" ),
        m_pageSize->m_bodyWd * property()->real( "graphScaleWidth" ),
        m_pageSize->m_bodyHt * property()->real( "graphScaleHeight" )
    );

    // Be polite and stop the composer.
    m_composer->end();
    delete[] color;
    return;
}
Example #11
0
void BpDocument::composeBarGraph( int yid, EqVar *xVar, EqVar *yVar,
        GraphAxleParms *xParms, GraphAxleParms *yParms )
{
    //--------------------------------------------------------------------------
    // 1: Set up fonts, pens, and colors used by this graph
    //--------------------------------------------------------------------------

    // Graph fonts.
    QFont textFont( property()->string( "graphTextFontFamily" ),
                    property()->integer( "graphTextFontSize" ) );
    QColor textColor( property()->color( "graphTextFontColor" ) );
    QPen textPen( textColor );

    // How many colors are requested?
    QString colorName( property()->color( "graphBarColor" ) );
    int colors = 1;
    if ( colorName == "rainbow" )
    {
        colors = property()->integer( "graphRainbowColors" );
    }
    // Allocate number of requested colors.
    QColor *color = new QColor [colors];
    checkmem( __FILE__, __LINE__, color, "QColor color", colors );
    int colorId = 0;
    // If only 1 color...
    if ( colors == 1 )
    {
        color[0].setNamedColor( colorName );
    }
    // else if rainbow colors are requested.
    else
    {
        // \todo - add some code to check conflicts with graphBackgroundColor
        // and graphGridColor (if graphGridWidth > 0 ).
        int hue = 0;
        for ( colorId = 0;
              colorId < colors;
              colorId++ )
        {
            color[colorId].setHsv( hue, 255, 255);
            hue += 360 / colors;
        }
        colorId = 0;
    }
    // Setup bar brush and color
    QBrush barBrush( color[colorId], Qt::SolidPattern );

    //--------------------------------------------------------------------------
    // 2: Create the graph and its text and axles.
    //--------------------------------------------------------------------------

    // Initialize graph and variables
    Graph g;
    int bars  = ( tableRows() < graphMaxBars )
              ? tableRows()
              : graphMaxBars ;
    int vStep = tableVars();

    // Draw thew basic graph (axis and text)
    composeGraphBasics( &g, false, xVar, yVar, 0, bars, xParms, yParms );

    //--------------------------------------------------------------------------
    // 3: Add the bars.
    //--------------------------------------------------------------------------

    // Each bar occupies 2/3 of its x range, plus a 1/3 padding on right.
    double xMin = xParms->m_axleMin;
    double xMax = xParms->m_axleMax;
    double xMinorStep = ( xMax - xMin ) / (double) ( 3 * bars + 1 );
    double xMajorStep = 3. * xMinorStep;

    // Create each data bar and add it to the graph.
    double x0, x1, y0, y1, xl;
    double yl = 0.;
    double rotation = 0.;
    QString label;
    int row, vid;
    for ( row = 0, vid = yid;
          row < bars;
          row++, vid += vStep )
    {
        x0 = xMin + xMinorStep + row * xMajorStep;
        x1 = xMin + ( row + 1 ) * xMajorStep;
        y0 = yParms->m_axleMin;
        y1 = tableVal( vid );
        xl = 0.5 * (x0 + x1) ;

        // If we're out of colors, start over.
        if ( colorId >= colors )
        {
            colorId = 0;
        }

        // Set the bar brush to this color.
        barBrush.setColor( color[colorId++] );

        // Create the graph bar.
        GraphBar *bar = g.addGraphBar( x0, y0, x1, y1, barBrush, textPen );

        // Create the bar label.
        int iid = (int) tableRow( row );
        label = xVar->m_itemList->itemName( iid );
        bar->setGraphBarLabel( label, xl, yl, textFont, textColor, rotation );
    }

    //--------------------------------------------------------------------------
    // 4: Add an output page on which to draw the graph.
    //--------------------------------------------------------------------------

    // Create a separate page for this graph.
    QString text("");
    translate( text, "BpDocument:Graphs:By" );
    label = QString( "%1 %2 %3" )
        .arg( *(yVar->m_label) )
        .arg( text )
        .arg( *(xVar->m_label) );
    startNewPage( label, TocBarGraph );

    // This is how we save the graph and its composer.
    m_composer->graph( g,
        m_pageSize->m_marginLeft
            + m_pageSize->m_bodyWd * property()->real( "graphXOffset" ),
        m_pageSize->m_marginTop
            + m_pageSize->m_bodyHt * property()->real( "graphYOffset" ),
        m_pageSize->m_bodyWd * property()->real( "graphScaleWidth" ),
        m_pageSize->m_bodyHt * property()->real( "graphScaleHeight" )
    );

    // Be polite and stop the composer.
    m_composer->end();
    delete[] color;
    return;
}
Example #12
0
QString Piece::name() const {
  QString res = colorName() + '_';
  if (m_promoted)
    res += "p_";
  return res + typeName();
}
Example #13
0
QString Piece::colorName() const { return colorName(m_color); }
Example #14
0
void drawEgg(ShapeRect bounds, ShapeColor fillColor)
{
    char * colorName(ShapeColor colorName);
    printf("drawing an egg at (%d %d %d %d) in %s\n", bounds.x, bounds.y, bounds.width, bounds.height, colorName(fillColor));
}
Example #15
0
QVariant CurvesModel::data(const QModelIndex& index, int role) const
{
    SolvWidget* solv =  solvers->at(index.row());
    QwtPlotCurve * curve = solv->curve;
    QColor col = curve->pen().color();
    int bright = col.red() + 2*col.green() + col.blue();
    QwtSymbol::Style symSty;
    switch(index.column()) {
    case 0:// title
        switch(role) {
        case Qt::DisplayRole :
        case Qt::EditRole:
            return solv->getTitle();
        }
        break;
    case 1:// line color
        switch(role) {
        case Qt::BackgroundRole:
            return QBrush(col);
        case Qt::ForegroundRole:
            if(bright > 600 ) return QBrush(Qt::darkGray);
            return QBrush(Qt::white);
        case Qt::DisplayRole:
            return QVariant(colorName(col));
        case Qt::EditRole:
        case Qt::UserRole:
            return QVariant(col);
        }
        break;
    case 2:// line style
        switch(role) {
        case Qt::DecorationRole:
            return penIcon(solv->curve->pen());
        case Qt::DisplayRole :
            return penStyles[solv->curve->pen().style()];
        case Qt::EditRole :
            return solv->curve->pen().style();
        }
        break;
    case 3:// line width
        switch(role) {
        case Qt::DecorationRole:
            return penIcon(solv->curve->pen());
        case Qt::DisplayRole :
            return QString("%1").arg(solv->curve->pen().widthF(),4,'f',2);
        case Qt::EditRole :
            return solv->curve->pen().widthF();
        }
        break;
    case 4:// symbol style
        if(curve->symbol() == NULL) {
            symSty = QwtSymbol::NoSymbol;
        } else {
            symSty = curve->symbol()->style();
        }
        switch(role) {
        case Qt::EditRole :
            return QVariant(symSty);
        case Qt::DisplayRole :
            return SymbolStyleDelegate::symName(symSty);
        }
        break;
    case 5:// symbol color
        if(curve->symbol() != NULL && curve->symbol()->style() != QwtSymbol::NoSymbol) {
            col= curve->symbol()->pen().color();
        } // default to curve pen color
        switch(role) {
        case Qt::BackgroundRole:
            return QBrush(col);
        case Qt::ForegroundRole:
            if(bright > 600 ) return QBrush(Qt::darkGray);
            return QBrush(Qt::white);
        case Qt::DisplayRole :
            if(curve->symbol() == NULL || curve->symbol()->style() == QwtSymbol::NoSymbol) {
                return ("No Symbol");
            }
            return QVariant(colorName(col)) ;
        case Qt::EditRole:
        case Qt::UserRole:
            return QVariant(col);
        }
        break;
    case 6: // symbol size
        switch(role) {
            //case Qt::DecorationRole:
            //return penIcon(solv->curve->pen());
        case Qt::DisplayRole :
	  if(curve->symbol() != NULL && curve->symbol()->style() != QwtSymbol::NoSymbol ) {
            return QString("%1").arg(curve->symbol()->size().width());
	  }
	  break;
        case Qt::EditRole :
        case Qt::UserRole:
	  if(curve->symbol() != NULL && curve->symbol()->style() != QwtSymbol::NoSymbol ) {
            return curve->symbol()->size().width();
	  }
	  return 7;
        }
    }
    return QVariant();
}