2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
* \file EmptyTable.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-26 03:53:02 +00:00
|
|
|
#include "EmptyTable.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A simple widget for a quick "preview" in TabularCreateDialog
|
|
|
|
*/
|
|
|
|
|
|
|
|
unsigned int const cellsize = 20;
|
|
|
|
|
|
|
|
|
|
|
|
EmptyTable::EmptyTable(QWidget * parent, int rows, int columns)
|
|
|
|
: QTableWidget(rows, columns, parent)
|
|
|
|
{
|
|
|
|
resetCellSize();
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
|
|
|
viewport()->resize(cellsize*rows,cellsize*columns);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QSize EmptyTable::sizeHint() const
|
|
|
|
{
|
|
|
|
return QSize(cellsize * (2+columnCount()), cellsize * (2+rowCount()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyTable::resetCellSize()
|
|
|
|
{
|
|
|
|
for(int i=0; i<rowCount(); ++i)
|
|
|
|
setRowHeight(i, cellsize);
|
|
|
|
for(int i=0; i<columnCount(); ++i)
|
|
|
|
setColumnWidth(i, cellsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyTable::paintCell(QPainter * p, int row, int col)
|
|
|
|
{
|
|
|
|
int const x2 = columnWidth(col) - 1;
|
|
|
|
int const y2 = rowHeight(row) - 1;
|
|
|
|
|
|
|
|
p->fillRect(0, 0, x2, y2, QColor("white"));
|
|
|
|
p->drawLine(x2, 0, x2, y2);
|
|
|
|
p->drawLine(0, y2, x2, y2);
|
|
|
|
|
|
|
|
if (row + 1 != rowCount() || col + 1 != columnCount())
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EmptyTable::setNumberColumns(int nr_cols)
|
|
|
|
{
|
|
|
|
if (nr_cols < 1)
|
|
|
|
return;
|
|
|
|
if (nr_cols == columnCount())
|
|
|
|
return;
|
|
|
|
setColumnCount(nr_cols);
|
|
|
|
resetCellSize();
|
|
|
|
updateGeometry();
|
2007-05-28 22:27:45 +00:00
|
|
|
// emit signal
|
2006-06-30 14:11:50 +00:00
|
|
|
colsChanged(nr_cols);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EmptyTable::setNumberRows(int nr_rows)
|
|
|
|
{
|
|
|
|
if (nr_rows < 1)
|
|
|
|
return;
|
|
|
|
if (nr_rows == rowCount())
|
|
|
|
return;
|
|
|
|
setRowCount(nr_rows);
|
|
|
|
resetCellSize();
|
|
|
|
updateGeometry();
|
2007-05-28 22:27:45 +00:00
|
|
|
// emit signal
|
2006-06-30 14:11:50 +00:00
|
|
|
rowsChanged(nr_rows);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
void EmptyTable::mouseMoveEvent(QMouseEvent *ev)
|
|
|
|
{
|
|
|
|
int const x = ev->pos().x();
|
|
|
|
int const y = ev->pos().y();
|
|
|
|
|
|
|
|
if (x > 0)
|
|
|
|
setNumberColumns(x / cellsize + columnCount()-1);
|
|
|
|
|
|
|
|
if (y > 0)
|
|
|
|
setNumberRows(y / cellsize + rowCount()-1);
|
|
|
|
}
|
2006-04-09 08:42:58 +00:00
|
|
|
*/
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_EmptyTable.cpp"
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|