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