Skip to content
Permalink
Browse files

[ui] Harmonize CAD panel by using toolbar (fixes hidpi et cie)

  • Loading branch information
nirvn committed Feb 11, 2019
1 parent 69e5415 commit f8f701c321a8d1ef8e8542f34f1f04cd8ff3951a
@@ -56,19 +56,11 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas *
mXLineEdit->installEventFilter( this );
mYLineEdit->installEventFilter( this );

// this action is also used in the advanced digitizing tool bar
mEnableAction = new QAction( this );
mEnableAction->setText( tr( "Enable advanced digitizing tools" ) );
mEnableAction->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/cadtools/cad.svg" ) ) );
mEnableAction->setCheckable( true );
mEnabledButton->addAction( mEnableAction );
mEnabledButton->setDefaultAction( mEnableAction );

// Connect the UI to the event filter to update constraints
connect( mEnableAction, &QAction::triggered, this, &QgsAdvancedDigitizingDockWidget::activateCad );
connect( mConstructionModeButton, &QAbstractButton::clicked, this, &QgsAdvancedDigitizingDockWidget::setConstructionMode );
connect( mParallelButton, &QAbstractButton::clicked, this, &QgsAdvancedDigitizingDockWidget::additionalConstraintClicked );
connect( mPerpendicularButton, &QAbstractButton::clicked, this, &QgsAdvancedDigitizingDockWidget::additionalConstraintClicked );
connect( mConstructionModeAction, &QAction::triggered, this, &QgsAdvancedDigitizingDockWidget::setConstructionMode );
connect( mParallelAction, &QAction::triggered, this, &QgsAdvancedDigitizingDockWidget::additionalConstraintClicked );
connect( mPerpendicularAction, &QAction::triggered, this, &QgsAdvancedDigitizingDockWidget::additionalConstraintClicked );
connect( mLockAngleButton, &QAbstractButton::clicked, this, &QgsAdvancedDigitizingDockWidget::lockConstraint );
connect( mLockDistanceButton, &QAbstractButton::clicked, this, &QgsAdvancedDigitizingDockWidget::lockConstraint );
connect( mLockXButton, &QAbstractButton::clicked, this, &QgsAdvancedDigitizingDockWidget::lockConstraint );
@@ -124,11 +116,12 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas *
mCommonAngleActions.insert( action, it->first );
}

mSettingsButton->setMenu( menu );
connect( mSettingsButton, SIGNAL( triggered( QAction * ) ), this, SLOT( settingsButtonTriggered( QAction * ) ) );
qobject_cast< QToolButton *>( mToolbar->widgetForAction( mSettingsAction ) )->setPopupMode( QToolButton::InstantPopup );
mSettingsAction->setMenu( menu );
connect( menu, &QMenu::triggered, this, &QgsAdvancedDigitizingDockWidget::settingsButtonTriggered );

// set tooltips
mConstructionModeButton->setToolTip( "<b>" + tr( "Construction mode" ) + "</b><br>(" + tr( "press c to toggle on/off" ) + ")" );
mConstructionModeAction->setToolTip( "<b>" + tr( "Construction mode" ) + "</b><br>(" + tr( "press c to toggle on/off" ) + ")" );
mDistanceLineEdit->setToolTip( "<b>" + tr( "Distance" ) + "</b><br>(" + tr( "press d for quick access" ) + ")" );
mLockDistanceButton->setToolTip( "<b>" + tr( "Lock distance" ) + "</b><br>(" + tr( "press Ctrl + d for quick access" ) + ")" );
mRepeatingLockDistanceButton->setToolTip( "<b>" + tr( "Continuously lock distance" ) + "</b>" );
@@ -166,7 +159,10 @@ void QgsAdvancedDigitizingDockWidget::setCadEnabled( bool enabled )
{
mCadEnabled = enabled;
mEnableAction->setChecked( enabled );
mCadButtons->setEnabled( enabled );
mConstructionModeAction->setEnabled( enabled );
mParallelAction->setEnabled( enabled );
mPerpendicularAction->setEnabled( enabled );
mSettingsAction->setEnabled( enabled );
mInputWidgets->setEnabled( enabled );

clear();
@@ -193,11 +189,11 @@ void QgsAdvancedDigitizingDockWidget::additionalConstraintClicked( bool activate
{
lockAdditionalConstraint( NoConstraint );
}
if ( sender() == mParallelButton )
if ( sender() == mParallelAction )
{
lockAdditionalConstraint( Parallel );
}
else if ( sender() == mPerpendicularButton )
else if ( sender() == mPerpendicularAction )
{
lockAdditionalConstraint( Perpendicular );
}
@@ -242,7 +238,7 @@ void QgsAdvancedDigitizingDockWidget::setConstraintRepeatingLock( bool activate
void QgsAdvancedDigitizingDockWidget::setConstructionMode( bool enabled )
{
mConstructionMode = enabled;
mConstructionModeButton->setChecked( enabled );
mConstructionModeAction->setChecked( enabled );
}

void QgsAdvancedDigitizingDockWidget::settingsButtonTriggered( QAction *action )
@@ -421,8 +417,8 @@ void QgsAdvancedDigitizingDockWidget::constraintFocusOut()
void QgsAdvancedDigitizingDockWidget::lockAdditionalConstraint( AdditionalConstraint constraint )
{
mAdditionalConstraint = constraint;
mPerpendicularButton->setChecked( constraint == Perpendicular );
mParallelButton->setChecked( constraint == Parallel );
mPerpendicularAction->setChecked( constraint == Perpendicular );
mParallelAction->setChecked( constraint == Parallel );
}

void QgsAdvancedDigitizingDockWidget::updateCapacity( bool updateUIwithoutChange )
@@ -451,19 +447,19 @@ void QgsAdvancedDigitizingDockWidget::updateCapacity( bool updateUIwithoutChange
bool absoluteAngle = mCadEnabled && newCapacities.testFlag( AbsoluteAngle );
bool relativeCoordinates = mCadEnabled && newCapacities.testFlag( RelativeCoordinates );

mPerpendicularButton->setEnabled( absoluteAngle && snappingEnabled );
mParallelButton->setEnabled( absoluteAngle && snappingEnabled );
mPerpendicularAction->setEnabled( absoluteAngle && snappingEnabled );
mParallelAction->setEnabled( absoluteAngle && snappingEnabled );

//update tooltips on buttons
if ( !snappingEnabled )
{
mPerpendicularButton->setToolTip( tr( "Snapping must be enabled to utilize perpendicular mode" ) );
mParallelButton->setToolTip( tr( "Snapping must be enabled to utilize parallel mode" ) );
mPerpendicularAction->setToolTip( tr( "Snapping must be enabled to utilize perpendicular mode" ) );
mParallelAction->setToolTip( tr( "Snapping must be enabled to utilize parallel mode" ) );
}
else
{
mPerpendicularButton->setToolTip( "<b>" + tr( "Perpendicular" ) + "</b><br>(" + tr( "press p to switch between perpendicular, parallel and normal mode" ) + ")" );
mParallelButton->setToolTip( "<b>" + tr( "Parallel" ) + "</b><br>(" + tr( "press p to switch between perpendicular, parallel and normal mode" ) + ")" );
mPerpendicularAction->setToolTip( "<b>" + tr( "Perpendicular" ) + "</b><br>(" + tr( "press p to switch between perpendicular, parallel and normal mode" ) + ")" );
mParallelAction->setToolTip( "<b>" + tr( "Parallel" ) + "</b><br>(" + tr( "press p to switch between perpendicular, parallel and normal mode" ) + ")" );
}


@@ -930,8 +926,8 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
{
if ( type == QEvent::KeyPress )
{
bool parallel = mParallelButton->isChecked();
bool perpendicular = mPerpendicularButton->isChecked();
bool parallel = mParallelAction->isChecked();
bool perpendicular = mPerpendicularAction->isChecked();

if ( !parallel && !perpendicular )
{
@@ -972,7 +968,6 @@ void QgsAdvancedDigitizingDockWidget::enable()
mEnableAction->setEnabled( true );
mErrorLabel->hide();
mCadWidget->show();
setMaximumHeight( 220 );

mCurrentMapToolSupportsCad = true;

@@ -992,7 +987,6 @@ void QgsAdvancedDigitizingDockWidget::disable()
mErrorLabel->setText( tr( "CAD tools are not enabled for the current map tool" ) );
mErrorLabel->show();
mCadWidget->hide();
setMaximumHeight( 80 );

mCurrentMapToolSupportsCad = false;

@@ -492,7 +492,6 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
std::unique_ptr<QgsMessageBarItem> mErrorMessage;

// UI
QAction *mEnableAction = nullptr;
QMap< QAction *, double > mCommonAngleActions; // map the common angle actions with their angle values

// Snap indicator

0 comments on commit f8f701c

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