Skip to content

Commit

Permalink
Make color swatch list hi-dpi friendly
Browse files Browse the repository at this point in the history
(cherry picked from commit b49e940)
  • Loading branch information
nyalldawson committed Jan 15, 2019
1 parent 7d88163 commit 74c5864
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/gui/qgscolorschemelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}

Expand All @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgscompoundcolorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/raster/qgscolorrampshaderwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ); }
Expand Down
2 changes: 1 addition & 1 deletion src/gui/raster/qgspalettedrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 74c5864

Please sign in to comment.