]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/TocWidget.h
Fix faulty undo recording
[lyx.git] / src / frontends / qt / 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 "FuncCode.h"
19
20 #include <QString>
21 #include <QWidget>
22
23 class QModelIndex;
24 class QPoint;
25 class QTimer;
26
27 namespace lyx {
28
29 class Cursor;
30 class DispatchResult;
31 class FuncRequest;
32 class FuncStatus;
33 class Inset;
34
35 namespace frontend {
36
37 class FancyLineEdit;
38 class GuiView;
39
40 class TocWidget : public QWidget, public Ui::TocUi
41 {
42         Q_OBJECT
43 public:
44         ///
45         TocWidget(GuiView & gui_view, QWidget * parent = 0);
46
47         /// Initialise GUI.
48         void init(QString const & str);
49         ///
50         void doDispatch(Cursor & cur, FuncRequest const & fr, DispatchResult & dr);
51         ///send request to lyx::dispatch with proper guiview handle
52         ///(if ToC is detached current_view can be different window)
53         void sendDispatch(FuncRequest fr);
54         ///
55         bool getStatus(Cursor & cur, FuncRequest const & fr, FuncStatus & status)
56                 const;
57
58 public Q_SLOTS:
59         /// Schedule an update of the dialog, delaying expensive operations
60         void updateView();
61         /// Update completely without delay
62         void updateViewNow();
63
64 protected Q_SLOTS:
65         ///
66         void select(QModelIndex const & index);
67         ///
68         void goTo(QModelIndex const &);
69
70         void on_tocTV_activated(QModelIndex const &);
71         void on_tocTV_pressed(QModelIndex const &);
72         void on_tocTV_doubleClicked(QModelIndex const &);
73         void on_updateTB_clicked();
74         void on_sortCB_stateChanged(int state);
75         void on_persistentCB_stateChanged(int state);
76         void on_depthSL_valueChanged(int depth);
77         void on_typeCO_activated(int value);
78         void on_moveUpTB_clicked();
79         void on_moveDownTB_clicked();
80         void on_moveInTB_clicked();
81         void on_moveOutTB_clicked();
82         void filterContents();
83
84         void showContextMenu(const QPoint & pos);
85
86 private Q_SLOTS:
87         /// Perform the expensive update operations
88         void finishUpdateView();
89
90 private:
91         ///
92         void enableControls(bool enable = true);
93         ///
94         bool canOutline()
95                 { return current_type_ == "tableofcontents"; }
96         /// It is not possible to have synchronous navigation in a correct
97         /// and efficient way with the label and change type because Toc::item()
98         /// does a linear search. Even when fixed, it might even not be desirable
99         /// to do so if we want to support drag&drop of labels and references.
100         bool canNavigate()
101                 { return current_type_ != "label" && current_type_ != "change"; }
102         ///
103         bool isSortable()
104                 { return current_type_ != "tableofcontents"; }
105         ///
106         QModelIndexList getIndices();
107         /// \returns the top-most ancestor of \p descendant
108         QModelIndex getAncestor(QModelIndex const & descendant) const;
109         /// \returns \c true if \p ancestor is an ancestor (parent, grandparent, etc.) of \p descendant
110         bool isAncestor(QModelIndex const & ancestor, QModelIndex const & descendant) const;
111         /// \returns depth of the current item
112         int getItemDepth(QModelIndex const & index);
113         /// collapse all nodes to \c depth except for the branch of the currently active item
114         void collapseAllOthers(int const depth);
115         ///
116         void setTreeDepth(int depth, bool const maintain_current = false);
117         ///
118         void outline(FuncCode func_code);
119         /// finds the inset that is connected to the current item,
120         /// if any, otherwise return null
121         Inset * itemInset() const;
122         ///
123         QString current_type_;
124
125         /// depth of list shown
126         int depth_;
127         /// persistence of uncollapsed nodes in toc view
128         bool persistent_;
129         /// keep uncollapsed nodes in this event
130         bool keep_expanded_;
131         ///
132         GuiView & gui_view_;
133         // Timer for scheduling expensive update operations
134         QTimer * timer_;
135         /// Filter bar
136         FancyLineEdit * filter_ = nullptr;
137 };
138
139 } // namespace frontend
140 } // namespace lyx
141
142 #endif // TOC_WIDGET_H