Beispiel #1
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;
}
Beispiel #2
0
void
KPaletteTable::addToRecentColors( const TQColor &color)
{
  //
  // 2000-02-12 Espen Sand.
  // The 'mPalette' is always 0 when current mode is i18n_namedColors
  //
  bool recentIsSelected = false;
  if ( mPalette && mPalette->name() == colorPaletteName[ recentColorIndex ].m_fileName )
  {
     delete mPalette;
     mPalette = 0;
     recentIsSelected = true;
  }
  KPalette *recentPal = new KPalette( colorPaletteName[ recentColorIndex ].m_fileName );
  if (recentPal->findColor(color) == -1)
  {
     recentPal->addColor( color );
     recentPal->save();
  }
  delete recentPal;
  if (recentIsSelected)
      setPalette( i18n( "palette name", colorPaletteName[ recentColorIndex ].m_displayName ) );
}
Beispiel #3
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);
       }
    }
}