Andre Poenitz wrote:
We write 'a = 1;', not 'a=1;', and 'for (', not 'for('...
i try to be good in the attached...
have you an idea on how to catch mouse events outside the iconview
widget here:
http://leuven.ecodip.net/lyx/iconview.zip
Is that the one you send to qt-interest?
yeah, but in the meantime (out of the lack of resourcefullness and
responses from qt-interest) i choose to inherit from qwidget and do the
painting myself instead of subclassing qtablewidget...
only small issue: the toolbutton is not reset on cancel (ie click
outside the widget).
inserting works fine, and clicking on the workarea (so that the cursos
gets focus) resets the button as well, but i haven't been able to
trigger this with an event to the button... (suggestions welcome of course)
what i haven't done: implement a lyxfunc
the main reason is that it is not clear to me that we would want to
introduce special casing in the core in order to avoid it in the frontend...
second, we are inserting a non-standard widget and i am not sure we want
a new lyxfunc for every deviation from a toolbutton: we will want to
have "iconpallete's" popups on some buttons in a math toolbar, do we
want lyxfuncs for these as well?
finally, although this is a practical obstacle, i haven't figured out a
clean way of having qlaction passing the pos() of the toolbutton to the
widget through the lyxfunc...
apart from this it works like a charm
thanks, ed.
Index: development/scons/SConscript
===================================================================
--- development/scons/SConscript (revision 13943)
+++ development/scons/SConscript (working copy)
@@ -816,6 +816,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,155 @@
+/**
+ * \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 "qt_helpers.h"
+
+#include "InsertTableWidget.h"
+#include <QMouseEvent>
+#include <QString>
+#include <QToolTip>
+#include <QPainter>
+
+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)
+{
+ setMouseTracking(true);
+}
+
+
+void InsertTableWidget::show()
+{
+ 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)
+{
+ if (!underMouse())
+ return;
+
+ right_ = event->x()/colwidth_ + 1;
+ bottom_ = event->y()/rowheight_ + 1;
+
+ if (bottom_ == rows_) {
+ ++rows_;
+ resetGeometry();
+ }
+
+ if (right_ == cols_) {
+ ++cols_;
+ resetGeometry();
+ }
+
+ 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::Paint) {
+ QPaintEvent * pe = static_cast<QPaintEvent *>(event);
+ paintEvent(pe);
+ return true;
+ } else if (event->type() == QEvent::Leave) {
+ update();
+ return true;
+ } else if (event->type() == QEvent::Close) {
+ close();
+ return true;
+ }
+ return QWidget::event(event);
+}
+
+
+void InsertTableWidget::mouseReleaseEvent(QMouseEvent * event)
+{
+ if (underMouse()) {
+ QString const data = QString("%1 %2").arg(bottom_).arg(right_);
+
lyxView_.view()->workAreaDispatch(FuncRequest(LFUN_TABULAR_INSERT,
fromqstr(data) ));
+ }
+ 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);
+}
+
+
+} // 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,72 @@
+// -*- 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 QMouseEvent;
+class QSize;
+
+namespace lyx {
+namespace frontend {
+
+
+class InsertTableWidget : public QWidget {
+ Q_OBJECT
+public:
+
+ InsertTableWidget(LyXView & lyxView, FuncRequest const & func, QWidget
* parent = 0);
+
+ QSize sizeHint();
+
+public slots:
+ void show();
+
+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_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // INSERTTABLEWIDGET_H
Index: src/frontends/qt4/Makefile.dialogs
===================================================================
--- src/frontends/qt4/Makefile.dialogs (revision 13943)
+++ 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/QLAction.C
===================================================================
--- src/frontends/qt4/QLAction.C (revision 13943)
+++ src/frontends/qt4/QLAction.C (working copy)
@@ -40,8 +40,8 @@
} // namespace anon
QLAction::QLAction(LyXView & lyxView, string const & text,
- FuncRequest const & func, string const & tooltip)
- : QAction(this), lyxView_(lyxView), func_(func)
+ FuncRequest const & func, string const & tooltip, bool const
updateonly)
+ : QAction(this), lyxView_(lyxView), func_(func),
updateonly_(updateonly)
{
setText(tr(toqstr(text)));
setToolTip(tr(toqstr(tooltip)));
@@ -51,8 +51,8 @@
}
QLAction::QLAction(LyXView & lyxView, string const & icon, string const & text,
- FuncRequest const & func, string const & tooltip)
- : QAction(this), lyxView_(lyxView), func_(func)
+ FuncRequest const & func, string const & tooltip, bool const
updateonly)
+ : QAction(this), lyxView_(lyxView), func_(func),
updateonly_(updateonly)
{
setIcon(QPixmap(icon.c_str()));
setText(tr(toqstr(text)));
@@ -81,6 +81,8 @@
void QLAction::action()
{
// lyxerr[Debug::ACTION] << "calling LyXFunc::dispatch: func_: " << func_
<< endl;
+ if (updateonly_)
+ return;
lyxView_.getLyXFunc().dispatch(func_);
}
Index: src/frontends/qt4/QLAction.h
===================================================================
--- src/frontends/qt4/QLAction.h (revision 13943)
+++ src/frontends/qt4/QLAction.h (working copy)
@@ -37,10 +37,10 @@
public:
QLAction(LyXView & lyxView, std::string const & text,
- FuncRequest const & func, std::string const & tooltip="");
+ FuncRequest const & func, std::string const & tooltip =
std::string(), bool updateonly_ = false);
QLAction(LyXView & lyxView, std::string const & icon, std::string const
& text,
- FuncRequest const & func, std::string const & tooltip="");
+ FuncRequest const & func, std::string const & tooltip =
std::string(), bool updateonly_ = false);
void update();
@@ -53,6 +53,8 @@
FuncRequest const & func_ ;
//FuncRequest func_ ;
LyXView & lyxView_;
+ //update only the parent no func dispatch
+ bool updateonly_;
};
Index: src/frontends/qt4/QLToolbar.C
===================================================================
--- src/frontends/qt4/QLToolbar.C (revision 13943)
+++ src/frontends/qt4/QLToolbar.C (working copy)
@@ -26,12 +26,13 @@
#include "QLToolbar.h"
#include "QLAction.h"
#include "qt_helpers.h"
+#include "InsertTableWidget.h"
#include <QComboBox>
#include <QToolBar>
#include <QToolButton>
+#include <QPushButton>
#include <QAction>
-//Added by qt3to4:
#include <QPixmap>
using std::endl;
@@ -239,10 +240,19 @@
if (owner_.getLyXFunc().getStatus(func).unknown())
break;
- QLAction * action = new QLAction(owner_,
toolbarbackend.getIcon(func), "", func, tooltip);
- toolbar_->addAction(action);
- ActionVector.push_back(action);
-
+ if (func.action==LFUN_TABULAR_INSERT) {
+ QLAction * action = new QLAction(owner_,
toolbarbackend.getIcon(func), "", func, tooltip, true);
+ QToolButton * tb = new QToolButton;
+ InsertTableWidget * iv = new InsertTableWidget(owner_,
func, tb);
+ connect(action, SIGNAL(triggered()), iv, SLOT(show()));
+ tb->setDefaultAction(action);
+ toolbar_->addWidget(tb);
+ ActionVector.push_back(action);
+ } else {
+ QLAction * action = new QLAction(owner_,
toolbarbackend.getIcon(func), "", func, tooltip);
+ toolbar_->addAction(action);
+ ActionVector.push_back(action);
+ }
break;
}
}