From ea905b82a2d708cb5d5ea1636bbc2da07180680b Mon Sep 17 00:00:00 2001 From: Zsolt Kovari Date: Sun, 3 Sep 2023 14:04:29 +0200 Subject: [PATCH] color picker --- src/main/python/plotlyst/view/style/button.py | 18 --------- .../view/widget/character/network/editor.py | 18 +++++++-- .../python/plotlyst/view/widget/graphics.py | 13 +++--- .../view/widget/story_map/controls.py | 40 +++++++++---------- .../python/plotlyst/view/widget/utility.py | 35 +++++++++++----- 5 files changed, 68 insertions(+), 56 deletions(-) diff --git a/src/main/python/plotlyst/view/style/button.py b/src/main/python/plotlyst/view/style/button.py index 3fb23bc3d..0c706eff7 100644 --- a/src/main/python/plotlyst/view/style/button.py +++ b/src/main/python/plotlyst/view/style/button.py @@ -17,11 +17,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -from typing import Union - -from PyQt6.QtCore import Qt -from PyQt6.QtGui import QColor -from PyQt6.QtWidgets import QAbstractButton style = ''' QPushButton::menu-indicator[no-menu] { @@ -422,16 +417,3 @@ } ''' - - -def apply_button_color(button: QAbstractButton, color: Union[str, QColor, Qt.GlobalColor]): - if isinstance(color, QColor): - color = color.name() - button.setStyleSheet(f''' - QToolButton {{ - background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 1, - stop: 0 {color}); - border: 1px solid darkGrey; - border-radius: 12px; - }} - ''') diff --git a/src/main/python/plotlyst/view/widget/character/network/editor.py b/src/main/python/plotlyst/view/widget/character/network/editor.py index 8af72aae2..8c829de3d 100644 --- a/src/main/python/plotlyst/view/widget/character/network/editor.py +++ b/src/main/python/plotlyst/view/widget/character/network/editor.py @@ -20,7 +20,7 @@ from typing import Optional from PyQt6.QtCore import pyqtSignal -from PyQt6.QtGui import QAction +from PyQt6.QtGui import QAction, QColor from PyQt6.QtWidgets import QButtonGroup from qthandy import vline from qtmenu import GridMenuWidget @@ -30,7 +30,8 @@ from src.main.python.plotlyst.view.dialog.utility import IconSelectorDialog from src.main.python.plotlyst.view.icons import IconRegistry from src.main.python.plotlyst.view.widget.graphics import BaseItemEditor, SolidPenStyleSelector, DashPenStyleSelector, \ - DotPenStyleSelector, ConnectorItem, PenWidthEditor, RelationsButton + DotPenStyleSelector, ConnectorItem, PenWidthEditor, RelationsButton, SecondarySelectorWidget +from src.main.python.plotlyst.view.widget.utility import ColorPicker class RelationSelector(GridMenuWidget): @@ -63,9 +64,13 @@ def __init__(self, network: RelationsNetwork, parent=None): self._connector: Optional[ConnectorItem] = None self._btnRelationType = RelationsButton() - self._btnColor = tool_btn(IconRegistry.from_name('fa5s.circle', color='darkBlue'), 'Change style', transparent_=True) + self._colorPicker = ColorPicker(self, maxColumn=5) + self._colorPicker.colorPicked.connect(self._colorChanged) + self._colorSecondaryWidget = SecondarySelectorWidget(self) + self._colorSecondaryWidget.addWidget(self._colorPicker, 0, 0) + self.addSecondaryWidget(self._btnColor, self._colorSecondaryWidget) self._btnIcon = tool_btn(IconRegistry.from_name('mdi.emoticon-outline'), 'Change icon', transparent_=True) self._btnIcon.clicked.connect(self._showIconSelector) @@ -126,7 +131,12 @@ def _widthChanged(self, value: int): if self._connector: self._connector.setPenWidth(value) + def _colorChanged(self, color: QColor): + if self._connector: + # self._connector.setColor(color) + pass + def _showIconSelector(self): result = IconSelectorDialog().display() if result and self._connector: - self._connector.setIcon(IconRegistry.from_name(result[0], result[1].name())) \ No newline at end of file + self._connector.setIcon(IconRegistry.from_name(result[0], result[1].name())) diff --git a/src/main/python/plotlyst/view/widget/graphics.py b/src/main/python/plotlyst/view/widget/graphics.py index 2792b6f4b..961367100 100644 --- a/src/main/python/plotlyst/view/widget/graphics.py +++ b/src/main/python/plotlyst/view/widget/graphics.py @@ -683,8 +683,11 @@ def __init__(self, parent=None, optional: bool = False): else: self._btnGroup = QButtonGroup() - def _newButton(self, icon: QIcon, tooltip: str, row: int, - col: int) -> QToolButton: + def addWidget(self, widget: QWidget, row: int, col: int): + self._grid.layout().addWidget(widget, row, col) + + def addButton(self, icon: QIcon, tooltip: str, row: int, + col: int) -> QToolButton: btn = tool_btn(icon, tooltip, True, icon_resize=False, properties=['transparent-rounded-bg-on-hover', 'top-selector'], @@ -694,13 +697,13 @@ def _newButton(self, icon: QIcon, tooltip: str, row: int, return btn - def _newItemTypeButton(self, itemType: NetworkItemType, icon: QIcon, tooltip: str, row: int, - col: int) -> QToolButton: + def addItemTypeButton(self, itemType: NetworkItemType, icon: QIcon, tooltip: str, row: int, + col: int) -> QToolButton: def clicked(toggled: bool): if toggled: self.selected.emit(itemType) - btn = self._newButton(icon, tooltip, row, col) + btn = self.addButton(icon, tooltip, row, col) btn.clicked.connect(clicked) return btn diff --git a/src/main/python/plotlyst/view/widget/story_map/controls.py b/src/main/python/plotlyst/view/widget/story_map/controls.py index 91ea4a069..2c8c22703 100644 --- a/src/main/python/plotlyst/view/widget/story_map/controls.py +++ b/src/main/python/plotlyst/view/widget/story_map/controls.py @@ -31,30 +31,30 @@ def __init__(self, parent=None): super().__init__(parent) self._grid.addWidget(QLabel('Events'), 0, 0, 1, 3) - self._btnGeneral = self._newItemTypeButton(ItemType.EVENT, IconRegistry.from_name('mdi.square-rounded-outline'), + self._btnGeneral = self.addItemTypeButton(ItemType.EVENT, IconRegistry.from_name('mdi.square-rounded-outline'), 'General event', 1, 0) - self._btnGoal = self._newItemTypeButton(ItemType.GOAL, IconRegistry.goal_icon('black', 'black'), 'Add new goal', - 1, 1) - self._btnConflict = self._newItemTypeButton(ItemType.CONFLICT, IconRegistry.conflict_icon('black', 'black'), + self._btnGoal = self.addItemTypeButton(ItemType.GOAL, IconRegistry.goal_icon('black', 'black'), 'Add new goal', + 1, 1) + self._btnConflict = self.addItemTypeButton(ItemType.CONFLICT, IconRegistry.conflict_icon('black', 'black'), 'Conflict', 1, 2) - self._btnDisturbance = self._newItemTypeButton(ItemType.DISTURBANCE, - IconRegistry.inciting_incident_icon('black'), + self._btnDisturbance = self.addItemTypeButton(ItemType.DISTURBANCE, + IconRegistry.inciting_incident_icon('black'), 'Inciting incident', 2, - 0) - self._btnBackstory = self._newItemTypeButton(ItemType.BACKSTORY, IconRegistry.backstory_icon('black', 'black'), + 0) + self._btnBackstory = self.addItemTypeButton(ItemType.BACKSTORY, IconRegistry.backstory_icon('black', 'black'), 'Backstory', 2, 1) self._grid.addWidget(QLabel('Narrative'), 3, 0, 1, 3) - self._btnQuestion = self._newItemTypeButton(ItemType.QUESTION, IconRegistry.from_name('ei.question-sign'), + self._btnQuestion = self.addItemTypeButton(ItemType.QUESTION, IconRegistry.from_name('ei.question-sign'), "Reader's question", 4, - 0) - self._btnSetup = self._newItemTypeButton(ItemType.SETUP, IconRegistry.from_name('ri.seedling-fill'), + 0) + self._btnSetup = self.addItemTypeButton(ItemType.SETUP, IconRegistry.from_name('ri.seedling-fill'), 'Setup and payoff', 4, 1) - self._btnForeshadowing = self._newItemTypeButton(ItemType.FORESHADOWING, - IconRegistry.from_name('mdi6.crystal-ball'), + self._btnForeshadowing = self.addItemTypeButton(ItemType.FORESHADOWING, + IconRegistry.from_name('mdi6.crystal-ball'), 'Foreshadowing', - 4, - 2) + 4, + 2) self._btnGeneral.setChecked(True) @@ -66,12 +66,12 @@ def showEvent(self, event: QShowEvent) -> None: class StickerSelectorWidget(SecondarySelectorWidget): def __init__(self, parent=None): super().__init__(parent) - self._btnComment = self._newItemTypeButton(ItemType.COMMENT, IconRegistry.from_name('mdi.comment-text-outline'), + self._btnComment = self.addItemTypeButton(ItemType.COMMENT, IconRegistry.from_name('mdi.comment-text-outline'), 'Add new comment', 0, 0) - self._btnTool = self._newItemTypeButton(ItemType.TOOL, IconRegistry.tool_icon('black', 'black'), 'Add new tool', - 0, 1) - self._btnCost = self._newItemTypeButton(ItemType.COST, IconRegistry.cost_icon('black', 'black'), 'Add new cost', - 1, 0) + self._btnTool = self.addItemTypeButton(ItemType.TOOL, IconRegistry.tool_icon('black', 'black'), 'Add new tool', + 0, 1) + self._btnCost = self.addItemTypeButton(ItemType.COST, IconRegistry.cost_icon('black', 'black'), 'Add new cost', + 1, 0) self._btnComment.setChecked(True) diff --git a/src/main/python/plotlyst/view/widget/utility.py b/src/main/python/plotlyst/view/widget/utility.py index 3e97dc41c..3789a91ae 100644 --- a/src/main/python/plotlyst/view/widget/utility.py +++ b/src/main/python/plotlyst/view/widget/utility.py @@ -40,7 +40,6 @@ from src.main.python.plotlyst.view.generated.resource_manager_dialog_ui import Ui_ResourceManagerDialog from src.main.python.plotlyst.view.icons import IconRegistry from src.main.python.plotlyst.view.layout import group -from src.main.python.plotlyst.view.style.button import apply_button_color from src.main.python.plotlyst.view.widget._icons import icons_registry from src.main.python.plotlyst.view.widget.button import SecondaryActionToolButton @@ -51,28 +50,46 @@ def __init__(self, color: str, parent=None): self.color = color self.setCheckable(True) pointy(self) - apply_button_color(self, self.color) + self.setIcon(IconRegistry.from_name('fa5s.circle', color=color)) + transparent(self) + self.setIconSize(QSize(24, 24)) self.installEventFilter(ButtonPressResizeEventFilter(self)) +BASE_COLORS = ['darkBlue', '#0077b6', '#00b4d8', '#007200', '#2a9d8f', '#94d2bd', '#ffe66d', '#ffd000', '#f48c06', + '#e85d04', + '#dc2f02', + '#ffc6ff', '#b5179e', '#7209b7', '#d6ccc2', '#6c757d', '#dda15e', '#bc6c25', 'black'] + + class ColorPicker(QWidget): colorPicked = pyqtSignal(QColor) - def __init__(self, parent=None): - super(ColorPicker, self).__init__(parent) - flow(self) + def __init__(self, parent=None, maxColumn: Optional[int] = None): + super().__init__(parent) + if maxColumn: + grid(self, 1, 1, 1) + else: + flow(self) self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Maximum) self.btnGroup = QButtonGroup(self) self.btnGroup.setExclusive(True) - for color in ['#0077b6', '#00b4d8', '#007200', '#2a9d8f', '#94d2bd', '#ffe66d', '#ffd000', '#f48c06', '#e85d04', - '#dc2f02', - '#ffc6ff', '#b5179e', '#7209b7', '#d6ccc2', '#6c757d', '#dda15e', '#bc6c25', 'black', 'white']: + row = -1 + for i, color in enumerate(BASE_COLORS): btn = ColorButton(color, self) self.btnGroup.addButton(btn) - self.layout().addWidget(btn) + if maxColumn: + if i % maxColumn == 0: + row += 1 + col = 0 + else: + col = i % maxColumn + self.layout().addWidget(btn, row, col) + else: + self.layout().addWidget(btn) self.btnGroup.buttonClicked.connect(self._clicked) def color(self) -> QColor: