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

Class Index

kdelibs'KCharSelectTable (./kdelibs/kdeui/kcharselect.h:49)

class KCharSelectTable : public QTableView
{
    Q_OBJECT

public:
    KCharSelectTable( QWidget *parent, const char *name, const QString &_font, 
		      const QChar &_chr, int _tableNum );

    virtual QSize sizeHint() const;

    virtual void setFont( const QString &_font );
    virtual void setChar( const QChar &_chr );
    virtual void setTableNum( int _tableNum );

    virtual QChar chr()
{ return vChr; }

protected:
    virtual void paintCell( class QPainter *p, int row, int col );

    virtual void mousePressEvent( QMouseEvent *e ) {  mouseMoveEvent( e ); }
    virtual void mouseReleaseEvent( QMouseEvent *e ) { mouseMoveEvent( e ); emit activated( chr() ); emit activated(); }
    virtual void mouseMoveEvent( QMouseEvent *e );

    virtual void keyPressEvent( QKeyEvent *e );

    void gotoLeft();
    void gotoRight();
    void gotoUp();
    void gotoDown();

    QString vFont;
    QChar vChr;
    int vTableNum;
    QPoint vPos;
    QChar focusItem;
    QPoint focusPos;

signals:
    void highlighted( const QChar &c );
    void highlighted();
    void activated( const QChar &c );
    void activated();
    void focusItemChanged();
    void focusItemChanged( const QChar &c );
    void tableUp();
    void tableDown();

private:
    KCharSelectTablePrivate *d;
};

/** 
 * A Widget which allows the user to select a character of a
 * specified font in a table
 *
 * You can specify the font whoes characters should be displayed via
 * @ref setFont(). Using @ref enableFontCombo() you can allow the
 * user to choose the font from a combob-box. As only 256 characters
 * are displayed at once in the table, using the spinbox on the top
 * the user can choose starting from which chracater the table
 * displayes them. This spinbox also can be enabled or disabled using
 * @ref enableTableSpinBox().
 *
 * KCharSelect supports keyboard and mouse navigation. Click+Move
 * selects always the character below the mouse cursor. Using the
 * arrow keys the focus mark is moved around and with pressing RETURN
 * or SPACE the cell which contains the focus mark gets selected.
 *
 * To get the current selected character, use the @ref chr()
 * method. You can set the character which should be displayed with
 * @ref setChar() and the table number which should be displayed with
 * @ref setTableNum().
 *
 * @short Character-Selection Widget
 * @version $Id: kcharselect.h,v 1.10 2000/04/02 09:54:15 reggie Exp $
 * @author Reginald Stadlbauer <reggie@kde.org>
 */


kdelibs'KCharSelectTable::KCharSelectTable() (./kdelibs/kdeui/kcharselect.cpp:52)

KCharSelectTable::KCharSelectTable( QWidget *parent, const char *name, const QString &_font,
				    const QChar &_chr, int _tableNum )
    : QTableView( parent, name ), vFont( _font ), vChr( _chr ),
      vTableNum( _tableNum ), vPos( 0, 0 ), focusItem( _chr ), focusPos( 0, 0 )
{
    setBackgroundColor( colorGroup().base() );

    setCellWidth( 20 );
    setCellHeight( 25 );

    setNumCols( 32 );
    setNumRows( 8 );

    repaint( true );

    setFocusPolicy( QWidget::StrongFocus );
    setBackgroundMode( QWidget::NoBackground );
}

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

kdelibs'KCharSelectTable::setFont() (./kdelibs/kdeui/kcharselect.cpp:72)

void KCharSelectTable::setFont( const QString &_font )
{
    vFont = _font;
    repaint( true );
}

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

kdelibs'KCharSelectTable::setChar() (./kdelibs/kdeui/kcharselect.cpp:79)

void KCharSelectTable::setChar( const QChar &_chr )
{
    vChr = _chr;
    repaint( true );
}

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

kdelibs'KCharSelectTable::setTableNum() (./kdelibs/kdeui/kcharselect.cpp:86)

void KCharSelectTable::setTableNum( int _tableNum )
{
    focusItem = QChar( _tableNum * 255 );

    vTableNum = _tableNum;
    repaint( true );
}

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

kdelibs'KCharSelectTable::sizeHint() (./kdelibs/kdeui/kcharselect.cpp:95)

QSize KCharSelectTable::sizeHint() const
{
    int w = cellWidth();
    int h = cellHeight();

    w *= numCols();
    h *= numRows();

    return QSize( w, h );
}

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

kdelibs'KCharSelectTable::paintCell() (./kdelibs/kdeui/kcharselect.cpp:107)

void KCharSelectTable::paintCell( class QPainter* p, int row, int col )
{
    int w = cellWidth( col );
    int h = cellHeight( row );
    int x2 = w - 1;
    int y2 = h - 1;

    unsigned short c = vTableNum * 255;
    c += row * numCols();
    c += col;

    if ( c == vChr.unicode() ) {
	p->setBrush( QBrush( colorGroup().highlight() ) );
	p->setPen( NoPen );
	p->drawRect( 0, 0, w, h );
	p->setPen( colorGroup().highlightedText() );
	vPos = QPoint( col, row );
    } else {
	p->setBrush( QBrush( colorGroup().base() ) );
	p->setPen( NoPen );
	p->drawRect( 0, 0, w, h );
	p->setPen( colorGroup().text() );
    }

    if ( c == focusItem.unicode() && hasFocus() ) {
	style().drawFocusRect( p, QRect( 2, 2, w - 4, h - 4 ), colorGroup() );
	focusPos = QPoint( col, row );
    }

    p->setFont( QFont( vFont ) );

    p->drawText( 0, 0, x2, y2, AlignHCenter | AlignVCenter, QString( QChar( c ) ) );

    p->setPen( colorGroup().text() );

    p->drawLine( x2, 0, x2, y2 );
    p->drawLine( 0, y2, x2, y2 );

    if ( row == 0 )
	p->drawLine( 0, 0, x2, 0 );
    if ( col == 0 )
	p->drawLine( 0, 0, 0, y2 );
}

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

kdelibs'KCharSelectTable::mouseMoveEvent() (./kdelibs/kdeui/kcharselect.cpp:152)

void KCharSelectTable::mouseMoveEvent( QMouseEvent *e )
{
    if ( findRow( e->y() ) != -1 && findCol( e->x() ) != -1 ) {
	QPoint oldPos = vPos;

	vPos.setX( findCol( e->x() ) );
	vPos.setY( findRow( e->y() ) );

	vChr = QChar( vTableNum * 255 + 32 * vPos.y() + vPos.x() );

	QPoint oldFocus = focusPos;

	focusPos = vPos;
	focusItem = vChr;

	updateCell( oldFocus.y(), oldFocus.x(), true );
	updateCell( oldPos.y(), oldPos.x(), true );
	updateCell( vPos.y(), vPos.x(), true );

	emit highlighted( vChr );
	emit highlighted();

	emit focusItemChanged( focusItem );
	emit focusItemChanged();
    }
}

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

kdelibs'KCharSelectTable::keyPressEvent() (./kdelibs/kdeui/kcharselect.cpp:180)

void KCharSelectTable::keyPressEvent( QKeyEvent *e )
{
    switch ( e->key() ) {
    case Key_Left:
	gotoLeft();
	break;
    case Key_Right:
	gotoRight();
	break;
    case Key_Up:
	gotoUp();
	break;
    case Key_Down:
	gotoDown();
	break;
    case Key_Next:
	emit tableDown();
	break;
    case Key_Prior:
	emit tableUp();
	break;
    case Key_Space: case Key_Enter: case Key_Return: {
	QPoint oldPos = vPos;

	vPos = focusPos;
	vChr = focusItem;

	updateCell( oldPos.y(), oldPos.x(), true );
	updateCell( vPos.y(), vPos.x(), true );

	emit activated( vChr );
	emit activated();
	emit highlighted( vChr );
	emit highlighted();
    } break;
    }
}

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

kdelibs'KCharSelectTable::gotoLeft() (./kdelibs/kdeui/kcharselect.cpp:219)

void KCharSelectTable::gotoLeft()
{
    if ( focusPos.x() > 0 ) {
	QPoint oldPos = focusPos;

	focusPos.setX( focusPos.x() - 1 );

	focusItem = QChar( vTableNum * 255 + 32 * focusPos.y() + focusPos.x() );

	updateCell( oldPos.y(), oldPos.x(), true );
	updateCell( focusPos.y(), focusPos.x(), true );

	emit focusItemChanged( vChr );
	emit focusItemChanged();
    }
}

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

kdelibs'KCharSelectTable::gotoRight() (./kdelibs/kdeui/kcharselect.cpp:237)

void KCharSelectTable::gotoRight()
{
    if ( focusPos.x() < 31 ) {
	QPoint oldPos = focusPos;

	focusPos.setX( focusPos.x() + 1 );

	focusItem = QChar( vTableNum * 255 + 32 * focusPos.y() + focusPos.x() );

	updateCell( oldPos.y(), oldPos.x(), true );
	updateCell( focusPos.y(), focusPos.x(), true );

	emit focusItemChanged( vChr );
	emit focusItemChanged();
    }
}

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

kdelibs'KCharSelectTable::gotoUp() (./kdelibs/kdeui/kcharselect.cpp:255)

void KCharSelectTable::gotoUp()
{
    if ( focusPos.y() > 0 ) {
	QPoint oldPos = focusPos;

	focusPos.setY( focusPos.y() - 1 );

	focusItem = QChar( vTableNum * 255 + 32 * focusPos.y() + focusPos.x() );

	updateCell( oldPos.y(), oldPos.x(), true );
	updateCell( focusPos.y(), focusPos.x(), true );

	emit focusItemChanged( vChr );
	emit focusItemChanged();
    }
}

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

kdelibs'KCharSelectTable::gotoDown() (./kdelibs/kdeui/kcharselect.cpp:273)

void KCharSelectTable::gotoDown()
{
    if ( focusPos.y() < 7 ) {
	QPoint oldPos = focusPos;

	focusPos.setY( focusPos.y() + 1 );

	focusItem = QChar( vTableNum * 255 + 32 * focusPos.y() + focusPos.x() );

	updateCell( oldPos.y(), oldPos.x(), true );
	updateCell( focusPos.y(), focusPos.x(), true );

	emit focusItemChanged( vChr );
	emit focusItemChanged();
    }
}

/******************************************************************/
/* Class: KCharSelect						  */
/******************************************************************/

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