Skip to content
qwt_abstract_scale_draw.h 3.53 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_ABSTRACT_SCALE_DRAW_H
#define QWT_ABSTRACT_SCALE_DRAW_H

#include "qwt_global.h"
#include "qwt_scale_div.h"
#include "qwt_text.h"

class QPalette;
class QPainter;
class QFont;
Bryant's avatar
Bryant committed
class QwtTransform;
pixhawk's avatar
pixhawk committed
class QwtScaleMap;

/*!
  \brief A abstract base class for drawing scales

  QwtAbstractScaleDraw can be used to draw linear or logarithmic scales.

  After a scale division has been specified as a QwtScaleDiv object
Bryant's avatar
Bryant committed
  using setScaleDiv(), the scale can be drawn with the draw() member.
pixhawk's avatar
pixhawk committed
*/
class QWT_EXPORT QwtAbstractScaleDraw
{
public:

    /*!
       Components of a scale
Bryant's avatar
Bryant committed
       \sa enableComponent(), hasComponent
    */
    enum ScaleComponent
    {
        //! Backbone = the line where the ticks are located
        Backbone = 0x01,
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
        //! Ticks
        Ticks = 0x02,
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
        //! Labels
        Labels = 0x04
pixhawk's avatar
pixhawk committed
    };
Bryant's avatar
Bryant committed
    //! Scale components
    typedef QFlags<ScaleComponent> ScaleComponents;

pixhawk's avatar
pixhawk committed
    QwtAbstractScaleDraw();
    virtual ~QwtAbstractScaleDraw();

Bryant's avatar
Bryant committed
    void setScaleDiv( const QwtScaleDiv &s );
pixhawk's avatar
pixhawk committed
    const QwtScaleDiv& scaleDiv() const;

Bryant's avatar
Bryant committed
    void setTransformation( QwtTransform * );
    const QwtScaleMap &scaleMap() const;
    QwtScaleMap &scaleMap();
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void enableComponent( ScaleComponent, bool enable = true );
    bool hasComponent( ScaleComponent ) const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void setTickLength( QwtScaleDiv::TickType, double length );
    double tickLength( QwtScaleDiv::TickType ) const;
    double maxTickLength() const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void setSpacing( double margin );
    double spacing() const;
Bryant's avatar
Bryant committed
    void setPenWidth( int width );
    int penWidth() const;

    virtual void draw( QPainter *, const QPalette & ) const;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    virtual QwtText label( double ) const;
pixhawk's avatar
pixhawk committed

    /*!
      Calculate the extent
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
      The extent is the distance from the baseline to the outermost
pixhawk's avatar
pixhawk committed
      pixel of the scale draw in opposite to its orientation.
      It is at least minimumExtent() pixels.
Bryant's avatar
Bryant committed
      \param font Font used for drawing the tick labels
      \return Number of pixels

pixhawk's avatar
pixhawk committed
      \sa setMinimumExtent(), minimumExtent()
    */
Bryant's avatar
Bryant committed
    virtual double extent( const QFont &font ) const = 0;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    void setMinimumExtent( double );
    double minimumExtent() const;
pixhawk's avatar
pixhawk committed

protected:
    /*!
       Draw a tick
pixhawk's avatar
pixhawk committed
       \param painter Painter
       \param value Value of the tick
Bryant's avatar
Bryant committed
       \param len Length of the tick
pixhawk's avatar
pixhawk committed

       \sa drawBackbone(), drawLabel()
Bryant's avatar
Bryant committed
    virtual void drawTick( QPainter *painter, double value, double len ) const = 0;
pixhawk's avatar
pixhawk committed

    /*!
      Draws the baseline of the scale
      \param painter Painter

      \sa drawTick(), drawLabel()
    */
Bryant's avatar
Bryant committed
    virtual void drawBackbone( QPainter *painter ) const = 0;
pixhawk's avatar
pixhawk committed

pixhawk's avatar
pixhawk committed
        Draws the label for a major scale tick
pixhawk's avatar
pixhawk committed
        \param painter Painter
        \param value Value

Bryant's avatar
Bryant committed
        \sa drawTick(), drawBackbone()
Bryant's avatar
Bryant committed
    virtual void drawLabel( QPainter *painter, double value ) const = 0;
pixhawk's avatar
pixhawk committed

    void invalidateCache();
Bryant's avatar
Bryant committed
    const QwtText &tickLabel( const QFont &, double value ) const;
pixhawk's avatar
pixhawk committed

private:
Bryant's avatar
Bryant committed
    QwtAbstractScaleDraw( const QwtAbstractScaleDraw & );
    QwtAbstractScaleDraw &operator=( const QwtAbstractScaleDraw & );
pixhawk's avatar
pixhawk committed

    class PrivateData;
    PrivateData *d_data;
};

Bryant's avatar
Bryant committed
Q_DECLARE_OPERATORS_FOR_FLAGS( QwtAbstractScaleDraw::ScaleComponents )

pixhawk's avatar
pixhawk committed
#endif