2006-06-30 14:50:44 +00:00
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
* \file InsertTableWidget.cpp
|
2006-06-30 14:50:44 +00:00
|
|
|
*
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Edwin Leuven
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
#include "InsertTableWidget.h"
|
2006-06-30 14:50:44 +00:00
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
#include "GuiView.h"
|
2006-06-30 14:50:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
#include "FuncStatus.h"
|
|
|
|
#include "FuncRequest.h"
|
2010-02-09 16:11:13 +00:00
|
|
|
#include "LyX.h"
|
2007-11-23 09:44:02 +00:00
|
|
|
|
2006-06-30 14:50:44 +00:00
|
|
|
#include <QMouseEvent>
|
2007-11-23 09:44:02 +00:00
|
|
|
#include <QPainter>
|
2006-06-30 14:50:44 +00:00
|
|
|
#include <QString>
|
|
|
|
#include <QToolTip>
|
|
|
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2013-05-02 16:27:32 +00:00
|
|
|
InsertTableWidget::InsertTableWidget(QWidget * parent)
|
|
|
|
: QWidget(parent, Qt::Popup), colwidth_(20), rowheight_(12)
|
2006-06-30 14:50:44 +00:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsertTableWidget::init()
|
|
|
|
{
|
|
|
|
rows_ = 5;
|
|
|
|
cols_ = 5;
|
|
|
|
bottom_ = 0;
|
|
|
|
right_ = 0;
|
|
|
|
underMouse_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsertTableWidget::show(bool show)
|
|
|
|
{
|
|
|
|
if (!show)
|
|
|
|
return;
|
|
|
|
|
|
|
|
init();
|
|
|
|
resetGeometry();
|
|
|
|
setVisible(true);
|
2006-07-06 08:18:51 +00:00
|
|
|
// emit signal
|
2006-06-30 14:50:44 +00:00
|
|
|
visible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsertTableWidget::resetGeometry()
|
|
|
|
{
|
|
|
|
QPoint p = parentWidget()->mapToGlobal(parentWidget()->geometry().bottomLeft());
|
2006-07-06 08:18:51 +00:00
|
|
|
setGeometry(p.x() - parentWidget()->pos().x(),
|
2006-06-30 14:50:44 +00:00
|
|
|
p.y() - parentWidget()->pos().y(),
|
|
|
|
cols_ * colwidth_ + 1, rows_ * rowheight_ + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsertTableWidget::mouseMoveEvent(QMouseEvent * event)
|
|
|
|
{
|
|
|
|
// do this ourselves because when the mouse leaves the app
|
|
|
|
// we get an enter event (ie underMouse() is true)!!
|
|
|
|
underMouse_ = geometry().contains(event->globalPos());
|
|
|
|
if (!underMouse_) {
|
|
|
|
bottom_ = 0;
|
|
|
|
right_ = 0;
|
|
|
|
update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int const r0 = right_;
|
|
|
|
int const b0 = bottom_;
|
|
|
|
right_ = event->x() / colwidth_ + 1;
|
|
|
|
bottom_ = event->y() / rowheight_ + 1;
|
|
|
|
|
|
|
|
if (bottom_ == rows_) {
|
|
|
|
++rows_;
|
|
|
|
resetGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (right_ == cols_) {
|
|
|
|
++cols_;
|
|
|
|
resetGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bottom_ != b0 || right_ != r0) {
|
|
|
|
update();
|
|
|
|
QString const status = QString("%1x%2").arg(bottom_).arg(right_);
|
|
|
|
QToolTip::showText(event->globalPos(), status , this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-06 08:18:51 +00:00
|
|
|
void InsertTableWidget::mouseReleaseEvent(QMouseEvent * /*event*/)
|
2006-06-30 14:50:44 +00:00
|
|
|
{
|
|
|
|
if (underMouse_) {
|
|
|
|
QString const data = QString("%1 %2").arg(bottom_).arg(right_);
|
2007-11-26 22:45:17 +00:00
|
|
|
lyx::dispatch(FuncRequest(LFUN_TABULAR_INSERT, fromqstr(data)));
|
2006-06-30 14:50:44 +00:00
|
|
|
}
|
2006-07-06 08:18:51 +00:00
|
|
|
// emit signal
|
2006-06-30 14:50:44 +00:00
|
|
|
visible(false);
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-06 08:18:51 +00:00
|
|
|
void InsertTableWidget::mousePressEvent(QMouseEvent * /*event*/)
|
2006-06-30 14:50:44 +00:00
|
|
|
{
|
|
|
|
// swallow this one
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-06 08:18:51 +00:00
|
|
|
void InsertTableWidget::paintEvent(QPaintEvent * /*event*/)
|
2006-06-30 14:50:44 +00:00
|
|
|
{
|
|
|
|
drawGrid(rows_, cols_, Qt::white);
|
|
|
|
if (underMouse_)
|
|
|
|
drawGrid(bottom_, right_, Qt::darkBlue);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsertTableWidget::drawGrid(int const rows, int const cols, Qt::GlobalColor const color)
|
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
painter.setPen(Qt::darkGray);
|
|
|
|
painter.setBrush(color);
|
|
|
|
|
|
|
|
for (int r = 0 ; r < rows ; ++r ) {
|
|
|
|
for (int c = 0 ; c < cols ; ++c ) {
|
|
|
|
QRect rectangle(c * colwidth_, r * rowheight_, colwidth_, rowheight_);
|
|
|
|
painter.drawRect(rectangle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsertTableWidget::updateParent()
|
|
|
|
{
|
2007-04-25 16:39:21 +00:00
|
|
|
bool status = getStatus(FuncRequest(LFUN_TABULAR_INSERT)).enabled();
|
2006-06-30 14:50:44 +00:00
|
|
|
parentWidget()->setEnabled(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_InsertTableWidget.cpp"
|