File indexing completed on 2024-05-12 04:19:38

0001 /*
0002  * SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-or-later
0005  */
0006 
0007 #ifndef BACKGROUNDITEM_H
0008 #define BACKGROUNDITEM_H
0009 
0010 #include <QGraphicsItem>
0011 
0012 #include <lib/gwenviewlib_export.h>
0013 
0014 #include "abstractimageview.h"
0015 
0016 namespace Gwenview
0017 {
0018 /**
0019  * A QGraphicsItem subclass that draws the appropriate background for alpha images.
0020  */
0021 class GWENVIEWLIB_EXPORT AlphaBackgroundItem : public QGraphicsItem
0022 {
0023 public:
0024     AlphaBackgroundItem(AbstractImageView *parent);
0025     ~AlphaBackgroundItem() override;
0026 
0027     AbstractImageView::AlphaBackgroundMode mode() const;
0028     void setMode(AbstractImageView::AlphaBackgroundMode mode);
0029 
0030     QColor color();
0031     void setColor(const QColor &color);
0032 
0033     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) override;
0034 
0035     virtual QRectF boundingRect() const override;
0036 
0037 private:
0038     void createCheckBoardTexture();
0039 
0040     AbstractImageView *mParent;
0041     AbstractImageView::AlphaBackgroundMode mMode = AbstractImageView::AlphaBackgroundCheckBoard;
0042     QColor mColor = Qt::black;
0043 
0044     // This pixmap will be used to fill the background when mMode is
0045     // AlphaBackgroundCheckBoard.
0046     std::unique_ptr<QPixmap> mCheckBoardTexture;
0047 };
0048 
0049 }
0050 
0051 #endif // BACKGROUNDITEM_H