/***************************************************************************
                          parabolas.cpp  -  description
                             -------------------
    begin                : Sam Mai 4 2002
    copyright            : (C) 2002 by Birgit Schulz
    email                : B.Schulz@Superlehrer.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <math.h>
#include <knuminput.h>
#include <krestrictedline.h>
#include <kpushbutton.h>
#include <ktextbrowser.h>
#include <klocale.h>
#include <kapplication.h>

#include <qlabel.h>
#include <qstring.h>
#include <qlayout.h>
#include <qcheckbox.h>
//Added by qt3to4:
#include <QPaintEvent>
#include <Q3VBoxLayout>

#include <parabolas.h>

#include <../kplotwidget.h>


Parabolas::Parabolas(QWidget *parent, const char *name ) : ParabolasD(parent,name)
{
    TextLabelInformation->setText(i18n("Choose a function from the Icons below"));


    QWidget *viewPlot = new QWidget ( PlotFrame, 0);

    Q3VBoxLayout *vlay1 = new Q3VBoxLayout( viewPlot, 0, -1 );

    pi = new ParabolaInputD();

    pw = new KPlotWidget( -100.0, 100.0, -100.0, 100.0, viewPlot);

    pw->setShowAxes( false );
    pw->setShowTickMarks( false );
    pw->setCartesian ( true );
    pw->setBGColor( QColor( "black" ) );
    pw->setFGColor( QColor ( "white") );

    pw->setShowCartAxis( true );
    pw->setShowDegreeCircle( false );
    pw->setShowCartTickMarks( true );
    pw->setShowCartTickLabels( true );

    vlay1->addWidget( pw );

    viewPlot->resize( 400, 400 );

    connect( pi->parabola_mx, SIGNAL(valueChanged( int )), SLOT( slotUpdateParabolas()) );
    connect( pi->parabola_mx, SIGNAL(valueChanged( int )), SLOT( slotCalculate()) );
    connect( pi->parabola_bx, SIGNAL(valueChanged( int )), SLOT( slotUpdateParabolas()) );
    connect( pi->parabola_bx, SIGNAL(valueChanged( int )), SLOT( slotCalculate()) );
    connect( pi->parabola_c, SIGNAL(valueChanged( int )), SLOT( slotUpdateParabolas()) );
    connect( pi->parabola_c, SIGNAL(valueChanged( int )), SLOT( slotCalculate()) );
    connect( pi->parabola2_mx, SIGNAL(valueChanged( int )), SLOT( slotUpdateParabolas()) );
    connect( pi->parabola2_mx, SIGNAL(valueChanged( int )), SLOT( slotCalculate()) );
    connect( pi->parabola2_bx, SIGNAL(valueChanged( int )), SLOT( slotUpdateParabolas()) );
    connect( pi->parabola2_bx, SIGNAL(valueChanged( int )), SLOT( slotCalculate()) );
    connect( pi->parabola2_c, SIGNAL(valueChanged( int )), SLOT( slotUpdateParabolas()) );
    connect( pi->parabola2_c, SIGNAL(valueChanged( int )), SLOT( slotCalculate()) );

    connect( pi->Line_mx, SIGNAL(valueChanged( int )), SLOT( slotUpdateParabolas()) );
    connect( pi->Line_mx, SIGNAL(valueChanged( int )), SLOT( slotCalculate()) );
    connect( pi->Line_c, SIGNAL(valueChanged( int )), SLOT( slotUpdateParabolas()) );
    connect( pi->Line_c, SIGNAL(valueChanged( int )), SLOT( slotCalculate()) );

    connect( pi->Point1_x, SIGNAL(valueChanged( int )), SLOT( slotUpdateParabolas()) );
    connect( pi->Point1_x, SIGNAL(valueChanged( int )), SLOT( slotCalculate()) );
    connect( pi->Point1_y, SIGNAL(valueChanged( int )), SLOT( slotUpdateParabolas()) );
    connect( pi->Point1_y, SIGNAL(valueChanged( int )), SLOT( slotCalculate()) );

    connect( pi->Point2_x, SIGNAL(valueChanged( int )), SLOT( slotUpdateParabolas()) );
    connect( pi->Point2_x, SIGNAL(valueChanged( int )), SLOT( slotCalculate()) );
    connect( pi->Point2_y, SIGNAL(valueChanged( int )), SLOT( slotUpdateParabolas()) );
    connect( pi->Point2_y, SIGNAL(valueChanged( int )), SLOT( slotCalculate()) );

    connect( pi->Point3_x, SIGNAL(valueChanged( int )), SLOT( slotUpdateParabolas()) );
    connect( pi->Point3_x, SIGNAL(valueChanged( int )), SLOT( slotCalculate()) );
    connect( pi->Point3_y, SIGNAL(valueChanged( int )), SLOT( slotUpdateParabolas()) );
    connect( pi->Point3_y, SIGNAL(valueChanged( int )), SLOT( slotCalculate()) );

    p3_a = 0.0;
    p3_b = 0.0;
    p3_c = 0.0;

    pi->Point1_x->hide();
    pi->Point1_y->hide();
    pi->Point2_x->hide();
    pi->Point2_y->hide();
    pi->Point3_x->hide();
    pi->Point3_y->hide();
    pi->Line_mx->hide();
    pi->Line_c->hide();
    pi->parabola_mx->hide();
    pi->parabola_bx->hide();
    pi->parabola_c->hide();
    pi->parabola2_mx->hide();
    pi->parabola2_bx->hide();
    pi->parabola2_c->hide();

    pi->point1->hide();
    pi->textLabel3->hide();
    pi->textLabel2->hide();
    pi->pointformat1->hide();
    pi->point2->hide();
    pi->textLabel3_2->hide();
    pi->textLabel2_2->hide();
    pi->pointformat2->hide();
    pi->point3->hide();
    pi->textLabel3_2_2->hide();
    pi->textLabel2_3->hide();
    pi->pointformat3->hide();
    pi->lineEquation->hide();
    pi->textLabel6->hide();
    pi->lineFormat->hide();
    pi->parabolaEquation1->hide();
    pi->x1->hide();
    pi->X1->hide();
    pi->parabolaEquation2->hide();
    pi->x2->hide();
    pi->X2->hide();

    initObjects();
}

Parabolas::~Parabolas()
{}

void Parabolas::paintEvent( QPaintEvent* )
{
    pw->update();
}

void Parabolas::initObjects()
{
    double a = 0.0;
    double b = 0.0;
    double c = 0.0;

    KPlotObject *parabola_one;
    KPlotObject *parabola_two;

    KPlotObject *line_one;

    KPlotObject *point3parab;

    parabola_one = new KPlotObject( "1", "red", KPlotObject::CURVE, 1, KPlotObject::SOLID );

    for( double x = -99.0; x < 99.0; x=x+1.0 )
    {
        DPoint *p = new DPoint( x,  a*x*x + b*x + c ); //sets both X and Y coords
        parabola_one->addPoint( p );
    }
    pw->addObject( parabola_one );

    parabola_two = new KPlotObject( "2", "green", KPlotObject::CURVE, 1, KPlotObject::SOLID );

    for( double x = -99.0; x < 99.0; x=x+1.0 )
    {
        DPoint *p = new DPoint( x,  a*x*x + b*x + c ); //sets both X and Y coords
        parabola_two->addPoint( p );
    }
    pw->addObject( parabola_two );

    line_one = new KPlotObject( "3", "blue", KPlotObject::POLYGON, 1, KPlotObject::SOLID );
    line_one->addPoint( new DPoint( -20.0, 0.0 ) );
    line_one->addPoint( new DPoint( 20.0, 0.0 ) );

    pw->addObject( line_one );

    point3parab = new KPlotObject( "4", "yellow", KPlotObject::CURVE, 1, KPlotObject::SOLID );

    for( double x = -99.0; x < 99.0; x=x+1.0 )
    {
        DPoint *p = new DPoint( x,  a*x*x + b*x + c ); //sets both X and Y coords
        point3parab->addPoint( p );
    }
    pw->addObject( point3parab );

}

void Parabolas::slotUpdateParabolas()
{
    KPlotObject *parab1 = pw->object( 0 );              //Parabolas one
    double a = pi->parabola_mx->value();
    double b = pi->parabola_bx->value();
    double c = pi->parabola_c->value();

    DPoint *pp1 = new DPoint();
    for ( pp1 = parab1->points()->first(); pp1; pp1 = parab1->points()->next() )
    {
        //No need to change X values, they just go from -99. to +99.
        pp1->setY( a*(pp1->x())*(pp1->x()) + b*(pp1->x()) + c );
    }

    KPlotObject *parab2 = pw->object( 1 );              //Parabolas two
    double a2 = pi->parabola2_mx->value();
    double b2 = pi->parabola2_bx->value();
    double c2 = pi->parabola2_c->value();

    DPoint *pp2 = new DPoint();
    for ( pp2 = parab2->points()->first(); pp2; pp2 = parab2->points()->next() )
    {
        //No need to change X values, they just go from -99. to +99.
        pp2->setY( a2*(pp2->x())*(pp2->x()) + b2*(pp2->x()) + c2 );
    }

    KPlotObject *line_one = pw->object( 2 );
    double m = pi->Line_mx->value();
    double cl = pi->Line_c->value();

    DPoint *p = new DPoint();
    for ( p = line_one->points()->first(); p; p = line_one->points()->next() )
    {
        p->setY( m*(p->x()) + cl );
    }

    KPlotObject *point3parab = pw->object( 3 );              //3 point Parabolas
    double pa = p3_a;
    double pb = p3_b;
    double pc = p3_c;

    DPoint *p3 = new DPoint();
    for ( p3 = point3parab->points()->first(); p3; p3 = point3parab->points()->next() )
    {
        //No need to change X values, they just go from -99. to +99.
        p3->setY( pa*(p3->x())*(p3->x()) + pb*(p3->x()) + pc );
    }

    if ( showAxis->isChecked() )
    {
        pw->setShowCartAxis( true );
    }
    else
    {
        pw->setShowCartAxis( false );
    }

    if ( showTickMarks->isChecked() )
    {
        pw->setShowCartTickMarks( true );
        showTickLabels->setEnabled ( true );
    }
    else
    {
        pw->setShowCartTickMarks( false );
        showTickLabels->setEnabled ( false );
    }

    if ( showTickLabels->isChecked() )
    {
        pw->setShowCartTickLabels( true );
    }
    else
    {
        pw->setShowCartTickLabels( false );
    }

    update();
}

void Parabolas::slotCalculate()
{
    switch (m_eSelected)
    {
    case TurnPoint: //Find the turnPoint of the given parabola
        {
            double a, b, c;
            QString qsResult, qsYs, qsXs;

            a = pi->parabola_mx->value();
            b = pi->parabola_bx->value();
            c = pi->parabola_c->value();

            if (a == 0)
            {
                qsResult = i18n("The given equation is <b>not the equation of a parabola</b>, so the vertex cannot be found");

            }
            else
            {
                qsXs = " ";
                qsYs = " ";
                double xs = b / (-2.0*a);
                double ys = c-b*b/(4.0*a);
                qsXs = qsXs.number(xs);
                qsYs = qsYs.number(ys);
                qsResult = i18n("The vertex of the given parabola is <b>S(%1|%2)</b>.").arg(qsXs).arg(qsYs);
            }
            KTextBrowserResult->setText(qsResult);

            break;
        }

    case AxisSection: //Find the X and Y axis cuts from parabola equation
        {
            double a, b, c;
            QString qsResult, qsYs, qsX1s, qsX2s, qsC;

            a = pi->parabola_mx->value();
            b = pi->parabola_bx->value();
            c = pi->parabola_c->value();

            if (a == 0)
            {
                qsResult = i18n("The given equation is <b>not the equation of a parabola</b>, so the TurnPoint cannot be found");
            }
            else
            {
                double d = b*b / (4 * a*a) - c / a; //this might be d = c/a-b*b/(4*a*a)
                if (d > 0)
                {
                    double xs1 = b / (-2*a) + sqrt(d);
                    double xs2 = b / (-2*a) - sqrt(d);
                    qsX1s = qsX1s.number(xs1);
                    qsX2s = qsX2s.number(xs2);
                    qsC = qsC.number(c);
                    qsResult = i18n("The given parabola has the <font color = red><b>two</b></font> intersection-points with the x-axis<br>"
                                    "<b>Sx<sub>1</sub>( %1 | 0 )</b> and <b>Sx<sub>1</sub>( %2 | 0 )</b> "
                                    "and with the y-axis the intersection-point <b>Sy( 0 | %3 )</b>.").arg(qsX1s).arg(qsX2s).arg(qsC);
                }
                else
                {
                    if (d == 0)
                    {
                        double xs1 = b / (-2*a);
                        qsX1s = qsX1s.number(xs1);
                        qsC = qsC.number(c);
                        qsResult = i18n("The given parabola has only <font color = red><b>one</b></font> intersection-point with the x-axis<br>"
                                        "<b>Sx( %1 | 0 )</b> and with the y-axis the intersection-point<br> <b>Sy( 0 | %2 )</b>.").arg(qsX1s).arg(qsC);

                    }
                    else
                    {
                        qsC = qsC.number(c);
                        qsResult = "The given parabola has <font color = red><b>no</b></font> intersection-point with the x-axis<br>";
                        if (a > 0)
                        {
                            qsResult += "because it is completely over the x-axis.<br>";
                        }
                        else
                        {
                            qsResult += "because it is completely under the x-axis.<br>";
                        }

                        qsResult += "The intersection-point with the y-axis the intersection-point<br> <b>Sy( 0 |" + qsC+" )</b>.";
                    }
                }
            }
            KTextBrowserResult->setText(qsResult);
            break;
        }


    case ThreePoints: //Find equation of parabola with three given points
        {
            double x1,x2,x3,y1,y2,y3, Det, Deta, Detb, Detc, a, b, c;
            QString qsResult, qsA, qsB, qsC, qsEquation;

            x1 = pi->Point1_x->value();
            y1 = pi->Point1_y->value();
            x2 = pi->Point2_x->value();
            y2 = pi->Point2_y->value();
            x3 = pi->Point3_x->value();
            y3 = pi->Point3_y->value();

            Det = Determinant(x1*x1,x1, 1,x2*x2,x2,1,x3*x3,x3,1);
            if (Det == 0)
            {
                qsResult = i18n("<b>The function determined by the three given points <font color = red>is not a parabola.</font></b>");
            }
            else
            {
                Deta = Determinant(y1,x1, 1,y2,x2,1,y3,x3,1);
                Detb = Determinant(x1*x1,y1, 1,x2*x2,y2,1,x3*x3,y3,1);
                Detc = Determinant(x1*x1,x1, y1,x2*x2,x2,y2,x3*x3,x3,y3);
                a = Deta / Det;
                if (a == 0)
                {
                    qsResult = i18n("<b>The function determined by the three given points <font color = red>is not a parabola but a line.</font></b>");
                }
                else
                {
                    b = Detb / Det;
                    c = Detc / Det;
                    qsA = qsA.number(a);
                    qsB = qsB.number(b);
                    qsC = qsC.number(c);
                    //Formatting the equation
                    qsEquation = qsA + "x <sup>2</sup> ";
                    if (b == 0)
                    {
                        //Nothing to do
                    }
                    else if (b > 0)
                    {
                        qsEquation += "+ " + qsB + "x";
                    }
                    else
                    {
                        qsEquation += qsB + "x";
                    }
                    if (c == 0)
                    {
                        //Nothing to do
                    }
                    else if (c > 0)
                    {
                        qsEquation += "+ " + qsC;
                    }
                    else
                    {
                        qsEquation += qsC;
                    }
                    qsEquation.simplified();
                    //End of Formatting
                    qsResult = i18n("The equation of the parabola, that runs through the three given points is:<br>"
                                    "<b><i>%1</i></b>.").arg(qsEquation);

                    p3_a = a;
                    p3_b = b;
                    p3_c = c;
                }
            }
            KTextBrowserResult->setText(qsResult);
            break;
        }

    case TurnPointAndPoint: //Find equation of parabola with turnPoint and one point
        {
            double x1,xs,y1,ys, Det, Deta, Detb, Detc, a, b, c;
            QString qsResult, qsA, qsB, qsC, qsEquation;

            x1 = pi->Point1_x->value();
            y1 = pi->Point1_y->value();
            xs = pi->Point2_x->value();
            ys = pi->Point2_y->value();

            Det = Determinant(x1*x1,x1, 1,xs*xs,xs,1,2*xs,1,0);
            if (Det == 0)
            {
                qsResult = i18n("<b>The function determined by the turn point and point <font color = red>is not a parabola.</font></b><br>"
                                "Maybe the vertex is identical to the second point?");
            }
            else
            {
                Deta = Determinant(y1,x1, 1,ys,xs,1,0,1,0);
                Detb = Determinant(x1*x1,y1, 1,xs*xs,ys,1,2*xs,0,0);
                Detc = Determinant(x1*x1,x1, y1,xs*xs,xs,ys,2*xs,1,0);
                a = Deta / Det;
                if (a == 0)
                {
                    qsResult = i18n("<b>The function determined by the turn point and point <font color = red>is not a parabola  but a line.</font></b>");
                }
                else
                {
                    b = Detb / Det;
                    c = Detc / Det;
                    qsA = qsA.number(a);
                    qsB = qsB.number(b);
                    qsC = qsC.number(c);
                    //Formatting the equation
                    qsEquation = qsA + "x <sup>2</sup> ";
                    if (b == 0)
                    {
                        //Nothing to do
                    }
                    else if (b > 0)
                    {
                        qsEquation += "+ " + qsB + "x";
                    }
                    else
                    {
                        qsEquation += qsB + "x";
                    }
                    if (c == 0)
                    {
                        //Nothing to do
                    }
                    else if (c > 0)
                    {
                        qsEquation += "+ " + qsC;
                    }
                    else
                    {
                        qsEquation += qsC;
                    }
                    qsEquation.simplified();
                    //End of Formatting
                    qsResult = i18n("The equation of the parabola, that runs through the turn point and point is:<br>"
                                    "Y = <b><i>%1</i></b>.").arg(qsEquation);

                    p3_a = a;
                    p3_b = b;
                    p3_c = c;


                }
            }
            KTextBrowserResult->setText(qsResult);
            break;
        }

    case Intersect_Parabola_Line: //Find intersection point of parabola and line
        {
            double a, b, c, m, d, Dis, xs1, xs2, ys1,ys2;
            QString qsResult, qsYs1, qsXs1, qsYs2, qsXs2;

            //parabola values
            a = pi->parabola_mx->value();
            b = pi->parabola_bx->value();
            c = pi->parabola_c->value();
            //line values
            m = pi->Line_mx->value();
            d = pi->Line_c->value();

            Dis = ((b - m)*(b - m)/(4*a*a)) - (( c- d)/a);
            if ( Dis < 0 )
            {
                //No intersection
                qsResult = i18n("The given parabola and line <font color = red>do not intersect.</font>.");
            }
            else if (Dis == 0)
            {
                //one intersection point
                xs1 = -(b - m)/(2*a);
                ys1 = m*xs1+d;

                qsXs1 = qsXs1.number(xs1);
                qsYs1 = qsYs1.number(ys1);

                qsResult = i18n("There is <b>one intersection-point</b> of the parabola and the line at<br>"
                                "<b><i>S(%1|%2)</i></b>.<br>"
                                "So the line is a <b>tangent</b> to the parabola.").arg(qsXs1);
            }
            else
            {
                //two intersection points
                xs1 = -(b - m)/(2*a) + sqrt(Dis);
                xs2 = -(b - m)/(2*a) - sqrt(Dis);
                ys1 = m*xs1+d;
                ys2 = m*xs2+d;

                qsXs1 = qsXs1.number(xs1);
                qsYs1 = qsYs1.number(ys1);
                qsXs2 = qsXs2.number(xs2);
                qsYs2 = qsYs2.number(ys2);

                qsResult = i18n("There are <b>two intersection-points</b> of the parabola and the line at<br>"
                                "<b><i>S<sub>1</sub>(%1|%2)</i></b> and <b><i>S<sub>2</sub>(%3|%4)</i></b>.<br>"
                                "So the line and the parabola do <b>intersect</b>.").arg(qsXs1).arg(qsYs1).arg(qsXs2).arg(qsYs2);
            }
            KTextBrowserResult->setText(qsResult);
            break;
        }

    case Intersect_Parabola_Parabola: //Find intersection point of two parabolas
        {
            double a, b, c,d,e,f, Dis, xs1, xs2, ys1,ys2;
            QString qsResult, qsYs1, qsXs1, qsYs2, qsXs2;

            //parabola 1
            a = pi->parabola_mx->value();
            b = pi->parabola_bx->value();
            c = pi->parabola_c->value();
            //parabola 2
            d = pi->parabola2_mx->value();
            e = pi->parabola2_bx->value();
            f = pi->parabola2_c->value();

            Dis = (b- e)*(b-e)/(2*(a-d)*(a-d))-((c-f)/(a-d));
            if ( Dis < 0 )
            {
                //No intersection
                qsResult = i18n("The two given parabolas <font color = red>do not intersect.</font>.");
            }
            else if (Dis == 0)
            {
                //one intersection point
                xs1 = - (b - e)/(2*(a-d));
                ys1 = a*xs1*xs1+b*xs1+c;

                qsXs1 = qsXs1.number(xs1);
                qsYs1 = qsYs1.number(ys1);

                qsResult = i18n("There is <b>one intersection-point</b> of the two parabolas at<br>"
                                "<b><i>S(%1|%2)</i></b>.<br>"
                                "So the two parabolas are <b>tangent</b> to each other at the intersection point.").arg(qsXs1).arg(qsYs1);
            }
            else
            {
                //two intersection points
                xs1 = - (b - e)/(2*(a-d)) + sqrt(Dis);
                xs2 = - (b - e)/(2*(a-d)) - sqrt(Dis);
                ys1 = a*xs1*xs1+b*xs1+c;
                ys2 = a*xs2*xs2+b*xs2+c;

                qsXs1 = qsXs1.number(xs1);
                qsYs1 = qsYs1.number(ys1);
                qsXs2 = qsXs2.number(xs2);
                qsYs2 = qsYs2.number(ys2);

                qsResult = i18n("There are <b>two intersection-points</b> of the two parabolas at<br>"
                                "<b><i>S<sub>1</sub>(%1|%2)</i></b> and <b><i>S<sub>2</sub>(%3|%4)</i></b>.<br>"
                                "So the two parabolas do <b>intersect</b>.").arg(qsXs1).arg(qsYs1).arg(qsXs2).arg(qsYs2);
            }
            KTextBrowserResult->setText(qsResult);
            break;
        }
    }
}

void Parabolas::slotClear()
{
    KTextBrowserResult->setText(" ");

    pi->Point1_x->setValue(0);
    pi->Point1_y->setValue(0);
    pi->Point2_x->setValue(0);
    pi->Point2_y->setValue(0);
    pi->Point3_x->setValue(0);
    pi->Point3_y->setValue(0);
    pi->Line_mx->setValue(0);
    pi->Line_c->setValue(0);
    pi->parabola_mx->setValue(0);
    pi->parabola_bx->setValue(0);
    pi->parabola_c->setValue(0);
    pi->parabola2_mx->setValue(0);
    pi->parabola2_bx->setValue(0);
    pi->parabola2_c->setValue(0);

}

void Parabolas::slotShowParabolaAxisSection()  //find X-Y axis cuts of equation
{
    clearBoxes();

    TextLabelInformation->setText(i18n("Find intersection with X & Y axis"));
    KTextBrowserResult->setText(" ");

    pi->parabola_mx->show();
    pi->parabola_bx->show();
    pi->parabola_c->show();
    pi->parabolaEquation1->show();
    pi->x1->show();
    pi->X1->show();

    m_eSelected = AxisSection;

    pi->show();
}



void Parabolas::slotShowParabola3Points() //Find equation with 3 points
{
    clearBoxes();

    TextLabelInformation->setText(i18n("Find equation with three points"));
    KTextBrowserResult->setText(" ");

    pi->Point1_x->show();
    pi->Point1_y->show();
    pi->Point2_x->show();
    pi->Point2_y->show();
    pi->Point3_x->show();
    pi->Point3_y->show();

    pi->point1->show();
    pi->textLabel3->show();
    pi->textLabel2->show();
    pi->pointformat1->show();
    pi->point2->show();
    pi->textLabel3_2->show();
    pi->textLabel2_2->show();
    pi->pointformat2->show();
    pi->point3->show();
    pi->textLabel3_2_2->show();
    pi->textLabel2_3->show();
    pi->pointformat3->show();

    m_eSelected = ThreePoints;

    pi->show();
}

void Parabolas::slotShowParabolaPointandTurnPoint()
{
    clearBoxes();

    TextLabelInformation->setText(i18n("Find equation with the TurnPoint and point"));
    pi->point1->setText(i18n("TurnPoint S:"));
    pi->point2->setText (i18n("one Point :"));

    pi->Point1_x->show();
    pi->Point1_y->show();
    pi->Point2_x->show();
    pi->Point2_y->show();

    pi->point1->show();
    pi->textLabel3->show();
    pi->textLabel2->show();
    pi->pointformat1->show();
    pi->point2->show();
    pi->textLabel3_2->show();
    pi->textLabel2_2->show();
    pi->pointformat2->show();

    KTextBrowserResult->setText(" ");
    m_eSelected = TurnPointAndPoint;

    pi->show();
}

void Parabolas::slotShowParabolaFindTurnPoint()
{
    clearBoxes();

    TextLabelInformation->setText(i18n("Find the TurnPoint of a parabola"));

    pi->parabola_mx->show();
    pi->parabola_bx->show();
    pi->parabola_c->show();

    pi->parabolaEquation1->show();
    pi->x1->show();
    pi->X1->show();

    KTextBrowserResult->setText(" ");
    m_eSelected = TurnPoint;

    pi->show();
}

void Parabolas::slotShowParabolaLineSection()
{
    clearBoxes();

    TextLabelInformation->setText(i18n("Find intersect(s) parabola and line"));

    pi->Line_mx->show();
    pi->Line_c->show();
    pi->parabola_mx->show();
    pi->parabola_bx->show();
    pi->parabola_c->show();

    pi->lineEquation->show();
    pi->textLabel6->show();
    pi->lineFormat->show();
    pi->parabolaEquation1->show();
    pi->x1->show();
    pi->X1->show();

    KTextBrowserResult->setText(" ");
    m_eSelected = Intersect_Parabola_Line;

    pi->show();
}

void Parabolas::slotShowParabolaParabola()
{
    clearBoxes();

    TextLabelInformation->setText(i18n("Find intersect(s) of two parabolas"));

    pi->parabola_mx->show();
    pi->parabola_bx->show();
    pi->parabola_c->show();
    pi->parabola2_mx->show();
    pi->parabola2_bx->show();
    pi->parabola2_c->show();

    pi->parabolaEquation1->show();
    pi->x1->show();
    pi->X1->show();
    pi->parabolaEquation2->show();
    pi->x2->show();
    pi->X2->show();

    KTextBrowserResult->setText(" ");
    m_eSelected = Intersect_Parabola_Parabola;

    pi->show();
}

void Parabolas::clearBoxes()
{   //Clear Boxes
    KTextBrowserResult->setText(" ");

    pi->Point1_x->setValue(0);
    pi->Point1_y->setValue(0);
    pi->Point2_x->setValue(0);
    pi->Point2_y->setValue(0);
    pi->Point3_x->setValue(0);
    pi->Point3_y->setValue(0);
    pi->Line_mx->setValue(0);
    pi->Line_c->setValue(0);
    pi->parabola_mx->setValue(0);
    pi->parabola_bx->setValue(0);
    pi->parabola_c->setValue(0);
    pi->parabola2_mx->setValue(0);
    pi->parabola2_bx->setValue(0);
    pi->parabola2_c->setValue(0);

    pi->Point1_x->hide();
    pi->Point1_y->hide();
    pi->Point2_x->hide();
    pi->Point2_y->hide();
    pi->Point3_x->hide();
    pi->Point3_y->hide();
    pi->Line_mx->hide();
    pi->Line_c->hide();
    pi->parabola_mx->hide();
    pi->parabola_bx->hide();
    pi->parabola_c->hide();
    pi->parabola2_mx->hide();
    pi->parabola2_bx->hide();
    pi->parabola2_c->hide();

    pi->point1->hide();
    pi->textLabel3->hide();
    pi->textLabel2->hide();
    pi->pointformat1->hide();
    pi->point2->hide();
    pi->textLabel3_2->hide();
    pi->textLabel2_2->hide();
    pi->pointformat2->hide();
    pi->point3->hide();
    pi->textLabel3_2_2->hide();
    pi->textLabel2_3->hide();
    pi->pointformat3->hide();
    pi->lineEquation->hide();
    pi->textLabel6->hide();
    pi->lineFormat->hide();
    pi->parabolaEquation1->hide();
    pi->x1->hide();
    pi->X1->hide();
    pi->parabolaEquation2->hide();
    pi->x2->hide();
    pi->X2->hide();
}

void Parabolas::allDisconnect()
{
}

double Parabolas::Determinant(double d11,double d12, double d13, double d21, double d22, double d23, double d31, double d32, double d33)
{
    double Det = d11*d22*d33+d12*d23*d31+d13*d21*d32-d31*d22*d13-d32*d23*d11-d33*d21*d12;
    return Det;
}

#include "parabolas.moc"

