Skip to content

Commit

Permalink
Fix some ugly high DPI rendering issues
Browse files Browse the repository at this point in the history
  • Loading branch information
walmis committed Jan 1, 2025
1 parent 8a53982 commit 41adcfb
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 31 deletions.
17 changes: 13 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import traceback
from datetime import datetime

from PyQt5 import QtCore, QtWidgets
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtCore import QCoreApplication
from PyQt5.QtWidgets import QApplication, QMessageBox, QPlainTextEdit

Expand Down Expand Up @@ -104,6 +104,14 @@ def main():
app = QApplication(sys.argv)
app.setStyle('Fusion') # Set Fusion style

# Create and set custom palette with accent color
palette = app.palette()
accent_color = QtGui.QColor('#9430ad')
palette.setColor(palette.Highlight, accent_color)
palette.setColor(palette.HighlightedText, QtGui.QColor('white'))
palette.setColor(palette.Link, accent_color)
app.setPalette(palette)

G.args = CmdLineArgs.parse()

G.is_exe = getattr(sys, 'frozen', False)
Expand Down Expand Up @@ -240,9 +248,9 @@ def excepthook(exc_type, exc_value, exc_tb):

app.setStyleSheet(
"""
QCheckBox::indicator:checked { image: url(:/image/purplecheckbox.png); }
/*QCheckBox::indicator:checked { image: url(:/image/purplecheckbox.png); }
QCheckBox::indicator:checked:disabled {image: url(:/image/disabledcheckbox.png); }
QRadioButton::indicator:checked { image: url(:/image/rchecked.png);}
QRadioButton::indicator:checked { image: url(:/image/rchecked.png);}*/
QPushButton:!pressed, #styledButton:!pressed {
background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1,
Expand Down Expand Up @@ -291,6 +299,7 @@ def excepthook(exc_type, exc_value, exc_tb):
}
/*
QComboBox::down-arrow {
image: url(:/image/down-down.png);
}
Expand All @@ -299,7 +308,7 @@ def excepthook(exc_type, exc_value, exc_tb):
border: 2px solid darkgray;
selection-background-color: #ab37c8;
}
*/
QLineEdit {
selection-background-color: #ab37c8; /* Set the highlight color for selected text */
}
Expand Down
23 changes: 13 additions & 10 deletions telemffb/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
from telemffb.telem.SimTelemListener import SimTelemListener
from telemffb.SystemSettingsDialog import SystemSettingsDialog
from telemffb.TeleplotSetupDialog import TeleplotSetupDialog
from telemffb.utils import exit_application, overrides
from telemffb.utils import exit_application, overrides, HiDpiPixmap

class MainWindow(QMainWindow):

Expand Down Expand Up @@ -329,16 +329,19 @@ def do_open_file(url):
self.vpflogo_label = QLabel(self.logo_stack)
self.devicetype_label = ClickLogo(self.logo_stack)
self.devicetype_label.clicked.connect(self.device_logo_click_event)
pixmap = QPixmap(":/image/vpforcelogo.png")
pixmap2 = QPixmap(utils.get_device_logo(G.device_type))

pixmap = HiDpiPixmap(":/image/vpforcelogo.png")
pixmap = pixmap._scaled(271, 115, aspectRatioMode=QtCore.Qt.KeepAspectRatio, transformMode=QtCore.Qt.SmoothTransformation)

pixmap2 = HiDpiPixmap(utils.get_device_logo(G.device_type))
pixmap2 = pixmap2._scaled(round(pixmap2.width()), round(pixmap2.height()))

self.vpflogo_label.setPixmap(pixmap)
self.devicetype_label.setPixmap(pixmap2)
self.devicetype_label.setScaledContents(True)

# Resize QGroupBox to match the size of the larger label
max_width = pixmap.width()
max_height = pixmap.height()
max_width = round(pixmap.width() / pixmap.devicePixelRatioF())
max_height = round(pixmap.height() / pixmap.devicePixelRatioF())
self.logo_stack.setFixedSize(max_width, max_height)
self.logo_stack.setStyleSheet("QGroupBox { border: none; }")
# Align self.image_label2 with the upper left corner of self.image_label
Expand Down Expand Up @@ -519,7 +522,7 @@ def on_event(event):
# self.tab_widget.setCursor(QCursor(QtCore.Qt.PointingHandCursor))

# Set the main window area height to 0
self.tab_widget.setMinimumHeight(14)
self.tab_widget.setMinimumHeight(24)
style_sheet = """
QTabBar::tab:selected {
background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1,
Expand Down Expand Up @@ -816,7 +819,7 @@ def toggle_start_with_windows(self, set_enabled=None):
except FileNotFoundError:
return False
else:
if set_enabled:
if set_enabled:
winreg.SetValueEx(reg_key, reg_key_name, 0, winreg.REG_SZ, exe_path)
else:
try:
Expand Down Expand Up @@ -1089,9 +1092,9 @@ def change_config_scope(self, _arg):
xmlutils.update_vars(types[arg], G.userconfig_path, G.defaults_path)
G.current_device_config_scope = types[arg]

pixmap = QPixmap(utils.get_device_logo(G.current_device_config_scope))
pixmap = HiDpiPixmap(utils.get_device_logo(G.current_device_config_scope))
self.devicetype_label.setPixmap(pixmap)
self.devicetype_label.setFixedSize(pixmap.width(), pixmap.height())
#self.devicetype_label.setFixedSize(pixmap.width(), pixmap.height())

if G.master_instance:
self.effect_lbl.setText(f'Active Effects for: {G.current_device_config_scope}')
Expand Down
10 changes: 5 additions & 5 deletions telemffb/SettingsLayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from telemffb.custom_widgets import (InfoLabel, NoWheelSlider, NoWheelNumberSlider, vpf_purple, t_purple, Toggle, AnimatedToggle)
from telemffb.ConfiguratorDialog import ConfiguratorDialog
from telemffb.hw.ffb_rhino import HapticEffect
from telemffb.utils import validate_vpconf_profile, dbprint
from telemffb.utils import validate_vpconf_profile, dbprint, HiDpiPixmap

from . import globals as G
from . import xmlutils
Expand Down Expand Up @@ -743,17 +743,17 @@ def generate_settings_row(self, item, i, rowdisabled=False):

# erase_button = QToolButton()
icon = QIcon()
pixmap = QPixmap(":/image/delete_button.png")
resized_pixmap = pixmap.scaled(15, 15, Qt.KeepAspectRatio, Qt.SmoothTransformation)
icon.addPixmap(resized_pixmap)
pixmap = HiDpiPixmap(":/image/delete_button.png")
#pixmap = pixmap.scaled(15, 15, Qt.KeepAspectRatio, Qt.SmoothTransformation)
icon.addPixmap(pixmap)

# Create the erase button

erase_button.setObjectName(f"eb_{item['name']}")
erase_button.setMaximumSize(25, 25)
erase_button.setMinimumSize(25, 25)
erase_button.setIcon(icon)
erase_button.setIconSize(resized_pixmap.rect().size())
#erase_button.setIconSize(pixmap.rect().size())
erase_button.setToolTip("")
erase_button.clicked.connect(lambda _, name=item['name']: self.erase_setting(name))
self.addWidget(erase_button, i, erase_col)
Expand Down
22 changes: 11 additions & 11 deletions telemffb/custom_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(self, *args, **kwargs):
self._timer.timeout.connect(self._emitDelayedValueChanged)
self.valueChanged.connect(self._startTimer)

self.setMinimumHeight(int(self.handle_height * self.devicePixelRatioF()) + 10)
self.setMinimumHeight(int(self.handle_height ) + 10)
def _startTimer(self):
self._timer.start(self._delay)

Expand Down Expand Up @@ -146,7 +146,7 @@ def update_styles(self):
css = f"""
QSlider::groove:horizontal {{
border: 1px solid #565a5e;
height: {int(8 * self.devicePixelRatioF())}px; /* Adjusted groove height */
height: 8px; /* Adjusted groove height */
background: qlineargradient(
x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #e6e6e6, stop: 1 #bfbfbf
Expand All @@ -162,11 +162,11 @@ def update_styles(self):
stop: 1.0 {QColor(self.handle_color).darker().name()}
);
border: 1px solid #565a5e;
width: {int(self.handle_width * self.devicePixelRatioF())}px; /* Adjusted handle width */
height: {int(self.handle_height * self.devicePixelRatioF())}px; /* Adjusted handle height */
border-radius: {int(self.handle_height / 4 * self.devicePixelRatioF())}px; /* Adjusted border radius */
margin-top: -{int(self.handle_height / 4 * self.devicePixelRatioF())}px; /* Negative margin to overlap with groove */
margin-bottom: -{int(self.handle_height / 4 * self.devicePixelRatioF())}px; /* Negative margin to overlap with groove */
width: {int(self.handle_width)}px; /* Adjusted handle width */
height: {int(self.handle_height)}px; /* Adjusted handle height */
border-radius: {int(self.handle_height / 4 )}px; /* Adjusted border radius */
margin-top: -{int(self.handle_height / 4 )}px; /* Negative margin to overlap with groove */
margin-bottom: -{int(self.handle_height / 4 )}px; /* Negative margin to overlap with groove */
margin-left: -1px; /* Adjusted left margin */
margin-right: -1px; /* Adjusted right margin */
}}
Expand Down Expand Up @@ -311,7 +311,7 @@ def __init__(self, text=None, tooltip=None, parent=None):
# icon_img = os.path.join(script_dir, "image/information.png")
icon_img = ":/image/information.png"
self.pixmap = HiDpiPixmap(icon_img)
self.icon_label.setPixmap(self.pixmap.scaled(12, 12, Qt.KeepAspectRatio, Qt.SmoothTransformation)) # Adjust the height as needed
self.icon_label.setPixmap(self.pixmap._scaled(12, 12, Qt.KeepAspectRatio, Qt.SmoothTransformation)) # Adjust the height as needed
self.icon_label.setVisible(False)

# Layout to align the text label and icon
Expand Down Expand Up @@ -546,7 +546,7 @@ def update(self):
self.setToolTip("Sim is disabled")

def create_status_icon(self, color, size: QSize, icon_type="colored"):
pixmap = QPixmap(size)
pixmap = HiDpiPixmap(size)
pixmap.fill(Qt.transparent)

painter = QPainter(pixmap)
Expand Down Expand Up @@ -596,9 +596,9 @@ def create_status_icon(self, color, size: QSize, icon_type="colored"):

# Draw the colored dot
dot_gradient = QRadialGradient(size.width() / 3, size.height() / 3, size.width() / 2)
dot_gradient.setColorAt(0, color.lighter(180)) # Increase lightness for stronger highlight
dot_gradient.setColorAt(0, color) # Increase lightness for stronger highlight
dot_gradient.setColorAt(0.35, color) # Base color in the middle
dot_gradient.setColorAt(1, color.darker(200)) # Increase darkness for stronger shadow
dot_gradient.setColorAt(1, color) # Increase darkness for stronger shadow

painter.setBrush(dot_gradient)
painter.setPen(Qt.NoPen)
Expand Down
8 changes: 7 additions & 1 deletion telemffb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1995,4 +1995,10 @@ def __init__(self, arg):
else: # If no arg is provided, create an empty pixmap
super().__init__()

self.setDevicePixelRatio(ratio)
self.setDevicePixelRatio(ratio)

def _scaled(self, width, height, aspectRatioMode=QtCore.Qt.KeepAspectRatio, transformMode=QtCore.Qt.SmoothTransformation):
ratio = self.devicePixelRatio()
scaled_pixmap = super().scaled(int(width * ratio), int(height * ratio), aspectRatioMode, transformMode)
scaled_pixmap.setDevicePixelRatio(ratio)
return scaled_pixmap

0 comments on commit 41adcfb

Please sign in to comment.