2006-04-15 14:13:41 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiViewSource.h
|
2006-04-15 14:13:41 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Bo Peng
|
2007-03-25 01:25:29 +00:00
|
|
|
* \author Abdelrazak Younes
|
2006-04-15 14:13:41 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#ifndef GUIVIEWSOURCE_H
|
|
|
|
#define GUIVIEWSOURCE_H
|
2006-04-15 14:13:41 +00:00
|
|
|
|
2007-08-11 15:48:15 +00:00
|
|
|
#include "ui_ViewSourceUi.h"
|
2007-02-13 18:27:46 +00:00
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
#include "Dialog.h"
|
2007-10-06 15:03:58 +00:00
|
|
|
#include "GuiView.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
#include "debug.h"
|
2007-09-08 16:36:53 +00:00
|
|
|
|
2007-10-06 15:03:58 +00:00
|
|
|
#include <QDockWidget>
|
2007-04-24 14:08:53 +00:00
|
|
|
#include <QWidget>
|
2006-04-15 14:13:41 +00:00
|
|
|
#include <QSyntaxHighlighter>
|
2007-03-25 01:25:29 +00:00
|
|
|
#include <QTextCharFormat>
|
2007-04-24 14:08:53 +00:00
|
|
|
|
|
|
|
class QTextDocument;
|
2006-04-15 14:13:41 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-10-06 15:03:58 +00:00
|
|
|
class ControlViewSource;
|
2007-10-06 19:03:41 +00:00
|
|
|
class LaTeXHighlighter;
|
2007-04-24 14:08:53 +00:00
|
|
|
|
2007-09-08 16:04:25 +00:00
|
|
|
class GuiViewSourceDialog : public QWidget, public Ui::ViewSourceUi
|
2007-09-05 20:33:29 +00:00
|
|
|
{
|
2007-03-25 01:25:29 +00:00
|
|
|
Q_OBJECT
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-03-25 01:25:29 +00:00
|
|
|
public:
|
2007-09-08 16:04:25 +00:00
|
|
|
GuiViewSourceDialog(ControlViewSource &);
|
2007-04-24 14:08:53 +00:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
// update content
|
2007-09-03 20:28:26 +00:00
|
|
|
void updateView();
|
2007-04-24 14:08:53 +00:00
|
|
|
///
|
|
|
|
QTextDocument * document() { return document_; }
|
|
|
|
///
|
2007-03-25 01:25:29 +00:00
|
|
|
void update(bool full_source);
|
|
|
|
|
|
|
|
private:
|
2007-09-05 20:33:29 +00:00
|
|
|
///
|
2007-09-08 16:04:25 +00:00
|
|
|
ControlViewSource & controller_;
|
2007-03-25 01:25:29 +00:00
|
|
|
///
|
|
|
|
QTextDocument * document_;
|
2007-04-24 14:08:53 +00:00
|
|
|
/// LaTeX syntax highlighter
|
|
|
|
LaTeXHighlighter * highlighter_;
|
2007-03-25 01:25:29 +00:00
|
|
|
};
|
|
|
|
|
2007-10-06 15:03:58 +00:00
|
|
|
/**
|
|
|
|
* A controller for a read-only text browser.
|
|
|
|
*/
|
|
|
|
class ControlViewSource : public Controller {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
ControlViewSource(Dialog &);
|
|
|
|
/** \param source source code to be displayed
|
|
|
|
*/
|
|
|
|
bool initialiseParams(std::string const & source);
|
|
|
|
///
|
|
|
|
void clearParams() {}
|
|
|
|
///
|
|
|
|
void dispatchParams() {}
|
|
|
|
///
|
|
|
|
bool isBufferDependent() const { return true; }
|
|
|
|
///
|
|
|
|
bool canApply() const { return true; }
|
|
|
|
///
|
|
|
|
bool canApplyToReadOnly() const { return true; }
|
|
|
|
|
|
|
|
/// The title displayed by the dialog reflects source type.
|
|
|
|
docstring const title() const;
|
|
|
|
|
|
|
|
/** get the source code of selected paragraphs, or the whole document
|
|
|
|
\param fullSource get full source code
|
|
|
|
*/
|
|
|
|
docstring const updateContent(bool fullSource);
|
|
|
|
/** get the cursor position in the source code
|
|
|
|
*/
|
|
|
|
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:
|
|
|
|
/// The encapsulated widget.
|
|
|
|
GuiViewSourceDialog * widget_;
|
|
|
|
Controller * controller_;
|
|
|
|
std::string name_;
|
|
|
|
};
|
2006-04-15 14:13:41 +00:00
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#endif // GUIVIEWSOURCE_H
|