| 
									
										
										
										
											2021-01-01 17:55:44 +01:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							|  |  |  | // A legend box, which is shown on the chart.
 | 
					
						
							|  |  |  | #ifndef STATS_LEGEND_H
 | 
					
						
							|  |  |  | #define STATS_LEGEND_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 15:20:05 +01:00
										 |  |  | #include "chartitem.h"
 | 
					
						
							| 
									
										
										
										
											2021-01-03 12:49:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-01 17:55:44 +01:00
										 |  |  | #include <memory>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							| 
									
										
										
										
											2021-01-12 15:20:05 +01:00
										 |  |  | #include <QFont>
 | 
					
						
							| 
									
										
										
										
											2021-01-01 17:55:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 15:20:05 +01:00
										 |  |  | class QFontMetrics; | 
					
						
							| 
									
										
										
										
											2021-01-01 17:55:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 15:20:05 +01:00
										 |  |  | class Legend : public ChartRectItem { | 
					
						
							| 
									
										
										
										
											2021-01-01 17:55:44 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2021-01-12 15:20:05 +01:00
										 |  |  | 	Legend(StatsView &view, const std::vector<QString> &names); | 
					
						
							| 
									
										
										
										
											2021-01-01 17:55:44 +01:00
										 |  |  | 	void resize(); // called when the chart size changes.
 | 
					
						
							| 
									
										
										
										
											2021-01-13 21:15:11 +01:00
										 |  |  | 	void setPos(QPointF pos); // Attention: not virtual - always call on this class.
 | 
					
						
							| 
									
										
										
										
											2021-01-01 17:55:44 +01:00
										 |  |  | private: | 
					
						
							|  |  |  | 	// Each entry is a text besides a rectangle showing the color
 | 
					
						
							|  |  |  | 	struct Entry { | 
					
						
							| 
									
										
										
										
											2021-01-12 15:20:05 +01:00
										 |  |  | 		QString name; | 
					
						
							|  |  |  | 		QBrush rectBrush; | 
					
						
							| 
									
										
										
										
											2021-01-01 17:55:44 +01:00
										 |  |  | 		QPointF pos; | 
					
						
							|  |  |  | 		double width; | 
					
						
							| 
									
										
										
										
											2021-01-12 15:20:05 +01:00
										 |  |  | 		Entry(const QString &name, int idx, int numBins, const QFontMetrics &fm); | 
					
						
							| 
									
										
										
										
											2021-01-01 17:55:44 +01:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 	int displayedItems; | 
					
						
							|  |  |  | 	double width; | 
					
						
							|  |  |  | 	double height; | 
					
						
							| 
									
										
										
										
											2021-01-12 15:20:05 +01:00
										 |  |  | 	QFont font; | 
					
						
							| 
									
										
										
										
											2021-01-13 21:15:11 +01:00
										 |  |  | 	// The position is specified with respect to the center and in relative terms
 | 
					
						
							|  |  |  | 	// with respect to the canvas.
 | 
					
						
							|  |  |  | 	QPointF centerPos; | 
					
						
							|  |  |  | 	bool posInitialized; | 
					
						
							| 
									
										
										
										
											2021-01-01 17:55:44 +01:00
										 |  |  | 	int fontHeight; | 
					
						
							|  |  |  | 	std::vector<Entry> entries; | 
					
						
							|  |  |  | 	void hide(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 |