3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
9 #include "emptytable.h"
12 * A simple widget for a quick "preview" in TabularCreateDialog
15 const unsigned int cellsize = 20;
17 EmptyTable::EmptyTable(QWidget * parent, const char * name)
18 : QtTableView(parent, name, WRepaintNoErase)
22 setCellWidth(cellsize);
23 setCellHeight(cellsize);
24 setTableFlags(Tbl_autoScrollBars);
27 QSize EmptyTable::sizeHint() const
29 return QSize(cellsize * numCols(), cellsize * numRows());
33 void EmptyTable::paintCell(QPainter *p, int row, int col)
35 int const x2 = cellWidth(col) - 1;
36 int const y2 = cellHeight(row) - 1;
38 p->fillRect(0, 0, x2, y2, QColor("white"));
39 p->drawLine(x2, 0, x2, y2);
40 p->drawLine(0, y2, x2, y2);
42 if (row + 1 != numRows() || col + 1 != numCols())
46 int const step = cellsize / 5;
48 int x = cellsize - step;
49 int const y = cellsize - space;
50 int const ex = cellsize - space;
51 int ey = cellsize - step;
53 p->drawLine(x, y, ex, ey);
59 void EmptyTable::setNumberColumns(int nr_cols)
63 if (nr_cols == numCols())
70 emit colsChanged(nr_cols);
73 void EmptyTable::setNumberRows(int nr_rows)
77 if (nr_rows == numRows())
84 emit rowsChanged(nr_rows);
87 void EmptyTable::mouseMoveEvent(QMouseEvent *ev)
89 int const x = ev->pos().x();
90 int const y = ev->pos().y();
93 setNumberColumns(x / cellsize + leftCell());
96 setNumberRows(y / cellsize + topCell());