30
30
#include < QMouseEvent>
31
31
#include < QInputDialog>
32
32
33
- QgsColorDialog::QgsColorDialog ()
34
- {
35
- }
36
-
37
- QgsColorDialog::~QgsColorDialog ()
38
- {
39
- }
40
-
41
- QColor QgsColorDialog::getLiveColor ( const QColor& initialColor, QObject* updateObject, const char * updateSlot,
42
- QWidget* parent,
43
- const QString& title,
44
- const QColorDialog::ColorDialogOptions& options )
45
- {
46
- QColor returnColor ( initialColor );
47
- QColorDialog* liveDialog = new QColorDialog ( initialColor, parent );
48
- liveDialog->setWindowTitle ( title.isEmpty () ? tr ( " Select Color" ) : title );
49
- liveDialog->setOptions ( options );
50
-
51
- connect ( liveDialog, SIGNAL ( currentColorChanged ( const QColor& ) ),
52
- updateObject, updateSlot );
53
-
54
- if ( liveDialog->exec () )
55
- {
56
- returnColor = liveDialog->currentColor ();
57
- }
58
- delete liveDialog;
59
- liveDialog = nullptr ;
60
-
61
- return returnColor;
62
- }
63
-
64
-
65
- //
66
- // QgsColorDialogV2
67
- //
68
-
69
- QgsColorDialogV2::QgsColorDialogV2 ( QWidget *parent, Qt::WindowFlags fl, const QColor& color )
33
+ QgsColorDialog::QgsColorDialog ( QWidget *parent, Qt::WindowFlags fl, const QColor& color )
70
34
: QDialog( parent, fl )
71
35
, mPreviousColor( color )
72
36
, mAllowAlpha( true )
@@ -93,51 +57,73 @@ QgsColorDialogV2::QgsColorDialogV2( QWidget *parent, Qt::WindowFlags fl, const Q
93
57
connect ( mColorWidget , SIGNAL ( currentColorChanged ( QColor ) ), this , SIGNAL ( currentColorChanged ( QColor ) ) );
94
58
}
95
59
96
- QgsColorDialogV2 ::~QgsColorDialogV2 ()
60
+ QgsColorDialog ::~QgsColorDialog ()
97
61
{
98
62
99
63
}
100
64
101
- QColor QgsColorDialogV2 ::color () const
65
+ QColor QgsColorDialog ::color () const
102
66
{
103
67
return mColorWidget ->color ();
104
68
}
105
69
106
- void QgsColorDialogV2 ::setTitle ( const QString& title )
70
+ void QgsColorDialog ::setTitle ( const QString& title )
107
71
{
108
72
setWindowTitle ( title.isEmpty () ? tr ( " Select Color" ) : title );
109
73
}
110
74
111
- void QgsColorDialogV2 ::setAllowAlpha ( const bool allowAlpha )
75
+ void QgsColorDialog ::setAllowAlpha ( const bool allowAlpha )
112
76
{
113
77
mAllowAlpha = allowAlpha;
114
78
mColorWidget ->setAllowAlpha ( allowAlpha );
115
79
}
116
80
117
- QColor QgsColorDialogV2 ::getLiveColor ( const QColor &initialColor, QObject *updateObject, const char *updateSlot, QWidget *parent, const QString &title, const bool allowAlpha )
81
+ QColor QgsColorDialog ::getLiveColor ( const QColor &initialColor, QObject *updateObject, const char *updateSlot, QWidget *parent, const QString &title, const bool allowAlpha )
118
82
{
119
83
QColor returnColor ( initialColor );
120
- QgsColorDialogV2* liveDialog = new QgsColorDialogV2 ( parent, 0 , initialColor );
121
- liveDialog->setWindowTitle ( title.isEmpty () ? tr ( " Select Color" ) : title );
122
- if ( !allowAlpha )
84
+
85
+ QSettings settings;
86
+
87
+ // using native color dialogs?
88
+ bool useNative = settings.value ( " /qgis/native_color_dialogs" , false ).toBool ();
89
+ if ( useNative )
123
90
{
124
- liveDialog->setAllowAlpha ( false );
125
- }
91
+ QColorDialog* liveDialog = new QColorDialog ( initialColor, parent );
92
+ liveDialog->setWindowTitle ( title.isEmpty () ? tr ( " Select Color" ) : title );
93
+ liveDialog->setOptions ( allowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
126
94
127
- connect ( liveDialog, SIGNAL ( currentColorChanged ( const QColor& ) ),
128
- updateObject, updateSlot );
95
+ connect ( liveDialog, SIGNAL ( currentColorChanged ( const QColor& ) ),
96
+ updateObject, updateSlot );
129
97
130
- if ( liveDialog->exec () )
98
+ if ( liveDialog->exec () )
99
+ {
100
+ returnColor = liveDialog->currentColor ();
101
+ }
102
+ delete liveDialog;
103
+ }
104
+ else
131
105
{
132
- returnColor = liveDialog->color ();
106
+ QgsColorDialog* liveDialog = new QgsColorDialog ( parent, 0 , initialColor );
107
+ liveDialog->setWindowTitle ( title.isEmpty () ? tr ( " Select Color" ) : title );
108
+ if ( !allowAlpha )
109
+ {
110
+ liveDialog->setAllowAlpha ( false );
111
+ }
112
+
113
+ connect ( liveDialog, SIGNAL ( currentColorChanged ( const QColor& ) ),
114
+ updateObject, updateSlot );
115
+
116
+ if ( liveDialog->exec () )
117
+ {
118
+ returnColor = liveDialog->color ();
119
+ }
120
+ delete liveDialog;
133
121
}
134
- delete liveDialog;
135
- liveDialog = nullptr ;
136
122
137
123
return returnColor;
138
124
}
139
125
140
- QColor QgsColorDialogV2 ::getColor ( const QColor &initialColor, QWidget *parent, const QString &title, const bool allowAlpha )
126
+ QColor QgsColorDialog ::getColor ( const QColor &initialColor, QWidget *parent, const QString &title, const bool allowAlpha )
141
127
{
142
128
QString dialogTitle = title.isEmpty () ? tr ( " Select Color" ) : title;
143
129
@@ -150,7 +136,7 @@ QColor QgsColorDialogV2::getColor( const QColor &initialColor, QWidget *parent,
150
136
}
151
137
else
152
138
{
153
- QgsColorDialogV2 * dialog = new QgsColorDialogV2 ( parent, 0 , initialColor );
139
+ QgsColorDialog * dialog = new QgsColorDialog ( parent, 0 , initialColor );
154
140
dialog->setWindowTitle ( dialogTitle );
155
141
dialog->setAllowAlpha ( allowAlpha );
156
142
@@ -168,33 +154,33 @@ QColor QgsColorDialogV2::getColor( const QColor &initialColor, QWidget *parent,
168
154
}
169
155
}
170
156
171
- void QgsColorDialogV2 ::on_mButtonBox_accepted ()
157
+ void QgsColorDialog ::on_mButtonBox_accepted ()
172
158
{
173
159
saveSettings ();
174
160
accept ();
175
161
}
176
162
177
- void QgsColorDialogV2 ::on_mButtonBox_rejected ()
163
+ void QgsColorDialog ::on_mButtonBox_rejected ()
178
164
{
179
165
saveSettings ();
180
166
reject ();
181
167
}
182
168
183
- void QgsColorDialogV2 ::on_mButtonBox_clicked ( QAbstractButton * button )
169
+ void QgsColorDialog ::on_mButtonBox_clicked ( QAbstractButton * button )
184
170
{
185
171
if ( mButtonBox ->buttonRole ( button ) == QDialogButtonBox::ResetRole && mPreviousColor .isValid () )
186
172
{
187
173
setColor ( mPreviousColor );
188
174
}
189
175
}
190
176
191
- void QgsColorDialogV2 ::saveSettings ()
177
+ void QgsColorDialog ::saveSettings ()
192
178
{
193
179
QSettings settings;
194
180
settings.setValue ( " /Windows/ColorDialog/geometry" , saveGeometry () );
195
181
}
196
182
197
- void QgsColorDialogV2 ::setColor ( const QColor &color )
183
+ void QgsColorDialog ::setColor ( const QColor &color )
198
184
{
199
185
if ( !color.isValid () )
200
186
{
@@ -212,7 +198,7 @@ void QgsColorDialogV2::setColor( const QColor &color )
212
198
emit currentColorChanged ( fixedColor );
213
199
}
214
200
215
- void QgsColorDialogV2 ::closeEvent ( QCloseEvent *e )
201
+ void QgsColorDialog ::closeEvent ( QCloseEvent *e )
216
202
{
217
203
saveSettings ();
218
204
QDialog::closeEvent ( e );
0 commit comments