24#include <QInputDialog>
32#include "moc_qgscolordialog.cpp"
34using namespace Qt::StringLiterals;
37 : QDialog( parent, fl )
38 , mPreviousColor(
color )
43 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsColorDialog::mButtonBox_accepted );
44 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsColorDialog::mButtonBox_rejected );
45 connect( mButtonBox, &QDialogButtonBox::clicked,
this, &QgsColorDialog::mButtonBox_clicked );
49 if ( mPreviousColor.isValid() )
51 QPushButton *resetButton =
new QPushButton( tr(
"Reset" ) );
52 mButtonBox->addButton( resetButton, QDialogButtonBox::ResetRole );
55 if (
color.isValid() )
57 mColorWidget->setColor(
color );
58 mColorWidget->setPreviousColor(
color );
61 mColorWidget->setAllowOpacity(
true );
64 connect(
this, &QDialog::rejected,
this, &QgsColorDialog::discardColor );
65 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsColorDialog::showHelp );
70 return mColorWidget->color();
75 setWindowTitle( title.isEmpty() ? tr(
"Select Color" ) : title );
80 mAllowOpacity = allowOpacity;
81 mColorWidget->setAllowOpacity( allowOpacity );
86 const QString dialogTitle = title.isEmpty() ? tr(
"Select Color" ) : title;
90 const bool useNative = settings.
value( u
"qgis/native_color_dialogs"_s,
false ).toBool();
93 return QColorDialog::getColor( initialColor, parent, dialogTitle, allowOpacity ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption ) 0 );
98 dialog->setWindowTitle( dialogTitle );
102 if ( dialog->exec() )
104 result = dialog->
color();
115void QgsColorDialog::mButtonBox_accepted()
120void QgsColorDialog::mButtonBox_rejected()
125void QgsColorDialog::mButtonBox_clicked( QAbstractButton *button )
127 if ( mButtonBox->buttonRole( button ) == QDialogButtonBox::ResetRole && mPreviousColor.isValid() )
133void QgsColorDialog::discardColor()
135 mColorWidget->setDiscarded(
true );
140 if ( !
color.isValid() )
145 QColor fixedColor = QColor(
color );
146 if ( !mAllowOpacity )
149 fixedColor.setAlpha( 255 );
152 mColorWidget->setColor( fixedColor );
158 QDialog::closeEvent( e );
161void QgsColorDialog::showHelp()
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.
Stores settings for use within QGIS.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.