Skip to content

Commit

Permalink
Merge pull request #782 from kartoza/timlinux/issue781
Browse files Browse the repository at this point in the history
Scale font size based on panel resolution
  • Loading branch information
timlinux authored Jan 17, 2025
2 parents caae913 + a367dac commit fdac68e
Show file tree
Hide file tree
Showing 16 changed files with 666 additions and 511 deletions.
22 changes: 16 additions & 6 deletions geest/gui/geest_dock.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,24 @@ def on_panel_changed(self, index: int) -> None:
:param index: The index of the newly selected panel.
"""
if index == 0:
if index == INTRO_PANEL:
log_message("Switched to Intro panel")
if index == 1:
self.intro_widget.set_font_size()
elif index == CREDITS_PANEL:
log_message("Switched to Credits panel")
self.credits_widget.set_font_size()
elif index == SETUP_PANEL:
log_message("Switched to Setup panel")
elif index == ORS_PANEL:
self.ors_widget.set_font_size()
log_message("Switched to ORS panel")
elif index == 2:
log_message("Switched to Project panel")
elif index == 3:
elif index == OPEN_PROJECT_PANEL:
log_message("Switched to Open Project panel")
elif index == CREATE_PROJECT_PANEL:
self.create_project_widget.set_font_size()
log_message("Switched to Create Project panel")
elif index == TREE_PANEL:
log_message("Switched to Tree panel")
# self.tree_widget.set_working_directory(self.setup_widget.working_dir)
elif index == 4:
elif index == HELP_PANEL:
log_message("Switched to Help panel")
28 changes: 25 additions & 3 deletions geest/gui/panels/create_project_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
)

from qgis.PyQt.QtCore import QSettings, pyqtSignal
from qgis.PyQt.QtGui import QPixmap
from geest.core.tasks import StudyAreaProcessingTask, OrsCheckerTask
from geest.utilities import get_ui_class, resources_path
from qgis.PyQt.QtGui import QPixmap, QFont
from geest.core.tasks import StudyAreaProcessingTask
from geest.utilities import get_ui_class, resources_path, linear_interpolation
from geest.core import WorkflowQueueManager
from geest.utilities import log_message
from geest.gui.widgets import CustomBannerLabel
Expand Down Expand Up @@ -234,3 +234,25 @@ def update_recent_projects(self, directory):

# Save back to QSettings
self.settings.setValue("recent_projects", recent_projects)

def resizeEvent(self, event):
self.set_font_size()
super().resizeEvent(event)

def set_font_size(self):
# Scale the font size to fit the text in the available space
log_message(f"Description Label Width: {self.description.rect().width()}")
# scale the font size linearly from 16 pt to 8 ps as the width of the panel decreases
font_size = int(
linear_interpolation(self.description.rect().width(), 12, 16, 400, 600)
)

log_message(f"Description Label Font Size: {font_size}")
self.description.setFont(QFont("Arial", font_size))
self.description2.setFont(QFont("Arial", font_size))
self.description3.setFont(QFont("Arial", font_size))
self.create_project_directory_button.setFont(QFont("Arial", font_size))
self.load_boundary_button.setFont(QFont("Arial", font_size))
self.cell_size_spinbox.setFont(QFont("Arial", font_size))
self.layer_combo.setFont(QFont("Arial", font_size))
self.field_combo.setFont(QFont("Arial", font_size))
32 changes: 28 additions & 4 deletions geest/gui/panels/credits_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
from qgis.core import Qgis

from qgis.PyQt.QtCore import QUrl, pyqtSignal
from qgis.PyQt.QtGui import QPixmap, QDesktopServices
from geest.core.tasks import OrsCheckerTask
from geest.utilities import get_ui_class, resources_path, log_message
from qgis.PyQt.QtGui import QFont, QDesktopServices
from geest.utilities import (
get_ui_class,
resources_path,
log_message,
linear_interpolation,
)
from geest.gui.widgets import CustomBannerLabel

FORM_CLASS = get_ui_class("credits_panel_base.ui")
Expand All @@ -21,7 +25,7 @@ def __init__(self):
self.setWindowTitle("GEEST")
# Dynamically load the .ui file
self.setupUi(self)
log_message(f"Loading intro panel")
log_message(f"Loading Credits panel")
self.initUI()

def initUI(self):
Expand All @@ -37,6 +41,7 @@ def initUI(self):
self.next_button.clicked.connect(self.on_next_button_clicked)
self.previous_button.clicked.connect(self.on_previous_button_clicked)
self.description.linkActivated.connect(self.open_link_in_browser)
self.set_font_size()

def on_next_button_clicked(self):
self.switch_to_next_tab.emit()
Expand All @@ -47,3 +52,22 @@ def on_previous_button_clicked(self):
def open_link_in_browser(self, url: str):
"""Open the given URL in the user's default web browser using QDesktopServices."""
QDesktopServices.openUrl(QUrl(url))

def repaint(self):
self.set_font_size()
super().repaint()

def resizeEvent(self, event):
self.set_font_size()
super().resizeEvent(event)

def set_font_size(self):
# Scale the font size to fit the text in the available space
log_message(f"Label Width: {self.description.rect().width()}")
# scale the font size linearly from 16 pt to 8 ps as the width of the panel decreases
font_size = int(
linear_interpolation(self.description.rect().width(), 12, 16, 400, 600)
)
log_message(f"Label Font Size: {font_size}")
self.description.setFont(QFont("Arial", font_size))
self.description.repaint()
27 changes: 23 additions & 4 deletions geest/gui/panels/intro_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
from qgis.core import Qgis

from qgis.PyQt.QtCore import pyqtSignal
from qgis.PyQt.QtGui import QPixmap
from qgis.PyQt.QtGui import QFont
from geest.core.tasks import OrsCheckerTask
from geest.utilities import get_ui_class, resources_path
from geest.utilities import log_message
from geest.utilities import (
get_ui_class,
resources_path,
log_message,
linear_interpolation,
)
from geest.gui.widgets import CustomBannerLabel

FORM_CLASS = get_ui_class("intro_panel_base.ui")
Expand All @@ -34,8 +38,23 @@ def initUI(self):
parent_layout.replaceWidget(self.banner_label, self.custom_label)
self.banner_label.deleteLater()
parent_layout.update()

self.next_button.clicked.connect(self.on_next_button_clicked)
self.set_font_size()

def on_next_button_clicked(self):
self.switch_to_next_tab.emit()

def resizeEvent(self, event):
self.set_font_size()
super().resizeEvent(event)

def set_font_size(self):
# Scale the font size to fit the text in the available space
log_message(f"Intro Label Width: {self.intro_label.rect().width()}")
# scale the font size linearly from 16 pt to 8 ps as the width of the panel decreases
font_size = int(
linear_interpolation(self.intro_label.rect().width(), 12, 16, 400, 600)
)

log_message(f"Intro Label Font Size: {font_size}")
self.intro_label.setFont(QFont("Arial", font_size))
18 changes: 16 additions & 2 deletions geest/gui/panels/open_project_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
Qgis,
)
from qgis.PyQt.QtCore import QSettings, pyqtSignal
from qgis.PyQt.QtGui import QPixmap
from geest.utilities import get_ui_class, resources_path
from qgis.PyQt.QtGui import QFont
from geest.utilities import get_ui_class, resources_path, linear_interpolation
from geest.core import WorkflowQueueManager
from geest.utilities import log_message
from geest.gui.widgets import CustomBannerLabel
Expand Down Expand Up @@ -158,3 +158,17 @@ def load_project(self, working_directory=None):
# QMessageBox.critical(
# self, "Error", "Selected project does not contain a model.json file."
# )

def resizeEvent(self, event):
self.set_font_size()
super().resizeEvent(event)

def set_font_size(self):
# Scale the font size to fit the text in the available space
log_message(f"Label Width: {self.label.rect().width()}")
# scale the font size linearly from 16 pt to 8 ps as the width of the panel decreases
font_size = int(
linear_interpolation(self.label.rect().width(), 12, 16, 400, 600)
)
log_message(f"Label Font Size: {font_size}")
self.label.setFont(QFont("Arial", font_size))
24 changes: 22 additions & 2 deletions geest/gui/panels/ors_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
QWidget,
)
from qgis.PyQt.QtCore import QUrl, pyqtSignal
from qgis.PyQt.QtGui import QPixmap, QDesktopServices
from qgis.PyQt.QtGui import QPixmap, QDesktopServices, QFont
from qgis.PyQt.QtWidgets import QMessageBox
from geest.core.tasks import OrsCheckerTask
from geest.utilities import get_ui_class, resources_path, log_message
from geest.utilities import (
get_ui_class,
resources_path,
log_message,
linear_interpolation,
)
from geest.core import setting, set_setting
from geest.core import WorkflowQueueManager
from geest.gui.widgets import CustomBannerLabel
Expand All @@ -25,6 +30,7 @@ def __init__(self):
log_message(f"Loading ORS panel")
self.initUI()
self.queue_manager = WorkflowQueueManager(pool_size=1)
self.set_font_size()

def initUI(self):
self.custom_label = CustomBannerLabel(
Expand Down Expand Up @@ -83,3 +89,17 @@ def on_next_button_clicked(self):

def on_previous_button_clicked(self):
self.switch_to_previous_tab.emit()

def resizeEvent(self, event):
self.set_font_size()
super().resizeEvent(event)

def set_font_size(self):
# Scale the font size to fit the text in the available space
log_message(f"Label Width: {self.description.rect().width()}")
# scale the font size linearly from 16 pt to 8 ps as the width of the panel decreases
font_size = int(
linear_interpolation(self.description.rect().width(), 12, 16, 400, 600)
)
log_message(f"Label Font Size: {font_size}")
self.description.setFont(QFont("Arial", font_size))
22 changes: 21 additions & 1 deletion geest/gui/panels/setup_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
QWidget,
)
from qgis.PyQt.QtCore import pyqtSignal
from geest.utilities import get_ui_class, resources_path, log_message
from PyQt5.QtGui import QFont
from geest.utilities import (
get_ui_class,
resources_path,
log_message,
linear_interpolation,
)
from geest.gui.widgets import CustomBannerLabel

FORM_CLASS = get_ui_class("setup_panel_base.ui")
Expand Down Expand Up @@ -47,3 +53,17 @@ def create_project(self):

def on_previous_button_clicked(self):
self.switch_to_previous_tab.emit()

def resizeEvent(self, event):
self.set_font_size()
super().resizeEvent(event)

def set_font_size(self):
# Scale the font size to fit the text in the available space
log_message(f"Label Width: {self.description.rect().width()}")
# scale the font size linearly from 16 pt to 8 ps as the width of the panel decreases
font_size = int(
linear_interpolation(self.description.rect().width(), 12, 16, 400, 600)
)
log_message(f"Label Font Size: {font_size}")
self.description.setFont(QFont("Arial", font_size))
10 changes: 9 additions & 1 deletion geest/gui/widgets/custom_banner_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
)
from qgis.PyQt.QtGui import QPixmap, QPainter, QColor, QFont
from qgis.PyQt.QtCore import Qt
from geest.utilities import log_message


class CustomBannerLabel(QLabel):
Expand All @@ -22,8 +23,15 @@ def paintEvent(self, event):

# Draw the title text
painter.setPen(QColor("white"))
painter.setFont(QFont("Arial", 16))
text_rect = self.rect().adjusted(10, 0, -10, -5)
# Scale the font size to fit the text in the available space
font_size = 16
threshold = 430
log_message(f"Banner Label Width: {self.rect().width()}")
if self.rect().width() < threshold:
font_size = int(14 * (self.rect().width() / threshold))
log_message(f"Font Size: {font_size}")
painter.setFont(QFont("Arial", font_size))
painter.drawText(text_rect, Qt.AlignCenter | Qt.AlignBottom, self.text)

painter.end()
Loading

0 comments on commit fdac68e

Please sign in to comment.