Wire up the hyperlinks

This commit is contained in:
Kovid Goyal 2014-05-20 16:11:17 +05:30
parent 1f480dd3b8
commit 0efd5c5515
4 changed files with 44 additions and 3 deletions

Binary file not shown.

View File

@ -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) -> process_rules = (node, cssRules, address, sheet, sheet_index, matching_selectors, all_properties, node_style, is_ancestor, ans) ->
for rule, rule_index in cssRules for rule, rule_index in cssRules
rule_address = address + [rule_index] rule_address = address.concat([rule_index])
if rule.type == CSSRule.MEDIA_RULE 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) process_rules(node, rule.cssRules, rule_address, sheet, sheet_index, matching_selectors, all_properties, node_style, is_ancestor, ans)
continue continue

View File

@ -118,6 +118,7 @@ class Boss(QObject):
self.gui.spell_check.refresh_requested.connect(self.commit_all_editors_to_container) 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_replaced.connect(self.word_replaced)
self.gui.spell_check.word_ignored.connect(self.word_ignored) self.gui.spell_check.word_ignored.connect(self.word_ignored)
self.gui.live_css.goto_declaration.connect(self.goto_style_declaration)
def preferences(self): def preferences(self):
p = Preferences(self.gui) p = Preferences(self.gui)
@ -1037,6 +1038,11 @@ class Boss(QObject):
if name is not None and getattr(ed, 'syntax', None) == 'html': if name is not None and getattr(ed, 'syntax', None) == 'html':
self.gui.live_css.sync_to_editor(name) 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): def init_editor(self, name, editor, data=None, use_template=False):
editor.undo_redo_state_changed.connect(self.editor_undo_redo_state_changed) editor.undo_redo_state_changed.connect(self.editor_undo_redo_state_changed)
editor.data_changed.connect(self.editor_data_changed) editor.data_changed.connect(self.editor_data_changed)

View File

@ -112,6 +112,8 @@ class Cell(object): # {{{
class Declaration(QWidget): class Declaration(QWidget):
hyperlink_activated = pyqtSignal(object)
def __init__(self, html_name, data, is_first=False, parent=None): def __init__(self, html_name, data, is_first=False, parent=None):
QWidget.__init__(self, parent) QWidget.__init__(self, parent)
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum) self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum)
@ -197,6 +199,27 @@ class Declaration(QWidget):
self.setCursor(cursor) self.setCursor(cursor)
return QWidget.mouseMoveEvent(self, ev) 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): def leaveEvent(self, ev):
self.update_hover(False) self.update_hover(False)
self.setCursor(Qt.ArrowCursor) self.setCursor(Qt.ArrowCursor)
@ -211,6 +234,8 @@ class Declaration(QWidget):
class Box(QWidget): class Box(QWidget):
hyperlink_activated = pyqtSignal(object)
def __init__(self, parent=None): def __init__(self, parent=None):
QWidget.__init__(self, parent) QWidget.__init__(self, parent)
self.l = l = QVBoxLayout(self) self.l = l = QVBoxLayout(self)
@ -221,9 +246,12 @@ class Box(QWidget):
def show_data(self, data): def show_data(self, data):
for w in self.widgets: for w in self.widgets:
self.layout().removeWidget(w) self.layout().removeWidget(w)
for x in ('toggled',): for x in ('toggled', 'hyperlink_activated'):
if hasattr(w, x): if hasattr(w, x):
try:
getattr(w, x).disconnect() getattr(w, x).disconnect()
except TypeError:
pass
w.deleteLater() w.deleteLater()
self.widgets = [] self.widgets = []
for node in data['nodes']: for node in data['nodes']:
@ -237,6 +265,7 @@ class Box(QWidget):
self.widgets.append(h), self.layout().addWidget(h) self.widgets.append(h), self.layout().addWidget(h)
for i, declaration in enumerate(node['css']): for i, declaration in enumerate(node['css']):
d = Declaration(data['html_name'], declaration, is_first=i == 0, parent=self) 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) self.widgets.append(d), self.layout().addWidget(d)
h = Heading(_('Computed final style'), parent=self) h = Heading(_('Computed final style'), parent=self)
@ -263,6 +292,8 @@ class Box(QWidget):
class LiveCSS(QWidget): class LiveCSS(QWidget):
goto_declaration = pyqtSignal(object)
def __init__(self, preview, parent=None): def __init__(self, preview, parent=None):
QWidget.__init__(self, parent) QWidget.__init__(self, parent)
self.preview = preview self.preview = preview
@ -285,6 +316,7 @@ class LiveCSS(QWidget):
s.addWidget(la) s.addWidget(la)
self.box = box = Box(self) self.box = box = Box(self)
box.hyperlink_activated.connect(self.goto_declaration)
self.scroll = sc = QScrollArea(self) self.scroll = sc = QScrollArea(self)
sc.setWidget(box) sc.setWidget(box)
sc.setWidgetResizable(True) sc.setWidgetResizable(True)
@ -376,3 +408,6 @@ class LiveCSS(QWidget):
def stop_update_timer(self): def stop_update_timer(self):
self.update_timer.stop() self.update_timer.stop()
def navigate_to_declaration(self, data, editor):
print (data) # TODO: Implement this