Annotation placement
This commit is contained in:
3
TODO
3
TODO
@@ -62,6 +62,8 @@ TODO
|
|||||||
✓ Track open bookmark windows so they can be closed quickly at exit
|
✓ Track open bookmark windows so they can be closed quickly at exit
|
||||||
Annotations
|
Annotations
|
||||||
Text
|
Text
|
||||||
|
Overlapping - Will involve passing current charformat
|
||||||
|
Annotation preview upon application
|
||||||
Image
|
Image
|
||||||
Adjust key navigation according to viewport dimensions
|
Adjust key navigation according to viewport dimensions
|
||||||
Search document using QTextCursor
|
Search document using QTextCursor
|
||||||
@@ -80,6 +82,7 @@ TODO
|
|||||||
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
|
||||||
Clean up 'switch' page layout
|
Clean up 'switch' page layout
|
||||||
|
Colors aren't loaded properly for annotation previews
|
||||||
|
|
||||||
Secondary:
|
Secondary:
|
||||||
Graphical themes
|
Graphical themes
|
||||||
|
@@ -164,9 +164,10 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
|||||||
self.libraryToolBar.tableViewButton.trigger()
|
self.libraryToolBar.tableViewButton.trigger()
|
||||||
|
|
||||||
# Book toolbar
|
# Book toolbar
|
||||||
|
self.bookToolBar.annotationButton.triggered.connect(self.toggle_dock_widgets)
|
||||||
self.bookToolBar.addBookmarkButton.triggered.connect(self.add_bookmark)
|
self.bookToolBar.addBookmarkButton.triggered.connect(self.add_bookmark)
|
||||||
self.bookToolBar.bookmarkButton.triggered.connect(self.toggle_dock_widget)
|
self.bookToolBar.bookmarkButton.triggered.connect(self.toggle_dock_widgets)
|
||||||
self.bookToolBar.distractionFreeButton.triggered.connect(self.toggle_distraction_free)
|
self.bookToolBar.distractionFreeButton.triggered.connect(self.toggle_dock_widgets)
|
||||||
self.bookToolBar.fullscreenButton.triggered.connect(self.set_fullscreen)
|
self.bookToolBar.fullscreenButton.triggered.connect(self.set_fullscreen)
|
||||||
|
|
||||||
for count, i in enumerate(self.display_profiles):
|
for count, i in enumerate(self.display_profiles):
|
||||||
@@ -510,9 +511,10 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
|||||||
|
|
||||||
self.current_tab = self.tabWidget.currentIndex()
|
self.current_tab = self.tabWidget.currentIndex()
|
||||||
|
|
||||||
# Hide bookmark widgets
|
# Hide bookmark and annotation widgets
|
||||||
for i in range(1, self.tabWidget.count()):
|
for i in range(1, self.tabWidget.count()):
|
||||||
self.tabWidget.widget(i).dockWidget.setVisible(False)
|
self.tabWidget.widget(i).bookmarkDock.setVisible(False)
|
||||||
|
self.tabWidget.widget(i).annotationDock.setVisible(False)
|
||||||
|
|
||||||
if self.tabWidget.currentIndex() == 0:
|
if self.tabWidget.currentIndex() == 0:
|
||||||
|
|
||||||
@@ -598,14 +600,17 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
|||||||
current_tab_widget = self.tabWidget.widget(current_tab)
|
current_tab_widget = self.tabWidget.widget(current_tab)
|
||||||
current_tab_widget.go_fullscreen()
|
current_tab_widget.go_fullscreen()
|
||||||
|
|
||||||
def toggle_dock_widget(self):
|
def toggle_dock_widgets(self):
|
||||||
sender = self.sender().objectName()
|
sender = self.sender()
|
||||||
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)
|
||||||
|
|
||||||
if sender == 'bookmarkButton':
|
if sender == self.bookToolBar.bookmarkButton:
|
||||||
current_tab_widget.toggle_bookmarks()
|
current_tab_widget.toggle_bookmarks()
|
||||||
|
|
||||||
|
if sender == self.bookToolBar.annotationButton:
|
||||||
|
current_tab_widget.toggle_annotations()
|
||||||
|
|
||||||
def library_doubleclick(self, index):
|
def library_doubleclick(self, index):
|
||||||
sender = self.sender().objectName()
|
sender = self.sender().objectName()
|
||||||
|
|
||||||
|
@@ -69,6 +69,10 @@ class AnnotationsUI(QtWidgets.QDialog, annotationswindow.Ui_Dialog):
|
|||||||
self.underlineCheck.clicked.connect(self.modify_annotation)
|
self.underlineCheck.clicked.connect(self.modify_annotation)
|
||||||
|
|
||||||
def show_dialog(self, mode, index=None):
|
def show_dialog(self, mode, index=None):
|
||||||
|
# TODO
|
||||||
|
# Account for annotation type here
|
||||||
|
# and point to a relevant set of widgets accordingly
|
||||||
|
|
||||||
if mode == 'edit' or mode == 'preview':
|
if mode == 'edit' or mode == 'preview':
|
||||||
self.modelIndex = index
|
self.modelIndex = index
|
||||||
this_annotation = self.parent.annotationModel.data(
|
this_annotation = self.parent.annotationModel.data(
|
||||||
@@ -244,3 +248,62 @@ class AnnotationsUI(QtWidgets.QDialog, annotationswindow.Ui_Dialog):
|
|||||||
self.parent.annotationModel.appendRow(new_annotation_item)
|
self.parent.annotationModel.appendRow(new_annotation_item)
|
||||||
|
|
||||||
self.hide()
|
self.hide()
|
||||||
|
|
||||||
|
|
||||||
|
class AnnotationPlacement:
|
||||||
|
def __init__(self):
|
||||||
|
self.annotation_type = None
|
||||||
|
self.annotation_components = None
|
||||||
|
self.underline_styles = {
|
||||||
|
'Solid': QtGui.QTextCharFormat.SingleUnderline,
|
||||||
|
'Dashes': QtGui.QTextCharFormat.DashUnderline,
|
||||||
|
'Dots': QtGui.QTextCharFormat.DotLine,
|
||||||
|
'Wavy': QtGui.QTextCharFormat.WaveUnderline}
|
||||||
|
|
||||||
|
def set_current_annotation(self, annotation_type, annotation_components):
|
||||||
|
# Components expected to be a dictionary
|
||||||
|
self.annotation_type = annotation_type # This is currently unused
|
||||||
|
self.annotation_components = annotation_components
|
||||||
|
|
||||||
|
def format_text(self, cursor, start_here, end_here):
|
||||||
|
# This is applicable only to the PliantQTextBrowser
|
||||||
|
# for the text_markup style of annotation
|
||||||
|
|
||||||
|
# The cursor is the textCursor of the QTextEdit
|
||||||
|
# containing the text that has to be modified
|
||||||
|
|
||||||
|
if not self.annotation_components:
|
||||||
|
return
|
||||||
|
|
||||||
|
cursor.setPosition(start_here)
|
||||||
|
cursor.setPosition(end_here, QtGui.QTextCursor.KeepAnchor)
|
||||||
|
|
||||||
|
newCharFormat = QtGui.QTextCharFormat()
|
||||||
|
|
||||||
|
if 'foregroundColor' in self.annotation_components:
|
||||||
|
newCharFormat.setForeground(
|
||||||
|
self.annotation_components['foregroundColor'])
|
||||||
|
|
||||||
|
if 'highlightColor' in self.annotation_components:
|
||||||
|
newCharFormat.setBackground(
|
||||||
|
self.annotation_components['highlightColor'])
|
||||||
|
|
||||||
|
if 'bold' in self.annotation_components:
|
||||||
|
newCharFormat.setFontWeight(QtGui.QFont.Bold)
|
||||||
|
|
||||||
|
if 'italic' in self.annotation_components:
|
||||||
|
newCharFormat.setFontItalic(True)
|
||||||
|
|
||||||
|
if 'underline' in self.annotation_components:
|
||||||
|
newCharFormat.setFontUnderline(True)
|
||||||
|
newCharFormat.setUnderlineStyle(
|
||||||
|
self.underline_styles[self.annotation_components['underline'][0]])
|
||||||
|
newCharFormat.setUnderlineColor(
|
||||||
|
self.annotation_components['underline'][1])
|
||||||
|
|
||||||
|
newCharFormat.setFontStyleStrategy(
|
||||||
|
QtGui.QFont.PreferAntialias)
|
||||||
|
|
||||||
|
cursor.setCharFormat(newCharFormat)
|
||||||
|
cursor.clearSelection()
|
||||||
|
return cursor
|
||||||
|
@@ -27,6 +27,7 @@ from PyQt5 import QtWidgets, QtGui, QtCore
|
|||||||
|
|
||||||
from lector.rarfile import rarfile
|
from lector.rarfile import rarfile
|
||||||
from lector.threaded import BackGroundCacheRefill
|
from lector.threaded import BackGroundCacheRefill
|
||||||
|
from lector.annotations import AnnotationPlacement
|
||||||
|
|
||||||
|
|
||||||
class PliantQGraphicsView(QtWidgets.QGraphicsView):
|
class PliantQGraphicsView(QtWidgets.QGraphicsView):
|
||||||
@@ -326,6 +327,9 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
|
|||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.main_window = main_window
|
self.main_window = main_window
|
||||||
|
|
||||||
|
self.annotator = AnnotationPlacement()
|
||||||
|
self.current_annotation = None
|
||||||
|
|
||||||
self.common_functions = PliantWidgetsCommonFunctions(
|
self.common_functions = PliantWidgetsCommonFunctions(
|
||||||
self, self.main_window)
|
self, self.main_window)
|
||||||
|
|
||||||
@@ -334,7 +338,6 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
|
|||||||
self.generate_textbrowser_context_menu)
|
self.generate_textbrowser_context_menu)
|
||||||
|
|
||||||
self.setMouseTracking(True)
|
self.setMouseTracking(True)
|
||||||
self.viewport().setCursor(QtCore.Qt.IBeamCursor)
|
|
||||||
self.verticalScrollBar().sliderMoved.connect(
|
self.verticalScrollBar().sliderMoved.connect(
|
||||||
self.record_position)
|
self.record_position)
|
||||||
self.ignore_wheel_event = False
|
self.ignore_wheel_event = False
|
||||||
@@ -391,6 +394,36 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
|
|||||||
else:
|
else:
|
||||||
self.parent.metadata['position']['cursor_position'] = cursor_position
|
self.parent.metadata['position']['cursor_position'] = cursor_position
|
||||||
|
|
||||||
|
def toggle_annotation_mode(self):
|
||||||
|
self.annotation_mode = True
|
||||||
|
self.viewport().setCursor(QtCore.Qt.IBeamCursor)
|
||||||
|
self.parent.annotationDock.setWindowOpacity(.40)
|
||||||
|
|
||||||
|
selected_index = self.parent.annotationListView.currentIndex()
|
||||||
|
self.current_annotation = self.parent.annotationModel.data(
|
||||||
|
selected_index, QtCore.Qt.UserRole)
|
||||||
|
print('Current annotation: ' + self.current_annotation['name'])
|
||||||
|
|
||||||
|
def mouseReleaseEvent(self, event):
|
||||||
|
# This takes care of annotation placement
|
||||||
|
if not self.current_annotation:
|
||||||
|
QtWidgets.QTextBrowser.mouseReleaseEvent(self, event)
|
||||||
|
return
|
||||||
|
|
||||||
|
self.annotator.set_current_annotation(
|
||||||
|
'text_markup', self.current_annotation['components'])
|
||||||
|
|
||||||
|
cursor = self.textCursor()
|
||||||
|
new_cursor = self.annotator.format_text(
|
||||||
|
cursor, cursor.selectionStart(), cursor.selectionEnd())
|
||||||
|
self.setTextCursor(new_cursor)
|
||||||
|
|
||||||
|
self.annotation_mode = False
|
||||||
|
self.viewport().setCursor(QtCore.Qt.ArrowCursor)
|
||||||
|
self.current_annotation = None
|
||||||
|
self.parent.annotationListView.clearSelection()
|
||||||
|
self.parent.annotationDock.setWindowOpacity(.95)
|
||||||
|
|
||||||
def generate_textbrowser_context_menu(self, position):
|
def generate_textbrowser_context_menu(self, position):
|
||||||
selection = self.textCursor().selection()
|
selection = self.textCursor().selection()
|
||||||
selection = selection.toPlainText()
|
selection = selection.toPlainText()
|
||||||
@@ -479,7 +512,7 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
|
|||||||
self.main_window.closeEvent()
|
self.main_window.closeEvent()
|
||||||
|
|
||||||
def mouseMoveEvent(self, event):
|
def mouseMoveEvent(self, event):
|
||||||
self.viewport().setCursor(QtCore.Qt.IBeamCursor)
|
self.viewport().setCursor(QtCore.Qt.ArrowCursor)
|
||||||
self.parent.mouse_hide_timer.start(3000)
|
self.parent.mouse_hide_timer.start(3000)
|
||||||
QtWidgets.QTextBrowser.mouseMoveEvent(self, event)
|
QtWidgets.QTextBrowser.mouseMoveEvent(self, event)
|
||||||
|
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="images">
|
<qresource prefix="images">
|
||||||
|
<file>LightIcons/annotate.svg</file>
|
||||||
|
<file>DarkIcons/annotate.svg</file>
|
||||||
<file>Google.png</file>
|
<file>Google.png</file>
|
||||||
<file>Wikipedia.png</file>
|
<file>Wikipedia.png</file>
|
||||||
<file>Youtube.png</file>
|
<file>Youtube.png</file>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -190,14 +190,14 @@ class Settings:
|
|||||||
self.settings.endGroup()
|
self.settings.endGroup()
|
||||||
|
|
||||||
self.settings.beginGroup('settingsSwitches')
|
self.settings.beginGroup('settingsSwitches')
|
||||||
self.settings.setValue('rememberFiles', current_settings['remember_files'])
|
self.settings.setValue('rememberFiles', str(current_settings['remember_files']))
|
||||||
self.settings.setValue('coverShadows', current_settings['cover_shadows'])
|
self.settings.setValue('coverShadows', str(current_settings['cover_shadows']))
|
||||||
self.settings.setValue('autoTags', current_settings['auto_tags'])
|
self.settings.setValue('autoTags', str(current_settings['auto_tags']))
|
||||||
self.settings.setValue('scanLibraryAtStart', current_settings['scan_library'])
|
self.settings.setValue('scanLibraryAtStart', str(current_settings['scan_library']))
|
||||||
self.settings.setValue('performCulling', current_settings['perform_culling'])
|
self.settings.setValue('performCulling', str(current_settings['perform_culling']))
|
||||||
self.settings.setValue('dictionaryLanguage', current_settings['dictionary_language'])
|
self.settings.setValue('dictionaryLanguage', str(current_settings['dictionary_language']))
|
||||||
self.settings.setValue('cachingEnabled', current_settings['caching_enabled'])
|
self.settings.setValue('cachingEnabled', str(current_settings['caching_enabled']))
|
||||||
self.settings.setValue('hideScrollBars', current_settings['hide_scrollbars'])
|
self.settings.setValue('hideScrollBars', str(current_settings['hide_scrollbars']))
|
||||||
self.settings.setValue('scrollSpeed', current_settings['scroll_speed'])
|
self.settings.setValue('scrollSpeed', current_settings['scroll_speed'])
|
||||||
self.settings.setValue('considerReadAt', current_settings['consider_read_at'])
|
self.settings.setValue('considerReadAt', current_settings['consider_read_at'])
|
||||||
self.settings.endGroup()
|
self.settings.endGroup()
|
||||||
|
@@ -314,6 +314,7 @@ class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog):
|
|||||||
self.main_window.libraryToolBar.settingsButton.setChecked(False)
|
self.main_window.libraryToolBar.settingsButton.setChecked(False)
|
||||||
self.gather_annotations()
|
self.gather_annotations()
|
||||||
Settings(self.main_window).save_settings()
|
Settings(self.main_window).save_settings()
|
||||||
|
Settings(self.main_window).read_settings()
|
||||||
self.resizeEvent()
|
self.resizeEvent()
|
||||||
|
|
||||||
def resizeEvent(self, event=None):
|
def resizeEvent(self, event=None):
|
||||||
|
@@ -43,6 +43,10 @@ class BookToolBar(QtWidgets.QToolBar):
|
|||||||
image_factory.get_image('gtk-select-font'),
|
image_factory.get_image('gtk-select-font'),
|
||||||
self._translate('BookToolBar', 'View settings'),
|
self._translate('BookToolBar', 'View settings'),
|
||||||
self)
|
self)
|
||||||
|
self.annotationButton = QtWidgets.QAction(
|
||||||
|
image_factory.get_image('annotate'),
|
||||||
|
self._translate('BookToolBar', 'Annotations'),
|
||||||
|
self)
|
||||||
self.addBookmarkButton = QtWidgets.QAction(
|
self.addBookmarkButton = QtWidgets.QAction(
|
||||||
image_factory.get_image('bookmark-new'),
|
image_factory.get_image('bookmark-new'),
|
||||||
self._translate('BookToolBar', 'Add bookmark'),
|
self._translate('BookToolBar', 'Add bookmark'),
|
||||||
@@ -51,7 +55,6 @@ class BookToolBar(QtWidgets.QToolBar):
|
|||||||
image_factory.get_image('bookmarks'),
|
image_factory.get_image('bookmarks'),
|
||||||
self._translate('BookToolBar', 'Bookmarks (Ctrl + B)'),
|
self._translate('BookToolBar', 'Bookmarks (Ctrl + B)'),
|
||||||
self)
|
self)
|
||||||
self.bookmarkButton.setObjectName('bookmarkButton')
|
|
||||||
self.distractionFreeButton = QtWidgets.QAction(
|
self.distractionFreeButton = QtWidgets.QAction(
|
||||||
image_factory.get_image('visibility'),
|
image_factory.get_image('visibility'),
|
||||||
self._translate('Main_BookToolBarUI', 'Toggle distraction free mode (Ctrl + D)'),
|
self._translate('Main_BookToolBarUI', 'Toggle distraction free mode (Ctrl + D)'),
|
||||||
@@ -70,6 +73,9 @@ class BookToolBar(QtWidgets.QToolBar):
|
|||||||
self.fontButton.setCheckable(True)
|
self.fontButton.setCheckable(True)
|
||||||
self.fontButton.triggered.connect(self.toggle_font_settings)
|
self.fontButton.triggered.connect(self.toggle_font_settings)
|
||||||
self.addSeparator()
|
self.addSeparator()
|
||||||
|
self.addAction(self.annotationButton)
|
||||||
|
self.annotationButton.setCheckable(True)
|
||||||
|
self.addSeparator()
|
||||||
self.addAction(self.addBookmarkButton)
|
self.addAction(self.addBookmarkButton)
|
||||||
self.addAction(self.bookmarkButton)
|
self.addAction(self.bookmarkButton)
|
||||||
self.bookmarkButton.setCheckable(True)
|
self.bookmarkButton.setCheckable(True)
|
||||||
@@ -280,6 +286,7 @@ class BookToolBar(QtWidgets.QToolBar):
|
|||||||
self.searchBarAction = self.addWidget(self.searchBar)
|
self.searchBarAction = self.addWidget(self.searchBar)
|
||||||
|
|
||||||
self.bookActions = [
|
self.bookActions = [
|
||||||
|
self.annotationButton,
|
||||||
self.addBookmarkButton,
|
self.addBookmarkButton,
|
||||||
self.bookmarkButton,
|
self.bookmarkButton,
|
||||||
self.distractionFreeButton,
|
self.distractionFreeButton,
|
||||||
|
@@ -111,27 +111,43 @@ class Tab(QtWidgets.QWidget):
|
|||||||
self.contentView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
|
self.contentView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
|
||||||
self.contentView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
|
self.contentView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
|
||||||
|
|
||||||
|
# Create the annotations dock
|
||||||
|
self.annotationDock = PliantDockWidget(self.main_window, 'annotations', self.contentView)
|
||||||
|
self.annotationDock.setWindowTitle(self._translate('Tab', 'Annotations'))
|
||||||
|
self.annotationDock.setFeatures(QtWidgets.QDockWidget.DockWidgetClosable)
|
||||||
|
self.annotationDock.hide()
|
||||||
|
|
||||||
|
self.annotationListView = QtWidgets.QListView(self.annotationDock)
|
||||||
|
self.annotationListView.setResizeMode(QtWidgets.QListWidget.Adjust)
|
||||||
|
self.annotationListView.setMaximumWidth(350)
|
||||||
|
self.annotationListView.doubleClicked.connect(self.contentView.toggle_annotation_mode)
|
||||||
|
self.annotationListView.setEditTriggers(QtWidgets.QListView.NoEditTriggers)
|
||||||
|
self.annotationDock.setWidget(self.annotationListView)
|
||||||
|
|
||||||
|
self.annotationModel = QtGui.QStandardItemModel(self)
|
||||||
|
self.generate_annotation_model()
|
||||||
|
|
||||||
# See bookmark availability
|
# See bookmark availability
|
||||||
if not self.metadata['bookmarks']:
|
if not self.metadata['bookmarks']:
|
||||||
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.main_window, self.contentView)
|
self.bookmarkDock = PliantDockWidget(self.main_window, 'bookmarks', self.contentView)
|
||||||
self.dockWidget.setWindowTitle(self._translate('Tab', 'Bookmarks'))
|
self.bookmarkDock.setWindowTitle(self._translate('Tab', 'Bookmarks'))
|
||||||
self.dockWidget.setFeatures(QtWidgets.QDockWidget.DockWidgetClosable)
|
self.bookmarkDock.setFeatures(QtWidgets.QDockWidget.DockWidgetClosable)
|
||||||
self.dockWidget.hide()
|
self.bookmarkDock.hide()
|
||||||
|
|
||||||
self.dockListView = QtWidgets.QListView(self.dockWidget)
|
self.bookmarkListView = QtWidgets.QListView(self.bookmarkDock)
|
||||||
self.dockListView.setResizeMode(QtWidgets.QListWidget.Adjust)
|
self.bookmarkListView.setResizeMode(QtWidgets.QListWidget.Adjust)
|
||||||
self.dockListView.setMaximumWidth(350)
|
self.bookmarkListView.setMaximumWidth(350)
|
||||||
self.dockListView.setItemDelegate(
|
self.bookmarkListView.setItemDelegate(
|
||||||
BookmarkDelegate(self.main_window, self.dockListView))
|
BookmarkDelegate(self.main_window, self.bookmarkListView))
|
||||||
self.dockListView.setUniformItemSizes(True)
|
self.bookmarkListView.setUniformItemSizes(True)
|
||||||
self.dockListView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
self.bookmarkListView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
||||||
self.dockListView.customContextMenuRequested.connect(
|
self.bookmarkListView.customContextMenuRequested.connect(
|
||||||
self.generate_bookmark_context_menu)
|
self.generate_bookmark_context_menu)
|
||||||
self.dockListView.clicked.connect(self.navigate_to_bookmark)
|
self.bookmarkListView.clicked.connect(self.navigate_to_bookmark)
|
||||||
self.dockWidget.setWidget(self.dockListView)
|
self.bookmarkDock.setWidget(self.bookmarkListView)
|
||||||
|
|
||||||
self.bookmarkModel = QtGui.QStandardItemModel(self)
|
self.bookmarkModel = QtGui.QStandardItemModel(self)
|
||||||
self.bookmarkProxyModel = BookmarkProxyModel(self)
|
self.bookmarkProxyModel = BookmarkProxyModel(self)
|
||||||
@@ -140,9 +156,14 @@ class Tab(QtWidgets.QWidget):
|
|||||||
self.generate_keyboard_shortcuts()
|
self.generate_keyboard_shortcuts()
|
||||||
|
|
||||||
self.masterLayout.addWidget(self.contentView)
|
self.masterLayout.addWidget(self.contentView)
|
||||||
self.masterLayout.addWidget(self.dockWidget)
|
self.masterLayout.addWidget(self.annotationDock)
|
||||||
self.dockWidget.setFloating(True)
|
self.masterLayout.addWidget(self.bookmarkDock)
|
||||||
self.dockWidget.setWindowOpacity(.95)
|
|
||||||
|
# The following has to be after the docks are added to the layout
|
||||||
|
self.annotationDock.setFloating(True)
|
||||||
|
self.annotationDock.setWindowOpacity(.95)
|
||||||
|
self.bookmarkDock.setFloating(True)
|
||||||
|
self.bookmarkDock.setWindowOpacity(.95)
|
||||||
|
|
||||||
title = self.metadata['title']
|
title = self.metadata['title']
|
||||||
self.main_window.tabWidget.addTab(self, title)
|
self.main_window.tabWidget.addTab(self, title)
|
||||||
@@ -277,8 +298,8 @@ class Tab(QtWidgets.QWidget):
|
|||||||
self.is_fullscreen = True
|
self.is_fullscreen = True
|
||||||
|
|
||||||
def exit_fullscreen(self):
|
def exit_fullscreen(self):
|
||||||
if self.dockWidget.isVisible():
|
if self.bookmarkDock.isVisible():
|
||||||
self.dockWidget.setVisible(False)
|
self.bookmarkDock.setVisible(False)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self.are_we_doing_images_only:
|
if not self.are_we_doing_images_only:
|
||||||
@@ -370,11 +391,31 @@ class Tab(QtWidgets.QWidget):
|
|||||||
if old_position == new_position:
|
if old_position == new_position:
|
||||||
break
|
break
|
||||||
|
|
||||||
def toggle_bookmarks(self):
|
def toggle_annotations(self):
|
||||||
if self.dockWidget.isVisible():
|
if self.annotationDock.isVisible():
|
||||||
self.dockWidget.hide()
|
self.annotationDock.hide()
|
||||||
else:
|
else:
|
||||||
self.dockWidget.show()
|
self.annotationDock.show()
|
||||||
|
|
||||||
|
def generate_annotation_model(self):
|
||||||
|
saved_annotations = self.main_window.settings['annotations']
|
||||||
|
|
||||||
|
if not saved_annotations:
|
||||||
|
return
|
||||||
|
|
||||||
|
for i in saved_annotations:
|
||||||
|
item = QtGui.QStandardItem()
|
||||||
|
item.setText(i['name'])
|
||||||
|
item.setData(i, QtCore.Qt.UserRole)
|
||||||
|
self.annotationModel.appendRow(item)
|
||||||
|
|
||||||
|
self.annotationListView.setModel(self.annotationModel)
|
||||||
|
|
||||||
|
def toggle_bookmarks(self):
|
||||||
|
if self.bookmarkDock.isVisible():
|
||||||
|
self.bookmarkDock.hide()
|
||||||
|
else:
|
||||||
|
self.bookmarkDock.show()
|
||||||
|
|
||||||
def add_bookmark(self):
|
def add_bookmark(self):
|
||||||
# TODO
|
# TODO
|
||||||
@@ -396,7 +437,7 @@ class Tab(QtWidgets.QWidget):
|
|||||||
|
|
||||||
self.add_bookmark_to_model(
|
self.add_bookmark_to_model(
|
||||||
description, chapter, cursor_position, identifier)
|
description, chapter, cursor_position, identifier)
|
||||||
self.dockWidget.setVisible(True)
|
self.bookmarkDock.setVisible(True)
|
||||||
|
|
||||||
def add_bookmark_to_model(self, description, chapter, cursor_position, identifier):
|
def add_bookmark_to_model(self, description, chapter, cursor_position, identifier):
|
||||||
bookmark = QtGui.QStandardItem()
|
bookmark = QtGui.QStandardItem()
|
||||||
@@ -445,7 +486,7 @@ class Tab(QtWidgets.QWidget):
|
|||||||
self.bookmarkProxyModel.setSourceModel(self.bookmarkModel)
|
self.bookmarkProxyModel.setSourceModel(self.bookmarkModel)
|
||||||
self.bookmarkProxyModel.setSortCaseSensitivity(False)
|
self.bookmarkProxyModel.setSortCaseSensitivity(False)
|
||||||
self.bookmarkProxyModel.setSortRole(QtCore.Qt.UserRole)
|
self.bookmarkProxyModel.setSortRole(QtCore.Qt.UserRole)
|
||||||
self.dockListView.setModel(self.bookmarkProxyModel)
|
self.bookmarkListView.setModel(self.bookmarkProxyModel)
|
||||||
|
|
||||||
def update_bookmark_proxy_model(self):
|
def update_bookmark_proxy_model(self):
|
||||||
self.bookmarkProxyModel.invalidateFilter()
|
self.bookmarkProxyModel.invalidateFilter()
|
||||||
@@ -455,7 +496,7 @@ class Tab(QtWidgets.QWidget):
|
|||||||
self.main_window.bookToolBar.searchBar.text())
|
self.main_window.bookToolBar.searchBar.text())
|
||||||
|
|
||||||
def generate_bookmark_context_menu(self, position):
|
def generate_bookmark_context_menu(self, position):
|
||||||
index = self.dockListView.indexAt(position)
|
index = self.bookmarkListView.indexAt(position)
|
||||||
if not index.isValid():
|
if not index.isValid():
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -468,10 +509,10 @@ class Tab(QtWidgets.QWidget):
|
|||||||
self._translate('Tab', 'Delete'))
|
self._translate('Tab', 'Delete'))
|
||||||
|
|
||||||
action = bookmarkMenu.exec_(
|
action = bookmarkMenu.exec_(
|
||||||
self.dockListView.mapToGlobal(position))
|
self.bookmarkListView.mapToGlobal(position))
|
||||||
|
|
||||||
if action == editAction:
|
if action == editAction:
|
||||||
self.dockListView.edit(index)
|
self.bookmarkListView.edit(index)
|
||||||
|
|
||||||
if action == deleteAction:
|
if action == deleteAction:
|
||||||
row = index.row()
|
row = index.row()
|
||||||
@@ -497,29 +538,43 @@ class Tab(QtWidgets.QWidget):
|
|||||||
|
|
||||||
|
|
||||||
class PliantDockWidget(QtWidgets.QDockWidget):
|
class PliantDockWidget(QtWidgets.QDockWidget):
|
||||||
def __init__(self, main_window, contentView, parent=None):
|
def __init__(self, main_window, intended_for, contentView, parent=None):
|
||||||
super(PliantDockWidget, self).__init__()
|
super(PliantDockWidget, self).__init__()
|
||||||
self.main_window = main_window
|
self.main_window = main_window
|
||||||
|
self.intended_for = intended_for
|
||||||
self.contentView = contentView
|
self.contentView = contentView
|
||||||
|
|
||||||
def showEvent(self, event):
|
def showEvent(self, event):
|
||||||
viewport_height = self.contentView.viewport().size().height()
|
viewport_height = self.contentView.viewport().size().height()
|
||||||
viewport_topRight = self.contentView.mapToGlobal(
|
viewport_topRight = self.contentView.mapToGlobal(
|
||||||
self.contentView.viewport().rect().topRight())
|
self.contentView.viewport().rect().topRight())
|
||||||
|
viewport_topLeft = self.contentView.mapToGlobal(
|
||||||
|
self.contentView.viewport().rect().topLeft())
|
||||||
|
|
||||||
desktop_size = QtWidgets.QDesktopWidget().screenGeometry()
|
desktop_size = QtWidgets.QDesktopWidget().screenGeometry()
|
||||||
dock_width = desktop_size.width() // 5.5
|
|
||||||
|
|
||||||
dock_x = viewport_topRight.x() - dock_width + 1
|
if self.intended_for == 'bookmarks':
|
||||||
|
dock_x = viewport_topRight.x() - dock_width + 1
|
||||||
|
dock_width = desktop_size.width() // 5.5
|
||||||
|
self.main_window.bookToolBar.bookmarkButton.setChecked(True)
|
||||||
|
|
||||||
|
elif self.intended_for == 'annotations':
|
||||||
|
dock_x = viewport_topLeft.x()
|
||||||
|
dock_width = desktop_size.width() // 10
|
||||||
|
self.main_window.bookToolBar.annotationButton.setChecked(True)
|
||||||
|
|
||||||
dock_y = viewport_topRight.y() + (viewport_height * .10)
|
dock_y = viewport_topRight.y() + (viewport_height * .10)
|
||||||
dock_height = viewport_height * .80
|
dock_height = viewport_height * .80
|
||||||
|
|
||||||
self.setGeometry(dock_x, dock_y, dock_width, dock_height)
|
|
||||||
self.main_window.bookToolBar.bookmarkButton.setChecked(True)
|
|
||||||
self.main_window.active_bookmark_docks.append(self)
|
self.main_window.active_bookmark_docks.append(self)
|
||||||
|
self.setGeometry(dock_x, dock_y, dock_width, dock_height)
|
||||||
|
|
||||||
def hideEvent(self, event=None):
|
def hideEvent(self, event=None):
|
||||||
self.main_window.bookToolBar.bookmarkButton.setChecked(False)
|
if self.intended_for == 'bookmarks':
|
||||||
|
self.main_window.bookToolBar.bookmarkButton.setChecked(False)
|
||||||
|
elif self.intended_for == 'annotations':
|
||||||
|
self.main_window.bookToolBar.annotationButton.setChecked(False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.main_window.active_bookmark_docks.remove(self)
|
self.main_window.active_bookmark_docks.remove(self)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
Reference in New Issue
Block a user