QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsfloatingwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfloatingwidget.h
3  -------------------
4  begin : April 2016
5  copyright : (C) 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 #ifndef QGSFLOATINGWIDGET_H
16 #define QGSFLOATINGWIDGET_H
17 
18 #include <QWidget>
19 #include "qgis_sip.h"
20 #include "qgis_gui.h"
21 
22 class QgsFloatingWidgetEventFilter;
23 
33 class GUI_EXPORT QgsFloatingWidget: public QWidget
34 {
35  Q_OBJECT
36  Q_PROPERTY( QWidget *anchorWidget READ anchorWidget WRITE setAnchorWidget NOTIFY anchorWidgetChanged )
37  Q_PROPERTY( AnchorPoint anchorPoint READ anchorPoint WRITE setAnchorPoint NOTIFY anchorPointChanged )
38  Q_PROPERTY( AnchorPoint anchorWidgetPoint READ anchorWidgetPoint WRITE setAnchorWidgetPoint NOTIFY anchorWidgetPointChanged )
39 
40  public:
41 
44  {
54  };
55  Q_ENUM( AnchorPoint )
56 
57 
61  QgsFloatingWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
62 
69  void setAnchorWidget( QWidget *widget );
70 
76  QWidget *anchorWidget();
77 
83  AnchorPoint anchorPoint() const { return mFloatAnchorPoint; }
84 
91  void setAnchorPoint( AnchorPoint point );
92 
99  AnchorPoint anchorWidgetPoint() const { return mAnchorWidgetAnchorPoint; }
100 
107  void setAnchorWidgetPoint( AnchorPoint point );
108 
109  signals:
110 
112  void anchorWidgetChanged( QWidget *widget );
113 
116 
119 
120  protected:
121  void showEvent( QShowEvent *e ) override;
122  void paintEvent( QPaintEvent *e ) override;
123  void resizeEvent( QResizeEvent *e ) override;
124 
125  private slots:
126 
128  void onAnchorPointChanged();
129 
130  private:
131 
132  QWidget *mAnchorWidget = nullptr;
133  QgsFloatingWidgetEventFilter *mParentEventFilter = nullptr;
134  QgsFloatingWidgetEventFilter *mAnchorEventFilter = nullptr;
135  AnchorPoint mFloatAnchorPoint = BottomMiddle;
136  AnchorPoint mAnchorWidgetAnchorPoint = TopMiddle;
137 
138 };
139 
140 
141 #ifndef SIP_RUN
142 
144 
145 class QgsFloatingWidgetEventFilter: public QObject
146 {
147  Q_OBJECT
148 
149  public:
150 
151  QgsFloatingWidgetEventFilter( QWidget *parent = nullptr );
152 
153  bool eventFilter( QObject *object, QEvent *event ) override;
154 
155  signals:
156 
158  void anchorPointChanged();
159 
160 };
161 
163 
164 #endif
165 
166 #endif // QGSFLOATINGWIDGET_H
QgsFloatingWidget::TopMiddle
@ TopMiddle
Top center of widget.
Definition: qgsfloatingwidget.h:46
QgsFloatingWidget::anchorWidgetPoint
AnchorPoint anchorWidgetPoint() const
Returns the anchor widget's anchor point, which corresponds to the point on the anchor widget which t...
Definition: qgsfloatingwidget.h:99
QgsFloatingWidget::Middle
@ Middle
Middle of widget.
Definition: qgsfloatingwidget.h:49
QgsFloatingWidget::AnchorPoint
AnchorPoint
Reference points for anchoring widget position.
Definition: qgsfloatingwidget.h:44
QgsFloatingWidget::BottomLeft
@ BottomLeft
Bottom-left of widget.
Definition: qgsfloatingwidget.h:51
QgsFloatingWidget::MiddleRight
@ MiddleRight
Middle right of widget.
Definition: qgsfloatingwidget.h:50
QgsFloatingWidget::anchorPointChanged
void anchorPointChanged(QgsFloatingWidget::AnchorPoint point)
Emitted when the anchor point changes.
QgsFloatingWidget::anchorWidgetPointChanged
void anchorWidgetPointChanged(QgsFloatingWidget::AnchorPoint point)
Emitted when the anchor widget point changes.
QgsFloatingWidget::BottomMiddle
@ BottomMiddle
Bottom center of widget.
Definition: qgsfloatingwidget.h:52
QgsFloatingWidget::MiddleLeft
@ MiddleLeft
Middle left of widget.
Definition: qgsfloatingwidget.h:48
AnchorPoint
record about vertex coordinates and index of anchor to which it is snapped
Definition: qgsgeometrysnappersinglesource.cpp:30
QgsFloatingWidget::anchorWidget
QWidget * anchorWidget()
Returns the widget that the floating widget is "anchored" tto.
QgsFloatingWidget::TopLeft
@ TopLeft
Top-left of widget.
Definition: qgsfloatingwidget.h:45
qgis_sip.h
QgsFloatingWidget::TopRight
@ TopRight
Top-right of widget.
Definition: qgsfloatingwidget.h:47
QgsFloatingWidget::anchorPoint
AnchorPoint anchorPoint() const
Returns the floating widget's anchor point, which corresponds to the point on the widget which should...
Definition: qgsfloatingwidget.h:83
QgsFloatingWidget
A QWidget subclass for creating widgets which float outside of the normal Qt layout system.
Definition: qgsfloatingwidget.h:34
QgsFloatingWidget::anchorWidgetChanged
void anchorWidgetChanged(QWidget *widget)
Emitted when the anchor widget changes.
QgsFloatingWidget::BottomRight
@ BottomRight
Bottom-right of widget.
Definition: qgsfloatingwidget.h:53
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53