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 class ControlViewSource;
35 class LaTeXHighlighter;
37 class GuiViewSourceDialog : public QWidget, public Ui::ViewSourceUi
42 GuiViewSourceDialog(ControlViewSource &);
48 QTextDocument * document() { return document_; }
50 void update(bool full_source);
54 ControlViewSource & controller_;
56 QTextDocument * document_;
57 /// LaTeX syntax highlighter
58 LaTeXHighlighter * highlighter_;
62 * A controller for a read-only text browser.
64 class ControlViewSource : public Controller {
67 ControlViewSource(Dialog &);
68 /** \param source source code to be displayed
70 bool initialiseParams(std::string const & source);
74 void dispatchParams() {}
76 bool isBufferDependent() const { return true; }
78 bool canApply() const { return true; }
80 bool canApplyToReadOnly() const { return true; }
82 /// The title displayed by the dialog reflects source type.
83 docstring const title() const;
85 /** get the source code of selected paragraphs, or the whole document
86 \param fullSource get full source code
88 docstring const updateContent(bool fullSource);
89 /** get the cursor position in the source code
91 std::pair<int, int> getRows() const;
95 class GuiViewSource : public QDockWidget, public Dialog
98 GuiViewSource(GuiViewBase & parent)
99 : QDockWidget(&parent, Qt::WindowFlags(0)), name_("view-source")
101 ControlViewSource * c = new ControlViewSource(*this);
103 controller_->setLyXView(parent);
104 widget_ = new GuiViewSourceDialog(*c);
106 setWindowTitle(widget_->windowTitle());
107 parent.addDockWidget(Qt::BottomDockWidgetArea, this);
109 ~GuiViewSource() { delete widget_; delete controller_; }
111 /// Dialog inherited methods
114 void hideView() { QDockWidget::hide(); }
115 void showData(std::string const & data)
117 controller_->initialiseParams(data);
122 widget_->updateView(); // make sure its up-to-date
125 bool isVisibleView() const { return QDockWidget::isVisible(); }
126 void checkStatus() { updateView(); }
127 void redraw() { redrawView(); }
129 void updateData(std::string const & data)
131 controller_->initialiseParams(data);
136 widget_->updateView();
137 QDockWidget::update();
139 bool isClosing() const { return false; }
140 void partialUpdateView(int /*id*/) {}
141 Controller & controller() { return *controller_; }
142 std::string name() const { return name_; }
145 /// The encapsulated widget.
146 GuiViewSourceDialog * widget_;
147 Controller * controller_;
151 } // namespace frontend
154 #endif // GUIVIEWSOURCE_H