Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'KColorCombo (./kdelibs/kdeui/kcolordlg.h:380)
class KColorCombo : public QComboBox
{
Q_OBJECT
public:
KColorCombo( QWidget *parent, const char *name = 0L );
void setColor( const QColor &col );
public slots:
void slotActivated( int index );
void slotHighlighted( int index );
signals:
void activated( const QColor &col );
void highlighted( const QColor &col );
protected:
virtual void resizeEvent( QResizeEvent *re );
private:
void addColors();
QColor customColor;
QColor color;
class KColorComboPrivate;
KColorComboPrivate *d;
};
kdelibs'KColorCombo::KColorCombo() (./kdelibs/kdeui/kcolordlg.cpp:1218)
KColorCombo::KColorCombo( QWidget *parent, const char *name )
: QComboBox( parent, name )
{
customColor.setRgb( 255, 255, 255 );
color.setRgb( 255, 255, 255 );
createStandardPalette();
addColors();
connect( this, SIGNAL( activated(int) ), SLOT( slotActivated(int) ) );
connect( this, SIGNAL( highlighted(int) ), SLOT( slotHighlighted(int) ) );
}
kdelibs'KColorCombo::setColor() (./kdelibs/kdeui/kcolordlg.cpp:1232)
void KColorCombo::setColor( const QColor &col )
{
color = col;
addColors();
}
kdelibs'KColorCombo::resizeEvent() (./kdelibs/kdeui/kcolordlg.cpp:1239)
void KColorCombo::resizeEvent( QResizeEvent *re )
{
QComboBox::resizeEvent( re );
addColors();
}
kdelibs'KColorCombo::slotActivated() (./kdelibs/kdeui/kcolordlg.cpp:1246)
void KColorCombo::slotActivated( int index )
{
if ( index == 0 )
{
if ( KColorDialog::getColor( customColor ) == QDialog::Accepted )
{
QRect rect( 0, 0, width(), 20 );
QPixmap pixmap( rect.width(), rect.height() );
QPainter painter;
QPen pen;
if ( qGray( customColor.rgb() ) < 128 )
pen.setColor( white );
else
pen.setColor( black );
painter.begin( &pixmap );
QBrush brush( customColor );
painter.fillRect( rect, brush );
painter.setPen( pen );
painter.drawText( 2, 18,
i18n("Custom...") );
painter.end();
changeItem( pixmap, 0 );
pixmap.detach();
}
color = customColor;
}
else
color = standardPalette[ index - 1 ];
emit activated( color );
}
kdelibs'KColorCombo::slotHighlighted() (./kdelibs/kdeui/kcolordlg.cpp:1282)
void KColorCombo::slotHighlighted( int index )
{
if ( index == 0 )
color = customColor;
else
color = standardPalette[ index - 1 ];
emit highlighted( color );
}
kdelibs'KColorCombo::addColors() (./kdelibs/kdeui/kcolordlg.cpp:1292)
void KColorCombo::addColors()
{
QRect rect( 0, 0, width(), 20 );
QPixmap pixmap( rect.width(), rect.height() );
QPainter painter;
QPen pen;
int i;
clear();
createStandardPalette();
for ( i = 0; i < STANDARD_PAL_SIZE; i++ )
if ( standardPalette[i] == color ) break;
if ( i == STANDARD_PAL_SIZE )
customColor = color;
if ( qGray( customColor.rgb() ) < 128 )
pen.setColor( white );
else
pen.setColor( black );
painter.begin( &pixmap );
QBrush brush( customColor );
painter.fillRect( rect, brush );
painter.setPen( pen );
painter.drawText( 2, 18, i18n("Custom...") );
painter.end();
insertItem( pixmap );
pixmap.detach();
for ( i = 0; i < STANDARD_PAL_SIZE; i++ )
{
painter.begin( &pixmap );
QBrush brush( standardPalette[i] );
painter.fillRect( rect, brush );
painter.end();
insertItem( pixmap );
pixmap.detach();
if ( standardPalette[i] == color )
setCurrentItem( i + 1 );
}
}