]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiViewSource.h
9f460aa105443ddd38904b784e2602f7ccad4e3c
[lyx.git] / src / frontends / qt4 / GuiViewSource.h
1 // -*- C++ -*-
2 /**
3  * \file GuiViewSource.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  * \author Bo Peng
9  * \author Abdelrazak Younes
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef GUIVIEWSOURCE_H
15 #define GUIVIEWSOURCE_H
16
17 #include "ui_ViewSourceUi.h"
18
19 #include "DockView.h"
20 #include "GuiView.h"
21 #include "qt_helpers.h"
22
23 #include <QDockWidget>
24 #include <QString>
25 #include <QTextCharFormat>
26
27 class QTextDocument;
28
29 namespace lyx {
30 namespace frontend {
31
32 class GuiViewSource;
33 class LaTeXHighlighter;
34
35 class ViewSourceWidget : public QWidget, public Ui::ViewSourceUi
36 {
37         Q_OBJECT
38
39 public:
40         ViewSourceWidget(GuiViewSource &);
41
42 public Q_SLOTS:
43         // update content
44         void updateView();
45
46 private:
47         ///
48         GuiViewSource & controller_;    
49         ///
50         QTextDocument * document_;
51         /// LaTeX syntax highlighter
52         LaTeXHighlighter * highlighter_;
53 };
54
55
56 class GuiViewSource : public DockView
57 {
58         Q_OBJECT
59
60 public:
61         GuiViewSource(
62                 GuiView & parent, ///< the main window where to dock.
63                 Qt::DockWidgetArea area = Qt::BottomDockWidgetArea, ///< Position of the dock (and also drawer)
64                 Qt::WindowFlags flags = 0);
65
66         ~GuiViewSource();
67
68         /// Controller inherited method.
69         ///@{
70         bool initialiseParams(std::string const & source);
71         void clearParams() {}
72         void dispatchParams() {}
73         bool isBufferDependent() const { return true; }
74         bool canApply() const { return true; }
75         bool canApplyToReadOnly() const { return true; }
76         void updateView();
77         void enableView(bool enable);
78         void saveSession() const;
79         void restoreSession();
80         ///@}
81
82         /// The title displayed by the dialog reflects source type.
83         QString title() const;
84
85         /** get the source code of selected paragraphs, or the whole document
86                 \param fullSource get full source code
87          */
88         QString getContent(bool fullSource);
89         // cursor position in the source code
90         struct Row { int begin; int end; };
91         Row getRows() const;
92
93 private:
94         /// The encapsulated widget.
95         ViewSourceWidget * widget_;
96 };
97
98 } // namespace frontend
99 } // namespace lyx
100
101 #endif // GUIVIEWSOURCE_H