Skip to content

Commit a58d8d5

Browse files
committedOct 2, 2018
Use golden ratio for tooltip preview swatches
1 parent 62d6c8c commit a58d8d5

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed
 

‎src/core/symbology/qgsstylemodel.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,16 @@ QVariant QgsStyleModel::data( const QModelIndex &index, int role ) const
7474

7575
if ( role == Qt::ToolTipRole )
7676
{
77-
QString tooltip = QStringLiteral( "<b>%1</b><br><i>%2</i>" ).arg( name,
77+
QString tooltip = QStringLiteral( "<h3>%1</h3><p><i>%2</i>" ).arg( name,
7878
tags.count() > 0 ? tags.join( QStringLiteral( ", " ) ) : tr( "Not tagged" ) );
7979

8080
// create very large preview image
8181
std::unique_ptr< QgsSymbol > symbol( mStyle->symbol( name ) );
8282
if ( symbol )
8383
{
84-
int size = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).width( 'X' ) * 20 );
85-
QPixmap pm = QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), QSize( size, size ), size / 20 );
84+
int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).width( 'X' ) * 23 );
85+
int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
86+
QPixmap pm = QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), QSize( width, height ), height / 20 );
8687
QByteArray data;
8788
QBuffer buffer( &data );
8889
pm.save( &buffer, "PNG", 100 );

‎src/gui/qgscolorbutton.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,11 @@ bool QgsColorButton::event( QEvent *e )
163163
int saturation = mColor.saturation();
164164

165165
// create very large preview swatch
166-
int size = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 15 );
167-
int margin = static_cast< int >( size * 0.1 );
168-
QImage icon = QImage( size + 2 * margin, size + 2 * margin, QImage::Format_ARGB32 );
166+
int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 23 );
167+
int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
168+
169+
int margin = static_cast< int >( height * 0.1 );
170+
QImage icon = QImage( width + 2 * margin, height + 2 * margin, QImage::Format_ARGB32 );
169171
icon.fill( Qt::transparent );
170172

171173
QPainter p;
@@ -175,14 +177,14 @@ bool QgsColorButton::event( QEvent *e )
175177
QBrush checkBrush = QBrush( transparentBackground() );
176178
p.setPen( Qt::NoPen );
177179
p.setBrush( checkBrush );
178-
p.drawRect( margin, margin, size, size );
180+
p.drawRect( margin, margin, width, height );
179181

180182
//draw color over pattern
181183
p.setBrush( QBrush( mColor ) );
182184

183185
//draw border
184186
p.setPen( QColor( 197, 197, 197 ) );
185-
p.drawRect( margin, margin, size, size );
187+
p.drawRect( margin, margin, width, height );
186188
p.end();
187189

188190
QByteArray data;

‎src/gui/qgscolorswatchgrid.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,10 @@ void QgsColorSwatchGrid::updateTooltip( const int colorIdx )
123123
QString colorName = mColors.at( colorIdx ).second;
124124

125125
// create very large preview swatch, because the grid itself has only tiny preview icons
126-
int size = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 15 );
127-
int margin = static_cast< int >( size * 0.1 );
128-
QImage icon = QImage( size + 2 * margin, size + 2 * margin, QImage::Format_ARGB32 );
126+
int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 23 );
127+
int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
128+
int margin = static_cast< int >( height * 0.1 );
129+
QImage icon = QImage( width + 2 * margin, height + 2 * margin, QImage::Format_ARGB32 );
129130
icon.fill( Qt::transparent );
130131

131132
QPainter p;
@@ -135,14 +136,14 @@ void QgsColorSwatchGrid::updateTooltip( const int colorIdx )
135136
QBrush checkBrush = QBrush( transparentBackground() );
136137
p.setPen( Qt::NoPen );
137138
p.setBrush( checkBrush );
138-
p.drawRect( margin, margin, size, size );
139+
p.drawRect( margin, margin, width, height );
139140

140141
//draw color over pattern
141142
p.setBrush( QBrush( mColors.at( colorIdx ).first ) );
142143

143144
//draw border
144145
p.setPen( QColor( 197, 197, 197 ) );
145-
p.drawRect( margin, margin, size, size );
146+
p.drawRect( margin, margin, width, height );
146147
p.end();
147148

148149
QByteArray data;

‎src/gui/qgssymbolbutton.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ QgsSymbolButton::QgsSymbolButton( QWidget *parent, const QString &dialogTitle )
4545

4646
//make sure height of button looks good under different platforms
4747
QSize size = QToolButton::minimumSizeHint();
48-
int fontHeight = Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.4;
48+
int fontHeight = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.4 );
4949
mSizeHint = QSize( size.width(), std::max( size.height(), fontHeight ) );
5050
}
5151

@@ -473,8 +473,10 @@ void QgsSymbolButton::updatePreview( const QColor &color, QgsSymbol *tempSymbol
473473

474474
// set tooltip
475475
// create very large preview image
476-
int size = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 20 );
477-
QPixmap pm = QgsSymbolLayerUtils::symbolPreviewPixmap( previewSymbol.get(), QSize( size, size ), size / 20 );
476+
int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 23 );
477+
int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
478+
479+
QPixmap pm = QgsSymbolLayerUtils::symbolPreviewPixmap( previewSymbol.get(), QSize( width, height ), height / 20 );
478480
QByteArray data;
479481
QBuffer buffer( &data );
480482
pm.save( &buffer, "PNG", 100 );

0 commit comments

Comments
 (0)
Please sign in to comment.