File indexing completed on 2024-05-12 15:27:31
0001 /*************************************************************************** 0002 File : Image.h 0003 Project : LabPlot 0004 Description : Worksheet element to draw images 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2019 Alexander Semke (alexander.semke@web.de) 0007 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 IMAGE_H 0030 #define IMAGE_H 0031 0032 #include "backend/lib/macros.h" 0033 #include "backend/worksheet/WorksheetElement.h" 0034 0035 #include <QPen> 0036 0037 class QBrush; 0038 class QFont; 0039 class ImagePrivate; 0040 0041 class Image : public WorksheetElement { 0042 Q_OBJECT 0043 0044 public: 0045 explicit Image(const QString& name); 0046 ~Image() override; 0047 0048 QIcon icon() const override; 0049 QMenu* createContextMenu() override; 0050 QGraphicsItem* graphicsItem() const override; 0051 void setParentGraphicsItem(QGraphicsItem*); 0052 0053 void save(QXmlStreamWriter*) const override; 0054 bool load(XmlStreamReader*, bool preview) override; 0055 void loadThemeConfig(const KConfig&) override; 0056 void saveThemeConfig(const KConfig&) override; 0057 0058 CLASS_D_ACCESSOR_DECL(QString, fileName, FileName) 0059 BASIC_D_ACCESSOR_DECL(qreal, opacity, Opacity) 0060 BASIC_D_ACCESSOR_DECL(int, width, Width) 0061 BASIC_D_ACCESSOR_DECL(int, height, Height) 0062 BASIC_D_ACCESSOR_DECL(bool, keepRatio, KeepRatio) 0063 CLASS_D_ACCESSOR_DECL(WorksheetElement::PositionWrapper, position, Position) 0064 void setPosition(QPointF); 0065 BASIC_D_ACCESSOR_DECL(WorksheetElement::HorizontalAlignment, horizontalAlignment, HorizontalAlignment) 0066 BASIC_D_ACCESSOR_DECL(WorksheetElement::VerticalAlignment, verticalAlignment, VerticalAlignment) 0067 BASIC_D_ACCESSOR_DECL(qreal, rotationAngle, RotationAngle) 0068 0069 CLASS_D_ACCESSOR_DECL(QPen, borderPen, BorderPen) 0070 BASIC_D_ACCESSOR_DECL(qreal, borderOpacity, BorderOpacity) 0071 0072 void setVisible(bool on) override; 0073 bool isVisible() const override; 0074 void setPrinting(bool) override; 0075 0076 void retransform() override; 0077 void handleResize(double horizontalRatio, double verticalRatio, bool pageResize) override; 0078 0079 typedef ImagePrivate Private; 0080 0081 private slots: 0082 //SLOTs for changes triggered via QActions in the context menu 0083 void visibilityChanged(); 0084 0085 protected: 0086 ImagePrivate* const d_ptr; 0087 Image(const QString&, ImagePrivate*); 0088 0089 private: 0090 Q_DECLARE_PRIVATE(Image) 0091 void init(); 0092 0093 QAction* visibilityAction{nullptr}; 0094 0095 signals: 0096 void fileNameChanged(const QString&); 0097 void opacityChanged(float); 0098 void widthChanged(int); 0099 void heightChanged(int); 0100 void keepRatioChanged(bool); 0101 void positionChanged(const WorksheetElement::PositionWrapper&); 0102 void horizontalAlignmentChanged(WorksheetElement::HorizontalAlignment); 0103 void verticalAlignmentChanged(WorksheetElement::VerticalAlignment); 0104 void rotationAngleChanged(qreal); 0105 void borderPenChanged(QPen&); 0106 void borderOpacityChanged(float); 0107 void visibleChanged(bool); 0108 void changed(); 0109 }; 0110 0111 #endif