/*
Copyright (C) 2008 Alessandro Bugatti (alessandro.bugatti@istruzione.it)
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*! \file
* \brief Programma grafico per calcolare il preventivo di un'automobile
* \author Alessandro Bugatti
*
* \version 0.1
* \date Creazione 15/04/2009
* \date Ultima modifica 25/05/2009
*
*/
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Round_Button.H>
#include <FL/Fl_Choice.H>
#include <FL/fl_ask.H>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include "preventivo.h"
using namespace std;
Fl_Window *window;
Fl_Box *valore;
Fl_Button *btnCalcola;
Fl_Choice *choModello;
Fl_Round_Button *rndMotore[4];
Fl_Choice *choVernice;
Preventivo *prv;
void Calcola(Fl_Widget *w, void *data)
{
int motore;
prv->setModello(choModello->value());
for (int i = 0; i < prv->getMotorizzazioni().size(); i++)
if (rndMotore[i]->value()) prv->setMotorizzazione(i);
prv->setColore(choVernice->value());
double prezzo = prv->getPreventivo();
char str[100];
sprintf(str,"Preventivo: %.2f",prezzo);
valore->copy_label(str);
}
//Quetsa callback serve a sistemare un errore della libreria sotto Linux
void Ridisegna(Fl_Widget *w, void *data)
{
w->redraw_label();
}
int main (int argc, char *argv[])
{
prv = new Preventivo;
vector <string> temp;
window = new Fl_Window (380, 260, "Preventivo per automobili");
//Componenti contenuti nella finestra
window->begin();
choModello=new Fl_Choice(20,30,100,20,"Modello");
choModello->align(FL_ALIGN_TOP | FL_ALIGN_LEFT);
temp = prv->getModelli();
for (int i=0;i<temp.size();i++)
choModello->add(temp.at(i).c_str());
choModello->value(0);
temp = prv->getMotorizzazioni();
for (int i=0;i<temp.size();i++){
rndMotore[i]=new Fl_Round_Button(20,70+i*20,20,20,temp.at(i).c_str());
rndMotore[i]->align(FL_ALIGN_RIGHT);
rndMotore[i]->type(FL_RADIO_BUTTON);
rndMotore[i]->callback(Ridisegna);
}
rndMotore[0]->value(1);
choVernice=new Fl_Choice(220,30,100,20,"Vernice");
choVernice->align(FL_ALIGN_TOP | FL_ALIGN_LEFT);
temp = prv->getColori();
for (int i=0;i<temp.size();i++)
choVernice->add(temp.at(i).c_str());
choVernice->value(0);
btnCalcola = new Fl_Button(220,80,100,40,"Calcola");
btnCalcola->labelsize(20);
valore = new Fl_Box(20,180,340,60,"Preventivo: ");
valore->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
valore->labelsize(20);
valore->box(FL_PLASTIC_UP_BOX);
btnCalcola->callback(Calcola);
window->end ();
//Callback
//btnCalcola->callback(Calcola);
window->show (argc, argv);
return Fl::run();
}