mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-06-02 11:04:33 +12:00
Corrects a few bug, tweaks a thing or two
This commit is contained in:
parent
3dc5217554
commit
21de78c27b
|
@ -49,6 +49,11 @@ class outlineModel(QAbstractItemModel):
|
||||||
col = column
|
col = column
|
||||||
return self.createIndex(row, col, item)
|
return self.createIndex(row, col, item)
|
||||||
|
|
||||||
|
def ID(self, index):
|
||||||
|
if index.isValid():
|
||||||
|
item = index.internalPointer()
|
||||||
|
return item.ID()
|
||||||
|
|
||||||
def getIndexByID(self, ID):
|
def getIndexByID(self, ID):
|
||||||
"Returns the index of item whose ID is ``ID``. If none, returns QModelIndex()."
|
"Returns the index of item whose ID is ``ID``. If none, returns QModelIndex()."
|
||||||
def search(item):
|
def search(item):
|
||||||
|
@ -240,12 +245,19 @@ class outlineModel(QAbstractItemModel):
|
||||||
items = []
|
items = []
|
||||||
for child in root:
|
for child in root:
|
||||||
if child.tag == "outlineItem":
|
if child.tag == "outlineItem":
|
||||||
items.append(outlineItem(xml=ET.tostring(child)))
|
item = outlineItem(xml=ET.tostring(child))
|
||||||
|
items.append(item)
|
||||||
|
|
||||||
if not items:
|
if not items:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return self.insertItems(items, beginRow, parent)
|
r = self.insertItems(items, beginRow, parent)
|
||||||
|
|
||||||
|
if action == Qt.CopyAction:
|
||||||
|
for item in items:
|
||||||
|
item.getUniqueID()
|
||||||
|
|
||||||
|
return r
|
||||||
|
|
||||||
################# ADDING AND REMOVING #################
|
################# ADDING AND REMOVING #################
|
||||||
|
|
||||||
|
@ -362,7 +374,7 @@ class outlineModel(QAbstractItemModel):
|
||||||
path = path.split(",")
|
path = path.split(",")
|
||||||
item = self.rootItem
|
item = self.rootItem
|
||||||
for p in path:
|
for p in path:
|
||||||
if p != "":
|
if p != "" and int(p) < item.childCount():
|
||||||
item = item.child(int(p))
|
item = item.child(int(p))
|
||||||
return self.indexFromItem(item)
|
return self.indexFromItem(item)
|
||||||
|
|
||||||
|
@ -577,6 +589,7 @@ class outlineItem():
|
||||||
|
|
||||||
def removeChild(self, row):
|
def removeChild(self, row):
|
||||||
self.childItems.pop(row)
|
self.childItems.pop(row)
|
||||||
|
self.updateWordCount()
|
||||||
|
|
||||||
def parent(self):
|
def parent(self):
|
||||||
return self._parent
|
return self._parent
|
||||||
|
|
|
@ -42,6 +42,33 @@ def infoForRef(ref):
|
||||||
else:
|
else:
|
||||||
return qApp.translate("references", "Unknown reference: {}.").format(ref)
|
return qApp.translate("references", "Unknown reference: {}.").format(ref)
|
||||||
|
|
||||||
|
def tooltipForRef(ref):
|
||||||
|
match = re.fullmatch("::(\w):(\d+?)::", ref)
|
||||||
|
if match:
|
||||||
|
_type = match.group(1)
|
||||||
|
_ref = match.group(2)
|
||||||
|
|
||||||
|
if _type == "T":
|
||||||
|
m = mainWindow().mdlOutline
|
||||||
|
idx = m.getIndexByID(_ref)
|
||||||
|
|
||||||
|
if not idx.isValid():
|
||||||
|
return qApp.translate("references", "Unknown reference: {}.").format(ref)
|
||||||
|
|
||||||
|
item = idx.internalPointer()
|
||||||
|
|
||||||
|
tooltip = qApp.translate("references", "Text: <b>{}</b>").format(item.title())
|
||||||
|
tooltip += "<br><i>{}</i>".format(item.path())
|
||||||
|
|
||||||
|
return tooltip
|
||||||
|
|
||||||
|
elif _type == "C":
|
||||||
|
m = mainWindow().mdlPersos
|
||||||
|
name = m.item(int(_ref), Perso.name.value).text()
|
||||||
|
return qApp.translate("references", "Character: <b>{}</b>").format(name)
|
||||||
|
|
||||||
|
else:
|
||||||
|
return qApp.translate("references", "Unknown reference: {}.").format(ref)
|
||||||
|
|
||||||
def openReference(ref):
|
def openReference(ref):
|
||||||
match = re.fullmatch("::(\w):(\d+?)::", ref)
|
match = re.fullmatch("::(\w):(\d+?)::", ref)
|
||||||
|
|
|
@ -24,6 +24,14 @@ class completer(QWidget, Ui_completer):
|
||||||
self.outlineModel = mainWindow().mdlOutline
|
self.outlineModel = mainWindow().mdlOutline
|
||||||
self.persoModel = mainWindow().mdlPersos
|
self.persoModel = mainWindow().mdlPersos
|
||||||
|
|
||||||
|
self.populateTimer = QTimer(self)
|
||||||
|
self.populateTimer.setSingleShot(True)
|
||||||
|
self.populateTimer.setInterval(500)
|
||||||
|
self.populateTimer.timeout.connect(self.populate)
|
||||||
|
self.populateTimer.stop()
|
||||||
|
self.outlineModel.dataChanged.connect(self.populateTimer.start)
|
||||||
|
self.persoModel.dataChanged.connect(self.populateTimer.start)
|
||||||
|
|
||||||
self.data = {}
|
self.data = {}
|
||||||
|
|
||||||
self.populate()
|
self.populate()
|
||||||
|
|
|
@ -20,11 +20,11 @@ class outlineBasics(QAbstractItemView):
|
||||||
return sel
|
return sel
|
||||||
|
|
||||||
def mouseReleaseEvent(self, event):
|
def mouseReleaseEvent(self, event):
|
||||||
|
|
||||||
if event.button() == Qt.RightButton:
|
if event.button() == Qt.RightButton:
|
||||||
|
|
||||||
self.menu = self.makePopupMenu()
|
self.menu = self.makePopupMenu()
|
||||||
self.menu.popup(event.globalPos())
|
self.menu.popup(event.globalPos())
|
||||||
|
else:
|
||||||
|
QAbstractItemView.mouseReleaseEvent(self, event)
|
||||||
|
|
||||||
def makePopupMenu(self):
|
def makePopupMenu(self):
|
||||||
index = self.currentIndex()
|
index = self.currentIndex()
|
||||||
|
|
|
@ -123,7 +123,7 @@ class textEditCompleter(textEditView):
|
||||||
if ref:
|
if ref:
|
||||||
if not qApp.overrideCursor():
|
if not qApp.overrideCursor():
|
||||||
qApp.setOverrideCursor(Qt.PointingHandCursor)
|
qApp.setOverrideCursor(Qt.PointingHandCursor)
|
||||||
QToolTip.showText(self.mapToGlobal(event.pos()), infoForRef(ref))
|
QToolTip.showText(self.mapToGlobal(event.pos()), tooltipForRef(ref))
|
||||||
|
|
||||||
def mouseReleaseEvent(self, event):
|
def mouseReleaseEvent(self, event):
|
||||||
textEditView.mouseReleaseEvent(self, event)
|
textEditView.mouseReleaseEvent(self, event)
|
||||||
|
@ -147,7 +147,6 @@ class textEditCompleter(textEditView):
|
||||||
cursor.setPosition(txt.start())
|
cursor.setPosition(txt.start())
|
||||||
r = self.cursorRect(cursor)
|
r = self.cursorRect(cursor)
|
||||||
r.setWidth(fm.width(txt.group(0)))
|
r.setWidth(fm.width(txt.group(0)))
|
||||||
r = r.adjusted(-2, -2, 2, 2)
|
|
||||||
refs.append(r)
|
refs.append(r)
|
||||||
self.refRects = refs
|
self.refRects = refs
|
||||||
|
|
||||||
|
|
|
@ -57,9 +57,9 @@ class treeView(QTreeView, dndView, outlineBasics):
|
||||||
menu.insertSeparator(first)
|
menu.insertSeparator(first)
|
||||||
|
|
||||||
# Expand /collapse item
|
# Expand /collapse item
|
||||||
if len(self.selectedIndexes()) != 0:
|
if mouseIndex.isValid():
|
||||||
index = self.currentIndex()
|
#index = self.currentIndex()
|
||||||
item = index.internalPointer()
|
item = mouseIndex.internalPointer()
|
||||||
self.actExpand = QAction(self.tr("Expand {}").format(item.title()), menu)
|
self.actExpand = QAction(self.tr("Expand {}").format(item.title()), menu)
|
||||||
self.actExpand.triggered.connect(self.expandCurrentIndex)
|
self.actExpand.triggered.connect(self.expandCurrentIndex)
|
||||||
menu.insertAction(first, self.actExpand)
|
menu.insertAction(first, self.actExpand)
|
||||||
|
@ -88,7 +88,7 @@ class treeView(QTreeView, dndView, outlineBasics):
|
||||||
|
|
||||||
def expandCurrentIndex(self, index=None):
|
def expandCurrentIndex(self, index=None):
|
||||||
if index is None or type(index) == bool:
|
if index is None or type(index) == bool:
|
||||||
index = self.currentIndex()
|
index = self._indexesToOpen[0] #self.currentIndex()
|
||||||
|
|
||||||
self.expand(index)
|
self.expand(index)
|
||||||
for i in range(self.model().rowCount(index)):
|
for i in range(self.model().rowCount(index)):
|
||||||
|
@ -97,7 +97,7 @@ class treeView(QTreeView, dndView, outlineBasics):
|
||||||
|
|
||||||
def collapseCurrentIndex(self, index=None):
|
def collapseCurrentIndex(self, index=None):
|
||||||
if index is None or type(index) == bool:
|
if index is None or type(index) == bool:
|
||||||
index = self.currentIndex()
|
index = self._indexesToOpen[0] #self.currentIndex()
|
||||||
|
|
||||||
self.collapse(index)
|
self.collapse(index)
|
||||||
for i in range(self.model().rowCount(index)):
|
for i in range(self.model().rowCount(index)):
|
||||||
|
@ -114,8 +114,4 @@ class treeView(QTreeView, dndView, outlineBasics):
|
||||||
# on right click
|
# on right click
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
QTreeView.mousePressEvent(self, event)
|
QTreeView.mousePressEvent(self, event)
|
||||||
|
|
||||||
def mouseReleaseEvent(self, event):
|
|
||||||
QTreeView.mouseReleaseEvent(self, event)
|
|
||||||
outlineBasics.mouseReleaseEvent(self, event)
|
|
Loading…
Reference in a new issue