2006-04-15 14:13:41 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiViewSource.h
|
2006-04-15 14:13:41 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Bo Peng
|
2007-03-25 01:25:29 +00:00
|
|
|
* \author Abdelrazak Younes
|
2006-04-15 14:13:41 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#ifndef GUIVIEWSOURCE_H
|
|
|
|
#define GUIVIEWSOURCE_H
|
2006-04-15 14:13:41 +00:00
|
|
|
|
2007-08-11 15:48:15 +00:00
|
|
|
#include "ui_ViewSourceUi.h"
|
2007-02-13 18:27:46 +00:00
|
|
|
|
2015-08-04 22:16:40 +00:00
|
|
|
#include "Buffer.h"
|
2007-10-09 09:43:56 +00:00
|
|
|
#include "DockView.h"
|
|
|
|
|
2007-10-06 15:03:58 +00:00
|
|
|
#include <QDockWidget>
|
2007-10-09 09:43:56 +00:00
|
|
|
#include <QString>
|
2015-07-31 00:05:54 +00:00
|
|
|
#include <QTimer>
|
2007-04-24 14:08:53 +00:00
|
|
|
|
2016-06-19 02:39:38 +00:00
|
|
|
|
2007-04-24 14:08:53 +00:00
|
|
|
class QTextDocument;
|
2006-04-15 14:13:41 +00:00
|
|
|
|
2016-06-19 02:39:38 +00:00
|
|
|
|
2006-04-15 14:13:41 +00:00
|
|
|
namespace lyx {
|
2016-06-19 02:39:38 +00:00
|
|
|
|
|
|
|
class TexRow;
|
|
|
|
|
|
|
|
|
2006-04-15 14:13:41 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
2007-10-09 09:43:56 +00:00
|
|
|
class GuiViewSource;
|
2007-10-06 19:03:41 +00:00
|
|
|
class LaTeXHighlighter;
|
2007-04-24 14:08:53 +00:00
|
|
|
|
2016-06-19 02:39:38 +00:00
|
|
|
|
2007-10-09 09:43:56 +00:00
|
|
|
class ViewSourceWidget : public QWidget, public Ui::ViewSourceUi
|
2007-09-05 20:33:29 +00:00
|
|
|
{
|
2007-03-25 01:25:29 +00:00
|
|
|
Q_OBJECT
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-03-25 01:25:29 +00:00
|
|
|
public:
|
2008-10-18 13:20:17 +00:00
|
|
|
ViewSourceWidget();
|
|
|
|
///
|
|
|
|
void setBufferView(BufferView const * bv);
|
2015-08-04 22:16:40 +00:00
|
|
|
/// returns true if the string has changed
|
|
|
|
bool setText(QString const & qstr = QString());
|
2015-07-31 00:05:54 +00:00
|
|
|
///
|
|
|
|
void saveSession(QString const & session_key) const;
|
|
|
|
///
|
|
|
|
void restoreSession(QString const & session_key);
|
2007-04-24 14:08:53 +00:00
|
|
|
|
2013-05-06 21:50:23 +00:00
|
|
|
protected:
|
|
|
|
///
|
|
|
|
void resizeEvent (QResizeEvent * event);
|
|
|
|
|
2007-04-24 14:08:53 +00:00
|
|
|
public Q_SLOTS:
|
2015-07-31 00:05:54 +00:00
|
|
|
/// schedule an update after delay
|
2007-09-03 20:28:26 +00:00
|
|
|
void updateView();
|
2015-07-31 00:05:54 +00:00
|
|
|
/// schedule an update now
|
|
|
|
void updateViewNow();
|
2010-12-10 10:34:24 +00:00
|
|
|
///
|
2015-07-31 00:05:54 +00:00
|
|
|
void setViewFormat(int const index);
|
|
|
|
//
|
2010-12-10 10:34:24 +00:00
|
|
|
void updateDefaultFormat();
|
2011-01-04 00:00:20 +00:00
|
|
|
///
|
2011-10-29 21:00:23 +00:00
|
|
|
void contentsChanged();
|
2015-10-11 13:50:32 +00:00
|
|
|
///
|
|
|
|
void gotoCursor();
|
2016-08-28 20:57:17 +00:00
|
|
|
/// Name of the current format. Empty if none.
|
2016-09-28 19:57:54 +00:00
|
|
|
docstring currentFormatName(BufferView const * bv) const;
|
2016-08-28 20:57:17 +00:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void formatChanged() const;
|
2007-03-25 01:25:29 +00:00
|
|
|
|
2015-07-31 00:05:54 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
/// update content
|
|
|
|
void realUpdateView();
|
|
|
|
|
2007-03-25 01:25:29 +00:00
|
|
|
private:
|
2015-08-04 22:16:40 +00:00
|
|
|
/// Get the source code of selected paragraphs, or the whole document.
|
2015-10-11 13:50:32 +00:00
|
|
|
void getContent(BufferView const * view, Buffer::OutputWhat output,
|
|
|
|
docstring & str, std::string const & format, bool master);
|
2007-09-05 20:33:29 +00:00
|
|
|
///
|
2008-10-18 13:20:17 +00:00
|
|
|
BufferView const * bv_;
|
2007-03-25 01:25:29 +00:00
|
|
|
///
|
|
|
|
QTextDocument * document_;
|
2007-04-24 14:08:53 +00:00
|
|
|
/// LaTeX syntax highlighter
|
|
|
|
LaTeXHighlighter * highlighter_;
|
2011-01-04 00:00:20 +00:00
|
|
|
///
|
2016-08-28 20:57:17 +00:00
|
|
|
std::string view_format_;
|
2015-07-31 00:05:54 +00:00
|
|
|
///
|
|
|
|
QTimer * update_timer_;
|
2015-10-11 13:50:32 +00:00
|
|
|
/// TexRow information from the last source view. If TexRow is unavailable
|
|
|
|
/// for the last format then texrow_ is null.
|
2016-06-02 20:58:52 +00:00
|
|
|
unique_ptr<TexRow> texrow_;
|
2007-03-25 01:25:29 +00:00
|
|
|
};
|
|
|
|
|
2007-10-09 09:43:56 +00:00
|
|
|
|
|
|
|
class GuiViewSource : public DockView
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2007-10-06 15:03:58 +00:00
|
|
|
public:
|
2007-10-09 09:43:56 +00:00
|
|
|
GuiViewSource(
|
2007-11-05 13:52:37 +00:00
|
|
|
GuiView & parent, ///< the main window where to dock.
|
2007-10-09 09:43:56 +00:00
|
|
|
Qt::DockWidgetArea area = Qt::BottomDockWidgetArea, ///< Position of the dock (and also drawer)
|
|
|
|
Qt::WindowFlags flags = 0);
|
|
|
|
|
|
|
|
~GuiViewSource();
|
|
|
|
|
|
|
|
/// Controller inherited method.
|
|
|
|
///@{
|
2007-10-06 15:03:58 +00:00
|
|
|
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; }
|
2007-10-09 09:43:56 +00:00
|
|
|
void updateView();
|
2008-05-13 21:28:04 +00:00
|
|
|
void enableView(bool enable);
|
2008-05-14 14:24:55 +00:00
|
|
|
void saveSession() const;
|
|
|
|
void restoreSession();
|
2008-06-09 14:52:38 +00:00
|
|
|
bool wantInitialFocus() const { return false; }
|
2007-10-09 09:43:56 +00:00
|
|
|
///@}
|
2007-10-06 15:03:58 +00:00
|
|
|
|
2016-08-28 20:57:17 +00:00
|
|
|
private Q_SLOTS:
|
2007-10-06 15:03:58 +00:00
|
|
|
/// The title displayed by the dialog reflects source type.
|
2016-08-28 20:57:17 +00:00
|
|
|
void updateTitle();
|
2007-10-06 15:03:58 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// The encapsulated widget.
|
2007-10-09 09:43:56 +00:00
|
|
|
ViewSourceWidget * widget_;
|
2007-10-06 15:03:58 +00:00
|
|
|
};
|
2006-04-15 14:13:41 +00:00
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#endif // GUIVIEWSOURCE_H
|