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 EmptyTable::EmptyTable(QWidget * parent, int rows, int columns)
26 : QTableWidget(rows, columns, parent)
29 setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
30 setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
31 viewport()->resize(cellheight * rows, cellwidth * columns);
32 setSelectionMode(QAbstractItemView::NoSelection);
33 setFocusPolicy(Qt::NoFocus);
34 setEditTriggers(QAbstractItemView::NoEditTriggers);
39 QSize EmptyTable::sizeHint() const
41 return QSize(cellwidth * (2 + columnCount()), cellheight * (2 + rowCount()));
45 void EmptyTable::adjustMinCellSize()
47 setRowHeight(0, cellheight);
48 cellheight = rowHeight(0);
49 setColumnWidth(0, cellwidth);
50 cellwidth = columnWidth(0);
54 void EmptyTable::resetCellSize()
56 for(int i = 0; i < rowCount(); ++i)
57 setRowHeight(i, cellheight);
58 for(int i = 0; i < columnCount(); ++i)
59 setColumnWidth(i, cellwidth);
62 void EmptyTable::paintCell(QPainter * p, int row, int col)
64 int const x2 = columnWidth(col) - 1;
65 int const y2 = rowHeight(row) - 1;
67 p->fillRect(0, 0, x2, y2, QColor("white"));
68 p->drawLine(x2, 0, x2, y2);
69 p->drawLine(0, y2, x2, y2);
71 if (row + 1 != rowCount() || col + 1 != columnCount())
75 int const step = cellheight / 5;
77 int x = cellwidth - step;
78 int const y = cellheight - space;
79 int const ex = cellwidth - space;
80 int ey = cellheight - step;
82 p->drawLine(x, y, ex, ey);
89 void EmptyTable::setNumberColumns(int nr_cols)
93 if (nr_cols == columnCount())
95 setColumnCount(nr_cols);
103 void EmptyTable::setNumberRows(int nr_rows)
107 if (nr_rows == rowCount())
109 setRowCount(nr_rows);
113 rowsChanged(nr_rows);
117 void EmptyTable::mouseMoveEvent(QMouseEvent *ev)
119 int cc = columnCount();
121 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
122 int x = ev->position().x();
123 int y = ev->position().y();
128 int w = cellwidth * cc;
129 int h = cellheight * rc;
130 int wl = cellwidth * (cc - 1);
131 int hl = cellheight * (rc - 1);
133 setNumberColumns(cc + 1);
135 setNumberRows(rc + 1);
137 setNumberColumns(cc - 1);
139 setNumberRows(rc - 1);
142 #include "moc_EmptyTable.cpp"