File indexing completed on 2024-05-12 15:26:41

0001 /***************************************************************************
0002   File                 : DatapickerImage.h
0003   Project              : LabPlot
0004   Description          : Worksheet for Datapicker
0005   --------------------------------------------------------------------
0006   Copyright            : (C) 2015 by Ankit Wagadre (wagadre.ankit@gmail.com)
0007   Copyright            : (C) 2015-2016 by Alexander Semke (alexander.semke@web.de)
0008 
0009 ***************************************************************************/
0010 /***************************************************************************
0011  *                                                                         *
0012  *  This program is free software; you can redistribute it and/or modify   *
0013  *  it under the terms of the GNU General Public License as published by   *
0014  *  the Free Software Foundation; either version 2 of the License, or      *
0015  *  (at your option) any later version.                                    *
0016  *                                                                         *
0017  *  This program is distributed in the hope that it will be useful,        *
0018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0020  *  GNU General Public License for more details.                           *
0021  *                                                                         *
0022  *   You should have received a copy of the GNU General Public License     *
0023  *   along with this program; if not, write to the Free Software           *
0024  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0025  *   Boston, MA  02110-1301  USA                                           *
0026  *                                                                         *
0027  ***************************************************************************/
0028 
0029 #ifndef DATAPICKERIMAGE_H
0030 #define DATAPICKERIMAGE_H
0031 
0032 #include "backend/core/AbstractPart.h"
0033 #include "backend/lib/macros.h"
0034 #include "backend/worksheet/plots/cartesian/Symbol.h"
0035 
0036 #include <QVector3D>
0037 #include <QPen>
0038 
0039 class QImage;
0040 class QBrush;
0041 class DatapickerImagePrivate;
0042 class DatapickerImageView;
0043 class ImageEditor;
0044 class Segments;
0045 
0046 class QGraphicsScene;
0047 class QGraphicsPixmapItem;
0048 
0049 class DatapickerImage : public AbstractPart {
0050     Q_OBJECT
0051 
0052 public:
0053     explicit DatapickerImage(const QString& name, bool loading = false);
0054     ~DatapickerImage() override;
0055 
0056     enum class GraphType {Cartesian, PolarInDegree, PolarInRadians, LogarithmicX, LogarithmicY, Ternary};
0057     enum class ColorAttributes {None, Intensity, Foreground, Hue, Saturation, Value};
0058     enum class PlotImageType {NoImage, OriginalImage, ProcessedImage};
0059     enum class PointsType {AxisPoints, CurvePoints, SegmentPoints};
0060 
0061     struct ReferencePoints {
0062         GraphType type{GraphType::Cartesian};
0063         QPointF scenePos[3];
0064         QVector3D logicalPos[3];
0065         double ternaryScale{1.0};
0066     };
0067 
0068     struct EditorSettings {
0069         int intensityThresholdLow{20};
0070         int intensityThresholdHigh{100};
0071         int foregroundThresholdLow{30};
0072         int foregroundThresholdHigh{90};
0073         int hueThresholdLow{0};
0074         int hueThresholdHigh{360};
0075         int saturationThresholdLow{30};
0076         int saturationThresholdHigh{100};
0077         int valueThresholdLow{30};
0078         int valueThresholdHigh{90};
0079     };
0080 
0081     QIcon icon() const override;
0082     QMenu* createContextMenu() override;
0083     void createContextMenu(QMenu*);
0084     QWidget* view() const override;
0085 
0086     bool exportView() const override;
0087     bool printView() override;
0088     bool printPreview() const override;
0089 
0090     void save(QXmlStreamWriter*) const override;
0091     bool load(XmlStreamReader*, bool preview) override;
0092 
0093     QRectF pageRect() const;
0094     void setPageRect(const QRectF&);
0095     QGraphicsScene *scene() const;
0096     void setPrinting(bool) const;
0097     void setSelectedInView(const bool);
0098     void setSegmentsHoverEvent(const bool);
0099 
0100     void setPlotImageType(const DatapickerImage::PlotImageType);
0101     DatapickerImage::PlotImageType plotImageType();
0102 
0103     bool isLoaded{false};
0104     QImage originalPlotImage;
0105     QImage processedPlotImage;
0106     QColor background;
0107     int *foregroundBins;
0108     int *hueBins;
0109     int *saturationBins;
0110     int *valueBins;
0111     int *intensityBins;
0112 
0113     QGraphicsPixmapItem* m_magnificationWindow{nullptr};
0114 
0115     CLASS_D_ACCESSOR_DECL(QString, fileName, FileName)
0116     CLASS_D_ACCESSOR_DECL(DatapickerImage::ReferencePoints, axisPoints, AxisPoints)
0117     CLASS_D_ACCESSOR_DECL(DatapickerImage::EditorSettings, settings, Settings)
0118     BASIC_D_ACCESSOR_DECL(float, rotationAngle, RotationAngle)
0119     BASIC_D_ACCESSOR_DECL(PointsType, plotPointsType, PlotPointsType)
0120     BASIC_D_ACCESSOR_DECL(int, pointSeparation, PointSeparation)
0121     BASIC_D_ACCESSOR_DECL(int, minSegmentLength, minSegmentLength)
0122 
0123     BASIC_D_ACCESSOR_DECL(Symbol::Style, pointStyle, PointStyle)
0124     BASIC_D_ACCESSOR_DECL(qreal, pointOpacity, PointOpacity)
0125     BASIC_D_ACCESSOR_DECL(qreal, pointRotationAngle, PointRotationAngle)
0126     BASIC_D_ACCESSOR_DECL(qreal, pointSize, PointSize)
0127     CLASS_D_ACCESSOR_DECL(QBrush, pointBrush, PointBrush)
0128     CLASS_D_ACCESSOR_DECL(QPen, pointPen, PointPen)
0129     BASIC_D_ACCESSOR_DECL(bool, pointVisibility, PointVisibility)
0130 
0131     typedef DatapickerImagePrivate Private;
0132 
0133 private:
0134     void init();
0135 
0136     DatapickerImagePrivate* const d;
0137     mutable DatapickerImageView* m_view{nullptr};
0138     friend class DatapickerImagePrivate;
0139     Segments* m_segments;
0140 
0141 signals:
0142     void requestProjectContextMenu(QMenu*);
0143     void requestUpdate();
0144     void requestUpdateActions();
0145 
0146     void fileNameChanged(const QString&);
0147     void rotationAngleChanged(float);
0148     void axisPointsChanged(const DatapickerImage::ReferencePoints&);
0149     void settingsChanged(const DatapickerImage::EditorSettings&);
0150     void minSegmentLengthChanged(const int);
0151     void pointStyleChanged(Symbol::Style);
0152     void pointSizeChanged(qreal);
0153     void pointRotationAngleChanged(qreal);
0154     void pointOpacityChanged(qreal);
0155     void pointBrushChanged(QBrush);
0156     void pointPenChanged(const QPen&);
0157     void pointVisibilityChanged(bool);
0158 };
0159 #endif