Source Code (Use browser search to find items of interest.)

Class Index

kdelibs'KCharSelect (./kdelibs/kdeui/kcharselect.h:128)

class KCharSelect : public QVBox
{
    Q_OBJECT

public:
    /** 
     * Constructor. @p font specifies which font should be displayed, @p
     * chr which character should be selected and @tableNum specifies
     * the number of the table which should be displayed.
     */
    KCharSelect( QWidget *parent, const char *name, 
		 const QString &font = QString::null, const QChar &chr = ' ', int tableNum = 0 );
    /**
     * Reimplemented.
     */
    virtual QSize sizeHint() const;

    /**
     * Sets the font which is displayed to @p font
     */
    virtual void setFont( const QString &font );
    
    /**
     * Sets the currently selected character to @p chr.
     */
    virtual void setChar( const QChar &chr );
    
    /**
     * Sets the currently displayed table to @p tableNum.
     */
    virtual void setTableNum( int tableNum );

    /**
     * Returns the currently selected chafacter.
     */
    virtual QChar chr() { return charTable->chr(); }

    /**
     * Returns the currently displayed font.
     */
    virtual QString font() { return fontCombo->currentText(); }

    /**
     * Returns the currently displayed table
     */
    virtual int tableNum() { return tableSpinBox->value(); }

    /**
     * If @p e is set to TRUE, the combobox which allows the user to
     * select the font which should be displayed is enabled, else
     * disabled.
     */
    virtual void enableFontCombo( bool e ) { fontCombo->setEnabled( e ); }
    
    /**

     * If @p e is set to TRUE, the spinbox which allows the user to
     * specify which characters of the font should be displayed, is
     * enabled, else disabled.
     */
    virtual void enableTableSpinBox( bool e ) { tableSpinBox->setEnabled( e ); }

    /**
     * Returns wether the font combobox on the top is enabled or
     * disabled.
     *
     * @see enableFontCombo()
     */
    virtual bool isFontComboEnabled() { return fontCombo->isEnabled(); }

    /**
     * Returns wether the table spinbox on the top is enabled or
     * disabled.
     *
     * @see enableTableSpinBox()
     */
    virtual bool isTableSpinBoxEnabled() { return tableSpinBox->isEnabled(); }

protected:
    virtual void fillFontCombo();
    static void cleanupFontDatabase();

    QComboBox *fontCombo;
    QSpinBox *tableSpinBox;
    KCharSelectTable *charTable;
    QStringList fontList;
    static QFontDatabase * fontDataBase;

protected slots:
    void fontSelected( const QString &_font );
    void tableChanged( int _value );
    void charHighlighted( const QChar &c ) { emit highlighted( c ); }
    void charHighlighted() { emit highlighted(); }
    void charActivated( const QChar &c ) { emit activated( c ); }
    void charActivated() { emit activated(); }
    void charFocusItemChanged() { emit focusItemChanged(); }
    void charFocusItemChanged( const QChar &c ) { emit focusItemChanged( c ); }
    void charTableUp() { if ( tableNum() < 255 ) setTableNum( tableNum() + 1 ); }
    void charTableDown() { if ( tableNum() > 0 ) setTableNum( tableNum() - 1 ); }

signals:
    void highlighted( const QChar &c );
    void highlighted();
    void activated( const QChar &c );
    void activated();
    void fontChanged( const QString &_font );
    void focusItemChanged();
    void focusItemChanged( const QChar &c );

private:
    KCharSelectPrivate *d;
};

kdelibs'KCharSelect::cleanupFontDatabase() (./kdelibs/kdeui/kcharselect.cpp:41)

void KCharSelect::cleanupFontDatabase()
{
    delete fontDataBase;
    fontDataBase = 0;
}

/******************************************************************/
/* Class: KCharSelectTable					  */
/******************************************************************/

//==================================================================

kdelibs'KCharSelect::KCharSelect() (./kdelibs/kdeui/kcharselect.cpp:295)

KCharSelect::KCharSelect( QWidget *parent, const char *name, const QString &_font, const QChar &_chr, int _tableNum )
    : QVBox( parent, name )
{
    setSpacing( KDialog::spacingHint() );
    setMargin( KDialog::marginHint() );
    QHBox *bar = new QHBox( this );
    bar->setSpacing( KDialog::spacingHint() );

    QLabel *lFont = new QLabel( i18n( "	 Font:	" ), bar );
    lFont->resize( lFont->sizeHint() );
    lFont->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
    lFont->setMaximumWidth( lFont->sizeHint().width() );

    fontCombo = new QComboBox( true, bar );
    fillFontCombo();
    fontCombo->resize( fontCombo->sizeHint() );

    connect( fontCombo, SIGNAL( activated( const QString & ) ), this, SLOT( fontSelected( const QString & ) ) );

    QLabel *lTable = new QLabel( i18n( "  Table:  " ), bar );
    lTable->resize( lTable->sizeHint() );
    lTable->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
    lTable->setMaximumWidth( lTable->sizeHint().width() );

    tableSpinBox = new QSpinBox( 0, 255, 1, bar );
    tableSpinBox->resize( tableSpinBox->sizeHint() );

    connect( tableSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( tableChanged( int ) ) );

    charTable = new KCharSelectTable( this, name, _font.isEmpty() ? QVBox::font().family() : _font, _chr, _tableNum );
    charTable->resize( charTable->sizeHint() );
    charTable->setMaximumSize( charTable->size() );
    charTable->setMinimumSize( charTable->size() );

    setFont( _font.isEmpty() ? QVBox::font().family() : _font );
    setTableNum( _tableNum );

    connect( charTable, SIGNAL( highlighted( const QChar & ) ), this, SLOT( charHighlighted( const QChar & ) ) );
    connect( charTable, SIGNAL( highlighted() ), this, SLOT( charHighlighted() ) );
    connect( charTable, SIGNAL( activated( const QChar & ) ), this, SLOT( charActivated( const QChar & ) ) );
    connect( charTable, SIGNAL( activated() ), this, SLOT( charActivated() ) );
    connect( charTable, SIGNAL( focusItemChanged( const QChar & ) ),
	     this, SLOT( charFocusItemChanged( const QChar & ) ) );
    connect( charTable, SIGNAL( focusItemChanged() ), this, SLOT( charFocusItemChanged() ) );
    connect( charTable, SIGNAL( tableUp() ), this, SLOT( charTableUp() ) );
    connect( charTable, SIGNAL( tableDown() ), this, SLOT( charTableDown() ) );

    setFocusPolicy( QWidget::StrongFocus );
    setFocusProxy( charTable );
}

//==================================================================

kdelibs'KCharSelect::sizeHint() (./kdelibs/kdeui/kcharselect.cpp:347)

QSize KCharSelect::sizeHint() const
{
    return QVBox::sizeHint();
}

//==================================================================

kdelibs'KCharSelect::setFont() (./kdelibs/kdeui/kcharselect.cpp:353)

void KCharSelect::setFont( const QString &_font )
{
    QValueList<QString>::Iterator it = fontList.find( _font );

    if ( it != fontList.end() ) {
	QValueList<QString>::Iterator it2 = fontList.begin();
	int pos = 0;
	for ( ; it != it2; ++it2, ++pos);
	fontCombo->setCurrentItem( pos );
	charTable->setFont( _font );
    }
    else
	warning( "Can't find Font: %s", _font.latin1() );
}

//==================================================================

kdelibs'KCharSelect::setChar() (./kdelibs/kdeui/kcharselect.cpp:369)

void KCharSelect::setChar( const QChar &_chr )
{
    charTable->setChar( _chr );
}

//==================================================================

kdelibs'KCharSelect::setTableNum() (./kdelibs/kdeui/kcharselect.cpp:375)

void KCharSelect::setTableNum( int _tableNum )
{
    tableSpinBox->setValue( _tableNum );
    charTable->setTableNum( _tableNum );
}

//==================================================================

kdelibs'KCharSelect::fillFontCombo() (./kdelibs/kdeui/kcharselect.cpp:382)

void KCharSelect::fillFontCombo()
{
    if ( !fontDataBase ) {
	fontDataBase = new QFontDatabase();
	qAddPostRoutine( cleanupFontDatabase );
    }
    fontCombo->insertStringList( fontDataBase->families() );
}

//==================================================================

kdelibs'KCharSelect::fontSelected() (./kdelibs/kdeui/kcharselect.cpp:392)

void KCharSelect::fontSelected( const QString &_font )
{
    charTable->setFont( _font );
    emit fontChanged( _font );
}

//==================================================================

kdelibs'KCharSelect::tableChanged() (./kdelibs/kdeui/kcharselect.cpp:399)

void KCharSelect::tableChanged( int _value )
{
    charTable->setTableNum( _value );
}