editorview.h 6.56 KB
Newer Older
1
/**************************************************************************
2 3 4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
8
**
9
** Commercial Usage
10
**
11 12 13 14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** 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.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
27
**
28
**************************************************************************/
29 30 31 32 33 34 35 36 37 38 39

#ifndef EDITORVIEW_H
#define EDITORVIEW_H

#include <QtCore/QMap>
#include <QtCore/QList>
#include <QtCore/QString>
#include <QtCore/QSettings>
#include <QtGui/QWidget>
#include <QtGui/QAction>
#include <QtGui/QSplitter>
40
#include <QtGui/QStackedLayout>
41
#include <QtCore/QPointer>
42 43

#include <coreplugin/icontext.h>
44
#include <coreplugin/ifile.h>
45 46 47 48 49 50 51 52 53 54 55 56 57 58

#include <QtCore/QMap>
#include <QtGui/QSortFilterProxyModel>

QT_BEGIN_NAMESPACE
class QComboBox;
class QToolButton;
class QLabel;
class QStackedWidget;
QT_END_NAMESPACE

namespace Core {

class IEditor;
59
class OpenEditorsModel;
60 61 62

namespace Internal {

63 64 65 66 67 68
    struct EditLocation {
        QPointer<IFile> file;
        QString fileName;
        QString kind;
        QVariant state;
    };
69 70 71 72 73 74

class EditorView : public QWidget
{
    Q_OBJECT

public:
75
    EditorView(OpenEditorsModel *model = 0, QWidget *parent = 0);
76 77 78 79 80 81
    virtual ~EditorView();

    int editorCount() const;
    void addEditor(IEditor *editor);
    void removeEditor(IEditor *editor);
    IEditor *currentEditor() const;
mae's avatar
mae committed
82
    void setCurrentEditor(IEditor *editor);
83 84 85

    bool hasEditor(IEditor *editor) const;

86 87 88 89 90 91 92
    QList<IEditor *> editors() const;
    void showEditorInfoBar(const QString &kind,
                           const QString &infoText,
                           const QString &buttonText,
                           QObject *object, const char *member);
    void hideEditorInfoBar(const QString &kind);

93 94 95 96 97
    void showEditorStatusBar(const QString &kind,
                           const QString &infoText,
                           const QString &buttonText,
                           QObject *object, const char *member);
    void hideEditorStatusBar(const QString &kind);
98

mae's avatar
mae committed
99 100 101
public slots:
    void closeView();

102 103 104 105
private slots:
    void updateEditorStatus(Core::IEditor *editor = 0);
    void checkEditorStatus();
    void makeEditorWritable();
mae's avatar
mae committed
106
    void listSelectionActivated(int index);
107
    void listContextMenu(QPoint);
108 109 110 111 112

private:
    void updateToolBar(IEditor *editor);
    void checkProjectLoaded(IEditor *editor);

113
    OpenEditorsModel *m_model;
114
    QWidget *m_toolBar;
con's avatar
con committed
115
    QWidget *m_activeToolBar;
116 117 118 119
    QStackedWidget *m_container;
    QComboBox *m_editorList;
    QToolButton *m_closeButton;
    QToolButton *m_lockButton;
con's avatar
con committed
120
    QWidget *m_defaultToolBar;
121 122 123 124 125
    QString m_infoWidgetKind;
    QFrame *m_infoWidget;
    QLabel *m_infoWidgetLabel;
    QToolButton *m_infoWidgetButton;
    IEditor *m_editorForInfoWidget;
126
    QString m_statusWidgetKind;
hjk's avatar
hjk committed
127
    QFrame *m_statusHLine;
128 129 130 131
    QFrame *m_statusWidget;
    QLabel *m_statusWidgetLabel;
    QToolButton *m_statusWidgetButton;
    QList<IEditor *> m_editors;
132
    QMap<QWidget *, IEditor *> m_widgetEditorMap;
133

mae's avatar
mae committed
134 135
    QList<EditLocation> m_navigationHistory;
    QList<EditLocation> m_editorHistory;
136 137
    int m_currentNavigationHistoryPosition;
    void updateCurrentPositionInNavigationHistory();
138 139 140
    QAction *m_goBackAction;
    QAction *m_goForwardAction;
    void updateActions();
141

mae's avatar
mae committed
142

143 144 145
public:
    inline bool canGoForward() const { return m_currentNavigationHistoryPosition < m_navigationHistory.size()-1; }
    inline bool canGoBack() const { return m_currentNavigationHistoryPosition > 0; }
146 147

public slots:
148 149
    void goBackInNavigationHistory();
    void goForwardInNavigationHistory();
150 151 152
    void updateActionShortcuts();

public:
153
    void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray());
mae's avatar
mae committed
154
    inline QList<EditLocation> editorHistory() const { return m_editorHistory; }
155 156

    void copyNavigationHistoryFrom(EditorView* other);
mae's avatar
mae committed
157
    void updateEditorHistory(IEditor *editor);
158 159
};

mae's avatar
mae committed
160 161 162 163
class SplitterOrView  : public QWidget
{
    Q_OBJECT
public:
164
    SplitterOrView(OpenEditorsModel *model); // creates a root splitter
165
    SplitterOrView(Core::IEditor *editor = 0);
166
    ~SplitterOrView();
mae's avatar
mae committed
167 168

    void split(Qt::Orientation orientation);
mae's avatar
mae committed
169
    void unsplit();
mae's avatar
mae committed
170

mae's avatar
mae committed
171 172
    inline bool isView() const { return m_view != 0; }
    inline bool isRoot() const { return m_isRoot; }
173

mae's avatar
mae committed
174 175 176 177 178 179 180
    inline bool isSplitter() const { return m_splitter != 0; }
    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; }
181 182
    QSplitter *takeSplitter();
    EditorView *takeView();
mae's avatar
mae committed
183

184 185
    QByteArray saveState() const;
    void restoreState(const QByteArray &);
mae's avatar
mae committed
186 187

    SplitterOrView *findView(Core::IEditor *editor);
mae's avatar
mae committed
188
    SplitterOrView *findView(EditorView *view);
189
    SplitterOrView *findFirstView();
mae's avatar
mae committed
190
    SplitterOrView *findEmptyView();
mae's avatar
mae committed
191
    SplitterOrView *findSplitter(Core::IEditor *editor);
mae's avatar
mae committed
192
    SplitterOrView *findSplitter(SplitterOrView *child);
mae's avatar
mae committed
193

mae's avatar
mae committed
194 195
    SplitterOrView *findNextView(SplitterOrView *view);

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

199 200
    void unsplitAll();

mae's avatar
mae committed
201 202
protected:
    void paintEvent(QPaintEvent *);
203
    void mousePressEvent(QMouseEvent *e);
mae's avatar
mae committed
204

205

mae's avatar
mae committed
206
private:
207
    void unsplitAll_helper();
mae's avatar
mae committed
208
    SplitterOrView *findNextView_helper(SplitterOrView *view, bool *found);
mae's avatar
mae committed
209 210 211 212 213 214
    bool m_isRoot;
    QStackedLayout *m_layout;
    EditorView *m_view;
    QSplitter *m_splitter;
};

215 216 217
}
}
#endif // EDITORVIEW_H