]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiViewSource.h
7b451a6bf6b9ed768ebc65c75fe82976853ce4ab
[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 "Buffer.h"
20 #include "DockView.h"
21 #include "TexRow.h"
22
23 #include <QDockWidget>
24 #include <QString>
25 #include <QTimer>
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();
41         ///
42         void setBufferView(BufferView const * bv);
43         /// returns true if the string has changed
44         bool setText(QString const & qstr = QString());
45         ///
46         void saveSession(QString const & session_key) const;
47         ///
48         void restoreSession(QString const & session_key);
49
50 protected:
51         ///
52         void resizeEvent (QResizeEvent * event);
53
54 public Q_SLOTS:
55         /// schedule an update after delay
56         void updateView();
57         /// schedule an update now
58         void updateViewNow();
59         ///
60         void setViewFormat(int const index);
61         //
62         void updateDefaultFormat();
63         ///
64         void contentsChanged();
65
66 private Q_SLOTS:
67         /// update content
68         void realUpdateView();
69
70 private:
71         /// Get the source code of selected paragraphs, or the whole document.
72         /// If TexRow is unavailable for the format then t is null.
73         std::auto_ptr<TexRow> getContent(BufferView const * view,
74                                                                          Buffer::OutputWhat output, docstring & str,
75                                                                          std::string const & format, bool master);
76         ///
77         BufferView const * bv_;
78         ///
79         QTextDocument * document_;
80         /// LaTeX syntax highlighter
81         LaTeXHighlighter * highlighter_;
82         ///
83         QString view_format_;
84         ///
85         QTimer * update_timer_;
86 };
87
88
89 class GuiViewSource : public DockView
90 {
91         Q_OBJECT
92
93 public:
94         GuiViewSource(
95                 GuiView & parent, ///< the main window where to dock.
96                 Qt::DockWidgetArea area = Qt::BottomDockWidgetArea, ///< Position of the dock (and also drawer)
97                 Qt::WindowFlags flags = 0);
98
99         ~GuiViewSource();
100
101         /// Controller inherited method.
102         ///@{
103         bool initialiseParams(std::string const & source);
104         void clearParams() {}
105         void dispatchParams() {}
106         bool isBufferDependent() const { return true; }
107         bool canApply() const { return true; }
108         bool canApplyToReadOnly() const { return true; }
109         void updateView();
110         void enableView(bool enable);
111         void saveSession() const;
112         void restoreSession();
113         bool wantInitialFocus() const { return false; }
114         ///@}
115
116         /// The title displayed by the dialog reflects source type.
117         QString title() const;
118
119 private:
120         /// The encapsulated widget.
121         ViewSourceWidget * widget_;
122 };
123
124 } // namespace frontend
125 } // namespace lyx
126
127 #endif // GUIVIEWSOURCE_H