Context menus for all views

This commit is contained in:
BasioMeusPuga
2018-03-02 20:08:39 +05:30
parent c2850a9c77
commit ca2f3469d1
3 changed files with 58 additions and 1 deletions

View File

@@ -219,6 +219,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.listView.verticalScrollBar().setSingleStep(9) self.listView.verticalScrollBar().setSingleStep(9)
self.listView.doubleClicked.connect(self.library_doubleclick) self.listView.doubleClicked.connect(self.library_doubleclick)
self.listView.setItemDelegate(LibraryDelegate(self.temp_dir.path(), self)) self.listView.setItemDelegate(LibraryDelegate(self.temp_dir.path(), self))
self.listView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.listView.customContextMenuRequested.connect(self.generate_library_context_menu)
self.listView.verticalScrollBar().valueChanged.connect(self.start_culling_timer) self.listView.verticalScrollBar().valueChanged.connect(self.start_culling_timer)
self.listView.setStyleSheet( self.listView.setStyleSheet(
@@ -240,6 +242,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.tableView.horizontalHeader().setStretchLastSection(True) self.tableView.horizontalHeader().setStretchLastSection(True)
self.tableView.horizontalHeader().sectionClicked.connect( self.tableView.horizontalHeader().sectionClicked.connect(
self.lib_ref.table_proxy_model.sort_table_columns) self.lib_ref.table_proxy_model.sort_table_columns)
self.tableView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.tableView.customContextMenuRequested.connect(self.generate_library_context_menu)
# Keyboard shortcuts # Keyboard shortcuts
self.ks_close_tab = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+W'), self) self.ks_close_tab = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+W'), self)
@@ -257,6 +261,30 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
if self.settings['scan_library']: if self.settings['scan_library']:
self.settings_dialog.start_library_scan() self.settings_dialog.start_library_scan()
def generate_library_context_menu(self, position):
# TODO
# The library might have multiple items selected
# Make sure the context menu actions are carried out on each
index = self.sender().indexAt(position)
if not index.isValid():
return
context_menu = QtWidgets.QMenu()
openAction = context_menu.addAction(
QtGui.QIcon.fromTheme('view-readermode'), 'Start reading')
editAction = context_menu.addAction(
QtGui.QIcon.fromTheme('edit-rename'), 'Edit')
deleteAction = context_menu.addAction(
QtGui.QIcon.fromTheme('trash-empty'), 'Delete')
readAction = context_menu.addAction(
QtGui.QIcon.fromTheme('vcs-normal'), 'Mark read')
unreadAction = context_menu.addAction(
QtGui.QIcon.fromTheme('emblem-unavailable'), 'Mark unread')
action = context_menu.exec_(self.sender().mapToGlobal(position))
def open_books_at_startup(self): def open_books_at_startup(self):
# Last open books and command line books aren't being opened together # Last open books and command line books aren't being opened together
# so that command line books are processed last and therefore retain focus # so that command line books are processed last and therefore retain focus

View File

@@ -19,7 +19,7 @@
import os import os
import pickle import pickle
import pathlib import pathlib
from PyQt5 import QtGui, QtCore from PyQt5 import QtGui, QtCore, QtWidgets
import database import database
from models import TableProxyModel, ItemProxyModel from models import TableProxyModel, ItemProxyModel

View File

@@ -106,6 +106,9 @@ class Tab(QtWidgets.QWidget):
self.dockListView.setMaximumWidth(350) self.dockListView.setMaximumWidth(350)
self.dockListView.setItemDelegate(BookmarkDelegate(self.dockListView)) self.dockListView.setItemDelegate(BookmarkDelegate(self.dockListView))
self.dockListView.setUniformItemSizes(True) self.dockListView.setUniformItemSizes(True)
self.dockListView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.dockListView.customContextMenuRequested.connect(
self.generate_bookmark_context_menu)
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)
@@ -299,6 +302,9 @@ class Tab(QtWidgets.QWidget):
self.dockWidget.show() self.dockWidget.show()
def add_bookmark(self): def add_bookmark(self):
# TODO
# Start dockListView.edit(index) when something new is added
identifier = uuid.uuid4().hex[:10] identifier = uuid.uuid4().hex[:10]
description = 'New bookmark' description = 'New bookmark'
@@ -366,6 +372,29 @@ class Tab(QtWidgets.QWidget):
self.proxy_model.setFilterFixedString( self.proxy_model.setFilterFixedString(
self.window().bookToolBar.searchBar.text()) self.window().bookToolBar.searchBar.text())
def generate_bookmark_context_menu(self, position):
index = self.dockListView.indexAt(position)
if not index.isValid():
return
bookmark_menu = QtWidgets.QMenu()
editAction = bookmark_menu.addAction(
QtGui.QIcon.fromTheme('edit-rename'), 'Edit')
deleteAction = bookmark_menu.addAction(
QtGui.QIcon.fromTheme('trash-empty'), 'Delete')
action = bookmark_menu.exec_(self.dockListView.mapToGlobal(position))
if action == editAction:
self.dockListView.edit(index)
if action == deleteAction:
row = index.row()
delete_uuid = self.bookmark_model.item(row).data(QtCore.Qt.UserRole + 2)
self.metadata['bookmarks'].pop(delete_uuid)
self.bookmark_model.removeRow(index.row())
def hide_mouse(self): def hide_mouse(self):
self.contentView.setCursor(QtCore.Qt.BlankCursor) self.contentView.setCursor(QtCore.Qt.BlankCursor)