Allink
v0.1
|
00001 #include "DrScript.h" 00002 00003 void DrScript::DrMessage(const char * s, ...) 00004 { 00005 #ifdef DEBUG 00006 va_list args; 00007 va_start(args, s); 00008 vfprintf(stderr, s, args); 00009 fprintf(stderr, "\n"); 00010 va_end(args); 00011 #else 00012 return; 00013 #endif 00014 } 00015 DrScript::DrScript(){ 00016 Slide = 0; 00017 } 00018 DrScript::~DrScript(){ 00019 } 00020 void DrScript::IncrSlide(){ 00021 Slide++; 00022 repaint(); 00023 } 00024 void DrScript::paintEvent(QPaintEvent *){ 00025 DrMessage("DrScript.paintEvent"); 00026 QPainter p(this); 00027 p.setPen(QPen(Qt::black,1,Qt::DashLine,Qt::RoundCap,Qt::RoundJoin)); 00028 p.drawRect(0,0,width(),height()); 00029 p.setFont(QFont("Helvetica",12 )); 00030 ReadSlide(&p); 00031 } 00032 void DrScript::ReadSlide(QPainter *p){ 00033 DrMessage("DrScript.ReadSlide"); 00034 if((File2Read = fopen("DrScript.dr","r"))==0){ 00035 return ; 00036 } 00037 char *cLine = (char *)calloc(256,sizeof(char)); 00038 for(int k=0;!(fgets(cLine,256,File2Read)==NULL);k++){ 00039 if(strncmp(cLine,"Slide",5)==0){ 00040 int NSlide = 0; 00041 fgets(cLine,256,File2Read); 00042 sscanf(cLine,"%d\n",&NSlide); 00043 if(NSlide != Slide) continue; 00044 ExecScript(p); 00045 } 00046 } 00047 free(cLine); 00048 fclose(File2Read); 00049 } 00050 void DrScript::ExecScript(QPainter *p){ 00051 DrMessage("DrScript.ExecScript"); 00052 char *cLine = (char *)calloc(256,sizeof(char)); 00053 double *From = (double *)calloc(2,sizeof(double)); 00054 int *iFrom = (int *)calloc(2,sizeof(int)); 00055 double *To = (double *)calloc(2,sizeof(double)); 00056 int *iTo = (int *)calloc(2,sizeof(int)); 00057 double *Hue = (double *)calloc(4,sizeof(double)); 00058 int *iHue = (int *)calloc(4,sizeof(int)); 00059 for(int k=0;!(fgets(cLine,256,File2Read)==NULL);k++){ 00060 if(strncmp(cLine,"Slide",5)==0) break; 00061 else if(strncmp(cLine,"Testo",5)==0){ 00062 //Colore 00063 fgets(cLine,256,File2Read); 00064 sscanf(cLine,"%lf %lf %lf %lf\n",Hue,Hue+1,Hue+2,Hue+3); 00065 for(int i=0;i<4;i++) iHue[i] = (int)(255.*Hue[i]); 00066 p->setBrush( QColor(iHue[0],iHue[1],iHue[2],iHue[3]) ); 00067 //Posizione 00068 fgets(cLine,256,File2Read); 00069 sscanf(cLine,"%lf %lf\n",From,From+1); 00070 iFrom[0] = (int)(width()*From[0]); 00071 iFrom[1] = (int)(height()*(1.-From[1])); 00072 //Testo 00073 char *String = (char *)calloc(512,sizeof(char)); 00074 fgets(cLine,512,File2Read); 00075 for(int c=0;c<strlen(cLine);c++) 00076 String[c] = cLine[c]; 00077 p->drawText(iFrom[0],iFrom[1],QString(String),-1,Qt::AlignTop); 00078 //printf("Col %d %d %d %d Pos %d %d Text %s\n",iHue[0],iHue[1],iHue[2],iHue[3],iFrom[0],iFrom[1],String); 00079 // while(1==1) { 00080 // fpos_t FPos; 00081 // fgetpos(File2Read,&FPos); 00082 // if(fgets(cLine,256,File2Read)==0) break; 00083 // if(sscanf(cLine,"%lf %lf\n",From,From+1)!=3){ 00084 // fsetpos(File2Read,&FPos); 00085 // break; 00086 // } 00087 // } 00088 free(String); 00089 } 00090 else if(strncmp(cLine,"Picture",4)==0){ 00091 //Posizione 00092 fgets(cLine,256,File2Read); 00093 sscanf(cLine,"%lf %lf\n",From,From+1); 00094 iFrom[0] = (int)(width()*From[0]); 00095 iFrom[1] = (int)(height()*(1.-From[1])); 00096 //Posizione 00097 fgets(cLine,256,File2Read); 00098 sscanf(cLine,"%lf %lf\n",To,To+1); 00099 iTo[0] = (int)(width()*To[0]); 00100 iTo[1] = (int)(height()*(1.-To[1])); 00101 //Testo 00102 char *String = (char *)calloc(512,sizeof(char)); 00103 fgets(cLine,512,File2Read); 00104 // sprintf(String,"%s",cLine); 00105 for(int c=0;c<strlen(cLine)-1;c++) String[c] = cLine[c]; 00106 //printf("Apro %s in %d %d -> %d %d\n",String,iFrom[0],iFrom[1],iTo[0],iTo[1]); 00107 //p->drawImage(QPoint(iFrom[0],iFrom[1]),QImage(QString(String),0),QRect(0,0,iTo[0]-iFrom[0],iTo[1]-iFrom[1]),0); 00108 p->drawImage(QRect(iFrom[0],iFrom[1],iTo[0],iTo[1]),QImage(QString(String),0)); 00109 free(String); 00110 } 00111 else if(strncmp(cLine,"Background",10)==0){ 00112 } 00113 } 00114 free(From); 00115 free(To); 00116 free(Hue); 00117 free(cLine); 00118 }