Add bookmark button, Bookmark delegate put into place - but mostly useless

This commit is contained in:
BasioMeusPuga
2018-02-27 09:12:27 +05:30
parent 7874838550
commit dcfd19aa43
2 changed files with 60 additions and 9 deletions

View File

@@ -127,6 +127,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.libraryToolBar.tableViewButton.trigger() self.libraryToolBar.tableViewButton.trigger()
# Book toolbar # Book toolbar
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_widget)
self.bookToolBar.fullscreenButton.triggered.connect(self.set_fullscreen) self.bookToolBar.fullscreenButton.triggered.connect(self.set_fullscreen)
@@ -221,6 +222,10 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.settings_dialog.start_library_scan() self.settings_dialog.start_library_scan()
def open_books_at_startup(self): def open_books_at_startup(self):
# TODO
# See if there's some reason why last open books and command line
# argument books can't be opened together
# Open last... open books. # Open last... open books.
# Then set the value to None for the next run # Then set the value to None for the next run
if self.settings['last_open_books']: if self.settings['last_open_books']:
@@ -333,11 +338,13 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
item.setIcon(QtGui.QIcon(img_pixmap)) item.setIcon(QtGui.QIcon(img_pixmap))
item.setData(True, QtCore.Qt.UserRole + 8) item.setData(True, QtCore.Qt.UserRole + 8)
def test_function(self): def add_bookmark(self):
# print('Caesar si viveret, ad remum dareris')
if self.tabWidget.currentIndex() != 0: if self.tabWidget.currentIndex() != 0:
self.tabWidget.widget(self.tabWidget.currentIndex()).add_bookmark() self.tabWidget.widget(self.tabWidget.currentIndex()).add_bookmark()
def test_function(self):
print('Caesar si viveret, ad remum dareris')
def resizeEvent(self, event=None): def resizeEvent(self, event=None):
if event: if event:
# This implies a vertical resize event only # This implies a vertical resize event only

View File

@@ -53,9 +53,12 @@ class BookToolBar(QtWidgets.QToolBar):
self.fullscreenButton = QtWidgets.QAction( self.fullscreenButton = QtWidgets.QAction(
QtGui.QIcon.fromTheme('view-fullscreen'), QtGui.QIcon.fromTheme('view-fullscreen'),
'Fullscreen', self) 'Fullscreen', self)
self.addBookmarkButton = QtWidgets.QAction(
QtGui.QIcon.fromTheme('bookmark-new'),
'Add bookmark', self)
self.bookmarkButton = QtWidgets.QAction( self.bookmarkButton = QtWidgets.QAction(
QtGui.QIcon.fromTheme('bookmarks'), QtGui.QIcon.fromTheme('bookmarks'),
'Bookmark', self) 'Bookmarks', self)
self.bookmarkButton.setObjectName('bookmarkButton') self.bookmarkButton.setObjectName('bookmarkButton')
self.resetProfile = QtWidgets.QAction( self.resetProfile = QtWidgets.QAction(
QtGui.QIcon.fromTheme('view-refresh'), QtGui.QIcon.fromTheme('view-refresh'),
@@ -66,8 +69,10 @@ 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.addBookmarkButton)
self.addAction(self.bookmarkButton) self.addAction(self.bookmarkButton)
self.bookmarkButton.setCheckable(True) self.bookmarkButton.setCheckable(True)
self.addSeparator()
self.addAction(self.fullscreenButton) self.addAction(self.fullscreenButton)
# Font modification # Font modification
@@ -219,6 +224,7 @@ class BookToolBar(QtWidgets.QToolBar):
self.searchBarAction = self.addWidget(self.searchBar) self.searchBarAction = self.addWidget(self.searchBar)
self.bookActions = [ self.bookActions = [
self.addBookmarkButton,
self.bookmarkButton, self.bookmarkButton,
self.fullscreenButton, self.fullscreenButton,
self.tocBoxAction, self.tocBoxAction,
@@ -441,6 +447,8 @@ class Tab(QtWidgets.QWidget):
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.setUniformItemSizes(True)
self.dockListView.clicked.connect(self.navigate_to_bookmark) self.dockListView.clicked.connect(self.navigate_to_bookmark)
self.dockWidget.setWidget(self.dockListView) self.dockWidget.setWidget(self.dockListView)
@@ -476,6 +484,13 @@ class Tab(QtWidgets.QWidget):
matching_item[0], self.metadata['last_accessed'], QtCore.Qt.UserRole + 12) matching_item[0], self.metadata['last_accessed'], QtCore.Qt.UserRole + 12)
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
if self.sender().objectName() == 'tabWidget':
return
if switch_widgets: if switch_widgets:
previous_widget = self.window().tabWidget.currentWidget() previous_widget = self.window().tabWidget.currentWidget()
self.window().tabWidget.setCurrentWidget(self) self.window().tabWidget.setCurrentWidget(self)
@@ -487,15 +502,15 @@ class Tab(QtWidgets.QWidget):
# Scroll a little ahead # Scroll a little ahead
# This avoids confusion with potentially duplicate phrases # This avoids confusion with potentially duplicate phrases
# And the found result is at the top of the window # And the found result is at the top of the window
scroll_position = scroll_value * self.contentView.verticalScrollBar().maximum() * 1.1 scroll_position = scroll_value * self.contentView.verticalScrollBar().maximum()
self.contentView.verticalScrollBar().setValue(scroll_position) self.contentView.verticalScrollBar().setValue(scroll_position * 1.1)
last_visible_text = self.metadata['position']['last_visible_text'] search_text = self.metadata['position']['last_visible_text']
if search_data: if search_data:
last_visible_text = search_data[1] search_text = search_data[1]
if last_visible_text: if search_text:
self.contentView.find(last_visible_text) self.contentView.find(search_text)
text_cursor = self.contentView.textCursor() text_cursor = self.contentView.textCursor()
text_cursor.clearSelection() text_cursor.clearSelection()
@@ -939,3 +954,32 @@ class LibraryDelegate(QtWidgets.QStyledItemDelegate):
y_draw = option.rect.bottomRight().y() - 35 y_draw = option.rect.bottomRight().y() - 35
if current_chapter != 1: if current_chapter != 1:
painter.drawPixmap(x_draw, y_draw, read_icon) painter.drawPixmap(x_draw, y_draw, read_icon)
class BookmarkDelegate(QtWidgets.QStyledItemDelegate):
def __init__(self, parent=None):
super(BookmarkDelegate, self).__init__(parent)
self.parent = parent
def sizeHint(self, *args):
dockwidget_width = self.parent.width()
return QtCore.QSize(dockwidget_width, 50)
def paint(self, painter, option, index):
# TODO
# Alignment of the painted item
option = option.__class__(option)
chapter_index = index.data(QtCore.Qt.UserRole)
chapter_name = self.parent.window().bookToolBar.tocBox.itemText(chapter_index - 1)
painter.save()
painter.translate(0, -10)
QtWidgets.QStyledItemDelegate.paint(self, painter, option, index)
painter.restore()
painter.drawText(
option.rect,
QtCore.Qt.AlignBottom|QtCore.Qt.AlignLeft|QtCore.Qt.TextWordWrap,
' ' + chapter_name)