-
-
Notifications
You must be signed in to change notification settings - Fork 380
Fix note list rendering at fractional display scaling #769
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,11 +135,11 @@ NoteListDelegateEditor::~NoteListDelegateEditor() | |
| void NoteListDelegateEditor::paintBackground(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
| { | ||
| auto bufferSize = rect().size(); | ||
| QPixmap buffer{ bufferSize }; | ||
| QPixmap buffer = utils::makeDevicePixelRatioPixmap(bufferSize, this); | ||
|
Owner
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. Same coordinate-space issue here: the buffer is now DPR-aware, but the later source rect passed to auto rowHeight = rect().height();
const QRect sourceRect{ 0, bufferSize.height() - rowHeight, rect().width(), rowHeight };
painter->drawPixmap(rect(), buffer, utils::devicePixelRatioPixmapSourceRect(sourceRect, buffer)); |
||
| buffer.fill(Qt::transparent); | ||
| QPainter bufferPainter{ &buffer }; | ||
| bufferPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); | ||
| QRect bufferRect = buffer.rect(); | ||
| QRect bufferRect{ QPoint{ }, bufferSize }; | ||
| auto const *noteListModel = static_cast<NoteListModel *>(m_view->model()); | ||
| if (noteListModel->hasPinnedNote() && (noteListModel->isFirstPinnedNote(index) || noteListModel->isFirstUnpinnedNote(index))) { | ||
| int fifthYOffset = 0; | ||
|
|
@@ -375,7 +375,7 @@ bool NoteListDelegateEditor::underMouseC() const | |
|
|
||
| QPixmap NoteListDelegateEditor::renderToPixmap() | ||
| { | ||
| QPixmap result{ rect().size() }; | ||
| QPixmap result = utils::makeDevicePixelRatioPixmap(rect().size(), this); | ||
| result.fill(Qt::yellow); | ||
| QPainter painter(&result); | ||
| painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,13 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| #pragma once | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| #include <QGuiApplication> | ||||||||||||||||||||||||||||||||||||||||||||
| #include <cmath> | ||||||||||||||||||||||||||||||||||||||||||||
| #include <QString> | ||||||||||||||||||||||||||||||||||||||||||||
| #include <QDateTime> | ||||||||||||||||||||||||||||||||||||||||||||
| #include <QPixmap> | ||||||||||||||||||||||||||||||||||||||||||||
|
Owner
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. This helper will also need
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| #include <QScreen> | ||||||||||||||||||||||||||||||||||||||||||||
| #include <QString> | ||||||||||||||||||||||||||||||||||||||||||||
| #include <QWidget> | ||||||||||||||||||||||||||||||||||||||||||||
| #include <QWindow> | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| namespace utils { | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -44,4 +49,29 @@ inline QString parseDateTime(const QDateTime &dateTime) | |||||||||||||||||||||||||||||||||||||||||||
| return dateTime.date().toString("M/d/yy"); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| } // namespace utils | ||||||||||||||||||||||||||||||||||||||||||||
| inline qreal devicePixelRatioForWidget(const QWidget *widget) | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| if (widget != nullptr) { | ||||||||||||||||||||||||||||||||||||||||||||
| if (auto *topLevelWindow = widget->window(); (topLevelWindow != nullptr) && (topLevelWindow->windowHandle() != nullptr)) { | ||||||||||||||||||||||||||||||||||||||||||||
| return topLevelWindow->windowHandle()->devicePixelRatio(); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| return widget->devicePixelRatioF(); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if (auto *screen = QGuiApplication::primaryScreen(); screen != nullptr) { | ||||||||||||||||||||||||||||||||||||||||||||
| return screen->devicePixelRatio(); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| return qreal(1); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| inline QPixmap makeDevicePixelRatioPixmap(const QSize &logicalSize, const QWidget *widget) | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| const qreal scale = devicePixelRatioForWidget(widget); | ||||||||||||||||||||||||||||||||||||||||||||
| QPixmap pixmap(logicalSize * scale); | ||||||||||||||||||||||||||||||||||||||||||||
| pixmap.setDevicePixelRatio(scale); | ||||||||||||||||||||||||||||||||||||||||||||
| return pixmap; | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+69
to
+75
Owner
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. Could we pair the DPR pixmap allocator with a small source-rect conversion helper? Painting into the pixmap stays in logical coordinates, but
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| } // namespace utils | ||||||||||||||||||||||||||||||||||||||||||||
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.
Once this buffer is DPR-aware, the
drawPixmap(..., buffer, QRect{...})calls lower inpaintBackground()still need to convert their source rects before drawing. One compact way is to add this near the draw section and route those calls through it:Then replace each
painter->drawPixmap(..., buffer, QRect{...})in this function withdrawBuffer(..., QRect{...}). The same pattern applies to the animated label buffer inpaintLabels().