mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-02-01 07:39:10 +00:00
ui: add "is category" checkbox in tag panel
This commit is contained in:
@@ -10,8 +10,10 @@ import structlog
|
||||
from PySide6.QtCore import Qt, Signal
|
||||
from PySide6.QtWidgets import (
|
||||
QApplication,
|
||||
QCheckBox,
|
||||
QComboBox,
|
||||
QFrame,
|
||||
QHBoxLayout,
|
||||
QLabel,
|
||||
QLineEdit,
|
||||
QPushButton,
|
||||
@@ -115,8 +117,7 @@ class BuildTagPanel(PanelWidget):
|
||||
|
||||
self.alias_add_button.clicked.connect(self.add_alias_callback)
|
||||
|
||||
# Subtags ------------------------------------------------------------
|
||||
|
||||
# Parent Tags ----------------------------------------------------------
|
||||
self.subtags_widget = QWidget()
|
||||
self.subtags_layout = QVBoxLayout(self.subtags_widget)
|
||||
self.subtags_layout.setStretch(1, 1)
|
||||
@@ -159,11 +160,11 @@ class BuildTagPanel(PanelWidget):
|
||||
Translations.translate_with_setter(self.add_tag_modal.setWindowTitle, "tag.parent_tags.add")
|
||||
self.subtags_add_button.clicked.connect(self.add_tag_modal.show)
|
||||
|
||||
# Shorthand ------------------------------------------------------------
|
||||
# Color ----------------------------------------------------------------
|
||||
self.color_widget = QWidget()
|
||||
self.color_layout = QVBoxLayout(self.color_widget)
|
||||
self.color_layout.setStretch(1, 1)
|
||||
self.color_layout.setContentsMargins(0, 0, 0, 0)
|
||||
self.color_layout.setContentsMargins(0, 0, 0, 24)
|
||||
self.color_layout.setSpacing(0)
|
||||
self.color_layout.setAlignment(Qt.AlignmentFlag.AlignLeft)
|
||||
self.color_title = QLabel()
|
||||
@@ -190,6 +191,50 @@ class BuildTagPanel(PanelWidget):
|
||||
)
|
||||
self.color_layout.addWidget(self.color_field)
|
||||
|
||||
# Category -------------------------------------------------------------
|
||||
self.cat_widget = QWidget()
|
||||
self.cat_layout = QHBoxLayout(self.cat_widget)
|
||||
self.cat_layout.setStretch(1, 1)
|
||||
self.cat_layout.setContentsMargins(0, 0, 0, 0)
|
||||
self.cat_layout.setSpacing(0)
|
||||
self.cat_layout.setAlignment(Qt.AlignmentFlag.AlignLeft)
|
||||
self.cat_title = QLabel()
|
||||
self.cat_title.setText("Is Category")
|
||||
self.cat_checkbox = QCheckBox()
|
||||
# TODO: Style checkbox
|
||||
self.cat_checkbox.setStyleSheet(
|
||||
"QCheckBox::indicator{"
|
||||
"width: 19px; height: 19px;"
|
||||
# f"background: #1e1e1e;"
|
||||
# # f"color: #FFFFFF;"
|
||||
# # f"font-weight: bold;"
|
||||
# f"border-color: #333333;"
|
||||
# f"border-radius: 6px;"
|
||||
# f"border-style:solid;"
|
||||
# f"border-width:{math.ceil(self.devicePixelRatio())}px;"
|
||||
# f"padding-bottom: 5px;"
|
||||
# f"font-size: 20p+x;"
|
||||
"}"
|
||||
# f"QCheckBox::indicator::hover"
|
||||
# f"{{"
|
||||
# f"border-color: #CCCCCC;"
|
||||
# f"background: #555555;"
|
||||
# f"}}"
|
||||
)
|
||||
self.cat_layout.addWidget(self.cat_checkbox)
|
||||
self.cat_layout.addWidget(self.cat_title)
|
||||
|
||||
# Keyboard Actions =====================================================
|
||||
remove_selected_alias_action = QAction("remove selected alias", self)
|
||||
remove_selected_alias_action.triggered.connect(self.remove_selected_alias)
|
||||
remove_selected_alias_action.setShortcut(
|
||||
QtCore.QKeyCombination(
|
||||
QtCore.Qt.KeyboardModifier(QtCore.Qt.KeyboardModifier.ControlModifier),
|
||||
QtCore.Qt.Key.Key_D,
|
||||
)
|
||||
)
|
||||
self.addAction(remove_selected_alias_action)
|
||||
|
||||
# Add Widgets to Layout ================================================
|
||||
self.root_layout.addWidget(self.name_widget)
|
||||
self.root_layout.addWidget(self.shorthand_widget)
|
||||
@@ -198,6 +243,9 @@ class BuildTagPanel(PanelWidget):
|
||||
self.root_layout.addWidget(self.alias_add_button)
|
||||
self.root_layout.addWidget(self.subtags_widget)
|
||||
self.root_layout.addWidget(self.color_widget)
|
||||
self.root_layout.addWidget(QLabel("<h3>Properties</h3>"))
|
||||
self.root_layout.addWidget(self.cat_widget)
|
||||
# self.parent().done.connect(self.update_tag)
|
||||
|
||||
self.subtag_ids: set[int] = set()
|
||||
self.alias_ids: list[int] = []
|
||||
@@ -349,21 +397,17 @@ class BuildTagPanel(PanelWidget):
|
||||
self.new_alias_names[item.id] = item.text()
|
||||
|
||||
def set_tag(self, tag: Tag):
|
||||
logger.info("[BuildTagPanel] Setting Tag", tag=tag)
|
||||
self.tag = tag
|
||||
|
||||
logger.info("setting tag", tag=tag)
|
||||
|
||||
self.name_field.setText(tag.name)
|
||||
self.shorthand_field.setText(tag.shorthand or "")
|
||||
|
||||
for alias_id in tag.alias_ids:
|
||||
self.alias_ids.append(alias_id)
|
||||
|
||||
self._set_aliases()
|
||||
|
||||
for subtag in tag.subtag_ids:
|
||||
self.subtag_ids.add(subtag)
|
||||
|
||||
for alias_id in tag.alias_ids:
|
||||
self.alias_ids.add(alias_id)
|
||||
|
||||
self.set_subtags()
|
||||
|
||||
# select item in self.color_field where the userData value matched tag.color
|
||||
@@ -372,6 +416,8 @@ class BuildTagPanel(PanelWidget):
|
||||
self.color_field.setCurrentIndex(i)
|
||||
break
|
||||
|
||||
self.cat_checkbox.setChecked(tag.is_category)
|
||||
|
||||
def on_name_changed(self):
|
||||
is_empty = not self.name_field.text().strip()
|
||||
|
||||
@@ -386,14 +432,13 @@ class BuildTagPanel(PanelWidget):
|
||||
|
||||
def build_tag(self) -> Tag:
|
||||
color = self.color_field.currentData() or TagColor.DEFAULT
|
||||
|
||||
tag = self.tag
|
||||
|
||||
self.add_aliases()
|
||||
|
||||
tag.name = self.name_field.text()
|
||||
tag.shorthand = self.shorthand_field.text()
|
||||
tag.color = color
|
||||
tag.is_category = self.cat_checkbox.isChecked()
|
||||
|
||||
logger.info("built tag", tag=tag)
|
||||
return tag
|
||||
|
||||
Reference in New Issue
Block a user