Browse Source

Backwards-compatible QFontMetrics horizontalAdvance/width call

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.1-rc1
falkTX 4 years ago
parent
commit
3af5915de9
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
5 changed files with 18 additions and 10 deletions
  1. +1
    -1
      source/frontend/carla_database.py
  2. +4
    -4
      source/frontend/carla_host.py
  3. +1
    -1
      source/frontend/carla_settings.py
  4. +10
    -2
      source/frontend/carla_shared.py
  5. +2
    -2
      source/frontend/carla_widgets.py

+ 1
- 1
source/frontend/carla_database.py View File

@@ -1433,7 +1433,7 @@ class PluginDatabaseW(QDialog):
self.ui.tab_info.tabBar().hide()
self.ui.tab_reqs.tabBar().hide()
# FIXME, why /2 needed?
self.ui.tab_info.setMinimumWidth(self.ui.la_id.width()/2 + self.ui.l_id.fontMetrics().width("9999999999") + 6*3)
self.ui.tab_info.setMinimumWidth(self.ui.la_id.width()/2 + fontMetricsHorizontalAdvance(self.ui.l_id.fontMetrics(), "9999999999") + 6*3)
self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)

# ----------------------------------------------------------------------------------------------------


+ 4
- 4
source/frontend/carla_host.py View File

@@ -307,11 +307,11 @@ class HostWindow(QMainWindow):
# Set up GUI (transport)

fontMetrics = self.ui.l_transport_bbt.fontMetrics()
minValueWidth = fontMetrics.width("000|00|0000")
minLabelWidth = fontMetrics.width(self.ui.label_transport_frame.text())
minValueWidth = fontMetricsHorizontalAdvance(fontMetrics, "000|00|0000")
minLabelWidth = fontMetricsHorizontalAdvance(fontMetrics, self.ui.label_transport_frame.text())

labelTimeWidth = fontMetrics.width(self.ui.label_transport_time.text())
labelBBTWidth = fontMetrics.width(self.ui.label_transport_bbt.text())
labelTimeWidth = fontMetricsHorizontalAdvance(fontMetrics, self.ui.label_transport_time.text())
labelBBTWidth = fontMetricsHorizontalAdvance(fontMetrics, self.ui.label_transport_bbt.text())

if minLabelWidth < labelTimeWidth:
minLabelWidth = labelTimeWidth


+ 1
- 1
source/frontend/carla_settings.py View File

@@ -364,7 +364,7 @@ class CarlaSettingsW(QDialog):
# ----------------------------------------------------------------------------------------------------
# Set-up GUI

self.ui.lw_page.setFixedWidth(48 + 6*3 + self.ui.lw_page.fontMetrics().width(" Experimental "))
self.ui.lw_page.setFixedWidth(48 + 6*3 + fontMetricsHorizontalAdvance(self.ui.lw_page.fontMetrics(), "Experimental"))

for i in range(host.get_engine_driver_count()):
self.ui.cb_engine_audio_driver.addItem(host.get_engine_driver_name(i))


+ 10
- 2
source/frontend/carla_shared.py View File

@@ -30,7 +30,7 @@ import os
import sys

from PyQt5.Qt import PYQT_VERSION_STR
from PyQt5.QtCore import qFatal, QT_VERSION_STR, qWarning, QDir, QSettings
from PyQt5.QtCore import qFatal, QT_VERSION, QT_VERSION_STR, qWarning, QDir, QSettings
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QFileDialog, QMessageBox

@@ -752,6 +752,14 @@ def getAndSetPath(parent, lineEdit):
lineEdit.setText(newPath)
return newPath

# ------------------------------------------------------------------------------------------------------------
# Backwards-compatible horizontalAdvance/width call, depending on Qt version

def fontMetricsHorizontalAdvance(fontMetrics, string):
if QT_VERSION >= 0x51100:
return fontMetrics.horizontalAdvance(string)
return fontMetrics.width(string)

# ------------------------------------------------------------------------------------------------------------
# Custom QMessageBox which resizes itself to fit text

@@ -768,7 +776,7 @@ class QMessageBoxWithBetterWidth(QMessageBox):
width = 0

for line in lines:
width = max(fontMetrics.width(line), width)
width = max(fontMetricsHorizontalAdvance(fontMetrics, line), width)

self.layout().setColumnMinimumWidth(2, width + 12)



+ 2
- 2
source/frontend/carla_widgets.py View File

@@ -924,7 +924,7 @@ class PluginEdit(QDialog):
# Get width values, in packs of 20

if parameter['type'] == PARAMETER_INPUT:
paramInputWidthTMP = self.fontMetrics().width(parameter['name'])
paramInputWidthTMP = fontMetricsHorizontalAdvance(self.fontMetrics(), parameter['name'])

if paramInputWidthTMP > paramInputWidth:
paramInputWidth = paramInputWidthTMP
@@ -932,7 +932,7 @@ class PluginEdit(QDialog):
paramInputList.append(parameter)

else:
paramOutputWidthTMP = self.fontMetrics().width(parameter['name'])
paramOutputWidthTMP = fontMetricsHorizontalAdvance(self.fontMetrics(), parameter['name'])

if paramOutputWidthTMP > paramOutputWidth:
paramOutputWidth = paramOutputWidthTMP


Loading…
Cancel
Save