File indexing completed on 2024-05-12 03:47:29
0001 /* 0002 File : DatapickerImage.h 0003 Project : LabPlot 0004 Description : Worksheet for Datapicker 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2015 Ankit Wagadre <wagadre.ankit@gmail.com> 0007 SPDX-FileCopyrightText: 2015-2021 Alexander Semke <alexander.semke@web.de> 0008 0009 SPDX-License-Identifier: GPL-2.0-or-later 0010 */ 0011 0012 #ifndef DATAPICKERIMAGE_H 0013 #define DATAPICKERIMAGE_H 0014 0015 #include "Vector3D.h" 0016 #include "backend/core/AbstractPart.h" 0017 #include "backend/lib/macros.h" 0018 #include "backend/worksheet/plots/cartesian/Symbol.h" 0019 0020 #include <QPen> 0021 0022 class DatapickerImagePrivate; 0023 class DatapickerImageView; 0024 class DatapickerPoint; 0025 class Segments; 0026 0027 class QGraphicsScene; 0028 class QGraphicsPixmapItem; 0029 0030 class DatapickerImage : public AbstractPart { 0031 Q_OBJECT 0032 0033 public: 0034 explicit DatapickerImage(const QString& name, bool loading = false); 0035 ~DatapickerImage() override; 0036 0037 enum class GraphType { Linear, PolarInDegree, PolarInRadians, LnX, LnY, Ternary, LnXY, Log10XY, Log10X, Log10Y }; 0038 enum class ColorAttributes { None, Intensity, Foreground, Hue, Saturation, Value }; 0039 enum class PlotImageType { NoImage, OriginalImage, ProcessedImage }; 0040 enum class PointsType { AxisPoints, CurvePoints, SegmentPoints }; 0041 0042 struct ReferencePoints { 0043 GraphType type{GraphType::Linear}; 0044 QPointF scenePos[3]; 0045 Vector3D logicalPos[3]; 0046 double ternaryScale{1.0}; 0047 bool datetime{false}; // Datetime for the x axis 0048 }; 0049 0050 struct EditorSettings { 0051 int hueThresholdLow{0}; 0052 int hueThresholdHigh{360}; 0053 int saturationThresholdLow{0}; 0054 int saturationThresholdHigh{100}; 0055 int valueThresholdLow{0}; 0056 int valueThresholdHigh{100}; 0057 int intensityThresholdLow{0}; 0058 int intensityThresholdHigh{100}; 0059 int foregroundThresholdLow{20}; 0060 int foregroundThresholdHigh{100}; 0061 }; 0062 0063 QIcon icon() const override; 0064 QMenu* createContextMenu() override; 0065 void createContextMenu(QMenu*); 0066 QWidget* view() const override; 0067 0068 bool exportView() const override; 0069 bool printView() override; 0070 bool printPreview() const override; 0071 0072 void save(QXmlStreamWriter*) const override; 0073 bool load(XmlStreamReader*, bool preview) override; 0074 0075 QRectF pageRect() const; 0076 void setPageRect(const QRectF&); 0077 QGraphicsScene* scene() const; 0078 void setPrinting(bool) const; 0079 void setSelectedInView(const bool); 0080 void setSegmentsHoverEvent(const bool); 0081 int currentSelectedReferencePoint() const; 0082 0083 void setPlotImageType(const DatapickerImage::PlotImageType); 0084 DatapickerImage::PlotImageType plotImageType() const; 0085 void setImage(const QImage&, const QString& filename, bool embedded); 0086 void setImage(const QString&, bool embedded); 0087 0088 static QString graphTypeToString(const GraphType); 0089 static GraphType stringToGraphType(const QString&); 0090 0091 bool isLoaded{false}; 0092 QImage originalPlotImage; 0093 QImage processedPlotImage; 0094 QColor background; 0095 int* foregroundBins; 0096 int* hueBins; 0097 int* saturationBins; 0098 int* valueBins; 0099 int* intensityBins; 0100 0101 QGraphicsPixmapItem* m_magnificationWindow{nullptr}; 0102 0103 CLASS_D_ACCESSOR_DECL(QString, fileName, FileName) 0104 BASIC_D_ACCESSOR_DECL(bool, isRelativeFilePath, RelativeFilePath) 0105 BASIC_D_ACCESSOR_DECL(bool, embedded, Embedded) 0106 CLASS_D_ACCESSOR_DECL(DatapickerImage::ReferencePoints, axisPoints, AxisPoints) 0107 CLASS_D_ACCESSOR_DECL(DatapickerImage::EditorSettings, settings, Settings) 0108 BASIC_D_ACCESSOR_DECL(float, rotationAngle, RotationAngle) 0109 BASIC_D_ACCESSOR_DECL(PointsType, plotPointsType, PlotPointsType) 0110 BASIC_D_ACCESSOR_DECL(int, pointSeparation, PointSeparation) 0111 BASIC_D_ACCESSOR_DECL(int, minSegmentLength, minSegmentLength) 0112 0113 Symbol* symbol() const; 0114 BASIC_D_ACCESSOR_DECL(bool, pointVisibility, PointVisibility) 0115 0116 typedef DatapickerImagePrivate Private; 0117 0118 public Q_SLOTS: 0119 void referencePointSelected(const DatapickerPoint*); 0120 0121 private: 0122 void init(); 0123 0124 Q_DECLARE_PRIVATE(DatapickerImage) 0125 DatapickerImagePrivate* const d_ptr; 0126 0127 mutable DatapickerImageView* m_view{nullptr}; 0128 friend class DatapickerImagePrivate; 0129 Segments* m_segments; 0130 int m_currentRefPoint{-1}; 0131 0132 Q_SIGNALS: 0133 void requestProjectContextMenu(QMenu*); 0134 void requestUpdate(); 0135 void requestUpdateActions(); 0136 0137 void relativeFilePathChanged(bool); 0138 void fileNameChanged(const QString&); 0139 void embeddedChanged(bool); 0140 void rotationAngleChanged(float); 0141 void axisPointsChanged(const DatapickerImage::ReferencePoints&); 0142 void settingsChanged(const DatapickerImage::EditorSettings&); 0143 void minSegmentLengthChanged(const int); 0144 void pointStyleChanged(Symbol::Style); 0145 void pointSizeChanged(qreal); 0146 void pointRotationAngleChanged(qreal); 0147 void pointOpacityChanged(qreal); 0148 void pointBrushChanged(QBrush); 0149 void pointPenChanged(const QPen&); 0150 void pointVisibilityChanged(bool); 0151 void referencePointSelected(int index); 0152 }; 0153 #endif