25 #include <QPushButton>
27 #include <QToolButton>
28 #include <QFileDialog>
29 #include <QMessageBox>
30 #include <QMouseEvent>
31 #include <QInputDialog>
34 : QDialog( parent, fl )
35 , mPreviousColor( color )
40 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsColorDialog::mButtonBox_accepted );
41 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsColorDialog::mButtonBox_rejected );
42 connect( mButtonBox, &QDialogButtonBox::clicked,
this, &QgsColorDialog::mButtonBox_clicked );
46 if ( mPreviousColor.isValid() )
48 QPushButton *resetButton =
new QPushButton( tr(
"Reset" ) );
49 mButtonBox->addButton( resetButton, QDialogButtonBox::ResetRole );
52 if (
color.isValid() )
54 mColorWidget->setColor(
color );
55 mColorWidget->setPreviousColor(
color );
58 mColorWidget->setAllowOpacity(
true );
61 connect(
this, &QDialog::rejected,
this, &QgsColorDialog::discardColor );
62 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsColorDialog::showHelp );
67 return mColorWidget->color();
72 setWindowTitle( title.isEmpty() ? tr(
"Select Color" ) : title );
77 mAllowOpacity = allowOpacity;
78 mColorWidget->setAllowOpacity( allowOpacity );
83 const QString dialogTitle = title.isEmpty() ? tr(
"Select Color" ) : title;
87 const bool useNative = settings.
value( QStringLiteral(
"qgis/native_color_dialogs" ),
false ).toBool();
90 return QColorDialog::getColor( initialColor, parent, dialogTitle, allowOpacity ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
95 dialog->setWindowTitle( dialogTitle );
101 result = dialog->
color();
112 void QgsColorDialog::mButtonBox_accepted()
117 void QgsColorDialog::mButtonBox_rejected()
122 void QgsColorDialog::mButtonBox_clicked( QAbstractButton *button )
124 if ( mButtonBox->buttonRole( button ) == QDialogButtonBox::ResetRole && mPreviousColor.isValid() )
130 void QgsColorDialog::discardColor()
132 mColorWidget->setDiscarded(
true );
137 if ( !
color.isValid() )
142 QColor fixedColor = QColor(
color );
143 if ( !mAllowOpacity )
146 fixedColor.setAlpha( 255 );
149 mColorWidget->setColor( fixedColor );
155 QDialog::closeEvent( e );
158 void QgsColorDialog::showHelp()
160 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.