editorview.h 6.29 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
**
hjk's avatar
hjk committed
24 25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29 30 31 32

#ifndef EDITORVIEW_H
#define EDITORVIEW_H

hjk's avatar
hjk committed
33 34
#include "coreplugin/id.h"

35 36 37 38 39
#include <QMap>
#include <QList>
#include <QString>
#include <QPointer>
#include <QVariant>
40

41 42
#include <QIcon>
#include <QWidget>
Eike Ziller's avatar
Eike Ziller committed
43

44
QT_BEGIN_NAMESPACE
Eike Ziller's avatar
Eike Ziller committed
45
class QAction;
46
class QComboBox;
Eike Ziller's avatar
Eike Ziller committed
47
class QFrame;
48
class QLabel;
49 50
class QSplitter;
class QStackedLayout;
Eike Ziller's avatar
Eike Ziller committed
51 52
class QStackedWidget;
class QToolButton;
53 54 55
QT_END_NAMESPACE

namespace Core {
56
class IContext;
57
class IDocument;
58
class IEditor;
59
class InfoBarDisplay;
60
class DocumentModel;
Lasse Holmstedt's avatar
Lasse Holmstedt committed
61
class EditorToolBar;
62 63 64

namespace Internal {

65
struct EditLocation {
66
    QPointer<IDocument> document;
67
    QString fileName;
hjk's avatar
hjk committed
68
    Id id;
69 70
    QVariant state;
};
71

72 73
class SplitterOrView;

74 75 76 77 78
class EditorView : public QWidget
{
    Q_OBJECT

public:
79
    explicit EditorView(SplitterOrView *parentSplitterOrView, QWidget *parent = 0);
80 81
    virtual ~EditorView();

82
    SplitterOrView *parentSplitterOrView() const;
83
    EditorView *findNextView();
84

85 86 87 88
    int editorCount() const;
    void addEditor(IEditor *editor);
    void removeEditor(IEditor *editor);
    IEditor *currentEditor() const;
mae's avatar
mae committed
89
    void setCurrentEditor(IEditor *editor);
90 91 92

    bool hasEditor(IEditor *editor) const;

93
    QList<IEditor *> editors() const;
94
    IEditor *editorForDocument(const IDocument *document) const;
95

96
    void showEditorStatusBar(const QString &id,
97 98 99
                           const QString &infoText,
                           const QString &buttonText,
                           QObject *object, const char *member);
100
    void hideEditorStatusBar(const QString &id);
101
    void setCloseSplitEnabled(bool enable);
Eike Ziller's avatar
Eike Ziller committed
102
    void setCloseSplitIcon(const QIcon &icon);
103

104 105
    static void updateEditorHistory(IEditor *editor, QList<EditLocation> &history);

106 107 108
signals:
    void currentEditorChanged(Core::IEditor *editor);

109 110
protected:
    void paintEvent(QPaintEvent *);
111
    void mousePressEvent(QMouseEvent *e);
112
    void focusInEvent(QFocusEvent *);
113

114 115 116
private slots:
    void closeView();
    void listSelectionActivated(int index);
117 118
    void splitHorizontally();
    void splitVertically();
119
    void splitNewWindow();
120
    void closeSplit();
121
    void openDroppedFiles(const QStringList &files);
122

123
private:
124 125 126
    friend class SplitterOrView; // for setParentSplitterOrView
    void setParentSplitterOrView(SplitterOrView *splitterOrView);

Lasse Holmstedt's avatar
Lasse Holmstedt committed
127
    void updateNavigatorActions();
128 129 130
    void updateToolBar(IEditor *editor);
    void checkProjectLoaded(IEditor *editor);

131
    SplitterOrView *m_parentSplitterOrView;
Lasse Holmstedt's avatar
Lasse Holmstedt committed
132 133
    EditorToolBar *m_toolBar;

134
    QStackedWidget *m_container;
135
    InfoBarDisplay *m_infoBarDisplay;
136
    QString m_statusWidgetId;
hjk's avatar
hjk committed
137
    QFrame *m_statusHLine;
138 139 140 141
    QFrame *m_statusWidget;
    QLabel *m_statusWidgetLabel;
    QToolButton *m_statusWidgetButton;
    QList<IEditor *> m_editors;
142
    QMap<QWidget *, IEditor *> m_widgetEditorMap;
143

mae's avatar
mae committed
144 145
    QList<EditLocation> m_navigationHistory;
    QList<EditLocation> m_editorHistory;
146 147 148 149 150 151
    int m_currentNavigationHistoryPosition;
    void updateCurrentPositionInNavigationHistory();

public:
    inline bool canGoForward() const { return m_currentNavigationHistoryPosition < m_navigationHistory.size()-1; }
    inline bool canGoBack() const { return m_currentNavigationHistoryPosition > 0; }
152 153

public slots:
154 155
    void goBackInNavigationHistory();
    void goForwardInNavigationHistory();
156 157

public:
158
    void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray());
159 160
    void cutForwardNavigationHistory();

mae's avatar
mae committed
161
    inline QList<EditLocation> editorHistory() const { return m_editorHistory; }
162 163

    void copyNavigationHistoryFrom(EditorView* other);
mae's avatar
mae committed
164
    void updateEditorHistory(IEditor *editor);
165 166
};

mae's avatar
mae committed
167 168 169 170
class SplitterOrView  : public QWidget
{
    Q_OBJECT
public:
171
    explicit SplitterOrView(Core::IEditor *editor = 0);
172
    explicit SplitterOrView(EditorView *view);
173
    ~SplitterOrView();
mae's avatar
mae committed
174 175

    void split(Qt::Orientation orientation);
mae's avatar
mae committed
176
    void unsplit();
mae's avatar
mae committed
177

mae's avatar
mae committed
178 179
    inline bool isView() const { return m_view != 0; }
    inline bool isSplitter() const { return m_splitter != 0; }
180

mae's avatar
mae committed
181 182 183 184 185 186
    inline Core::IEditor *editor() const { return m_view ? m_view->currentEditor() : 0; }
    inline QList<Core::IEditor *> editors() const { return m_view ? m_view->editors() : QList<Core::IEditor*>(); }
    inline bool hasEditor(Core::IEditor *editor) const { return m_view && m_view->hasEditor(editor); }
    inline bool hasEditors() const { return m_view && m_view->editorCount() != 0; }
    inline EditorView *view() const { return m_view; }
    inline QSplitter *splitter() const { return m_splitter; }
187 188
    QSplitter *takeSplitter();
    EditorView *takeView();
mae's avatar
mae committed
189

190 191
    QByteArray saveState() const;
    void restoreState(const QByteArray &);
mae's avatar
mae committed
192

193
    EditorView *findFirstView();
194
    SplitterOrView *findParentSplitter() const;
mae's avatar
mae committed
195

196 197
    QSize sizeHint() const { return minimumSizeHint(); }
    QSize minimumSizeHint() const;
198

199 200
    void unsplitAll();

mae's avatar
mae committed
201
private:
202
    void unsplitAll_helper();
mae's avatar
mae committed
203 204 205 206 207
    QStackedLayout *m_layout;
    EditorView *m_view;
    QSplitter *m_splitter;
};

208 209 210
}
}
#endif // EDITORVIEW_H