attached my latest patch i'd like to put it in
any objections? thanks, edwin
Index: development/scons/SConscript =================================================================== --- development/scons/SConscript (revision 13969) +++ development/scons/SConscript (working copy) @@ -856,6 +856,7 @@ floatplacement.C iconpalette.C lengthcombo.C + InsertTableWidget.C panelstack.C QAboutDialog.C QBibitemDialog.C Index: src/frontends/qt4/InsertTableWidget.C =================================================================== --- src/frontends/qt4/InsertTableWidget.C (revision 0) +++ src/frontends/qt4/InsertTableWidget.C (revision 0) @@ -0,0 +1,171 @@ +/** + * \file InsertTableWidget.C + * + * 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> + +#include "BufferView.h" // needed for lyxfunc +#include "lyxfunc.h" +#include "FuncStatus.h" +#include "funcrequest.h" +#include "LyXView.h" +#include "debug.h" + +#include "qt_helpers.h" + +#include "InsertTableWidget.h" +#include <QMouseEvent> +#include <QString> +#include <QToolTip> +#include <QPainter> +#include <QCoreApplication> + + +namespace lyx { +namespace frontend { + +InsertTableWidget::InsertTableWidget(LyXView & lyxView, FuncRequest const & func, QWidget * parent) + : QWidget(parent, Qt::Popup), colwidth_(20), rowheight_(12), + rows_(5), cols_(5), bottom_(0), right_(0), lyxView_(lyxView), func_(func), underMouse_(false) +{ + setMouseTracking(true); +} + + +void InsertTableWidget::show(bool show) +{ + if (!show) + return; + + underMouse_ = false; + rows_ = 5; + cols_ = 5; + resetGeometry(); + setVisible(true); +} + + +void InsertTableWidget::resetGeometry() +{ + if (parentWidget()) { + QPoint p = parentWidget()->mapToGlobal(parentWidget()->geometry().bottomLeft()); + setGeometry(p.x() - parentWidget()->pos().x(), + p.y() - parentWidget()->pos().y(), + cols_ * colwidth_ + 1, rows_ * rowheight_ + 1); + } else resize(sizeHint()); +} + + +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_) + 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 status = QString("%1x%2").arg(bottom_).arg(right_); + QToolTip::showText(event->globalPos(), status , this); +} + + +bool InsertTableWidget::event(QEvent * event) +{ + if (event->type() == QEvent::MouseMove) { + QMouseEvent * me = static_cast<QMouseEvent *>(event); + mouseMoveEvent(me); + return true; + } else if (event->type() == QEvent::MouseButtonRelease) { + QMouseEvent * me = static_cast<QMouseEvent *>(event); + mouseReleaseEvent(me); + return true; + } else if (event->type() == QEvent::MouseButtonPress) { + // swallow this one... + return true; + } else if (event->type() == QEvent::Leave) { + update(); + return true; + } + return QWidget::event(event); +} + + +void InsertTableWidget::mouseReleaseEvent(QMouseEvent * event) +{ + if (underMouse_) { + QString const data = QString("%1 %2").arg(bottom_).arg(right_); + lyxView_.getLyXFunc().dispatch(FuncRequest(LFUN_TABULAR_INSERT, fromqstr(data))); + } + emit check(false); + close(); +} + + +void InsertTableWidget::paintEvent(QPaintEvent * event) +{ + 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); + } + } +} + + +QSize InsertTableWidget::sizeHint() +{ + return QSize(cols_ * colwidth_ + 1, rows_ * rowheight_ + 1); +} + + +void InsertTableWidget::updateParent() +{ + if (!parentWidget()) + return; + + FuncStatus const status = lyxView_.getLyXFunc().getStatus(func_); + parentWidget()->setEnabled(status.enabled()); +} + + +} // namespace frontend +} // namespace lyx + +#include "InsertTableWidget_moc.cpp" Index: src/frontends/qt4/InsertTableWidget.h =================================================================== --- src/frontends/qt4/InsertTableWidget.h (revision 0) +++ src/frontends/qt4/InsertTableWidget.h (revision 0) @@ -0,0 +1,76 @@ +// -*- C++ -*- +/** + * \file InsertTableWidget.h + * 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. + */ + + +#ifndef INSERTTABLEWIDGET_H +#define INSERTTABLEWIDGET_H + +#include "frontends/LyXView.h" +#include <QWidget> + +class QSize; + +namespace lyx { +namespace frontend { + + +class InsertTableWidget : public QWidget { + Q_OBJECT +public: + + InsertTableWidget(LyXView & lyxView, FuncRequest const & func, QWidget * parent = 0); + + QSize sizeHint(); + +signals: + void check(bool); + +public slots: + void show(bool); + void updateParent(); + +protected slots: + bool event(QEvent *); + void mouseMoveEvent(QMouseEvent *); + void mouseReleaseEvent(QMouseEvent *); + void paintEvent(QPaintEvent *); + +private: + // update the geometry + void resetGeometry(); + // draw the grid + void drawGrid(int rows, int cols, Qt::GlobalColor color); + + // colwidth in pixels + int colwidth_; + // rowheight in pixels + int rowheight_; + // total rows + int rows_; + // total cols + int cols_; + // row of pointer + int bottom_; + // column of pointer + int right_; + + // the tabular_insert funcrequest + FuncRequest const & func_ ; + // the lyxview we need to dispatch the funcrequest + LyXView & lyxView_; + // widget under mouse + bool underMouse_; +}; + +} // namespace frontend +} // namespace lyx + +#endif // INSERTTABLEWIDGET_H Index: src/frontends/qt4/Makefile.dialogs =================================================================== --- src/frontends/qt4/Makefile.dialogs (revision 13969) +++ src/frontends/qt4/Makefile.dialogs (working copy) @@ -77,6 +77,7 @@ FileDialog_private.C FileDialog_private.h \ floatplacement.C floatplacement.h \ iconpalette.C iconpalette.h \ + InsertTableWidget.C InsertTableWidget.h \ lengthcombo.C lengthcombo.h \ panelstack.C panelstack.h \ QAboutDialog.C QAboutDialog.h \ Index: src/frontends/qt4/QLToolbar.C =================================================================== --- src/frontends/qt4/QLToolbar.C (revision 13969) +++ src/frontends/qt4/QLToolbar.C (working copy) @@ -26,12 +26,12 @@ #include "QLToolbar.h" #include "QLAction.h" #include "qt_helpers.h" +#include "InsertTableWidget.h" #include <QComboBox> #include <QToolBar> #include <QToolButton> #include <QAction> -//Added by qt3to4: #include <QPixmap> using std::endl; @@ -235,6 +235,19 @@ /// \todo find a Qt4 equivalent to setHorizontalStretchable(true); //toolbar_->setHorizontalStretchable(true); break; + case LFUN_TABULAR_INSERT: { + QToolButton * tb = new QToolButton; + tb->setCheckable(true); + tb->setIcon(QPixmap(toqstr(toolbarbackend.getIcon(func)))); + tb->setToolTip(toqstr(tooltip)); + tb->setFocusPolicy(Qt::NoFocus); + InsertTableWidget * iv = new InsertTableWidget(owner_, func, tb); + connect(tb, SIGNAL(toggled(bool)), iv, SLOT(show(bool))); + connect(iv, SIGNAL(check(bool)), tb, SLOT(setChecked(bool))); + connect(this, SIGNAL(updateToolbar()), iv, SLOT(updateParent())); + toolbar_->addWidget(tb); + break; + } default: { if (owner_.getLyXFunc().getStatus(func).unknown()) break; @@ -242,10 +255,9 @@ QLAction * action = new QLAction(owner_, toolbarbackend.getIcon(func), "", func, tooltip); toolbar_->addAction(action); ActionVector.push_back(action); - break; + } } - } } @@ -265,6 +277,8 @@ { for (size_t i=0; i<ActionVector.size(); ++i) ActionVector[i]->update(); + + emit updateToolbar(); } Index: src/frontends/qt4/QLToolbar.h =================================================================== --- src/frontends/qt4/QLToolbar.h (revision 13969) +++ src/frontends/qt4/QLToolbar.h (working copy) @@ -71,6 +71,9 @@ void update(); LayoutBox * layout() const { return layout_.get(); } +signals: + void updateToolbar(); + private: std::vector<QLAction *> ActionVector; Index: src/frontends/qt4/QTabularCreateDialog.C =================================================================== --- src/frontends/qt4/QTabularCreateDialog.C (revision 13969) +++ src/frontends/qt4/QTabularCreateDialog.C (working copy) @@ -26,7 +26,6 @@ { setupUi(this); - table->setMinimumSize(100,100); rowsSB->setValue(5); columnsSB->setValue(5); @@ -34,13 +33,10 @@ form_, SLOT(slotOK())); connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose())); - - connect( table, SIGNAL( rowsChanged(int) ), rowsSB, SLOT( setValue(int) ) ); - connect( table, SIGNAL( colsChanged(int) ), columnsSB, SLOT( setValue(int) ) ); - connect( rowsSB, SIGNAL( valueChanged(int) ), table, SLOT( setNumberRows(int) ) ); - connect( columnsSB, SIGNAL( valueChanged(int) ), table, SLOT( setNumberColumns(int) ) ); - connect( rowsSB, SIGNAL( valueChanged(int) ), this, SLOT( rowsChanged(int) ) ); - connect( columnsSB, SIGNAL( valueChanged(int) ), this, SLOT( columnsChanged(int) ) ); + connect(rowsSB, SIGNAL(valueChanged(int)), + this, SLOT( rowsChanged(int))); + connect(columnsSB, SIGNAL(valueChanged(int)), + this, SLOT(columnsChanged(int))); } Index: src/frontends/qt4/ui/QTabularCreateUi.ui =================================================================== --- src/frontends/qt4/ui/QTabularCreateUi.ui (revision 13969) +++ src/frontends/qt4/ui/QTabularCreateUi.ui (working copy) @@ -8,8 +8,8 @@ <rect> <x>0</x> <y>0</y> - <width>272</width> - <height>243</height> + <width>198</width> + <height>125</height> </rect> </property> <property name="windowTitle" > @@ -18,170 +18,27 @@ <property name="sizeGripEnabled" > <bool>true</bool> </property> - <layout class="QVBoxLayout" > + <layout class="QGridLayout" > <property name="margin" > - <number>11</number> + <number>9</number> </property> <property name="spacing" > <number>6</number> </property> - <item> - <layout class="QHBoxLayout" > - <property name="margin" > - <number>0</number> + <item row="2" column="1" > + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> </property> - <property name="spacing" > - <number>6</number> + <property name="sizeHint" > + <size> + <width>20</width> + <height>40</height> + </size> </property> - <item> - <widget class="QLabel" name="rowsL" > - <property name="toolTip" > - <string>Number of rows</string> - </property> - <property name="text" > - <string>&Rows:</string> - </property> - <property name="buddy" > - <cstring>rowsSB</cstring> - </property> - </widget> - </item> - <item> - <widget class="QSpinBox" name="rowsSB" > - <property name="toolTip" > - <string>Number of rows</string> - </property> - <property name="buttonSymbols" > - <enum>QAbstractSpinBox::PlusMinus</enum> - </property> - <property name="maximum" > - <number>511</number> - </property> - <property name="minimum" > - <number>1</number> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="columnsL" > - <property name="toolTip" > - <string>Number of columns</string> - </property> - <property name="text" > - <string>&Columns:</string> - </property> - <property name="buddy" > - <cstring>columnsSB</cstring> - </property> - </widget> - </item> - <item> - <widget class="QSpinBox" name="columnsSB" > - <property name="toolTip" > - <string>Number of columns</string> - </property> - <property name="buttonSymbols" > - <enum>QAbstractSpinBox::PlusMinus</enum> - </property> - <property name="maximum" > - <number>511</number> - </property> - <property name="minimum" > - <number>1</number> - </property> - </widget> - </item> - <item> - <spacer> - <property name="orientation" > - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType" > - <enum>QSizePolicy::Expanding</enum> - </property> - <property name="sizeHint" > - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> + </spacer> </item> - <item> - <layout class="QGridLayout" > - <property name="margin" > - <number>0</number> - </property> - <property name="spacing" > - <number>6</number> - </property> - <item row="0" column="1" > - <spacer> - <property name="orientation" > - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType" > - <enum>QSizePolicy::MinimumExpanding</enum> - </property> - <property name="sizeHint" > - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="1" column="0" > - <spacer> - <property name="orientation" > - <enum>Qt::Vertical</enum> - </property> - <property name="sizeType" > - <enum>QSizePolicy::MinimumExpanding</enum> - </property> - <property name="sizeHint" > - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="0" > - <widget class="EmptyTable" name="table" > - <property name="sizePolicy" > - <sizepolicy> - <hsizetype>5</hsizetype> - <vsizetype>5</vsizetype> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize" > - <size> - <width>100</width> - <height>100</height> - </size> - </property> - <property name="maximumSize" > - <size> - <width>600</width> - <height>600</height> - </size> - </property> - <property name="focusPolicy" > - <enum>Qt::NoFocus</enum> - </property> - <property name="toolTip" > - <string>Resize this to the correct table dimensions</string> - </property> - </widget> - </item> - </layout> - </item> - <item> + <item row="3" column="0" colspan="3" > <layout class="QHBoxLayout" > <property name="margin" > <number>0</number> @@ -221,22 +78,86 @@ </item> </layout> </item> + <item row="0" column="0" > + <widget class="QLabel" name="rowsL" > + <property name="toolTip" > + <string>Number of rows</string> + </property> + <property name="text" > + <string>&Rows:</string> + </property> + <property name="buddy" > + <cstring>rowsSB</cstring> + </property> + </widget> + </item> + <item row="0" column="2" > + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::Expanding</enum> + </property> + <property name="sizeHint" > + <size> + <width>58</width> + <height>22</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="0" > + <widget class="QLabel" name="columnsL" > + <property name="toolTip" > + <string>Number of columns</string> + </property> + <property name="text" > + <string>&Columns:</string> + </property> + <property name="buddy" > + <cstring>columnsSB</cstring> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QSpinBox" name="rowsSB" > + <property name="toolTip" > + <string>Number of rows</string> + </property> + <property name="buttonSymbols" > + <enum>QAbstractSpinBox::PlusMinus</enum> + </property> + <property name="maximum" > + <number>511</number> + </property> + <property name="minimum" > + <number>1</number> + </property> + </widget> + </item> + <item row="1" column="1" > + <widget class="QSpinBox" name="columnsSB" > + <property name="toolTip" > + <string>Number of columns</string> + </property> + <property name="buttonSymbols" > + <enum>QAbstractSpinBox::PlusMinus</enum> + </property> + <property name="maximum" > + <number>511</number> + </property> + <property name="minimum" > + <number>1</number> + </property> + </widget> + </item> </layout> </widget> <pixmapfunction></pixmapfunction> - <customwidgets> - <customwidget> - <class>EmptyTable</class> - <extends></extends> - <header>emptytable.h</header> - <container>0</container> - <pixmap></pixmap> - </customwidget> - </customwidgets> <tabstops> <tabstop>rowsSB</tabstop> <tabstop>columnsSB</tabstop> - <tabstop>table</tabstop> <tabstop>okPB</tabstop> <tabstop>closePB</tabstop> </tabstops>