mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 13:31:49 +00:00
Initial Qt4 support for view-source feature (r13610), from Bo Peng (ben.bob@gmail.com)
* add src/frontend/qt4/QViewSource.h/C, QViewSourceDialog.h/C, ui/QViewSourceUi.ui * modify corresponding qt4/Makefile.am Makefile.dialogs, Dialogs.C git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13682 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
1bed69439f
commit
2f3ac2d20f
@ -27,6 +27,7 @@
|
||||
#include "ControlGraphics.h"
|
||||
#include "ControlInclude.h"
|
||||
#include "ControlLog.h"
|
||||
#include "ControlViewSource.h"
|
||||
#include "ControlMath.h"
|
||||
#include "ControlNote.h"
|
||||
#include "ControlParagraph.h"
|
||||
@ -67,6 +68,7 @@
|
||||
#include "QInclude.h"
|
||||
#include "QIndex.h"
|
||||
#include "QLog.h"
|
||||
#include "QViewSource.h"
|
||||
#include "QMath.h"
|
||||
#include "QNote.h"
|
||||
#include "QParagraph.h"
|
||||
@ -104,7 +106,7 @@ namespace {
|
||||
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",
|
||||
|
||||
@ -245,6 +247,10 @@ Dialogs::DialogPtr Dialogs::build(string const & name)
|
||||
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));
|
||||
|
@ -50,6 +50,7 @@ libqt4_la_SOURCES = \
|
||||
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 \
|
||||
|
@ -33,6 +33,7 @@ UIFILES = \
|
||||
QIncludeUi.ui \
|
||||
QIndexUi.ui \
|
||||
QLogUi.ui \
|
||||
QViewSourceUi.ui \
|
||||
QMathUi.ui \
|
||||
QMathMatrixUi.ui \
|
||||
QNoteUi.ui \
|
||||
@ -101,6 +102,8 @@ MOCFILES = \
|
||||
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 \
|
||||
|
110
src/frontends/qt4/QViewSource.C
Normal file
110
src/frontends/qt4/QViewSource.C
Normal file
@ -0,0 +1,110 @@
|
||||
/**
|
||||
* \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
|
68
src/frontends/qt4/QViewSource.h
Normal file
68
src/frontends/qt4/QViewSource.h
Normal file
@ -0,0 +1,68 @@
|
||||
// -*- 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
|
40
src/frontends/qt4/QViewSourceDialog.C
Normal file
40
src/frontends/qt4/QViewSourceDialog.C
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* \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
|
36
src/frontends/qt4/QViewSourceDialog.h
Normal file
36
src/frontends/qt4/QViewSourceDialog.h
Normal file
@ -0,0 +1,36 @@
|
||||
// -*- 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
|
77
src/frontends/qt4/ui/QViewSourceUi.ui
Normal file
77
src/frontends/qt4/ui/QViewSourceUi.ui
Normal file
@ -0,0 +1,77 @@
|
||||
<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>
|
Loading…
Reference in New Issue
Block a user