File indexing completed on 2025-02-23 03:35:01

0001 /*
0002     File                 : CartesianPlotLegendPrivate.h
0003     Project              : LabPlot
0004     Description          : Private members of CartesianPlotLegend
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2013-2022 Alexander Semke <alexander.semke@web.de>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef CARTESIANPLOTLEGENDPRIVATE_H
0012 #define CARTESIANPLOTLEGENDPRIVATE_H
0013 
0014 #include "backend/worksheet/WorksheetElementPrivate.h"
0015 #include <QFont>
0016 
0017 class Background;
0018 class CartesianPlotLegend;
0019 class Line;
0020 class XYCurve;
0021 
0022 class QBrush;
0023 class QGraphicsSceneContextMenuEvent;
0024 class QKeyEvent;
0025 
0026 class CartesianPlotLegendPrivate : public WorksheetElementPrivate {
0027 public:
0028     explicit CartesianPlotLegendPrivate(CartesianPlotLegend* owner);
0029 
0030     CartesianPlotLegend* const q;
0031 
0032     void retransform() override;
0033     void updatePosition();
0034 
0035     // QGraphicsItem's virtual functions
0036     void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
0037     virtual QPainterPath shape() const override;
0038     virtual void recalcShapeAndBoundingRect() override;
0039 
0040     QFont labelFont;
0041     QColor labelColor;
0042     bool labelColumnMajor{true};
0043     qreal lineSymbolWidth{Worksheet::convertToSceneUnits(1, Worksheet::Unit::Centimeter)}; // the width of line+symbol
0044     QList<double> maxColumnTextWidths; // the maximal width of the text within each column
0045     int columnCount{0}; // the actual number of columns, can be smaller than the specified layoutColumnCount
0046     int rowCount{0}; // the number of rows in the legend, depends on the number of curves and on columnCount
0047 
0048     const CartesianPlot* plot{nullptr};
0049 
0050     TextLabel* title{nullptr};
0051     Background* background{nullptr};
0052 
0053     // Border
0054     Line* borderLine{nullptr};
0055     qreal borderCornerRadius{0.0};
0056 
0057     // Layout
0058     qreal layoutTopMargin{Worksheet::convertToSceneUnits(0.2, Worksheet::Unit::Centimeter)};
0059     qreal layoutBottomMargin{Worksheet::convertToSceneUnits(0.2, Worksheet::Unit::Centimeter)};
0060     qreal layoutLeftMargin{Worksheet::convertToSceneUnits(0.2, Worksheet::Unit::Centimeter)};
0061     qreal layoutRightMargin{Worksheet::convertToSceneUnits(0.2, Worksheet::Unit::Centimeter)};
0062     qreal layoutVerticalSpacing{Worksheet::convertToSceneUnits(0.1, Worksheet::Unit::Centimeter)};
0063     qreal layoutHorizontalSpacing{Worksheet::convertToSceneUnits(0.1, Worksheet::Unit::Centimeter)};
0064     int layoutColumnCount{1};
0065 
0066 private:
0067     QList<Plot*> m_plots; // list containing all visible plots/curves
0068     QStringList m_names;
0069 
0070     bool translatePainter(QPainter*, int& row, int& col, int height);
0071 };
0072 
0073 #endif