Add a right click menu to the cover browser. It allows you to view a book, edit metadata etc. from withing the cover browser. The menu can be customized in Preferences->Toolbars

This commit is contained in:
Kovid Goyal 2011-07-09 18:34:12 -06:00
parent 8fc02ccdb0
commit afc1a7e2d1
6 changed files with 49 additions and 5 deletions

View File

@ -74,6 +74,13 @@ gprefs.defaults['action-layout-context-menu-device'] = (
'Add To Library', 'Edit Collections', 'Add To Library', 'Edit Collections',
) )
gprefs.defaults['action-layout-context-menu-cover-browser'] = (
'Edit Metadata', 'Send To Device', 'Save To Disk',
'Connect Share', 'Copy To Library', None,
'Convert Books', 'View', 'Open Folder', 'Show Book Details',
'Similar Books', 'Tweak ePub', None, 'Remove Books',
)
gprefs.defaults['show_splash_screen'] = True gprefs.defaults['show_splash_screen'] = True
gprefs.defaults['toolbar_icon_size'] = 'medium' gprefs.defaults['toolbar_icon_size'] = 'medium'
gprefs.defaults['automerge'] = 'ignore' gprefs.defaults['automerge'] = 'ignore'

View File

@ -9,8 +9,8 @@ Module to implement the Cover Flow feature
import sys, os, time import sys, os, time
from PyQt4.Qt import QImage, QSizePolicy, QTimer, QDialog, Qt, QSize, \ from PyQt4.Qt import (QImage, QSizePolicy, QTimer, QDialog, Qt, QSize,
QStackedLayout, QLabel, QByteArray, pyqtSignal QStackedLayout, QLabel, QByteArray, pyqtSignal)
from calibre import plugins from calibre import plugins
from calibre.gui2 import config, available_height, available_width, gprefs from calibre.gui2 import config, available_height, available_width, gprefs
@ -84,6 +84,7 @@ if pictureflow is not None:
class CoverFlow(pictureflow.PictureFlow): class CoverFlow(pictureflow.PictureFlow):
dc_signal = pyqtSignal() dc_signal = pyqtSignal()
context_menu_requested = pyqtSignal()
def __init__(self, parent=None): def __init__(self, parent=None):
pictureflow.PictureFlow.__init__(self, parent, pictureflow.PictureFlow.__init__(self, parent,
@ -94,6 +95,17 @@ if pictureflow is not None:
QSizePolicy.Expanding)) QSizePolicy.Expanding))
self.dc_signal.connect(self._data_changed, self.dc_signal.connect(self._data_changed,
type=Qt.QueuedConnection) type=Qt.QueuedConnection)
self.context_menu = None
self.setContextMenuPolicy(Qt.DefaultContextMenu)
def set_context_menu(self, cm):
self.context_menu = cm
def contextMenuEvent(self, event):
if self.context_menu is not None:
self.context_menu_requested.emit()
self.context_menu.popup(event.globalPos())
event.accept()
def sizeHint(self): def sizeHint(self):
return self.minimumSize() return self.minimumSize()
@ -149,6 +161,7 @@ class CoverFlowMixin(object):
self.cover_flow_sync_flag = True self.cover_flow_sync_flag = True
self.cover_flow = CoverFlow(parent=self) self.cover_flow = CoverFlow(parent=self)
self.cover_flow.currentChanged.connect(self.sync_listview_to_cf) self.cover_flow.currentChanged.connect(self.sync_listview_to_cf)
self.cover_flow.context_menu_requested.connect(self.cf_context_menu_requested)
self.library_view.selectionModel().currentRowChanged.connect( self.library_view.selectionModel().currentRowChanged.connect(
self.sync_cf_to_listview) self.sync_cf_to_listview)
self.db_images = DatabaseImages(self.library_view.model()) self.db_images = DatabaseImages(self.library_view.model())
@ -234,6 +247,14 @@ class CoverFlowMixin(object):
self.cover_flow.setCurrentSlide(current.row()) self.cover_flow.setCurrentSlide(current.row())
self.cover_flow_sync_flag = True self.cover_flow_sync_flag = True
def cf_context_menu_requested(self):
row = self.cover_flow.currentSlide()
m = self.library_view.model()
index = m.index(row, 0)
sm = self.library_view.selectionModel()
sm.select(index, sm.ClearAndSelect|sm.Rows)
self.library_view.setCurrentIndex(index)
def cover_flow_do_sync(self): def cover_flow_do_sync(self):
self.cover_flow_sync_flag = True self.cover_flow_sync_flag = True
try: try:

View File

@ -62,7 +62,6 @@ class LibraryViewMixin(object): # {{{
view = getattr(self, view+'_view') view = getattr(self, view+'_view')
view.verticalHeader().sectionDoubleClicked.connect(self.iactions['View'].view_specific_book) view.verticalHeader().sectionDoubleClicked.connect(self.iactions['View'].view_specific_book)
self.build_context_menus()
self.library_view.model().set_highlight_only(config['highlight_search_matches']) self.library_view.model().set_highlight_only(config['highlight_search_matches'])
def build_context_menus(self): def build_context_menus(self):
@ -81,6 +80,11 @@ class LibraryViewMixin(object): # {{{
for v in (self.memory_view, self.card_a_view, self.card_b_view): for v in (self.memory_view, self.card_a_view, self.card_b_view):
v.set_context_menu(dm, ec) v.set_context_menu(dm, ec)
if self.cover_flow is not None:
cm = QMenu(self.cover_flow)
populate_menu(cm,
gprefs['action-layout-context-menu-cover-browser'])
self.cover_flow.set_context_menu(cm)
def search_done(self, view, ok): def search_done(self, view, ok):
if view is self.current_view(): if view is self.current_view():

View File

@ -1332,6 +1332,7 @@ void PictureFlow::mousePressEvent(QMouseEvent* event)
void PictureFlow::mouseReleaseEvent(QMouseEvent* event) void PictureFlow::mouseReleaseEvent(QMouseEvent* event)
{ {
bool accepted = false;
int sideWidth = (d->buffer.width() - slideSize().width()) /2; int sideWidth = (d->buffer.width() - slideSize().width()) /2;
if (d->singlePress) if (d->singlePress)
@ -1339,14 +1340,21 @@ void PictureFlow::mouseReleaseEvent(QMouseEvent* event)
if (event->x() < sideWidth ) if (event->x() < sideWidth )
{ {
showPrevious(); showPrevious();
accepted = true;
} else if ( event->x() > sideWidth + slideSize().width() ) { } else if ( event->x() > sideWidth + slideSize().width() ) {
showNext(); showNext();
accepted = true;
} else { } else {
if (event->button() == Qt::LeftButton) {
emit itemActivated(d->getTarget()); emit itemActivated(d->getTarget());
accepted = true;
}
} }
if (accepted) {
event->accept(); event->accept();
} }
}
emit inputReceived(); emit inputReceived();
} }

View File

@ -225,6 +225,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
'calibre library')), 'calibre library')),
('context-menu-device', _('The context menu for the books on ' ('context-menu-device', _('The context menu for the books on '
'the device')), 'the device')),
('context-menu-cover-browser', _('The context menu for the cover '
'browser')),
] ]
def genesis(self, gui): def genesis(self, gui):

View File

@ -308,6 +308,8 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
self.height()) self.height())
self.resize(self.width(), self._calculated_available_height) self.resize(self.width(), self._calculated_available_height)
self.build_context_menus()
for ac in self.iactions.values(): for ac in self.iactions.values():
try: try:
ac.gui_layout_complete() ac.gui_layout_complete()