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

« back to all changes in this revision

Viewing changes to qwt-5.1.0/src/qwt_slider.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
 
// 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
 
void QwtSlider::setScaleDraw(QwtScaleDraw *scaleDraw)
321
 
{
322
 
    setAbstractScaleDraw(scaleDraw);
323
 
}
324
 
 
325
 
const QwtScaleDraw *QwtSlider::scaleDraw() const
326
 
{
327
 
    return (QwtScaleDraw *)abstractScaleDraw();
328
 
}
329
 
 
330
 
QwtScaleDraw *QwtSlider::scaleDraw()
331
 
{
332
 
    return (QwtScaleDraw *)abstractScaleDraw();
333
 
}
334
 
 
335
 
//! Notify changed scale
336
 
void QwtSlider::scaleChange()
337
 
{
338
 
    layoutSlider();
339
 
}
340
 
 
341
 
 
342
 
//! Notify change in font
343
 
void QwtSlider::fontChange(const QFont &f)
344
 
{
345
 
    QwtAbstractSlider::fontChange( f );
346
 
    layoutSlider();
347
 
}
348
 
 
349
 
//! Draw the slider into the specified rectangle.
350
 
void QwtSlider::drawSlider(QPainter *p, const QRect &r)
351
 
{
352
 
    QRect cr(r);
353
 
 
354
 
    if (d_data->bgStyle & BgTrough)
355
 
    {
356
 
        qDrawShadePanel(p, r.x(), r.y(),
357
 
            r.width(), r.height(),
358
 
#if QT_VERSION < 0x040000
359
 
            colorGroup(), 
360
 
#else
361
 
            palette(), 
362
 
#endif
363
 
            true, d_data->borderWidth,0);
364
 
 
365
 
        cr.setRect(r.x() + d_data->borderWidth,
366
 
            r.y() + d_data->borderWidth,
367
 
            r.width() - 2 * d_data->borderWidth,
368
 
            r.height() - 2 * d_data->borderWidth);
369
 
 
370
 
        p->fillRect(cr.x(), cr.y(), cr.width(), cr.height(), 
371
 
#if QT_VERSION < 0x040000
372
 
            colorGroup().brush(QColorGroup::Mid)
373
 
#else
374
 
            palette().brush(QPalette::Mid)
375
 
#endif
376
 
        );
377
 
    }
378
 
 
379
 
    if ( d_data->bgStyle & BgSlot)
380
 
    {
381
 
        int ws = 4;
382
 
        int ds = d_data->thumbLength / 2 - 4;
383
 
        if ( ds < 1 )
384
 
            ds = 1;
385
 
 
386
 
        QRect rSlot;
387
 
        if (orientation() == Qt::Horizontal)
388
 
        {
389
 
            if ( cr.height() & 1 )
390
 
                ws++;
391
 
            rSlot = QRect(cr.x() + ds, 
392
 
                    cr.y() + (cr.height() - ws) / 2,
393
 
                    cr.width() - 2 * ds, ws);
394
 
        }
395
 
        else
396
 
        {
397
 
            if ( cr.width() & 1 )
398
 
                ws++;
399
 
            rSlot = QRect(cr.x() + (cr.width() - ws) / 2, 
400
 
                    cr.y() + ds,
401
 
                    ws, cr.height() - 2 * ds);
402
 
        }
403
 
        p->fillRect(rSlot.x(), rSlot.y(), rSlot.width(), rSlot.height(),
404
 
#if QT_VERSION < 0x040000
405
 
            colorGroup().brush(QColorGroup::Dark)
406
 
#else
407
 
            palette().brush(QPalette::Dark)
408
 
#endif
409
 
        );
410
 
        qDrawShadePanel(p, rSlot.x(), rSlot.y(),
411
 
            rSlot.width(), rSlot.height(), 
412
 
#if QT_VERSION < 0x040000
413
 
            colorGroup(), 
414
 
#else
415
 
            palette(), 
416
 
#endif
417
 
            true, 1 ,0);
418
 
 
419
 
    }
420
 
 
421
 
    if ( isValid() )
422
 
        drawThumb(p, cr, xyPosition(value()));
423
 
}
424
 
 
425
 
//! Draw the thumb at a position
426
 
void QwtSlider::drawThumb(QPainter *p, const QRect &sliderRect, int pos)
427
 
{
428
 
    pos++; // shade line points one pixel below
429
 
    if (orientation() == Qt::Horizontal)
430
 
    {
431
 
        qDrawShadePanel(p, pos - d_data->thumbLength / 2, 
432
 
            sliderRect.y(), d_data->thumbLength, sliderRect.height(),
433
 
#if QT_VERSION < 0x040000
434
 
            colorGroup(), 
435
 
#else
436
 
            palette(), 
437
 
#endif
438
 
            false, d_data->borderWidth, 
439
 
#if QT_VERSION < 0x040000
440
 
            &colorGroup().brush(QColorGroup::Button)
441
 
#else
442
 
            &palette().brush(QPalette::Button)
443
 
#endif
444
 
        );
445
 
 
446
 
        qDrawShadeLine(p, pos, sliderRect.y(), 
447
 
            pos, sliderRect.y() + sliderRect.height() - 2, 
448
 
#if QT_VERSION < 0x040000
449
 
            colorGroup(), 
450
 
#else
451
 
            palette(), 
452
 
#endif
453
 
            true, 1);
454
 
    }
455
 
    else // Vertical
456
 
    {
457
 
        qDrawShadePanel(p,sliderRect.x(), pos - d_data->thumbLength / 2, 
458
 
            sliderRect.width(), d_data->thumbLength,
459
 
#if QT_VERSION < 0x040000
460
 
            colorGroup(),
461
 
#else
462
 
            palette(), 
463
 
#endif
464
 
            false, d_data->borderWidth, 
465
 
#if QT_VERSION < 0x040000
466
 
            &colorGroup().brush(QColorGroup::Button)
467
 
#else
468
 
            &palette().brush(QPalette::Button)
469
 
#endif
470
 
        );
471
 
 
472
 
        qDrawShadeLine(p, sliderRect.x(), pos,
473
 
            sliderRect.x() + sliderRect.width() - 2, pos, 
474
 
#if QT_VERSION < 0x040000
475
 
            colorGroup(), 
476
 
#else
477
 
            palette(), 
478
 
#endif
479
 
            true, 1);
480
 
    }
481
 
}
482
 
 
483
 
//! Find the x/y position for a given value v
484
 
int QwtSlider::xyPosition(double v) const
485
 
{
486
 
    return d_data->map.transform(v);
487
 
}
488
 
 
489
 
//! Determine the value corresponding to a specified mouse location.
490
 
double QwtSlider::getValue(const QPoint &p)
491
 
{
492
 
    return d_data->map.invTransform(
493
 
        orientation() == Qt::Horizontal ? p.x() : p.y());
494
 
}
495
 
 
496
 
 
497
 
/*!
498
 
  \brief Determine scrolling mode and direction
499
 
  \param p point
500
 
  \param scrollMode Scrolling mode
501
 
  \param direction Direction
502
 
*/
503
 
void QwtSlider::getScrollMode(const QPoint &p, 
504
 
    int &scrollMode, int &direction )
505
 
{
506
 
    if (!d_data->sliderRect.contains(p))
507
 
    {
508
 
        scrollMode = ScrNone;
509
 
        direction = 0;
510
 
        return;
511
 
    }
512
 
 
513
 
    const int pos = ( orientation() == Qt::Horizontal ) ? p.x() : p.y();
514
 
    const int markerPos = xyPosition(value());
515
 
 
516
 
    if ((pos > markerPos - d_data->thumbLength / 2)
517
 
        && (pos < markerPos + d_data->thumbLength / 2))
518
 
    {
519
 
        scrollMode = ScrMouse;
520
 
        direction = 0;
521
 
        return;
522
 
    }
523
 
 
524
 
    scrollMode = ScrPage;
525
 
    direction = (pos > markerPos) ? 1 : -1;
526
 
 
527
 
    if ( scaleDraw()->map().p1() > scaleDraw()->map().p2() )
528
 
        direction = -direction;
529
 
}
530
 
 
531
 
//! Qt paint event
532
 
void QwtSlider::paintEvent(QPaintEvent *e)
533
 
{
534
 
    const QRect &ur = e->rect();
535
 
    if ( ur.isValid() )
536
 
    {
537
 
#if QT_VERSION < 0x040000
538
 
        QwtPaintBuffer paintBuffer(this, ur);
539
 
        draw(paintBuffer.painter(), ur);
540
 
#else
541
 
        QPainter painter(this);
542
 
        draw(&painter, ur);
543
 
#endif
544
 
    }
545
 
}
546
 
 
547
 
//! Draw the QwtSlider
548
 
void QwtSlider::draw(QPainter *painter, const QRect&)
549
 
{
550
 
    if (d_data->scalePos != NoScale)
551
 
    {
552
 
#if QT_VERSION < 0x040000
553
 
        scaleDraw()->draw(painter, colorGroup());
554
 
#else
555
 
        scaleDraw()->draw(painter, palette());
556
 
#endif
557
 
    }
558
 
 
559
 
    drawSlider(painter, d_data->sliderRect);
560
 
 
561
 
    if ( hasFocus() )
562
 
        QwtPainter::drawFocusRect(painter, this, d_data->sliderRect);
563
 
}
564
 
 
565
 
//! Qt resize event
566
 
void QwtSlider::resizeEvent(QResizeEvent *)
567
 
{
568
 
    layoutSlider( false );
569
 
}
570
 
 
571
 
/*!
572
 
  Recalculate the slider's geometry and layout based on
573
 
  the current rect and fonts.
574
 
  \param update_geometry  notify the layout system and call update
575
 
         to redraw the scale
576
 
*/
577
 
void QwtSlider::layoutSlider( bool update_geometry )
578
 
{
579
 
    int sliderWidth = d_data->thumbWidth;
580
 
    int sld1 = d_data->thumbLength / 2 - 1;
581
 
    int sld2 = d_data->thumbLength / 2 + d_data->thumbLength % 2;
582
 
    if ( d_data->bgStyle & BgTrough )
583
 
    {
584
 
        sliderWidth += 2 * d_data->borderWidth;
585
 
        sld1 += d_data->borderWidth;
586
 
        sld2 += d_data->borderWidth;
587
 
    }
588
 
 
589
 
    int scd = 0;
590
 
    if ( d_data->scalePos != NoScale )
591
 
    {
592
 
        int d1, d2;
593
 
        scaleDraw()->getBorderDistHint(font(), d1, d2);
594
 
        scd = qwtMax(d1, d2);
595
 
    }
596
 
 
597
 
    int slo = scd - sld1;
598
 
    if ( slo < 0 )
599
 
        slo = 0;
600
 
 
601
 
    int x, y, length;
602
 
 
603
 
    const QRect r = rect();
604
 
    if (orientation() == Qt::Horizontal)
605
 
    {
606
 
        switch (d_data->scalePos)
607
 
        {
608
 
            case TopScale:
609
 
            {
610
 
                d_data->sliderRect.setRect(
611
 
                    r.x() + d_data->xMargin + slo,
612
 
                    r.y() + r.height() -
613
 
                    d_data->yMargin - sliderWidth,
614
 
                    r.width() - 2 * d_data->xMargin - 2 * slo,
615
 
                    sliderWidth);
616
 
 
617
 
                x = d_data->sliderRect.x() + sld1;
618
 
                y = d_data->sliderRect.y() - d_data->scaleDist;
619
 
 
620
 
                break;
621
 
            }
622
 
 
623
 
            case BottomScale:
624
 
            {
625
 
                d_data->sliderRect.setRect(
626
 
                    r.x() + d_data->xMargin + slo,
627
 
                    r.y() + d_data->yMargin,
628
 
                    r.width() - 2 * d_data->xMargin - 2 * slo,
629
 
                    sliderWidth);
630
 
    
631
 
                x = d_data->sliderRect.x() + sld1;
632
 
                y = d_data->sliderRect.y() + d_data->sliderRect.height() 
633
 
                    + d_data->scaleDist;
634
 
 
635
 
                break;
636
 
            }
637
 
 
638
 
            case NoScale: // like Bottom, but no scale. See QwtSlider().
639
 
            default:   // inconsistent orientation and scale position
640
 
            {
641
 
                d_data->sliderRect.setRect(
642
 
                    r.x() + d_data->xMargin + slo,
643
 
                    r.y() + d_data->yMargin,
644
 
                    r.width() - 2 * d_data->xMargin - 2 * slo,
645
 
                    sliderWidth);
646
 
 
647
 
                x = d_data->sliderRect.x() + sld1;
648
 
                y = 0;
649
 
 
650
 
                break;
651
 
            }
652
 
        }
653
 
        length = d_data->sliderRect.width() - (sld1 + sld2);
654
 
    }
655
 
    else // if (orientation() == Qt::Vertical
656
 
    {
657
 
        switch (d_data->scalePos)
658
 
        {
659
 
            case RightScale:
660
 
                d_data->sliderRect.setRect(
661
 
                    r.x() + d_data->xMargin,
662
 
                    r.y() + d_data->yMargin + slo,
663
 
                    sliderWidth,
664
 
                    r.height() - 2 * d_data->yMargin - 2 * slo);
665
 
 
666
 
                x = d_data->sliderRect.x() + d_data->sliderRect.width() 
667
 
                    + d_data->scaleDist;
668
 
                y = d_data->sliderRect.y() + sld1;
669
 
 
670
 
                break;
671
 
 
672
 
            case LeftScale:
673
 
                d_data->sliderRect.setRect(
674
 
                    r.x() + r.width() - sliderWidth - d_data->xMargin,
675
 
                    r.y() + d_data->yMargin + slo,
676
 
                    sliderWidth,
677
 
                    r.height() - 2 * d_data->yMargin - 2 * slo);
678
 
 
679
 
                x = d_data->sliderRect.x() - d_data->scaleDist;
680
 
                y = d_data->sliderRect.y() + sld1;
681
 
 
682
 
                break;
683
 
 
684
 
            case NoScale: // like Left, but no scale. See QwtSlider().
685
 
            default:   // inconsistent orientation and scale position
686
 
                d_data->sliderRect.setRect(
687
 
                    r.x() + r.width() - sliderWidth - d_data->xMargin,
688
 
                    r.y() + d_data->yMargin + slo,
689
 
                    sliderWidth,
690
 
                    r.height() - 2 * d_data->yMargin - 2 * slo);
691
 
 
692
 
                x = 0;
693
 
                y = d_data->sliderRect.y() + sld1;
694
 
 
695
 
                break;
696
 
        }
697
 
        length = d_data->sliderRect.height() - (sld1 + sld2);
698
 
    }
699
 
 
700
 
    scaleDraw()->move(x, y);
701
 
    scaleDraw()->setLength(length);
702
 
 
703
 
    d_data->map.setPaintXInterval(scaleDraw()->map().p1(),
704
 
        scaleDraw()->map().p2());
705
 
 
706
 
    if ( update_geometry )
707
 
    {
708
 
        d_data->sizeHintCache = QSize(); // invalidate
709
 
        updateGeometry();
710
 
        update();
711
 
    }
712
 
}
713
 
 
714
 
//! Notify change of value
715
 
void QwtSlider::valueChange()
716
 
{
717
 
    QwtAbstractSlider::valueChange();
718
 
    update();
719
 
}
720
 
 
721
 
 
722
 
//! Notify change of range
723
 
void QwtSlider::rangeChange()
724
 
{
725
 
    d_data->map.setScaleInterval(minValue(), maxValue());
726
 
 
727
 
    if (autoScale())
728
 
        rescale(minValue(), maxValue());
729
 
 
730
 
    QwtAbstractSlider::rangeChange();
731
 
    layoutSlider();
732
 
}
733
 
 
734
 
/*!
735
 
  \brief Set distances between the widget's border and internals.
736
 
  \param xMargin Horizontal margin
737
 
  \param yMargin Vertical margin
738
 
*/
739
 
void QwtSlider::setMargins(int xMargin, int yMargin)
740
 
{
741
 
    if ( xMargin < 0 )
742
 
        xMargin = 0;
743
 
    if ( yMargin < 0 )
744
 
        yMargin = 0;
745
 
 
746
 
    if ( xMargin != d_data->xMargin || yMargin != d_data->yMargin )
747
 
    {
748
 
        d_data->xMargin = xMargin;
749
 
        d_data->yMargin = yMargin;
750
 
        layoutSlider();
751
 
    }
752
 
}
753
 
 
754
 
/*!
755
 
  Set the background style.
756
 
*/
757
 
void QwtSlider::setBgStyle(BGSTYLE st) 
758
 
{
759
 
    d_data->bgStyle = st; 
760
 
    layoutSlider();
761
 
}
762
 
 
763
 
/*!
764
 
  \return the background style.
765
 
*/
766
 
QwtSlider::BGSTYLE QwtSlider::bgStyle() const 
767
 
768
 
    return d_data->bgStyle; 
769
 
}
770
 
 
771
 
/*!
772
 
  \return the thumb length.
773
 
*/
774
 
int QwtSlider::thumbLength() const 
775
 
{
776
 
    return d_data->thumbLength;
777
 
}
778
 
 
779
 
/*!
780
 
  \return the thumb width.
781
 
*/
782
 
int QwtSlider::thumbWidth() const 
783
 
{
784
 
    return d_data->thumbWidth;
785
 
}
786
 
 
787
 
/*!
788
 
  \return the border width.
789
 
*/
790
 
int QwtSlider::borderWidth() const 
791
 
{
792
 
    return d_data->borderWidth;
793
 
}
794
 
 
795
 
/*!
796
 
  \return QwtSlider::minimumSizeHint()
797
 
*/
798
 
QSize QwtSlider::sizeHint() const
799
 
{
800
 
    return minimumSizeHint();
801
 
}
802
 
 
803
 
/*!
804
 
  \brief Return a minimum size hint
805
 
  \warning The return value of QwtSlider::minimumSizeHint() depends on 
806
 
           the font and the scale.
807
 
*/
808
 
QSize QwtSlider::minimumSizeHint() const
809
 
{
810
 
    if (!d_data->sizeHintCache.isEmpty()) 
811
 
        return d_data->sizeHintCache;
812
 
 
813
 
    int sliderWidth = d_data->thumbWidth;
814
 
    if (d_data->bgStyle & BgTrough)
815
 
        sliderWidth += 2 * d_data->borderWidth;
816
 
 
817
 
    int w = 0, h = 0;
818
 
    if (d_data->scalePos != NoScale)
819
 
    {
820
 
        int d1, d2;
821
 
        scaleDraw()->getBorderDistHint(font(), d1, d2);
822
 
        int msMbd = qwtMax(d1, d2);
823
 
 
824
 
        int mbd = d_data->thumbLength / 2;
825
 
        if (d_data->bgStyle & BgTrough)
826
 
            mbd += d_data->borderWidth;
827
 
 
828
 
        if ( mbd < msMbd )
829
 
            mbd = msMbd;
830
 
 
831
 
        const int sdExtent = scaleDraw()->extent( QPen(), font() );
832
 
        const int sdLength = scaleDraw()->minLength( QPen(), font() );
833
 
 
834
 
        h = sliderWidth + sdExtent + d_data->scaleDist;
835
 
        w = sdLength - 2 * msMbd + 2 * mbd;
836
 
    }
837
 
    else  // no scale
838
 
    {
839
 
        w = 200;
840
 
        h = sliderWidth;
841
 
    }
842
 
 
843
 
    if ( orientation() == Qt::Vertical )
844
 
        qSwap(w, h);
845
 
 
846
 
    w += 2 * d_data->xMargin;
847
 
    h += 2 * d_data->yMargin;
848
 
 
849
 
    d_data->sizeHintCache = QSize(w, h);
850
 
    return d_data->sizeHintCache;
851
 
}