-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI: Fix marker generation on HiDPI displays #54
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -775,8 +775,8 @@ void ListViewDelegate::paintLog(QPainter* p, const QStyleOptionViewItem& opt, | |
} | ||
QStyleOptionViewItem newOpt(opt); // we need a copy | ||
if (pm) { | ||
p->drawPixmap(newOpt.rect.x(), newOpt.rect.y() + 1, *pm); // +1 means leave a pixel spacing above the pixmap | ||
newOpt.rect.adjust(pm->width(), 0, 0, 0); | ||
p->drawPixmap(newOpt.rect.x(), newOpt.rect.y() + 1, *pm); // +1 means leave a pixel spacing above the pixmap | ||
newOpt.rect.adjust(pm->width() / dpr(), 0, 0, 0); | ||
delete pm; | ||
} | ||
if (isHighlighted) | ||
|
@@ -874,36 +874,52 @@ QString ListView::refNameAt(const QPoint &pos) | |
return QString(); | ||
} | ||
|
||
/* | ||
* Return the device pixel ratio | ||
*/ | ||
const qreal ListViewDelegate::dpr(void) const { | ||
#if QT_VERSION >= QT_VERSION_CHECK(5,6,0) | ||
return qApp->devicePixelRatio(); | ||
#else | ||
return 1.0; | ||
#endif | ||
} | ||
|
||
void ListViewDelegate::addTextPixmap(QPixmap** pp, SCRef txt, const QStyleOptionViewItem& opt) const { | ||
|
||
QPixmap* pm = *pp; | ||
int ofs = pm->isNull() ? 0 : pm->width() + 2; | ||
int spacing = 4; | ||
QFontMetrics fm(opt.font); | ||
int pw = fm.boundingRect(txt).width() + 2 * spacing; | ||
int ph = fm.height(); | ||
|
||
QSize pixmapSize(ofs + pw, ph); | ||
const unsigned int mark_spacing = 2; // Space between markers in pixels | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is highly preferable to avoid mixing functional changes and whitespace or code cleanup (like changing variable names without changing their use). |
||
unsigned int offset = pm->isNull() ? 0 : (pm->width() / dpr()) + mark_spacing; // Marker's offset in the base pixmap | ||
|
||
QFontMetrics fm(opt.font); | ||
const unsigned int text_spacing = 4; | ||
unsigned int text_width = fm.boundingRect(txt).width() + 2 * text_spacing; | ||
unsigned int text_height = fm.height(); | ||
|
||
// Define size of the new Pixmap | ||
QSize pixmapSize((offset + text_width) * dpr(), | ||
(text_height) * dpr()); | ||
|
||
QPixmap* newPm = new QPixmap(pixmapSize); | ||
#if QT_VERSION >= QT_VERSION_CHECK(5,6,0) | ||
qreal dpr = qApp->devicePixelRatio(); | ||
QPixmap* newPm = new QPixmap(pixmapSize * dpr); | ||
newPm->setDevicePixelRatio(dpr); | ||
#else | ||
QPixmap* newPm = new QPixmap(pixmapSize); | ||
newPm->setDevicePixelRatio(dpr()); | ||
#endif | ||
|
||
QPainter p; | ||
p.begin(newPm); | ||
|
||
if (!pm->isNull()) { | ||
newPm->fill(opt.palette.base().color()); | ||
p.drawPixmap(0, 0, *pm); | ||
} | ||
|
||
p.setPen(opt.palette.color(QPalette::WindowText)); | ||
p.setBrush(opt.palette.color(QPalette::Window)); | ||
p.setFont(opt.font); | ||
p.drawRect(ofs, 0, pw - 1, ph - 1); | ||
p.drawText(ofs + spacing, fm.ascent(), txt); | ||
p.setFont(opt.font); | ||
|
||
p.drawRect(offset, 0, text_width - 1, text_height - 1); | ||
p.drawText(offset + text_spacing, fm.ascent(), txt); | ||
p.end(); | ||
|
||
delete pm; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not need to be a private method on the class. It can very well be a local function and releave a tiny bit of the burden from the compiler.