mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-27 03:36:39 +00:00
* GuiViewSource: port back to DockView.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20866 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
17ffac2ae9
commit
c1472a5c78
@ -33,7 +33,7 @@ using std::string;
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
GuiViewSourceDialog::GuiViewSourceDialog(ControlViewSource & controller)
|
||||
ViewSourceWidget::ViewSourceWidget(GuiViewSource & controller)
|
||||
: controller_(controller), document_(new QTextDocument(this)),
|
||||
highlighter_(new LaTeXHighlighter(document_))
|
||||
{
|
||||
@ -49,9 +49,9 @@ GuiViewSourceDialog::GuiViewSourceDialog(ControlViewSource & controller)
|
||||
|
||||
// setting a document at this point trigger an assertion in Qt
|
||||
// so we disable the signals here:
|
||||
document()->blockSignals(true);
|
||||
viewSourceTV->setDocument(document());
|
||||
document()->blockSignals(false);
|
||||
document_->blockSignals(true);
|
||||
viewSourceTV->setDocument(document_);
|
||||
document_->blockSignals(false);
|
||||
viewSourceTV->setReadOnly(true);
|
||||
///dialog_->viewSourceTV->setAcceptRichText(false);
|
||||
// this is personal. I think source code should be in fixed-size font
|
||||
@ -65,7 +65,7 @@ GuiViewSourceDialog::GuiViewSourceDialog(ControlViewSource & controller)
|
||||
}
|
||||
|
||||
|
||||
void GuiViewSourceDialog::updateView()
|
||||
void ViewSourceWidget::updateView()
|
||||
{
|
||||
if (autoUpdateCB->isChecked())
|
||||
update(viewFullSourceCB->isChecked());
|
||||
@ -77,28 +77,44 @@ void GuiViewSourceDialog::updateView()
|
||||
c.select(QTextCursor::BlockUnderCursor);
|
||||
c.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor, end - beg + 1);
|
||||
viewSourceTV->setTextCursor(c);
|
||||
QWidget::update();
|
||||
}
|
||||
|
||||
|
||||
void GuiViewSourceDialog::update(bool full_source)
|
||||
void ViewSourceWidget::update(bool full_source)
|
||||
{
|
||||
document_->setPlainText(toqstr(controller_.updateContent(full_source)));
|
||||
document_->setPlainText(controller_.getContent(full_source));
|
||||
}
|
||||
|
||||
|
||||
ControlViewSource::ControlViewSource(Dialog & parent)
|
||||
: Controller(parent)
|
||||
{}
|
||||
|
||||
|
||||
bool ControlViewSource::initialiseParams(string const & /*source*/)
|
||||
GuiViewSource::GuiViewSource(GuiViewBase & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
|
||||
: DockView(parent, "view-source", area, flags)
|
||||
{
|
||||
widget_ = new ViewSourceWidget(*this);
|
||||
setWidget(widget_);
|
||||
setWindowTitle(widget_->windowTitle());
|
||||
}
|
||||
|
||||
|
||||
GuiViewSource::~GuiViewSource()
|
||||
{
|
||||
delete widget_;
|
||||
}
|
||||
|
||||
|
||||
void GuiViewSource::updateView()
|
||||
{
|
||||
widget_->updateView();
|
||||
}
|
||||
|
||||
|
||||
bool GuiViewSource::initialiseParams(string const & /*source*/)
|
||||
{
|
||||
setWindowTitle(title());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
docstring const ControlViewSource::updateContent(bool fullSource)
|
||||
QString GuiViewSource::getContent(bool fullSource)
|
||||
{
|
||||
// get the *top* level paragraphs that contain the cursor,
|
||||
// or the selected text
|
||||
@ -117,11 +133,11 @@ docstring const ControlViewSource::updateContent(bool fullSource)
|
||||
std::swap(par_begin, par_end);
|
||||
odocstringstream ostr;
|
||||
view->buffer().getSourceCode(ostr, par_begin, par_end + 1, fullSource);
|
||||
return ostr.str();
|
||||
return toqstr(ostr.str());
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, int> ControlViewSource::getRows() const
|
||||
std::pair<int, int> GuiViewSource::getRows() const
|
||||
{
|
||||
BufferView const * view = bufferview();
|
||||
CursorSlice beg = view->cursor().selectionBegin().bottom();
|
||||
@ -137,19 +153,18 @@ std::pair<int, int> ControlViewSource::getRows() const
|
||||
}
|
||||
|
||||
|
||||
docstring const ControlViewSource::title() const
|
||||
QString GuiViewSource::title() const
|
||||
{
|
||||
switch (docType()) {
|
||||
case LATEX:
|
||||
return _("LaTeX Source");
|
||||
return qt_("LaTeX Source");
|
||||
case DOCBOOK:
|
||||
return _("DocBook Source");
|
||||
return qt_("DocBook Source");
|
||||
case LITERATE:
|
||||
return _("Literate Source");
|
||||
default:
|
||||
BOOST_ASSERT(false);
|
||||
return docstring();
|
||||
return qt_("Literate Source");
|
||||
}
|
||||
BOOST_ASSERT(false);
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,14 +16,14 @@
|
||||
|
||||
#include "ui_ViewSourceUi.h"
|
||||
|
||||
#include "Dialog.h"
|
||||
#include "DockView.h"
|
||||
#include "GuiView.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#include <QDockWidget>
|
||||
#include <QWidget>
|
||||
#include <QSyntaxHighlighter>
|
||||
#include <QString>
|
||||
#include <QTextCharFormat>
|
||||
|
||||
class QTextDocument;
|
||||
@ -31,121 +31,69 @@ class QTextDocument;
|
||||
namespace lyx {
|
||||
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(GuiViewSource &);
|
||||
|
||||
public Q_SLOTS:
|
||||
// update content
|
||||
void updateView();
|
||||
///
|
||||
QTextDocument * document() { return document_; }
|
||||
///
|
||||
void update(bool full_source);
|
||||
|
||||
private:
|
||||
///
|
||||
ControlViewSource & controller_;
|
||||
GuiViewSource & controller_;
|
||||
///
|
||||
QTextDocument * document_;
|
||||
/// LaTeX syntax highlighter
|
||||
LaTeXHighlighter * highlighter_;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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(
|
||||
GuiViewBase & parent, ///< the main window where to dock.
|
||||
Qt::DockWidgetArea area = Qt::BottomDockWidgetArea, ///< Position of the dock (and also drawer)
|
||||
Qt::WindowFlags flags = 0);
|
||||
|
||||
~GuiViewSource();
|
||||
|
||||
/// 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();
|
||||
///@}
|
||||
|
||||
/// The title displayed by the dialog reflects source type.
|
||||
docstring const title() const;
|
||||
QString title() const;
|
||||
|
||||
/** get the source code of selected paragraphs, or the whole document
|
||||
\param fullSource get full source code
|
||||
*/
|
||||
docstring const updateContent(bool fullSource);
|
||||
QString getContent(bool fullSource);
|
||||
/** get the cursor position in the source code
|
||||
*/
|
||||
std::pair<int, int> getRows() const;
|
||||
};
|
||||
|
||||
|
||||
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_;
|
||||
};
|
||||
|
||||
} // namespace frontend
|
||||
|
Loading…
Reference in New Issue
Block a user