Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/notelistdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ NoteListDelegate::NoteListDelegate(NoteListView *view, TagPool *tagPool, QObject
});
}

int NoteListDelegate::minimumContentHeight() const
{
const int titleHeight = qMax(QFontMetrics(m_titleFont).height(), QFontMetrics(m_titleSelectedFont).height());
const int dateHeight = QFontMetrics(m_dateFont).height();
const int contentHeight = titleHeight;

return note_list_constants::TOP_OFFSET_Y + titleHeight + dateHeight + contentHeight + note_list_constants::DATE_DESC_SPACE;
}

int NoteListDelegate::minimumRowHeight(bool isInAllNotes) const
{
int result = minimumContentHeight() + note_list_constants::LAST_EL_SEP_SPACE;
if (isInAllNotes) {
Comment thread
zjeffer marked this conversation as resolved.
Outdated
const int folderLineHeight = qMax(QFontMetrics(m_titleFont).height(), 16) + note_list_constants::DESC_FOLDER_SPACE;
result += folderLineHeight;
}
return result;
}

void NoteListDelegate::setState(NoteListState NewState, QModelIndexList indexes)
{
if (animationState() != QTimeLine::NotRunning) {
Expand Down Expand Up @@ -224,11 +243,13 @@ QSize NoteListDelegate::sizeHint(const QStyleOptionViewItem &option, const QMode
}

int yOffsets = secondYOffset + thirdYOffset + fourthYOffset + fifthYOffset;
const int minimumHeight = minimumRowHeight(m_isInAllNotes) + yOffsets;
if (m_isInAllNotes) {
result.setHeight(result.height() - 2 + note_list_constants::LAST_EL_SEP_SPACE + yOffsets);
} else {
result.setHeight(result.height() - 10 + note_list_constants::LAST_EL_SEP_SPACE + yOffsets);
}
result.setHeight(qMax(result.height(), minimumHeight));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clamp also runs for animated rows. In the animated branch above, result.height() is intentionally scaled by the timeline so insert/remove/move rows can grow or collapse, but the final qMax(..., minimumHeight) raises it back to at least the full minimum height.

Suggested fix: only apply the minimum-height floor when the row is not in m_animatedIndexes, or clamp the target row height before applying the timeline rate.

How to test: create, delete, pin, or unpin a note and watch the affected row. It should smoothly grow/collapse. You can also log result.height() near currentFrame == 0: it is computed near zero, then raised again by this qMax.

return result;
}

Expand Down Expand Up @@ -278,11 +299,13 @@ QSize NoteListDelegate::bufferSizeHint(const QStyleOptionViewItem &option, const
}

int yOffsets = secondYOffset + thirdYOffset + fourthYOffset;
const int minimumHeight = minimumRowHeight(m_isInAllNotes) + yOffsets;
if (m_isInAllNotes) {
result.setHeight(result.height() - 2 + note_list_constants::LAST_EL_SEP_SPACE + yOffsets);
} else {
result.setHeight(result.height() - 10 + note_list_constants::LAST_EL_SEP_SPACE + yOffsets);
}
result.setHeight(qMax(result.height(), minimumHeight));
return result;
}

Expand Down
2 changes: 2 additions & 0 deletions src/notelistdelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public slots:
void animationFinished(NoteListState animationState);

private:
int minimumContentHeight() const;
int minimumRowHeight(bool isInAllNotes) const;
void paintBackground(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void paintLabels(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void paintSeparator(QPainter *painter, QRect rect, const QModelIndex &index) const;
Expand Down
131 changes: 48 additions & 83 deletions src/notelistdelegateeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,49 +71,7 @@ NoteListDelegateEditor::NoteListDelegateEditor(const NoteListDelegate *delegate,
m_tagListView->setItemDelegate(m_tagListDelegate);
m_tagListModel->setTagPool(tagPool);
m_tagListModel->setModelData(index.data(NoteListModel::NoteTagsList).value<QSet<int>>());
if (m_delegate->isInAllNotes()) {
int y = 90;
auto const *noteListModel = static_cast<NoteListModel *>(m_view->model());
if (noteListModel != nullptr) {
auto idx = noteListModel->getNoteIndex(m_id);
if (noteListModel->hasPinnedNote() && (noteListModel->isFirstPinnedNote(idx) || noteListModel->isFirstUnpinnedNote(idx))) {
y += 25;
}
}
int fourthYOffset = 0;
if ((noteListModel != nullptr) && noteListModel->isFirstUnpinnedNote(index)) {
fourthYOffset = note_list_constants::UNPINNED_HEADER_TO_NOTE_SPACE;
}
int fifthYOffset = 0;
if ((noteListModel != nullptr) && noteListModel->hasPinnedNote() && !m_view->isPinnedNotesCollapsed() && noteListModel->isFirstUnpinnedNote(index)) {
fifthYOffset = note_list_constants::LAST_PINNED_TO_UNPINNED_HEADER;
}
int yOffsets = fourthYOffset + fifthYOffset;

y += yOffsets;
m_tagListView->setGeometry(10, y - 5, rect().width() - 15, m_tagListView->height());
} else {
int y = 70;
auto const *noteListModel = static_cast<NoteListModel *>(m_view->model());
if (noteListModel != nullptr) {
auto idx = noteListModel->getNoteIndex(m_id);
if (noteListModel->hasPinnedNote() && (noteListModel->isFirstPinnedNote(idx) || noteListModel->isFirstUnpinnedNote(idx))) {
y += 25;
}
}
int fourthYOffset = 0;
if ((noteListModel != nullptr) && noteListModel->isFirstUnpinnedNote(index)) {
fourthYOffset = note_list_constants::UNPINNED_HEADER_TO_NOTE_SPACE;
}
int fifthYOffset = 0;
if ((noteListModel != nullptr) && noteListModel->hasPinnedNote() && !m_view->isPinnedNotesCollapsed() && noteListModel->isFirstUnpinnedNote(index)) {
fifthYOffset = note_list_constants::LAST_PINNED_TO_UNPINNED_HEADER;
}
int yOffsets = fourthYOffset + fifthYOffset;

y += yOffsets;
m_tagListView->setGeometry(10, y - 5, rect().width() - 15, m_tagListView->height());
}
m_tagListView->setGeometry(10, tagListTop(index) - 5, rect().width() - 15, m_tagListView->height());
connect(m_tagListView->verticalScrollBar(), &QScrollBar::valueChanged, this, [this] {
auto idx = static_cast<NoteListModel *>(m_view->model())->getNoteIndex(m_id);
static_cast<NoteListModel *>(m_view->model())->setData(idx, getScrollBarPos(), NoteListModel::NoteTagListScrollbarPos);
Expand All @@ -127,6 +85,49 @@ NoteListDelegateEditor::NoteListDelegateEditor(const NoteListDelegate *delegate,
setAcceptDrops(true);
}

int NoteListDelegateEditor::minimumContentHeight() const
{
const int titleHeight = qMax(QFontMetrics(m_titleFont).height(), QFontMetrics(m_titleSelectedFont).height());
const int dateHeight = QFontMetrics(m_dateFont).height();
const int contentHeight = titleHeight;

return note_list_constants::TOP_OFFSET_Y + titleHeight + dateHeight + contentHeight + note_list_constants::DATE_DESC_SPACE;
}

int NoteListDelegateEditor::minimumRowHeight() const
{
int result = minimumContentHeight() + note_list_constants::LAST_EL_SEP_SPACE;
if (m_delegate->isInAllNotes()) {
const int folderLineHeight = qMax(QFontMetrics(m_titleFont).height(), 16) + note_list_constants::DESC_FOLDER_SPACE;
result += folderLineHeight;
}
return result;
}

int NoteListDelegateEditor::tagListTop(const QModelIndex &index) const
{
int top = minimumContentHeight();
if (m_delegate->isInAllNotes()) {
top += qMax(QFontMetrics(m_titleFont).height(), 16) + note_list_constants::DESC_FOLDER_SPACE;
}

auto const *noteListModel = static_cast<NoteListModel *>(m_view->model());
if (noteListModel != nullptr) {
auto idx = noteListModel->getNoteIndex(m_id);
if (noteListModel->hasPinnedNote() && (noteListModel->isFirstPinnedNote(idx) || noteListModel->isFirstUnpinnedNote(idx))) {
top += 25;
}
if (noteListModel->isFirstUnpinnedNote(index)) {
top += note_list_constants::UNPINNED_HEADER_TO_NOTE_SPACE;
}
if (noteListModel->hasPinnedNote() && !m_view->isPinnedNotesCollapsed() && noteListModel->isFirstUnpinnedNote(index)) {
top += note_list_constants::LAST_PINNED_TO_UNPINNED_HEADER;
}
}

return top;
}

NoteListDelegateEditor::~NoteListDelegateEditor()
{
m_view->unsetEditorWidget(m_id, nullptr);
Expand Down Expand Up @@ -402,46 +403,9 @@ void NoteListDelegateEditor::paintEvent(QPaintEvent *event)
void NoteListDelegateEditor::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
if (m_delegate->isInAllNotes()) {
int y = 90;
auto const *noteListModel = static_cast<NoteListModel *>(m_view->model());
auto const idx = noteListModel->getNoteIndex(m_id);
if (noteListModel->hasPinnedNote() && (noteListModel->isFirstPinnedNote(idx) || noteListModel->isFirstUnpinnedNote(idx))) {
y += 25;
}
int fourthYOffset = 0;
if (noteListModel->isFirstUnpinnedNote(idx)) {
fourthYOffset = note_list_constants::UNPINNED_HEADER_TO_NOTE_SPACE;
}
int fifthYOffset = 0;
if (noteListModel->hasPinnedNote() && !m_view->isPinnedNotesCollapsed() && noteListModel->isFirstUnpinnedNote(idx)) {
fifthYOffset = note_list_constants::LAST_PINNED_TO_UNPINNED_HEADER;
}
int yOffsets = fourthYOffset + fifthYOffset;
y += yOffsets;

m_tagListView->setGeometry(note_list_constants::LEFT_OFFSET_X - 5, y + 5, rect().width() - 15, m_tagListView->height());
} else {
int y = 70;
auto const *noteListModel = static_cast<NoteListModel *>(m_view->model());
auto const idx = noteListModel->getNoteIndex(m_id);
if (noteListModel->hasPinnedNote() && (noteListModel->isFirstPinnedNote(idx) || noteListModel->isFirstUnpinnedNote(idx))) {
y += 25;
}
int fourthYOffset = 0;
if (noteListModel->isFirstUnpinnedNote(idx)) {
fourthYOffset = note_list_constants::UNPINNED_HEADER_TO_NOTE_SPACE;
}
int fifthYOffset = 0;
if (noteListModel->hasPinnedNote() && !m_view->isPinnedNotesCollapsed() && noteListModel->isFirstUnpinnedNote(idx)) {
fifthYOffset = note_list_constants::LAST_PINNED_TO_UNPINNED_HEADER;
}
int yOffsets = fourthYOffset + fifthYOffset;

y += yOffsets;

m_tagListView->setGeometry(note_list_constants::LEFT_OFFSET_X - 5, y, rect().width() - 15, m_tagListView->height());
}
auto const *noteListModel = static_cast<NoteListModel *>(m_view->model());
auto const idx = noteListModel->getNoteIndex(m_id);
m_tagListView->setGeometry(note_list_constants::LEFT_OFFSET_X - 5, tagListTop(idx), rect().width() - 15, m_tagListView->height());
recalculateSize();
}

Expand Down Expand Up @@ -536,6 +500,7 @@ void NoteListDelegateEditor::recalculateSize()
} else {
result.setHeight(result.height() - 10 + note_list_constants::LAST_EL_SEP_SPACE + yOffsets);
}
result.setHeight(qMax(result.height(), minimumRowHeight() + m_tagListView->height() + 2 + yOffsets));
emit updateSizeHint(m_id, result, idx);
}

Expand Down
3 changes: 3 additions & 0 deletions src/notelistdelegateeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public slots:
void nearDestroyed(int id, const QModelIndex &index);

private:
int minimumContentHeight() const;
int minimumRowHeight() const;
int tagListTop(const QModelIndex &index) const;
void paintBackground(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void paintLabels(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void paintSeparator(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
Expand Down
Loading