mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 19:25:39 +00:00
Present for Bo: Cleanup ViewSource and make it a DockWidget.
* DockView.h: add the orientation option. * QViewSource: now a model and a controller * QViewSourceDialog: now only a simple QWidget. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17538 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
dfbc9cfccc
commit
14f3344f0b
@ -66,6 +66,7 @@
|
|||||||
#include "QNomencl.h"
|
#include "QNomencl.h"
|
||||||
#include "QLog.h"
|
#include "QLog.h"
|
||||||
#include "QViewSource.h"
|
#include "QViewSource.h"
|
||||||
|
#include "QViewSourceDialog.h"
|
||||||
#include "QMath.h"
|
#include "QMath.h"
|
||||||
#include "QNote.h"
|
#include "QNote.h"
|
||||||
#include "QParagraph.h"
|
#include "QParagraph.h"
|
||||||
@ -237,8 +238,11 @@ Dialogs::DialogPtr Dialogs::build(string const & name)
|
|||||||
dialog->setView(new QLog(*dialog));
|
dialog->setView(new QLog(*dialog));
|
||||||
dialog->bc().bp(new OkCancelPolicy);
|
dialog->bc().bp(new OkCancelPolicy);
|
||||||
} else if (name == "view-source") {
|
} else if (name == "view-source") {
|
||||||
dialog->setController(new ControlViewSource(*dialog));
|
QViewSource * qvs = new QViewSource(*dialog);
|
||||||
dialog->setView(new QViewSource(*dialog));
|
dialog->setController(qvs);
|
||||||
|
GuiView & gui_view = static_cast<GuiView &>(lyxview_);
|
||||||
|
dialog->setView(new DockView<QViewSource, QViewSourceDialog>(
|
||||||
|
*dialog, qvs, &gui_view, _("LateX Source"), Qt::BottomDockWidgetArea));
|
||||||
dialog->bc().bp(new OkCancelPolicy);
|
dialog->bc().bp(new OkCancelPolicy);
|
||||||
} else if (name == "mathpanel") {
|
} else if (name == "mathpanel") {
|
||||||
dialog->setController(new ControlMath(*dialog));
|
dialog->setController(new ControlMath(*dialog));
|
||||||
|
@ -34,13 +34,14 @@ public:
|
|||||||
Dialog & dialog, ///< The (one) parent Dialog class.
|
Dialog & dialog, ///< The (one) parent Dialog class.
|
||||||
Controller * form, ///< Associated model/controller
|
Controller * form, ///< Associated model/controller
|
||||||
QMainWindow * parent, ///< the main window where to dock.
|
QMainWindow * parent, ///< the main window where to dock.
|
||||||
docstring const & title ///< Window title (shown in the top title bar).
|
docstring const & title, ///< Window title (shown in the top title bar).
|
||||||
|
Qt::DockWidgetArea area = Qt::LeftDockWidgetArea
|
||||||
)
|
)
|
||||||
: QDockWidget(toqstr(title), parent), Dialog::View(dialog, title)
|
: QDockWidget(toqstr(title), parent), Dialog::View(dialog, title)
|
||||||
{
|
{
|
||||||
widget_.reset(new Widget(form));
|
widget_.reset(new Widget(form));
|
||||||
setWidget(widget_.get());
|
setWidget(widget_.get());
|
||||||
parent->addDockWidget(Qt::LeftDockWidgetArea, this);
|
parent->addDockWidget(area, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dialog::View inherited methods
|
/// Dialog::View inherited methods
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*
|
*
|
||||||
* \author John Levon
|
* \author John Levon
|
||||||
* \author Bo Peng
|
* \author Bo Peng
|
||||||
|
* \author Abdelrazak Younes
|
||||||
*
|
*
|
||||||
* Full author contact details are available in file CREDITS.
|
* Full author contact details are available in file CREDITS.
|
||||||
*/
|
*/
|
||||||
@ -15,25 +16,9 @@
|
|||||||
#include "QViewSourceDialog.h"
|
#include "QViewSourceDialog.h"
|
||||||
#include "qt_helpers.h"
|
#include "qt_helpers.h"
|
||||||
|
|
||||||
#include "frontends/Application.h"
|
|
||||||
|
|
||||||
#include "controllers/ControlViewSource.h"
|
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include <QTextEdit>
|
|
||||||
#include <QPushButton>
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
namespace frontend {
|
namespace frontend {
|
||||||
|
|
||||||
typedef QController<ControlViewSource, QView<QViewSourceDialog> > viewsource_base_class;
|
|
||||||
|
|
||||||
|
|
||||||
QViewSource::QViewSource(Dialog & parent)
|
|
||||||
: viewsource_base_class(parent, lyx::docstring())
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
latexHighlighter::latexHighlighter(QTextDocument * parent) :
|
latexHighlighter::latexHighlighter(QTextDocument * parent) :
|
||||||
QSyntaxHighlighter(parent)
|
QSyntaxHighlighter(parent)
|
||||||
@ -82,37 +67,18 @@ void latexHighlighter::highlightBlock(QString const & text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void QViewSource::build_dialog()
|
QViewSource::QViewSource(Dialog & parent)
|
||||||
|
: ControlViewSource(parent)
|
||||||
{
|
{
|
||||||
dialog_.reset(new QViewSourceDialog(this));
|
document_ = new QTextDocument(this);
|
||||||
// set syntex highlighting
|
// set syntex highlighting
|
||||||
highlighter = new latexHighlighter(dialog_->viewSourceTV->document());
|
highlighter_ = new latexHighlighter(document_);
|
||||||
//
|
|
||||||
dialog_->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);
|
|
||||||
dialog_->viewSourceTV->setFont(font);
|
|
||||||
// again, personal taste
|
|
||||||
dialog_->viewSourceTV->setWordWrapMode(QTextOption::NoWrap);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void QViewSource::update_source()
|
|
||||||
{
|
|
||||||
bool fullSource = dialog_->viewFullSourceCB->isChecked();
|
|
||||||
dialog_->viewSourceTV->setPlainText(toqstr(controller().updateContent(fullSource)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void QViewSource::update_contents()
|
void QViewSource::update(bool full_source)
|
||||||
{
|
{
|
||||||
setTitle(controller().title());
|
document_->setPlainText(toqstr(updateContent(full_source)));
|
||||||
if (dialog_->autoUpdateCB->isChecked())
|
|
||||||
update_source();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
*
|
*
|
||||||
* \author John Levon
|
* \author John Levon
|
||||||
* \author Bo Peng
|
* \author Bo Peng
|
||||||
|
* \author Abdelrazak Younes
|
||||||
*
|
*
|
||||||
* Full author contact details are available in file CREDITS.
|
* Full author contact details are available in file CREDITS.
|
||||||
*/
|
*/
|
||||||
@ -13,45 +14,20 @@
|
|||||||
#ifndef QVIEWSOURCE_H
|
#ifndef QVIEWSOURCE_H
|
||||||
#define QVIEWSOURCE_H
|
#define QVIEWSOURCE_H
|
||||||
|
|
||||||
#include "QDialogView.h"
|
#include "frontends/controllers/ControlViewSource.h"
|
||||||
#include "QViewSourceDialog.h"
|
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
#include <QSyntaxHighlighter>
|
#include <QSyntaxHighlighter>
|
||||||
|
#include <QTextCharFormat>
|
||||||
|
#include <QTextDocument>
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
namespace frontend {
|
namespace frontend {
|
||||||
|
|
||||||
class ControlViewSource;
|
|
||||||
class latexHighlighter;
|
|
||||||
|
|
||||||
///
|
|
||||||
class QViewSource
|
|
||||||
: public QController<ControlViewSource, QView<QViewSourceDialog> >
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
friend class QViewSourceDialog;
|
|
||||||
///
|
|
||||||
QViewSource(Dialog &);
|
|
||||||
private:
|
|
||||||
/// Apply changes
|
|
||||||
virtual void apply() {}
|
|
||||||
///
|
|
||||||
void update_source();
|
|
||||||
/// update
|
|
||||||
virtual void update_contents();
|
|
||||||
/// build the dialog
|
|
||||||
virtual void build_dialog();
|
|
||||||
/// latex syntax highlighter
|
|
||||||
latexHighlighter * highlighter;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
class latexHighlighter : public QSyntaxHighlighter
|
class latexHighlighter : public QSyntaxHighlighter
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
latexHighlighter(QTextDocument * parent);
|
latexHighlighter(QTextDocument * parent);
|
||||||
|
|
||||||
@ -64,6 +40,26 @@ private:
|
|||||||
QTextCharFormat mathFormat;
|
QTextCharFormat mathFormat;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
///
|
||||||
|
class QViewSource: public QObject, public ControlViewSource
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
QViewSource(Dialog &);
|
||||||
|
virtual ~QViewSource() {}
|
||||||
|
|
||||||
|
QTextDocument * document() { return document_; }
|
||||||
|
|
||||||
|
void update(bool full_source);
|
||||||
|
|
||||||
|
private:
|
||||||
|
///
|
||||||
|
QTextDocument * document_;
|
||||||
|
|
||||||
|
/// latex syntax highlighter
|
||||||
|
latexHighlighter * highlighter_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*
|
*
|
||||||
* \author John Levon
|
* \author John Levon
|
||||||
* \author Bo Peng
|
* \author Bo Peng
|
||||||
|
* \author Abdelrazak Younes
|
||||||
*
|
*
|
||||||
* Full author contact details are available in file CREDITS.
|
* Full author contact details are available in file CREDITS.
|
||||||
*/
|
*/
|
||||||
@ -12,10 +13,8 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "QViewSourceDialog.h"
|
#include "QViewSourceDialog.h"
|
||||||
#include "QViewSource.h"
|
|
||||||
|
|
||||||
#include <QPushButton>
|
#include "QViewSource.h"
|
||||||
#include <QCloseEvent>
|
|
||||||
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
@ -26,26 +25,33 @@ QViewSourceDialog::QViewSourceDialog(QViewSource * form)
|
|||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
|
|
||||||
connect(viewFullSourceCB, SIGNAL(clicked()),
|
connect(viewFullSourceCB, SIGNAL(clicked()),
|
||||||
this, SLOT(slotUpdate()));
|
this, SLOT(update()));
|
||||||
connect(autoUpdateCB, SIGNAL(toggled(bool)),
|
connect(autoUpdateCB, SIGNAL(toggled(bool)),
|
||||||
updatePB, SLOT(setDisabled(bool)));
|
updatePB, SLOT(setDisabled(bool)));
|
||||||
connect(updatePB, SIGNAL(clicked()),
|
connect(updatePB, SIGNAL(clicked()),
|
||||||
this, SLOT(slotUpdate()));
|
this, SLOT(update()));
|
||||||
|
|
||||||
|
viewSourceTV->setDocument(form_->document());
|
||||||
|
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::closeEvent(QCloseEvent * e)
|
void QViewSourceDialog::update()
|
||||||
{
|
{
|
||||||
form_->slotWMHide();
|
if (autoUpdateCB->isChecked())
|
||||||
e->accept();
|
form_->update(viewFullSourceCB->isChecked());
|
||||||
}
|
|
||||||
|
|
||||||
|
QWidget::update();
|
||||||
void QViewSourceDialog::slotUpdate()
|
|
||||||
{
|
|
||||||
form_->update_source();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
*
|
*
|
||||||
* \author John Levon
|
* \author John Levon
|
||||||
* \author Bo Peng
|
* \author Bo Peng
|
||||||
|
* \author Abdelrazak Younes
|
||||||
*
|
*
|
||||||
* Full author contact details are available in file CREDITS.
|
* Full author contact details are available in file CREDITS.
|
||||||
*/
|
*/
|
||||||
@ -15,20 +16,24 @@
|
|||||||
|
|
||||||
#include "ui/QViewSourceUi.h"
|
#include "ui/QViewSourceUi.h"
|
||||||
|
|
||||||
|
#include "frontends/Application.h"
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
namespace frontend {
|
namespace frontend {
|
||||||
|
|
||||||
class QViewSource;
|
class QViewSource;
|
||||||
|
|
||||||
class QViewSourceDialog : public QDialog, public Ui::QViewSourceUi {
|
class QViewSourceDialog : public QWidget, public Ui::QViewSourceUi {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
QViewSourceDialog(QViewSource * form);
|
QViewSourceDialog(QViewSource * form);
|
||||||
protected:
|
|
||||||
virtual void closeEvent(QCloseEvent * e);
|
public Q_SLOTS:
|
||||||
private Q_SLOTS:
|
|
||||||
// update content
|
// update content
|
||||||
void slotUpdate();
|
void update();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QViewSource * form_;
|
QViewSource * form_;
|
||||||
};
|
};
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
<ui version="4.0" >
|
<ui version="4.0" >
|
||||||
<class>QViewSourceUi</class>
|
<class>QViewSourceUi</class>
|
||||||
<widget class="QDialog" name="QViewSourceUi" >
|
<widget class="QWidget" name="QViewSourceUi" >
|
||||||
<property name="geometry" >
|
<property name="geometry" >
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>460</width>
|
<width>460</width>
|
||||||
<height>424</height>
|
<height>116</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle" >
|
<property name="windowTitle" >
|
||||||
@ -15,108 +15,49 @@
|
|||||||
<property name="sizeGripEnabled" >
|
<property name="sizeGripEnabled" >
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" >
|
<layout class="QGridLayout" >
|
||||||
<property name="margin" >
|
<property name="margin" >
|
||||||
<number>9</number>
|
<number>9</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="spacing" >
|
<property name="spacing" >
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item row="1" column="1" >
|
||||||
|
<widget class="QCheckBox" name="autoUpdateCB" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Automatic update</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2" >
|
||||||
|
<widget class="QPushButton" name="updatePB" >
|
||||||
|
<property name="enabled" >
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>&Update</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0" colspan="3" >
|
||||||
<widget class="QTextEdit" name="viewSourceTV" >
|
<widget class="QTextEdit" name="viewSourceTV" >
|
||||||
<property name="whatsThis" >
|
<property name="whatsThis" >
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="1" column="0" >
|
||||||
<layout class="QHBoxLayout" >
|
<widget class="QCheckBox" name="viewFullSourceCB" >
|
||||||
<property name="margin" >
|
<property name="cursor" >
|
||||||
<number>0</number>
|
<cursor>0</cursor>
|
||||||
</property>
|
</property>
|
||||||
<property name="spacing" >
|
<property name="text" >
|
||||||
<number>6</number>
|
<string>Display complete source</string>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
</widget>
|
||||||
<widget class="QCheckBox" name="viewFullSourceCB" >
|
|
||||||
<property name="cursor" >
|
|
||||||
<cursor>0</cursor>
|
|
||||||
</property>
|
|
||||||
<property name="text" >
|
|
||||||
<string>Display complete source</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="autoUpdateCB" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>Automatic update</string>
|
|
||||||
</property>
|
|
||||||
<property name="checked" >
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</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>201</width>
|
|
||||||
<height>44</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="updatePB" >
|
|
||||||
<property name="enabled" >
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text" >
|
|
||||||
<string>&Update</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer>
|
|
||||||
<property name="orientation" >
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeType" >
|
|
||||||
<enum>QSizePolicy::Fixed</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" >
|
|
||||||
<size>
|
|
||||||
<width>31</width>
|
|
||||||
<height>44</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="closePB" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>&Close</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@ -125,7 +66,6 @@
|
|||||||
<tabstop>viewFullSourceCB</tabstop>
|
<tabstop>viewFullSourceCB</tabstop>
|
||||||
<tabstop>autoUpdateCB</tabstop>
|
<tabstop>autoUpdateCB</tabstop>
|
||||||
<tabstop>updatePB</tabstop>
|
<tabstop>updatePB</tabstop>
|
||||||
<tabstop>closePB</tabstop>
|
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<includes>
|
<includes>
|
||||||
<include location="local" >qt_helpers.h</include>
|
<include location="local" >qt_helpers.h</include>
|
||||||
|
Loading…
Reference in New Issue
Block a user