mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-13 06:20:28 +00:00
* GuiViewSource: port back to DockView.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20866 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
17ffac2ae9
commit
c1472a5c78
@ -33,7 +33,7 @@ using std::string;
|
|||||||
namespace lyx {
|
namespace lyx {
|
||||||
namespace frontend {
|
namespace frontend {
|
||||||
|
|
||||||
GuiViewSourceDialog::GuiViewSourceDialog(ControlViewSource & controller)
|
ViewSourceWidget::ViewSourceWidget(GuiViewSource & controller)
|
||||||
: controller_(controller), document_(new QTextDocument(this)),
|
: controller_(controller), document_(new QTextDocument(this)),
|
||||||
highlighter_(new LaTeXHighlighter(document_))
|
highlighter_(new LaTeXHighlighter(document_))
|
||||||
{
|
{
|
||||||
@ -49,9 +49,9 @@ GuiViewSourceDialog::GuiViewSourceDialog(ControlViewSource & controller)
|
|||||||
|
|
||||||
// setting a document at this point trigger an assertion in Qt
|
// setting a document at this point trigger an assertion in Qt
|
||||||
// so we disable the signals here:
|
// so we disable the signals here:
|
||||||
document()->blockSignals(true);
|
document_->blockSignals(true);
|
||||||
viewSourceTV->setDocument(document());
|
viewSourceTV->setDocument(document_);
|
||||||
document()->blockSignals(false);
|
document_->blockSignals(false);
|
||||||
viewSourceTV->setReadOnly(true);
|
viewSourceTV->setReadOnly(true);
|
||||||
///dialog_->viewSourceTV->setAcceptRichText(false);
|
///dialog_->viewSourceTV->setAcceptRichText(false);
|
||||||
// this is personal. I think source code should be in fixed-size font
|
// this is personal. I think source code should be in fixed-size font
|
||||||
@ -65,7 +65,7 @@ GuiViewSourceDialog::GuiViewSourceDialog(ControlViewSource & controller)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiViewSourceDialog::updateView()
|
void ViewSourceWidget::updateView()
|
||||||
{
|
{
|
||||||
if (autoUpdateCB->isChecked())
|
if (autoUpdateCB->isChecked())
|
||||||
update(viewFullSourceCB->isChecked());
|
update(viewFullSourceCB->isChecked());
|
||||||
@ -77,28 +77,44 @@ void GuiViewSourceDialog::updateView()
|
|||||||
c.select(QTextCursor::BlockUnderCursor);
|
c.select(QTextCursor::BlockUnderCursor);
|
||||||
c.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor, end - beg + 1);
|
c.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor, end - beg + 1);
|
||||||
viewSourceTV->setTextCursor(c);
|
viewSourceTV->setTextCursor(c);
|
||||||
QWidget::update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiViewSourceDialog::update(bool full_source)
|
void ViewSourceWidget::update(bool full_source)
|
||||||
{
|
{
|
||||||
document_->setPlainText(toqstr(controller_.updateContent(full_source)));
|
document_->setPlainText(controller_.getContent(full_source));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ControlViewSource::ControlViewSource(Dialog & parent)
|
GuiViewSource::GuiViewSource(GuiViewBase & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
|
||||||
: Controller(parent)
|
: DockView(parent, "view-source", area, flags)
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
bool ControlViewSource::initialiseParams(string const & /*source*/)
|
|
||||||
{
|
{
|
||||||
|
widget_ = new ViewSourceWidget(*this);
|
||||||
|
setWidget(widget_);
|
||||||
|
setWindowTitle(widget_->windowTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GuiViewSource::~GuiViewSource()
|
||||||
|
{
|
||||||
|
delete widget_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiViewSource::updateView()
|
||||||
|
{
|
||||||
|
widget_->updateView();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GuiViewSource::initialiseParams(string const & /*source*/)
|
||||||
|
{
|
||||||
|
setWindowTitle(title());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
docstring const ControlViewSource::updateContent(bool fullSource)
|
QString GuiViewSource::getContent(bool fullSource)
|
||||||
{
|
{
|
||||||
// get the *top* level paragraphs that contain the cursor,
|
// get the *top* level paragraphs that contain the cursor,
|
||||||
// or the selected text
|
// or the selected text
|
||||||
@ -117,11 +133,11 @@ docstring const ControlViewSource::updateContent(bool fullSource)
|
|||||||
std::swap(par_begin, par_end);
|
std::swap(par_begin, par_end);
|
||||||
odocstringstream ostr;
|
odocstringstream ostr;
|
||||||
view->buffer().getSourceCode(ostr, par_begin, par_end + 1, fullSource);
|
view->buffer().getSourceCode(ostr, par_begin, par_end + 1, fullSource);
|
||||||
return ostr.str();
|
return toqstr(ostr.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::pair<int, int> ControlViewSource::getRows() const
|
std::pair<int, int> GuiViewSource::getRows() const
|
||||||
{
|
{
|
||||||
BufferView const * view = bufferview();
|
BufferView const * view = bufferview();
|
||||||
CursorSlice beg = view->cursor().selectionBegin().bottom();
|
CursorSlice beg = view->cursor().selectionBegin().bottom();
|
||||||
@ -137,19 +153,18 @@ std::pair<int, int> ControlViewSource::getRows() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
docstring const ControlViewSource::title() const
|
QString GuiViewSource::title() const
|
||||||
{
|
{
|
||||||
switch (docType()) {
|
switch (docType()) {
|
||||||
case LATEX:
|
case LATEX:
|
||||||
return _("LaTeX Source");
|
return qt_("LaTeX Source");
|
||||||
case DOCBOOK:
|
case DOCBOOK:
|
||||||
return _("DocBook Source");
|
return qt_("DocBook Source");
|
||||||
case LITERATE:
|
case LITERATE:
|
||||||
return _("Literate Source");
|
return qt_("Literate Source");
|
||||||
default:
|
|
||||||
BOOST_ASSERT(false);
|
|
||||||
return docstring();
|
|
||||||
}
|
}
|
||||||
|
BOOST_ASSERT(false);
|
||||||
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
|
|
||||||
#include "ui_ViewSourceUi.h"
|
#include "ui_ViewSourceUi.h"
|
||||||
|
|
||||||
#include "Dialog.h"
|
#include "DockView.h"
|
||||||
#include "GuiView.h"
|
#include "GuiView.h"
|
||||||
#include "qt_helpers.h"
|
#include "qt_helpers.h"
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include <QDockWidget>
|
#include <QDockWidget>
|
||||||
#include <QWidget>
|
#include <QString>
|
||||||
#include <QSyntaxHighlighter>
|
|
||||||
#include <QTextCharFormat>
|
#include <QTextCharFormat>
|
||||||
|
|
||||||
class QTextDocument;
|
class QTextDocument;
|
||||||
@ -31,121 +31,69 @@ class QTextDocument;
|
|||||||
namespace lyx {
|
namespace lyx {
|
||||||
namespace frontend {
|
namespace frontend {
|
||||||
|
|
||||||
class ControlViewSource;
|
class GuiViewSource;
|
||||||
class LaTeXHighlighter;
|
class LaTeXHighlighter;
|
||||||
|
|
||||||
class GuiViewSourceDialog : public QWidget, public Ui::ViewSourceUi
|
class ViewSourceWidget : public QWidget, public Ui::ViewSourceUi
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GuiViewSourceDialog(ControlViewSource &);
|
ViewSourceWidget(GuiViewSource &);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
// update content
|
// update content
|
||||||
void updateView();
|
void updateView();
|
||||||
///
|
///
|
||||||
QTextDocument * document() { return document_; }
|
|
||||||
///
|
|
||||||
void update(bool full_source);
|
void update(bool full_source);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
ControlViewSource & controller_;
|
GuiViewSource & controller_;
|
||||||
///
|
///
|
||||||
QTextDocument * document_;
|
QTextDocument * document_;
|
||||||
/// LaTeX syntax highlighter
|
/// LaTeX syntax highlighter
|
||||||
LaTeXHighlighter * highlighter_;
|
LaTeXHighlighter * highlighter_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* A controller for a read-only text browser.
|
class GuiViewSource : public DockView
|
||||||
*/
|
{
|
||||||
class ControlViewSource : public Controller {
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
///
|
GuiViewSource(
|
||||||
ControlViewSource(Dialog &);
|
GuiViewBase & parent, ///< the main window where to dock.
|
||||||
/** \param source source code to be displayed
|
Qt::DockWidgetArea area = Qt::BottomDockWidgetArea, ///< Position of the dock (and also drawer)
|
||||||
*/
|
Qt::WindowFlags flags = 0);
|
||||||
|
|
||||||
|
~GuiViewSource();
|
||||||
|
|
||||||
|
/// Controller inherited method.
|
||||||
|
///@{
|
||||||
bool initialiseParams(std::string const & source);
|
bool initialiseParams(std::string const & source);
|
||||||
///
|
|
||||||
void clearParams() {}
|
void clearParams() {}
|
||||||
///
|
|
||||||
void dispatchParams() {}
|
void dispatchParams() {}
|
||||||
///
|
|
||||||
bool isBufferDependent() const { return true; }
|
bool isBufferDependent() const { return true; }
|
||||||
///
|
|
||||||
bool canApply() const { return true; }
|
bool canApply() const { return true; }
|
||||||
///
|
|
||||||
bool canApplyToReadOnly() const { return true; }
|
bool canApplyToReadOnly() const { return true; }
|
||||||
|
void updateView();
|
||||||
|
///@}
|
||||||
|
|
||||||
/// The title displayed by the dialog reflects source type.
|
/// The title displayed by the dialog reflects source type.
|
||||||
docstring const title() const;
|
QString title() const;
|
||||||
|
|
||||||
/** get the source code of selected paragraphs, or the whole document
|
/** get the source code of selected paragraphs, or the whole document
|
||||||
\param fullSource get full source code
|
\param fullSource get full source code
|
||||||
*/
|
*/
|
||||||
docstring const updateContent(bool fullSource);
|
QString getContent(bool fullSource);
|
||||||
/** get the cursor position in the source code
|
/** get the cursor position in the source code
|
||||||
*/
|
*/
|
||||||
std::pair<int, int> getRows() const;
|
std::pair<int, int> getRows() const;
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class GuiViewSource : public QDockWidget, public Dialog
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GuiViewSource(GuiViewBase & parent)
|
|
||||||
: QDockWidget(&parent, Qt::WindowFlags(0)), name_("view-source")
|
|
||||||
{
|
|
||||||
ControlViewSource * c = new ControlViewSource(*this);
|
|
||||||
controller_ = c;
|
|
||||||
controller_->setLyXView(parent);
|
|
||||||
widget_ = new GuiViewSourceDialog(*c);
|
|
||||||
setWidget(widget_);
|
|
||||||
setWindowTitle(widget_->windowTitle());
|
|
||||||
parent.addDockWidget(Qt::BottomDockWidgetArea, this);
|
|
||||||
}
|
|
||||||
~GuiViewSource() { delete widget_; delete controller_; }
|
|
||||||
|
|
||||||
/// Dialog inherited methods
|
|
||||||
//@{
|
|
||||||
void applyView() {}
|
|
||||||
void hideView() { QDockWidget::hide(); }
|
|
||||||
void showData(std::string const & data)
|
|
||||||
{
|
|
||||||
controller_->initialiseParams(data);
|
|
||||||
showView();
|
|
||||||
}
|
|
||||||
void showView()
|
|
||||||
{
|
|
||||||
widget_->updateView(); // make sure its up-to-date
|
|
||||||
QDockWidget::show();
|
|
||||||
}
|
|
||||||
bool isVisibleView() const { return QDockWidget::isVisible(); }
|
|
||||||
void checkStatus() { updateView(); }
|
|
||||||
void redraw() { redrawView(); }
|
|
||||||
void redrawView() {}
|
|
||||||
void updateData(std::string const & data)
|
|
||||||
{
|
|
||||||
controller_->initialiseParams(data);
|
|
||||||
updateView();
|
|
||||||
}
|
|
||||||
void updateView()
|
|
||||||
{
|
|
||||||
widget_->updateView();
|
|
||||||
QDockWidget::update();
|
|
||||||
}
|
|
||||||
bool isClosing() const { return false; }
|
|
||||||
void partialUpdateView(int /*id*/) {}
|
|
||||||
Controller & controller() { return *controller_; }
|
|
||||||
std::string name() const { return name_; }
|
|
||||||
//@}
|
|
||||||
private:
|
private:
|
||||||
/// The encapsulated widget.
|
/// The encapsulated widget.
|
||||||
GuiViewSourceDialog * widget_;
|
ViewSourceWidget * widget_;
|
||||||
Controller * controller_;
|
|
||||||
std::string name_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
|
Loading…
Reference in New Issue
Block a user