mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Merge pull request #4821 from ynput/feature/OP-5529_Settings-Allow-setting-a-size-hint-for-text-fields
This commit is contained in:
commit
03c7eb2d60
4 changed files with 30 additions and 4 deletions
|
|
@ -448,6 +448,8 @@ class TextEntity(InputEntity):
|
|||
self.multiline = self.schema_data.get("multiline", False)
|
||||
self.placeholder_text = self.schema_data.get("placeholder")
|
||||
self.value_hints = self.schema_data.get("value_hints") or []
|
||||
self.minimum_lines_count = (
|
||||
self.schema_data.get("minimum_lines_count") or 0)
|
||||
|
||||
def schema_validations(self):
|
||||
if self.multiline and self.value_hints:
|
||||
|
|
|
|||
|
|
@ -380,6 +380,7 @@ How output of the schema could look like on save:
|
|||
- simple text input
|
||||
- key `"multiline"` allows to enter multiple lines of text (Default: `False`)
|
||||
- key `"placeholder"` allows to show text inside input when is empty (Default: `None`)
|
||||
- key `"minimum_lines_count"` allows to define minimum size hint for UI. Can be 0-n lines.
|
||||
|
||||
```
|
||||
{
|
||||
|
|
|
|||
|
|
@ -360,14 +360,16 @@ class TextWidget(InputWidget):
|
|||
def _add_inputs_to_layout(self):
|
||||
multiline = self.entity.multiline
|
||||
if multiline:
|
||||
self.input_field = SettingsPlainTextEdit(self.content_widget)
|
||||
input_field = SettingsPlainTextEdit(self.content_widget)
|
||||
if self.entity.minimum_lines_count:
|
||||
input_field.set_minimum_lines(self.entity.minimum_lines_count)
|
||||
else:
|
||||
self.input_field = SettingsLineEdit(self.content_widget)
|
||||
|
||||
input_field = SettingsLineEdit(self.content_widget)
|
||||
placeholder_text = self.entity.placeholder_text
|
||||
if placeholder_text:
|
||||
self.input_field.setPlaceholderText(placeholder_text)
|
||||
input_field.setPlaceholderText(placeholder_text)
|
||||
|
||||
self.input_field = input_field
|
||||
self.setFocusProxy(self.input_field)
|
||||
|
||||
layout_kwargs = {}
|
||||
|
|
|
|||
|
|
@ -310,11 +310,32 @@ class SettingsLineEdit(PlaceholderLineEdit):
|
|||
|
||||
class SettingsPlainTextEdit(QtWidgets.QPlainTextEdit):
|
||||
focused_in = QtCore.Signal()
|
||||
_min_lines = 0
|
||||
|
||||
def focusInEvent(self, event):
|
||||
super(SettingsPlainTextEdit, self).focusInEvent(event)
|
||||
self.focused_in.emit()
|
||||
|
||||
def set_minimum_lines(self, lines):
|
||||
self._min_lines = lines
|
||||
self.update()
|
||||
|
||||
def minimumSizeHint(self):
|
||||
result = super(SettingsPlainTextEdit, self).minimumSizeHint()
|
||||
if self._min_lines < 1:
|
||||
return result
|
||||
document = self.document()
|
||||
margins = self.contentsMargins()
|
||||
d_margin = (
|
||||
((document.documentMargin() + self.frameWidth()) * 2)
|
||||
+ margins.top() + margins.bottom()
|
||||
)
|
||||
font = document.defaultFont()
|
||||
font_metrics = QtGui.QFontMetrics(font)
|
||||
result.setHeight(
|
||||
d_margin + (font_metrics.lineSpacing() * self._min_lines))
|
||||
return result
|
||||
|
||||
|
||||
class SettingsToolBtn(ImageButton):
|
||||
_mask_pixmap = None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue