File indexing completed on 2025-02-02 07:28:26
0001 /*************************************************************************** 0002 * Copyright 2010 Stefan Majewsky <majewsky@gmx.net> 0003 * 0004 * This program is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU General Public License 0015 * along with this program; if not, write to the Free Software 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0017 ***************************************************************************/ 0018 0019 #ifndef UTILS_ANIMATEDITEM_H 0020 #define UTILS_ANIMATEDITEM_H 0021 0022 #include <QGraphicsObject> 0023 class QPropertyAnimation; 0024 0025 namespace Utils 0026 { 0027 /** 0028 * \class AnimatedItem 0029 * This QGraphicsItem has a simple interface for animated opacity changes. 0030 */ 0031 class AnimatedItem : public QGraphicsObject 0032 { 0033 Q_OBJECT 0034 Q_PROPERTY(qreal correct_opacity READ opacity WRITE setOpacity) //I'm talking of AnimatedItem::setOpacity, not QGraphicsItem::setOpacity! 0035 public: 0036 explicit AnimatedItem(QGraphicsItem* parent = nullptr); 0037 0038 ///Returns the duration of opacity animations. 0039 int animationTime() const; 0040 ///\note This won't have an effect on running animations. 0041 void setAnimationTime(int time); 0042 ///Returns whether the object's visibility will be set to false when the opacity is reduced to 0. 0043 bool hideWhenInvisible() const; 0044 void setHideWhenInvisible(bool hideWhenInvisible); 0045 void setOpacityAnimated(qreal opacity); 0046 ///\warning Always use this instead of QGraphicsItem::setOpacity for direct opacity adjustments. 0047 void setOpacity(qreal opacity); 0048 0049 QRectF boundingRect() const override; 0050 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override; 0051 private: 0052 int m_animationTime; 0053 bool m_hideWhenInvisible; 0054 QPropertyAnimation* m_animator; 0055 }; 0056 } 0057 0058 #endif // KOLF_OVERLAY_P_H