18#include <QStyleOption> 
   30    mParentEventFilter = 
new QgsFloatingWidgetEventFilter( parent );
 
   31    parent->installEventFilter( mParentEventFilter );
 
   32    connect( mParentEventFilter, &QgsFloatingWidgetEventFilter::anchorPointChanged, 
this, &QgsFloatingWidget::onAnchorPointChanged );
 
 
   38  if ( widget == mAnchorWidget )
 
   44    mAnchorWidget->removeEventFilter( mAnchorEventFilter );
 
   45    delete mAnchorEventFilter;
 
   46    mAnchorEventFilter = 
nullptr;
 
   49  mAnchorWidget = widget;
 
   52    mAnchorEventFilter = 
new QgsFloatingWidgetEventFilter( mAnchorWidget );
 
   53    mAnchorWidget->installEventFilter( mAnchorEventFilter );
 
   54    connect( mAnchorEventFilter, &QgsFloatingWidgetEventFilter::anchorPointChanged, 
this, &QgsFloatingWidget::onAnchorPointChanged );
 
   57  onAnchorPointChanged();
 
 
   68  if ( point == mFloatAnchorPoint )
 
   71  mFloatAnchorPoint = point;
 
   72  onAnchorPointChanged();
 
 
   78  if ( point == mAnchorWidgetAnchorPoint )
 
   81  mAnchorWidgetAnchorPoint = point;
 
   82  onAnchorPointChanged();
 
 
   88  QWidget::showEvent( e );
 
   89  onAnchorPointChanged();
 
 
   96#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 
  102  style()->drawPrimitive( QStyle::PE_Widget, &opt, &p, 
this );
 
 
  107  QWidget::resizeEvent( e );
 
  108  onAnchorPointChanged();
 
 
  111void QgsFloatingWidget::onAnchorPointChanged()
 
  113  if ( !parentWidget() )
 
  118    QPoint anchorWidgetOrigin;
 
  120    switch ( mAnchorWidgetAnchorPoint )
 
  123        anchorWidgetOrigin = QPoint( 0, 0 );
 
  126        anchorWidgetOrigin = QPoint( mAnchorWidget->width() / 2, 0 );
 
  129        anchorWidgetOrigin = QPoint( mAnchorWidget->width(), 0 );
 
  132        anchorWidgetOrigin = QPoint( 0, mAnchorWidget->height() / 2 );
 
  135        anchorWidgetOrigin = QPoint( mAnchorWidget->width() / 2, mAnchorWidget->height() / 2 );
 
  138        anchorWidgetOrigin = QPoint( mAnchorWidget->width(), mAnchorWidget->height() / 2 );
 
  141        anchorWidgetOrigin = QPoint( 0, mAnchorWidget->height() );
 
  144        anchorWidgetOrigin = QPoint( mAnchorWidget->width() / 2, mAnchorWidget->height() );
 
  147        anchorWidgetOrigin = QPoint( mAnchorWidget->width(), mAnchorWidget->height() );
 
  151    anchorWidgetOrigin = mAnchorWidget->mapTo( parentWidget(), anchorWidgetOrigin );
 
  152    int anchorX = anchorWidgetOrigin.x();
 
  153    int anchorY = anchorWidgetOrigin.y();
 
  155    switch ( mFloatAnchorPoint )
 
  160        anchorX = anchorX - width() / 2;
 
  163        anchorX = anchorX - width();
 
  166        anchorY = anchorY - height() / 2;
 
  169        anchorY = anchorY - height() / 2;
 
  170        anchorX = anchorX - width() / 2;
 
  173        anchorX = anchorX - width();
 
  174        anchorY = anchorY - height() / 2;
 
  177        anchorY = anchorY - height();
 
  180        anchorX = anchorX - width() / 2;
 
  181        anchorY = anchorY - height();
 
  184        anchorX = anchorX - width();
 
  185        anchorY = anchorY - height();
 
  190    anchorX = std::clamp( anchorX, 0, parentWidget()->width() - width() );
 
  192    move( anchorX, anchorY );
 
  201QgsFloatingWidgetEventFilter::QgsFloatingWidgetEventFilter( QWidget *parent )
 
  207bool QgsFloatingWidgetEventFilter::eventFilter( QObject *
object, QEvent *event )
 
  210  switch ( event->type() )
 
  214      emit anchorPointChanged();