@@ -38,7 +38,7 @@ QgsColorWidget::QgsColorWidget( QWidget* parent, const ColorComponent component
3838 , mCurrentColor( Qt::red )
3939 , mComponent( component )
4040{
41-
41+ setAcceptDrops ( true );
4242}
4343
4444QgsColorWidget::~QgsColorWidget ()
@@ -163,6 +163,43 @@ const QPixmap &QgsColorWidget::transparentBackground()
163163 return transpBkgrd;
164164}
165165
166+ void QgsColorWidget::dragEnterEvent ( QDragEnterEvent *e )
167+ {
168+ // is dragged data valid color data?
169+ bool hasAlpha;
170+ QColor mimeColor = QgsSymbolLayerV2Utils::colorFromMimeData ( e->mimeData (), hasAlpha );
171+
172+ if ( mimeColor.isValid () )
173+ {
174+ // if so, we accept the drag
175+ e->acceptProposedAction ();
176+ }
177+ }
178+
179+ void QgsColorWidget::dropEvent ( QDropEvent *e )
180+ {
181+ // is dropped data valid color data?
182+ bool hasAlpha = false ;
183+ QColor mimeColor = QgsSymbolLayerV2Utils::colorFromMimeData ( e->mimeData (), hasAlpha );
184+
185+ if ( mimeColor.isValid () )
186+ {
187+ // accept drop and set new color
188+ e->acceptProposedAction ();
189+
190+ if ( !hasAlpha )
191+ {
192+ // mime color has no explicit alpha component, so keep existing alpha
193+ mimeColor.setAlpha ( mCurrentColor .alpha () );
194+ }
195+
196+ setColor ( mimeColor );
197+ emit colorChanged ( mCurrentColor );
198+ }
199+
200+ // could not get color from mime data
201+ }
202+
166203QColor QgsColorWidget::color () const
167204{
168205 return mCurrentColor ;
0 commit comments