Annotation notes
This commit is contained in:
@@ -405,6 +405,7 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
|
|||||||
if self.annotation_mode:
|
if self.annotation_mode:
|
||||||
self.annotation_mode = False
|
self.annotation_mode = False
|
||||||
self.viewport().setCursor(QtCore.Qt.ArrowCursor)
|
self.viewport().setCursor(QtCore.Qt.ArrowCursor)
|
||||||
|
self.parent.annotationDock.show()
|
||||||
self.parent.annotationDock.setWindowOpacity(.95)
|
self.parent.annotationDock.setWindowOpacity(.95)
|
||||||
|
|
||||||
self.current_annotation = None
|
self.current_annotation = None
|
||||||
@@ -413,7 +414,7 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
|
|||||||
else:
|
else:
|
||||||
self.annotation_mode = True
|
self.annotation_mode = True
|
||||||
self.viewport().setCursor(QtCore.Qt.IBeamCursor)
|
self.viewport().setCursor(QtCore.Qt.IBeamCursor)
|
||||||
self.parent.annotationDock.setWindowOpacity(.40)
|
self.parent.annotationDock.hide()
|
||||||
|
|
||||||
selected_index = self.parent.annotationListView.currentIndex()
|
selected_index = self.parent.annotationListView.currentIndex()
|
||||||
self.current_annotation = self.parent.annotationModel.data(
|
self.current_annotation = self.parent.annotationModel.data(
|
||||||
@@ -556,6 +557,10 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
|
|||||||
webbrowser.open_new_tab(
|
webbrowser.open_new_tab(
|
||||||
f'https://www.youtube.com/results?search_query={selection}')
|
f'https://www.youtube.com/results?search_query={selection}')
|
||||||
|
|
||||||
|
if action == editAnnotationNoteAction:
|
||||||
|
self.common_functions.show_annotation_note(
|
||||||
|
'text', current_chapter, cursor_at_mouse.position())
|
||||||
|
|
||||||
if action == deleteAnnotationAction:
|
if action == deleteAnnotationAction:
|
||||||
self.common_functions.delete_annotation(
|
self.common_functions.delete_annotation(
|
||||||
'text', current_chapter, cursor_at_mouse.position())
|
'text', current_chapter, cursor_at_mouse.position())
|
||||||
@@ -705,6 +710,26 @@ class PliantWidgetsCommonFunctions:
|
|||||||
self.load_annotations(chapter)
|
self.load_annotations(chapter)
|
||||||
self.pw.verticalScrollBar().setValue(current_scroll_position)
|
self.pw.verticalScrollBar().setValue(current_scroll_position)
|
||||||
|
|
||||||
|
def show_annotation_note(self, annotation_type, chapter, cursor_position):
|
||||||
|
# TODO
|
||||||
|
# Consolidate this and the next 2 functions
|
||||||
|
|
||||||
|
try:
|
||||||
|
chapter_annotations = self.pw.annotation_dict[chapter]
|
||||||
|
except KeyError:
|
||||||
|
return
|
||||||
|
|
||||||
|
for i in chapter_annotations:
|
||||||
|
if annotation_type == 'text':
|
||||||
|
cursor_start = i['cursor'][0]
|
||||||
|
cursor_end = i['cursor'][1]
|
||||||
|
|
||||||
|
if cursor_start <= cursor_position <= cursor_end:
|
||||||
|
note = i['note']
|
||||||
|
self.pw.parent.annotationNoteDock.set_annotation(i)
|
||||||
|
self.pw.parent.annotationNoteEdit.setText(note)
|
||||||
|
self.pw.parent.annotationNoteDock.show()
|
||||||
|
|
||||||
def clear_annotations(self):
|
def clear_annotations(self):
|
||||||
if not self.are_we_doing_images_only:
|
if not self.are_we_doing_images_only:
|
||||||
cursor = self.pw.textCursor()
|
cursor = self.pw.textCursor()
|
||||||
|
@@ -138,6 +138,17 @@ class Tab(QtWidgets.QWidget):
|
|||||||
self.annotationModel = QtGui.QStandardItemModel(self)
|
self.annotationModel = QtGui.QStandardItemModel(self)
|
||||||
self.generate_annotation_model()
|
self.generate_annotation_model()
|
||||||
|
|
||||||
|
# Create the annotation notes dock
|
||||||
|
self.annotationNoteDock = PliantDockWidget(self.main_window, 'notes', self.contentView)
|
||||||
|
self.annotationNoteDock.setWindowTitle(self._translate('Tab', 'Note'))
|
||||||
|
self.annotationNoteDock.setFeatures(QtWidgets.QDockWidget.DockWidgetClosable)
|
||||||
|
self.annotationNoteDock.hide()
|
||||||
|
|
||||||
|
self.annotationNoteEdit = QtWidgets.QTextEdit(self.annotationDock)
|
||||||
|
self.annotationNoteEdit.setMaximumSize(QtCore.QSize(200, 200))
|
||||||
|
self.annotationNoteEdit.setFocusPolicy(QtCore.Qt.StrongFocus)
|
||||||
|
self.annotationNoteDock.setWidget(self.annotationNoteEdit)
|
||||||
|
|
||||||
# Create the dock widget for context specific display
|
# Create the dock widget for context specific display
|
||||||
self.bookmarkDock = PliantDockWidget(self.main_window, 'bookmarks', self.contentView)
|
self.bookmarkDock = PliantDockWidget(self.main_window, 'bookmarks', self.contentView)
|
||||||
self.bookmarkDock.setWindowTitle(self._translate('Tab', 'Bookmarks'))
|
self.bookmarkDock.setWindowTitle(self._translate('Tab', 'Bookmarks'))
|
||||||
@@ -164,11 +175,14 @@ class Tab(QtWidgets.QWidget):
|
|||||||
|
|
||||||
self.masterLayout.addWidget(self.contentView)
|
self.masterLayout.addWidget(self.contentView)
|
||||||
self.masterLayout.addWidget(self.annotationDock)
|
self.masterLayout.addWidget(self.annotationDock)
|
||||||
|
self.masterLayout.addWidget(self.annotationNoteDock)
|
||||||
self.masterLayout.addWidget(self.bookmarkDock)
|
self.masterLayout.addWidget(self.bookmarkDock)
|
||||||
|
|
||||||
# The following has to be after the docks are added to the layout
|
# The following has to be after the docks are added to the layout
|
||||||
self.annotationDock.setFloating(True)
|
self.annotationDock.setFloating(True)
|
||||||
self.annotationDock.setWindowOpacity(.95)
|
self.annotationDock.setWindowOpacity(.95)
|
||||||
|
self.annotationNoteDock.setFloating(True)
|
||||||
|
self.annotationNoteDock.setWindowOpacity(.95)
|
||||||
self.bookmarkDock.setFloating(True)
|
self.bookmarkDock.setFloating(True)
|
||||||
self.bookmarkDock.setWindowOpacity(.95)
|
self.bookmarkDock.setWindowOpacity(.95)
|
||||||
|
|
||||||
@@ -305,8 +319,9 @@ class Tab(QtWidgets.QWidget):
|
|||||||
self.is_fullscreen = True
|
self.is_fullscreen = True
|
||||||
|
|
||||||
def exit_fullscreen(self):
|
def exit_fullscreen(self):
|
||||||
if self.bookmarkDock.isVisible():
|
for i in (self.bookmarkDock, self.annotationDock, self.annotationNoteDock):
|
||||||
self.bookmarkDock.setVisible(False)
|
if i.isVisible():
|
||||||
|
i.setVisible(False)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self.are_we_doing_images_only:
|
if not self.are_we_doing_images_only:
|
||||||
@@ -559,6 +574,7 @@ class PliantDockWidget(QtWidgets.QDockWidget):
|
|||||||
self.main_window = main_window
|
self.main_window = main_window
|
||||||
self.intended_for = intended_for
|
self.intended_for = intended_for
|
||||||
self.contentView = contentView
|
self.contentView = contentView
|
||||||
|
self.current_annotation = None
|
||||||
|
|
||||||
def showEvent(self, event):
|
def showEvent(self, event):
|
||||||
viewport_height = self.contentView.viewport().size().height()
|
viewport_height = self.contentView.viewport().size().height()
|
||||||
@@ -568,6 +584,8 @@ class PliantDockWidget(QtWidgets.QDockWidget):
|
|||||||
self.contentView.viewport().rect().topLeft())
|
self.contentView.viewport().rect().topLeft())
|
||||||
|
|
||||||
desktop_size = QtWidgets.QDesktopWidget().screenGeometry()
|
desktop_size = QtWidgets.QDesktopWidget().screenGeometry()
|
||||||
|
dock_y = viewport_topRight.y() + (viewport_height * .10)
|
||||||
|
dock_height = viewport_height * .80
|
||||||
|
|
||||||
if self.intended_for == 'bookmarks':
|
if self.intended_for == 'bookmarks':
|
||||||
dock_width = desktop_size.width() // 5.5
|
dock_width = desktop_size.width() // 5.5
|
||||||
@@ -579,8 +597,10 @@ class PliantDockWidget(QtWidgets.QDockWidget):
|
|||||||
dock_x = viewport_topLeft.x()
|
dock_x = viewport_topLeft.x()
|
||||||
self.main_window.bookToolBar.annotationButton.setChecked(True)
|
self.main_window.bookToolBar.annotationButton.setChecked(True)
|
||||||
|
|
||||||
dock_y = viewport_topRight.y() + (viewport_height * .10)
|
elif self.intended_for == 'notes':
|
||||||
dock_height = viewport_height * .80
|
dock_width = dock_height = desktop_size.width() // 6
|
||||||
|
dock_x = QtGui.QCursor.pos().x()
|
||||||
|
dock_y = QtGui.QCursor.pos().y()
|
||||||
|
|
||||||
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)
|
self.setGeometry(dock_x, dock_y, dock_width, dock_height)
|
||||||
@@ -590,14 +610,24 @@ class PliantDockWidget(QtWidgets.QDockWidget):
|
|||||||
self.main_window.bookToolBar.bookmarkButton.setChecked(False)
|
self.main_window.bookToolBar.bookmarkButton.setChecked(False)
|
||||||
elif self.intended_for == 'annotations':
|
elif self.intended_for == 'annotations':
|
||||||
self.main_window.bookToolBar.annotationButton.setChecked(False)
|
self.main_window.bookToolBar.annotationButton.setChecked(False)
|
||||||
|
elif self.intended_for == 'notes':
|
||||||
|
annotationNoteEdit = self.findChild(QtWidgets.QTextEdit)
|
||||||
|
if self.current_annotation:
|
||||||
|
self.current_annotation['note'] = annotationNoteEdit.toPlainText()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.main_window.active_bookmark_docks.remove(self)
|
self.main_window.active_bookmark_docks.remove(self)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def set_annotation(self, annotation):
|
||||||
|
self.current_annotation = annotation
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
|
self.main_window.bookToolBar.annotationButton.setChecked(False)
|
||||||
self.hide()
|
self.hide()
|
||||||
|
|
||||||
|
# Ignoring this event prevents application closure when everything is fullscreened
|
||||||
event.ignore()
|
event.ignore()
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user