From ffb485add6b64aef19c58e117cf322de7d4ca14c Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Mon, 3 Oct 2022 19:13:41 +0100 Subject: [PATCH 1/2] Changes to the column width dialog suggested in https://www.mobileread.com/forums/showthread.php?t=349471 - Put all the resize actions in the dialog. - Moved menu lines around to make more sense (to me) - Added some tooltips BTW: your "addRow()" worked perfectly when given a button as its only argument. :) --- src/calibre/gui2/library/views.py | 39 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 3a98487729..6293519c44 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -231,7 +231,9 @@ class AdjustColumnSize(QDialog): # {{{ l.addRow = add_row original_size = self.original_size = view.horizontalHeader().sectionSize(column) - l.addRow(_('Original size:'), QLabel(_('{0} pixels').format(str(original_size)))) + label = QLabel(_('{0} pixels').format(str(original_size))) + label.setToolTip('

' + _('The original size can be larger than the maximum if the window has been resized') + '

') + l.addRow(_('Original size:'), label) self.minimum_size = self.view.horizontalHeader().minimumSectionSize() l.addRow(_('Minimum size:'), QLabel(_('{0} pixels').format(str(self.minimum_size)))) @@ -251,12 +253,17 @@ class AdjustColumnSize(QDialog): # {{{ b = self.set_maximum_button = QPushButton(_('Set to ma&ximum')) l.addRow(self.set_minimum_button, b) + b = self.resize_to_fit_button = QPushButton(_('&Resize column to fit contents')) + b.setToolTip('

' + _('The width will be set to the size of the widest entry or the maximum size, whichever is smaller') + '

') + l.addRow(b) + sb = self.spin_box = QSpinBox() sb.setMinimum(self.view.horizontalHeader().minimumSectionSize()) sb.setMaximum(self.maximum_size) sb.setValue(original_size) sb.setSuffix(' ' + _('pixels')) - l.addRow(_('Set &to:'), sb) + sb.setToolTip(_('This box shows the current width after using the above buttons')) + l.addRow(_('Set width &to:'), sb) bb = self.button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) @@ -267,6 +274,7 @@ class AdjustColumnSize(QDialog): # {{{ self.spin_box.valueChanged.connect(self.spin_box_changed) self.set_minimum_button.clicked.connect(self.set_minimum_button_clicked) self.set_maximum_button.clicked.connect(self.set_maximum_button_clicked) + self.resize_to_fit_button.clicked.connect(self.resize_to_fit_button_clicked) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) @@ -274,6 +282,12 @@ class AdjustColumnSize(QDialog): # {{{ self.view.setColumnWidth(self.column, self.original_size) QDialog.reject(self) + def resize_to_fit_button_clicked(self): + self.view.resizeColumnToContents(self.column) + w = self.view.horizontalHeader().sectionSize(self.column) + w = w if w <= self.maximum_size else self.maximum_size + self.spin_box.setValue(w) + def set_maximum_button_clicked(self): # Do this dance in case the current width exceeds the maximum, which can # happen if the user is playing across multiple monitors @@ -531,8 +545,6 @@ class BooksView(QTableView): # {{{ def create_context_menu(self, col, name, view): ans = QMenu(view) handler = partial(self.column_header_context_handler, view=view, column=col) - if col not in ('ondevice', 'inlibrary'): - ans.addAction(QIcon.ic('minus.png'), _('Hide column %s') % name, partial(handler, action='hide')) m = ans.addMenu(_('Sort on %s') % name) m.setIcon(QIcon.ic('sort.png')) a = m.addAction(_('Ascending'), partial(handler, action='ascending')) @@ -567,6 +579,8 @@ class BooksView(QTableView): # {{{ if f is col_font: a.setCheckable(True) a.setChecked(True) + ans.addAction(QIcon.ic('split.png'), _('Adjust width of column {0}').format(name), + partial(self.manually_adjust_column_size, view, col, name)) if self.is_library_view: if self._model.db.field_metadata[col]['is_category']: @@ -583,6 +597,8 @@ class BooksView(QTableView): # {{{ if view.column_header.isSectionHidden(i) and self.column_map[i] not in ('ondevice', 'inlibrary')} ans.addSeparator() + if col not in ('ondevice', 'inlibrary'): + ans.addAction(QIcon.ic('minus.png'), _('Hide column %s') % name, partial(handler, action='hide')) if hidden_cols: m = ans.addMenu(_('Show column')) m.setIcon(QIcon.ic('plus.png')) @@ -597,12 +613,6 @@ class BooksView(QTableView): # {{{ partial(handler, action='remember_ondevice_width')) ans.addAction(_('Reset On Device column width to default'), partial(handler, action='reset_ondevice_width')) - ans.addAction(_('Shrink column if it is too wide to fit'), - partial(self.resize_column_to_fit, view, col)) - ans.addAction(_('Resize column to fit contents'), - partial(self.fit_column_to_contents, view, col)) - ans.addAction(_('Adjust width of column'), - partial(self.manually_adjust_column_size, view, col, name)) ans.addAction(_('Restore default layout'), partial(handler, action='defaults')) if self.can_add_columns: ans.addAction( @@ -1026,15 +1036,6 @@ class BooksView(QTableView): # {{{ self._model.set_row_height(self.rowHeight(0)) self.row_sizing_done = True - def resize_column_to_fit(self, view, column): - col = self.column_map.index(column) - w = view.columnWidth(col) - restrict_column_width(view, col, w, w) - - def fit_column_to_contents(self, view, column): - col = self.column_map.index(column) - view.resizeColumnToContents(col) - def manually_adjust_column_size(self, view, column, name): col = self.column_map.index(column) AdjustColumnSize(view, col, name).exec_() From 0f4a94b3f7d075d709f289003b9ec4f0a78d9d88 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Mon, 3 Oct 2022 20:58:48 +0100 Subject: [PATCH 2/2] Use an icon drawn by un_pogaz. --- imgsrc/width.svg | 1 + resources/images/width.png | Bin 0 -> 2009 bytes src/calibre/gui2/library/views.py | 2 +- 3 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 imgsrc/width.svg create mode 100644 resources/images/width.png diff --git a/imgsrc/width.svg b/imgsrc/width.svg new file mode 100644 index 0000000000..e82af93610 --- /dev/null +++ b/imgsrc/width.svg @@ -0,0 +1 @@ + diff --git a/resources/images/width.png b/resources/images/width.png new file mode 100644 index 0000000000000000000000000000000000000000..2bbda723e08aa7823dfce026e786b72798a4e06f GIT binary patch literal 2009 zcmZ{lXH?S(7RCPwoj|C8Fw$9?f<&YUArLSi5~(Jj6afLjfk8qs0TcovN+=mek!lFi zQDlsTE>WpVGisy@cp^dq27;*cb>{5ZvvYRm!+rO>d)|lp>HV@i+>S|0{v-(ifb?-^ zjMon*{~>YFAM>Sc@W2m~h;cq02LPfc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