Skip to content
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

Fixed Whiteouts of Book Descriptions on Hover #1115

Merged
merged 5 commits into from
Jun 11, 2024

Conversation

ShaopengLin
Copy link
Collaborator

@ShaopengLin ShaopengLin commented May 22, 2024

Fix #1112

Changes:

  • For the description row, only use one column to span across.
  • DescriptionNode's data is now available on column index 0 instead of 1.
  • Added word wrap to previously unwrapped text
  • Prevented button actions from the last column to overflow into the description row.

Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

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

Whiteouts of book description have not been fixed - on the contrary, the name column was included in that undesirable behaviour.

On another note, this PR fixes several issues. Please extract each fix in a commit of its own.

src/contentmanagerdelegate.cpp Outdated Show resolved Hide resolved
src/contentmanagerview.cpp Outdated Show resolved Hide resolved
@ShaopengLin
Copy link
Collaborator Author

ShaopengLin commented May 22, 2024

Whiteouts of book description have not been fixed - on the contrary, the name column was included in that undesirable behaviour.

@veloman-yunkan I can't seem to reproduce what you mean in both 5.15.2 and 6.2.4.

@kelson42 does this fix work on your build?

@kelson42
Copy link
Collaborator

kelson42 commented May 23, 2024

@ShaopengLin In the future, please develop your PR in a feature branch in our repo (not in your fork). I didn't had the time to test your branch which somehow seems to be difficult to reconciliate with my (this repo) revision log.

@ShaopengLin
Copy link
Collaborator Author

I will try installing 5.12 a bit later and see if I can reproduce it. Will need to download it eventually since it seems compilation issues will continue to present themselves in the future (e.g. #1116) :).

@ShaopengLin
Copy link
Collaborator Author

Cannot seem to reproduce it either in 5.12. Will just wait for a response.

@veloman-yunkan
Copy link
Collaborator

Whiteouts of book description have not been fixed - on the contrary, the name column was included in that undesirable behaviour.

I double checked that it was not a result of an incorrect build:

Screencast.from.05-29-2024.05.44.02.PM.webm

I am using Ubuntu 22.04.

@kelson42
Copy link
Collaborator

kelson42 commented Jun 1, 2024

@ShaopengLin I have been able to reproduce this problem (with both Qt6 and Qt6) but I hard a had time. It's important to:

  • Deal with the very same ZIM files like in the screencast
  • Windows size should be the very same
  • After downloading, go once to "online" and then back "to offline"
  • Finally uncollapse and the bug should be there

@ShaopengLin ShaopengLin force-pushed the Issue#1112-fix-bookmark-description branch from f3cd032 to f7a71f2 Compare June 1, 2024 22:39
@ShaopengLin
Copy link
Collaborator Author

Confirmed fixed in all Qt5 and Qt6. The reason it isn't working is the press on the specific drop-down button will not count as a clicked event, thus our handler for the fix isn't called.

src/contentmanagerdelegate.cpp Outdated Show resolved Hide resolved
Comment on lines 256 to 243
if (lastColumnClicked)
/* The description row does not constitute as part of the open button. */
if (lastColumnClicked && !index.parent().isValid())
handleLastColumnClicked(index, e, option);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I fixed this same problem slightly differently in my so far WIP PR #1118. Do you think that an early return may have undesirable effects?

Copy link
Collaborator Author

@ShaopengLin ShaopengLin Jun 3, 2024

Choose a reason for hiding this comment

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

Users previously can open the book by middle clicking on the description section. An early return would then disable this feature.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@veloman-yunkan I believe fixing this your commit makes more sense. Your can do that check anytime after the middle button click check.

@ShaopengLin ShaopengLin force-pushed the Issue#1112-fix-bookmark-description branch from f7a71f2 to 2d62484 Compare June 5, 2024 03:29
Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

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

Great! The PR is so much better this way. Let's make it close to ideal and we will merge.

src/contentmanagermodel.cpp Outdated Show resolved Hide resolved
src/contentmanagerdelegate.cpp Outdated Show resolved Hide resolved
Comment on lines 288 to 304
if (index.parent().isValid())
{
auto view = KiwixApp::instance()->getContentManager()->getView()->getView();

/* Get the Rectangle from start of column1 to end of column 5. */
QRect r = view->visualRect(index.parent().siblingAtColumn(1));
QRect lastColRect = view->visualRect(index.parent().siblingAtColumn(5));
r.setWidth(lastColRect.x() + lastColRect.width() - r.x());

/* Based on the rectangle and text, find the best fitting size. */
QFontMetrics fm(option.font);
QSize textRectSize = fm
.boundingRect(r,
Qt::AlignLeft | Qt::AlignVCenter | Qt::TextWordWrap,
index.data().toString())
.size();

if (textRectSize.height() < 70)
textRectSize.setHeight(70);
return textRectSize;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, but it seems to slightly fall short of its goal:

Screenshot from 2024-06-06 13-49-50

@ShaopengLin ShaopengLin force-pushed the Issue#1112-fix-bookmark-description branch from 2d62484 to db53bb2 Compare June 7, 2024 06:24
src/contentmanagermodel.cpp Outdated Show resolved Hide resolved
src/descriptionnode.cpp Outdated Show resolved Hide resolved
Comment on lines 288 to 304
if (index.parent().isValid())
{
auto header = KiwixApp::instance()->getContentManager()->getView()->getView()->header();

/* Get the Rectangle from start of column1 to end of column 5. This is a
slight underestimate of the actual width, but it means we will produce
a proper height upper bound from boundingRect and the painting process
will span the width regardless of what we return in sizeHint.
*/
QRect descRect(0, 0, header->length() - header->sectionSize(0), 0);

/* Based on the rectangle and text, find the best fitting size. */
QFontMetrics fm(option.font);
const QString text = index.data().toString();
const auto format = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextWordWrap;
const QRect textRect = fm.boundingRect(descRect, format, text);
QSize textSize = textRect.size();

if (textSize.height() < 70)
textSize.setHeight(70);
return textSize;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This still doesn't work correctly

Screencast.from.06-07-2024.01.55.59.PM.webm

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe you have to account for some padding

Copy link
Collaborator Author

@ShaopengLin ShaopengLin Jun 7, 2024

Choose a reason for hiding this comment

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

Hmm either the header length or the boundingRect function is being inaccurate between systems. I will try to find an appropriate width for the height calculation.

@ShaopengLin ShaopengLin force-pushed the Issue#1112-fix-bookmark-description branch from db53bb2 to 21df619 Compare June 7, 2024 22:56
Comment on lines -89 to +92
if (index.isValid() && index.parent().isValid()) {
if (isDescriptionIndex(index)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does isDescriptionIndex() handle an invalid index correctly?

Copy link
Collaborator Author

@ShaopengLin ShaopengLin Jun 9, 2024

Choose a reason for hiding this comment

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

Yep, if the index is invalid, index.parent() will be invalid as well. Consequently, they have the same effect.

src/contentmanagermodel.cpp Outdated Show resolved Hide resolved
src/contentmanagerdelegate.cpp Outdated Show resolved Hide resolved
src/contentmanagerview.cpp Outdated Show resolved Hide resolved
@ShaopengLin ShaopengLin force-pushed the Issue#1112-fix-bookmark-description branch from 21df619 to aea74f6 Compare June 9, 2024 08:44
Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

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

LGTM

The branch must be rebased and the a conflict resolved. Then we will merge.

Handler is now a slot function instead of a lambda.
index.parent().isValid replaced with static function isDescriptionNode.
Clicking and hovering the description dropdown of zim no longer whites out. Replaced manual drawing with default handling as it is no longer necessary.
The description row height fits the text context when expanded.
Already expanded description row will now adjust with respect to any window size changes to fit the content.
@ShaopengLin ShaopengLin force-pushed the Issue#1112-fix-bookmark-description branch from aea74f6 to fa2d425 Compare June 11, 2024 18:51
@kelson42 kelson42 merged commit b59155a into kiwix:main Jun 11, 2024
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Book description misbehaves on hover
3 participants