File indexing completed on 2024-05-05 04:47:43

0001 /***************************************************************************
0002  *   Copyright (c) 2008  Jeff Mitchell <mitchell@kde.org>                  *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (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                         *
0016  *   Free Software Foundation, Inc.,                                       *
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
0018  ***************************************************************************/
0019 
0020 #ifndef POPUPDROPPERITEM_H
0021 #define POPUPDROPPERITEM_H
0022 
0023 #include <QGraphicsSvgItem>
0024 #include <QString>
0025 #include <QFont>
0026 
0027 #include "PopupDropper_Export.h"
0028 
0029 class QDropEvent;
0030 class QGraphicsTextItem;
0031 class QSvgRenderer;
0032 class QAction;
0033 class PopupDropper;
0034 class PopupDropperItemPrivate;
0035 
0036 class POPUPDROPPER_EXPORT PopupDropperItem : public QObject, public QAbstractGraphicsShapeItem
0037 {
0038     Q_OBJECT
0039 
0040     Q_PROPERTY( HoverIndicatorShowStyle hoverIndicatorShowStyle READ hoverIndicatorShowStyle WRITE setHoverIndicatorShowStyle )
0041     Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation )
0042     Q_PROPERTY( TextProtection textProtection READ textProtection WRITE setTextProtection )
0043     Q_PROPERTY( QAction* action READ action WRITE setAction )
0044     Q_PROPERTY( QString text READ text WRITE setText )
0045     Q_PROPERTY( QFont font READ font WRITE setFont )
0046     Q_PROPERTY( QGraphicsTextItem* textItem READ textItem WRITE setTextItem )
0047     Q_PROPERTY( QGraphicsRectItem* borderRectItem READ borderRectItem WRITE setBorderRectItem )
0048     Q_PROPERTY( QGraphicsSvgItem* svgItem READ svgItem )
0049     Q_PROPERTY( QSvgRenderer* sharedRenderer READ sharedRenderer WRITE setSharedRenderer )
0050     Q_PROPERTY( QString elementId READ elementId WRITE setElementId )
0051     Q_PROPERTY( QRect svgElementRect READ svgElementRect WRITE setSvgElementRect )
0052     Q_PROPERTY( int horizontalOffset READ horizontalOffset WRITE setHorizontalOffset )
0053     Q_PROPERTY( int textOffset READ textOffset WRITE setTextOffset )
0054     Q_PROPERTY( int hoverMsecs READ hoverMsecs WRITE setHoverMsecs )
0055     Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth )
0056     Q_PROPERTY( int hoverIndicatorRectWidth READ hoverIndicatorRectWidth WRITE setHoverIndicatorRectWidth )
0057     Q_PROPERTY( bool submenuTrigger READ isSubmenuTrigger WRITE setSubmenuTrigger )
0058     Q_PROPERTY( QColor baseTextColor READ baseTextColor WRITE setBaseTextColor )
0059     Q_PROPERTY( QColor hoveredTextColor READ hoveredTextColor WRITE setHoveredTextColor )
0060     Q_PROPERTY( QPen hoveredBorderPen READ hoveredBorderPen WRITE setHoveredBorderPen )
0061     Q_PROPERTY( QBrush hoveredBrush READ hoveredFillBrush WRITE setHoveredFillBrush )
0062     Q_PROPERTY( QBrush hoverIndicatorBrush READ hoverIndicatorFillBrush WRITE setHoverIndicatorFillBrush )
0063     Q_PROPERTY( bool customBaseTextColor READ customBaseTextColor )
0064     Q_PROPERTY( bool customHoveredTextColor READ customHoveredTextColor )
0065     Q_PROPERTY( bool customHoveredBorderPen READ customHoveredBorderPen )
0066     Q_PROPERTY( bool customHoveredFillBrush READ customHoveredFillBrush )
0067     Q_PROPERTY( qreal subitemOpacity READ subitemOpacity WRITE setSubitemOpacity )
0068     Q_PROPERTY( bool separator READ isSeparator WRITE setSeparator )
0069     Q_PROPERTY( PopupDropperItem::SeparatorStyle separatorStyle READ separatorStyle WRITE setSeparatorStyle )
0070     Q_PROPERTY( bool hasLineSeparatorPen READ hasLineSeparatorPen )
0071     Q_PROPERTY( QPen lineSeparatorPen READ lineSeparatorPen WRITE setLineSeparatorPen )
0072 
0073 public:
0074     enum HoverIndicatorShowStyle { Never, OnHover, AlwaysShow };
0075     Q_ENUM( HoverIndicatorShowStyle )
0076     enum Orientation { Left, Right };
0077     Q_ENUM( Orientation )
0078     enum TextProtection { NoProtection, MultiLine, ScaleFont };
0079     Q_ENUM( TextProtection )
0080     enum SeparatorStyle { TextSeparator, LineSeparator };
0081     Q_ENUM( SeparatorStyle )
0082 
0083     PopupDropperItem( QGraphicsItem *parent = nullptr );
0084     explicit PopupDropperItem( const QString &file, QGraphicsItem *parent = nullptr );
0085     ~PopupDropperItem() override;
0086 
0087     void show();
0088 
0089     QAction* action() const;
0090     void setAction( QAction *action );
0091 
0092     HoverIndicatorShowStyle hoverIndicatorShowStyle() const;
0093     void setHoverIndicatorShowStyle( HoverIndicatorShowStyle hover );
0094     Orientation orientation() const;
0095     void setOrientation( Orientation orientation );
0096     TextProtection textProtection() const;
0097     void setTextProtection( TextProtection protection );
0098 
0099     QString text() const;
0100     void setText( const QString &text );
0101     QFont font() const;
0102     void setFont( const QFont &font );
0103     QColor baseTextColor() const;
0104     void setBaseTextColor( const QColor &color );
0105     QColor hoveredTextColor() const;
0106     void setHoveredTextColor( const QColor &color );
0107     QPen hoveredBorderPen() const;
0108     void setHoveredBorderPen( const QPen &pen );
0109     QBrush hoveredFillBrush() const;
0110     void setHoveredFillBrush( const QBrush &brush );
0111     QBrush hoverIndicatorFillBrush() const;
0112     void setHoverIndicatorFillBrush( const QBrush &brush );
0113     bool customBaseTextColor() const;
0114     bool customHoveredTextColor() const;
0115     bool customHoveredBorderPen() const;
0116     bool customHoveredFillBrush() const;
0117     void setSubitemOpacity( qreal opacity );
0118     qreal subitemOpacity() const;
0119 
0120     QGraphicsTextItem* textItem() const;
0121     void setTextItem( QGraphicsTextItem *textItem );
0122     void scaleAndReposSvgItem();
0123     void reposTextItem();
0124     void reposHoverFillRects();
0125     QGraphicsRectItem* borderRectItem() const;
0126     void setBorderRectItem( QGraphicsRectItem *borderRectItem );
0127     QGraphicsSvgItem* svgItem() const;
0128 
0129     QSvgRenderer* sharedRenderer() const;
0130     void setSharedRenderer( QSvgRenderer *renderer );
0131     QString elementId() const;
0132     void setElementId( const QString &id );
0133     QRect svgElementRect() const;
0134     void setSvgElementRect( const QRect &rect );
0135     int horizontalOffset() const;
0136     void setHorizontalOffset( int offset );
0137     int textOffset() const;
0138     void setTextOffset( int offset );
0139 
0140     bool isSeparator() const;
0141     void setSeparator( bool separator );
0142     PopupDropperItem::SeparatorStyle separatorStyle() const;
0143     void setSeparatorStyle( PopupDropperItem::SeparatorStyle style );
0144     bool hasLineSeparatorPen() const;
0145     QPen lineSeparatorPen() const;
0146     void setLineSeparatorPen( const QPen &pen );
0147     void clearLineSeparatorPen();
0148 
0149     int hoverMsecs() const;
0150     void setHoverMsecs( const int msecs );
0151     void hoverEntered();
0152     void hoverLeft();
0153 
0154     int borderWidth() const;
0155     void setBorderWidth( int width );
0156     int hoverIndicatorRectWidth() const;
0157     void setHoverIndicatorRectWidth( int width );
0158 
0159     bool isSubmenuTrigger() const;
0160     void setSubmenuTrigger( bool trigger );
0161 
0162     void setPopupDropper( PopupDropper* pd );
0163 
0164     //bool operator<( const PopupDropperItem &other ) const;
0165 
0166     void fullUpdate();
0167     
0168     QRectF boundingRect() const override;
0169     void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr ) override;
0170 
0171 public Q_SLOTS:
0172     virtual void dropped( QDropEvent *event );
0173     virtual void hoverFinished();
0174     virtual void hoverFrameChanged( int frame );
0175 
0176 private:
0177     friend class PopupDropperItemPrivate;
0178     PopupDropperItemPrivate* const d;
0179 
0180 };
0181 
0182 #endif