Rewritten how document margins and text width is handled

This commit is contained in:
Veronica K. B. Olsen
2019-06-15 12:25:02 +02:00
parent 89ee9c7bf4
commit 4e5f2d30f4
5 changed files with 122 additions and 127 deletions
+3 -3
View File
@@ -69,7 +69,7 @@ class Config:
self.textSize = 12 self.textSize = 12
self.textFixedW = True self.textFixedW = True
self.textWidth = 600 self.textWidth = 600
self.textMargin = [40, 40] self.textMargin = 40
self.tabWidth = 40 self.tabWidth = 40
self.doJustify = True self.doJustify = True
self.autoSelect = True self.autoSelect = True
@@ -165,7 +165,7 @@ class Config:
self.textSize = self._parseLine(cnfParse, cnfSec, "textsize", self.CNF_INT, self.textSize) self.textSize = self._parseLine(cnfParse, cnfSec, "textsize", self.CNF_INT, self.textSize)
self.textFixedW = self._parseLine(cnfParse, cnfSec, "fixedwidth", self.CNF_BOOL, self.textFixedW) self.textFixedW = self._parseLine(cnfParse, cnfSec, "fixedwidth", self.CNF_BOOL, self.textFixedW)
self.textWidth = self._parseLine(cnfParse, cnfSec, "width", self.CNF_INT, self.textWidth) self.textWidth = self._parseLine(cnfParse, cnfSec, "width", self.CNF_INT, self.textWidth)
self.textMargin = self._parseLine(cnfParse, cnfSec, "margins", self.CNF_LIST, self.textMargin) self.textMargin = self._parseLine(cnfParse, cnfSec, "margin", self.CNF_INT, self.textMargin)
self.tabWidth = self._parseLine(cnfParse, cnfSec, "tabwidth", self.CNF_INT, self.tabWidth) self.tabWidth = self._parseLine(cnfParse, cnfSec, "tabwidth", self.CNF_INT, self.tabWidth)
self.doJustify = self._parseLine(cnfParse, cnfSec, "justify", self.CNF_BOOL, self.doJustify) self.doJustify = self._parseLine(cnfParse, cnfSec, "justify", self.CNF_BOOL, self.doJustify)
self.autoSelect = self._parseLine(cnfParse, cnfSec, "autoselect", self.CNF_BOOL, self.autoSelect) self.autoSelect = self._parseLine(cnfParse, cnfSec, "autoselect", self.CNF_BOOL, self.autoSelect)
@@ -220,7 +220,7 @@ class Config:
cnfParse.set(cnfSec,"textsize", str(self.textSize)) cnfParse.set(cnfSec,"textsize", str(self.textSize))
cnfParse.set(cnfSec,"fixedwidth", str(self.textFixedW)) cnfParse.set(cnfSec,"fixedwidth", str(self.textFixedW))
cnfParse.set(cnfSec,"width", str(self.textWidth)) cnfParse.set(cnfSec,"width", str(self.textWidth))
cnfParse.set(cnfSec,"margins", self._packList(self.textMargin)) cnfParse.set(cnfSec,"margin", str(self.textMargin))
cnfParse.set(cnfSec,"tabwidth", str(self.tabWidth)) cnfParse.set(cnfSec,"tabwidth", str(self.tabWidth))
cnfParse.set(cnfSec,"justify", str(self.doJustify)) cnfParse.set(cnfSec,"justify", str(self.doJustify))
cnfParse.set(cnfSec,"autoselect", str(self.autoSelect)) cnfParse.set(cnfSec,"autoselect", str(self.autoSelect))
+84 -83
View File
@@ -260,21 +260,12 @@ class GuiConfigEditEditor(QWidget):
else: else:
self.textFlowJustify.setCheckState(Qt.Unchecked) self.textFlowJustify.setCheckState(Qt.Unchecked)
self.testFlowAutoSelect = QCheckBox(self)
self.testFlowAutoSelect.setToolTip("Auto-select word under cursor when applying formatting.")
if self.mainConf.autoSelect:
self.testFlowAutoSelect.setCheckState(Qt.Checked)
else:
self.testFlowAutoSelect.setCheckState(Qt.Unchecked)
self.textFlowForm.addWidget(QLabel("Fixed Width"), 0, 0) self.textFlowForm.addWidget(QLabel("Fixed Width"), 0, 0)
self.textFlowForm.addWidget(self.textFlowFixed, 0, 1) self.textFlowForm.addWidget(self.textFlowFixed, 0, 1)
self.textFlowForm.addWidget(self.textFlowWidth, 0, 2) self.textFlowForm.addWidget(self.textFlowWidth, 0, 2)
self.textFlowForm.addWidget(QLabel("px"), 0, 3) self.textFlowForm.addWidget(QLabel("px"), 0, 3)
self.textFlowForm.addWidget(QLabel("Justify Text"), 1, 0) self.textFlowForm.addWidget(QLabel("Justify Text"), 1, 0)
self.textFlowForm.addWidget(self.textFlowJustify, 1, 1) self.textFlowForm.addWidget(self.textFlowJustify, 1, 1)
self.textFlowForm.addWidget(QLabel("Auto-Select Text"), 2, 0)
self.textFlowForm.addWidget(self.testFlowAutoSelect, 2, 1)
self.textFlowForm.setColumnStretch(4, 1) self.textFlowForm.setColumnStretch(4, 1)
# Text Margins # Text Margins
@@ -282,17 +273,11 @@ class GuiConfigEditEditor(QWidget):
self.textMarginForm = QGridLayout(self) self.textMarginForm = QGridLayout(self)
self.textMargin.setLayout(self.textMarginForm) self.textMargin.setLayout(self.textMarginForm)
self.textMarginHor = QSpinBox(self) self.textMarginDoc = QSpinBox(self)
self.textMarginHor.setMinimum(0) self.textMarginDoc.setMinimum(0)
self.textMarginHor.setMaximum(2000) self.textMarginDoc.setMaximum(2000)
self.textMarginHor.setSingleStep(1) self.textMarginDoc.setSingleStep(1)
self.textMarginHor.setValue(self.mainConf.textMargin[0]) self.textMarginDoc.setValue(self.mainConf.textMargin)
self.textMarginVer = QSpinBox(self)
self.textMarginVer.setMinimum(0)
self.textMarginVer.setMaximum(2000)
self.textMarginVer.setSingleStep(1)
self.textMarginVer.setValue(self.mainConf.textMargin[1])
self.textMarginTab = QSpinBox(self) self.textMarginTab = QSpinBox(self)
self.textMarginTab.setMinimum(0) self.textMarginTab.setMinimum(0)
@@ -300,22 +285,26 @@ class GuiConfigEditEditor(QWidget):
self.textMarginTab.setSingleStep(1) self.textMarginTab.setSingleStep(1)
self.textMarginTab.setValue(self.mainConf.tabWidth) self.textMarginTab.setValue(self.mainConf.tabWidth)
self.textMarginForm.addWidget(QLabel("Horizontal"), 0, 0) self.textMarginForm.addWidget(QLabel("Document"), 0, 0)
self.textMarginForm.addWidget(self.textMarginHor, 0, 1) self.textMarginForm.addWidget(self.textMarginDoc, 0, 1)
self.textMarginForm.addWidget(QLabel("px"), 0, 2) self.textMarginForm.addWidget(QLabel("px"), 0, 2)
self.textMarginForm.addWidget(QLabel("Vertical"), 1, 0)
self.textMarginForm.addWidget(self.textMarginVer, 1, 1)
self.textMarginForm.addWidget(QLabel("px"), 1, 2)
self.textMarginForm.addWidget(QLabel("Tab Width"), 2, 0) self.textMarginForm.addWidget(QLabel("Tab Width"), 2, 0)
self.textMarginForm.addWidget(self.textMarginTab, 2, 1) self.textMarginForm.addWidget(self.textMarginTab, 2, 1)
self.textMarginForm.addWidget(QLabel("px"), 2, 2) self.textMarginForm.addWidget(QLabel("px"), 2, 2)
self.textMarginForm.setColumnStretch(4, 1) self.textMarginForm.setColumnStretch(4, 1)
# Auto-Replace # Automatic Features
self.autoReplace = QGroupBox("Auto-Replace", self) self.autoReplace = QGroupBox("Automatic Features", self)
self.autoReplaceForm = QGridLayout(self) self.autoReplaceForm = QGridLayout(self)
self.autoReplace.setLayout(self.autoReplaceForm) self.autoReplace.setLayout(self.autoReplaceForm)
self.autoSelect = QCheckBox(self)
self.autoSelect.setToolTip("Auto-select word under cursor when applying formatting.")
if self.mainConf.autoSelect:
self.autoSelect.setCheckState(Qt.Checked)
else:
self.autoSelect.setCheckState(Qt.Unchecked)
self.autoReplaceMain = QCheckBox(self) self.autoReplaceMain = QCheckBox(self)
self.autoReplaceMain.setToolTip("Auto-replace text as you type.") self.autoReplaceMain.setToolTip("Auto-replace text as you type.")
if self.mainConf.doReplace: if self.mainConf.doReplace:
@@ -330,18 +319,6 @@ class GuiConfigEditEditor(QWidget):
else: else:
self.autoReplaceSQ.setCheckState(Qt.Unchecked) self.autoReplaceSQ.setCheckState(Qt.Unchecked)
self.autoReplaceSStyleO = QLineEdit()
self.autoReplaceSStyleO.setMaxLength(1)
self.autoReplaceSStyleO.setFixedWidth(30)
self.autoReplaceSStyleO.setAlignment(Qt.AlignCenter)
self.autoReplaceSStyleO.setText(self.mainConf.fmtSingleQuotes[0])
self.autoReplaceSStyleC = QLineEdit()
self.autoReplaceSStyleC.setMaxLength(1)
self.autoReplaceSStyleC.setFixedWidth(30)
self.autoReplaceSStyleC.setAlignment(Qt.AlignCenter)
self.autoReplaceSStyleC.setText(self.mainConf.fmtSingleQuotes[1])
self.autoReplaceDQ = QCheckBox(self) self.autoReplaceDQ = QCheckBox(self)
self.autoReplaceDQ.setToolTip("Auto-replace double quotes.") self.autoReplaceDQ.setToolTip("Auto-replace double quotes.")
if self.mainConf.doReplaceDQuote: if self.mainConf.doReplaceDQuote:
@@ -349,18 +326,6 @@ class GuiConfigEditEditor(QWidget):
else: else:
self.autoReplaceDQ.setCheckState(Qt.Unchecked) self.autoReplaceDQ.setCheckState(Qt.Unchecked)
self.autoReplaceDStyleO = QLineEdit()
self.autoReplaceDStyleO.setMaxLength(1)
self.autoReplaceDStyleO.setFixedWidth(30)
self.autoReplaceDStyleO.setAlignment(Qt.AlignCenter)
self.autoReplaceDStyleO.setText(self.mainConf.fmtDoubleQuotes[0])
self.autoReplaceDStyleC = QLineEdit()
self.autoReplaceDStyleC.setMaxLength(1)
self.autoReplaceDStyleC.setFixedWidth(30)
self.autoReplaceDStyleC.setAlignment(Qt.AlignCenter)
self.autoReplaceDStyleC.setText(self.mainConf.fmtDoubleQuotes[1])
self.autoReplaceDash = QCheckBox(self) self.autoReplaceDash = QCheckBox(self)
self.autoReplaceDash.setToolTip("Auto-replace double and triple hyphens with short and long dash.") self.autoReplaceDash.setToolTip("Auto-replace double and triple hyphens with short and long dash.")
if self.mainConf.doReplaceDash: if self.mainConf.doReplaceDash:
@@ -375,31 +340,68 @@ class GuiConfigEditEditor(QWidget):
else: else:
self.autoReplaceDots.setCheckState(Qt.Unchecked) self.autoReplaceDots.setCheckState(Qt.Unchecked)
self.autoReplaceForm.addWidget(QLabel("Enable Feature"), 0, 0) self.autoReplaceForm.addWidget(QLabel("Auto-Select Text"), 0, 0)
self.autoReplaceForm.addWidget(self.autoReplaceMain, 0, 1) self.autoReplaceForm.addWidget(self.autoSelect, 0, 1)
self.autoReplaceForm.addWidget(QLabel("Single Quotes"), 1, 0) self.autoReplaceForm.addWidget(QLabel("Auto-Replace:"), 1, 0)
self.autoReplaceForm.addWidget(self.autoReplaceSQ, 1, 1) self.autoReplaceForm.addWidget(self.autoReplaceMain, 1, 1)
self.autoReplaceForm.addWidget(QLabel("Open"), 1, 2) self.autoReplaceForm.addWidget(QLabel("\u2192 Single Quotes"), 2, 0)
self.autoReplaceForm.addWidget(self.autoReplaceSStyleO, 1, 3) self.autoReplaceForm.addWidget(self.autoReplaceSQ, 2, 1)
self.autoReplaceForm.addWidget(QLabel("Close"), 1, 4) self.autoReplaceForm.addWidget(QLabel("\u2192 Double Quotes"), 3, 0)
self.autoReplaceForm.addWidget(self.autoReplaceSStyleC, 1, 5) self.autoReplaceForm.addWidget(self.autoReplaceDQ, 3, 1)
self.autoReplaceForm.addWidget(QLabel("Double Quotes"), 2, 0) self.autoReplaceForm.addWidget(QLabel("\u2192 Hyphens with Dash"), 4, 0)
self.autoReplaceForm.addWidget(self.autoReplaceDQ, 2, 1) self.autoReplaceForm.addWidget(self.autoReplaceDash, 4, 1)
self.autoReplaceForm.addWidget(QLabel("Open"), 2, 2) self.autoReplaceForm.addWidget(QLabel("\u2192 Dots with Ellipsis"), 5, 0)
self.autoReplaceForm.addWidget(self.autoReplaceDStyleO, 2, 3) self.autoReplaceForm.addWidget(self.autoReplaceDots, 5, 1)
self.autoReplaceForm.addWidget(QLabel("Close"), 2, 4) self.autoReplaceForm.setColumnStretch(2, 1)
self.autoReplaceForm.addWidget(self.autoReplaceDStyleC, 2, 5)
self.autoReplaceForm.addWidget(QLabel("Hyphens with Dash"), 3, 0) # Quote Style
self.autoReplaceForm.addWidget(self.autoReplaceDash, 3, 1) self.quoteStyle = QGroupBox("Quotation Style", self)
self.autoReplaceForm.addWidget(QLabel("Dots with Ellipsis"), 4, 0) self.quoteStyleForm = QGridLayout(self)
self.autoReplaceForm.addWidget(self.autoReplaceDots, 4, 1) self.quoteStyle.setLayout(self.quoteStyleForm)
self.autoReplaceForm.setColumnStretch(6, 1)
self.quoteSingleStyleO = QLineEdit()
self.quoteSingleStyleO.setMaxLength(1)
self.quoteSingleStyleO.setFixedWidth(30)
self.quoteSingleStyleO.setAlignment(Qt.AlignCenter)
self.quoteSingleStyleO.setText(self.mainConf.fmtSingleQuotes[0])
self.quoteSingleStyleC = QLineEdit()
self.quoteSingleStyleC.setMaxLength(1)
self.quoteSingleStyleC.setFixedWidth(30)
self.quoteSingleStyleC.setAlignment(Qt.AlignCenter)
self.quoteSingleStyleC.setText(self.mainConf.fmtSingleQuotes[1])
self.quoteDoubleStyleO = QLineEdit()
self.quoteDoubleStyleO.setMaxLength(1)
self.quoteDoubleStyleO.setFixedWidth(30)
self.quoteDoubleStyleO.setAlignment(Qt.AlignCenter)
self.quoteDoubleStyleO.setText(self.mainConf.fmtDoubleQuotes[0])
self.quoteDoubleStyleC = QLineEdit()
self.quoteDoubleStyleC.setMaxLength(1)
self.quoteDoubleStyleC.setFixedWidth(30)
self.quoteDoubleStyleC.setAlignment(Qt.AlignCenter)
self.quoteDoubleStyleC.setText(self.mainConf.fmtDoubleQuotes[1])
self.quoteStyleForm.addWidget(QLabel("Single Quotes"), 0, 0, 1, 3)
self.quoteStyleForm.addWidget(QLabel("Open"), 1, 0)
self.quoteStyleForm.addWidget(self.quoteSingleStyleO, 1, 1)
self.quoteStyleForm.addWidget(QLabel("Close"), 1, 2)
self.quoteStyleForm.addWidget(self.quoteSingleStyleC, 1, 3)
self.quoteStyleForm.addWidget(QLabel("Double Quotes"), 2, 0, 1, 3)
self.quoteStyleForm.addWidget(QLabel("Open"), 3, 0)
self.quoteStyleForm.addWidget(self.quoteDoubleStyleO, 3, 1)
self.quoteStyleForm.addWidget(QLabel("Close"), 3, 2)
self.quoteStyleForm.addWidget(self.quoteDoubleStyleC, 3, 3)
self.quoteStyleForm.setColumnStretch(4, 1)
self.quoteStyleForm.setRowStretch(4, 1)
# Assemble # Assemble
self.outerBox.addWidget(self.textStyle, 0, 0, 1, 2) self.outerBox.addWidget(self.textStyle, 0, 0, 1, 2)
self.outerBox.addWidget(self.textFlow, 1, 0) self.outerBox.addWidget(self.textFlow, 1, 0)
self.outerBox.addWidget(self.textMargin, 1, 1) self.outerBox.addWidget(self.textMargin, 1, 1)
self.outerBox.addWidget(self.autoReplace, 2, 0, 1, 2) self.outerBox.addWidget(self.autoReplace, 2, 0)
self.outerBox.addWidget(self.quoteStyle, 2, 1)
self.outerBox.setColumnStretch(2, 1) self.outerBox.setColumnStretch(2, 1)
self.setLayout(self.outerBox) self.setLayout(self.outerBox)
@@ -418,37 +420,36 @@ class GuiConfigEditEditor(QWidget):
textWidth = self.textFlowWidth.value() textWidth = self.textFlowWidth.value()
textFixedW = self.textFlowFixed.isChecked() textFixedW = self.textFlowFixed.isChecked()
doJustify = self.textFlowJustify.isChecked() doJustify = self.textFlowJustify.isChecked()
autoSelect = self.testFlowAutoSelect.isChecked()
self.mainConf.textWidth = textWidth self.mainConf.textWidth = textWidth
self.mainConf.textFixedW = textFixedW self.mainConf.textFixedW = textFixedW
self.mainConf.doJustify = doJustify self.mainConf.doJustify = doJustify
self.mainConf.autoSelect = autoSelect
textMarginH = self.textMarginHor.value() textMargin = self.textMarginDoc.value()
textMarginV = self.textMarginVer.value() tabWidth = self.textMarginTab.value()
tabWidth = self.textMarginTab.value()
self.mainConf.textMargin[0] = textMarginH self.mainConf.textMargin = textMargin
self.mainConf.textMargin[1] = textMarginV self.mainConf.tabWidth = tabWidth
self.mainConf.tabWidth = tabWidth
autoSelect = self.autoSelect.isChecked()
doReplace = self.autoReplaceMain.isChecked() doReplace = self.autoReplaceMain.isChecked()
doReplaceSQuote = self.autoReplaceSQ.isChecked() doReplaceSQuote = self.autoReplaceSQ.isChecked()
doReplaceDQuote = self.autoReplaceDQ.isChecked() doReplaceDQuote = self.autoReplaceDQ.isChecked()
doReplaceDash = self.autoReplaceDash.isChecked() doReplaceDash = self.autoReplaceDash.isChecked()
doReplaceDots = self.autoReplaceDash.isChecked() doReplaceDots = self.autoReplaceDash.isChecked()
fmtSingleQuotesO = self.autoReplaceSStyleO.text()
fmtSingleQuotesC = self.autoReplaceSStyleC.text()
fmtDoubleQuotesO = self.autoReplaceDStyleO.text()
fmtDoubleQuotesC = self.autoReplaceDStyleC.text()
self.mainConf.autoSelect = autoSelect
self.mainConf.doReplace = doReplace self.mainConf.doReplace = doReplace
self.mainConf.doReplaceSQuote = doReplaceSQuote self.mainConf.doReplaceSQuote = doReplaceSQuote
self.mainConf.doReplaceDQuote = doReplaceDQuote self.mainConf.doReplaceDQuote = doReplaceDQuote
self.mainConf.doReplaceDash = doReplaceDash self.mainConf.doReplaceDash = doReplaceDash
self.mainConf.doReplaceDots = doReplaceDots self.mainConf.doReplaceDots = doReplaceDots
fmtSingleQuotesO = self.quoteSingleStyleO.text()
fmtSingleQuotesC = self.quoteSingleStyleC.text()
fmtDoubleQuotesO = self.quoteDoubleStyleO.text()
fmtDoubleQuotesC = self.quoteDoubleStyleC.text()
if self._checkQuoteSymbol(fmtSingleQuotesO): if self._checkQuoteSymbol(fmtSingleQuotesO):
self.mainConf.fmtSingleQuotes[0] = fmtSingleQuotesO self.mainConf.fmtSingleQuotes[0] = fmtSingleQuotesO
else: else:
+33 -39
View File
@@ -15,7 +15,7 @@ import nw
from time import time from time import time
from PyQt5.QtCore import Qt, QTimer from PyQt5.QtCore import Qt, QTimer, QSizeF
from PyQt5.QtWidgets import QTextEdit, QAction, QMenu, QShortcut from PyQt5.QtWidgets import QTextEdit, QAction, QMenu, QShortcut
from PyQt5.QtGui import QTextCursor, QTextOption, QIcon, QKeySequence, QFont from PyQt5.QtGui import QTextCursor, QTextOption, QIcon, QKeySequence, QFont
@@ -36,13 +36,13 @@ class GuiDocEditor(QTextEdit):
logger.debug("Initialising DocEditor ...") logger.debug("Initialising DocEditor ...")
# Class Variables # Class Variables
self.mainConf = nw.CONFIG self.mainConf = nw.CONFIG
self.theParent = theParent self.theParent = theParent
self.theProject = theProject self.theProject = theProject
self.docChanged = False self.docChanged = False
self.spellCheck = False self.spellCheck = False
self.theDocument = NWDoc(self.theProject, self.theParent) self.nwDocument = NWDoc(self.theProject, self.theParent)
self.theHandle = None self.theHandle = None
# Document Variables # Document Variables
self.charCount = 0 self.charCount = 0
@@ -57,14 +57,15 @@ class GuiDocEditor(QTextEdit):
self.typSQClose = self.mainConf.fmtSingleQuotes[1] self.typSQClose = self.mainConf.fmtSingleQuotes[1]
# Core Elements # Core Elements
self.theQDoc = self.document() self.qDocument = self.document()
self.qDocument.contentsChange.connect(self._docChange)
if self.mainConf.spellTool == "enchant": if self.mainConf.spellTool == "enchant":
from nw.tools.spellenchant import NWSpellEnchant from nw.tools.spellenchant import NWSpellEnchant
self.theDict = NWSpellEnchant() self.theDict = NWSpellEnchant()
else: else:
self.theDict = NWSpellCheck() self.theDict = NWSpellCheck()
self.hLight = GuiDocHighlighter(self.theQDoc, self.theParent) self.hLight = GuiDocHighlighter(self.qDocument, self.theParent)
self.hLight.setDict(self.theDict) self.hLight.setDict(self.theDict)
# Context Menu # Context Menu
@@ -76,9 +77,6 @@ class GuiDocEditor(QTextEdit):
self.setMinimumWidth(300) self.setMinimumWidth(300)
self.setAcceptRichText(False) self.setAcceptRichText(False)
self.theQDoc.setDocumentMargin(0)
self.theQDoc.contentsChange.connect(self._docChange)
# Custom Shortcuts # Custom Shortcuts
QShortcut(QKeySequence("Ctrl+."), self, context=Qt.WidgetShortcut, activated=self._openSpellContext) QShortcut(QKeySequence("Ctrl+."), self, context=Qt.WidgetShortcut, activated=self._openSpellContext)
@@ -100,7 +98,7 @@ class GuiDocEditor(QTextEdit):
def clearEditor(self): def clearEditor(self):
self.theDocument.clearDocument() self.nwDocument.clearDocument()
self.setReadOnly(True) self.setReadOnly(True)
self.clear() self.clear()
self.wcTimer.stop() self.wcTimer.stop()
@@ -129,19 +127,14 @@ class GuiDocEditor(QTextEdit):
theFont = QFont() theFont = QFont()
if self.mainConf.textFont is None: if self.mainConf.textFont is None:
# If none is defined, set the default back to config # If none is defined, set the default back to config
self.mainConf.textFont = self.theQDoc.defaultFont().family() self.mainConf.textFont = self.qDocument.defaultFont().family()
theFont.setFamily(self.mainConf.textFont) theFont.setFamily(self.mainConf.textFont)
theFont.setPointSize(self.mainConf.textSize) theFont.setPointSize(self.mainConf.textSize)
self.setFont(theFont) self.setFont(theFont)
# Set text fixed width, or alternatively, just margins # Set text fixed width, or alternatively, just margins
if self.mainConf.textFixedW: self.qDocument.setDocumentMargin(self.mainConf.textMargin)
self.setLineWrapMode(QTextEdit.FixedPixelWidth) self.changeWidth()
self.setLineWrapColumnOrWidth(self.mainConf.textWidth)
else:
mTB = self.mainConf.textMargin[0]
mLR = self.mainConf.textMargin[1]
self.setViewportMargins(mLR,mTB,mLR,mTB)
# Also set the document text options for the document text flow # Also set the document text options for the document text flow
theOpt = QTextOption() theOpt = QTextOption()
@@ -149,7 +142,7 @@ class GuiDocEditor(QTextEdit):
theOpt.setTabStopDistance(self.mainConf.tabWidth) theOpt.setTabStopDistance(self.mainConf.tabWidth)
if self.mainConf.doJustify: if self.mainConf.doJustify:
theOpt.setAlignment(Qt.AlignJustify) theOpt.setAlignment(Qt.AlignJustify)
self.theQDoc.setDefaultTextOption(theOpt) self.qDocument.setDefaultTextOption(theOpt)
# If we have a document open, we should reload it in case the font changed # If we have a document open, we should reload it in case the font changed
if self.theHandle is not None: if self.theHandle is not None:
@@ -163,8 +156,8 @@ class GuiDocEditor(QTextEdit):
def loadText(self, tHandle): def loadText(self, tHandle):
self.hLight.setHandle(tHandle) self.hLight.setHandle(tHandle)
self.setPlainText(self.theDocument.openDocument(tHandle)) self.setPlainText(self.nwDocument.openDocument(tHandle))
self.setCursorPosition(self.theDocument.theItem.cursorPos) self.setCursorPosition(self.nwDocument.theItem.cursorPos)
self.lastEdit = time() self.lastEdit = time()
self._runCounter() self._runCounter()
self.wcTimer.start() self.wcTimer.start()
@@ -176,17 +169,17 @@ class GuiDocEditor(QTextEdit):
def saveText(self): def saveText(self):
if self.theDocument.theItem is None: if self.nwDocument.theItem is None:
return False return False
docText = self.getText() docText = self.getText()
cursPos = self.getCursorPosition() cursPos = self.getCursorPosition()
theItem = self.theDocument.theItem theItem = self.nwDocument.theItem
theItem.setCharCount(self.charCount) theItem.setCharCount(self.charCount)
theItem.setWordCount(self.wordCount) theItem.setWordCount(self.wordCount)
theItem.setParaCount(self.paraCount) theItem.setParaCount(self.paraCount)
theItem.setCursorPos(cursPos) theItem.setCursorPos(cursPos)
self.theDocument.saveDocument(docText) self.nwDocument.saveDocument(docText)
self.setDocumentChanged(False) self.setDocumentChanged(False)
self.theParent.theIndex.scanText(theItem.itemHandle, docText) self.theParent.theIndex.scanText(theItem.itemHandle, docText)
@@ -253,15 +246,16 @@ class GuiDocEditor(QTextEdit):
sW = vBar.width() sW = vBar.width()
else: else:
sW = 0 sW = 0
tW = self.width() tW = self.mainConf.textWidth
tM = int((tW - sW - self.mainConf.textWidth)/2) wW = self.width()
mTB = self.mainConf.textMargin[0] tM = int((wW - sW - tW)/2)
if tM >= 10: if tM < 0:
self.setViewportMargins(tM,mTB,0,mTB) tM = 0
self.setLineWrapColumnOrWidth(self.mainConf.textWidth) # print(wW, tW, dW, sW, tM)
else: self.setViewportMargins(tM,0,tM,0)
self.setViewportMargins(10,mTB,0,mTB) self.qDocument.setTextWidth(tW)
self.setLineWrapColumnOrWidth(tW - sW - 20) else:
self.setViewportMargins(0,0,0,0)
return return
def docAction(self, theAction): def docAction(self, theAction):
@@ -369,7 +363,7 @@ class GuiDocEditor(QTextEdit):
if not self.wcTimer.isActive(): if not self.wcTimer.isActive():
self.wcTimer.start() self.wcTimer.start()
if self.mainConf.doReplace and not self.hasSelection: if self.mainConf.doReplace and not self.hasSelection:
self._docAutoReplace(self.theQDoc.findBlock(thePos)) self._docAutoReplace(self.qDocument.findBlock(thePos))
# logger.verbose("Doc change signal took %.3f µs" % ((time()-self.lastEdit)*1e6)) # logger.verbose("Doc change signal took %.3f µs" % ((time()-self.lastEdit)*1e6))
return return
@@ -447,7 +441,7 @@ class GuiDocEditor(QTextEdit):
""" """
logger.verbose("Updating word count") logger.verbose("Updating word count")
tHandle = self.theDocument.docHandle tHandle = self.nwDocument.docHandle
self.charCount = self.wCounter.charCount self.charCount = self.wCounter.charCount
self.wordCount = self.wCounter.wordCount self.wordCount = self.wCounter.wordCount
self.paraCount = self.wCounter.paraCount self.paraCount = self.wCounter.paraCount
+1 -1
View File
@@ -111,7 +111,7 @@ class GuiDocViewer(QTextBrowser):
theFont.setPointSize(self.mainConf.textSize) theFont.setPointSize(self.mainConf.textSize)
self.setFont(theFont) self.setFont(theFont)
self.theQDoc.setDocumentMargin(self.mainConf.textMargin[0]) self.theQDoc.setDocumentMargin(self.mainConf.textMargin)
theOpt = QTextOption() theOpt = QTextOption()
if self.mainConf.doJustify: if self.mainConf.doJustify:
theOpt.setAlignment(Qt.AlignJustify) theOpt.setAlignment(Qt.AlignJustify)
+1 -1
View File
@@ -296,8 +296,8 @@ class GuiMain(QMainWindow):
if self.hasProject: if self.hasProject:
self.closeDocument() self.closeDocument()
self.docEditor.loadText(tHandle) self.docEditor.loadText(tHandle)
self.docEditor.changeWidth()
self.docEditor.setFocus() self.docEditor.setFocus()
self.docEditor.changeWidth()
self.theProject.setLastEdited(tHandle) self.theProject.setLastEdited(tHandle)
return True return True