3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "EmptyTable.h"
16 #include <QMouseEvent>
19 * A simple widget for a quick "preview" in TabularCreateDialog
22 unsigned int const cellsize = 20;
25 EmptyTable::EmptyTable(QWidget * parent, int rows, int columns)
26 : QTableWidget(rows, columns, parent)
29 setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
30 setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
31 viewport()->resize(cellsize*rows,cellsize*columns);
35 QSize EmptyTable::sizeHint() const
37 return QSize(cellsize * (2+columnCount()), cellsize * (2+rowCount()));
40 void EmptyTable::resetCellSize()
42 for(int i=0; i<rowCount(); ++i)
43 setRowHeight(i, cellsize);
44 for(int i=0; i<columnCount(); ++i)
45 setColumnWidth(i, cellsize);
48 void EmptyTable::paintCell(QPainter * p, int row, int col)
50 int const x2 = columnWidth(col) - 1;
51 int const y2 = rowHeight(row) - 1;
53 p->fillRect(0, 0, x2, y2, QColor("white"));
54 p->drawLine(x2, 0, x2, y2);
55 p->drawLine(0, y2, x2, y2);
57 if (row + 1 != rowCount() || col + 1 != columnCount())
61 int const step = cellsize / 5;
63 int x = cellsize - step;
64 int const y = cellsize - space;
65 int const ex = cellsize - space;
66 int ey = cellsize - step;
68 p->drawLine(x, y, ex, ey);
75 void EmptyTable::setNumberColumns(int nr_cols)
79 if (nr_cols == columnCount())
81 setColumnCount(nr_cols);
89 void EmptyTable::setNumberRows(int nr_rows)
93 if (nr_rows == rowCount())
103 void EmptyTable::mouseMoveEvent(QMouseEvent *ev)
105 int const x = ev->pos().x();
106 int const y = ev->pos().y();
109 setNumberColumns(x / cellsize + columnCount()-1);
112 setNumberRows(y / cellsize + rowCount()-1);
116 #include "moc_EmptyTable.cpp"