~ubuntu-branches/ubuntu/vivid/kate/vivid-proposed

« back to all changes in this revision

Viewing changes to kate/src/kateviewspace.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
 
3
   Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
 
4
   Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>
 
5
 
 
6
   This library is free software; you can redistribute it and/or
 
7
   modify it under the terms of the GNU Library General Public
 
8
   License version 2 as published by the Free Software Foundation.
 
9
 
 
10
   This library is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   Library General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Library General Public License
 
16
   along with this library; see the file COPYING.LIB.  If not, write to
 
17
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
   Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
#ifndef KATE_VIEWSPACE_H
 
22
#define KATE_VIEWSPACE_H
 
23
 
 
24
#include <ktexteditor/view.h>
 
25
#include <ktexteditor/document.h>
 
26
#include <ktexteditor/modificationinterface.h>
 
27
 
 
28
#include <QHash>
 
29
#include <QWidget>
 
30
 
 
31
class KConfigBase;
 
32
class KateViewManager;
 
33
class QStackedWidget;
 
34
class QToolButton;
 
35
class KateTabBar;
 
36
 
 
37
class KateViewSpace : public QWidget
 
38
{
 
39
    Q_OBJECT
 
40
 
 
41
public:
 
42
    explicit KateViewSpace(KateViewManager *, QWidget *parent = 0, const char *name = 0);
 
43
 
 
44
    /**
 
45
     * Returns \e true, if this view space is currently the active view space.
 
46
     */
 
47
    bool isActiveSpace();
 
48
 
 
49
    /**
 
50
     * Depending on @p active, mark this view space as active or inactive.
 
51
     * Called from the view manager.
 
52
     */
 
53
    void setActive(bool active);
 
54
 
 
55
    /**
 
56
     * Create new view for given document
 
57
     * @param doc document to create view for
 
58
     * @return new created view
 
59
     */
 
60
    KTextEditor::View *createView(KTextEditor::Document *doc);
 
61
    void removeView(KTextEditor::View *v);
 
62
 
 
63
    bool showView(KTextEditor::View *view) {
 
64
        return showView(view->document());
 
65
    }
 
66
    bool showView(KTextEditor::Document *document);
 
67
 
 
68
    KTextEditor::View *currentView();
 
69
 
 
70
    void saveConfig(KConfigBase *config, int myIndex, const QString &viewConfGrp);
 
71
    void restoreConfig(KateViewManager *viewMan, const KConfigBase *config, const QString &group);
 
72
 
 
73
    /**
 
74
     * Returns the document LRU list of this view space.
 
75
     */
 
76
    QVector<KTextEditor::Document*> lruDocumentList() const;
 
77
 
 
78
    /**
 
79
     * Called by the view manager if a viewspace was closed.
 
80
     * The documents of the closed are merged into this viewspace
 
81
     */
 
82
    void mergeLruList(const QVector<KTextEditor::Document*> & lruList);
 
83
 
 
84
    /**
 
85
     * Called by the view manager to notify that new documents were created
 
86
     * while this view space was active. If @p append is @e true, the @p doc
 
87
     * is appended to the lru document list, otherwise, it is prepended.
 
88
     */
 
89
    void registerDocument(KTextEditor::Document *doc, bool append = true);
 
90
 
 
91
    /**
 
92
     * Event filter to catch events from view space tool buttons.
 
93
     */
 
94
    bool eventFilter(QObject *obj, QEvent *event);
 
95
 
 
96
    /**
 
97
     * Focus the previous tab in the tabbar.
 
98
     */
 
99
    void focusPrevTab();
 
100
 
 
101
    /**
 
102
     * Focus the next tab in the tabbar.
 
103
     */
 
104
    void focusNextTab();
 
105
 
 
106
public Q_SLOTS:
 
107
    void documentDestroyed(QObject *doc);
 
108
    void updateDocumentName(KTextEditor::Document *doc);
 
109
    void updateDocumentState(KTextEditor::Document *doc);
 
110
 
 
111
private Q_SLOTS:
 
112
    void statusBarToggled();
 
113
    void tabBarToggled();
 
114
    void changeView(int buttonId);
 
115
 
 
116
    /**
 
117
     * Calls this slot to make this view space the currently active view space.
 
118
     * Making it active goes through the KateViewManager.
 
119
     * @param focusCurrentView if @e true, the current view will get focus
 
120
     */
 
121
    void makeActive(bool focusCurrentView = true);
 
122
 
 
123
    /**
 
124
     * Add a tab for @p doc at position @p index.
 
125
     */
 
126
    void insertTab(int index, KTextEditor::Document * doc);
 
127
 
 
128
    /**
 
129
     * Remove tab for @p doc, and return the index (position)
 
130
     * of the removed tab.
 
131
     */
 
132
    int removeTab(KTextEditor::Document * doc, bool documentDestroyed);
 
133
 
 
134
    /**
 
135
     * Remove @p count tabs, since the tab bar shrinked.
 
136
     */
 
137
    void removeTabs(int count);
 
138
 
 
139
    /**
 
140
     * Add @p count tabs, since the tab bar grew.
 
141
     */
 
142
    void addTabs(int count);
 
143
 
 
144
    /**
 
145
     * This slot is called by the tabbar, if tab @p id was closed through the
 
146
     * context menu.
 
147
     */
 
148
    void closeTabRequest(int id);
 
149
 
 
150
    /**
 
151
     * This slot is called when the context menu is requested for button
 
152
     * @p id at position @p globalPos.
 
153
     * @param id the button, or -1 if the context menu was requested on
 
154
     *        at a place where no tab exists
 
155
     * @param globalPos the position of the context menu in global coordinates
 
156
     */
 
157
    void showContextMenu(int id, const QPoint & globalPos);
 
158
 
 
159
    /**
 
160
     * Called to create a new empty document.
 
161
     */
 
162
    void createNewDocument();
 
163
 
 
164
    /**
 
165
     * Update the quick open button to reflect the currently hidden tabs.
 
166
     */
 
167
    void updateQuickOpen();
 
168
 
 
169
private:
 
170
    /**
 
171
     * Returns the amount of documents in KateDocManager that currently
 
172
     * have no tab in this tab bar.
 
173
     */
 
174
    int hiddenDocuments() const;
 
175
 
 
176
private:
 
177
    // Kate's view manager
 
178
    KateViewManager *m_viewManager;
 
179
 
 
180
    // config group string, used for restoring View session configuration
 
181
    QString m_group;
 
182
 
 
183
    // flag that indicates whether this view space is the active one.
 
184
    // correct setter: m_viewManager->setActiveSpace(this);
 
185
    bool mIsActiveSpace;
 
186
 
 
187
    // widget stack that contains all KTE::Views
 
188
    QStackedWidget *stack;
 
189
 
 
190
    // document's in the view space, sorted in LRU mode:
 
191
    // the most recently used Document is at the end of the list
 
192
    QVector<KTextEditor::Document *> m_lruDocList;
 
193
 
 
194
    // the list of views that are contained in this view space,
 
195
    // mapped through a hash from Document to View.
 
196
    // note: the number of entries match stack->count();
 
197
    QHash<KTextEditor::Document*, KTextEditor::View*> m_docToView;
 
198
 
 
199
    // tab bar that contains viewspace tabs
 
200
    KateTabBar *m_tabBar;
 
201
    
 
202
    // split action
 
203
    QToolButton *m_split;
 
204
    
 
205
    // quick open action
 
206
    QToolButton *m_quickOpen;
 
207
 
 
208
    // map from Document to button id
 
209
    QHash<KTextEditor::Document *, int> m_docToTabId;
 
210
};
 
211
 
 
212
#endif