#ifndef GUIVIEWSOURCE_H
#define GUIVIEWSOURCE_H
-#include "ControlViewSource.h"
-#include "Application.h"
#include "ui_ViewSourceUi.h"
-#include <QWidget>
-#include <QSyntaxHighlighter>
-#include <QTextCharFormat>
+#include "Buffer.h"
+#include "DockView.h"
+
+#include <QDockWidget>
+#include <QString>
+#include <QTimer>
+
class QTextDocument;
-namespace lyx {
-namespace frontend {
-// used already twice...
-class LaTeXHighlighter : public QSyntaxHighlighter
-{
-public:
- LaTeXHighlighter(QTextDocument * parent);
+namespace lyx {
-protected:
- void highlightBlock(QString const & text);
+class TexRow;
-private:
- QTextCharFormat commentFormat;
- QTextCharFormat keywordFormat;
- QTextCharFormat mathFormat;
-};
+namespace frontend {
class GuiViewSource;
+class LaTeXHighlighter;
-class GuiViewSourceDialog : public QWidget, public Ui::ViewSourceUi {
- Q_OBJECT
-public:
- GuiViewSourceDialog(GuiViewSource * form);
-public Q_SLOTS:
- // update content
- void update();
+class ViewSourceWidget : public QWidget, public Ui::ViewSourceUi
+{
+ Q_OBJECT
-private:
- GuiViewSource * form_;
-};
+public:
+ ViewSourceWidget(QWidget * parent);
+ /// returns true if the string has changed
+ bool setText(QString const & qstr = QString());
+ ///
+ void saveSession(QString const & session_key) const;
+ ///
+ void restoreSession(QString const & session_key);
+ ///
+ int updateDelay() const;
+protected:
+ ///
+ void resizeEvent (QResizeEvent * event);
-///
-class GuiViewSource : public QObject, public ControlViewSource {
-public:
+public Q_SLOTS:
+ ///
+ void updateView(BufferView const * bv);
///
- GuiViewSource(Dialog &);
+ void setViewFormat(int const index);
+ //
+ void updateDefaultFormat(BufferView const & bv);
///
- QTextDocument * document() { return document_; }
+ void contentsChanged();
///
- void update(bool full_source);
+ void goToCursor() const;
+ /// Name of the current format. Empty if none.
+ docstring currentFormatName(BufferView const * bv) const;
+
+Q_SIGNALS:
+ void needUpdate() const;
private:
+ /// Get the source code of selected paragraphs, or the whole document.
+ void getContent(BufferView const & view, Buffer::OutputWhat output,
+ docstring & str, std::string const & format, bool master);
+ /// Grab double clicks on the viewport
+ bool eventFilter(QObject * obj, QEvent * event);
///
QTextDocument * document_;
/// LaTeX syntax highlighter
LaTeXHighlighter * highlighter_;
+ ///
+ std::string view_format_;
+ /// TexRow information from the last source view. If TexRow is unavailable
+ /// for the last format then texrow_ is null.
+ unique_ptr<TexRow> texrow_;
};
+class GuiViewSource : public DockView
+{
+ Q_OBJECT
+
+public:
+ GuiViewSource(
+ GuiView & parent, ///< the main window where to dock.
+ Qt::DockWidgetArea area = Qt::BottomDockWidgetArea, ///< Position of the dock (and also drawer)
+ Qt::WindowFlags flags = 0);
+
+ /// Controller inherited method.
+ ///@{
+ bool initialiseParams(std::string const & source);
+ void clearParams() {}
+ void dispatchParams() {}
+ bool isBufferDependent() const { return true; }
+ bool canApply() const { return true; }
+ bool canApplyToReadOnly() const { return true; }
+ void updateView();
+ void enableView(bool enable);
+ void saveSession() const;
+ void restoreSession();
+ bool wantInitialFocus() const { return false; }
+ ///@}
+
+public Q_SLOTS:
+ ///
+ void onBufferViewChanged();//override
+
+private Q_SLOTS:
+ /// The title displayed by the dialog reflects source type.
+ void updateTitle();
+ /// schedule an update after delay
+ void scheduleUpdate();
+ /// schedule an update now
+ void scheduleUpdateNow();
+
+ /// update content
+ void realUpdateView();
+
+private:
+ /// The encapsulated widget.
+ ViewSourceWidget * widget_;
+ ///
+ QTimer * update_timer_;
+};
+
} // namespace frontend
} // namespace lyx