mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 05:42:15 +01:00
use create functions to create buttons
This commit is contained in:
parent
1b05dbbf52
commit
ca3a29b28b
2 changed files with 20 additions and 125 deletions
|
|
@ -3,7 +3,12 @@ from uuid import uuid4
|
|||
from Qt import QtWidgets, QtCore, QtGui
|
||||
|
||||
from .base import BaseWidget
|
||||
from .lib import create_deffered_value_change_timer
|
||||
from .lib import (
|
||||
create_deffered_value_change_timer,
|
||||
create_add_btn,
|
||||
create_remove_btn,
|
||||
create_confirm_btn
|
||||
)
|
||||
from .widgets import (
|
||||
ExpandingWidget,
|
||||
IconButton
|
||||
|
|
@ -21,92 +26,6 @@ KEY_INPUT_TOOLTIP = (
|
|||
)
|
||||
|
||||
|
||||
class PaintHelper:
|
||||
cached_icons = {}
|
||||
|
||||
@classmethod
|
||||
def _draw_image(cls, width, height, brush):
|
||||
image = QtGui.QPixmap(width, height)
|
||||
image.fill(QtCore.Qt.transparent)
|
||||
|
||||
icon_path_stroker = QtGui.QPainterPathStroker()
|
||||
icon_path_stroker.setCapStyle(QtCore.Qt.RoundCap)
|
||||
icon_path_stroker.setJoinStyle(QtCore.Qt.RoundJoin)
|
||||
icon_path_stroker.setWidth(height / 5)
|
||||
|
||||
painter = QtGui.QPainter(image)
|
||||
painter.setPen(QtCore.Qt.transparent)
|
||||
painter.setBrush(brush)
|
||||
rect = QtCore.QRect(0, 0, image.width(), image.height())
|
||||
fifteenth = rect.height() / 15
|
||||
# Left point
|
||||
p1 = QtCore.QPoint(
|
||||
rect.x() + (5 * fifteenth),
|
||||
rect.y() + (9 * fifteenth)
|
||||
)
|
||||
# Middle bottom point
|
||||
p2 = QtCore.QPoint(
|
||||
rect.center().x(),
|
||||
rect.y() + (11 * fifteenth)
|
||||
)
|
||||
# Top right point
|
||||
p3 = QtCore.QPoint(
|
||||
rect.x() + (10 * fifteenth),
|
||||
rect.y() + (5 * fifteenth)
|
||||
)
|
||||
|
||||
path = QtGui.QPainterPath(p1)
|
||||
path.lineTo(p2)
|
||||
path.lineTo(p3)
|
||||
|
||||
stroked_path = icon_path_stroker.createStroke(path)
|
||||
painter.drawPath(stroked_path)
|
||||
|
||||
painter.end()
|
||||
|
||||
return image
|
||||
|
||||
@classmethod
|
||||
def get_confirm_icon(cls, width, height):
|
||||
key = "{}x{}-confirm_image".format(width, height)
|
||||
icon = cls.cached_icons.get(key)
|
||||
|
||||
if icon is None:
|
||||
image = cls._draw_image(width, height, QtCore.Qt.white)
|
||||
icon = QtGui.QIcon(image)
|
||||
cls.cached_icons[key] = icon
|
||||
return icon
|
||||
|
||||
|
||||
def create_add_btn(parent):
|
||||
add_btn = QtWidgets.QPushButton("+", parent)
|
||||
add_btn.setFocusPolicy(QtCore.Qt.ClickFocus)
|
||||
add_btn.setObjectName("SettingsToolBtn")
|
||||
add_btn.setFixedSize(BTN_FIXED_SIZE, BTN_FIXED_SIZE)
|
||||
return add_btn
|
||||
|
||||
|
||||
def create_remove_btn(parent):
|
||||
remove_btn = QtWidgets.QPushButton("-", parent)
|
||||
remove_btn.setFocusPolicy(QtCore.Qt.ClickFocus)
|
||||
remove_btn.setObjectName("SettingsToolBtn")
|
||||
remove_btn.setFixedSize(BTN_FIXED_SIZE, BTN_FIXED_SIZE)
|
||||
return remove_btn
|
||||
|
||||
|
||||
def create_confirm_btn(parent):
|
||||
confirm_btn = QtWidgets.QPushButton(parent)
|
||||
|
||||
icon = PaintHelper.get_confirm_icon(
|
||||
BTN_FIXED_SIZE, BTN_FIXED_SIZE
|
||||
)
|
||||
confirm_btn.setIcon(icon)
|
||||
confirm_btn.setFocusPolicy(QtCore.Qt.ClickFocus)
|
||||
confirm_btn.setObjectName("SettingsToolBtn")
|
||||
confirm_btn.setFixedSize(BTN_FIXED_SIZE, BTN_FIXED_SIZE)
|
||||
return confirm_btn
|
||||
|
||||
|
||||
class ModifiableDictEmptyItem(QtWidgets.QWidget):
|
||||
def __init__(self, entity_widget, store_as_list, parent):
|
||||
super(ModifiableDictEmptyItem, self).__init__(parent)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
from Qt import QtWidgets, QtCore
|
||||
|
||||
from .base import InputWidget
|
||||
from .widgets import ExpandingWidget
|
||||
from openpype.tools.settings import (
|
||||
BTN_FIXED_SIZE,
|
||||
CHILD_OFFSET
|
||||
)
|
||||
|
||||
from avalon.vendor import qtawesome
|
||||
from .base import InputWidget
|
||||
from .widgets import ExpandingWidget
|
||||
from .lib import (
|
||||
create_add_btn,
|
||||
create_remove_btn,
|
||||
create_up_btn,
|
||||
create_down_btn
|
||||
)
|
||||
|
||||
|
||||
class EmptyListItem(QtWidgets.QWidget):
|
||||
|
|
@ -16,18 +21,11 @@ class EmptyListItem(QtWidgets.QWidget):
|
|||
|
||||
self.entity_widget = entity_widget
|
||||
|
||||
add_btn = QtWidgets.QPushButton("+", self)
|
||||
remove_btn = QtWidgets.QPushButton("-", self)
|
||||
add_btn = create_add_btn(self)
|
||||
remove_btn = create_remove_btn(self)
|
||||
|
||||
add_btn.setFocusPolicy(QtCore.Qt.ClickFocus)
|
||||
remove_btn.setEnabled(False)
|
||||
|
||||
add_btn.setFixedSize(BTN_FIXED_SIZE, BTN_FIXED_SIZE)
|
||||
remove_btn.setFixedSize(BTN_FIXED_SIZE, BTN_FIXED_SIZE)
|
||||
|
||||
add_btn.setObjectName("SettingsToolBtn")
|
||||
remove_btn.setObjectName("SettingsToolBtn")
|
||||
|
||||
layout = QtWidgets.QHBoxLayout(self)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.setSpacing(3)
|
||||
|
|
@ -52,32 +50,10 @@ class ListItem(QtWidgets.QWidget):
|
|||
|
||||
self.ignore_input_changes = entity_widget.ignore_input_changes
|
||||
|
||||
char_up = qtawesome.charmap("fa.angle-up")
|
||||
char_down = qtawesome.charmap("fa.angle-down")
|
||||
|
||||
add_btn = QtWidgets.QPushButton("+")
|
||||
remove_btn = QtWidgets.QPushButton("-")
|
||||
up_btn = QtWidgets.QPushButton(char_up)
|
||||
down_btn = QtWidgets.QPushButton(char_down)
|
||||
|
||||
font_up_down = qtawesome.font("fa", 13)
|
||||
up_btn.setFont(font_up_down)
|
||||
down_btn.setFont(font_up_down)
|
||||
|
||||
add_btn.setFocusPolicy(QtCore.Qt.ClickFocus)
|
||||
remove_btn.setFocusPolicy(QtCore.Qt.ClickFocus)
|
||||
up_btn.setFocusPolicy(QtCore.Qt.ClickFocus)
|
||||
down_btn.setFocusPolicy(QtCore.Qt.ClickFocus)
|
||||
|
||||
add_btn.setFixedSize(BTN_FIXED_SIZE, BTN_FIXED_SIZE)
|
||||
remove_btn.setFixedSize(BTN_FIXED_SIZE, BTN_FIXED_SIZE)
|
||||
up_btn.setFixedSize(BTN_FIXED_SIZE, BTN_FIXED_SIZE)
|
||||
down_btn.setFixedSize(BTN_FIXED_SIZE, BTN_FIXED_SIZE)
|
||||
|
||||
add_btn.setObjectName("SettingsToolBtn")
|
||||
remove_btn.setObjectName("SettingsToolBtn")
|
||||
up_btn.setObjectName("SettingsToolBtn")
|
||||
down_btn.setObjectName("SettingsToolBtn")
|
||||
add_btn = create_add_btn(self)
|
||||
remove_btn = create_remove_btn(self)
|
||||
up_btn = create_up_btn(self)
|
||||
down_btn = create_down_btn(self)
|
||||
|
||||
add_btn.clicked.connect(self._on_add_clicked)
|
||||
remove_btn.clicked.connect(self._on_remove_clicked)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue