24 #include <QPushButton> 26 #include <QToolButton> 27 #include <QFileDialog> 28 #include <QMessageBox> 29 #include <QDesktopWidget> 30 #include <QMouseEvent> 31 #include <QInputDialog> 34 : QDialog( parent, fl )
35 , 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 );
43 restoreGeometry( settings.
value( QStringLiteral(
"Windows/ColorDialog/geometry" ) ).toByteArray() );
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()
117 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 );
136 void QgsColorDialog::saveSettings()
144 if ( !color.isValid() )
149 QColor fixedColor = QColor( color );
150 if ( !mAllowOpacity )
153 fixedColor.setAlpha( 255 );
156 mColorWidget->setColor( fixedColor );
163 QDialog::closeEvent( e );
166 void QgsColorDialog::showHelp()
168 QgsHelp::openHelp( QStringLiteral(
"introduction/general_tools.html#color-selector" ) );
void currentColorChanged(const QColor &color)
Emitted when the dialog's color changes.
This class is a composition of two QSettings instances:
void saveGeometry(QWidget *widget, const QString &keyName)
Save the wigget geometry into settings.
bool restoreGeometry(QWidget *widget, const QString &keyName)
Restore the wigget geometry from settings.
void setValue(const QString &key, const QVariant &value, const QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
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.
void setAllowOpacity(const bool allowOpacity)
Sets whether opacity modification (transparency) is permitted for the color dialog.
A custom QGIS dialog for selecting a color.
static QColor getColor(const QColor &initialColor, QWidget *parent, const QString &title=QString(), const bool allowOpacity=false)
Return a color selection from a color dialog.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
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.