QtiPlot 0.9.7.3

LegendWidget.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : LegendWidget.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2007 by Ion Vasilief
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : A 2D Plot Legend Widget
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
00027  *                                                                         *
00028  ***************************************************************************/
00029 #ifndef LEGENDWIDGET_H
00030 #define LEGENDWIDGET_H
00031 
00032 #include "FrameWidget.h"
00033 #include "Graph.h"
00034 
00035 #include <qwt_plot.h>
00036 #include <qwt_text.h>
00037 
00038 #include <QWidget>
00039 
00040 class PlotCurve;
00041 
00042 class LegendWidget: public FrameWidget
00043 {
00044     Q_OBJECT
00045 
00046 public:
00047     LegendWidget(Graph *);
00048     ~LegendWidget();
00049 
00050     void clone(LegendWidget* t);
00051 
00052     QString text(){return d_text->text();};
00053     void setText(const QString& s);
00054 
00055     QColor textColor(){return d_text->color();};
00056     void setTextColor(const QColor& c);
00057 
00058     QFont font(){return d_text->font();};
00059     void setFont(const QFont& font);
00060 
00061     void showTextEditor();
00062     void print(QPainter *p, const QwtScaleMap map[QwtPlot::axisCnt]);
00063 
00064     QString saveToString();
00065     static void restore(Graph *g, const QStringList& lst);
00066 
00067     bool isAutoUpdateEnabled(){return d_auto_update;};
00068     void setAutoUpdate(bool on = true){d_auto_update = on;};
00069 
00070     int angle(){return d_angle;};
00071     void setAngle(int angle);
00072 
00073     QSize textSize(QPainter *p, const QwtText& text);
00074 
00075     bool hasTeXOutput(){return d_tex_output;};
00076     void setTeXOutput(bool on = true){d_tex_output = on;};
00077 
00078 private:
00079     PlotCurve* getCurve(const QString& s, int &point);
00080     void drawVector(PlotCurve *c, QPainter *p, int x, int y, int l);
00081     void drawSymbol(PlotCurve *c, int point, QPainter *p, int x, int y, int l);
00082     void drawText(QPainter *, const QRect&, QwtArray<long>, int);
00083 
00084     QwtArray<long> itemsHeight(QPainter *p, int symbolLineLength, int &width, int &height, int &textWidth, int &textHeight);
00085     int symbolsMaxWidth();
00086     QString parse(const QString& str);
00087 
00088     virtual void paintEvent(QPaintEvent *e);
00089 
00091     QwtText* d_text;
00093     int d_angle;
00095     int h_space;
00097     int left_margin, top_margin;
00099     int line_length;
00101     bool d_auto_update;
00103     bool d_tex_output;
00104 
00105 signals:
00106     void enableEditor();
00107 };
00108 
00109 #endif