#include "ControlGraphics.h"
#include "ControlInclude.h"
#include "ControlLog.h"
+#include "ControlViewSource.h"
#include "ControlMath.h"
#include "ControlNote.h"
#include "ControlParagraph.h"
#include "QInclude.h"
#include "QIndex.h"
#include "QLog.h"
+#include "QViewSource.h"
#include "QMath.h"
#include "QNote.h"
#include "QParagraph.h"
char const * const dialognames[] = {
"aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
"citation", "document", "errorlist", "ert", "external", "file",
-"findreplace", "float", "graphics", "include", "index", "label", "log",
+"findreplace", "float", "graphics", "include", "index", "label", "log", "view-source",
"mathpanel", "mathdelimiter", "mathmatrix", "note", "paragraph", "preamble",
"prefs", "print", "ref", "sendto", "spellchecker","tabular", "tabularcreate",
dialog->setController(new ControlLog(*dialog));
dialog->setView(new QLog(*dialog));
dialog->bc().bp(new OkCancelPolicy);
+ } else if (name == "view-source") {
+ dialog->setController(new ControlViewSource(*dialog));
+ dialog->setView(new QViewSource(*dialog));
+ dialog->bc().bp(new OkCancelPolicy);
} else if (name == "mathpanel") {
dialog->setController(new ControlMath(*dialog));
dialog->setView(new QMath(*dialog));
QLAction.C QLAction.h \
QLImage.C QLImage.h \
QLog.C QLog.h \
+ QViewSource.C QViewSource.h \
QLPainter.C QLPainter.h \
QLyXKeySym.C QLyXKeySym.h \
QMath.C QMath.h \
QIncludeUi.ui \
QIndexUi.ui \
QLogUi.ui \
+ QViewSourceUi.ui \
QMathUi.ui \
QMathMatrixUi.ui \
QNoteUi.ui \
QIndexDialog.C QIndexDialog.h \
QLAction.C QLAction.h \
QLogDialog.C QLogDialog.h \
+ QViewSourceDialog.C QViewSourceDialog.h \
+ QViewSource.C QViewSource.h \
QLMenubar.C QLMenubar.h \
QLPopupMenu.C QLPopupMenu.h \
QLPrintDialog.C QLPrintDialog.h \
--- /dev/null
+/**
+ * \file QViewSource.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Bo Peng
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QViewSource.h"
+#include "QViewSourceDialog.h"
+#include "qt_helpers.h"
+#include "lyx_gui.h"
+
+#include "controllers/ControlViewSource.h"
+
+#include <sstream>
+
+#include <QTextEdit>
+#include <QPushButton>
+
+namespace lyx {
+namespace frontend {
+
+typedef QController<ControlViewSource, QView<QViewSourceDialog> > base_class;
+
+
+QViewSource::QViewSource(Dialog & parent)
+ : base_class(parent, "")
+{}
+
+
+latexHighlighter::latexHighlighter(QTextDocument * parent) :
+ QSyntaxHighlighter(parent)
+{
+ keywordFormat.setForeground(Qt::darkBlue);
+ keywordFormat.setFontWeight(QFont::Bold);
+ commentFormat.setForeground(Qt::gray);
+ mathFormat.setForeground(Qt::red);
+}
+
+
+void latexHighlighter::highlightBlock(QString const & text)
+{
+ // comment
+ QRegExp exprComment("^%.*$");
+ int index = text.indexOf(exprComment);
+ while (index >= 0) {
+ int length = exprComment.matchedLength();
+ setFormat(index, length, commentFormat);
+ index = text.indexOf(exprComment, index + length);
+ }
+ // $ $
+ QRegExp exprMath("\\$[^\\$]*\\$");
+ index = text.indexOf(exprMath);
+ while (index >= 0) {
+ int length = exprMath.matchedLength();
+ setFormat(index, length, mathFormat);
+ index = text.indexOf(exprMath, index + length);
+ }
+ // [ ]
+ QRegExp exprDispMath("\\[[^\\]]*\\]");
+ index = text.indexOf(exprDispMath);
+ while (index >= 0) {
+ int length = exprDispMath.matchedLength();
+ setFormat(index, length, mathFormat);
+ index = text.indexOf(exprDispMath, index + length);
+ }
+ // \whatever
+ QRegExp exprKeyword("\\\\[A-Za-z]+");
+ index = text.indexOf(exprKeyword);
+ while (index >= 0) {
+ int length = exprKeyword.matchedLength();
+ setFormat(index, length, keywordFormat);
+ index = text.indexOf(exprKeyword, index + length);
+ }
+}
+
+
+void QViewSource::build_dialog()
+{
+ dialog_.reset(new QViewSourceDialog(this));
+ // set syntex highlighting
+ highlighter = new latexHighlighter(dialog_->viewSourceTV->document());
+ //
+ dialog_->viewSourceTV->setReadOnly(true);
+ dialog_->viewSourceTV->setTextFormat(Qt::PlainText);
+ // this is personal. I think source code should be in fixed-size font
+ QFont font(toqstr(lyx_gui::typewriter_font_name()));
+ font.setFixedPitch(true);
+ font.setStyleHint(QFont::TypeWriter);
+ dialog_->viewSourceTV->setFont(font);
+ // again, personal taste
+ dialog_->viewSourceTV->setWordWrapMode(QTextOption::NoWrap);
+}
+
+
+void QViewSource::update_contents()
+{
+ setTitle(controller().title());
+ dialog_->viewSourceTV->setText(toqstr(controller().updateContent()));
+}
+
+
+} // namespace frontend
+} // namespace lyx
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file QViewSource.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Bo Peng
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef QVIEWSOURCE_H
+#define QVIEWSOURCE_H
+
+#include "QDialogView.h"
+#include <QSyntaxHighlighter>
+
+namespace lyx {
+namespace frontend {
+
+class ControlViewSource;
+class QViewSourceDialog;
+class latexHighlighter;
+
+///
+class QViewSource
+ : public QController<ControlViewSource, QView<QViewSourceDialog> >
+{
+public:
+ ///
+ friend class QViewSourceDialog;
+ ///
+ QViewSource(Dialog &);
+private:
+ /// Apply changes
+ virtual void apply() {}
+ /// update
+ virtual void update_contents();
+ /// build the dialog
+ virtual void build_dialog();
+ /// latex syntax highlighter
+ latexHighlighter * highlighter;
+};
+
+
+///
+class latexHighlighter : public QSyntaxHighlighter
+{
+ Q_OBJECT
+
+public:
+ latexHighlighter(QTextDocument * parent);
+
+protected:
+ void highlightBlock(QString const & text);
+
+private:
+ QTextCharFormat commentFormat;
+ QTextCharFormat keywordFormat;
+ QTextCharFormat mathFormat;
+};
+
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // QVIEWSOURCE_H
--- /dev/null
+/**
+ * \file QViewSourceDialog.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Bo Peng
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QViewSourceDialog.h"
+#include "QViewSource.h"
+
+#include <qpushbutton.h>
+
+
+namespace lyx {
+namespace frontend {
+
+QViewSourceDialog::QViewSourceDialog(QViewSource * form)
+ : form_(form)
+{
+ setupUi(this);
+
+ connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+}
+
+
+void QViewSourceDialog::closeEvent(QCloseEvent * e)
+{
+ form_->slotWMHide();
+ e->accept();
+}
+
+
+} // namespace frontend
+} // namespace lyx
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file QViewSourceDialog.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Bo Peng
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef QVIEWSOURCEDIALOG_H
+#define QVIEWSOURCEDIALOG_H
+
+#include "ui/QViewSourceUi.h"
+
+namespace lyx {
+namespace frontend {
+
+class QViewSource;
+
+class QViewSourceDialog : public QDialog, public Ui::QViewSourceUi {
+ Q_OBJECT
+public:
+ QViewSourceDialog(QViewSource * form);
+protected:
+ virtual void closeEvent(QCloseEvent * e);
+private:
+ QViewSource * form_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // QVIEWSOURCEDIALOG_H
--- /dev/null
+<ui version="4.0" >
+ <author></author>
+ <comment></comment>
+ <exportmacro></exportmacro>
+ <class>QViewSourceUi</class>
+ <widget class="QDialog" name="QViewSourceUi" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>420</width>
+ <height>328</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string/>
+ </property>
+ <property name="sizeGripEnabled" >
+ <bool>true</bool>
+ </property>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>11</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QTextEdit" name="viewSourceTV" >
+ <property name="whatsThis" >
+ <string><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:Sans Serif; font-size:13pt; font-weight:400; font-style:normal; text-decoration:none;"><p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html></string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::Expanding</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="closePB" >
+ <property name="text" >
+ <string>&Close</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
+ <tabstops>
+ <tabstop>viewSourceTV</tabstop>
+ <tabstop>closePB</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>