SciDAVis  1.D4
Legend.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : Legend.h
3  Project : SciDAVis
4  --------------------------------------------------------------------
5  Copyright : (C) 2006 by Ion Vasilief, Tilman Benkert
6  Email (use @ for *) : ion_vasilief*yahoo.fr, thzs*gmx.net
7  Description : Legend marker (extension to QwtPlotMarker)
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  * This program is distributed in the hope that it will be useful, *
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21  * GNU General Public License for more details. *
22  * *
23  * You should have received a copy of the GNU General Public License *
24  * along with this program; if not, write to the Free Software *
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26  * Boston, MA 02110-1301 USA *
27  * *
28  ***************************************************************************/
29 #ifndef LEGENDMARKER_H
30 #define LEGENDMARKER_H
31 
32 #include <qfont.h>
33 #include <qpen.h>
34 
35 #include <qwt_plot.h>
36 #include <qwt_array.h>
37 #include <qwt_text.h>
38 
39 #include "Graph.h"
40 #include "Plot.h"
41 #include "PlotEnrichement.h"
42 
55 class Legend: public PlotEnrichement
56 {
57 public:
58  Legend(Plot *);
59  ~Legend();
60 
62  enum FrameStyle{None = 0, Line = 1, Shadow=2};
63 
64  QString text(){return d_text->text();};
65  void setText(const QString& s);
66 
68  QRect rect() const;
70  virtual QwtDoubleRect boundingRect() const;
71 
72  void setOrigin(const QPoint & p);
73 
75  void setOriginCoord(double x, double y);
76 
78  void updateOrigin();
79 
80  QColor textColor(){return d_text->color();};
81  void setTextColor(const QColor& c);
82 
83  QColor backgroundColor(){return d_text->backgroundBrush().color();};
84  void setBackgroundColor(const QColor& c);
85 
86  int frameStyle(){return d_frame;};
87  void setFrameStyle(int style);
88 
89  QFont font(){return d_text->font();};
90  void setFont(const QFont& font);
91 
92  int angle(){return d_angle;};
93  void setAngle(int ang){d_angle=ang;};
94 
95 private:
96  void draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &r) const;
97 
98  void drawFrame(QPainter *p, int type, const QRect& rect) const;
99  void drawSymbols(QPainter *p, const QRect& rect,
100  QwtArray<long> height, int symbolLineLength) const;
101  void drawLegends(QPainter *p, const QRect& rect,
102  QwtArray<long> height, int symbolLineLength) const;
103  void drawVector(QPainter *p, int x, int y, int l, int curveIndex) const;
104 
105  QwtArray<long> itemsHeight(int y, int symbolLineLength, int &width, int &height) const;
106  int symbolsMaxLineLength() const;
107  QString parse(const QString& str) const;
108 
109 protected:
112 
114  int d_frame;
115 
117  int d_angle;
118 
120  QwtText* d_text;
121 
123  QPoint d_pos;
124 
126  int hspace;
127 
130 
132 };
133 
134 #endif