Fix filtering for a new database, Remember scroll position

This commit is contained in:
BasioMeusPuga
2018-02-16 01:28:48 +05:30
parent 303bbc799c
commit d73a1c7383
4 changed files with 41 additions and 15 deletions

1
TODO
View File

@@ -50,6 +50,7 @@ TODO
Continuous paging Continuous paging
Double pages Double pages
Record progress Record progress
Bookmarks
Pagination Pagination
Set context menu for definitions and the like Set context menu for definitions and the like
Scrolling: Smooth / By Line Scrolling: Smooth / By Line

View File

@@ -35,7 +35,6 @@ from settings import Settings
from settingsdialog import SettingsUI from settingsdialog import SettingsUI
class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
def __init__(self): def __init__(self):
super(MainUI, self).__init__() super(MainUI, self).__init__()
@@ -558,6 +557,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# Go on to change the value of the Table of Contents box # Go on to change the value of the Table of Contents box
current_tab.change_chapter_tocBox() current_tab.change_chapter_tocBox()
self.format_contentView()
def set_fullscreen(self): def set_fullscreen(self):
current_tab = self.tabWidget.currentIndex() current_tab = self.tabWidget.currentIndex()
@@ -637,6 +637,9 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.tabWidget.setCurrentIndex(self.tabWidget.count() - 1) self.tabWidget.setCurrentIndex(self.tabWidget.count() - 1)
finishing_touches() finishing_touches()
# TODO
# def dropEvent
def get_color(self): def get_color(self):
signal_sender = self.sender().objectName() signal_sender = self.sender().objectName()
@@ -697,9 +700,9 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
current_profile['font_size'] = old_size current_profile['font_size'] = old_size
if signal_sender == 'lineSpacingUp' and current_profile['line_spacing'] < 200: if signal_sender == 'lineSpacingUp' and current_profile['line_spacing'] < 200:
current_profile['line_spacing'] += 10 current_profile['line_spacing'] += 5
if signal_sender == 'lineSpacingDown' and current_profile['line_spacing'] > 100: if signal_sender == 'lineSpacingDown' and current_profile['line_spacing'] > 100:
current_profile['line_spacing'] -= 10 current_profile['line_spacing'] -= 5
if signal_sender == 'paddingUp': if signal_sender == 'paddingUp':
current_profile['padding'] += 5 current_profile['padding'] += 5
@@ -753,7 +756,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
def format_contentView(self): def format_contentView(self):
# TODO # TODO
# Implement line spacing
# See what happens if a font isn't installed # See what happens if a font isn't installed
current_tab = self.tabWidget.widget(self.tabWidget.currentIndex()) current_tab = self.tabWidget.widget(self.tabWidget.currentIndex())

View File

@@ -44,7 +44,7 @@ class ItemProxyModel(QtCore.QSortFilterProxyModel):
directory_tags = model.data(this_index, QtCore.Qt.UserRole + 11) directory_tags = model.data(this_index, QtCore.Qt.UserRole + 11)
if self.active_library_filters: if self.active_library_filters:
if directory_name not in self.active_library_filters: if directory_name.lower() not in [i.lower() for i in self.active_library_filters]:
return False return False
else: else:
return False return False
@@ -188,8 +188,8 @@ class TableProxyModel(QtCore.QSortFilterProxyModel):
# Filter out all books not in the active library filters # Filter out all books not in the active library filters
if self.active_library_filters: if self.active_library_filters:
current_library_name = valid_data[-2] current_library_name = valid_data[-2].lower()
if current_library_name not in self.active_library_filters: if current_library_name not in [i.lower() for i in self.active_library_filters]:
return False return False
else: else:
return False return False
@@ -198,7 +198,6 @@ class TableProxyModel(QtCore.QSortFilterProxyModel):
if i: if i:
if self.filter_string in i: if self.filter_string in i:
return True return True
return False return False

View File

@@ -420,13 +420,35 @@ class Tab(QtWidgets.QWidget):
relative_paths.append(os.path.join(relative_path_root, i[0])) relative_paths.append(os.path.join(relative_path_root, i[0]))
self.contentView.setSearchPaths(relative_paths) self.contentView.setSearchPaths(relative_paths)
self.contentView.setOpenLinks(False) # Change this when HTML navigation works self.contentView.setOpenLinks(False) # TODO Change this when HTML navigation works
self.contentView.setHtml(chapter_content) self.contentView.setHtml(chapter_content)
def set_scroll_value():
# self.window().tabWidget.blockSignals(True)
previous_widget = self.window().tabWidget.currentWidget()
self.window().tabWidget.setCurrentWidget(self)
scroll_position = int(
self.metadata['position']['scroll_value'] *
self.contentView.verticalScrollBar().maximum())
# print(self.contentView.verticalScrollBar().maximum(), scroll_position)
# print(self.metadata['position'])
self.contentView.verticalScrollBar().setValue(scroll_position)
self.window().tabWidget.setCurrentWidget(previous_widget)
# self.window().tabWidget.blockSignals(False)
temp_hidden_button = QtWidgets.QToolButton(self)
temp_hidden_button.setVisible(False)
temp_hidden_button.clicked.connect(set_scroll_value)
temp_hidden_button.animateClick(100)
# The following are common to both the text browser and # The following are common to both the text browser and
# the graphics view # the graphics view
self.contentView.setFrameShape(QtWidgets.QFrame.NoFrame) self.contentView.setFrameShape(QtWidgets.QFrame.NoFrame)
self.contentView.setObjectName("contentView") self.contentView.setObjectName('contentView')
self.contentView.verticalScrollBar().setSingleStep(7) self.contentView.verticalScrollBar().setSingleStep(7)
self.contentView.setHorizontalScrollBarPolicy( self.contentView.setHorizontalScrollBarPolicy(
QtCore.Qt.ScrollBarAlwaysOff) QtCore.Qt.ScrollBarAlwaysOff)
@@ -454,7 +476,7 @@ class Tab(QtWidgets.QWidget):
self.mouse_hide_timer.timeout.connect(self.hide_mouse) self.mouse_hide_timer.timeout.connect(self.hide_mouse)
self.contentView.setFocus() self.contentView.setFocus()
def generate_position(self): def generate_position(self):
total_chapters = len(self.metadata['content'].keys()) total_chapters = len(self.metadata['content'].keys())
# TODO # TODO
@@ -463,8 +485,7 @@ class Tab(QtWidgets.QWidget):
'current_chapter': 1, 'current_chapter': 1,
'current_line': 0, 'current_line': 0,
'total_chapters': total_chapters, 'total_chapters': total_chapters,
'read_lines': 0, 'scroll_value': 0}
'total_lines': 0}
def generate_keyboard_shortcuts(self): def generate_keyboard_shortcuts(self):
self.next_chapter = QtWidgets.QShortcut( self.next_chapter = QtWidgets.QShortcut(
@@ -527,7 +548,6 @@ class Tab(QtWidgets.QWidget):
self.contentView.resizeEvent() self.contentView.resizeEvent()
else: else:
self.contentView.setStyleSheet( self.contentView.setStyleSheet(
"QTextEdit {{font-family: {0}; font-size: {1}px; color: {2}; background-color: {3}}}".format( "QTextEdit {{font-family: {0}; font-size: {1}px; color: {2}; background-color: {3}}}".format(
font, font_size, foreground.name(), background.name())) font, font_size, foreground.name(), background.name()))
@@ -677,6 +697,8 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
self.setMouseTracking(True) self.setMouseTracking(True)
def wheelEvent(self, event): def wheelEvent(self, event):
self.parent.metadata['position']['scroll_value'] = (
self.verticalScrollBar().value() / self.verticalScrollBar().maximum())
self.common_functions.wheelEvent(event, False) self.common_functions.wheelEvent(event, False)
def keyPressEvent(self, event): def keyPressEvent(self, event):
@@ -684,6 +706,8 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
vertical = self.verticalScrollBar().value() vertical = self.verticalScrollBar().value()
maximum = self.verticalScrollBar().maximum() maximum = self.verticalScrollBar().maximum()
self.parent.metadata['position']['scroll_value'] = (vertical / maximum)
if vertical == maximum: if vertical == maximum:
self.common_functions.change_chapter(1, True) self.common_functions.change_chapter(1, True)
else: else:
@@ -760,7 +784,7 @@ class PliantWidgetsCommonFunctions():
if not was_button_pressed: if not was_button_pressed:
self.pw.ignore_wheel_event = True self.pw.ignore_wheel_event = True
class LibraryDelegate(QtWidgets.QStyledItemDelegate): class LibraryDelegate(QtWidgets.QStyledItemDelegate):
def __init__(self, temp_dir, parent=None): def __init__(self, temp_dir, parent=None):