22 #include "qgssettings.h" 
   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 );
 
   47   if ( mPreviousColor.isValid() )
 
   49     QPushButton *resetButton = 
new QPushButton( tr( 
"Reset" ) );
 
   50     mButtonBox->addButton( resetButton, QDialogButtonBox::ResetRole );
 
   53   if ( 
color.isValid() )
 
   55     mColorWidget->setColor( 
color );
 
   56     mColorWidget->setPreviousColor( 
color );
 
   59   mColorWidget->setAllowOpacity( 
true );
 
   62   connect( 
this, &QDialog::rejected, 
this, &QgsColorDialog::discardColor );
 
   63   connect( mButtonBox, &QDialogButtonBox::helpRequested, 
this, &QgsColorDialog::showHelp );
 
   68   return mColorWidget->color();
 
   73   setWindowTitle( title.isEmpty() ? tr( 
"Select Color" ) : title );
 
   78   mAllowOpacity = allowOpacity;
 
   79   mColorWidget->setAllowOpacity( allowOpacity );
 
   84   QString dialogTitle = title.isEmpty() ? tr( 
"Select Color" ) : title;
 
   88   bool useNative = settings.value( QStringLiteral( 
"qgis/native_color_dialogs" ), 
false ).toBool();
 
   91     return QColorDialog::getColor( initialColor, parent, dialogTitle, allowOpacity ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
 
   96     dialog->setWindowTitle( dialogTitle );
 
  100     if ( dialog->exec() )
 
  102       result = dialog->
color();
 
  113 void QgsColorDialog::mButtonBox_accepted()
 
  118 void QgsColorDialog::mButtonBox_rejected()
 
  123 void QgsColorDialog::mButtonBox_clicked( QAbstractButton *button )
 
  125   if ( mButtonBox->buttonRole( button ) == QDialogButtonBox::ResetRole && mPreviousColor.isValid() )
 
  131 void QgsColorDialog::discardColor()
 
  133   mColorWidget->setDiscarded( 
true );
 
  138   if ( !
color.isValid() )
 
  143   QColor fixedColor = QColor( 
color );
 
  144   if ( !mAllowOpacity )
 
  147     fixedColor.setAlpha( 255 );
 
  150   mColorWidget->setColor( fixedColor );
 
  156   QDialog::closeEvent( e );
 
  159 void QgsColorDialog::showHelp()
 
  161   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.