Allink  v0.1
DrScript.cpp
1 #include "DrScript.h"
2 
3 void DrScript::DrMessage(const char * s, ...)
4 {
5 #ifdef DEBUG
6  va_list args;
7  va_start(args, s);
8  vfprintf(stderr, s, args);
9  fprintf(stderr, "\n");
10  va_end(args);
11 #else
12  return;
13 #endif
14 }
15 DrScript::DrScript(){
16  Slide = 0;
17 }
18 DrScript::~DrScript(){
19 }
20 void DrScript::IncrSlide(){
21  Slide++;
22  repaint();
23 }
24 void DrScript::paintEvent(QPaintEvent *){
25  DrMessage("DrScript.paintEvent");
26  QPainter p(this);
27  p.setPen(QPen(Qt::black,1,Qt::DashLine,Qt::RoundCap,Qt::RoundJoin));
28  p.drawRect(0,0,width(),height());
29  p.setFont(QFont("Helvetica",12 ));
30  ReadSlide(&p);
31 }
32 void DrScript::ReadSlide(QPainter *p){
33  DrMessage("DrScript.ReadSlide");
34  if((File2Read = fopen("DrScript.dr","r"))==0){
35  return ;
36  }
37  char *cLine = (char *)calloc(256,sizeof(char));
38  for(int k=0;!(fgets(cLine,256,File2Read)==NULL);k++){
39  if(strncmp(cLine,"Slide",5)==0){
40  int NSlide = 0;
41  fgets(cLine,256,File2Read);
42  sscanf(cLine,"%d\n",&NSlide);
43  if(NSlide != Slide) continue;
44  ExecScript(p);
45  }
46  }
47  free(cLine);
48  fclose(File2Read);
49 }
50 void DrScript::ExecScript(QPainter *p){
51  DrMessage("DrScript.ExecScript");
52  char *cLine = (char *)calloc(256,sizeof(char));
53  double *From = (double *)calloc(2,sizeof(double));
54  int *iFrom = (int *)calloc(2,sizeof(int));
55  double *To = (double *)calloc(2,sizeof(double));
56  int *iTo = (int *)calloc(2,sizeof(int));
57  double *Hue = (double *)calloc(4,sizeof(double));
58  int *iHue = (int *)calloc(4,sizeof(int));
59  for(int k=0;!(fgets(cLine,256,File2Read)==NULL);k++){
60  if(strncmp(cLine,"Slide",5)==0) break;
61  else if(strncmp(cLine,"Testo",5)==0){
62  //Colore
63  fgets(cLine,256,File2Read);
64  sscanf(cLine,"%lf %lf %lf %lf\n",Hue,Hue+1,Hue+2,Hue+3);
65  for(int i=0;i<4;i++) iHue[i] = (int)(255.*Hue[i]);
66  p->setBrush( QColor(iHue[0],iHue[1],iHue[2],iHue[3]) );
67  //Posizione
68  fgets(cLine,256,File2Read);
69  sscanf(cLine,"%lf %lf\n",From,From+1);
70  iFrom[0] = (int)(width()*From[0]);
71  iFrom[1] = (int)(height()*(1.-From[1]));
72  //Testo
73  char *String = (char *)calloc(512,sizeof(char));
74  fgets(cLine,512,File2Read);
75  for(int c=0;c<strlen(cLine);c++)
76  String[c] = cLine[c];
77  p->drawText(iFrom[0],iFrom[1],QString(String),-1,Qt::AlignTop);
78  //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);
79 // while(1==1) {
80 // fpos_t FPos;
81 // fgetpos(File2Read,&FPos);
82 // if(fgets(cLine,256,File2Read)==0) break;
83 // if(sscanf(cLine,"%lf %lf\n",From,From+1)!=3){
84 // fsetpos(File2Read,&FPos);
85 // break;
86 // }
87 // }
88  free(String);
89  }
90  else if(strncmp(cLine,"Picture",4)==0){
91  //Posizione
92  fgets(cLine,256,File2Read);
93  sscanf(cLine,"%lf %lf\n",From,From+1);
94  iFrom[0] = (int)(width()*From[0]);
95  iFrom[1] = (int)(height()*(1.-From[1]));
96  //Posizione
97  fgets(cLine,256,File2Read);
98  sscanf(cLine,"%lf %lf\n",To,To+1);
99  iTo[0] = (int)(width()*To[0]);
100  iTo[1] = (int)(height()*(1.-To[1]));
101  //Testo
102  char *String = (char *)calloc(512,sizeof(char));
103  fgets(cLine,512,File2Read);
104  // sprintf(String,"%s",cLine);
105  for(int c=0;c<strlen(cLine)-1;c++) String[c] = cLine[c];
106  //printf("Apro %s in %d %d -> %d %d\n",String,iFrom[0],iFrom[1],iTo[0],iTo[1]);
107  //p->drawImage(QPoint(iFrom[0],iFrom[1]),QImage(QString(String),0),QRect(0,0,iTo[0]-iFrom[0],iTo[1]-iFrom[1]),0);
108  p->drawImage(QRect(iFrom[0],iFrom[1],iTo[0],iTo[1]),QImage(QString(String),0));
109  free(String);
110  }
111  else if(strncmp(cLine,"Background",10)==0){
112  }
113  }
114  free(From);
115  free(To);
116  free(Hue);
117  free(cLine);
118 }