Abdelrazak Younes wrote:
In principle it should be as easy as replacing QTabularCreate in
"qt4/Dialog.C" with your new dialog. Then, to correctly position your
dialog, you will need to add a method in ControlTabularCreate that
will give the coordinate of toolbar button.
the attached patch is what i came up with.
it works quite well apart from cancelling: i haven't figured out how to
catch mouse events outside the widget (for example on the toolbutton) in
order to close it.
i would greatly appreciate it if someone with some qt knowledge could
have a look at this (i tried the qt-interest list, but haven't received
any clues)
(the contents of the zip here:
http://leuven.ecodip.net/lyx/iconview.zip
allows easy playing around with it)
comments more in general of course appreciated
thanks, edwin
Index: development/scons/SConscript
===================================================================
--- development/scons/SConscript (revision 13913)
+++ development/scons/SConscript (working copy)
@@ -816,6 +816,7 @@
floatplacement.C
iconpalette.C
lengthcombo.C
+ liconview.C
panelstack.C
QAboutDialog.C
QBibitemDialog.C
Index: src/frontends/qt4/liconview.C
===================================================================
--- src/frontends/qt4/liconview.C (revision 0)
+++ src/frontends/qt4/liconview.C (revision 0)
@@ -0,0 +1,140 @@
+
+#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 "liconview.h"
+#include <QHeaderView>
+#include <QMouseEvent>
+#include <QTableWidgetSelectionRange>
+#include <QString>
+#include <QToolTip>
+#include <QCoreApplication>
+
+#include "qt_helpers.h"
+
+
+namespace lyx {
+namespace frontend {
+
+
+LIconView::LIconView(QWidget * parent, LyXView & lyxView, FuncRequest const &
func, int rows, int columns )
+ : QTableWidget( rows, columns, parent), lyxView_(lyxView), func_(func),
colwidth_(20), rowheight_(12)
+{
+ horizontalHeader()->hide();
+ verticalHeader()->hide();
+
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+ setFrameStyle(QFrame::NoFrame);
+ setWindowFlags(Qt::Popup);
+ setMouseTracking(true);
+
+ for(int i=0; i<rowCount() ; ++i)
+ setRowHeight(i, rowheight_);
+
+ for(int i=0; i<columnCount() ; ++i)
+ setColumnWidth(i, colwidth_);
+}
+
+
+void LIconView::updateParent()
+{
+ FuncStatus const status = lyxView_.getLyXFunc().getStatus(func_);
+ parentWidget()->setEnabled(status.enabled());
+}
+
+
+void LIconView::show()
+{
+ resize(sizeHint());
+ QPoint p =
parentWidget()->mapToGlobal(parentWidget()->geometry().bottomLeft());
+ move(p.x() - parentWidget()->pos().x(), p.y() -
parentWidget()->pos().y());
+ setVisible(true);
+}
+
+
+QSize LIconView::sizeHint() const
+{
+ return QSize(columnCount()*colwidth_, rowCount()*rowheight_);
+}
+
+
+void LIconView::addColumn()
+{
+ int const nr = columnCount();
+ insertColumn(nr);
+ setColumnWidth(nr, colwidth_);
+ resize(sizeHint());
+}
+
+
+void LIconView::addRow()
+{
+ int const nr = rowCount();
+ insertRow(nr);
+ setRowHeight(nr, rowheight_);
+ resize(sizeHint());
+}
+
+
+void LIconView::mouseMoveEvent(QMouseEvent * event)
+{
+ clearSelection();
+
+ int const bottom = event->y()/rowheight_;
+ int const right = event->x()/colwidth_;
+ if (event->x()>0 && event->y()>0) {
+ setRangeSelected(QTableWidgetSelectionRange(0, 0, bottom, right
), true);
+ }
+
+ QString status = QString("%1x%2").arg(bottom + 1).arg(right + 1);
+ QToolTip::showText(event->globalPos(), status , this);
+
+ if (event->x()>((columnCount()-1)*colwidth_))
+ addColumn();
+
+ if (event->y()>((rowCount()-1)*rowheight_))
+ addRow();
+}
+
+
+void LIconView::mouseReleaseEvent(QMouseEvent * event)
+{
+ int const bottom = event->y()/rowheight_;
+ int const right = event->x()/colwidth_;
+ QString const data = QString("%1 %2").arg(bottom + 1).arg(right + 1);
+ lyxView_.view()->workAreaDispatch(FuncRequest(LFUN_TABULAR_INSERT,
fromqstr(data) ));
+
+ int const cc = columnCount() - 5;
+ for(int i = 0 ; i<cc ; ++i)
+ removeColumn(0);
+
+ int const rc = rowCount() - 5;
+ for(int i = 0 ; i<rc ; ++i)
+ removeRow(0);
+
+ close();
+}
+
+
+void LIconView::closeEvent(QCloseEvent * event)
+{
+ event->accept();
+
+ QMouseEvent me(QEvent::MouseButtonRelease, QPoint(0,0), QPoint(0,0),
+ Qt::LeftButton, Qt::NoButton);
+ QCoreApplication::sendEvent( parentWidget(), &me );
+}
+
+
+} // namespace frontend
+} // namespace lyx
+
+#include "liconview_moc.cpp"
Index: src/frontends/qt4/liconview.h
===================================================================
--- src/frontends/qt4/liconview.h (revision 0)
+++ src/frontends/qt4/liconview.h (revision 0)
@@ -0,0 +1,49 @@
+#ifndef LICONVIEW_H
+#define LICONVIEW_H
+
+#include <QTableWidget>
+#include "frontends/LyXView.h"
+
+
+class QMouseEvent;
+class QFocusEvent;
+class QCloseEvent;
+
+namespace lyx {
+namespace frontend {
+
+
+class LIconView : public QTableWidget {
+ Q_OBJECT
+public:
+
+ LIconView(QWidget * parent, LyXView & lyxView, FuncRequest const &
func, int rows = 5, int columns = 5);
+
+ QSize sizeHint() const;
+
+public slots:
+
+ void show();
+ void updateParent();
+
+protected slots:
+
+ void mouseMoveEvent(QMouseEvent * event );
+ void mouseReleaseEvent(QMouseEvent * event );
+ void closeEvent(QCloseEvent * event );
+
+private:
+ void addRow();
+ void addColumn();
+
+ int colwidth_;
+ int rowheight_;
+
+ FuncRequest const & func_ ;
+ LyXView & lyxView_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // LICONVIEW_H
Index: src/frontends/qt4/QLToolbar.C
===================================================================
--- src/frontends/qt4/QLToolbar.C (revision 13913)
+++ src/frontends/qt4/QLToolbar.C (working copy)
@@ -26,12 +26,13 @@
#include "QLToolbar.h"
#include "QLAction.h"
#include "qt_helpers.h"
+#include "liconview.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) {
+ QToolButton * tb = new QToolButton;
+
tb->setIcon(QIcon(toolbarbackend.getIcon(func).c_str()));
+ tb->setToolTip(toqstr(tooltip));
+ LIconView * iv = new LIconView(tb, owner_, func);
+ connect(tb, SIGNAL(pressed()), iv, SLOT(show()));
+ connect(this, SIGNAL(updateChildren()), iv,
SLOT(updateParent()));
+ toolbar_->addWidget(tb);
+ } else {
+ QLAction * action = new QLAction(owner_,
toolbarbackend.getIcon(func), "", func, tooltip);
+ toolbar_->addAction(action);
+ ActionVector.push_back(action);
+ }
break;
}
}
@@ -265,6 +275,8 @@
{
for (size_t i=0; i<ActionVector.size(); ++i)
ActionVector[i]->update();
+
+ emit updateChildren();
}
Index: src/frontends/qt4/QLToolbar.h
===================================================================
--- src/frontends/qt4/QLToolbar.h (revision 13913)
+++ src/frontends/qt4/QLToolbar.h (working copy)
@@ -71,6 +71,8 @@
void update();
LayoutBox * layout() const { return layout_.get(); }
+signals:
+ void updateChildren();
private:
std::vector<QLAction *> ActionVector;