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

« back to all changes in this revision

Viewing changes to kspread/qtai_meter.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
 
 *          99/10/28 Last Change
12
 
 *          99/10/28 Shaded Background color added
13
 
 *                      99/10/26 Changes will only be made to free qtai!!!
14
 
 *          98/17/03
15
 
 *
16
 
 */
17
 
 
18
 
#include <qpainter.h>
19
 
#include <qpixmap.h>
20
 
#include <qpntarry.h>
21
 
#include <qapp.h>
22
 
#include <qsocknot.h>
23
 
#include <qpopmenu.h>
24
 
#include <qlabel.h>
25
 
#include <qlayout.h>
26
 
#include <qkeycode.h>
27
 
#include <qtimer.h>
28
 
#include <qbttngrp.h>
29
 
#include <qfiledlg.h>
30
 
#include <qstrlist.h>
31
 
#include <qmsgbox.h>
32
 
 
33
 
#include <stdio.h>
34
 
#include <stdlib.h>
35
 
#include <math.h>
36
 
 
37
 
#include "qtai_meter.h"
38
 
 
39
 
#define FACTOR 1
40
 
 
41
 
AIMeter::AIMeter(QWidget *parent,const char *name,int n)
42
 
  : AIBar(parent,name,n)
43
 
{
44
 
  int i;
45
 
 
46
 
  for (i=0;i<8;i++) {
47
 
    color[i].setRgb( 0, 164, 0 );               
48
 
  }
49
 
 
50
 
  setType(AI_METER_LEVEL);
51
 
}
52
 
 
53
 
void AIMeter::drawGrid( QPainter *p )
54
 
{
55
 
  int w=width()*FACTOR,h=height()*FACTOR;
56
 
  QString str="";
57
 
  QWMatrix matrix;
58
 
  QWMatrix zmatrix;
59
 
  QFont font("Helvetica",10);
60
 
  QFontMetrics fm(font);
61
 
  double   azero;
62
 
  int      i;
63
 
 
64
 
  p->setFont(font);
65
 
  p->setPen(c_grid);
66
 
  p->setWindow(0,0,w,h);                // defines coordinate system
67
 
 
68
 
  azero=(0-min)*(amax-amin)/(max-min)+amin;
69
 
  zmatrix.translate( zx, zy );  // move to center
70
 
  zmatrix.rotate(270+azero);
71
 
  p->setWorldMatrix( zmatrix );         // use this world matrix
72
 
 
73
 
  str.sprintf("%.2f",0.0);
74
 
  p->drawText(-fm.width(str)/2,-rs-10,str);
75
 
 
76
 
  matrix.translate( zx, zy );   // move to center
77
 
  matrix.rotate(270+amin);
78
 
 
79
 
  for (i=0;i<=scale_tile;i++) {
80
 
 
81
 
    p->setWorldMatrix( matrix );        // use this world matrix
82
 
    p->drawLine(0,-r,0,-rs);
83
 
 
84
 
    if (i==0 || i==scale_tile) {
85
 
      str.sprintf("%.2f",i*(max-min)/scale_tile+min);
86
 
      p->drawText(-fm.width(str)/2,-rs-10,str);
87
 
    }
88
 
 
89
 
    matrix.rotate((amax-amin)/scale_tile);
90
 
  }
91
 
}
92
 
 
93
 
void AIMeter::drawIt( QPainter *p )
94
 
{
95
 
  QPoint   qp(0,0);
96
 
  QWMatrix matrix,pmatrix;
97
 
  int      w=width()*FACTOR;
98
 
  int      h=height()*FACTOR;
99
 
  QFont    font("Helvetica",10);
100
 
  QFontMetrics fm(font);
101
 
  int      i;
102
 
  double   aact;
103
 
  QString str="";
104
 
 
105
 
  zx=(int)(fzx*w);
106
 
  zy=(int)(fzy*h);
107
 
  r=(int)(fr*h);
108
 
  rs=(int)(fr*h+10);
109
 
 
110
 
  QPainter tmp; // for double buffering
111
 
  QPixmap  pix(width(),height());
112
 
 
113
 
  tmp.begin( &pix );
114
 
 
115
 
  tmp.setWindow(0,0,w,h);       // defines coordinate system
116
 
int    n;
117
 
 
118
 
  static int     bw=-1,bh=-1; // BG Buffer
119
 
  static QPixmap *bg_buf=NULL;
120
 
  QPainter bg_p;
121
 
  QColor   c;
122
 
 
123
 
#define SHADE_BG
124
 
#ifdef SHADE_BG
125
 
  if (bh!=h || bw!=w || bg_buf==NULL) {
126
 
    delete bg_buf;
127
 
    bg_buf=new QPixmap(w,h);
128
 
 
129
 
    bg_p.begin( bg_buf );                       // begin painting
130
 
 
131
 
    float step=100.0/(double)h;
132
 
    float colval=150.0;
133
 
 
134
 
    // Must be buffered !!!
135
 
    for (n=0;n<h;n++) {
136
 
      c.setRgb(64,64,(int)colval);
137
 
      colval+=step;
138
 
      bg_p.setPen(c);
139
 
      bg_p.drawLine(0,n,w,n);
140
 
    }
141
 
 
142
 
    bg_p.end();                         // painting done
143
 
 
144
 
  }
145
 
 
146
 
  tmp.drawPixmap(qp,*bg_buf);
147
 
#else
148
 
  // 1999-05-23 UL, disabled, enabled
149
 
  tmp.fillRect(0,0,w,h,c_bg);
150
 
#endif
151
 
  //tmp.fillRect(0,0,w,h,c_bg);
152
 
 
153
 
  tmp.setPen(c_grid);
154
 
 
155
 
  drawGrid(&tmp);
156
 
 
157
 
  pmatrix.translate(0,0);                       // move to center
158
 
  tmp.setWorldMatrix( pmatrix );                // use this world matrix
159
 
 
160
 
  tmp.setFont(font);
161
 
  tmp.setPen(c_comm);
162
 
 
163
 
  tmp.drawText(w-(fm.width(range_s)+10),fm.height(),range_s);
164
 
 
165
 
  for (i=0;i<nbars;i++) {
166
 
    tmp.setWorldMatrix( pmatrix );              // use this world matrix
167
 
 
168
 
    tmp.setPen(color[i]);
169
 
    str.sprintf("%.2f",actual[i]);
170
 
    tmp.drawText(10,(i+1)*fm.height(),str);
171
 
 
172
 
    aact=(actual[i]-min)*(amax-amin)/(max-min)+amin;
173
 
    matrix.translate( zx, zy );                 // move to center
174
 
    matrix.rotate(270+aact);
175
 
    tmp.setWorldMatrix( matrix );               // use this world matrix
176
 
 
177
 
    // draw data scale
178
 
    tmp.drawLine(-2,0,0,-r);
179
 
    //tmp.drawLine(0,0,0,-r);
180
 
    tmp.drawLine(2,0,0,-r);
181
 
  }
182
 
 
183
 
  p->drawPixmap(qp,pix);
184
 
 
185
 
  tmp.end();
186
 
}
187
 
 
188
 
void AIMeter::setType(int type)
189
 
{
190
 
  switch(type) {
191
 
  case AI_METER_LEVEL:
192
 
    // Type Level Meter
193
 
    amin=60;
194
 
    amax=120;
195
 
    fzx=0.5f,fzy=1.3f,fr=0.8f;
196
 
    break;
197
 
  case AI_METER_TACHO:
198
 
    // Type Tachometer
199
 
    amin=-40;
200
 
    amax=220;
201
 
    fzx=0.5f,fzy=0.5f,fr=0.3f;
202
 
    break;
203
 
  }
204
 
}
205
 
#include "qtai_meter.moc"