mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Dynamic StarWidget metrics
The default IMG_SIZE and SPACING in the StarWidget are not appropriate for HiDPI displays. Replace them with StarMetrics which are auto-computed from the (default) font size (which Qt determines from the display DPI settings). Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
29851d956f
commit
0171368b6d
3 changed files with 35 additions and 11 deletions
|
@ -50,17 +50,19 @@ void StarWidgetsDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
|
|||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
const QPixmap active = QPixmap::fromImage(StarWidget::starActive());
|
||||
const QPixmap inactive = QPixmap::fromImage(StarWidget::starInactive());
|
||||
const StarMetrics& metrics = StarWidget::metrics();
|
||||
|
||||
for (int i = 0; i < rating; i++)
|
||||
painter->drawPixmap(option.rect.x() + i * IMG_SIZE + SPACING, option.rect.y() + deltaY, active);
|
||||
painter->drawPixmap(option.rect.x() + i * metrics.size + metrics.spacing, option.rect.y() + deltaY, active);
|
||||
for (int i = rating; i < TOTALSTARS; i++)
|
||||
painter->drawPixmap(option.rect.x() + i * IMG_SIZE + SPACING, option.rect.y() + deltaY, inactive);
|
||||
painter->drawPixmap(option.rect.x() + i * metrics.size + metrics.spacing, option.rect.y() + deltaY, inactive);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
QSize StarWidgetsDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
return QSize(IMG_SIZE * TOTALSTARS + SPACING * (TOTALSTARS - 1), IMG_SIZE);
|
||||
const StarMetrics& metrics = StarWidget::metrics();
|
||||
return QSize(metrics.size * TOTALSTARS + metrics.spacing * (TOTALSTARS - 1), metrics.size);
|
||||
}
|
||||
|
||||
ComboBoxDelegate::ComboBoxDelegate(QAbstractItemModel *model, QObject *parent) : QStyledItemDelegate(parent), model(model)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue