2015-05-28 13:32:09 +12:00
|
|
|
#!/usr/bin/env python
|
2016-02-07 00:34:22 +13:00
|
|
|
# --!-- coding: utf8 --!--
|
|
|
|
from PyQt5.QtCore import pyqtSignal, pyqtProperty
|
|
|
|
from PyQt5.QtWidgets import QWidget
|
2016-03-04 06:55:57 +13:00
|
|
|
from manuskript.ui.views.sldImportance_ui import Ui_sldImportance
|
2016-02-07 00:34:22 +13:00
|
|
|
|
|
|
|
from manuskript.functions import toInt
|
|
|
|
|
2015-05-28 13:32:09 +12:00
|
|
|
|
|
|
|
class sldImportance(QWidget, Ui_sldImportance):
|
2015-05-31 16:03:07 +12:00
|
|
|
importanceChanged = pyqtSignal(str)
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-05-28 13:32:09 +12:00
|
|
|
def __init__(self, parent=None):
|
2015-06-24 04:22:39 +12:00
|
|
|
QWidget.__init__(self, parent)
|
2015-05-28 13:32:09 +12:00
|
|
|
self.setupUi(self)
|
2015-06-22 04:35:42 +12:00
|
|
|
self._column = 0
|
|
|
|
self._updating = False
|
|
|
|
self._index = None
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-05-31 16:03:07 +12:00
|
|
|
self.lastValue = -1
|
2015-05-28 13:32:09 +12:00
|
|
|
self.sld.valueChanged.connect(self.changed)
|
|
|
|
self.setValue(0)
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-05-31 16:03:07 +12:00
|
|
|
def getImportance(self):
|
|
|
|
return str(self.sld.value())
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-05-28 13:32:09 +12:00
|
|
|
def changed(self, v):
|
|
|
|
val = [
|
2015-06-08 22:01:45 +12:00
|
|
|
self.tr("Minor"),
|
|
|
|
self.tr("Secondary"),
|
|
|
|
self.tr("Main"),
|
2016-02-07 00:34:22 +13:00
|
|
|
]
|
2015-05-28 13:32:09 +12:00
|
|
|
self.lbl.setText(val[v])
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-05-31 16:03:07 +12:00
|
|
|
self.importanceChanged.emit(str(v))
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-06-22 04:35:42 +12:00
|
|
|
if self._index and not self._updating:
|
|
|
|
if str(v) != self._model.data(self._index):
|
|
|
|
self._updating = True
|
|
|
|
self._model.setData(self._index, str(v))
|
|
|
|
self._updating = False
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-05-28 13:32:09 +12:00
|
|
|
def setValue(self, v):
|
2016-02-07 00:34:22 +13:00
|
|
|
if v != self.lastValue:
|
2015-06-01 08:41:32 +12:00
|
|
|
self.sld.setValue(int(v) if v else 0)
|
|
|
|
self.changed(int(v) if v else 0)
|
2015-05-31 16:03:07 +12:00
|
|
|
self.lastValue = v
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-05-31 16:03:07 +12:00
|
|
|
def setProperty():
|
|
|
|
pass
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-06-22 04:35:42 +12:00
|
|
|
# MODEL / VIEW
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-06-22 04:35:42 +12:00
|
|
|
def setColumn(self, column):
|
|
|
|
self._column = column
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-06-22 04:35:42 +12:00
|
|
|
def setModel(self, model):
|
|
|
|
self._model = model
|
|
|
|
self._model.dataChanged.connect(self.update)
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-06-22 04:35:42 +12:00
|
|
|
def update(self, topLeft, bottomRight):
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-06-22 04:35:42 +12:00
|
|
|
if self._updating:
|
|
|
|
return
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-06-22 04:35:42 +12:00
|
|
|
if self._index:
|
|
|
|
if topLeft.row() <= self._index.row() <= bottomRight.row():
|
|
|
|
self.updateValue()
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-06-22 04:35:42 +12:00
|
|
|
def setCurrentModelIndex(self, index):
|
|
|
|
if index.isValid():
|
|
|
|
if index.column() != self._column:
|
|
|
|
index = index.sibling(index.row(), self._column)
|
|
|
|
self._index = index
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-06-22 04:35:42 +12:00
|
|
|
self.updateValue()
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-06-22 04:35:42 +12:00
|
|
|
def updateValue(self):
|
|
|
|
if self._index:
|
|
|
|
val = toInt(self._model.data(self._index))
|
|
|
|
if self.sld.value() != val:
|
|
|
|
self._updating = True
|
|
|
|
self.setValue(val)
|
|
|
|
self._updating = False
|
2016-02-07 00:34:22 +13:00
|
|
|
|
|
|
|
importance = pyqtProperty(str, fget=getImportance, fset=setValue, notify=importanceChanged)
|