mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-10-01 01:36:27 +13:00
260 lines
No EOL
9.7 KiB
Python
260 lines
No EOL
9.7 KiB
Python
#!/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, index, parent=None):
|
|
QWidget.__init__(self, parent)
|
|
self._background = None
|
|
self._index = index
|
|
self._index.model().dataChanged.connect(self.dataChanged)
|
|
self._theme = findThemePath(settings.fullScreenTheme)
|
|
self._themeDatas = loadThemeDatas(self._theme)
|
|
self.setMouseTracking(True)
|
|
|
|
# Text editor
|
|
self.editor = textEditView(self, index=index, spellcheck=settings.spellcheck, dict=settings.dict)
|
|
self.editor.setFrameStyle(QFrame.NoFrame)
|
|
#f = QFile(appPath("resources/themes/preview.txt"))
|
|
#f.open(QIODevice.ReadOnly)
|
|
#self.editor.setPlainText(QTextStream(f).readAll()*5)
|
|
self.editor.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
self.editor.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
self.editor.installEventFilter(self)
|
|
self.editor.setMouseTracking(True)
|
|
|
|
self.editor.setVerticalScrollBar(myScrollBar())
|
|
self.scrollBar = self.editor.verticalScrollBar()
|
|
self.scrollBar.setParent(self)
|
|
|
|
# Top Panel
|
|
self.topPanel = myPanel(parent=self)
|
|
self.topPanel.layout().addStretch(1)
|
|
|
|
self.btnSpellCheck = QPushButton()
|
|
self.btnSpellCheck.setFlat(True)
|
|
self.btnSpellCheck.setIcon(QIcon.fromTheme("tools-check-spelling"))
|
|
self.btnSpellCheck.setCheckable(True)
|
|
self.btnSpellCheck.setChecked(self.editor.spellcheck)
|
|
self.btnSpellCheck.toggled.connect(self.editor.toggleSpellcheck)
|
|
self.topPanel.layout().addWidget(self.btnSpellCheck)
|
|
self.topPanel.layout().addStretch(1)
|
|
|
|
b = QPushButton(self)
|
|
b.setIcon(qApp.style().standardIcon(QStyle.SP_DialogCloseButton))
|
|
b.clicked.connect(self.close)
|
|
b.setFlat(True)
|
|
self.topPanel.layout().addWidget(b)
|
|
|
|
# Bottom Panel
|
|
self.bottomPanel = myPanel(parent=self)
|
|
|
|
self.bottomPanel.layout().addSpacing(24)
|
|
self.lstThemes = QComboBox(self)
|
|
self.lstThemes.setAttribute(Qt.WA_TranslucentBackground)
|
|
paths = allPaths("resources/themes")
|
|
for p in paths:
|
|
lst = [i for i in os.listdir(p) if os.path.splitext(i)[1] == ".theme"]
|
|
for t in lst:
|
|
themeIni = os.path.join(p, t)
|
|
self.lstThemes.addItem(os.path.splitext(t)[0])
|
|
self.lstThemes.currentTextChanged.connect(self.setTheme)
|
|
self.lstThemes.setMaximumSize(QSize(300, QFontMetrics(qApp.font()).height()))
|
|
self.bottomPanel.layout().addWidget(QLabel(self.tr("Theme:"), self))
|
|
self.bottomPanel.layout().addWidget(self.lstThemes)
|
|
self.bottomPanel.layout().addStretch(1)
|
|
|
|
self.lblProgress = QLabel(self)
|
|
self.lblProgress.setMaximumSize(QSize(200, 14))
|
|
self.lblProgress.setMinimumSize(QSize(100, 14))
|
|
self.lblWC = QLabel(self)
|
|
self.bottomPanel.layout().addWidget(self.lblWC)
|
|
self.bottomPanel.layout().addWidget(self.lblProgress)
|
|
self.updateStatusBar()
|
|
|
|
self.bottomPanel.layout().addSpacing(24)
|
|
|
|
#self.updateTheme()
|
|
self.showFullScreen()
|
|
#self.showMaximized()
|
|
#self.show()
|
|
|
|
def setTheme(self, themeName):
|
|
settings.fullScreenTheme = themeName
|
|
self._theme = findThemePath(themeName)
|
|
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)
|
|
|
|
# Colors
|
|
if self._themeDatas["Foreground/Color"] == self._themeDatas["Background/Color"] or \
|
|
self._themeDatas["Foreground/Opacity"] < 5:
|
|
self._bgcolor = QColor(self._themeDatas["Text/Color"])
|
|
self._fgcolor = QColor(self._themeDatas["Background/Color"])
|
|
else:
|
|
self._bgcolor = QColor(self._themeDatas["Foreground/Color"])
|
|
self._bgcolor.setAlpha(self._themeDatas["Foreground/Opacity"] * 255 / 100)
|
|
self._fgcolor = QColor(self._themeDatas["Text/Color"])
|
|
if self._themeDatas["Text/Color"] == self._themeDatas["Foreground/Color"]:
|
|
self._fgcolor = QColor(self._themeDatas["Background/Color"])
|
|
|
|
# ScrollBar
|
|
r = self.editor.geometry()
|
|
w = qApp.style().pixelMetric(QStyle.PM_ScrollBarExtent)
|
|
r.setWidth(w)
|
|
r.moveRight(rect.right() - rect.left())
|
|
self.scrollBar.setGeometry(r)
|
|
self.scrollBar.setVisible(False)
|
|
p = self.scrollBar.palette()
|
|
b = QBrush(self._background.copy(self.scrollBar.geometry()))
|
|
p.setBrush(QPalette.Base, b)
|
|
self.scrollBar.setPalette(p)
|
|
|
|
self.scrollBar.setColor(self._bgcolor)
|
|
|
|
# Panels
|
|
r = QRect(0, 0, 0, 24)
|
|
r.setWidth(rect.width())
|
|
#r.moveLeft(rect.center().x() - r.width() / 2)
|
|
self.topPanel.setGeometry(r)
|
|
self.topPanel.setVisible(False)
|
|
r.moveBottom(rect.bottom() - rect.top())
|
|
self.bottomPanel.setGeometry(r)
|
|
self.bottomPanel.setVisible(False)
|
|
self.topPanel.setColor(self._bgcolor)
|
|
self.bottomPanel.setColor(self._bgcolor)
|
|
|
|
# Lst theme
|
|
#p = self.lstThemes.palette()
|
|
p = self.palette()
|
|
p.setBrush(QPalette.Button, self._bgcolor)
|
|
p.setBrush(QPalette.ButtonText, self._fgcolor)
|
|
p.setBrush(QPalette.WindowText, self._fgcolor)
|
|
|
|
for panel in (self.bottomPanel, self.topPanel):
|
|
for i in range(panel.layout().count()):
|
|
item = panel.layout().itemAt(i)
|
|
if item.widget():
|
|
item.widget().setPalette(p)
|
|
#self.lstThemes.setPalette(p)
|
|
#self.lblWC.setPalette(p)
|
|
|
|
self.update()
|
|
|
|
def paintEvent(self, event):
|
|
if self._background:
|
|
painter = QPainter(self)
|
|
painter.setClipRegion(event.region())
|
|
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()
|
|
|
|
for w in [self.scrollBar, self.topPanel, self.bottomPanel]:
|
|
w.setVisible(w.geometry().contains(event.pos()))
|
|
|
|
def eventFilter(self, obj, event):
|
|
if obj == self.editor and event.type() == QEvent.Enter:
|
|
for w in [self.scrollBar, self.topPanel, self.bottomPanel]:
|
|
w.setVisible(False)
|
|
return QWidget.eventFilter(self, obj, event)
|
|
|
|
def dataChanged(self, topLeft, bottomRight):
|
|
if not self._index:
|
|
return
|
|
if topLeft.row() <= self._index.row() <= bottomRight.row():
|
|
self.updateStatusBar()
|
|
|
|
def updateStatusBar(self):
|
|
if self._index:
|
|
item = self._index.internalPointer()
|
|
|
|
wc = item.data(Outline.wordCount.value)
|
|
goal = item.data(Outline.goal.value)
|
|
pg = item.data(Outline.goalPercentage.value)
|
|
|
|
if goal:
|
|
rect = self.lblProgress.geometry()
|
|
rect = QRect(QPoint(0, 0), rect.size())
|
|
self.px = QPixmap(rect.size())
|
|
self.px.fill(Qt.transparent)
|
|
p = QPainter(self.px)
|
|
drawProgress(p, rect, pg, 2)
|
|
p.end()
|
|
self.lblProgress.setPixmap(self.px)
|
|
self.lblWC.setText(self.tr("{} words / {}").format(wc, goal))
|
|
else:
|
|
mw.lblProgress.hide()
|
|
mw.lblWC.setText(self.tr("{} words").format(wc))
|
|
|
|
class myScrollBar(QScrollBar):
|
|
def __init__(self, color=Qt.white, parent=None):
|
|
QScrollBar.__init__(self, parent)
|
|
self._color = color
|
|
#self.setAttribute(Qt.WA_TranslucentBackground)
|
|
self.timer = QTimer()
|
|
self.timer.setInterval(500)
|
|
self.timer.setSingleShot(True)
|
|
self.timer.timeout.connect(self.hide)
|
|
self.valueChanged.connect(lambda v: self.timer.start())
|
|
self.valueChanged.connect(self.show)
|
|
|
|
def setColor(self, color):
|
|
self._color = color
|
|
|
|
def paintEvent(self, event):
|
|
opt = QStyleOptionSlider()
|
|
self.initStyleOption(opt)
|
|
style = qApp.style()
|
|
painter = QPainter(self)
|
|
|
|
# Background (Necessary with Qt 5.2 it seems, not with 5.4)
|
|
painter.save()
|
|
painter.setPen(Qt.NoPen)
|
|
painter.setBrush(self.palette().brush(QPalette.Base))
|
|
painter.drawRect(event.rect())
|
|
painter.restore()
|
|
|
|
#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)
|
|
self.setLayout(QHBoxLayout())
|
|
self.layout().setContentsMargins(0, 0, 0, 0)
|
|
|
|
def setColor(self, color):
|
|
self._color = color
|
|
|
|
def paintEvent(self, event):
|
|
r = event.rect()
|
|
painter = QPainter(self)
|
|
painter.fillRect(r, self._color) |