]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiViewSource.h
Skip paint event when in the middle of a buffer operation
[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
22 #include <QDockWidget>
23 #include <QString>
24 #include <QTimer>
25
26
27 class QTextDocument;
28
29
30 namespace lyx {
31
32 class TexRow;
33
34
35 namespace frontend {
36
37 class GuiViewSource;
38 class LaTeXHighlighter;
39
40
41 class ViewSourceWidget : public QWidget, public Ui::ViewSourceUi
42 {
43         Q_OBJECT
44
45 public:
46         ViewSourceWidget(QWidget * parent);
47         /// returns true if the string has changed
48         bool setText(QString const & qstr = QString());
49         ///
50         void saveSession(QSettings & settings, QString const & session_key) const;
51         ///
52         void restoreSession(QString const & session_key);
53         ///
54         int updateDelay() const;
55
56 protected:
57         ///
58         void resizeEvent (QResizeEvent * event);
59
60 public Q_SLOTS:
61         ///
62         void updateView(BufferView const * bv);
63         ///
64         void setViewFormat(int const index);
65         //
66         void updateDefaultFormat(BufferView const & bv);
67         ///
68         void contentsChanged();
69         ///
70         void goToCursor() const;
71         /// Name of the current format. Empty if none.
72         docstring currentFormatName(BufferView const * bv) const;
73
74 Q_SIGNALS:
75         void needUpdate() const;
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         /// Grab double clicks on the viewport
82         bool eventFilter(QObject * obj, QEvent * event);
83         ///
84         QTextDocument * document_;
85         /// LaTeX syntax highlighter
86         LaTeXHighlighter * highlighter_;
87         ///
88         std::string view_format_;
89         /// TexRow information from the last source view. If TexRow is unavailable
90         /// for the last format then texrow_ is null.
91         unique_ptr<TexRow> texrow_;
92 };
93
94
95 class GuiViewSource : public DockView
96 {
97         Q_OBJECT
98
99 public:
100         GuiViewSource(
101                 GuiView & parent, ///< the main window where to dock.
102                 Qt::DockWidgetArea area = Qt::BottomDockWidgetArea, ///< Position of the dock (and also drawer)
103                 Qt::WindowFlags flags = 0);
104
105         /// Controller inherited method.
106         ///@{
107         bool initialiseParams(std::string const & source);
108         void clearParams() {}
109         void dispatchParams() {}
110         bool isBufferDependent() const { return true; }
111         bool canApply() const { return true; }
112         bool canApplyToReadOnly() const { return true; }
113         void updateView();
114         void enableView(bool enable);
115         void saveSession(QSettings & settings) const;
116         void restoreSession();
117         bool wantInitialFocus() const { return false; }
118         ///@}
119
120 public Q_SLOTS:
121         ///
122         void onBufferViewChanged();//override
123
124 private Q_SLOTS:
125         /// The title displayed by the dialog reflects source type.
126         void updateTitle();
127         /// schedule an update after delay
128         void scheduleUpdate();
129         /// schedule an update now
130         void scheduleUpdateNow();
131
132         /// update content
133         void realUpdateView();
134
135 private:
136         /// The encapsulated widget.
137         ViewSourceWidget * widget_;
138         ///
139         QTimer * update_timer_;
140 };
141
142 } // namespace frontend
143 } // namespace lyx
144
145 #endif // GUIVIEWSOURCE_H