~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to kspread/qtai_strip.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
        Written 1998-1999 by Uwe Langenkamp
3
 
 
4
 
        This software may be used and distributed according to the terms
5
 
        of the GNU Public License, incorporated herein by reference.
6
 
 
7
 
        The author may be reached as ul@it-guru.de
8
 
*/
9
 
 
10
 
/* History:
11
 
 *          98/19/03 Last Change
12
 
 *          98/19/03 Moving Grid added
13
 
 *
14
 
 */
15
 
 
16
 
#include <qpainter.h>
17
 
#include <qpntarry.h>
18
 
#include <qapp.h>
19
 
#include <qsocknot.h>
20
 
#include <qpopmenu.h>
21
 
#include <qlabel.h>
22
 
#include <qlayout.h>
23
 
#include <qkeycode.h>
24
 
#include <qtimer.h>
25
 
#include <qbttngrp.h>
26
 
#include <qfiledlg.h>
27
 
#include <qstrlist.h>
28
 
#include <qmsgbox.h>
29
 
 
30
 
#include <stdio.h>
31
 
#include <stdlib.h>
32
 
#include <math.h>
33
 
 
34
 
#include <sys/types.h>
35
 
#include <time.h>
36
 
 
37
 
#include "qtai_strip.h"
38
 
 
39
 
#define FACTOR 1
40
 
 
41
 
AIStrip::AIStrip(QWidget *parent,const char *name,int b,int t)
42
 
  : AIPlot(parent,name,b,t)
43
 
{
44
 
  int i;
45
 
  for (i=0;i<traces;i++)
46
 
    qn[0]=0;
47
 
  xrange=1.0;
48
 
  w_of_x=10;
49
 
  xmax=1;
50
 
  xmax=0;
51
 
}
52
 
 
53
 
void AIStrip::addData(double xp,double *yp)
54
 
{
55
 
  int i;
56
 
 
57
 
  if (qn[0]>=bufsize) {
58
 
    qn[0]=bufsize-1;
59
 
    for (i=0;i<traces;i++) {
60
 
      calced[i]=FALSE;
61
 
      memmove((char*)&xtrace[i][0],
62
 
              (char*)&xtrace[i][1],
63
 
              (bufsize-1)*sizeof(double));
64
 
      memmove((char*)&ytrace[i][0],
65
 
              (char*)&ytrace[i][1],
66
 
              (bufsize-1)*sizeof(double));
67
 
    }
68
 
  }
69
 
 
70
 
  // Set all X Traces
71
 
  for (i=0;i<traces;i++) {
72
 
    xtrace[i][qn[0]]=xp;
73
 
    calced[i]=FALSE;
74
 
    ytrace[i][qn[0]]=yp[i];
75
 
    qn[i]=qn[0];
76
 
  }
77
 
 
78
 
  // ... BUT Check only on trace 0,
79
 
  // CAUSE in Strip all Data is based on one time trace
80
 
  if (xtrace[0][qn[0]]>=getXmax()){
81
 
    setXRange(xtrace[0][qn[0]]-xrange,xtrace[0][qn[0]]);
82
 
  } else {
83
 
    setXRange(xtrace[0][0],xtrace[0][0]+xrange);
84
 
  }
85
 
 
86
 
  qn[0]++;
87
 
 
88
 
  // Hide Cursor, maybe we should use a p_curs..->hide()
89
 
  for (i=0;i<2;i++)
90
 
    p_curs[i].set(p_curs[i].x(),p_curs[i].y());
91
 
}
92
 
 
93
 
void AIStrip::setViewRange(double xr,double ymn,double ymx)
94
 
{
95
 
  xrange=xr;
96
 
  setRanges(0,xrange,ymn,ymx);
97
 
}
98
 
 
99
 
void AIStrip::drawScale( QPainter *p,int direction,int w,int h)
100
 
{
101
 
  int   y;
102
 
  int   maxx=8,maxy=8;
103
 
  int    spos,pos;
104
 
  double shift;
105
 
  int zx1,zx2,zy1,zy2;
106
 
 
107
 
  //p->fillRect(0,0,w,h,c_bg);
108
 
  p->setPen(c_grid);                            
109
 
 
110
 
  if (direction & HORIZONTAL) {
111
 
 
112
 
    zx1=(int)(zoomx1[zoomed_in]*(double)w/100.0f);
113
 
    zx2=(int)((zoomx2[zoomed_in]-zoomx1[zoomed_in])*(double)w/100.0f);
114
 
 
115
 
    p->setWindow(zx1,0,zx2,h);
116
 
 
117
 
    shift=(double)((int)(xmin / w_of_x))*w_of_x;
118
 
    while(1) {
119
 
 
120
 
      spos=(int)(((double)shift-(double)xmin)/(double)(xmax-xmin)*(double)w);
121
 
 
122
 
      if (spos>=zx1 && spos<=zx1+zx2) {
123
 
        /*
124
 
          if (!((int)shift % (int) (5*w_of_x))) {
125
 
          p->drawLine(spos,(int)0,
126
 
          spos,(int)h);         
127
 
          } else {
128
 
          */
129
 
        p->drawLine(spos,(int)0,
130
 
                    spos,(int)h/2);             
131
 
      }
132
 
 
133
 
      shift+=w_of_x;
134
 
      if (shift>=xmax)
135
 
        break;
136
 
    }
137
 
    p->drawLine(zx1,(int)0,zx1,(int)h);         
138
 
    p->drawLine(zx1+zx2,(int)0,zx1+zx2,(int)h);         
139
 
  }
140
 
 else if (direction & VERTICAL) {
141
 
 
142
 
   zy1=(int)(zoomy1[zoomed_in]*(double)h/100.0f);
143
 
   zy2=(int)((zoomy2[zoomed_in]-zoomy1[zoomed_in])*(double)h/100.0f);
144
 
 
145
 
   p->setWindow(0,zy1,w,zy2);
146
 
 
147
 
   // Draw vertical scale
148
 
   for (y=0;y<=maxy;y++) {
149
 
     pos=(int)(y*h/maxy);
150
 
     if (pos>=zy1 && pos<=zy1+zy2) {
151
 
       p->drawLine((int)w/2,pos,(int)w,pos);
152
 
     }
153
 
   }
154
 
 }
155
 
}
156
 
 
157
 
void AIStrip::drawLabel( QPainter *p,int direction,int w,int rw,int h,int rh)
158
 
{
159
 
  int   y;
160
 
  int   maxx=8,maxy=8;
161
 
  int   tpos;
162
 
  QString str="";
163
 
  QFont font("Helvetica",10);
164
 
  QFontMetrics fm(font);
165
 
  double rzb,rze;
166
 
  double lw,lh;
167
 
  static double lzx1,lzy1,lzx2,lzy2;
168
 
  time_t tt=0;
169
 
  struct tm *ts = NULL;
170
 
 
171
 
  lzx1=zoomx1[zoomed_in],lzy1=zoomy1[zoomed_in];
172
 
  lzx2=zoomx2[zoomed_in],lzy2=zoomy2[zoomed_in];
173
 
 
174
 
  //p->fillRect(0,0,w,h,c_bg);
175
 
  p->setPen(c_grid);                            
176
 
 
177
 
  // Calculate begin and end of zoom area to the real world,
178
 
  // means orig xmin,xmax
179
 
  if (direction & HORIZONTAL) {
180
 
      rzb=(double)lzx1*((double)xmax-(double)xmin)/
181
 
        (double)100.0f + (double)xmin;
182
 
      rze=(double)lzx2*((double)xmax-(double)xmin)/
183
 
        (double)100.0f + (double)xmin;
184
 
  } else if (direction & VERTICAL) {
185
 
      rzb=(double)(100.0f-lzy1)*((double)ymax-(double)ymin)/
186
 
        (double)100.0f + (double)ymin;
187
 
      rze=(double)(100.0f-lzy2)*((double)ymax-(double)ymin)/
188
 
        (double)100.0f + (double)ymin;
189
 
  }
190
 
  p->setFont(font);
191
 
 
192
 
  // set original width,height e.g.:
193
 
  // zoom(lzx1,lzx2,lzy1,lzy2) =0,0% to 50,50%,
194
 
  // window width (rw)= 100 pixel
195
 
  // => local virtual width,height (lw,hw)= 200 pixel
196
 
  lw=rw*100.0f/(lzx2-lzx1);
197
 
  lh=rh*100.0f/(lzy2-lzy1);
198
 
 
199
 
  if (direction & HORIZONTAL) {
200
 
 
201
 
    //shift=(double)((int)(xmin / w_of_x))*w_of_x;
202
 
 
203
 
#ifdef MOVE_X
204
 
    while(1) {
205
 
      spos=(int)(((double)shift-(double)xmin)/(double)(xmax-xmin)*(double)lw);
206
 
      if (spos>=0) {
207
 
        str.sprintf("%.2f\0",
208
 
                (double)(xmin+(xmax-xmin)*(double)spos/(double)lw));
209
 
        
210
 
        tpos=(int)(spos-lzx1*lw/100.0f-fm.width(str)/2+(w-rw)/2);
211
 
 
212
 
        if (!(tpos<0 || tpos+fm.width(str)>w)) {
213
 
          p->drawText(tpos,0+fm.height(),str);
214
 
        }
215
 
      }
216
 
 
217
 
      shift+=w_of_x;
218
 
      if (shift>=xmax)
219
 
        break;
220
 
    }
221
 
#else
222
 
    if ((x_axis_display_type & X_AXIS_NUMBER)==X_AXIS_NUMBER) {
223
 
      str.sprintf("%.2f\0",(double)rzb);
224
 
      tpos=(w-rw)/2-fm.width(str)/2;
225
 
      p->drawText(tpos,0+fm.height(),str);
226
 
 
227
 
      str.sprintf("%.2f\0",(double)rze);
228
 
      tpos=w-(w-rw)/2-fm.width(str)/2;
229
 
      p->drawText(tpos,0+fm.height(),str);
230
 
    } else if ((x_axis_display_type & X_AXIS_DATE)==X_AXIS_DATE) {
231
 
      if ((x_axis_display_type & X_AXIS_UK)==X_AXIS_UK) {
232
 
      } else {
233
 
        
234
 
        if (rzb<=0.0)
235
 
                return;
236
 
 
237
 
        tt=(time_t)rzb;
238
 
        ts = localtime(&tt);
239
 
        if (ts==NULL)
240
 
                return;
241
 
 
242
 
        str.sprintf("%02d:%02d:%02d\0",
243
 
                ts->tm_hour,ts->tm_min,ts->tm_sec);
244
 
        tpos=(w-rw)/2-fm.width(str)/2;
245
 
        p->drawText(tpos,0+fm.height(),str);
246
 
        int year=0;
247
 
        if (ts->tm_year<80) year=2000+ts->tm_year;
248
 
        else year=1900+ts->tm_year;
249
 
        str.sprintf("%02d.%02d.%04d\0",
250
 
                ts->tm_mday,ts->tm_mon+1,year);
251
 
        p->drawText(tpos,0+2*fm.height(),str);
252
 
        
253
 
        tt=(time_t)rze;
254
 
        ts = localtime(&tt);
255
 
        str.sprintf("%02d:%02d:%02d\0",
256
 
                ts->tm_hour,ts->tm_min,ts->tm_sec);
257
 
        tpos=w-(w-rw)/2-fm.width(str)/2;
258
 
        p->drawText(tpos,0+fm.height(),str);
259
 
      }
260
 
    }
261
 
#endif
262
 
  }
263
 
 else if (direction & VERTICAL) {
264
 
 
265
 
    for (y=0;y<=maxy;y++) {
266
 
 
267
 
      str.sprintf("%.2f\0",(double)(ymax+(ymin-ymax)*(double)y/(double)maxy));
268
 
      tpos=(int)(y*lh/maxy-lzy1*lh/100.0f+fm.height()/2+(h-rh)/2);
269
 
      if (!(tpos-fm.height()<0 || tpos+fm.height()>h))
270
 
        p->drawText(w-fm.width(str),tpos,str);
271
 
    }
272
 
 }
273
 
}
274
 
 
275
 
void AIStrip::drawGrid( QPainter *p )
276
 
{
277
 
  int y;
278
 
  int maxx=8,maxy=8;
279
 
  int w=width()*20,h=height()*20;
280
 
  int    spos;
281
 
  double shift;
282
 
 
283
 
    int    n;
284
 
  static int     bw=-1,bh=-1; // BG Buffer
285
 
  static QPixmap *bg_buf=NULL;
286
 
  QPainter bg_p;
287
 
  QPoint   qp(0,0);
288
 
  QColor   c;
289
 
 
290
 
  w=width();
291
 
  h=height();
292
 
 
293
 
#define SHADE_BG
294
 
#ifdef SHADE_BG
295
 
#else
296
 
  // 1999-05-23 UL, disabled, enabled
297
 
  //p->fillRect(0,0,w,h,c_bg);
298
 
#endif
299
 
 
300
 
  QPen pen(c_grid,1,DotLine);
301
 
  p->setPen(pen);                               
302
 
 
303
 
  if (zoomed_in>0) {
304
 
    p->setWindow(
305
 
                 (int)(zoomx1[zoomed_in]*(double)w/100.0f),
306
 
                 (int)(zoomy1[zoomed_in]*(double)h/100.0f),
307
 
                 (int)((zoomx2[zoomed_in]-zoomx1[zoomed_in])*(double)w/100.0f),
308
 
                 (int)((zoomy2[zoomed_in]-zoomy1[zoomed_in])*(double)h/100.0f));
309
 
  } else {
310
 
    p->setWindow(0,0,w,h);      // defines coordinate system
311
 
  }
312
 
 
313
 
  shift=(double)((int)(xmin / w_of_x))*w_of_x;
314
 
  while(1) {
315
 
 
316
 
    spos=(int)(((double)shift-(double)xmin)/(double)(xmax-xmin)*(double)w);
317
 
 
318
 
    p->drawLine((int)spos,(int)0,
319
 
                (int)spos,(int)h);
320
 
 
321
 
    shift+=w_of_x;
322
 
    if (shift>=xmax)
323
 
      break;
324
 
  }
325
 
 
326
 
  for (y=1;y<maxy;y++) {
327
 
    p->drawLine((int)0,(int)(y*h/maxy),
328
 
                (int)w,(int)(y*h/maxy));                
329
 
  }
330
 
 
331
 
  p->drawRect(0,0,w,h);
332
 
}
333
 
 
334
 
void AIStrip::setGridUnit(double wox)
335
 
{
336
 
  w_of_x=wox; // Set the width between 2 X Axis Scales
337
 
}
338
 
 
339
 
#include "qtai_strip.moc"