18#include "moc_qgscolordialog.cpp" 
   29#include <QInputDialog> 
   32  : QDialog( parent, fl )
 
   33  , mPreviousColor( color )
 
   38  connect( mButtonBox, &QDialogButtonBox::accepted, 
this, &QgsColorDialog::mButtonBox_accepted );
 
   39  connect( mButtonBox, &QDialogButtonBox::rejected, 
this, &QgsColorDialog::mButtonBox_rejected );
 
   40  connect( mButtonBox, &QDialogButtonBox::clicked, 
this, &QgsColorDialog::mButtonBox_clicked );
 
   44  if ( mPreviousColor.isValid() )
 
   46    QPushButton *resetButton = 
new QPushButton( tr( 
"Reset" ) );
 
   47    mButtonBox->addButton( resetButton, QDialogButtonBox::ResetRole );
 
   50  if ( 
color.isValid() )
 
   52    mColorWidget->setColor( 
color );
 
   53    mColorWidget->setPreviousColor( 
color );
 
   56  mColorWidget->setAllowOpacity( 
true );
 
   59  connect( 
this, &QDialog::rejected, 
this, &QgsColorDialog::discardColor );
 
   60  connect( mButtonBox, &QDialogButtonBox::helpRequested, 
this, &QgsColorDialog::showHelp );
 
 
   65  return mColorWidget->color();
 
 
   70  setWindowTitle( title.isEmpty() ? tr( 
"Select Color" ) : title );
 
 
   75  mAllowOpacity = allowOpacity;
 
   76  mColorWidget->setAllowOpacity( allowOpacity );
 
 
   81  const QString dialogTitle = title.isEmpty() ? tr( 
"Select Color" ) : title;
 
   85  const bool useNative = settings.
value( QStringLiteral( 
"qgis/native_color_dialogs" ), 
false ).toBool();
 
   88    return QColorDialog::getColor( initialColor, parent, dialogTitle, allowOpacity ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption ) 0 );
 
   93    dialog->setWindowTitle( dialogTitle );
 
   99      result = dialog->
color();
 
 
  110void QgsColorDialog::mButtonBox_accepted()
 
  115void QgsColorDialog::mButtonBox_rejected()
 
  120void QgsColorDialog::mButtonBox_clicked( QAbstractButton *button )
 
  122  if ( mButtonBox->buttonRole( button ) == QDialogButtonBox::ResetRole && mPreviousColor.isValid() )
 
  128void QgsColorDialog::discardColor()
 
  130  mColorWidget->setDiscarded( 
true );
 
  135  if ( !
color.isValid() )
 
  140  QColor fixedColor = QColor( 
color );
 
  141  if ( !mAllowOpacity )
 
  144    fixedColor.setAlpha( 255 );
 
  147  mColorWidget->setColor( fixedColor );
 
 
  153  QDialog::closeEvent( e );
 
 
  156void QgsColorDialog::showHelp()
 
  158  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.
 
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.