change font size via mouse wheel

This commit is contained in:
2024-11-23 08:55:25 +01:00
parent 8cf02c8f6a
commit ddd377da7e

View File

@@ -9,7 +9,7 @@ from io import TextIOWrapper
from typing import List
from PySide6 import QtCore, QtGui
from PySide6.QtGui import QPaintEvent, QPainter, QFont, QFontMetrics, QColor, QBrush
from PySide6.QtGui import QPaintEvent, QPainter, QFont, QFontMetrics, QColor, QBrush, QWheelEvent
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QStatusBar
from PySide6.QtCore import QTimer, QPoint, Qt, QRect, QLine
import sys
@@ -245,6 +245,7 @@ class BiggerText(QWidget):
def __init__(self, ):
super(BiggerText, self).__init__()
self._font_size = 20
self.selection = Selection()
self.mouse_pressed = False
@@ -257,9 +258,8 @@ class BiggerText(QWidget):
# font = "ZedMono" # is not found
#font = "Noto Sans Mono"
font = "Noto Color Emoji"
font_size = 20
qfont = QFont(font, font_size)
qfont = QFont(font, self._font_size)
# qfont.setStyleHint(QFont.StyleHint.Monospace)
self.qfont = qfont
@@ -279,6 +279,15 @@ class BiggerText(QWidget):
#print(f"selection: {self.selection} -> {self.file_model.get_selection(self.selection.min_byte(), self.selection.max_byte())}")
self.update()
def wheelEvent(self, event: QWheelEvent):
direction = 1 if event.angleDelta().y() < 0 else -1
if event.modifiers() == Qt.KeyboardModifier.ControlModifier:
self._font_size = max(4, min(50, self._font_size - direction))
self.update()
else:
# print("wheel event fired :) %s" % (direction))
self.scroll_by_lines(direction * 3)
def to_byte_offset(self, pos: QPoint) -> SelectionPos:
line_number = self.y_pos_to_line_number_on_screen(pos.y())
@@ -322,7 +331,7 @@ class BiggerText(QWidget):
start_ns = time.process_time_ns()
painter = QPainter(self)
font = painter.font()
font.setPointSize(25)
font.setPointSize(self._font_size)
painter.setFont(font)
# ---