Skip to content

Commit

Permalink
Fixed a bug with change text direction using keyboard.
Browse files Browse the repository at this point in the history
  • Loading branch information
QaisAlrefai committed Dec 13, 2024
1 parent b72b433 commit 773c7aa
Showing 1 changed file with 13 additions and 39 deletions.
52 changes: 13 additions & 39 deletions ui/widgets/qText_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,73 +44,47 @@ def set_ctrl(self):
self.parent.menu_bar.copy_verse_action.setEnabled(status)

def keyPressEvent(self, e):
super().keyPressEvent(e)
self.set_ctrl()

# Space Key Handling (Play/Pause or Stop Audio)
if e.key() == Qt.Key.Key_Space:
if e.modifiers() & Qt.KeyboardModifier.ControlModifier: # Ctrl + Space
if hasattr(self.parent.toolbar, "stop_audio"):
self.parent.toolbar.stop_audio()
e.accept() # Block the event (no space inserted)
return
elif e.modifiers() & Qt.KeyboardModifier.ShiftModifier: # Shift + Space
if hasattr(self.parent.toolbar, "toggle_play_pause"):
self.parent.toolbar.toggle_play_pause()
e.accept() # Block the event (no space inserted)
self.parent.toolbar.stop_audio()
return
else: # Space without modifiers (default case)
if hasattr(self.parent.toolbar, "toggle_play_pause"):
self.parent.toolbar.toggle_play_pause()
e.accept() # Block the event (no space inserted)
elif e.modifiers() & Qt.KeyboardModifier.ShiftModifier:
self.parent.toolbar.toggle_play_pause()
return
else:
self.parent.toolbar.toggle_play_pause()
return

# Shift Key with Modifiers Handling (Left/Right Shift)
if e.modifiers() & Qt.KeyboardModifier.ShiftModifier:
if e.modifiers() & Qt.KeyboardModifier.ControlModifier:
if e.key() == Qt.Key.Key_Shift:
if e.nativeScanCode() == 42: # Scan code for Left Shift
self.parent.menu_bar.set_text_direction_ltr()
e.accept() # Block the event
return
elif e.nativeScanCode() == 54: # Scan code for Right Shift
elif e.nativeScanCode() == 54: # Scan code for Right Shift
self.parent.menu_bar.set_text_direction_rtl()
e.accept() # Block the event
return

# Auto Page Turn Feature
if not SettingsManager.current_settings["reading"]["auto_page_turn"]:
super().keyPressEvent(e) # Call default implementation for unhandled keys
return

current_line = self.textCursor().block().blockNumber()
total_lines = self.document().blockCount()

# Reset page-turn alert flag if not at the first or last line

if current_line >= 1 and current_line + 1 != total_lines:
self.is_page_turn_alert = False

# Handle Up Key
if e.key() == Qt.Key.Key_Up:
if current_line == 0 and self.parent.quran.current_pos > 1:
if (current_line == 0) and (self.parent.quran.current_pos > 1):
if not self.is_page_turn_alert:
self.is_page_turn_alert = True
Globals.effects_manager.play("alert")
e.accept() # Block the event
return
self.parent.OnBack(is_auto_call=True)
e.accept() # Block the event
return

# Handle Down Key
elif e.key() == Qt.Key.Key_Down:
if current_line == total_lines - 1 and self.parent.quran.current_pos < self.parent.quran.max_pos:
if (current_line == total_lines - 1) and (self.parent.quran.current_pos < self.parent.quran.max_pos):
if not self.is_page_turn_alert:
self.is_page_turn_alert = True
Globals.effects_manager.play("alert")
e.accept() # Block the event
return
self.parent.OnNext()
e.accept() # Block the event
return

# Call default implementation for unhandled keys
super().keyPressEvent(e)
self.parent.OnNext()

0 comments on commit 773c7aa

Please sign in to comment.