#include "TocWidget.h"
-#include "GuiToc.h"
+#include "GuiView.h"
#include "qt_helpers.h"
+#include "TocModel.h"
+
+#include "FuncRequest.h"
+#include "LyXFunc.h"
#include "support/debug.h"
+#include "support/lassert.h"
#include <QHeaderView>
#include <QTimer>
namespace lyx {
namespace frontend {
-TocWidget::TocWidget(GuiToc & form, QWidget * parent)
- : QWidget(parent), depth_(0), form_(form)
+TocWidget::TocWidget(GuiView & gui_view, QWidget * parent)
+ : QWidget(parent), depth_(0), gui_view_(gui_view)
{
setupUi(this);
}
-void TocWidget::selectionChanged(const QModelIndex & current,
- const QModelIndex & /*previous*/)
+void TocWidget::on_tocTV_activated(QModelIndex const & index)
{
- LYXERR(Debug::GUI, "selectionChanged index " << current.row()
- << ", " << current.column());
+ goTo(index);
+}
- form_.goTo(typeCO->currentIndex(), current);
+
+void TocWidget::on_tocTV_clicked(QModelIndex const & index)
+{
+ goTo(index);
+ gui_view_.setFocus();
+}
+
+
+void TocWidget::goTo(QModelIndex const & index)
+{
+ LYXERR(Debug::GUI, "goto " << index.row()
+ << ", " << index.column());
+
+ gui_view_.tocModels().goTo(typeCO->currentIndex(), index);
}
// The backend update can take some time so we disable
// the controls while waiting.
enableControls(false);
- form_.updateBackend();
+ gui_view_.tocModels().updateBackend();
}
+
/* FIXME (Ugras 17/11/06):
-I have implemented a getIndexDepth function to get the model indices. In my
+I have implemented a indexDepth 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 TocWidget::getIndexDepth(QModelIndex const & index, int depth)
+which saves the string data and depth information. That will save the
+depth calculation. */
+
+static int indexDepth(QModelIndex const & index, int depth = -1)
{
++depth;
- return (index.parent() == QModelIndex())
- ? depth : getIndexDepth(index.parent(),depth);
+ return index.parent() == QModelIndex()
+ ? depth : indexDepth(index.parent(), depth);
}
if (depth == depth_)
return;
setTreeDepth(depth);
+ gui_view_.setFocus();
}
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);
+ tocTV->setExpanded(index, indexDepth(index) < depth_);
}
}
-void TocWidget::on_typeCO_currentIndexChanged(int value)
+
+void TocWidget::on_typeCO_currentIndexChanged(int)
{
- setTocModel(value);
+ updateView();
+ gui_view_.setFocus();
}
-void TocWidget::on_moveUpTB_clicked()
+void TocWidget::outline(int func_code)
{
enableControls(false);
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
- if (!list.isEmpty()) {
- enableControls(false);
- form_.goTo(typeCO->currentIndex(), list[0]);
- form_.outlineUp();
- enableControls(true);
- }
+ if (list.isEmpty())
+ return;
+ enableControls(false);
+ goTo(list[0]);
+ dispatch(FuncRequest(static_cast<FuncCode>(func_code)));
+ enableControls(true);
+ gui_view_.setFocus();
+}
+
+
+void TocWidget::on_moveUpTB_clicked()
+{
+ outline(LFUN_OUTLINE_UP);
}
void TocWidget::on_moveDownTB_clicked()
{
- enableControls(false);
- QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
- if (!list.isEmpty()) {
- enableControls(false);
- form_.goTo(typeCO->currentIndex(), list[0]);
- form_.outlineDown();
- enableControls(true);
- }
+ outline(LFUN_OUTLINE_DOWN);
}
void TocWidget::on_moveInTB_clicked()
{
- enableControls(false);
- QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
- if (!list.isEmpty()) {
- enableControls(false);
- form_.goTo(typeCO->currentIndex(), list[0]);
- form_.outlineIn();
- enableControls(true);
- }
+ outline(LFUN_OUTLINE_IN);
}
void TocWidget::on_moveOutTB_clicked()
{
- QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
- if (!list.isEmpty()) {
- enableControls(false);
- form_.goTo(typeCO->currentIndex(), list[0]);
- form_.outlineOut();
- enableControls(true);
- }
+ outline(LFUN_OUTLINE_OUT);
}
return;
}
- disconnectSelectionModel();
- tocTV->setCurrentIndex(index);
tocTV->scrollTo(index);
- reconnectSelectionModel();
+ tocTV->clearSelection();
+ tocTV->setCurrentIndex(index);
}
{
updateTB->setEnabled(enable);
- if (!form_.canOutline(typeCO->currentIndex()))
+ if (!gui_view_.tocModels().canOutline(typeCO->currentIndex()))
enable = false;
moveUpTB->setEnabled(enable);
void TocWidget::updateView()
{
LYXERR(Debug::GUI, "In TocWidget::updateView()");
- setTreeDepth();
- select(form_.currentIndex(typeCO->currentIndex()));
+ setTocModel();
+ setTreeDepth(depth_);
+ select(gui_view_.tocModels().currentIndex(typeCO->currentIndex()));
}
-void TocWidget::updateGui(int selected_type)
+void TocWidget::init(QString const & str)
{
- QStringList const & type_names = form_.typeNames();
+ QStringList const & type_names = gui_view_.tocModels().typeNames();
if (type_names.isEmpty()) {
enableControls(false);
- typeCO->clear();
+ typeCO->setEnabled(false);
tocTV->setModel(new QStandardItemModel);
- tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ tocTV->setEnabled(false);
return;
}
+ typeCO->setEnabled(true);
+ tocTV->setEnabled(true);
+ int selected_type = gui_view_.tocModels().decodeType(str);
+
QString const current_text = typeCO->currentText();
typeCO->blockSignals(true);
typeCO->clear();
for (int i = 0; i != type_names.size(); ++i)
typeCO->addItem(type_names[i]);
- if (selected_type != -1)
+ if (!str.isEmpty())
typeCO->setCurrentIndex(selected_type);
else {
int const new_index = typeCO->findText(current_text);
if (new_index != -1)
typeCO->setCurrentIndex(new_index);
+ else
+ typeCO->setCurrentIndex(selected_type);
}
typeCO->blockSignals(false);
- setTocModel(typeCO->currentIndex());
-
// setTocModel produce QTreeView reset and setting depth again
// is needed. That must be done after all Qt updates are processed.
QTimer::singleShot(0, this, SLOT(updateView()));
}
-void TocWidget::setTocModel(size_t type)
+void TocWidget::setTocModel()
{
- bool controls_enabled = false;
- QStandardItemModel * toc_model = form_.tocModel(type);
- if (toc_model) {
- controls_enabled = toc_model->rowCount() > 0;
+ int const toc_type = typeCO->currentIndex();
+ QStandardItemModel * toc_model = gui_view_.tocModels().model(toc_type);
+ LASSERT(toc_model, return);
+
+ if (tocTV->model() != toc_model) {
tocTV->setModel(toc_model);
tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
+ bool controls_enabled = toc_model->rowCount() > 0;;
enableControls(controls_enabled);
- reconnectSelectionModel();
-
if (controls_enabled) {
- depthSL->setMaximum(form_.getTocDepth(type));
+ depthSL->setMaximum(gui_view_.tocModels().depth(toc_type));
depthSL->setValue(depth_);
}
-
- LYXERR(Debug::GUI, "In TocWidget::updateGui()");
-
- select(form_.currentIndex(typeCO->currentIndex()));
-
- if (toc_model) {
- LYXERR(Debug::GUI, "tocModel()->rowCount "
- << toc_model->rowCount()
- << "\nform_->tocModel()->columnCount "
- << toc_model->columnCount());
- }
-}
-
-
-void TocWidget::reconnectSelectionModel()
-{
- connect(tocTV->selectionModel(),
- SIGNAL(currentChanged(const QModelIndex &,
- const QModelIndex &)),
- this,
- SLOT(selectionChanged(const QModelIndex &,
- const QModelIndex &)));
-}
-
-void TocWidget::disconnectSelectionModel()
-{
- disconnect(tocTV->selectionModel(),
- SIGNAL(currentChanged(QModelIndex, QModelIndex)),
- this, SLOT(selectionChanged(QModelIndex, QModelIndex)));
}
} // namespace frontend