LegendWidget.h 4.4 KB
Newer Older
Roman Tolchenov's avatar
re #79  
Roman Tolchenov committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/***************************************************************************
    File                 : LegendWidget.h
    Project              : QtiPlot
    --------------------------------------------------------------------
    Copyright            : (C) 2007 by Ion Vasilief
    Email (use @ for *)  : ion_vasilief*yahoo.fr
    Description          : A 2D Plot Legend Widget

 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *  This program is free software; you can redistribute it and/or modify   *
 *  it under the terms of the GNU General Public License as published by   *
 *  the Free Software Foundation; either version 2 of the License, or      *
 *  (at your option) any later version.                                    *
 *                                                                         *
 *  This program is distributed in the hope that it will be useful,        *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *  GNU General Public License for more details.                           *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the Free Software           *
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
 *   Boston, MA  02110-1301  USA                                           *
 *                                                                         *
 ***************************************************************************/
#ifndef LEGENDWIDGET_H
#define LEGENDWIDGET_H

#include <QWidget>
#include <qwt_plot.h>
#include <qwt_text.h>

#include "Graph.h"
#include "Plot.h"

class LegendWidget: public QWidget
{
	Q_OBJECT

public:
44
  explicit LegendWidget(Plot *);
45
  ~LegendWidget() override;
Roman Tolchenov's avatar
re #79  
Roman Tolchenov committed
46

47
        void clone(LegendWidget* t);
Roman Tolchenov's avatar
re #79  
Roman Tolchenov committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
	QwtPlot *plot(){return d_plot;};

	//! The kinds of frame a LegendWidget can draw around the Text.
	enum FrameStyle{None = 0, Line = 1, Shadow = 2};

	QString text(){return d_text->text();};
	void setText(const QString& s);

	//! Sets the position of the top left corner in axis coordinates
	void setOriginCoord(double x, double y);
	//! Sets the position of the top left corner in paint coordinates
	void setOrigin(int x, int y){move(x, y);};

	QColor textColor(){return d_text->color();};
	void setTextColor(const QColor& c);

	QColor backgroundColor(){return d_text->backgroundBrush().color();};
	void setBackgroundColor(const QColor& c);

	int frameStyle(){return d_frame;};
	void setFrameStyle(int style);

	QFont font(){return d_text->font();};
	void setFont(const QFont& font);

	int angle(){return d_angle;};
Peterson, Peter's avatar
Peterson, Peter committed
74
	void setAngle(int ang){d_angle = ang;};
Roman Tolchenov's avatar
re #79  
Roman Tolchenov committed
75
76
77

	double xValue();
	double yValue();
Peterson, Peter's avatar
Peterson, Peter committed
78

Roman Tolchenov's avatar
re #79  
Roman Tolchenov committed
79
80
81
82
83
	void setSelected(bool on = true);

	void showTextEditor();
	void showTextDialog(){emit showDialog();};
	void showContextMenu(){emit showMenu();};
Peterson, Peter's avatar
Peterson, Peter committed
84

85
  void print(QPainter *p, const QwtScaleMap map[QwtPlot::axisCnt]);
Roman Tolchenov's avatar
re #79  
Roman Tolchenov committed
86
87
88
89
90
	void setFixedCoordinatesMode(bool on = true);
	
private:
	PlotCurve* getCurve(const QString& s, int &point);
	void drawFrame(QPainter *p, const QRect& rect);
Peterson, Peter's avatar
Peterson, Peter committed
91
	void drawVector(PlotCurve *c, QPainter *p, int x, int y, int l);
Roman Tolchenov's avatar
re #79  
Roman Tolchenov committed
92
	void drawSymbol(PlotCurve *c, int point, QPainter *p, int x, int y, int l);
93
	void drawText(QPainter *, const QRect&, QwtArray<int>, int);
Roman Tolchenov's avatar
re #79  
Roman Tolchenov committed
94

95
	QwtArray<int> itemsHeight(int y, int symbolLineLength, int &width, int &height);
Roman Tolchenov's avatar
re #79  
Roman Tolchenov committed
96
97
98
	int symbolsMaxWidth();
	QString parse(const QString& str);

99
100
101
102
103
        void paintEvent(QPaintEvent *e) override;
        void mousePressEvent(QMouseEvent *e) override;
        void contextMenuEvent(QContextMenuEvent *) override {
          emit showMenu();
        };
Roman Tolchenov's avatar
re #79  
Roman Tolchenov committed
104

105
        //! Parent plot
Roman Tolchenov's avatar
re #79  
Roman Tolchenov committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
	Plot *d_plot;

	//! Frame type
	int d_frame;

	//! Rotation angle: not implemented yet
	int d_angle;

	//! Pointer to the QwtText object
	QwtText* d_text;

	//! Distance between symbols and legend text
	int h_space;

	//! Distance between frame and content
	int left_margin, top_margin;

	//! Length of the symbol line
	int line_length;
Peterson, Peter's avatar
Peterson, Peter committed
125

Roman Tolchenov's avatar
re #79  
Roman Tolchenov committed
126
127
128
129
130
131
132
133
134
135
136
137
	SelectionMoveResizer *d_selector;
	
	double d_x, d_y;
	bool d_fixed_coordinates;

signals:
	void showDialog();
	void showMenu();
	void enableEditor();
};

#endif