Exemple #1
0
QgsCurveEditorWidget::QgsCurveEditorWidget( QWidget *parent, const QgsCurveTransform &transform )
  : QWidget( parent )
  , mCurve( transform )
  , mCurrentPlotMarkerIndex( -1 )
{
  mPlot = new QwtPlot();
  mPlot->setMinimumSize( QSize( 0, 100 ) );
  mPlot->setAxisScale( QwtPlot::yLeft, 0, 1 );
  mPlot->setAxisScale( QwtPlot::yRight, 0, 1 );
  mPlot->setAxisScale( QwtPlot::xBottom, 0, 1 );
  mPlot->setAxisScale( QwtPlot::xTop, 0, 1 );

  QVBoxLayout *vlayout = new QVBoxLayout();
  vlayout->addWidget( mPlot );
  setLayout( vlayout );

  // hide the ugly canvas frame
  mPlot->setFrameStyle( QFrame::NoFrame );
  QFrame *plotCanvasFrame = dynamic_cast<QFrame *>( mPlot->canvas() );
  if ( plotCanvasFrame )
    plotCanvasFrame->setFrameStyle( QFrame::NoFrame );

  mPlot->enableAxis( QwtPlot::yLeft, false );
  mPlot->enableAxis( QwtPlot::xBottom, false );

  // add a grid
  QwtPlotGrid *grid = new QwtPlotGrid();
  QwtScaleDiv gridDiv( 0.0, 1.0, QList<double>(), QList<double>(), QList<double>() << 0.2 << 0.4 << 0.6 << 0.8 );
  grid->setXDiv( gridDiv );
  grid->setYDiv( gridDiv );
  grid->setPen( QPen( QColor( 0, 0, 0, 50 ) ) );
  grid->attach( mPlot );

  mPlotCurve = new QwtPlotCurve();
  mPlotCurve->setTitle( QStringLiteral( "Curve" ) );
  mPlotCurve->setPen( QPen( QColor( 30, 30, 30 ), 0.0 ) ),
             mPlotCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  mPlotCurve->attach( mPlot );

  mPlotFilter = new QgsCurveEditorPlotEventFilter( mPlot );
  connect( mPlotFilter, &QgsCurveEditorPlotEventFilter::mousePress, this, &QgsCurveEditorWidget::plotMousePress );
  connect( mPlotFilter, &QgsCurveEditorPlotEventFilter::mouseRelease, this, &QgsCurveEditorWidget::plotMouseRelease );
  connect( mPlotFilter, &QgsCurveEditorPlotEventFilter::mouseMove, this, &QgsCurveEditorWidget::plotMouseMove );

  mPlotCurve->setVisible( true );
  updatePlot();
}
QgsGradientColorRampDialog::QgsGradientColorRampDialog( const QgsGradientColorRamp &ramp, QWidget *parent )
  : QDialog( parent )
  , mRamp( ramp )
  , mCurrentPlotColorComponent( -1 )
  , mCurrentPlotMarkerIndex( 0 )
{
  setupUi( this );
#ifdef Q_OS_MAC
  setWindowModality( Qt::WindowModal );
#endif

  mPositionSpinBox->setShowClearButton( false );
  btnColor1->setAllowOpacity( true );
  btnColor1->setColorDialogTitle( tr( "Select Ramp Color" ) );
  btnColor1->setContext( QStringLiteral( "symbology" ) );
  btnColor1->setShowNoColor( true );
  btnColor1->setNoColorString( tr( "Transparent" ) );
  btnColor2->setAllowOpacity( true );
  btnColor2->setColorDialogTitle( tr( "Select Ramp Color" ) );
  btnColor2->setContext( QStringLiteral( "symbology" ) );
  btnColor2->setShowNoColor( true );
  btnColor2->setNoColorString( tr( "Transparent" ) );
  updateColorButtons();
  connect( btnColor1, &QgsColorButton::colorChanged, this, &QgsGradientColorRampDialog::setColor1 );
  connect( btnColor2, &QgsColorButton::colorChanged, this, &QgsGradientColorRampDialog::setColor2 );

  // fill type combobox
  cboType->blockSignals( true );
  cboType->addItem( tr( "Discrete" ) );
  cboType->addItem( tr( "Continuous" ) );
  if ( mRamp.isDiscrete() )
    cboType->setCurrentIndex( 0 );
  else
    cboType->setCurrentIndex( 1 );
  cboType->blockSignals( false );

  if ( mRamp.info().isEmpty() )
    btnInformation->setEnabled( false );

  mStopEditor->setGradientRamp( mRamp );
  connect( mStopEditor, &QgsGradientStopEditor::changed, this, &QgsGradientColorRampDialog::updateRampFromStopEditor );

  connect( mColorWidget, &QgsCompoundColorWidget::currentColorChanged, this, &QgsGradientColorRampDialog::colorWidgetChanged );
  connect( mDeleteStopButton, &QAbstractButton::clicked, mStopEditor, &QgsGradientStopEditor::deleteSelectedStop );

  QgsSettings settings;
  restoreGeometry( settings.value( QStringLiteral( "Windows/GradientEditor/geometry" ) ).toByteArray() );

  // hide the ugly canvas frame
  mPlot->setFrameStyle( QFrame::NoFrame );
  QFrame *plotCanvasFrame = dynamic_cast<QFrame *>( mPlot->canvas() );
  if ( plotCanvasFrame )
    plotCanvasFrame->setFrameStyle( QFrame::NoFrame );

  mPlot->setAxisScale( QwtPlot::yLeft, 0.0, 1.0 );
  mPlot->enableAxis( QwtPlot::yLeft, false );

  // add a grid
  QwtPlotGrid *grid = new QwtPlotGrid();
  QwtScaleDiv gridDiv( 0.0, 1.0, QList<double>(), QList<double>(), QList<double>() << 0.2 << 0.4 << 0.6 << 0.8 );
  grid->setXDiv( gridDiv );
  grid->setYDiv( gridDiv );
  grid->setPen( QPen( QColor( 0, 0, 0, 50 ) ) );
  grid->attach( mPlot );

  mLightnessCurve = new QwtPlotCurve();
  mLightnessCurve->setTitle( QStringLiteral( "Lightness" ) );
  mLightnessCurve->setPen( QPen( QColor( 70, 150, 255 ), 0.0 ) ),
                  mLightnessCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  mLightnessCurve->attach( mPlot );

  mHueCurve = new QwtPlotCurve();
  mHueCurve->setTitle( QStringLiteral( "Hue" ) );
  mHueCurve->setPen( QPen( QColor( 255, 215, 70 ), 0.0 ) ),
            mHueCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  mHueCurve->attach( mPlot );

  mSaturationCurve = new QwtPlotCurve();
  mSaturationCurve->setTitle( QStringLiteral( "Saturation" ) );
  mSaturationCurve->setPen( QPen( QColor( 255, 70, 150 ), 0.0 ) ),
                   mSaturationCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  mSaturationCurve->attach( mPlot );

  mAlphaCurve = new QwtPlotCurve();
  mAlphaCurve->setTitle( QStringLiteral( "Opacity" ) );
  mAlphaCurve->setPen( QPen( QColor( 50, 50, 50 ), 0.0 ) ),
              mAlphaCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  mAlphaCurve->attach( mPlot );

  mPlotFilter = new QgsGradientPlotEventFilter( mPlot );
  connect( mPlotFilter, &QgsGradientPlotEventFilter::mousePress, this, &QgsGradientColorRampDialog::plotMousePress );
  connect( mPlotFilter, &QgsGradientPlotEventFilter::mouseRelease, this, &QgsGradientColorRampDialog::plotMouseRelease );
  connect( mPlotFilter, &QgsGradientPlotEventFilter::mouseMove, this, &QgsGradientColorRampDialog::plotMouseMove );

  mPlotHueCheckbox->setChecked( settings.value( QStringLiteral( "GradientEditor/plotHue" ), false ).toBool() );
  mPlotLightnessCheckbox->setChecked( settings.value( QStringLiteral( "GradientEditor/plotLightness" ), true ).toBool() );
  mPlotSaturationCheckbox->setChecked( settings.value( QStringLiteral( "GradientEditor/plotSaturation" ), false ).toBool() );
  mPlotAlphaCheckbox->setChecked( settings.value( QStringLiteral( "GradientEditor/plotAlpha" ), false ).toBool() );

  mHueCurve->setVisible( mPlotHueCheckbox->isChecked() );
  mLightnessCurve->setVisible( mPlotLightnessCheckbox->isChecked() );
  mSaturationCurve->setVisible( mPlotSaturationCheckbox->isChecked() );
  mAlphaCurve->setVisible( mPlotAlphaCheckbox->isChecked() );

  connect( mStopEditor, &QgsGradientStopEditor::selectedStopChanged, this, &QgsGradientColorRampDialog::selectedStopChanged );
  mStopEditor->selectStop( 0 );

  connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsGradientColorRampDialog::showHelp );
}