From 14f3344f0bdf6bd6b5447b384e5c5343dbb02d33 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sun, 25 Mar 2007 01:25:29 +0000 Subject: [PATCH] Present for Bo: Cleanup ViewSource and make it a DockWidget. * DockView.h: add the orientation option. * QViewSource: now a model and a controller * QViewSourceDialog: now only a simple QWidget. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17538 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/Dialogs.C | 8 +- src/frontends/qt4/DockView.h | 5 +- src/frontends/qt4/QViewSource.C | 48 ++-------- src/frontends/qt4/QViewSource.h | 56 ++++++------ src/frontends/qt4/QViewSourceDialog.C | 34 ++++--- src/frontends/qt4/QViewSourceDialog.h | 15 ++-- src/frontends/qt4/ui/QViewSourceUi.ui | 122 +++++++------------------- 7 files changed, 103 insertions(+), 185 deletions(-) diff --git a/src/frontends/qt4/Dialogs.C b/src/frontends/qt4/Dialogs.C index c0c35b1d42..da819f6195 100644 --- a/src/frontends/qt4/Dialogs.C +++ b/src/frontends/qt4/Dialogs.C @@ -66,6 +66,7 @@ #include "QNomencl.h" #include "QLog.h" #include "QViewSource.h" +#include "QViewSourceDialog.h" #include "QMath.h" #include "QNote.h" #include "QParagraph.h" @@ -237,8 +238,11 @@ Dialogs::DialogPtr Dialogs::build(string const & name) dialog->setView(new QLog(*dialog)); dialog->bc().bp(new OkCancelPolicy); } else if (name == "view-source") { - dialog->setController(new ControlViewSource(*dialog)); - dialog->setView(new QViewSource(*dialog)); + QViewSource * qvs = new QViewSource(*dialog); + dialog->setController(qvs); + GuiView & gui_view = static_cast(lyxview_); + dialog->setView(new DockView( + *dialog, qvs, &gui_view, _("LateX Source"), Qt::BottomDockWidgetArea)); dialog->bc().bp(new OkCancelPolicy); } else if (name == "mathpanel") { dialog->setController(new ControlMath(*dialog)); diff --git a/src/frontends/qt4/DockView.h b/src/frontends/qt4/DockView.h index 5dc8bf2e71..1c2f13436e 100644 --- a/src/frontends/qt4/DockView.h +++ b/src/frontends/qt4/DockView.h @@ -34,13 +34,14 @@ public: Dialog & dialog, ///< The (one) parent Dialog class. Controller * form, ///< Associated model/controller QMainWindow * parent, ///< the main window where to dock. - docstring const & title ///< Window title (shown in the top title bar). + docstring const & title, ///< Window title (shown in the top title bar). + Qt::DockWidgetArea area = Qt::LeftDockWidgetArea ) : QDockWidget(toqstr(title), parent), Dialog::View(dialog, title) { widget_.reset(new Widget(form)); setWidget(widget_.get()); - parent->addDockWidget(Qt::LeftDockWidgetArea, this); + parent->addDockWidget(area, this); } /// Dialog::View inherited methods diff --git a/src/frontends/qt4/QViewSource.C b/src/frontends/qt4/QViewSource.C index ad81a744b2..981cbc40ef 100644 --- a/src/frontends/qt4/QViewSource.C +++ b/src/frontends/qt4/QViewSource.C @@ -5,6 +5,7 @@ * * \author John Levon * \author Bo Peng + * \author Abdelrazak Younes * * Full author contact details are available in file CREDITS. */ @@ -15,25 +16,9 @@ #include "QViewSourceDialog.h" #include "qt_helpers.h" -#include "frontends/Application.h" - -#include "controllers/ControlViewSource.h" - -#include - -#include -#include - namespace lyx { namespace frontend { -typedef QController > viewsource_base_class; - - -QViewSource::QViewSource(Dialog & parent) - : viewsource_base_class(parent, lyx::docstring()) -{} - latexHighlighter::latexHighlighter(QTextDocument * parent) : QSyntaxHighlighter(parent) @@ -82,37 +67,18 @@ void latexHighlighter::highlightBlock(QString const & text) } -void QViewSource::build_dialog() +QViewSource::QViewSource(Dialog & parent) + : ControlViewSource(parent) { - dialog_.reset(new QViewSourceDialog(this)); + document_ = new QTextDocument(this); // set syntex highlighting - highlighter = new latexHighlighter(dialog_->viewSourceTV->document()); - // - dialog_->viewSourceTV->setReadOnly(true); - ///dialog_->viewSourceTV->setAcceptRichText(false); - // this is personal. I think source code should be in fixed-size font - QFont font(toqstr(theApp()->typewriterFontName())); - font.setKerning(false); - font.setFixedPitch(true); - font.setStyleHint(QFont::TypeWriter); - dialog_->viewSourceTV->setFont(font); - // again, personal taste - dialog_->viewSourceTV->setWordWrapMode(QTextOption::NoWrap); -} - - -void QViewSource::update_source() -{ - bool fullSource = dialog_->viewFullSourceCB->isChecked(); - dialog_->viewSourceTV->setPlainText(toqstr(controller().updateContent(fullSource))); + highlighter_ = new latexHighlighter(document_); } -void QViewSource::update_contents() +void QViewSource::update(bool full_source) { - setTitle(controller().title()); - if (dialog_->autoUpdateCB->isChecked()) - update_source(); + document_->setPlainText(toqstr(updateContent(full_source))); } diff --git a/src/frontends/qt4/QViewSource.h b/src/frontends/qt4/QViewSource.h index 5569684201..12c9e3fcf9 100644 --- a/src/frontends/qt4/QViewSource.h +++ b/src/frontends/qt4/QViewSource.h @@ -6,6 +6,7 @@ * * \author John Levon * \author Bo Peng + * \author Abdelrazak Younes * * Full author contact details are available in file CREDITS. */ @@ -13,45 +14,20 @@ #ifndef QVIEWSOURCE_H #define QVIEWSOURCE_H -#include "QDialogView.h" -#include "QViewSourceDialog.h" +#include "frontends/controllers/ControlViewSource.h" +#include #include +#include +#include namespace lyx { namespace frontend { -class ControlViewSource; -class latexHighlighter; - -/// -class QViewSource - : public QController > -{ -public: - /// - friend class QViewSourceDialog; - /// - QViewSource(Dialog &); -private: - /// Apply changes - virtual void apply() {} - /// - void update_source(); - /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); - /// latex syntax highlighter - latexHighlighter * highlighter; -}; - - /// class latexHighlighter : public QSyntaxHighlighter { - Q_OBJECT - + Q_OBJECT public: latexHighlighter(QTextDocument * parent); @@ -64,6 +40,26 @@ private: QTextCharFormat mathFormat; }; +/// +class QViewSource: public QObject, public ControlViewSource +{ + Q_OBJECT +public: + QViewSource(Dialog &); + virtual ~QViewSource() {} + + QTextDocument * document() { return document_; } + + void update(bool full_source); + +private: + /// + QTextDocument * document_; + + /// latex syntax highlighter + latexHighlighter * highlighter_; +}; + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/QViewSourceDialog.C b/src/frontends/qt4/QViewSourceDialog.C index 1bcf733440..d4ae0f641e 100644 --- a/src/frontends/qt4/QViewSourceDialog.C +++ b/src/frontends/qt4/QViewSourceDialog.C @@ -5,6 +5,7 @@ * * \author John Levon * \author Bo Peng + * \author Abdelrazak Younes * * Full author contact details are available in file CREDITS. */ @@ -12,10 +13,8 @@ #include #include "QViewSourceDialog.h" -#include "QViewSource.h" -#include -#include +#include "QViewSource.h" namespace lyx { @@ -26,26 +25,33 @@ QViewSourceDialog::QViewSourceDialog(QViewSource * form) { setupUi(this); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); connect(viewFullSourceCB, SIGNAL(clicked()), - this, SLOT(slotUpdate())); + this, SLOT(update())); connect(autoUpdateCB, SIGNAL(toggled(bool)), updatePB, SLOT(setDisabled(bool))); connect(updatePB, SIGNAL(clicked()), - this, SLOT(slotUpdate())); + this, SLOT(update())); + + viewSourceTV->setDocument(form_->document()); + viewSourceTV->setReadOnly(true); + ///dialog_->viewSourceTV->setAcceptRichText(false); + // this is personal. I think source code should be in fixed-size font + QFont font(toqstr(theApp()->typewriterFontName())); + font.setKerning(false); + font.setFixedPitch(true); + font.setStyleHint(QFont::TypeWriter); + viewSourceTV->setFont(font); + // again, personal taste + viewSourceTV->setWordWrapMode(QTextOption::NoWrap); } -void QViewSourceDialog::closeEvent(QCloseEvent * e) +void QViewSourceDialog::update() { - form_->slotWMHide(); - e->accept(); -} + if (autoUpdateCB->isChecked()) + form_->update(viewFullSourceCB->isChecked()); - -void QViewSourceDialog::slotUpdate() -{ - form_->update_source(); + QWidget::update(); } } // namespace frontend diff --git a/src/frontends/qt4/QViewSourceDialog.h b/src/frontends/qt4/QViewSourceDialog.h index c2643f5a68..59f9f40885 100644 --- a/src/frontends/qt4/QViewSourceDialog.h +++ b/src/frontends/qt4/QViewSourceDialog.h @@ -6,6 +6,7 @@ * * \author John Levon * \author Bo Peng + * \author Abdelrazak Younes * * Full author contact details are available in file CREDITS. */ @@ -15,20 +16,24 @@ #include "ui/QViewSourceUi.h" +#include "frontends/Application.h" + +#include + namespace lyx { namespace frontend { class QViewSource; -class QViewSourceDialog : public QDialog, public Ui::QViewSourceUi { +class QViewSourceDialog : public QWidget, public Ui::QViewSourceUi { Q_OBJECT public: QViewSourceDialog(QViewSource * form); -protected: - virtual void closeEvent(QCloseEvent * e); -private Q_SLOTS: + +public Q_SLOTS: // update content - void slotUpdate(); + void update(); + private: QViewSource * form_; }; diff --git a/src/frontends/qt4/ui/QViewSourceUi.ui b/src/frontends/qt4/ui/QViewSourceUi.ui index ff50ba17d1..da34dc4351 100644 --- a/src/frontends/qt4/ui/QViewSourceUi.ui +++ b/src/frontends/qt4/ui/QViewSourceUi.ui @@ -1,12 +1,12 @@ QViewSourceUi - + 0 0 460 - 424 + 116 @@ -15,108 +15,49 @@ true - + 9 6 - + + + + Automatic update + + + true + + + + + + + false + + + &Update + + + + - - - - 0 + + + + 0 - - 6 + + Display complete source - - - - 0 - - - Display complete source - - - - - - - Automatic update - - - true - - - - - - - - - 0 - - - 6 - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 201 - 44 - - - - - - - - false - - - &Update - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 31 - 44 - - - - - - - - &Close - - - - + @@ -125,7 +66,6 @@ viewFullSourceCB autoUpdateCB updatePB - closePB qt_helpers.h