Significant improvements to bookmark dock display

This commit is contained in:
BasioMeusPuga
2018-03-28 00:46:12 +05:30
parent 5fa724ae69
commit 66c8626d43
6 changed files with 80 additions and 42 deletions

11
TODO
View File

@@ -1,8 +1,8 @@
TODO TODO
General: General:
✓ Internationalization ✓ Internationalization
Application icon Application icon
.desktop file .desktop file
Options: Options:
✓ Automatic library management ✓ Automatic library management
✓ Recursive file addition ✓ Recursive file addition
@@ -57,9 +57,9 @@ 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 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:
✓ pdf support ✓ pdf support
Parse TOC Parse TOC
@@ -74,6 +74,9 @@ TODO
✓ Define every widget in code ✓ Define every widget in code
Bugs: Bugs:
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
Scrollbar set to maximum value for cover pages with large cover images
Only one tab has its scroll position set when opening multiple books @ startup
It's the one that has focus when application starts and ends
Secondary: Secondary:
Annotations Annotations

View File

@@ -513,6 +513,10 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.current_tab = self.tabWidget.currentIndex() self.current_tab = self.tabWidget.currentIndex()
# Hide bookmark widgets
for i in range(1, self.tabWidget.count()):
self.tabWidget.widget(i).dockWidget.setVisible(False)
if self.tabWidget.currentIndex() == 0: if self.tabWidget.currentIndex() == 0:
self.resizeEvent() self.resizeEvent()
@@ -632,10 +636,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
current_tab = self.tabWidget.currentIndex() current_tab = self.tabWidget.currentIndex()
current_tab_widget = self.tabWidget.widget(current_tab) current_tab_widget = self.tabWidget.widget(current_tab)
# TODO
# Extend this to other context related functions
# Make this fullscreenable
if sender == 'bookmarkButton': if sender == 'bookmarkButton':
current_tab_widget.toggle_bookmarks() current_tab_widget.toggle_bookmarks()

View File

@@ -83,8 +83,9 @@ class LibraryDelegate(QtWidgets.QStyledItemDelegate):
class BookmarkDelegate(QtWidgets.QStyledItemDelegate): class BookmarkDelegate(QtWidgets.QStyledItemDelegate):
def __init__(self, parent=None): def __init__(self, main_window, parent=None):
super(BookmarkDelegate, self).__init__(parent) super(BookmarkDelegate, self).__init__()
self.main_window = main_window
self.parent = parent self.parent = parent
def sizeHint(self, *args): def sizeHint(self, *args):
@@ -98,7 +99,7 @@ class BookmarkDelegate(QtWidgets.QStyledItemDelegate):
option = option.__class__(option) option = option.__class__(option)
chapter_index = index.data(QtCore.Qt.UserRole) chapter_index = index.data(QtCore.Qt.UserRole)
chapter_name = self.parent.window().bookToolBar.tocBox.itemText(chapter_index - 1) chapter_name = self.main_window.bookToolBar.tocBox.itemText(chapter_index - 1)
if len(chapter_name) > 25: if len(chapter_name) > 25:
chapter_name = chapter_name[:25] + '...' chapter_name = chapter_name[:25] + '...'

View File

@@ -47,7 +47,7 @@ class BookToolBar(QtWidgets.QToolBar):
self) self)
self.fullscreenButton = QtWidgets.QAction( self.fullscreenButton = QtWidgets.QAction(
image_factory.get_image('view-fullscreen'), image_factory.get_image('view-fullscreen'),
self._translate('BookToolBar', 'Fullscreen'), self._translate('BookToolBar', 'Fullscreen (F11)'),
self) self)
self.addBookmarkButton = QtWidgets.QAction( self.addBookmarkButton = QtWidgets.QAction(
image_factory.get_image('bookmark-new'), image_factory.get_image('bookmark-new'),
@@ -55,7 +55,7 @@ class BookToolBar(QtWidgets.QToolBar):
self) self)
self.bookmarkButton = QtWidgets.QAction( self.bookmarkButton = QtWidgets.QAction(
image_factory.get_image('bookmarks'), image_factory.get_image('bookmarks'),
self._translate('BookToolBar', 'Bookmarks'), self._translate('BookToolBar', 'Bookmarks (Ctrl + B)'),
self) self)
self.bookmarkButton.setObjectName('bookmarkButton') self.bookmarkButton.setObjectName('bookmarkButton')
self.resetProfile = QtWidgets.QAction( self.resetProfile = QtWidgets.QAction(
@@ -317,6 +317,7 @@ class BookToolBar(QtWidgets.QToolBar):
i.setVisible(False) i.setVisible(False)
def customize_view_off(self): def customize_view_off(self):
self.fontButton.setChecked(False)
for i in self.fontActions: for i in self.fontActions:
i.setVisible(False) i.setVisible(False)

View File

@@ -55,9 +55,6 @@ class Tab(QtWidgets.QWidget):
self.masterLayout = QtWidgets.QHBoxLayout(self) self.masterLayout = QtWidgets.QHBoxLayout(self)
self.masterLayout.setContentsMargins(0, 0, 0, 0) self.masterLayout.setContentsMargins(0, 0, 0, 0)
self.horzLayout = QtWidgets.QSplitter(self)
self.horzLayout.setOrientation(QtCore.Qt.Horizontal)
self.masterLayout.addWidget(self.horzLayout)
self.metadata['last_accessed'] = QtCore.QDateTime().currentDateTime() self.metadata['last_accessed'] = QtCore.QDateTime().currentDateTime()
@@ -129,16 +126,15 @@ class Tab(QtWidgets.QWidget):
self.metadata['bookmarks'] = {} self.metadata['bookmarks'] = {}
# Create the dock widget for context specific display # Create the dock widget for context specific display
self.dockWidget = PliantDockWidget(self) self.dockWidget = PliantDockWidget(self.main_window, self.contentView)
self.dockWidget.setWindowTitle(self._translate('Tab', 'Bookmarks')) self.dockWidget.setWindowTitle(self._translate('Tab', 'Bookmarks'))
self.dockWidget.setFeatures(QtWidgets.QDockWidget.DockWidgetClosable) self.dockWidget.setFeatures(QtWidgets.QDockWidget.DockWidgetClosable)
self.dockWidget.setFloating(False)
self.dockWidget.hide() self.dockWidget.hide()
self.dockListView = QtWidgets.QListView(self.dockWidget) self.dockListView = QtWidgets.QListView(self.dockWidget)
self.dockListView.setResizeMode(QtWidgets.QListWidget.Adjust) self.dockListView.setResizeMode(QtWidgets.QListWidget.Adjust)
self.dockListView.setMaximumWidth(350) self.dockListView.setMaximumWidth(350)
self.dockListView.setItemDelegate(BookmarkDelegate(self.dockListView)) self.dockListView.setItemDelegate(BookmarkDelegate(self.main_window, self.dockListView))
self.dockListView.setUniformItemSizes(True) self.dockListView.setUniformItemSizes(True)
self.dockListView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.dockListView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.dockListView.customContextMenuRequested.connect( self.dockListView.customContextMenuRequested.connect(
@@ -152,8 +148,11 @@ class Tab(QtWidgets.QWidget):
self.generate_keyboard_shortcuts() self.generate_keyboard_shortcuts()
self.horzLayout.addWidget(self.contentView) self.masterLayout.addWidget(self.contentView)
self.horzLayout.addWidget(self.dockWidget) self.masterLayout.addWidget(self.dockWidget)
self.dockWidget.setFloating(True)
self.dockWidget.setWindowOpacity(.95)
title = self.metadata['title'] title = self.metadata['title']
self.main_window.tabWidget.addTab(self, title) self.main_window.tabWidget.addTab(self, title)
@@ -193,23 +192,22 @@ class Tab(QtWidgets.QWidget):
if search_data: if search_data:
search_text = search_data[1] search_text = search_data[1]
if search_text: # textCursor() RETURNS a copy of the textcursor
# textCursor() RETURNS a copy of the textcursor cursor = self.contentView.textCursor()
cursor = self.contentView.textCursor() cursor.movePosition(QtGui.QTextCursor.Start, QtGui.QTextCursor.KeepAnchor)
cursor.movePosition(QtGui.QTextCursor.Start, QtGui.QTextCursor.KeepAnchor) self.contentView.setTextCursor(cursor)
self.contentView.setTextCursor(cursor)
# This is needed so that search results are always at the top # This is needed so that search results are always at the top
# of the window # of the window
self.contentView.verticalScrollBar().setValue( self.contentView.verticalScrollBar().setValue(
self.contentView.verticalScrollBar().maximum()) self.contentView.verticalScrollBar().maximum())
# find_forward is a new cursor object that must replace # find_forward is a new cursor object that must replace
# the existing text cursor # the existing text cursor
find_forward = self.contentView.document().find(search_text) find_forward = self.contentView.document().find(search_text)
find_forward.clearSelection() find_forward.clearSelection()
self.contentView.setTextCursor(find_forward) self.contentView.setTextCursor(find_forward)
self.contentView.ensureCursorVisible() self.contentView.ensureCursorVisible()
except KeyError: except KeyError:
pass pass
@@ -274,6 +272,10 @@ class Tab(QtWidgets.QWidget):
self.ksExitFullscreen.setContext(QtCore.Qt.ApplicationShortcut) self.ksExitFullscreen.setContext(QtCore.Qt.ApplicationShortcut)
self.ksExitFullscreen.activated.connect(self.exit_fullscreen) self.ksExitFullscreen.activated.connect(self.exit_fullscreen)
self.ksToggleBookMarks = QtWidgets.QShortcut(
QtGui.QKeySequence('Ctrl+B'), self.contentView)
self.ksToggleBookMarks.activated.connect(self.toggle_bookmarks)
def go_fullscreen(self): def go_fullscreen(self):
if self.contentView.windowState() == QtCore.Qt.WindowFullScreen: if self.contentView.windowState() == QtCore.Qt.WindowFullScreen:
self.exit_fullscreen() self.exit_fullscreen()
@@ -293,6 +295,10 @@ class Tab(QtWidgets.QWidget):
self.is_fullscreen = True self.is_fullscreen = True
def exit_fullscreen(self): def exit_fullscreen(self):
if self.dockWidget.isVisible():
self.dockWidget.setVisible(False)
return
if not self.are_we_doing_images_only: if not self.are_we_doing_images_only:
self.contentView.record_scroll_position() self.contentView.record_scroll_position()
@@ -741,7 +747,12 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView):
self.main_window.QImageFactory.get_image('zoom-original'), self.main_window.QImageFactory.get_image('zoom-original'),
self._translate('PliantQGraphicsView', 'Original size (O)')) self._translate('PliantQGraphicsView', 'Original size (O)'))
bookmarksToggleAction = 'Latin quote 2. Electric Boogaloo.'
if not self.main_window.settings['show_bars'] or self.parent.is_fullscreen: if not self.main_window.settings['show_bars'] or self.parent.is_fullscreen:
bookmarksToggleAction = contextMenu.addAction(
self.main_window.QImageFactory.get_image('bookmarks'),
self._translate('PliantQGraphicsView', 'Bookmarks'))
self.common_functions.generate_combo_box_action(contextMenu) self.common_functions.generate_combo_box_action(contextMenu)
action = contextMenu.exec_(self.sender().mapToGlobal(position)) action = contextMenu.exec_(self.sender().mapToGlobal(position))
@@ -756,6 +767,8 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView):
if save_file: if save_file:
self.image_pixmap.save(save_file[0]) self.image_pixmap.save(save_file[0])
if action == bookmarksToggleAction:
self.parent.toggle_bookmarks()
if action == dfToggleAction: if action == dfToggleAction:
self.main_window.toggle_distraction_free() self.main_window.toggle_distraction_free()
if action == fsToggleAction: if action == fsToggleAction:
@@ -876,7 +889,12 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
self.main_window.QImageFactory.get_image('visibility'), self.main_window.QImageFactory.get_image('visibility'),
distraction_free_prompt) distraction_free_prompt)
bookmarksToggleAction = 'Latin quote 2. Electric Boogaloo.'
if not self.main_window.settings['show_bars'] or self.parent.is_fullscreen: if not self.main_window.settings['show_bars'] or self.parent.is_fullscreen:
bookmarksToggleAction = contextMenu.addAction(
self.main_window.QImageFactory.get_image('bookmarks'),
self._translate('PliantQTextBrowser', 'Bookmarks'))
self.common_functions.generate_combo_box_action(contextMenu) self.common_functions.generate_combo_box_action(contextMenu)
action = contextMenu.exec_(self.sender().mapToGlobal(position)) action = contextMenu.exec_(self.sender().mapToGlobal(position))
@@ -885,6 +903,8 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
self.main_window.definitionDialog.find_definition(selected_word) self.main_window.definitionDialog.find_definition(selected_word)
if action == searchAction: if action == searchAction:
self.main_window.bookToolBar.searchBar.setFocus() self.main_window.bookToolBar.searchBar.setFocus()
if action == bookmarksToggleAction:
self.parent.toggle_bookmarks()
if action == fsToggleAction: if action == fsToggleAction:
self.parent.exit_fullscreen() self.parent.exit_fullscreen()
if action == dfToggleAction: if action == dfToggleAction:
@@ -982,15 +1002,28 @@ class PliantWidgetsCommonFunctions():
class PliantDockWidget(QtWidgets.QDockWidget): class PliantDockWidget(QtWidgets.QDockWidget):
def __init__(self, parent=None): def __init__(self, main_window, contentView, parent=None):
super(PliantDockWidget, self).__init__(parent) super(PliantDockWidget, self).__init__()
self.parent = parent self.main_window = main_window
self.contentView = contentView
def showEvent(self, event): def showEvent(self, event):
self.parent.window().bookToolBar.bookmarkButton.setChecked(True) viewport_height = self.contentView.viewport().size().height()
viewport_topRight = self.contentView.mapToGlobal(
self.contentView.viewport().rect().topRight())
desktop_size = QtWidgets.QDesktopWidget().screenGeometry()
dock_width = desktop_size.width() // 5.5
dock_x = viewport_topRight.x() - dock_width + 1
dock_y = viewport_topRight.y() + (viewport_height * .10)
dock_height = viewport_height * .80
self.setGeometry(dock_x, dock_y, dock_width, dock_height)
self.main_window.bookToolBar.bookmarkButton.setChecked(True)
def hideEvent(self, event): def hideEvent(self, event):
self.parent.window().bookToolBar.bookmarkButton.setChecked(False) self.main_window.bookToolBar.bookmarkButton.setChecked(False)
class PliantQGraphicsScene(QtWidgets.QGraphicsScene): class PliantQGraphicsScene(QtWidgets.QGraphicsScene):

View File

@@ -6,7 +6,7 @@ HERE = path.abspath(path.dirname(__file__))
MAJOR_VERSION = '0' MAJOR_VERSION = '0'
MINOR_VERSION = '3' MINOR_VERSION = '3'
MICRO_VERSION = '2' MICRO_VERSION = '3'
VERSION = "{}.{}.{}".format(MAJOR_VERSION, MINOR_VERSION, MICRO_VERSION) VERSION = "{}.{}.{}".format(MAJOR_VERSION, MINOR_VERSION, MICRO_VERSION)
# Get the long description from the README file # Get the long description from the README file