Skip to content

Commit

Permalink
164 lvlptr mouse move (#189)
Browse files Browse the repository at this point in the history
* LvlPtr selecting works

* LvlPtr selecting works
  • Loading branch information
tieugene authored Nov 14, 2022
1 parent 0b2cc89 commit d477699
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 12 deletions.
3 changes: 2 additions & 1 deletion iosc/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# (moved)
FONT_TOPBAR = QFont('mono', 8) # font of timeline ticks labels
FONT_DND = FONT_TOPBAR
CURSOR_PTR = Qt.SplitHCursor
CURSOR_PTR_V = Qt.SplitHCursor
CURSOR_PTR_H = Qt.SplitVCursor
COLOR_LABEL_Z = Qt.black
BRUSH_LABEL_Z = QBrush(Qt.white)
COLOR_LABEL_X = Qt.white # top xPtr label font color
Expand Down
2 changes: 1 addition & 1 deletion iosc/core/mycomtrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def v_max(self) -> float:

def get_mult(self, ps: bool) -> float:
"""
Get multiplier
Get multiplier between pri/sec
:param ps:
:return: Multiplier
"""
Expand Down
71 changes: 61 additions & 10 deletions iosc/sig/widget/ptr.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def i(self) -> int:
def _switch_cursor(self, selected: bool):
if selected:
self.__cursor = self._oscwin.cursor()
cur = iosc.const.CURSOR_PTR
cur = iosc.const.CURSOR_PTR_V
else:
cur = self.__cursor
self._oscwin.setCursor(cur)
Expand Down Expand Up @@ -416,6 +416,7 @@ def __init__(self, cp: QCustomPlot):
super().__init__(cp)
self.setColor(Qt.white) # text

__cursor: QCursor
__ss: 'AnalogSignalSuit'
__oscwin: 'ComtradeWidget'
__uid: int # uniq id
Expand All @@ -431,19 +432,36 @@ def __init__(self, ss: 'AnalogSignalSuit', uid: int):
self.__tip = self._Tip(self.parentPlot())
# self.setPen(iosc.const.PEN_PTR_OMP)
self.__set_color()
self.y_reduced = self.__ss.lvl_ptr[self.__uid][1]
self.__mult = max(max(self.__ss.signal.v_max, 0), abs(min(0, self.__ss.signal.v_min))) # mult-r rediced<>real
self.__slot_update_text()
self.y_reduced = self.__ss.lvl_ptr[self.__uid][1]
self.__ss.lvl_ptr[self.__uid][0] = self
self.__oscwin.lvl_ptr_uids.add(self.__uid)
self.selectionChanged.connect(self.__selection_chg)
self.signal_rmb_clicked.connect(self.__slot_context_menu)
# self.__oscwin.signal_chged_shift.connect(self.__slot_update_text) # behavior undefined
self.__oscwin.signal_chged_pors.connect(self.__slot_update_text)

@property
def selection(self) -> bool:
return self.selected()

@selection.setter
def selection(self, val: bool):
self.setSelected(val)
self.parentPlot().ptr_selected = val

@property
def uid(self) -> int:
return self.__uid

@property
def y_reduced_min(self) -> float:
return self.__ss.signal.v_min / self.__mult

@property
def y_reduced_max(self) -> float:
return self.__ss.signal.v_max / self.__mult

@property
def y_reduced(self) -> float:
return self.point1.coords().y()
Expand All @@ -458,6 +476,7 @@ def y_reduced(self, y: float):
self.point2.setCoords(self.__oscwin.osc.x_max, y)
self.__tip.position.setCoords(0, self.y_reduced) # FIXME: x = ?
self.__tip.setPositionAlignment(Qt.AlignLeft | (Qt.AlignTop if self.y_reduced > 0 else Qt.AlignBottom))
self.__slot_update_text()

@property
def y_real(self) -> float:
Expand Down Expand Up @@ -490,18 +509,51 @@ def __slot_update_text(self):
self.__tip.setText("L%d: %s" % (self.__uid, self.__ss.sig2str(self.y_real)))
self.parentPlot().replot() # TODO: don't to this on total repaint

def mousePressEvent(self, event: QMouseEvent, _): # rmb click start
if event.button() == Qt.RightButton:
def mousePressEvent(self, event: QMouseEvent, _):
if event.button() == Qt.LeftButton:
event.accept()
self.selection = True
elif event.button() == Qt.RightButton:
event.accept() # for signal_rmb_clicked
else:
event.ignore()

def mouseReleaseEvent(self, event: QMouseEvent, _): # rmb click end
if event.button() == Qt.RightButton:
def mouseReleaseEvent(self, event: QMouseEvent, _):
if event.button() == Qt.LeftButton:
if self.selection:
event.accept()
self.selection = False
elif event.button() == Qt.RightButton:
self.signal_rmb_clicked.emit(event.pos())
else:
event.ignore()

def mouseMoveEvent(self, event: QMouseEvent, pos: QPointF):
"""
:param event:
:param pos: Where mouse was pressed (mousePressEvent), not changing each step; unusual
:note: self.mouseMoveEvent() unusable because points to click position
"""
if not self.selected(): # protection against 2click
event.ignore()
return
event.accept()
y_reduced_new = self.parentPlot().yAxis.pixelToCoord(event.pos().y())
if self.y_reduced_min <= y_reduced_new <= self.y_reduced_max:
self.y_reduced = y_reduced_new

def __switch_cursor(self, selected: bool):
if selected:
self.__cursor = self.__oscwin.cursor()
cur = iosc.const.CURSOR_PTR_H
else:
cur = self.__cursor
self.__oscwin.setCursor(cur)

def __selection_chg(self, selection: bool):
self.__switch_cursor(selection)
self.parentPlot().replot() # update selection decoration

def __slot_context_menu(self, pos: QPointF):
context_menu = QMenu()
action_edit = context_menu.addAction("Edit...")
Expand All @@ -517,13 +569,12 @@ def __edit_self(self):
# pors all values
form = LvlPtrDialog((
self.__y_pors(self.y_real),
self.__y_pors(min(self.__ss.signal.value)),
self.__y_pors(max(self.__ss.signal.value))
self.__y_pors(self.__ss.signal.v_min),
self.__y_pors(self.__ss.signal.v_max)
))
if form.exec_():
# unpors back
self.y_real = form.f_val.value() / self.__ss.signal.get_mult(self.__oscwin.show_sec)
self.__slot_update_text()

def suicide(self):
self.__ss.lvl_ptr[self.__uid][1] = self.y_reduced
Expand Down

0 comments on commit d477699

Please sign in to comment.