Annotation notes

This commit is contained in:
BasioMeusPuga
2018-04-19 20:35:22 +05:30
parent ec197f0829
commit d9efe2da3c
2 changed files with 61 additions and 6 deletions

View File

@@ -405,6 +405,7 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
if self.annotation_mode:
self.annotation_mode = False
self.viewport().setCursor(QtCore.Qt.ArrowCursor)
self.parent.annotationDock.show()
self.parent.annotationDock.setWindowOpacity(.95)
self.current_annotation = None
@@ -413,7 +414,7 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
else:
self.annotation_mode = True
self.viewport().setCursor(QtCore.Qt.IBeamCursor)
self.parent.annotationDock.setWindowOpacity(.40)
self.parent.annotationDock.hide()
selected_index = self.parent.annotationListView.currentIndex()
self.current_annotation = self.parent.annotationModel.data(
@@ -556,6 +557,10 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
webbrowser.open_new_tab(
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:
self.common_functions.delete_annotation(
'text', current_chapter, cursor_at_mouse.position())
@@ -705,6 +710,26 @@ class PliantWidgetsCommonFunctions:
self.load_annotations(chapter)
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):
if not self.are_we_doing_images_only:
cursor = self.pw.textCursor()

View File

@@ -138,6 +138,17 @@ class Tab(QtWidgets.QWidget):
self.annotationModel = QtGui.QStandardItemModel(self)
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
self.bookmarkDock = PliantDockWidget(self.main_window, 'bookmarks', self.contentView)
self.bookmarkDock.setWindowTitle(self._translate('Tab', 'Bookmarks'))
@@ -164,11 +175,14 @@ class Tab(QtWidgets.QWidget):
self.masterLayout.addWidget(self.contentView)
self.masterLayout.addWidget(self.annotationDock)
self.masterLayout.addWidget(self.annotationNoteDock)
self.masterLayout.addWidget(self.bookmarkDock)
# The following has to be after the docks are added to the layout
self.annotationDock.setFloating(True)
self.annotationDock.setWindowOpacity(.95)
self.annotationNoteDock.setFloating(True)
self.annotationNoteDock.setWindowOpacity(.95)
self.bookmarkDock.setFloating(True)
self.bookmarkDock.setWindowOpacity(.95)
@@ -305,9 +319,10 @@ class Tab(QtWidgets.QWidget):
self.is_fullscreen = True
def exit_fullscreen(self):
if self.bookmarkDock.isVisible():
self.bookmarkDock.setVisible(False)
return
for i in (self.bookmarkDock, self.annotationDock, self.annotationNoteDock):
if i.isVisible():
i.setVisible(False)
return
if not self.are_we_doing_images_only:
self.contentView.record_position()
@@ -559,6 +574,7 @@ class PliantDockWidget(QtWidgets.QDockWidget):
self.main_window = main_window
self.intended_for = intended_for
self.contentView = contentView
self.current_annotation = None
def showEvent(self, event):
viewport_height = self.contentView.viewport().size().height()
@@ -568,6 +584,8 @@ class PliantDockWidget(QtWidgets.QDockWidget):
self.contentView.viewport().rect().topLeft())
desktop_size = QtWidgets.QDesktopWidget().screenGeometry()
dock_y = viewport_topRight.y() + (viewport_height * .10)
dock_height = viewport_height * .80
if self.intended_for == 'bookmarks':
dock_width = desktop_size.width() // 5.5
@@ -579,8 +597,10 @@ class PliantDockWidget(QtWidgets.QDockWidget):
dock_x = viewport_topLeft.x()
self.main_window.bookToolBar.annotationButton.setChecked(True)
dock_y = viewport_topRight.y() + (viewport_height * .10)
dock_height = viewport_height * .80
elif self.intended_for == 'notes':
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.setGeometry(dock_x, dock_y, dock_width, dock_height)
@@ -590,14 +610,24 @@ class PliantDockWidget(QtWidgets.QDockWidget):
self.main_window.bookToolBar.bookmarkButton.setChecked(False)
elif self.intended_for == 'annotations':
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:
self.main_window.active_bookmark_docks.remove(self)
except ValueError:
pass
def set_annotation(self, annotation):
self.current_annotation = annotation
def closeEvent(self, event):
self.main_window.bookToolBar.annotationButton.setChecked(False)
self.hide()
# Ignoring this event prevents application closure when everything is fullscreened
event.ignore()