Skip to content

Commit

Permalink
- 为数字标记图元新增双击修改对话框
Browse files Browse the repository at this point in the history
  • Loading branch information
YaoXuanZhi committed Dec 25, 2024
1 parent 7cc2288 commit 28d333a
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from .pin_window import *
from .app_dpi_helper import *
from .ring_color_selector_dialog import RingColorSelectorDialog
from .text_modify_dialog import TextModifyDialog
46 changes: 46 additions & 0 deletions src/base/text_modify_dialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# coding:utf-8
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from qfluentwidgets import *

class LineEditPlus(LineEdit):
finalTextChanged = pyqtSignal(str)
def __init__(self, oldText: str, parent=None):
super().__init__(parent)
self.oldText = oldText
self.setText(oldText)
self.setPlaceholderText(oldText)
# self.setClearButtonEnabled(True)
self.setAlignment(Qt.AlignCenter)
self.setValidator(QIntValidator())

def keyPressEvent(self, a0: QKeyEvent) -> None:
if a0.key() == Qt.Key_Return or a0.key() == Qt.Key_Enter:
self.finalTextChanged.emit(self.text())
super().keyPressEvent(a0)

class TextModifyDialog(MaskDialogBase):
finalTextChanged = pyqtSignal(str)

def __init__(self, oldText: str, parent=None):
super().__init__(parent)
self.lineEdit = LineEditPlus(oldText)
self.lineEdit.finalTextChanged.connect(self.finalTextChanged)
self.contentLayout = QVBoxLayout(self.widget)
self.__initWidget()

def __initWidget(self):
self.setShadowEffect(60, (0, 10), QColor(0, 0, 0, 80))
# self.setMaskColor(QColor(0, 0, 0, 2)) # 几乎透明
self.setMaskColor(QColor(0, 0, 0, 30)) # 半透明
self.__initLayout()

def __initLayout(self):
self._hBoxLayout.setContentsMargins(0, 0, 0, 0)
self.contentLayout.setContentsMargins(0, 0, 0, 0)
self.contentLayout.addWidget(self.lineEdit, 0, Qt.AlignCenter)

def showEvent(self, e):
self.lineEdit.setFocus()
return super().showEvent(e)
6 changes: 6 additions & 0 deletions src/canvas_editor/canvas_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
self.currentItem.setPos(targetPos)
self.__completeDraw(self.currentItem)
elif self.currentDrawActionEnum == DrawActionEnum.UseNumberMarker:
# 如果当前位置下已经存在一个数字标记图元,则不再创建新的
for item0 in self.itemList:
if isinstance(item0, CanvasNumberMarkerItem):
if item0.sceneBoundingRect().contains(event.scenePos()):
return super().mousePressEvent(event)

self.currentItem = CanvasNumberMarkerItem(QRectF(0, 0, 20, 20))
self.__startDraw(self.currentItem)
targetPos.setX(
Expand Down
18 changes: 17 additions & 1 deletion src/canvas_item/canvas_number_marker_item.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=utf-8
from .canvas_util import *

from base import *

class CanvasNumberMarkerItem(QGraphicsRectItem):
"""
Expand Down Expand Up @@ -31,6 +31,22 @@ def applyShadow(self):
self.shadowEffect.setOffset(5 * self.devicePixelRatio, 5 * self.devicePixelRatio) # 阴影的偏移量
self.setGraphicsEffect(self.shadowEffect)

def mouseDoubleClickEvent(self, event: QGraphicsSceneMouseEvent):
if(event.button() == Qt.MouseButton.LeftButton):
self.textDialog = TextModifyDialog(f"{self.index}", self.scene().views()[0])
self.textDialog.finalTextChanged.connect(self.__finalTextChanged)
self.textDialog.exec()
return
return super().mouseDoubleClickEvent(event)

def __finalTextChanged(self, text: str):
try:
self.textDialog.close()
self.index = int(text)
self.update()
except Exception as e:
pass

def removeShadow(self):
self.setGraphicsEffect(None)
delattr(self, "shadowEffect")
Expand Down
1 change: 1 addition & 0 deletions src/extend_widgets/bubble_tip.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def make(position: BubbleTipTailPosition):
BubbleTipTailPosition.AUTO: AutoTailBubbleTipManager,
BubbleTipTailPosition.TOP_LEFT_AUTO: TopLeftAutoTailBubbleTipManager,
BubbleTipTailPosition.BOTTOM_LEFT_AUTO: BottomLeftAutoTailBubbleTipManager,
BubbleTipTailPosition.BOTTOM: BottomTailBubbleTipManager,
}

if position not in managers:
Expand Down

0 comments on commit 28d333a

Please sign in to comment.