File indexing completed on 2025-01-19 04:24:07
0001 /**************************************************************************************** 0002 * Copyright (c) 2010 Daniel Faust <hessijames@gmail.com> * 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 LABEL_GRAPHICS_ITEM_H 0018 #define LABEL_GRAPHICS_ITEM_H 0019 0020 #include "context/Applet.h" 0021 0022 #include <QGraphicsObject> 0023 #include <QWeakPointer> 0024 0025 class LabelOverlayButton; 0026 class QGraphicsBlurEffect; 0027 class QGraphicsPixmapItem; 0028 class QGraphicsSceneHoverEvent; 0029 class QGraphicsSceneMouseEvent; 0030 class QGraphicsTextItem; 0031 class QPropertyAnimation; 0032 0033 class LabelGraphicsItem : public QGraphicsObject 0034 { 0035 Q_OBJECT 0036 Q_PROPERTY( qreal hoverValue READ hoverValue WRITE setHoverValue ) 0037 Q_PROPERTY( QPointF pos READ pos WRITE setPos ) 0038 0039 public: 0040 LabelGraphicsItem( const QString& text, qreal deltaPointSize, QGraphicsItem *parent ); 0041 ~LabelGraphicsItem() override; 0042 0043 QString text(); 0044 void setText( const QString& text ); 0045 void setDeltaPointSize( qreal deltaPointSize ); 0046 void setSelected( bool selected ); 0047 void setSelectedColor( QColor color ); 0048 void setBackgroundColor( QColor color ); 0049 void showBlacklistButton( bool enabled ); 0050 0051 void updateHoverStatus(); 0052 0053 QRectF boundingRect() const; 0054 void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ); 0055 0056 protected: 0057 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override; 0058 void hoverEnterEvent( QGraphicsSceneHoverEvent *event ) override; 0059 void mousePressEvent( QGraphicsSceneMouseEvent *event ) override; 0060 0061 private: 0062 qreal hoverValue(); 0063 void setHoverValue( qreal value ); 0064 void updateGeometry(); 0065 0066 QGraphicsTextItem *m_textItem; 0067 QGraphicsPixmapItem *m_backgroundItem; 0068 QGraphicsBlurEffect *m_backgroundBlurEffect; 0069 QColor m_backgroundColor; 0070 0071 qreal m_hoverValue; 0072 QColor m_hoverColor; 0073 QWeakPointer<QPropertyAnimation> m_hoverValueAnimation; 0074 bool m_selected; 0075 QColor m_selectedColor; 0076 0077 bool m_showBlacklistButton; 0078 0079 QWeakPointer<LabelOverlayButton> m_addLabelItem; 0080 QWeakPointer<LabelOverlayButton> m_removeLabelItem; 0081 QWeakPointer<LabelOverlayButton> m_listLabelItem; 0082 QWeakPointer<LabelOverlayButton> m_blacklistLabelItem; 0083 0084 QWeakPointer<QPropertyAnimation> m_addLabelAnimation; 0085 QWeakPointer<QPropertyAnimation> m_removeLabelAnimation; 0086 QWeakPointer<QPropertyAnimation> m_listLabelAnimation; 0087 QWeakPointer<QPropertyAnimation> m_blacklistLabelAnimation; 0088 0089 Q_SIGNALS: 0090 void toggled( const QString &label ); 0091 void blacklisted( const QString &label ); 0092 void list( const QString &label ); 0093 }; 0094 0095 #endif 0096