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

« back to all changes in this revision

Viewing changes to qwt/src/qwt_plot_layout.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2011-06-10 11:22:47 UTC
  • mfrom: (1.1.6 upstream) (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110610112247-0i1019vvmzaq6p86
Tags: 6.0.0-1
* New upstream release (Closes: #624107):
  - drop Qt3 support. (Closes: #604379, #626868)
* Register documentation with doc-base. (Closes: #626567)
* Drop patches:
  - 01_makefiles.diff
  - 02_add_missing_warnings.diff
  - 03_qwt_branch_pull_r544.diff
* Add qwt_install_paths.patch to fix the hardcoded installation paths.
* Update debian/control:
  - drop libqt3-mt-dev build dependency.
  - bump Standards-Version to 3.9.2 (no changes).
  - drop Qt3 related packages.
  - due to bump soname (and as we dropper Qt3 support):
    - libqwt5-qt4-dev -> libqwt-dev
    - libqwt5-qt4 -> libqwt6
    - libqwt5-doc -> libqwt-doc
* Update debian/copyright file.
* Update debian/rules: drop Qt3 packages support.

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 <qscrollbar.h>
13
 
#include "qwt_text.h"
14
 
#include "qwt_text_label.h"
15
 
#include "qwt_plot_canvas.h"
16
 
#include "qwt_scale_widget.h"
17
 
#include "qwt_legend.h"
18
 
#include "qwt_plot_layout.h"
19
 
 
20
 
class QwtPlotLayout::LayoutData
21
 
{
22
 
public:
23
 
    void init(const QwtPlot *, const QRect &rect);
24
 
 
25
 
    struct t_legendData
26
 
    {
27
 
        int frameWidth;
28
 
        int vScrollBarWidth;
29
 
        int hScrollBarHeight;
30
 
        QSize hint;
31
 
    } legend;
32
 
    
33
 
    struct t_titleData
34
 
    {
35
 
        QwtText text;
36
 
        int frameWidth;
37
 
    } title;
38
 
 
39
 
    struct t_scaleData
40
 
    {
41
 
        bool isEnabled;
42
 
        const QwtScaleWidget *scaleWidget;
43
 
        QFont scaleFont;
44
 
        int start;
45
 
        int end;
46
 
        int baseLineOffset;
47
 
        int tickOffset; 
48
 
        int dimWithoutTitle;
49
 
    } scale[QwtPlot::axisCnt];
50
 
 
51
 
    struct t_canvasData
52
 
    {
53
 
        int frameWidth;
54
 
    } canvas;
55
 
};
56
 
 
57
 
/*
58
 
  Extract all layout relevant data from the plot components
59
 
*/
60
 
 
61
 
void QwtPlotLayout::LayoutData::init(const QwtPlot *plot, const QRect &rect)
62
 
{
63
 
    // legend
64
 
 
65
 
    if ( plot->plotLayout()->legendPosition() != QwtPlot::ExternalLegend 
66
 
        && plot->legend() )
67
 
    {
68
 
        legend.frameWidth = plot->legend()->frameWidth();
69
 
        legend.vScrollBarWidth = 
70
 
            plot->legend()->verticalScrollBar()->sizeHint().width();
71
 
        legend.hScrollBarHeight = 
72
 
            plot->legend()->horizontalScrollBar()->sizeHint().height();
73
 
 
74
 
        const QSize hint = plot->legend()->sizeHint();
75
 
 
76
 
        int w = qwtMin(hint.width(), rect.width());
77
 
        int h = plot->legend()->heightForWidth(w);
78
 
        if ( h == 0 )
79
 
            h = hint.height();
80
 
 
81
 
        if ( h > rect.height() )
82
 
            w += legend.vScrollBarWidth;
83
 
 
84
 
        legend.hint = QSize(w, h);
85
 
    }
86
 
 
87
 
    // title 
88
 
 
89
 
    title.frameWidth = 0;
90
 
    title.text = QwtText();
91
 
 
92
 
    if (plot->titleLabel() )
93
 
    {
94
 
        const QwtTextLabel *label = plot->titleLabel();
95
 
        title.text = label->text(); 
96
 
        if ( !(title.text.testPaintAttribute(QwtText::PaintUsingTextFont)) )
97
 
            title.text.setFont(label->font());
98
 
        
99
 
        title.frameWidth = plot->titleLabel()->frameWidth();
100
 
    }
101
 
 
102
 
    // scales 
103
 
 
104
 
    for (int axis = 0; axis < QwtPlot::axisCnt; axis++ )
105
 
    {
106
 
        if ( plot->axisEnabled(axis) )
107
 
        {
108
 
            const QwtScaleWidget *scaleWidget = plot->axisWidget(axis);
109
 
 
110
 
            scale[axis].isEnabled = true;
111
 
 
112
 
            scale[axis].scaleWidget = scaleWidget;
113
 
 
114
 
            scale[axis].scaleFont = scaleWidget->font();
115
 
 
116
 
            scale[axis].start = scaleWidget->startBorderDist();
117
 
            scale[axis].end = scaleWidget->endBorderDist();
118
 
 
119
 
            scale[axis].baseLineOffset = scaleWidget->margin();
120
 
            scale[axis].tickOffset = scaleWidget->margin();
121
 
            if ( scaleWidget->scaleDraw()->hasComponent(
122
 
                QwtAbstractScaleDraw::Ticks) )
123
 
            {
124
 
                scale[axis].tickOffset += 
125
 
                    (int)scaleWidget->scaleDraw()->majTickLength();
126
 
            }
127
 
 
128
 
            scale[axis].dimWithoutTitle = scaleWidget->dimForLength(
129
 
                QWIDGETSIZE_MAX, scale[axis].scaleFont);
130
 
 
131
 
            if ( !scaleWidget->title().isEmpty() )
132
 
            {
133
 
                scale[axis].dimWithoutTitle -= 
134
 
                    scaleWidget->titleHeightForWidth(QWIDGETSIZE_MAX);
135
 
            }
136
 
        }
137
 
        else
138
 
        {
139
 
            scale[axis].isEnabled = false;
140
 
            scale[axis].start = 0;
141
 
            scale[axis].end = 0;
142
 
            scale[axis].baseLineOffset = 0;
143
 
            scale[axis].tickOffset = 0;
144
 
            scale[axis].dimWithoutTitle = 0;
145
 
        }
146
 
    }
147
 
 
148
 
    // canvas 
149
 
 
150
 
    canvas.frameWidth = plot->canvas()->frameWidth();
151
 
}
152
 
 
153
 
class QwtPlotLayout::PrivateData
154
 
{
155
 
public:
156
 
    PrivateData():
157
 
        margin(0),
158
 
        spacing(5),
159
 
        alignCanvasToScales(false)
160
 
    {
161
 
    }
162
 
 
163
 
    QRect titleRect;
164
 
    QRect legendRect;
165
 
    QRect scaleRect[QwtPlot::axisCnt];
166
 
    QRect canvasRect;
167
 
 
168
 
    QwtPlotLayout::LayoutData layoutData;
169
 
 
170
 
    QwtPlot::LegendPosition legendPos;
171
 
    double legendRatio;
172
 
    unsigned int margin;
173
 
    unsigned int spacing;
174
 
    unsigned int canvasMargin[QwtPlot::axisCnt];
175
 
    bool alignCanvasToScales;
176
 
};
177
 
 
178
 
/*!
179
 
  \brief Constructor
180
 
 */
181
 
 
182
 
QwtPlotLayout::QwtPlotLayout()
183
 
{
184
 
    d_data = new PrivateData;
185
 
 
186
 
    setLegendPosition(QwtPlot::BottomLegend);
187
 
    setCanvasMargin(4);
188
 
 
189
 
    invalidate();
190
 
}
191
 
 
192
 
//! Destructor
193
 
QwtPlotLayout::~QwtPlotLayout()
194
 
{
195
 
    delete d_data;
196
 
}
197
 
 
198
 
/*!
199
 
  Change the margin of the plot. The margin is the space
200
 
  around all components.
201
 
 
202
 
  \param margin new margin
203
 
  \sa margin(), setSpacing(),
204
 
      QwtPlot::setMargin()
205
 
*/
206
 
void QwtPlotLayout::setMargin(int margin)
207
 
{
208
 
    if ( margin < 0 )
209
 
        margin = 0;
210
 
    d_data->margin = margin;
211
 
}
212
 
 
213
 
/*!
214
 
    \return margin
215
 
    \sa setMargin(), spacing(), QwtPlot::margin()
216
 
*/
217
 
int QwtPlotLayout::margin() const
218
 
{
219
 
    return d_data->margin;
220
 
}
221
 
 
222
 
/*!
223
 
  Change a margin of the canvas. The margin is the space
224
 
  above/below the scale ticks. A negative margin will
225
 
  be set to -1, excluding the borders of the scales.
226
 
 
227
 
  \param margin New margin
228
 
  \param axis One of QwtPlot::Axis. Specifies where the position of the margin. 
229
 
              -1 means margin at all borders.
230
 
  \sa canvasMargin() 
231
 
 
232
 
  \warning The margin will have no effect when alignCanvasToScales is true
233
 
*/
234
 
 
235
 
void QwtPlotLayout::setCanvasMargin(int margin, int axis)
236
 
{
237
 
    if ( margin < -1 )
238
 
        margin = -1;
239
 
 
240
 
    if ( axis == -1 )
241
 
    {
242
 
        for (axis = 0; axis < QwtPlot::axisCnt; axis++)
243
 
            d_data->canvasMargin[axis] = margin;
244
 
    }
245
 
    else if ( axis >= 0 && axis < QwtPlot::axisCnt )
246
 
        d_data->canvasMargin[axis] = margin;
247
 
}
248
 
 
249
 
/*!
250
 
    \return Margin around the scale tick borders
251
 
    \sa setCanvasMargin()
252
 
*/
253
 
int QwtPlotLayout::canvasMargin(int axis) const
254
 
{
255
 
    if ( axis < 0 || axis >= QwtPlot::axisCnt )
256
 
        return 0;
257
 
 
258
 
    return d_data->canvasMargin[axis];
259
 
}
260
 
 
261
 
/*!
262
 
  Change the align-canvas-to-axis-scales setting. The canvas may:
263
 
  - extend beyond the axis scale ends to maximize its size,
264
 
  - align with the axis scale ends to control its size.
265
 
 
266
 
  \param alignCanvasToScales New align-canvas-to-axis-scales setting
267
 
 
268
 
  \sa setCanvasMargin() 
269
 
  \note In this context the term 'scale' means the backbone of a scale.
270
 
  \warning In case of alignCanvasToScales == true canvasMargin will have 
271
 
           no effect
272
 
*/
273
 
void QwtPlotLayout::setAlignCanvasToScales(bool alignCanvasToScales)
274
 
{
275
 
    d_data->alignCanvasToScales = alignCanvasToScales;
276
 
}
277
 
 
278
 
/*!
279
 
  Return the align-canvas-to-axis-scales setting. The canvas may:
280
 
  - extend beyond the axis scale ends to maximize its size
281
 
  - align with the axis scale ends to control its size.
282
 
 
283
 
  \return align-canvas-to-axis-scales setting
284
 
  \sa setAlignCanvasToScales, setCanvasMargin() 
285
 
  \note In this context the term 'scale' means the backbone of a scale.
286
 
*/
287
 
bool QwtPlotLayout::alignCanvasToScales() const
288
 
{
289
 
    return d_data->alignCanvasToScales;
290
 
}
291
 
 
292
 
/*!
293
 
  Change the spacing of the plot. The spacing is the distance
294
 
  between the plot components.
295
 
 
296
 
  \param spacing new spacing
297
 
  \sa setMargin(), spacing() 
298
 
*/
299
 
void QwtPlotLayout::setSpacing(int spacing)
300
 
{
301
 
    d_data->spacing = qwtMax(0, spacing);
302
 
}
303
 
 
304
 
/*!
305
 
  \return spacing
306
 
  \sa margin(), setSpacing() 
307
 
*/
308
 
int QwtPlotLayout::spacing() const
309
 
{
310
 
    return d_data->spacing;
311
 
}
312
 
 
313
 
/*!
314
 
  \brief Specify the position of the legend
315
 
  \param pos The legend's position. 
316
 
  \param ratio Ratio between legend and the bounding rect 
317
 
               of title, canvas and axes. The legend will be shrinked
318
 
               if it would need more space than the given ratio.
319
 
               The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0
320
 
               it will be reset to the default ratio.
321
 
               The default vertical/horizontal ratio is 0.33/0.5. 
322
 
               
323
 
  \sa QwtPlot::setLegendPosition()
324
 
*/
325
 
 
326
 
void QwtPlotLayout::setLegendPosition(QwtPlot::LegendPosition pos, double ratio)
327
 
{
328
 
    if ( ratio > 1.0 )
329
 
        ratio = 1.0;
330
 
 
331
 
    switch(pos)
332
 
    {
333
 
        case QwtPlot::TopLegend:
334
 
        case QwtPlot::BottomLegend:
335
 
            if ( ratio <= 0.0 )
336
 
                ratio = 0.33;
337
 
            d_data->legendRatio = ratio;
338
 
            d_data->legendPos = pos;
339
 
            break;
340
 
        case QwtPlot::LeftLegend:
341
 
        case QwtPlot::RightLegend:
342
 
            if ( ratio <= 0.0 )
343
 
                ratio = 0.5;
344
 
            d_data->legendRatio = ratio;
345
 
            d_data->legendPos = pos;
346
 
            break;
347
 
        case QwtPlot::ExternalLegend:
348
 
            d_data->legendRatio = ratio; // meaningless
349
 
            d_data->legendPos = pos;
350
 
        default:
351
 
            break;
352
 
    }
353
 
}
354
 
 
355
 
/*!
356
 
  \brief Specify the position of the legend
357
 
  \param pos The legend's position. Valid values are 
358
 
      \c QwtPlot::LeftLegend, \c QwtPlot::RightLegend, 
359
 
      \c QwtPlot::TopLegend, \c QwtPlot::BottomLegend.
360
 
               
361
 
  \sa QwtPlot::setLegendPosition()
362
 
*/
363
 
void QwtPlotLayout::setLegendPosition(QwtPlot::LegendPosition pos)
364
 
{
365
 
    setLegendPosition(pos, 0.0);
366
 
}
367
 
 
368
 
/*!
369
 
  \return Position of the legend
370
 
  \sa setLegendPosition(), QwtPlot::setLegendPosition(),
371
 
      QwtPlot::legendPosition()
372
 
*/
373
 
QwtPlot::LegendPosition QwtPlotLayout::legendPosition() const
374
 
{
375
 
    return d_data->legendPos;
376
 
}
377
 
 
378
 
/*!
379
 
  Specify the relative size of the legend in the plot
380
 
  \param ratio Ratio between legend and the bounding rect 
381
 
               of title, canvas and axes. The legend will be shrinked
382
 
               if it would need more space than the given ratio.
383
 
               The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0
384
 
               it will be reset to the default ratio.
385
 
               The default vertical/horizontal ratio is 0.33/0.5. 
386
 
*/
387
 
void QwtPlotLayout::setLegendRatio(double ratio)
388
 
{
389
 
    setLegendPosition(legendPosition(), ratio);
390
 
}
391
 
 
392
 
/*!
393
 
  \return The relative size of the legend in the plot.
394
 
  \sa setLegendPosition()
395
 
*/
396
 
double QwtPlotLayout::legendRatio() const
397
 
{
398
 
    return d_data->legendRatio;
399
 
}
400
 
 
401
 
/*!
402
 
  \return Geometry for the title
403
 
  \sa activate(), invalidate()
404
 
*/
405
 
 
406
 
const QRect &QwtPlotLayout::titleRect() const
407
 
{
408
 
    return d_data->titleRect;
409
 
}
410
 
 
411
 
/*!
412
 
  \return Geometry for the legend
413
 
  \sa activate(), invalidate()
414
 
*/
415
 
 
416
 
const QRect &QwtPlotLayout::legendRect() const
417
 
{
418
 
    return d_data->legendRect;
419
 
}
420
 
 
421
 
/*!
422
 
  \param axis Axis index
423
 
  \return Geometry for the scale
424
 
  \sa activate(), invalidate()
425
 
*/
426
 
 
427
 
const QRect &QwtPlotLayout::scaleRect(int axis) const
428
 
{
429
 
    if ( axis < 0 || axis >= QwtPlot::axisCnt )
430
 
    {
431
 
        static QRect dummyRect;
432
 
        return dummyRect;
433
 
    }
434
 
    return d_data->scaleRect[axis];
435
 
}
436
 
 
437
 
/*!
438
 
  \return Geometry for the canvas
439
 
  \sa activate(), invalidate()
440
 
*/
441
 
 
442
 
const QRect &QwtPlotLayout::canvasRect() const
443
 
{
444
 
    return d_data->canvasRect;
445
 
}
446
 
 
447
 
/*!
448
 
  Invalidate the geometry of all components. 
449
 
  \sa activate()
450
 
*/
451
 
void QwtPlotLayout::invalidate()
452
 
{
453
 
    d_data->titleRect = d_data->legendRect = d_data->canvasRect = QRect();
454
 
    for (int axis = 0; axis < QwtPlot::axisCnt; axis++ )
455
 
        d_data->scaleRect[axis] = QRect();
456
 
}
457
 
 
458
 
/*!  
459
 
  \brief Return a minimum size hint
460
 
  \sa QwtPlot::minimumSizeHint()
461
 
*/
462
 
 
463
 
QSize QwtPlotLayout::minimumSizeHint(const QwtPlot *plot) const
464
 
{
465
 
    class ScaleData
466
 
    {
467
 
    public:
468
 
        ScaleData()
469
 
        {
470
 
            w = h = minLeft = minRight = tickOffset = 0;
471
 
        }
472
 
 
473
 
        int w;
474
 
        int h;
475
 
        int minLeft;
476
 
        int minRight;
477
 
        int tickOffset;
478
 
    } scaleData[QwtPlot::axisCnt];
479
 
 
480
 
    int canvasBorder[QwtPlot::axisCnt];
481
 
 
482
 
    int axis;
483
 
    for ( axis = 0; axis < QwtPlot::axisCnt; axis++ )
484
 
    {
485
 
        if ( plot->axisEnabled(axis) )
486
 
        {
487
 
            const QwtScaleWidget *scl = plot->axisWidget(axis);
488
 
            ScaleData &sd = scaleData[axis];
489
 
 
490
 
            const QSize hint = scl->minimumSizeHint();
491
 
            sd.w = hint.width(); 
492
 
            sd.h = hint.height(); 
493
 
            scl->getBorderDistHint(sd.minLeft, sd.minRight);
494
 
            sd.tickOffset = scl->margin();
495
 
            if ( scl->scaleDraw()->hasComponent(QwtAbstractScaleDraw::Ticks) )
496
 
                sd.tickOffset += scl->scaleDraw()->majTickLength();
497
 
        }
498
 
 
499
 
        canvasBorder[axis] = plot->canvas()->frameWidth() +
500
 
            d_data->canvasMargin[axis] + 1;
501
 
            
502
 
    }
503
 
 
504
 
 
505
 
    for ( axis = 0; axis < QwtPlot::axisCnt; axis++ )
506
 
    {
507
 
        ScaleData &sd = scaleData[axis];
508
 
        if ( sd.w && (axis == QwtPlot::xBottom || axis == QwtPlot::xTop) )
509
 
        {
510
 
            if ( (sd.minLeft > canvasBorder[QwtPlot::yLeft]) 
511
 
                && scaleData[QwtPlot::yLeft].w )
512
 
            {
513
 
                int shiftLeft = sd.minLeft - canvasBorder[QwtPlot::yLeft];
514
 
                if ( shiftLeft > scaleData[QwtPlot::yLeft].w )
515
 
                    shiftLeft = scaleData[QwtPlot::yLeft].w;
516
 
 
517
 
                sd.w -= shiftLeft;
518
 
            }
519
 
            if ( (sd.minRight > canvasBorder[QwtPlot::yRight]) 
520
 
                && scaleData[QwtPlot::yRight].w )
521
 
            {
522
 
                int shiftRight = sd.minRight - canvasBorder[QwtPlot::yRight];
523
 
                if ( shiftRight > scaleData[QwtPlot::yRight].w )
524
 
                    shiftRight = scaleData[QwtPlot::yRight].w;
525
 
 
526
 
                sd.w -= shiftRight;
527
 
            }
528
 
        }
529
 
 
530
 
        if ( sd.h && (axis == QwtPlot::yLeft || axis == QwtPlot::yRight) )
531
 
        {
532
 
            if ( (sd.minLeft > canvasBorder[QwtPlot::xBottom]) &&
533
 
                scaleData[QwtPlot::xBottom].h )
534
 
            {
535
 
                int shiftBottom = sd.minLeft - canvasBorder[QwtPlot::xBottom];
536
 
                if ( shiftBottom > scaleData[QwtPlot::xBottom].tickOffset )
537
 
                    shiftBottom = scaleData[QwtPlot::xBottom].tickOffset;
538
 
 
539
 
                sd.h -= shiftBottom;
540
 
            }
541
 
            if ( (sd.minLeft > canvasBorder[QwtPlot::xTop]) &&
542
 
                scaleData[QwtPlot::xTop].h )
543
 
            {
544
 
                int shiftTop = sd.minRight - canvasBorder[QwtPlot::xTop];
545
 
                if ( shiftTop > scaleData[QwtPlot::xTop].tickOffset )
546
 
                    shiftTop = scaleData[QwtPlot::xTop].tickOffset;
547
 
 
548
 
                sd.h -= shiftTop;
549
 
            }
550
 
        }
551
 
    }
552
 
 
553
 
    const QwtPlotCanvas *canvas = plot->canvas();
554
 
    const QSize minCanvasSize = canvas->minimumSize();
555
 
 
556
 
    int w = scaleData[QwtPlot::yLeft].w + scaleData[QwtPlot::yRight].w;
557
 
    int cw = qwtMax(scaleData[QwtPlot::xBottom].w, scaleData[QwtPlot::xTop].w)
558
 
        + 2 * (canvas->frameWidth() + 1);
559
 
    w += qwtMax(cw, minCanvasSize.width());
560
 
 
561
 
    int h = scaleData[QwtPlot::xBottom].h + scaleData[QwtPlot::xTop].h;
562
 
    int ch = qwtMax(scaleData[QwtPlot::yLeft].h, scaleData[QwtPlot::yRight].h)
563
 
        + 2 * (canvas->frameWidth() + 1);
564
 
    h += qwtMax(ch, minCanvasSize.height());
565
 
 
566
 
    const QwtTextLabel *title = plot->titleLabel();
567
 
    if (title && !title->text().isEmpty())
568
 
    {
569
 
        // If only QwtPlot::yLeft or QwtPlot::yRight is showing, 
570
 
        // we center on the plot canvas.
571
 
        const bool centerOnCanvas = !(plot->axisEnabled(QwtPlot::yLeft) 
572
 
            && plot->axisEnabled(QwtPlot::yRight));
573
 
 
574
 
        int titleW = w;
575
 
        if ( centerOnCanvas )
576
 
        {
577
 
            titleW -= scaleData[QwtPlot::yLeft].w 
578
 
                + scaleData[QwtPlot::yRight].w;
579
 
        }
580
 
 
581
 
        int titleH = title->heightForWidth(titleW);
582
 
        if ( titleH > titleW ) // Compensate for a long title
583
 
        {
584
 
            w = titleW = titleH;
585
 
            if ( centerOnCanvas )
586
 
            {
587
 
                w += scaleData[QwtPlot::yLeft].w
588
 
                    + scaleData[QwtPlot::yRight].w;
589
 
            }
590
 
 
591
 
            titleH = title->heightForWidth(titleW);
592
 
        }
593
 
        h += titleH + d_data->spacing;
594
 
    }
595
 
 
596
 
    // Compute the legend contribution
597
 
 
598
 
    const QwtLegend *legend = plot->legend();
599
 
    if ( d_data->legendPos != QwtPlot::ExternalLegend
600
 
        && legend && !legend->isEmpty() )
601
 
    {
602
 
        if ( d_data->legendPos == QwtPlot::LeftLegend 
603
 
            || d_data->legendPos == QwtPlot::RightLegend )
604
 
        {
605
 
            int legendW = legend->sizeHint().width();
606
 
            int legendH = legend->heightForWidth(legendW); 
607
 
 
608
 
            if ( legend->frameWidth() > 0 )
609
 
                w += d_data->spacing;
610
 
 
611
 
            if ( legendH > h )
612
 
                legendW += legend->verticalScrollBar()->sizeHint().height();
613
 
 
614
 
            if ( d_data->legendRatio < 1.0 )
615
 
                legendW = qwtMin(legendW, int(w / (1.0 - d_data->legendRatio)));
616
 
 
617
 
            w += legendW;
618
 
        }
619
 
        else // QwtPlot::Top, QwtPlot::Bottom
620
 
        {
621
 
            int legendW = qwtMin(legend->sizeHint().width(), w);
622
 
            int legendH = legend->heightForWidth(legendW); 
623
 
 
624
 
            if ( legend->frameWidth() > 0 )
625
 
                h += d_data->spacing;
626
 
 
627
 
            if ( d_data->legendRatio < 1.0 )
628
 
                legendH = qwtMin(legendH, int(h / (1.0 - d_data->legendRatio)));
629
 
            
630
 
            h += legendH;
631
 
        }
632
 
    }
633
 
 
634
 
    w += 2 * d_data->margin;
635
 
    h += 2 * d_data->margin;
636
 
 
637
 
    return QSize( w, h );
638
 
}
639
 
 
640
 
/*!
641
 
  Find the geometry for the legend
642
 
  \param options Options how to layout the legend
643
 
  \param rect Rectangle where to place the legend
644
 
  \return Geometry for the legend
645
 
  \sa Options
646
 
*/
647
 
 
648
 
QRect QwtPlotLayout::layoutLegend(int options, 
649
 
    const QRect &rect) const
650
 
{
651
 
    const QSize hint(d_data->layoutData.legend.hint);
652
 
 
653
 
    int dim;
654
 
    if ( d_data->legendPos == QwtPlot::LeftLegend 
655
 
        || d_data->legendPos == QwtPlot::RightLegend )
656
 
    {
657
 
        // We don't allow vertical legends to take more than
658
 
        // half of the available space.
659
 
 
660
 
        dim = qwtMin(hint.width(), int(rect.width() * d_data->legendRatio));
661
 
 
662
 
        if ( !(options & IgnoreScrollbars) )
663
 
        {
664
 
            if ( hint.height() > rect.height() )
665
 
            {
666
 
                // The legend will need additional
667
 
                // space for the vertical scrollbar. 
668
 
 
669
 
                dim += d_data->layoutData.legend.vScrollBarWidth;
670
 
            }
671
 
        }
672
 
    }
673
 
    else
674
 
    {
675
 
        dim = qwtMin(hint.height(), int(rect.height() * d_data->legendRatio));
676
 
        dim = qwtMax(dim, d_data->layoutData.legend.hScrollBarHeight);
677
 
    }
678
 
 
679
 
    QRect legendRect = rect;
680
 
    switch(d_data->legendPos)
681
 
    {
682
 
        case QwtPlot::LeftLegend:
683
 
            legendRect.setWidth(dim);
684
 
            break;
685
 
        case QwtPlot::RightLegend:
686
 
            legendRect.setX(rect.right() - dim + 1);
687
 
            legendRect.setWidth(dim);
688
 
            break;
689
 
        case QwtPlot::TopLegend:
690
 
            legendRect.setHeight(dim);
691
 
            break;
692
 
        case QwtPlot::BottomLegend:
693
 
            legendRect.setY(rect.bottom() - dim + 1);
694
 
            legendRect.setHeight(dim);
695
 
            break;
696
 
        case QwtPlot::ExternalLegend:
697
 
            break;
698
 
    }
699
 
 
700
 
    return legendRect;
701
 
}
702
 
 
703
 
/*!
704
 
  Align the legend to the canvas
705
 
  \param canvasRect Geometry of the canvas
706
 
  \param legendRect Maximum geometry for the legend
707
 
  \return Geometry for the aligned legend
708
 
*/
709
 
QRect QwtPlotLayout::alignLegend(const QRect &canvasRect, 
710
 
    const QRect &legendRect) const
711
 
{
712
 
    QRect alignedRect = legendRect;
713
 
 
714
 
    if ( d_data->legendPos == QwtPlot::BottomLegend 
715
 
        || d_data->legendPos == QwtPlot::TopLegend )
716
 
    {
717
 
        if ( d_data->layoutData.legend.hint.width() < canvasRect.width() )
718
 
        {
719
 
            alignedRect.setX(canvasRect.x());
720
 
            alignedRect.setWidth(canvasRect.width());
721
 
        }
722
 
    }
723
 
    else
724
 
    {
725
 
        if ( d_data->layoutData.legend.hint.height() < canvasRect.height() )
726
 
        {
727
 
            alignedRect.setY(canvasRect.y());
728
 
            alignedRect.setHeight(canvasRect.height());
729
 
        }
730
 
    }
731
 
 
732
 
    return alignedRect;
733
 
}
734
 
 
735
 
/*!
736
 
  Expand all line breaks in text labels, and calculate the height
737
 
  of their widgets in orientation of the text.
738
 
 
739
 
  \param options Options how to layout the legend
740
 
  \param rect Bounding rect for title, axes and canvas.
741
 
  \param dimTitle Expanded height of the title widget
742
 
  \param dimAxis Expanded heights of the axis in axis orientation.
743
 
 
744
 
  \sa Options
745
 
*/
746
 
void QwtPlotLayout::expandLineBreaks(int options, const QRect &rect, 
747
 
    int &dimTitle, int dimAxis[QwtPlot::axisCnt]) const
748
 
{
749
 
    dimTitle = 0;
750
 
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
751
 
        dimAxis[axis] = 0;
752
 
 
753
 
    int backboneOffset[QwtPlot::axisCnt];
754
 
    for (int axis = 0; axis < QwtPlot::axisCnt; axis++ )
755
 
    {
756
 
        backboneOffset[axis] = 0;
757
 
        if ( !d_data->alignCanvasToScales )
758
 
            backboneOffset[axis] += d_data->canvasMargin[axis];
759
 
        if ( !(options & IgnoreFrames) )
760
 
            backboneOffset[axis] += d_data->layoutData.canvas.frameWidth;
761
 
    }
762
 
 
763
 
    bool done = false;
764
 
    while (!done)
765
 
    {
766
 
        done = true;
767
 
 
768
 
        // the size for the 4 axis depend on each other. Expanding
769
 
        // the height of a horizontal axis will shrink the height
770
 
        // for the vertical axis, shrinking the height of a vertical
771
 
        // axis will result in a line break what will expand the
772
 
        // width and results in shrinking the width of a horizontal
773
 
        // axis what might result in a line break of a horizontal
774
 
        // axis ... . So we loop as long until no size changes.
775
 
 
776
 
        if ( !d_data->layoutData.title.text.isEmpty() )
777
 
        {
778
 
            int w = rect.width();
779
 
 
780
 
            if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled
781
 
                != d_data->layoutData.scale[QwtPlot::yRight].isEnabled )
782
 
            {
783
 
                // center to the canvas
784
 
                w -= dimAxis[QwtPlot::yLeft] + dimAxis[QwtPlot::yRight]; 
785
 
            }
786
 
 
787
 
            int d = d_data->layoutData.title.text.heightForWidth(w);
788
 
            if ( !(options & IgnoreFrames) )
789
 
                d += 2 * d_data->layoutData.title.frameWidth;
790
 
 
791
 
            if ( d > dimTitle )
792
 
            {
793
 
                dimTitle = d;
794
 
                done = false;
795
 
            }
796
 
        }
797
 
 
798
 
        for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
799
 
        {
800
 
            const struct LayoutData::t_scaleData &scaleData = 
801
 
                d_data->layoutData.scale[axis];
802
 
 
803
 
            if (scaleData.isEnabled)
804
 
            {
805
 
                int length;
806
 
                if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom )
807
 
                {
808
 
                    length = rect.width() - dimAxis[QwtPlot::yLeft] 
809
 
                        - dimAxis[QwtPlot::yRight];
810
 
                    length -= scaleData.start + scaleData.end;
811
 
 
812
 
                    if ( dimAxis[QwtPlot::yRight] > 0 )
813
 
                        length -= 1;
814
 
 
815
 
                    length += qwtMin(dimAxis[QwtPlot::yLeft], 
816
 
                        scaleData.start - backboneOffset[QwtPlot::yLeft]);
817
 
                    length += qwtMin(dimAxis[QwtPlot::yRight], 
818
 
                        scaleData.end - backboneOffset[QwtPlot::yRight]);
819
 
                }
820
 
                else // QwtPlot::yLeft, QwtPlot::yRight
821
 
                {
822
 
                    length = rect.height() - dimAxis[QwtPlot::xTop] 
823
 
                        - dimAxis[QwtPlot::xBottom];
824
 
                    length -= scaleData.start + scaleData.end;
825
 
                    length -= 1;
826
 
 
827
 
                    if ( dimAxis[QwtPlot::xBottom] <= 0 )
828
 
                        length -= 1;
829
 
                    if ( dimAxis[QwtPlot::xTop] <= 0 )
830
 
                        length -= 1;
831
 
 
832
 
                    if ( dimAxis[QwtPlot::xBottom] > 0 )
833
 
                    {
834
 
                        length += qwtMin(
835
 
                            d_data->layoutData.scale[QwtPlot::xBottom].tickOffset, 
836
 
                            scaleData.start - backboneOffset[QwtPlot::xBottom]);
837
 
                    }
838
 
                    if ( dimAxis[QwtPlot::xTop] > 0 )
839
 
                    {
840
 
                        length += qwtMin(
841
 
                            d_data->layoutData.scale[QwtPlot::xTop].tickOffset, 
842
 
                            scaleData.end - backboneOffset[QwtPlot::xTop]);
843
 
                    }
844
 
 
845
 
                    if ( dimTitle > 0 )
846
 
                        length -= dimTitle + d_data->spacing;
847
 
                }
848
 
 
849
 
                int d = scaleData.dimWithoutTitle;
850
 
                if ( !scaleData.scaleWidget->title().isEmpty() )
851
 
                {
852
 
                    d += scaleData.scaleWidget->titleHeightForWidth(length);
853
 
                }
854
 
 
855
 
 
856
 
                if ( d > dimAxis[axis] )
857
 
                {
858
 
                    dimAxis[axis] = d;
859
 
                    done = false;
860
 
                }
861
 
            }
862
 
        }
863
 
    }
864
 
}
865
 
 
866
 
/*!
867
 
  Align the ticks of the axis to the canvas borders using
868
 
  the empty corners.
869
 
 
870
 
  \sa Options
871
 
*/
872
 
 
873
 
void QwtPlotLayout::alignScales(int options,
874
 
    QRect &canvasRect, QRect scaleRect[QwtPlot::axisCnt]) const
875
 
{
876
 
    int axis;
877
 
 
878
 
    int backboneOffset[QwtPlot::axisCnt];
879
 
    for (axis = 0; axis < QwtPlot::axisCnt; axis++ )
880
 
    {
881
 
        backboneOffset[axis] = 0;
882
 
        if ( !d_data->alignCanvasToScales )
883
 
            backboneOffset[axis] += d_data->canvasMargin[axis];
884
 
        if ( !(options & IgnoreFrames) )
885
 
            backboneOffset[axis] += d_data->layoutData.canvas.frameWidth;
886
 
    }
887
 
 
888
 
    for (axis = 0; axis < QwtPlot::axisCnt; axis++ )
889
 
    {
890
 
        if ( !scaleRect[axis].isValid() )
891
 
            continue;
892
 
 
893
 
        const int startDist = d_data->layoutData.scale[axis].start;
894
 
        const int endDist = d_data->layoutData.scale[axis].end;
895
 
 
896
 
        QRect &axisRect = scaleRect[axis];
897
 
 
898
 
        if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom )
899
 
        {
900
 
            const int leftOffset = 
901
 
                backboneOffset[QwtPlot::yLeft] - startDist;
902
 
 
903
 
            if ( scaleRect[QwtPlot::yLeft].isValid() )
904
 
            {
905
 
                int minLeft = scaleRect[QwtPlot::yLeft].left();
906
 
                int left = axisRect.left() + leftOffset;
907
 
                axisRect.setLeft(qwtMax(left, minLeft));
908
 
            }
909
 
            else
910
 
            {
911
 
                if ( d_data->alignCanvasToScales && leftOffset < 0 )
912
 
                {
913
 
                    canvasRect.setLeft(qwtMax(canvasRect.left(), 
914
 
                        axisRect.left() - leftOffset));
915
 
                }
916
 
                else
917
 
                {
918
 
                    if ( leftOffset > 0 )
919
 
                        axisRect.setLeft(axisRect.left() + leftOffset);
920
 
                }
921
 
            }
922
 
 
923
 
            const int rightOffset = 
924
 
                backboneOffset[QwtPlot::yRight] - endDist + 1;
925
 
 
926
 
            if ( scaleRect[QwtPlot::yRight].isValid() )
927
 
            {
928
 
                int maxRight = scaleRect[QwtPlot::yRight].right();
929
 
                int right = axisRect.right() - rightOffset;
930
 
                axisRect.setRight(qwtMin(right, maxRight));
931
 
            }
932
 
            else
933
 
            {
934
 
                if ( d_data->alignCanvasToScales && rightOffset < 0 )
935
 
                {
936
 
                    canvasRect.setRight( qwtMin(canvasRect.right(), 
937
 
                        axisRect.right() + rightOffset) );
938
 
                }
939
 
                else
940
 
                {
941
 
                    if ( rightOffset > 0 )
942
 
                        axisRect.setRight(axisRect.right() - rightOffset);
943
 
                }
944
 
            }
945
 
        }
946
 
        else // QwtPlot::yLeft, QwtPlot::yRight
947
 
        {
948
 
            const int bottomOffset = 
949
 
                backboneOffset[QwtPlot::xBottom] - endDist + 1;
950
 
 
951
 
            if ( scaleRect[QwtPlot::xBottom].isValid() )
952
 
            {
953
 
                int maxBottom = scaleRect[QwtPlot::xBottom].top() + 
954
 
                    d_data->layoutData.scale[QwtPlot::xBottom].tickOffset;
955
 
 
956
 
                int bottom = axisRect.bottom() - bottomOffset;
957
 
                axisRect.setBottom(qwtMin(bottom, maxBottom));
958
 
            }
959
 
            else
960
 
            {
961
 
                if ( d_data->alignCanvasToScales && bottomOffset < 0 )
962
 
                {
963
 
                    canvasRect.setBottom(qwtMin(canvasRect.bottom(), 
964
 
                        axisRect.bottom() + bottomOffset));
965
 
                }
966
 
                else
967
 
                {
968
 
                    if ( bottomOffset > 0 )
969
 
                        axisRect.setBottom(axisRect.bottom() - bottomOffset);
970
 
                }
971
 
            }
972
 
        
973
 
            const int topOffset = backboneOffset[QwtPlot::xTop] - startDist;
974
 
 
975
 
            if ( scaleRect[QwtPlot::xTop].isValid() )
976
 
            {
977
 
                int minTop = scaleRect[QwtPlot::xTop].bottom() -
978
 
                    d_data->layoutData.scale[QwtPlot::xTop].tickOffset;
979
 
 
980
 
                int top = axisRect.top() + topOffset;
981
 
                axisRect.setTop(qwtMax(top, minTop));
982
 
            }
983
 
            else
984
 
            {
985
 
                if ( d_data->alignCanvasToScales && topOffset < 0 )
986
 
                {
987
 
                    canvasRect.setTop(qwtMax(canvasRect.top(), 
988
 
                        axisRect.top() - topOffset));
989
 
                }
990
 
                else
991
 
                {
992
 
                    if ( topOffset > 0 )
993
 
                        axisRect.setTop(axisRect.top() + topOffset);
994
 
                }
995
 
            }
996
 
        }
997
 
    }
998
 
 
999
 
    if ( d_data->alignCanvasToScales )
1000
 
    {
1001
 
        /*
1002
 
          The canvas has been aligned to the scale with largest
1003
 
          border distances. Now we have to realign the other scale.
1004
 
         */
1005
 
 
1006
 
        int fw = 0;
1007
 
        if ( !(options & IgnoreFrames) )
1008
 
            fw = d_data->layoutData.canvas.frameWidth;
1009
 
 
1010
 
        if ( scaleRect[QwtPlot::xBottom].isValid() &&
1011
 
            scaleRect[QwtPlot::xTop].isValid() )
1012
 
        {
1013
 
            for ( int axis = QwtPlot::xBottom; axis <= QwtPlot::xTop; axis++ )
1014
 
            {
1015
 
                scaleRect[axis].setLeft(canvasRect.left() + fw
1016
 
                    - d_data->layoutData.scale[axis].start);
1017
 
                scaleRect[axis].setRight(canvasRect.right() - fw - 1
1018
 
                    + d_data->layoutData.scale[axis].end);
1019
 
            }
1020
 
        }
1021
 
 
1022
 
        if ( scaleRect[QwtPlot::yLeft].isValid() &&
1023
 
            scaleRect[QwtPlot::yRight].isValid() )
1024
 
        {
1025
 
            for ( int axis = QwtPlot::yLeft; axis <= QwtPlot::yRight; axis++ )
1026
 
            {
1027
 
                scaleRect[axis].setTop(canvasRect.top() + fw
1028
 
                    - d_data->layoutData.scale[axis].start);
1029
 
                scaleRect[axis].setBottom(canvasRect.bottom() - fw - 1
1030
 
                    + d_data->layoutData.scale[axis].end);
1031
 
            }
1032
 
        }
1033
 
    }
1034
 
}
1035
 
 
1036
 
/*!
1037
 
  \brief Recalculate the geometry of all components. 
1038
 
 
1039
 
  \param plot Plot to be layout
1040
 
  \param plotRect Rect where to place the components
1041
 
  \param options Options
1042
 
 
1043
 
  \sa invalidate(), Options, titleRect(),
1044
 
      legendRect(), scaleRect(), canvasRect()
1045
 
*/
1046
 
void QwtPlotLayout::activate(const QwtPlot *plot,
1047
 
    const QRect &plotRect, int options) 
1048
 
{
1049
 
    invalidate();
1050
 
 
1051
 
    QRect rect(plotRect);  // undistributed rest of the plot rect
1052
 
 
1053
 
    if ( !(options & IgnoreMargin) )
1054
 
    {
1055
 
        // subtract the margin
1056
 
 
1057
 
        rect.setRect(
1058
 
            rect.x() + d_data->margin, 
1059
 
            rect.y() + d_data->margin,
1060
 
            rect.width() - 2 * d_data->margin, 
1061
 
            rect.height() - 2 * d_data->margin
1062
 
        );
1063
 
    }
1064
 
 
1065
 
    // We extract all layout relevant data from the widgets,
1066
 
    // filter them through pfilter and save them to d_data->layoutData.
1067
 
 
1068
 
    d_data->layoutData.init(plot, rect);
1069
 
 
1070
 
    if (!(options & IgnoreLegend) 
1071
 
        && d_data->legendPos != QwtPlot::ExternalLegend
1072
 
        && plot->legend() && !plot->legend()->isEmpty() )
1073
 
    {
1074
 
        d_data->legendRect = layoutLegend(options, rect);
1075
 
 
1076
 
        // subtract d_data->legendRect from rect
1077
 
 
1078
 
        const QRegion region(rect);
1079
 
        rect = region.subtract(d_data->legendRect).boundingRect(); 
1080
 
 
1081
 
        if ( d_data->layoutData.legend.frameWidth && 
1082
 
            !(options & IgnoreFrames ) )
1083
 
        {
1084
 
            // In case of a frame we have to insert a spacing.
1085
 
            // Otherwise the leading of the font separates
1086
 
            // legend and scale/canvas
1087
 
 
1088
 
            switch(d_data->legendPos)
1089
 
            {
1090
 
                case QwtPlot::LeftLegend:
1091
 
                    rect.setLeft(rect.left() + d_data->spacing);
1092
 
                    break;
1093
 
                case QwtPlot::RightLegend:
1094
 
                    rect.setRight(rect.right() - d_data->spacing);
1095
 
                    break;
1096
 
                case QwtPlot::TopLegend:
1097
 
                    rect.setTop(rect.top() + d_data->spacing);
1098
 
                    break;
1099
 
                case QwtPlot::BottomLegend:
1100
 
                    rect.setBottom(rect.bottom() - d_data->spacing);
1101
 
                    break;
1102
 
                case QwtPlot::ExternalLegend:
1103
 
                    break; // suppress compiler warning
1104
 
            }
1105
 
        }
1106
 
    }
1107
 
 
1108
 
#ifdef __GNUC__
1109
 
#endif
1110
 
    /*
1111
 
     +---+-----------+---+
1112
 
     |       Title       |
1113
 
     +---+-----------+---+
1114
 
     |   |   Axis    |   |
1115
 
     +---+-----------+---+
1116
 
     | A |           | A |
1117
 
     | x |  Canvas   | x |
1118
 
     | i |           | i |
1119
 
     | s |           | s |
1120
 
     +---+-----------+---+
1121
 
     |   |   Axis    |   |
1122
 
     +---+-----------+---+
1123
 
    */
1124
 
 
1125
 
    // axes and title include text labels. The height of each
1126
 
    // label depends on its line breaks, that depend on the width
1127
 
    // for the label. A line break in a horizontal text will reduce
1128
 
    // the available width for vertical texts and vice versa. 
1129
 
    // expandLineBreaks finds the height/width for title and axes
1130
 
    // including all line breaks.
1131
 
 
1132
 
    int dimTitle, dimAxes[QwtPlot::axisCnt];
1133
 
    expandLineBreaks(options, rect, dimTitle, dimAxes);
1134
 
 
1135
 
    if (dimTitle > 0 )
1136
 
    {
1137
 
        d_data->titleRect = QRect(rect.x(), rect.y(),
1138
 
            rect.width(), dimTitle);
1139
 
 
1140
 
        if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled !=
1141
 
            d_data->layoutData.scale[QwtPlot::yRight].isEnabled )
1142
 
        {
1143
 
            // if only one of the y axes is missing we align
1144
 
            // the title centered to the canvas
1145
 
 
1146
 
            d_data->titleRect.setX(rect.x() + dimAxes[QwtPlot::yLeft]);
1147
 
            d_data->titleRect.setWidth(rect.width() 
1148
 
                - dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight]);
1149
 
        }
1150
 
 
1151
 
        // subtract title 
1152
 
        rect.setTop(rect.top() + dimTitle + d_data->spacing);
1153
 
    }
1154
 
 
1155
 
    d_data->canvasRect.setRect(
1156
 
        rect.x() + dimAxes[QwtPlot::yLeft],
1157
 
        rect.y() + dimAxes[QwtPlot::xTop],
1158
 
        rect.width() - dimAxes[QwtPlot::yRight] - dimAxes[QwtPlot::yLeft],
1159
 
        rect.height() - dimAxes[QwtPlot::xBottom] - dimAxes[QwtPlot::xTop]);
1160
 
 
1161
 
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
1162
 
    {
1163
 
        // set the rects for the axes
1164
 
 
1165
 
        if ( dimAxes[axis] )
1166
 
        {
1167
 
            int dim = dimAxes[axis];
1168
 
            QRect &scaleRect = d_data->scaleRect[axis];
1169
 
 
1170
 
            scaleRect = d_data->canvasRect;
1171
 
            switch(axis)
1172
 
            {
1173
 
                case QwtPlot::yLeft:
1174
 
                    scaleRect.setX(d_data->canvasRect.left() - dim);
1175
 
                    scaleRect.setWidth(dim);
1176
 
                    break;
1177
 
                case QwtPlot::yRight:
1178
 
                    scaleRect.setX(d_data->canvasRect.right() + 1);
1179
 
                    scaleRect.setWidth(dim);
1180
 
                    break;
1181
 
                case QwtPlot::xBottom:
1182
 
                    scaleRect.setY(d_data->canvasRect.bottom() + 1);
1183
 
                    scaleRect.setHeight(dim);
1184
 
                    break;
1185
 
                case QwtPlot::xTop:
1186
 
                    scaleRect.setY(d_data->canvasRect.top() - dim);
1187
 
                    scaleRect.setHeight(dim);
1188
 
                    break;
1189
 
            }
1190
 
#if QT_VERSION < 0x040000
1191
 
            scaleRect = scaleRect.normalize();
1192
 
#else
1193
 
            scaleRect = scaleRect.normalized();
1194
 
#endif
1195
 
        }
1196
 
    }
1197
 
 
1198
 
    // +---+-----------+---+
1199
 
    // |  <-   Axis   ->   |
1200
 
    // +-^-+-----------+-^-+
1201
 
    // | | |           | | |
1202
 
    // |   |           |   |
1203
 
    // | A |           | A |
1204
 
    // | x |  Canvas   | x |
1205
 
    // | i |           | i |
1206
 
    // | s |           | s |
1207
 
    // |   |           |   |
1208
 
    // | | |           | | |
1209
 
    // +-V-+-----------+-V-+
1210
 
    // |   <-  Axis   ->   |
1211
 
    // +---+-----------+---+
1212
 
 
1213
 
    // The ticks of the axes - not the labels above - should
1214
 
    // be aligned to the canvas. So we try to use the empty
1215
 
    // corners to extend the axes, so that the label texts
1216
 
    // left/right of the min/max ticks are moved into them.
1217
 
 
1218
 
    alignScales(options, d_data->canvasRect, d_data->scaleRect);
1219
 
 
1220
 
    if (!d_data->legendRect.isEmpty() )
1221
 
    {
1222
 
        // We prefer to align the legend to the canvas - not to
1223
 
        // the complete plot - if possible.
1224
 
 
1225
 
        d_data->legendRect = alignLegend(d_data->canvasRect, d_data->legendRect);
1226
 
    }
1227
 
}