Am Donnerstag, 27. April 2006 14:12 schrieb Enrico Forestieri: > Well, here is the result of my effort. I also attach separately a diff > against src/frontends/qt3/ui/moc/Makefile.in and > src/frontends/qt3/moc/Makefile.in as "svn diff" doesn't seem to have > catched them. I had to patch them because "qt_helpers.h" was not found > after I edited QDelimiterDialogBase.ui with the Qt3 designer.
Includes from Qt3 .ui files are put into the .h file, not the .C file as it was done by Qt2. I solved this problem already with the Qt2 -> Qt3 conversion this morning. > Please, someone should have a look at QDelimiterDialogBase.ui as I > managed to break it wrt resizing and don't know what else (Abdel?). > Sorry guys, but I have never programmed Qt or used designer before. I don't know how it happened, but you did more than just inserting the size combo. I guess this was not intended? I removed the additional changes, and now it works. > Something as to be done also for Qt4 and gtk, but I leave this to > someone more knowledgeable than me, as I risk to do more damage than > good ;-) I added FIXMEs. > IMO this work is still unfinished, as when there is a selection the > fixed size delimiters should be placed at the left and right of it. > Instead, currently the selection is replaced by the delimiters. I solved that problem by introducing a new lfun. Apart from that I also changed the code in QDelimiterDialog.C a bit: Translate the combobox items and use static arrays for the delimiter names. The latter has the advantage that it can be easily adapted: Want to support biggg? Just add it to bigleft, bigright and biggui, no other code changes required. The attached patch works well here. If I don't get objections I will put it in tomorrow. Georg Log: Implement GUI for fixed size math delimiters (by Enrico Forestieri and me): * src/lfuns.h (enum kb_action): New lfun LFUN_MATH_BIGDELIM * src/LyXAction.C (void LyXAction::init): New lfun LFUN_MATH_BIGDELIM * src/mathed/math_nestinset.C (void MathNestInset::doDispatch): remove debug message (void MathNestInset::doDispatch): remove LFUN_MATH_DELIM test for multiple cells (now in getStatus) (void MathNestInset::doDispatch): Handle LFUN_MATH_BIGDELIM (bool MathNestInset::getStatus): Disable LFUN_MATH_DELIM and LFUN_MATH_BIGDELIM when the selection spans multiple cells * src/frontends/qt3/ui/QDelimiterDialogBase.ui Added a combobox for selecting delimiter size. * src/frontends/qt3/QDelimiterDialog.[Ch] (fix_name, QDelimiterDialog, insertClicked, size_selected): Allow for fixed size delimiters. * src/frontends/gtk/GMathDelim.C: Add FIXME commnent for fixed size delimiters * src/frontends/qt4/QDelimiterDialog.C: ditto * src/frontends/xforms/FormMathsDelim.C: ditto * src/frontends/controllers/ControlMath.[Ch]: Added dispatchBigDelim() to deal with fixed size delimiters. * src/text3.C (void LyXText::dispatch): Handle LFUN_MATH_BIGDELIM (bool LyXText::getStatus): ditto * src/ToolbarBackend.C (string const ToolbarBackend::getIcon): Handle LFUN_MATH_BIGDELIM
Index: src/LyXAction.C =================================================================== --- src/LyXAction.C (Revision 13785) +++ src/LyXAction.C (Arbeitskopie) @@ -212,6 +212,7 @@ void LyXAction::init() { LFUN_MARK_ON, "mark-on", ReadOnly }, { LFUN_SETMARK, "mark-toggle", ReadOnly }, { LFUN_MATH_DELIM, "math-delim", Noop }, + { LFUN_MATH_BIGDELIM, "math-bigdelim", Noop }, { LFUN_MATH_DISPLAY, "math-display", Noop }, { LFUN_INSERT_MATH, "math-insert", Noop }, { LFUN_SUBSCRIPT, "math-subscript", Noop }, Index: src/mathed/math_nestinset.C =================================================================== --- src/mathed/math_nestinset.C (Revision 13786) +++ src/mathed/math_nestinset.C (Arbeitskopie) @@ -848,7 +848,6 @@ void MathNestInset::doDispatch(LCursor & } case LFUN_MATH_DELIM: { - lyxerr << "MathNestInset::LFUN_MATH_DELIM" << endl; string ls; string rs = lyx::support::split(cmd.argument, ls, ' '); // Reasonable default values @@ -857,9 +856,34 @@ void MathNestInset::doDispatch(LCursor & if (rs.empty()) rs = ')'; recordUndo(cur, Undo::ATOMIC); - // Don't do this with multi-cell selections - if (cur.selBegin().idx() == cur.selEnd().idx()) - cur.handleNest(MathAtom(new MathDelimInset(ls, rs))); + cur.handleNest(MathAtom(new MathDelimInset(ls, rs))); + break; + } + + case LFUN_MATH_BIGDELIM: { + string const lname = cmd.getArg(0); + string const ldelim = cmd.getArg(1); + string const rname = cmd.getArg(2); + string const rdelim = cmd.getArg(3); + latexkeys const * l = in_word_set(lname); + if (l && l->inset == "big" && + MathBigInset::isBigInsetDelim(ldelim)) { + // Simply replace the selection by the delimiter if + // we have only one. Insert the delimiters around the + // selection otherwise. + recordUndo(cur, Undo::ATOMIC); + string const selection = grabAndEraseSelection(cur); + selClearOrDel(cur); + cur.insert(MathAtom(new MathBigInset(lname, ldelim))); + latexkeys const * l = in_word_set(rname); + if (l && l->inset == "big" && + MathBigInset::isBigInsetDelim(rdelim)) + cur.niceInsert(selection); + cur.insert(MathAtom(new MathBigInset(rname, + rdelim))); + } + // Don't call cur.undispatched() if we did nothing, this would + // lead to infinite recursion via LyXText::dispatch(). break; } @@ -917,7 +941,7 @@ void MathNestInset::doDispatch(LCursor & } -bool MathNestInset::getStatus(LCursor & /*cur*/, FuncRequest const & cmd, +bool MathNestInset::getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { // the font related toggles @@ -993,6 +1017,13 @@ bool MathNestInset::getStatus(LCursor & case LFUN_INSERT_MATRIX: flag.enabled(currentMode() == MATH_MODE); break; + + case LFUN_MATH_DELIM: + case LFUN_MATH_BIGDELIM: + // Don't do this with multi-cell selections + flag.enabled(cur.selBegin().idx() == cur.selEnd().idx()); + break; + default: ret = false; break; Index: src/frontends/gtk/GMathDelim.C =================================================================== --- src/frontends/gtk/GMathDelim.C (Revision 13785) +++ src/frontends/gtk/GMathDelim.C (Arbeitskopie) @@ -36,6 +36,8 @@ using std::string; namespace lyx { namespace frontend { +// FIXME: Implement fixed size delimiters (see qt3 frontend) + namespace { Index: src/frontends/qt3/QDelimiterDialog.C =================================================================== --- src/frontends/qt3/QDelimiterDialog.C (Revision 13785) +++ src/frontends/qt3/QDelimiterDialog.C (Arbeitskopie) @@ -18,9 +18,14 @@ #include "controllers/ControlMath.h" +#include "gettext.h" + #include <qlabel.h> #include <qpixmap.h> #include <qcheckbox.h> +#include <qcombobox.h> + +#include <sstream> using std::string; @@ -38,6 +43,12 @@ char const * delim[] = { }; +char const * const bigleft[] = {"bigl", "Bigl", "biggl", "Biggl", ""}; +char const * const bigright[] = {"bigr", "Bigr", "biggr", "Biggr", ""}; +char const * const biggui[] = {N_("big size"), N_("Big size"), + N_("bigg size"), N_("Bigg size"), ""}; + + string do_match(const string & str) { if (str == "(") return ")"; @@ -59,7 +70,7 @@ string do_match(const string & str) } -string fix_name(const string & str) +string fix_name(const string & str, bool big) { if (str == "slash") return "/"; @@ -67,7 +78,10 @@ string fix_name(const string & str) return "\\"; if (str == "empty") return "."; - return str; + if (!big || str == "(" || str == ")" || str == "[" || str == "]") + return str; + + return "\\" + str; } } // namespace anon @@ -89,11 +103,17 @@ QDelimiterDialog::QDelimiterDialog(QMath leftIP->add(QPixmap(toqstr(empty_xpm)), "empty", "empty"); rightIP->add(QPixmap(toqstr(empty_xpm)), "empty", "empty"); + delimSize->insertItem(qt_("Variable size")); + for (int i = 0; *biggui[i]; ++i) + delimSize->insertItem(qt_(biggui[i])); + size_ = 0; // Leave these std:: qualifications alone ! connect(leftIP, SIGNAL(button_clicked(const std::string &)), this, SLOT(ldelim_clicked(const std::string &))); connect(rightIP, SIGNAL(button_clicked(const std::string &)), this, SLOT(rdelim_clicked(const std::string &))); + connect(delimSize, SIGNAL(activated(int)), + this, SLOT(size_selected(int)) ); ldelim_clicked("("); rdelim_clicked(")"); } @@ -101,7 +121,16 @@ QDelimiterDialog::QDelimiterDialog(QMath void QDelimiterDialog::insertClicked() { - form_->controller().dispatchDelim(fix_name(left_) + ' ' + fix_name(right_)); + if (size_ == 0) { + form_->controller().dispatchDelim( + fix_name(left_, false) + ' ' + + fix_name(right_, false)); + } else { + std::ostringstream os; + os << bigleft[size_ - 1] << ' ' << fix_name(left_, true) << ' ' + << bigright[size_ - 1] << ' ' << fix_name(right_, true); + form_->controller().dispatchBigDelim(os.str()); + } } @@ -137,5 +166,11 @@ void QDelimiterDialog::rdelim_clicked(co } } + +void QDelimiterDialog::size_selected(int index) +{ + size_ = index; +} + } // namespace frontend } // namespace lyx Index: src/frontends/qt3/QDelimiterDialog.h =================================================================== --- src/frontends/qt3/QDelimiterDialog.h (Revision 13785) +++ src/frontends/qt3/QDelimiterDialog.h (Arbeitskopie) @@ -30,6 +30,7 @@ public: public slots: void ldelim_clicked(const std::string & str); void rdelim_clicked(const std::string & str); + void size_selected(int); void insertClicked(); protected: //needed ? virtual void closeEvent(QCloseEvent * e); @@ -42,6 +43,9 @@ private: /// symbol of right delimiter std::string right_; + /// size of delimiters + int size_; + /// owning form QMathDelimiter * form_; }; Index: src/frontends/qt3/ui/QDelimiterDialogBase.ui =================================================================== --- src/frontends/qt3/ui/QDelimiterDialogBase.ui (Revision 13787) +++ src/frontends/qt3/ui/QDelimiterDialogBase.ui (Arbeitskopie) @@ -307,6 +307,22 @@ </size> </property> </spacer> + <widget class="QComboBox"> + <property name="name"> + <cstring>delimSize</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="toolTip" stdset="0"> + <string>Choose delimiter size</string> + </property> + </widget> </hbox> </widget> <widget class="QLayoutWidget"> Index: src/frontends/qt4/QDelimiterDialog.C =================================================================== --- src/frontends/qt4/QDelimiterDialog.C (Revision 13785) +++ src/frontends/qt4/QDelimiterDialog.C (Arbeitskopie) @@ -28,6 +28,8 @@ using std::string; namespace lyx { namespace frontend { +// FIXME: Implement fixed size delimiters (see qt3 frontend) + namespace { char const * delim[] = { Index: src/frontends/xforms/FormMathsDelim.C =================================================================== --- src/frontends/xforms/FormMathsDelim.C (Revision 13785) +++ src/frontends/xforms/FormMathsDelim.C (Arbeitskopie) @@ -33,6 +33,8 @@ using std::ostringstream; namespace lyx { namespace frontend { +// FIXME: Implement fixed size delimiters (see qt3 frontend) + namespace { int const delim_rversion[] = { Index: src/frontends/controllers/ControlMath.h =================================================================== --- src/frontends/controllers/ControlMath.h (Revision 13785) +++ src/frontends/controllers/ControlMath.h (Arbeitskopie) @@ -43,9 +43,11 @@ public: void dispatchCubeRoot() const; /// Insert a matrix void dispatchMatrix(std::string const & str) const; - /// Insert a delimiter + /// Insert a variable size delimiter void dispatchDelim(std::string const & str) const; - /// Wwitch between display and inline + /// Insert a big delimiter + void dispatchBigDelim(std::string const & str) const; + /// Switch between display and inline void dispatchToggleDisplay() const; /** A request to the kernel to launch a dialog. * \param name the dialog identifier. Index: src/frontends/controllers/ControlMath.C =================================================================== --- src/frontends/controllers/ControlMath.C (Revision 13785) +++ src/frontends/controllers/ControlMath.C (Arbeitskopie) @@ -79,6 +79,12 @@ void ControlMath::dispatchDelim(string c } +void ControlMath::dispatchBigDelim(string const & str) const +{ + dispatchFunc(LFUN_MATH_BIGDELIM, str); +} + + void ControlMath::dispatchToggleDisplay() const { dispatchFunc(LFUN_MATH_DISPLAY); Index: src/text3.C =================================================================== --- src/text3.C (Revision 13785) +++ src/text3.C (Arbeitskopie) @@ -1311,7 +1311,8 @@ void LyXText::dispatch(LCursor & cur, Fu case LFUN_INSERT_MATH: case LFUN_INSERT_MATRIX: - case LFUN_MATH_DELIM: { + case LFUN_MATH_DELIM: + case LFUN_MATH_BIGDELIM: { cur.insert(new MathHullInset("simple")); cur.dispatch(FuncRequest(LFUN_RIGHT)); cur.dispatch(cmd); @@ -1878,6 +1879,7 @@ bool LyXText::getStatus(LCursor & cur, F case LFUN_INSERT_MATH: case LFUN_INSERT_MATRIX: case LFUN_MATH_DELIM: + case LFUN_MATH_BIGDELIM: case LFUN_SUBSCRIPT: case LFUN_SUPERSCRIPT: case LFUN_DEFAULT: Index: src/lfuns.h =================================================================== --- src/lfuns.h (Revision 13785) +++ src/lfuns.h (Arbeitskopie) @@ -362,10 +362,11 @@ enum kb_action { LFUN_OUTLINE_DOWN, LFUN_OUTLINE_IN, LFUN_OUTLINE_OUT, - // 275 LFUN_PARAGRAPH_MOVE_DOWN, // Edwin 20060408 LFUN_PARAGRAPH_MOVE_UP, // Edwin 20060408 + // 280 LFUN_TOGGLE_COMPRESSION, // bpeng 20060427 + LFUN_MATH_BIGDELIM, LFUN_LASTACTION // end of the table }; Index: src/ToolbarBackend.C =================================================================== --- src/ToolbarBackend.C (Revision 13785) +++ src/ToolbarBackend.C (Arbeitskopie) @@ -217,12 +217,16 @@ string const ToolbarBackend::getIcon(Fun string fullname; - if (f.action == LFUN_INSERT_MATH) { + switch (f.action) { + case LFUN_INSERT_MATH: if (!f.argument.empty()) fullname = find_xpm(f.argument.substr(1)); - } else if (f.action == LFUN_MATH_DELIM) { + break; + case LFUN_MATH_DELIM: + case LFUN_MATH_BIGDELIM: fullname = find_xpm(f.argument); - } else { + break; + default: string const name = lyxaction.getActionName(f.action); string xpm_name(name);