Abdelrazak Younes wrote:
Dear Jose,
Here is the proposed patch. There's still one bug remaining in the
type's list but it should be easy to solve.
I propose to commit the safe part now (everything that is not in qt4)
and, when the above bug is solved, commit the rest.
Here are the main difference compared with the previous one:
- TocWidget is renamed from QTocDialog in order to keep SVN history
- The former QTocDialog (now DockView) is now a templatized widget
container using a DockWidget. The idea would be to reuse that framework
for other dialogs (ErrorList and Layout list come to mind).
- Dialogs are no more hidden upon buffer switch.
I have not looked at the type list related bug yet.
Abdel.
Index: development/scons/scons_manifest.py
===================================================================
--- development/scons/scons_manifest.py (revision 17409)
+++ development/scons/scons_manifest.py (working copy)
@@ -726,7 +726,8 @@
QTexinfoDialog.C
QThesaurusDialog.C
TocModel.C
- QTocDialog.C
+ TocWidget.C
+ QToc.C
GuiView.C
QURLDialog.C
QVSpaceDialog.C
@@ -743,6 +744,7 @@
BiblioModuleBase.h
BulletsModule.h
ColorCache.h
+ DockView.h
FileDialog_private.h
GuiApplication.h
GuiClipboard.h
@@ -831,7 +833,6 @@
QThesaurus.h
QThesaurusDialog.h
QToc.h
- QTocDialog.h
QURLDialog.h
QVSpace.h
QVSpaceDialog.h
@@ -841,6 +842,7 @@
QWrapDialog.h
Qt2BC.h
TocModel.h
+ TocWidget.h
UrlView.h
checkedwidgets.h
emptytable.h
@@ -953,7 +955,6 @@
QThesaurus.C
QThesaurusDialog.C
QToc.C
- QTocDialog.C
QURLDialog.C
QVSpace.C
QVSpaceDialog.C
@@ -963,6 +964,7 @@
QWrapDialog.C
Qt2BC.C
TocModel.C
+ TocWidget.C
UrlView.C
checkedwidgets.C
emptytable.C
Index: src/buffer.h
===================================================================
--- src/buffer.h (revision 17409)
+++ src/buffer.h (working copy)
@@ -130,6 +130,8 @@
/// This signal is emitted when the buffer is changed.
boost::signal<void()> changed;
+ /// This signal is emitted when the buffer structure is changed.
+ boost::signal<void()> structureChanged;
/// This signal is emitted when some parsing error shows up.
boost::signal<void(std::string)> errors;
/// This signal is emitted when some message shows up.
Index: src/buffer_funcs.C
===================================================================
--- src/buffer_funcs.C (revision 17409)
+++ src/buffer_funcs.C (working copy)
@@ -695,7 +695,9 @@
}
}
- const_cast<Buffer &>(buf).tocBackend().update();
+ Buffer & cbuf = const_cast<Buffer &>(buf);
+ cbuf.tocBackend().update();
+ cbuf.structureChanged();
}
Index: src/frontends/controllers/ControlToc.C
===================================================================
--- src/frontends/controllers/ControlToc.C (revision 17409)
+++ src/frontends/controllers/ControlToc.C (working copy)
@@ -37,9 +37,16 @@
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<string>(item.id());
@@ -83,6 +90,12 @@
}
+void ControlToc::updateBackend()
+{
+ kernel().buffer().tocBackend().update();
+}
+
+
TocIterator const ControlToc::getCurrentTocItem(
string const & type) const
{
Index: src/frontends/controllers/ControlToc.h
===================================================================
--- src/frontends/controllers/ControlToc.h (revision 17409)
+++ src/frontends/controllers/ControlToc.h (working copy)
@@ -27,7 +27,12 @@
public:
///
ControlToc(Dialog &);
+ ///
+ virtual ~ControlToc() {}
+ ///
+ virtual bool initialiseParams(std::string const & data);
+
/// Goto this paragraph id
void goTo(TocItem const &);
@@ -51,9 +56,13 @@
void outlineIn();
///
void outlineOut();
-
/// Test if outlining operation is possible
bool canOutline(std::string const & type);
+ ///
+ void updateBackend();
+
+public:
+ virtual void update() = 0;
};
} // namespace frontend
Index: src/frontends/Dialogs.C
===================================================================
--- src/frontends/Dialogs.C (revision 17409)
+++ src/frontends/Dialogs.C (working copy)
@@ -215,7 +215,10 @@
for(; it != end; ++it) {
Dialog * dialog = it->second.get();
if (switched && dialog->controller().isBufferDependent()) {
- dialog->hide();
+ if (dialog->controller().initialiseParams(""))
+ dialog->view().update();
+ else
+ dialog->hide();
} else {
// A bit clunky, but the dialog will request
// that the kernel provides it with the necessary
Index: src/frontends/LyXView.C
===================================================================
--- src/frontends/LyXView.C (revision 17409)
+++ src/frontends/LyXView.C (working copy)
@@ -133,6 +133,8 @@
getDialogs().hideBufferDependent();
work_area_->bufferView().setBuffer(b);
+ // Make sure the TOC is updated before anything else.
+ updateToc();
if (work_area_->bufferView().buffer()) {
// Buffer-dependent dialogs should be updated or
@@ -166,6 +168,7 @@
bool loaded = work_area_->bufferView().loadLyXFile(filename,
tolastfiles);
+ updateToc();
updateMenubar();
updateToolbars();
updateLayoutChoice();
@@ -192,6 +195,10 @@
buf.changed.connect(
boost::bind(&WorkArea::redraw, work_area_));
+ bufferStructureChangedConnection_ =
+ buf.structureChanged.connect(
+ boost::bind(&LyXView::updateToc, this));
+
errorsConnection_ =
buf.errors.connect(
boost::bind(&LyXView::showErrorList, this, _1));
@@ -226,6 +233,7 @@
{
errorsConnection_.disconnect();
bufferChangedConnection_.disconnect();
+ bufferStructureChangedConnection_.disconnect();
messageConnection_.disconnect();
busyConnection_.disconnect();
titleConnection_.disconnect();
@@ -309,6 +317,12 @@
}
+void LyXView::updateToc()
+{
+ updateDialog("toc", "");
+}
+
+
void LyXView::updateToolbars()
{
BOOST_ASSERT(work_area_);
Index: src/frontends/LyXView.h
===================================================================
--- src/frontends/LyXView.h (revision 17409)
+++ src/frontends/LyXView.h (working copy)
@@ -224,6 +224,8 @@
/// buffer changed signal connection
boost::signals::connection bufferChangedConnection_;
+ /// buffer structure changed signal connection
+ boost::signals::connection bufferStructureChangedConnection_;
/// buffer errors signal connection
boost::signals::connection errorsConnection_;
/// buffer messages signal connection
@@ -268,6 +270,9 @@
void showReadonly(bool);
protected:
+ ///
+ void updateToc();
+
/// view's command buffer controller
// this has to be declared _after_ lyxfunc_ as its initialization
depends
// on it!
Index: src/frontends/qt4/Dialogs.C
===================================================================
--- src/frontends/qt4/Dialogs.C (revision 17409)
+++ src/frontends/qt4/Dialogs.C (working copy)
@@ -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 <boost/assert.hpp>
-
using std::string;
using namespace lyx::frontend;
@@ -131,6 +132,7 @@
namespace lyx {
+
bool Dialogs::isValidName(string const & name) const
{
return std::find_if(dialognames, end_dialognames,
@@ -300,7 +302,9 @@
} else if (name == "toc") {
QToc * qtoc = new QToc(*dialog);
dialog->setController(qtoc);
- dialog->setView(new QTocDialog(*dialog, qtoc));
+ GuiView & gui_view = static_cast<GuiView &>(lyxview_);
+ dialog->setView(new DockView<QToc, TocWidget>(
+ *dialog, qtoc, &gui_view, _("Toc")));
dialog->bc().bp(new OkCancelPolicy);
} else if (name == "url") {
dialog->setController(new ControlCommand(*dialog, name, name));
Index: src/frontends/qt4/DockView.h
===================================================================
--- src/frontends/qt4/DockView.h (revision 0)
+++ src/frontends/qt4/DockView.h (revision 0)
@@ -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 <boost/scoped_ptr.hpp>
+
+#include <QDockWidget>
+#include <QMainWindow>
+
+namespace lyx {
+namespace frontend {
+
+/// A TOC dialog dock widget
+/// This class encapsulate a given Widget inside a DockWidget.
+template<class Controller, class Widget>
+class DockView : public QDockWidget, public Dialog::View
+{
+public:
+ DockView(
+ Dialog & dialog, ///<
+ Controller * form, ///<
+ QMainWindow * parent, ///<
+ docstring const & title ///<
+ )
+ : QDockWidget(toqstr(title), parent), Dialog::View(dialog,
title)
+ {
+ // There is no memory leak here because DockWidget will
+ // own the Widget.
+ 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:
+ boost::scoped_ptr<Widget> widget_;
+};
+
+} // frontend
+} // lyx
+
+#endif // TOC_WIDGET_H
Property changes on: src\frontends\qt4\DockView.h
___________________________________________________________________
Name: svn:eol-style
+ native
Index: src/frontends/qt4/Makefile.am
===================================================================
--- src/frontends/qt4/Makefile.am (revision 17409)
+++ src/frontends/qt4/Makefile.am (working copy)
@@ -32,6 +32,7 @@
libqt4_la_SOURCES = \
Alert_pimpl.C \
ColorCache.h ColorCache.C \
+ DockView.h \
Dialogs.C \
FileDialog.C \
GuiClipboard.h GuiClipboard.C \
@@ -78,7 +79,6 @@
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 \
Index: src/frontends/qt4/Makefile.dialogs
===================================================================
--- src/frontends/qt4/Makefile.dialogs (revision 17409)
+++ src/frontends/qt4/Makefile.dialogs (working copy)
@@ -131,7 +131,8 @@
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 \
Index: src/frontends/qt4/QToc.C
===================================================================
--- src/frontends/qt4/QToc.C (revision 17409)
+++ src/frontends/qt4/QToc.C (working copy)
@@ -12,6 +12,7 @@
#include <config.h>
#include "QToc.h"
+
#include "TocModel.h"
#include "Qt2BC.h"
#include "qt_helpers.h"
@@ -135,7 +136,6 @@
void QToc::updateType()
{
-
QStringList type_list;
vector<string> const & types = getTypes();
@@ -169,18 +169,32 @@
}
+void QToc::resetToc()
+{
+ vector<string> const & types = getTypes();
+ toc_models_.clear();
+ for (size_t i = 0; i != types.size(); ++i)
+ toc_models_.push_back(new TocModel(getContents(types[i])));
+
+ modelReset();
+}
+
+
void QToc::updateToc()
{
- toc_models_.clear();
vector<string> const & types = getTypes();
- for (size_t i = 0; i != types.size(); ++i) {
+ if (toc_models_.size() != types.size()) {
+ resetToc();
+ return;
+ }
- toc_models_.push_back(new TocModel(getContents(types[i])));
- }
-
+ for (size_t i = 0; i != types.size(); ++i)
+ toc_models_[i]->populate(getContents(types[i]));
}
} // namespace frontend
} // namespace lyx
+
+#include "QToc_moc.cpp"
Index: src/frontends/qt4/QToc.h
===================================================================
--- src/frontends/qt4/QToc.h (revision 17409)
+++ src/frontends/qt4/QToc.h (working copy)
@@ -16,6 +16,7 @@
#include "ControlToc.h"
+#include <QObject>
#include <QStandardItemModel>
#include <QStringListModel>
@@ -25,8 +26,9 @@
class ControlToc;
class TocModel;
-class QToc : public ControlToc
+class QToc : public QObject, public ControlToc
{
+ Q_OBJECT
public:
QToc(Dialog &);
@@ -54,8 +56,14 @@
///
int getTocDepth();
+Q_SIGNALS:
+ /// Signal that the internal toc_models_ has been reset.
+ void modelReset();
+
private:
+ void resetToc();
+
std::vector<TocModel *> toc_models_;
QStringListModel type_model_;
Index: src/frontends/qt4/QTocDialog.C
===================================================================
--- src/frontends/qt4/QTocDialog.C (revision 17409)
+++ src/frontends/qt4/QTocDialog.C (working copy)
@@ -1,298 +0,0 @@
-/**
- * \file QTocDialog.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QTocDialog.h"
-#include "QToc.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-#include "controllers/ControlToc.h"
-
-#include "debug.h"
-
-#include <QTreeWidgetItem>
-#include <QPushButton>
-#include <QCloseEvent>
-#include <QHeaderView>
-
-#include <vector>
-#include <string>
-#include <stack>
-
-using std::endl;
-using std::pair;
-using std::stack;
-using std::vector;
-using std::string;
-
-
-namespace lyx {
-namespace frontend {
-
-QTocDialog::QTocDialog(Dialog & dialog, QToc * form)
- : Dialog::View(dialog, _("Toc")), form_(form), depth_(2)
-{
- setupUi(this);
-
- updateGui();
-
- connect(tocTV->selectionModel(),
- SIGNAL(currentChanged(const QModelIndex &,
- const QModelIndex &)),
- this, SLOT(selectionChanged(const QModelIndex &,
- const QModelIndex &)));
-}
-
-
-QTocDialog::~QTocDialog()
-{
- accept();
-}
-
-
-void QTocDialog::selectionChanged(const QModelIndex & current,
- const QModelIndex & /*previous*/)
-{
- lyxerr[Debug::GUI]
- << "selectionChanged index " << current.row()
- << ", " << current.column()
- << endl;
-
- form_->goTo(current);
-}
-
-
-void QTocDialog::on_closePB_clicked()
-{
- accept();
-}
-
-
-void QTocDialog::on_updatePB_clicked()
-{
- update();
-}
-
-/* FIXME (Ugras 17/11/06):
-I have implemented a getIndexDepth function to get the model indices. In my
-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)
-{
- ++depth;
- return (index.parent() == QModelIndex())? depth :
getIndexDepth(index.parent(),depth);
-}
-
-
-void QTocDialog::on_depthSL_valueChanged(int depth)
-{
- if (depth == depth_)
- return;
- setTreeDepth(depth);
-}
-
-
-void QTocDialog::setTreeDepth(int depth)
-{
- if(depth!=-1)
- depth_ = depth;
-
- // expanding and then collapsing is probably better,
- // but my qt 4.1.2 doesn't have expandAll()..
- //tocTV->expandAll();
- QModelIndexList indices =
- form_->tocModel()->match(form_->tocModel()->index(0,0),
- Qt::DisplayRole, "*", -1,
- Qt::MatchWildcard|Qt::MatchRecursive);
-
- int size = indices.size();
- for (int i = 0; i < size; i++) {
- QModelIndex index = indices[i];
- if (getIndexDepth(index) < depth_)
- tocTV->expand(index);
- else
- tocTV->collapse(index);
- }
-}
-
-
-void QTocDialog::on_typeCO_activated(int value)
-{
- form_->setTocModel(value);
- tocTV->setModel(form_->tocModel());
- reconnectSelectionModel();
- enableButtons();
- update();
-}
-
-
-void QTocDialog::on_moveUpPB_clicked()
-{
- enableButtons(false);
- QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
- form_->goTo(index);
- form_->outlineUp();
- update();
-}
-
-
-void QTocDialog::on_moveDownPB_clicked()
-{
- enableButtons(false);
- QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
- form_->goTo(index);
- form_->outlineDown();
- update();
-}
-
-
-void QTocDialog::on_moveInPB_clicked()
-{
- enableButtons(false);
- QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
- form_->goTo(index);
- form_->outlineIn();
- update();
-}
-
-
-void QTocDialog::on_moveOutPB_clicked()
-{
- enableButtons(false);
- QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
- form_->goTo(index);
- form_->outlineOut();
- update();
-}
-
-
-void QTocDialog::select(QModelIndex const & index)
-{
-// tocTV->setModel(form_->tocModel());
-
- if (!index.isValid()) {
- lyxerr[Debug::GUI]
- << "QTocDialog::select(): QModelIndex is invalid!" <<
endl;
- return;
- }
-
- tocTV->scrollTo(index);
- tocTV->selectionModel()->select(index, QItemSelectionModel::Select);
-}
-
-
-void QTocDialog::enableButtons(bool enable)
-{
- updatePB->setEnabled(enable);
-
- if (!form_->canOutline())
- enable = false;
-
- moveUpPB->setEnabled(enable);
- moveDownPB->setEnabled(enable);
- moveInPB->setEnabled(enable);
- moveOutPB->setEnabled(enable);
-}
-
-
-void QTocDialog::update()
-{
- form_->updateToc();
- updateGui();
-}
-
-
-void QTocDialog::updateGui()
-{
- QStringListModel * type_model = form_->typeModel();
- if (type_model->stringList().isEmpty()) {
- enableButtons();
- typeCO->setModel(type_model);
- tocTV->setModel(new QStandardItemModel);
- tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
- depthSL->setEnabled(false);
- return;
- }
-
- typeCO->setModel(type_model);
- typeCO->setCurrentIndex(form_->getType());
-
- if (form_->tocModel()) {
- 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();
-
- reconnectSelectionModel();
- depthSL->setEnabled(true);
- depthSL->setMaximum(form_->getTocDepth());
- setTreeDepth();
- 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()
-{
- connect(tocTV->selectionModel(),
- SIGNAL(currentChanged(const QModelIndex &,
- const QModelIndex &)),
- this, SLOT(selectionChanged(const QModelIndex &,
- 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"
Index: src/frontends/qt4/QTocDialog.h
===================================================================
--- src/frontends/qt4/QTocDialog.h (revision 17409)
+++ src/frontends/qt4/QTocDialog.h (working copy)
@@ -1,92 +0,0 @@
-// -*- C++ -*-
-/**
- * \file QTocDialog.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef QTOCDIALOG_H
-#define QTOCDIALOG_H
-
-#include "ui/QTocUi.h"
-#include "controllers/ControlToc.h"
-
-#include <QDialog>
-
-class QTreeViewItem;
-
-namespace lyx {
-namespace frontend {
-
-class QToc;
-
-class QTocDialog : public QDialog, public Ui::QTocUi, public Dialog::View {
- 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();
-
- /// Update the display of the dialog whilst it is still visible.
- void update();
-
- /// 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);
- void on_moveUpPB_clicked();
- void on_moveDownPB_clicked();
- void on_moveInPB_clicked();
- void on_moveOutPB_clicked();
-
-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);
-
-private:
-
- QToc * form_;
-
- /// depth of list shown
- int depth_;
-};
-
-} // namespace frontend
-} // namespace lyx
-
-#endif // QTOCDIALOG_H
Index: src/frontends/qt4/TocWidget.C
===================================================================
--- src/frontends/qt4/TocWidget.C (revision 17409)
+++ src/frontends/qt4/TocWidget.C (working copy)
@@ -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 <config.h>
-#include "QTocDialog.h"
+#include "TocWidget.h"
+
#include "QToc.h"
-#include "Qt2BC.h"
#include "qt_helpers.h"
-#include "controllers/ControlToc.h"
#include "debug.h"
-#include <QTreeWidgetItem>
-#include <QPushButton>
-#include <QCloseEvent>
#include <QHeaderView>
+#include <QPushButton>
+#include <QTreeWidgetItem>
#include <vector>
#include <string>
@@ -38,28 +36,31 @@
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_(2)
{
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);
-QTocDialog::~QTocDialog()
-{
- accept();
+ // hide the pointless QHeader for now
+ // in the future, new columns may appear
+ // like labels, bookmarks, etc...
+ // tocTV->header()->hide();
+ tocTV->header()->setVisible(false);
+
+ updateGui();
}
-void QTocDialog::selectionChanged(const QModelIndex & current,
+void TocWidget::selectionChanged(const QModelIndex & current,
const QModelIndex & /*previous*/)
{
lyxerr[Debug::GUI]
@@ -71,14 +72,10 @@
}
-void QTocDialog::on_closePB_clicked()
+void TocWidget::on_updatePB_clicked()
{
- accept();
-}
-
-
-void QTocDialog::on_updatePB_clicked()
-{
+ form_->updateBackend();
+ form_->update();
update();
}
@@ -88,14 +85,14 @@
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,7 +100,7 @@
}
-void QTocDialog::setTreeDepth(int depth)
+void TocWidget::setTreeDepth(int depth)
{
if(depth!=-1)
depth_ = depth;
@@ -127,7 +124,7 @@
}
-void QTocDialog::on_typeCO_activated(int value)
+void TocWidget::on_typeCO_activated(int value)
{
form_->setTocModel(value);
tocTV->setModel(form_->tocModel());
@@ -137,62 +134,74 @@
}
-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 +215,18 @@
}
-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,20 +237,15 @@
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());
@@ -252,11 +256,10 @@
<< "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 +268,7 @@
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"
Index: src/frontends/qt4/TocWidget.h
===================================================================
--- src/frontends/qt4/TocWidget.h (revision 17409)
+++ src/frontends/qt4/TocWidget.h (working copy)
@@ -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 <QDialog>
+#include <QWidget>
-class QTreeViewItem;
-
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);
+ TocWidget(QToc * form, QMainWindow * parent = 0);
- ~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();
-
/// 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:
///
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);
private:
+ /// Reconnects the selection model change signal when TOC changed.
+ void reconnectSelectionModel();
QToc * form_;
@@ -89,4 +68,4 @@
} // namespace frontend
} // namespace lyx
-#endif // QTOCDIALOG_H
+#endif // TOC_WIDGET_H
Index: src/frontends/qt4/ui/QTocUi.ui
===================================================================
--- src/frontends/qt4/ui/QTocUi.ui (revision 17409)
+++ src/frontends/qt4/ui/QTocUi.ui (working copy)
@@ -1,23 +1,20 @@
<ui version="4.0" >
- <author></author>
- <comment></comment>
- <exportmacro></exportmacro>
<class>QTocUi</class>
- <widget class="QDialog" name="QTocUi" >
+ <widget class="QWidget" name="QTocUi" >
+ <property name="windowModality" >
+ <enum>Qt::NonModal</enum>
+ </property>
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
- <width>386</width>
- <height>351</height>
+ <width>257</width>
+ <height>404</height>
</rect>
</property>
<property name="windowTitle" >
<string/>
</property>
- <property name="sizeGripEnabled" >
- <bool>true</bool>
- </property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
@@ -25,7 +22,7 @@
<property name="spacing" >
<number>6</number>
</property>
- <item row="3" column="0" >
+ <item row="3" column="0" colspan="2" >
<layout class="QGridLayout" >
<property name="margin" >
<number>0</number>
@@ -34,76 +31,67 @@
<number>6</number>
</property>
<item row="0" column="0" >
- <widget class="QPushButton" name="moveUpPB" >
+ <widget class="QPushButton" name="moveOutPB" >
<property name="text" >
- <string>&Up</string>
+ <string><- &Promote</string>
</property>
</widget>
</item>
- <item row="0" column="1" >
+ <item row="1" column="2" >
<widget class="QPushButton" name="moveDownPB" >
<property name="text" >
<string>&Down</string>
</property>
</widget>
</item>
- <item row="0" column="2" >
- <widget class="QPushButton" name="moveOutPB" >
- <property name="text" >
- <string><- &Promote</string>
- </property>
- </widget>
- </item>
- <item row="0" column="3" >
+ <item row="0" column="1" >
<widget class="QPushButton" name="moveInPB" >
<property name="text" >
<string>&Demote -></string>
</property>
</widget>
</item>
- </layout>
- </item>
- <item row="4" column="0" >
- <layout class="QGridLayout" >
- <property name="margin" >
- <number>0</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item row="0" column="2" >
- <widget class="QPushButton" name="closePB" >
+ <item row="1" column="0" colspan="2" >
+ <widget class="QPushButton" name="updatePB" >
<property name="text" >
- <string>&Close</string>
+ <string>&Update</string>
</property>
- <property name="default" >
- <bool>true</bool>
- </property>
</widget>
</item>
- <item row="0" column="1" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="0" column="0" >
- <widget class="QPushButton" name="updatePB" >
+ <item row="0" column="2" >
+ <widget class="QPushButton" name="moveUpPB" >
<property name="text" >
- <string>&Update</string>
+ <string>&Up</string>
</property>
</widget>
</item>
</layout>
</item>
- <item row="2" column="0" >
+ <item row="0" column="1" >
+ <widget class="QComboBox" name="typeCO" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="2" >
+ <widget class="QTreeView" name="tocTV" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>7</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" colspan="2" >
<widget class="QSlider" name="depthSL" >
<property name="maximum" >
<number>5</number>
@@ -123,59 +111,17 @@
</widget>
</item>
<item row="0" column="0" >
- <layout class="QHBoxLayout" >
- <property name="margin" >
- <number>0</number>
+ <widget class="QLabel" name="typeLA" >
+ <property name="text" >
+ <string>&Type:</string>
</property>
- <property name="spacing" >
- <number>6</number>
+ <property name="buddy" >
+ <cstring>typeCO</cstring>
</property>
- <item>
- <widget class="QLabel" name="typeLA" >
- <property name="text" >
- <string>&Type:</string>
- </property>
- <property name="buddy" >
- <cstring>typeCO</cstring>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QComboBox" name="typeCO" >
- <property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>3</hsizetype>
- <vsizetype>0</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- </widget>
- </item>
- <item>
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeType" >
- <enum>QSizePolicy::Expanding</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
+ </widget>
</item>
- <item row="1" column="0" >
- <widget class="QTreeView" name="tocTV" />
- </item>
</layout>
</widget>
- <pixmapfunction></pixmapfunction>
<tabstops>
<tabstop>typeCO</tabstop>
<tabstop>tocTV</tabstop>
@@ -184,8 +130,6 @@
<tabstop>moveDownPB</tabstop>
<tabstop>moveInPB</tabstop>
<tabstop>moveOutPB</tabstop>
- <tabstop>updatePB</tabstop>
- <tabstop>closePB</tabstop>
</tabstops>
<includes>
<include location="local" >qt_helpers.h</include>