22#include <QAbstractButton>
23#include <QDialogButtonBox>
28#include "moc_qgspresetcolorrampdialog.cpp"
30using namespace Qt::StringLiterals;
37 connect( mButtonAddColor, &QToolButton::clicked,
this, &QgsPresetColorRampWidget::mButtonAddColor_clicked );
38 mTreeColors->setScheme( &mRamp );
46 connect( mTreeColors->model(), &QAbstractItemModel::dataChanged,
this, &QgsPresetColorRampWidget::schemeChanged );
47 connect( mTreeColors->model(), &QAbstractItemModel::rowsRemoved,
this, &QgsPresetColorRampWidget::schemeChanged );
60 mTreeColors->setScheme( &mRamp );
65void QgsPresetColorRampWidget::updatePreview()
67 const QSize size( 300, 40 );
71void QgsPresetColorRampWidget::setColors()
77void QgsPresetColorRampWidget::mButtonAddColor_clicked()
92 if ( !newColor.isValid() )
102void QgsPresetColorRampWidget::schemeChanged()
104 mTreeColors->saveColorsToScheme();
109void QgsPresetColorRampWidget::newColorChanged(
const QColor &color )
111 const int row = mTreeColors->model()->rowCount() - 1;
112 const QModelIndex colorIndex = mTreeColors->model()->index( row, 0 );
113 mTreeColors->model()->setData( colorIndex, color );
119 QVBoxLayout *vLayout =
new QVBoxLayout();
123 vLayout->addWidget( mWidget );
124 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
125 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
126 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
127 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsPresetColorRampDialog::showHelp );
128 vLayout->addWidget( mButtonBox );
129 setLayout( vLayout );
130 setWindowTitle( tr(
"Color Presets Ramp" ) );
139void QgsPresetColorRampDialog::showHelp()
static QColor getColor(const QColor &initialColor, QWidget *parent, const QString &title=QString(), bool allowOpacity=false)
Returns a color selection from a color dialog.
void pasteColors()
Pastes colors from clipboard to the list.
void removeSelection()
Removes any selected colors from the list.
void copyColors()
Copies colors from the list to the clipboard.
void showExportColorsDialog()
Displays a file picker dialog allowing users to export colors from the list into a file.
void showImportColorsDialog()
Displays a file picker dialog allowing users to import colors into the list from a file.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
QgsPresetSchemeColorRamp ramp
void changed()
Emitted when the dialog settings change.
QgsPresetColorRampDialog(const QgsPresetSchemeColorRamp &ramp, QWidget *parent=nullptr)
Constructor for QgsPresetColorRampDialog.
A scheme based color ramp consisting of a list of predefined colors.
static QColor lastUsedColor()
Returns the most recently used color.
static QPixmap colorRampPreviewPixmap(QgsColorRamp *ramp, QSize size, int padding=0, Qt::Orientation direction=Qt::Horizontal, bool flipDirection=false, bool drawTransparentBackground=true)
Returns a pixmap preview for a color ramp.
static QString colorToName(const QColor &color)
Returns a friendly display name for a color.