Skip to content

Commit

Permalink
Allow the formats list to use less height
Browse files Browse the repository at this point in the history
Also remove some wasted margins in various sub layouts
  • Loading branch information
kovidgoyal committed Nov 12, 2021
1 parent 70a88ca commit 0c77d88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/calibre/gui2/metadata/basic_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())]
Expand Down Expand Up @@ -850,6 +854,7 @@ def remove_format(self, fmt):
class FormatsManager(QWidget):

data_changed = pyqtSignal()
ICON_SIZE = 32

@property
def changed(self):
Expand All @@ -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'))
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion src/calibre/gui2/metadata/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0c77d88

Please sign in to comment.