~ubuntu-branches/ubuntu/oneiric/qwt/oneiric-proposed

« back to all changes in this revision

Viewing changes to qwt-5.1.0/src/qwt_thermo.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2008-05-26 10:26:31 UTC
  • mfrom: (1.1.3 upstream) (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526102631-bp95mfccnrb957nx
Tags: 5.1.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2
 
 * Qwt Widget Library
3
 
 * Copyright (C) 1997   Josef Wilgen
4
 
 * Copyright (C) 2002   Uwe Rathmann
5
 
 *
6
 
 * This library is free software; you can redistribute it and/or
7
 
 * modify it under the terms of the Qwt License, Version 1.0
8
 
 *****************************************************************************/
9
 
 
10
 
#include <qpainter.h>
11
 
#include <qevent.h>
12
 
#include <qstyle.h>
13
 
#include <qpixmap.h>
14
 
#include <qdrawutil.h>
15
 
#include "qwt_math.h"
16
 
#include "qwt_scale_engine.h"
17
 
#include "qwt_scale_draw.h"
18
 
#include "qwt_scale_map.h"
19
 
#include "qwt_paint_buffer.h"
20
 
#include "qwt_thermo.h"
21
 
 
22
 
class QwtThermo::PrivateData
23
 
{
24
 
public:
25
 
    PrivateData():
26
 
        fillBrush(Qt::black),
27
 
        alarmBrush(Qt::white),
28
 
        orientation(Qt::Vertical),
29
 
        scalePos(QwtThermo::LeftScale),
30
 
        borderWidth(2),
31
 
        scaleDist(3),
32
 
        thermoWidth(10),
33
 
        minValue(0.0),
34
 
        maxValue(1.0),
35
 
        value(0.0),
36
 
        alarmLevel(0.0),
37
 
        alarmEnabled(false)
38
 
    {
39
 
        map.setScaleInterval(minValue, maxValue);
40
 
    }
41
 
 
42
 
    QwtScaleMap map;
43
 
    QRect thermoRect;
44
 
    QBrush fillBrush;
45
 
    QBrush alarmBrush;
46
 
 
47
 
    Qt::Orientation orientation;
48
 
    ScalePos scalePos;
49
 
    int borderWidth;
50
 
    int scaleDist;
51
 
    int thermoWidth;
52
 
 
53
 
    double minValue;
54
 
    double maxValue;
55
 
    double value;
56
 
    double alarmLevel;
57
 
    bool alarmEnabled;
58
 
};
59
 
 
60
 
/*! 
61
 
  Constructor
62
 
  \param parent Parent widget
63
 
*/
64
 
QwtThermo::QwtThermo(QWidget *parent): 
65
 
    QWidget(parent)
66
 
{
67
 
    initThermo();
68
 
}
69
 
 
70
 
#if QT_VERSION < 0x040000
71
 
/*! 
72
 
  Constructor
73
 
  \param parent Parent widget
74
 
  \param name Object name
75
 
*/
76
 
QwtThermo::QwtThermo(QWidget *parent, const char *name): 
77
 
    QWidget(parent, name)
78
 
{
79
 
    initThermo();
80
 
}
81
 
#endif
82
 
 
83
 
void QwtThermo::initThermo()
84
 
{
85
 
#if QT_VERSION < 0x040000
86
 
    setWFlags(Qt::WNoAutoErase);
87
 
#endif
88
 
    d_data = new PrivateData;
89
 
    setRange(d_data->minValue, d_data->maxValue, false);
90
 
 
91
 
    QSizePolicy policy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
92
 
    if (d_data->orientation == Qt::Vertical) 
93
 
        policy.transpose();
94
 
 
95
 
    setSizePolicy(policy);
96
 
    
97
 
#if QT_VERSION >= 0x040000
98
 
    setAttribute(Qt::WA_WState_OwnSizePolicy, false);
99
 
#else
100
 
    clearWState( WState_OwnSizePolicy );
101
 
#endif
102
 
}
103
 
 
104
 
//! Destructor
105
 
QwtThermo::~QwtThermo()
106
 
{
107
 
    delete d_data;
108
 
}
109
 
 
110
 
//! Set the maximum value.
111
 
void QwtThermo::setMaxValue(double v) 
112
 
113
 
    setRange(d_data->minValue, v); 
114
 
}
115
 
 
116
 
//! Return the maximum value.
117
 
double QwtThermo::maxValue() const 
118
 
119
 
    return d_data->maxValue; 
120
 
}
121
 
 
122
 
//! Set the minimum value.
123
 
void QwtThermo::setMinValue(double v) 
124
 
125
 
    setRange(v, d_data->maxValue); 
126
 
}
127
 
 
128
 
//! Return the minimum value.
129
 
double QwtThermo::minValue() const 
130
 
131
 
    return d_data->minValue; 
132
 
}
133
 
 
134
 
//! Set the current value.
135
 
void QwtThermo::setValue(double v)
136
 
{
137
 
    if (d_data->value != v)
138
 
    {
139
 
        d_data->value = v;
140
 
        update();
141
 
    }
142
 
}
143
 
 
144
 
//! Return the value.
145
 
double QwtThermo::value() const 
146
 
147
 
    return d_data->value; 
148
 
}
149
 
 
150
 
void QwtThermo::setScaleDraw(QwtScaleDraw *scaleDraw)
151
 
{
152
 
    setAbstractScaleDraw(scaleDraw);
153
 
}
154
 
 
155
 
const QwtScaleDraw *QwtThermo::scaleDraw() const
156
 
{
157
 
    return (QwtScaleDraw *)abstractScaleDraw();
158
 
}
159
 
 
160
 
QwtScaleDraw *QwtThermo::scaleDraw() 
161
 
{
162
 
    return (QwtScaleDraw *)abstractScaleDraw();
163
 
}
164
 
 
165
 
//! Qt paint event.
166
 
void QwtThermo::paintEvent(QPaintEvent *e)
167
 
{
168
 
    // Use double-buffering
169
 
    const QRect &ur = e->rect();
170
 
    if ( ur.isValid() )
171
 
    {
172
 
#if QT_VERSION < 0x040000
173
 
        QwtPaintBuffer paintBuffer(this, ur);
174
 
        draw(paintBuffer.painter(), ur);
175
 
#else
176
 
        QPainter painter(this);
177
 
        draw(&painter, ur);
178
 
#endif
179
 
    }
180
 
}
181
 
 
182
 
//! Draw the whole QwtThermo.
183
 
void QwtThermo::draw(QPainter *p, const QRect& ur)
184
 
{
185
 
    if ( !d_data->thermoRect.contains(ur) )
186
 
    {
187
 
        if (d_data->scalePos != NoScale)
188
 
        {
189
 
#if QT_VERSION < 0x040000
190
 
            scaleDraw()->draw(p, colorGroup());
191
 
#else
192
 
            scaleDraw()->draw(p, palette());
193
 
#endif
194
 
        }
195
 
 
196
 
        qDrawShadePanel(p,
197
 
            d_data->thermoRect.x() - d_data->borderWidth,
198
 
            d_data->thermoRect.y() - d_data->borderWidth,
199
 
            d_data->thermoRect.width() + 2*d_data->borderWidth,
200
 
            d_data->thermoRect.height() + 2*d_data->borderWidth,
201
 
#if QT_VERSION < 0x040000
202
 
            colorGroup(), 
203
 
#else
204
 
            palette(), 
205
 
#endif
206
 
            true, d_data->borderWidth,0);
207
 
    }
208
 
    drawThermo(p);
209
 
}
210
 
 
211
 
//! Qt resize event handler
212
 
void QwtThermo::resizeEvent(QResizeEvent *)
213
 
{
214
 
    layoutThermo( false );
215
 
}
216
 
 
217
 
/*!
218
 
  Recalculate the QwtThermo geometry and layout based on
219
 
  the QwtThermo::rect() and the fonts.
220
 
  \param update_geometry notify the layout system and call update
221
 
         to redraw the scale
222
 
*/
223
 
void QwtThermo::layoutThermo( bool update_geometry )
224
 
{
225
 
    QRect r = rect();
226
 
    int mbd = 0;
227
 
    if ( d_data->scalePos != NoScale )
228
 
    {
229
 
        int d1, d2;
230
 
        scaleDraw()->getBorderDistHint(font(), d1, d2);
231
 
        mbd = qwtMax(d1, d2);
232
 
    }
233
 
 
234
 
    if ( d_data->orientation == Qt::Horizontal )
235
 
    {
236
 
        switch ( d_data->scalePos )
237
 
        {
238
 
            case TopScale:
239
 
            {
240
 
                d_data->thermoRect.setRect(
241
 
                    r.x() + mbd + d_data->borderWidth,
242
 
                    r.y() + r.height()
243
 
                    - d_data->thermoWidth - 2*d_data->borderWidth,
244
 
                    r.width() - 2*(d_data->borderWidth + mbd),
245
 
                    d_data->thermoWidth);
246
 
                scaleDraw()->setAlignment(QwtScaleDraw::TopScale);
247
 
                scaleDraw()->move( d_data->thermoRect.x(),
248
 
                    d_data->thermoRect.y() - d_data->borderWidth 
249
 
                        - d_data->scaleDist);
250
 
                scaleDraw()->setLength(d_data->thermoRect.width());
251
 
                break;
252
 
            }
253
 
 
254
 
            case BottomScale:
255
 
            case NoScale: // like Bottom but without scale
256
 
            default:   // inconsistent orientation and scale position
257
 
                       // Mapping between values and pixels requires
258
 
                       // initialization of the scale geometry
259
 
            {
260
 
                d_data->thermoRect.setRect(
261
 
                    r.x() + mbd + d_data->borderWidth,
262
 
                    r.y() + d_data->borderWidth,
263
 
                    r.width() - 2*(d_data->borderWidth + mbd),
264
 
                    d_data->thermoWidth);
265
 
                scaleDraw()->setAlignment(QwtScaleDraw::BottomScale);
266
 
                scaleDraw()->move(
267
 
                    d_data->thermoRect.x(),
268
 
                    d_data->thermoRect.y() + d_data->thermoRect.height()
269
 
                        + d_data->borderWidth + d_data->scaleDist );
270
 
                scaleDraw()->setLength(d_data->thermoRect.width());
271
 
                break;
272
 
            }
273
 
        }
274
 
        d_data->map.setPaintInterval(d_data->thermoRect.x(),
275
 
            d_data->thermoRect.x() + d_data->thermoRect.width() - 1);
276
 
    }
277
 
    else // Qt::Vertical
278
 
    {
279
 
        switch ( d_data->scalePos )
280
 
        {
281
 
            case RightScale:
282
 
            {
283
 
                d_data->thermoRect.setRect(
284
 
                    r.x() + d_data->borderWidth,
285
 
                    r.y() + mbd + d_data->borderWidth,
286
 
                    d_data->thermoWidth,
287
 
                    r.height() - 2*(d_data->borderWidth + mbd));
288
 
                scaleDraw()->setAlignment(QwtScaleDraw::RightScale);
289
 
                scaleDraw()->move(
290
 
                    d_data->thermoRect.x() + d_data->thermoRect.width()
291
 
                        + d_data->borderWidth + d_data->scaleDist,
292
 
                    d_data->thermoRect.y());
293
 
                scaleDraw()->setLength(d_data->thermoRect.height());
294
 
                break;
295
 
            }
296
 
 
297
 
            case LeftScale:
298
 
            case NoScale: // like Left but without scale
299
 
            default:   // inconsistent orientation and scale position
300
 
                       // Mapping between values and pixels requires
301
 
                       // initialization of the scale geometry
302
 
            {
303
 
                d_data->thermoRect.setRect(
304
 
                    r.x() + r.width() - 2*d_data->borderWidth - d_data->thermoWidth,
305
 
                    r.y() + mbd + d_data->borderWidth,
306
 
                    d_data->thermoWidth,
307
 
                    r.height() - 2*(d_data->borderWidth + mbd));
308
 
                scaleDraw()->setAlignment(QwtScaleDraw::LeftScale);
309
 
                scaleDraw()->move(
310
 
                    d_data->thermoRect.x() - d_data->scaleDist 
311
 
                        - d_data->borderWidth,
312
 
                    d_data->thermoRect.y() );
313
 
                scaleDraw()->setLength(d_data->thermoRect.height());
314
 
                break;
315
 
            }
316
 
        }
317
 
        d_data->map.setPaintInterval(
318
 
            d_data->thermoRect.y() + d_data->thermoRect.height() - 1,
319
 
            d_data->thermoRect.y());
320
 
    }
321
 
    if ( update_geometry )
322
 
    {
323
 
        updateGeometry();
324
 
        update();
325
 
    }
326
 
}
327
 
 
328
 
/*!
329
 
  \brief Set the thermometer orientation and the scale position.
330
 
 
331
 
  The scale position NoScale disables the scale.
332
 
  \param o orientation. Possible values are Qt::Horizontal and Qt::Vertical.
333
 
         The default value is Qt::Vertical.
334
 
  \param s Position of the scale.
335
 
         The default value is NoScale.
336
 
 
337
 
  A valid combination of scale position and orientation is enforced:
338
 
  - a horizontal thermometer can have the scale positions TopScale, 
339
 
    BottomScale or NoScale;
340
 
  - a vertical thermometer can have the scale positions LeftScale, 
341
 
    RightScale or NoScale;
342
 
  - an invalid scale position will default to NoScale.
343
 
 
344
 
  \sa QwtThermo::setScalePosition()
345
 
*/
346
 
void QwtThermo::setOrientation(Qt::Orientation o, ScalePos s)
347
 
{
348
 
    if ( o == d_data->orientation && s == d_data->scalePos )
349
 
        return;
350
 
 
351
 
    switch(o)
352
 
    {
353
 
        case Qt::Horizontal:
354
 
        {
355
 
            if ((s == NoScale) || (s == BottomScale) || (s == TopScale))
356
 
                d_data->scalePos = s;
357
 
            else
358
 
                d_data->scalePos = NoScale;
359
 
            break;
360
 
        }
361
 
        case Qt::Vertical:
362
 
        {
363
 
            if ((s == NoScale) || (s == LeftScale) || (s == RightScale))
364
 
                d_data->scalePos = s;
365
 
            else
366
 
                d_data->scalePos = NoScale;
367
 
            break;
368
 
        }
369
 
    }
370
 
 
371
 
    if ( o != d_data->orientation )
372
 
    {
373
 
#if QT_VERSION >= 0x040000
374
 
        if ( !testAttribute(Qt::WA_WState_OwnSizePolicy) )
375
 
#else
376
 
        if ( !testWState( WState_OwnSizePolicy ) )
377
 
#endif
378
 
        {
379
 
            QSizePolicy sp = sizePolicy();
380
 
            sp.transpose();
381
 
            setSizePolicy(sp);
382
 
 
383
 
#if QT_VERSION >= 0x040000
384
 
            setAttribute(Qt::WA_WState_OwnSizePolicy, false);
385
 
#else
386
 
            clearWState( WState_OwnSizePolicy );
387
 
#endif
388
 
        }
389
 
    }
390
 
 
391
 
    d_data->orientation = o;
392
 
    layoutThermo();
393
 
}
394
 
 
395
 
/*!
396
 
  \brief Change the scale position (and thermometer orientation).
397
 
 
398
 
  \param s Position of the scale.
399
 
  
400
 
  A valid combination of scale position and orientation is enforced:
401
 
  - if the new scale position is LeftScale or RightScale, the 
402
 
    scale orientation will become Qt::Vertical;
403
 
  - if the new scale position is BottomScale or TopScale, the scale 
404
 
    orientation will become Qt::Horizontal;
405
 
  - if the new scale position is NoScale, the scale orientation will not change.
406
 
 
407
 
  \sa QwtThermo::setOrientation()
408
 
*/
409
 
void QwtThermo::setScalePosition(ScalePos s)
410
 
{
411
 
    if ((s == BottomScale) || (s == TopScale))
412
 
        setOrientation(Qt::Horizontal, s);
413
 
    else if ((s == LeftScale) || (s == RightScale))
414
 
        setOrientation(Qt::Vertical, s);
415
 
    else
416
 
        setOrientation(d_data->orientation, NoScale);
417
 
}
418
 
 
419
 
//! Return the scale position.
420
 
QwtThermo::ScalePos QwtThermo::scalePosition() const
421
 
{
422
 
    return d_data->scalePos;
423
 
}
424
 
 
425
 
//! Notify a font change.
426
 
void QwtThermo::fontChange(const QFont &f)
427
 
{
428
 
    QWidget::fontChange( f );
429
 
    layoutThermo();
430
 
}
431
 
 
432
 
//! Notify a scale change.
433
 
void QwtThermo::scaleChange()
434
 
{
435
 
    update();
436
 
    layoutThermo();
437
 
}
438
 
 
439
 
//! Redraw the liquid in thermometer pipe.
440
 
void QwtThermo::drawThermo(QPainter *p)
441
 
{
442
 
    int alarm  = 0, taval = 0;
443
 
 
444
 
    QRect fRect;
445
 
    QRect aRect;
446
 
    QRect bRect;
447
 
 
448
 
    int inverted = ( d_data->maxValue < d_data->minValue );
449
 
 
450
 
    //
451
 
    //  Determine if value exceeds alarm threshold.
452
 
    //  Note: The alarm value is allowed to lie
453
 
    //        outside the interval (minValue, maxValue).
454
 
    //
455
 
    if (d_data->alarmEnabled)
456
 
    {
457
 
        if (inverted)
458
 
        {
459
 
            alarm = ((d_data->alarmLevel >= d_data->maxValue)
460
 
                 && (d_data->alarmLevel <= d_data->minValue)
461
 
                 && (d_data->value >= d_data->alarmLevel));
462
 
        
463
 
        }
464
 
        else
465
 
        {
466
 
            alarm = (( d_data->alarmLevel >= d_data->minValue)
467
 
                 && (d_data->alarmLevel <= d_data->maxValue)
468
 
                 && (d_data->value >= d_data->alarmLevel));
469
 
        }
470
 
    }
471
 
 
472
 
    //
473
 
    //  transform values
474
 
    //
475
 
    int tval = transform(d_data->value);
476
 
 
477
 
    if (alarm)
478
 
       taval = transform(d_data->alarmLevel);
479
 
 
480
 
    //
481
 
    //  calculate recangles
482
 
    //
483
 
    if ( d_data->orientation == Qt::Horizontal )
484
 
    {
485
 
        if (inverted)
486
 
        {
487
 
            bRect.setRect(d_data->thermoRect.x(), d_data->thermoRect.y(),
488
 
                  tval - d_data->thermoRect.x(),
489
 
                  d_data->thermoRect.height());
490
 
        
491
 
            if (alarm)
492
 
            {
493
 
                aRect.setRect(tval, d_data->thermoRect.y(),
494
 
                      taval - tval + 1,
495
 
                      d_data->thermoRect.height());
496
 
                fRect.setRect(taval + 1, d_data->thermoRect.y(),
497
 
                      d_data->thermoRect.x() + d_data->thermoRect.width() - (taval + 1),
498
 
                      d_data->thermoRect.height());
499
 
            }
500
 
            else
501
 
            {
502
 
                fRect.setRect(tval, d_data->thermoRect.y(),
503
 
                      d_data->thermoRect.x() + d_data->thermoRect.width() - tval,
504
 
                      d_data->thermoRect.height());
505
 
            }
506
 
        }
507
 
        else
508
 
        {
509
 
            bRect.setRect(tval + 1, d_data->thermoRect.y(),
510
 
                  d_data->thermoRect.width() - (tval + 1 - d_data->thermoRect.x()),
511
 
                  d_data->thermoRect.height());
512
 
        
513
 
            if (alarm)
514
 
            {
515
 
                aRect.setRect(taval, d_data->thermoRect.y(),
516
 
                      tval - taval + 1,
517
 
                      d_data->thermoRect.height());
518
 
                fRect.setRect(d_data->thermoRect.x(), d_data->thermoRect.y(),
519
 
                      taval - d_data->thermoRect.x(),
520
 
                      d_data->thermoRect.height());
521
 
            }
522
 
            else
523
 
            {
524
 
                fRect.setRect(d_data->thermoRect.x(), d_data->thermoRect.y(),
525
 
                      tval - d_data->thermoRect.x() + 1,
526
 
                      d_data->thermoRect.height());
527
 
            }
528
 
        
529
 
        }
530
 
    }
531
 
    else // Qt::Vertical
532
 
    {
533
 
        if (tval < d_data->thermoRect.y())
534
 
            tval = d_data->thermoRect.y();
535
 
        else 
536
 
        {
537
 
            if (tval > d_data->thermoRect.y() + d_data->thermoRect.height())
538
 
                tval = d_data->thermoRect.y() + d_data->thermoRect.height();
539
 
        }
540
 
 
541
 
        if (inverted)
542
 
        {
543
 
            bRect.setRect(d_data->thermoRect.x(), tval + 1,
544
 
            d_data->thermoRect.width(),
545
 
            d_data->thermoRect.height() - (tval + 1 - d_data->thermoRect.y()));
546
 
 
547
 
            if (alarm)
548
 
            {
549
 
                aRect.setRect(d_data->thermoRect.x(), taval,
550
 
                    d_data->thermoRect.width(),
551
 
                    tval - taval + 1);
552
 
                fRect.setRect(d_data->thermoRect.x(), d_data->thermoRect.y(),
553
 
                    d_data->thermoRect.width(),
554
 
                taval - d_data->thermoRect.y());
555
 
            }
556
 
            else
557
 
            {
558
 
                fRect.setRect(d_data->thermoRect.x(), d_data->thermoRect.y(),
559
 
                    d_data->thermoRect.width(),
560
 
                    tval - d_data->thermoRect.y() + 1);
561
 
            }
562
 
        }
563
 
        else
564
 
        {
565
 
            bRect.setRect(d_data->thermoRect.x(), d_data->thermoRect.y(),
566
 
            d_data->thermoRect.width(),
567
 
            tval - d_data->thermoRect.y());
568
 
            if (alarm)
569
 
            {
570
 
                aRect.setRect(d_data->thermoRect.x(),tval,
571
 
                    d_data->thermoRect.width(),
572
 
                    taval - tval + 1);
573
 
                fRect.setRect(d_data->thermoRect.x(),taval + 1,
574
 
                    d_data->thermoRect.width(),
575
 
                    d_data->thermoRect.y() + d_data->thermoRect.height() - (taval + 1));
576
 
            }
577
 
            else
578
 
            {
579
 
                fRect.setRect(d_data->thermoRect.x(),tval,
580
 
                    d_data->thermoRect.width(),
581
 
                d_data->thermoRect.y() + d_data->thermoRect.height() - tval);
582
 
            }
583
 
        }
584
 
    }
585
 
 
586
 
    //
587
 
    // paint thermometer
588
 
    //
589
 
    const QColor bgColor =
590
 
#if QT_VERSION < 0x040000
591
 
        colorGroup().color(QColorGroup::Background);
592
 
#else
593
 
        palette().color(QPalette::Background);
594
 
#endif
595
 
    p->fillRect(bRect, bgColor);
596
 
 
597
 
    if (alarm)
598
 
       p->fillRect(aRect, d_data->alarmBrush);
599
 
 
600
 
    p->fillRect(fRect, d_data->fillBrush);
601
 
}
602
 
 
603
 
//! Set the border width of the pipe.
604
 
void QwtThermo::setBorderWidth(int w)
605
 
{
606
 
    if ((w >= 0) && (w < (qwtMin(d_data->thermoRect.width(), 
607
 
        d_data->thermoRect.height()) + d_data->borderWidth) / 2  - 1))
608
 
    {
609
 
        d_data->borderWidth = w;
610
 
        layoutThermo();
611
 
    }
612
 
}
613
 
 
614
 
//! Return the border width of the thermometer pipe.
615
 
int QwtThermo::borderWidth() const
616
 
{
617
 
    return d_data->borderWidth;
618
 
}
619
 
 
620
 
/*!
621
 
  \brief Set the range
622
 
  \param vmin value corresponding lower or left end of the thermometer
623
 
  \param vmax value corresponding to the upper or right end of the thermometer
624
 
  \param logarithmic logarithmic mapping, true or false 
625
 
*/
626
 
void QwtThermo::setRange(double vmin, double vmax, bool logarithmic)
627
 
{
628
 
    d_data->minValue = vmin;
629
 
    d_data->maxValue = vmax;
630
 
 
631
 
    if ( logarithmic )
632
 
        setScaleEngine(new QwtLog10ScaleEngine);
633
 
    else
634
 
        setScaleEngine(new QwtLinearScaleEngine);
635
 
 
636
 
    /*
637
 
      There are two different maps, one for the scale, the other
638
 
      for the values. This is confusing and will be changed
639
 
      in the future. TODO ...
640
 
     */
641
 
 
642
 
    d_data->map.setTransformation(scaleEngine()->transformation());
643
 
    d_data->map.setScaleInterval(d_data->minValue, d_data->maxValue);
644
 
 
645
 
    if (autoScale())
646
 
        rescale(d_data->minValue, d_data->maxValue);
647
 
 
648
 
    layoutThermo();
649
 
}
650
 
 
651
 
/*!
652
 
  \brief Change the brush of the liquid.
653
 
  \param brush New brush. The default brush is solid black.
654
 
*/
655
 
void QwtThermo::setFillBrush(const QBrush& brush)
656
 
{
657
 
    d_data->fillBrush = brush;
658
 
    update();
659
 
}
660
 
 
661
 
//! Return the liquid brush.
662
 
const QBrush& QwtThermo::fillBrush() const
663
 
{
664
 
    return d_data->fillBrush;
665
 
}
666
 
 
667
 
/*!
668
 
  \brief Change the color of the liquid.
669
 
  \param c New color. The default color is black.
670
 
*/
671
 
void QwtThermo::setFillColor(const QColor &c)
672
 
{
673
 
    d_data->fillBrush.setColor(c);
674
 
    update();
675
 
}
676
 
 
677
 
//! Return the liquid color.
678
 
const QColor &QwtThermo::fillColor() const
679
 
{
680
 
    return d_data->fillBrush.color();
681
 
}
682
 
 
683
 
/*!
684
 
  \brief Specify the liquid brush above the alarm threshold
685
 
  \param brush New brush. The default is solid white.
686
 
*/
687
 
void QwtThermo::setAlarmBrush(const QBrush& brush)
688
 
{
689
 
    d_data->alarmBrush = brush;
690
 
    update();
691
 
}
692
 
 
693
 
//! Return the liquid brush above the alarm threshold.
694
 
const QBrush& QwtThermo::alarmBrush() const
695
 
{
696
 
    return d_data->alarmBrush;
697
 
}
698
 
 
699
 
/*!
700
 
  \brief Specify the liquid color above the alarm threshold
701
 
  \param c New color. The default is white.
702
 
*/
703
 
void QwtThermo::setAlarmColor(const QColor &c)
704
 
{
705
 
    d_data->alarmBrush.setColor(c);
706
 
    update();
707
 
}
708
 
 
709
 
//! Return the liquid color above the alarm threshold.
710
 
const QColor &QwtThermo::alarmColor() const
711
 
{
712
 
    return d_data->alarmBrush.color();
713
 
}
714
 
 
715
 
//! Specify the alarm threshold.
716
 
void QwtThermo::setAlarmLevel(double v)
717
 
{
718
 
    d_data->alarmLevel = v;
719
 
    d_data->alarmEnabled = 1;
720
 
    update();
721
 
}
722
 
 
723
 
//! Return the alarm threshold.
724
 
double QwtThermo::alarmLevel() const
725
 
{
726
 
    return d_data->alarmLevel;
727
 
}
728
 
 
729
 
//! Change the width of the pipe.
730
 
void QwtThermo::setPipeWidth(int w)
731
 
{
732
 
    if (w > 0)
733
 
    {
734
 
        d_data->thermoWidth = w;
735
 
        layoutThermo();
736
 
    }
737
 
}
738
 
 
739
 
//! Return the width of the pipe.
740
 
int QwtThermo::pipeWidth() const
741
 
{
742
 
    return d_data->thermoWidth;
743
 
}
744
 
 
745
 
 
746
 
/*!
747
 
  \brief Specify the distance between the pipe's endpoints
748
 
         and the widget's border
749
 
 
750
 
  The margin is used to leave some space for the scale
751
 
  labels. If a large font is used, it is advisable to
752
 
  adjust the margins.
753
 
  \param m New Margin. The default values are 10 for
754
 
           horizontal orientation and 20 for vertical
755
 
           orientation.
756
 
  \warning The margin has no effect if the scale is disabled.
757
 
  \warning This function is a NOOP because margins are determined
758
 
           automatically.
759
 
*/
760
 
void QwtThermo::setMargin(int)
761
 
{
762
 
}
763
 
 
764
 
 
765
 
/*!
766
 
  \brief Enable or disable the alarm threshold
767
 
  \param tf true (disabled) or false (enabled)
768
 
*/
769
 
void QwtThermo::setAlarmEnabled(bool tf)
770
 
{
771
 
    d_data->alarmEnabled = tf;
772
 
    update();
773
 
}
774
 
 
775
 
//! Return if the alarm threshold is enabled or disabled.
776
 
bool QwtThermo::alarmEnabled() const
777
 
{
778
 
    return d_data->alarmEnabled;
779
 
}
780
 
 
781
 
/*!
782
 
  \return the minimum size hint
783
 
  \sa QwtThermo::minimumSizeHint
784
 
*/
785
 
QSize QwtThermo::sizeHint() const
786
 
{
787
 
    return minimumSizeHint();
788
 
}
789
 
 
790
 
/*!
791
 
  \brief Return a minimum size hint
792
 
  \warning The return value depends on the font and the scale.
793
 
  \sa QwtThermo::sizeHint
794
 
*/
795
 
QSize QwtThermo::minimumSizeHint() const
796
 
{
797
 
    int w = 0, h = 0;
798
 
 
799
 
    if ( d_data->scalePos != NoScale )
800
 
    {
801
 
        const int sdExtent = scaleDraw()->extent( QPen(), font() );
802
 
        const int sdLength = scaleDraw()->minLength( QPen(), font() );
803
 
 
804
 
        w = sdLength;
805
 
        h = d_data->thermoWidth + sdExtent + 
806
 
            d_data->borderWidth + d_data->scaleDist;
807
 
 
808
 
    }
809
 
    else // no scale
810
 
    {
811
 
        w = 200;
812
 
        h = d_data->thermoWidth;
813
 
    }
814
 
 
815
 
    if ( d_data->orientation == Qt::Vertical )
816
 
        qSwap(w, h);
817
 
 
818
 
    w += 2 * d_data->borderWidth;
819
 
    h += 2 * d_data->borderWidth;
820
 
 
821
 
    return QSize( w, h );
822
 
}
823
 
 
824
 
int QwtThermo::transform(double value) const
825
 
{
826
 
    const double min = qwtMin(d_data->map.s1(), d_data->map.s2());
827
 
    const double max = qwtMax(d_data->map.s1(), d_data->map.s2());
828
 
 
829
 
    if ( value > max )
830
 
        value = max;
831
 
    if ( value < min )
832
 
        value = min;
833
 
 
834
 
    return d_data->map.transform(value);
835
 
}