A little further into finalizing Profile setting

This commit is contained in:
BasioMeusPuga
2017-11-13 09:46:41 +05:30
parent e2ec7e680e
commit 9099811c28
4 changed files with 79 additions and 17 deletions

View File

@@ -28,10 +28,10 @@
✓ Override the keypress event of the textedit
✓ Use format* icons for toolbar buttons
✓ Implement book view settings with a(nother) toolbar
? Substitute textedit for another widget
Substitute textedit for another widget
Theming
All ebooks should first be added to the database and then returned as HTML
Pagination
Theming
Set context menu for definitions and the like
Keep fontsize and margins consistent - Let page increase in length
Filetypes:
@@ -97,13 +97,19 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.bookToolBar = BookToolBar(self)
self.bookToolBar.fullscreenButton.triggered.connect(self.set_fullscreen)
self.bookToolBar.fontBox.activated.connect(self.modify_font)
self.bookToolBar.fontBox.currentFontChanged.connect(self.modify_font)
self.bookToolBar.fontSizeUp.triggered.connect(self.modify_font)
self.bookToolBar.fontSizeDown.triggered.connect(self.modify_font)
self.bookToolBar.lineSpacingUp.triggered.connect(self.modify_font)
self.bookToolBar.lineSpacingDown.triggered.connect(self.modify_font)
self.bookToolBar.paddingUp.triggered.connect(self.modify_font)
self.bookToolBar.paddingDown.triggered.connect(self.modify_font)
for count, i in enumerate(self.display_profiles):
self.bookToolBar.profileBox.setItemData(count, i, QtCore.Qt.UserRole)
self.bookToolBar.profileBox.currentIndexChanged.connect(self.change_display_profile)
self.current_profile = self.bookToolBar.profileBox.itemData(
self.current_profile_index, QtCore.Qt.UserRole)
self.bookToolBar.profileBox.setCurrentIndex(self.current_profile_index)
self.bookToolBar.colorBoxFG.clicked.connect(self.get_color)
self.bookToolBar.colorBoxBG.clicked.connect(self.get_color)
@@ -114,8 +120,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.tab_switch()
self.tabWidget.currentChanged.connect(self.tab_switch)
# New tabs and their contents
self.current_tab = None
# For fullscreening purposes
self.current_contentView = None
# Tab closing
@@ -141,12 +146,14 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# TODO
# Get display profiles from settings
# Current using a default
self.current_profile = {
'foreground': 'grey',
'background': 'black',
'padding': 100,
'font_size': 22,
'line_spacing': 1.5}
# self.bookToolBar.profileBox.setItemData(1, 'asdadasd', QtCore.Qt.UserRole)
# self.current_profile = {
# 'font': 'Noto Sans',
# 'foreground': 'grey',
# 'background': 'black',
# 'padding': 100,
# 'font_size': 22,
# 'line_spacing': 1.5}
def resizeEvent(self, event=None):
if event:
@@ -269,6 +276,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.bookToolBar.tocBox.setCurrentIndex(current_position)
self.bookToolBar.tocBox.blockSignals(False)
self.format_contentView()
self.statusMessage.setText(
current_author + ' - ' + current_title)
@@ -353,7 +362,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
signal_sender = self.sender().objectName()
if signal_sender == 'fontBox':
pass
self.current_profile['font'] = self.bookToolBar.fontBox.currentFont().family()
if signal_sender == 'fontSizeUp':
self.current_profile['font_size'] += 1
@@ -376,7 +385,14 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# TODO
# Implement line spacing
# Implement font changing
# See what happens if a font isn't installed
# print(self.bookToolBar.profileBox.itemData(1, QtCore.Qt.UserRole))
# print(self.current_profile)
# current_profile = self.bookToolBar.profileBox.itemData()
font = self.current_profile['font']
foreground = self.current_profile['foreground']
background = self.current_profile['background']
padding = self.current_profile['padding']
@@ -387,8 +403,20 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
current_contentView = current_tab_widget.findChildren(QtWidgets.QTextBrowser)[0]
current_contentView.setStyleSheet(
"QTextEdit {{font-size: {0}px; padding-left: {1}; padding-right: {1}; color: {2}; background-color: {3}}}".format(
font_size, padding, foreground, background))
"QTextEdit {{font-family: {0}; font-size: {1}px; padding-left: {2}; padding-right: {2}; color: {3}; background-color: {4}}}".format(
font, font_size, padding, foreground, background))
def change_display_profile(self):
profile_index = self.bookToolBar.profileBox.currentIndex()
self.bookToolBar.profileBox.setItemData()
self.current_profile = self.bookToolBar.profileBox.itemData(
profile_index, QtCore.Qt.UserRole)
self.format_contentView()
def closeEvent(self, event=None):
# All tabs must be iterated upon here

View File

@@ -58,5 +58,5 @@ class ParseCBZ:
# TODO
# Image resizing, formatting
# Cleanup after exit
contents[page_name] = "<img src='%s'/>" % image_path
contents[page_name] = "<img src='%s' align='middle'/>" % image_path
return contents, tmp_dir

View File

@@ -126,6 +126,30 @@ class Settings:
self.parent_window = parent
self.settings = QtCore.QSettings('Lector', 'Lector')
self.default_profile1 = {
'font': 'Noto Sans',
'foreground': '#000000',
'background': '#d8d8d8',
'padding': 140,
'font_size': 20,
'line_spacing': 1.5}
self.default_profile2 = {
'font': 'Roboto',
'foreground': '#c2c2c2',
'background': '#161616',
'padding': 140,
'font_size': 20,
'line_spacing': 1.5}
self.default_profile3 = {
'font': 'Roboto',
'foreground': '#657b83',
'background': '#002b36',
'padding': 140,
'font_size': 20,
'line_spacing': 1.5}
def read_settings(self):
self.settings.beginGroup('mainWindow')
self.parent_window.resize(self.settings.value(
@@ -142,6 +166,14 @@ class Settings:
self.parent_window.database_path = self.settings.value(
'databasePath',
QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.AppDataLocation))
self.parent_window.display_profiles = self.settings.value(
'displayProfiles', [
self.default_profile1,
self.default_profile2,
self.default_profile3])
self.parent_window.current_profile_index = self.settings.value(
'currentProfileIndex', 0)
self.settings.endGroup()
def save_settings(self):

View File

@@ -65,6 +65,7 @@ class BookToolBar(QtWidgets.QToolBar):
self.lineSpacingDown.setObjectName('lineSpacingDown')
self.fontBox = QtWidgets.QFontComboBox()
self.fontBox.setFontFilters(QtWidgets.QFontComboBox.ScalableFonts)
self.fontBox.setObjectName('fontBox')
self.colorBoxFG = FixedPushButton(self)
@@ -77,6 +78,7 @@ class BookToolBar(QtWidgets.QToolBar):
# TODO
# Get color profiles from settings
# Generate default profiles
# Maybe a default button
profiles = ['Profile 1', 'Profile 2', 'Profile 3']
self.profileBox = QtWidgets.QComboBox(self)
self.profileBox.addItems(profiles)
@@ -288,8 +290,8 @@ class Tab(QtWidgets.QWidget):
self.contentView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.gridLayout.addWidget(self.contentView, 0, 0, 1, 1)
self.parent.addTab(self, title)
self.contentView.setStyleSheet(
"QTextEdit {font-size:20px; padding-left:100; padding-right:100; background-color:black}")
# self.contentView.setStyleSheet(
# "QTextEdit {font-size:20px; padding-left:100; padding-right:100; background-color:black}")
class LibraryDelegate(QtWidgets.QStyledItemDelegate):