mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-06-02 19:14:32 +12:00
Merge pull request #690 from nagolinc/addWorldPlotCharacterButtons
added 3 buttons to the textEditView that allow quickly adding new items
This commit is contained in:
commit
06aab9ce62
|
@ -378,8 +378,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||||
else:
|
else:
|
||||||
self.chkPersoPOV.setCheckState(Qt.Unchecked)
|
self.chkPersoPOV.setCheckState(Qt.Unchecked)
|
||||||
|
|
||||||
self.chkPersoPOV.stateChanged.connect(self.lstCharacters.changeCharacterPOVState, F.AUC)
|
try:
|
||||||
self.chkPersoPOV.setEnabled(len(self.mdlOutline.findItemsByPOV(ID)) == 0)
|
self.chkPersoPOV.stateChanged.connect(self.lstCharacters.changeCharacterPOVState, F.AUC)
|
||||||
|
self.chkPersoPOV.setEnabled(len(self.mdlOutline.findItemsByPOV(ID)) == 0)
|
||||||
|
except TypeError:
|
||||||
|
#don't know what's up with this
|
||||||
|
pass
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# PLOTS
|
# PLOTS
|
||||||
|
|
|
@ -165,14 +165,17 @@ class characterModel(QAbstractItemModel):
|
||||||
# ADDING / REMOVING
|
# ADDING / REMOVING
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
def addCharacter(self, importance = 0):
|
def addCharacter(self, importance = 0, name="New character"):
|
||||||
"""
|
"""
|
||||||
Creates a new character
|
Creates a new character
|
||||||
@param importance: the importance level of the character
|
@param importance: the importance level of the character
|
||||||
@return: the character
|
@return: the character
|
||||||
"""
|
"""
|
||||||
c = Character(model=self, name=self.tr("New character"), importance = importance)
|
if not name:
|
||||||
self.beginInsertRows(QModelIndex(), len(self.characters), len(self.characters))
|
name="New Character"
|
||||||
|
c = Character(model=self, name=self.tr(name), importance = importance)
|
||||||
|
self.beginInsertRows(QModelIndex(), len(
|
||||||
|
self.characters), len(self.characters))
|
||||||
self.characters.append(c)
|
self.characters.append(c)
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
return c
|
return c
|
||||||
|
@ -184,7 +187,8 @@ class characterModel(QAbstractItemModel):
|
||||||
@return: nothing
|
@return: nothing
|
||||||
"""
|
"""
|
||||||
c = self.getCharacterByID(ID)
|
c = self.getCharacterByID(ID)
|
||||||
self.beginRemoveRows(QModelIndex(), self.characters.index(c), self.characters.index(c))
|
self.beginRemoveRows(QModelIndex(), self.characters.index(
|
||||||
|
c), self.characters.index(c))
|
||||||
self.characters.remove(c)
|
self.characters.remove(c)
|
||||||
self.endRemoveRows()
|
self.endRemoveRows()
|
||||||
|
|
||||||
|
@ -204,7 +208,8 @@ class characterModel(QAbstractItemModel):
|
||||||
def addCharacterInfo(self, ID):
|
def addCharacterInfo(self, ID):
|
||||||
c = self.getCharacterByID(ID)
|
c = self.getCharacterByID(ID)
|
||||||
self.beginInsertRows(c.index(), len(c.infos), len(c.infos))
|
self.beginInsertRows(c.index(), len(c.infos), len(c.infos))
|
||||||
c.infos.append(CharacterInfo(c, description="Description", value="Value"))
|
c.infos.append(CharacterInfo(
|
||||||
|
c, description="Description", value="Value"))
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
|
|
||||||
mainWindow().updatePersoInfoView()
|
mainWindow().updatePersoInfoView()
|
||||||
|
@ -228,6 +233,7 @@ class characterModel(QAbstractItemModel):
|
||||||
# CHARACTER
|
# CHARACTER
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
class Character():
|
class Character():
|
||||||
def __init__(self, model, name="No name", importance = 0):
|
def __init__(self, model, name="No name", importance = 0):
|
||||||
self._model = model
|
self._model = model
|
||||||
|
@ -245,6 +251,9 @@ class Character():
|
||||||
def name(self):
|
def name(self):
|
||||||
return self._data[C.name.value]
|
return self._data[C.name.value]
|
||||||
|
|
||||||
|
def setName(self, value):
|
||||||
|
self._data[C.name.value] = value
|
||||||
|
|
||||||
def importance(self):
|
def importance(self):
|
||||||
return self._data[C.importance.value]
|
return self._data[C.importance.value]
|
||||||
|
|
||||||
|
@ -316,6 +325,7 @@ class Character():
|
||||||
r.append((i.description, i.value))
|
r.append((i.description, i.value))
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
class CharacterInfo():
|
class CharacterInfo():
|
||||||
def __init__(self, character, description="", value=""):
|
def __init__(self, character, description="", value=""):
|
||||||
self.description = description
|
self.description = description
|
||||||
|
|
|
@ -73,7 +73,7 @@ class plotModel(QStandardItemModel):
|
||||||
if i == row:
|
if i == row:
|
||||||
importance = self.item(i, Plot.importance).text()
|
importance = self.item(i, Plot.importance).text()
|
||||||
return importance
|
return importance
|
||||||
return "0" # Default to "Minor"
|
return "0" # Default to "Minor"
|
||||||
|
|
||||||
def getSubPlotTextsByID(self, plotID, subplotRaw):
|
def getSubPlotTextsByID(self, plotID, subplotRaw):
|
||||||
"""Returns a tuple (name, summary) for the subplot whose raw in the model
|
"""Returns a tuple (name, summary) for the subplot whose raw in the model
|
||||||
|
@ -102,12 +102,15 @@ class plotModel(QStandardItemModel):
|
||||||
# ADDING / REMOVING
|
# ADDING / REMOVING
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
def addPlot(self):
|
def addPlot(self, name="New plot"):
|
||||||
p = QStandardItem(self.tr("New plot"))
|
if not name:
|
||||||
|
name="New Plot"
|
||||||
|
p = QStandardItem(self.tr(name))
|
||||||
_id = QStandardItem(self.getUniqueID())
|
_id = QStandardItem(self.getUniqueID())
|
||||||
importance = QStandardItem(str(0))
|
importance = QStandardItem(str(0))
|
||||||
self.appendRow([p, _id, importance, QStandardItem("Characters"),
|
self.appendRow([p, _id, importance, QStandardItem("Characters"),
|
||||||
QStandardItem(), QStandardItem(), QStandardItem("Resolution steps")])
|
QStandardItem(), QStandardItem(), QStandardItem("Resolution steps")])
|
||||||
|
return p, _id
|
||||||
|
|
||||||
def getUniqueID(self, parent=QModelIndex()):
|
def getUniqueID(self, parent=QModelIndex()):
|
||||||
"""Returns an unused ID"""
|
"""Returns an unused ID"""
|
||||||
|
@ -147,8 +150,8 @@ class plotModel(QStandardItemModel):
|
||||||
|
|
||||||
def data(self, index, role=Qt.DisplayRole):
|
def data(self, index, role=Qt.DisplayRole):
|
||||||
if index.parent().isValid() and \
|
if index.parent().isValid() and \
|
||||||
index.parent().column() == Plot.steps and \
|
index.parent().column() == Plot.steps and \
|
||||||
index.column() == PlotStep.meta:
|
index.column() == PlotStep.meta:
|
||||||
if role == Qt.TextAlignmentRole:
|
if role == Qt.TextAlignmentRole:
|
||||||
return Qt.AlignRight | Qt.AlignVCenter
|
return Qt.AlignRight | Qt.AlignVCenter
|
||||||
elif role == Qt.ForegroundRole:
|
elif role == Qt.ForegroundRole:
|
||||||
|
@ -186,7 +189,8 @@ class plotModel(QStandardItemModel):
|
||||||
# Don't know why, if summary is in third position, then drag/drop deletes it...
|
# Don't know why, if summary is in third position, then drag/drop deletes it...
|
||||||
parentItem.appendRow([p, _id, QStandardItem(), summary])
|
parentItem.appendRow([p, _id, QStandardItem(), summary])
|
||||||
# Select last index
|
# Select last index
|
||||||
self.mw.lstSubPlots.setCurrentIndex(parent.child(self.rowCount(parent) - 1, 0))
|
self.mw.lstSubPlots.setCurrentIndex(
|
||||||
|
parent.child(self.rowCount(parent) - 1, 0))
|
||||||
|
|
||||||
def removeSubPlot(self):
|
def removeSubPlot(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -14,6 +14,8 @@ from manuskript.models import outlineModel, outlineItem
|
||||||
from manuskript.ui.highlighters import BasicHighlighter
|
from manuskript.ui.highlighters import BasicHighlighter
|
||||||
from manuskript.ui import style as S
|
from manuskript.ui import style as S
|
||||||
from manuskript.functions import Spellchecker
|
from manuskript.functions import Spellchecker
|
||||||
|
from manuskript.models.characterModel import Character, CharacterInfo
|
||||||
|
|
||||||
|
|
||||||
class textEditView(QTextEdit):
|
class textEditView(QTextEdit):
|
||||||
def __init__(self, parent=None, index=None, html=None, spellcheck=None,
|
def __init__(self, parent=None, index=None, html=None, spellcheck=None,
|
||||||
|
@ -165,9 +167,9 @@ class textEditView(QTextEdit):
|
||||||
|
|
||||||
def loadFontSettings(self):
|
def loadFontSettings(self):
|
||||||
if self._fromTheme or \
|
if self._fromTheme or \
|
||||||
not self._index or \
|
not self._index or \
|
||||||
type(self._index.model()) != outlineModel or \
|
type(self._index.model()) != outlineModel or \
|
||||||
self._column != Outline.text:
|
self._column != Outline.text:
|
||||||
return
|
return
|
||||||
|
|
||||||
opt = settings.textEditor
|
opt = settings.textEditor
|
||||||
|
@ -175,7 +177,7 @@ class textEditView(QTextEdit):
|
||||||
f.fromString(opt["font"])
|
f.fromString(opt["font"])
|
||||||
background = (opt["background"] if not opt["backgroundTransparent"]
|
background = (opt["background"] if not opt["backgroundTransparent"]
|
||||||
else "transparent")
|
else "transparent")
|
||||||
foreground = opt["fontColor"] # if not opt["backgroundTransparent"]
|
foreground = opt["fontColor"] # if not opt["backgroundTransparent"]
|
||||||
# else S.text
|
# else S.text
|
||||||
# self.setFont(f)
|
# self.setFont(f)
|
||||||
self.setStyleSheet("""QTextEdit{{
|
self.setStyleSheet("""QTextEdit{{
|
||||||
|
@ -187,15 +189,16 @@ class textEditView(QTextEdit):
|
||||||
{maxWidth}
|
{maxWidth}
|
||||||
}}
|
}}
|
||||||
""".format(
|
""".format(
|
||||||
bg=background,
|
bg=background,
|
||||||
foreground=foreground,
|
foreground=foreground,
|
||||||
ff=f.family(),
|
ff=f.family(),
|
||||||
fs="{}pt".format(str(f.pointSize())),
|
fs="{}pt".format(str(f.pointSize())),
|
||||||
mTB = opt["marginsTB"],
|
mTB=opt["marginsTB"],
|
||||||
mLR = opt["marginsLR"],
|
mLR=opt["marginsLR"],
|
||||||
maxWidth = "max-width: {}px;".format(opt["maxWidth"]) if opt["maxWidth"] else "",
|
maxWidth="max-width: {}px;".format(
|
||||||
)
|
opt["maxWidth"]) if opt["maxWidth"] else "",
|
||||||
)
|
)
|
||||||
|
)
|
||||||
self._defaultFontSize = f.pointSize()
|
self._defaultFontSize = f.pointSize()
|
||||||
|
|
||||||
# We set the parent background to the editor's background in case
|
# We set the parent background to the editor's background in case
|
||||||
|
@ -207,11 +210,11 @@ class textEditView(QTextEdit):
|
||||||
QWidget#{name}{{
|
QWidget#{name}{{
|
||||||
background: {bg};
|
background: {bg};
|
||||||
}}""".format(
|
}}""".format(
|
||||||
# We style by name, otherwise all inheriting widgets get the same
|
# We style by name, otherwise all inheriting widgets get the same
|
||||||
# colored background, for example context menu.
|
# colored background, for example context menu.
|
||||||
name=self.parent().objectName(),
|
name=self.parent().objectName(),
|
||||||
bg=background,
|
bg=background,
|
||||||
))
|
))
|
||||||
|
|
||||||
cf = QTextCharFormat()
|
cf = QTextCharFormat()
|
||||||
# cf.setFont(f)
|
# cf.setFont(f)
|
||||||
|
@ -472,18 +475,73 @@ class textEditView(QTextEdit):
|
||||||
QAction.__init__(self, *args)
|
QAction.__init__(self, *args)
|
||||||
|
|
||||||
self.triggered.connect(lambda x: self.correct.emit(
|
self.triggered.connect(lambda x: self.correct.emit(
|
||||||
str(self.text())))
|
str(self.text())))
|
||||||
|
|
||||||
def contextMenuEvent(self, event):
|
def contextMenuEvent(self, event):
|
||||||
# Based on http://john.nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check/
|
# Based on http://john.nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check/
|
||||||
popup_menu = self.createStandardContextMenu()
|
popup_menu = self.createStandardContextMenu()
|
||||||
popup_menu.exec_(event.globalPos())
|
popup_menu.exec_(event.globalPos())
|
||||||
|
|
||||||
|
def newCharacter(self):
|
||||||
|
text = self.sender().data()
|
||||||
|
print("new character!", text)
|
||||||
|
# switch to character page
|
||||||
|
mw = F.mainWindow()
|
||||||
|
mw.tabMain.setCurrentIndex(mw.TabPersos)
|
||||||
|
# add character
|
||||||
|
c = mw.mdlCharacter.addCharacter(name=text)
|
||||||
|
# switch to character
|
||||||
|
item = mw.lstCharacters.getItemByID(c.ID())
|
||||||
|
mw.lstCharacters.setCurrentItem(item)
|
||||||
|
|
||||||
|
def newPlotItem(self):
|
||||||
|
text = self.sender().data()
|
||||||
|
print("new plot item!", text)
|
||||||
|
# switch to plot page
|
||||||
|
mw = F.mainWindow()
|
||||||
|
mw.tabMain.setCurrentIndex(mw.TabPlots)
|
||||||
|
# add character
|
||||||
|
p, ID = mw.mdlPlots.addPlot(text)
|
||||||
|
# switch to character
|
||||||
|
plotIndex = mw.mdlPlots.getIndexFromID(ID.text())
|
||||||
|
# segfaults for some reason
|
||||||
|
# mw.lstSubPlots.setCurrentIndex(plotIndex)
|
||||||
|
|
||||||
|
def newWorldItem(self):
|
||||||
|
text = self.sender().data()
|
||||||
|
print("new world item!", text)
|
||||||
|
mw = F.mainWindow()
|
||||||
|
mw.tabMain.setCurrentIndex(mw.TabWorld)
|
||||||
|
item = mw.mdlWorld.addItem(title=text)
|
||||||
|
mw.treeWorld.setCurrentIndex(
|
||||||
|
mw.mdlWorld.indexFromItem(item))
|
||||||
|
|
||||||
def createStandardContextMenu(self):
|
def createStandardContextMenu(self):
|
||||||
popup_menu = QTextEdit.createStandardContextMenu(self)
|
popup_menu = QTextEdit.createStandardContextMenu(self)
|
||||||
|
|
||||||
cursor = self.textCursor()
|
cursor = self.textCursor()
|
||||||
selectedWord = cursor.selectedText() if cursor.hasSelection() else None
|
# add "new <something>" buttons at end
|
||||||
|
if cursor.hasSelection():
|
||||||
|
selectedWord = cursor.selectedText() if cursor.hasSelection() else None
|
||||||
|
# new character
|
||||||
|
charAction = QAction(self.tr("&New Character"), popup_menu)
|
||||||
|
charAction.setIcon(F.themeIcon("characters"))
|
||||||
|
charAction.triggered.connect(self.newCharacter)
|
||||||
|
charAction.setData(selectedWord)
|
||||||
|
popup_menu.insertAction(None, charAction)
|
||||||
|
# new plot item
|
||||||
|
plotAction = QAction(self.tr("&New Plot Item"), popup_menu)
|
||||||
|
plotAction.setIcon(F.themeIcon("plots"))
|
||||||
|
plotAction.triggered.connect(self.newPlotItem)
|
||||||
|
plotAction.setData(selectedWord)
|
||||||
|
popup_menu.insertAction(None, plotAction)
|
||||||
|
# new world item
|
||||||
|
worldAction = QAction(self.tr("&New World Item"), popup_menu)
|
||||||
|
worldAction.setIcon(F.themeIcon("world"))
|
||||||
|
worldAction.triggered.connect(self.newWorldItem)
|
||||||
|
worldAction.setData(selectedWord)
|
||||||
|
popup_menu.insertAction(None, worldAction)
|
||||||
|
|
||||||
|
|
||||||
if not self.spellcheck:
|
if not self.spellcheck:
|
||||||
return popup_menu
|
return popup_menu
|
||||||
|
@ -518,7 +576,6 @@ class textEditView(QTextEdit):
|
||||||
|
|
||||||
if len(suggestions) > 0 or selectedWord != None:
|
if len(suggestions) > 0 or selectedWord != None:
|
||||||
valid = len(suggestions) == 0
|
valid = len(suggestions) == 0
|
||||||
|
|
||||||
if not valid:
|
if not valid:
|
||||||
# I think it should focus on one type of error at a time.
|
# I think it should focus on one type of error at a time.
|
||||||
match = suggestions[0]
|
match = suggestions[0]
|
||||||
|
@ -597,7 +654,8 @@ class textEditView(QTextEdit):
|
||||||
elif self._dict.isCustomWord(selectedWord):
|
elif self._dict.isCustomWord(selectedWord):
|
||||||
popup_menu.insertSeparator(popup_menu.actions()[0])
|
popup_menu.insertSeparator(popup_menu.actions()[0])
|
||||||
# Adds: remove from dictionary
|
# Adds: remove from dictionary
|
||||||
rmAction = QAction(self.tr("&Remove from custom dictionary"), popup_menu)
|
rmAction = QAction(
|
||||||
|
self.tr("&Remove from custom dictionary"), popup_menu)
|
||||||
rmAction.setIcon(QIcon.fromTheme("list-remove"))
|
rmAction.setIcon(QIcon.fromTheme("list-remove"))
|
||||||
rmAction.triggered.connect(self.rmWordFromDict)
|
rmAction.triggered.connect(self.rmWordFromDict)
|
||||||
rmAction.setData(selectedWord)
|
rmAction.setData(selectedWord)
|
||||||
|
|
Loading…
Reference in a new issue