]> git.lyx.org Git - features.git/commitdiff
make macrfos readable again
authorAndré Pönitz <poenitz@gmx.net>
Sun, 22 Oct 2006 14:37:32 +0000 (14:37 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Sun, 22 Oct 2006 14:37:32 +0000 (14:37 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15479 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiApplication.C
src/frontends/qt4/GuiView.C
src/frontends/qt4/QCommandBuffer.C
src/frontends/qt4/QCommandBuffer.h
src/frontends/qt4/QCommandEdit.C
src/frontends/qt4/QCommandEdit.h
src/lyx_main.C
src/mathed/MathMacroTable.C
src/mathed/MathMacroTemplate.C
src/mathed/MathMacroTemplate.h
src/text3.C

index 27016b7415f6653675a38325f5aaf41929bb68d8..72d12b01809c06e41cd12a81ccb7fe580513fed3 100644 (file)
@@ -90,7 +90,7 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
        : QApplication(argc, argv), Application(argc, argv)
 {
 #ifdef Q_WS_X11
-       // doubleClickInterval() is 400 ms on X11 witch is just too long.
+       // doubleClickInterval() is 400 ms on X11 which is just too long.
        // On Windows and Mac OS X, the operating system's value is used.
        // On Microsoft Windows, calling this function sets the double
        // click interval for all applications. So we don't!
index aeeba51e1fb6f738bdcaffd9acd43651fad7d323..98f3542076361927c18fafa1065796d6fd88c25f 100644 (file)
 #include "QCommandBuffer.h"
 #include "qt_helpers.h"
 
+#include <QAction>
 #include <QApplication>
+#include <QCloseEvent>
 #include <QPixmap>
 #include <QStatusBar>
 #include <QToolBar>
-#include <QCloseEvent>
-#include <QAction>
 
 
 #include <boost/bind.hpp>
@@ -93,13 +93,15 @@ GuiView::~GuiView()
 void GuiView::init()
 {
        menubar_.reset(new QLMenubar(this, menubackend));
-       QObject::connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *)));
+       QObject::connect(menuBar(), SIGNAL(triggered(QAction *)),
+               this, SLOT(updateMenu(QAction *)));
 
        getToolbars().init();
 
        statusBar()->setSizeGripEnabled(false);
 
-       QObject::connect(&statusbar_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
+       QObject::connect(&statusbar_timer_, SIGNAL(timeout()),
+               this, SLOT(update_view_state_qt()));
 
        // make sure the buttons are disabled if needed
        updateToolbars();
index 7081e0820e1e3b9766aefa9539bd700a3219cdeb..916b76ac8b0a28d8e16a209806c10118c1bdae68 100644 (file)
 #include "QCommandBuffer.h"
 #include "QCommandEdit.h"
 #include "qt_helpers.h"
-//Added by qt3to4:
-#include <QVBoxLayout>
-#include <QMouseEvent>
-#include <QPixmap>
-#include <QHBoxLayout>
-#include <QKeyEvent>
 
 #include "controllers/ControlCommandBuffer.h"
 
 #include "support/filetools.h"
 
-#include <QListWidget>
+#include <QHBoxLayout>
+#include <QKeyEvent>
 #include <QLayout>
-#include <QToolTip>
+#include <QListWidget>
+#include <QMouseEvent>
+#include <QPixmap>
 #include <QPushButton>
+#include <QToolTip>
+#include <QVBoxLayout>
 
 using lyx::support::libFileSearch;
 
@@ -53,29 +52,30 @@ public:
                setAttribute(Qt::WA_DeleteOnClose);
        }
 protected:
-       void mouseReleaseEvent(QMouseEvent * e) {
-               if (e->x() < 0 || e->y() < 0
-                   || e->x() > width() || e->y() > height()) {
+       void mouseReleaseEvent(QMouseEvent * ev) {
+               if (ev->x() < 0 || ev->y() < 0
+                   || ev->x() > width() || ev->y() > height()) {
                        hide();
                } else {
-                        // emit signal
+                       // emit signal
                        itemPressed(currentItem());
                }
        }
 
-       void keyPressEvent(QKeyEvent * e) {
-               if (e->key() == Qt::Key_Escape) {
+       void keyPressEvent(QKeyEvent * ev) {
+               if (ev->key() == Qt::Key_Escape) {
                        hide();
                        return;
                }
-               QListWidget::keyPressEvent(e);
+               QListWidget::keyPressEvent(ev);
        }
 };
 
 } // end of anon
 
 
-QCommandBuffer::QCommandBuffer(GuiView * view, ControlCommandBuffer & control, QWidget * parent)
+QCommandBuffer::QCommandBuffer(GuiView * view, ControlCommandBuffer & control,
+                       QWidget * parent)
        : QWidget(parent), view_(view), controller_(control)
 {
        QPixmap qpup(toqstr(libFileSearch("images", "up", "xpm")));
@@ -104,7 +104,9 @@ QCommandBuffer::QCommandBuffer(GuiView * view, ControlCommandBuffer & control, Q
        layout->addWidget(up, 0);
        layout->addWidget(down, 0);
        layout->addWidget(edit_, 10);
+       layout->setMargin(0);
        top->addLayout(layout);
+       top->setMargin(0);
 }
 
 
@@ -118,7 +120,7 @@ void QCommandBuffer::focus_command()
 void QCommandBuffer::cancel()
 {
        view_->centralWidget()->setFocus();
-       edit_->setText("");
+       edit_->setText(QString());
 }
 
 
@@ -126,7 +128,7 @@ void QCommandBuffer::dispatch()
 {
        controller_.dispatch(fromqstr(edit_->text()));
        view_->centralWidget()->setFocus();
-       edit_->setText("");
+       edit_->setText(QString());
        edit_->clearFocus();
 }
 
@@ -138,7 +140,7 @@ void QCommandBuffer::complete()
        vector<string> comp = controller_.completions(input, new_input);
 
        if (comp.empty() && new_input == input) {
-       //      show_info_suffix(qt_("[no match]"), input);
+               // show_info_suffix(qt_("[no match]"), input);
                return;
        }
 
@@ -156,17 +158,13 @@ void QCommandBuffer::complete()
        // than the number of actual items...
        vector<string>::const_iterator cit = comp.begin();
        vector<string>::const_iterator end = comp.end();
-       for (; cit != end; ++cit) {
+       for (; cit != end; ++cit)
                list->addItem(toqstr(*cit));
-       }
-
-       // width() is not big enough by a few pixels. Qt Sucks.
-//     list->setMinimumWidth(list->sizeHint().width() + 10);
 
        list->resize(list->sizeHint());
-       QPoint pos(edit_->mapToGlobal(QPoint(0, 0)));
+       QPoint const pos = edit_->mapToGlobal(QPoint(0, 0));
 
-       int y = std::max(0, pos.y() - list->height());
+       int const y = std::max(0, pos.y() - list->height());
 
        list->move(pos.x(), y);
 
@@ -189,8 +187,8 @@ void QCommandBuffer::complete_selected(QListWidgetItem * item)
 
 void QCommandBuffer::up()
 {
-       string const input(fromqstr(edit_->text()));
-       string const h(controller_.historyUp());
+       string const input = fromqstr(edit_->text());
+       string const h = controller_.historyUp();
 
        if (h.empty()) {
        //      show_info_suffix(qt_("[Beginning of history]"), input);
@@ -202,8 +200,8 @@ void QCommandBuffer::up()
 
 void QCommandBuffer::down()
 {
-       string const input(fromqstr(edit_->text()));
-       string const h(controller_.historyDown());
+       string const input = fromqstr(edit_->text());
+       string const h = controller_.historyDown();
 
        if (h.empty()) {
        //      show_info_suffix(qt_("[End of history]"), input);
index 3aee759f7f97f753c0425d89c670d5bb2bddd784..e221383af70e8ac65c1a876040505695da6b24e9 100644 (file)
@@ -26,7 +26,8 @@ class ControlCommandBuffer;
 class QCommandBuffer : public QWidget {
        Q_OBJECT
 public:
-       QCommandBuffer(GuiView * view, ControlCommandBuffer & control, QWidget * parent=NULL);
+       QCommandBuffer(GuiView * view, ControlCommandBuffer & control,
+               QWidget * parent=NULL);
 
        /// focus the edit widget
        void focus_command();
index d0882f49d7139ce03ab415132e742f17aee5dc1e..41eea45f74c38a964953bc33b92e2d0e4bf6f601 100644 (file)
@@ -11,7 +11,7 @@
 #include <config.h>
 
 #include "QCommandEdit.h"
-//Added by qt3to4:
+
 #include <QKeyEvent>
 #include <QEvent>
 
@@ -29,17 +29,17 @@ void QCommandEdit::keyPressEvent(QKeyEvent * e)
 {
        switch (e->key()) {
        case Qt::Key_Escape:
-                // emit signal
+               // emit signal
                escapePressed();
                break;
 
        case Qt::Key_Up:
-                // emit signal
+               // emit signal
                upPressed();
                break;
 
        case Qt::Key_Down:
-                // emit signal
+               // emit signal
                downPressed();
                break;
 
@@ -60,7 +60,7 @@ bool QCommandEdit::event(QEvent * e)
        if (ev->key() != Qt::Key_Tab)
                return QLineEdit::event(e);
 
-        // emit signal
+       // emit signal
        tabPressed();
        return true;
 }
index d37c1a2f003f850044be63abd6271900d6a9139d..5a846844fd43ef8ccff10f25b71c440974ea3532 100644 (file)
@@ -26,19 +26,17 @@ public:
 Q_SIGNALS:
        /// cancel
        void escapePressed();
-
        /// up history
        void upPressed();
-
        /// down history
        void downPressed();
-
        /// complete
        void tabPressed();
 
 protected:
+       ///
        virtual bool event(QEvent * e);
-
+       ///
        virtual void keyPressEvent(QKeyEvent * e);
 };
 
index a36bc40c0657b8ede8d62fb4b1c37ca56ec847e6..6d0949458bda0fe2fc60eb36f2cd37975d9a98e7 100644 (file)
@@ -333,9 +333,10 @@ int LyX::priv_exec(int & argc, char * argv[])
                // Start the real execution loop.
 
                // FIXME
-               /* Create a CoreApplication class that will provide the main event loop and 
-                * the socket callback registering. With Qt4, only QtCore library would be needed.
-                * When this done, a server_mode could be created and the following two
+               /* Create a CoreApplication class that will provide the main event loop
+                * and the socket callback registering. With Qt4, only QtCore
+                * library would be needed.
+                * When this is done, a server_mode could be created and the following two
                 * line would be moved out from here.
                 */
                pimpl_->lyx_server_.reset(new LyXServer(&pimpl_->lyxfunc_, lyxrc.lyxpipes));
index 88e794d1d2f10696f85ad717d2297df841906565..da31ea15deb9e5408fe433122ee96d3ec4f831b2 100644 (file)
@@ -102,8 +102,7 @@ void MacroTable::insert(docstring const & name, MacroData const & data)
 void MacroTable::insert(docstring const & def)
 {
        //lyxerr << "MacroTable::insert, def: " << to_utf8(def) << endl;
-       std::istringstream is(to_utf8(def));
-       MathMacroTemplate mac(is);
+       MathMacroTemplate mac(def);
        insert(mac.name(), mac.asMacroData());
 }
 
index a260d193f9053874c1c679ff9b97feb44893665f..0ba5c231e6096d44911fbe89534d50d10aed5b97 100644 (file)
@@ -57,15 +57,15 @@ MathMacroTemplate::MathMacroTemplate(docstring const & name, int numargs,
 }
 
 
-MathMacroTemplate::MathMacroTemplate(std::istream & is)
+MathMacroTemplate::MathMacroTemplate(docstring const & str)
        : InsetMathNest(2), numargs_(0), name_()
 {
        initMath();
 
        MathArray ar;
-       mathed_parse_cell(ar, is);
+       mathed_parse_cell(ar, str);
        if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
-               lyxerr << "cannot read macro from '" << ar << "'" << endl;
+               lyxerr << "Cannot read macro from '" << ar << "'" << endl;
                return;
        }
        operator=( *(ar[0]->asMacroTemplate()) );
@@ -173,9 +173,15 @@ void MathMacroTemplate::draw(PainterInfo & p, int x, int y) const
 void MathMacroTemplate::read(Buffer const &, LyXLex & lex)
 {
        MathArray ar;
-       mathed_parse_cell(ar, lex.getDocString());
+       lex.next(); // eat \begin_inset FormulaMacro line
+       docstring const str = lex.getDocString();
+       lex.next(); // eat that macro definition
+       lex.next(); // eat the \\end_insrt line
+       lyxerr << "Got to read from: " << to_utf8(str) << endl;
+       mathed_parse_cell(ar, str);
        if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
-               lyxerr << "cannot read macro from '" << ar << "'" << endl;
+               lyxerr << "Cannot read macro from '" << ar << "'" << endl;
+               lyxerr << "Read: " << to_utf8(asString(ar)) << endl;
                return;
        }
        operator=( *(ar[0]->asMacroTemplate()) );
index cc07d4e10f96c1d22c6a47544994ee46bb844896..c319ae5a8e13769e96f87efff4d1af57cd5e5d44 100644 (file)
@@ -33,7 +33,7 @@ public:
                MathArray const & = MathArray(),
                MathArray const & = MathArray());
        ///
-       explicit MathMacroTemplate(std::istream & is);
+       explicit MathMacroTemplate(const docstring & str);
        ///
        void edit(LCursor & cur, bool left);
        ///
index 9c613595881d7abd5e73993f4dc6bde05b01982a..221b297d9a9ca563199614e57b15435f28d3290f 100644 (file)
@@ -136,7 +136,7 @@ namespace {
        void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
        {
                recordUndo(cur);
-               string sel = to_utf8(cur.selectionAsString(false));
+               docstring sel = cur.selectionAsString(false);
                //lyxerr << "selection is: '" << sel << "'" << endl;
 
                // It may happen that sel is empty but there is a selection
@@ -162,11 +162,11 @@ namespace {
                        // create a macro if we see "\\newcommand"
                        // somewhere, and an ordinary formula
                        // otherwise
-                       istringstream is(sel);
-                       if (sel.find("\\newcommand") == string::npos
-                           && sel.find("\\def") == string::npos)
+                       if (sel.find(from_ascii("\\newcommand")) == string::npos
+                           && sel.find(from_ascii("\\def")) == string::npos)
                        {
                                InsetMathHull * formula = new InsetMathHull;
+                               istringstream is(to_utf8(sel));
                                LyXLex lex(0, 0);
                                lex.setStream(is);
                                formula->read(cur.buffer(), lex);
@@ -175,8 +175,9 @@ namespace {
                                        // delimiters are left out
                                        formula->mutate(hullSimple);
                                cur.insert(formula);
-                       } else
-                               cur.insert(new MathMacroTemplate(is));
+                       } else {
+                               cur.insert(new MathMacroTemplate(sel));
+                       }
                }
                cur.message(from_utf8(N_("Math editor mode")));
        }