mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-15 02:12:29 +12:00
added 3 buttons to the textEditView that allow quickly adding new items
add character takes parameter name
This commit is contained in:
parent
0cb65c452e
commit
22fdab3f46
|
@ -378,8 +378,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
else:
|
||||
self.chkPersoPOV.setCheckState(Qt.Unchecked)
|
||||
|
||||
self.chkPersoPOV.stateChanged.connect(self.lstCharacters.changeCharacterPOVState, F.AUC)
|
||||
self.chkPersoPOV.setEnabled(len(self.mdlOutline.findItemsByPOV(ID)) == 0)
|
||||
try:
|
||||
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
|
||||
|
|
|
@ -165,14 +165,17 @@ class characterModel(QAbstractItemModel):
|
|||
# ADDING / REMOVING
|
||||
###############################################################################
|
||||
|
||||
def addCharacter(self, importance = 0):
|
||||
def addCharacter(self, importance = 0, name="New character"):
|
||||
"""
|
||||
Creates a new character
|
||||
@param importance: the importance level of the character
|
||||
@return: the character
|
||||
"""
|
||||
c = Character(model=self, name=self.tr("New character"), importance = importance)
|
||||
self.beginInsertRows(QModelIndex(), len(self.characters), len(self.characters))
|
||||
if not name:
|
||||
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.endInsertRows()
|
||||
return c
|
||||
|
@ -184,7 +187,8 @@ class characterModel(QAbstractItemModel):
|
|||
@return: nothing
|
||||
"""
|
||||
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.endRemoveRows()
|
||||
|
||||
|
@ -204,7 +208,8 @@ class characterModel(QAbstractItemModel):
|
|||
def addCharacterInfo(self, ID):
|
||||
c = self.getCharacterByID(ID)
|
||||
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()
|
||||
|
||||
mainWindow().updatePersoInfoView()
|
||||
|
@ -228,6 +233,7 @@ class characterModel(QAbstractItemModel):
|
|||
# CHARACTER
|
||||
###############################################################################
|
||||
|
||||
|
||||
class Character():
|
||||
def __init__(self, model, name="No name", importance = 0):
|
||||
self._model = model
|
||||
|
@ -245,6 +251,9 @@ class Character():
|
|||
def name(self):
|
||||
return self._data[C.name.value]
|
||||
|
||||
def setName(self, value):
|
||||
self._data[C.name.value] = value
|
||||
|
||||
def importance(self):
|
||||
return self._data[C.importance.value]
|
||||
|
||||
|
@ -316,6 +325,7 @@ class Character():
|
|||
r.append((i.description, i.value))
|
||||
return r
|
||||
|
||||
|
||||
class CharacterInfo():
|
||||
def __init__(self, character, description="", value=""):
|
||||
self.description = description
|
||||
|
|
|
@ -73,7 +73,7 @@ class plotModel(QStandardItemModel):
|
|||
if i == row:
|
||||
importance = self.item(i, Plot.importance).text()
|
||||
return importance
|
||||
return "0" # Default to "Minor"
|
||||
return "0" # Default to "Minor"
|
||||
|
||||
def getSubPlotTextsByID(self, plotID, subplotRaw):
|
||||
"""Returns a tuple (name, summary) for the subplot whose raw in the model
|
||||
|
@ -102,12 +102,15 @@ class plotModel(QStandardItemModel):
|
|||
# ADDING / REMOVING
|
||||
###############################################################################
|
||||
|
||||
def addPlot(self):
|
||||
p = QStandardItem(self.tr("New plot"))
|
||||
def addPlot(self, name="New plot"):
|
||||
if not name:
|
||||
name="New Plot"
|
||||
p = QStandardItem(self.tr(name))
|
||||
_id = QStandardItem(self.getUniqueID())
|
||||
importance = QStandardItem(str(0))
|
||||
self.appendRow([p, _id, importance, QStandardItem("Characters"),
|
||||
QStandardItem(), QStandardItem(), QStandardItem("Resolution steps")])
|
||||
return p, _id
|
||||
|
||||
def getUniqueID(self, parent=QModelIndex()):
|
||||
"""Returns an unused ID"""
|
||||
|
@ -147,8 +150,8 @@ class plotModel(QStandardItemModel):
|
|||
|
||||
def data(self, index, role=Qt.DisplayRole):
|
||||
if index.parent().isValid() and \
|
||||
index.parent().column() == Plot.steps and \
|
||||
index.column() == PlotStep.meta:
|
||||
index.parent().column() == Plot.steps and \
|
||||
index.column() == PlotStep.meta:
|
||||
if role == Qt.TextAlignmentRole:
|
||||
return Qt.AlignRight | Qt.AlignVCenter
|
||||
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...
|
||||
parentItem.appendRow([p, _id, QStandardItem(), summary])
|
||||
# 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):
|
||||
"""
|
||||
|
|
|
@ -14,6 +14,8 @@ from manuskript.models import outlineModel, outlineItem
|
|||
from manuskript.ui.highlighters import BasicHighlighter
|
||||
from manuskript.ui import style as S
|
||||
from manuskript.functions import Spellchecker
|
||||
from manuskript.models.characterModel import Character, CharacterInfo
|
||||
|
||||
|
||||
class textEditView(QTextEdit):
|
||||
def __init__(self, parent=None, index=None, html=None, spellcheck=None,
|
||||
|
@ -165,9 +167,9 @@ class textEditView(QTextEdit):
|
|||
|
||||
def loadFontSettings(self):
|
||||
if self._fromTheme or \
|
||||
not self._index or \
|
||||
type(self._index.model()) != outlineModel or \
|
||||
self._column != Outline.text:
|
||||
not self._index or \
|
||||
type(self._index.model()) != outlineModel or \
|
||||
self._column != Outline.text:
|
||||
return
|
||||
|
||||
opt = settings.textEditor
|
||||
|
@ -175,7 +177,7 @@ class textEditView(QTextEdit):
|
|||
f.fromString(opt["font"])
|
||||
background = (opt["background"] if not opt["backgroundTransparent"]
|
||||
else "transparent")
|
||||
foreground = opt["fontColor"] # if not opt["backgroundTransparent"]
|
||||
foreground = opt["fontColor"] # if not opt["backgroundTransparent"]
|
||||
# else S.text
|
||||
# self.setFont(f)
|
||||
self.setStyleSheet("""QTextEdit{{
|
||||
|
@ -187,15 +189,16 @@ class textEditView(QTextEdit):
|
|||
{maxWidth}
|
||||
}}
|
||||
""".format(
|
||||
bg=background,
|
||||
foreground=foreground,
|
||||
ff=f.family(),
|
||||
fs="{}pt".format(str(f.pointSize())),
|
||||
mTB = opt["marginsTB"],
|
||||
mLR = opt["marginsLR"],
|
||||
maxWidth = "max-width: {}px;".format(opt["maxWidth"]) if opt["maxWidth"] else "",
|
||||
)
|
||||
)
|
||||
bg=background,
|
||||
foreground=foreground,
|
||||
ff=f.family(),
|
||||
fs="{}pt".format(str(f.pointSize())),
|
||||
mTB=opt["marginsTB"],
|
||||
mLR=opt["marginsLR"],
|
||||
maxWidth="max-width: {}px;".format(
|
||||
opt["maxWidth"]) if opt["maxWidth"] else "",
|
||||
)
|
||||
)
|
||||
self._defaultFontSize = f.pointSize()
|
||||
|
||||
# We set the parent background to the editor's background in case
|
||||
|
@ -207,11 +210,11 @@ class textEditView(QTextEdit):
|
|||
QWidget#{name}{{
|
||||
background: {bg};
|
||||
}}""".format(
|
||||
# We style by name, otherwise all inheriting widgets get the same
|
||||
# colored background, for example context menu.
|
||||
name=self.parent().objectName(),
|
||||
bg=background,
|
||||
))
|
||||
# We style by name, otherwise all inheriting widgets get the same
|
||||
# colored background, for example context menu.
|
||||
name=self.parent().objectName(),
|
||||
bg=background,
|
||||
))
|
||||
|
||||
cf = QTextCharFormat()
|
||||
# cf.setFont(f)
|
||||
|
@ -472,18 +475,73 @@ class textEditView(QTextEdit):
|
|||
QAction.__init__(self, *args)
|
||||
|
||||
self.triggered.connect(lambda x: self.correct.emit(
|
||||
str(self.text())))
|
||||
str(self.text())))
|
||||
|
||||
def contextMenuEvent(self, event):
|
||||
# Based on http://john.nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check/
|
||||
popup_menu = self.createStandardContextMenu()
|
||||
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):
|
||||
popup_menu = QTextEdit.createStandardContextMenu(self)
|
||||
|
||||
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:
|
||||
return popup_menu
|
||||
|
@ -518,7 +576,6 @@ class textEditView(QTextEdit):
|
|||
|
||||
if len(suggestions) > 0 or selectedWord != None:
|
||||
valid = len(suggestions) == 0
|
||||
|
||||
if not valid:
|
||||
# I think it should focus on one type of error at a time.
|
||||
match = suggestions[0]
|
||||
|
@ -597,7 +654,8 @@ class textEditView(QTextEdit):
|
|||
elif self._dict.isCustomWord(selectedWord):
|
||||
popup_menu.insertSeparator(popup_menu.actions()[0])
|
||||
# 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.triggered.connect(self.rmWordFromDict)
|
||||
rmAction.setData(selectedWord)
|
||||
|
|
Loading…
Reference in a new issue