3 * \file GuiViewSource.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * \author Abdelrazak Younes
11 * Full author contact details are available in file CREDITS.
14 #ifndef GUIVIEWSOURCE_H
15 #define GUIVIEWSOURCE_H
17 #include "ui_ViewSourceUi.h"
19 #include "controllers/Dialog.h"
21 #include "qt_helpers.h"
24 #include <QDockWidget>
26 #include <QSyntaxHighlighter>
27 #include <QTextCharFormat>
34 // used already twice...
35 class LaTeXHighlighter : public QSyntaxHighlighter
38 LaTeXHighlighter(QTextDocument * parent);
41 void highlightBlock(QString const & text);
44 QTextCharFormat commentFormat;
45 QTextCharFormat keywordFormat;
46 QTextCharFormat mathFormat;
49 class ControlViewSource;
51 class GuiViewSourceDialog : public QWidget, public Ui::ViewSourceUi
56 GuiViewSourceDialog(ControlViewSource &);
62 QTextDocument * document() { return document_; }
64 void update(bool full_source);
68 ControlViewSource & controller_;
70 QTextDocument * document_;
71 /// LaTeX syntax highlighter
72 LaTeXHighlighter * highlighter_;
76 * A controller for a read-only text browser.
78 class ControlViewSource : public Controller {
81 ControlViewSource(Dialog &);
82 /** \param source source code to be displayed
84 bool initialiseParams(std::string const & source);
88 void dispatchParams() {}
90 bool isBufferDependent() const { return true; }
92 bool canApply() const { return true; }
94 bool canApplyToReadOnly() const { return true; }
96 /// The title displayed by the dialog reflects source type.
97 docstring const title() const;
99 /** get the source code of selected paragraphs, or the whole document
100 \param fullSource get full source code
102 docstring const updateContent(bool fullSource);
103 /** get the cursor position in the source code
105 std::pair<int, int> getRows() const;
109 class GuiViewSource : public QDockWidget, public Dialog
112 GuiViewSource(GuiViewBase & parent)
113 : QDockWidget(&parent, Qt::WindowFlags(0)), name_("view-source")
115 ControlViewSource * c = new ControlViewSource(*this);
117 controller_->setLyXView(parent);
118 widget_ = new GuiViewSourceDialog(*c);
120 setWindowTitle(widget_->windowTitle());
121 parent.addDockWidget(Qt::BottomDockWidgetArea, this);
123 ~GuiViewSource() { delete widget_; delete controller_; }
125 /// Dialog inherited methods
128 void hideView() { QDockWidget::hide(); }
129 void showData(std::string const & data)
131 controller_->initialiseParams(data);
136 widget_->updateView(); // make sure its up-to-date
139 bool isVisibleView() const { return QDockWidget::isVisible(); }
140 void checkStatus() { updateView(); }
141 void redraw() { redrawView(); }
143 void updateData(std::string const & data)
145 controller_->initialiseParams(data);
150 widget_->updateView();
151 QDockWidget::update();
153 bool isClosing() const { return false; }
154 void partialUpdateView(int /*id*/) {}
155 Controller & controller() { return *controller_; }
156 std::string name() const { return name_; }
159 /// The encapsulated widget.
160 GuiViewSourceDialog * widget_;
161 Controller * controller_;
165 } // namespace frontend
168 #endif // GUIVIEWSOURCE_H