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

Added magnifying hover effect #17

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
56 changes: 40 additions & 16 deletions gnarrator/windows.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from PyQt5.QtGui import QPainter, QPen, QBrush
from PyQt5.QtCore import Qt, QRect
import cv2
import cv2, math
from PyQt5.QtWidgets import (QMainWindow, QPushButton, QWidget, qApp)
from gnarrator.utils.utils import map_rgb_string_to_qcolor

Expand Down Expand Up @@ -149,6 +149,26 @@ def __init__(self, settings, mode):
self.border_width = 1.5
self.border_color = settings["border_color"]
self.border_radius = 3
self.original_border_widths = {}

self.original_style_sheet = (
f"QPushButton {{"
f"background-color: {self.bbox_color};"
f"border: {self.border_width}px solid {self.border_color};"
f"border-radius: {self.border_radius}px;"
f"}}"
f"QPushButton:hover {{"
f"background-color: {self.hover_color};"
f"}}"
)

self.magnified_style_sheet = self.original_style_sheet.replace(
f'border: {self.border_width}px',
f'border: {math.ceil(self.border_width * 3.5)}px'
).replace(
f'border-radius: {self.border_radius}px',
f'border-radius: {math.ceil(self.border_radius * 2)}px'
)

def set_window_opacity(self, opacity):
self.setWindowOpacity(opacity)
Expand Down Expand Up @@ -184,22 +204,26 @@ def create_button(self, coords : list):

def style_buttons(self):

# if theres only one button (small_n_quick mode):
# if theres only one button (small_n_quick mode) then set the propper style
if len(self.buttons) == 1:
self.bbox_color = self.hover_color

for button in self.buttons:
button.setStyleSheet(
f"QPushButton {{"
f"background-color: {self.bbox_color};"
f"border: {self.border_width}px solid {self.border_color};"
f"border-radius: {self.border_radius}px;"
f"}}"
f"QPushButton:hover {{"
f"background-color: {self.hover_color};"
f"}}"
)

# TODO: add hover color activated
self.buttons.pop().setStyleSheet(self.magnified_style_sheet)
else:
for button in self.buttons:
button.setStyleSheet(self.original_style_sheet)

# Store the original border width for each button
self.original_border_widths[button] = button.styleSheet()

# Connect hover events to the slot functions
button.enterEvent = lambda event, btn=button: self.onHoverEnter(btn)
button.leaveEvent = lambda event, btn=button: self.onHoverLeave(btn)

def onHoverEnter(self, button):
button.setStyleSheet(self.magnified_style_sheet)

def onHoverLeave(self, button):
button.setStyleSheet(self.original_border_widths[button])

def keyPressEvent(self, event):
if event.key() == Qt.Key_Escape:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setuptools.setup(
name='gnarrator',
version='1.1.210',
version='1.1.235',
python_requires='>=3.9.0',
author='Arnau Castelalno',
author_email='[email protected]',
Expand Down