Skip to content
Permalink
Browse files

Add a colorSelected signal to QgsColorSchemeList

  • Loading branch information
nyalldawson committed Sep 15, 2014
1 parent 05e1629 commit 33b120f72a932df869b765d472b34535502cdb10
Showing with 53 additions and 0 deletions.
  1. +11 −0 python/gui/qgscolorschemelist.sip
  2. +29 −0 src/gui/qgscolorschemelist.cpp
  3. +13 −0 src/gui/qgscolorschemelist.h
@@ -169,10 +169,21 @@ class QgsColorSchemeList: QTreeView
* @see pasteColors
*/
void copyColors();

signals:

/**Emitted when a color is selected from the list
* @param color color selected
*/
void colorSelected( const QColor color );

protected:

void keyPressEvent( QKeyEvent* event );

void mousePressEvent( QMouseEvent* event );

void mouseReleaseEvent( QMouseEvent* event );

};

@@ -157,6 +157,35 @@ void QgsColorSchemeList::keyPressEvent( QKeyEvent *event )
QTreeView::keyPressEvent( event );
}

void QgsColorSchemeList::mousePressEvent( QMouseEvent *event )
{
if ( event->button() == Qt::LeftButton )
{
//record press start position
mDragStartPosition = event->pos();
}
QTreeView::mousePressEvent( event );
}

void QgsColorSchemeList::mouseReleaseEvent( QMouseEvent *event )
{
if (( event->button() == Qt::LeftButton ) &&
( event->pos() - mDragStartPosition ).manhattanLength() <= QApplication::startDragDistance() )
{
//just a click, not a drag

//if only one item is selected, emit color changed signal
//(if multiple are selected, user probably was interacting with color list rather than trying to pick a color)
if ( selectedIndexes().length() == mModel->columnCount() )
{
QModelIndex selectedColor = selectedIndexes().at( 0 );
emit colorSelected( mModel->colors().at( selectedColor.row() ).first );
}
}

QTreeView::mouseReleaseEvent( event );
}

bool QgsColorSchemeList::importColorsFromGpl( QFile &file )
{
QgsNamedColorList importedColors;
@@ -211,15 +211,28 @@ class GUI_EXPORT QgsColorSchemeList: public QTreeView
*/
void copyColors();

signals:

/**Emitted when a color is selected from the list
* @param color color selected
*/
void colorSelected( const QColor color );

protected:

void keyPressEvent( QKeyEvent* event );

void mousePressEvent( QMouseEvent* event );

void mouseReleaseEvent( QMouseEvent* event );

private:
QgsColorScheme* mScheme;
QgsColorSchemeModel* mModel;
QgsColorSwatchDelegate* mSwatchDelegate;

QPoint mDragStartPosition;

};

#endif

0 comments on commit 33b120f

Please sign in to comment.
You can’t perform that action at this time.