[calamares] Fix off-center text in sidepane

- The text rectangle was **moved**, not shrunk-in-place. Add
   the missing - sign for the right and bottom margin.
 - While here, move from #define to constexpr.
This commit is contained in:
Adriaan de Groot 2019-05-06 13:45:08 +02:00
parent fdc2cff65a
commit 0f30acc13f

View File

@ -31,8 +31,8 @@
#include <QAbstractItemView> #include <QAbstractItemView>
#include <QPainter> #include <QPainter>
#define ITEM_MARGIN 12 static constexpr int const item_margin = 8;
#define VS_FONTSIZE CalamaresUtils::defaultFontSize() + 4 static inline int item_fontsize() { return CalamaresUtils::defaultFontSize() + 4; }
ProgressTreeDelegate::ProgressTreeDelegate( QAbstractItemView* parent ) ProgressTreeDelegate::ProgressTreeDelegate( QAbstractItemView* parent )
: QStyledItemDelegate( parent ) : QStyledItemDelegate( parent )
@ -50,11 +50,11 @@ ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option,
QFont font = qApp->font(); QFont font = qApp->font();
font.setPointSize( VS_FONTSIZE ); font.setPointSize( item_fontsize() );
QFontMetrics fm( font ); QFontMetrics fm( font );
int height = fm.height(); int height = fm.height();
height += 2*ITEM_MARGIN; //margin height += 2 * item_margin;
return QSize( option.rect.width(), height ); return QSize( option.rect.width(), height );
} }
@ -88,12 +88,9 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter,
const QStyleOptionViewItem& option, const QStyleOptionViewItem& option,
const QModelIndex& index ) const const QModelIndex& index ) const
{ {
QRect textRect = option.rect.adjusted( ITEM_MARGIN, QRect textRect = option.rect.adjusted( item_margin, item_margin, -item_margin, -item_margin );
ITEM_MARGIN,
ITEM_MARGIN,
ITEM_MARGIN );
QFont font = qApp->font(); QFont font = qApp->font();
font.setPointSize( VS_FONTSIZE ); font.setPointSize( item_fontsize() );
font.setBold( false ); font.setBold( false );
painter->setFont( font ); painter->setFont( font );