|
| 1 | +/** \ingroup gui |
| 2 | + * \class QgsFloatingWidget |
| 3 | + * A QWidget subclass for creating widgets which float outside of the normal Qt layout |
| 4 | + * system. Floating widgets use an "anchor widget" to determine how they are anchored |
| 5 | + * within their parent widget. |
| 6 | + * \note Added in version 2.16 |
| 7 | + */ |
| 8 | + |
| 9 | +class QgsFloatingWidget : QWidget |
| 10 | +{ |
| 11 | +%TypeHeaderCode |
| 12 | +#include <qgsfloatingwidget.h> |
| 13 | +%End |
| 14 | + |
| 15 | + public: |
| 16 | + |
| 17 | + //! Reference points for anchoring widget position |
| 18 | + enum AnchorPoint |
| 19 | + { |
| 20 | + TopLeft, //!< Top-left of widget |
| 21 | + TopMiddle, //!< Top center of widget |
| 22 | + TopRight, //!< Top-right of widget |
| 23 | + MiddleLeft, //!< Middle left of widget |
| 24 | + Middle, //!< Middle of widget |
| 25 | + MiddleRight, //!< Middle right of widget |
| 26 | + BottomLeft, //!< Bottom-left of widget |
| 27 | + BottomMiddle, //!< Bottom center of widget |
| 28 | + BottomRight, //!< Bottom-right of widget |
| 29 | + }; |
| 30 | + |
| 31 | + /** Constructor for QgsFloatingWidget. |
| 32 | + * @param parent parent widget |
| 33 | + */ |
| 34 | + QgsFloatingWidget( QWidget* parent /TransferThis/ = nullptr ); |
| 35 | + |
| 36 | + /** Sets the widget to "anchor" the floating widget to. The floating widget will be repositioned whenever the |
| 37 | + * anchor widget moves or is resized so that it maintains the same relative position to the anchor widget. |
| 38 | + * @param widget anchor widget. Both the floating widget and the anchor widget must share some common parent. |
| 39 | + * @see anchorWidget() |
| 40 | + */ |
| 41 | + void setAnchorWidget( QWidget* widget ); |
| 42 | + |
| 43 | + /** Returns the widget that the floating widget is "anchored" tto. The floating widget will be repositioned whenever the |
| 44 | + * anchor widget moves or is resized so that it maintains the same relative position to the anchor widget. |
| 45 | + * @see setAnchorWidget() |
| 46 | + */ |
| 47 | + QWidget* anchorWidget(); |
| 48 | + |
| 49 | + /** Returns the floating widget's anchor point, which corresponds to the point on the widget which should remain |
| 50 | + * fixed in the same relative position whenever the widget's parent is resized or moved. |
| 51 | + * @see setAnchorPoint() |
| 52 | + */ |
| 53 | + AnchorPoint anchorPoint() const; |
| 54 | + |
| 55 | + /** Sets the floating widget's anchor point, which corresponds to the point on the widget which should remain |
| 56 | + * fixed in the same relative position whenever the widget's parent is resized or moved. |
| 57 | + * @param point anchor point |
| 58 | + * @see anchorPoint() |
| 59 | + */ |
| 60 | + void setAnchorPoint( AnchorPoint point ); |
| 61 | + |
| 62 | + /** Returns the anchor widget's anchor point, which corresponds to the point on the anchor widget which |
| 63 | + * the floating widget should "attach" to. The floating widget should remain fixed in the same relative position |
| 64 | + * to this anchor widget whenever the widget's parent is resized or moved. |
| 65 | + * @see setAnchorWidgetPoint() |
| 66 | + */ |
| 67 | + AnchorPoint anchorWidgetPoint() const; |
| 68 | + |
| 69 | + /** Returns the anchor widget's anchor point, which corresponds to the point on the anchor widget which |
| 70 | + * the floating widget should "attach" to. The floating widget should remain fixed in the same relative position |
| 71 | + * to this anchor widget whenever the widget's parent is resized or moved. |
| 72 | + * @see setAnchorWidgetPoint() |
| 73 | + */ |
| 74 | + void setAnchorWidgetPoint( AnchorPoint point ); |
| 75 | + |
| 76 | + protected: |
| 77 | + void showEvent( QShowEvent* e ); |
| 78 | + virtual void paintEvent( QPaintEvent* e ); |
| 79 | + |
| 80 | +}; |
0 commit comments