From 0ae22558a229492801f0bd1c93141d2c7367c7de Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 11 May 2013 12:00:30 +0200
Subject: [PATCH 01/10] Add highlighting the header of the column containing
the current cell
---
resources/default_tweaks.py | 6 ++++++
src/calibre/gui2/library/models.py | 10 ++++++++++
src/calibre/gui2/library/views.py | 4 ++++
3 files changed, 20 insertions(+)
diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py
index 9d7974a59c..eac9e33d06 100644
--- a/resources/default_tweaks.py
+++ b/resources/default_tweaks.py
@@ -537,3 +537,9 @@ many_libraries = 10
# that off.
highlight_virtual_library_book_count = True
+#: Color for the current column highlight in the library view
+# This color is used to highlight the column header of the column containing the
+# currently-selected cell. It must be an valid color name. See
+# http://webdesign.about.com/od/colorcharts/l/bl_namedcolors.htm
+# for a list of valid color names
+column_highlight_color = 'lightgrey'
diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py
index d252af6395..c16f0022d4 100644
--- a/src/calibre/gui2/library/models.py
+++ b/src/calibre/gui2/library/models.py
@@ -164,6 +164,8 @@ class BooksModel(QAbstractTableModel): # {{{
self.ids_to_highlight_set = set()
self.current_highlighted_idx = None
self.highlight_only = False
+ self.current_index_column = -1
+ self.column_highlight_color = QVariant(QColor(tweaks['column_highlight_color']))
self.read_config()
def _clear_caches(self):
@@ -889,6 +891,12 @@ class BooksModel(QAbstractTableModel): # {{{
# return QVariant(_("Double click to edit me
"))
return NONE
+ def set_current_cell(self, idx):
+ if idx and idx.isValid():
+ self.current_index_column = idx.column()
+ else:
+ self.current_index_column = -1
+
def headerData(self, section, orientation, role):
if orientation == Qt.Horizontal:
if section >= len(self.column_map): # same problem as in data, the column_map can be wrong
@@ -900,6 +908,8 @@ class BooksModel(QAbstractTableModel): # {{{
return QVariant(_('The lookup/search name is "{0}"').format(ht))
if role == Qt.DisplayRole:
return QVariant(self.headers[self.column_map[section]])
+ if role == Qt.BackgroundRole and section == self.current_index_column:
+ return self.column_highlight_color
return NONE
if DEBUG and role == Qt.ToolTipRole and orientation == Qt.Vertical:
col = self.db.field_metadata['uuid']['rec_index']
diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py
index 928d6d6107..9dbf4df1bd 100644
--- a/src/calibre/gui2/library/views.py
+++ b/src/calibre/gui2/library/views.py
@@ -169,6 +169,10 @@ class BooksView(QTableView): # {{{
self._model.sorting_done.connect(self.sorting_done,
type=Qt.QueuedConnection)
+ def currentChanged(self, current, previous):
+ self.model().set_current_cell(current)
+ QTableView.currentChanged(self, current, previous)
+
# Column Header Context Menu {{{
def column_header_context_handler(self, action=None, column=None):
if not action or not column:
From 3f98133107990f983e5d31b325edbaccc8ee439d Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 11 May 2013 12:52:36 +0200
Subject: [PATCH 02/10] Change the name of the column highlight tweak to make
it more representative
---
resources/default_tweaks.py | 3 ++-
src/calibre/gui2/library/models.py | 5 +++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py
index 868da1ebf5..f1b36d3cf8 100644
--- a/resources/default_tweaks.py
+++ b/resources/default_tweaks.py
@@ -542,4 +542,5 @@ highlight_virtual_library_book_count = True
# currently-selected cell. It must be an valid color name. See
# http://webdesign.about.com/od/colorcharts/l/bl_namedcolors.htm
# for a list of valid color names
-column_highlight_color = 'lightgrey'
+column_header_highlight_color = 'lightgrey'
+
diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py
index c16f0022d4..20491f583d 100644
--- a/src/calibre/gui2/library/models.py
+++ b/src/calibre/gui2/library/models.py
@@ -165,7 +165,8 @@ class BooksModel(QAbstractTableModel): # {{{
self.current_highlighted_idx = None
self.highlight_only = False
self.current_index_column = -1
- self.column_highlight_color = QVariant(QColor(tweaks['column_highlight_color']))
+ self.column_header_highlight_color = \
+ QVariant(QColor(tweaks['column_header_highlight_color']))
self.read_config()
def _clear_caches(self):
@@ -909,7 +910,7 @@ class BooksModel(QAbstractTableModel): # {{{
if role == Qt.DisplayRole:
return QVariant(self.headers[self.column_map[section]])
if role == Qt.BackgroundRole and section == self.current_index_column:
- return self.column_highlight_color
+ return self.column_header_highlight_color
return NONE
if DEBUG and role == Qt.ToolTipRole and orientation == Qt.Vertical:
col = self.db.field_metadata['uuid']['rec_index']
From 2f45ed19c33c6cfcd51498cf5cea630ddd04261d Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 11 May 2013 12:53:10 +0200
Subject: [PATCH 03/10] Add a tweak that permits setting a style sheet for the
selected cell.
---
resources/default_tweaks.py | 19 +++++++++++++++++++
src/calibre/gui2/library/views.py | 3 +++
2 files changed, 22 insertions(+)
diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py
index f1b36d3cf8..90fc1d8e2f 100644
--- a/resources/default_tweaks.py
+++ b/resources/default_tweaks.py
@@ -544,3 +544,22 @@ highlight_virtual_library_book_count = True
# for a list of valid color names
column_header_highlight_color = 'lightgrey'
+#: Control how the currently selected cell is marked.
+# You can control how the currently selected cell is marked using something
+# very similar to a CSS style sheet.
+# This is a very experimental feature. There may be problems using this on some
+# platforms or with some setting values. Some system defaults cannot be
+# overridded. See
+# http://qt-project.org/doc/qt-4.8/stylesheet-reference.html#list-of-properties
+# for a list of the CSS properties that are (in theory) supported.
+# Example: on windows 7 the following style sheet results in a cell with the
+# default background color, black text, and a black border around the cell.
+# selected_cell_highlight_css = ('QTableView::item:focus { '
+# 'background:transparent; '
+# 'color:black; '
+# 'border: 1px; '
+# 'border-style: solid; '
+# 'border-color: black; '
+# '}')
+# Default (no style): cell_highlight_css = ''
+selected_cell_highlight_css = ''
diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py
index 9dbf4df1bd..6c856a48b9 100644
--- a/src/calibre/gui2/library/views.py
+++ b/src/calibre/gui2/library/views.py
@@ -169,6 +169,9 @@ class BooksView(QTableView): # {{{
self._model.sorting_done.connect(self.sorting_done,
type=Qt.QueuedConnection)
+ if tweaks['selected_cell_highlight_css']:
+ self.setStyleSheet(tweaks['selected_cell_highlight_css'])
+
def currentChanged(self, current, previous):
self.model().set_current_cell(current)
QTableView.currentChanged(self, current, previous)
From df9f089c12a5c6df676329d0854c1084bf8b5636 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 11 May 2013 18:18:42 +0200
Subject: [PATCH 04/10] Performance improvement in quickview when switching
books
---
src/calibre/gui2/dialogs/quickview.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/calibre/gui2/dialogs/quickview.py b/src/calibre/gui2/dialogs/quickview.py
index 597edae057..7b3719a49a 100644
--- a/src/calibre/gui2/dialogs/quickview.py
+++ b/src/calibre/gui2/dialogs/quickview.py
@@ -149,6 +149,9 @@ class Quickview(QDialog, Ui_Quickview):
key = self.view.model().column_map[self.current_column]
book_id = self.view.model().id(bv_row)
+ if self.current_book_id == book_id and self.current_key == key:
+ return
+
# Only show items for categories
if not self.db.field_metadata[key]['is_category']:
if self.current_key is None:
@@ -203,8 +206,7 @@ class Quickview(QDialog, Ui_Quickview):
sv = selected_item
sv = sv.replace('"', r'\"')
self.last_search = self.current_key+':"=' + sv + '"'
- books = self.db.search_getting_ids(self.last_search,
- self.db.data.search_restriction)
+ books = self.db.search(self.last_search, return_matches=True)
self.books_table.setRowCount(len(books))
self.books_label.setText(_('Books with selected item "{0}": {1}').
From 6b227f9a49419a464d04b9fd58f1d9ee0d07b317 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 11 May 2013 18:20:08 +0200
Subject: [PATCH 05/10] Use bold italic font in headers to indicate current
selected cell
---
resources/default_tweaks.py | 7 -------
src/calibre/gui2/library/models.py | 18 +++++++++++++-----
2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py
index 90fc1d8e2f..b424e67cbb 100644
--- a/resources/default_tweaks.py
+++ b/resources/default_tweaks.py
@@ -537,13 +537,6 @@ many_libraries = 10
# that off.
highlight_virtual_library_book_count = True
-#: Color for the current column highlight in the library view
-# This color is used to highlight the column header of the column containing the
-# currently-selected cell. It must be an valid color name. See
-# http://webdesign.about.com/od/colorcharts/l/bl_namedcolors.htm
-# for a list of valid color names
-column_header_highlight_color = 'lightgrey'
-
#: Control how the currently selected cell is marked.
# You can control how the currently selected cell is marked using something
# very similar to a CSS style sheet.
diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py
index 20491f583d..efae25d95b 100644
--- a/src/calibre/gui2/library/models.py
+++ b/src/calibre/gui2/library/models.py
@@ -9,7 +9,7 @@ import functools, re, os, traceback, errno, time
from collections import defaultdict
from PyQt4.Qt import (QAbstractTableModel, Qt, pyqtSignal, QIcon, QImage,
- QModelIndex, QVariant, QDateTime, QColor, QPixmap)
+ QModelIndex, QVariant, QDateTime, QColor, QPixmap, QFont)
from calibre.gui2 import NONE, UNDEFINED_QDATETIME, error_dialog
from calibre.utils.search_query_parser import ParseException
@@ -165,8 +165,11 @@ class BooksModel(QAbstractTableModel): # {{{
self.current_highlighted_idx = None
self.highlight_only = False
self.current_index_column = -1
- self.column_header_highlight_color = \
- QVariant(QColor(tweaks['column_header_highlight_color']))
+ self.current_index_row = -1
+ self.selected_header_font = QFont()
+ self.selected_header_font.setBold(True)
+ self.selected_header_font.setItalic(True)
+
self.read_config()
def _clear_caches(self):
@@ -894,9 +897,12 @@ class BooksModel(QAbstractTableModel): # {{{
def set_current_cell(self, idx):
if idx and idx.isValid():
+ # Copy these out here for performance, avoiding using idx in headerData
self.current_index_column = idx.column()
+ self.current_index_row = idx.row()
else:
self.current_index_column = -1
+ self.current_index_row = -1
def headerData(self, section, orientation, role):
if orientation == Qt.Horizontal:
@@ -909,8 +915,8 @@ class BooksModel(QAbstractTableModel): # {{{
return QVariant(_('The lookup/search name is "{0}"').format(ht))
if role == Qt.DisplayRole:
return QVariant(self.headers[self.column_map[section]])
- if role == Qt.BackgroundRole and section == self.current_index_column:
- return self.column_header_highlight_color
+ if role == Qt.FontRole and self.current_index_column == section:
+ return QVariant(self.selected_header_font)
return NONE
if DEBUG and role == Qt.ToolTipRole and orientation == Qt.Vertical:
col = self.db.field_metadata['uuid']['rec_index']
@@ -918,6 +924,8 @@ class BooksModel(QAbstractTableModel): # {{{
if role == Qt.DisplayRole: # orientation is vertical
return QVariant(section+1)
+ if role == Qt.FontRole and self.current_index_row == section:
+ return QVariant(self.selected_header_font)
return NONE
From 2e6f424e0a37eee238bd9f603d9c81deeed55e82 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 11 May 2013 18:29:52 +0200
Subject: [PATCH 06/10] Remove header changes from model
---
src/calibre/gui2/library/models.py | 21 +--------------------
1 file changed, 1 insertion(+), 20 deletions(-)
diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py
index efae25d95b..d252af6395 100644
--- a/src/calibre/gui2/library/models.py
+++ b/src/calibre/gui2/library/models.py
@@ -9,7 +9,7 @@ import functools, re, os, traceback, errno, time
from collections import defaultdict
from PyQt4.Qt import (QAbstractTableModel, Qt, pyqtSignal, QIcon, QImage,
- QModelIndex, QVariant, QDateTime, QColor, QPixmap, QFont)
+ QModelIndex, QVariant, QDateTime, QColor, QPixmap)
from calibre.gui2 import NONE, UNDEFINED_QDATETIME, error_dialog
from calibre.utils.search_query_parser import ParseException
@@ -164,12 +164,6 @@ class BooksModel(QAbstractTableModel): # {{{
self.ids_to_highlight_set = set()
self.current_highlighted_idx = None
self.highlight_only = False
- self.current_index_column = -1
- self.current_index_row = -1
- self.selected_header_font = QFont()
- self.selected_header_font.setBold(True)
- self.selected_header_font.setItalic(True)
-
self.read_config()
def _clear_caches(self):
@@ -895,15 +889,6 @@ class BooksModel(QAbstractTableModel): # {{{
# return QVariant(_("Double click to edit me
"))
return NONE
- def set_current_cell(self, idx):
- if idx and idx.isValid():
- # Copy these out here for performance, avoiding using idx in headerData
- self.current_index_column = idx.column()
- self.current_index_row = idx.row()
- else:
- self.current_index_column = -1
- self.current_index_row = -1
-
def headerData(self, section, orientation, role):
if orientation == Qt.Horizontal:
if section >= len(self.column_map): # same problem as in data, the column_map can be wrong
@@ -915,8 +900,6 @@ class BooksModel(QAbstractTableModel): # {{{
return QVariant(_('The lookup/search name is "{0}"').format(ht))
if role == Qt.DisplayRole:
return QVariant(self.headers[self.column_map[section]])
- if role == Qt.FontRole and self.current_index_column == section:
- return QVariant(self.selected_header_font)
return NONE
if DEBUG and role == Qt.ToolTipRole and orientation == Qt.Vertical:
col = self.db.field_metadata['uuid']['rec_index']
@@ -924,8 +907,6 @@ class BooksModel(QAbstractTableModel): # {{{
if role == Qt.DisplayRole: # orientation is vertical
return QVariant(section+1)
- if role == Qt.FontRole and self.current_index_row == section:
- return QVariant(self.selected_header_font)
return NONE
From 9fbdff152e4e51667bfb5c7d8edbf6b3e3d21c1e Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 11 May 2013 18:31:02 +0200
Subject: [PATCH 07/10] Remove calls to model when selected text changes
---
src/calibre/gui2/library/views.py | 4 ----
1 file changed, 4 deletions(-)
diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py
index 1cb095adf0..97e4d56ad2 100644
--- a/src/calibre/gui2/library/views.py
+++ b/src/calibre/gui2/library/views.py
@@ -224,10 +224,6 @@ class BooksView(QTableView): # {{{
if tweaks['selected_cell_highlight_css']:
self.setStyleSheet(tweaks['selected_cell_highlight_css'])
- def currentChanged(self, current, previous):
- self.model().set_current_cell(current)
- QTableView.currentChanged(self, current, previous)
-
# Column Header Context Menu {{{
def column_header_context_handler(self, action=None, column=None):
if not action or not column:
From cf8a7905ba5def2124ef13ae554f882d336695e0 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 11 May 2013 18:33:14 +0200
Subject: [PATCH 08/10] Add italic to the bolded header cell
---
src/calibre/gui2/library/views.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py
index 97e4d56ad2..151fcbafb2 100644
--- a/src/calibre/gui2/library/views.py
+++ b/src/calibre/gui2/library/views.py
@@ -32,6 +32,7 @@ class HeaderView(QHeaderView): # {{{
self.hover = -1
self.current_font = QFont(self.font())
self.current_font.setBold(True)
+ self.current_font.setItalic(True)
def event(self, e):
if e.type() in (e.HoverMove, e.HoverEnter):
From ff9334080f3705f5fa6413682c828445a5e48257 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 11 May 2013 18:47:20 +0200
Subject: [PATCH 09/10] Remove cell highlighting tweak
---
resources/default_tweaks.py | 21 +--------------------
src/calibre/gui2/library/views.py | 3 ---
2 files changed, 1 insertion(+), 23 deletions(-)
diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py
index b424e67cbb..9d7974a59c 100644
--- a/resources/default_tweaks.py
+++ b/resources/default_tweaks.py
@@ -32,7 +32,7 @@ defaults.
# Set the use_series_auto_increment_tweak_when_importing tweak to True to
# use the above values when importing/adding books. If this tweak is set to
# False (the default) then the series number will be set to 1 if it is not
-# explicitly set during the import. If set to True, then the
+# explicitly set to during the import. If set to True, then the
# series index will be set according to the series_index_auto_increment setting.
# Note that the use_series_auto_increment_tweak_when_importing tweak is used
# only when a value is not provided during import. If the importing regular
@@ -537,22 +537,3 @@ many_libraries = 10
# that off.
highlight_virtual_library_book_count = True
-#: Control how the currently selected cell is marked.
-# You can control how the currently selected cell is marked using something
-# very similar to a CSS style sheet.
-# This is a very experimental feature. There may be problems using this on some
-# platforms or with some setting values. Some system defaults cannot be
-# overridded. See
-# http://qt-project.org/doc/qt-4.8/stylesheet-reference.html#list-of-properties
-# for a list of the CSS properties that are (in theory) supported.
-# Example: on windows 7 the following style sheet results in a cell with the
-# default background color, black text, and a black border around the cell.
-# selected_cell_highlight_css = ('QTableView::item:focus { '
-# 'background:transparent; '
-# 'color:black; '
-# 'border: 1px; '
-# 'border-style: solid; '
-# 'border-color: black; '
-# '}')
-# Default (no style): cell_highlight_css = ''
-selected_cell_highlight_css = ''
diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py
index 151fcbafb2..e6a816621f 100644
--- a/src/calibre/gui2/library/views.py
+++ b/src/calibre/gui2/library/views.py
@@ -222,9 +222,6 @@ class BooksView(QTableView): # {{{
self._model.sorting_done.connect(self.sorting_done,
type=Qt.QueuedConnection)
- if tweaks['selected_cell_highlight_css']:
- self.setStyleSheet(tweaks['selected_cell_highlight_css'])
-
# Column Header Context Menu {{{
def column_header_context_handler(self, action=None, column=None):
if not action or not column:
From ae71204c7cfca5af0f086f264aa2c1182d3d67e0 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 11 May 2013 18:50:42 +0200
Subject: [PATCH 10/10] Fully revert default_tweaks
---
resources/default_tweaks.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py
index 9d7974a59c..e14366af21 100644
--- a/resources/default_tweaks.py
+++ b/resources/default_tweaks.py
@@ -32,7 +32,7 @@ defaults.
# Set the use_series_auto_increment_tweak_when_importing tweak to True to
# use the above values when importing/adding books. If this tweak is set to
# False (the default) then the series number will be set to 1 if it is not
-# explicitly set to during the import. If set to True, then the
+# explicitly set during the import. If set to True, then the
# series index will be set according to the series_index_auto_increment setting.
# Note that the use_series_auto_increment_tweak_when_importing tweak is used
# only when a value is not provided during import. If the importing regular