16 #include <QMouseEvent>
17 #include <QEnterEvent>
23 #include "qgssettings.h"
27 : QWidget( canvas->viewport() ), mMapCanvas( canvas ), mCadDockWidget( cadDockWidget )
31 setAttribute( Qt::WA_TransparentForMouseEvents );
34 setActive( QgsSettings().value( QStringLiteral(
"/Cad/Floater" ),
false ).toBool() );
39 mMapCanvas->viewport()->installEventFilter(
this );
40 mMapCanvas->viewport()->setMouseTracking(
true );
43 mAngleLineEdit->installEventFilter( cadDockWidget );
44 mDistanceLineEdit->installEventFilter( cadDockWidget );
45 mXLineEdit->installEventFilter( cadDockWidget );
46 mYLineEdit->installEventFilter( cadDockWidget );
77 connect( mXLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setX( mXLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
78 connect( mYLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setY( mYLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
79 connect( mAngleLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setAngle( mAngleLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
80 connect( mDistanceLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setDistance( mDistanceLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
82 connect( mXLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setX( mXLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
83 connect( mYLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setY( mYLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
84 connect( mAngleLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setAngle( mAngleLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
85 connect( mDistanceLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setDistance( mDistanceLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
88 connect( xWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setX( mXLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
90 connect( yWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setY( mYLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
92 connect( angleWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setAngle( mAngleLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
94 connect( distanceWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setDistance( mDistanceLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
98 bool QgsAdvancedDigitizingFloater::eventFilter( QObject *obj, QEvent *event )
100 if ( mCadDockWidget->
cadEnabled() && mActive )
102 if ( event->type() == QEvent::MouseMove )
105 QMouseEvent *mouseEvent =
dynamic_cast<QMouseEvent *
>( event );
106 updatePos( mouseEvent->pos() );
108 else if ( event->type() == QEvent::Enter )
111 QEnterEvent *enterEvent =
dynamic_cast<QEnterEvent *
>( event );
112 updatePos( enterEvent->pos() );
115 else if ( event->type() == QEvent::Leave )
121 return QWidget::eventFilter( obj, event );
131 QgsSettings().setValue( QStringLiteral(
"/Cad/Floater" ),
active );
138 void QgsAdvancedDigitizingFloater::updatePos(
const QPoint &pos )
141 move( pos + QPoint( 15, 5 ) );
144 void QgsAdvancedDigitizingFloater::hideIfDisabled()
146 if ( ! mCadDockWidget->
cadEnabled() || ! mActive )
152 void QgsAdvancedDigitizingFloater::changeX(
const QString &text )
154 mXLineEdit->setText( text );
157 void QgsAdvancedDigitizingFloater::changeY(
const QString &text )
159 mYLineEdit->setText( text );
162 void QgsAdvancedDigitizingFloater::changeDistance(
const QString &text )
164 mDistanceLineEdit->setText( text );
167 void QgsAdvancedDigitizingFloater::changeAngle(
const QString &text )
169 mAngleLineEdit->setText( text );
172 void QgsAdvancedDigitizingFloater::changeLockX(
bool locked )
176 mXLineEdit->setStyleSheet( QString() );
177 mXLabel->setStyleSheet( QString() );
181 mXLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
182 mXLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
186 void QgsAdvancedDigitizingFloater::changeLockY(
bool locked )
190 mYLineEdit->setStyleSheet( QString() );
191 mYLabel->setStyleSheet( QString() );
195 mYLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
196 mYLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
200 void QgsAdvancedDigitizingFloater::changeLockDistance(
bool locked )
204 mDistanceLineEdit->setStyleSheet( QString() );
205 mDistanceLabel->setStyleSheet( QString() );
209 mDistanceLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
210 mDistanceLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
214 void QgsAdvancedDigitizingFloater::changeLockAngle(
bool locked )
218 mAngleLineEdit->setStyleSheet( QString() );
219 mAngleLabel->setStyleSheet( QString() );
223 mAngleLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
224 mAngleLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
229 void QgsAdvancedDigitizingFloater::changeRelativeX(
bool relative )
233 mXLabel->setText(
"x" );
237 mXLabel->setText(
"Δx" );
242 void QgsAdvancedDigitizingFloater::changeRelativeY(
bool relative )
246 mYLabel->setText(
"y" );
250 mYLabel->setText(
"Δy" );
257 void QgsAdvancedDigitizingFloater::changeRelativeAngle(
bool relative )
261 mAngleLabel->setText(
"a" );
265 mAngleLabel->setText(
"Δa" );
270 void QgsAdvancedDigitizingFloater::focusOnX()
274 mXLineEdit->setFocus();
275 mXLineEdit->selectAll();
279 void QgsAdvancedDigitizingFloater::focusOnY()
283 mYLineEdit->setFocus();
284 mYLineEdit->selectAll();
288 void QgsAdvancedDigitizingFloater::focusOnDistance()
292 mDistanceLineEdit->setFocus();
293 mDistanceLineEdit->selectAll();
297 void QgsAdvancedDigitizingFloater::focusOnAngle()
301 mAngleLineEdit->setFocus();
302 mAngleLineEdit->selectAll();
307 void QgsAdvancedDigitizingFloater::enabledChangedX(
bool enabled )
309 mXLineEdit->setVisible( enabled );
310 mXLabel->setVisible( enabled );
314 void QgsAdvancedDigitizingFloater::enabledChangedY(
bool enabled )
316 mYLineEdit->setVisible( enabled );
317 mYLabel->setVisible( enabled );
321 void QgsAdvancedDigitizingFloater::enabledChangedDistance(
bool enabled )
323 mDistanceLineEdit->setVisible( enabled );
324 mDistanceLabel->setVisible( enabled );
328 void QgsAdvancedDigitizingFloater::enabledChangedAngle(
bool enabled )
330 mAngleLineEdit->setVisible( enabled );
331 mAngleLabel->setVisible( enabled );
QgsAdvancedDigitizingFloater(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget)
Create an advanced digitizing floater widget.
void setActive(bool active)
Set whether the floater should be active or not.
bool active()
Whether the floater is active or not.
A event filter for watching for focus events on a parent object.
void focusOut()
Emitted when parent object loses focus.
Map canvas is a class for displaying all GIS data types on a canvas.