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

« back to all changes in this revision

Viewing changes to qwt-5.1.1/src/qwt_slider.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
 
// vim: expandtab
11
 
 
12
 
#include <math.h>
13
 
#include <qevent.h>
14
 
#include <qdrawutil.h>
15
 
#include <qpainter.h>
16
 
#include "qwt_painter.h"
17
 
#include "qwt_paint_buffer.h"
18
 
#include "qwt_scale_draw.h"
19
 
#include "qwt_scale_map.h"
20
 
#include "qwt_slider.h"
21
 
 
22
 
class QwtSlider::PrivateData
23
 
{
24
 
public:
25
 
    QRect sliderRect;
26
 
 
27
 
    int thumbLength;
28
 
    int thumbWidth;
29
 
    int borderWidth;
30
 
    int scaleDist;
31
 
    int xMargin;
32
 
    int yMargin;
33
 
 
34
 
    QwtSlider::ScalePos scalePos;
35
 
    QwtSlider::BGSTYLE bgStyle;
36
 
 
37
 
    /*
38
 
      Scale and values might have different maps. This is
39
 
      confusing and I can't see strong arguments for such
40
 
      a feature. TODO ...
41
 
     */
42
 
    QwtScaleMap map; // linear map
43
 
    mutable QSize sizeHintCache;
44
 
};
45
 
 
46
 
/*!
47
 
  \brief Constructor
48
 
  \param parent parent widget
49
 
  \param orientation Orientation of the slider. Can be Qt::Horizontal
50
 
         or Qt::Vertical. Defaults to Qt::Horizontal.
51
 
  \param scalePos Position of the scale.  
52
 
         Defaults to QwtSlider::NoScale.
53
 
  \param bgStyle Background style. QwtSlider::BgTrough draws the
54
 
         slider button in a trough, QwtSlider::BgSlot draws
55
 
         a slot underneath the button. An or-combination of both
56
 
         may also be used. The default is QwtSlider::BgTrough.
57
 
 
58
 
  QwtSlider enforces valid combinations of its orientation and scale position.
59
 
  If the combination is invalid, the scale position will be set to NoScale. 
60
 
  Valid combinations are:
61
 
  - Qt::Horizonal with NoScale, TopScale, or BottomScale;
62
 
  - Qt::Vertical with NoScale, LeftScale, or RightScale.
63
 
*/
64
 
QwtSlider::QwtSlider(QWidget *parent,
65
 
        Qt::Orientation orientation, ScalePos scalePos, BGSTYLE bgStyle): 
66
 
    QwtAbstractSlider(orientation, parent)
67
 
{
68
 
    initSlider(orientation, scalePos, bgStyle);
69
 
}
70
 
 
71
 
#if QT_VERSION < 0x040000
72
 
/*!
73
 
  \brief Constructor
74
 
 
75
 
  Build a horizontal slider with no scale and BgTrough as 
76
 
  background style
77
 
 
78
 
  \param parent parent widget
79
 
  \param name Object name
80
 
*/
81
 
QwtSlider::QwtSlider(QWidget *parent, const char* name):
82
 
    QwtAbstractSlider(Qt::Horizontal, parent)
83
 
{
84
 
    setName(name);
85
 
    initSlider(Qt::Horizontal, NoScale, BgTrough);
86
 
}
87
 
#endif
88
 
 
89
 
void QwtSlider::initSlider(Qt::Orientation orientation, 
90
 
    ScalePos scalePos, BGSTYLE bgStyle)
91
 
{
92
 
    if (orientation == Qt::Vertical) 
93
 
        setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
94
 
    else
95
 
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
96
 
 
97
 
#if QT_VERSION >= 0x040000
98
 
    setAttribute(Qt::WA_WState_OwnSizePolicy, false);
99
 
#else
100
 
    clearWState( WState_OwnSizePolicy );
101
 
#endif
102
 
 
103
 
 
104
 
#if QT_VERSION < 0x040000
105
 
    setWFlags(Qt::WNoAutoErase);
106
 
#endif
107
 
 
108
 
    d_data = new QwtSlider::PrivateData;
109
 
 
110
 
    d_data->borderWidth = 2;
111
 
    d_data->scaleDist = 4;
112
 
    d_data->scalePos = scalePos;
113
 
    d_data->xMargin = 0;
114
 
    d_data->yMargin = 0;
115
 
    d_data->bgStyle = bgStyle;
116
 
 
117
 
    if (bgStyle == BgSlot)
118
 
    {
119
 
        d_data->thumbLength = 16;
120
 
        d_data->thumbWidth = 30;
121
 
    }
122
 
    else
123
 
    {
124
 
        d_data->thumbLength = 31;
125
 
        d_data->thumbWidth = 16;
126
 
    }
127
 
 
128
 
    d_data->sliderRect.setRect(0,0,8,8);
129
 
 
130
 
    QwtScaleDraw::Alignment align;
131
 
    if ( orientation == Qt::Vertical )
132
 
    {
133
 
        // enforce a valid combination of scale position and orientation
134
 
        if ((d_data->scalePos == BottomScale) || (d_data->scalePos == TopScale))
135
 
            d_data->scalePos = NoScale;
136
 
        // adopt the policy of layoutSlider (NoScale lays out like Left)
137
 
        if (d_data->scalePos == RightScale)
138
 
           align = QwtScaleDraw::RightScale;
139
 
        else
140
 
           align = QwtScaleDraw::LeftScale;
141
 
    }
142
 
    else
143
 
    {
144
 
        // enforce a valid combination of scale position and orientation
145
 
        if ((d_data->scalePos == LeftScale) || (d_data->scalePos == RightScale))
146
 
            d_data->scalePos = NoScale;
147
 
        // adopt the policy of layoutSlider (NoScale lays out like Bottom)
148
 
        if (d_data->scalePos == TopScale)
149
 
           align = QwtScaleDraw::TopScale;
150
 
        else
151
 
           align = QwtScaleDraw::BottomScale;
152
 
    }
153
 
 
154
 
    scaleDraw()->setAlignment(align);
155
 
    scaleDraw()->setLength(100);
156
 
 
157
 
    setRange(0.0, 100.0, 1.0);
158
 
    setValue(0.0);
159
 
}
160
 
 
161
 
QwtSlider::~QwtSlider()
162
 
{
163
 
    delete d_data;
164
 
}
165
 
 
166
 
/*!
167
 
  \brief Set the orientation.
168
 
  \param o Orientation. Allowed values are Qt::Horizontal and Qt::Vertical.
169
 
  
170
 
  If the new orientation and the old scale position are an invalid combination,
171
 
  the scale position will be set to QwtSlider::NoScale.
172
 
  \sa QwtAbstractSlider::orientation()
173
 
*/
174
 
void QwtSlider::setOrientation(Qt::Orientation o) 
175
 
{
176
 
    if ( o == orientation() )
177
 
        return;
178
 
 
179
 
    if (o == Qt::Horizontal)
180
 
    {
181
 
        if ((d_data->scalePos == LeftScale) || (d_data->scalePos == RightScale))
182
 
            d_data->scalePos = NoScale;
183
 
    }
184
 
    else // if (o == Qt::Vertical)
185
 
    {
186
 
        if ((d_data->scalePos == BottomScale) || (d_data->scalePos == TopScale))
187
 
            d_data->scalePos = NoScale;
188
 
    }
189
 
 
190
 
#if QT_VERSION >= 0x040000
191
 
    if ( !testAttribute(Qt::WA_WState_OwnSizePolicy) )
192
 
#else
193
 
    if ( !testWState( WState_OwnSizePolicy ) ) 
194
 
#endif
195
 
    {
196
 
        QSizePolicy sp = sizePolicy();
197
 
        sp.transpose();
198
 
        setSizePolicy(sp);
199
 
 
200
 
#if QT_VERSION >= 0x040000
201
 
        setAttribute(Qt::WA_WState_OwnSizePolicy, false);
202
 
#else
203
 
        clearWState( WState_OwnSizePolicy );
204
 
#endif
205
 
    }
206
 
 
207
 
    QwtAbstractSlider::setOrientation(o);
208
 
    layoutSlider();
209
 
}
210
 
 
211
 
/*!
212
 
  \brief Change the scale position (and slider orientation).
213
 
 
214
 
  \param s Position of the scale.
215
 
 
216
 
  A valid combination of scale position and orientation is enforced:
217
 
  - if the new scale position is Left or Right, the scale orientation will
218
 
    become Qt::Vertical;
219
 
  - if the new scale position is Bottom or Top the scale orientation will
220
 
    become Qt::Horizontal;
221
 
  - if the new scale position is QwtSlider::NoScale, the scale 
222
 
    orientation will not change.
223
 
*/
224
 
void QwtSlider::setScalePosition(ScalePos s)
225
 
{
226
 
    if ( d_data->scalePos == s )
227
 
        return;
228
 
 
229
 
    d_data->scalePos = s;
230
 
 
231
 
    switch(d_data->scalePos)
232
 
    {
233
 
        case BottomScale:
234
 
        {
235
 
            setOrientation(Qt::Horizontal);
236
 
            scaleDraw()->setAlignment(QwtScaleDraw::BottomScale);
237
 
            break;
238
 
        }
239
 
        case TopScale:
240
 
        {
241
 
            setOrientation(Qt::Horizontal);
242
 
            scaleDraw()->setAlignment(QwtScaleDraw::TopScale);
243
 
            break;
244
 
        }
245
 
        case LeftScale:
246
 
        {
247
 
            setOrientation(Qt::Vertical);
248
 
            scaleDraw()->setAlignment(QwtScaleDraw::LeftScale);
249
 
            break;
250
 
        }
251
 
        case RightScale:
252
 
        {
253
 
            setOrientation(Qt::Vertical);
254
 
            scaleDraw()->setAlignment(QwtScaleDraw::RightScale);
255
 
            break;
256
 
        }
257
 
        default:
258
 
        {
259
 
            // nothing
260
 
        }
261
 
    }
262
 
 
263
 
    layoutSlider();
264
 
}
265
 
 
266
 
//! Return the scale position.
267
 
QwtSlider::ScalePos QwtSlider::scalePosition() const
268
 
{
269
 
    return d_data->scalePos;
270
 
}
271
 
 
272
 
/*!
273
 
  \brief Change the slider's border width
274
 
  \param bd border width
275
 
*/
276
 
void QwtSlider::setBorderWidth(int bd)
277
 
{
278
 
    if ( bd < 0 )
279
 
        bd = 0;
280
 
 
281
 
    if ( bd != d_data->borderWidth )
282
 
    {
283
 
        d_data->borderWidth = bd;
284
 
        layoutSlider();
285
 
    }
286
 
}
287
 
 
288
 
/*!
289
 
  \brief Set the slider's thumb length
290
 
  \param thumbLength new length
291
 
*/
292
 
void QwtSlider::setThumbLength(int thumbLength)
293
 
{
294
 
    if ( thumbLength < 8 )
295
 
        thumbLength = 8;
296
 
 
297
 
    if ( thumbLength != d_data->thumbLength )
298
 
    {
299
 
        d_data->thumbLength = thumbLength;
300
 
        layoutSlider();
301
 
    }
302
 
}
303
 
 
304
 
/*!
305
 
  \brief Change the width of the thumb
306
 
  \param w new width
307
 
*/
308
 
void QwtSlider::setThumbWidth(int w)
309
 
{
310
 
    if ( w < 4 )
311
 
        w = 4;
312
 
 
313
 
    if ( d_data->thumbWidth != w )
314
 
    {
315
 
        d_data->thumbWidth = w;
316
 
        layoutSlider();
317
 
    }
318
 
}
319
 
 
320
 
/*!
321
 
  \brief Set a scale draw
322
 
 
323
 
  For changing the labels of the scales, it
324
 
  is necessary to derive from QwtScaleDraw and
325
 
  overload QwtScaleDraw::label().
326
 
 
327
 
  \param scaleDraw ScaleDraw object, that has to be created with 
328
 
                   new and will be deleted in ~QwtSlider or the next 
329
 
                   call of setScaleDraw().
330
 
*/
331
 
void QwtSlider::setScaleDraw(QwtScaleDraw *scaleDraw)
332
 
{
333
 
    const QwtScaleDraw *previousScaleDraw = this->scaleDraw();
334
 
    if ( scaleDraw == NULL || scaleDraw == previousScaleDraw )
335
 
        return;
336
 
 
337
 
    if ( previousScaleDraw )
338
 
        scaleDraw->setAlignment(previousScaleDraw->alignment());
339
 
 
340
 
    setAbstractScaleDraw(scaleDraw);
341
 
    layoutSlider();
342
 
}
343
 
 
344
 
/*!
345
 
  \return the scale draw of the slider
346
 
  \sa setScaleDraw()
347
 
*/
348
 
const QwtScaleDraw *QwtSlider::scaleDraw() const
349
 
{
350
 
    return (QwtScaleDraw *)abstractScaleDraw();
351
 
}
352
 
 
353
 
/*!
354
 
  \return the scale draw of the slider
355
 
  \sa setScaleDraw()
356
 
*/
357
 
QwtScaleDraw *QwtSlider::scaleDraw()
358
 
{
359
 
    return (QwtScaleDraw *)abstractScaleDraw();
360
 
}
361
 
 
362
 
//! Notify changed scale
363
 
void QwtSlider::scaleChange()
364
 
{
365
 
    layoutSlider();
366
 
}
367
 
 
368
 
 
369
 
//! Notify change in font
370
 
void QwtSlider::fontChange(const QFont &f)
371
 
{
372
 
    QwtAbstractSlider::fontChange( f );
373
 
    layoutSlider();
374
 
}
375
 
 
376
 
//! Draw the slider into the specified rectangle.
377
 
void QwtSlider::drawSlider(QPainter *p, const QRect &r)
378
 
{
379
 
    QRect cr(r);
380
 
 
381
 
    if (d_data->bgStyle & BgTrough)
382
 
    {
383
 
        qDrawShadePanel(p, r.x(), r.y(),
384
 
            r.width(), r.height(),
385
 
#if QT_VERSION < 0x040000
386
 
            colorGroup(), 
387
 
#else
388
 
            palette(), 
389
 
#endif
390
 
            true, d_data->borderWidth,0);
391
 
 
392
 
        cr.setRect(r.x() + d_data->borderWidth,
393
 
            r.y() + d_data->borderWidth,
394
 
            r.width() - 2 * d_data->borderWidth,
395
 
            r.height() - 2 * d_data->borderWidth);
396
 
 
397
 
        p->fillRect(cr.x(), cr.y(), cr.width(), cr.height(), 
398
 
#if QT_VERSION < 0x040000
399
 
            colorGroup().brush(QColorGroup::Mid)
400
 
#else
401
 
            palette().brush(QPalette::Mid)
402
 
#endif
403
 
        );
404
 
    }
405
 
 
406
 
    if ( d_data->bgStyle & BgSlot)
407
 
    {
408
 
        int ws = 4;
409
 
        int ds = d_data->thumbLength / 2 - 4;
410
 
        if ( ds < 1 )
411
 
            ds = 1;
412
 
 
413
 
        QRect rSlot;
414
 
        if (orientation() == Qt::Horizontal)
415
 
        {
416
 
            if ( cr.height() & 1 )
417
 
                ws++;
418
 
            rSlot = QRect(cr.x() + ds, 
419
 
                    cr.y() + (cr.height() - ws) / 2,
420
 
                    cr.width() - 2 * ds, ws);
421
 
        }
422
 
        else
423
 
        {
424
 
            if ( cr.width() & 1 )
425
 
                ws++;
426
 
            rSlot = QRect(cr.x() + (cr.width() - ws) / 2, 
427
 
                    cr.y() + ds,
428
 
                    ws, cr.height() - 2 * ds);
429
 
        }
430
 
        p->fillRect(rSlot.x(), rSlot.y(), rSlot.width(), rSlot.height(),
431
 
#if QT_VERSION < 0x040000
432
 
            colorGroup().brush(QColorGroup::Dark)
433
 
#else
434
 
            palette().brush(QPalette::Dark)
435
 
#endif
436
 
        );
437
 
        qDrawShadePanel(p, rSlot.x(), rSlot.y(),
438
 
            rSlot.width(), rSlot.height(), 
439
 
#if QT_VERSION < 0x040000
440
 
            colorGroup(), 
441
 
#else
442
 
            palette(), 
443
 
#endif
444
 
            true, 1 ,0);
445
 
 
446
 
    }
447
 
 
448
 
    if ( isValid() )
449
 
        drawThumb(p, cr, xyPosition(value()));
450
 
}
451
 
 
452
 
//! Draw the thumb at a position
453
 
void QwtSlider::drawThumb(QPainter *p, const QRect &sliderRect, int pos)
454
 
{
455
 
    pos++; // shade line points one pixel below
456
 
    if (orientation() == Qt::Horizontal)
457
 
    {
458
 
        qDrawShadePanel(p, pos - d_data->thumbLength / 2, 
459
 
            sliderRect.y(), d_data->thumbLength, sliderRect.height(),
460
 
#if QT_VERSION < 0x040000
461
 
            colorGroup(), 
462
 
#else
463
 
            palette(), 
464
 
#endif
465
 
            false, d_data->borderWidth, 
466
 
#if QT_VERSION < 0x040000
467
 
            &colorGroup().brush(QColorGroup::Button)
468
 
#else
469
 
            &palette().brush(QPalette::Button)
470
 
#endif
471
 
        );
472
 
 
473
 
        qDrawShadeLine(p, pos, sliderRect.y(), 
474
 
            pos, sliderRect.y() + sliderRect.height() - 2, 
475
 
#if QT_VERSION < 0x040000
476
 
            colorGroup(), 
477
 
#else
478
 
            palette(), 
479
 
#endif
480
 
            true, 1);
481
 
    }
482
 
    else // Vertical
483
 
    {
484
 
        qDrawShadePanel(p,sliderRect.x(), pos - d_data->thumbLength / 2, 
485
 
            sliderRect.width(), d_data->thumbLength,
486
 
#if QT_VERSION < 0x040000
487
 
            colorGroup(),
488
 
#else
489
 
            palette(), 
490
 
#endif
491
 
            false, d_data->borderWidth, 
492
 
#if QT_VERSION < 0x040000
493
 
            &colorGroup().brush(QColorGroup::Button)
494
 
#else
495
 
            &palette().brush(QPalette::Button)
496
 
#endif
497
 
        );
498
 
 
499
 
        qDrawShadeLine(p, sliderRect.x(), pos,
500
 
            sliderRect.x() + sliderRect.width() - 2, pos, 
501
 
#if QT_VERSION < 0x040000
502
 
            colorGroup(), 
503
 
#else
504
 
            palette(), 
505
 
#endif
506
 
            true, 1);
507
 
    }
508
 
}
509
 
 
510
 
//! Find the x/y position for a given value v
511
 
int QwtSlider::xyPosition(double v) const
512
 
{
513
 
    return d_data->map.transform(v);
514
 
}
515
 
 
516
 
//! Determine the value corresponding to a specified mouse location.
517
 
double QwtSlider::getValue(const QPoint &p)
518
 
{
519
 
    return d_data->map.invTransform(
520
 
        orientation() == Qt::Horizontal ? p.x() : p.y());
521
 
}
522
 
 
523
 
 
524
 
/*!
525
 
  \brief Determine scrolling mode and direction
526
 
  \param p point
527
 
  \param scrollMode Scrolling mode
528
 
  \param direction Direction
529
 
*/
530
 
void QwtSlider::getScrollMode(const QPoint &p, 
531
 
    int &scrollMode, int &direction )
532
 
{
533
 
    if (!d_data->sliderRect.contains(p))
534
 
    {
535
 
        scrollMode = ScrNone;
536
 
        direction = 0;
537
 
        return;
538
 
    }
539
 
 
540
 
    const int pos = ( orientation() == Qt::Horizontal ) ? p.x() : p.y();
541
 
    const int markerPos = xyPosition(value());
542
 
 
543
 
    if ((pos > markerPos - d_data->thumbLength / 2)
544
 
        && (pos < markerPos + d_data->thumbLength / 2))
545
 
    {
546
 
        scrollMode = ScrMouse;
547
 
        direction = 0;
548
 
        return;
549
 
    }
550
 
 
551
 
    scrollMode = ScrPage;
552
 
    direction = (pos > markerPos) ? 1 : -1;
553
 
 
554
 
    if ( scaleDraw()->map().p1() > scaleDraw()->map().p2() )
555
 
        direction = -direction;
556
 
}
557
 
 
558
 
//! Qt paint event
559
 
void QwtSlider::paintEvent(QPaintEvent *e)
560
 
{
561
 
    const QRect &ur = e->rect();
562
 
    if ( ur.isValid() )
563
 
    {
564
 
#if QT_VERSION < 0x040000
565
 
        QwtPaintBuffer paintBuffer(this, ur);
566
 
        draw(paintBuffer.painter(), ur);
567
 
#else
568
 
        QPainter painter(this);
569
 
        draw(&painter, ur);
570
 
#endif
571
 
    }
572
 
}
573
 
 
574
 
//! Draw the QwtSlider
575
 
void QwtSlider::draw(QPainter *painter, const QRect&)
576
 
{
577
 
    if (d_data->scalePos != NoScale)
578
 
    {
579
 
#if QT_VERSION < 0x040000
580
 
        scaleDraw()->draw(painter, colorGroup());
581
 
#else
582
 
        scaleDraw()->draw(painter, palette());
583
 
#endif
584
 
    }
585
 
 
586
 
    drawSlider(painter, d_data->sliderRect);
587
 
 
588
 
    if ( hasFocus() )
589
 
        QwtPainter::drawFocusRect(painter, this, d_data->sliderRect);
590
 
}
591
 
 
592
 
//! Qt resize event
593
 
void QwtSlider::resizeEvent(QResizeEvent *)
594
 
{
595
 
    layoutSlider( false );
596
 
}
597
 
 
598
 
/*!
599
 
  Recalculate the slider's geometry and layout based on
600
 
  the current rect and fonts.
601
 
  \param update_geometry  notify the layout system and call update
602
 
         to redraw the scale
603
 
*/
604
 
void QwtSlider::layoutSlider( bool update_geometry )
605
 
{
606
 
    int sliderWidth = d_data->thumbWidth;
607
 
    int sld1 = d_data->thumbLength / 2 - 1;
608
 
    int sld2 = d_data->thumbLength / 2 + d_data->thumbLength % 2;
609
 
    if ( d_data->bgStyle & BgTrough )
610
 
    {
611
 
        sliderWidth += 2 * d_data->borderWidth;
612
 
        sld1 += d_data->borderWidth;
613
 
        sld2 += d_data->borderWidth;
614
 
    }
615
 
 
616
 
    int scd = 0;
617
 
    if ( d_data->scalePos != NoScale )
618
 
    {
619
 
        int d1, d2;
620
 
        scaleDraw()->getBorderDistHint(font(), d1, d2);
621
 
        scd = qwtMax(d1, d2);
622
 
    }
623
 
 
624
 
    int slo = scd - sld1;
625
 
    if ( slo < 0 )
626
 
        slo = 0;
627
 
 
628
 
    int x, y, length;
629
 
 
630
 
    const QRect r = rect();
631
 
    if (orientation() == Qt::Horizontal)
632
 
    {
633
 
        switch (d_data->scalePos)
634
 
        {
635
 
            case TopScale:
636
 
            {
637
 
                d_data->sliderRect.setRect(
638
 
                    r.x() + d_data->xMargin + slo,
639
 
                    r.y() + r.height() -
640
 
                    d_data->yMargin - sliderWidth,
641
 
                    r.width() - 2 * d_data->xMargin - 2 * slo,
642
 
                    sliderWidth);
643
 
 
644
 
                x = d_data->sliderRect.x() + sld1;
645
 
                y = d_data->sliderRect.y() - d_data->scaleDist;
646
 
 
647
 
                break;
648
 
            }
649
 
 
650
 
            case BottomScale:
651
 
            {
652
 
                d_data->sliderRect.setRect(
653
 
                    r.x() + d_data->xMargin + slo,
654
 
                    r.y() + d_data->yMargin,
655
 
                    r.width() - 2 * d_data->xMargin - 2 * slo,
656
 
                    sliderWidth);
657
 
    
658
 
                x = d_data->sliderRect.x() + sld1;
659
 
                y = d_data->sliderRect.y() + d_data->sliderRect.height() 
660
 
                    + d_data->scaleDist;
661
 
 
662
 
                break;
663
 
            }
664
 
 
665
 
            case NoScale: // like Bottom, but no scale. See QwtSlider().
666
 
            default:   // inconsistent orientation and scale position
667
 
            {
668
 
                d_data->sliderRect.setRect(
669
 
                    r.x() + d_data->xMargin + slo,
670
 
                    r.y() + d_data->yMargin,
671
 
                    r.width() - 2 * d_data->xMargin - 2 * slo,
672
 
                    sliderWidth);
673
 
 
674
 
                x = d_data->sliderRect.x() + sld1;
675
 
                y = 0;
676
 
 
677
 
                break;
678
 
            }
679
 
        }
680
 
        length = d_data->sliderRect.width() - (sld1 + sld2);
681
 
    }
682
 
    else // if (orientation() == Qt::Vertical
683
 
    {
684
 
        switch (d_data->scalePos)
685
 
        {
686
 
            case RightScale:
687
 
                d_data->sliderRect.setRect(
688
 
                    r.x() + d_data->xMargin,
689
 
                    r.y() + d_data->yMargin + slo,
690
 
                    sliderWidth,
691
 
                    r.height() - 2 * d_data->yMargin - 2 * slo);
692
 
 
693
 
                x = d_data->sliderRect.x() + d_data->sliderRect.width() 
694
 
                    + d_data->scaleDist;
695
 
                y = d_data->sliderRect.y() + sld1;
696
 
 
697
 
                break;
698
 
 
699
 
            case LeftScale:
700
 
                d_data->sliderRect.setRect(
701
 
                    r.x() + r.width() - sliderWidth - d_data->xMargin,
702
 
                    r.y() + d_data->yMargin + slo,
703
 
                    sliderWidth,
704
 
                    r.height() - 2 * d_data->yMargin - 2 * slo);
705
 
 
706
 
                x = d_data->sliderRect.x() - d_data->scaleDist;
707
 
                y = d_data->sliderRect.y() + sld1;
708
 
 
709
 
                break;
710
 
 
711
 
            case NoScale: // like Left, but no scale. See QwtSlider().
712
 
            default:   // inconsistent orientation and scale position
713
 
                d_data->sliderRect.setRect(
714
 
                    r.x() + r.width() - sliderWidth - d_data->xMargin,
715
 
                    r.y() + d_data->yMargin + slo,
716
 
                    sliderWidth,
717
 
                    r.height() - 2 * d_data->yMargin - 2 * slo);
718
 
 
719
 
                x = 0;
720
 
                y = d_data->sliderRect.y() + sld1;
721
 
 
722
 
                break;
723
 
        }
724
 
        length = d_data->sliderRect.height() - (sld1 + sld2);
725
 
    }
726
 
 
727
 
    scaleDraw()->move(x, y);
728
 
    scaleDraw()->setLength(length);
729
 
 
730
 
    d_data->map.setPaintXInterval(scaleDraw()->map().p1(),
731
 
        scaleDraw()->map().p2());
732
 
 
733
 
    if ( update_geometry )
734
 
    {
735
 
        d_data->sizeHintCache = QSize(); // invalidate
736
 
        updateGeometry();
737
 
        update();
738
 
    }
739
 
}
740
 
 
741
 
//! Notify change of value
742
 
void QwtSlider::valueChange()
743
 
{
744
 
    QwtAbstractSlider::valueChange();
745
 
    update();
746
 
}
747
 
 
748
 
 
749
 
//! Notify change of range
750
 
void QwtSlider::rangeChange()
751
 
{
752
 
    d_data->map.setScaleInterval(minValue(), maxValue());
753
 
 
754
 
    if (autoScale())
755
 
        rescale(minValue(), maxValue());
756
 
 
757
 
    QwtAbstractSlider::rangeChange();
758
 
    layoutSlider();
759
 
}
760
 
 
761
 
/*!
762
 
  \brief Set distances between the widget's border and internals.
763
 
  \param xMargin Horizontal margin
764
 
  \param yMargin Vertical margin
765
 
*/
766
 
void QwtSlider::setMargins(int xMargin, int yMargin)
767
 
{
768
 
    if ( xMargin < 0 )
769
 
        xMargin = 0;
770
 
    if ( yMargin < 0 )
771
 
        yMargin = 0;
772
 
 
773
 
    if ( xMargin != d_data->xMargin || yMargin != d_data->yMargin )
774
 
    {
775
 
        d_data->xMargin = xMargin;
776
 
        d_data->yMargin = yMargin;
777
 
        layoutSlider();
778
 
    }
779
 
}
780
 
 
781
 
/*!
782
 
  Set the background style.
783
 
*/
784
 
void QwtSlider::setBgStyle(BGSTYLE st) 
785
 
{
786
 
    d_data->bgStyle = st; 
787
 
    layoutSlider();
788
 
}
789
 
 
790
 
/*!
791
 
  \return the background style.
792
 
*/
793
 
QwtSlider::BGSTYLE QwtSlider::bgStyle() const 
794
 
795
 
    return d_data->bgStyle; 
796
 
}
797
 
 
798
 
/*!
799
 
  \return the thumb length.
800
 
*/
801
 
int QwtSlider::thumbLength() const 
802
 
{
803
 
    return d_data->thumbLength;
804
 
}
805
 
 
806
 
/*!
807
 
  \return the thumb width.
808
 
*/
809
 
int QwtSlider::thumbWidth() const 
810
 
{
811
 
    return d_data->thumbWidth;
812
 
}
813
 
 
814
 
/*!
815
 
  \return the border width.
816
 
*/
817
 
int QwtSlider::borderWidth() const 
818
 
{
819
 
    return d_data->borderWidth;
820
 
}
821
 
 
822
 
/*!
823
 
  \return QwtSlider::minimumSizeHint()
824
 
*/
825
 
QSize QwtSlider::sizeHint() const
826
 
{
827
 
    return minimumSizeHint();
828
 
}
829
 
 
830
 
/*!
831
 
  \brief Return a minimum size hint
832
 
  \warning The return value of QwtSlider::minimumSizeHint() depends on 
833
 
           the font and the scale.
834
 
*/
835
 
QSize QwtSlider::minimumSizeHint() const
836
 
{
837
 
    if (!d_data->sizeHintCache.isEmpty()) 
838
 
        return d_data->sizeHintCache;
839
 
 
840
 
    int sliderWidth = d_data->thumbWidth;
841
 
    if (d_data->bgStyle & BgTrough)
842
 
        sliderWidth += 2 * d_data->borderWidth;
843
 
 
844
 
    int w = 0, h = 0;
845
 
    if (d_data->scalePos != NoScale)
846
 
    {
847
 
        int d1, d2;
848
 
        scaleDraw()->getBorderDistHint(font(), d1, d2);
849
 
        int msMbd = qwtMax(d1, d2);
850
 
 
851
 
        int mbd = d_data->thumbLength / 2;
852
 
        if (d_data->bgStyle & BgTrough)
853
 
            mbd += d_data->borderWidth;
854
 
 
855
 
        if ( mbd < msMbd )
856
 
            mbd = msMbd;
857
 
 
858
 
        const int sdExtent = scaleDraw()->extent( QPen(), font() );
859
 
        const int sdLength = scaleDraw()->minLength( QPen(), font() );
860
 
 
861
 
        h = sliderWidth + sdExtent + d_data->scaleDist;
862
 
        w = sdLength - 2 * msMbd + 2 * mbd;
863
 
    }
864
 
    else  // no scale
865
 
    {
866
 
        w = 200;
867
 
        h = sliderWidth;
868
 
    }
869
 
 
870
 
    if ( orientation() == Qt::Vertical )
871
 
        qSwap(w, h);
872
 
 
873
 
    w += 2 * d_data->xMargin;
874
 
    h += 2 * d_data->yMargin;
875
 
 
876
 
    d_data->sizeHintCache = QSize(w, h);
877
 
    return d_data->sizeHintCache;
878
 
}