2001-06-05 17:05:51 +00:00
|
|
|
/**
|
|
|
|
* \file emptytable.C
|
|
|
|
* Copyright 2001 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author John Levon
|
2001-02-14 19:43:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "emptytable.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A simple widget for a quick "preview" in TabularCreateDialog
|
|
|
|
*/
|
|
|
|
|
|
|
|
const unsigned int cellsize = 20;
|
|
|
|
|
|
|
|
EmptyTable::EmptyTable(QWidget * parent, const char * name)
|
2002-06-19 03:38:44 +00:00
|
|
|
: QtTableView(parent, name, WRepaintNoErase)
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
|
|
|
setNumCols(5);
|
|
|
|
setNumRows(5);
|
|
|
|
setCellWidth(cellsize);
|
|
|
|
setCellHeight(cellsize);
|
|
|
|
setTableFlags(Tbl_autoScrollBars);
|
|
|
|
}
|
|
|
|
|
2001-08-31 03:01:11 +00:00
|
|
|
QSize EmptyTable::sizeHint() const
|
|
|
|
{
|
|
|
|
return QSize(cellsize * numCols(), cellsize * numRows());
|
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-02-14 19:43:56 +00:00
|
|
|
void EmptyTable::paintCell(QPainter *p, int row, int col)
|
|
|
|
{
|
2001-08-19 13:25:15 +00:00
|
|
|
int const x2 = cellWidth(col) - 1;
|
|
|
|
int const y2 = cellHeight(row) - 1;
|
2001-02-14 19:43:56 +00:00
|
|
|
|
|
|
|
p->fillRect(0, 0, x2, y2, QColor("white"));
|
|
|
|
p->drawLine(x2, 0, x2, y2);
|
|
|
|
p->drawLine(0, y2, x2, y2);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
if (row + 1 != numRows() || col + 1 != numCols())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// draw handle
|
|
|
|
int const step = cellsize / 5;
|
|
|
|
int const space = 4;
|
|
|
|
int x = cellsize - step;
|
|
|
|
int const y = cellsize - space;
|
|
|
|
int const ex = cellsize - space;
|
|
|
|
int ey = cellsize - step;
|
|
|
|
while (x > space) {
|
|
|
|
p->drawLine(x, y, ex, ey);
|
|
|
|
x -= step;
|
|
|
|
ey -= step;
|
|
|
|
}
|
2001-02-14 19:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyTable::setNumberColumns(int nr_cols)
|
|
|
|
{
|
|
|
|
if (nr_cols < 1)
|
|
|
|
return;
|
|
|
|
if (nr_cols == numCols())
|
|
|
|
return;
|
|
|
|
setAutoUpdate(false);
|
|
|
|
setNumCols(nr_cols);
|
2001-08-31 03:01:11 +00:00
|
|
|
updateGeometry();
|
2001-02-14 19:43:56 +00:00
|
|
|
setAutoUpdate(true);
|
|
|
|
update();
|
|
|
|
emit colsChanged(nr_cols);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyTable::setNumberRows(int nr_rows)
|
|
|
|
{
|
|
|
|
if (nr_rows < 1)
|
|
|
|
return;
|
|
|
|
if (nr_rows == numRows())
|
|
|
|
return;
|
|
|
|
setAutoUpdate(false);
|
|
|
|
setNumRows(nr_rows);
|
2001-08-31 03:01:11 +00:00
|
|
|
updateGeometry();
|
2001-02-14 19:43:56 +00:00
|
|
|
setAutoUpdate(true);
|
|
|
|
update();
|
|
|
|
emit rowsChanged(nr_rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyTable::mouseMoveEvent(QMouseEvent *ev)
|
|
|
|
{
|
2001-08-19 13:25:15 +00:00
|
|
|
int const x = ev->pos().x();
|
|
|
|
int const y = ev->pos().y();
|
2001-02-14 19:43:56 +00:00
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
if (x > 0)
|
2001-02-14 19:43:56 +00:00
|
|
|
setNumberColumns(x / cellsize + leftCell());
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
if (y > 0)
|
2001-02-14 19:43:56 +00:00
|
|
|
setNumberRows(y / cellsize + topCell());
|
|
|
|
}
|