Merge from trunk

This commit is contained in:
Charles Haley 2011-05-23 09:28:15 +01:00
commit 72e65402e5
5 changed files with 106 additions and 62 deletions

View File

@ -5,7 +5,7 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from PyQt4.Qt import (SIGNAL, QLineEdit)
from PyQt4.Qt import QLineEdit
from calibre.gui2.dialogs.template_dialog import TemplateDialog
class TemplateLineEditor(QLineEdit):
@ -18,13 +18,14 @@ class TemplateLineEditor(QLineEdit):
menu = self.createStandardContextMenu()
menu.addSeparator()
action_open_editor = menu.addAction(_('Open Editor'))
action_open_editor = menu.addAction(_('Open Template Editor'))
self.connect(action_open_editor, SIGNAL('triggered()'), self.open_editor)
action_open_editor.triggered.connect(self.open_editor)
menu.exec_(event.globalPos())
def open_editor(self):
t = TemplateDialog(self, self.text())
t.setWindowTitle(_('Edit template'))
if t.exec_():
self.setText(t.textbox.toPlainText())

View File

@ -323,10 +323,12 @@ class CcCommentsDelegate(QStyledItemDelegate): # {{{
style = QApplication.style() if option.widget is None \
else option.widget.style()
self.document.setHtml(option.text)
option.text = ""
style.drawControl(QStyle.CE_ItemViewItem, option, painter);
option.text = u''
if hasattr(QStyle, 'CE_ItemViewItem'):
style.drawControl(QStyle.CE_ItemViewItem, option, painter)
ctx = QAbstractTextDocumentLayout.PaintContext()
ctx.palette = option.palette #.setColor(QPalette.Text, QColor("red"));
if hasattr(QStyle, 'SE_ItemViewItemText'):
textRect = style.subElementRect(QStyle.SE_ItemViewItemText, option)
painter.save()
painter.translate(textRect.topLeft())

View File

@ -707,7 +707,7 @@ class BooksModel(QAbstractTableModel): # {{{
return self.column_to_dc_map[col](index.row())
elif role == Qt.BackgroundRole:
if self.id(index) in self.ids_to_highlight_set:
return QColor('lightgreen')
return QVariant(QColor('lightgreen'))
elif role == Qt.ForegroundRole:
key = self.column_map[col]
if key in self.column_color_map:
@ -716,9 +716,9 @@ class BooksModel(QAbstractTableModel): # {{{
try:
color = QColor(composite_formatter.safe_format(fmt, mi, '', mi))
if color.isValid():
return color
return QVariant(color)
except:
return None
return NONE
elif self.is_custom_column(key) and \
self.custom_columns[key]['datatype'] == 'enumeration':
cc = self.custom_columns[self.column_map[col]]['display']
@ -729,10 +729,10 @@ class BooksModel(QAbstractTableModel): # {{{
try:
color = QColor(colors[values.index(txt)])
if color.isValid():
return color
return QVariant(color)
except:
pass
return None
return NONE
elif role == Qt.DecorationRole:
if self.column_to_dc_decorator_map[col] is not None:
return self.column_to_dc_decorator_map[index.column()](index.row())

View File

@ -160,9 +160,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.df_down_button.clicked.connect(self.move_df_down)
self.color_help_text.setText('<p>' +
_('Here you can specify coloring rules for fields shown in the '
'library view. Choose the field you wish to color, then '
'supply a template that specifies the color to use.') +
_('Here you can specify coloring rules for columns shown in the '
'library view. Choose the column you wish to color, then '
'supply a template that specifies the color to use based on '
'the values in the column. There is a '
'<a href="http://calibre-ebook.com/user_manual/template_lang.html">'
'tutorial</a> on using templates.') +
'</p><p>' +
_('The template must evaluate to one of the color names shown '
'below. You can use any legal template expression. '
@ -187,8 +190,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
'</p><p>' +
_('You can access a multi-line template editor from the '
'context menu (right-click).') + '</p><p>' +
_('Note: if you want to color a "custom column with a fixed set '
'of values", it is possible and often easier to specify the '
_('<b>Note:</b> if you want to color a "custom column with a fixed set '
'of values", it is often easier to specify the '
'colors in the column definition dialog. There you can '
'provide a color for each value without using a template.')+ '</p>')
choices = db.field_metadata.displayable_field_keys()

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>717</width>
<height>390</height>
<height>519</height>
</rect>
</property>
<property name="windowTitle">
@ -417,86 +417,124 @@ then the tags will be displayed each on their own line.</string>
</attribute>
<layout class="QGridLayout" name="column_color_layout">
<item row="1" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Column name</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QTextEdit" name="color_help_text">
<property name="readOnly">
<bool>true</bool>
</property>
<sizepolicy vsizetype="Minimum" hsizetype="Expanding">
</sizepolicy>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Selection template</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QComboBox" name="opt_column_color_name_1">
</widget>
<widget class="QComboBox" name="opt_column_color_name_1"/>
</item>
<item row="2" column="1">
<widget class="TemplateLineEditor" name="opt_column_color_template_1">
</widget>
<widget class="TemplateLineEditor" name="opt_column_color_template_1"/>
</item>
<item row="3" column="0">
<widget class="QComboBox" name="opt_column_color_name_2">
</widget>
<widget class="QComboBox" name="opt_column_color_name_2"/>
</item>
<item row="3" column="1">
<widget class="TemplateLineEditor" name="opt_column_color_template_2">
</widget>
<widget class="TemplateLineEditor" name="opt_column_color_template_2"/>
</item>
<item row="4" column="0">
<widget class="QComboBox" name="opt_column_color_name_3">
</widget>
<widget class="QComboBox" name="opt_column_color_name_3"/>
</item>
<item row="4" column="1">
<widget class="TemplateLineEditor" name="opt_column_color_template_3">
</widget>
<widget class="TemplateLineEditor" name="opt_column_color_template_3"/>
</item>
<item row="5" column="0">
<widget class="QComboBox" name="opt_column_color_name_4">
</widget>
<widget class="QComboBox" name="opt_column_color_name_4"/>
</item>
<item row="5" column="1">
<widget class="TemplateLineEditor" name="opt_column_color_template_4">
</widget>
<widget class="TemplateLineEditor" name="opt_column_color_template_4"/>
</item>
<item row="6" column="0">
<widget class="QComboBox" name="opt_column_color_name_5">
</widget>
<widget class="QComboBox" name="opt_column_color_name_5"/>
</item>
<item row="6" column="1">
<widget class="TemplateLineEditor" name="opt_column_color_template_5">
</widget>
<widget class="TemplateLineEditor" name="opt_column_color_template_5"/>
</item>
<item row="20" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Color names</string>
</property>
</widget>
</item>
<item row="21" column="0" colspan="2">
<widget class="QTextEdit" name="colors_box">
<property name="readOnly">
<item row="0" column="0" colspan="2">
<widget class="QScrollArea" name="scrollArea">
<property name="minimumSize">
<size>
<width>0</width>
<height>200</height>
</size>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy vsizetype="Expanding" hsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>687</width>
<height>194</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="color_help_text">
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="21" column="0" colspan="2">
<widget class="QScrollArea" name="scrollArea_2">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>120</height>
</size>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>687</width>
<height>61</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="colors_box">
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>