Debian Codegraph @

src/context/popupdropper/libpud/PopupDropperItem.h

raw
1 /***************************************************************************
2 * Copyright (c) 2008 Jeff Mitchell <[email protected]> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
19
20 #ifndef POPUPDROPPERITEM_H
21 #define POPUPDROPPERITEM_H
22
23 #include <QGraphicsSvgItem>
24 #include <QString>
25 #include <QFont>
26
27 #include "PopupDropper_Export.h"
28
29 class QDropEvent;
30 class QGraphicsTextItem;
31 class QSvgRenderer;
32 class QAction;
33 class PopupDropper;
34 class PopupDropperItemPrivate;
35
36 class POPUPDROPPER_EXPORT PopupDropperItem : public QObject, public QAbstractGraphicsShapeItem
37 {
38 Q_OBJECT
39
40 Q_PROPERTY( HoverIndicatorShowStyle hoverIndicatorShowStyle READ hoverIndicatorShowStyle WRITE setHoverIndicatorShowStyle )
41 Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation )
42 Q_PROPERTY( TextProtection textProtection READ textProtection WRITE setTextProtection )
43 Q_PROPERTY( QAction* action READ action WRITE setAction )
44 Q_PROPERTY( QString text READ text WRITE setText )
45 Q_PROPERTY( QFont font READ font WRITE setFont )
46 Q_PROPERTY( QGraphicsTextItem* textItem READ textItem WRITE setTextItem )
47 Q_PROPERTY( QGraphicsRectItem* borderRectItem READ borderRectItem WRITE setBorderRectItem )
48 Q_PROPERTY( QGraphicsSvgItem* svgItem READ svgItem )
49 Q_PROPERTY( QSvgRenderer* sharedRenderer READ sharedRenderer WRITE setSharedRenderer )
50 Q_PROPERTY( QString elementId READ elementId WRITE setElementId )
51 Q_PROPERTY( QRect svgElementRect READ svgElementRect WRITE setSvgElementRect )
52 Q_PROPERTY( int horizontalOffset READ horizontalOffset WRITE setHorizontalOffset )
53 Q_PROPERTY( int textOffset READ textOffset WRITE setTextOffset )
54 Q_PROPERTY( int hoverMsecs READ hoverMsecs WRITE setHoverMsecs )
55 Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth )
56 Q_PROPERTY( int hoverIndicatorRectWidth READ hoverIndicatorRectWidth WRITE setHoverIndicatorRectWidth )
57 Q_PROPERTY( bool submenuTrigger READ isSubmenuTrigger WRITE setSubmenuTrigger )
58 Q_PROPERTY( QColor baseTextColor READ baseTextColor WRITE setBaseTextColor )
59 Q_PROPERTY( QColor hoveredTextColor READ hoveredTextColor WRITE setHoveredTextColor )
60 Q_PROPERTY( QPen hoveredBorderPen READ hoveredBorderPen WRITE setHoveredBorderPen )
61 Q_PROPERTY( QBrush hoveredBrush READ hoveredFillBrush WRITE setHoveredFillBrush )
62 Q_PROPERTY( QBrush hoverIndicatorBrush READ hoverIndicatorFillBrush WRITE setHoverIndicatorFillBrush )
63 Q_PROPERTY( bool customBaseTextColor READ customBaseTextColor )
64 Q_PROPERTY( bool customHoveredTextColor READ customHoveredTextColor )
65 Q_PROPERTY( bool customHoveredBorderPen READ customHoveredBorderPen )
66 Q_PROPERTY( bool customHoveredFillBrush READ customHoveredFillBrush )
67 Q_PROPERTY( qreal subitemOpacity READ subitemOpacity WRITE setSubitemOpacity )
68 Q_PROPERTY( bool separator READ isSeparator WRITE setSeparator )
69 Q_PROPERTY( PopupDropperItem::SeparatorStyle separatorStyle READ separatorStyle WRITE setSeparatorStyle )
70 Q_PROPERTY( bool hasLineSeparatorPen READ hasLineSeparatorPen )
71 Q_PROPERTY( QPen lineSeparatorPen READ lineSeparatorPen WRITE setLineSeparatorPen )
72
73 public:
74 enum HoverIndicatorShowStyle { Never, OnHover, AlwaysShow };
75 Q_ENUM( HoverIndicatorShowStyle )
76 enum Orientation { Left, Right };
77 Q_ENUM( Orientation )
78 enum TextProtection { NoProtection, MultiLine, ScaleFont };
79 Q_ENUM( TextProtection )
80 enum SeparatorStyle { TextSeparator, LineSeparator };
81 Q_ENUM( SeparatorStyle )
82
83 PopupDropperItem( QGraphicsItem *parent = nullptr );
84 explicit PopupDropperItem( const QString &file, QGraphicsItem *parent = nullptr );
85 ~PopupDropperItem() override;
86
87 void show();
88
89 QAction* action() const;
90 void setAction( QAction *action );
91
92 HoverIndicatorShowStyle hoverIndicatorShowStyle() const;
93 void setHoverIndicatorShowStyle( HoverIndicatorShowStyle hover );
94 Orientation orientation() const;
95 void setOrientation( Orientation orientation );
96 TextProtection textProtection() const;
97 void setTextProtection( TextProtection protection );
98
99 QString text() const;
100 void setText( const QString &text );
101 QFont font() const;
102 void setFont( const QFont &font );
103 QColor baseTextColor() const;
104 void setBaseTextColor( const QColor &color );
105 QColor hoveredTextColor() const;
106 void setHoveredTextColor( const QColor &color );
107 QPen hoveredBorderPen() const;
108 void setHoveredBorderPen( const QPen &pen );
109 QBrush hoveredFillBrush() const;
110 void setHoveredFillBrush( const QBrush &brush );
111 QBrush hoverIndicatorFillBrush() const;
112 void setHoverIndicatorFillBrush( const QBrush &brush );
113 bool customBaseTextColor() const;
114 bool customHoveredTextColor() const;
115 bool customHoveredBorderPen() const;
116 bool customHoveredFillBrush() const;
117 void setSubitemOpacity( qreal opacity );
118 qreal subitemOpacity() const;
119
120 QGraphicsTextItem* textItem() const;
121 void setTextItem( QGraphicsTextItem *textItem );
122 void scaleAndReposSvgItem();
123 void reposTextItem();
124 void reposHoverFillRects();
125 QGraphicsRectItem* borderRectItem() const;
126 void setBorderRectItem( QGraphicsRectItem *borderRectItem );
127 QGraphicsSvgItem* svgItem() const;
128
129 QSvgRenderer* sharedRenderer() const;
130 void setSharedRenderer( QSvgRenderer *renderer );
131 QString elementId() const;
132 void setElementId( const QString &id );
133 QRect svgElementRect() const;
134 void setSvgElementRect( const QRect &rect );
135 int horizontalOffset() const;
136 void setHorizontalOffset( int offset );
137 int textOffset() const;
138 void setTextOffset( int offset );
139
140 bool isSeparator() const;
141 void setSeparator( bool separator );
142 PopupDropperItem::SeparatorStyle separatorStyle() const;
143 void setSeparatorStyle( PopupDropperItem::SeparatorStyle style );
144 bool hasLineSeparatorPen() const;
145 QPen lineSeparatorPen() const;
146 void setLineSeparatorPen( const QPen &pen );
147 void clearLineSeparatorPen();
148
149 int hoverMsecs() const;
150 void setHoverMsecs( const int msecs );
151 void hoverEntered();
152 void hoverLeft();
153
154 int borderWidth() const;
155 void setBorderWidth( int width );
156 int hoverIndicatorRectWidth() const;
157 void setHoverIndicatorRectWidth( int width );
158
159 bool isSubmenuTrigger() const;
160 void setSubmenuTrigger( bool trigger );
161
162 void setPopupDropper( PopupDropper* pd );
163
164 //bool operator<( const PopupDropperItem &other ) const;
165
166 void fullUpdate();
167
168 QRectF boundingRect() const override;
169 void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr ) override;
170
171 public Q_SLOTS:
172 virtual void dropped( QDropEvent *event );
173 virtual void hoverFinished();
174 virtual void hoverFrameChanged( int frame );
175
176 private:
177 friend class PopupDropperItemPrivate;
178 PopupDropperItemPrivate* const d;
179
180 };
181
182 #endif