mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
merge QViewSource and QViewSourceDialog
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17947 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
90e03494bb
commit
700c7cf5bd
@ -68,7 +68,6 @@
|
||||
#include "QNomencl.h"
|
||||
#include "QLog.h"
|
||||
#include "QViewSource.h"
|
||||
#include "QViewSourceDialog.h"
|
||||
#include "QNote.h"
|
||||
#include "QParagraph.h"
|
||||
#include "QPrefs.h"
|
||||
|
@ -108,7 +108,6 @@ MOCFILES = \
|
||||
QIndexDialog.C QIndexDialog.h \
|
||||
QLog.C QLog.h \
|
||||
QLogDialog.C QLogDialog.h \
|
||||
QViewSourceDialog.C QViewSourceDialog.h \
|
||||
QViewSource.C QViewSource.h \
|
||||
QLMenubar.C QLMenubar.h \
|
||||
QLPopupMenu.C QLPopupMenu.h \
|
||||
|
@ -374,10 +374,11 @@ QDocumentDialog::QDocumentDialog(QDocument * form)
|
||||
|
||||
// preamble
|
||||
preambleModule = new UiWidget<Ui::PreambleUi>;
|
||||
connect(preambleModule->preambleTE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
|
||||
connect(preambleModule->preambleTE, SIGNAL(textChanged()),
|
||||
this, SLOT(change_adaptor()));
|
||||
// This is not a memory leak. The object will be destroyed
|
||||
// with preambleModule.
|
||||
new latexHighlighter(preambleModule->preambleTE->document());
|
||||
(void) new LaTeXHighlighter(preambleModule->preambleTE->document());
|
||||
|
||||
|
||||
// bullets
|
||||
|
@ -13,15 +13,67 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "QViewSource.h"
|
||||
#include "QViewSourceDialog.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include <QTextDocument>
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// QViewSourceDialog
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
latexHighlighter::latexHighlighter(QTextDocument * parent) :
|
||||
QSyntaxHighlighter(parent)
|
||||
QViewSourceDialog::QViewSourceDialog(QViewSource * form)
|
||||
: form_(form)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
connect(viewFullSourceCB, SIGNAL(clicked()),
|
||||
this, SLOT(update()));
|
||||
connect(autoUpdateCB, SIGNAL(toggled(bool)),
|
||||
updatePB, SLOT(setDisabled(bool)));
|
||||
connect(updatePB, SIGNAL(clicked()),
|
||||
this, SLOT(update()));
|
||||
|
||||
// setting a document at this point trigger an assertion in Qt
|
||||
// so we disable the signals here:
|
||||
form_->document()->blockSignals(true);
|
||||
viewSourceTV->setDocument(form_->document());
|
||||
form_->document()->blockSignals(false);
|
||||
viewSourceTV->setReadOnly(true);
|
||||
///dialog_->viewSourceTV->setAcceptRichText(false);
|
||||
// this is personal. I think source code should be in fixed-size font
|
||||
QFont font(toqstr(theApp()->typewriterFontName()));
|
||||
font.setKerning(false);
|
||||
font.setFixedPitch(true);
|
||||
font.setStyleHint(QFont::TypeWriter);
|
||||
viewSourceTV->setFont(font);
|
||||
// again, personal taste
|
||||
viewSourceTV->setWordWrapMode(QTextOption::NoWrap);
|
||||
}
|
||||
|
||||
|
||||
void QViewSourceDialog::update()
|
||||
{
|
||||
if (autoUpdateCB->isChecked())
|
||||
form_->update(viewFullSourceCB->isChecked());
|
||||
|
||||
QWidget::update();
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// LaTeXHighlighter
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
LaTeXHighlighter::LaTeXHighlighter(QTextDocument * parent)
|
||||
: QSyntaxHighlighter(parent)
|
||||
{
|
||||
keywordFormat.setForeground(Qt::darkBlue);
|
||||
keywordFormat.setFontWeight(QFont::Bold);
|
||||
@ -30,7 +82,7 @@ latexHighlighter::latexHighlighter(QTextDocument * parent) :
|
||||
}
|
||||
|
||||
|
||||
void latexHighlighter::highlightBlock(QString const & text)
|
||||
void LaTeXHighlighter::highlightBlock(QString const & text)
|
||||
{
|
||||
// $ $
|
||||
QRegExp exprMath("\\$[^\\$]*\\$");
|
||||
@ -91,7 +143,7 @@ void latexHighlighter::highlightBlock(QString const & text)
|
||||
QRegExp exprComment("(^|[^\\\\])%.*$");
|
||||
index = text.indexOf(exprComment);
|
||||
while (index >= 0) {
|
||||
int length = exprComment.matchedLength();
|
||||
int const length = exprComment.matchedLength();
|
||||
setFormat(index, length, commentFormat);
|
||||
index = text.indexOf(exprComment, index + length);
|
||||
}
|
||||
@ -102,11 +154,16 @@ QViewSource::QViewSource(Dialog & parent)
|
||||
: ControlViewSource(parent)
|
||||
{
|
||||
document_ = new QTextDocument(this);
|
||||
// set syntex highlighting
|
||||
highlighter_ = new latexHighlighter(document_);
|
||||
highlighter_ = new LaTeXHighlighter(document_);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// QViewSource
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
void QViewSource::update(bool full_source)
|
||||
{
|
||||
document_->setPlainText(toqstr(updateContent(full_source)));
|
||||
|
@ -15,23 +15,23 @@
|
||||
#define QVIEWSOURCE_H
|
||||
|
||||
#include "frontends/controllers/ControlViewSource.h"
|
||||
#include "frontends/Application.h"
|
||||
#include "ui/ViewSourceUi.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QSyntaxHighlighter>
|
||||
#include <QTextCharFormat>
|
||||
#include <QTextDocument>
|
||||
|
||||
class QTextDocument;
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
/// LaTeX syntax highlighting.
|
||||
/// \todo FIXME: extract the latexHighlighter class into its
|
||||
/// own .[Ch] files.
|
||||
class latexHighlighter : public QSyntaxHighlighter
|
||||
// used already twice...
|
||||
class LaTeXHighlighter : public QSyntaxHighlighter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
latexHighlighter(QTextDocument * parent);
|
||||
LaTeXHighlighter(QTextDocument * parent);
|
||||
|
||||
protected:
|
||||
void highlightBlock(QString const & text);
|
||||
@ -42,24 +42,39 @@ private:
|
||||
QTextCharFormat mathFormat;
|
||||
};
|
||||
|
||||
///
|
||||
class QViewSource: public QObject, public ControlViewSource
|
||||
{
|
||||
|
||||
|
||||
class QViewSource;
|
||||
|
||||
class QViewSourceDialog : public QWidget, public Ui::QViewSourceUi {
|
||||
Q_OBJECT
|
||||
public:
|
||||
QViewSourceDialog(QViewSource * form);
|
||||
|
||||
public Q_SLOTS:
|
||||
// update content
|
||||
void update();
|
||||
|
||||
private:
|
||||
QViewSource * form_;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
class QViewSource : public QObject, public ControlViewSource {
|
||||
public:
|
||||
///
|
||||
QViewSource(Dialog &);
|
||||
virtual ~QViewSource() {}
|
||||
|
||||
///
|
||||
QTextDocument * document() { return document_; }
|
||||
|
||||
///
|
||||
void update(bool full_source);
|
||||
|
||||
private:
|
||||
///
|
||||
QTextDocument * document_;
|
||||
|
||||
/// latex syntax highlighter
|
||||
latexHighlighter * highlighter_;
|
||||
/// LaTeX syntax highlighter
|
||||
LaTeXHighlighter * highlighter_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,64 +0,0 @@
|
||||
/**
|
||||
* \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
|
||||
* \author Abdelrazak Younes
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "QViewSourceDialog.h"
|
||||
|
||||
#include "QViewSource.h"
|
||||
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
QViewSourceDialog::QViewSourceDialog(QViewSource * form)
|
||||
: form_(form)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
connect(viewFullSourceCB, SIGNAL(clicked()),
|
||||
this, SLOT(update()));
|
||||
connect(autoUpdateCB, SIGNAL(toggled(bool)),
|
||||
updatePB, SLOT(setDisabled(bool)));
|
||||
connect(updatePB, SIGNAL(clicked()),
|
||||
this, SLOT(update()));
|
||||
|
||||
// setting a document at this point trigger an assertion in Qt
|
||||
// so we disable the signals here:
|
||||
form_->document()->blockSignals(true);
|
||||
viewSourceTV->setDocument(form_->document());
|
||||
form_->document()->blockSignals(false);
|
||||
viewSourceTV->setReadOnly(true);
|
||||
///dialog_->viewSourceTV->setAcceptRichText(false);
|
||||
// this is personal. I think source code should be in fixed-size font
|
||||
QFont font(toqstr(theApp()->typewriterFontName()));
|
||||
font.setKerning(false);
|
||||
font.setFixedPitch(true);
|
||||
font.setStyleHint(QFont::TypeWriter);
|
||||
viewSourceTV->setFont(font);
|
||||
// again, personal taste
|
||||
viewSourceTV->setWordWrapMode(QTextOption::NoWrap);
|
||||
}
|
||||
|
||||
|
||||
void QViewSourceDialog::update()
|
||||
{
|
||||
if (autoUpdateCB->isChecked())
|
||||
form_->update(viewFullSourceCB->isChecked());
|
||||
|
||||
QWidget::update();
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
#include "QViewSourceDialog_moc.cpp"
|
@ -1,44 +0,0 @@
|
||||
// -*- 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
|
||||
* \author Abdelrazak Younes
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef QVIEWSOURCEDIALOG_H
|
||||
#define QVIEWSOURCEDIALOG_H
|
||||
|
||||
#include "ui/ViewSourceUi.h"
|
||||
|
||||
#include "frontends/Application.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
class QViewSource;
|
||||
|
||||
class QViewSourceDialog : public QWidget, public Ui::QViewSourceUi {
|
||||
Q_OBJECT
|
||||
public:
|
||||
QViewSourceDialog(QViewSource * form);
|
||||
|
||||
public Q_SLOTS:
|
||||
// update content
|
||||
void update();
|
||||
|
||||
private:
|
||||
QViewSource * form_;
|
||||
};
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
#endif // QVIEWSOURCEDIALOG_H
|
Loading…
Reference in New Issue
Block a user