From c1472a5c78a4afb059c408905da37590d635e296 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 9 Oct 2007 09:43:56 +0000 Subject: [PATCH] * GuiViewSource: port back to DockView. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20866 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiViewSource.cpp | 59 ++++++++++------ src/frontends/qt4/GuiViewSource.h | 104 +++++++--------------------- 2 files changed, 63 insertions(+), 100 deletions(-) diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp index a779ae2268..d6b141b969 100644 --- a/src/frontends/qt4/GuiViewSource.cpp +++ b/src/frontends/qt4/GuiViewSource.cpp @@ -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) -{} +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 ControlViewSource::initialiseParams(string const & /*source*/) +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 ControlViewSource::getRows() const +std::pair GuiViewSource::getRows() const { BufferView const * view = bufferview(); CursorSlice beg = view->cursor().selectionBegin().bottom(); @@ -137,19 +153,18 @@ std::pair 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(); } diff --git a/src/frontends/qt4/GuiViewSource.h b/src/frontends/qt4/GuiViewSource.h index cd96789be6..ab1db03640 100644 --- a/src/frontends/qt4/GuiViewSource.h +++ b/src/frontends/qt4/GuiViewSource.h @@ -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 -#include -#include +#include #include 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 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 -- 2.39.5