]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiViewSource.h
Speed up exit time
[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(QSettings & settings, 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         void gotoCursor();
67         /// Name of the current format. Empty if none.
68         docstring currentFormatName(BufferView const * bv) const;
69
70 Q_SIGNALS:
71         void formatChanged() const;
72
73 private Q_SLOTS:
74         /// update content
75         void realUpdateView();
76
77 private:
78         /// Get the source code of selected paragraphs, or the whole document.
79         void getContent(BufferView const * view, Buffer::OutputWhat output,
80                            docstring & str, std::string const & format, bool master);
81         ///
82         BufferView const * bv_;
83         ///
84         QTextDocument * document_;
85         /// LaTeX syntax highlighter
86         LaTeXHighlighter * highlighter_;
87         ///
88         std::string view_format_;
89         ///
90         QTimer * update_timer_;
91         /// TexRow information from the last source view. If TexRow is unavailable
92         /// for the last format then texrow_ is null.
93         std::auto_ptr<TexRow> texrow_;
94 };
95
96
97 class GuiViewSource : public DockView
98 {
99         Q_OBJECT
100
101 public:
102         GuiViewSource(
103                 GuiView & parent, ///< the main window where to dock.
104                 Qt::DockWidgetArea area = Qt::BottomDockWidgetArea, ///< Position of the dock (and also drawer)
105                 Qt::WindowFlags flags = 0);
106
107         ~GuiViewSource();
108
109         /// Controller inherited method.
110         ///@{
111         bool initialiseParams(std::string const & source);
112         void clearParams() {}
113         void dispatchParams() {}
114         bool isBufferDependent() const { return true; }
115         bool canApply() const { return true; }
116         bool canApplyToReadOnly() const { return true; }
117         void updateView();
118         void enableView(bool enable);
119         void saveSession(QSettings & settings) const;
120         void restoreSession();
121         bool wantInitialFocus() const { return false; }
122         ///@}
123
124 private Q_SLOTS:
125         /// The title displayed by the dialog reflects source type.
126         void updateTitle();
127
128 private:
129         /// The encapsulated widget.
130         ViewSourceWidget * widget_;
131 };
132
133 } // namespace frontend
134 } // namespace lyx
135
136 #endif // GUIVIEWSOURCE_H