html editor

This commit is contained in:
Damien Elmes 2008-11-23 08:34:57 +09:00
parent 0207298bb5
commit 9c67a69b65
4 changed files with 101 additions and 0 deletions

View file

@ -188,6 +188,17 @@ class FactEditor(object):
self.latexMathEnv.setEnabled(False)
self.iconsBox.addWidget(self.latexMathEnv)
self.latexMathEnv.setStyle(self.plastiqueStyle)
# html
self.htmlEdit = QPushButton(self.widget)
self.htmlEdit.connect(self.htmlEdit, SIGNAL("clicked()"),
self.onHtmlEdit)
self.htmlEdit.setToolTip(_("HTML Editor (F9)"))
self.htmlEdit.setShortcut(_("F9"))
self.htmlEdit.setIcon(QIcon(":/icons/text-xml.png"))
self.htmlEdit.setFocusPolicy(Qt.NoFocus)
self.htmlEdit.setEnabled(False)
self.iconsBox.addWidget(self.htmlEdit)
self.htmlEdit.setStyle(self.plastiqueStyle)
self.fieldsFrame = None
self.widget.setLayout(self.fieldsBox)
@ -384,6 +395,7 @@ class FactEditor(object):
self.latexEqn.setEnabled(val)
self.latexMathEnv.setEnabled(val)
self.preview.setEnabled(val)
self.htmlEdit.setEnabled(val)
def disableButtons(self):
self.enableButtons(False)
@ -458,6 +470,24 @@ class FactEditor(object):
def onPreview(self):
PreviewDialog(self.parent, self.deck, self.fact).exec_()
def onHtmlEdit(self):
def helpRequested():
QDesktopServices.openUrl(QUrl(ankiqt.appWiki +
"HtmlEditor"))
w = self.focusedEdit()
if w:
self.saveFields()
d = QDialog(self.parent)
form = ankiqt.forms.edithtml.Ui_Dialog()
form.setupUi(d)
d.connect(form.buttonBox, SIGNAL("helpRequested()"),
helpRequested)
form.textEdit.setPlainText(self.widgets[w].value)
form.textEdit.moveCursor(QTextCursor.End)
d.exec_()
self.widgets[w].value = unicode(form.textEdit.toPlainText())
self.loadFields()
def fieldsAreBlank(self):
for (field, widget) in self.fields.values():
value = tidyHTML(unicode(widget.toHtml()))

70
designer/edithtml.ui Normal file
View file

@ -0,0 +1,70 @@
<ui version="4.0" >
<class>Dialog</class>
<widget class="QDialog" name="Dialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>HTML Editor</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QTextEdit" name="textEdit" >
<property name="acceptRichText" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel" >
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel" >
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/" >
<file>icons/text-xml.png</file>
<file>icons/document-preview.png</file>
<file>icons/media-record.png</file>
<file>icons/edit-rename.png</file>

BIN
icons/text-xml.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB