28#include <QInputDialog>
31 : QDialog( parent, fl )
32 , mPreviousColor( color )
37 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsColorDialog::mButtonBox_accepted );
38 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsColorDialog::mButtonBox_rejected );
39 connect( mButtonBox, &QDialogButtonBox::clicked,
this, &QgsColorDialog::mButtonBox_clicked );
43 if ( mPreviousColor.isValid() )
45 QPushButton *resetButton =
new QPushButton( tr(
"Reset" ) );
46 mButtonBox->addButton( resetButton, QDialogButtonBox::ResetRole );
49 if (
color.isValid() )
51 mColorWidget->setColor(
color );
52 mColorWidget->setPreviousColor(
color );
55 mColorWidget->setAllowOpacity(
true );
58 connect(
this, &QDialog::rejected,
this, &QgsColorDialog::discardColor );
59 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsColorDialog::showHelp );
64 return mColorWidget->color();
69 setWindowTitle( title.isEmpty() ? tr(
"Select Color" ) : title );
74 mAllowOpacity = allowOpacity;
75 mColorWidget->setAllowOpacity( allowOpacity );
80 const QString dialogTitle = title.isEmpty() ? tr(
"Select Color" ) : title;
84 const bool useNative = settings.
value( QStringLiteral(
"qgis/native_color_dialogs" ),
false ).toBool();
87 return QColorDialog::getColor( initialColor, parent, dialogTitle, allowOpacity ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
92 dialog->setWindowTitle( dialogTitle );
98 result = dialog->
color();
109void QgsColorDialog::mButtonBox_accepted()
114void QgsColorDialog::mButtonBox_rejected()
119void QgsColorDialog::mButtonBox_clicked( QAbstractButton *button )
121 if ( mButtonBox->buttonRole( button ) == QDialogButtonBox::ResetRole && mPreviousColor.isValid() )
127void QgsColorDialog::discardColor()
129 mColorWidget->setDiscarded(
true );
134 if ( !
color.isValid() )
139 QColor fixedColor = QColor(
color );
140 if ( !mAllowOpacity )
143 fixedColor.setAlpha( 255 );
146 mColorWidget->setColor( fixedColor );
152 QDialog::closeEvent( e );
155void QgsColorDialog::showHelp()
157 QgsHelp::openHelp( QStringLiteral(
"introduction/general_tools.html#color-selector" ) );
A custom QGIS dialog for selecting a color.
QColor color() const
Returns the current color for the dialog.
void setColor(const QColor &color)
Sets the current color for the dialog.
void currentColorChanged(const QColor &color)
Emitted when the dialog's color changes.
void setAllowOpacity(bool allowOpacity)
Sets whether opacity modification (transparency) is permitted for the color dialog.
void closeEvent(QCloseEvent *e) override
static QColor getColor(const QColor &initialColor, QWidget *parent, const QString &title=QString(), bool allowOpacity=false)
Returns a color selection from a color dialog.
QgsColorDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, const QColor &color=QColor())
Create a new color picker dialog.
void setTitle(const QString &title)
Sets the title for the color dialog.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.