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

Class Index

kuser'KRowTable (./kdeadmin/kuser/krowtable.h:24)

class KRowTable : public QTableView
{
	Q_OBJECT
protected:
	enum Flags {SelectRow, SelectCell, SelectFixed};

public:
	KRowTable( Flags aflags=SelectRow, QWidget *parent = 0, const char *name = 0 );
	KRowTable( int rows, int cols, Flags aflags=SelectRow, QWidget *parent = 0, const char *name = 0 );
	~KRowTable();

	KRow *selectedRow();
	void setNumCols( int cols );
	void setNumRows( int rows );
	void appendRow( KRow *cell );
	void insertRow( KRow *cell, int row );
	bool replaceRow( KRow *cell, int row );
	void setCurrentRow( int row, int col );
	void setHighlightColumn( int col );
	KRow *getRow( int row );
	void clear();
	void setAutoDelete( bool autodelete );
	bool autoDelete() const;
	void setCellWidth( int width );
	void setCellHeight( int height );
	void setSelectColumn( int col );
	int selectColumn();

protected:
	int cellWidth( int col );
	int cellHeight( int row );

	virtual void paintCell( QPainter *p, int row, int col );
	virtual void mousePressEvent( QMouseEvent *e );
	virtual void mouseDoubleClickEvent( QMouseEvent *e );
	virtual void keyPressEvent( QKeyEvent *e );
	virtual void focusInEvent( QFocusEvent *e );
	virtual void focusOutEvent( QFocusEvent *e );
	virtual void paletteChange( const QPalette &oldPalette );

signals:
	void selected(int row, int col);
	void highlighted(int row, int col);
	void hSliderMoved(int value);
	void vSliderMoved(int value);

public slots:
	void setColumnWidth(int col, int width);
	void setRowHeight(int row, int height);

private slots:
	void hSliderMovedSlot(int value);
	void vSliderMovedSlot(int value);

private:
	void init(Flags aflags);
	QArray<KRow *> m_rows;
	QArray<int> m_colWidths;
	QArray<int> m_rowHeights;
	bool autoDeleteFlag;
	int	current_col;
	int	current_row;
	int m_flags;
};

kuser'KRowTable::KRowTable() (./kdeadmin/kuser/krowtable.cpp:5)

KRowTable::KRowTable( Flags aflags, QWidget *parent, const char *name )
	: QTableView( parent, name ) {
	init(aflags);
}


kuser'KRowTable::KRowTable() (./kdeadmin/kuser/krowtable.cpp:10)

KRowTable::KRowTable( int rows, int cols, Flags aflags, QWidget *parent, const char *name )
	: QTableView( parent, name )
{
	init(aflags);
	setNumRows( rows );
	setNumCols( cols );
}


kuser'KRowTable::~KRowTable() (./kdeadmin/kuser/krowtable.cpp:18)

KRowTable::~KRowTable()
{
	clear();
}


kuser'KRowTable::init() (./kdeadmin/kuser/krowtable.cpp:23)

void KRowTable::init(Flags aflags)
{
	m_flags = aflags;
	current_row = -1;
	if( aflags == SelectRow )
		current_col = -1;
	else
		current_col = 0;

	setFrameStyle( WinPanel | Sunken );
	setBackgroundColor( colorGroup().base() );

	setCellWidth( 0 );
	setCellHeight( 0 );

	setAutoUpdate( TRUE );
    setFocusPolicy( StrongFocus );
    setTableFlags( Tbl_autoScrollBars |
                   Tbl_clipCellPainting |
                   Tbl_smoothScrolling);

	connect( (QObject*)horizontalScrollBar(), SIGNAL(sliderMoved(int)),
				SLOT(hSliderMovedSlot(int)) );
	connect( (QObject*)horizontalScrollBar(), SIGNAL(valueChanged(int)),
				SLOT(hSliderMovedSlot(int)) );

	connect( (QObject*)verticalScrollBar(), SIGNAL(sliderMoved(int)),
				SLOT(vSliderMovedSlot(int)) );
	connect( (QObject*)verticalScrollBar(), SIGNAL(valueChanged(int)),
				SLOT(vSliderMovedSlot(int)) );

	autoDeleteFlag = FALSE;
}


kuser'KRowTable::setCellWidth() (./kdeadmin/kuser/krowtable.cpp:57)

void KRowTable::setCellWidth( int width )
{
	QTableView::setCellWidth( width );
}


kuser'KRowTable::setCellHeight() (./kdeadmin/kuser/krowtable.cpp:62)

void KRowTable::setCellHeight( int height )
{
	QTableView::setCellHeight( height );
}


kuser'KRowTable::clear() (./kdeadmin/kuser/krowtable.cpp:67)

void KRowTable::clear()
{
	if( autoDelete() )
		for(int i=0 ; i<numRows() ; i++) {
			delete m_rows[i];
			m_rows[i] = 0;
		}
	if( autoUpdate() )
		repaint();
}


kuser'KRowTable::setAutoDelete() (./kdeadmin/kuser/krowtable.cpp:78)

void KRowTable::setAutoDelete( bool autodelete )
{
	autoDeleteFlag = autodelete;
}


kuser'KRowTable::autoDelete() (./kdeadmin/kuser/krowtable.cpp:83)

bool KRowTable::autoDelete() const
{
	return autoDeleteFlag;
}


kuser'KRowTable::setNumCols() (./kdeadmin/kuser/krowtable.cpp:88)

void KRowTable::setNumCols( int cols )
{
	int oldsize = m_colWidths.size();
	m_colWidths.resize( cols );
	for( int i=oldsize ; i<cols ; i++)
		m_colWidths[i] = 0;
	QTableView::setNumCols( cols );
}


kuser'KRowTable::setNumRows() (./kdeadmin/kuser/krowtable.cpp:97)

void KRowTable::setNumRows( int rows )
{
	int oldsize = m_rowHeights.size();
	m_rowHeights.resize( rows );
	m_rows.resize( rows );
	for( int i=oldsize ; i<rows ; i++) {
		m_rowHeights[i] = 0;
		m_rows[i] = 0;
	}
	QTableView::setNumRows( rows );
}


kuser'KRowTable::cellWidth() (./kdeadmin/kuser/krowtable.cpp:109)

int KRowTable::cellWidth( int col )
{
	int width = QTableView::cellWidth();
	if( width != 0 )
		return width;
	return m_colWidths[col];
}


kuser'KRowTable::setHighlightColumn() (./kdeadmin/kuser/krowtable.cpp:117)

void KRowTable::setHighlightColumn( int col )
{
	current_col = col;
	repaint();
}


kuser'KRowTable::setColumnWidth() (./kdeadmin/kuser/krowtable.cpp:123)

void KRowTable::setColumnWidth( int col, int width )
{
	m_colWidths[col] = width;
	resizeEvent(0);
	repaint();
}


kuser'KRowTable::cellHeight() (./kdeadmin/kuser/krowtable.cpp:130)

int KRowTable::cellHeight( int row )
{
	int height = QTableView::cellHeight();
	if( height != 0 )
		return height;
	return m_rowHeights[row];
}


kuser'KRowTable::setRowHeight() (./kdeadmin/kuser/krowtable.cpp:138)

void KRowTable::setRowHeight( int row, int height )
{
	m_rowHeights[row] = height;
	resizeEvent(0);
	repaint();
}


kuser'KRowTable::vSliderMovedSlot() (./kdeadmin/kuser/krowtable.cpp:145)

void KRowTable::vSliderMovedSlot(int value)
{
	emit(vSliderMoved(value));
}


kuser'KRowTable::hSliderMovedSlot() (./kdeadmin/kuser/krowtable.cpp:150)

void KRowTable::hSliderMovedSlot(int value)
{
	emit(hSliderMoved(value));
}


kuser'KRowTable::focusInEvent() (./kdeadmin/kuser/krowtable.cpp:155)

void KRowTable::focusInEvent( QFocusEvent * )
{
	if( current_row != -1 && current_col != -1 )
		updateCell( current_row, current_col, FALSE );
	else if( current_row != -1 ) {
		for( int i=0 ; i<numCols() ; i++ ) {
			updateCell( current_row, i, FALSE );
		}
	}
}


kuser'KRowTable::focusOutEvent() (./kdeadmin/kuser/krowtable.cpp:166)

void KRowTable::focusOutEvent( QFocusEvent * )
{
	if( current_row != -1 && current_col != -1 )
		updateCell( current_row, current_col, FALSE );
	else if( current_row != -1 ) {
		for( int i=0 ; i<numCols() ; i++ ) {
			updateCell( current_row, i, FALSE );
		}
	}
}


kuser'KRowTable::paletteChange() (./kdeadmin/kuser/krowtable.cpp:177)

void KRowTable::paletteChange( const QPalette & )
{
	setBackgroundColor( colorGroup().base() );
}


kuser'KRowTable::paintCell() (./kdeadmin/kuser/krowtable.cpp:182)

void KRowTable::paintCell( QPainter *p, int row, int col )
{
	QPen oldPen = p->pen();
	QColor oldBackground = p->backgroundColor();

	QColorGroup g = colorGroup();
	p->setBackgroundColor( g.base() );
	p->setPen( g.text() );

	if( current_row == row && 
		( current_col == col || current_col == -1 ) )
	{
		QColor fc;
		if( style() == WindowsStyle )
			fc = darkBlue;
		else
			fc = g.text();
		p->fillRect( 0, 0, cellWidth( col ), cellHeight( row ), fc );
		p->setPen( g.base() );
		p->setBackgroundColor( g.text() );
	}

	KRow *cell = getRow( row );
	if( cell != 0 )
		cell->paint( p, col, cellWidth(col) );

	if( current_row == row &&
	    ( current_col == col || current_col == -1 ) &&
		hasFocus() )
	{
		if( style() == WindowsStyle )
			p->drawWinFocusRect( 1, 1, cellWidth( col )-2, cellHeight( row )-2 );
		else
		{
			p->setPen( g.base() );
			p->setBrush( NoBrush );
			p->drawRect( 1, 1, cellWidth( col )-2, cellHeight( row )-2 );
		}
	}

	p->setPen( oldPen );
	p->setBackgroundColor( oldBackground );
}


kuser'KRowTable::selectedRow() (./kdeadmin/kuser/krowtable.cpp:226)

KRow *KRowTable::selectedRow()
{
	if( current_row == -1 )
		return 0;
	return getRow( current_row );
}


kuser'KRowTable::appendRow() (./kdeadmin/kuser/krowtable.cpp:233)

void KRowTable::appendRow( KRow *cell )
{
	setNumRows( numRows() + 1 );
	m_rows[numRows()-1] = cell;
	if( autoUpdate() )
		repaint();
}


kuser'KRowTable::insertRow() (./kdeadmin/kuser/krowtable.cpp:241)

void KRowTable::insertRow( KRow *cell, int row )
{
	if( row < 0 )
		row=0;

	if( row >= numRows() )
		setNumRows( row+1 );
        else {
	        setNumRows( numRows() + 1 );

		for( int i=numRows()-1 ; i>row ; i-- ) {
		        m_rowHeights[i] = m_rowHeights[i-1];
		        m_rows[i] = m_rows[i-1];
		}
	}
	m_rowHeights[row] = 0;
	m_rows[row] = cell;

	if( autoUpdate() )
		repaint();
}


kuser'KRowTable::replaceRow() (./kdeadmin/kuser/krowtable.cpp:263)

bool KRowTable::replaceRow( KRow *cell, int row )
{
	if( row < 0 || row >= numRows() )
		return FALSE;

	if( autoDelete() && m_rows[row] != 0 )
		delete m_rows[row];
	m_rows[row] = cell;

	if( autoUpdate() )
		repaint();

	return TRUE;
}


kuser'KRowTable::getRow() (./kdeadmin/kuser/krowtable.cpp:278)

KRow *KRowTable::getRow( int row )
{
	if( row >= numRows() )
		return 0;
	return m_rows[row];
}


kuser'KRowTable::mousePressEvent() (./kdeadmin/kuser/krowtable.cpp:285)

void KRowTable::mousePressEvent( QMouseEvent *e )
{
	if( m_flags & SelectCell )
		setCurrentRow( findRow( e->pos().y() ), findCol( e->pos().x() ) );
	else if( m_flags & SelectFixed )
		setCurrentRow( findRow( e->pos().y() ), current_col );
	else
		setCurrentRow( findRow( e->pos().y() ), -1 );
}


kuser'KRowTable::mouseDoubleClickEvent() (./kdeadmin/kuser/krowtable.cpp:295)

void KRowTable::mouseDoubleClickEvent( QMouseEvent * )
{
	if( m_flags == SelectRow ) {
		if( current_row != -1 )
			emit selected( current_row, current_col );
	} else {
		if( current_col != -1 && current_row != -1 )
			emit selected( current_row, current_col );
	}
	repaint();
}


kuser'KRowTable::setCurrentRow() (./kdeadmin/kuser/krowtable.cpp:307)

void KRowTable::setCurrentRow( int row, int col )
{
	int old_row = current_row;
	current_row = row;
	int old_col = current_col;
	current_col = col;
	updateCell( old_row, old_col );
	updateCell( current_row, current_col, FALSE );
	emit highlighted( current_row, current_col );
	repaint();
}


kuser'KRowTable::keyPressEvent() (./kdeadmin/kuser/krowtable.cpp:319)

void KRowTable::keyPressEvent( QKeyEvent *e )
{
	if( m_colWidths.size() == 0 )
		return;
	if( current_row == -1 )
		setCurrentRow( topCell(), current_col );

	int pageSize;

	switch( e->key() )
	{
	case Key_Up:
		if( current_row > 0 )
		{
			setCurrentRow( current_row-1, current_col );
			if( current_row < topCell() )
				setTopCell( current_row );
		}
		break;

	case Key_Down:
		if( current_row < numRows()-1 )
		{
			setCurrentRow( current_row + 1, current_col );
			if( current_row > lastRowVisible() )
				setTopCell( topCell() + current_row - lastRowVisible() );
		}
		break;

	case Key_Next:
		pageSize = lastRowVisible() - topCell();
		if( rowIsVisible( current_row ) )
			setTopCell( QMIN( topCell() + pageSize, numRows()-pageSize ) );
		else
			setTopCell( QMIN( current_row + pageSize, numRows()-pageSize ) );
		setCurrentRow( QMIN( current_row + pageSize, numRows()-1 ), current_col );
		break;

	case Key_Prior:
		pageSize = lastRowVisible() - topCell();
		if( rowIsVisible( current_row ) )
			setTopCell( QMAX( topCell() - pageSize, 0 ) );
		else
			setTopCell( QMAX( current_row - pageSize, 0 ) );
		setCurrentRow( QMAX( current_row - pageSize, 0 ), current_col );
		break;

	case Key_Return:
	case Key_Enter:
		if( current_row != -1 && current_col != -1 )
			emit selected( current_row, current_col );
		break;

	default:
		e->ignore();
		break;
	}
}


kuser'KRowTable::setSelectColumn() (./kdeadmin/kuser/krowtable.cpp:378)

void KRowTable::setSelectColumn( int col )
{
	if( m_flags == SelectRow )
		col = -1;
	current_col = col;
	repaint();
}


kuser'KRowTable::selectColumn() (./kdeadmin/kuser/krowtable.cpp:386)

int KRowTable::selectColumn()
{
	return current_col;
}