Profile reset, Scroll past end, HTML whitespace error fixed
This commit is contained in:
16
__main__.py
16
__main__.py
@@ -121,6 +121,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
||||
self.bookToolBar.lineSpacingDown.triggered.connect(self.modify_font)
|
||||
self.bookToolBar.paddingUp.triggered.connect(self.modify_font)
|
||||
self.bookToolBar.paddingDown.triggered.connect(self.modify_font)
|
||||
self.bookToolBar.resetProfile.triggered.connect(self.reset_profile)
|
||||
|
||||
self.bookToolBar.colorBoxFG.clicked.connect(self.get_color)
|
||||
self.bookToolBar.colorBoxBG.clicked.connect(self.get_color)
|
||||
@@ -313,9 +314,9 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
||||
self.viewModel.setData(
|
||||
model_index, current_tab.metadata['position'], QtCore.Qt.UserRole + 7)
|
||||
|
||||
current_tab.contentView.verticalScrollBar().setValue(0)
|
||||
# current_tab.contentView.verticalScrollBar().setValue(0)
|
||||
current_tab.contentView.clear()
|
||||
current_tab.contentView.setHtml(required_content)
|
||||
current_tab.contentView.setAlignment(QtCore.Qt.AlignCenter)
|
||||
|
||||
def set_fullscreen(self):
|
||||
current_tab = self.tabWidget.currentIndex()
|
||||
@@ -356,7 +357,9 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
||||
|
||||
for i in contents:
|
||||
file_data = contents[i]
|
||||
Tab(file_data, self.tabWidget)
|
||||
Tab(file_data, self.tabWidget) # New tabs are created here
|
||||
# Initial position adjustment
|
||||
# is carried out by the tab itself
|
||||
if file_data['path'] == self.last_open_tab:
|
||||
found_a_focusable_tab = True
|
||||
self.tabWidget.setCurrentIndex(self.tabWidget.count() - 1)
|
||||
@@ -466,6 +469,13 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
||||
"QTextEdit {{font-family: {0}; font-size: {1}px; color: {2}; background-color: {3}}}".format(
|
||||
font, font_size, foreground, background))
|
||||
|
||||
def reset_profile(self):
|
||||
current_profile_index = self.bookToolBar.profileBox.currentIndex()
|
||||
current_profile_default = Settings(self).default_profiles[current_profile_index]
|
||||
self.bookToolBar.profileBox.setItemData(
|
||||
current_profile_index, current_profile_default, QtCore.Qt.UserRole)
|
||||
self.format_contentView()
|
||||
|
||||
def closeEvent(self, event=None):
|
||||
# All tabs must be iterated upon here
|
||||
self.temp_dir.remove()
|
||||
|
14
settings.py
14
settings.py
@@ -9,7 +9,7 @@ class Settings:
|
||||
self.parent_window = parent
|
||||
self.settings = QtCore.QSettings('Lector', 'Lector')
|
||||
|
||||
self.default_profile1 = {
|
||||
default_profile1 = {
|
||||
'font': 'Noto Sans',
|
||||
'foreground': '#000000',
|
||||
'background': '#d8d8d8',
|
||||
@@ -17,7 +17,7 @@ class Settings:
|
||||
'font_size': 20,
|
||||
'line_spacing': 1.5}
|
||||
|
||||
self.default_profile2 = {
|
||||
default_profile2 = {
|
||||
'font': 'Roboto',
|
||||
'foreground': '#c2c2c2',
|
||||
'background': '#161616',
|
||||
@@ -25,7 +25,7 @@ class Settings:
|
||||
'font_size': 20,
|
||||
'line_spacing': 1.5}
|
||||
|
||||
self.default_profile3 = {
|
||||
default_profile3 = {
|
||||
'font': 'Roboto',
|
||||
'foreground': '#657b83',
|
||||
'background': '#002b36',
|
||||
@@ -33,6 +33,9 @@ class Settings:
|
||||
'font_size': 20,
|
||||
'line_spacing': 1.5}
|
||||
|
||||
self.default_profiles = [
|
||||
default_profile1, default_profile2, default_profile3]
|
||||
|
||||
def read_settings(self):
|
||||
self.settings.beginGroup('mainWindow')
|
||||
self.parent_window.resize(self.settings.value(
|
||||
@@ -50,10 +53,7 @@ class Settings:
|
||||
'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])
|
||||
'displayProfiles', self.default_profiles)
|
||||
self.parent_window.current_profile_index = int(self.settings.value(
|
||||
'currentProfileIndex', 0))
|
||||
self.settings.endGroup()
|
||||
|
33
widgets.py
33
widgets.py
@@ -8,7 +8,6 @@ import database
|
||||
import pie_chart
|
||||
import resources
|
||||
|
||||
|
||||
class BookToolBar(QtWidgets.QToolBar):
|
||||
def __init__(self, parent=None):
|
||||
super(BookToolBar, self).__init__(parent)
|
||||
@@ -33,6 +32,8 @@ class BookToolBar(QtWidgets.QToolBar):
|
||||
QtGui.QIcon.fromTheme('gtk-select-font'), 'Font settings', self)
|
||||
self.settingsButton = QtWidgets.QAction(
|
||||
QtGui.QIcon.fromTheme('settings'), 'Settings', self)
|
||||
self.resetProfile = QtWidgets.QAction(
|
||||
QtGui.QIcon.fromTheme('view-refresh'), 'Reset profile', self)
|
||||
|
||||
# Add buttons
|
||||
self.addAction(self.fontButton)
|
||||
@@ -131,6 +132,8 @@ class BookToolBar(QtWidgets.QToolBar):
|
||||
|
||||
self.tocBoxAction = self.addWidget(self.tocBox)
|
||||
self.searchBarAction = self.addWidget(self.searchBar)
|
||||
self.addAction(self.resetProfile)
|
||||
self.resetProfile.setVisible(False)
|
||||
|
||||
def toggle_font_settings(self):
|
||||
if self.fontButton.isChecked():
|
||||
@@ -159,6 +162,7 @@ class BookToolBar(QtWidgets.QToolBar):
|
||||
|
||||
self.tocBoxAction.setVisible(False)
|
||||
self.searchBarAction.setVisible(False)
|
||||
self.resetProfile.setVisible(True)
|
||||
|
||||
def font_settings_off(self):
|
||||
self.fullscreenButton.setVisible(True)
|
||||
@@ -180,6 +184,7 @@ class BookToolBar(QtWidgets.QToolBar):
|
||||
|
||||
self.tocBoxAction.setVisible(True)
|
||||
self.searchBarAction.setVisible(True)
|
||||
self.resetProfile.setVisible(False)
|
||||
|
||||
|
||||
class LibraryToolBar(QtWidgets.QToolBar):
|
||||
@@ -304,7 +309,6 @@ class Tab(QtWidgets.QWidget):
|
||||
self.contentView.setSearchPaths(relative_paths)
|
||||
self.contentView.setOpenLinks(False) # Change this when HTML navigation works
|
||||
self.contentView.setHtml(chapter_content)
|
||||
self.contentView.setAlignment(QtCore.Qt.AlignCenter)
|
||||
|
||||
self.generate_keyboard_shortcuts()
|
||||
|
||||
@@ -357,7 +361,7 @@ class Tab(QtWidgets.QWidget):
|
||||
if self.sender().objectName() == 'nextChapter':
|
||||
direction = 1
|
||||
|
||||
self.contentView.change_chapter(direction)
|
||||
self.contentView.change_chapter(direction, True)
|
||||
|
||||
def sneaky_exit(self):
|
||||
self.contentView.hide()
|
||||
@@ -368,8 +372,18 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
|
||||
def __init__(self, main_window, parent=None):
|
||||
super(PliantQTextBrowser, self).__init__(parent)
|
||||
self.main_window = main_window
|
||||
self.ignore_wheel_event = False
|
||||
self.ignore_wheel_event_number = 0
|
||||
|
||||
def wheelEvent(self, event):
|
||||
if self.ignore_wheel_event:
|
||||
# Ignore first n wheel events after a chapter change
|
||||
self.ignore_wheel_event_number += 1
|
||||
if self.ignore_wheel_event_number > 20:
|
||||
self.ignore_wheel_event = False
|
||||
self.ignore_wheel_event_number = 0
|
||||
return
|
||||
|
||||
QtWidgets.QTextBrowser.wheelEvent(self, event)
|
||||
|
||||
# Since this is a delta on a mouse move event, it cannot ever be 0
|
||||
@@ -379,7 +393,7 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
|
||||
elif vertical_pdelta < 0:
|
||||
moving_up = False
|
||||
|
||||
if abs(vertical_pdelta) > 150: # Adjust sensitivity here
|
||||
if abs(vertical_pdelta) > 100: # Adjust sensitivity here
|
||||
# Implies that no scrollbar movement is possible
|
||||
if self.verticalScrollBar().value() == self.verticalScrollBar().maximum() == 0:
|
||||
if moving_up:
|
||||
@@ -397,7 +411,7 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
|
||||
if moving_up:
|
||||
self.change_chapter(-1)
|
||||
|
||||
def change_chapter(self, direction):
|
||||
def change_chapter(self, direction, was_button_pressed=None):
|
||||
current_toc_index = self.main_window.bookToolBar.tocBox.currentIndex()
|
||||
max_toc_index = self.main_window.bookToolBar.tocBox.count() - 1
|
||||
|
||||
@@ -405,6 +419,15 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
|
||||
current_toc_index > 0 and direction == -1):
|
||||
self.main_window.bookToolBar.tocBox.setCurrentIndex(current_toc_index + direction)
|
||||
|
||||
# Set page position depending on if the chapter number is increasing or decreasing
|
||||
if direction == 1 or was_button_pressed:
|
||||
self.verticalScrollBar().setValue(0)
|
||||
else:
|
||||
self.verticalScrollBar().setValue(
|
||||
self.verticalScrollBar().maximum())
|
||||
|
||||
self.ignore_wheel_event = True
|
||||
|
||||
|
||||
class LibraryDelegate(QtWidgets.QStyledItemDelegate):
|
||||
def __init__(self, temp_dir, parent=None):
|
||||
|
Reference in New Issue
Block a user