Skip to content
qwt_scale_draw.h 3.09 KiB
Newer Older
pixhawk's avatar
pixhawk committed
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
pixhawk's avatar
pixhawk committed
 * 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 "qwt_global.h"
#include "qwt_abstract_scale_draw.h"
Bryant's avatar
Bryant committed
#include <qpoint.h>
#include <qrect.h>
#include <qtransform.h>
pixhawk's avatar
pixhawk committed

/*!
  \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:
pixhawk's avatar
pixhawk committed
        Alignment of the scale draw
        \sa setAlignment(), alignment()
     */
Bryant's avatar
Bryant committed
    enum Alignment 
    { 
        //! The scale is below
        BottomScale, 
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
        //! The scale is above
        TopScale, 
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
        //! The scale is left
        LeftScale, 

        //! The scale is right
        RightScale 
    };
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    QwtScaleDraw();
    virtual ~QwtScaleDraw();
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void getBorderDistHint( const QFont &, int &start, int &end ) const;
    int minLabelDist( const QFont & ) const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    int minLength( const QFont & ) const;
    virtual double extent( const QFont & ) const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void move( double x, double y );
    void move( const QPointF & );
    void setLength( double length );
pixhawk's avatar
pixhawk committed

    Alignment alignment() const;
Bryant's avatar
Bryant committed
    void setAlignment( Alignment );
pixhawk's avatar
pixhawk committed

    Qt::Orientation orientation() const;

Bryant's avatar
Bryant committed
    QPointF pos() const;
    double length() const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void setLabelAlignment( Qt::Alignment );
pixhawk's avatar
pixhawk committed
    Qt::Alignment labelAlignment() const;

Bryant's avatar
Bryant committed
    void setLabelRotation( double rotation );
pixhawk's avatar
pixhawk committed
    double labelRotation() const;

Bryant's avatar
Bryant committed
    int maxLabelHeight( const QFont & ) const;
    int maxLabelWidth( const QFont & ) const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    QPointF labelPosition( double val ) const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    QRectF labelRect( const QFont &, double val ) const;
    QSizeF labelSize( const QFont &, double val ) const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    QRect boundingLabelRect( const QFont &, double val ) const;
pixhawk's avatar
pixhawk committed

protected:
Bryant's avatar
Bryant committed
    QTransform labelTransformation( const QPointF &, const QSizeF & ) const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    virtual void drawTick( QPainter *, double val, double len ) const;
    virtual void drawBackbone( QPainter * ) const;
    virtual void drawLabel( QPainter *, double val ) const;
pixhawk's avatar
pixhawk committed

private:
Bryant's avatar
Bryant committed
    QwtScaleDraw( const QwtScaleDraw & );
    QwtScaleDraw &operator=( const QwtScaleDraw &other );

pixhawk's avatar
pixhawk committed
    void updateMap();

    class PrivateData;
    PrivateData *d_data;
};

Bryant's avatar
Bryant committed
/*!
   Move the position of the scale

   \param x X coordinate
   \param y Y coordinate

   \sa move(const QPointF &)
*/
inline void QwtScaleDraw::move( double x, double y )
pixhawk's avatar
pixhawk committed
{
Bryant's avatar
Bryant committed
    move( QPointF( x, y ) );
pixhawk's avatar
pixhawk committed
}

#endif