Abdelrazak Younes wrote:
I agree it's overkill and we already discussed at length the subject. But all other dialogs go through this controller framework so I would prefer that you use that. Besides, I suspect that the change would be even less intrusive if you do so. No need need to touch the QLToolbar code at all, just replace the "add-table" dialog call with the InsertTableWidget one.

the attached slightly modifies qlaction and avoids changing qltoolbar. opinion?

i also guess we need to keep the add-table dialog call for when the user chooses to insert a table through the menu...


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,147 @@
+
+#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::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)
+{
+       if (event->button() == Qt::LeftButton)  {
+               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, 
Qt::NoModifier);
+    QCoreApplication::sendEvent(parentWidget(), &me);
+}
+
+
+void LIconView::keyPressEvent(QKeyEvent * event)
+{
+       event->accept();
+
+       QKeyEvent ke(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier);
+    QCoreApplication::sendEvent(parentWidget(), &ke);
+
+       if (event->key()==Qt::Key_Escape)
+               close();
+               
+}
+
+} // 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,51 @@
+#ifndef LICONVIEW_H
+#define LICONVIEW_H
+
+#include <QTableWidget>
+#include "frontends/LyXView.h"
+
+
+class QMouseEvent;
+class QFocusEvent;
+class QCloseEvent;
+class QKeyEvent;
+
+
+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();
+
+protected slots:
+
+       void mouseMoveEvent(QMouseEvent * event );
+       void mouseReleaseEvent(QMouseEvent * event );
+       void closeEvent(QCloseEvent * event );
+       void keyPressEvent(QKeyEvent * 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/QLAction.C
===================================================================
--- src/frontends/qt4/QLAction.C        (revision 13913)
+++ 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 13913)
+++ 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="", bool 
const 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="", bool 
const updateonly_ = false);
 
        void update();
 
@@ -53,6 +53,7 @@
        FuncRequest const & func_ ;
        //FuncRequest func_ ;
        LyXView & lyxView_;
+       bool updateonly_;
 };
 
 
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) {
+                       QLAction * action = new QLAction(owner_, 
toolbarbackend.getIcon(func), "", func, tooltip, true);
+                       QToolButton * tb = new QToolButton;
+                       LIconView * iv = new LIconView(tb, owner_, func);
+                       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;
        }
        }

Reply via email to