1 /*************************************************************************** 2 qgsmodelgraphicitem.h 3 ---------------------------------- 4 Date : February 2020 5 Copyright : (C) 2020 Nyall Dawson 6 Email : nyall dot dawson at gmail dot com 7 *************************************************************************** 8 * * 9 * This program is free software; you can redistribute it and/or modify * 10 * it under the terms of the GNU General Public License as published by * 11 * the Free Software Foundation; either version 2 of the License, or * 12 * (at your option) any later version. * 13 * * 14 ***************************************************************************/ 15 16 #ifndef QGSMODELGRAPHICITEM_H 17 #define QGSMODELGRAPHICITEM_H 18 19 #include "qgis.h" 20 #include "qgis_gui.h" 21 #include <QGraphicsObject> 22 #include <QPicture> 23 24 class QgsModelGraphicsView; 25 class QgsModelViewMouseEvent; 26 27 ///@cond NOT_STABLE 28 29 30 /** 31 * \ingroup gui 32 * \brief A flat button graphic item for use in the Processing model designer. 33 * \warning Not stable API 34 * \since QGIS 3.14 35 */ 36 class GUI_EXPORT QgsModelDesignerFlatButtonGraphicItem : public QGraphicsObject 37 { 38 Q_OBJECT 39 public: 40 41 /** 42 * Constructor for QgsModelDesignerFlatButtonGraphicItem, with the specified \a parent item. 43 * 44 * The \a picture argument specifies a QPicture object containing the graphic to render 45 * for the button. The button will be rendered at the specified \a position and \a size. 46 */ 47 QgsModelDesignerFlatButtonGraphicItem( QGraphicsItem *parent SIP_TRANSFERTHIS, const QPicture &picture, const QPointF &position, 48 const QSizeF &size = QSizeF( 16, 16 ) ); 49 50 void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr ) override; 51 QRectF boundingRect() const override; 52 void hoverEnterEvent( QGraphicsSceneHoverEvent *event ) override; 53 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override; 54 void mousePressEvent( QGraphicsSceneMouseEvent *event ) override; 55 56 #ifndef SIP_RUN 57 58 /** 59 * Handles a model hover enter \a event. 60 */ 61 virtual void modelHoverEnterEvent( QgsModelViewMouseEvent *event ); 62 63 /** 64 * Handles a model hover leave \a event. 65 */ 66 virtual void modelHoverLeaveEvent( QgsModelViewMouseEvent *event ); 67 68 /** 69 * Handles a model mouse press \a event. 70 */ 71 virtual void modelPressEvent( QgsModelViewMouseEvent *event ); 72 #endif 73 74 /** 75 * Sets the button's \a position. 76 */ 77 void setPosition( const QPointF &position ); 78 79 /** 80 * Returns the associated model view. 81 */ 82 QgsModelGraphicsView *view(); 83 84 signals: 85 86 /** 87 * Emitted when the button is clicked. 88 */ 89 void clicked(); 90 91 protected: 92 93 /** 94 * Sets the \a picture to render for the button graphics. 95 */ 96 void setPicture( const QPicture &picture ); 97 98 private: 99 QPicture mPicture; 100 QPointF mPosition; 101 QSizeF mSize; 102 bool mHoverState = false; 103 }; 104 105 106 /** 107 * \ingroup gui 108 * \brief A button allowing folding or expanding component graphics in the Processing model designer. 109 * \warning Not stable API 110 * \since QGIS 3.14 111 */ 112 class GUI_EXPORT QgsModelDesignerFoldButtonGraphicItem : public QgsModelDesignerFlatButtonGraphicItem 113 { 114 115 Q_OBJECT 116 public: 117 118 /** 119 * Constructor for QgsModelDesignerFoldButtonGraphicItem, with the specified \a parent item. 120 * 121 * The \a folded argument specifies whether the button should initially indicate the folded (collapsed) 122 * state. 123 * 124 * The button will be rendered at the specified \a position and \a size. 125 */ 126 QgsModelDesignerFoldButtonGraphicItem( QGraphicsItem *parent SIP_TRANSFERTHIS, bool folded, const QPointF &position, 127 const QSizeF &size = QSizeF( 11, 11 ) ); 128 129 void mousePressEvent( QGraphicsSceneMouseEvent *event ) override; 130 #ifndef SIP_RUN 131 void modelPressEvent( QgsModelViewMouseEvent *event ) override; 132 #endif 133 134 signals: 135 136 /** 137 * Emitted when the button \a folded state changes. 138 * 139 * If \a folded is TRUE, the button represents the collapsed state for the item. 140 */ 141 void folded( bool folded ); 142 143 private: 144 145 QPicture mPlusPicture; 146 QPicture mMinusPicture; 147 bool mFolded = false; 148 }; 149 150 ///@endcond 151 152 #endif // QGSMODELGRAPHICITEM_H 153