]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/TocWidget.h
ec1d5ad2643731c91f4e4e688990cb4e57b58521
[lyx.git] / src / frontends / qt4 / TocWidget.h
1 // -*- C++ -*-
2 /**
3  * \file TocWidget.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef TOC_WIDGET_H
14 #define TOC_WIDGET_H
15
16 #include "ui_TocUi.h"
17
18 #include "Cursor.h"
19 #include "FuncCode.h"
20
21 #include <QTimer>
22 #include <QWidget>
23
24 class QModelIndex;
25 class QString;
26
27 namespace lyx {
28 namespace frontend {
29
30 class GuiView;
31
32 class TocWidget : public QWidget, public Ui::TocUi
33 {
34         Q_OBJECT
35 public:
36         ///
37         TocWidget(GuiView & gui_view, QWidget * parent = 0);
38
39         /// Initialise GUI.
40         void init(QString const & str);
41         ///
42         void doDispatch(Cursor & cur, FuncRequest const & fr);
43         ///
44         bool getStatus(Cursor & cur, FuncRequest const & fr, FuncStatus & status)
45                 const;
46         // update the view when the model has changed
47         void checkModelChanged();
48
49 public Q_SLOTS:
50         /// Schedule an update of the dialog after a delay
51         void updateView();
52         /// Schedule an update of the dialog immediately
53         void updateViewNow();
54
55 protected Q_SLOTS:
56         ///
57         void select(QModelIndex const & index);
58         ///
59         void goTo(QModelIndex const &);
60
61         void on_tocTV_activated(QModelIndex const &);
62         void on_tocTV_pressed(QModelIndex const &);
63         void on_updateTB_clicked();
64         void on_sortCB_stateChanged(int state);
65         void on_persistentCB_stateChanged(int state);
66         void on_depthSL_valueChanged(int depth);
67         void on_typeCO_currentIndexChanged(int value);
68         void on_moveUpTB_clicked();
69         void on_moveDownTB_clicked();
70         void on_moveInTB_clicked();
71         void on_moveOutTB_clicked();
72         void filterContents();
73
74         void showContextMenu(const QPoint & pos);
75
76 private Q_SLOTS:
77         /// Update the display of the dialog
78         void realUpdateView();
79
80 private:
81         ///
82         void enableControls(bool enable = true);
83         ///
84         bool canOutline()
85                 { return current_type_ == "tableofcontents"; }
86         /// It is not possible to have synchronous navigation in a correct
87         /// and efficient way with the label and change type because Toc::item()
88         /// does a linear search. Even when fixed, it might even not be desirable
89         /// to do so if we want to support drag&drop of labels and references.
90         bool canNavigate()
91                 { return current_type_ != "label" && current_type_ != "change"; }
92         ///
93         bool isSortable()
94                 { return current_type_ != "tableofcontents"; }
95         ///
96         void setTreeDepth(int depth);
97         ///
98         void outline(FuncCode func_code);
99         /// finds the inset that is connected to the current item,
100         /// if any, otherwise return null
101         Inset * itemInset() const;
102         ///
103         QString current_type_;
104
105         /// depth of list shown
106         int depth_;
107         /// persistence of uncollapsed nodes in toc view
108         bool persistent_;
109         ///
110         GuiView & gui_view_;
111         // Timers for scheduling updates: one immediately and one after a delay.
112         // This is according to the logic of the previous code: when at rest, the
113         // update is carried out immediately, and when an update was done recently,
114         // we schedule an update to occur 2s after resting.
115         QTimer * update_timer_short_;
116         QTimer * update_timer_long_;
117 };
118
119 } // namespace frontend
120 } // namespace lyx
121
122 #endif // TOC_WIDGET_H