2 * \file InsertTableWidget.C
\r
4 * This file is part of LyX, the document processor.
\r
5 * Licence details can be found in the file COPYING.
\r
7 * \author Edwin Leuven
\r
9 * Full author contact details are available in file CREDITS.
\r
14 #include "BufferView.h" // needed for lyxfunc
\r
15 #include "lyxfunc.h"
\r
16 #include "FuncStatus.h"
\r
17 #include "funcrequest.h"
\r
18 #include "LyXView.h"
\r
20 #include "qt_helpers.h"
\r
22 #include "InsertTableWidget.h"
\r
23 #include <QMouseEvent>
\r
30 namespace frontend {
\r
32 InsertTableWidget::InsertTableWidget(LyXView & lyxView, QWidget * parent)
\r
33 : QWidget(parent, Qt::Popup), colwidth_(20), rowheight_(12), lyxView_(lyxView)
\r
36 setMouseTracking(true);
\r
40 void InsertTableWidget::init()
\r
46 underMouse_ = false;
\r
50 void InsertTableWidget::show(bool show)
\r
63 void InsertTableWidget::resetGeometry()
\r
65 QPoint p = parentWidget()->mapToGlobal(parentWidget()->geometry().bottomLeft());
\r
66 setGeometry(p.x() - parentWidget()->pos().x(),
\r
67 p.y() - parentWidget()->pos().y(),
\r
68 cols_ * colwidth_ + 1, rows_ * rowheight_ + 1);
\r
72 void InsertTableWidget::mouseMoveEvent(QMouseEvent * event)
\r
74 // do this ourselves because when the mouse leaves the app
\r
75 // we get an enter event (ie underMouse() is true)!!
\r
76 underMouse_ = geometry().contains(event->globalPos());
\r
84 int const r0 = right_;
\r
85 int const b0 = bottom_;
\r
86 right_ = event->x() / colwidth_ + 1;
\r
87 bottom_ = event->y() / rowheight_ + 1;
\r
89 if (bottom_ == rows_) {
\r
94 if (right_ == cols_) {
\r
99 if (bottom_ != b0 || right_ != r0) {
\r
101 QString const status = QString("%1x%2").arg(bottom_).arg(right_);
\r
102 QToolTip::showText(event->globalPos(), status , this);
\r
107 void InsertTableWidget::mouseReleaseEvent(QMouseEvent * event)
\r
110 QString const data = QString("%1 %2").arg(bottom_).arg(right_);
\r
111 lyxView_.getLyXFunc().dispatch(FuncRequest(LFUN_TABULAR_INSERT, fromqstr(data)));
\r
119 void InsertTableWidget::mousePressEvent(QMouseEvent * event)
\r
121 // swallow this one
\r
125 void InsertTableWidget::paintEvent(QPaintEvent * event)
\r
127 drawGrid(rows_, cols_, Qt::white);
\r
129 drawGrid(bottom_, right_, Qt::darkBlue);
\r
133 void InsertTableWidget::drawGrid(int const rows, int const cols, Qt::GlobalColor const color)
\r
135 QPainter painter(this);
\r
136 painter.setPen(Qt::darkGray);
\r
137 painter.setBrush(color);
\r
139 for (int r = 0 ; r < rows ; ++r ) {
\r
140 for (int c = 0 ; c < cols ; ++c ) {
\r
141 QRect rectangle(c * colwidth_, r * rowheight_, colwidth_, rowheight_);
\r
142 painter.drawRect(rectangle);
\r
148 void InsertTableWidget::updateParent()
\r
150 bool status = lyxView_.getLyXFunc().getStatus(FuncRequest(LFUN_TABULAR_INSERT)).enabled();
\r
151 parentWidget()->setEnabled(status);
\r
155 } // namespace frontend
\r
158 #include "InsertTableWidget_moc.cpp"
\r