mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Wire up the hyperlinks
This commit is contained in:
parent
1f480dd3b8
commit
0efd5c5515
Binary file not shown.
@ -174,7 +174,7 @@ get_style_properties = (style, all_properties, node_style, is_ancestor) ->
|
||||
|
||||
process_rules = (node, cssRules, address, sheet, sheet_index, matching_selectors, all_properties, node_style, is_ancestor, ans) ->
|
||||
for rule, rule_index in cssRules
|
||||
rule_address = address + [rule_index]
|
||||
rule_address = address.concat([rule_index])
|
||||
if rule.type == CSSRule.MEDIA_RULE
|
||||
process_rules(node, rule.cssRules, rule_address, sheet, sheet_index, matching_selectors, all_properties, node_style, is_ancestor, ans)
|
||||
continue
|
||||
|
@ -118,6 +118,7 @@ class Boss(QObject):
|
||||
self.gui.spell_check.refresh_requested.connect(self.commit_all_editors_to_container)
|
||||
self.gui.spell_check.word_replaced.connect(self.word_replaced)
|
||||
self.gui.spell_check.word_ignored.connect(self.word_ignored)
|
||||
self.gui.live_css.goto_declaration.connect(self.goto_style_declaration)
|
||||
|
||||
def preferences(self):
|
||||
p = Preferences(self.gui)
|
||||
@ -1037,6 +1038,11 @@ class Boss(QObject):
|
||||
if name is not None and getattr(ed, 'syntax', None) == 'html':
|
||||
self.gui.live_css.sync_to_editor(name)
|
||||
|
||||
def goto_style_declaration(self, data):
|
||||
name = data['name']
|
||||
editor = self.edit_file(name, syntax=data['syntax'])
|
||||
self.gui.live_css.navigate_to_declaration(data, editor)
|
||||
|
||||
def init_editor(self, name, editor, data=None, use_template=False):
|
||||
editor.undo_redo_state_changed.connect(self.editor_undo_redo_state_changed)
|
||||
editor.data_changed.connect(self.editor_data_changed)
|
||||
|
@ -112,6 +112,8 @@ class Cell(object): # {{{
|
||||
|
||||
class Declaration(QWidget):
|
||||
|
||||
hyperlink_activated = pyqtSignal(object)
|
||||
|
||||
def __init__(self, html_name, data, is_first=False, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum)
|
||||
@ -197,6 +199,27 @@ class Declaration(QWidget):
|
||||
self.setCursor(cursor)
|
||||
return QWidget.mouseMoveEvent(self, ev)
|
||||
|
||||
def mousePressEvent(self, ev):
|
||||
if hasattr(self, 'hyperlink_rect'):
|
||||
pos = ev.pos()
|
||||
if self.hyperlink_rect.contains(pos):
|
||||
self.emit_hyperlink_activated()
|
||||
return QWidget.mouseMoveEvent(self, ev)
|
||||
|
||||
def emit_hyperlink_activated(self):
|
||||
dt = self.data['type']
|
||||
data = {'type':dt, 'name':self.html_name, 'syntax':'html'}
|
||||
if dt == 'inline': # style attribute
|
||||
data['sourceline_address'] = self.data['href']
|
||||
elif dt == 'elem': # <style> tag
|
||||
data['sourceline_address'] = self.data['href']
|
||||
data['rule_address'] = self.data['rule_address']
|
||||
else: # stylesheet
|
||||
data['name'] = self.data['href']
|
||||
data['rule_address'] = self.data['rule_address']
|
||||
data['syntax'] = 'css'
|
||||
self.hyperlink_activated.emit(data)
|
||||
|
||||
def leaveEvent(self, ev):
|
||||
self.update_hover(False)
|
||||
self.setCursor(Qt.ArrowCursor)
|
||||
@ -211,6 +234,8 @@ class Declaration(QWidget):
|
||||
|
||||
class Box(QWidget):
|
||||
|
||||
hyperlink_activated = pyqtSignal(object)
|
||||
|
||||
def __init__(self, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
self.l = l = QVBoxLayout(self)
|
||||
@ -221,9 +246,12 @@ class Box(QWidget):
|
||||
def show_data(self, data):
|
||||
for w in self.widgets:
|
||||
self.layout().removeWidget(w)
|
||||
for x in ('toggled',):
|
||||
for x in ('toggled', 'hyperlink_activated'):
|
||||
if hasattr(w, x):
|
||||
getattr(w, x).disconnect()
|
||||
try:
|
||||
getattr(w, x).disconnect()
|
||||
except TypeError:
|
||||
pass
|
||||
w.deleteLater()
|
||||
self.widgets = []
|
||||
for node in data['nodes']:
|
||||
@ -237,6 +265,7 @@ class Box(QWidget):
|
||||
self.widgets.append(h), self.layout().addWidget(h)
|
||||
for i, declaration in enumerate(node['css']):
|
||||
d = Declaration(data['html_name'], declaration, is_first=i == 0, parent=self)
|
||||
d.hyperlink_activated.connect(self.hyperlink_activated)
|
||||
self.widgets.append(d), self.layout().addWidget(d)
|
||||
|
||||
h = Heading(_('Computed final style'), parent=self)
|
||||
@ -263,6 +292,8 @@ class Box(QWidget):
|
||||
|
||||
class LiveCSS(QWidget):
|
||||
|
||||
goto_declaration = pyqtSignal(object)
|
||||
|
||||
def __init__(self, preview, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
self.preview = preview
|
||||
@ -285,6 +316,7 @@ class LiveCSS(QWidget):
|
||||
s.addWidget(la)
|
||||
|
||||
self.box = box = Box(self)
|
||||
box.hyperlink_activated.connect(self.goto_declaration)
|
||||
self.scroll = sc = QScrollArea(self)
|
||||
sc.setWidget(box)
|
||||
sc.setWidgetResizable(True)
|
||||
@ -376,3 +408,6 @@ class LiveCSS(QWidget):
|
||||
def stop_update_timer(self):
|
||||
self.update_timer.stop()
|
||||
|
||||
def navigate_to_declaration(self, data, editor):
|
||||
print (data) # TODO: Implement this
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user