26#include <QInputDialog>
34#include "moc_qgscolordialog.cpp"
36using namespace Qt::StringLiterals;
39 : QDialog( parent, fl )
40 , mPreviousColor(
color )
45 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsColorDialog::mButtonBox_accepted );
46 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsColorDialog::mButtonBox_rejected );
47 connect( mButtonBox, &QDialogButtonBox::clicked,
this, &QgsColorDialog::mButtonBox_clicked );
51 if ( mPreviousColor.isValid() )
53 QPushButton *resetButton =
new QPushButton( tr(
"Reset" ) );
54 mButtonBox->addButton( resetButton, QDialogButtonBox::ResetRole );
57 if (
color.isValid() )
59 mColorWidget->setColor(
color );
60 mColorWidget->setPreviousColor(
color );
63 mColorWidget->setAllowOpacity(
true );
66 connect(
this, &QDialog::rejected,
this, &QgsColorDialog::discardColor );
67 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsColorDialog::showHelp );
72 return mColorWidget->color();
77 setWindowTitle( title.isEmpty() ? tr(
"Select Color" ) : title );
82 mAllowOpacity = allowOpacity;
83 mColorWidget->setAllowOpacity( allowOpacity );
88 const QString dialogTitle = title.isEmpty() ? tr(
"Select Color" ) : title;
95 return QColorDialog::getColor( initialColor, parent, dialogTitle, allowOpacity ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption ) 0 );
100 dialog->setWindowTitle( dialogTitle );
104 if ( dialog->exec() )
106 result = dialog->
color();
117void QgsColorDialog::mButtonBox_accepted()
122void QgsColorDialog::mButtonBox_rejected()
127void QgsColorDialog::mButtonBox_clicked( QAbstractButton *button )
129 if ( mButtonBox->buttonRole( button ) == QDialogButtonBox::ResetRole && mPreviousColor.isValid() )
135void QgsColorDialog::discardColor()
137 mColorWidget->setDiscarded(
true );
142 if ( !
color.isValid() )
147 QColor fixedColor = QColor(
color );
148 if ( !mAllowOpacity )
151 fixedColor.setAlpha( 255 );
154 mColorWidget->setColor( fixedColor );
160 QDialog::closeEvent( e );
163void 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.
static const QgsSettingsEntryBool * settingsNativeColorDialogs
Settings entry whether to use native color dialogs.
Stores settings for use within QGIS.