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

Class Index

kghostview'MarkListTable (./kdegraphics/kghostview/marklist.h:34)

class MarkListTable: public QTableView
{
	Q_OBJECT

public:
	MarkListTable( QWidget * parent = 0, const char * name = 0 );
	~MarkListTable() { }
	QStrList *	markList();
	void	insertItem ( const char *text, int index=-1);
	void	setAutoUpdate ( bool enable );
	void	clear();
	int	rowHeight();
	const char *text( int index );
	
	QColor selectColor;
	QColor selectTextColor;

public slots:
	void	select(int);
	void	markSelected();
	void	markAll();
	void	markEven();
	void	markOdd();
	void	toggleMarks();
	void	removeMarks();

signals:
	void	selected( int index );
	void	selected( const char * text );

protected:
	void	mousePressEvent ( QMouseEvent* );
	void	mouseReleaseEvent ( QMouseEvent* ) {}
	void	mouseMoveEvent ( QMouseEvent* );
	void	paintCell( QPainter *p, int row, int col );
	int	cellWidth( int );
	void	updateItem( int i );
	

private:
	void	changeMarks( int, int = 0 );
        void    initPixmaps();
	QPoint	mouse;
	int	sel;
	QPopupMenu* pup;
	int	drag;
	QList<MarkListTableItem> items;
        QPixmap *flagPixmap, *bulletPixmap;
};


kghostview'MarkListTable::MarkListTable() (./kdegraphics/kghostview/marklist.cpp:30)

MarkListTable::MarkListTable( QWidget * parent , const char * name )
        : QTableView( parent, name ), sel(-1), drag(-1), items()
{
        setFrameStyle( Panel | Sunken );
        setTableFlags( Tbl_autoVScrollBar | Tbl_snapToVGrid | 
                       Tbl_clipCellPainting);
        setLineWidth( 1 );
        setCellHeight( fontMetrics().lineSpacing()+4 );
        setNumCols( 2 );
        
        pup = new QPopupMenu(0, "pup");
        pup->insertItem( i18n("Mark current page"), this, SLOT(markSelected()) );
        pup->insertItem( i18n("Mark all pages"), this, SLOT(markAll()) );
        pup->insertItem( i18n("Mark even pages"), this, SLOT(markEven()) );
        pup->insertItem( i18n("Mark odd pages"), this, SLOT(markOdd()) );
        pup->insertItem( i18n("Toggle page marks"), this, SLOT(toggleMarks()) );
        pup->insertItem( i18n("Remove page marks"), this, SLOT(removeMarks()) );
        
        selectColor = QColor( black );
        selectTextColor = QColor( white );
        
        initPixmaps();
}


kghostview'MarkListTable::initPixmaps() (./kdegraphics/kghostview/marklist.cpp:54)

void MarkListTable::initPixmaps() 
{
        QColorGroup cg = QApplication::palette().normal();
  
        int w = cellWidth(0);
        int h = cellHeight(0);
        int xOffset, yOffset;
        
        flagPixmap = new QPixmap(w, h);
        bulletPixmap =new QPixmap(w, h);
        
        QPainter p;
        QBrush brush(cg.base());
        
        p.begin( flagPixmap );
        
        xOffset=6;
        yOffset=3;
        
        p.fillRect(0, 0, w, h, brush); 
        p.drawLine( xOffset+4, yOffset, xOffset+4, yOffset+9 );
        p.setPen( red );
        p.drawLine( xOffset+3, yOffset+1, xOffset, yOffset+4 );
        p.drawLine( xOffset+3, yOffset+1, xOffset+3, yOffset+4 );
        p.drawLine( xOffset, yOffset+4, xOffset+3, yOffset+4 );
        
        p.end();
        
        p.begin( bulletPixmap );
        
        xOffset=4; 
        yOffset=5;        
        
        p.fillRect(0, 0, w, h, brush); 
        p.setPen( cg.dark() );
        p.setBrush( cg.dark() );
        p.drawEllipse( xOffset+4, yOffset, 4, 4 );
        p.setPen( white );
        p.drawPoint( xOffset+5, yOffset+1);
        
        p.end();
}



kghostview'MarkListTable::insertItem() (./kdegraphics/kghostview/marklist.cpp:98)

void	MarkListTable::insertItem ( const char *text, int index)
{
        MarkListTableItem *mli = new MarkListTableItem( text );
	items.insert( index, mli );
	setNumRows( items.count() );
}


kghostview'MarkListTable::setAutoUpdate() (./kdegraphics/kghostview/marklist.cpp:105)

void MarkListTable::setAutoUpdate ( bool enable)
{
	QTableView::setAutoUpdate( enable );
	if (enable) 
          repaint();
}


kghostview'MarkListTable::clear() (./kdegraphics/kghostview/marklist.cpp:112)

void MarkListTable::clear()
{
	QColorGroup cg = QApplication::palette().normal();
	if( backgroundColor() != cg.base() )
		setBackgroundColor(cg.base());
	items.clear();
	sel = -1;
	update();
}


kghostview'MarkListTable::cellWidth() (./kdegraphics/kghostview/marklist.cpp:122)

int MarkListTable::cellWidth( int col )
{
	if( col==0 )
		return FLAG_WIDTH;
	else
		return width()-FLAG_WIDTH-2*frameWidth();
}


kghostview'MarkListTable::paintCell() (./kdegraphics/kghostview/marklist.cpp:130)

void MarkListTable::paintCell( QPainter *p, int row, int col)
{
	QColorGroup cg = QApplication::palette().normal();
        
	if ( col == 0  ) {
                if( items.at( row )->mark() ) 
                        p->drawPixmap(0, 0, *flagPixmap);
                else
                        p->drawPixmap(0, 0, *bulletPixmap);
        }
        
        if ( col == 1 ) {
                int w = cellWidth( col );
                int h = cellHeight( row );
                QBrush brush(items.at(row)->select() ? selectColor : cg.base());
                
                p->fillRect(0, 0, w, h, brush);                      
                
                if ( items.at( row )->select() )
                        p->setPen(selectTextColor);
                else
                        p->setPen(cg.text());
                
                p->drawText( 0, 0, w, h, AlignCenter, items.at( row )->text() );
        }
}


kghostview'MarkListTable::mousePressEvent() (./kdegraphics/kghostview/marklist.cpp:157)

void MarkListTable::mousePressEvent ( QMouseEvent *e )
{
        int i = findRow( e->pos().y() );
	int c = findCol(e->pos().x());
        if ( i == -1 )
                return;
        MarkListTableItem *it = items.at( i );

	if ( e->button() == LeftButton )
	  {
	    switch (c)
	      {
	      case 0: //flags
		it->setMark( !it->mark() );
		updateCell( i, 0 );
		drag = i;
		break;
	      case 1: //page numbers
		select( i );
		break;
	      }
	  }
	else
	  if ( e->button() == RightButton )
	    pup->popup( mapToGlobal( e->pos() ) );
	  else
	    if ( e->button() == MidButton )
	      {
		it->setMark( !it->mark() );
		updateCell( i, 0 );
		drag = i;
	      }
}


kghostview'MarkListTable::mouseMoveEvent() (./kdegraphics/kghostview/marklist.cpp:191)

void MarkListTable::mouseMoveEvent ( QMouseEvent *e )
{
	if (e->state() != MidButton &&
	    e->state() != LeftButton)
		return;

	int i = findRow( e->pos().y() );
	if ( i == drag || i == -1 )
		return;
	do {
		drag += i > drag ? 1 : -1;
		items.at( drag )->setMark( !items.at( drag )->mark() );
		updateCell( drag, 0 );
	} while ( i != drag );
}


kghostview'MarkListTable::text() (./kdegraphics/kghostview/marklist.cpp:207)

const char * MarkListTable::text( int index )
{
	if( index < 0 || index > (int) items.count() ) {
		printf("MarkList: Index out of range");
		return 0;
	}
        
	MarkListTableItem *it = items.at( index );
	return it->text();
}


kghostview'MarkListTable::select() (./kdegraphics/kghostview/marklist.cpp:218)

void MarkListTable::select( int i )
{
	if ( i < 0 || i >= (signed) items.count() || i == sel )
		return ;
        
	MarkListTableItem *it = items.at( i );
	if ( sel != -1 )
	  {
	    items.at( sel )->setSelect( FALSE );
	    updateCell( sel, 0 );
	    updateCell( sel, 1 );
	}
	it->setSelect( TRUE );
	sel = i;
	updateCell( i, 0 );
	updateCell( i, 1 );
	emit selected( i );
	emit selected( it->text() );
	if ( ( i<=0 || rowIsVisible( i-1 ) ) &&
	     ( i>= (signed) items.count()-1 || rowIsVisible( i+1 ) ) )
		return;
	setTopCell( QMAX( 0, i - viewHeight()/cellHeight()/2 ) );
}


kghostview'MarkListTable::markSelected() (./kdegraphics/kghostview/marklist.cpp:242)

void MarkListTable::markSelected()
{
	if ( sel == -1 )
		return;
	MarkListTableItem *it = items.at( sel );
	it->setMark( ! it->mark() );
	updateCell( sel, 0 );
}


kghostview'MarkListTable::markAll() (./kdegraphics/kghostview/marklist.cpp:251)

void MarkListTable::markAll()
{
	changeMarks( 1 );
}


kghostview'MarkListTable::markEven() (./kdegraphics/kghostview/marklist.cpp:256)

void MarkListTable::markEven()
{
	changeMarks( 1, 2 );
}


kghostview'MarkListTable::markOdd() (./kdegraphics/kghostview/marklist.cpp:261)

void MarkListTable::markOdd()
{
	changeMarks( 1, 1 );
}



kghostview'MarkListTable::removeMarks() (./kdegraphics/kghostview/marklist.cpp:267)

void MarkListTable::removeMarks()
{
	changeMarks( 0 );
}


kghostview'MarkListTable::toggleMarks() (./kdegraphics/kghostview/marklist.cpp:272)

void MarkListTable::toggleMarks()
{
	changeMarks( 2 );
}


kghostview'MarkListTable::rowHeight() (./kdegraphics/kghostview/marklist.cpp:277)

int MarkListTable::rowHeight()
{
	return cellHeight();
}


kghostview'MarkListTable::changeMarks() (./kdegraphics/kghostview/marklist.cpp:282)

void MarkListTable::changeMarks( int how, int which  )
{
	MarkListTableItem *it;
	QString t;

	setUpdatesEnabled( FALSE );
	for ( int i=items.count(); i-->0 ; )
	{
		if ( which )
		{
			t = items.at( i )->text();
			if ( t.toInt() % 2 == which - 1 )
				continue;
		}
		it = items.at( i );
		if ( how == 2 )
			it->setMark( ! it->mark() );
		else	it->setMark( how );
		updateCell( i, 0 );
	}
	setUpdatesEnabled( TRUE );
        repaint();
}


kghostview'MarkListTable::markList() (./kdegraphics/kghostview/marklist.cpp:306)

QStrList *MarkListTable::markList()
{
	QStrList *l = new QStrList;

	for ( int i=0 ; i < (signed) items.count(); i++ )
		if ( ( items.at( i ) )->mark() )
			l->append( items.at( i )->text() );
	return l;
}

//------------------------------------------------------------------