25 #include <QColorDialog>
26 #include <QHeaderView>
27 #include <QInputDialog>
29 #include <QTableWidget>
33 #include <qwt_global.h>
34 #include <qwt_plot_canvas.h>
36 #include <qwt_plot_curve.h>
37 #include <qwt_plot_grid.h>
38 #include <qwt_plot_marker.h>
39 #include <qwt_plot_picker.h>
40 #include <qwt_picker_machine.h>
41 #include <qwt_plot_layout.h>
42 #include <qwt_symbol.h>
43 #include <qwt_legend.h>
44 #include <qwt_scale_div.h>
45 #include <qwt_scale_map.h>
50 , mCurrentPlotColorComponent( -1 )
51 , mCurrentPlotMarkerIndex( 0 )
56 mStopColorSpec->addItem( tr(
"RGB" ),
static_cast< int >( QColor::Spec::Rgb ) );
57 mStopColorSpec->addItem( tr(
"HSV" ),
static_cast< int >( QColor::Spec::Hsv ) );
58 mStopColorSpec->addItem( tr(
"HSL" ),
static_cast< int >( QColor::Spec::Hsl ) );
59 mStopColorSpec->setCurrentIndex( mStopColorSpec->findData(
static_cast< int >(
ramp.
colorSpec() ) ) );
63 mStopDirection->setCurrentIndex( mStopColorSpec->findData(
static_cast< int >(
ramp.
direction() ) ) );
65 mStopDirection->setEnabled(
static_cast< QColor::Spec
>( mStopColorSpec->currentData().toInt() ) != QColor::Spec::Rgb );
67 connect( mStopColorSpec,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [ = ]
69 mStopDirection->setEnabled(
static_cast< QColor::Spec
>( mStopColorSpec->currentData().toInt() ) != QColor::Spec::Rgb );
73 mStopEditor->setSelectedStopColorSpec(
static_cast< QColor::Spec
>( mStopColorSpec->currentData().toInt() ) );
76 connect( mStopDirection,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [ = ]
81 mStopEditor->setSelectedStopDirection(
static_cast< Qgis::AngularDirection >( mStopDirection->currentData().toInt() ) );
84 connect( cboType,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsGradientColorRampDialog::cboType_currentIndexChanged );
85 connect( btnInformation, &QPushButton::pressed,
this, &QgsGradientColorRampDialog::btnInformation_pressed );
86 connect( mPositionSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsGradientColorRampDialog::mPositionSpinBox_valueChanged );
87 connect( mPlotHueCheckbox, &QCheckBox::toggled,
this, &QgsGradientColorRampDialog::mPlotHueCheckbox_toggled );
88 connect( mPlotLightnessCheckbox, &QCheckBox::toggled,
this, &QgsGradientColorRampDialog::mPlotLightnessCheckbox_toggled );
89 connect( mPlotSaturationCheckbox, &QCheckBox::toggled,
this, &QgsGradientColorRampDialog::mPlotSaturationCheckbox_toggled );
90 connect( mPlotAlphaCheckbox, &QCheckBox::toggled,
this, &QgsGradientColorRampDialog::mPlotAlphaCheckbox_toggled );
92 setWindowModality( Qt::WindowModal );
95 mPositionSpinBox->setShowClearButton(
false );
96 btnColor1->setAllowOpacity(
true );
97 btnColor1->setColorDialogTitle( tr(
"Select Ramp Color" ) );
98 btnColor1->setContext( QStringLiteral(
"symbology" ) );
99 btnColor1->setShowNoColor(
true );
100 btnColor1->setNoColorString( tr(
"Transparent" ) );
101 btnColor2->setAllowOpacity(
true );
102 btnColor2->setColorDialogTitle( tr(
"Select Ramp Color" ) );
103 btnColor2->setContext( QStringLiteral(
"symbology" ) );
104 btnColor2->setShowNoColor(
true );
105 btnColor2->setNoColorString( tr(
"Transparent" ) );
106 updateColorButtons();
111 cboType->blockSignals(
true );
112 cboType->addItem( tr(
"Discrete" ) );
113 cboType->addItem( tr(
"Continuous" ) );
115 cboType->setCurrentIndex( 0 );
117 cboType->setCurrentIndex( 1 );
118 cboType->blockSignals(
false );
120 if ( mRamp.
info().isEmpty() )
121 btnInformation->setEnabled(
false );
123 mStopEditor->setGradientRamp( mRamp );
130 mPlot->setFrameStyle( QFrame::NoFrame );
131 QFrame *plotCanvasFrame =
dynamic_cast<QFrame *
>( mPlot->canvas() );
132 if ( plotCanvasFrame )
133 plotCanvasFrame->setFrameStyle( QFrame::NoFrame );
135 mPlot->setAxisScale( QwtPlot::yLeft, 0.0, 1.0 );
136 mPlot->enableAxis( QwtPlot::yLeft,
false );
139 QwtPlotGrid *grid =
new QwtPlotGrid();
140 QwtScaleDiv gridDiv( 0.0, 1.0, QList<double>(), QList<double>(), QList<double>() << 0.2 << 0.4 << 0.6 << 0.8 );
141 grid->setXDiv( gridDiv );
142 grid->setYDiv( gridDiv );
143 grid->setPen( QPen( QColor( 0, 0, 0, 50 ) ) );
144 grid->attach( mPlot );
146 mLightnessCurve =
new QwtPlotCurve();
147 mLightnessCurve->setTitle( tr(
"Lightness" ) );
148 mLightnessCurve->setPen( QPen( QColor( 70, 150, 255 ), 0.0 ) ),
149 mLightnessCurve->setRenderHint( QwtPlotItem::RenderAntialiased,
true );
150 mLightnessCurve->attach( mPlot );
152 mHueCurve =
new QwtPlotCurve();
153 mHueCurve->setTitle( tr(
"Hue" ) );
154 mHueCurve->setPen( QPen( QColor( 255, 215, 70 ), 0.0 ) ),
155 mHueCurve->setRenderHint( QwtPlotItem::RenderAntialiased,
true );
156 mHueCurve->attach( mPlot );
158 mSaturationCurve =
new QwtPlotCurve();
159 mSaturationCurve->setTitle( tr(
"Saturation" ) );
160 mSaturationCurve->setPen( QPen( QColor( 255, 70, 150 ), 0.0 ) ),
161 mSaturationCurve->setRenderHint( QwtPlotItem::RenderAntialiased,
true );
162 mSaturationCurve->attach( mPlot );
164 mAlphaCurve =
new QwtPlotCurve();
165 mAlphaCurve->setTitle( tr(
"Opacity" ) );
166 mAlphaCurve->setPen( QPen( QColor( 50, 50, 50 ), 0.0 ) ),
167 mAlphaCurve->setRenderHint( QwtPlotItem::RenderAntialiased,
true );
168 mAlphaCurve->attach( mPlot );
170 mPlotFilter =
new QgsGradientPlotEventFilter( mPlot );
171 connect( mPlotFilter, &QgsGradientPlotEventFilter::mousePress,
this, &QgsGradientColorRampDialog::plotMousePress );
172 connect( mPlotFilter, &QgsGradientPlotEventFilter::mouseRelease,
this, &QgsGradientColorRampDialog::plotMouseRelease );
173 connect( mPlotFilter, &QgsGradientPlotEventFilter::mouseMove,
this, &QgsGradientColorRampDialog::plotMouseMove );
176 mPlotHueCheckbox->setChecked( settings.
value( QStringLiteral(
"GradientEditor/plotHue" ),
false ).toBool() );
177 mPlotLightnessCheckbox->setChecked( settings.
value( QStringLiteral(
"GradientEditor/plotLightness" ),
true ).toBool() );
178 mPlotSaturationCheckbox->setChecked( settings.
value( QStringLiteral(
"GradientEditor/plotSaturation" ),
false ).toBool() );
179 mPlotAlphaCheckbox->setChecked( settings.
value( QStringLiteral(
"GradientEditor/plotAlpha" ),
false ).toBool() );
181 mHueCurve->setVisible( mPlotHueCheckbox->isChecked() );
182 mLightnessCurve->setVisible( mPlotLightnessCheckbox->isChecked() );
183 mSaturationCurve->setVisible( mPlotSaturationCheckbox->isChecked() );
184 mAlphaCurve->setVisible( mPlotAlphaCheckbox->isChecked() );
187 mStopEditor->selectStop( 0 );
189 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsGradientColorRampDialog::showHelp );
195 settings.
setValue( QStringLiteral(
"GradientEditor/plotHue" ), mPlotHueCheckbox->isChecked() );
196 settings.
setValue( QStringLiteral(
"GradientEditor/plotLightness" ), mPlotLightnessCheckbox->isChecked() );
197 settings.
setValue( QStringLiteral(
"GradientEditor/plotSaturation" ), mPlotSaturationCheckbox->isChecked() );
198 settings.
setValue( QStringLiteral(
"GradientEditor/plotAlpha" ), mPlotAlphaCheckbox->isChecked() );
206 updateColorButtons();
218 void QgsGradientColorRampDialog::cboType_currentIndexChanged(
int index )
224 updateColorButtons();
231 void QgsGradientColorRampDialog::btnInformation_pressed()
233 if ( mRamp.
info().isEmpty() )
237 QLabel *label =
nullptr;
240 QTableWidget *tableInfo =
new QTableWidget( dlg );
241 tableInfo->verticalHeader()->hide();
242 tableInfo->horizontalHeader()->hide();
243 tableInfo->setRowCount( mRamp.
info().count() );
244 tableInfo->setColumnCount( 2 );
247 for ( QgsStringMap::const_iterator it = rampInfo.constBegin();
248 it != rampInfo.constEnd(); ++it )
250 if ( it.key().startsWith( QLatin1String(
"cpt-city" ) ) )
252 tableInfo->setItem( i, 0,
new QTableWidgetItem( it.key() ) );
253 tableInfo->setItem( i, 1,
new QTableWidgetItem( it.value() ) );
254 tableInfo->resizeRowToContents( i );
257 tableInfo->resizeColumnToContents( 0 );
258 tableInfo->horizontalHeader()->setStretchLastSection(
true );
259 tableInfo->setRowCount( i );
260 tableInfo->setFixedHeight( tableInfo->rowHeight( 0 ) * i + 5 );
261 dlg->
layout()->addWidget( tableInfo );
262 dlg->resize( 600, 250 );
264 dlg->
layout()->addSpacing( 5 );
267 QString gradientFile = mRamp.
info().value( QStringLiteral(
"cpt-city-gradient" ) );
268 if ( ! gradientFile.isNull() )
270 QString fileName = gradientFile;
272 if ( ! QFile::exists( fileName ) )
274 fileName = gradientFile;
275 fileName.replace( QLatin1String(
"<cpt-city>" ), QLatin1String(
"http://soliton.vm.bytemark.co.uk/pub/cpt-city" ) );
277 label =
new QLabel( tr(
"Gradient file : %1" ).arg( fileName ), dlg );
278 label->setTextInteractionFlags( Qt::TextBrowserInteraction );
279 dlg->
layout()->addSpacing( 5 );
280 dlg->
layout()->addWidget( label );
284 QString licenseFile = mRamp.
info().value( QStringLiteral(
"cpt-city-license" ) );
285 if ( !licenseFile.isNull() )
287 QString fileName = licenseFile;
289 if ( ! QFile::exists( fileName ) )
291 fileName = licenseFile;
292 fileName.replace( QLatin1String(
"<cpt-city>" ), QLatin1String(
"http://soliton.vm.bytemark.co.uk/pub/cpt-city" ) );
294 label =
new QLabel( tr(
"License file : %1" ).arg( fileName ), dlg );
295 label->setTextInteractionFlags( Qt::TextBrowserInteraction );
296 dlg->
layout()->addSpacing( 5 );
297 dlg->
layout()->addWidget( label );
298 if ( QFile::exists( fileName ) )
300 QTextEdit *textEdit =
new QTextEdit( dlg );
301 textEdit->setReadOnly(
true );
302 QFile file( fileName );
303 if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
305 textEdit->setText( file.readAll() );
307 dlg->
layout()->addSpacing( 5 );
308 dlg->
layout()->addWidget( textEdit );
309 dlg->resize( 600, 500 );
317 void QgsGradientColorRampDialog::updateColorButtons()
319 btnColor1->blockSignals(
true );
320 btnColor1->setColor( mRamp.
color1() );
321 btnColor1->blockSignals(
false );
322 btnColor2->blockSignals(
true );
323 btnColor2->setColor( mRamp.
color2() );
324 btnColor2->blockSignals(
false );
327 void QgsGradientColorRampDialog::updateStopEditor()
329 mStopEditor->blockSignals(
true );
330 mStopEditor->setGradientRamp( mRamp );
331 mStopEditor->blockSignals(
false );
334 void QgsGradientColorRampDialog::selectedStopChanged(
const QgsGradientStop &stop )
337 mColorWidget->blockSignals(
true );
338 mColorWidget->setColor( stop.
color );
339 mColorWidget->blockSignals(
false );
340 mPositionSpinBox->blockSignals(
true );
341 mPositionSpinBox->setValue( stop.
offset * 100 );
342 mPositionSpinBox->blockSignals(
false );
344 mStopColorSpec->setCurrentIndex( mStopColorSpec->findData(
static_cast< int >( mStopEditor->selectedStop().colorSpec() ) ) );
345 mStopDirection->setCurrentIndex( mStopDirection->findData(
static_cast< int >( mStopEditor->selectedStop().direction() ) ) );
351 mPositionSpinBox->setDisabled(
true );
352 mDeleteStopButton->setDisabled(
true );
356 mPositionSpinBox->setDisabled(
false );
357 mDeleteStopButton->setDisabled(
false );
361 mStopColorSpec->setEnabled( !( stop.
offset == 0 && stop.
color == mRamp.
color1() ) );
362 mStopDirection->setEnabled( !( stop.
offset == 0 && stop.
color == mRamp.
color1() ) && mStopEditor->selectedStop().colorSpec() != QColor::Rgb );
367 void QgsGradientColorRampDialog::colorWidgetChanged(
const QColor &color )
369 mStopEditor->setSelectedStopColor( color );
372 void QgsGradientColorRampDialog::mPositionSpinBox_valueChanged(
double val )
374 mStopEditor->setSelectedStopOffset( val / 100.0 );
377 void QgsGradientColorRampDialog::mPlotHueCheckbox_toggled(
bool checked )
379 mHueCurve->setVisible( checked );
383 void QgsGradientColorRampDialog::mPlotLightnessCheckbox_toggled(
bool checked )
385 mLightnessCurve->setVisible( checked );
389 void QgsGradientColorRampDialog::mPlotSaturationCheckbox_toggled(
bool checked )
391 mSaturationCurve->setVisible( checked );
395 void QgsGradientColorRampDialog::mPlotAlphaCheckbox_toggled(
bool checked )
397 mAlphaCurve->setVisible( checked );
401 void QgsGradientColorRampDialog::plotMousePress( QPointF point )
406 mCurrentPlotColorComponent = -1;
407 mCurrentPlotMarkerIndex = -1;
410 for (
int i = 0; i < mRamp.
count(); ++i )
413 double currentOff = 0.0;
417 currentCol = mRamp.
color1();
419 else if ( i == mRamp.
count() - 1 )
422 currentCol = mRamp.
color2();
426 currentOff = mRamp.
stops().at( i - 1 ).offset;
427 currentCol = mRamp.
stops().at( i - 1 ).color;
431 if ( mPlotHueCheckbox->isChecked() )
433 currentDist = std::pow( point.x() - currentOff, 2.0 ) + std::pow( point.y() - currentCol.hslHueF(), 2.0 );
434 if ( currentDist < minDist )
436 minDist = currentDist;
437 mCurrentPlotColorComponent = 0;
438 mCurrentPlotMarkerIndex = i;
441 if ( mPlotLightnessCheckbox->isChecked() )
443 currentDist = std::pow( point.x() - currentOff, 2.0 ) + std::pow( point.y() - currentCol.lightnessF(), 2.0 );
444 if ( currentDist < minDist )
446 minDist = currentDist;
447 mCurrentPlotColorComponent = 1;
448 mCurrentPlotMarkerIndex = i;
451 if ( mPlotSaturationCheckbox->isChecked() )
453 currentDist = std::pow( point.x() - currentOff, 2.0 ) + std::pow( point.y() - currentCol.hslSaturationF(), 2.0 );
454 if ( currentDist < minDist )
456 minDist = currentDist;
457 mCurrentPlotColorComponent = 2;
458 mCurrentPlotMarkerIndex = i;
461 if ( mPlotAlphaCheckbox->isChecked() )
463 currentDist = std::pow( point.x() - currentOff, 2.0 ) + std::pow( point.y() - currentCol.alphaF(), 2.0 );
464 if ( currentDist < minDist )
466 minDist = currentDist;
467 mCurrentPlotColorComponent = 3;
468 mCurrentPlotMarkerIndex = i;
474 if ( mCurrentPlotMarkerIndex >= 0 )
475 mStopEditor->selectStop( mCurrentPlotMarkerIndex );
478 void QgsGradientColorRampDialog::plotMouseRelease( QPointF )
480 mCurrentPlotColorComponent = -1;
483 void QgsGradientColorRampDialog::plotMouseMove( QPointF point )
485 QColor newColor = mStopEditor->selectedStop().color;
487 if ( mCurrentPlotColorComponent == 0 )
488 newColor = QColor::fromHslF( std::clamp( point.y(), qreal( 0.0 ), qreal( 1.0 ) ), newColor.hslSaturationF(), newColor.lightnessF(), newColor.alphaF() );
489 else if ( mCurrentPlotColorComponent == 1 )
490 newColor = QColor::fromHslF( newColor.hslHueF(), newColor.hslSaturationF(), std::clamp( point.y(), qreal( 0.0 ), qreal( 1.0 ) ), newColor.alphaF() );
491 else if ( mCurrentPlotColorComponent == 2 )
492 newColor = QColor::fromHslF( newColor.hslHueF(), std::clamp( point.y(), qreal( 0.0 ), qreal( 1.0 ) ), newColor.lightnessF(), newColor.alphaF() );
493 else if ( mCurrentPlotColorComponent == 3 )
494 newColor = QColor::fromHslF( newColor.hslHueF(), newColor.hslSaturationF(), newColor.lightnessF(), std::clamp( point.y(), qreal( 0.0 ), qreal( 1.0 ) ) );
496 mStopEditor->setSelectedStopDetails( newColor, std::clamp( point.x(), qreal( 0.0 ), qreal( 1.0 ) ) );
499 bool byX( QPointF p1, QPointF p2 )
501 return p1.x() < p2.x();
504 void QgsGradientColorRampDialog::addPlotMarker(
double x,
double y,
const QColor &color,
bool isSelected )
506 QColor borderColor = color.darker( 200 );
507 borderColor.setAlpha( 255 );
509 QColor brushColor = color;
510 brushColor.setAlpha( 255 );
512 QwtPlotMarker *marker =
new QwtPlotMarker();
513 marker->setSymbol(
new QwtSymbol( QwtSymbol::Ellipse, QBrush( brushColor ), QPen( borderColor, isSelected ? 2 : 1 ), QSize( 8, 8 ) ) );
514 marker->setValue( x, y );
515 marker->attach( mPlot );
516 marker->setRenderHint( QwtPlotItem::RenderAntialiased,
true );
520 void QgsGradientColorRampDialog::addMarkersForColor(
double x,
const QColor &color,
bool isSelected )
522 if ( mPlotHueCheckbox->isChecked() )
523 addPlotMarker( x, color.hslHueF(), color, isSelected && mCurrentPlotColorComponent == 0 );
524 if ( mPlotLightnessCheckbox->isChecked() )
525 addPlotMarker( x, color.lightnessF(), color, isSelected && mCurrentPlotColorComponent == 1 );
526 if ( mPlotSaturationCheckbox->isChecked() )
527 addPlotMarker( x, color.hslSaturationF(), color, isSelected && mCurrentPlotColorComponent == 2 );
528 if ( mPlotAlphaCheckbox->isChecked() )
529 addPlotMarker( x, color.alphaF(), color, isSelected && mCurrentPlotColorComponent == 3 );
532 void QgsGradientColorRampDialog::updatePlot()
535 const auto constMMarkers = mMarkers;
536 for ( QwtPlotMarker *marker : constMMarkers )
543 QPolygonF lightnessPoints;
545 QPolygonF saturationPoints;
546 QPolygonF alphaPoints;
547 lightnessPoints << QPointF( 0.0, mRamp.
color1().lightnessF() );
548 huePoints << QPointF( 0.0, mRamp.
color1().hslHueF() );
549 saturationPoints << QPointF( 0.0, mRamp.
color1().hslSaturationF() );
550 alphaPoints << QPointF( 0.0, mRamp.
color1().alphaF() );
551 addMarkersForColor( 0, mRamp.
color1(), mCurrentPlotMarkerIndex == 0 );
554 const auto constStops = mRamp.
stops();
557 lightnessPoints << QPointF( stop.
offset, stop.
color.lightnessF() );
558 huePoints << QPointF( stop.
offset, stop.
color.hslHueF() );
559 saturationPoints << QPointF( stop.
offset, stop.
color.hslSaturationF() );
560 alphaPoints << QPointF( stop.
offset, stop.
color.alphaF() );
562 addMarkersForColor( stop.
offset, stop.
color, mCurrentPlotMarkerIndex == i );
567 for (
double p = 0.001; p < 1.0; p += 0.001 )
569 QColor
c = mRamp.
color( p );
570 lightnessPoints << QPointF( p,
c.lightnessF() );
571 huePoints << QPointF( p,
c.hslHueF() );
572 saturationPoints << QPointF( p,
c.hslSaturationF() );
573 alphaPoints << QPointF( p,
c.alphaF() );
576 lightnessPoints << QPointF( 1.0, mRamp.
color2().lightnessF() );
577 huePoints << QPointF( 1.0, mRamp.
color2().hslHueF() );
578 saturationPoints << QPointF( 1.0, mRamp.
color2().hslSaturationF() );
579 alphaPoints << QPointF( 1.0, mRamp.
color2().alphaF() );
580 addMarkersForColor( 1.0, mRamp.
color2(), mCurrentPlotMarkerIndex == i );
582 std::sort( lightnessPoints.begin(), lightnessPoints.end(),
byX );
583 std::sort( huePoints.begin(), huePoints.end(),
byX );
584 std::sort( saturationPoints.begin(), saturationPoints.end(),
byX );
585 std::sort( alphaPoints.begin(), alphaPoints.end(),
byX );
587 mLightnessCurve->setSamples( lightnessPoints );
588 mHueCurve->setSamples( huePoints );
589 mSaturationCurve->setSamples( saturationPoints );
590 mAlphaCurve->setSamples( alphaPoints );
594 void QgsGradientColorRampDialog::updateRampFromStopEditor()
596 mRamp = mStopEditor->gradientRamp();
599 mPositionSpinBox->blockSignals(
true );
600 mPositionSpinBox->setValue( mStopEditor->selectedStop().offset * 100 );
601 mPositionSpinBox->blockSignals(
false );
602 mColorWidget->blockSignals(
true );
603 mColorWidget->setColor( mStopEditor->selectedStop().color );
604 mColorWidget->blockSignals(
false );
606 mStopColorSpec->setCurrentIndex( mStopColorSpec->findData(
static_cast< int >( mStopEditor->selectedStop().colorSpec() ) ) );
607 mStopDirection->setCurrentIndex( mStopDirection->findData(
static_cast< int >( mStopEditor->selectedStop().direction() ) ) );
611 mStopColorSpec->setEnabled( !( mStopEditor->selectedStop().offset == 0 && mStopEditor->selectedStop().color == mRamp.
color1() ) );
612 mStopDirection->setEnabled( !( mStopEditor->selectedStop().offset == 0 && mStopEditor->selectedStop().color == mRamp.
color1() ) && mStopEditor->selectedStop().colorSpec() != QColor::Rgb );
614 updateColorButtons();
622 mStopEditor->setColor1( color );
623 updateColorButtons();
628 mStopEditor->setColor2( color );
629 updateColorButtons();
632 void QgsGradientColorRampDialog::showHelp()
634 QgsHelp::openHelp( QStringLiteral(
"style_library/style_manager.html#setting-a-color-ramp" ) );
640 QgsGradientPlotEventFilter::QgsGradientPlotEventFilter( QwtPlot *plot )
644 mPlot->canvas()->installEventFilter(
this );
647 bool QgsGradientPlotEventFilter::eventFilter( QObject *
object, QEvent *event )
649 if ( !mPlot->isEnabled() )
650 return QObject::eventFilter(
object, event );
652 switch ( event->type() )
654 case QEvent::MouseButtonPress:
656 const QMouseEvent *mouseEvent =
static_cast<QMouseEvent *
>( event );
657 if ( mouseEvent->button() == Qt::LeftButton )
659 emit mousePress( mapPoint( mouseEvent->pos() ) );
663 case QEvent::MouseMove:
665 const QMouseEvent *mouseEvent =
static_cast<QMouseEvent *
>( event );
666 if ( mouseEvent->buttons() & Qt::LeftButton )
669 emit mouseMove( mapPoint( mouseEvent->pos() ) );
673 case QEvent::MouseButtonRelease:
675 const QMouseEvent *mouseEvent =
static_cast<QMouseEvent *
>( event );
676 if ( mouseEvent->button() == Qt::LeftButton )
678 emit mouseRelease( mapPoint( mouseEvent->pos() ) );
686 return QObject::eventFilter(
object, event );
689 QPointF QgsGradientPlotEventFilter::mapPoint( QPointF point )
const
694 return QPointF( mPlot->canvasMap( QwtPlot::xBottom ).invTransform( point.x() ),
695 mPlot->canvasMap( QwtPlot::yLeft ).invTransform( point.y() ) );