Skip to content
Permalink
Browse files

Small cleanups to QgsFloatingWidget

  • Loading branch information
nyalldawson committed Dec 22, 2016
1 parent b19278c commit e27822bf397b299c55726dbe514679e46a397cc9
Showing with 65 additions and 11 deletions.
  1. +11 −0 python/gui/qgsfloatingwidget.sip
  2. +32 −5 src/gui/qgsfloatingwidget.cpp
  3. +22 −6 src/gui/qgsfloatingwidget.h
@@ -73,6 +73,17 @@ class QgsFloatingWidget : QWidget
*/
void setAnchorWidgetPoint( AnchorPoint point );

signals:

//! Emitted when the anchor widget changes
void anchorWidgetChanged( QWidget* widget );

//! Emitted when the anchor point changes
void anchorPointChanged( AnchorPoint point );

//! Emitted when the anchor widget point changes
void anchorWidgetPointChanged( AnchorPoint point );

protected:
void showEvent( QShowEvent* e );
virtual void paintEvent( QPaintEvent* e );
@@ -34,12 +34,15 @@ QgsFloatingWidget::QgsFloatingWidget( QWidget *parent )
{
mParentEventFilter = new QgsFloatingWidgetEventFilter( parent );
parent->installEventFilter( mParentEventFilter );
connect( mParentEventFilter, SIGNAL( anchorPointChanged() ), this, SLOT( anchorPointChanged() ) );
connect( mParentEventFilter, &QgsFloatingWidgetEventFilter::anchorPointChanged, this, &QgsFloatingWidget::onAnchorPointChanged );
}
}

void QgsFloatingWidget::setAnchorWidget( QWidget *widget )
{
if ( widget == mAnchorWidget )
return;

// remove existing event filter
if ( mAnchorWidget )
{
@@ -53,20 +56,41 @@ void QgsFloatingWidget::setAnchorWidget( QWidget *widget )
{
mAnchorEventFilter = new QgsFloatingWidgetEventFilter( mAnchorWidget );
mAnchorWidget->installEventFilter( mAnchorEventFilter );
connect( mAnchorEventFilter, SIGNAL( anchorPointChanged() ), this, SLOT( anchorPointChanged() ) );
connect( mAnchorEventFilter, &QgsFloatingWidgetEventFilter::anchorPointChanged, this, &QgsFloatingWidget::onAnchorPointChanged );
}

anchorPointChanged();
onAnchorPointChanged();
emit anchorWidgetChanged( mAnchorWidget );
}

QWidget *QgsFloatingWidget::anchorWidget()
{
return mAnchorWidget;
}

void QgsFloatingWidget::setAnchorPoint( QgsFloatingWidget::AnchorPoint point )
{
if ( point == mFloatAnchorPoint )
return;

mFloatAnchorPoint = point;
onAnchorPointChanged();
emit anchorPointChanged( mFloatAnchorPoint );
}

void QgsFloatingWidget::setAnchorWidgetPoint( QgsFloatingWidget::AnchorPoint point )
{
if ( point == mAnchorWidgetAnchorPoint )
return;

mAnchorWidgetAnchorPoint = point;
onAnchorPointChanged();
emit anchorWidgetPointChanged( mAnchorWidgetAnchorPoint );
}

void QgsFloatingWidget::showEvent( QShowEvent *e )
{
anchorPointChanged();
onAnchorPointChanged();
QWidget::showEvent( e );
}

@@ -79,8 +103,11 @@ void QgsFloatingWidget::paintEvent( QPaintEvent* e )
style()->drawPrimitive( QStyle::PE_Widget, &opt, &p, this );
}

void QgsFloatingWidget::anchorPointChanged()
void QgsFloatingWidget::onAnchorPointChanged()
{
if ( !parentWidget() )
return;

if ( mAnchorWidget )
{
QPoint anchorWidgetOrigin;
@@ -17,18 +17,23 @@

#include <QWidget>

class QgsFloatingWidgetEventFilter;

/** \ingroup gui
* \class QgsFloatingWidget
* A QWidget subclass for creating widgets which float outside of the normal Qt layout
* system. Floating widgets use an "anchor widget" to determine how they are anchored
* within their parent widget.
* \note Added in version 2.16
* \note Added in version 3.0
*/

class GUI_EXPORT QgsFloatingWidget: public QWidget
{
Q_OBJECT
Q_ENUMS( AnchorPoint )
Q_PROPERTY( QWidget* anchorWidget READ anchorWidget WRITE setAnchorWidget NOTIFY anchorWidgetChanged )
Q_PROPERTY( AnchorPoint anchorPoint READ anchorPoint WRITE setAnchorPoint NOTIFY anchorPointChanged )
Q_PROPERTY( AnchorPoint anchorWidgetPoint READ anchorWidgetPoint WRITE setAnchorWidgetPoint NOTIFY anchorWidgetPointChanged )

public:

@@ -75,7 +80,7 @@ class GUI_EXPORT QgsFloatingWidget: public QWidget
* @param point anchor point
* @see anchorPoint()
*/
void setAnchorPoint( AnchorPoint point ) { mFloatAnchorPoint = point; anchorPointChanged(); }
void setAnchorPoint( AnchorPoint point );

/** Returns the anchor widget's anchor point, which corresponds to the point on the anchor widget which
* the floating widget should "attach" to. The floating widget should remain fixed in the same relative position
@@ -89,7 +94,18 @@ class GUI_EXPORT QgsFloatingWidget: public QWidget
* to this anchor widget whenever the widget's parent is resized or moved.
* @see setAnchorWidgetPoint()
*/
void setAnchorWidgetPoint( AnchorPoint point ) { mAnchorWidgetAnchorPoint = point; anchorPointChanged(); }
void setAnchorWidgetPoint( AnchorPoint point );

signals:

//! Emitted when the anchor widget changes
void anchorWidgetChanged( QWidget* widget );

//! Emitted when the anchor point changes
void anchorPointChanged( AnchorPoint point );

//! Emitted when the anchor widget point changes
void anchorWidgetPointChanged( AnchorPoint point );

protected:
void showEvent( QShowEvent* e ) override;
@@ -98,13 +114,13 @@ class GUI_EXPORT QgsFloatingWidget: public QWidget
private slots:

//! Repositions the floating widget to a changed anchor point
void anchorPointChanged();
void onAnchorPointChanged();

private:

QWidget* mAnchorWidget;
QObject* mParentEventFilter;
QObject* mAnchorEventFilter;
QgsFloatingWidgetEventFilter* mParentEventFilter;
QgsFloatingWidgetEventFilter* mAnchorEventFilter;
AnchorPoint mFloatAnchorPoint;
AnchorPoint mAnchorWidgetAnchorPoint;

0 comments on commit e27822b

Please sign in to comment.
You can’t perform that action at this time.