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 43 /** 44 * \brief A piece of text to be drawn on a Plot. 45 * 46 * Contrary to its name, Legend is not just used for the plot legend, 47 * but for any kind of text; particularly also for the "Add Text" tool. 48 * Accordingly, it is also referred to as "TextMarker" by other classes. 49 * 50 * \section future_plans Future Plans 51 * Rename to TextMarker (or maybe TextEnrichment; see documentation of ImageMarker for details). 52 * 53 * \sa ImageMarker, ArrowMarker 54 */ 55 class Legend : public PlotEnrichement 56 { 57 public: 58 Legend(Plot *); 59 ~Legend(); 60 61 //! The kinds of frame a Legend can draw around the Text. 62 enum FrameStyle { None = 0, Line = 1, Shadow = 2 }; 63 text()64 QString text() { return d_text->text(); }; 65 void setText(const QString &s); 66 67 //! Bounding rectangle in paint coordinates. 68 QRect rect() const; 69 //! Bounding rectangle in plot coordinates. 70 virtual QwtDoubleRect boundingRect() const; 71 72 void setOrigin(const QPoint &p); 73 74 //! Sets the position of the top left corner in axis coordinates 75 void setOriginCoord(double x, double y); 76 77 //! Keep the markers on screen each time the scales are modified by adding/removing curves 78 void updateOrigin(); 79 textColor()80 QColor textColor() { return d_text->color(); }; 81 void setTextColor(const QColor &c); 82 backgroundColor()83 QColor backgroundColor() { return d_text->backgroundBrush().color(); }; 84 void setBackgroundColor(const QColor &c); 85 frameStyle()86 int frameStyle() { return d_frame; }; 87 void setFrameStyle(int style); 88 font()89 QFont font() { return d_text->font(); }; 90 void setFont(const QFont &font); 91 angle()92 int angle() { return d_angle; }; setAngle(int ang)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, QwtArray<long> height, 100 int symbolLineLength) const; 101 void drawLegends(QPainter *p, const QRect &rect, QwtArray<long> height, 102 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: 110 //! Parent plot 111 Plot *d_plot; 112 113 //! Frame type 114 int d_frame; 115 116 //! Rotation angle: not implemented yet 117 int d_angle; 118 119 //! Pointer to the QwtText object 120 QwtText *d_text; 121 122 //! TopLeft position in pixels 123 QPoint d_pos; 124 125 //!Distance between symbols and legend text 126 int hspace; 127 128 //!Distance between frame and content 129 int left_margin, top_margin; 130 131 int d_shadow_size_x, d_shadow_size_y; 132 }; 133 134 #endif 135