void KColorTable::setColors(const QString &_collectionName) { QString collectionName(_collectionName); if (d->combo->currentText() != collectionName) { bool found = false; for (int i = 0; i < d->combo->count(); i++) { if (d->combo->itemText(i) == collectionName) { d->combo->setCurrentIndex(i); found = true; break; } } if (!found) { d->combo->addItem(collectionName); d->combo->setCurrentIndex(d->combo->count() - 1); } } // We must again find the file name of the palette from the eventual translation for (int i = 0; colorCollectionName[i].m_fileName; ++i) { if (collectionName == tr(colorCollectionName[i].m_displayName)) { collectionName = colorCollectionName[i].m_fileName; break; } } // // 2000-02-12 Espen Sand // The palette mode "i18n_namedColors" does not use the KColorCollection // class. In fact, 'mPalette' and 'cells' are 0 when in this mode. The reason // for this is maninly that KColorCollection reads from and writes to files // using "locate()". The colors used in "i18n_namedColors" mode comes from // the X11 diretory and is not writable. I don't think this fit in // KColorCollection. // if (!d->mPalette || d->mPalette->name() != collectionName) { if (collectionName == d->i18n_namedColors) { d->sv->hide(); d->mNamedColorList->show(); readNamedColor(); delete d->cells; d->cells = 0; delete d->mPalette; d->mPalette = 0; } else { d->mNamedColorList->hide(); d->sv->show(); delete d->cells; delete d->mPalette; d->mPalette = new KColorCollection(collectionName); int rows = (d->mPalette->count() + d->mCols - 1) / d->mCols; if (rows < 1) rows = 1; d->cells = new KColorCells(d->sv->viewport(), rows, d->mCols); d->cells->setShading(false); d->cells->setAcceptDrags(false); QSize cellSize = QSize(d->mMinWidth, d->mMinWidth * rows / d->mCols); d->cells->setFixedSize(cellSize); for (int i = 0; i < d->mPalette->count(); i++) { d->cells->setColor(i, d->mPalette->color(i)); } connect(d->cells, SIGNAL(colorSelected(int , const QColor&)), SLOT(slotColorCellSelected(int , const QColor&))); connect(d->cells, SIGNAL(colorDoubleClicked(int , const QColor&)), SLOT(slotColorCellDoubleClicked(int , const QColor&))); d->sv->setWidget(d->cells); d->cells->show(); //d->sv->updateScrollBars(); } } }
void KPaletteTable::setPalette( const TQString &_paletteName ) { TQString paletteName( _paletteName); if (paletteName.isEmpty()) paletteName = i18n_recentColors; if (combo->currentText() != paletteName) { bool found = false; for(int i = 0; i < combo->count(); i++) { if (combo->text(i) == paletteName) { combo->setCurrentItem(i); found = true; break; } } if (!found) { combo->insertItem(paletteName); combo->setCurrentItem(combo->count()-1); } } // We must again find the file name of the palette from the eventual translation for ( int i = 0; colorPaletteName[i].m_fileName; ++i ) { if ( paletteName == i18n( "palette name", colorPaletteName[i].m_displayName ) ) { paletteName = colorPaletteName[i].m_fileName; break; } } // // 2000-02-12 Espen Sand // The palette mode "i18n_namedColors" does not use the KPalette class. // In fact, 'mPalette' and 'cells' are 0 when in this mode. The reason // for this is maninly that KPalette reads from and writes to files using // "locate()". The colors used in "i18n_namedColors" mode comes from the // X11 diretory and is not writable. I don't think this fit in KPalette. // if( !mPalette || mPalette->name() != paletteName ) { if( paletteName == i18n_namedColors ) { sv->hide(); mNamedColorList->show(); readNamedColor(); delete cells; cells = 0; delete mPalette; mPalette = 0; } else { mNamedColorList->hide(); sv->show(); delete cells; delete mPalette; mPalette = new KPalette(paletteName); int rows = (mPalette->nrColors()+mCols-1) / mCols; if (rows < 1) rows = 1; cells = new KColorCells( sv->viewport(), rows, mCols); cells->setShading(false); cells->setAcceptDrags(false); TQSize cellSize = TQSize( mMinWidth, mMinWidth * rows / mCols); cells->setFixedSize( cellSize ); for( int i = 0; i < mPalette->nrColors(); i++) { cells->setColor( i, mPalette->color(i) ); } connect( cells, TQT_SIGNAL( colorSelected( int ) ), TQT_SLOT( slotColorCellSelected( int ) ) ); connect( cells, TQT_SIGNAL( colorDoubleClicked( int ) ), TQT_SLOT( slotColorCellDoubleClicked( int ) ) ); sv->addChild( cells ); cells->show(); sv->updateScrollBars(); } } }