mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Small cleanups to QgsFloatingWidget
This commit is contained in:
parent
b19278c79d
commit
e27822bf39
@ -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,10 +56,11 @@ 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()
|
||||
@ -64,9 +68,29 @@ 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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user