"""
This module contains classes for managing various view controls in the application.
Classes:
- ControlViewRotate: Manages image rotation functionality and UI controls.
- ControlViewZoom: Manages image zoom functionality and UI controls.
"""
[docs]
class ControlViewZoom:
"""
Manages image zoom functionality and UI controls.
This class provides methods to handle zoom in, zoom out operations, and control the zooming level
displayed in the user interface.
Methods:
- __init__: Initializes the ControlViewZoom object.
- _connect_event: Connects UI events to corresponding methods.
- _onclick_zoom: Handles zoom in/out operations.
- _control_change_zooming: Controls the change of zooming in the displayed image.
- show_percentage_zoom: Displays the percentage of the current zoom level in the zoom spin box.
"""
def __init__(self, controller):
self._controller = controller
self._model = controller.model
self._ui_object = controller.ui_object
self._connect_event()
def _connect_event(self):
self._ui_object.zoom_in_button.clicked.connect(lambda: self._onclick_zoom("zoom_in"))
self._ui_object.zoom_in_button.setShortcut("=")
self._ui_object.zoom_out_button.clicked.connect(lambda: self._onclick_zoom("zoom_out"))
self._ui_object.zoom_out_button.setShortcut("-")
self._ui_object.spinBox_zooming.valueChanged.connect(self._control_change_zooming)
def _onclick_zoom(self, operation):
"""
Handles zoom in/out operations.
Arg:
operation (str): The zoom operation, either "zoom_in" or "zoom_out".
"""
if self._model.debug_mode:
self._model.activity_logger.info("ControlViewZoom: _onclick_zoom(), "
f"Click to change zoom to {operation}")
if self._model.image_original is not None:
if operation == "zoom_in":
self._controller.model.view_properties.zoom_in()
else:
self._controller.model.view_properties.zoom_out()
self.show_percentage_zoom()
self._controller.display_image_to_ui()
def _control_change_zooming(self):
"""
Control the change of zooming in the displayed image.
Update the displayed image's width according to
the zoom level set by the user through the spinBox_zooming input. The updated width is chosen from a
predefined list of possible values to ensure the closest match to the desired width.
"""
if self._model.debug_mode:
self._model.activity_logger.info("ControlViewZoom: _control_change_zooming(), "
"Click to change zoom base on spinBox_zooming user interface")
width = self._model.image_original.shape[1]
value = width * (self._ui_object.spinBox_zooming.value() / 100)
self._model.view_properties.percentage_zoom(value)
self._controller.display_image_to_ui()
[docs]
def show_percentage_zoom(self):
"""
Display the percentage of the current zoom level in the zoom spin box.
Calculate the percentage of the current width of the image result with respect to the original width of
the input image, and sets the value of the zoom spin box to this percentage.
Return:
None
"""
if self._model.debug_mode:
self._model.activity_logger.info("ControlViewZoom: show_percentage_zoom(), "
"Show percentage zoom to user interface")
if self._model.image_original is not None:
self._ui_object.spinBox_zooming.setEnabled(True)
value = round((self._model.view_properties.zooming_size / self._model.image_original.shape[1]) * 100)
self._ui_object.spinBox_zooming.blockSignals(True)
self._ui_object.spinBox_zooming.setValue(value)
self._ui_object.spinBox_zooming.blockSignals(False)
else:
self._ui_object.spinBox_zooming.setEnabled(False)