Skip to content

Commit

Permalink
text editor
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Sep 23, 2024
1 parent d3c7cdd commit 57afbad
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/main/python/plotlyst/view/widget/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,9 +1380,10 @@ def __init__(self, parent=None):
self.layout().addWidget(self.lineSearch)


class DecoratedTextEdit(QTextEdit):
class DecoratedTextEdit(AutoAdjustableTextEdit):
def __init__(self, parent=None):
super().__init__(parent)
super().__init__(parent, height=75)
self._indentSize: int = 25
self._has_text = False
self._updateStylesheet()
self.textChanged.connect(self._onTextChanged)
Expand All @@ -1394,10 +1395,10 @@ def setEmoji(self, name: str, tooltip: str = ''):
self._decoration.setToolTip(tooltip)
self._decoration.setFont(emoji_font())
self._decoration.setText(emoji.emojize(name))
self._decoration.setGeometry(3, 10, 20, 20)
self._decoration.setGeometry(2, 4, self._indentSize, self._indentSize)

def _updateStylesheet(self):
self.setStyleSheet("QTextEdit {padding-left: 20px;}")
self.setStyleSheet(f"QTextEdit {{padding-left: {self._indentSize}px;}}")

def _indent(self, value: int):
cursor = self.textCursor()
Expand All @@ -1412,7 +1413,7 @@ def _onTextChanged(self):
if self.toPlainText():
if not self._has_text:
self.setStyleSheet('')
self._indent(20)
self._indent(self._indentSize)
self._has_text = True
elif self._has_text:
self._indent(0)
Expand Down
70 changes: 65 additions & 5 deletions src/main/python/plotlyst/view/widget/world/milieu.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from PyQt6.QtCore import pyqtSignal, Qt
from PyQt6.QtWidgets import QWidget, QLineEdit, QGraphicsColorizeEffect
from overrides import overrides
from qthandy import vbox, incr_font, vspacer, line, clear_layout, incr_icon, decr_icon, margins, spacer, hbox, grid
from qthandy import vbox, incr_font, vspacer, line, clear_layout, incr_icon, decr_icon, margins, spacer, hbox, grid, sp
from qthandy.filter import OpacityEventFilter, DisabledClickEventFilter
from qtmenu import MenuWidget

Expand All @@ -36,7 +36,8 @@
RequestMilieuDictionaryResetEvent
from plotlyst.service.cache import entities_registry
from plotlyst.service.persistence import RepositoryPersistenceManager
from plotlyst.view.common import fade_in, insert_before_the_end, DelayedSignalSlotConnector, push_btn, tool_btn, label
from plotlyst.view.common import fade_in, insert_before_the_end, DelayedSignalSlotConnector, push_btn, tool_btn, label, \
fade_out_and_gc
from plotlyst.view.icons import IconRegistry
from plotlyst.view.layout import group
from plotlyst.view.style.base import apply_white_menu
Expand Down Expand Up @@ -249,8 +250,22 @@ def icon(self) -> str:
elif self == LocationAttributeType.TEXTURE:
return 'mdi.hand'

def emoji(self) -> str:
if self == LocationAttributeType.SIGHT:
return ':eyes:'
elif self == LocationAttributeType.SOUND:
return ':musical_note:'
elif self == LocationAttributeType.SMELL:
return ':nose:'
elif self == LocationAttributeType.TASTE:
return ':tongue:'
elif self == LocationAttributeType.TEXTURE:
return ':hand_with_fingers_splayed:'


class LocationAttributeSetting(SettingBaseWidget):
settingChanged = pyqtSignal(LocationAttributeType, bool)

def __init__(self, attrType: LocationAttributeType, parent=None):
super().__init__(parent)
self._attrType = attrType
Expand All @@ -266,10 +281,26 @@ def __init__(self, attrType: LocationAttributeType, parent=None):

@overrides
def _clicked(self, toggled: bool):
pass
self.settingChanged.emit(self._attrType, toggled)


class LocationAttributeTextEdit(DecoratedTextEdit):
def __init__(self, attrType: LocationAttributeType, parent=None):
super().__init__(parent)
self.setProperty('rounded', True)
self.setProperty('white-bg', True)
desc = attrType.description()
self.setPlaceholderText(desc)
self.setMaximumWidth(600)
self.setToolTip(desc)
self.setEmoji(attrType.emoji(), desc)

sp(self).v_exp()


class LocationAttributeSelectorMenu(MenuWidget):
settingChanged = pyqtSignal(LocationAttributeType, bool)

def __init__(self, parent=None):
super().__init__(parent)
apply_white_menu(self)
Expand All @@ -281,6 +312,12 @@ def __init__(self, parent=None):
self.settingTexture = LocationAttributeSetting(LocationAttributeType.TEXTURE)
self.settingTexture.setChecked(False)

self.settingSight.settingChanged.connect(self.settingChanged)
self.settingSound.settingChanged.connect(self.settingChanged)
self.settingSmell.settingChanged.connect(self.settingChanged)
self.settingTaste.settingChanged.connect(self.settingChanged)
self.settingTexture.settingChanged.connect(self.settingChanged)

self.toggleDayNight = Toggle()
effect = QGraphicsColorizeEffect(self.toggleDayNight)
effect.setColor(Qt.GlobalColor.black)
Expand Down Expand Up @@ -340,7 +377,7 @@ def __init__(self, novel: Novel, parent=None):

self._attributesSelectorMenu = LocationAttributeSelectorMenu(self.btnAttributesEditor)
self._attributesSelectorMenu.toggleDayNight.toggled.connect(self._dayNightToggled)
# self._attributesSelectorMenu.principleToggled.connect(self._principleToggled)
self._attributesSelectorMenu.settingChanged.connect(self._settingChanged)
self.btnAttributes.clicked.connect(lambda: self._attributesSelectorMenu.exec())

self.wdgDayNightHeader = QWidget()
Expand All @@ -350,7 +387,12 @@ def __init__(self, novel: Novel, parent=None):
self.wdgDayNightHeader.setHidden(True)

self.wdgAttributes = QWidget()
grid(self.wdgAttributes)
self._gridAttributesLayout = grid(self.wdgAttributes)
spac = spacer()
sp(spac).h_preferred()
self._gridAttributesLayout.addWidget(spac, 25, 1, 1, 1)
margins(self.wdgAttributes, left=15)
self._gridAttributesLayout.setVerticalSpacing(15)

vbox(self)
self.layout().addWidget(self.lineEditName)
Expand All @@ -366,6 +408,10 @@ def __init__(self, novel: Novel, parent=None):

self.setVisible(False)

self._settingChanged(LocationAttributeType.SIGHT, True)
self._settingChanged(LocationAttributeType.SOUND, True)
self._settingChanged(LocationAttributeType.SMELL, True)

def setLocation(self, location: Location):
self.setVisible(True)
self._location = location
Expand Down Expand Up @@ -393,5 +439,19 @@ def _summaryChanged(self):
def _dayNightToggled(self, toggled: bool):
self.wdgDayNightHeader.setVisible(toggled)

def _settingChanged(self, attrType: LocationAttributeType, toggled: bool):
if toggled:
wdg = self._addAttribute(attrType)
fade_in(wdg)
else:
item = self._gridAttributesLayout.itemAtPosition(attrType.value, 0)
if item and item.widget():
fade_out_and_gc(self.wdgAttributes, item.widget())

def _addAttribute(self, attrType: LocationAttributeType) -> LocationAttributeTextEdit:
wdg = LocationAttributeTextEdit(attrType)
self._gridAttributesLayout.addWidget(wdg, attrType.value, 0, 1, 1)
return wdg

def _save(self):
self.repo.update_novel(self._novel)

0 comments on commit 57afbad

Please sign in to comment.