Remember line

This commit is contained in:
BasioMeusPuga
2018-02-17 12:11:39 +05:30
parent d73a1c7383
commit 50b4a36f52
3 changed files with 44 additions and 13 deletions

3
TODO
View File

@@ -70,3 +70,6 @@ TODO
✓ Define every widget in code
✓ Include icons for emblems
Shift to logging instead of print statements
Bugs:
If there are files open and the database is deleted, TypeErrors result
The auto scan doesn't work on a new database

View File

@@ -33,6 +33,8 @@ class ItemProxyModel(QtCore.QSortFilterProxyModel):
self.active_library_filters = active_library_filters
def filterAcceptsRow(self, row, parent):
return True
model = self.sourceModel()
this_index = model.index(row, 0)
@@ -171,6 +173,8 @@ class TableProxyModel(QtCore.QSortFilterProxyModel):
self.active_library_filters = active_library_filters
def filterAcceptsRow(self, row_num, parent):
return True
if self.filter_string is None or self.filter_columns is None:
return True
@@ -224,7 +228,10 @@ class MostExcellentFileSystemModel(QtWidgets.QFileSystemModel):
0: 'Path',
4: 'Name',
5: 'Tags'}
try:
return column_dict[col]
except KeyError:
pass
def data(self, index, role):
if (index.column() in (4, 5)

View File

@@ -422,23 +422,33 @@ class Tab(QtWidgets.QWidget):
self.contentView.setOpenLinks(False) # TODO Change this when HTML navigation works
self.contentView.setHtml(chapter_content)
self.contentView.setReadOnly(True)
def set_scroll_value():
# self.window().tabWidget.blockSignals(True)
# TODO
# Stays in place upon switching tabs
previous_widget = self.window().tabWidget.currentWidget()
self.window().tabWidget.setCurrentWidget(self)
scroll_position = int(
scroll_position = (
self.metadata['position']['scroll_value'] *
self.contentView.verticalScrollBar().maximum())
# print(self.contentView.verticalScrollBar().maximum(), scroll_position)
# print(self.metadata['position'])
# Scroll a little ahead
# This avoids confusion with potentially duplicate phrases
# And the found result is at the top of the window
self.contentView.verticalScrollBar().setValue(scroll_position * 1.1)
self.contentView.verticalScrollBar().setValue(scroll_position)
last_visible_text = self.metadata['position']['last_visible_text']
if last_visible_text:
self.contentView.find(last_visible_text)
text_cursor = self.contentView.textCursor()
text_cursor.clearSelection()
self.contentView.setTextCursor(text_cursor)
self.window().tabWidget.setCurrentWidget(previous_widget)
# self.window().tabWidget.blockSignals(False)
temp_hidden_button = QtWidgets.QToolButton(self)
temp_hidden_button.setVisible(False)
@@ -485,7 +495,8 @@ class Tab(QtWidgets.QWidget):
'current_chapter': 1,
'current_line': 0,
'total_chapters': total_chapters,
'scroll_value': 0}
'scroll_value': 0,
'last_visible_text': None}
def generate_keyboard_shortcuts(self):
self.next_chapter = QtWidgets.QShortcut(
@@ -674,7 +685,6 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView):
if vertical == maximum:
self.common_functions.change_chapter(1, True)
else:
# Increment by following value
scroll_increment = int((maximum - 0) / 2)
@@ -699,6 +709,17 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
def wheelEvent(self, event):
self.parent.metadata['position']['scroll_value'] = (
self.verticalScrollBar().value() / self.verticalScrollBar().maximum())
cursor = self.cursorForPosition(QtCore.QPoint(0, 0))
bottom_right = QtCore.QPoint(self.viewport().width() - 1, self.viewport().height())
bottom_right_cursor = self.cursorForPosition(bottom_right).position()
cursor.setPosition(bottom_right_cursor, QtGui.QTextCursor.KeepAnchor)
visible_text = cursor.selectedText()
if len(visible_text) > 30:
visible_text = visible_text[:31]
self.parent.metadata['position']['last_visible_text'] = visible_text
self.common_functions.wheelEvent(event, False)
def keyPressEvent(self, event):
@@ -711,10 +732,10 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
if vertical == maximum:
self.common_functions.change_chapter(1, True)
else:
QtWidgets.QTextBrowser.keyPressEvent(self, event)
QtWidgets.QTextEdit.keyPressEvent(self, event)
else:
QtWidgets.QTextBrowser.keyPressEvent(self, event)
QtWidgets.QTextEdit.keyPressEvent(self, event)
# def mouseMoveEvent(self, event):
# TODO