Skip to content

Commit

Permalink
Improves theme desktop integration greatly
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierkes committed Nov 14, 2017
2 parents 3c78b51 + ee212db commit a334e8b
Show file tree
Hide file tree
Showing 38 changed files with 1,121 additions and 1,026 deletions.
27 changes: 15 additions & 12 deletions manuskript/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ def toString(text):


def drawProgress(painter, rect, progress, radius=0):
from manuskript.ui import style as S
painter.setPen(Qt.NoPen)
painter.setBrush(QColor("#dddddd"))
painter.setBrush(QColor(S.base)) # "#dddddd"
painter.drawRoundedRect(rect, radius, radius)

painter.setBrush(QBrush(colorFromProgress(progress)))
Expand Down Expand Up @@ -145,14 +146,24 @@ def randomColor(mix=None):


def mixColors(col1, col2, f=.5):
fromString = False
if type(col1) == str:
fromString = True
col1 = QColor(col1)
if type(col2) == str:
col2 = QColor(col2)
f2 = 1-f
r = col1.red() * f + col2.red() * f2
g = col1.green() * f + col2.green() * f2
b = col1.blue() * f + col2.blue() * f2
return QColor(r, g, b)

return QColor(r, g, b) if not fromString else QColor(r, g, b).name()


def outlineItemColors(item):

from manuskript.ui import style as S

"""Takes an OutlineItem and returns a dict of colors."""
colors = {}
mw = mainWindow()
Expand Down Expand Up @@ -184,9 +195,9 @@ def outlineItemColors(item):

# Compile
if item.compile() in [0, "0"]:
colors["Compile"] = QColor(Qt.gray)
colors["Compile"] = mixColors(QColor(S.text), QColor(S.window))
else:
colors["Compile"] = QColor(Qt.black)
colors["Compile"] = QColor(Qt.transparent) # will use default

return colors

Expand Down Expand Up @@ -232,14 +243,6 @@ def tempFile(name):
return os.path.join(QDir.tempPath(), name)


def lightBlue():
"""
A light blue used in several places in manuskript.
@return: QColor
"""
return QColor(Qt.blue).lighter(190)


def totalObjects():
return len(mainWindow().findChildren(QObject))

Expand Down
1 change: 1 addition & 0 deletions manuskript/mainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ def loadProject(self, project, loadFromFile=True):
if loadFromFile:
# Load empty settings
imp.reload(settings)
settings.initDefaultValues()

# Load data
self.loadEmptyDatas()
Expand Down
89 changes: 45 additions & 44 deletions manuskript/models/persosProxyModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,107 +2,108 @@
#--!-- coding: utf8 --!--

from manuskript import enums
from manuskript.ui import style as S


class persosProxyModel(QSortFilterProxyModel):

newStatuses = pyqtSignal()

def __init__(self, parent=None):
QSortFilterProxyModel.__init__(self, parent)

#self.rootItem = QStandardItem()
self.p1 = QStandardItem(self.tr("Main"))
self.p2 = QStandardItem(self.tr("Secundary"))
self.p3 = QStandardItem(self.tr("Minors"))

self._cats = [
self.p1,
self.p2,
self.p3
]

def mapFromSource(self, sourceIndex):
if not sourceIndex.isValid():
return QModelIndex()

row = self._map.index(sourceIndex.row())
#item = sourceIndex.internalPointer()
item = self.sourceModel().itemFromIndex(sourceIndex)

return self.createIndex(row, sourceIndex.column(), item)

def flags(self, index):
if not index.isValid():
return Qt.NoItemFlags

if index.isValid() and not self.mapToSource(index).isValid():
return Qt.NoItemFlags#Qt.ItemIsEnabled
else:
return Qt.ItemIsEnabled | Qt.ItemIsSelectable

def mapToSource(self, proxyIndex):
if not proxyIndex.isValid():
return QModelIndex()

row = self._map[proxyIndex.row()]

if type(row) != int:
return QModelIndex()

#item = proxyIndex.internalPointer()
item = self.sourceModel().item(row, proxyIndex.column())

return self.sourceModel().indexFromItem(item)

def setSourceModel(self, model):
QSortFilterProxyModel.setSourceModel(self, model)
self.sourceModel().dataChanged.connect(self.mapModelMaybe)
self.sourceModel().rowsInserted.connect(self.mapModel)
self.sourceModel().rowsRemoved.connect(self.mapModel)
self.sourceModel().rowsMoved.connect(self.mapModel)

self.mapModel()

def mapModelMaybe(self, topLeft, bottomRight):
if topLeft.column() <= Perso.importance.value <= bottomRight.column():
self.mapModel()

def mapModel(self):
self.beginResetModel()
src = self.sourceModel()

self._map = []

for i, cat in enumerate(self._cats):
self._map.append(cat)

for p in range(src.rowCount()):
item = src.item(p, Perso.importance.value)

if item and item.text():
imp = int(item.text())
else:
imp = 0

if 2-imp == i:
self._map.append(p)

self.endResetModel()


def data(self, index, role=Qt.DisplayRole):

if index.isValid() and not self.mapToSource(index).isValid():
row = index.row()

if role == Qt.DisplayRole:
return self._map[row].text()

elif role == Qt.ForegroundRole:
return QBrush(Qt.darkBlue)
return QBrush(QColor(S.highlightedTextDark))
elif role == Qt.BackgroundRole:
return QBrush(QColor(Qt.blue).lighter(190))
return QBrush(QColor(S.highlightLight))
elif role == Qt.TextAlignmentRole:
return Qt.AlignCenter
elif role == Qt.FontRole:
Expand All @@ -113,32 +114,32 @@ def data(self, index, role=Qt.DisplayRole):
else:
#FIXME: sometimes, the name of the character is not displayed
return self.sourceModel().data(self.mapToSource(index), role)

def index(self, row, column, parent):

i = self._map[row]

if type(i) != int:

return self.createIndex(row, column, i)

else:

return self.mapFromSource(self.sourceModel().index(i, column, QModelIndex()))

def parent(self, index=QModelIndex()):
return QModelIndex()

def rowCount(self, parent=QModelIndex()):
return len(self._map)

def columnCount(self, parent=QModelIndex()):
return self.sourceModel().columnCount(QModelIndex())

def item(self, row, col, parent=QModelIndex()):
idx = self.mapToSource(self.index(row, col, parent))
return self.sourceModel().item(idx.row(), idx.column())


#def setData(self, index, value, role=Qt.EditRole):
#pass
#pass
5 changes: 3 additions & 2 deletions manuskript/models/plotsProxyModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from PyQt5.QtGui import QStandardItem

from manuskript.enums import Plot
from manuskript.ui import style as S


class plotsProxyModel(QSortFilterProxyModel):
Expand Down Expand Up @@ -105,9 +106,9 @@ def data(self, index, role=Qt.DisplayRole):
return self._map[row].text()

elif role == Qt.ForegroundRole:
return QBrush(Qt.darkBlue)
return QBrush(QColor(S.highlightedTextDark))
elif role == Qt.BackgroundRole:
return QBrush(QColor(Qt.blue).lighter(190))
return QBrush(QColor(S.highlightLight))
elif role == Qt.TextAlignmentRole:
return Qt.AlignCenter
elif role == Qt.FontRole:
Expand Down
9 changes: 5 additions & 4 deletions manuskript/models/worldModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from PyQt5.QtCore import QSize
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QStandardItem, QBrush, QFontMetrics
from PyQt5.QtGui import QStandardItemModel
from PyQt5.QtGui import QStandardItemModel, QColor
from PyQt5.QtWidgets import QMenu, QAction, qApp

from manuskript.enums import World
from manuskript.functions import mainWindow, lightBlue
from manuskript.functions import mainWindow
from manuskript.ui import style as S


class worldModel(QStandardItemModel):
Expand Down Expand Up @@ -254,7 +255,7 @@ def data(self, index, role=Qt.EditRole):

if role == Qt.BackgroundRole:
if level == 0:
return QBrush(lightBlue())
return QBrush(QColor(S.highlightLight))

if role == Qt.TextAlignmentRole:
if level == 0:
Expand All @@ -268,7 +269,7 @@ def data(self, index, role=Qt.EditRole):

if role == Qt.ForegroundRole:
if level == 0:
return QBrush(Qt.darkBlue)
return QBrush(QColor(S.highlightedTextDark))

if role == Qt.SizeHintRole:
fm = QFontMetrics(qApp.font())
Expand Down
19 changes: 17 additions & 2 deletions manuskript/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
fullScreenTheme = "spacedreams"

textEditor = {
"background": "#fff",
"fontColor": "#000",
"background": "",
"fontColor": "",
"font": qApp.font().toString(),
"misspelled": "#F00",
"lineSpacing": 100,
Expand All @@ -73,6 +73,7 @@
"maxWidth": 0,
"marginsLR": 0,
"marginsTB": 0,
"backgroundTransparent": False,
}

revisions = {
Expand All @@ -98,6 +99,19 @@
saveToZip = True
dontShowDeleteWarning = False

def initDefaultValues():
"""
Load some default values based on system's settings.
Is called anytime we open/create a project.
"""
global textEditor
if not textEditor["background"]:
from manuskript.ui import style as S
textEditor["background"] = S.base
if not textEditor["fontColor"]:
from manuskript.ui import style as S
textEditor["fontColor"] = S.text

def save(filename=None, protocol=None):

global spellcheck, dict, corkSliderFactor, viewSettings, corkSizeFactor, folderView, lastTab, openIndexes, \
Expand Down Expand Up @@ -256,6 +270,7 @@ def load(string, fromString=False, protocol=None):
"maxWidth": 0,
"marginsLR": 0,
"marginsTB": 0,
"backgroundTransparent": False, # Added in 0.6.0
}

for k in added:
Expand Down
Loading

0 comments on commit a334e8b

Please sign in to comment.