Fix fullscreen toggle affecting reading position bug

Bookmark navigation much more reliable
Start annotations UI
This commit is contained in:
BasioMeusPuga
2018-03-27 08:23:07 +05:30
parent 9c85a1075e
commit d417a94829
6 changed files with 3585 additions and 3546 deletions

2
TODO
View File

@@ -57,6 +57,7 @@ TODO
✓ Paragraph indentation ✓ Paragraph indentation
✓ Comic view keyboard shortcuts ✓ Comic view keyboard shortcuts
✓ Comic view context menu ✓ Comic view context menu
Make the bookmark dock float over the reading area
Adjust key navigation according to viewport dimensions Adjust key navigation according to viewport dimensions
Search document using QTextCursor? Search document using QTextCursor?
Filetypes: Filetypes:
@@ -72,7 +73,6 @@ TODO
Other: Other:
✓ Define every widget in code ✓ Define every widget in code
Bugs: Bugs:
Slider position change might be acting up
Deselecting all directories in the settings dialog also filters out manually added books Deselecting all directories in the settings dialog also filters out manually added books
Secondary: Secondary:

View File

@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1022</width> <width>1088</width>
<height>513</height> <height>612</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -88,13 +88,6 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_9"> <layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QCheckBox" name="autoTags">
<property name="text">
<string>Generate tags from files</string>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_7"> <layout class="QHBoxLayout" name="horizontalLayout_7">
<item> <item>
@@ -129,6 +122,13 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QCheckBox" name="autoTags">
<property name="text">
<string>Generate tags from files</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
@@ -218,6 +218,27 @@ Reopen book to see changes</string>
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="annotationsPage">
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="textTab">
<attribute name="title">
<string>Text</string>
</attribute>
</widget>
<widget class="QWidget" name="imageTab">
<attribute name="title">
<string>Comic/PDF</string>
</attribute>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="aboutPage"> <widget class="QWidget" name="aboutPage">
<layout class="QGridLayout" name="gridLayout_6"> <layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0"> <item row="0" column="0">

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'raw/settings2.ui' # Form implementation generated from reading ui file 'raw/settings.ui'
# #
# Created by: PyQt5 UI code generator 5.10.1 # Created by: PyQt5 UI code generator 5.10.1
# #
@@ -11,7 +11,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object): class Ui_Dialog(object):
def setupUi(self, Dialog): def setupUi(self, Dialog):
Dialog.setObjectName("Dialog") Dialog.setObjectName("Dialog")
Dialog.resize(1022, 513) Dialog.resize(1088, 612)
self.gridLayout = QtWidgets.QGridLayout(Dialog) self.gridLayout = QtWidgets.QGridLayout(Dialog)
self.gridLayout.setObjectName("gridLayout") self.gridLayout.setObjectName("gridLayout")
self.listView = QtWidgets.QListView(Dialog) self.listView = QtWidgets.QListView(Dialog)
@@ -66,9 +66,6 @@ class Ui_Dialog(object):
self.verticalLayout_2.addLayout(self.horizontalLayout_3) self.verticalLayout_2.addLayout(self.horizontalLayout_3)
self.horizontalLayout_9 = QtWidgets.QHBoxLayout() self.horizontalLayout_9 = QtWidgets.QHBoxLayout()
self.horizontalLayout_9.setObjectName("horizontalLayout_9") self.horizontalLayout_9.setObjectName("horizontalLayout_9")
self.autoTags = QtWidgets.QCheckBox(self.groupBox)
self.autoTags.setObjectName("autoTags")
self.horizontalLayout_9.addWidget(self.autoTags)
self.horizontalLayout_7 = QtWidgets.QHBoxLayout() self.horizontalLayout_7 = QtWidgets.QHBoxLayout()
self.horizontalLayout_7.setObjectName("horizontalLayout_7") self.horizontalLayout_7.setObjectName("horizontalLayout_7")
self.label = QtWidgets.QLabel(self.groupBox) self.label = QtWidgets.QLabel(self.groupBox)
@@ -81,6 +78,9 @@ class Ui_Dialog(object):
self.lightIconsRadio.setObjectName("lightIconsRadio") self.lightIconsRadio.setObjectName("lightIconsRadio")
self.horizontalLayout_7.addWidget(self.lightIconsRadio) self.horizontalLayout_7.addWidget(self.lightIconsRadio)
self.horizontalLayout_9.addLayout(self.horizontalLayout_7) self.horizontalLayout_9.addLayout(self.horizontalLayout_7)
self.autoTags = QtWidgets.QCheckBox(self.groupBox)
self.autoTags.setObjectName("autoTags")
self.horizontalLayout_9.addWidget(self.autoTags)
self.verticalLayout_2.addLayout(self.horizontalLayout_9) self.verticalLayout_2.addLayout(self.horizontalLayout_9)
self.gridLayout_4.addLayout(self.verticalLayout_2, 0, 0, 1, 1) self.gridLayout_4.addLayout(self.verticalLayout_2, 0, 0, 1, 1)
self.verticalLayout.addWidget(self.groupBox) self.verticalLayout.addWidget(self.groupBox)
@@ -123,6 +123,20 @@ class Ui_Dialog(object):
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.gridLayout_2.addItem(spacerItem, 1, 0, 1, 1) self.gridLayout_2.addItem(spacerItem, 1, 0, 1, 1)
self.stackedWidget.addWidget(self.switchPage) self.stackedWidget.addWidget(self.switchPage)
self.annotationsPage = QtWidgets.QWidget()
self.annotationsPage.setObjectName("annotationsPage")
self.gridLayout_7 = QtWidgets.QGridLayout(self.annotationsPage)
self.gridLayout_7.setObjectName("gridLayout_7")
self.tabWidget = QtWidgets.QTabWidget(self.annotationsPage)
self.tabWidget.setObjectName("tabWidget")
self.textTab = QtWidgets.QWidget()
self.textTab.setObjectName("textTab")
self.tabWidget.addTab(self.textTab, "")
self.imageTab = QtWidgets.QWidget()
self.imageTab.setObjectName("imageTab")
self.tabWidget.addTab(self.imageTab, "")
self.gridLayout_7.addWidget(self.tabWidget, 0, 0, 1, 1)
self.stackedWidget.addWidget(self.annotationsPage)
self.aboutPage = QtWidgets.QWidget() self.aboutPage = QtWidgets.QWidget()
self.aboutPage.setObjectName("aboutPage") self.aboutPage.setObjectName("aboutPage")
self.gridLayout_6 = QtWidgets.QGridLayout(self.aboutPage) self.gridLayout_6 = QtWidgets.QGridLayout(self.aboutPage)
@@ -148,6 +162,7 @@ class Ui_Dialog(object):
self.gridLayout.addLayout(self.verticalLayout_4, 0, 1, 1, 1) self.gridLayout.addLayout(self.verticalLayout_4, 0, 1, 1, 1)
self.retranslateUi(Dialog) self.retranslateUi(Dialog)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog): def retranslateUi(self, Dialog):
@@ -159,13 +174,13 @@ class Ui_Dialog(object):
self.coverShadows.setText(_translate("Dialog", "Cover shadows")) self.coverShadows.setText(_translate("Dialog", "Cover shadows"))
self.performCulling.setToolTip(_translate("Dialog", "Enabling reduces startup time and memory usage")) self.performCulling.setToolTip(_translate("Dialog", "Enabling reduces startup time and memory usage"))
self.performCulling.setText(_translate("Dialog", "Load covers only when needed")) self.performCulling.setText(_translate("Dialog", "Load covers only when needed"))
self.autoTags.setText(_translate("Dialog", "Generate tags from files"))
self.label.setToolTip(_translate("Dialog", "Restart application to see changes")) self.label.setToolTip(_translate("Dialog", "Restart application to see changes"))
self.label.setText(_translate("Dialog", "Icon theme: ")) self.label.setText(_translate("Dialog", "Icon theme: "))
self.darkIconsRadio.setToolTip(_translate("Dialog", "Restart application to see changes")) self.darkIconsRadio.setToolTip(_translate("Dialog", "Restart application to see changes"))
self.darkIconsRadio.setText(_translate("Dialog", "&Dark")) self.darkIconsRadio.setText(_translate("Dialog", "&Dark"))
self.lightIconsRadio.setToolTip(_translate("Dialog", "Restart application to see changes")) self.lightIconsRadio.setToolTip(_translate("Dialog", "Restart application to see changes"))
self.lightIconsRadio.setText(_translate("Dialog", "L&ight")) self.lightIconsRadio.setText(_translate("Dialog", "L&ight"))
self.autoTags.setText(_translate("Dialog", "Generate tags from files"))
self.groupBox_2.setTitle(_translate("Dialog", "Reading")) self.groupBox_2.setTitle(_translate("Dialog", "Reading"))
self.hideScrollBars.setToolTip(_translate("Dialog", "Horizontal scrolling with Alt + Scroll\n" self.hideScrollBars.setToolTip(_translate("Dialog", "Horizontal scrolling with Alt + Scroll\n"
"Reopen book to see changes")) "Reopen book to see changes"))
@@ -173,6 +188,8 @@ class Ui_Dialog(object):
self.cachingEnabled.setToolTip(_translate("Dialog", "Greatly reduces page transition time at the cost of more memory")) self.cachingEnabled.setToolTip(_translate("Dialog", "Greatly reduces page transition time at the cost of more memory"))
self.cachingEnabled.setText(_translate("Dialog", "Cache comic / pdf pages")) self.cachingEnabled.setText(_translate("Dialog", "Cache comic / pdf pages"))
self.languageLabel.setText(_translate("Dialog", "Dictionary language:")) self.languageLabel.setText(_translate("Dialog", "Dictionary language:"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.textTab), _translate("Dialog", "Text"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.imageTab), _translate("Dialog", "Comic/PDF"))
self.okButton.setText(_translate("Dialog", "Scan Library")) self.okButton.setText(_translate("Dialog", "Scan Library"))
self.cancelButton.setText(_translate("Dialog", "Close")) self.cancelButton.setText(_translate("Dialog", "Close"))

View File

@@ -104,8 +104,10 @@ class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog):
library_string = self._translate('SettingsUI', 'Library') library_string = self._translate('SettingsUI', 'Library')
switches_string = self._translate('SettingsUI', 'Switches') switches_string = self._translate('SettingsUI', 'Switches')
annotations_string = self._translate('SettingsUI', 'Annotations')
about_string = self._translate('SettingsUI', 'About') about_string = self._translate('SettingsUI', 'About')
list_options = [library_string, switches_string, about_string] list_options = [
library_string, switches_string, annotations_string, about_string]
for i in list_options: for i in list_options:
item = QtGui.QStandardItem() item = QtGui.QStandardItem()

View File

@@ -20,6 +20,8 @@
# Reading modes # Reading modes
# Double page, Continuous etc # Double page, Continuous etc
# Especially for comics # Especially for comics
# Remove variables that have anything to do with scroll position
import os import os
import uuid import uuid
@@ -103,10 +105,10 @@ class Tab(QtWidgets.QWidget):
self.contentView.setHtml(chapter_content) self.contentView.setHtml(chapter_content)
self.contentView.setReadOnly(True) self.contentView.setReadOnly(True)
tempHiddenButton = QtWidgets.QToolButton(self) self.hiddenButton = QtWidgets.QToolButton(self)
tempHiddenButton.setVisible(False) self.hiddenButton.setVisible(False)
tempHiddenButton.clicked.connect(self.set_scroll_value) self.hiddenButton.clicked.connect(self.set_scroll_value)
tempHiddenButton.animateClick(100) self.hiddenButton.animateClick(50)
# 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
@@ -178,11 +180,6 @@ class Tab(QtWidgets.QWidget):
pass pass
def set_scroll_value(self, switch_widgets=True, search_data=None): def set_scroll_value(self, switch_widgets=True, search_data=None):
# TODO
# Bookmark navigation does not work in case 2 entries in the same
# chapter are clicked successively
# It plain refuses to work other times
if self.sender().objectName() == 'tabWidget': if self.sender().objectName() == 'tabWidget':
return return
@@ -190,37 +187,26 @@ class Tab(QtWidgets.QWidget):
previous_widget = self.main_window.tabWidget.currentWidget() previous_widget = self.main_window.tabWidget.currentWidget()
self.main_window.tabWidget.setCurrentWidget(self) self.main_window.tabWidget.setCurrentWidget(self)
scroll_value = self.metadata['position']['scroll_value']
if search_data:
scroll_value = search_data[0]
# Scroll a little ahead
# This avoids confusion with potentially duplicate phrases
# And the found result is at the top of the window
scroll_position = scroll_value * self.contentView.verticalScrollBar().maximum()
self.contentView.verticalScrollBar().setValue(scroll_position * 1.02)
try: try:
search_text = self.metadata['position']['last_visible_text'] search_text = self.metadata['position']['last_visible_text']
if search_data: if search_data:
search_text = search_data[1] search_text = search_data[1]
if search_text: if search_text:
find_backward = False cursor = self.contentView.textCursor()
cursor.movePosition(QtGui.QTextCursor.Start, QtGui.QTextCursor.KeepAnchor)
self.contentView.setTextCursor(cursor)
find_forward = self.contentView.find(search_text) self.contentView.verticalScrollBar().setValue(
if not find_forward: self.contentView.verticalScrollBar().maximum())
find_backward = self.contentView.find(
search_text, QtGui.QTextDocument.FindBackward)
if find_backward: # find_forward is a new cursor object that must replace
current_scroll_position = self.contentView.verticalScrollBar().value() # the existing text cursor
new_scroll_position = current_scroll_position * .98 find_forward = self.contentView.document().find(search_text)
self.contentView.verticalScrollBar().setValue(new_scroll_position) find_forward.clearSelection()
self.contentView.setTextCursor(find_forward)
self.contentView.ensureCursorVisible()
text_cursor = self.contentView.textCursor()
text_cursor.clearSelection()
self.contentView.setTextCursor(text_cursor)
except KeyError: except KeyError:
pass pass
@@ -289,19 +275,32 @@ class Tab(QtWidgets.QWidget):
self.exit_fullscreen() self.exit_fullscreen()
return return
if not self.are_we_doing_images_only:
self.contentView.record_scroll_position()
self.contentView.setWindowFlags(QtCore.Qt.Window) self.contentView.setWindowFlags(QtCore.Qt.Window)
self.contentView.setWindowState(QtCore.Qt.WindowFullScreen) self.contentView.setWindowState(QtCore.Qt.WindowFullScreen)
self.contentView.show() self.contentView.show()
self.main_window.hide() self.main_window.hide()
if not self.are_we_doing_images_only:
self.hiddenButton.animateClick(100)
self.is_fullscreen = True self.is_fullscreen = True
def exit_fullscreen(self): def exit_fullscreen(self):
if not self.are_we_doing_images_only:
self.contentView.record_scroll_position()
self.main_window.show() self.main_window.show()
self.contentView.setWindowFlags(QtCore.Qt.Widget) self.contentView.setWindowFlags(QtCore.Qt.Widget)
self.contentView.setWindowState(QtCore.Qt.WindowNoState) self.contentView.setWindowState(QtCore.Qt.WindowNoState)
self.contentView.show() self.contentView.show()
self.is_fullscreen = False self.is_fullscreen = False
if not self.are_we_doing_images_only:
self.hiddenButton.animateClick(100)
# Hide the view modification buttons in case they're visible # Hide the view modification buttons in case they're visible
self.main_window.bookToolBar.customize_view_off() self.main_window.bookToolBar.customize_view_off()