From 1fd7e6ae55aa6497080996ee8f2944cc75cbb1dc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 2 Nov 2014 09:30:00 +0530 Subject: [PATCH] Edit metadata dialog: Allow right clicking on buttons with popup menus to popup the menu --- src/calibre/gui2/metadata/basic_widgets.py | 14 +++++++++++--- src/calibre/gui2/metadata/single.py | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/metadata/basic_widgets.py b/src/calibre/gui2/metadata/basic_widgets.py index 694f71eea2..da69654f14 100644 --- a/src/calibre/gui2/metadata/basic_widgets.py +++ b/src/calibre/gui2/metadata/basic_widgets.py @@ -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, diff --git a/src/calibre/gui2/metadata/single.py b/src/calibre/gui2/metadata/single.py index ec83d1bf21..d4067ae97e 100644 --- a/src/calibre/gui2/metadata/single.py +++ b/src/calibre/gui2/metadata/single.py @@ -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)