Profile reset, Scroll past end, HTML whitespace error fixed
This commit is contained in:
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