Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

qwt_legend.h

00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
00002  * Qwt Widget Library
00003  * Copyright (C) 1997   Josef Wilgen
00004  * Copyright (C) 2002   Uwe Rathmann
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the Qwt License, Version 1.0
00008  *****************************************************************************/
00009 
00010 // vim: expandtab
00011 
00012 #ifndef QWT_LEGEND_H
00013 #define QWT_LEGEND_H
00014 
00015 #include <qpen.h>
00016 #include <qscrollview.h>
00017 #include <qlabel.h>
00018 #include "qwt_global.h"
00019 #include "qwt_symbol.h"
00020 #include "qwt_push_button.h"
00021 
00022 #if QT_VERSION < 0x040000
00023 #include <qwidgetintdict.h>
00024 #else
00025 #include "qwt_plot_dict.h"
00026 class QWT_EXPORT QWidgetIntDict: public QwtSeqDict<QWidget>
00027 {
00028 public:
00029     QWidgetIntDict() {}
00030 };
00031 typedef QIntDictIterator<QWidget> QWidgetIntDictIt;
00032 #endif
00033 
00034 class QPainter;
00035 class QwtText;
00036 
00041 class QwtLegendItem
00042 {
00043 public:
00051     enum IdentifierMode
00052     {
00053         NoIdentifier = 0,
00054         ShowLine = 1,
00055         ShowSymbol = 2,
00056         ShowText = 4
00057     };
00058 
00059     QwtLegendItem();
00060     QwtLegendItem(const QwtSymbol &, const QPen &);
00061 
00062     virtual ~QwtLegendItem();
00063 
00064     void setIdentifierMode(int);
00065     int identifierMode() const;
00066 
00067     void setSymbol(const QwtSymbol &);
00068     const QwtSymbol& symbol() const;
00069 
00070     void setCurvePen(const QPen &);
00071     const QPen& curvePen() const;
00072 
00073     virtual void drawIdentifier(QPainter *, const QRect &) const;
00074     virtual void drawItem(QPainter *p, const QRect &) const; 
00075     
00076     virtual void setTitle(const QString &) = 0;
00077     virtual QString title() const = 0;
00078 
00079 protected:
00080     virtual QwtText *titleText() const = 0;
00081     virtual void updateItem();
00082 
00083 private:
00084     int d_identifierMode; 
00085     QwtSymbol d_symbol;
00086     QPen d_curvePen;
00087 };
00088 
00099 class QWT_EXPORT QwtLegendButton: public QwtPushButton, public QwtLegendItem
00100 {
00101     Q_OBJECT
00102 public:
00103     QwtLegendButton(QWidget *parent = 0, const char *name = 0);
00104     QwtLegendButton(const QwtSymbol &, const QPen &,
00105         const QString &, QWidget *parent = 0, const char *name = 0);
00106 
00107     virtual void setTitle(const QString &);
00108     virtual QString title() const;
00109 
00110 protected:
00111     virtual QwtText *titleText() const;
00112     virtual void updateItem();
00113     virtual void updateIconset();
00114 
00115 private:
00116     void init();
00117 };
00118 
00128 class QWT_EXPORT QwtLegendLabel: public QLabel, public QwtLegendItem
00129 {
00130     Q_OBJECT
00131 public:
00132     QwtLegendLabel(QWidget *parent = 0, const char *name = 0);
00133     QwtLegendLabel(const QwtSymbol &, const QPen &,
00134         const QString &, QWidget *parent = 0, const char *name = 0);
00135 
00136     virtual void setTitle(const QString &);
00137     virtual QString title() const;
00138 
00139 protected:
00140     virtual QwtText *titleText() const;
00141     virtual void drawContents(QPainter *);
00142     virtual void updateItem();
00143 
00144 private:
00145     void init();
00146 };
00147 
00158 class QWT_EXPORT QwtLegend : public QScrollView
00159 {
00160     Q_OBJECT
00161 
00162     Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
00163 
00164 public:
00165 
00187     enum LegendDisplayPolicy
00188     {
00189         None = 0,
00190         Fixed = 1,
00191         Auto = 2
00192     };
00193 
00194     QwtLegend(QWidget *parent = 0, const char *name = 0);
00195     
00196     void setReadOnly(bool readOnly);
00197     bool isReadOnly() const;
00198 
00199     void setDisplayPolicy(LegendDisplayPolicy policy, int mode = -1);
00200     LegendDisplayPolicy displayPolicy() const;
00201 
00202     int identifierMode() const;
00203 
00204     QWidget *contentsWidget();
00205     const QWidget *contentsWidget() const;
00206 
00207     void insertItem(QWidget *, long key);
00208     QWidget *findItem(long key);
00209     const QWidget *findItem(long key) const;
00210     QWidget *takeItem(long key);
00211 
00212     virtual QWidgetIntDictIt itemIterator() const;
00213 
00214     long key(const QWidget *) const;
00215 
00216     void clear();
00217     
00218     bool isEmpty() const;
00219     uint itemCount() const;
00220 
00221     virtual bool eventFilter(QObject *, QEvent *);
00222 
00223     virtual QSize sizeHint() const;
00224     virtual int heightForWidth(int w) const;
00225 
00226 protected:
00227     virtual void viewportResizeEvent(QResizeEvent *);
00228     virtual void layoutContents();
00229 
00230 private:
00231     bool d_readOnly;
00232     LegendDisplayPolicy d_displayPolicy;
00233     int d_identifierMode;
00234     QWidgetIntDict d_items;
00235     QWidget *d_contentsWidget;
00236 };
00237 
00239 inline bool QwtLegend::isEmpty() const 
00240 { 
00241     return d_items.count() == 0; 
00242 }
00243 
00245 inline uint QwtLegend::itemCount() const 
00246 { 
00247     return d_items.count(); 
00248 }
00249 
00250 #endif // QWT_LEGEND_H

Generated on Sun Nov 21 11:12:43 2004 for Qwt User's Guide by doxygen 1.3.5