On Sun, Apr 02, 2006 at 08:54:46PM +0300, Martin Vermeer wrote:
> See patch. No GUI support for now.

Here is a new patch, using enum, and having GUI support. Wasn't so much
work after all.

Please give this some testing.

- Martin

Index: LaTeXFeatures.C
===================================================================
--- LaTeXFeatures.C     (revision 13546)
+++ LaTeXFeatures.C     (working copy)
@@ -242,6 +242,7 @@ char const * simplefeatures[] = {
        "dvipost",
        "fancybox",
        "calc",
+       "nicefrac",
 };
 
 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
Index: mathed/math_factory.C
===================================================================
--- mathed/math_factory.C       (revision 13546)
+++ mathed/math_factory.C       (working copy)
@@ -317,10 +317,12 @@ MathAtom createMathInset(string const & 
                return MathAtom(new MathBinomInset(s == "choose"));
        if (s == "over" || s == "frac")
                return MathAtom(new MathFracInset);
+       if (s == "nicefrac")
+               return MathAtom(new MathFracInset(MathFracInset::NICEFRAC));
        //if (s == "infer")
        //      return MathAtom(new MathInferInset);
        if (s == "atop")
-               return MathAtom(new MathFracInset(true));
+               return MathAtom(new MathFracInset(MathFracInset::ATOP));
        if (s == "lefteqn")
                return MathAtom(new MathLefteqnInset);
        if (s == "boldsymbol")
Index: mathed/math_fracinset.C
===================================================================
--- mathed/math_fracinset.C     (revision 13546)
+++ mathed/math_fracinset.C     (working copy)
@@ -15,6 +15,7 @@
 #include "math_data.h"
 #include "math_mathmlstream.h"
 #include "textpainter.h"
+#include "LaTeXFeatures.h"
 #include "LColor.h"
 #include "frontends/Painter.h"
 
@@ -24,8 +25,8 @@ using std::max;
 using std::auto_ptr;
 
 
-MathFracInset::MathFracInset(bool atop)
-       : atop_(atop)
+MathFracInset::MathFracInset(Kind kind)
+       : kind_(kind)
 {}
 
 
@@ -37,13 +38,13 @@ auto_ptr<InsetBase> MathFracInset::doClo
 
 MathFracInset * MathFracInset::asFracInset()
 {
-       return atop_ ? 0 : this;
+       return kind_ == ATOP ? 0 : this;
 }
 
 
 MathFracInset const * MathFracInset::asFracInset() const
 {
-       return atop_ ? 0 : this;
+       return kind_ == ATOP ? 0 : this;
 }
 
 
@@ -52,9 +53,15 @@ void MathFracInset::metrics(MetricsInfo 
        FracChanger dummy(mi.base);
        cell(0).metrics(mi);
        cell(1).metrics(mi);
-       dim.wid = max(cell(0).width(), cell(1).width()) + 2;
-       dim.asc = cell(0).height() + 2 + 5;
-       dim.des = cell(1).height() + 2 - 5;
+       if (kind_ == NICEFRAC) {
+               dim.wid =  cell(0).width() + cell(1).width() + 5;
+               dim.asc = cell(0).height() + 5;
+               dim.des = cell(1).height() - 5;
+       } else {
+               dim.wid = max(cell(0).width(), cell(1).width()) + 2;
+               dim.asc = cell(0).height() + 2 + 5;
+               dim.des = cell(1).height() + 2 - 5;
+       }
        metricsMarkers(dim);
        dim_ = dim;
 }
@@ -65,10 +72,25 @@ void MathFracInset::draw(PainterInfo & p
        setPosCache(pi, x, y);
        int m = x + dim_.wid / 2;
        FracChanger dummy(pi.base);
-       cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 
5);
-       cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 2 - 
5);
-       if (!atop_)
-               pi.pain.line(x + 1, y - 5, x + dim_.wid - 2, y - 5, 
LColor::math);
+       if (kind_ == NICEFRAC) {
+               cell(0).draw(pi, x + 2, 
+                               y - cell(0).descent() - 5);
+               cell(1).draw(pi, x + cell(0).width() + 5,
+                               y + cell(1).ascent() / 2);
+       } else {
+               cell(0).draw(pi, m - cell(0).width() / 2, 
+                               y - cell(0).descent() - 2 - 5);
+               cell(1).draw(pi, m - cell(1).width() / 2,
+                               y + cell(1).ascent()  + 2 - 5);
+       }
+       if (kind_ == NICEFRAC)
+               pi.pain.line(x + cell(0).width(), 
+                               y + dim_.des - 2, 
+                               x + cell(0).width() + 5, 
+                               y - dim_.asc + 2, LColor::math);
+       if (kind_ == FRAC)
+               pi.pain.line(x + 1, y - 5, 
+                               x + dim_.wid - 2, y - 5, LColor::math);
        drawMarkers(pi, x, y);
 }
 
@@ -89,14 +111,15 @@ void MathFracInset::drawT(TextPainter & 
        int m = x + dim_.width() / 2;
        cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
        cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
-       if (!atop_)
+       if (kind_ == FRAC)
                pain.horizontalLine(x, y, dim_.width());
+       // what for NICEFRAC?
 }
 
 
 void MathFracInset::write(WriteStream & os) const
 {
-       if (atop_)
+       if (kind_ == ATOP)
                os << '{' << cell(0) << "\\atop " << cell(1) << '}';
        else // it's \\frac
                MathNestInset::write(os);
@@ -105,7 +128,16 @@ void MathFracInset::write(WriteStream & 
 
 string MathFracInset::name() const
 {
-       return atop_ ? "atop" : "frac";
+       switch (kind_) {
+       case FRAC:
+               return "frac";
+       case NICEFRAC:
+               return "nicefrac";
+       case ATOP:
+               return "atop";
+       default:
+               return string();
+       }
 }
 
 
@@ -131,3 +163,12 @@ void MathFracInset::mathmlize(MathMLStre
 {
        os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac");
 }
+
+
+void MathFracInset::validate(LaTeXFeatures & features) const
+{
+       if (kind_ == NICEFRAC)
+               features.require("nicefrac");
+       MathNestInset::validate(features);
+}
+
Index: mathed/math_dfracinset.C
===================================================================
--- mathed/math_dfracinset.C    (revision 13546)
+++ mathed/math_dfracinset.C    (working copy)
@@ -24,7 +24,7 @@ using std::auto_ptr;
 
 
 MathDfracInset::MathDfracInset()
-       : MathFracInset(false)
+       : MathFracInset()
 {}
 
 
Index: mathed/math_tfracinset.C
===================================================================
--- mathed/math_tfracinset.C    (revision 13546)
+++ mathed/math_tfracinset.C    (working copy)
@@ -27,7 +27,7 @@ using std::auto_ptr;
 
 
 MathTfracInset::MathTfracInset()
-       : MathFracInset(false)
+       : MathFracInset()
 {}
 
 
Index: mathed/math_fracinset.h
===================================================================
--- mathed/math_fracinset.h     (revision 13546)
+++ mathed/math_fracinset.h     (working copy)
@@ -20,7 +20,14 @@
 class MathFracInset : public MathFracbaseInset {
 public:
        ///
-       explicit MathFracInset(bool atop = false);
+       enum Kind {
+               FRAC,
+               ATOP,
+               NICEFRAC
+       };
+
+       ///
+       explicit MathFracInset(Kind kind = FRAC);
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
@@ -46,10 +53,12 @@ public:
        void octave(OctaveStream &) const;
        ///
        void mathmlize(MathMLStream &) const;
+       ///
+       void validate(LaTeXFeatures & features) const;
 public:
        virtual std::auto_ptr<InsetBase> doClone() const;
        ///
-       bool const atop_;
+       Kind kind_;
 };
 
 #endif
Index: frontends/qt2/ui/QMathDialogBase.ui
===================================================================
--- frontends/qt2/ui/QMathDialogBase.ui (revision 13546)
+++ frontends/qt2/ui/QMathDialogBase.ui (working copy)
@@ -814,12 +814,6 @@
         <slot>accept()</slot>
     </connection>
     <connection>
-        <sender>fracPB</sender>
-        <signal>clicked()</signal>
-        <receiver>QMathDialogBase</receiver>
-        <slot>fracClicked()</slot>
-    </connection>
-    <connection>
         <sender>superscriptPB</sender>
         <signal>clicked()</signal>
         <receiver>QMathDialogBase</receiver>
Index: frontends/qt2/QMathDialog.C
===================================================================
--- frontends/qt2/QMathDialog.C (revision 13546)
+++ frontends/qt2/QMathDialog.C (working copy)
@@ -124,6 +124,18 @@ QMathDialog::QMathDialog(QMath * form)
        connect(m, SIGNAL(activated(int)), this, SLOT(insertRoot(int)));
        sqrtPB->setPopup(m);
 
+       m = new QPopupMenu(fracPB);
+       m->setCaption(qt_("LyX: Fractions"));
+       m->insertTearOffHandle();
+       m->insertItem(qt_("Standard     \\frac"), 1);
+       m->insertItem(qt_("No hor. line \\atop"), 2);
+       m->insertItem(qt_("Nice \\nicefrac"), 3);
+       m->insertItem(qt_("Text frac (amsmath)  \\tfrac"), 4);
+       m->insertItem(qt_("Display frac (amsmath)       \\dfrac"), 5);
+       m->insertItem(qt_("Binomial     \\choose"), 6);
+       connect(m, SIGNAL(activated(int)), this, SLOT(fracClicked(int)));
+       fracPB->setPopup(m);
+
        m = new QPopupMenu(stylePB);
        m->setCaption(qt_("LyX: Math Styles"));
        m->insertTearOffHandle();
@@ -191,9 +203,19 @@ void QMathDialog::symbol_clicked(const s
 }
 
 
-void QMathDialog::fracClicked()
+void QMathDialog::fracClicked(int id)
 {
-       form_->controller().dispatchInsert("frac");
+       string str;
+       switch (id) {
+               case 1: str = "frac"; break;
+               case 2: str = "atop"; break;
+               case 3: str = "nicefrac"; break;
+               case 4: str = "tfrac"; break;
+               case 5: str = "dfrac"; break;
+               case 6: str = "choose"; break;
+               default: return;
+       }
+       form_->controller().dispatchInsert(str);
 }
 
 
Index: frontends/qt2/QMathDialog.h
===================================================================
--- frontends/qt2/QMathDialog.h (revision 13546)
+++ frontends/qt2/QMathDialog.h (working copy)
@@ -30,7 +30,7 @@ public:
 public slots:
        virtual void delimiterClicked();
        virtual void expandClicked();
-       virtual void fracClicked();
+       virtual void fracClicked(int);
        virtual void functionSelected(const QString &);
        virtual void matrixClicked();
        virtual void subscriptClicked();

Attachment: pgpoYO0k8afF6.pgp
Description: PGP signature

Reply via email to