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" ) );