#include "TocWidget.h"
-#include "TocModel.h"
+#include "GuiView.h"
#include "qt_helpers.h"
+#include "TocModel.h"
#include "FuncRequest.h"
#include "LyXFunc.h"
namespace lyx {
namespace frontend {
-TocWidget::TocWidget(TocModels & models, QWidget * parent)
- : QWidget(parent), depth_(0), models_(models)
+TocWidget::TocWidget(GuiView & gui_view, QWidget * parent)
+ : QWidget(parent), depth_(0), gui_view_(gui_view)
{
setupUi(this);
void TocWidget::on_tocTV_clicked(QModelIndex const & index)
{
goTo(index);
- // FIXME: It would be nice to return the focus to the work area in this
- // case. But we need access to the GuiView!
+ gui_view_.setFocus();
}
LYXERR(Debug::GUI, "goto " << index.row()
<< ", " << index.column());
- models_.goTo(typeCO->currentIndex(), index);
+ gui_view_.tocModels().goTo(typeCO->currentIndex(), index);
}
// The backend update can take some time so we disable
// the controls while waiting.
enableControls(false);
- models_.updateBackend();
+ gui_view_.tocModels().updateBackend();
}
/* FIXME (Ugras 17/11/06):
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, getIndexDepth(index) < depth_);
}
}
+
void TocWidget::on_typeCO_currentIndexChanged(int value)
{
setTocModel(value);
+ 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);
- goTo(list[0]);
- dispatch(FuncRequest(LFUN_OUTLINE_UP));
- 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);
- goTo(list[0]);
- dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
- enableControls(true);
- }
+ outline(LFUN_OUTLINE_DOWN);
}
void TocWidget::on_moveInTB_clicked()
{
- enableControls(false);
- QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
- if (!list.isEmpty()) {
- enableControls(false);
- goTo(list[0]);
- dispatch(FuncRequest(LFUN_OUTLINE_IN));
- enableControls(true);
- }
+ outline(LFUN_OUTLINE_IN);
}
void TocWidget::on_moveOutTB_clicked()
{
- QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
- if (!list.isEmpty()) {
- enableControls(false);
- goTo(list[0]);
- dispatch(FuncRequest(LFUN_OUTLINE_OUT));
- enableControls(true);
- }
+ outline(LFUN_OUTLINE_OUT);
}
{
updateTB->setEnabled(enable);
- if (!models_.canOutline(typeCO->currentIndex()))
+ if (!gui_view_.tocModels().canOutline(typeCO->currentIndex()))
enable = false;
moveUpTB->setEnabled(enable);
{
LYXERR(Debug::GUI, "In TocWidget::updateView()");
setTreeDepth(depth_);
- select(models_.currentIndex(typeCO->currentIndex()));
+ select(gui_view_.tocModels().currentIndex(typeCO->currentIndex()));
}
void TocWidget::init(QString const & str)
{
- QStringList const & type_names = models_.typeNames();
+ QStringList const & type_names = gui_view_.tocModels().typeNames();
if (type_names.isEmpty()) {
enableControls(false);
typeCO->clear();
return;
}
- int selected_type = models_.decodeType(str);
+ int selected_type = gui_view_.tocModels().decodeType(str);
QString const current_text = typeCO->currentText();
typeCO->blockSignals(true);
void TocWidget::setTocModel(size_t type)
{
bool controls_enabled = false;
- QStandardItemModel * toc_model = models_.model(type);
+ QStandardItemModel * toc_model = gui_view_.tocModels().model(type);
if (toc_model) {
controls_enabled = toc_model->rowCount() > 0;
tocTV->setModel(toc_model);
enableControls(controls_enabled);
if (controls_enabled) {
- depthSL->setMaximum(models_.depth(type));
+ depthSL->setMaximum(gui_view_.tocModels().depth(type));
depthSL->setValue(depth_);
}