qwt_scale_draw.h 2.9 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
5
 *
pixhawk's avatar
pixhawk committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#ifndef QWT_SCALE_DRAW_H
#define QWT_SCALE_DRAW_H

#include <qpoint.h>
#include "qwt_global.h"
#include "qwt_abstract_scale_draw.h"

/*!
  \brief A class for drawing scales

  QwtScaleDraw can be used to draw linear or logarithmic scales.
  A scale has a position, an alignment and a length, which can be specified .
  The labels can be rotated and aligned
  to the ticks using setLabelRotation() and setLabelAlignment().

  After a scale division has been specified as a QwtScaleDiv object
  using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s),
  the scale can be drawn with the QwtAbstractScaleDraw::draw() member.
*/

class QWT_EXPORT QwtScaleDraw: public QwtAbstractScaleDraw
{
public:
33
    /*!
pixhawk's avatar
pixhawk committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
        Alignment of the scale draw
        \sa setAlignment(), alignment()
     */
    enum Alignment { BottomScale, TopScale, LeftScale, RightScale };

    QwtScaleDraw();
    QwtScaleDraw(const QwtScaleDraw &);

    virtual ~QwtScaleDraw();

    QwtScaleDraw &operator=(const QwtScaleDraw &other);

    void getBorderDistHint(const QFont &, int &start, int &end) const;
    int minLabelDist(const QFont &) const;

    int minLength(const QPen &, const QFont &) const;
    virtual int extent(const QPen &, const QFont &) const;

    void move(int x, int y);
    void move(const QPoint &);
    void setLength(int length);

    Alignment alignment() const;
    void setAlignment(Alignment);

    Qt::Orientation orientation() const;

    QPoint pos() const;
    int length() const;

#if QT_VERSION < 0x040000
    void setLabelAlignment(int);
    int labelAlignment() const;
#else
    void setLabelAlignment(Qt::Alignment);
    Qt::Alignment labelAlignment() const;
#endif

    void setLabelRotation(double rotation);
    double labelRotation() const;

    int maxLabelHeight(const QFont &) const;
    int maxLabelWidth(const QFont &) const;

    QPoint labelPosition(double val) const;

    QRect labelRect(const QFont &, double val) const;
    QSize labelSize(const QFont &, double val) const;

    QRect boundingLabelRect(const QFont &, double val) const;

protected:

#if QT_VERSION < 0x040000
    QWMatrix labelMatrix(const QPoint &, const QSize &) const;
89
#else
pixhawk's avatar
pixhawk committed
90
    QMatrix labelMatrix(const QPoint &, const QSize &) const;
91
#endif
pixhawk's avatar
pixhawk committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

    virtual void drawTick(QPainter *p, double val, int len) const;
    virtual void drawBackbone(QPainter *p) const;
    virtual void drawLabel(QPainter *p, double val) const;

private:
    void updateMap();

    class PrivateData;
    PrivateData *d_data;
};

inline void QwtScaleDraw::move(int x, int y)
{
    move(QPoint(x, y));
}

#endif