Skip to content
Permalink
Browse files

Make color swatch list hi-dpi friendly

(cherry picked from commit b49e940)
  • Loading branch information
nyalldawson committed Jan 15, 2019
1 parent 7d88163 commit 74c5864b2d0c8c750edec05a9a7e3461651ea992
@@ -704,9 +704,12 @@ void QgsColorSwatchDelegate::paint( QPainter *painter, const QStyleOptionViewIte
}

QRect rect = option.rect;
const int iconSize = Qgis::UI_SCALE_FACTOR * option.fontMetrics.width( 'X' ) * 4;
const int cornerSize = iconSize / 6;
//center it
rect.setLeft( option.rect.center().x() - 15 );
rect.setSize( QSize( 30, 30 ) );
rect.setLeft( option.rect.center().x() - iconSize / 2 );

rect.setSize( QSize( iconSize, iconSize ) );
rect.adjust( 0, 1, 0, 1 );
//create an icon pixmap
painter->save();
@@ -717,12 +720,12 @@ void QgsColorSwatchDelegate::paint( QPainter *painter, const QStyleOptionViewIte
//start with checkboard pattern
QBrush checkBrush = QBrush( transparentBackground() );
painter->setBrush( checkBrush );
painter->drawRoundedRect( rect, 5, 5 );
painter->drawRoundedRect( rect, cornerSize, cornerSize );
}

//draw semi-transparent color on top
painter->setBrush( color );
painter->drawRoundedRect( rect, 5, 5 );
painter->drawRoundedRect( rect, cornerSize, cornerSize );
painter->restore();
}

@@ -738,9 +741,10 @@ QPixmap QgsColorSwatchDelegate::transparentBackground() const

QSize QgsColorSwatchDelegate::sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
Q_UNUSED( option );
Q_UNUSED( index );
return QSize( 30, 32 );

const int iconSize = Qgis::UI_SCALE_FACTOR * option.fontMetrics.width( 'X' ) * 4;
return QSize( iconSize, iconSize * 32 / 30.0 );
}

bool QgsColorSwatchDelegate::editorEvent( QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index )
@@ -65,7 +65,7 @@ QgsCompoundColorWidget::QgsCompoundColorWidget( QWidget *parent, const QColor &c
QgsSettings settings;

mSchemeList->header()->hide();
mSchemeList->setColumnWidth( 0, 44 );
mSchemeList->setColumnWidth( 0, Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 6 );

//get schemes with ShowInColorDialog set
refreshSchemeComboBox();
@@ -63,7 +63,7 @@ QgsColorRampShaderWidget::QgsColorRampShaderWidget( QWidget *parent )

mSwatchDelegate = new QgsColorSwatchDelegate( this );
mColormapTreeWidget->setItemDelegateForColumn( ColorColumn, mSwatchDelegate );
mColormapTreeWidget->setColumnWidth( ColorColumn, 50 );
mColormapTreeWidget->setColumnWidth( ColorColumn, Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 6.6 );
mColormapTreeWidget->setContextMenuPolicy( Qt::CustomContextMenu );
mColormapTreeWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
connect( mColormapTreeWidget, &QTreeView::customContextMenuRequested, this, [ = ]( QPoint ) { contextMenu->exec( QCursor::pos() ); }
@@ -66,7 +66,7 @@ QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer *layer, con

mSwatchDelegate = new QgsColorSwatchDelegate( this );
mTreeView->setItemDelegateForColumn( QgsPalettedRendererModel::ColorColumn, mSwatchDelegate );
mTreeView->setColumnWidth( QgsPalettedRendererModel::ColorColumn, 50 );
mTreeView->setColumnWidth( QgsPalettedRendererModel::ColorColumn, Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 6.6 );
mTreeView->setContextMenuPolicy( Qt::CustomContextMenu );
mTreeView->setSelectionMode( QAbstractItemView::ExtendedSelection );
mTreeView->setDragEnabled( true );

0 comments on commit 74c5864

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