2006-04-15 14:13:41 +00:00
|
|
|
/**
|
|
|
|
* \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"
|
2006-10-03 14:21:15 +00:00
|
|
|
|
|
|
|
#include "frontends/Application.h"
|
2006-04-15 14:13:41 +00:00
|
|
|
|
|
|
|
#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)
|
2006-10-09 10:35:14 +00:00
|
|
|
: base_class(parent, lyx::docstring())
|
2006-04-15 14:13:41 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2006-08-17 09:01:46 +00:00
|
|
|
///dialog_->viewSourceTV->setAcceptRichText(false);
|
2006-04-15 14:13:41 +00:00
|
|
|
// this is personal. I think source code should be in fixed-size font
|
2006-10-03 14:21:15 +00:00
|
|
|
QFont font(toqstr(theApp->typewriterFontName()));
|
2006-11-14 17:25:31 +00:00
|
|
|
font.setKerning(false);
|
2006-04-15 14:13:41 +00:00
|
|
|
font.setFixedPitch(true);
|
|
|
|
font.setStyleHint(QFont::TypeWriter);
|
|
|
|
dialog_->viewSourceTV->setFont(font);
|
|
|
|
// again, personal taste
|
|
|
|
dialog_->viewSourceTV->setWordWrapMode(QTextOption::NoWrap);
|
|
|
|
}
|
|
|
|
|
2006-08-04 13:59:12 +00:00
|
|
|
|
|
|
|
void QViewSource::update_source()
|
|
|
|
{
|
|
|
|
bool fullSource = dialog_->viewFullSourceCB->isChecked();
|
2006-08-17 09:01:46 +00:00
|
|
|
dialog_->viewSourceTV->setPlainText(toqstr(controller().updateContent(fullSource)));
|
2006-08-04 13:59:12 +00:00
|
|
|
}
|
|
|
|
|
2006-04-15 14:13:41 +00:00
|
|
|
|
|
|
|
void QViewSource::update_contents()
|
|
|
|
{
|
|
|
|
setTitle(controller().title());
|
2006-08-04 13:59:12 +00:00
|
|
|
if (dialog_->autoUpdateCB->isChecked())
|
|
|
|
update_source();
|
2006-04-15 14:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
|
|
|
#include "QViewSource_moc.cpp"
|