From 0c77d88404180a4ce87ac4cac9ed51b1d2bde6f1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 12 Nov 2021 20:24:40 +0530 Subject: [PATCH] Allow the formats list to use less height Also remove some wasted margins in various sub layouts --- src/calibre/gui2/metadata/basic_widgets.py | 17 +++++++++++------ src/calibre/gui2/metadata/single.py | 6 +++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/calibre/gui2/metadata/basic_widgets.py b/src/calibre/gui2/metadata/basic_widgets.py index ee63e86a9b8a..d81c0bbbb8cc 100644 --- a/src/calibre/gui2/metadata/basic_widgets.py +++ b/src/calibre/gui2/metadata/basic_widgets.py @@ -811,6 +811,10 @@ def __init__(self, parent): _FormatList.__init__(self, parent) self.setContextMenuPolicy(Qt.ContextMenuPolicy.DefaultContextMenu) + def sizeHint(self): + sz = self.iconSize() + return QSize(sz.width() * 7, sz.height() * 3) + def contextMenuEvent(self, event): item = self.itemFromIndex(self.currentIndex()) originals = [self.item(x).ext.upper() for x in range(self.count())] @@ -850,6 +854,7 @@ def remove_format(self, fmt): class FormatsManager(QWidget): data_changed = pyqtSignal() + ICON_SIZE = 32 @property def changed(self): @@ -868,29 +873,30 @@ def __init__(self, parent, copy_fmt): self._changed = False self.l = l = QGridLayout() + l.setContentsMargins(0, 0, 0, 0) self.setLayout(l) self.cover_from_format_button = QToolButton(self) self.cover_from_format_button.setToolTip( _('Set the cover for the book from the selected format')) self.cover_from_format_button.setIcon(QIcon(I('default_cover.png'))) - self.cover_from_format_button.setIconSize(QSize(32, 32)) + self.cover_from_format_button.setIconSize(QSize(self.ICON_SIZE, self.ICON_SIZE)) self.metadata_from_format_button = QToolButton(self) self.metadata_from_format_button.setIcon(QIcon(I('edit_input.png'))) - self.metadata_from_format_button.setIconSize(QSize(32, 32)) + self.metadata_from_format_button.setIconSize(QSize(self.ICON_SIZE, self.ICON_SIZE)) self.metadata_from_format_button.setToolTip( _('Set metadata for the book from the selected format')) self.add_format_button = QToolButton(self) self.add_format_button.setIcon(QIcon(I('add_book.png'))) - self.add_format_button.setIconSize(QSize(32, 32)) + self.add_format_button.setIconSize(QSize(self.ICON_SIZE, self.ICON_SIZE)) self.add_format_button.clicked.connect(self.add_format) self.add_format_button.setToolTip( _('Add a format to this book')) self.remove_format_button = QToolButton(self) self.remove_format_button.setIcon(QIcon(I('trash.png'))) - self.remove_format_button.setIconSize(QSize(32, 32)) + self.remove_format_button.setIconSize(QSize(self.ICON_SIZE, self.ICON_SIZE)) self.remove_format_button.clicked.connect(self.remove_format) self.remove_format_button.setToolTip( _('Remove the selected format from this book')) @@ -904,8 +910,7 @@ def __init__(self, parent, copy_fmt): self.formats.delete_format.connect(self.remove_format) self.formats.itemDoubleClicked.connect(self.show_format) self.formats.setDragDropMode(QAbstractItemView.DragDropMode.DropOnly) - self.formats.setIconSize(QSize(32, 32)) - self.formats.setMaximumWidth(200) + self.formats.setIconSize(QSize(self.ICON_SIZE, self.ICON_SIZE)) l.addWidget(self.cover_from_format_button, 0, 0, 1, 1) l.addWidget(self.metadata_from_format_button, 2, 0, 1, 1) diff --git a/src/calibre/gui2/metadata/single.py b/src/calibre/gui2/metadata/single.py index e68c2cab534b..645972beabe4 100644 --- a/src/calibre/gui2/metadata/single.py +++ b/src/calibre/gui2/metadata/single.py @@ -1176,24 +1176,28 @@ def create_row(row, widget, tab_to, button=None, icon=None, span=1): # First the cover & buttons cover_group_box = QGroupBox(_('Cover'), tab0) cover_layout = QVBoxLayout() + cover_layout.setContentsMargins(0, 0, 0, 0) cover_group_box.setLayout(cover_layout) cover_layout.addWidget(self.cover) sto(self.manage_authors_button, self.cover.buttons[0]) # First row of cover buttons hl = QHBoxLayout() + hl.setContentsMargins(0, 0, 0, 0) for i, b in enumerate(self.cover.buttons[:3]): hl.addWidget(b) sto(b, self.cover.buttons[i+1]) cover_layout.addLayout(hl) # Second row of cover buttons hl = QHBoxLayout() + hl.setContentsMargins(0, 0, 0, 0) for b in self.cover.buttons[3:]: hl.addWidget(b) cover_layout.addLayout(hl) sto(self.cover.buttons[-2], self.cover.buttons[-1]) # Layout for both cover & formats boxes cover_and_formats = QVBoxLayout() - cover_and_formats.addWidget(cover_group_box, stretch = 10) + cover_and_formats.setContentsMargins(0, 0, 0, 0) + cover_and_formats.addWidget(cover_group_box, stretch=100) cover_and_formats.addWidget(self.formats_manager) l.addLayout(cover_and_formats, 0, 2, 2, 1) sto(self.cover.buttons[-1], self.formats_manager)