]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiViewSource.h
Consider class-provided citation engines
[lyx.git] / src / frontends / qt4 / GuiViewSource.h
index cd96789be654ec54fd26680b2fb7d11bc06d9c14..48f2903b74dce98bddabcbf04b56799eeb8c1c43 100644 (file)
 
 #include "ui_ViewSourceUi.h"
 
-#include "Dialog.h"
-#include "GuiView.h"
-#include "qt_helpers.h"
-#include "debug.h"
+#include "Buffer.h"
+#include "DockView.h"
 
 #include <QDockWidget>
-#include <QWidget>
-#include <QSyntaxHighlighter>
-#include <QTextCharFormat>
+#include <QString>
+#include <QTimer>
+
 
 class QTextDocument;
 
+
 namespace lyx {
+
+class TexRow;
+
+
 namespace frontend {
 
-class ControlViewSource;
+class GuiViewSource;
 class LaTeXHighlighter;
 
-class GuiViewSourceDialog : public QWidget, public Ui::ViewSourceUi
+
+class ViewSourceWidget : public QWidget, public Ui::ViewSourceUi
 {
        Q_OBJECT
 
 public:
-       GuiViewSourceDialog(ControlViewSource &);
+       ViewSourceWidget(QWidget * parent);
+       /// returns true if the string has changed
+       bool setText(QString const & qstr = QString());
+       ///
+       void saveSession(QSettings & settings, QString const & session_key) const;
+       ///
+       void restoreSession(QString const & session_key);
+       ///
+       int updateDelay() const;
+
+protected:
+       ///
+       void resizeEvent (QResizeEvent * event);
 
 public Q_SLOTS:
-       // update content
-       void updateView();
        ///
-       QTextDocument * document() { return document_; }
+       void updateView(BufferView const * bv);
+       ///
+       void setViewFormat(int const index);
+       //
+       void updateDefaultFormat(BufferView const & bv);
        ///
-       void update(bool full_source);
+       void contentsChanged();
+       ///
+       void goToCursor() const;
+       /// Name of the current format. Empty if none.
+       docstring currentFormatName(BufferView const * bv) const;
+
+Q_SIGNALS:
+       void needUpdate() const;
 
 private:
-       ///
-       ControlViewSource & controller_;        
+       /// 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_;
 };
 
-/**
- * A controller for a read-only text browser.
- */
-class ControlViewSource : public Controller {
+
+class GuiViewSource : public DockView
+{
+       Q_OBJECT
+
 public:
-       ///
-       ControlViewSource(Dialog &);
-       /** \param source source code to be displayed
-        */
+       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(QSettings & settings) 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.
-       docstring const title() const;
-
-       /** get the source code of selected paragraphs, or the whole document
-               \param fullSource get full source code
-        */
-       docstring const updateContent(bool fullSource);
-       /** get the cursor position in the source code
-        */
-       std::pair<int, int> getRows() const;
-};
+       void updateTitle();
+       /// schedule an update after delay
+       void scheduleUpdate();
+       /// schedule an update now
+       void scheduleUpdateNow();
 
+       /// update content
+       void realUpdateView();
 
-class GuiViewSource : public QDockWidget, public Dialog
-{
-public:
-       GuiViewSource(GuiViewBase & parent)
-               : QDockWidget(&parent, Qt::WindowFlags(0)), name_("view-source")
-       {
-               ControlViewSource * c = new ControlViewSource(*this);
-               controller_ = c;
-               controller_->setLyXView(parent);
-               widget_ = new GuiViewSourceDialog(*c);
-               setWidget(widget_);
-               setWindowTitle(widget_->windowTitle());
-               parent.addDockWidget(Qt::BottomDockWidgetArea, this);
-       }
-       ~GuiViewSource() { delete widget_; delete controller_; }
-
-       /// Dialog inherited methods
-       //@{
-       void applyView() {}
-       void hideView() { QDockWidget::hide(); }
-       void showData(std::string const & data)
-       {
-               controller_->initialiseParams(data);
-               showView();
-       }
-       void showView()
-       {
-               widget_->updateView();  // make sure its up-to-date
-               QDockWidget::show();
-       }
-       bool isVisibleView() const { return QDockWidget::isVisible(); }
-       void checkStatus() { updateView(); }
-       void redraw() { redrawView(); }
-       void redrawView() {}
-       void updateData(std::string const & data)
-       {
-               controller_->initialiseParams(data);
-               updateView();
-       }
-       void updateView()
-       {
-               widget_->updateView();
-               QDockWidget::update();
-       }
-       bool isClosing() const { return false; }
-       void partialUpdateView(int /*id*/) {}
-       Controller & controller() { return *controller_; }
-       std::string name() const { return name_; }
-       //@}
 private:
        /// The encapsulated widget.
-       GuiViewSourceDialog * widget_;
-       Controller * controller_;
-       std::string name_;
+       ViewSourceWidget * widget_;
+       ///
+       QTimer * update_timer_;
 };
 
 } // namespace frontend