1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef BOOKMARKMANAGER_H
35 #define BOOKMARKMANAGER_H
37 #include <coreplugin/icontext.h>
38 #include <coreplugin/inavigationwidgetfactory.h>
40 #include <QtCore/QAbstractItemModel>
41 #include <QtCore/QMultiMap>
42 #include <QtCore/QList>
43 #include <QtGui/QListView>
44 #include <QtGui/QPixmap>
45 #include <QtGui/QStyledItemDelegate>
47 namespace ProjectExplorer {
55 namespace TextEditor {
63 class BookmarksPlugin;
64 class BookmarkContext;
66 class BookmarkManager : public QAbstractItemModel
74 QIcon bookmarkIcon() const { return m_bookmarkIcon; }
76 void updateBookmark(Bookmark *bookmark);
77 void removeBookmark(Bookmark *bookmark); // Does not remove the mark
78 void removeAllBookmarks();
79 Bookmark *bookmarkForIndex(QModelIndex index);
81 enum State { NoBookMarks, HasBookMarks, HasBookmarksInDocument };
85 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
86 QModelIndex parent(const QModelIndex &child) const;
87 int rowCount(const QModelIndex &parent = QModelIndex()) const;
88 int columnCount(const QModelIndex &parent = QModelIndex()) const;
89 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
91 // this QItemSelectionModel is shared by all views
92 QItemSelectionModel *selectionModel() const;
95 Filename = Qt::UserRole,
96 LineNumber = Qt::UserRole + 1,
97 Directory = Qt::UserRole + 2,
98 LineText = Qt::UserRole + 3
102 void toggleBookmark();
103 void toggleBookmark(const QString &fileName, int lineNumber);
104 void nextInDocument();
105 void prevInDocument();
110 bool gotoBookmark(Bookmark *bookmark);
113 void updateActions(int state);
114 void currentIndexChanged(const QModelIndex &);
117 void updateActionStatus();
118 void loadBookmarks();
121 TextEditor::ITextEditor *currentTextEditor() const;
122 ProjectExplorer::SessionManager* sessionManager() const;
124 void documentPrevNext(bool next);
126 Bookmark* findBookmark(const QString &path, const QString &fileName, int lineNumber);
127 void addBookmark(Bookmark *bookmark, bool userset = true);
128 void addBookmark(const QString &s);
129 static QString bookmarkToString(const Bookmark *b);
130 void saveBookmarks();
132 typedef QMultiMap<QString, Bookmark *> FileNameBookmarksMap;
133 typedef QMap<QString, FileNameBookmarksMap *> DirectoryFileBookmarksMap;
135 DirectoryFileBookmarksMap m_bookmarksMap;
137 const QIcon m_bookmarkIcon;
139 QList<Bookmark *> m_bookmarksList;
140 QItemSelectionModel *m_selectionModel;
143 class BookmarkView : public QListView
147 BookmarkView(QWidget *parent = 0);
149 void setModel(QAbstractItemModel *model);
151 void gotoBookmark(const QModelIndex &index);
153 void removeFromContextMenu();
156 void contextMenuEvent(QContextMenuEvent *event);
157 void removeBookmark(const QModelIndex &index);
159 BookmarkContext *m_bookmarkContext;
160 QModelIndex m_contextMenuIndex;
161 BookmarkManager *m_manager;
164 class BookmarkContext : public Core::IContext
167 BookmarkContext(BookmarkView *widget);
168 virtual Core::Context context() const;
169 virtual QWidget *widget();
171 BookmarkView *m_bookmarkView;
172 const Core::Context m_context;
175 class BookmarkViewFactory : public Core::INavigationWidgetFactory
178 BookmarkViewFactory(BookmarkManager *bm);
179 QString displayName() const;
180 int priority() const;
182 QKeySequence activationSequence() const;
183 Core::NavigationView createWidget();
185 BookmarkManager *m_manager;
188 class BookmarkDelegate : public QStyledItemDelegate
192 BookmarkDelegate(QObject * parent = 0);
194 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
195 QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
198 void generateGradientPixmap(int width, int height, QColor color, bool selected) const;
199 mutable QPixmap *m_normalPixmap;
200 mutable QPixmap *m_selectedPixmap;
203 } // namespace Internal
204 } // namespace Bookmarks
206 #endif // BOOKMARKMANAGER_H