Edit metadata dialog: Allow right clicking on buttons with popup menus to popup the menu

This commit is contained in:
Kovid Goyal 2014-11-02 09:30:00 +05:30
parent d34a7b63c7
commit 1fd7e6ae55
2 changed files with 13 additions and 5 deletions

View File

@ -180,6 +180,14 @@ def make_undoable(spinbox):
return UndoableSpinbox
class RightClickButton(QToolButton):
def mousePressEvent(self, ev):
if ev.button() == Qt.RightButton and self.menu() is not None:
self.showMenu()
ev.accept()
return
return QToolButton.mousePressEvent(self, ev)
# Title {{{
class TitleEdit(EnLineEdit, ToMetadataMixin):
@ -1014,10 +1022,10 @@ class Cover(ImageView): # {{{
self.cdata_before_trim = None
self.cover_changed.connect(self.set_pixmap_from_data)
class CB(QToolButton):
class CB(RightClickButton):
def __init__(self, text, icon=None, action=None):
QToolButton.__init__(self, parent)
RightClickButton.__init__(self, parent)
self.setText(text)
if icon is not None:
self.setIcon(QIcon(I(icon)))
@ -1044,7 +1052,7 @@ class Cover(ImageView): # {{{
self.generate_cover_button = b = CB(_('&Generate cover'), 'default_cover.png', self.generate_cover)
b.m = m = QMenu()
b.setMenu(m)
m.addAction(_('Customize the styles and colors of the generated cover'), self.custom_cover)
m.addAction(QIcon(I('config.png')), _('Customize the styles and colors of the generated cover'), self.custom_cover)
b.setPopupMode(b.DelayedPopup)
self.buttons = [self.select_cover_button, self.remove_cover_button,
self.trim_cover_button, self.download_cover_button,

View File

@ -21,7 +21,7 @@ from calibre.gui2 import ResizableDialog, error_dialog, gprefs, pixmap_to_data
from calibre.gui2.metadata.basic_widgets import (TitleEdit, AuthorsEdit,
AuthorSortEdit, TitleSortEdit, SeriesEdit, SeriesIndexEdit, IdentifiersEdit,
RatingEdit, PublisherEdit, TagsEdit, FormatsManager, Cover, CommentsEdit,
BuddyLabel, DateEdit, PubdateEdit, LanguagesEdit)
BuddyLabel, DateEdit, PubdateEdit, LanguagesEdit, RightClickButton)
from calibre.gui2.metadata.single_download import FullFetch
from calibre.gui2.custom_column_widgets import populate_metadata_page
from calibre.utils.config import tweaks
@ -237,7 +237,7 @@ class MetadataSingleDialogBase(ResizableDialog):
self.pubdate = PubdateEdit(self)
self.basic_metadata_widgets.extend([self.timestamp, self.pubdate])
self.fetch_metadata_button = b = QToolButton(self)
self.fetch_metadata_button = b = RightClickButton(self)
b.setText(_('&Download metadata')), b.setPopupMode(b.DelayedPopup)
b.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed))
self.fetch_metadata_button.clicked.connect(self.fetch_metadata)