Exemple #1
0
int main( int argc, char **argv )
{
    TDEApplication a( argc, argv, "KPalettetest" );

    TQStringList palettes = KPalette::getPaletteList();
    for(TQStringList::ConstIterator it = palettes.begin(); 
	it != palettes.end(); it++) 
    {
       printf("Palette = %s\n", (*it).ascii());

       KPalette myPalette = KPalette(*it);
    
       printf("Palette Name = \"%s\"\n", myPalette.name().ascii());
       printf("Description:\n\"%s\"\n", myPalette.description().ascii());
       printf("Nr of Colors = %d\n", myPalette.nrColors());
       for(int i = 0; i < myPalette.nrColors(); i++)
       {
         int r,g,b;
         myPalette.color(i).rgb(&r, &g, &b);
         printf("#%d Name = \"%s\" #%02x%02x%02x\n", 
		i, myPalette.colorName(i).ascii(), r,g,b);
       }
    }
}
Exemple #2
0
void ColorPaletteWidget::updatePalette( const QString &palette) {
    KPalette* newPal = 0L;
    QColor color;
    int nrColors = 0;
    int height = _palette->height();
    int width = 7 * height;
    QPixmap pix(width, height);
    QPainter p(&pix);
    int size = 1;
    int step = 1;
    int pos = 0;
    int i;

    if (!palette.isEmpty()) {
        newPal = new KPalette(palette);
        nrColors = newPal->nrColors();
    }

    if (nrColors > 0) {
        size = width / nrColors;
        if (size == 0) {
            size = 1;
            step = nrColors / width;
        }
    }

    p.fillRect(p.window(), QColor("white"));
    for (i=0; i<nrColors; i+=step) {
        color = newPal->color(i);
        p.fillRect(pos*size, 0, size, height, QBrush(color));
        ++pos;
    }
    _paletteDisplay->setPixmap(pix);

    delete newPal;
}