Source Code (Use browser search to find items of interest.)
Class Index
kchart'SheetTable (./koffice/kchart/table.h:22)
class SheetTable : public QTableView
{
Q_OBJECT
public:
//SheetTable( QWidget *parent=0, const char *name=0 );
SheetTable( int cols, int rows, QWidget *parent=0, int flags = -1,
const char *name=0, bool _editable = true );
~SheetTable();
int tWidth() { return totalWidth() + extraW; }
int tHeight() { return totalHeight() + extraH; }
int numColsVisible() { return lastColVisible() - leftCell() + 1; }
int numRowsVisible() { return lastRowVisible() - topCell() + 1; }
void setText( int row, int col, QString, bool paint = TRUE );
bool hasValue(int,int);
public slots:
void showText( int row, int col, QString s) { setText( row, col, s); }
void nextInput();
void moveInput( int row, int col );
void makeVisible( int row, int col );
signals:
void selected( int row, int col );
void newText( int row, int col, QString );
void newRow(int);
void newCol(int);
void recalc();
//void recalc( int row, int col );
protected:
virtual void paintCell( QPainter *p, int row, int col );
virtual void mousePressEvent( QMouseEvent * );
protected slots:
void scrollHorz(int);
void scrollVert(int);
void setInputText(QString);
private:
int extraW;
int extraH;
QStrList table;
int index( int r, int c ) { return c+r*numCols(); }
QLineEdit *input;
int inRow;
int inCol;
void placeInput();
friend class Sheet; //###
bool editable;
};
kchart'SheetTable::SheetTable() (./koffice/kchart/table.cc:23)
SheetTable::SheetTable( int cols, int rows, QWidget *parent,
int flags, const char *name, bool _editable)
:QTableView(parent,name)
{
editable = _editable;
if ( flags < 0 )
setTableFlags( Tbl_clipCellPainting| Tbl_vScrollBar | Tbl_hScrollBar |
Tbl_snapToGrid| Tbl_cutCells );
else
setTableFlags( flags );
setNumRows(rows);
setNumCols(cols);
table = QStrList(true);
table.setAutoDelete(true);
for (int i = 0;i < rows*cols;i++)
table.append(0);
setCellWidth(100);
setCellHeight(30);
extraW = width() - viewWidth();
extraH = height() - viewHeight();
if (editable)
{
input = new QLineEdit(this);
input->setFrame(false);
input->resize( cellWidth()-2, cellHeight()-2 );
moveInput(0,0);
input->setFocus();
connect( input, SIGNAL(returnPressed()), this, SLOT(nextInput()) );
}
setBackgroundColor(colorGroup().base());
}
kchart'SheetTable::~SheetTable() (./koffice/kchart/table.cc:62)
SheetTable::~SheetTable()
{
//delete[] table;
}
kchart'SheetTable::setText() (./koffice/kchart/table.cc:68)
void SheetTable::setText( int row, int col, QString s, bool paint )
{
//table[index(row,col)].operator=( s.copy() );
table.remove(index(row,col));
table.insert(index(row,col),s);
int x,y;
if ( paint && rowYPos( row, &y ) && colXPos( col, &x ))
repaint( x,y, cellWidth(col), cellHeight(row));
if (row == inRow && col == inCol && editable)
input->setText(s);
}
kchart'SheetTable::hasValue() (./koffice/kchart/table.cc:80)
bool SheetTable::hasValue(int row,int col)
{
return !QString(table.at(index(row,col))).simplifyWhiteSpace().isEmpty();
}
kchart'SheetTable::placeInput() (./koffice/kchart/table.cc:85)
void SheetTable::placeInput()
{
// makeVisible( inRow, inCol );
int x,y;
if ( colXPos(inCol,&x) && rowYPos(inRow,&y) ) {
input->move(x+1,y+1);
input->show();
if (!input->hasFocus())
input->setFocus();
} else
input->hide();
}
kchart'SheetTable::paintCell() (./koffice/kchart/table.cc:98)
void SheetTable::paintCell( QPainter *p, int row, int col )
{
int w = cellWidth( col );
int h = cellHeight( row );
int x2 = w - 1;
int y2 = h - 1;
p->setPen(black);
p->drawLine( x2, 0, x2, y2 );
p->drawLine( 0, y2, x2, y2 );
if (row == topCell())
p->drawLine(0,0,x2,0);
if (col == leftCell())
p->drawLine(0,0,0,y2);
QString str;
if (!table.isEmpty())
//str = table[index(row,col)].copy();
str = table.at(index(row,col));
// if ( str.isEmpty() )
// str.sprintf( "%c%d", col+'A', row );
p->drawText( 1, 1, cellWidth()-2, cellHeight()-2,
AlignCenter, str );
if ( row == inRow && col == inCol && editable)
placeInput();
}
kchart'SheetTable::setInputText() (./koffice/kchart/table.cc:129)
void SheetTable::setInputText( QString s )
{
input->setText( s.data() );
}
kchart'SheetTable::nextInput() (./koffice/kchart/table.cc:134)
void SheetTable::nextInput()
{
int c = inCol;
int r = ( inRow + 1 ) % numRows();
if ( !r )
c = ( inCol + 1 ) % numCols();
moveInput( r, c );
}
kchart'SheetTable::moveInput() (./koffice/kchart/table.cc:143)
void SheetTable::moveInput( int row, int col )
{
if ( col < 0 || row < 0 )
return;
if ( col == inCol && row == inRow )
return;
if ( inRow >= 0 && inCol >= 0 ) {
QString str = input->text();
setText( inRow, inCol, str );
emit newText(inRow, inCol, str );
}
inCol = col;
inRow = row;
makeVisible( inRow, inCol );
placeInput();
emit selected(row,col);
}
kchart'SheetTable::makeVisible() (./koffice/kchart/table.cc:162)
void SheetTable::makeVisible( int row, int col )
{
if ( col < leftCell() ) {
setLeftCell(col);
emit newCol(col);
} else if ( col > lastColVisible() ) {
int c = leftCell() + col - lastColVisible();
setLeftCell(c);
emit newCol(c);
}
if ( row < topCell() ) {
setTopCell(row);
emit newRow(row);
} else if ( row > lastRowVisible() ) {
int r = topCell() + row - lastRowVisible();
setTopCell(r);
emit newRow(r);
}
}
kchart'SheetTable::mousePressEvent() (./koffice/kchart/table.cc:183)
void SheetTable::mousePressEvent( QMouseEvent * e )
{
if (editable)
{
int col = findCol(e->pos().x());
int row = findRow(e->pos().y());
moveInput( row, col );
}
}
kchart'SheetTable::scrollHorz() (./koffice/kchart/table.cc:194)
void SheetTable::scrollHorz( int col )
{
setLeftCell( col );
if (editable) placeInput();
repaint();
}
kchart'SheetTable::scrollVert() (./koffice/kchart/table.cc:201)
void SheetTable::scrollVert(int row )
{
setTopCell( row );
if (editable) placeInput();
repaint();
}