From dc94575f2b5e8736544a280c5643ef438cb60531 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sun, 22 Oct 2006 14:37:32 +0000 Subject: [PATCH] make macrfos readable again git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15479 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiApplication.C | 2 +- src/frontends/qt4/GuiView.C | 10 +++--- src/frontends/qt4/QCommandBuffer.C | 58 +++++++++++++++--------------- src/frontends/qt4/QCommandBuffer.h | 3 +- src/frontends/qt4/QCommandEdit.C | 10 +++--- src/frontends/qt4/QCommandEdit.h | 6 ++-- src/lyx_main.C | 7 ++-- src/mathed/MathMacroTable.C | 3 +- src/mathed/MathMacroTemplate.C | 16 ++++++--- src/mathed/MathMacroTemplate.h | 2 +- src/text3.C | 13 +++---- 11 files changed, 68 insertions(+), 62 deletions(-) diff --git a/src/frontends/qt4/GuiApplication.C b/src/frontends/qt4/GuiApplication.C index 27016b7415..72d12b0180 100644 --- a/src/frontends/qt4/GuiApplication.C +++ b/src/frontends/qt4/GuiApplication.C @@ -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! diff --git a/src/frontends/qt4/GuiView.C b/src/frontends/qt4/GuiView.C index aeeba51e1f..98f3542076 100644 --- a/src/frontends/qt4/GuiView.C +++ b/src/frontends/qt4/GuiView.C @@ -39,12 +39,12 @@ #include "QCommandBuffer.h" #include "qt_helpers.h" +#include #include +#include #include #include #include -#include -#include #include @@ -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(); diff --git a/src/frontends/qt4/QCommandBuffer.C b/src/frontends/qt4/QCommandBuffer.C index 7081e0820e..916b76ac8b 100644 --- a/src/frontends/qt4/QCommandBuffer.C +++ b/src/frontends/qt4/QCommandBuffer.C @@ -17,21 +17,20 @@ #include "QCommandBuffer.h" #include "QCommandEdit.h" #include "qt_helpers.h" -//Added by qt3to4: -#include -#include -#include -#include -#include #include "controllers/ControlCommandBuffer.h" #include "support/filetools.h" -#include +#include +#include #include -#include +#include +#include +#include #include +#include +#include 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 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::const_iterator cit = comp.begin(); vector::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); diff --git a/src/frontends/qt4/QCommandBuffer.h b/src/frontends/qt4/QCommandBuffer.h index 3aee759f7f..e221383af7 100644 --- a/src/frontends/qt4/QCommandBuffer.h +++ b/src/frontends/qt4/QCommandBuffer.h @@ -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(); diff --git a/src/frontends/qt4/QCommandEdit.C b/src/frontends/qt4/QCommandEdit.C index d0882f49d7..41eea45f74 100644 --- a/src/frontends/qt4/QCommandEdit.C +++ b/src/frontends/qt4/QCommandEdit.C @@ -11,7 +11,7 @@ #include #include "QCommandEdit.h" -//Added by qt3to4: + #include #include @@ -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; } diff --git a/src/frontends/qt4/QCommandEdit.h b/src/frontends/qt4/QCommandEdit.h index d37c1a2f00..5a846844fd 100644 --- a/src/frontends/qt4/QCommandEdit.h +++ b/src/frontends/qt4/QCommandEdit.h @@ -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); }; diff --git a/src/lyx_main.C b/src/lyx_main.C index a36bc40c06..6d0949458b 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -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)); diff --git a/src/mathed/MathMacroTable.C b/src/mathed/MathMacroTable.C index 88e794d1d2..da31ea15de 100644 --- a/src/mathed/MathMacroTable.C +++ b/src/mathed/MathMacroTable.C @@ -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()); } diff --git a/src/mathed/MathMacroTemplate.C b/src/mathed/MathMacroTemplate.C index a260d193f9..0ba5c231e6 100644 --- a/src/mathed/MathMacroTemplate.C +++ b/src/mathed/MathMacroTemplate.C @@ -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()) ); diff --git a/src/mathed/MathMacroTemplate.h b/src/mathed/MathMacroTemplate.h index cc07d4e10f..c319ae5a8e 100644 --- a/src/mathed/MathMacroTemplate.h +++ b/src/mathed/MathMacroTemplate.h @@ -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); /// diff --git a/src/text3.C b/src/text3.C index 9c61359588..221b297d9a 100644 --- a/src/text3.C +++ b/src/text3.C @@ -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"))); } -- 2.39.5