16 #include <QMouseEvent>
17 #include <QEnterEvent>
27 : QWidget( canvas->viewport() )
28 , mMapCanvas( canvas )
29 , mCadDockWidget( cadDockWidget )
33 setAttribute( Qt::WA_TransparentForMouseEvents );
41 mMapCanvas->viewport()->installEventFilter(
this );
42 mMapCanvas->viewport()->setMouseTracking(
true );
45 mAngleLineEdit->installEventFilter( cadDockWidget );
46 mDistanceLineEdit->installEventFilter( cadDockWidget );
47 mXLineEdit->installEventFilter( cadDockWidget );
48 mYLineEdit->installEventFilter( cadDockWidget );
49 mZLineEdit->installEventFilter( cadDockWidget );
50 mMLineEdit->installEventFilter( cadDockWidget );
91 connect( mXLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setX( mXLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
92 connect( mYLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setY( mYLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
93 connect( mZLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setZ( mZLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
94 connect( mMLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setM( mMLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
95 connect( mAngleLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setAngle( mAngleLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
96 connect( mDistanceLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setDistance( mDistanceLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
98 connect( mXLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setX( mXLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
99 connect( mYLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setY( mYLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
100 connect( mZLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setZ( mZLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
101 connect( mMLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setM( mMLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
102 connect( mAngleLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setAngle( mAngleLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
103 connect( mDistanceLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setDistance( mDistanceLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
106 connect( xWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setX( mXLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
108 connect( yWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setY( mYLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
110 connect( zWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setZ( mZLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
112 connect( mWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setM( mMLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
114 connect( angleWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setAngle( mAngleLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
116 connect( distanceWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setDistance( mDistanceLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
120 bool QgsAdvancedDigitizingFloater::eventFilter( QObject *obj, QEvent *event )
122 if ( mCadDockWidget && mCadDockWidget->cadEnabled() && mActive )
124 if ( event->type() == QEvent::MouseMove )
127 QMouseEvent *mouseEvent =
dynamic_cast<QMouseEvent *
>( event );
128 updatePos( mouseEvent->pos() );
130 else if ( event->type() == QEvent::Enter )
133 QEnterEvent *enterEvent =
dynamic_cast<QEnterEvent *
>( event );
134 updatePos( enterEvent->pos() );
137 else if ( event->type() == QEvent::Leave )
143 return QWidget::eventFilter( obj, event );
160 void QgsAdvancedDigitizingFloater::updatePos(
const QPoint &pos )
163 move( pos + QPoint( 15, 5 ) );
166 void QgsAdvancedDigitizingFloater::hideIfDisabled()
168 if ( !mCadDockWidget || ! mCadDockWidget->cadEnabled() || ! mActive )
174 void QgsAdvancedDigitizingFloater::changeX(
const QString &text )
176 mXLineEdit->setText( text );
179 void QgsAdvancedDigitizingFloater::changeY(
const QString &text )
181 mYLineEdit->setText( text );
184 void QgsAdvancedDigitizingFloater::changeZ(
const QString &text )
186 mZLineEdit->setText( text );
189 void QgsAdvancedDigitizingFloater::changeM(
const QString &text )
191 mMLineEdit->setText( text );
194 void QgsAdvancedDigitizingFloater::changeDistance(
const QString &text )
196 mDistanceLineEdit->setText( text );
199 void QgsAdvancedDigitizingFloater::changeAngle(
const QString &text )
201 mAngleLineEdit->setText( text );
204 void QgsAdvancedDigitizingFloater::changeLockX(
bool locked )
208 mXLineEdit->setStyleSheet( QString() );
209 mXLabel->setStyleSheet( QString() );
213 mXLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
214 mXLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
218 void QgsAdvancedDigitizingFloater::changeLockY(
bool locked )
222 mYLineEdit->setStyleSheet( QString() );
223 mYLabel->setStyleSheet( QString() );
227 mYLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
228 mYLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
232 void QgsAdvancedDigitizingFloater::changeLockZ(
bool locked )
236 mZLineEdit->setStyleSheet( QString() );
237 mZLabel->setStyleSheet( QString() );
241 mZLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
242 mZLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
246 void QgsAdvancedDigitizingFloater::changeLockM(
bool locked )
250 mMLineEdit->setStyleSheet( QString() );
251 mMLabel->setStyleSheet( QString() );
255 mMLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
256 mMLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
260 void QgsAdvancedDigitizingFloater::changeLockDistance(
bool locked )
264 mDistanceLineEdit->setStyleSheet( QString() );
265 mDistanceLabel->setStyleSheet( QString() );
269 mDistanceLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
270 mDistanceLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
274 void QgsAdvancedDigitizingFloater::changeLockAngle(
bool locked )
278 mAngleLineEdit->setStyleSheet( QString() );
279 mAngleLabel->setStyleSheet( QString() );
283 mAngleLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
284 mAngleLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
289 void QgsAdvancedDigitizingFloater::changeRelativeX(
bool relative )
293 mXLabel->setText(
"x" );
297 mXLabel->setText(
"Δx" );
302 void QgsAdvancedDigitizingFloater::changeRelativeY(
bool relative )
306 mYLabel->setText(
"y" );
310 mYLabel->setText(
"Δy" );
315 void QgsAdvancedDigitizingFloater::changeRelativeZ(
bool relative )
319 mZLabel->setText(
"z" );
323 mZLabel->setText(
"Δz" );
328 void QgsAdvancedDigitizingFloater::changeRelativeM(
bool relative )
332 mMLabel->setText(
"m" );
336 mMLabel->setText(
"Δm" );
343 void QgsAdvancedDigitizingFloater::changeRelativeAngle(
bool relative )
347 mAngleLabel->setText(
"a" );
351 mAngleLabel->setText(
"Δa" );
356 void QgsAdvancedDigitizingFloater::focusOnX()
360 mXLineEdit->setFocus();
361 mXLineEdit->selectAll();
365 void QgsAdvancedDigitizingFloater::focusOnY()
369 mYLineEdit->setFocus();
370 mYLineEdit->selectAll();
374 void QgsAdvancedDigitizingFloater::focusOnZ()
378 mZLineEdit->setFocus();
379 mZLineEdit->selectAll();
383 void QgsAdvancedDigitizingFloater::focusOnM()
387 mMLineEdit->setFocus();
388 mMLineEdit->selectAll();
392 void QgsAdvancedDigitizingFloater::focusOnDistance()
396 mDistanceLineEdit->setFocus();
397 mDistanceLineEdit->selectAll();
401 void QgsAdvancedDigitizingFloater::focusOnAngle()
405 mAngleLineEdit->setFocus();
406 mAngleLineEdit->selectAll();
411 void QgsAdvancedDigitizingFloater::enabledChangedX(
bool enabled )
413 mXLineEdit->setVisible( enabled );
414 mXLabel->setVisible( enabled );
418 void QgsAdvancedDigitizingFloater::enabledChangedY(
bool enabled )
420 mYLineEdit->setVisible( enabled );
421 mYLabel->setVisible( enabled );
425 void QgsAdvancedDigitizingFloater::enabledChangedZ(
bool enabled )
427 mZLineEdit->setVisible( enabled );
428 mZLabel->setVisible( enabled );
432 void QgsAdvancedDigitizingFloater::enabledChangedM(
bool enabled )
434 mMLineEdit->setVisible( enabled );
435 mMLabel->setVisible( enabled );
439 void QgsAdvancedDigitizingFloater::enabledChangedDistance(
bool enabled )
441 mDistanceLineEdit->setVisible( enabled );
442 mDistanceLabel->setVisible( enabled );
446 void QgsAdvancedDigitizingFloater::enabledChangedAngle(
bool enabled )
448 mAngleLineEdit->setVisible( enabled );
449 mAngleLabel->setVisible( enabled );