mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-15 18:32:27 +12:00
Adds: fullScreenEditor
This commit is contained in:
parent
54751611bb
commit
58f4e45e47
|
@ -153,12 +153,4 @@ def allPaths(suffix=None):
|
|||
paths.append(appPath(suffix))
|
||||
# user writable directory
|
||||
paths.append(writablePath(suffix))
|
||||
return paths
|
||||
|
||||
def findBackground(filename):
|
||||
paths = allPaths("resources/backgrounds")
|
||||
for p in paths:
|
||||
lst = os.listdir(p)
|
||||
for l in lst:
|
||||
if l == filename:
|
||||
return os.path.join(p, l)
|
||||
return paths
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import sys
|
||||
from qt import *
|
||||
from ui.editors.fullScreenEditor import *
|
||||
|
||||
_version = "0.1"
|
||||
|
||||
|
@ -38,8 +37,6 @@ def run():
|
|||
|
||||
main = MainWindow()
|
||||
main.show()
|
||||
|
||||
#testW = fullScreenEditor()
|
||||
|
||||
app.exec_()
|
||||
app.deleteLater()
|
||||
|
|
|
@ -227,8 +227,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
self.lstDebugStatus.setModel(self.mdlStatus)
|
||||
|
||||
self.loadProject(os.path.join(appPath(), "test_project.zip"))
|
||||
|
||||
self.settingsWindow(tab="Fullscreen")
|
||||
|
||||
####################################################################################################
|
||||
# OUTLINE #
|
||||
|
|
|
@ -43,11 +43,13 @@ corkBackground = {
|
|||
"image": ""
|
||||
}
|
||||
|
||||
fullScreenTheme = "spacedreams"
|
||||
|
||||
def save(filename=None):
|
||||
|
||||
global spellcheck, dict, corkSliderFactor, viewSettings, corkSizeFactor, folderView, lastTab, lastIndex, \
|
||||
autoSave, autoSaveDelay, saveOnQuit, autoSaveNoChanges, autoSaveNoChangesDelay, outlineViewColumns, \
|
||||
corkBackground
|
||||
corkBackground, fullScreenTheme
|
||||
|
||||
allSettings = {
|
||||
"viewSettings": viewSettings,
|
||||
|
@ -64,6 +66,7 @@ def save(filename=None):
|
|||
"autoSaveNoChangesDelay":autoSaveNoChangesDelay,
|
||||
"outlineViewColumns":outlineViewColumns,
|
||||
"corkBackground":corkBackground,
|
||||
"fullScreenTheme":fullScreenTheme,
|
||||
}
|
||||
|
||||
#pp=pprint.PrettyPrinter(indent=4, compact=False)
|
||||
|
@ -150,4 +153,8 @@ def load(string, fromString=False):
|
|||
|
||||
if "corkBackground" in allSettings:
|
||||
global corkBackground
|
||||
corkBackground = allSettings["corkBackground"]
|
||||
corkBackground = allSettings["corkBackground"]
|
||||
|
||||
if "fullScreenTheme" in allSettings:
|
||||
global fullScreenTheme
|
||||
fullScreenTheme = allSettings["fullScreenTheme"]
|
|
@ -91,8 +91,8 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
self.cmbThemeEdit.setCurrentIndex(0)
|
||||
self.cmbThemeEdit.currentIndexChanged.emit(0)
|
||||
self.themeStack.setCurrentIndex(0)
|
||||
self.populatesThemesList()
|
||||
self.lstThemes.currentItemChanged.connect(self.themeSelected)
|
||||
self.populatesThemesList()
|
||||
self.btnThemeAdd.clicked.connect(self.newTheme)
|
||||
self.btnThemeEdit.clicked.connect(self.editTheme)
|
||||
self.btnThemeRemove.clicked.connect(self.removeTheme)
|
||||
|
@ -280,9 +280,14 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
|
||||
def themeSelected(self, current, previous):
|
||||
if current:
|
||||
# UI updates
|
||||
self.btnThemeEdit.setEnabled(current.data(Qt.UserRole+1))
|
||||
self.btnThemeRemove.setEnabled(current.data(Qt.UserRole+1))
|
||||
# Save settings
|
||||
theme = current.data(Qt.UserRole)
|
||||
settings.fullScreenTheme = os.path.splitext(os.path.split(theme)[1])[0]
|
||||
else:
|
||||
# UI updates
|
||||
self.btnThemeEdit.setEnabled(False)
|
||||
self.btnThemeRemove.setEnabled(False)
|
||||
|
||||
|
@ -300,7 +305,6 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
settings = QSettings(name, QSettings.IniFormat)
|
||||
settings.setValue("Name", self.tr("New theme"))
|
||||
settings.sync()
|
||||
print(name)
|
||||
|
||||
self.populatesThemesList()
|
||||
|
||||
|
@ -318,6 +322,7 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
|
||||
def populatesThemesList(self):
|
||||
paths = allPaths("resources/themes")
|
||||
current = settings.fullScreenTheme
|
||||
self.lstThemes.clear()
|
||||
|
||||
for p in paths:
|
||||
|
@ -346,8 +351,17 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
item.setIcon(QIcon(px))
|
||||
|
||||
self.lstThemes.addItem(item)
|
||||
|
||||
if current and current in t:
|
||||
self.lstThemes.setCurrentItem(item)
|
||||
current = None
|
||||
|
||||
self.lstThemes.setIconSize(QSize(200, 120))
|
||||
|
||||
if current: # the theme from settings wasn't found
|
||||
# select the last from the list
|
||||
self.lstThemes.setCurrentRow(self.lstThemes.count() - 1)
|
||||
|
||||
def loadTheme(self, theme):
|
||||
self._editingTheme = theme
|
||||
self._loadingTheme = True # So we don't generate preview while loading
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
from qt import *
|
||||
from enums import *
|
||||
from ui.editors.editorWidget_ui import *
|
||||
from ui.editors.fullScreenEditor import *
|
||||
from ui.views.textEditView import *
|
||||
from functions import *
|
||||
import settings
|
||||
|
@ -237,26 +238,29 @@ class editorWidget(QWidget, Ui_editorWidget_ui):
|
|||
self.dictChanged.emit(dct)
|
||||
|
||||
def showFullscreen(self):
|
||||
self._parent = self.parent()
|
||||
self._geometry = self.geometry()
|
||||
self._fullscreen = True
|
||||
currentScreen = qApp.desktop().screenNumber(self)
|
||||
self.setParent(None)
|
||||
mainWindow().hide()
|
||||
|
||||
self.stack.setStyleSheet("""
|
||||
QTextEdit {{
|
||||
margin-left: {m}px;
|
||||
margin-right: {m}px;
|
||||
}};""".format(
|
||||
m=str((qApp.desktop().screenGeometry(currentScreen).width() - 800) / 2))
|
||||
)
|
||||
self.testW = fullScreenEditor()
|
||||
|
||||
self.move(qApp.desktop().screenGeometry(currentScreen).topLeft())
|
||||
QWidget.showFullScreen(self)
|
||||
#self._parent = self.parent()
|
||||
#self._geometry = self.geometry()
|
||||
#self._fullscreen = True
|
||||
#currentScreen = qApp.desktop().screenNumber(self)
|
||||
#self.setParent(None)
|
||||
#mainWindow().hide()
|
||||
|
||||
#FIXME: too big?
|
||||
print(qApp.desktop().screenGeometry(currentScreen), self.geometry())
|
||||
#self.stack.setStyleSheet("""
|
||||
#QTextEdit {{
|
||||
#margin-left: {m}px;
|
||||
#margin-right: {m}px;
|
||||
#}};""".format(
|
||||
#m=str((qApp.desktop().screenGeometry(currentScreen).width() - 800) / 2))
|
||||
#)
|
||||
|
||||
#self.move(qApp.desktop().screenGeometry(currentScreen).topLeft())
|
||||
#QWidget.showFullScreen(self)
|
||||
|
||||
##FIXME: too big?
|
||||
#print(qApp.desktop().screenGeometry(currentScreen), self.geometry())
|
||||
|
||||
|
||||
|
||||
|
|
128
src/ui/editors/fullScreenEditor.py
Normal file
128
src/ui/editors/fullScreenEditor.py
Normal file
|
@ -0,0 +1,128 @@
|
|||
#!/usr/bin/env python
|
||||
#--!-- coding: utf8 --!--
|
||||
|
||||
from qt import *
|
||||
from enums import *
|
||||
from ui.views.textEditView import *
|
||||
from ui.editors.themes import *
|
||||
from functions import *
|
||||
import settings
|
||||
|
||||
class fullScreenEditor(QWidget):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
self._background = None
|
||||
self._theme = findThemePath(settings.fullScreenTheme)
|
||||
self._themeDatas = loadThemeDatas(self._theme)
|
||||
self.setMouseTracking(True)
|
||||
|
||||
# Text editor
|
||||
self.editor = textEditView(self, dict=settings.dict)
|
||||
self.editor.setFrameStyle(QFrame.NoFrame)
|
||||
self.editor.document().setPlainText(open(appPath("resources/themes/preview.txt")).read() * 5)
|
||||
self.editor.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||
self.editor.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||
self.editor.installEventFilter(self)
|
||||
self.editor.setMouseTracking(True)
|
||||
|
||||
|
||||
# Scroll bar
|
||||
if self._themeDatas["Foreground/Color"] == self._themeDatas["Background/Color"] or \
|
||||
self._themeDatas["Foreground/Opacity"] < 5:
|
||||
color = QColor(self._themeDatas["Text/Color"])
|
||||
else:
|
||||
color = QColor(self._themeDatas["Foreground/Color"])
|
||||
color.setAlpha(self._themeDatas["Foreground/Opacity"] * 255 / 100)
|
||||
self.editor.setVerticalScrollBar(myScrollBar(color))
|
||||
self.scrollBar = self.editor.verticalScrollBar()
|
||||
self.scrollBar.setParent(self)
|
||||
|
||||
# Panel
|
||||
self.panel = myPanel(color, self)
|
||||
|
||||
|
||||
#self.updateTheme()
|
||||
self.showFullScreen()
|
||||
#self.showMaximized()
|
||||
#self.show()
|
||||
|
||||
def setTheme(self, themeName):
|
||||
self._theme = findThemePath(settings.fullScreenTheme)
|
||||
self._themeDatas = loadThemeDatas(self._theme)
|
||||
self.updateTheme()
|
||||
|
||||
def updateTheme(self):
|
||||
rect = self.geometry()
|
||||
self._background = generateTheme(self._themeDatas, rect)
|
||||
|
||||
setThemeEditorDatas(self.editor, self._themeDatas, self._background, rect)
|
||||
|
||||
#set ScrollBar
|
||||
r = self.editor.geometry()
|
||||
w = qApp.style().pixelMetric(QStyle.PM_ScrollBarExtent)
|
||||
r.setWidth(w)
|
||||
r.moveRight(rect.right())
|
||||
self.scrollBar.setGeometry(r)
|
||||
self.scrollBar.setVisible(False)
|
||||
|
||||
# Set Panel
|
||||
r = QRect(0, 0, 400, 120)
|
||||
r.moveBottom(rect.bottom())
|
||||
r.moveLeft(rect.center().x() - r.width() / 2)
|
||||
self.panel.setGeometry(r)
|
||||
self.panel.setVisible(False)
|
||||
|
||||
def paintEvent(self, event):
|
||||
if self._background:
|
||||
painter = QPainter(self)
|
||||
painter.drawPixmap(event.rect(), self._background, event.rect())
|
||||
painter.end()
|
||||
|
||||
def resizeEvent(self, event):
|
||||
self.updateTheme()
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
if event.key() in [Qt.Key_Escape, Qt.Key_F11]:
|
||||
self.close()
|
||||
else:
|
||||
QWidget.keyPressEvent(self, event)
|
||||
|
||||
def mouseMoveEvent(self, event):
|
||||
r = self.geometry()
|
||||
#print(event.pos(), r)
|
||||
|
||||
for w in [self.scrollBar, self.panel]:
|
||||
w.setVisible(w.geometry().contains(event.pos()))
|
||||
|
||||
def eventFilter(self, obj, event):
|
||||
if event.type() == QEvent.MouseMove or obj == self.editor and event.type() == QEvent.Enter:
|
||||
self.mouseMoveEvent(event)
|
||||
return QWidget.eventFilter(self, obj, event)
|
||||
|
||||
class myScrollBar(QScrollBar):
|
||||
def __init__(self, color=Qt.white, parent=None):
|
||||
QScrollBar.__init__(self, parent)
|
||||
self._color = color
|
||||
|
||||
def paintEvent(self, event):
|
||||
opt = QStyleOptionSlider()
|
||||
self.initStyleOption(opt)
|
||||
style = qApp.style()
|
||||
painter = QPainter(self)
|
||||
#slider
|
||||
r = style.subControlRect(style.CC_ScrollBar, opt, style.SC_ScrollBarSlider)
|
||||
painter.fillRect(r, self._color)
|
||||
painter.end()
|
||||
|
||||
class myPanel(QWidget):
|
||||
def __init__(self, color=Qt.white, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
self._color = color
|
||||
self.show()
|
||||
self.setAttribute(Qt.WA_TranslucentBackground)
|
||||
|
||||
def paintEvent(self, event):
|
||||
r = event.rect()
|
||||
painter = QPainter(self)
|
||||
painter.fillRect(r, self._color)
|
|
@ -28,7 +28,9 @@ class t2tHighlighter (QSyntaxHighlighter):
|
|||
self.thisDocument = editor.document()
|
||||
|
||||
self.style = t2tHighlighterStyle(self.editor, style)
|
||||
|
||||
self._defaultBlockFormat = QTextBlockFormat()
|
||||
self._misspelledColor = Qt.red
|
||||
|
||||
self.inDocRules = []
|
||||
|
||||
rules = [
|
||||
|
@ -60,6 +62,13 @@ class t2tHighlighter (QSyntaxHighlighter):
|
|||
for (pattern, state) in rules]
|
||||
State.Recursion = 0
|
||||
|
||||
def setDefaultBlockFormat(self, bf):
|
||||
self._defaultBlockFormat = bf
|
||||
self.rehighlight()
|
||||
|
||||
def setMisspelledColor(self, color):
|
||||
self._misspelledColor = color
|
||||
|
||||
def highlightBlock(self, text):
|
||||
"""Apply syntax highlighting to the given block of text.
|
||||
"""
|
||||
|
@ -68,8 +77,11 @@ class t2tHighlighter (QSyntaxHighlighter):
|
|||
if self.style is None:
|
||||
default = QTextBlockFormat()
|
||||
QTextCursor(self.currentBlock()).setBlockFormat(default)
|
||||
print("t2tHighlighter.py: is style supposed to be None?")
|
||||
return
|
||||
|
||||
|
||||
QTextCursor(self.currentBlock()).setBlockFormat(self._defaultBlockFormat)
|
||||
|
||||
block = self.currentBlock()
|
||||
oldState = blockUserData.getUserState(block)
|
||||
self.identifyBlock(block)
|
||||
|
@ -177,9 +189,9 @@ class t2tHighlighter (QSyntaxHighlighter):
|
|||
# Uncomment for markup to be same size as title
|
||||
#op = self.formats(preset="markup",
|
||||
#base=self.formats(preset=state))
|
||||
self.setFormat(r.pos(2), r.cap(2).length(), f)
|
||||
self.setFormat(r.pos(1), r.cap(1).length(), op)
|
||||
self.setFormat(r.pos(3), r.cap(3).length(), op)
|
||||
self.setFormat(r.pos(2), len(r.cap(2)), f)
|
||||
self.setFormat(r.pos(1), len(r.cap(1)), op)
|
||||
self.setFormat(r.pos(3), len(r.cap(3)), op)
|
||||
|
||||
# Areas: comment, code, raw tagged
|
||||
for (begins, middle, ends) in [
|
||||
|
@ -234,18 +246,18 @@ class t2tHighlighter (QSyntaxHighlighter):
|
|||
#if max([k[pos] for k in formatArray]) == 0 or 1 == 1:
|
||||
self.setFormat(pos, 1,
|
||||
self.style.format(State.MARKUP))
|
||||
self.setFormat(pos + 1, r.cap(0).length() - 1,
|
||||
self.setFormat(pos + 1, len(r.cap(0)) - 1,
|
||||
self.style.format(State.LINKS))
|
||||
self.setFormat(pos + r.cap(0).length() - 1, 1,
|
||||
self.setFormat(pos + len(r.cap(0)) - 1, 1,
|
||||
self.style.format(State.MARKUP))
|
||||
if r.pos(2) > 0:
|
||||
_f = QTextCharFormat(self.style.format(State.LINKS))
|
||||
_f.setForeground(QBrush(_f.foreground()
|
||||
.color().lighter()))
|
||||
_f.setFontUnderline(True)
|
||||
self.setFormat(r.pos(2), r.cap(2).length(), _f)
|
||||
self.setFormat(r.pos(2), len(r.cap(2)), _f)
|
||||
|
||||
links.append([pos, r.cap(0).length()]) # To remember for the next highlighter (single links)
|
||||
links.append([pos, len(r.cap(0))]) # To remember for the next highlighter (single links)
|
||||
pos = r.indexIn(text, pos + 1)
|
||||
|
||||
# Links like www.theologeek.ch, http://www.fsf.org, ...
|
||||
|
@ -262,7 +274,7 @@ class t2tHighlighter (QSyntaxHighlighter):
|
|||
if pos > k[0] and pos < k[0] + k[1]: # already highlighted
|
||||
break
|
||||
else:
|
||||
self.setFormat(pos, r.cap(0).length(), self.style.format(State.LINKS))
|
||||
self.setFormat(pos, len(r.cap(0)), self.style.format(State.LINKS))
|
||||
|
||||
pos = r.indexIn(text, pos + 1)
|
||||
|
||||
|
@ -279,7 +291,7 @@ class t2tHighlighter (QSyntaxHighlighter):
|
|||
pos = r.indexIn(text)
|
||||
while pos >= 0:
|
||||
if max([k[pos] for k in formatArray]) == 0:
|
||||
self.setFormat(pos, r.cap(0).length(),
|
||||
self.setFormat(pos, len(r.cap(0)),
|
||||
self.style.format(State.MACRO))
|
||||
pos = r.indexIn(text, pos + 1)
|
||||
|
||||
|
@ -322,9 +334,9 @@ class t2tHighlighter (QSyntaxHighlighter):
|
|||
if state not in [State.SETTINGS_LINE]:
|
||||
if self.editor.spellcheck:
|
||||
for word_object in re.finditer(WORDS, text):
|
||||
if not self.editor.dict.check(word_object.group()):
|
||||
if self.editor._dict and not self.editor._dict.check(word_object.group()):
|
||||
format = self.format(word_object.start())
|
||||
format.setUnderlineColor(Qt.red)
|
||||
format.setUnderlineColor(self._misspelledColor)
|
||||
format.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
|
||||
self.setFormat(word_object.start(),
|
||||
word_object.end() - word_object.start(), format)
|
||||
|
@ -476,7 +488,7 @@ class t2tHighlighter (QSyntaxHighlighter):
|
|||
block.userState() >= 100:
|
||||
return True
|
||||
|
||||
def setStyle(self, style):
|
||||
def setStyle(self, style="Default"):
|
||||
if style in t2tHighlighterStyle.validStyles:
|
||||
self.style = t2tHighlighterStyle(self.editor, style)
|
||||
else:
|
||||
|
|
|
@ -101,7 +101,7 @@ class t2tHighlighterStyle ():
|
|||
def formatBlock(self, block, state):
|
||||
"Apply transformation to given block."
|
||||
blockFormat = QTextBlockFormat()
|
||||
|
||||
|
||||
if state == State.BLOCKQUOTE_LINE:
|
||||
# Number of tabs
|
||||
n = block.text().indexOf(QRegExp(r'[^\t]'), 0)
|
||||
|
@ -125,6 +125,7 @@ class t2tHighlighterStyle ():
|
|||
else:
|
||||
blockFormat.setBackground(QColor("#EEEEFA"))
|
||||
n = blockUserData.getUserData(block).leadingSpaces() + 1
|
||||
|
||||
f = QFontMetrics(QFont(self.defaultFontFamily,
|
||||
self.defaultFontPointSize))
|
||||
fm = f.width(" " * n +
|
||||
|
@ -144,9 +145,11 @@ class t2tHighlighterStyle ():
|
|||
|
||||
_color = QColor()
|
||||
_format = QTextCharFormat()
|
||||
size = self.defaultFontPointSize
|
||||
_format.setFontFamily(self.defaultFontFamily)
|
||||
|
||||
#size = self.defaultFontPointSize
|
||||
#_format.setFontFamily(self.defaultFontFamily)
|
||||
_format.setFont(self.editor.font())
|
||||
size = _format.fontPointSize()
|
||||
|
||||
# Base
|
||||
if base: _format = base
|
||||
|
||||
|
@ -217,9 +220,9 @@ class t2tHighlighterStyle ():
|
|||
if preset == "higlighted":
|
||||
bgcolor = "yellow"
|
||||
|
||||
if preset == State.DEFAULT:
|
||||
size = self.defaultFontPointSize
|
||||
_format.setFontFamily(self.defaultFontFamily)
|
||||
#if preset == State.DEFAULT:
|
||||
#size = self.defaultFontPointSize
|
||||
#_format.setFontFamily(self.defaultFontFamily)
|
||||
|
||||
# Manual formatting
|
||||
if color:
|
||||
|
@ -241,5 +244,5 @@ class t2tHighlighterStyle ():
|
|||
_format.setFontPointSize(size)
|
||||
if fixedPitch:
|
||||
_format.setFontFixedPitch(True)
|
||||
|
||||
|
||||
return _format
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
#--!-- coding: utf8 --!--
|
||||
|
||||
|
||||
# Lots of stuff from here comes from the excellet focuswriter.
|
||||
|
||||
from qt import *
|
||||
from enums import *
|
||||
from functions import *
|
||||
from ui.views.textEditView import *
|
||||
import settings
|
||||
|
||||
def loadThemeDatas(themeFile):
|
||||
|
@ -84,6 +87,8 @@ def createThemePreview(theme, screenRect, size=QSize(200, 120)):
|
|||
|
||||
pixmap = generateTheme(themeDatas, screenRect)
|
||||
|
||||
addThemePreviewText(pixmap, themeDatas, screenRect)
|
||||
|
||||
px = QPixmap(pixmap).scaled(size, Qt.KeepAspectRatio)
|
||||
|
||||
w = px.width() / 10
|
||||
|
@ -97,6 +102,20 @@ def createThemePreview(theme, screenRect, size=QSize(200, 120)):
|
|||
painter.end()
|
||||
|
||||
return px
|
||||
|
||||
def findThemePath(themeName):
|
||||
return findFirstFile(themeName, "resources/themes", "{}.theme")
|
||||
|
||||
def findBackground(filename):
|
||||
return findFirstFile(filename, "resources/backgrounds")
|
||||
|
||||
def findFirstFile(filename, path="resources", mask="{}"):
|
||||
paths = allPaths(path)
|
||||
for p in paths:
|
||||
lst = os.listdir(p)
|
||||
for l in lst:
|
||||
if l == mask.format(filename):
|
||||
return os.path.join(p, l)
|
||||
|
||||
def generateTheme(themeDatas, screenRect):
|
||||
|
||||
|
@ -136,54 +155,77 @@ def generateTheme(themeDatas, screenRect):
|
|||
painter.restore()
|
||||
|
||||
painter.end()
|
||||
return px
|
||||
|
||||
# Text
|
||||
previewText = QTextEdit()
|
||||
previewText.setFrameStyle(QFrame.NoFrame)
|
||||
previewText.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||
previewText.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||
previewText.setPlainText(open(appPath("resources/themes/preview.txt")).read())
|
||||
def themeEditorGeometry(themeDatas, textRect):
|
||||
|
||||
padding = themeDatas["Foreground/Padding"]
|
||||
x = textRect.x() + padding
|
||||
y = textRect.y() + padding + themeDatas["Spacings/ParagraphAbove"]
|
||||
width = textRect.width() - 2 * padding
|
||||
height = textRect.height() - 2 * padding - themeDatas["Spacings/ParagraphAbove"]
|
||||
previewText.setGeometry(x, y, width, height)
|
||||
|
||||
p = previewText.palette()
|
||||
p.setBrush(QPalette.Base, QBrush(px.copy(x, y, width, height)))
|
||||
p.setColor(QPalette.Text, QColor(themeDatas["Text/Color"]))
|
||||
p.setColor(QPalette.Highlight, QColor(themeDatas["Text/Color"]))
|
||||
p.setColor(QPalette.HighlightedText, Qt.black if qGray(QColor(themeDatas["Text/Color"]).rgb()) > 127 else Qt.white)
|
||||
previewText.setPalette(p)
|
||||
return x, y, width, height
|
||||
|
||||
def getThemeBlockFormat(themeDatas):
|
||||
bf = QTextBlockFormat()
|
||||
bf.setLineHeight(themeDatas["Spacings/LineSpacing"], QTextBlockFormat.ProportionalHeight)
|
||||
bf.setTextIndent(themeDatas["Spacings/TabWidth"] * 1 if themeDatas["Spacings/IndendFirstLine"] else 0)
|
||||
bf.setTopMargin(themeDatas["Spacings/ParagraphAbove"])
|
||||
bf.setBottomMargin(themeDatas["Spacings/ParagraphBelow"])
|
||||
return bf
|
||||
|
||||
b = previewText.document().firstBlock()
|
||||
cursor = previewText.textCursor()
|
||||
while b.isValid():
|
||||
bf2 = b.blockFormat()
|
||||
bf2.merge(bf)
|
||||
cursor.setPosition(b.position())
|
||||
#cursor.setPosition(b.position(), QTextCursor.KeepAnchor)
|
||||
cursor.setBlockFormat(bf2)
|
||||
b = b.next()
|
||||
def setThemeEditorDatas(editor, themeDatas, pixmap, screenRect):
|
||||
|
||||
previewText.setTabStopWidth(themeDatas["Spacings/TabWidth"])
|
||||
previewText.document().setIndentWidth(themeDatas["Spacings/TabWidth"])
|
||||
textRect = themeTextRect(themeDatas, screenRect)
|
||||
x, y, width, height = themeEditorGeometry(themeDatas, textRect)
|
||||
editor.setGeometry(x, y, width, height)
|
||||
|
||||
p = editor.palette()
|
||||
#p.setBrush(QPalette.Base, QBrush(pixmap.copy(x, y, width, height)))
|
||||
p.setBrush(QPalette.Base, QColor(Qt.transparent))
|
||||
p.setColor(QPalette.Text, QColor(themeDatas["Text/Color"]))
|
||||
p.setColor(QPalette.Highlight, QColor(themeDatas["Text/Color"]))
|
||||
p.setColor(QPalette.HighlightedText, Qt.black if qGray(QColor(themeDatas["Text/Color"]).rgb()) > 127 else Qt.white)
|
||||
editor.setPalette(p)
|
||||
|
||||
editor.setAttribute(Qt.WA_NoSystemBackground, True)
|
||||
|
||||
bf = getThemeBlockFormat(themeDatas)
|
||||
editor.setDefaultBlockFormat(bf)
|
||||
|
||||
#b = editor.document().firstBlock()
|
||||
#cursor = editor.textCursor()
|
||||
#cursor.setBlockFormat(bf)
|
||||
#while b.isValid():
|
||||
#bf2 = b.blockFormat()
|
||||
#bf2.merge(bf)
|
||||
#cursor.setPosition(b.position())
|
||||
##cursor.setPosition(b.position(), QTextCursor.KeepAnchor)
|
||||
#cursor.setBlockFormat(bf2)
|
||||
#b = b.next()
|
||||
|
||||
editor.setTabStopWidth(themeDatas["Spacings/TabWidth"])
|
||||
editor.document().setIndentWidth(themeDatas["Spacings/TabWidth"])
|
||||
|
||||
f = QFont()
|
||||
f.fromString(themeDatas["Text/Font"])
|
||||
previewText.setFont(f)
|
||||
editor.setFont(f)
|
||||
editor.highlighter.setMisspelledColor(QColor(themeDatas["Text/Misspelled"]))
|
||||
|
||||
previewText.render(px, previewText.pos())
|
||||
return px
|
||||
editor.highlighter.setStyle() # Reupdates highlighter styles
|
||||
|
||||
def addThemePreviewText(pixmap, themeDatas, screenRect):
|
||||
|
||||
# Text
|
||||
previewText = textEditView()
|
||||
previewText.setFrameStyle(QFrame.NoFrame)
|
||||
previewText.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||
previewText.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||
previewText.setPlainText(open(appPath("resources/themes/preview.txt")).read())
|
||||
|
||||
setThemeEditorDatas(previewText, themeDatas, pixmap, screenRect)
|
||||
|
||||
previewText.render(pixmap, previewText.pos())
|
||||
|
||||
## Text Background
|
||||
##themeDatas["Foreground/Color"]
|
||||
|
|
|
@ -28,6 +28,11 @@ class textEditView(QTextEdit):
|
|||
self.currentDict = dict
|
||||
self.highlighter = None
|
||||
self._autoResize = autoResize
|
||||
self._defaultBlockFormat = QTextBlockFormat()
|
||||
self.highlightWord = ""
|
||||
self.highligtCS = False
|
||||
self.defaultFontPointSize = qApp.font().pointSize()
|
||||
self._dict = None
|
||||
|
||||
if index:
|
||||
self.setCurrentModelIndex(index)
|
||||
|
@ -37,6 +42,16 @@ class textEditView(QTextEdit):
|
|||
self.setReadOnly(True)
|
||||
|
||||
self.setAutoResize(self._autoResize)
|
||||
|
||||
# Spellchecking
|
||||
if enchant and self.spellcheck:
|
||||
self._dict = enchant.Dict(self.currentDict if self.currentDict else enchant.get_default_language())
|
||||
else:
|
||||
self.spellcheck = False
|
||||
|
||||
if self._highlighting and not self.highlighter:
|
||||
self.highlighter = t2tHighlighter(self)
|
||||
self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
|
||||
|
||||
def setModel(self, model):
|
||||
self._model = model
|
||||
|
@ -48,6 +63,11 @@ class textEditView(QTextEdit):
|
|||
def setHighlighting(self, val):
|
||||
self._highlighting = val
|
||||
|
||||
def setDefaultBlockFormat(self, bf):
|
||||
self._defaultBlockFormat = bf
|
||||
if self.highlighter:
|
||||
self.highlighter.setDefaultBlockFormat(bf)
|
||||
|
||||
def setCurrentModelIndex(self, index):
|
||||
self._indexes = None
|
||||
if index.isValid():
|
||||
|
@ -63,18 +83,9 @@ class textEditView(QTextEdit):
|
|||
self._model.dataChanged.connect(self.update)
|
||||
self.updateText()
|
||||
|
||||
self.defaultFontPointSize = qApp.font().pointSize()
|
||||
self.highlightWord = ""
|
||||
self.highligtCS = False
|
||||
|
||||
if self._highlighting and not self.highlighter:
|
||||
self.highlighter = t2tHighlighter(self)
|
||||
|
||||
# Spellchecking
|
||||
if enchant and self.spellcheck:
|
||||
self.dict = enchant.Dict(self.currentDict if self.currentDict else enchant.get_default_language())
|
||||
else:
|
||||
self.spellcheck = False
|
||||
self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
|
||||
|
||||
def setCurrentModelIndexes(self, indexes):
|
||||
self._index = None
|
||||
|
@ -180,14 +191,18 @@ class textEditView(QTextEdit):
|
|||
|
||||
def setDict(self, d):
|
||||
self.currentDict = d
|
||||
self.dict = enchant.Dict(d)
|
||||
self._dict = enchant.Dict(d)
|
||||
if self.highlighter:
|
||||
self.highlighter.rehighlight()
|
||||
|
||||
def toggleSpellcheck(self, v):
|
||||
self.spellcheck = v
|
||||
if enchant and self.spellcheck and not self._dict:
|
||||
self._dict = enchant.Dict(self.currentDict if self.currentDict else enchant.get_default_language())
|
||||
if self.highlighter:
|
||||
self.highlighter.rehighlight()
|
||||
else:
|
||||
self.spellcheck = False
|
||||
|
||||
def mousePressEvent(self, event):
|
||||
if event.button() == Qt.RightButton:
|
||||
|
@ -226,9 +241,9 @@ class textEditView(QTextEdit):
|
|||
# suggestions if it is.
|
||||
if self.textCursor().hasSelection():
|
||||
text = str(self.textCursor().selectedText())
|
||||
if not self.dict.check(text):
|
||||
if not self._dict.check(text):
|
||||
spell_menu = QMenu(self.tr('Spelling Suggestions'))
|
||||
for word in self.dict.suggest(text):
|
||||
for word in self._dict.suggest(text):
|
||||
action = self.SpellAction(word, spell_menu)
|
||||
action.correct.connect(self.correctWord)
|
||||
spell_menu.addAction(action)
|
||||
|
|
Loading…
Reference in a new issue