25 #include <QPushButton> 27 #include <QToolButton> 28 #include <QFileDialog> 29 #include <QMessageBox> 30 #include <QDesktopWidget> 31 #include <QMouseEvent> 32 #include <QInputDialog> 35 : QDialog( parent, fl )
36 , mPreviousColor( color )
41 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsColorDialog::mButtonBox_accepted );
42 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsColorDialog::mButtonBox_rejected );
43 connect( mButtonBox, &QDialogButtonBox::clicked,
this, &QgsColorDialog::mButtonBox_clicked );
45 if ( mPreviousColor.isValid() )
47 QPushButton *resetButton =
new QPushButton( tr(
"Reset" ) );
48 mButtonBox->addButton( resetButton, QDialogButtonBox::ResetRole );
51 if ( color.isValid() )
53 mColorWidget->setColor( color );
54 mColorWidget->setPreviousColor( color );
57 mColorWidget->setAllowOpacity(
true );
60 connect(
this, &QDialog::rejected,
this, &QgsColorDialog::discardColor );
61 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsColorDialog::showHelp );
66 return mColorWidget->color();
71 setWindowTitle( title.isEmpty() ? tr(
"Select Color" ) : title );
76 mAllowOpacity = allowOpacity;
77 mColorWidget->setAllowOpacity( allowOpacity );
82 QString dialogTitle = title.isEmpty() ? tr(
"Select Color" ) : title;
86 bool useNative = settings.
value( QStringLiteral(
"qgis/native_color_dialogs" ),
false ).toBool();
89 return QColorDialog::getColor( initialColor, parent, dialogTitle, allowOpacity ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
94 dialog->setWindowTitle( dialogTitle );
100 result = dialog->
color();
111 void QgsColorDialog::mButtonBox_accepted()
116 void QgsColorDialog::mButtonBox_rejected()
121 void QgsColorDialog::mButtonBox_clicked( QAbstractButton *button )
123 if ( mButtonBox->buttonRole( button ) == QDialogButtonBox::ResetRole && mPreviousColor.isValid() )
129 void QgsColorDialog::discardColor()
131 mColorWidget->setDiscarded(
true );
136 if ( !color.isValid() )
141 QColor fixedColor = QColor( color );
142 if ( !mAllowOpacity )
145 fixedColor.setAlpha( 255 );
148 mColorWidget->setColor( fixedColor );
154 QDialog::closeEvent( e );
157 void QgsColorDialog::showHelp()
159 QgsHelp::openHelp( QStringLiteral(
"introduction/general_tools.html#color-selector" ) );
static QColor getColor(const QColor &initialColor, QWidget *parent, const QString &title=QString(), bool allowOpacity=false)
Returns a color selection from a color dialog.
void currentColorChanged(const QColor &color)
Emitted when the dialog's color changes.
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.
void setAllowOpacity(bool allowOpacity)
Sets whether opacity modification (transparency) is permitted for the color dialog.
void setTitle(const QString &title)
Sets the title for the color dialog.
void setColor(const QColor &color)
Sets the current color for the dialog.
void closeEvent(QCloseEvent *e) override
QColor color() const
Returns the current color for the dialog.
A custom QGIS dialog for selecting a color.
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.
QgsColorDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, const QColor &color=QColor())
Create a new color picker dialog.