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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2009-04-12 23:25:58 UTC
  • mfrom: (1.1.4 upstream) (2.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090412232558-3bl06x785yr8xm8u
Tags: 5.1.2-1
* New upstream release.
* Bump compat/debhelper to 7.
* Bump Standards-Version to 3.8.1. No changes needed.
* Invert Maintainers and Uploaders field.
* Fix lintian warnings:
  - dh_clean _k deprecated.
  - missing dependency on libc.

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