diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index 78b055b6b6..660b504dea 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -726,7 +726,8 @@ src_frontends_qt4_moc_files = Split(''' QTexinfoDialog.C QThesaurusDialog.C TocModel.C - QTocDialog.C + TocWidget.C + QToc.C GuiView.C QURLDialog.C QVSpaceDialog.C @@ -743,6 +744,7 @@ src_frontends_qt4_header_files = Split(''' BiblioModuleBase.h BulletsModule.h ColorCache.h + DockView.h FileDialog_private.h GuiApplication.h GuiClipboard.h @@ -831,7 +833,6 @@ src_frontends_qt4_header_files = Split(''' QThesaurus.h QThesaurusDialog.h QToc.h - QTocDialog.h QURLDialog.h QVSpace.h QVSpaceDialog.h @@ -841,6 +842,7 @@ src_frontends_qt4_header_files = Split(''' QWrapDialog.h Qt2BC.h TocModel.h + TocWidget.h UrlView.h checkedwidgets.h emptytable.h @@ -953,7 +955,6 @@ src_frontends_qt4_files = Split(''' QThesaurus.C QThesaurusDialog.C QToc.C - QTocDialog.C QURLDialog.C QVSpace.C QVSpaceDialog.C @@ -963,6 +964,7 @@ src_frontends_qt4_files = Split(''' QWrapDialog.C Qt2BC.C TocModel.C + TocWidget.C UrlView.C checkedwidgets.C emptytable.C diff --git a/src/frontends/controllers/ControlToc.C b/src/frontends/controllers/ControlToc.C index a3c099be92..9bd9989564 100644 --- a/src/frontends/controllers/ControlToc.C +++ b/src/frontends/controllers/ControlToc.C @@ -37,9 +37,16 @@ namespace frontend { ControlToc::ControlToc(Dialog & d) : ControlCommand(d, "tableofcontents", "toc") -{} +{ +} +bool ControlToc::initialiseParams(string const & data) +{ + update(); + return ControlCommand::initialiseParams(data); +} + void ControlToc::goTo(TocItem const & item) { string const tmp = convert(item.id()); @@ -83,6 +90,12 @@ vector const & ControlToc::getTypes() const } +void ControlToc::updateBackend() +{ + kernel().buffer().tocBackend().update(); +} + + TocIterator const ControlToc::getCurrentTocItem( string const & type) const { diff --git a/src/frontends/controllers/ControlToc.h b/src/frontends/controllers/ControlToc.h index 9f30415154..273349b30f 100644 --- a/src/frontends/controllers/ControlToc.h +++ b/src/frontends/controllers/ControlToc.h @@ -27,6 +27,11 @@ class ControlToc : public ControlCommand { public: /// ControlToc(Dialog &); + /// + virtual ~ControlToc() {} + + /// \c ControlCommand inherited method. + bool initialiseParams(std::string const & data); /// Goto this paragraph id void goTo(TocItem const &); @@ -51,9 +56,14 @@ public: void outlineIn(); /// void outlineOut(); - /// Test if outlining operation is possible bool canOutline(std::string const & type); + /// + void updateBackend(); + +public: + /// Update the model data if needed. + virtual void update() = 0; }; } // namespace frontend diff --git a/src/frontends/qt4/Dialogs.C b/src/frontends/qt4/Dialogs.C index df2e5b0d6f..c0c35b1d42 100644 --- a/src/frontends/qt4/Dialogs.C +++ b/src/frontends/qt4/Dialogs.C @@ -44,6 +44,8 @@ #include "Qt2BC.h" #include "ButtonController.h" +#include "DockView.h" +#include "GuiView.h" #include "QAbout.h" #include "QBibitem.h" #include "QBibtex.h" @@ -78,7 +80,7 @@ #include "QTabularCreate.h" #include "QTexinfo.h" #include "QToc.h" -#include "QTocDialog.h" +#include "TocWidget.h" #include "UrlView.h" #include "QVSpace.h" #include "QWrap.h" @@ -92,7 +94,6 @@ #include - using std::string; using namespace lyx::frontend; @@ -131,6 +132,7 @@ private: namespace lyx { + bool Dialogs::isValidName(string const & name) const { return std::find_if(dialognames, end_dialognames, @@ -300,7 +302,9 @@ Dialogs::DialogPtr Dialogs::build(string const & name) } else if (name == "toc") { QToc * qtoc = new QToc(*dialog); dialog->setController(qtoc); - dialog->setView(new QTocDialog(*dialog, qtoc)); + GuiView & gui_view = static_cast(lyxview_); + dialog->setView(new DockView( + *dialog, qtoc, &gui_view, _("Toc"))); dialog->bc().bp(new OkCancelPolicy); } else if (name == "url") { dialog->setController(new ControlCommand(*dialog, name, name)); diff --git a/src/frontends/qt4/DockView.h b/src/frontends/qt4/DockView.h new file mode 100644 index 0000000000..ec68c180d1 --- /dev/null +++ b/src/frontends/qt4/DockView.h @@ -0,0 +1,67 @@ +// -*- C++ -*- +/** + * \file DockView.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef DOCK_VIEW_H +#define DOCK_VIEW_H + +#include "controllers/dialog.h" + +#include + +#include +#include + +namespace lyx { +namespace frontend { + +/// Dock Widget container for LyX dialogs. +/// This template class that encapsulates a given Widget inside a +/// DockWidget and presents a Dialog::View interface +template +class DockView : public QDockWidget, public Dialog::View +{ +public: + DockView( + 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). + ) + : QDockWidget(toqstr(title), parent), Dialog::View(dialog, title) + { + widget_.reset(new Widget(form)); + setWidget(widget_.get()); + parent->addDockWidget(Qt::LeftDockWidgetArea, this); + } + + /// Dialog::View inherited methods + //@{ + void apply() {} + void hide() { QDockWidget::hide(); } + void show() { QDockWidget::show(); } + bool isVisible() const + { return QDockWidget::isVisible(); } + void redraw() {} + void update() + { + widget_->update(); + QDockWidget::update(); + } + //@} +private: + /// The encapsulated widget. + boost::scoped_ptr widget_; +}; + +} // frontend +} // lyx + +#endif // TOC_WIDGET_H diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 4d5b35e0dc..20113224e7 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -32,6 +32,7 @@ AM_CPPFLAGS += \ libqt4_la_SOURCES = \ Alert_pimpl.C \ ColorCache.h ColorCache.C \ + DockView.h \ Dialogs.C \ FileDialog.C \ GuiClipboard.h GuiClipboard.C \ @@ -78,7 +79,6 @@ libqt4_la_SOURCES = \ QTabularCreate.C QTabularCreate.h \ QTexinfo.C QTexinfo.h \ QThesaurus.C QThesaurus.h \ - QToc.C QToc.h \ QVSpace.C QVSpace.h \ QWrap.C QWrap.h \ Qt2BC.C Qt2BC.h \ diff --git a/src/frontends/qt4/Makefile.dialogs b/src/frontends/qt4/Makefile.dialogs index 93090810e6..b928defe0e 100644 --- a/src/frontends/qt4/Makefile.dialogs +++ b/src/frontends/qt4/Makefile.dialogs @@ -131,7 +131,8 @@ MOCFILES = \ QTexinfoDialog.C QTexinfoDialog.h \ QThesaurusDialog.C QThesaurusDialog.h \ TocModel.C TocModel.h \ - QTocDialog.C QTocDialog.h \ + TocWidget.C TocWidget.h \ + QToc.C QToc.h \ QURLDialog.C QURLDialog.h \ QVSpaceDialog.C QVSpaceDialog.h \ QWrapDialog.C QWrapDialog.h \ diff --git a/src/frontends/qt4/QToc.C b/src/frontends/qt4/QToc.C index eeec2489aa..a6885d0dcd 100644 --- a/src/frontends/qt4/QToc.C +++ b/src/frontends/qt4/QToc.C @@ -12,6 +12,7 @@ #include #include "QToc.h" + #include "TocModel.h" #include "Qt2BC.h" #include "qt_helpers.h" @@ -35,7 +36,6 @@ namespace frontend { QToc::QToc(Dialog & parent) : ControlToc(parent) { - update(); } @@ -130,6 +130,7 @@ void QToc::update() { updateType(); updateToc(); + modelReset(); } @@ -184,3 +185,5 @@ void QToc::updateToc() } // namespace frontend } // namespace lyx + +#include "QToc_moc.cpp" diff --git a/src/frontends/qt4/QToc.h b/src/frontends/qt4/QToc.h index 5827be40cb..ea71c2b367 100644 --- a/src/frontends/qt4/QToc.h +++ b/src/frontends/qt4/QToc.h @@ -16,6 +16,7 @@ #include "ControlToc.h" +#include #include #include @@ -25,8 +26,9 @@ namespace frontend { class ControlToc; class TocModel; -class QToc : public ControlToc +class QToc : public QObject, public ControlToc { + Q_OBJECT public: QToc(Dialog &); @@ -54,14 +56,17 @@ public: /// int getTocDepth(); +Q_SIGNALS: + /// Signal that the internal toc_models_ has been reset. + void modelReset(); + private: - + /// std::vector toc_models_; - + /// QStringListModel type_model_; - + /// int type_; - int outline_type_; }; } // namespace frontend diff --git a/src/frontends/qt4/QTocDialog.C b/src/frontends/qt4/TocWidget.C similarity index 58% rename from src/frontends/qt4/QTocDialog.C rename to src/frontends/qt4/TocWidget.C index 2df9d466ef..2fb8b9bfb9 100644 --- a/src/frontends/qt4/QTocDialog.C +++ b/src/frontends/qt4/TocWidget.C @@ -1,5 +1,5 @@ /** - * \file QTocDialog.C + * \file TocWidget.C * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -11,18 +11,16 @@ #include -#include "QTocDialog.h" +#include "TocWidget.h" + #include "QToc.h" -#include "Qt2BC.h" #include "qt_helpers.h" -#include "controllers/ControlToc.h" #include "debug.h" -#include -#include -#include #include +#include +#include #include #include @@ -38,28 +36,29 @@ using std::string; namespace lyx { namespace frontend { -QTocDialog::QTocDialog(Dialog & dialog, QToc * form) - : Dialog::View(dialog, _("Toc")), form_(form), depth_(2) + +TocWidget::TocWidget(QToc * form, QMainWindow * parent) + : QWidget(parent), form_(form), depth_(0) { setupUi(this); - updateGui(); + connect(form, SIGNAL(modelReset()), + SLOT(updateGui())); - connect(tocTV->selectionModel(), - SIGNAL(currentChanged(const QModelIndex &, - const QModelIndex &)), - this, SLOT(selectionChanged(const QModelIndex &, - const QModelIndex &))); + // avoid flickering + tocTV->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + + tocTV->showColumn(0); + + // hide the pointless QHeader for now + // in the future, new columns may appear + // like labels, bookmarks, etc... + // tocTV->header()->hide(); + tocTV->header()->setVisible(false); } -QTocDialog::~QTocDialog() -{ - accept(); -} - - -void QTocDialog::selectionChanged(const QModelIndex & current, +void TocWidget::selectionChanged(const QModelIndex & current, const QModelIndex & /*previous*/) { lyxerr[Debug::GUI] @@ -71,14 +70,10 @@ void QTocDialog::selectionChanged(const QModelIndex & current, } -void QTocDialog::on_closePB_clicked() -{ - accept(); -} - - -void QTocDialog::on_updatePB_clicked() +void TocWidget::on_updatePB_clicked() { + form_->updateBackend(); + form_->update(); update(); } @@ -88,14 +83,14 @@ opinion, somebody should derive a new qvariant class for tocModelItem which saves the string data and depth information. that will save the depth calculation. */ -int QTocDialog::getIndexDepth(QModelIndex const & index, int depth) +int TocWidget::getIndexDepth(QModelIndex const & index, int depth) { ++depth; return (index.parent() == QModelIndex())? depth : getIndexDepth(index.parent(),depth); } -void QTocDialog::on_depthSL_valueChanged(int depth) +void TocWidget::on_depthSL_valueChanged(int depth) { if (depth == depth_) return; @@ -103,10 +98,9 @@ void QTocDialog::on_depthSL_valueChanged(int depth) } -void QTocDialog::setTreeDepth(int depth) +void TocWidget::setTreeDepth(int depth) { - if(depth!=-1) - depth_ = depth; + depth_ = depth; // expanding and then collapsing is probably better, // but my qt 4.1.2 doesn't have expandAll().. @@ -127,72 +121,81 @@ void QTocDialog::setTreeDepth(int depth) } -void QTocDialog::on_typeCO_activated(int value) +void TocWidget::on_typeCO_activated(int value) { form_->setTocModel(value); - tocTV->setModel(form_->tocModel()); - reconnectSelectionModel(); - enableButtons(); - update(); + updateGui(); } -void QTocDialog::on_moveUpPB_clicked() +void TocWidget::on_moveUpPB_clicked() { enableButtons(false); - QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0]; - form_->goTo(index); - form_->outlineUp(); - update(); + QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes(); + if (!list.isEmpty()) { + enableButtons(false); + form_->goTo(list[0]); + form_->outlineUp(); + enableButtons(true); + } } -void QTocDialog::on_moveDownPB_clicked() +void TocWidget::on_moveDownPB_clicked() { enableButtons(false); - QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0]; - form_->goTo(index); - form_->outlineDown(); - update(); + QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes(); + if (!list.isEmpty()) { + enableButtons(false); + form_->goTo(list[0]); + form_->outlineDown(); + enableButtons(true); + } } -void QTocDialog::on_moveInPB_clicked() +void TocWidget::on_moveInPB_clicked() { enableButtons(false); - QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0]; - form_->goTo(index); - form_->outlineIn(); - update(); + QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes(); + if (!list.isEmpty()) { + enableButtons(false); + form_->goTo(list[0]); + form_->outlineIn(); + enableButtons(true); + } } -void QTocDialog::on_moveOutPB_clicked() +void TocWidget::on_moveOutPB_clicked() { - enableButtons(false); - QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0]; - form_->goTo(index); - form_->outlineOut(); - update(); + QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes(); + if (!list.isEmpty()) { + enableButtons(false); + form_->goTo(list[0]); + form_->outlineOut(); + enableButtons(true); + } } -void QTocDialog::select(QModelIndex const & index) +void TocWidget::select(QModelIndex const & index) { -// tocTV->setModel(form_->tocModel()); - if (!index.isValid()) { lyxerr[Debug::GUI] - << "QTocDialog::select(): QModelIndex is invalid!" << endl; + << "TocWidget::select(): QModelIndex is invalid!" << endl; return; } + tocTV->selectionModel()->blockSignals(true); tocTV->scrollTo(index); - tocTV->selectionModel()->select(index, QItemSelectionModel::Select); + tocTV->selectionModel()->setCurrentIndex(index, + QItemSelectionModel::ClearAndSelect); + tocTV->selectionModel()->blockSignals(false); } -void QTocDialog::enableButtons(bool enable) +void TocWidget::enableButtons(bool enable) { updatePB->setEnabled(enable); @@ -206,18 +209,18 @@ void QTocDialog::enableButtons(bool enable) } -void QTocDialog::update() +void TocWidget::update() { - form_->updateToc(); - updateGui(); + select(form_->getCurrentIndex()); + QWidget::update(); } -void QTocDialog::updateGui() +void TocWidget::updateGui() { QStringListModel * type_model = form_->typeModel(); if (type_model->stringList().isEmpty()) { - enableButtons(); + enableButtons(false); typeCO->setModel(type_model); tocTV->setModel(new QStandardItemModel); tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers); @@ -228,35 +231,29 @@ void QTocDialog::updateGui() typeCO->setModel(type_model); typeCO->setCurrentIndex(form_->getType()); + bool buttons_enabled = false; if (form_->tocModel()) { + buttons_enabled = form_->tocModel()->rowCount() > 0; tocTV->setModel(form_->tocModel()); tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers); } - // avoid flickering - tocTV-> setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - tocTV->showColumn(0); - // hide the pointless QHeader for now - // in the future, new columns may appear - // like labels, bookmarks, etc... - // tocTV->header()->hide(); - tocTV->header()->setVisible(false); - enableButtons(); + + enableButtons(buttons_enabled); reconnectSelectionModel(); depthSL->setEnabled(true); depthSL->setMaximum(form_->getTocDepth()); - setTreeDepth(); + depthSL->setValue(depth_); select(form_->getCurrentIndex()); lyxerr[Debug::GUI] << "form_->tocModel()->rowCount " << form_->tocModel()->rowCount() << "\nform_->tocModel()->columnCount " << form_->tocModel()->columnCount() << endl; -// setTitle(form_->guiname()) } -void QTocDialog::reconnectSelectionModel() +void TocWidget::reconnectSelectionModel() { connect(tocTV->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, @@ -265,34 +262,7 @@ void QTocDialog::reconnectSelectionModel() const QModelIndex &))); } - -void QTocDialog::apply() -{ - // Nothing to do here... for now. - // Ideas welcome... (Abdel, 17042006) -} - - -void QTocDialog::hide() -{ - accept(); -} - - -void QTocDialog::show() -{ - form_->update(); - QDialog::show(); -} - - -bool QTocDialog::isVisible() const -{ - return QDialog::isVisible(); -} - - } // namespace frontend } // namespace lyx -#include "QTocDialog_moc.cpp" +#include "TocWidget_moc.cpp" diff --git a/src/frontends/qt4/QTocDialog.h b/src/frontends/qt4/TocWidget.h similarity index 64% rename from src/frontends/qt4/QTocDialog.h rename to src/frontends/qt4/TocWidget.h index c93e95e360..3cc950b2b8 100644 --- a/src/frontends/qt4/QTocDialog.h +++ b/src/frontends/qt4/TocWidget.h @@ -1,6 +1,6 @@ // -*- C++ -*- /** - * \file QTocDialog.h + * \file TocWidget.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -10,56 +10,35 @@ * Full author contact details are available in file CREDITS. */ -#ifndef QTOCDIALOG_H -#define QTOCDIALOG_H +#ifndef TOC_WIDGET_H +#define TOC_WIDGET_H #include "ui/QTocUi.h" -#include "controllers/ControlToc.h" -#include - -class QTreeViewItem; +#include namespace lyx { namespace frontend { class QToc; -class QTocDialog : public QDialog, public Ui::QTocUi, public Dialog::View { +class TocWidget : public QWidget, public Ui::QTocUi { Q_OBJECT public: - QTocDialog(Dialog &, QToc * form); - - ~QTocDialog(); - - virtual void apply(); - - /// Hide the dialog from sight - void hide(); - - /// Redraw the dialog (e.g. if the colors have been remapped). - void redraw() {} - - /// Create the dialog if necessary, update it and display it. - void show(); + TocWidget(QToc * form, QMainWindow * parent = 0); /// Update the display of the dialog whilst it is still visible. void update(); +protected Q_SLOTS: /// Update Gui of the display. void updateGui(); - - /// \return true if the dialog is visible. - bool isVisible() const; - -protected Q_SLOTS: /// void select(QModelIndex const & index); /// void selectionChanged(const QModelIndex & current, const QModelIndex & previous); - void on_closePB_clicked(); void on_updatePB_clicked(); void on_depthSL_valueChanged(int depth); void on_typeCO_activated(int value); @@ -71,14 +50,14 @@ protected Q_SLOTS: protected: /// void enableButtons(bool enable = true); - /// Reconnects the selection model change signal when TOC changed. - void reconnectSelectionModel(); /// int getIndexDepth(QModelIndex const & index, int depth = -1); /// - void setTreeDepth(int depth = -1); + void setTreeDepth(int depth); private: + /// Reconnects the selection model change signal when TOC changed. + void reconnectSelectionModel(); QToc * form_; @@ -89,4 +68,4 @@ private: } // namespace frontend } // namespace lyx -#endif // QTOCDIALOG_H +#endif // TOC_WIDGET_H diff --git a/src/frontends/qt4/ui/QTocUi.ui b/src/frontends/qt4/ui/QTocUi.ui index bd89b67c3c..aa9f8c4a9a 100644 --- a/src/frontends/qt4/ui/QTocUi.ui +++ b/src/frontends/qt4/ui/QTocUi.ui @@ -1,23 +1,20 @@ - - - QTocUi - + + + Qt::NonModal + 0 0 - 386 - 351 + 257 + 404 - - true - 9 @@ -25,7 +22,7 @@ 6 - + 0 @@ -34,76 +31,67 @@ 6 - + - &Up + <- P&romote - + &Down - - - - <- &Promote - - - - + &Demote -> - - - - - - 0 - - - 6 - - - - - &Close - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + &Update + + + + &Up + + + - + + + + + 7 + 0 + 0 + 0 + + + + + + + + + 7 + 7 + 0 + 0 + + + + + 5 @@ -123,59 +111,17 @@ - - - 0 + + + &Type: - - 6 + + typeCO - - - - &Type: - - - typeCO - - - - - - - - 3 - 0 - 0 - 0 - - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - + - typeCO tocTV @@ -184,8 +130,6 @@ moveDownPB moveInPB moveOutPB - updatePB - closePB qt_helpers.h