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

Show link on hover #634

Merged
merged 8 commits into from
Apr 9, 2024
Merged

Conversation

red-kite
Copy link
Contributor

@red-kite red-kite commented Oct 4, 2023

Please:

  • check that I'm doing right with super().__init__(parent)
  • verify and change positions of inserted code
  • eventually .setText('') additional to setVisible(False)
  • maybe test it :-)
  • …?

Thank you for creating and maintaining ReText!

red-kite added 3 commits September 30, 2023 22:09
- Catch QWebEnginePage's Signal linkHovered(url:str)
- Show hide url with statusbar

Preliminary implementation using QMainWindow.statusBar()
Implementation as urlPopup(QLabel) added to ReTextWindow

Known Issue: For links at the very bottom of the screen (footer) the
popup covers the link and thus prevents hovering long enough to read.

TODO: maybe find better place for 'self.urlPopup = ...' in window.py
ReText/dialogs.py Outdated Show resolved Hide resolved
ReText/dialogs.py Outdated Show resolved Hide resolved
ReText/window.py Outdated Show resolved Hide resolved
Revert changes to window.py and dialogs.py
@mitya57
Copy link
Member

mitya57 commented Oct 7, 2023

It does not look nice with dark themes:
Screenshot

I recommend that you take colors from QPalette where possible, rather than hard-coding them. If QPalette doesn't have the needed colors, please define both light and dark versions, you can add them after this line:

'whitespaceOnEnd': {'light': '#80e1e1a5', 'dark': '#8096966e'},

ReText/webenginepreview.py Outdated Show resolved Hide resolved
Avoid detour via method only routing a str.

Possible longer docstring for UrlPopup:
""" Show link target on mouse hover

QWebEnginePage emits signal 'linkHovered' which provides
url: str -- target of link hovered (or empty on mouse-release)
"""
@mitya57
Copy link
Member

mitya57 commented Oct 15, 2023

So the only thing remaining is my comment about dark themes.

untestet in dark-mode
@red-kite
Copy link
Contributor Author

red-kite commented Apr 1, 2024

Please excuse being that quiet on this for so long.
Thank you @mitya57 for guiding towards the solution via QPalette or hardcoded colors. I'd prefer latter for decent appearance with soft border and very little transparency (finetuning possible)
…but ran into issues:

  • Figure out how to access editor's colors-dictionary (Use example in highlighter.py: from ReText.editor import getColor)
  • Use QColor in stylesheet of UrlPopup ('QColor' has no attribute 'HexArgb') -- Got a solution, a more elegant might exist.
  • Major: I can't test dark-mode (because I don't use such). I tried (again) in a gnome shell but only window decoration gets dark (stylesheet disabled)

Thanks to motivation by @donjan I tried some more and pushed 8935a93 for further use…

-> Help appreciated


Some alternative code (palette usage found on the internet last year, no alpha):

        self.setStyleSheet('''
            border: 1px solid palette(mid);
            border-radius: 3px;
            background: palette(base);
        ''')

Resources:

https://stackoverflow.com/a/2756376 suggests ("not to use the palette and go for Qt Style Sheet")
https://stackoverflow.com/a/6876509 (long struggle to convert QColor to HexArgb!)

Copy link
Member

@mitya57 mitya57 left a comment

Choose a reason for hiding this comment

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

Thank you very much. Can I ask you for a couple more things?

ReText/editor.py Outdated
@@ -52,6 +52,8 @@
'restDirectives': {'light': '#800080', 'dark': '#d070d0'},
'restRoles': {'light': '#800000', 'dark': '#d07070'},
'whitespaceOnEnd': {'light': '#80e1e1a5', 'dark': '#8096966e'},
'UrlPopup': {'light': '#fafafafa', 'dark': '#fa323232'},
'UrlPopupBorder': {'light': '#64323232', 'dark': '#64fafafa'}
Copy link
Member

Choose a reason for hiding this comment

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

Please start a new section (add # Preview header). Also, please start the keys with a lower-case letter for consistency (url, not Url).

Also, please put a trailing comma at the end.

self.window = window

def hex_rgba(color):
''' color:QColor '''
Copy link
Member

Choose a reason for hiding this comment

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

Can this be made a static method or a top-level function?
This way we will have only one instance of this function for all labels.

Also, you can import QColor and use native type annotation (color: QColor).

red-kite added 2 commits April 6, 2024 00:11
- colors:

    Add #Preview section'
    Rename UrlPopup -> urlPopupArea (consistent with other 'Areas')

- import QColor (native type annotation)

- make function hex_rgba(color: QColor) toplevel

    Tested: id(hex_rgba) always identical object with or without `@staticmethod`

- raise UrlPopup text by 1px
   (especially letter '_' was very close to window border)
function returns str: 'rgba(...)'
@red-kite
Copy link
Contributor Author

red-kite commented Apr 5, 2024

see commit msg, note that dark-mode still not tested by me

unsure about position of hex_rgba() in file -- kept it close to it's class

(to-string-conversion of QColor could be part of getColor(colorName, rgba=False) but I don't like this because function gets blown up for other use)

@mitya57 mitya57 merged commit 6941d00 into retext-project:master Apr 9, 2024
8 checks passed
@mitya57
Copy link
Member

mitya57 commented Apr 9, 2024

Thank you!

Tested with dark theme (QT_STYLE_OVERRIDE=Adwaita-Dark), it looks good!

Screenshot with Adwaita-Dark

Although, the transparency is barely visible, so maybe it's an overcomplication and using the palette color would be enough. But as you already implemented it this way, I did not change.

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.

2 participants