mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 02:14:50 +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 "QLog.h"
|
||||
#include "QViewSource.h"
|
||||
#include "QViewSourceDialog.h"
|
||||
#include "QMath.h"
|
||||
#include "QNote.h"
|
||||
#include "QParagraph.h"
|
||||
@ -237,8 +238,11 @@ Dialogs::DialogPtr Dialogs::build(string const & name)
|
||||
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));
|
||||
QViewSource * qvs = 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);
|
||||
} else if (name == "mathpanel") {
|
||||
dialog->setController(new ControlMath(*dialog));
|
||||
|
@ -34,13 +34,14 @@ public:
|
||||
Dialog & dialog, ///< The (one) parent Dialog class.
|
||||
Controller * form, ///< Associated model/controller
|
||||
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)
|
||||
{
|
||||
widget_.reset(new Widget(form));
|
||||
setWidget(widget_.get());
|
||||
parent->addDockWidget(Qt::LeftDockWidgetArea, this);
|
||||
parent->addDockWidget(area, this);
|
||||
}
|
||||
|
||||
/// Dialog::View inherited methods
|
||||
|
@ -5,6 +5,7 @@
|
||||
*
|
||||
* \author John Levon
|
||||
* \author Bo Peng
|
||||
* \author Abdelrazak Younes
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
@ -15,25 +16,9 @@
|
||||
#include "QViewSourceDialog.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include "frontends/Application.h"
|
||||
|
||||
#include "controllers/ControlViewSource.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <QTextEdit>
|
||||
#include <QPushButton>
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
typedef QController<ControlViewSource, QView<QViewSourceDialog> > viewsource_base_class;
|
||||
|
||||
|
||||
QViewSource::QViewSource(Dialog & parent)
|
||||
: viewsource_base_class(parent, lyx::docstring())
|
||||
{}
|
||||
|
||||
|
||||
latexHighlighter::latexHighlighter(QTextDocument * 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
|
||||
highlighter = new latexHighlighter(dialog_->viewSourceTV->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)));
|
||||
highlighter_ = new latexHighlighter(document_);
|
||||
}
|
||||
|
||||
|
||||
void QViewSource::update_contents()
|
||||
void QViewSource::update(bool full_source)
|
||||
{
|
||||
setTitle(controller().title());
|
||||
if (dialog_->autoUpdateCB->isChecked())
|
||||
update_source();
|
||||
document_->setPlainText(toqstr(updateContent(full_source)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
*
|
||||
* \author John Levon
|
||||
* \author Bo Peng
|
||||
* \author Abdelrazak Younes
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
@ -13,45 +14,20 @@
|
||||
#ifndef QVIEWSOURCE_H
|
||||
#define QVIEWSOURCE_H
|
||||
|
||||
#include "QDialogView.h"
|
||||
#include "QViewSourceDialog.h"
|
||||
#include "frontends/controllers/ControlViewSource.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QSyntaxHighlighter>
|
||||
#include <QTextCharFormat>
|
||||
#include <QTextDocument>
|
||||
|
||||
namespace lyx {
|
||||
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
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
latexHighlighter(QTextDocument * parent);
|
||||
|
||||
@ -64,6 +40,26 @@ private:
|
||||
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 lyx
|
||||
|
@ -5,6 +5,7 @@
|
||||
*
|
||||
* \author John Levon
|
||||
* \author Bo Peng
|
||||
* \author Abdelrazak Younes
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
@ -12,10 +13,8 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "QViewSourceDialog.h"
|
||||
#include "QViewSource.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QCloseEvent>
|
||||
#include "QViewSource.h"
|
||||
|
||||
|
||||
namespace lyx {
|
||||
@ -26,26 +25,33 @@ QViewSourceDialog::QViewSourceDialog(QViewSource * form)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
|
||||
connect(viewFullSourceCB, SIGNAL(clicked()),
|
||||
this, SLOT(slotUpdate()));
|
||||
this, SLOT(update()));
|
||||
connect(autoUpdateCB, SIGNAL(toggled(bool)),
|
||||
updatePB, SLOT(setDisabled(bool)));
|
||||
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();
|
||||
e->accept();
|
||||
}
|
||||
if (autoUpdateCB->isChecked())
|
||||
form_->update(viewFullSourceCB->isChecked());
|
||||
|
||||
|
||||
void QViewSourceDialog::slotUpdate()
|
||||
{
|
||||
form_->update_source();
|
||||
QWidget::update();
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
|
@ -6,6 +6,7 @@
|
||||
*
|
||||
* \author John Levon
|
||||
* \author Bo Peng
|
||||
* \author Abdelrazak Younes
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
@ -15,20 +16,24 @@
|
||||
|
||||
#include "ui/QViewSourceUi.h"
|
||||
|
||||
#include "frontends/Application.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
class QViewSource;
|
||||
|
||||
class QViewSourceDialog : public QDialog, public Ui::QViewSourceUi {
|
||||
class QViewSourceDialog : public QWidget, public Ui::QViewSourceUi {
|
||||
Q_OBJECT
|
||||
public:
|
||||
QViewSourceDialog(QViewSource * form);
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent * e);
|
||||
private Q_SLOTS:
|
||||
|
||||
public Q_SLOTS:
|
||||
// update content
|
||||
void slotUpdate();
|
||||
void update();
|
||||
|
||||
private:
|
||||
QViewSource * form_;
|
||||
};
|
||||
|
@ -1,12 +1,12 @@
|
||||
<ui version="4.0" >
|
||||
<class>QViewSourceUi</class>
|
||||
<widget class="QDialog" name="QViewSourceUi" >
|
||||
<widget class="QWidget" name="QViewSourceUi" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>460</width>
|
||||
<height>424</height>
|
||||
<height>116</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
@ -15,108 +15,49 @@
|
||||
<property name="sizeGripEnabled" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<layout class="QGridLayout" >
|
||||
<property name="margin" >
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</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" >
|
||||
<property name="whatsThis" >
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="margin" >
|
||||
<number>0</number>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QCheckBox" name="viewFullSourceCB" >
|
||||
<property name="cursor" >
|
||||
<cursor>0</cursor>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
<property name="text" >
|
||||
<string>Display complete source</string>
|
||||
</property>
|
||||
<item>
|
||||
<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>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@ -125,7 +66,6 @@
|
||||
<tabstop>viewFullSourceCB</tabstop>
|
||||
<tabstop>autoUpdateCB</tabstop>
|
||||
<tabstop>updatePB</tabstop>
|
||||
<tabstop>closePB</tabstop>
|
||||
</tabstops>
|
||||
<includes>
|
||||
<include location="local" >qt_helpers.h</include>
|
||||
|
Loading…
Reference in New Issue
Block a user