From: Edwin Leuven Date: Wed, 31 May 2006 12:53:05 +0000 (+0000) Subject: Add new tableinsertwidget X-Git-Tag: 1.6.10~13168 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=5c8f40106a852cb616bb5dc21e14d1c98ffb3d84;p=features.git Add new tableinsertwidget + Remove table widget from inserttable dialog git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13972 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/development/scons/SConscript b/development/scons/SConscript index 3ca70f9130..fc71962353 100644 --- a/development/scons/SConscript +++ b/development/scons/SConscript @@ -856,6 +856,7 @@ if build_qt4: floatplacement.C iconpalette.C lengthcombo.C + InsertTableWidget.C panelstack.C QAboutDialog.C QBibitemDialog.C diff --git a/src/frontends/qt4/InsertTableWidget.C b/src/frontends/qt4/InsertTableWidget.C new file mode 100644 index 0000000000..e28ab2a973 --- /dev/null +++ b/src/frontends/qt4/InsertTableWidget.C @@ -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 + +#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 +#include +#include +#include +#include + + +namespace lyx { +namespace frontend { + +InsertTableWidget::InsertTableWidget(LyXView & lyxView, FuncRequest const & func, QWidget * parent) + : QWidget(parent, Qt::Popup), colwidth_(20), rowheight_(12), lyxView_(lyxView), func_(func) +{ + 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); + emit visible(true); +} + + +void InsertTableWidget::resetGeometry() +{ + QPoint p = parentWidget()->mapToGlobal(parentWidget()->geometry().bottomLeft()); + setGeometry(p.x() - parentWidget()->pos().x(), + 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_) + 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 = dynamic_cast(event); + mouseMoveEvent(me); + return true; + } else if (event->type() == QEvent::MouseButtonRelease) { + QMouseEvent * me = dynamic_cast(event); + mouseReleaseEvent(me); + return true; + } else if (event->type() == QEvent::MouseButtonPress) { + // swallow this one... + return true; + } else if (event->type() == QEvent::Leave) { + bottom_ = 0; + right_ = 0; + 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 visible(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); + } + } +} + + +void InsertTableWidget::updateParent() +{ + FuncStatus const status = lyxView_.getLyXFunc().getStatus(func_); + parentWidget()->setEnabled(status.enabled()); +} + + +} // namespace frontend +} // namespace lyx + +#include "InsertTableWidget_moc.cpp" diff --git a/src/frontends/qt4/InsertTableWidget.h b/src/frontends/qt4/InsertTableWidget.h new file mode 100644 index 0000000000..e3fc0f553d --- /dev/null +++ b/src/frontends/qt4/InsertTableWidget.h @@ -0,0 +1,78 @@ +// -*- 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 + +class QSize; + +namespace lyx { +namespace frontend { + + +class InsertTableWidget : public QWidget { + Q_OBJECT +public: + + InsertTableWidget(LyXView &, FuncRequest const &, QWidget *); + +signals: + //! widget is visible + void visible(bool); + +public slots: + //! show the widget + void show(bool); + //! enable/disable parent + void updateParent(); + +protected slots: + bool event(QEvent *); + void mouseMoveEvent(QMouseEvent *); + void mouseReleaseEvent(QMouseEvent *); + void paintEvent(QPaintEvent *); + +private: + //! update the geometry + void resetGeometry(); + //! initialize parameters to default values + void init(); + //! 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 diff --git a/src/frontends/qt4/Makefile.dialogs b/src/frontends/qt4/Makefile.dialogs index 340542f9c6..2d6dc8ab8d 100644 --- a/src/frontends/qt4/Makefile.dialogs +++ b/src/frontends/qt4/Makefile.dialogs @@ -77,6 +77,7 @@ MOCFILES = \ 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 \ diff --git a/src/frontends/qt4/QLToolbar.C b/src/frontends/qt4/QLToolbar.C index 2a24e35c45..945edbe796 100644 --- a/src/frontends/qt4/QLToolbar.C +++ b/src/frontends/qt4/QLToolbar.C @@ -26,12 +26,12 @@ #include "QLToolbar.h" #include "QLAction.h" #include "qt_helpers.h" +#include "InsertTableWidget.h" #include #include #include #include -//Added by qt3to4: #include using std::endl; @@ -235,6 +235,19 @@ void QLToolbar::add(FuncRequest const & func, string const & tooltip) /// \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(visible(bool)), tb, SLOT(setChecked(bool))); + connect(this, SIGNAL(updated()), iv, SLOT(updateParent())); + toolbar_->addWidget(tb); + break; + } default: { if (owner_.getLyXFunc().getStatus(func).unknown()) break; @@ -242,9 +255,8 @@ void QLToolbar::add(FuncRequest const & func, string const & tooltip) QLAction * action = new QLAction(owner_, toolbarbackend.getIcon(func), "", func, tooltip); toolbar_->addAction(action); ActionVector.push_back(action); - break; - } + } } } @@ -265,6 +277,8 @@ void QLToolbar::update() { for (size_t i=0; iupdate(); + + emit updated(); } diff --git a/src/frontends/qt4/QLToolbar.h b/src/frontends/qt4/QLToolbar.h index fe5dbc0346..892923ca3e 100644 --- a/src/frontends/qt4/QLToolbar.h +++ b/src/frontends/qt4/QLToolbar.h @@ -71,6 +71,9 @@ public: void update(); LayoutBox * layout() const { return layout_.get(); } +signals: + void updated(); + private: std::vector ActionVector; diff --git a/src/frontends/qt4/QTabularCreateDialog.C b/src/frontends/qt4/QTabularCreateDialog.C index 173581f9a7..27e96404dc 100644 --- a/src/frontends/qt4/QTabularCreateDialog.C +++ b/src/frontends/qt4/QTabularCreateDialog.C @@ -26,7 +26,6 @@ QTabularCreateDialog::QTabularCreateDialog(QTabularCreate * form) { setupUi(this); - table->setMinimumSize(100,100); rowsSB->setValue(5); columnsSB->setValue(5); @@ -34,13 +33,10 @@ QTabularCreateDialog::QTabularCreateDialog(QTabularCreate * form) 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))); } diff --git a/src/frontends/qt4/ui/QTabularCreateUi.ui b/src/frontends/qt4/ui/QTabularCreateUi.ui index 2c43666599..d4a85d2d14 100644 --- a/src/frontends/qt4/ui/QTabularCreateUi.ui +++ b/src/frontends/qt4/ui/QTabularCreateUi.ui @@ -8,8 +8,8 @@ 0 0 - 272 - 243 + 198 + 125 @@ -18,170 +18,27 @@ true - + - 11 + 9 6 - - - - 0 + + + + Qt::Vertical - - 6 + + + 20 + 40 + - - - - Number of rows - - - &Rows: - - - rowsSB - - - - - - - Number of rows - - - QAbstractSpinBox::PlusMinus - - - 511 - - - 1 - - - - - - - Number of columns - - - &Columns: - - - columnsSB - - - - - - - Number of columns - - - QAbstractSpinBox::PlusMinus - - - 511 - - - 1 - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - - - 0 - - - 6 - - - - - Qt::Horizontal - - - QSizePolicy::MinimumExpanding - - - - 20 - 20 - - - - - - - - Qt::Vertical - - - QSizePolicy::MinimumExpanding - - - - 20 - 20 - - - - - - - - - 5 - 5 - 0 - 0 - - - - - 100 - 100 - - - - - 600 - 600 - - - - Qt::NoFocus - - - Resize this to the correct table dimensions - - - - + - + 0 @@ -221,22 +78,86 @@ + + + + Number of rows + + + &Rows: + + + rowsSB + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 58 + 22 + + + + + + + + Number of columns + + + &Columns: + + + columnsSB + + + + + + + Number of rows + + + QAbstractSpinBox::PlusMinus + + + 511 + + + 1 + + + + + + + Number of columns + + + QAbstractSpinBox::PlusMinus + + + 511 + + + 1 + + + - - - EmptyTable - -
emptytable.h
- 0 - -
-
rowsSB columnsSB - table okPB closePB