On Mon, May 01, 2006 at 03:08:06PM +0200, Georg Baum wrote:

> Am Donnerstag, 27. April 2006 14:12 schrieb Enrico Forestieri:

> > 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.

I remember that designer won't let me adding the combobox without
breaking the layout containing the checkbox "Keep matched", so I broke
it, added the combobox and restored it. But clearly I did something
wrong.

> > 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.

It works well.

> 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.

There is a small problem with the "\" delimiter as it isn't recognized.
Please find attached an updated patch fixing that. The problem with "\"
is also in 1.4. I attach a patch for this, too.

-- 
Enrico
Index: src/LyXAction.C
===================================================================
--- src/LyXAction.C     (revision 13787)
+++ src/LyXAction.C     (working copy)
@@ -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 13787)
+++ src/mathed/math_nestinset.C (working copy)
@@ -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 13787)
+++ src/frontends/gtk/GMathDelim.C      (working copy)
@@ -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 13787)
+++ src/frontends/qt3/QDelimiterDialog.C        (working copy)
@@ -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,15 +70,16 @@ string do_match(const string & str)
 }
 
 
-string fix_name(const string & str)
+string fix_name(const string & str, bool big)
 {
        if (str == "slash")
                return "/";
-       if (str == "backslash")
-               return "\\";
        if (str == "empty")
                return ".";
-       return str;
+       if (!big || str == "(" || str == ")" || str == "[" || str == "]")
+               return str;
+
+       return "\\" + str;
 }
 
 } // namespace anon
@@ -89,11 +101,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 +119,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());
+       }
 }
 
 
@@ -135,6 +162,12 @@ void QDelimiterDialog::rdelim_clicked(co
                left_ = do_match(right_);
                set_label(leftPI, left_);
        }
+}
+
+
+void QDelimiterDialog::size_selected(int index)
+{
+       size_ = index;
 }
 
 } // namespace frontend
Index: src/frontends/qt3/QDelimiterDialog.h
===================================================================
--- src/frontends/qt3/QDelimiterDialog.h        (revision 13787)
+++ src/frontends/qt3/QDelimiterDialog.h        (working copy)
@@ -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);
@@ -41,6 +42,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        (working copy)
@@ -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 13787)
+++ src/frontends/qt4/QDelimiterDialog.C        (working copy)
@@ -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 13787)
+++ src/frontends/xforms/FormMathsDelim.C       (working copy)
@@ -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 13787)
+++ src/frontends/controllers/ControlMath.h     (working copy)
@@ -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 13787)
+++ src/frontends/controllers/ControlMath.C     (working copy)
@@ -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 13787)
+++ src/text3.C (working copy)
@@ -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 13787)
+++ src/lfuns.h (working copy)
@@ -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 13787)
+++ src/ToolbarBackend.C        (working copy)
@@ -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);
 
Index: src/frontends/qt2/QDelimiterDialog.C
===================================================================
--- src/frontends/qt2/QDelimiterDialog.C        (revision 13787)
+++ src/frontends/qt2/QDelimiterDialog.C        (working copy)
@@ -63,8 +63,6 @@ string fix_name(const string & str)
 {
        if (str == "slash")
                return "/";
-       if (str == "backslash")
-               return "\\";
        if (str == "empty")
                return ".";
        return str;

Reply via email to