3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Jürgen Spitzmüller
9 * Full author contact details are available in file CREDITS.
14 #include "EmptyTable.h"
16 #include "support/debug.h"
19 #include <QMouseEvent>
22 * A simple widget for a quick "preview" in TabularCreateDialog
25 unsigned int const cellheight = 20;
26 unsigned int const cellwidth = 30;
29 EmptyTable::EmptyTable(QWidget * parent, int rows, int columns)
30 : QTableWidget(rows, columns, parent)
33 setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
34 setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
35 viewport()->resize(cellheight * rows, cellwidth * columns);
36 setSelectionMode(QAbstractItemView::NoSelection);
37 setEditTriggers(QAbstractItemView::NoEditTriggers);
41 QSize EmptyTable::sizeHint() const
43 return QSize(cellwidth * (2 + columnCount()), cellheight * (2 + rowCount()));
46 void EmptyTable::resetCellSize()
48 for(int i = 0; i < rowCount(); ++i)
49 setRowHeight(i, cellheight);
50 for(int i = 0; i < columnCount(); ++i)
51 setColumnWidth(i, cellwidth);
54 void EmptyTable::paintCell(QPainter * p, int row, int col)
56 int const x2 = columnWidth(col) - 1;
57 int const y2 = rowHeight(row) - 1;
59 p->fillRect(0, 0, x2, y2, QColor("white"));
60 p->drawLine(x2, 0, x2, y2);
61 p->drawLine(0, y2, x2, y2);
63 if (row + 1 != rowCount() || col + 1 != columnCount())
67 int const step = cellheight / 5;
69 int x = cellwidth - step;
70 int const y = cellheight - space;
71 int const ex = cellwidth - space;
72 int ey = cellheight - step;
74 p->drawLine(x, y, ex, ey);
81 void EmptyTable::setNumberColumns(int nr_cols)
85 if (nr_cols == columnCount())
87 setColumnCount(nr_cols);
95 void EmptyTable::setNumberRows(int nr_rows)
99 if (nr_rows == rowCount())
101 setRowCount(nr_rows);
105 rowsChanged(nr_rows);
109 void EmptyTable::mouseMoveEvent(QMouseEvent *ev)
111 int cc = columnCount();
115 int w = cellwidth * cc;
116 int h = cellheight * rc;
117 int wl = cellwidth * (cc - 1);
118 int hl = cellheight * (rc - 1);
120 setNumberColumns(cc + 1);
122 setNumberRows(rc + 1);
124 setNumberColumns(cc - 1);
126 setNumberRows(rc - 1);
129 #include "moc_EmptyTable.cpp"