File indexing completed on 2022-12-06 18:50:30

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2012 Martin Kuettler <martin.kuettler@gmail.com>
0004 */
0005 
0006 #ifndef WORKSHEETIMAGEITEM_H
0007 #define WORKSHEETIMAGEITEM_H
0008 
0009 #include <QPixmap>
0010 #include <QGraphicsObject>
0011 
0012 class Worksheet;
0013 class QImage;
0014 class QGraphicsSceneContextMenuEvent;
0015 class QMenu;
0016 
0017 class WorksheetImageItem : public QGraphicsObject
0018 {
0019   Q_OBJECT
0020   public:
0021     explicit WorksheetImageItem(QGraphicsObject* parent);
0022     ~WorksheetImageItem() override;
0023 
0024     enum {Type = UserType + 101};
0025 
0026     int type() const override;
0027 
0028     bool imageIsValid();
0029 
0030     virtual qreal setGeometry(qreal x, qreal y, qreal w, bool centered=false);
0031 
0032     qreal height() const;
0033     qreal width() const;
0034     QSizeF size();
0035     void setSize(QSizeF size);
0036     QSize imageSize();
0037 
0038     QRectF boundingRect() const override;
0039 
0040     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
0041                QWidget *widget = nullptr) override;
0042 
0043     void setEps(const QUrl &url);
0044     void setImage(QImage img);
0045     void setImage(QImage img, QSize displaySize);
0046     void setPixmap(QPixmap pixmap);
0047     QPixmap pixmap() const;
0048 
0049     virtual void populateMenu(QMenu* menu, QPointF pos);
0050     Worksheet* worksheet();
0051 
0052   Q_SIGNALS:
0053     void sizeChanged();
0054     void menuCreated(QMenu*, QPointF);
0055 
0056   protected:
0057     void contextMenuEvent(QGraphicsSceneContextMenuEvent*) override;
0058 
0059   private:
0060     QPixmap m_pixmap;
0061     QSizeF m_size;
0062 };
0063 
0064 #endif //WORKSHEETIMAGEITEM_H