mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement collapsing of live css groups
This commit is contained in:
parent
6ed0ec5a70
commit
6dcf731564
@ -10,7 +10,7 @@ import json, math
|
|||||||
|
|
||||||
from PyQt4.Qt import (
|
from PyQt4.Qt import (
|
||||||
QWidget, QTimer, QStackedLayout, QLabel, QScrollArea, QVBoxLayout,
|
QWidget, QTimer, QStackedLayout, QLabel, QScrollArea, QVBoxLayout,
|
||||||
QPainter, Qt, QFontInfo, QPalette, QRect, QSize, QSizePolicy)
|
QPainter, Qt, QFontInfo, QPalette, QRect, QSize, QSizePolicy, pyqtSignal)
|
||||||
|
|
||||||
from calibre.constants import iswindows
|
from calibre.constants import iswindows
|
||||||
from calibre.gui2.tweak_book import editors, actions, current_container, tprefs
|
from calibre.gui2.tweak_book import editors, actions, current_container, tprefs
|
||||||
@ -19,6 +19,8 @@ from calibre.gui2.tweak_book.editor.text import default_font_family
|
|||||||
|
|
||||||
class Heading(QWidget):
|
class Heading(QWidget):
|
||||||
|
|
||||||
|
toggled = pyqtSignal(object)
|
||||||
|
|
||||||
def __init__(self, text, expanded=True, parent=None):
|
def __init__(self, text, expanded=True, parent=None):
|
||||||
QWidget.__init__(self, parent)
|
QWidget.__init__(self, parent)
|
||||||
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum)
|
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum)
|
||||||
@ -38,6 +40,15 @@ class Heading(QWidget):
|
|||||||
f.setPointSize(int(math.ceil(1.2 * sz)))
|
f.setPointSize(int(math.ceil(1.2 * sz)))
|
||||||
self.setFont(f)
|
self.setFont(f)
|
||||||
|
|
||||||
|
def mousePressEvent(self, ev):
|
||||||
|
if ev.button() == Qt.LeftButton:
|
||||||
|
ev.accept()
|
||||||
|
self.expanded ^= True
|
||||||
|
self.toggled.emit(self)
|
||||||
|
self.update()
|
||||||
|
else:
|
||||||
|
return QWidget.mousePressEvent(self, ev)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rendered_text(self):
|
def rendered_text(self):
|
||||||
return ('▾' if self.expanded else '▸') + '\xa0' + self.text
|
return ('▾' if self.expanded else '▸') + '\xa0' + self.text
|
||||||
@ -169,6 +180,9 @@ 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',):
|
||||||
|
if hasattr(w, x):
|
||||||
|
getattr(w, x).disconnect()
|
||||||
w.deleteLater()
|
w.deleteLater()
|
||||||
self.widgets = []
|
self.widgets = []
|
||||||
for node in data['nodes']:
|
for node in data['nodes']:
|
||||||
@ -178,18 +192,29 @@ class Box(QWidget):
|
|||||||
else:
|
else:
|
||||||
title = _('Matched CSS rules for %s') % node_name
|
title = _('Matched CSS rules for %s') % node_name
|
||||||
h = Heading(title, parent=self)
|
h = Heading(title, parent=self)
|
||||||
|
h.toggled.connect(self.heading_toggled)
|
||||||
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)
|
||||||
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)
|
||||||
|
h.toggled.connect(self.heading_toggled)
|
||||||
self.widgets.append(h), self.layout().addWidget(h)
|
self.widgets.append(h), self.layout().addWidget(h)
|
||||||
keys = sorted(data['computed_css'])
|
keys = sorted(data['computed_css'])
|
||||||
declaration = {'properties':[[k, data['computed_css'][k], ''] for k in keys]}
|
declaration = {'properties':[[k, data['computed_css'][k], ''] for k in keys]}
|
||||||
d = Declaration(None, declaration, is_first=True, parent=self)
|
d = Declaration(None, declaration, is_first=True, parent=self)
|
||||||
self.widgets.append(d), self.layout().addWidget(d)
|
self.widgets.append(d), self.layout().addWidget(d)
|
||||||
|
|
||||||
|
def heading_toggled(self, heading):
|
||||||
|
for i, w in enumerate(self.widgets):
|
||||||
|
if w is heading:
|
||||||
|
for b in self.widgets[i + 1:]:
|
||||||
|
if isinstance(b, Heading):
|
||||||
|
break
|
||||||
|
b.setVisible(heading.expanded)
|
||||||
|
break
|
||||||
|
|
||||||
def relayout(self):
|
def relayout(self):
|
||||||
for w in self.widgets:
|
for w in self.widgets:
|
||||||
w.do_layout()
|
w.do_layout()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user