File indexing completed on 2024-05-05 04:49:26

0001 /****************************************************************************************
0002 * Copyright (c) 2009 Thomas Luebking <thomas.luebking@web.de>                          *
0003 *                                                                                      *
0004 * This program is free software; you can redistribute it and/or modify it under        *
0005 * the terms of the GNU General Public License as published by the Free Software        *
0006 * Foundation; either version 2 of the License, or (at your option) any later           *
0007 * version.                                                                             *
0008 *                                                                                      *
0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012 *                                                                                      *
0013 * You should have received a copy of the GNU General Public License along with         *
0014 * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015 ****************************************************************************************/
0016 
0017 #ifndef ICONBUTTON_H
0018 #define ICONBUTTON_H
0019 
0020 #include <QImage>
0021 #include <QPixmap>
0022 #include <QWidget>
0023 
0024 class IconButton : public QWidget
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     explicit IconButton( QWidget *parent = nullptr );
0030     QSize sizeHint() const override;
0031     void setIcon( const QImage &img, int steps = 0 );
0032 
0033 Q_SIGNALS:
0034     void clicked();
0035 
0036 protected:
0037     void mousePressEvent( QMouseEvent * ) override;
0038     void mouseReleaseEvent( QMouseEvent * ) override;
0039     void paintEvent( QPaintEvent * ) override;
0040     void resizeEvent(QResizeEvent *) override;
0041     void timerEvent ( QTimerEvent * ) override;
0042 
0043     /**
0044      Reload the content for the given size
0045      The iconbutton preserves a square size, so sz.width() == sz.height()
0046     */
0047     virtual void reloadContent( const QSize &sz ) = 0;
0048 
0049 protected Q_SLOTS:
0050     void svgRetinted();
0051 
0052 private:
0053     void updateIconBuffer();
0054 
0055     bool m_isClick;
0056     struct
0057     {
0058         int step;
0059         int steps;
0060         int timer;
0061     } m_anim;
0062 
0063     struct
0064     {
0065         QImage image;
0066         QPixmap pixmap;
0067     } m_buffer;
0068 
0069     QImage m_icon, m_oldIcon;
0070 };
0071 
0072 
0073 #endif  // end include guard