File indexing completed on 2024-05-12 03:48:19

0001 /*
0002     File                 : ImagePrivate.h
0003     Project              : LabPlot
0004     Description          : Worksheet element to draw images
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2019-2022 Alexander Semke <alexander.semke@web.de>
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #ifndef IMAGEPRIVATE_H
0011 #define IMAGEPRIVATE_H
0012 
0013 #include "backend/worksheet/TextLabel.h"
0014 #include "backend/worksheet/WorksheetElementPrivate.h"
0015 
0016 class QGraphicsSceneHoverEvent;
0017 
0018 class ImagePrivate : public WorksheetElementPrivate {
0019 public:
0020     explicit ImagePrivate(Image*);
0021 
0022     QImage image; // original image
0023     QImage imageScaled; // scaled and the actual version of the original image that is used for drawing
0024     QString fileName;
0025     bool embedded{true};
0026     qreal opacity{1.0};
0027     int width = (int)Worksheet::convertToSceneUnits(2.0, Worksheet::Unit::Centimeter);
0028     int height = (int)Worksheet::convertToSceneUnits(3.0, Worksheet::Unit::Centimeter);
0029     bool keepRatio{true}; // keep aspect ratio when scaling the image
0030     Line* borderLine{nullptr};
0031 
0032     void retransform() override;
0033     void recalcShapeAndBoundingRect() override;
0034     void updateImage();
0035     void scaleImage();
0036     void updateBorder();
0037 
0038     QRectF transformedBoundingRectangle; // bounding rectangle of transformed (rotated etc.) text
0039     QPainterPath borderShapePath;
0040     QPainterPath imageShape;
0041 
0042     // reimplemented from QGraphicsItem
0043     QRectF boundingRect() const override;
0044     QPainterPath shape() const override;
0045     void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget* widget = nullptr) override;
0046 
0047     Image* const q;
0048 };
0049 
0050 #endif