Navigation Menu

Skip to content

Commit

Permalink
Add a colorSelected signal to QgsColorSchemeList
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 15, 2014
1 parent 05e1629 commit 33b120f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
11 changes: 11 additions & 0 deletions python/gui/qgscolorschemelist.sip
Expand Up @@ -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 );

};

29 changes: 29 additions & 0 deletions src/gui/qgscolorschemelist.cpp
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions src/gui/qgscolorschemelist.h
Expand Up @@ -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.