File indexing completed on 2024-04-28 03:59:12

0001 /*
0002     SPDX-FileCopyrightText: 2009 Sebastian Trueg <trueg@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #ifndef _K_PIXMAPSEQUENCE_OVERLAY_PAINTER_H_
0008 #define _K_PIXMAPSEQUENCE_OVERLAY_PAINTER_H_
0009 
0010 #include <QObject>
0011 #include <QPoint>
0012 #include <memory>
0013 
0014 #include <kwidgetsaddons_export.h>
0015 
0016 class KPixmapSequence;
0017 class QWidget;
0018 class QEvent;
0019 class QRect;
0020 
0021 /**
0022  * \class KPixmapSequenceOverlayPainter kpixmapsequenceoverlaypainter.h KPixmapSequenceOverlayPainter
0023  *
0024  * \brief Paints a KPixmapSequence on top of any widget at any position.
0025  *
0026  * The KPixmapSequenceOverlayPainter paints an overlay on top of an arbitrary QWidget
0027  * using a KPixmapSequence. This is typically used for spinners indicating that a process
0028  * is not finished yet.
0029  *
0030  * \author Sebastian Trueg <trueg@kde.org>
0031  *
0032  * \since 4.4
0033  */
0034 class KWIDGETSADDONS_EXPORT KPixmapSequenceOverlayPainter : public QObject
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039     /**
0040      * Constructor
0041      */
0042     explicit KPixmapSequenceOverlayPainter(QObject *parent = nullptr);
0043     KPixmapSequenceOverlayPainter(const KPixmapSequence &seq, QObject *parent = nullptr);
0044 
0045     /**
0046      * Destructor
0047      */
0048     ~KPixmapSequenceOverlayPainter() override;
0049 
0050     /**
0051      * The sequence used to draw the overlay.
0052      *
0053      * \sa setSequence
0054      */
0055     KPixmapSequence sequence() const;
0056 
0057     /**
0058      * The interval between frames.
0059      *
0060      * \sa setInterval
0061      */
0062     int interval() const;
0063 
0064     /**
0065      * The optional rect to draw the pixmaps in.
0066      * \sa setRect
0067      */
0068     QRect rect() const;
0069 
0070     /**
0071      * The alignment of the pixmaps in the rect.
0072      * \sa setAlignment
0073      */
0074     Qt::Alignment alignment() const;
0075 
0076     /**
0077      * The optional offset within the rect.
0078      * \sa setOffset
0079      */
0080     QPoint offset() const;
0081 
0082 public Q_SLOTS:
0083     /**
0084      * Set the sequence to be used. By default the KDE busy sequence is used.
0085      */
0086     void setSequence(const KPixmapSequence &seq);
0087 
0088     /**
0089      * Set the interval between frames. The default is 200.
0090      */
0091     void setInterval(int msecs);
0092 
0093     /**
0094      * Set the widget to draw the overlay on.
0095      */
0096     void setWidget(QWidget *w);
0097 
0098     /**
0099      * Set the rect in which to place the sequence. Be aware that
0100      * this optional property does not scale the pixmaps (except if
0101      * it is smaller) but allows to change the placement.
0102      *
0103      * \param rect The rect in which to draw the pixmap using alignment
0104      * and offset. Be aware that setting a rect bigger than the widget
0105      * can lead to weird painting errors.
0106      *
0107      * Defaults to the widget's rect.
0108      */
0109     void setRect(const QRect &rect);
0110 
0111     /**
0112      * Set the alignment of the sequence in rect.
0113      *
0114      * \param align alignment of the overlay. Qt::AlignJustify does not make sense here.
0115      * Defaults to Qt::Center.
0116      */
0117     void setAlignment(Qt::Alignment align);
0118 
0119     /**
0120      * Set the offset relative to the placement determined by alignment
0121      * and rect.
0122      *
0123      * \param offset An optional offset which allows an absolute placement.
0124      *
0125      * Defaults to an empty point.
0126      */
0127     void setOffset(const QPoint &offset);
0128 
0129     /**
0130      * Start drawing the sequence.
0131      *
0132      * The overlay will be drawn until a call to stop()
0133      */
0134     void start();
0135 
0136     /**
0137      * Stop drawing the overlay.
0138      */
0139     void stop();
0140 
0141 protected:
0142     bool eventFilter(QObject *obj, QEvent *event) override;
0143 
0144 private:
0145     std::unique_ptr<class KPixmapSequenceOverlayPainterPrivate> const d;
0146 };
0147 
0148 #endif