Skip to content

Commit

Permalink
color picker
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Sep 3, 2023
1 parent 12d6679 commit ea905b8
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 56 deletions.
18 changes: 0 additions & 18 deletions src/main/python/plotlyst/view/style/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
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] {
Expand Down Expand Up @@ -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;
}}
''')
18 changes: 14 additions & 4 deletions src/main/python/plotlyst/view/widget/character/network/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()))
self._connector.setIcon(IconRegistry.from_name(result[0], result[1].name()))
13 changes: 8 additions & 5 deletions src/main/python/plotlyst/view/widget/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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
Expand Down
40 changes: 20 additions & 20 deletions src/main/python/plotlyst/view/widget/story_map/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
35 changes: 26 additions & 9 deletions src/main/python/plotlyst/view/widget/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down

0 comments on commit ea905b8

Please sign in to comment.